public static bool FormationFightingInMelee(Formation formation, float desiredRatio) { float currentTime = Mission.Current.CurrentTime; float countedUnits = 0; float ratio = 0f; float countOfUnitsFightingInMelee = 0; formation.ApplyActionOnEachUnitViaBackupList(delegate(Agent agent) { if (agent != null && ratio <= desiredRatio && ((float)countedUnits / (float)formation.CountOfUnits) <= desiredRatio) { float lastMeleeAttackTime = agent.LastMeleeAttackTime; float lastMeleeHitTime = agent.LastMeleeHitTime; if ((currentTime - lastMeleeAttackTime < 4f) || (currentTime - lastMeleeHitTime < 4f)) { countOfUnitsFightingInMelee++; } countedUnits++; } }); if (countOfUnitsFightingInMelee / formation.CountOfUnits >= desiredRatio) { return(true); } return(false); }
public static Agent NearestAgentFromFormation(Vec2 unitPosition, Formation targetFormation) { Agent targetAgent = null; float distance = 10000f; targetFormation.ApplyActionOnEachUnitViaBackupList(delegate(Agent agent) { float newDist = unitPosition.Distance(agent.GetWorldPosition().AsVec2); if (newDist < distance) { targetAgent = agent; distance = newDist; } }); return(targetAgent); }
public static bool FormationActiveSkirmishersRatio(Formation formation, float desiredRatio) { float ratio = 0f; int countOfSkirmishers = 0; if (formation != null) { formation.ApplyActionOnEachUnitViaBackupList(delegate(Agent agent) { //float currentTime = MBCommon.TimeType.Mission.GetTime(); //if (currentTime - agent.LastRangedAttackTime < 6f) //{ // countOfSkirmishers++; //} bool isActiveSkrimisher = false; float countedUnits = 0f; float currentTime = Mission.Current.CurrentTime; if (currentTime - agent.LastRangedAttackTime < 7f && ratio <= desiredRatio && ((float)countedUnits / (float)formation.CountOfUnits) <= desiredRatio) { for (EquipmentIndex equipmentIndex = EquipmentIndex.WeaponItemBeginSlot; equipmentIndex < EquipmentIndex.NumAllWeaponSlots; equipmentIndex++) { if (agent.Equipment != null && !agent.Equipment[equipmentIndex].IsEmpty) { if (agent.Equipment[equipmentIndex].Item.Type == ItemTypeEnum.Thrown && agent.Equipment[equipmentIndex].Amount > 1) { isActiveSkrimisher = true; break; } } } } if (isActiveSkrimisher) { countOfSkirmishers++; } countedUnits++; ratio = (float)countOfSkirmishers / (float)formation.CountOfUnits; }); if (ratio > desiredRatio) { return(true); } } return(false); }
public static bool CheckIfMountedSkirmishFormation(Formation formation, float desiredRatio) { if (formation != null && formation.QuerySystem.IsCavalryFormation) { float ratio = 0f; int mountedSkirmishersCount = 0; int countedUnits = 0; formation.ApplyActionOnEachUnitViaBackupList(delegate(Agent agent) { bool ismountedSkrimisher = false; if (ratio <= desiredRatio && ((float)countedUnits / (float)formation.CountOfUnits) <= desiredRatio) { for (EquipmentIndex equipmentIndex = EquipmentIndex.WeaponItemBeginSlot; equipmentIndex < EquipmentIndex.NumAllWeaponSlots; equipmentIndex++) { if (agent.Equipment != null && !agent.Equipment[equipmentIndex].IsEmpty) { if (agent.MountAgent != null && agent.Equipment[equipmentIndex].Item.Type == ItemTypeEnum.Thrown && agent.Equipment[equipmentIndex].Amount > 0) { ismountedSkrimisher = true; break; } } } } if (ismountedSkrimisher) { mountedSkirmishersCount++; } countedUnits++; ratio = (float)mountedSkirmishersCount / (float)formation.CountOfUnits; }); if (ratio > desiredRatio) { return(true); } } return(false); }
static void PostfixManageFormationCounts(ref Formation ____leftCavalry, ref Formation ____rightCavalry) { if (____leftCavalry != null && ____rightCavalry != null) { List <Agent> mountedSkirmishersList = new List <Agent>(); List <Agent> mountedMeleeList = new List <Agent>(); ____leftCavalry.ApplyActionOnEachUnitViaBackupList(delegate(Agent agent) { bool ismountedSkrimisher = false; for (EquipmentIndex equipmentIndex = EquipmentIndex.WeaponItemBeginSlot; equipmentIndex < EquipmentIndex.NumAllWeaponSlots; equipmentIndex++) { if (agent.Equipment != null && !agent.Equipment[equipmentIndex].IsEmpty) { if (agent.Equipment[equipmentIndex].Item.Type == ItemTypeEnum.Thrown && agent.MountAgent != null) { ismountedSkrimisher = true; break; } } } if (ismountedSkrimisher) { mountedSkirmishersList.Add(agent); } else { mountedMeleeList.Add(agent); } }); ____rightCavalry.ApplyActionOnEachUnitViaBackupList(delegate(Agent agent) { bool ismountedSkrimisher = false; for (EquipmentIndex equipmentIndex = EquipmentIndex.WeaponItemBeginSlot; equipmentIndex < EquipmentIndex.NumAllWeaponSlots; equipmentIndex++) { if (agent.Equipment != null && !agent.Equipment[equipmentIndex].IsEmpty) { if (agent.Equipment[equipmentIndex].Item.Type == ItemTypeEnum.Thrown && agent.MountAgent != null) { ismountedSkrimisher = true; break; } } } if (ismountedSkrimisher) { mountedSkirmishersList.Add(agent); } else { mountedMeleeList.Add(agent); } }); int j = 0; int cavalryCount = ____leftCavalry.CountOfUnits + ____rightCavalry.CountOfUnits; foreach (Agent agent in mountedSkirmishersList.ToList()) { if (j < cavalryCount / 2) { agent.Formation = ____leftCavalry; } else { agent.Formation = ____rightCavalry; } j++; } foreach (Agent agent in mountedMeleeList.ToList()) { if (j < cavalryCount / 2) { agent.Formation = ____leftCavalry; } else { agent.Formation = ____rightCavalry; } j++; } } }