예제 #1
0
        bool Allocate(MilitaryUnitType type, int amount)
        {
            var troop         = GetTroop(type);
            var previousValue = troop == null ? 0 : troop.count;

            if (troop == null)
            {
                Debug.Log("No previous deployment for " + type + " on current order.");
                troop = Military.Allocate(Game.GetParticipant(data.participantId), Game.Map.GetProvince(data.pathByRegionNames[0]), type, amount);
                if (troop == null)
                {
                    Debug.LogWarning("Can't fulfill allocation!");
                    return(false);
                }
                var newUnits = new MilitaryUnit[data.troops.Length + 1];
                Array.Copy(data.troops, newUnits, data.troops.Length);
                newUnits[newUnits.Length - 1] = troop;
                data.troops = newUnits;
            }
            else
            {
                Military.AllocateInto(ref troop, Game.GetParticipant(data.participantId), Game.Map.GetProvince(data.pathByRegionNames[0]), type, amount);
            }

            return(previousValue != troop.count);
        }
예제 #2
0
 public MilitaryUnit join(MilitaryUnit other)
 {
     if (Joinable(this, other))
     {
         other.count += this.count;
         this.count   = 0;
     }
     return(other);
 }
예제 #3
0
        public MilitaryUnit template(int count, bool deployed)
        {
            var newUnit = new MilitaryUnit();

            newUnit.attack  = new int[attack.Length];
            newUnit.defence = new int[defence.Length];
            System.Array.Copy(attack, newUnit.attack, attack.Length);
            System.Array.Copy(defence, newUnit.defence, defence.Length);

            newUnit.constructionTimes    = constructionTimes;
            newUnit.constructionProgress = constructionProgress;
            newUnit._deployed            = deployed;

            newUnit.location = location;
            newUnit.name     = name;
            newUnit.count    = count;

            return(newUnit);
        }
예제 #4
0
 static bool Joinable(MilitaryUnit a, MilitaryUnit b)
 {
     return(a.type == b.type && a.available && b.available && a.location == b.location);
 }