Skip to content

Commit

Permalink
Merge pull request #22 from kbatbouta/development-settings
Browse files Browse the repository at this point in the history
Added new settings for fog of war, sprinting and groups.
  • Loading branch information
kbatbouta authored Feb 1, 2023
2 parents 513dc1e + 0e26082 commit 6fd4bc5
Show file tree
Hide file tree
Showing 14 changed files with 446 additions and 42 deletions.
Binary file modified 1.4/Assemblies/CombatAI.dll
Binary file not shown.
10 changes: 10 additions & 0 deletions 1.4/Languages/English/Keyed/Translations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@
<CombatAI.Settings.Basic.Presets.Deathwish>Deathwish</CombatAI.Settings.Basic.Presets.Deathwish>
<CombatAI.Settings.Basic.Presets.Applied>Applied preset:</CombatAI.Settings.Basic.Presets.Applied>
<CombatAI.Settings.Basic.Presets.Description>Performance presets will determine the complexity of AI calculations and their interval. More complex calculations means harder AI but lower performance. Default is normal.</CombatAI.Settings.Basic.Presets.Description>
<CombatAI.Settings.Basic.Sprinting>Enable sprinting</CombatAI.Settings.Basic.Sprinting>
<CombatAI.Settings.Basic.Sprinting.Description>If this is disabled: Pathetic F F...\n if not: Chad :thumbsup</CombatAI.Settings.Basic.Sprinting.Description>
<CombatAI.Settings.Basic.Groups>Enable tactical groups</CombatAI.Settings.Basic.Groups>
<CombatAI.Settings.Basic.Groups.Description>Raiders will be divided into tactical groups (2-10) each with their own objective. Not all pawns will be assigned to groups, some will remain on the default assault duty.</CombatAI.Settings.Basic.Groups.Description>
<CombatAI.Settings.Basic.SappingMul>Cost multiplier for pathing through walls (default is 1.0)</CombatAI.Settings.Basic.SappingMul>
<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.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>
<CombatAI.Settings.Basic.FogOfWar.Turrets>Colony turrets reveal fog of war</CombatAI.Settings.Basic.FogOfWar.Turrets>
<CombatAI.Settings.Basic.FogOfWar.Density>Fog density (how dark the fog of war is)</CombatAI.Settings.Basic.FogOfWar.Density>
<CombatAI.Settings.Basic.FogOfWar.Density.Readouts>{0} Fog desnity</CombatAI.Settings.Basic.FogOfWar.Density.Readouts>
<CombatAI.Settings.Basic.FogOfWar.RangeMul>Fog of war sight radius multiplie (default is 1.0)</CombatAI.Settings.Basic.FogOfWar.RangeMul>
Expand Down
1 change: 0 additions & 1 deletion Source/Rule56/CellFlooder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public void Flood(IntVec3 center, Action<Node> action, Func<IntVec3, float> cost
}
}
}
// }
}
}

Expand Down
215 changes: 215 additions & 0 deletions Source/Rule56/Collections/Tuple.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
using System;
using System.Runtime.CompilerServices;
using System.Security.Policy;

namespace CombatAI
{
public struct Tuple<A1, A2> : IEquatable<Tuple<A1, A2>>
{
public A1 val1;
public A2 val2;

public Tuple(A1 val1, A2 val2)
{
this.val1 = val1;
this.val2 = val2;
}

public Tuple(Tuple<A1, A2> other)
{
this.val1 = other.val1;
this.val2 = other.val2;
}

public override bool Equals(object obj)
{
return obj is Tuple<A1, A2> other && this.Equals(other);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Tuple<A1, A2> other)
{
return val1.Equals(other.val1) && val2.Equals(other.val2);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
{
int hash = 36469;
unchecked
{
hash = hash * 17 + val1.GetHashCode();
hash = hash * 17 + val2.GetHashCode();
}
return hash;
}

public override string ToString()
{
return $"({this.val1.ToString()}, {this.val2.ToString()})";
}
}

public struct Tuple<A1, A2, A3> : IEquatable<Tuple<A1, A2, A3>>
{
public A1 val1;
public A2 val2;
public A3 val3;

public Tuple(A1 val1, A2 val2, A3 val3)
{
this.val1 = val1;
this.val2 = val2;
this.val3 = val3;
}

public Tuple(Tuple<A1, A2, A3> other)
{
this.val1 = other.val1;
this.val2 = other.val2;
this.val3 = other.val3;
}

public override bool Equals(object obj)
{
return obj is Tuple<A1, A2, A3> other && this.Equals(other);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Tuple<A1, A2, A3> other)
{
return val1.Equals(other.val1) && val2.Equals(other.val2) && val3.Equals(other.val3);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
{
int hash = 36469;
unchecked
{
hash = hash * 17 + val1.GetHashCode();
hash = hash * 17 + val2.GetHashCode();
hash = hash * 17 + val3.GetHashCode();
}
return hash;
}

public override string ToString()
{
return $"({this.val1.ToString()}, {this.val2.ToString()}, {this.val3.ToString()})";
}
}

public struct Tuple<A1, A2, A3, A4> : IEquatable<Tuple<A1, A2, A3, A4>>
{
public A1 val1;
public A2 val2;
public A3 val3;
public A4 val4;

public Tuple(A1 val1, A2 val2, A3 val3, A4 val4)
{
this.val1 = val1;
this.val2 = val2;
this.val3 = val3;
this.val4 = val4;
}

public Tuple(Tuple<A1, A2, A3, A4> other)
{
this.val1 = other.val1;
this.val2 = other.val2;
this.val3 = other.val3;
this.val4 = other.val4;
}

public override bool Equals(object obj)
{
return obj is Tuple<A1, A2, A3, A4> other && this.Equals(other);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Tuple<A1, A2, A3, A4> other)
{
return val1.Equals(other.val1) && val2.Equals(other.val2) && val3.Equals(other.val3) && val4.Equals(other.val4);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
{
int hash = 36469;
unchecked
{
hash = hash * 17 + val1.GetHashCode();
hash = hash * 17 + val2.GetHashCode();
hash = hash * 17 + val3.GetHashCode();
hash = hash * 17 + val4.GetHashCode();
}
return hash;
}

public override string ToString()
{
return $"({this.val1.ToString()}, {this.val2.ToString()}, {this.val3.ToString()}, {this.val4.ToString()})";
}
}

public struct Tuple<A1, A2, A3, A4, A5> : IEquatable<Tuple<A1, A2, A3, A4, A5>>
{
public A1 val1;
public A2 val2;
public A3 val3;
public A4 val4;
public A5 val5;

public Tuple(A1 val1, A2 val2, A3 val3, A4 val4, A5 val5)
{
this.val1 = val1;
this.val2 = val2;
this.val3 = val3;
this.val4 = val4;
this.val5 = val5;
}

public Tuple(Tuple<A1, A2, A3, A4, A5> other)
{
this.val1 = other.val1;
this.val2 = other.val2;
this.val3 = other.val3;
this.val4 = other.val4;
this.val5 = other.val5;
}

public override bool Equals(object obj)
{
return obj is Tuple<A1, A2, A3, A4, A5> other && this.Equals(other);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Tuple<A1, A2, A3, A4, A5> other)
{
return val1.Equals(other.val1) && val2.Equals(other.val2) && val3.Equals(other.val3) && val4.Equals(other.val4) && val5.Equals(other.val5);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
{
int hash = 36469;
unchecked
{
hash = hash * 17 + val1.GetHashCode();
hash = hash * 17 + val2.GetHashCode();
hash = hash * 17 + val3.GetHashCode();
hash = hash * 17 + val4.GetHashCode();
hash = hash * 17 + val5.GetHashCode();
}
return hash;
}

public override string ToString()
{
return $"({this.val1.ToString()}, {this.val2.ToString()}, {this.val3.ToString()}, {this.val4.ToString()}, {this.val5.ToString()})";
}
}
}

43 changes: 42 additions & 1 deletion Source/Rule56/CombatAIMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ private void FillCollapsible_Basic(Listing_Collapsible collapsible)
Finder.Settings.React_Enabled = false;
Finder.Settings.Retreat_Enabled = false;
Finder.Settings.Flank_Enabled = false;

Finder.Settings.Enable_Sprinting = false;
Finder.Settings.Enable_Groups = false;
Finder.Settings.Pathfinding_SappingMul = 0.5f;

Finder.Settings.SightSettings_FriendliesAndRaiders.interval = 3;
if (Current.ProgramState != ProgramState.Playing)
{
Expand Down Expand Up @@ -128,6 +133,11 @@ private void FillCollapsible_Basic(Listing_Collapsible collapsible)
Finder.Settings.React_Enabled = true;
Finder.Settings.Retreat_Enabled = false;
Finder.Settings.Flank_Enabled = true;

Finder.Settings.Enable_Sprinting = false;
Finder.Settings.Enable_Groups = true;
Finder.Settings.Pathfinding_SappingMul = 1.0f;

Finder.Settings.SightSettings_FriendliesAndRaiders.interval = 3;
if (Current.ProgramState != ProgramState.Playing)
{
Expand Down Expand Up @@ -159,6 +169,11 @@ private void FillCollapsible_Basic(Listing_Collapsible collapsible)
Finder.Settings.Retreat_Enabled = true;
Finder.Settings.Flank_Enabled = true;
Finder.Settings.PerformanceOpt_Enabled = true;

Finder.Settings.Enable_Sprinting = false;
Finder.Settings.Enable_Groups = true;
Finder.Settings.Pathfinding_SappingMul = 0.9f;

Finder.Settings.SightSettings_FriendliesAndRaiders.interval = 2;
if (Current.ProgramState != ProgramState.Playing)
{
Expand Down Expand Up @@ -191,6 +206,11 @@ private void FillCollapsible_Basic(Listing_Collapsible collapsible)
Finder.Settings.Retreat_Enabled = true;
Finder.Settings.Flank_Enabled = true;
Finder.Settings.PerformanceOpt_Enabled = false;

Finder.Settings.Enable_Sprinting = true;
Finder.Settings.Enable_Groups = true;
Finder.Settings.Pathfinding_SappingMul = 0.85f;

Finder.Settings.SightSettings_FriendliesAndRaiders.interval = 1;
if (Current.ProgramState != ProgramState.Playing)
{
Expand Down Expand Up @@ -225,15 +245,26 @@ private void FillCollapsible_Basic(Listing_Collapsible collapsible)
collapsible.CheckboxLabeled(Keyed.CombatAI_Settings_Basic_Reaction, ref Finder.Settings.React_Enabled);
collapsible.CheckboxLabeled(Keyed.CombatAI_Settings_Basic_Flanking, ref Finder.Settings.Flank_Enabled);
collapsible.CheckboxLabeled(Keyed.CombatAI_Settings_Basic_Retreat, ref Finder.Settings.Retreat_Enabled);
collapsible.CheckboxLabeled(Keyed.CombatAI_Settings_Basic_Groups, ref Finder.Settings.Enable_Groups, tooltip: Keyed.CombatAI_Settings_Basic_Groups_Description);
collapsible.CheckboxLabeled(Keyed.CombatAI_Settings_Basic_Sprinting, ref Finder.Settings.Enable_Sprinting, tooltip: Keyed.CombatAI_Settings_Basic_Sprinting_Description);
}

private void FillCollapsible_FogOfWar(Listing_Collapsible collapsible)
{
collapsible.CheckboxLabeled(Keyed.CombatAI_Settings_Basic_FogOfWar_Enable, ref Finder.Settings.FogOfWar_Enabled);
collapsible.CheckboxLabeled(Keyed.CombatAI_Settings_Basic_FogOfWar_Enable, ref Finder.Settings.FogOfWar_Enabled);

if (Finder.Settings.FogOfWar_Enabled)
{
collapsible.Line(1);

collapsible.CheckboxLabeled(Keyed.CombatAI_Settings_Basic_FogOfWar_Animals, ref Finder.Settings.FogOfWar_Animals);
collapsible.CheckboxLabeled(Keyed.CombatAI_Settings_Basic_FogOfWar_Animals_SmartOnly, ref Finder.Settings.FogOfWar_AnimalsSmartOnly, disabled: !Finder.Settings.FogOfWar_Animals);
collapsible.Line(1);
collapsible.CheckboxLabeled(Keyed.CombatAI_Settings_Basic_FogOfWar_Allies, ref Finder.Settings.FogOfWar_Allies);
collapsible.CheckboxLabeled(Keyed.CombatAI_Settings_Basic_FogOfWar_Turrets, ref Finder.Settings.FogOfWar_Turrets);

collapsible.Line(1);

collapsible.Label(Keyed.CombatAI_Settings_Basic_FogOfWar_Density);
collapsible.Lambda(25, rect =>
{
Expand Down Expand Up @@ -387,6 +418,16 @@ private void FillCollapsible_Advance(Listing_Collapsible collapsible)
collapsible.Label(Keyed.CombatAI_Settings_Advance_Warning);
collapsible.Line(1);
collapsible.CheckboxLabeled(Keyed.CombatAI_Settings_Advance_Enable, ref Finder.Settings.AdvancedUser);
if (Finder.Settings.AdvancedUser)
{
collapsible.Line(1);
collapsible.Label(Keyed.CombatAI_Settings_Basic_SappingMul_Description);
collapsible.Lambda(25, rect =>
{
Widgets.HorizontalSlider(rect, ref Finder.Settings.Pathfinding_SappingMul, new FloatRange(0.5f, 1.5f), Keyed.CombatAI_Settings_Basic_SappingMul);
}, useMargins: true);
}
//collapsible.Line(1);
//if (Finder.Settings.AdvancedUser)
//{
// collapsible.Lambda(25, (rect) =>
Expand Down
21 changes: 7 additions & 14 deletions Source/Rule56/CombatAI_Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public static IntVec3 TryGetNextDutyDest(this Pawn pawn, float maxDistFromPawn =
{
return IntVec3.Invalid;
}
DutyDestCache key = new DutyDestCache()
Tuple<int, int, IntVec3> key = new Tuple<int, int, IntVec3>()
{
pawnId = pawn.thingIDNumber,
dutyDefId = pawn.mindState.duty.def.index,
dutyDest = pawn.mindState.duty.focus.Cell
val1 = pawn.thingIDNumber,
val2 = pawn.mindState.duty.def.index,
val3 = pawn.mindState.duty.focus.Cell
};
if (!TKVCache<DutyDestCache, PawnDuty, IntVec3>.TryGet(key, out IntVec3 dutyDest, 600))
if (!TKVCache<Tuple<int, int, IntVec3>, PawnDuty, IntVec3>.TryGet(key, out IntVec3 dutyDest, 600))
{
dutyDest = IntVec3.Invalid;
if (pawn.mindState.duty.focus.Cell.DistanceToSquared(pawn.Position) > Maths.Sqr(Maths.Max(pawn.mindState.duty.radius, 10)))
Expand All @@ -51,14 +51,14 @@ public static IntVec3 TryGetNextDutyDest(this Pawn pawn, float maxDistFromPawn =
float maxDistSqr = Maths.Sqr(maxDistFromPawn);
IntVec3 pawnPos = pawn.Position;
while (i >= 0 && path.nodes[i].DistanceToSquared(pawnPos) < maxDistSqr)
{
{
i--;
}
dutyDest = path.nodes[Maths.Max(i, 0)];
path.ReleaseToPool();
}
}
TKVCache<DutyDestCache, PawnDuty, IntVec3>.Put(key, dutyDest);
TKVCache<Tuple<int, int, IntVec3>, PawnDuty, IntVec3>.Put(key, dutyDest);
}
return dutyDest;
}
Expand Down Expand Up @@ -119,12 +119,5 @@ public static int GetThingFlagsIndex(this Thing thing)
{
return thing.thingIDNumber % 64;
}

private struct DutyDestCache
{
public int pawnId;
public int dutyDefId;
public IntVec3 dutyDest;
}
}
}
Loading

0 comments on commit 6fd4bc5

Please sign in to comment.