Skip to content

Commit

Permalink
New media and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kbatbouta committed Feb 28, 2023
1 parent e2f427d commit e342a81
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 30 deletions.
Binary file modified 1.4/Assemblies/CombatAI.dll
Binary file not shown.
Binary file added Media/fog1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Media/fog2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 4 additions & 7 deletions Source/Rule56/ITRegionGridPrepatched.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace CombatAI
public class ITRegionGridPrepatched : ITRegionGrid
{
private readonly int gridId;
private ISRegion[] cells;
private readonly ISRegion[] cells;

public ITRegionGridPrepatched(Map map) : base(map)
public ITRegionGridPrepatched(Map map, int id) : base(map)
{
cells = new ISRegion[NumGridCells];
gridId = ITRegionGridPrepatchedHelper.CombatAI_ReginGridCounter(map);
ITRegionGridPrepatchedHelper.CombatAI_ReginGridCounter(map) = gridId + 1;
gridId = id;
Log.Message($"gridId:{id}");
}
public override void Set(int index)
{
Expand Down Expand Up @@ -115,9 +115,6 @@ public sealed class IRegionFields

public static class ITRegionGridPrepatchedHelper
{
[PrepatcherField]
public static extern ref int CombatAI_ReginGridCounter(Map map);

[PrepatcherField]
[ValueInitializer(nameof(InitRegionFields))]
public static extern ref ITRegionGridPrepatched.IRegionFields CombatAI_RegionFields(Region region);
Expand Down
2 changes: 2 additions & 0 deletions Source/Rule56/Maths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public static byte Sqr(byte a)
return (byte)(a * a);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Sqrt_Fast(float x, int iterations)
{
if (x < 0.001f)
Expand Down Expand Up @@ -210,6 +211,7 @@ public static float Sqrt_Fast(float x, int iterations)
}
return (bot + top) / 64f;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Sqrt_Fast(int a, int iterations)
{
if (a == 0)
Expand Down
46 changes: 27 additions & 19 deletions Source/Rule56/SightGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,23 @@ public class SightGrid
/// Whether this is the player grid
/// </summary>
public bool trackFactions = false;
private bool wait;
/// <summary>
/// SightGrid Id.
/// </summary>
public readonly int gridId;
private bool wait;

public SightGrid(SightTracker sightTracker, Settings.SightPerformanceSettings settings)
public SightGrid(SightTracker sightTracker, Settings.SightPerformanceSettings settings, int gridId)
{
this.sightTracker = sightTracker;
map = sightTracker.map;
this.settings = settings;
grid = new ITSignalGrid(map);
this.gridId = gridId;
this.sightTracker = sightTracker;
map = sightTracker.map;
this.settings = settings;
grid = new ITSignalGrid(map);
if (!Extern.active)
grid_regions = new ITRegionGridLegacy(map);
else
grid_regions = new ITRegionGridPrepatched(map);
grid_regions = new ITRegionGridPrepatched(map, gridId);
asyncActions = new AsyncActions(1);
ticksUntilUpdate = Rand.Int % this.settings.interval;
buckets = new IBuckets<IBucketableThing>(settings.buckets);
Expand Down Expand Up @@ -140,18 +145,21 @@ public virtual void SightGridUpdate(bool gamePaused, bool performanceOkay)
{
if (gamePaused || performanceOkay)
{
int limit = gamePaused ? 32 : 8;
int numGridCells = map.cellIndices.NumGridCells;
for (int i = 0; i < limit; i++)
{
Region region = map.regionGrid.regionGrid[regionUpdateIndex];
grid_regions.SetRegionAt(regionUpdateIndex, (region?.valid ?? false) ? region : null);
regionUpdateIndex++;
if (regionUpdateIndex >= numGridCells)
{
regionUpdateIndex = 0;
}
}
// int limit = gamePaused ? 32 : 8;
// int numGridCells = map.cellIndices.NumGridCells;
// for (int i = 0; i < limit; i++)
// {
// Region region = map.regionGrid.regionGrid[regionUpdateIndex];
// if (region?.valid ?? false)
// {
// grid_regions.SetRegionAt(regionUpdateIndex, region);
// regionUpdateIndex++;
// if (regionUpdateIndex >= numGridCells)
// {
// regionUpdateIndex = 0;
// }
// }
// }
}
}

Expand Down
8 changes: 4 additions & 4 deletions Source/Rule56/SightTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ public SightTracker(Map map) : base(map)
{
fogGrid = new ITFloatGrid(map);
colonistsAndFriendlies =
new SightGrid(this, Finder.Settings.SightSettings_FriendliesAndRaiders);
new SightGrid(this, Finder.Settings.SightSettings_FriendliesAndRaiders, 0);
colonistsAndFriendlies.gridFog = fogGrid;
colonistsAndFriendlies.playerAlliance = true;
colonistsAndFriendlies.trackFactions = true;

raidersAndHostiles =
new SightGrid(this, Finder.Settings.SightSettings_FriendliesAndRaiders);
new SightGrid(this, Finder.Settings.SightSettings_FriendliesAndRaiders, 1);
raidersAndHostiles.trackFactions = true;

insectsAndMechs =
new SightGrid(this, Finder.Settings.SightSettings_MechsAndInsects);
new SightGrid(this, Finder.Settings.SightSettings_MechsAndInsects, 2);
insectsAndMechs.trackFactions = false;

wildlife =
new SightGrid(this, Finder.Settings.SightSettings_Wildlife);
new SightGrid(this, Finder.Settings.SightSettings_Wildlife, 3);
wildlife.trackFactions = false;

factionedUInt64Map = new IThingsUInt64Map();
Expand Down

0 comments on commit e342a81

Please sign in to comment.