예제 #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 static Queue <MilitaryUnit> AllUnits(MilitaryUnitType type)
 {
     if (Tile.SelectLock == null)
     {
         return(new Queue <MilitaryUnit>());
     }
     else
     {
         return(AllUnits(Tile.SelectLock, Game.activeUserID, type));
     }
 }
예제 #3
0
 MilitaryUnit GetTroop(MilitaryUnitType type)
 {
     for (int i = 0; i < data.troops.Length; i++)
     {
         if (data.troops[i].type == type)
         {
             return(data.troops[i]);
         }
     }
     return(null);
 }
예제 #4
0
 public bool ChangeTroopAllocation(MilitaryUnitType type, int countChange)
 {
     if (countChange < 0)
     {
         return(Free(type, -countChange));
     }
     else if (countChange > 0)
     {
         return(Allocate(type, countChange));
     }
     else
     {
         return(false);
     }
 }
예제 #5
0
        static public bool Construct(Participant participant, Tile region, MilitaryUnitType type, int quantity)
        {
            for (int i = 0; i < instance.unitTypes.Length; i++)
            {
                if (instance.unitTypes[i].type == type)
                {
                    var newUnit = instance.unitTypes[i].template(quantity);
                    newUnit.commander = participant.ID;
                    newUnit.location  = region.name;

                    instance.armies.Add(newUnit);
                    return(true);
                }
            }
            Debug.LogWarning("No model found for type " + type);
            return(false);
        }
예제 #6
0
        bool Free(MilitaryUnitType type, int amount)
        {
            var troop = GetTroop(type);

            if (amount <= 0 || troop == null || troop.count < amount)
            {
                return(false);
            }

            var success = Military.FreeFrom(ref troop, amount);

            if (!troop.deployed || troop.count == 0)
            {
                data.troops = data.troops.Where(t => t != troop).ToArray();
            }

            return(success);
        }
예제 #7
0
        public static Queue <MilitaryUnit> AllUnits(Tile region, int participantID, MilitaryUnitType type)
        {
            var units = new Queue <MilitaryUnit>();

            if (region == null)
            {
                return(units);
            }

            var allArmies = instance.armies;

            for (int i = 0, l = allArmies.Count; i < l; i++)
            {
                if (allArmies[i].type == type && allArmies[i].commander == participantID && allArmies[i].location == region.name)
                {
                    units.Enqueue(allArmies[i]);
                }
            }
            return(units);
        }
예제 #8
0
        public static MilitaryUnit Allocate(Participant participant, Tile region, MilitaryUnitType unitType, int quantity)
        {
            var armies = instance.armies;

            for (int i = 0, l = armies.Count; i < l; i++)
            {
                if (IsMatchingAndAvailable(armies[i], participant, region, unitType, quantity))
                {
                    var unit = armies[i];
                    if (unit.count == quantity)
                    {
                        unit.Deploy();
                        return(unit);
                    }

                    var newUnit = unit.split(quantity);
                    newUnit.Deploy();
                    instance.armies.Add(newUnit);
                    return(newUnit);
                }
            }

            return(null);
        }
예제 #9
0
        public static void AllocateInto(ref MilitaryUnit targetUnit, Participant participant, Tile region, MilitaryUnitType unitType, int quantity)
        {
            var additions = Allocate(participant, region, unitType, quantity);

            if (additions != null)
            {
                Debug.Log("Got addition of " + additions.count + " to add to the current " + targetUnit);
                additions.Free();
                targetUnit.Free();
                additions.join(targetUnit);
                targetUnit.Deploy();
                instance.armies.Remove(additions);
            }
            else
            {
                Debug.Log("Couldn't allocate into as no unit got allocated");
            }
        }
예제 #10
0
 static bool IsMatchingAndAvailable(MilitaryUnit unit, Participant participant, Tile region, MilitaryUnitType unitType)
 {
     return(unit.commander == participant.ID && unit.type == unitType && unit.location == region.name && unit.available);
 }
예제 #11
0
 static bool IsMatchingAndAvailable(MilitaryUnit unit, Participant participant, Tile region, MilitaryUnitType unitType, int count)
 {
     return(IsMatchingAndAvailable(unit, participant, region, unitType) && unit.count >= count);
 }
예제 #12
0
        public int GetTroopAllocation(MilitaryUnitType type)
        {
            var details = GetTroop(type);

            return(details == null ? 0 : details.count);
        }
예제 #13
0
 public MilitaryUnit(GameObject gameObject, MilitaryUnitType unitType) : base(gameObject)
 {
     this.unitType = unitType;
 }