Skip to content

Commit

Permalink
Merge pull request #93 from kbatbouta/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
kbatbouta authored Dec 24, 2023
2 parents 034922e + a890980 commit db1b36d
Show file tree
Hide file tree
Showing 83 changed files with 6,957 additions and 4,108 deletions.
Binary file modified 1.4/Assemblies/CombatAI.dll
Binary file not shown.
49 changes: 41 additions & 8 deletions 1.4/Defs/DutyDefs/Duties_Misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@
<li Class="JobGiver_TakeCombatEnhancingDrug">
<onlyIfInDanger>true</onlyIfInDanger>
</li>
<li Class="CombatAI.ThinkNode_ConditionalReacted">
<ticks>900</ticks>
<subNodes>
<li Class="JobGiver_AIFightEnemies">
<targetAcquireRadius>35</targetAcquireRadius>
<targetKeepRadius>42</targetKeepRadius>
</li>
</subNodes>
</li>
<li Class="JobGiver_AIDefendPoint">
<targetAcquireRadius>65</targetAcquireRadius>
<targetKeepRadius>72</targetKeepRadius>
</li>
</li>
<li Class="ThinkNode_ForbidOutsideFlagRadius">
<maxDistToSquadFlag>16</maxDistToSquadFlag>
<subNodes>
Expand All @@ -23,7 +32,7 @@
</subNodes>
</li>
<li Class="JobGiver_WanderNearDutyLocation">
<wanderRadius>32</wanderRadius>
<wanderRadius>12</wanderRadius>
<locomotionUrgencyOutsideRadius>Sprint</locomotionUrgencyOutsideRadius>
</li>
<li Class="JobGiver_AITrashBuildingsDistant">
Expand All @@ -45,9 +54,21 @@
<li Class="JobGiver_TakeCombatEnhancingDrug">
<onlyIfInDanger>true</onlyIfInDanger>
</li>
<li Class="ThinkNode_Subtree" MayRequire="Ludeon.RimWorld.Biotech">
<treeDef>Abilities_Aggressive</treeDef>
</li>
<li Class="CombatAI.ThinkNode_ConditionalReacted">
<ticks>900</ticks>
<subNodes>
<li Class="JobGiver_AIFightEnemies">
<targetAcquireRadius>35</targetAcquireRadius>
<targetKeepRadius>42</targetKeepRadius>
</li>
</subNodes>
</li>
<li Class="JobGiver_AIDefendPoint">
<targetAcquireRadius>65</targetAcquireRadius>
<targetKeepRadius>72</targetKeepRadius>
<targetAcquireRadius>32</targetAcquireRadius>
<targetKeepRadius>28</targetKeepRadius>
</li>
<li Class="ThinkNode_ForbidOutsideFlagRadius">
<maxDistToSquadFlag>16</maxDistToSquadFlag>
Expand All @@ -59,6 +80,7 @@
</li>
<li Class="JobGiver_WanderNearDutyLocation">
<wanderRadius>8</wanderRadius>
<expiryInterval>30</expiryInterval>
<locomotionUrgencyOutsideRadius>Sprint</locomotionUrgencyOutsideRadius>
</li>
<li Class="JobGiver_AITrashBuildingsDistant">
Expand All @@ -78,17 +100,28 @@
<li Class="JobGiver_TakeCombatEnhancingDrug">
<onlyIfInDanger>true</onlyIfInDanger>
</li>
<li Class="CombatAI.ThinkNode_ConditionalReacted">
<ticks>900</ticks>
<subNodes>
<li Class="JobGiver_AIFightEnemies">
<targetAcquireRadius>35</targetAcquireRadius>
<targetKeepRadius>42</targetKeepRadius>
</li>
</subNodes>
</li>
<li Class="JobGiver_AIDefendEscortee">
<targetAcquireRadius>65</targetAcquireRadius>
<targetAcquireRadius>35</targetAcquireRadius>
<targetKeepRadius>72</targetKeepRadius>
</li>
<li Class="JobGiver_AIFollowEscortee"/>
</li>
<li Class="CombatAI.JobGiver_CAIFollowEscortee"/>
<li Class="ThinkNode_Subtree">
<treeDef>SatisfyVeryUrgentNeeds</treeDef>
</li>
<li Class="JobGiver_WanderNearDutyLocation">
<wanderRadius>8</wanderRadius>
</li>
<expiryInterval>60</expiryInterval>
<locomotionUrgencyOutsideRadius>Jog</locomotionUrgencyOutsideRadius>
</li>
<li Class="JobGiver_AITrashBuildingsDistant">
<attackAllInert>true</attackAllInert>
</li>
Expand Down
2 changes: 1 addition & 1 deletion 1.4/Defs/Jobs/Jobs_Misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<defName>CombatAI_Goto_Cover</defName>
<driverClass>JobDriver_Goto</driverClass>
<reportString>moving.</reportString>
<allowOpportunisticPrefix>true</allowOpportunisticPrefix>
<allowOpportunisticPrefix>false</allowOpportunisticPrefix>
<carryThingAfterJob>true</carryThingAfterJob>
<dropThingBeforeJob>false</dropThingBeforeJob>
<checkOverrideOnDamage>Never</checkOverrideOnDamage>
Expand Down
17 changes: 17 additions & 0 deletions 1.4/Languages/English/Keyed/Translations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<CombatAI.Hide>Hide</CombatAI.Hide>
<CombatAI.Expand>Hide</CombatAI.Expand>
<CombatAI.Quick.Welcome>Welcome to CAI-5000</CombatAI.Quick.Welcome>
<CombatAI.DefKindSettings.Title>AI Race Settings</CombatAI.DefKindSettings.Title>
<CombatAI.DefKindSettings.Description>Here you can configure different AI settings for each race.</CombatAI.DefKindSettings.Description>
<CombatAI.DefKindSettings.Selected>Selected</CombatAI.DefKindSettings.Selected>
<CombatAI.Gizmos.AttackMove>Move-Attack</CombatAI.Gizmos.AttackMove>
<CombatAI.Gizmos.AttackMove.Warning>Warning: Melee pawns cannot use move-attack. Melee pawns skipped.</CombatAI.Gizmos.AttackMove.Warning>
<CombatAI.Gizmos.AttackMove.Cancel>Cancel Move-Attack</CombatAI.Gizmos.AttackMove.Cancel>
Expand All @@ -21,6 +24,7 @@
<CombatAI.Animator.Controller>Hold</CombatAI.Animator.Controller>
<CombatAI.Animator.Controller.Description>Hold at the current angle.</CombatAI.Animator.Controller.Description>
<CombatAI.Settings.Basic>Basic Settings</CombatAI.Settings.Basic>
<CombatAI.Settings.Basic.RandomizedPersonality>Enable variation in faction tactics depending on the faction leader and the current time of year</CombatAI.Settings.Basic.RandomizedPersonality>
<CombatAI.Settings.Basic.Presets>Performance/Difficulty presets</CombatAI.Settings.Basic.Presets>
<CombatAI.Settings.Basic.Presets.Easy>Easy/Perf</CombatAI.Settings.Basic.Presets.Easy>
<CombatAI.Settings.Basic.Presets.Normal>Normal</CombatAI.Settings.Basic.Presets.Normal>
Expand All @@ -37,6 +41,8 @@
<CombatAI.Settings.Basic.SappingMul.Description>Cost multiplier for pathing through walls. Higher values means raiders are less likely to path through walls.</CombatAI.Settings.Basic.SappingMul.Description>
<CombatAI.Settings.Basic.FogOfWar>[BETA] Fog of war</CombatAI.Settings.Basic.FogOfWar>
<CombatAI.Settings.Basic.FogOfWar.Enable>Enable fog of war</CombatAI.Settings.Basic.FogOfWar.Enable>
<CombatAI.Settings.Basic.FogOfWar.OldShader>Use the old legacy shader</CombatAI.Settings.Basic.FogOfWar.OldShader>
<CombatAI.Settings.Basic.FogOfWar.OldShader.Restart>The new shader settings will be applied after restart!</CombatAI.Settings.Basic.FogOfWar.OldShader.Restart>
<CombatAI.Settings.Basic.FogOfWar.Allies>Allies reveal fog of war</CombatAI.Settings.Basic.FogOfWar.Allies>
<CombatAI.Settings.Basic.FogOfWar.Animals>Colony animals reveal fog of war</CombatAI.Settings.Basic.FogOfWar.Animals>
<CombatAI.Settings.Basic.FogOfWar.Animals.SmartOnly>Only smart animals reveal fog of war</CombatAI.Settings.Basic.FogOfWar.Animals.SmartOnly>
Expand Down Expand Up @@ -64,6 +70,8 @@
<CombatAI.Settings.Debugging>Debugging</CombatAI.Settings.Debugging>
<CombatAI.Settings.Debugging.Enable>Enable Debugging</CombatAI.Settings.Debugging.Enable>
<CombatAI.Settings.Advance>Advance Settings</CombatAI.Settings.Advance>
<CombatAI.Settings.Advance.SquadPathWidth>Avoidance path width. Avoidance path width determine flanking aggressiveness.</CombatAI.Settings.Advance.SquadPathWidth>
<CombatAI.Settings.Advance.SquadPathWidth.Description>Path width {0} cells (default: 1)</CombatAI.Settings.Advance.SquadPathWidth.Description>
<CombatAI.Settings.Advance.Warning>WARNING: This is only for advanced users! Don't enable this if you don't know what you're doing!</CombatAI.Settings.Advance.Warning>
<CombatAI.Settings.Advance.Enable>I'm an advanced user!</CombatAI.Settings.Advance.Enable>
<CombatAI.Settings.Advance.Sight.Performance>Performance</CombatAI.Settings.Advance.Sight.Performance>
Expand All @@ -77,4 +85,13 @@
<CombatAI.Settings.Advance.Sight.Performance.Readouts.Interval>Ticks between bucket updates {0} Ticks</CombatAI.Settings.Advance.Sight.Performance.Readouts.Interval>
<CombatAI.Settings.Advance.Sight.Performance.Readouts.CarryLimit>{0} Things maximum can obstuct line of sight</CombatAI.Settings.Advance.Sight.Performance.Readouts.CarryLimit>
<CombatAI.Settings.Advance.Sight.Performance.Readouts.CarryLimit.Description>The maximum number of things along line of sight. This includes trees, buildings, etc. Higher values means more accurate sight model but higher performance impact.</CombatAI.Settings.Advance.Sight.Performance.Readouts.CarryLimit.Description>
<CombatAI.Settings.FactionTech>Faction Tech Level Settings</CombatAI.Settings.FactionTech>
<CombatAI.Settings.FactionTech.Desciption>Here you can configure factions with different tech levels.</CombatAI.Settings.FactionTech.Desciption>
<CombatAI.Settings.FactionTech.Tech>Tech {0}</CombatAI.Settings.FactionTech.Tech>
<CombatAI.Settings.FactionTech.Duck>Duck {0}x. Higher values means more likely to duck for cover</CombatAI.Settings.FactionTech.Duck>
<CombatAI.Settings.FactionTech.Retreat>Retreat {0}x. Higher values means more likely to retreat</CombatAI.Settings.FactionTech.Retreat>
<CombatAI.Settings.FactionTech.Cover>Cover {0}x. Higher values means more aggressive cover</CombatAI.Settings.FactionTech.Cover>
<CombatAI.Settings.FactionTech.Pathing>Pathing {0}x. Higher values means more aggressive pathing</CombatAI.Settings.FactionTech.Pathing>
<CombatAI.Settings.FactionTech.Sapping>Sapping {0}x. Higher values means less aggressive sapping</CombatAI.Settings.FactionTech.Sapping>
<CombatAI.Settings.FactionTech.Group>Charge {0}x. Higher values means groups are more likely to charge</CombatAI.Settings.FactionTech.Group>
</LanguageData>
1 change: 1 addition & 0 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<li>Ludeon.RimWorld.Royalty</li>
<li>brrainz.harmony</li>
<li>zetrith.prepatcher</li>
<li>owlchemist.simplefx.vapor</li>
<li>CETeam.CombatExtended</li>
</loadAfter>
<loadBefore>
Expand Down
10 changes: 9 additions & 1 deletion Source/Rule56/ArmorUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static ArmorReport GetArmorReport(this Pawn pawn, Listing_Collapsible col
{
return default(ArmorReport);
}
if (collapsible != null || !reports.TryGetValue(pawn.thingIDNumber, out ArmorReport report) || GenTicks.TicksGame - report.createdAt > 900)
if (collapsible != null || !reports.TryGetValue(pawn.thingIDNumber, out ArmorReport report) || GenTicks.TicksGame - report.createdAt > 7200)
{
reports[pawn.thingIDNumber] = report = CreateReport(pawn, collapsible);
}
Expand Down Expand Up @@ -179,5 +179,13 @@ public float Coverage(ApparelProperties apparel)
return coverage;
}
}

public static void Invalidate(Thing thing)
{
if (reports.ContainsKey(thing.thingIDNumber))
{
reports.Remove(thing.thingIDNumber);
}
}
}
}
32 changes: 26 additions & 6 deletions Source/Rule56/AsyncActions.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Verse;
namespace CombatAI
{
public class AsyncActions
{

private static readonly List<AsyncActions> running = new List<AsyncActions>();

private readonly int hashOffset;

public readonly object locker_Main = new object();
public readonly object locker_offMain = new object();
private readonly int mainLoopTickInterval;

private readonly List<Action> queuedMainThreadActions = new List<Action>();
private readonly List<Action> queuedOffThreadActions = new List<Action>();
private readonly Thread thread;
private bool mainThreadActionQueueEmpty;
private readonly List<Action> queuedMainThreadActions = new List<Action>();
private readonly List<Action> queuedOffThreadActions = new List<Action>();
private readonly AutoResetEvent waitHandle = new AutoResetEvent(false);
private readonly Thread thread;
private bool mainThreadActionQueueEmpty;

public AsyncActions(int mainLoopTickInterval = 5)
{
Expand All @@ -34,6 +37,7 @@ public bool Alive
public void Start()
{
thread.Start();
running.Add(this);
}

public void ExecuteMainThreadActions()
Expand All @@ -44,6 +48,7 @@ public void ExecuteMainThreadActions()
public void Kill()
{
Alive = false;
running.Remove(this);
try
{
lock (locker_Main)
Expand All @@ -55,12 +60,22 @@ public void Kill()
queuedOffThreadActions.Clear();
}
thread.Abort();
thread.Join(100);
waitHandle.Close();
}
catch (Exception)
{
}
}

public static void KillAll()
{
foreach (AsyncActions asyncActions in running.ToList())
{
asyncActions.Kill();
}
}

public void EnqueueOffThreadAction(Action action)
{
lock (locker_offMain)
Expand All @@ -72,6 +87,7 @@ public void EnqueueOffThreadAction(Action action)
else
{
queuedOffThreadActions.Add(action);
waitHandle.Set();
}
}
}
Expand Down Expand Up @@ -151,14 +167,18 @@ private void OffMainThreadActionLoop()
{
action();
}
catch (ThreadAbortException)
{
throw;
}
catch (Exception er)
{
Log.Error(er.ToString());
}
}
else
{
Thread.Sleep(1);
waitHandle.WaitOne();
}
}
}
Expand Down
Loading

0 comments on commit db1b36d

Please sign in to comment.