public static AssaultTemplate GetAssualtTemplate(Fortification toAssault, ArmyBlueprint subArmy) { bool isPossibleAssault = true; ushort simulationDamage = 0; if (!toAssault.IsPlaceHolderFort) { float damageRatio = 1; if (subArmy.Damage > 0) { damageRatio = (float)toAssault.Defense / subArmy.Damage; } // The more damage an army has the faster it will take the city simulationDamage = (ushort)(toAssault.Offense * damageRatio); ushort damageReduction = (ushort)(subArmy.Soldiers.Count > 1 ? (subArmy.Soldiers.Count - 1 * ArmyConstants.SOLDIER_STACKING_DEFENCE) * subArmy.Soldiers.Count : 0); simulationDamage = (ushort)(damageReduction > simulationDamage ? 0 : simulationDamage - damageReduction); isPossibleAssault = subArmy.Health > simulationDamage && subArmy.Damage >= toAssault.Defense || toAssault.IsPlaceHolderFort; } // else fort damage is zero so just put it through return(isPossibleAssault ? new AssaultTemplate(toAssault, subArmy, simulationDamage) : null); }
public Fortification(Fortification copy) { Position = copy.Position; IsPlaceHolderFort = copy.IsPlaceHolderFort; FortificationId = copy.FortificationId; FortificationLevel = copy.FortificationLevel; }
public void BeginInvasion(Vector2 invasionDirection) // north south east west { Vector2 invasionPoint = -invasionDirection * NationSize / 2; if (mLoadedFromFile) { foreach (Fortification fort in Fortifications) { IsCapturedMap.Add(fort.FortificationId, false); // all forts start off not captured mNumProtectorsMap.Add(fort.FortificationId, 0); mInvasionOrderingsMap.Add(fort.FortificationId, new HashSet <int>()); } } var sortedFortifications = new List <Fortification>(Fortifications); sortedFortifications.Sort(delegate(Fortification lhs, Fortification rhs) { return((invasionPoint - rhs.PositionInNation(NationSize)).sqrMagnitude.CompareTo((invasionPoint - lhs.PositionInNation(NationSize)).sqrMagnitude)); }); for (int closestToInvasion = sortedFortifications.Count - 1; closestToInvasion > 0; --closestToInvasion) { Fortification protectingFortification = sortedFortifications[closestToInvasion]; for (int protectedCity = closestToInvasion - 1; protectedCity >= 0; --protectedCity) { Fortification protectedFortification = sortedFortifications[protectedCity]; Vector2 deltaProtector = protectingFortification.PositionInNation(NationSize) - invasionPoint; Vector2 deltaProtected = protectedFortification.PositionInNation(NationSize) - invasionPoint; Vector2 protectionLine = protectedFortification.PositionInNation(NationSize) - protectingFortification.PositionInNation(NationSize); float rowsBehind = Vector2.Dot(invasionDirection, protectionLine); float columnsBehind = 0; if (invasionDirection.x == 0) { columnsBehind = Mathf.Abs(protectionLine.x); } else { columnsBehind = Mathf.Abs(protectionLine.y); } if (rowsBehind > 0 && columnsBehind <= rowsBehind) { mInvasionOrderingsMap[protectingFortification.FortificationId].Add(protectedFortification.FortificationId); mNumProtectorsMap[protectedFortification.FortificationId]++; } } } }
private void PopulateFortifications(bool[,] fortificationGrid) { int numGridElements = NationSize * NationSize; for (int column = 0; column < NationSize; column++) { for (int row = 0; row < NationSize; row++) { int product = row * NationSize; if (fortificationGrid[row, column]) { Fortification fort = new Fortification(product + column, Fortifications.Count); Fortifications.Add(fort); IsCapturedMap.Add(fort.FortificationId, false); // all forts start off not captured mNumProtectorsMap.Add(fort.FortificationId, 0); mInvasionOrderingsMap.Add(fort.FortificationId, new HashSet <int>()); } } } }
private void PopulateFortifications(int numFortsToPopulate) { Debug.Assert(NationSize % 2 == 1); Fortification[,] fortGrid = new Fortification[NationSize, NationSize]; int numGridElements = NationSize * NationSize; for (int column = 0; column < NationSize && Fortifications.Count < numFortsToPopulate; column++) { for (int row = 0; row < NationSize && Fortifications.Count < numFortsToPopulate; row++) { int product = row * NationSize; if ((numFortsToPopulate - Fortifications.Count) == (numGridElements - (product + column)) || // have to place the rest of the forts UnityEngine.Random.Range(1f, 1f) >= 0.5f) { Fortification fort = new Fortification(product + column, Fortifications.Count); Fortifications.Add(fort); IsCapturedMap.Add(fort.FortificationId, false); // all forts start off not captured mNumProtectorsMap.Add(fort.FortificationId, 0); mInvasionOrderingsMap.Add(fort.FortificationId, new HashSet <int>()); } } } }
public AssaultTemplate(Fortification toAssault, ArmyBlueprint invaders, ushort fortDamage) { ToAssault = toAssault; Attackers = invaders; CalculatedFortDamage = fortDamage; }