Beispiel #1
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="unitType">The type of the unit to train</param>
 /// <param name="quantity">The number of combatants to train</param>
 /// <param name="isOrderStanding">Whether the order should be executed every turn</param>
 public UnitTrainingOrder(UnitType unitType, int quantity, bool isOrderStanding)
 {
     _unitType = unitType;
     _data     = new UnitTrainingOrderData(unitType.GetId(), quantity, isOrderStanding);
 }
Beispiel #2
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="data">Serialized unit training order data</param>
 /// <param name="unitTypes">Hash of unit type id => unit type of in-game units</param>
 public UnitTrainingOrder(UnitTrainingOrderData data, Dictionary <int, UnitType> allUnitTypes)
 {
     _data     = data;
     _unitType = allUnitTypes[_data.id];
 }
Beispiel #3
0
    /// <summary>
    /// Class constructor
    /// </summary>
    /// <param name="data">Province data loaded from a save</param>
    /// <param name="dwellers">Race that populates the province</param>
    /// <param name="owners">Faction that owns the province</param>
    /// <param name="allUnitTypes">A hash of id => unit type that includes all unit types in the game</param>
    public Province(ProvinceData data, Race dwellers, Faction owners, Dictionary <int, UnitType> allUnitTypes)
    {
        _data     = data;
        _dwellers = dwellers;
        _owners   = owners;

        if (_data.raceId != dwellers.GetId())
        {
            Debug.Log("Bad race data for province " + _data.id + ": " + _data.raceId + " is changed to " + dwellers.GetId());
            _data.raceId = dwellers.GetId();
        }

        if (_data.factionId != owners.GetId())
        {
            Debug.Log("Bad faction data for province " + _data.id + ": " + _data.factionId + " is changed to " + owners.GetId());
            _data.factionId = owners.GetId();
        }

        _neighbors = new List <Province>();

        _units = new List <Unit>();
        for (int i = 0; i < data.units.Length; i++)
        {
            _units.Add(new Unit(data.units[i], allUnitTypes[data.units[i].id]));
        }

        _trainingOrders = new Dictionary <UnitType, UnitTrainingOrder>();
        if (data.training != null && data.training.Length > 0)
        {
            for (int i = 0; i < data.training.Length; i++)
            {
                UnitTrainingOrderData order = data.training[i];
                // order.id is unit type id just for conspiration
                UnitType unitType = allUnitTypes[order.id];
                _trainingOrders[unitType] = new UnitTrainingOrder(order, allUnitTypes);
            }
        }

        _trainable = new List <UnitType>();
        int minTrainingCost = 100500; // means "a lot"

        // if the province doesn't have defined trainable unit types, use the list of racial units
        if (_data.trainable == null || _data.trainable.Length == 0)
        {
            List <UnitType> racialUnits = _dwellers.GetRacialUnits();
            for (int i = 0; i < racialUnits.Count; i++)
            {
                // heroes can't be trained
                if (racialUnits[i].IsTrainable())
                {
                    _trainable.Add(racialUnits[i]);
                    if (!racialUnits[i].IsHoly())
                    {
                        minTrainingCost = Math.Min(minTrainingCost, racialUnits[i].GetTrainingCost());
                    }
                }
            }
        }
        else
        {
            for (int i = 0; i < _data.trainable.Length; i++)
            {
                UnitType unitType = allUnitTypes[_data.trainable[i]];
                if (unitType != null && unitType.IsTrainable())
                {
                    _trainable.Add(unitType);
                    if (!unitType.IsHoly())
                    {
                        minTrainingCost = Math.Min(minTrainingCost, unitType.GetTrainingCost());
                    }
                }
            }
        }

        SelectCheapestToTrainUnits(minTrainingCost);
    }