Example #1
0
        //basic initial implimentation
        //does a check if it is withen range of an enemy, if it is holds
        //onto its resources.
        //TODO decide wether this belongs here or in the Resource Class. In Resource Class
        public void DistributeResources(List <SystemStatus> nSystems, bool inRangeOfEnemy, string myFaction)
        {
            WarFaction warFaction = new WarFaction(myFaction);

            if (!inRangeOfEnemy)
            {
                PushResourcesToLocalFactionSystems(nSystems);
            }

            /***************************************************************
             * This section Will get activated if the system is in range of an enemy Faction.
             * TODO need to decide if a SystemStatus will process ask requests
             * for resources here or not.
             * a function(s)? will probably need to be made so that resource queries can be proccessed
             * and resources can be returned if available.
             *
             * Originally had this else statement in the wronge place.*
             * **************************************************************/
            //--Start-enemy-in-range-resource-block--------------------------------------------------
            else
            {
                //ResourcesRequestedFromNeighbor();
            }
            //-----End-----enemy-faction--in-range---resource-Block------------------------------------
            hasDoneDistrobution = true;
        }
Example #2
0
 public Combat(string systemName, string faction, SystemStatus nSystems, Resource resource)
 {
     sysName     = systemName;
     sysFaction  = faction;
     sysResource = resource;
     warFaction  = Globals.WarStatusTracker.warFactionTracker.Find(x => x.faction == sysFaction);
 }
Example #3
0
        public static void DivideAttackResources(WarFaction warFaction, bool useFullSet)
        {
            //Log("Attacking");
            var deathList = warFaction.DeathListTracker;
            var warFar    = warFaction.WarFactionAttackResources;

            warFar.Clear();
            var tempTargets = new Dictionary <string, float>();

            foreach (var fact in warFaction.AttackTargets.Keys)
            {
                tempTargets.Add(fact, deathList.DeathList[fact]);
            }

            var total           = tempTargets.Values.Sum();
            var attackResources = warFaction.AttackResources - warFaction.AR_Against_Pirates;

            if (warFaction.ComstarSupported)
            {
                attackResources += Globals.Settings.GaW_Police_ARBonus;
            }
            warFaction.AR_Against_Pirates = 0;
            if (Globals.Settings.AggressiveToggle && !Globals.Settings.DefensiveFactions.Contains(warFaction.FactionName))
            {
                attackResources += Globals.Sim.Constants.Finances.LeopardBaseMaintenanceCost;
            }

            attackResources  = attackResources * (1 + warFaction.DaysSinceSystemAttacked * Globals.Settings.AResourceAdjustmentPerCycle / 100);
            attackResources += attackResources * (float)(Globals.Rng.Next(-1, 1) * Globals.Settings.ResourceSpread);
            foreach (var rfact in tempTargets.Keys)
            {
                warFar.Add(rfact, tempTargets[rfact] * attackResources / total);
            }
        }
Example #4
0
        //---------------------^^------------------------------------^^------------------

        /*******************************************************************************
        *  This code block may be used long term. For now though it will be used
        *  as a staging filter for Items from the old Resource code base that needs to be
        *  kept, like trackers. currently its a storage area, not so great.
        *******************************************************************************/
        /*
         * public void extractedResourceCode()
         * {
         *  //------From-----DivideAttackResources----will more then likely not use any of it---
         *  var deathList = warFaction.DeathListTracker;  // Still really need to properly figure out what this is (assumed systems faction is attacking)
         *  var tempTargets = new Dictionary<string, float>(); //targets current faction is attacking
         *
         *  //gets all systems on the factions deathlist
         *  foreach (var fact in warFaction.attackTargets.Keys)
         *  {
         *      tempTargets.Add(fact, deathList.deathList[fact]);
         *  }
         *
         *  var total = tempTargets.Values.Sum();  //total amount of systems in combat with
         *
         *  //warFar changes never do anything, unless DIctionarys are passed by ref nativly.
         *  //TODO check how dictionarys are passed
         *  //some of this doesn't add up sit right with me, more code to follow, but since i will be
         *  //doing processing differently, by a system calculating it's own resources do not believe much of the code
         *  //in here will be used.
         *  foreach (var rfact in tempTargets.Keys)
         *  {
         *      warFar.Add(rfact, tempTargets[rfact] * attackResources / total); //ahh warfar is pretty much just a label/pointer that refers to
         *  }                                                                    //warFaction.warFactionAttackResources
         *  //-----------End Divide attack resources-------------------------------------------------
         *
         *  //--------From allocate attack resources-------------------------------------------------
         *  var deathListTracker = warFaction.DeathListTracker;
         *
         *  //sinse a system is checking itself no loop is needed to determin faction.
         *  //this code will need to be adjusted to reflect that.
         *  var attackTargets = warFaction.attackTargets[targetFaction];  //gets the list of systems names in combat with, of the currently selected faction
         *                                                                // makes a list of systemStatus of the currents systems of the current faction this faction is at war with
         *  var map = new Dictionary<string, SystemStatus>();
         *  foreach (var targetName in attackTargets)
         *  {
         *      map.Add(targetName, Globals.WarStatusTracker.systems.Find(x => x.name == targetName));
         *  }
         *
         *  var hatred = deathListTracker.deathList[targetFaction];  // I dont actualy know what the float is refering to for this, AR or DR ?
         *                                                           // or something else entirely
         *
         *  var targetWarFaction = Globals.WarStatusTracker.warFactionTracker.Find(x => x.faction == targetFaction); //gets opposong factions warfaction info
         *
         *  //this looks like a filter check to catch anything that should not have gotten through, or is currently immune to war.
         *  if (system.owner == warFaction.faction || Globals.WarStatusTracker.FlashpointSystems.Contains(system.name))
         *  {
         *      attackTargets.Remove(target);
         *      return;
         *  }
         *
         *  //Find most valuable target for attacking for later. Used in HotSpots.
         *  if (hatred >= Globals.Settings.PriorityHatred &&
         *      system.DifficultyRating <= maxContracts &&
         *      system.DifficultyRating >= maxContracts - 4)
         *  {
         *      system.PriorityAttack = true; //another item i'm not so sure on, have to dig some to find out.
         *
         *
         *      if (!system.CurrentlyAttackedBy.Contains(warFaction.faction)) //does a check to see if the opposing system is currently beiing attacked
         *      {                                                             //by this faction
         *          system.CurrentlyAttackedBy.Add(warFaction.faction);
         *      }
         *
         *      if (!Globals.WarStatusTracker.PrioritySystems.Contains(system.starSystem.Name))
         *      {
         *          Globals.WarStatusTracker.PrioritySystems.Add(system.starSystem.Name);
         *      }
         *  }
         *
         *  //Distribute attacking resources to systems.
         *  //TODO find out what triggers/flags the Contended status
         *  if (system.Contended || Globals.WarStatusTracker.HotBox.Contains(system.name))
         *  {
         *      attackTargets.Remove(system.starSystem.Name);
         *      if (warFaction.attackTargets[targetFaction].Count == 0 || !warFaction.attackTargets.Keys.Contains(targetFaction))
         *      {
         *          break;
         *      }
         *      continue;
         *  }
         *
         *  //--------end------------Attack resources block----Ignores all code to do with influence----------------------------------
         *  //---------Start---AllocateDefensiveResources---------------block---------------------------------------------------------
         *  if (warFaction.defenseTargets.Count == 0)                  // not going to change it, but systems defending would be easier to understand
         *                                                             // or defendingSystems. just checks if the current faction is defending itself from
         *                                                             // another faction or not.
         *      return;
         *
         *  var faction = warFaction.faction;
         *
         *  var map = new Dictionary<string, SystemStatus>();
         *
         *  // makes a dictionary of SystemStatus of this factions defending systems.
         *  foreach (var defenseTarget in warFaction.defenseTargets.Distinct())
         *  {
         *      map.Add(defenseTarget, Globals.WarStatusTracker.systems.Find(x => x.name == defenseTarget));
         *  }
         *
         *  if (systemStatus.Contended || Globals.WarStatusTracker.HotBox.Contains(systemStatus.name))
         *  {
         *      warFaction.defenseTargets.Remove(systemStatus.starSystem.Name);
         *      if (warFaction.defenseTargets.Count == 0 || warFaction.defenseTargets == null)
         *      {
         *          break;
         *      }
         *
         *      continue;
         *  }
         *  //----end-----------AllocateDefensiveResources-------Block---------Ignores all code to do with influence---------------------
         *  //---Basic core of what I want to test. The Code will obviously not work in it's current state, its just the blocks i will be
         *  //---working from, with changes. probably some stuff in the influence area that needs to be untangled more will worry about that later
         *  //---if required.
         * }
         */

        // TODO go through this code.
        // putting in notes, there are somethings that i don't quiet understand in it
        // Will repurpose modify/take parts that are needed
        // So far my understanding is this takes the factions total attack resources
        // divides it all up. Then stores the total amount that is going to be used agaisnt each other faction it is currently
        // in combat with. Assuming this gets carried on in the next method AllocateAttackResources.
        public static void DivideAttackResources(WarFaction warFaction, bool useFullSet)
        {
            //Log("Attacking");
            var deathList = warFaction.DeathListTracker;          // Still really need to properly figure out what this is (assumed systems faction is attacking)
            var warFar    = warFaction.warFactionAttackResources; //is this attack resources spent against each faction ? key == faction value==attackresources

            warFar.Clear();

            var tempTargets = new Dictionary <string, float>(); //targets current faction is attacking

            //gets all systems on the factions deathlist
            foreach (var fact in warFaction.attackTargets.Keys)
            {
                tempTargets.Add(fact, deathList.deathList[fact]);
            }

            var total = tempTargets.Values.Sum();  //total amount of systems in combat with


            // this one line wouldve been making some pretty heafty negative values, while the pirates math was going awol
            var attackResources = warFaction.AttackResources - warFaction.AR_Against_Pirates;   //total amount of attack resources

            //attackResources = Helpers.Clamp(attackResources, Globals.ResourceGenericMax);
            //---look---at-this-some-more-
            if (warFaction.ComstarSupported)
            {
                attackResources += Globals.Settings.GaW_Police_ARBonus;
            }

            warFaction.AR_Against_Pirates = 0;

            if (Globals.Settings.AggressiveToggle && !Globals.Settings.DefensiveFactions.Contains(warFaction.faction))
            {
                attackResources += Globals.Sim.Constants.Finances.LeopardBaseMaintenanceCost;
            }

            //not sure why this is necessary.
            attackResources = attackResources * (1 + warFaction.DaysSinceSystemAttacked * Globals.Settings.AResourceAdjustmentPerCycle / 100);

            //attackResources = Helpers.Clamp(attackResources, Globals.ResourceGenericMax);

            //potential negative value -1,1
            attackResources += attackResources * (float)(Globals.Rng.Next(-1, 1) * Globals.Settings.ResourceSpread);
            //---end--looking--------------

            ///attackResources = Helpers.Clamp(attackResources, Globals.ResourceGenericMax);

            //warFar changes never do anything, unless DIctionarys are passed by ref nativly.
            //TODO check how dictionarys are passed
            //some of this doesn't add up sit right with me, more code to follow, but since i will be
            //doing processing differently, by a system calculating it's own resources do not believe much of the code
            //in here will be used.
            foreach (var rfact in tempTargets.Keys)
            {
                warFar.Add(rfact, tempTargets[rfact] * attackResources / total); //ahh warfar is pretty much just a label/pointer that refers to
            }                                                                    //warFaction.warFactionAttackResources
        }
Example #5
0
        public WarStatus()
        {
            Logger.LogDebug("WarStatus ctor");
            if (Globals.Settings.ISMCompatibility)
            {
                Globals.Settings.IncludedFactions = new List <string>(Globals.Settings.IncludedFactions_ISM);
            }

            CurSystem        = Globals.Sim.CurSystem.Name;
            TempPRGain       = 0;
            HotBoxTravelling = false;
            HotBox           = new List <string>();
            if (Globals.Settings.HyadesRimCompatible)
            {
                InactiveTHRFactions = Globals.Settings.HyadesAppearingPirates;
                FlashpointSystems   = Globals.Settings.HyadesFlashpointSystems;
                NeverControl        = Globals.Settings.HyadesNeverControl;
            }

            //initialize all WarFactions, DeathListTrackers, and SystemStatuses
            foreach (var faction in Globals.Settings.IncludedFactions)
            {
                var warFaction = new WarFaction(faction);
                var d          = new DeathListTracker(faction)
                {
                    WarFaction = warFaction
                };
                warFaction.DeathListTracker = d;
                warFactionTracker.Add(warFaction);
                deathListTracker.Add(d);
            }

            foreach (var system in Globals.GaWSystems)
            {
                if (system.OwnerValue.Name == "NoFaction" || system.OwnerValue.Name == "AuriganPirates")
                {
                    AbandonedSystems.Add(system.Name);
                }
                var warFaction = warFactionTracker.Find(x => x.faction == system.OwnerValue.Name);
                if (Globals.Settings.DefensiveFactions.Contains(warFaction.faction) && Globals.Settings.DefendersUseARforDR)
                {
                    warFaction.DefensiveResources += GetTotalAttackResources(system);
                }
                else
                {
                    warFaction.AttackResources += GetTotalAttackResources(system);
                }
                warFaction.DefensiveResources += GetTotalDefensiveResources(system);
            }

            Logger.LogDebug("WarFaction AR/DR set.");
            var maxAR = warFactionTracker.Select(x => x.AttackResources).Max();
            var maxDR = warFactionTracker.Select(x => x.DefensiveResources).Max();

            foreach (var faction in Globals.Settings.IncludedFactions)
            {
                var warFaction = warFactionTracker.Find(x => x.faction == faction);
                if (Globals.Settings.DefensiveFactions.Contains(faction) && Globals.Settings.DefendersUseARforDR)
                {
                    if (!Globals.Settings.ISMCompatibility)
                    {
                        warFaction.DefensiveResources = maxAR + maxDR + Globals.Settings.BonusAttackResources[faction] +
                                                        Globals.Settings.BonusDefensiveResources[faction];
                    }
                    else
                    {
                        warFaction.DefensiveResources = maxAR + maxDR + Globals.Settings.BonusAttackResources_ISM[faction] +
                                                        Globals.Settings.BonusDefensiveResources_ISM[faction];
                    }

                    warFaction.AttackResources = 0;
                }
                else
                {
                    if (!Globals.Settings.ISMCompatibility)
                    {
                        warFaction.AttackResources    = maxAR + Globals.Settings.BonusAttackResources[faction];
                        warFaction.DefensiveResources = maxDR + Globals.Settings.BonusDefensiveResources[faction];
                    }
                    else
                    {
                        warFaction.AttackResources    = maxAR + Globals.Settings.BonusAttackResources_ISM[faction];
                        warFaction.DefensiveResources = maxDR + Globals.Settings.BonusDefensiveResources_ISM[faction];
                    }
                }
            }

            Logger.LogDebug("WarFaction bonus AR/DR set.");
            if (!Globals.Settings.ISMCompatibility)
            {
                PirateResources = maxAR * Globals.Settings.FractionPirateResources + Globals.Settings.BonusPirateResources;
            }
            else
            {
                PirateResources = maxAR * Globals.Settings.FractionPirateResources_ISM + Globals.Settings.BonusPirateResources_ISM;
            }

            MinimumPirateResources  = PirateResources;
            StartingPirateResources = PirateResources;
            Logger.LogDebug("SystemStatus mass creation...");
            systems = new List <SystemStatus>(Globals.GaWSystems.Count);
            for (var index = 0; index < Globals.Sim.StarSystems.Count; index++)
            {
                var system = Globals.Sim.StarSystems[index];
                if (Globals.Settings.ImmuneToWar.Contains(system.OwnerValue.Name))
                {
                    continue;
                }

                var systemStatus = new SystemStatus(system, system.OwnerValue.Name);
                systems.Add(systemStatus);
                if (system.Tags.Contains("planet_other_pirate") && !system.Tags.Contains("planet_region_hyadesrim"))
                {
                    FullPirateSystems.Add(system.Name);
                    PiratesAndLocals.FullPirateListSystems.Add(systemStatus);
                }

                if (system.Tags.Contains("planet_region_hyadesrim") && !FlashpointSystems.Contains(system.Name) &&
                    (system.OwnerValue.Name == "NoFaction" || system.OwnerValue.Name == "Locals"))
                {
                    HyadesRimGeneralPirateSystems.Add(system.Name);
                }
            }

            Logger.LogDebug("Full pirate systems created.");
            systems            = systems.OrderBy(x => x.name).ToList();
            systemsByResources = systems.OrderBy(x => x.TotalResources).ToList();
            PrioritySystems    = new List <string>(systems.Count);
            Logger.LogDebug("SystemStatus ordered lists created.");
        }
Example #6
0
        public WarStatus()
        {
            Logger.LogDebug("WarStatus ctor");
            if (Globals.Settings.ISMCompatibility)
            {
                Globals.Settings.IncludedFactions = new List <string>(Globals.Settings.IncludedFactions_ISM);
            }

            CurSystem        = Globals.Sim.CurSystem.Name;
            TempPRGain       = 0;
            HotBoxTravelling = false;
            HotBox           = new List <string>();
            if (Globals.Settings.HyadesRimCompatible)
            {
                InactiveTHRFactions = Globals.Settings.HyadesAppearingPirates;
                FlashpointSystems   = Globals.Settings.HyadesFlashpointSystems;
                NeverControl        = Globals.Settings.HyadesNeverControl;
            }

            //initialize all WarFactions, DeathListTrackers, and SystemStatuses
            foreach (var faction in Globals.Settings.IncludedFactions)
            {
                var warFaction = new WarFaction(faction);
                var d          = new DeathListTracker(faction)
                {
                    WarFaction = warFaction
                };
                warFaction.DeathListTracker = d;
                warFactionTracker.Add(warFaction);
                deathListTracker.Add(d);
            }

            foreach (var system in Globals.GaWSystems)
            {
                if (system.OwnerValue.Name == "NoFaction" || system.OwnerValue.Name == "AuriganPirates")
                {
                    AbandonedSystems.Add(system.Name);
                }
                var warFaction = warFactionTracker.Find(x => x.faction == system.OwnerValue.Name);

                /*if (Globals.Settings.DefensiveFactions.Contains(warFaction.faction) && Globals.Settings.DefendersUseARforDR)
                 *  warFaction.DefensiveResources += GetTotalAttackResources(system);
                 * else*/
                warFaction.AttackResources    += GetTotalAttackResources(system);
                warFaction.DefensiveResources += GetTotalDefensiveResources(system);
            }

            Logger.LogDebug("WarFaction AR/DR set.");

            /*var maxAR = warFactionTracker.Select(x => x.AttackResources).Max();
             * var maxDR = warFactionTracker.Select(x => x.DefensiveResources).Max();
             *
             * foreach (var faction in Globals.Settings.IncludedFactions)
             * {
             *  var warFaction = warFactionTracker.Find(x => x.faction == faction);
             *  if (Globals.Settings.DefensiveFactions.Contains(faction) && Globals.Settings.DefendersUseARforDR)
             *  {
             *      if (!Globals.Settings.ISMCompatibility)
             *          warFaction.DefensiveResources = maxAR + maxDR + Globals.Settings.BonusAttackResources[faction] +
             *                                          Globals.Settings.BonusDefensiveResources[faction];
             *      else
             *          warFaction.DefensiveResources = maxAR + maxDR + Globals.Settings.BonusAttackResources_ISM[faction] +
             *                                          Globals.Settings.BonusDefensiveResources_ISM[faction];
             *
             *      warFaction.AttackResources = 0;
             *  }
             *  else
             *  {
             *      if (!Globals.Settings.ISMCompatibility)
             *      {
             *          warFaction.AttackResources = maxAR + Globals.Settings.BonusAttackResources[faction];
             *          warFaction.DefensiveResources = maxDR + Globals.Settings.BonusDefensiveResources[faction];
             *      }
             *      else
             *      {
             *          warFaction.AttackResources = maxAR + Globals.Settings.BonusAttackResources_ISM[faction];
             *          warFaction.DefensiveResources = maxDR + Globals.Settings.BonusDefensiveResources_ISM[faction];
             *      }
             *  }
             * }*/

            Logger.LogDebug("WarFaction bonus AR/DR set.");

            /*if (!Globals.Settings.ISMCompatibility)
             *  PirateResources = maxAR * Globals.Settings.FractionPirateResources + Globals.Settings.BonusPirateResources;
             * else
             *  PirateResources = maxAR * Globals.Settings.FractionPirateResources_ISM + Globals.Settings.BonusPirateResources_ISM;
             *
             * MinimumPirateResources = PirateResources;
             * StartingPirateResources = PirateResources;*/
            Logger.LogDebug("SystemStatus mass creation...");
            systems = new List <SystemStatus>(Globals.GaWSystems.Count);
            for (var index = 0; index < Globals.Sim.StarSystems.Count; index++)
            {
                var system = Globals.Sim.StarSystems[index];
                if (Globals.Settings.ImmuneToWar.Contains(system.OwnerValue.Name))
                {
                    continue;
                }

                SystemStatus systemStatus = new SystemStatus(system, system.OwnerValue.Name);

                //--new-block------------------------
                systemStatus.absPosX = Math.Abs(0 - system.Position.x);
                systemStatus.absPosY = Math.Abs(0 - system.Position.y);
                systemStatus.systemsDistanceFromZero = (float)Math.Sqrt((systemStatus.absPosX * systemStatus.absPosX) + (systemStatus.absPosY * systemStatus.absPosY));
                systems.Add(systemStatus);

                foreach (SystemStatus curSystem in systems)
                {
                    curSystem.InitializeContracts();
                }
                //---end-new-block-------------------

                if (system.Tags.Contains("planet_other_pirate") && !system.Tags.Contains("planet_region_hyadesrim"))
                {
                    FullPirateSystems.Add(system.Name);
                    PiratesAndLocals.FullPirateListSystems.Add(systemStatus);
                }

                if (system.Tags.Contains("planet_region_hyadesrim") && !FlashpointSystems.Contains(system.Name) &&
                    (system.OwnerValue.Name == "NoFaction" || system.OwnerValue.Name == "Locals"))
                {
                    HyadesRimGeneralPirateSystems.Add(system.Name);
                }
            }

            Logger.LogDebug("Full pirate systems created.");
            systems            = systems.OrderBy(x => x.name).ToList();
            systemsByResources = systems.OrderBy(x => x.systemResources.TotalResources).ToList();
            PrioritySystems    = new List <string>(systems.Count);

            /*
             * an attempt at sorting the systems in a way that is good for resource distrobution.
             * Sort by faction, then by systems distance from 0 (zero), decending.
             */
            systems.Sort((f1, f2) =>
            {
                int result = string.Compare(f1.owner, f2.owner, StringComparison.Ordinal);
                return(result == 0 ? f2.systemsDistanceFromZero.CompareTo(f1.systemsDistanceFromZero) : result);
            });

            Logger.LogDebug("SystemStatus ordered lists created.");
        }
Example #7
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);
            //    }
            //}
        }
Example #8
0
        public static void AllocateAttackResources(WarFaction warFaction)
        {
            int factionRep = -1;

            try
            {
                factionRep = Globals.Sim.GetRawReputation(Globals.FactionValues.Find(value => value.Name == warFaction.FactionName));
            }
            catch (Exception ex)
            {
                LogDebug("warFaction.FactionName: " + warFaction.FactionName);
                Error(ex);
            }

            var maxContracts = HotSpots.ProcessReputation(factionRep);

            if (warFaction.WarFactionAttackResources.Count == 0)
            {
                return;
            }
            var warFactionAR = warFaction.WarFactionAttackResources;
            //Go through the different resources allocated from attacking faction to spend against each targetFaction
            var deathListTracker = warFaction.DeathListTracker;
            var attackFactions   = warFactionAR.Keys.Intersect(warFaction.AttackTargets.Keys);

            foreach (var targetFaction in attackFactions)
            {
                var targetFar         = warFactionAR[targetFaction];
                var startingTargetFar = targetFar;
                var attackTargets     = warFaction.AttackTargets[targetFaction];
                var hatred            = deathListTracker.DeathList[targetFaction];
                var targetWarFaction  = Globals.WarStatusTracker.WarFactionTracker.Find(x => x.FactionName == targetFaction);
                while (targetFar > 0 && attackTargets.Count > 0)
                {
                    var systemStatus = attackTargets.GetRandomElement();
                    if (systemStatus.Owner == warFaction.FactionName || Globals.WarStatusTracker.FlashpointSystems.Contains(systemStatus.Name))
                    {
                        attackTargets.Remove(systemStatus);
                        return;
                    }

                    //Find most valuable target for attacking for later. Used in HotSpots.
                    if (hatred >= Globals.Settings.PriorityHatred &&
                        systemStatus.DifficultyRating <= maxContracts &&
                        systemStatus.DifficultyRating >= maxContracts - 4)
                    {
                        systemStatus.PriorityAttack = true;
                        if (!systemStatus.CurrentlyAttackedBy.Contains(warFaction.FactionName))
                        {
                            systemStatus.CurrentlyAttackedBy.Add(warFaction.FactionName);
                        }

                        if (!Globals.WarStatusTracker.PrioritySystems.Contains(systemStatus.StarSystem.Name))
                        {
                            Globals.WarStatusTracker.PrioritySystems.Add(systemStatus.StarSystem.Name);
                        }
                    }

                    //Distribute attacking resources to systems.
                    if (systemStatus.Contested || Globals.WarStatusTracker.HotBox.IsHot(systemStatus.Name))
                    {
                        attackTargets.Remove(systemStatus);
                        if (warFaction.AttackTargets[targetFaction].Count == 0 || !warFaction.AttackTargets.Keys.Contains(targetFaction))
                        {
                            break;
                        }

                        continue;
                    }

                    var arFactor = Random.Range(Globals.Settings.MinimumResourceFactor, Globals.Settings.MaximumResourceFactor);
                    var spendAR  = Mathf.Min(startingTargetFar * arFactor, targetFar);
                    spendAR = spendAR < 1 ? 1 : Math.Max(1 * Globals.SpendFactor, spendAR * Globals.SpendFactor);
                    var maxValueList = systemStatus.InfluenceTracker.Values.OrderByDescending(x => x).ToList();
                    var pMaxValue    = 200.0f;
                    if (maxValueList.Count > 1)
                    {
                        pMaxValue = maxValueList[1];
                    }

                    var itValue = systemStatus.InfluenceTracker[warFaction.FactionName];
                    var basicAR = (float)(11 - systemStatus.DifficultyRating) / 2;
                    var bonusAR = 0f;
                    if (itValue > pMaxValue)
                    {
                        bonusAR = (itValue - pMaxValue) * 0.15f;
                    }

                    var totalAR = basicAR + bonusAR + spendAR;
                    if (targetFar > totalAR)
                    {
                        systemStatus.InfluenceTracker[warFaction.FactionName] += totalAR;
                        targetFar -= totalAR;
                        targetWarFaction.DefenseTargets.Add(systemStatus);
                    }
                    else
                    {
                        systemStatus.InfluenceTracker[warFaction.FactionName] += targetFar;
                        targetFar = 0;
                        targetWarFaction.DefenseTargets.Add(systemStatus);
                    }
                }
            }
        }
Example #9
0
        public static void AllocateDefensiveResources(WarFaction warFaction, bool useFullSet)
        {
            if (warFaction.DefenseTargets.Count == 0)
            {
                return;
            }

            var faction            = warFaction.FactionName;
            var defensiveResources = warFaction.DefensiveResources + warFaction.DR_Against_Pirates;

            if (warFaction.ComstarSupported)
            {
                defensiveResources += Globals.Settings.GaW_Police_DRBonus;
            }
            warFaction.DR_Against_Pirates = 0;
            if (Globals.Settings.AggressiveToggle && Globals.Settings.DefensiveFactions.Contains(warFaction.FactionName))
            {
                defensiveResources += Globals.Sim.Constants.Finances.LeopardBaseMaintenanceCost;
            }
            var defensiveCorrection = defensiveResources * (100 * Globals.Settings.GlobalDefenseFactor -
                                                            Globals.Settings.DResourceAdjustmentPerCycle * warFaction.DaysSinceSystemLost) / 100;

            defensiveResources  = Math.Max(defensiveResources, defensiveCorrection);
            defensiveResources += defensiveResources * (float)(Globals.Rng.Next(-1, 1) * Globals.Settings.ResourceSpread);
            var startingDefensiveResources = defensiveResources;
            var defenseTargets             = warFaction.DefenseTargets.Distinct().ToList();

            // reset the cached state for the next tick
            Globals.WarStatusTracker.Systems.Do(systemStatus => systemStatus.TrackerSum = -1);
            // spend and decrement defensiveResources
            while (defensiveResources > 0)
            {
                var highest        = 0f;
                var highestFaction = faction;
                var drFactor       = Random.Range(Globals.Settings.MinimumResourceFactor, Globals.Settings.MaximumResourceFactor);
                var spendDr        = Globals.Settings.MinimumSpendDR;
                //var spendDr = Mathf.Min(startingDefensiveResources * drFactor, defensiveResources);
                //spendDr = spendDr < 1 ? 1 : Math.Max(1 * Globals.SpendFactor, spendDr * Globals.SpendFactor);

                var systemStatus = defenseTargets.GetRandomElement();
                if (systemStatus == null)
                {
                    LogDebug("NULL SystemStatus at AllocateDefensiveResources");
                    return;
                }

                if (systemStatus.Contested || Globals.WarStatusTracker.HotBox.IsHot(systemStatus.Name))
                {
                    warFaction.DefenseTargets.Remove(systemStatus);
                    if (warFaction.DefenseTargets.Count == 0 || warFaction.DefenseTargets == null)
                    {
                        break;
                    }

                    continue;
                }

                var total           = systemStatus.TrackerSum;
                var factionTrackers = systemStatus.InfluenceTracker.Where(x => x.Value != 0);
                foreach (var factionKVP in factionTrackers)
                {
                    var factionStr = factionKVP.Key;
                    if (systemStatus.InfluenceTracker[factionStr] > highest)
                    {
                        highest        = systemStatus.InfluenceTracker[factionStr];
                        highestFaction = factionStr;
                    }

                    if (highest / total >= 0.5)
                    {
                        break;
                    }
                }

                if (highestFaction == faction)
                {
                    if (defensiveResources > 0)
                    {
                        systemStatus.InfluenceTracker[faction] += spendDr;
                        defensiveResources -= spendDr;
                    }
                    else
                    {
                        systemStatus.InfluenceTracker[faction] += defensiveResources;
                        defensiveResources = 0;
                    }
                }
                else
                {
                    var diffRes      = systemStatus.InfluenceTracker[highestFaction] / total - systemStatus.InfluenceTracker[faction] / total;
                    var bonusDefense = spendDr + (diffRes * total - Globals.Settings.TakeoverThreshold / 100 * total) / (Globals.Settings.TakeoverThreshold / 100 + 1);
                    //LogDebug(bonusDefense);
                    if (100 * diffRes > Globals.Settings.TakeoverThreshold)
                    {
                        if (defensiveResources >= bonusDefense)
                        {
                            systemStatus.InfluenceTracker[faction] += bonusDefense;
                            defensiveResources -= bonusDefense;
                        }
                        else
                        {
                            systemStatus.InfluenceTracker[faction] += Math.Min(defensiveResources, 10 * spendDr);
                            defensiveResources -= Math.Min(defensiveResources, 10 * spendDr);
                        }
                    }
                    else
                    {
                        systemStatus.InfluenceTracker[faction] += Math.Min(defensiveResources, 10 * spendDr);
                        defensiveResources -= Math.Min(defensiveResources, 10 * spendDr);
                    }
                }
            }
        }
Example #10
0
        //TODO go through this code.
        public static void AllocateDefensiveResources(WarFaction warFaction, bool useFullSet)
        {
            if (warFaction.defenseTargets.Count == 0)                  // not going to change it, but systems defending would be easier to understand
                                                                       // or defendingSystems. just checks if the current faction is defending itself from
                                                                       // another faction or not.
            {
                return;
            }

            var faction            = warFaction.faction;
            var defensiveResources = warFaction.DefensiveResources + warFaction.DR_Against_Pirates; // calculates the total amount of the current factions pool

            // of defence resources.
            // was clamped to make sure the value was not negative.
            defensiveResources = Helpers.Clamp(defensiveResources, Globals.ResourceGenericMax);

            if (warFaction.ComstarSupported)
            {
                defensiveResources += Globals.Settings.GaW_Police_DRBonus;
            }

            warFaction.DR_Against_Pirates = 0;              // not sure why this gets set to 0, the resources have already been applied to the factions
                                                            // total defence resources. Maybe i made that change last year ?
                                                            // gets set in the pirates class that is disabled for now.

            if (Globals.Settings.AggressiveToggle && Globals.Settings.DefensiveFactions.Contains(warFaction.faction))
            {
                defensiveResources += Globals.Sim.Constants.Finances.LeopardBaseMaintenanceCost;   // gonna take a stab in the dark and assume that is adding
            }
            // a negative value.

            // TODO follow the Globals
            // Currently not sure why this exists, player added difficulty ?
            var defensiveCorrection = defensiveResources * (100 * Globals.Settings.GlobalDefenseFactor -
                                                            Globals.Settings.DResourceAdjustmentPerCycle * warFaction.DaysSinceSystemLost) / 100;

            defensiveResources  = Math.Max(defensiveResources, defensiveCorrection);
            defensiveResources += defensiveResources * (float)(Globals.Rng.Next(-1, 1) * Globals.Settings.ResourceSpread);


            var startingDefensiveResources = defensiveResources;
            var map = new Dictionary <string, SystemStatus>();

            // makes a dictionary of SystemStatus of this factions defending systems.
            foreach (var defenseTarget in warFaction.defenseTargets.Distinct())
            {
                map.Add(defenseTarget, Globals.WarStatusTracker.systems.Find(x => x.name == defenseTarget));
            }


            // spend and decrement defensiveResources
            while (defensiveResources > 0.0f)
            {
                var highest        = 0f;
                var highestFaction = faction;
                var drFactor       = Random.Range(Globals.Settings.MinimumResourceFactor, Globals.Settings.MaximumResourceFactor);

                var spendDr = Mathf.Min(startingDefensiveResources * drFactor, defensiveResources);

                spendDr = spendDr < 1 ? 1 : Math.Max(1 * Globals.SpendFactor, spendDr * Globals.SpendFactor);
                spendDr = Helpers.Clamp(spendDr, Globals.ResourceGenericMax);

                var systemStatus = map.GetRandomElement().Value;
                if (systemStatus == null)
                {
                    LogDebug("NULL SystemStatus at AllocateDefensiveResources");
                    return;
                }

                if (systemStatus.Contended || Globals.WarStatusTracker.HotBox.Contains(systemStatus.name))
                {
                    warFaction.defenseTargets.Remove(systemStatus.starSystem.Name);
                    if (warFaction.defenseTargets.Count == 0 || warFaction.defenseTargets == null)
                    {
                        break;
                    }

                    continue;
                }

                var total = systemStatus.influenceTracker.Values.Sum();  // Influence code, gets total influence, should equal 100

                // sorts influence by faction name and influence is greater then 0, I think?
                var sequence = systemStatus.influenceTracker
                               .Where(x => x.Value != 0)
                               .Select(x => x.Key);

                foreach (var factionStr in sequence)                                // finds the first faction with influence greater then or equal to 50
                                                                                    // and exits loop imidiately
                {
                    if (systemStatus.influenceTracker[factionStr] > highest)
                    {
                        highest        = systemStatus.influenceTracker[factionStr];
                        highestFaction = factionStr;
                    }

                    if (highest / total >= 0.5)
                    {
                        break;
                    }
                }

                if (highestFaction == faction)
                {
                    if (defensiveResources > 0)
                    {
                        systemStatus.influenceTracker[faction] += spendDr;         // gives the owner faction in the system more influence if they are still
                                                                                   // the main influence holder of the system.
                        defensiveResources -= spendDr;
                    }
                    else
                    {
                        systemStatus.influenceTracker[faction] += defensiveResources; // this should probably just be commented out, or removed.
                        defensiveResources = 0;
                    }
                }
                else
                {
                    // is processed when the owner faction no longer has majority Influence
                    // There is one thing that confuses me most, shouldnt someone who is defending be reducing an attackers attack points with defence points
                    // in both the attack and defence methods, atk reduces atk and def reduces def. You may have atk vs atk posibly, but def vs def makes no sense at all.
                    var diffRes      = systemStatus.influenceTracker[highestFaction] / total - systemStatus.influenceTracker[faction] / total;
                    var bonusDefense = spendDr + (diffRes * total - Globals.Settings.TakeoverThreshold / 100 * total) / (Globals.Settings.TakeoverThreshold / 100 + 1);
                    //LogDebug(bonusDefense);
                    if (100 * diffRes > Globals.Settings.TakeoverThreshold)
                    {
                        if (defensiveResources >= bonusDefense)
                        {
                            systemStatus.influenceTracker[faction] += bonusDefense;
                            defensiveResources -= bonusDefense;
                        }
                        else
                        {
                            systemStatus.influenceTracker[faction] += Math.Min(defensiveResources, 50);
                            defensiveResources -= Math.Min(defensiveResources, 50);
                        }
                    }
                    else
                    {
                        systemStatus.influenceTracker[faction] += Math.Min(defensiveResources, 50);
                        defensiveResources -= Math.Min(defensiveResources, 50);
                    }
                }
            }
        }
Example #11
0
        //TODO go through this code.
        public static void AllocateAttackResources(WarFaction warFaction)
        {
            //contracts--code-------
            var factionRep   = Globals.Sim.GetRawReputation(Globals.FactionValues.Find(x => x.Name == warFaction.faction));
            var maxContracts = HotSpots.ProcessReputation(factionRep);

            //end------contracts---code-----


            if (warFaction.warFactionAttackResources.Count == 0)
            {
                return;
            }

            var warFactionAR = warFaction.warFactionAttackResources;
            //Go through the different resources allocated from attacking faction to spend against each targetFaction
            var deathListTracker = warFaction.DeathListTracker;

            foreach (var targetFaction in warFactionAR.Keys.Intersect(warFaction.attackTargets.Keys))
            {
                var targetFar         = warFactionAR[targetFaction];             //gets resources allocated to swing at other faction
                var startingTargetFar = targetFar;
                var attackTargets     = warFaction.attackTargets[targetFaction]; //gets the list of systems names in combat with, of the currently selected faction

                // makes a list of systemStatus of the currents systems of the current faction this faction is at war with
                var map = new Dictionary <string, SystemStatus>();
                foreach (var targetName in attackTargets)
                {
                    map.Add(targetName, Globals.WarStatusTracker.systems.Find(x => x.name == targetName));
                }

                var hatred = deathListTracker.deathList[targetFaction];                                                  // I dont actualy know what the float is refering to for this, AR or DR ?
                                                                                                                         // or something else entirely

                var targetWarFaction = Globals.WarStatusTracker.warFactionTracker.Find(x => x.faction == targetFaction); //gets opposong factions warfaction info

                // this loop keeps going untill the total amount of resources to use against the current enemy faction is exausted
                // targetFar is the total allocated resource
                while (targetFar > 0 && attackTargets.Count > 0)
                {
                    // DE-CONSTRUCTOR!
                    (string target, SystemStatus system) = map.GetRandomElement(); // gets a random system or a return value of null

                    if (system == null)
                    {
                        Log("CRITICAL:  No system found at AllocateAttackResources, aborting processing.");
                        return;
                    }

                    //this looks like a filter check to catch anything that should not have gotten through, or is currently immune to war.
                    if (system.owner == warFaction.faction || Globals.WarStatusTracker.FlashpointSystems.Contains(system.name))
                    {
                        attackTargets.Remove(target);
                        return;
                    }

                    //Find most valuable target for attacking for later. Used in HotSpots.
                    if (hatred >= Globals.Settings.PriorityHatred &&
                        system.DifficultyRating <= maxContracts &&
                        system.DifficultyRating >= maxContracts - 4)
                    {
                        system.PriorityAttack = true; //another item i'm not so sure on, have to dig some to find out.


                        if (!system.CurrentlyAttackedBy.Contains(warFaction.faction)) //does a check to see if the opposing system is currently beiing attacked
                        {                                                             //by this faction
                            system.CurrentlyAttackedBy.Add(warFaction.faction);
                        }

                        if (!Globals.WarStatusTracker.PrioritySystems.Contains(system.starSystem.Name))
                        {
                            Globals.WarStatusTracker.PrioritySystems.Add(system.starSystem.Name);
                        }
                    }

                    //Distribute attacking resources to systems.
                    //TODO find out what triggers/flags the Contended status
                    if (system.Contended || Globals.WarStatusTracker.HotBox.Contains(system.name))
                    {
                        attackTargets.Remove(system.starSystem.Name);
                        if (warFaction.attackTargets[targetFaction].Count == 0 || !warFaction.attackTargets.Keys.Contains(targetFaction))
                        {
                            break;
                        }
                        continue;
                    }

                    var arFactor = Random.Range(Globals.Settings.MinimumResourceFactor, Globals.Settings.MaximumResourceFactor);

                    // this calculates the total amount of resources the current system will get upto the the total amount that can potentially be
                    // allocated to it.
                    var spendAR = Mathf.Min(startingTargetFar * arFactor, targetFar);

                    spendAR = spendAR < 1 ? 1 : Math.Max(1 * Globals.SpendFactor, spendAR * Globals.SpendFactor); //Spend factor could inflate value considerably

                    //clamp that had been put in many places to try get rid of the crazy negative values.
                    spendAR = Helpers.Clamp(spendAR, Globals.ResourceGenericMax);

                    var maxValueList = system.influenceTracker.Values.OrderByDescending(x => x).ToList();

                    var pMaxValue = 200.0f;          //What is P ?

                    if (maxValueList.Count > 1)
                    {
                        pMaxValue = maxValueList[1];                           //why 1 instead of 0
                    }
                    var itValue = system.influenceTracker[warFaction.faction]; //should be a value between or equal to 0 and 100

                    var basicAR = (float)(11 - system.DifficultyRating) / 2;   //I changed this from memory it was creating a much larger value and wasnt / 2
                                                                               //just seemed like there was way to much inflation of values
                                                                               //almost like numbers were inflated so more weird dodgy math could be added to
                                                                               //try fix a problem.
                    var bonusAR = 0f;

                    if (itValue > pMaxValue)                                  //either ive missed something or this code should never have to be called
                    {
                        bonusAR = (itValue - pMaxValue) * 0.15f;
                    }

                    var totalAR = basicAR + bonusAR + spendAR;                // actuall amount of AR being swung at the current enemy system

                    //looking back at things I modified this block of code originally not realising what it did.
                    //from memory this one block, affects overaul influence way more then you would expect.
                    if (targetFar > totalAR)
                    {
                        system.influenceTracker[warFaction.faction] += totalAR; //what i don't get is why boost the enemys influence by the amount of resources
                                                                                //they lose.  It is possible that at the time i may have changed them to +
                                                                                //while trying to get rid of negative values. ahh yes because of the resource
                                                                                //system getting mangled and throwing massive negative values everywhere
                                                                                //influence was all over the place as well.
                        targetFar -= totalAR;
                        targetWarFaction.defenseTargets.Add(system.name);
                    }
                    else
                    {
                        system.influenceTracker[warFaction.faction] += targetFar;
                        targetFar = 0;
                    }
                }
            }
        }
Example #12
0
        public static void AllocateAttackResources(WarFaction warFaction)
        {
            var factionRep   = Globals.Sim.GetRawReputation(Globals.FactionValues.Find(x => x.Name == warFaction.faction));
            var maxContracts = HotSpots.ProcessReputation(factionRep);

            if (warFaction.warFactionAttackResources.Count == 0)
            {
                return;
            }
            var warFactionAR = warFaction.warFactionAttackResources;
            //Go through the different resources allocated from attacking faction to spend against each targetFaction
            var deathListTracker = warFaction.DeathListTracker;

            foreach (var targetFaction in warFactionAR.Keys.Intersect(warFaction.attackTargets.Keys))
            {
                var targetFar         = warFactionAR[targetFaction];
                var startingTargetFar = targetFar;
                var attackTargets     = warFaction.attackTargets[targetFaction];
                var map = new Dictionary <string, SystemStatus>();
                foreach (var targetName in attackTargets)
                {
                    map.Add(targetName, Globals.WarStatusTracker.systems.Find(x => x.name == targetName));
                }

                var hatred           = deathListTracker.deathList[targetFaction];
                var targetWarFaction = Globals.WarStatusTracker.warFactionTracker.Find(x => x.faction == targetFaction);
                while (targetFar > 0 && attackTargets.Count > 0)
                {
                    // DE-CONSTRUCTOR!
                    var(target, system) = map.GetRandomElement();

                    if (system == null)
                    {
                        Log("CRITICAL:  No system found at AllocateAttackResources, aborting processing.");
                        return;
                    }

                    if (system.owner == warFaction.faction || Globals.WarStatusTracker.FlashpointSystems.Contains(system.name))
                    {
                        attackTargets.Remove(target);
                        return;
                    }

                    //Find most valuable target for attacking for later. Used in HotSpots.
                    if (hatred >= Globals.Settings.PriorityHatred &&
                        system.DifficultyRating <= maxContracts &&
                        system.DifficultyRating >= maxContracts - 4)
                    {
                        system.PriorityAttack = true;
                        if (!system.CurrentlyAttackedBy.Contains(warFaction.faction))
                        {
                            system.CurrentlyAttackedBy.Add(warFaction.faction);
                        }

                        if (!Globals.WarStatusTracker.PrioritySystems.Contains(system.starSystem.Name))
                        {
                            Globals.WarStatusTracker.PrioritySystems.Add(system.starSystem.Name);
                        }
                    }

                    //Distribute attacking resources to systems.
                    if (system.Contended || Globals.WarStatusTracker.HotBox.Contains(system.name))
                    {
                        attackTargets.Remove(system.starSystem.Name);
                        if (warFaction.attackTargets[targetFaction].Count == 0 || !warFaction.attackTargets.Keys.Contains(targetFaction))
                        {
                            break;
                        }

                        continue;
                    }

                    var arFactor = Random.Range(Globals.Settings.MinimumResourceFactor, Globals.Settings.MaximumResourceFactor);
                    var spendAR  = Mathf.Min(startingTargetFar * arFactor, targetFar);
                    spendAR = spendAR < 1 ? 1 : Math.Max(1 * Globals.SpendFactor, spendAR * Globals.SpendFactor);
                    var maxValueList = system.influenceTracker.Values.OrderByDescending(x => x).ToList();
                    var pMaxValue    = 200.0f;
                    if (maxValueList.Count > 1)
                    {
                        pMaxValue = maxValueList[1];
                    }

                    var itValue = system.influenceTracker[warFaction.faction];
                    var basicAR = (float)(11 - system.DifficultyRating) / 2;
                    var bonusAR = 0f;
                    if (itValue > pMaxValue)
                    {
                        bonusAR = (itValue - pMaxValue) * 0.15f;
                    }

                    var totalAR = basicAR + bonusAR + spendAR;
                    if (targetFar > totalAR)
                    {
                        system.influenceTracker[warFaction.faction] += totalAR;
                        targetFar -= totalAR;
                        targetWarFaction.defenseTargets.Add(system.name);
                    }
                    else
                    {
                        system.influenceTracker[warFaction.faction] += targetFar;
                        targetFar = 0;
                    }
                }
            }
        }
Example #13
0
        public static void AllocateDefensiveResources(WarFaction warFaction, bool useFullSet)
        {
            if (warFaction.defenseTargets.Count == 0)
            {
                return;
            }

            var faction            = warFaction.faction;
            var defensiveResources = warFaction.DefensiveResources + warFaction.DR_Against_Pirates;

            if (warFaction.ComstarSupported)
            {
                defensiveResources += Globals.Settings.GaW_Police_DRBonus;
            }
            warFaction.DR_Against_Pirates = 0;
            if (Globals.Settings.AggressiveToggle && Globals.Settings.DefensiveFactions.Contains(warFaction.faction))
            {
                defensiveResources += Globals.Sim.Constants.Finances.LeopardBaseMaintenanceCost;
            }
            var defensiveCorrection = defensiveResources * (100 * Globals.Settings.GlobalDefenseFactor -
                                                            Globals.Settings.DResourceAdjustmentPerCycle * warFaction.DaysSinceSystemLost) / 100;

            defensiveResources  = Math.Max(defensiveResources, defensiveCorrection);
            defensiveResources += defensiveResources * (float)(Globals.Rng.Next(-1, 1) * Globals.Settings.ResourceSpread);
            var startingDefensiveResources = defensiveResources;
            var map = new Dictionary <string, SystemStatus>();

            foreach (var defenseTarget in warFaction.defenseTargets.Distinct())
            {
                map.Add(defenseTarget, Globals.WarStatusTracker.systems.Find(x => x.name == defenseTarget));
            }

            // spend and decrement defensiveResources
            while (defensiveResources > float.Epsilon)
            {
                var highest        = 0f;
                var highestFaction = faction;
                var drFactor       = Random.Range(Globals.Settings.MinimumResourceFactor, Globals.Settings.MaximumResourceFactor);
                var spendDr        = Mathf.Min(startingDefensiveResources * drFactor, defensiveResources);
                spendDr = spendDr < 1 ? 1 : Math.Max(1 * Globals.SpendFactor, spendDr * Globals.SpendFactor);

                var systemStatus = map.GetRandomElement().Value;
                if (systemStatus == null)
                {
                    LogDebug("NULL SystemStatus at AllocateDefensiveResources");
                    return;
                }

                if (systemStatus.Contended || Globals.WarStatusTracker.HotBox.Contains(systemStatus.name))
                {
                    warFaction.defenseTargets.Remove(systemStatus.starSystem.Name);
                    if (warFaction.defenseTargets.Count == 0 || warFaction.defenseTargets == null)
                    {
                        break;
                    }

                    continue;
                }

                var total    = systemStatus.influenceTracker.Values.Sum();
                var sequence = systemStatus.influenceTracker
                               .Where(x => x.Value != 0)
                               .Select(x => x.Key);
                foreach (var factionStr in sequence)
                {
                    if (systemStatus.influenceTracker[factionStr] > highest)
                    {
                        highest        = systemStatus.influenceTracker[factionStr];
                        highestFaction = factionStr;
                    }

                    if (highest / total >= 0.5)
                    {
                        break;
                    }
                }

                if (highestFaction == faction)
                {
                    if (defensiveResources > 0)
                    {
                        systemStatus.influenceTracker[faction] += spendDr;
                        defensiveResources -= spendDr;
                    }
                    else
                    {
                        systemStatus.influenceTracker[faction] += defensiveResources;
                        defensiveResources = 0;
                    }
                }
                else
                {
                    var diffRes      = systemStatus.influenceTracker[highestFaction] / total - systemStatus.influenceTracker[faction] / total;
                    var bonusDefense = spendDr + (diffRes * total - Globals.Settings.TakeoverThreshold / 100 * total) / (Globals.Settings.TakeoverThreshold / 100 + 1);
                    //LogDebug(bonusDefense);
                    if (100 * diffRes > Globals.Settings.TakeoverThreshold)
                    {
                        if (defensiveResources >= bonusDefense)
                        {
                            systemStatus.influenceTracker[faction] += bonusDefense;
                            defensiveResources -= bonusDefense;
                        }
                        else
                        {
                            systemStatus.influenceTracker[faction] += Math.Min(defensiveResources, 50);
                            defensiveResources -= Math.Min(defensiveResources, 50);
                        }
                    }
                    else
                    {
                        systemStatus.influenceTracker[faction] += Math.Min(defensiveResources, 50);
                        defensiveResources -= Math.Min(defensiveResources, 50);
                    }
                }
            }
        }