Skip to content

Commit

Permalink
Quick bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
XeoNovaDan committed Sep 25, 2018
1 parent d317077 commit 198639e
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
<author>XeoNovaDan</author>
<url>https://ludeon.com/forums/index.php?topic=29503.0</url>
<targetVersion>0.19.0</targetVersion>
<description>Current Version: v1.1 (25th September 2018)\n\nV.A.T.S for RimWorld! Allow your colonists, obedient animals and even some raiders to prioritize targeting certain body part groups of their enemies. Shoot those heads off in style!</description>
<description>Current Version: v1.1.1 (25th September 2018)\n\nV.A.T.S for RimWorld! Allow your colonists, obedient animals and even some raiders to prioritize targeting certain body part groups of their enemies. Shoot those heads off in style!</description>
</ModMetaData>
2 changes: 1 addition & 1 deletion About/ModSync.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ModSyncNinjaData>
<ID>6ff764b2-16e6-400f-be30-c004b847f984</ID>
<ModName>[XND] Targeting Modes</ModName>
<Version>1.1</Version>
<Version>1.1.1</Version>
<SaveBreaking>False</SaveBreaking>
<Host name="Github">
<Owner>XeoNovaDan</Owner>
Expand Down
Binary file modified Assemblies/TargetingModes.dll
Binary file not shown.
Binary file modified Source/TargetingModes/.vs/TargetingModes/v15/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
43 changes: 27 additions & 16 deletions Source/TargetingModes/CompTargetingMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,43 @@ public override void CompTick()
// Log.Message(this.ToString());
// For compatibility with existing saves
if (_targetingMode == null || CanResetTargetingMode())
_targetingMode = TargetingModesUtility.DefaultTargetingMode;
SetTargetingMode(TargetingModesUtility.DefaultTargetingMode);
}

public bool CanResetTargetingMode()
{
// Non-player world pawns are exempt to player restrictions
if (parent.Faction != Faction.OfPlayer && parent.Map == null)
return Find.TickManager.TicksGame % TargModeResetAttemptInterval(3) == 0;
if (parent.Map == null)
return Find.TickManager.TicksGame % TargModeResetAttemptInterval() == 0;

// If player's set it to never reset, if it isn't time to update or if it's already been reset
if (TargetingModesSettings.TargModeResetFrequencyInt == 0 ||
Find.TickManager.TicksGame % TargModeResetAttemptInterval(TargetingModesSettings.TargModeResetFrequencyInt) != 0 ||
Find.TickManager.TicksGame != _resetTargetingModeTick ||
_targetingMode == TargetingModesUtility.DefaultTargetingMode)
return false;

_resetTargetingModeTick += TargModeResetAttemptInterval();

// Not super efficient code, but legibility's the priority
if (Pawn != null)
{
if (Pawn.drafter?.Drafted == false)
return true;
if (!GenAI.InDangerousCombat(Pawn))
return true;
if (Pawn.drafter?.Drafted == true)
return false;
if (GenAI.InDangerousCombat(Pawn))
return false;
}
if (parent is Building_TurretGun turret)
{
if (turret.CurrentTarget == null)
return true;
if (turret.CurrentTarget != null)
return false;
}

return false;
return true;
}

private static int TargModeResetAttemptInterval(int freqInt)
private int TargModeResetAttemptInterval()
{
switch (freqInt)
switch ((parent.Faction == Faction.OfPlayer) ? TargetingModesSettings.TargModeResetFrequencyInt : 3)
{
// 1 = 1d
case 1:
Expand All @@ -78,7 +80,7 @@ private static int TargModeResetAttemptInterval(int freqInt)
// 4 = 3h
case 4:
return GenDate.TicksPerHour * 3;
// other (5) = 1h
// other = 1h
default:
return GenDate.TicksPerHour;
};
Expand All @@ -88,16 +90,25 @@ public override void PostExposeData()
{
base.PostExposeData();
Scribe_Defs.Look(ref _targetingMode, "targetingMode");
Scribe_Values.Look(ref _resetTargetingModeTick, "resetTargetingModeTick", -1);
}

public override string ToString() =>
$"CompTargetingMode for {parent} :: _targetingMode = {_targetingMode.LabelCap}";
$"CompTargetingMode for {parent} :: _targetingMode={_targetingMode.LabelCap}; _resetTargetingModeTick={_resetTargetingModeTick} (TicksGame={Find.TickManager.TicksGame})";

public TargetingModeDef GetTargetingMode() => _targetingMode;

public void SetTargetingMode(TargetingModeDef targetMode) => _targetingMode = targetMode;
public void SetTargetingMode(TargetingModeDef targetMode)
{
// Actually set the targeting mode
_targetingMode = targetMode;

// Set which tick the game will try to reset the mode at
_resetTargetingModeTick = Find.TickManager.TicksGame + TargModeResetAttemptInterval();
}

private TargetingModeDef _targetingMode = TargetingModesUtility.DefaultTargetingMode;
private int _resetTargetingModeTick = -1;

}
}
2 changes: 1 addition & 1 deletion Source/TargetingModes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.1.1.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
1 change: 1 addition & 0 deletions Source/TargetingModes/TargetingModesSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void DoWindowContents(Rect wrect)
public override void ExposeData()
{
Scribe_Values.Look(ref accuracyPenalties, "accuracyPenalties", true);
Scribe_Values.Look(ref targModeResetFrequencyInt, "targModeResetFrequencyInt", 3f);
Scribe_Values.Look(ref raidersUseTargModes, "raidersUseTargModes", true);
Scribe_Values.Look(ref raiderMinSkillForTargMode, "raiderMinSkillForTargMode", 8f);
Scribe_Values.Look(ref mechanoidTargModeChance, "mechanoidTargModeChance", 0.35f);
Expand Down
Binary file modified Source/TargetingModes/obj/Debug/TargetingModes.dll
Binary file not shown.

0 comments on commit 198639e

Please sign in to comment.