// generate target army for this combat phase public UnitMap GenerateTargetArmy(UnitPriorities unitPriorities, BuildingType plannedBuilding) { UnitMap targetArmy = new UnitMap(startingUnits); int remainingSupplyCopy = remainingSupply; // while army not full (won't cause any issues as all units currently have 1 or 2 as their supplyCost, may need changes in future) while (remainingSupplyCopy > 0) { UnitPurchaseModel model = null; while (model == null) { model = RandomlySelectUnit(unitPriorities); } UnitType type = model.unitType; if (IsUnitTrainable(type, remainingSupplyCopy, plannedBuilding)) { requiredWood += model.buildCost.GetResourceAmount(ResourceType.WOOD); requiredMagicStone += model.buildCost.GetResourceAmount(ResourceType.MAGIC_STONE); remainingSupplyCopy -= model.armySize; targetArmy.Add(type); } ; } // check if supply has gone negative if (remainingSupplyCopy != 0) { Debug.LogError("supply < 0? (=" + remainingSupplyCopy + ")"); } Debug.Log(targetArmy.StatusString()); return(targetArmy); }
// queue up target army creation public Queue <AI_GameBehaviourCommand> GetArmyConstructionCommands(UnitMap targetMap, BuildingType plannedBuilding) { // calculate units that need to be trained Queue <AI_GameBehaviourCommand> armyCommands = new Queue <AI_GameBehaviourCommand>(); UnitMap unitsToBeConstructed = startingUnits.UnitsRequiredToBecome(targetMap); Debug.Log(unitsToBeConstructed.StatusString()); // iterate over required units and add the command to the queue foreach (KeyValuePair <UnitType, int> unitMapEntry in unitsToBeConstructed.units) { UnitType type = unitMapEntry.Key; UnitPurchaseModel model = UnitPurchaseModelFactory.Create(type); int numUnits = unitMapEntry.Value; while (numUnits > 0) { if (IsUnitTrainable(type, remainingSupply, plannedBuilding)) { GameBehaviourCommand command = GetUnitToAddToQueue(type); AI_GameBehaviourCommand aiCommand = new AI_GameBehaviourCommand(command, model.buildCost); armyCommands.Enqueue(aiCommand); numUnits--; remainingSupply -= model.armySize; } else { Debug.LogError("Bad error -- cant create unit that was planned to be created"); break; } } } return(armyCommands); }
public string MapStatusString() { return(activeUnitNumbers.StatusString()); }