Ejemplo n.º 1
0
 public void init()
 {
     t1 = new Tile(0,0);
     t2 = new Tile(1, 1, Globals.TerrainTypes.Slow);
     p = new Player();
     u1 = new Unit(p, Vector2.Zero);
     u2 = new Unit(p, Vector2.Zero);
     u3 = new Unit(p, Vector2.Zero);
     b1 = new BaseBuilding("test", 0, 0, new Player(), new LinkedList<Tile>());
     b2 = new BarrierBuilding("TestBuilding1", 1, 1, p, b1, new LinkedList<Tile>());
 }
Ejemplo n.º 2
0
 public void RemoveUnit(Unit u)
 {
     lock (units)
     {
         this.units.Remove(u);
     }
 }
Ejemplo n.º 3
0
 public void AddUnit(Unit u)
 {
     lock (units)
     {
         units.Add(u);
     }
 }
        /// <summary>
        /// Quite possibly a horribly slow way of adding units.
        /// </summary>
        public void ProduceUnits()
        {
            Random randomer = new Random();

            uint totalUnits = owner.CountUnits();

            foreach (Graph g in owner.GetGraphs())
            {
                if (totalUnits >= POP_CAP_PER_PLAYER)
                    break;

                List<Unit> res = new List<Unit>();

                //TODO Remove when middle point position is implemented.

                BaseBuilding b = g.baseBuilding;
                if (b == null)
                {
                    continue;
                }
                int unitsToProduce = b.RateOfProduction;
                if (b.RateOfProduction + totalUnits > POP_CAP_PER_PLAYER)
                {
                    unitsToProduce = (int) (POP_CAP_PER_PLAYER - totalUnits);
                }
                logger.Debug("Producing " + unitsToProduce + " units!");
                if (unitsToProduce > 0)
                {
                    totalUnits += (uint)unitsToProduce;
                }
                for (int i = 0; i < unitsToProduce; i++)
                {
                    // Places them randomly around the fromBuilding. - John
                    // No, it does not. - Martin

                    Unit temp = new Unit(b.owner, b.position, b);

                    res.Add(temp);
                }
                b.owner.AddUnits(res);
                b.AddUnits(res);

                //This should not be needed but does not hurt i hope.
                res.Clear();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="u"></param>
        public void RemoveUnit(Unit u)
        {
            lock (units)
            {
                lock (allUnits)
                {
                    this.units[u.GetOwner()].Remove(u);
                    this.allUnits.Remove(u);

                    if (unitsChanged != null)
                    {
                        //I'm sorry for this ugly hax - John
                        List<Unit> temp = new List<Unit>();
                        temp.Add(u);
                        unitsChanged(this, new Event<IEnumerable<Unit>>(temp, EventType.REMOVE));
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void AddUnit(Unit u)
        {
            lock (units)
            {
                lock (allUnits)
                {
                    HashSet<Unit> nits;
                    if (!this.units.TryGetValue(u.GetOwner(), out nits))
                    {
                        nits = new HashSet<Unit>();
                    }

                    nits.Add(u);

                    this.units[u.GetOwner()] = nits;
                    this.allUnits.Add(u);

                    if (unitsChanged != null)
                    {
                        //I'm sorry for this ugly hax - John
                        List<Unit> temp = new List<Unit>();
                        temp.Add(u);
                        unitsChanged(this, new Event<IEnumerable<Unit>>(temp, EventType.ADD));
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Add a unit to this Tile.
        /// </summary>
        /// <param name="units">Units to be added to this Tile.</param>
        public void AddUnit(Player p, Unit u)
        {
            lock (units)
            {
                lock (allUnits)
                {
                    if (!this.units.ContainsKey(p))
                    {
                        this.units.Add(p, new HashSet<Unit>());
                    }
                    this.units[p].Add(u);
                    this.allUnits.Add(u);

                    if (unitsChanged != null)
                    {
                        //I'm sorry for this ugly hax - John
                        List<Unit> temp = new List<Unit>();
                        temp.Add(u);
                        unitsChanged(this, new Event<IEnumerable<Unit>>(temp, EventType.ADD));
                    }
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Removes one unit from the Unit list
 /// </summary>
 /// <param name="unit">The Unit to remove</param>
 public void RemoveUnit(Unit unit)
 {
     this.units.Remove(unit);
     if (unitsChanged != null)
     {
         //I'm sorry for this ugly hax - John
         List<Unit> temp = new List<Unit>();
         temp.Add(unit);
         unitsChanged(this, new BuildingEvent(this, temp,
                 EventType.REMOVE));
     }
 }
Ejemplo n.º 9
0
        //public abstract Texture2D GetSprite();
        /// <summary>
        /// Add one unit to the unit list if the fromBuilding is alive
        /// </summary>
        /// <param name="unit">The Unit to add to the list</param>
        /// <exception cref="ArgumentNullException">The Unit to add was null
        /// </exception>
        /// <exception cref="BuildingNotAliveException">
        /// The fromBuilding is dead</exception>
        public void AddUnit(Unit unit)
        {
            if(unit == null)
            {
                throw new ArgumentNullException("unit",
                    "The given parameter unit was null");
            }

            if (IsAlive())
            {
                units.Add(unit);
                if (unitsChanged != null)
                {
                    //I'm sorry for this ugly hax - John
                    List<Unit> temp = new List<Unit>();
                    temp.Add(unit);
                    unitsChanged(this, new BuildingEvent(this, temp,
                        EventType.ADD));
                }
            }
            else
            {
                throw new BuildingNotAliveException();
            }
        }
Ejemplo n.º 10
0
 public void init()
 {
     p = new Player();
     u1 = new Unit(p);
     u2 = new Unit(p);
 }
 public static void MarkUnitAsDead(Unit u)
 {
     toBeKilled.Add(u);
 }
        private static void FindEnemy(Unit u, World.Map worldMap)
        {
            if (! u.IsAggressive)
            {
                return;
            }

            Tile t = worldMap.GetTile((int)u.position.X, (int)u.position.Y);

            // Search for units
            lock (t.GetUnits())
            {
                foreach (Unit ou in t.GetUnits(u.owner.Enemy))
                {
                    // Is he dead already?
                    if (ou.isDead)
                        continue;

                    // FIGHT TO THE DEATH!
                    u.TargetEntity = ou;
                    return;
                }
            }

            // Is there a building to kill?
            if (t.GetBuilding() != null && t.GetBuilding().owner != u.owner)
            {
                u.TargetEntity = t.GetBuilding();
                return;
            }
        }