public static int CalculateAttackCost(Gang attackerGang, GangWarManager.AttackStrength attackType)
        {
            int attackTypeInt         = (int)attackType;
            int pow2NonZeroAttackType = (attackTypeInt * attackTypeInt + 1);

            return(ModOptions.instance.baseCostToTakeTurf + ModOptions.instance.baseCostToTakeTurf * attackTypeInt * attackTypeInt * attackTypeInt +
                   attackerGang.GetFixedStrengthValue() * pow2NonZeroAttackType);
        }
        public static GangWarManager.AttackStrength CalculateRequiredAttackStrength(Gang attackerGang, int defenderStrength)
        {
            GangWarManager.AttackStrength requiredAtk = GangWarManager.AttackStrength.light;

            for (int i = 0; i < 3; i++)
            {
                if (CalculateAttackerStrength(attackerGang, requiredAtk) >= defenderStrength)
                {
                    break;
                }
                else
                {
                    requiredAtk++;
                }
            }

            return(requiredAtk);
        }
Beispiel #3
0
        /// <summary>
        /// if fighting is enabled and the targetzone is controlled by an enemy, attack it! ... But only if it's affordable.
        /// if we're desperate we do it anyway
        /// </summary>
        /// <param name="targetZone"></param>
        void TryStartFightForZone(TurfZone targetZone)
        {
            Gang ownerGang = GangManager.instance.GetGangByName(targetZone.ownerGangName);

            if (ownerGang == null)
            {
                Logger.Log("Gang with name " + targetZone.ownerGangName + " no longer exists; assigning all owned turf to 'none'", 1);
                ZoneManager.instance.GiveGangZonesToAnother(targetZone.ownerGangName, "none");

                //this zone was controlled by a gang that no longer exists. it is neutral now
                if (watchedGang.moneyAvailable >= ModOptions.instance.baseCostToTakeTurf)
                {
                    watchedGang.moneyAvailable -= ModOptions.instance.baseCostToTakeTurf;
                    watchedGang.TakeZone(targetZone);
                }
            }
            else
            {
                if (GangWarManager.instance.isOccurring && GangWarManager.instance.warZone == targetZone)
                {
                    //don't mess with this zone then, it's a warzone
                    return;
                }
                //we check how well defended this zone is,
                //then figure out how large our attack should be.
                //if we can afford that attack, we do it
                int defenderStrength = GangCalculations.CalculateDefenderStrength(ownerGang, targetZone);
                GangWarManager.AttackStrength requiredStrength =
                    GangCalculations.CalculateRequiredAttackStrength(watchedGang, defenderStrength);
                int atkCost = GangCalculations.CalculateAttackCost(watchedGang, requiredStrength);

                if (watchedGang.moneyAvailable < atkCost)
                {
                    if (myZones.Count == 0)
                    {
                        //if we're out of turf and cant afford a decent attack, lets just attack anyway
                        //we use a light attack and do it even if that means our money gets negative.
                        //this should make gangs get back in the game or be wiped out instead of just staying away
                        requiredStrength = GangWarManager.AttackStrength.light;
                        atkCost          = GangCalculations.CalculateAttackCost(watchedGang, requiredStrength);
                    }
                    else
                    {
                        return;                         //hopefully we can just find a cheaper fight
                    }
                }

                if (targetZone.ownerGangName == GangManager.instance.PlayerGang.name)
                {
                    if (ModOptions.instance.warAgainstPlayerEnabled &&
                        GangWarManager.instance.CanStartWarAgainstPlayer)
                    {
                        //the player may be in big trouble now
                        watchedGang.moneyAvailable -= atkCost;
                        GangWarManager.instance.StartWar(watchedGang, targetZone, GangWarManager.WarType.defendingFromEnemy, requiredStrength);
                    }
                }
                else
                {
                    watchedGang.moneyAvailable -= atkCost;
                    int attackStrength = GangCalculations.CalculateAttackerStrength(watchedGang, requiredStrength);
                    //roll dices... favor the defenders a little here
                    if (attackStrength / RandoMath.CachedRandom.Next(1, 22) >
                        defenderStrength / RandoMath.CachedRandom.Next(1, 15))
                    {
                        watchedGang.TakeZone(targetZone);
                        watchedGang.moneyAvailable += (int)(GangCalculations.CalculateBattleRewards(ownerGang, targetZone.value, true) *
                                                            ModOptions.instance.extraProfitForAIGangsFactor);
                    }
                    else
                    {
                        ownerGang.moneyAvailable += (int)(GangCalculations.CalculateBattleRewards(watchedGang, (int)requiredStrength, false) *
                                                          ModOptions.instance.extraProfitForAIGangsFactor);
                    }
                }
            }
        }
 public static int CalculateAttackerReinforcements(Gang attackerGang, GangWarManager.AttackStrength attackType)
 {
     return(ModOptions.instance.extraKillsPerTurfValue * ((int)(attackType + 1) * (int)(attackType + 1)) + ModOptions.instance.baseNumKillsBeforeWarVictory / 2 +
            attackerGang.GetReinforcementsValue() / 100);
 }
 /// <summary>
 /// gets the reinforcement count for the attackers and estimates a total power based on that number and
 /// the gang's fixed strength value
 /// </summary>
 /// <param name="defenderGang"></param>
 /// <param name="contestedZone"></param>
 /// <returns></returns>
 public static int CalculateAttackerStrength(Gang attackerGang, GangWarManager.AttackStrength attackType)
 {
     return(attackerGang.GetFixedStrengthValue() *
            CalculateAttackerReinforcements(attackerGang, attackType));
 }