예제 #1
0
        internal static void Tick(bool useFullSet, bool checkForSystemChange)
        {
            Globals.WarStatusTracker.PrioritySystems.Clear();
            var systemSubsetSize = Globals.WarStatusTracker.systems.Count;
            List <SystemStatus> systemStatuses;

            if (Globals.Settings.UseSubsetOfSystems && !useFullSet)
            {
                systemSubsetSize = (int)(systemSubsetSize * Globals.Settings.SubSetFraction);
                systemStatuses   = Globals.WarStatusTracker.systems
                                   .OrderBy(x => Guid.NewGuid()).Take(systemSubsetSize)
                                   .ToList();
            }
            else
            {
                systemStatuses = Globals.WarStatusTracker.systems;
            }

            if (checkForSystemChange && Globals.Settings.GaW_PoliceSupport)
            {
                CalculateComstarSupport();
            }

            if (Globals.WarStatusTracker.FirstTickInitialization)
            {
                var lowestAR = 5000f;
                var lowestDr = 5000f;
                var sequence = Globals.WarStatusTracker.warFactionTracker.Where(x =>
                                                                                Globals.IncludedFactions.Contains(x.faction)).ToList();
                foreach (var faction in sequence)
                {
                    var systemCount = Globals.WarStatusTracker.systems.Count(x => x.owner == faction.faction);
                    if (!Globals.Settings.ISMCompatibility && systemCount != 0)
                    {
                        faction.AR_PerPlanet = (float)Globals.Settings.BonusAttackResources[faction.faction] / systemCount;
                        faction.DR_PerPlanet = (float)Globals.Settings.BonusDefensiveResources[faction.faction] / systemCount;
                        if (faction.AR_PerPlanet < lowestAR)
                        {
                            lowestAR = faction.AR_PerPlanet;
                        }
                        if (faction.DR_PerPlanet < lowestDr)
                        {
                            lowestDr = faction.DR_PerPlanet;
                        }
                    }
                    else if (systemCount != 0)
                    {
                        faction.AR_PerPlanet = (float)Globals.Settings.BonusAttackResources_ISM[faction.faction] / systemCount;
                        faction.DR_PerPlanet = (float)Globals.Settings.BonusDefensiveResources_ISM[faction.faction] / systemCount;
                        if (faction.AR_PerPlanet < lowestAR)
                        {
                            lowestAR = faction.AR_PerPlanet;
                        }
                        if (faction.DR_PerPlanet < lowestDr)
                        {
                            lowestDr = faction.DR_PerPlanet;
                        }
                    }
                }

                foreach (var faction in sequence)
                {
                    faction.AR_PerPlanet = Mathf.Min(faction.AR_PerPlanet, 2 * lowestAR);
                    faction.DR_PerPlanet = Mathf.Min(faction.DR_PerPlanet, 2 * lowestDr);
                }

                foreach (var systemStatus in systemStatuses)
                {
                    //Spread out bonus resources and make them fair game for the taking.
                    var warFaction = Globals.WarStatusTracker.warFactionTracker.Find(x => x.faction == systemStatus.owner);
                    systemStatus.AttackResources  += warFaction.AR_PerPlanet;
                    systemStatus.TotalResources   += warFaction.AR_PerPlanet;
                    systemStatus.DefenseResources += warFaction.DR_PerPlanet;
                    systemStatus.TotalResources   += warFaction.DR_PerPlanet;
                }
            }

            //Distribute Pirate Influence throughout the StarSystems
            LogDebug("Processing pirates.");
            PiratesAndLocals.CorrectResources();
            PiratesAndLocals.PiratesStealResources();
            PiratesAndLocals.CurrentPAResources = Globals.WarStatusTracker.PirateResources;
            PiratesAndLocals.DistributePirateResources();
            PiratesAndLocals.DefendAgainstPirates();

            if (checkForSystemChange && Globals.Settings.HyadesRimCompatible && Globals.WarStatusTracker.InactiveTHRFactions.Count != 0 &&
                Globals.WarStatusTracker.HyadesRimGeneralPirateSystems.Count != 0)
            {
                var rand = Globals.Rng.Next(0, 100);
                if (rand < Globals.WarStatusTracker.HyadesRimsSystemsTaken)
                {
                    var hyadesSystem    = Globals.WarStatusTracker.HyadesRimGeneralPirateSystems.GetRandomElement();
                    var flipSystem      = Globals.WarStatusTracker.systems.Find(x => x.name == hyadesSystem).starSystem;
                    var inactiveFaction = Globals.WarStatusTracker.InactiveTHRFactions.GetRandomElement();
                    ChangeSystemOwnership(flipSystem, inactiveFaction, true);
                    Globals.WarStatusTracker.InactiveTHRFactions.Remove(inactiveFaction);
                    Globals.WarStatusTracker.HyadesRimGeneralPirateSystems.Remove(hyadesSystem);
                }
            }

            LogDebug("Processing systems' influence.");
            foreach (var systemStatus in systemStatuses)
            {
                systemStatus.PriorityAttack  = false;
                systemStatus.PriorityDefense = false;
                if (Globals.WarStatusTracker.FirstTickInitialization)
                {
                    systemStatus.CurrentlyAttackedBy.Clear();
                    CalculateAttackAndDefenseTargets(systemStatus.starSystem);
                    RefreshContractsEmployersAndTargets(systemStatus);
                }

                if (systemStatus.Contended || Globals.WarStatusTracker.HotBox.Contains(systemStatus.name))
                {
                    continue;
                }

                if (!systemStatus.owner.Equals("Locals") && systemStatus.influenceTracker.Keys.Contains("Locals") &&
                    !Globals.WarStatusTracker.FlashpointSystems.Contains(systemStatus.name))
                {
                    systemStatus.influenceTracker["Locals"] *= 1.1f;
                }

                //Add resources from neighboring systems.
                if (systemStatus.neighborSystems.Count != 0)
                {
                    foreach (var neighbor in systemStatus.neighborSystems.Keys)
                    {
                        if (!Globals.Settings.ImmuneToWar.Contains(neighbor) && !Globals.Settings.DefensiveFactions.Contains(neighbor) &&
                            !Globals.WarStatusTracker.FlashpointSystems.Contains(systemStatus.name))
                        {
                            var pushFactor = Globals.Settings.APRPush * Globals.Rng.Next(1, Globals.Settings.APRPushRandomizer + 1);
                            systemStatus.influenceTracker[neighbor] += systemStatus.neighborSystems[neighbor] * pushFactor;
                        }
                    }
                }

                //Revolt on previously taken systems.
                if (systemStatus.owner != systemStatus.OriginalOwner)
                {
                    systemStatus.influenceTracker[systemStatus.OriginalOwner] *= 0.10f;
                }

                var pirateSystemFlagValue = Globals.Settings.PirateSystemFlagValue;

                if (Globals.Settings.ISMCompatibility)
                {
                    pirateSystemFlagValue = Globals.Settings.PirateSystemFlagValue_ISM;
                }

                var totalPirates = systemStatus.PirateActivity * systemStatus.TotalResources / 100;

                if (totalPirates >= pirateSystemFlagValue)
                {
                    if (!Globals.WarStatusTracker.PirateHighlight.Contains(systemStatus.name))
                    {
                        Globals.WarStatusTracker.PirateHighlight.Add(systemStatus.name);
                    }
                }
                else
                {
                    if (Globals.WarStatusTracker.PirateHighlight.Contains(systemStatus.name))
                    {
                        Globals.WarStatusTracker.PirateHighlight.Remove(systemStatus.name);
                    }
                }
            }

            Globals.WarStatusTracker.FirstTickInitialization = false;
            LogDebug("Processing resource spending.");
            foreach (var warFaction in Globals.WarStatusTracker.warFactionTracker)
            {
                DivideAttackResources(warFaction, useFullSet);
            }

            CalculateDefensiveSystems();
            foreach (var warFaction in Globals.WarStatusTracker.warFactionTracker)
            {
                AllocateDefensiveResources(warFaction, useFullSet);
                AllocateAttackResources(warFaction);
            }

            LogDebug("Processing influence changes.");
            UpdateInfluenceFromAttacks(checkForSystemChange);

            //Increase War Escalation or decay defenses.
            foreach (var warFaction in Globals.WarStatusTracker.warFactionTracker)
            {
                if (!warFaction.GainedSystem)
                {
                    warFaction.DaysSinceSystemAttacked += 1;
                }
                else
                {
                    warFaction.DaysSinceSystemAttacked = 0;
                    warFaction.GainedSystem            = false;
                }

                if (!warFaction.LostSystem)
                {
                    warFaction.DaysSinceSystemLost += 1;
                }
                else
                {
                    warFaction.DaysSinceSystemLost = 0;
                    warFaction.LostSystem          = false;
                }
            }

            LogDebug("Processing flipped systems.");
            foreach (var system in Globals.WarStatusTracker.systems.Where(x => Globals.WarStatusTracker.SystemChangedOwners.Contains(x.name)))
            {
                system.CurrentlyAttackedBy.Clear();
                CalculateAttackAndDefenseTargets(system.starSystem);
                RefreshContractsEmployersAndTargets(system);
            }

            if (Globals.WarStatusTracker.SystemChangedOwners.Count > 0)
            {
                LogDebug($"Changed on {Globals.Sim.CurrentDate.ToShortDateString()}: {Globals.WarStatusTracker.SystemChangedOwners.Count} systems:");
                Globals.WarStatusTracker.SystemChangedOwners.OrderBy(x => x).Do(x =>
                                                                                LogDebug($"  {x}"));
                Globals.WarStatusTracker.SystemChangedOwners.Clear();
                if (StarmapMod.eventPanel != null)
                {
                    StarmapMod.UpdatePanelText();
                }
            }

            //Log("===================================================");
            //Log("TESTING ZONE");
            //Log("===================================================");
            //////TESTING ZONE
            //foreach (WarFaction WF in Globals.WarStatusTracker.warFactionTracker)
            //{
            //    Log("----------------------------------------------");
            //    Log(WF.faction.ToString());
            //    try
            //    {
            //        var DLT = Globals.WarStatusTracker.DeathListTrackers.Find(x => x.faction == WF.faction);
            //        //                Log("\tAttacked By :");
            //        //                foreach (Faction fac in DLT.AttackedBy)
            //        //                    Log("\t\t" + fac.ToString());
            //        //                Log("\tOwner :" + DLT.);
            //        //                Log("\tAttack Resources :" + WF.AttackResources.ToString());
            //        //                Log("\tDefensive Resources :" + WF.DefensiveResources.ToString());
            //        Log("\tDeath List:");
            //        foreach (var faction in DLT.deathList.Keys)
            //        {
            //            Log("\t\t" + faction.ToString() + ": " + DLT.deathList[faction]);
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        Error(e);
            //    }
            //}
        }
예제 #2
0
        internal static void Tick(bool useFullSet, bool checkForSystemChange)
        {
            Globals.WarStatusTracker.PrioritySystems.Clear();
            var systemSubsetSize = Globals.WarStatusTracker.systems.Count;
            List <SystemStatus> systemStatuses;

            if (Globals.Settings.UseSubsetOfSystems && !useFullSet)
            {
                systemSubsetSize = (int)(systemSubsetSize * Globals.Settings.SubSetFraction);
                systemStatuses   = Globals.WarStatusTracker.systems
                                   .OrderBy(x => Guid.NewGuid()).Take(systemSubsetSize)
                                   .ToList();
            }
            else
            {
                systemStatuses = Globals.WarStatusTracker.systems;
            }

            /*
             * if (checkForSystemChange && Globals.Settings.GaW_PoliceSupport)
             *  CalculateComstarSupport();
             *
             * if (Globals.WarStatusTracker.FirstTickInitialization)
             * {
             *  //AddBaseWarTickResourcesPerSystem();
             *
             *  var sequence = Globals.WarStatusTracker.warFactionTracker.Where(x =>
             *      Globals.IncludedFactions.Contains(x.faction)).ToList();
             *  foreach (var faction in sequence)
             *  {
             *      var systemCount = Globals.WarStatusTracker.systems.Count(x => x.owner == faction.faction);
             *      if (!Globals.Settings.ISMCompatibility && systemCount != 0)
             *      {
             *          faction.AR_PerPlanet = (float) Globals.Settings.BonusAttackResources[faction.faction] / systemCount;
             *          faction.DR_PerPlanet = (float) Globals.Settings.BonusDefensiveResources[faction.faction] / systemCount;
             *      }
             *      else if (systemCount != 0)
             *      {
             *          faction.AR_PerPlanet = (float) Globals.Settings.BonusAttackResources_ISM[faction.faction] / systemCount;
             *          faction.DR_PerPlanet = (float) Globals.Settings.BonusDefensiveResources_ISM[faction.faction] / systemCount;
             *      }
             *  }
             *  ///-------------
             *
             *  foreach (var faction in sequence)
             *  {
             *      faction.AR_PerPlanet = Mathf.Min(faction.AR_PerPlanet, 2 * lowestAR);
             *      faction.DR_PerPlanet = Mathf.Min(faction.DR_PerPlanet, 2 * lowestDr);
             *  }
             *
             *  foreach (var systemStatus in systemStatuses)
             *  {
             *      //Spread out bonus resources and make them fair game for the taking.
             *      var warFaction = Globals.WarStatusTracker.warFactionTracker.Find(x => x.faction == systemStatus.owner);
             *      systemStatus.AttackResources += warFaction.AR_PerPlanet + GetTotalAttackResources(systemStatus.starSystem);          //probably doesn't need to be += as it should be 0
             *      systemStatus.TotalResources += warFaction.AR_PerPlanet + GetTotalAttackResources(systemStatus.starSystem);           //may remove will leave in place for now
             *      systemStatus.DefenseResources += warFaction.DR_PerPlanet + GetTotalDefensiveResources(systemStatus.starSystem);      //probably doesn't need to be += as it should be 0
             *      systemStatus.TotalResources += warFaction.DR_PerPlanet + GetTotalDefensiveResources(systemStatus.starSystem);        //may remove will leave in place for now
             *  }
             * }
             */

            //Distribute Pirate Influence throughout the StarSystems
            LogDebug("Processing pirates.");

            /*
             * //PiratesAndLocals.CorrectResources();
             * //PiratesAndLocals.PiratesStealResources();
             * //PiratesAndLocals.CurrentPAResources = Globals.WarStatusTracker.PirateResources;
             * //PiratesAndLocals.DistributePirateResources();
             * //PiratesAndLocals.DefendAgainstPirates();
             *
             *
             * if (checkForSystemChange && Globals.Settings.HyadesRimCompatible && Globals.WarStatusTracker.InactiveTHRFactions.Count != 0
             *  && Globals.WarStatusTracker.HyadesRimGeneralPirateSystems.Count != 0)
             * {
             *  var rand = Globals.Rng.Next(0, 100);
             *  if (rand < Globals.WarStatusTracker.HyadesRimsSystemsTaken)
             *  {
             *      var hyadesSystem = Globals.WarStatusTracker.HyadesRimGeneralPirateSystems.GetRandomElement();
             *      var flipSystem = Globals.WarStatusTracker.systems.Find(x => x.name == hyadesSystem).starSystem;
             *      var inactiveFaction = Globals.WarStatusTracker.InactiveTHRFactions.GetRandomElement();
             *      ChangeSystemOwnership(flipSystem, inactiveFaction, true);
             *      Globals.WarStatusTracker.InactiveTHRFactions.Remove(inactiveFaction);
             *      Globals.WarStatusTracker.HyadesRimGeneralPirateSystems.Remove(hyadesSystem);
             *  }
             * }*/

            LogDebug("Processing systems' influence.");
            foreach (var systemStatus in systemStatuses)
            {
                systemStatus.PriorityAttack  = false;
                systemStatus.PriorityDefense = false;
                if (Globals.WarStatusTracker.FirstTickInitialization)
                {
                    systemStatus.CurrentlyAttackedBy.Clear();
                    CalculateAttackAndDefenseTargets(systemStatus.starSystem);
                    RefreshContractsEmployersAndTargets(systemStatus);
                }

                if (systemStatus.Contended || Globals.WarStatusTracker.HotBox.Contains(systemStatus.name))
                {
                    continue;
                }

                if (!systemStatus.owner.Equals("Locals") && systemStatus.influenceTracker.Keys.Contains("Locals") &&
                    !Globals.WarStatusTracker.FlashpointSystems.Contains(systemStatus.name))
                {
                    systemStatus.influenceTracker["Locals"] *= 1.1f;
                }

                //Add resources from neighboring systems.
                if (systemStatus.neighborSystems.Count != 0)
                {
                    foreach (var neighbor in systemStatus.neighborSystems.Keys)
                    {
                        if (!Globals.Settings.ImmuneToWar.Contains(neighbor) && !Globals.Settings.DefensiveFactions.Contains(neighbor) &&
                            !Globals.WarStatusTracker.FlashpointSystems.Contains(systemStatus.name))
                        {
                            if (neighbor == systemStatus.owner)
                            {
                                var pushFactor = Globals.Settings.APRPush * Globals.Rng.Next(1, Globals.Settings.APRPushRandomizer + 1);
                                systemStatus.influenceTracker[neighbor] += systemStatus.influenceTracker[neighbor] / 100 + pushFactor;
                            }
                            else
                            {
                                //int a = 0;
                                //int b = 0;
                                systemStatus.neighborSystems.TryGetValue(neighbor, out int a);
                                systemStatus.neighborSystems.TryGetValue(neighbor, out int b);
                                var diffeence = Math.Abs(a - b);
                            }
                        }
                    }
                }

                //Revolt on previously taken systems.
                if (systemStatus.owner != systemStatus.OriginalOwner)
                {
                    systemStatus.influenceTracker[systemStatus.OriginalOwner] *= 0.10f;
                }

                //TODO remember to return to this pirate code.

                /* var pirateSystemFlagValue = Globals.Settings.PirateSystemFlagValue;
                 *
                 * if (Globals.Settings.ISMCompatibility)
                 *  pirateSystemFlagValue = Globals.Settings.PirateSystemFlagValue_ISM;
                 *
                 * var totalPirates = systemStatus.PirateActivity;
                 *
                 * //var totalPirates = systemStatus.PirateActivity * systemStatus.TotalResources / 100;
                 *
                 * ValueLog("System Name: " + systemStatus.name + "\n" + "Current PA: " + systemStatus.PirateActivity+ "\n" + "current AR: " + systemStatus.AttackResources + "\n" + "CurrentDR: "
                 + systemStatus.DefenseResources + "\n" + "Current TotalResources: " + systemStatus.TotalResources + "\n" + "totalPirates: " + totalPirates + "\n");
                 + totalPirates = Helpers.Clamp(totalPirates, Globals.ResourceGenericMax);
                 + if (totalPirates >= pirateSystemFlagValue)
                 + {
                 +  if (!Globals.WarStatusTracker.PirateHighlight.Contains(systemStatus.name))
                 +      Globals.WarStatusTracker.PirateHighlight.Add(systemStatus.name);
                 + }
                 + else
                 + {
                 +  if (Globals.WarStatusTracker.PirateHighlight.Contains(systemStatus.name))
                 +      Globals.WarStatusTracker.PirateHighlight.Remove(systemStatus.name);
                 + }*/
            }

            //TODO remember to check the commented line of code under this.
            //Globals.WarStatusTracker.FirstTickInitialization = false;

            /*--------start-next------------
             * Intention is to make it so that each system will retain at least it's base min resources and only push out any resources that exceed that base value.
             * A system that is requesting resources, will pull the maximum available resource from faction systems withen range that are not in conflict with another system.
             * Instead of a global pool of resources that all faction systems pull from systems can only get reources from systems that are near them and the resources they generate
             * themselves if neccessary.
             * Any system that has excess resources and is not in conflict with another system will divide it's excess reources by the amount of faction systems within range and push those resources out
             */
            LogDebug("Processing resource spending.");

            foreach (SystemStatus system in Globals.WarStatusTracker.systems)
            {
                system.FindNeighbors();
                system.systemResources.hasDoneDistrobution = false;
                system.systemResources.AddBaseWarTickResourcesForSystem();
            }

            //Testing wether it is easier/better to let there be a single tick of resources
            //before starting distrobution (Tick 2)
            //TODO check DistrobuteResourcesToLocalFactionSystems for bugs. Cureently looks fine.
            //Have noticed that to bug check, Total resources should be wired up properly, or i just shouldn't use it for testing output till it is wired up.
            //Have a feeling systems with local faction stopped getting resources will run a few tests first before diving back in.
            //Want to make sure that it is working correctly before moving on otherwise the problems will pile up.
            if (!Globals.WarStatusTracker.FirstTickInitialization)
            {
                foreach (SystemStatus system in Globals.WarStatusTracker.systems)
                {
                    system.DistributeResources();
                }
            }
            else
            {
                Globals.WarStatusTracker.FirstTickInitialization = false;
            }
            //--end----new----block--------------------------------------------------------------------------------------------


            foreach (var warFaction in Globals.WarStatusTracker.warFactionTracker)
            {
                //TODO follow the method
                //DivideAttackResources(warFaction, useFullSet);
            }

            CalculateDefensiveSystems();
            foreach (var warFaction in Globals.WarStatusTracker.warFactionTracker)
            {
                //TODO follow the methods
                //AllocateDefensiveResources(warFaction, useFullSet);
                //AllocateAttackResources(warFaction);
            }

            LogDebug("Processing influence changes.");
            // TODO follow the method
            UpdateInfluenceFromAttacks(checkForSystemChange);

            //Increase War Escalation or decay defenses.
            foreach (var warFaction in Globals.WarStatusTracker.warFactionTracker)
            {
                if (!warFaction.GainedSystem)
                {
                    warFaction.DaysSinceSystemAttacked += 1;
                }
                else
                {
                    warFaction.DaysSinceSystemAttacked = 0;
                    warFaction.GainedSystem            = false;
                }

                if (!warFaction.LostSystem)
                {
                    warFaction.DaysSinceSystemLost += 1;
                }
                else
                {
                    warFaction.DaysSinceSystemLost = 0;
                    warFaction.LostSystem          = false;
                }
            }

            LogDebug("Processing flipped systems.");
            foreach (var system in Globals.WarStatusTracker.systems.Where(x => Globals.WarStatusTracker.SystemChangedOwners.Contains(x.name)))
            {
                system.CurrentlyAttackedBy.Clear();
                // TODO follow the method
                CalculateAttackAndDefenseTargets(system.starSystem);
                RefreshContractsEmployersAndTargets(system);
            }

            if (Globals.WarStatusTracker.SystemChangedOwners.Count > 0)
            {
                LogDebug($"Changed on {Globals.Sim.CurrentDate.ToShortDateString()}: {Globals.WarStatusTracker.SystemChangedOwners.Count} systems:");
                Globals.WarStatusTracker.SystemChangedOwners.OrderBy(x => x).Do(x =>
                                                                                LogDebug($"  {x}"));
                Globals.WarStatusTracker.SystemChangedOwners.Clear();
                if (StarmapMod.eventPanel != null)
                {
                    StarmapMod.UpdatePanelText();
                }
            }

            //Log("===================================================");
            //Log("TESTING ZONE");
            //Log("===================================================");
            //////TESTING ZONE
            //foreach (WarFaction WF in Globals.WarStatusTracker.warFactionTracker)
            //{
            //    Log("----------------------------------------------");
            //    Log(WF.faction.ToString());
            //    try
            //    {
            //        var DLT = Globals.WarStatusTracker.DeathListTrackers.Find(x => x.faction == WF.faction);
            //        //                Log("\tAttacked By :");
            //        //                foreach (Faction fac in DLT.AttackedBy)
            //        //                    Log("\t\t" + fac.ToString());
            //        //                Log("\tOwner :" + DLT.);
            //        //                Log("\tAttack Resources :" + WF.AttackResources.ToString());
            //        //                Log("\tDefensive Resources :" + WF.DefensiveResources.ToString());
            //        Log("\tDeath List:");
            //        foreach (var faction in DLT.deathList.Keys)
            //        {
            //            Log("\t\t" + faction.ToString() + ": " + DLT.deathList[faction]);
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        Error(e);
            //    }
            //}
        }
예제 #3
0
        internal static void Tick(bool useFullSet, bool checkForSystemChange)
        {
            Globals.WarStatusTracker.PrioritySystems.Clear();
            var systemSubsetSize = Globals.WarStatusTracker.Systems.Count;
            List <SystemStatus> systemStatuses;

            if (Globals.Settings.UseSubsetOfSystems && !useFullSet)
            {
                systemSubsetSize = (int)(systemSubsetSize * Globals.Settings.SubSetFraction);
                systemStatuses   = Globals.WarStatusTracker.Systems
                                   .OrderBy(x => Guid.NewGuid()).Take(systemSubsetSize)
                                   .ToList();
            }
            else
            {
                systemStatuses = Globals.WarStatusTracker.Systems;
            }

            if (checkForSystemChange && Globals.Settings.GaW_PoliceSupport)
            {
                CalculateComstarSupport();
            }

            if (Globals.WarStatusTracker.FirstTickInitialization)
            {
                var perPlanetAR = 0f;
                var perPlanetDR = 0f;
                var sequence    = Globals.WarStatusTracker.WarFactionTracker.Where(x =>
                                                                                   Globals.IncludedFactions.Contains(x.FactionName)).ToList();
                var factionPerPlanetAR = new Dictionary <WarFaction, float>();
                var factionPerPlanetDR = new Dictionary <WarFaction, float>();
                Logger.LogDebug("Faction Bonus Resources");
                Logger.LogDebug("=============================");
                foreach (var faction in sequence)
                {
                    var systemCount = Globals.WarStatusTracker.Systems.Count(x => x.Owner == faction.FactionName);
                    if (systemCount != 0)
                    {
                        perPlanetAR = faction.TotalBonusAttackResources / systemCount;
                        perPlanetDR = faction.TotalBonusDefensiveResources / systemCount;
                        factionPerPlanetAR.Add(faction, perPlanetAR);
                        factionPerPlanetDR.Add(faction, perPlanetDR);
                        Logger.LogDebug("Faction: " + faction.FactionName + " Bonus AR: " + faction.TotalBonusAttackResources + " Bonus DR: " + faction.TotalBonusDefensiveResources);
                        Logger.LogDebug("     Systems: " + systemCount + "; perPlanetAR: " + perPlanetAR + "; perPlanetDR: " + perPlanetDR);
                    }
                }

                foreach (var systemStatus in systemStatuses)
                {
                    //Spread out bonus resources and make them fair game for the taking.
                    WarFaction faction = Globals.WarStatusTracker.WarFactionTracker.Find(x => x.FactionName == systemStatus.Owner);
                    systemStatus.AttackResourcesOriginal  = Mathf.Min(systemStatus.AttackResources + factionPerPlanetAR[faction], systemStatus.AttackResources * 2);
                    systemStatus.DefenseResourcesOriginal = Mathf.Min(systemStatus.DefenseResources + factionPerPlanetDR[faction], systemStatus.DefenseResources * 2);
                    systemStatus.AttackResources          = systemStatus.AttackResourcesOriginal;
                    systemStatus.DefenseResources         = systemStatus.DefenseResourcesOriginal;
                    systemStatus.TotalOriginalResources   = systemStatus.AttackResources + systemStatus.DefenseResources;
                    systemStatus.TotalResources           = systemStatus.TotalOriginalResources;
                }
            }

            //Distribute Pirate Influence throughout the StarSystems
            LogDebug("Processing pirates.");
            PiratesAndLocals.AdjustPirateResources();
            PiratesAndLocals.PiratesStealResources();
            PiratesAndLocals.DistributePirateResources(Globals.WarStatusTracker.PirateResources);
            PiratesAndLocals.DefendAgainstPirates();

            if (checkForSystemChange && Globals.Settings.HyadesRimCompatible && Globals.WarStatusTracker.InactiveTHRFactions.Count != 0 &&
                Globals.WarStatusTracker.HyadesRimGeneralPirateSystems.Count != 0)
            {
                var rand = Globals.Rng.Next(0, 100);
                if (rand < Globals.WarStatusTracker.HyadesRimsSystemsTaken)
                {
                    var inactiveFaction = Globals.WarStatusTracker.InactiveTHRFactions.GetRandomElement();
                    BattleTech.StarSystem flipSystem = new();
                    if (Globals.Settings.HyadesAppearingPiratesFlipSystems.ContainsKey(inactiveFaction))
                    {
                        foreach (var changeSystem in Globals.Settings.HyadesAppearingPiratesFlipSystems[inactiveFaction])
                        {
                            flipSystem = Globals.WarStatusTracker.Systems.Find(x => x.Name == changeSystem).StarSystem;
                            ChangeSystemOwnership(flipSystem, inactiveFaction, true);
                            if (Globals.WarStatusTracker.HyadesRimGeneralPirateSystems.Contains(changeSystem))
                            {
                                Globals.WarStatusTracker.HyadesRimGeneralPirateSystems.Remove(changeSystem);
                            }
                        }
                    }
                    else
                    {
                        var hyadesSystem = Globals.WarStatusTracker.HyadesRimGeneralPirateSystems.GetRandomElement();
                        flipSystem = Globals.WarStatusTracker.Systems.Find(x => x.Name == hyadesSystem).StarSystem;
                        ChangeSystemOwnership(flipSystem, inactiveFaction, true);
                        Globals.WarStatusTracker.HyadesRimGeneralPirateSystems.Remove(hyadesSystem);
                    }
                    Globals.WarStatusTracker.InactiveTHRFactions.Remove(inactiveFaction);
                }
            }

            LogDebug("Processing systems' influence.");
            foreach (var systemStatus in systemStatuses)
            {
                systemStatus.PriorityAttack  = false;
                systemStatus.PriorityDefense = false;
                if (Globals.WarStatusTracker.FirstTickInitialization)
                {
                    systemStatus.CurrentlyAttackedBy.Clear();
                    CalculateAttackAndDefenseTargets(systemStatus.StarSystem);
                    RefreshContractsEmployersAndTargets(systemStatus);
                }

                if (systemStatus.Contested || Globals.WarStatusTracker.HotBox.IsHot(systemStatus.Name))
                {
                    continue;
                }

                if (!systemStatus.Owner.Equals("Locals") && systemStatus.InfluenceTracker.Keys.Contains("Locals") &&
                    !Globals.WarStatusTracker.FlashpointSystems.Contains(systemStatus.Name))
                {
                    systemStatus.InfluenceTracker["Locals"] = Math.Min(systemStatus.InfluenceTracker["Locals"] * 1.1f, 100);
                }

                //Add resources from neighboring systems.
                if (systemStatus.NeighborSystems.Count != 0)
                {
                    foreach (var neighbor in systemStatus.NeighborSystems.Keys)
                    {
                        if (!Globals.Settings.ImmuneToWar.Contains(neighbor) && !Globals.Settings.DefensiveFactions.Contains(neighbor) &&
                            !Globals.WarStatusTracker.FlashpointSystems.Contains(systemStatus.Name))
                        {
                            var pushFactor = Globals.Settings.APRPush * Globals.Rng.Next(1, Globals.Settings.APRPushRandomizer + 1);
                            systemStatus.InfluenceTracker[neighbor] += systemStatus.NeighborSystems[neighbor] * pushFactor;
                        }
                    }
                }

                //Revolt on previously taken systems.
                // that represents is the previous faction essentially "revolting" against the new faction.
                // So, if they have any influence in the system it gets bigger every turn. The only way to make it stop is to completely wipe them out.
                if (systemStatus.Owner != systemStatus.OriginalOwner)
                {
                    systemStatus.InfluenceTracker[systemStatus.OriginalOwner] *= 1.10f;
                }

                var pirateSystemFlagValue = Globals.Settings.PirateSystemFlagValue;

                if (Globals.Settings.ISMCompatibility)
                {
                    pirateSystemFlagValue = Globals.Settings.PirateSystemFlagValue_ISM;
                }

                // LogDebug($"{systemStatus.starSystem.Name} total resources: {systemStatus.TotalResources}.  Pirate activity {systemStatus.PirateActivity}");
                var totalPirates = systemStatus.PirateActivity * systemStatus.TotalOriginalResources / 100;
                if (totalPirates >= pirateSystemFlagValue)
                {
                    if (!Globals.WarStatusTracker.PirateHighlight.Contains(systemStatus.Name))
                    {
                        Globals.WarStatusTracker.PirateHighlight.Add(systemStatus.Name);
                    }
                }
                else
                {
                    if (Globals.WarStatusTracker.PirateHighlight.Contains(systemStatus.Name))
                    {
                        Globals.WarStatusTracker.PirateHighlight.Remove(systemStatus.Name);
                    }
                }
            }

            Globals.WarStatusTracker.FirstTickInitialization = false;
            LogDebug("Processing resource spending.");
            foreach (var warFaction in Globals.WarStatusTracker.WarFactionTracker)
            {
                DivideAttackResources(warFaction, useFullSet);
            }

            foreach (var warFaction in Globals.WarStatusTracker.WarFactionTracker)
            {
                AllocateAttackResources(warFaction);
            }

            CalculateDefensiveSystems();

            foreach (var warFaction in Globals.WarStatusTracker.WarFactionTracker)
            {
                AllocateDefensiveResources(warFaction, useFullSet);
            }

            LogDebug("Processing influence changes.");
            UpdateInfluenceFromAttacks(checkForSystemChange);

            //Increase War Escalation or decay defenses.
            foreach (var warFaction in Globals.WarStatusTracker.WarFactionTracker)
            {
                if (!warFaction.GainedSystem)
                {
                    warFaction.DaysSinceSystemAttacked += 1;
                }
                else
                {
                    warFaction.DaysSinceSystemAttacked = 0;
                    warFaction.GainedSystem            = false;
                }

                if (!warFaction.LostSystem)
                {
                    warFaction.DaysSinceSystemLost += 1;
                }
                else
                {
                    warFaction.DaysSinceSystemLost = 0;
                    warFaction.LostSystem          = false;
                }
            }

            LogDebug("Processing flipped systems.");
            foreach (var system in Globals.WarStatusTracker.Systems.Where(x => Globals.WarStatusTracker.SystemChangedOwners.Contains(x.Name)))
            {
                system.CurrentlyAttackedBy.Clear();
                CalculateAttackAndDefenseTargets(system.StarSystem);
                RefreshContractsEmployersAndTargets(system);
            }

            if (Globals.WarStatusTracker.SystemChangedOwners.Count > 0)
            {
                LogDebug($"Changed on {Globals.Sim.CurrentDate.ToShortDateString()}: {Globals.WarStatusTracker.SystemChangedOwners.Count} systems:");
                Globals.WarStatusTracker.SystemChangedOwners.OrderBy(x => x).Do(x =>
                                                                                LogDebug($"  {x}"));
                Globals.WarStatusTracker.SystemChangedOwners.Clear();
                if (StarmapMod.eventPanel != null)
                {
                    StarmapMod.UpdatePanelText();
                }
            }

            //Log("===================================================");
            //Log("TESTING ZONE");
            //Log("===================================================");
            //////TESTING ZONE
            //foreach (WarFaction WF in Globals.WarStatusTracker.warFactionTracker)
            //{
            //    Log("----------------------------------------------");
            //    Log(WF.faction.ToString());
            //    try
            //    {
            //        var DLT = Globals.WarStatusTracker.DeathListTrackers.Find(x => x.faction == WF.faction);
            //        //                Log("\tAttacked By :");
            //        //                foreach (Faction fac in DLT.AttackedBy)
            //        //                    Log("\t\t" + fac.ToString());
            //        //                Log("\tOwner :" + DLT.);
            //        //                Log("\tAttack Resources :" + WF.AttackResources.ToString());
            //        //                Log("\tDefensive Resources :" + WF.DefensiveResources.ToString());
            //        Log("\tDeath List:");
            //        foreach (var faction in DLT.deathList.Keys)
            //        {
            //            Log("\t\t" + faction.ToString() + ": " + DLT.deathList[faction]);
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        Error(e);
            //    }
            //}
        }