Skip to content

Commit

Permalink
Fix: Soft Crash when A Dyson Swarm Controller is destroyed.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkapulis committed Oct 12, 2024
1 parent 61a4138 commit c042b30
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Ship_Game/Universe/SolarBodies/DysonSwarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,21 @@ void AddControllerPositions(int numPerRing, int distance)
public void Update() // Once per turn or when a new Dyson Swarm Sat is deployed
{
int count = 0;
List<Vector2> keysToUpdate = new List<Vector2>();
foreach (KeyValuePair<Vector2, Ship> item in SwarmControllers)
{
Ship swarmController = item.Value;
if (swarmController != null)
{
if (!swarmController.Active) SwarmControllers[item.Key] = null;
if (!swarmController.Active) keysToUpdate.Add(item.Key);
else if (swarmController.Loyalty != Owner) swarmController.AI.OrderScuttleShip();
else count++;
}
}

for (int i = 0; i < keysToUpdate.Count; i++)
SwarmControllers[keysToUpdate[i]] = null;

UpdateMaxOverclock();
ControllerCompletion = count / (float)TotalSwarmControllers;
int desiredOverclock = OverclockEnabled ? MaxOverclock : 0;
Expand Down

0 comments on commit c042b30

Please sign in to comment.