Пример #1
0
 /// <summary>
 /// Constructs and initializes a graph with a single basebuilding.
 /// </summary>
 public Graph(BaseBuilding baseBuilding)
     : this()
 {
     buildings.Add(baseBuilding, defaultWeight);
     this.baseBuilding = baseBuilding;
     TotalWeight += defaultWeight;
 }
 public void init()
 {
     this.p = new Player();
     this.bb = new BaseBuilding("test", 0, 0, new Player(), new LinkedList<Tile>());
     this.g = new Graph(bb);
     this.ua = new UnitAccountant(p);
     this.p.AddGraph(g);
 }
 /// <summary>
 /// Constructs a new ResourceBuilding
 /// </summary>
 /// <param name="name"></param>
 /// <param name="posX"></param>
 /// <param name="posY"></param>
 /// <param name="maxHealth"></param>
 /// <param name="owner"></param>
 /// <param name="baseBuilding"></param>
 public ResourceBuilding(String name, int posX, int posY,
     Player owner, BaseBuilding baseBuilding, LinkedList<Tile> controlZone)
     : base(name, posX, posY, RESOURCE_BUILDING_HEALTH, owner, Globals.BuildingTypes.Resource, baseBuilding,controlZone)
 {
     this.rateOfProduction = controlZone.First().GetTerrainType().getResourceModifier() + DEFAULT_PRODUCTION;
     if (baseBuilding != null)
     {
         baseBuilding.RateOfProduction += this.rateOfProduction;
     }
 }
Пример #4
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>());
 }
        public void Init()
        {
            b1 = new BaseBuilding("test", 0, 0, new Player(), new LinkedList<Tile>());
            b2 = new TestBuilding();
            b3 = new TestBuilding();

            ba = new BaseBuilding("test", 0, 0, new Player(), new LinkedList<Tile>());
            bb = new TestBuilding();
            bc = new TestBuilding();

            gc = GraphController.Instance;
        }
 /// <summary>
 /// Constructs a new BarrierBuilding
 /// </summary>
 /// <param name="name"></param>
 /// <param name="posX"></param>
 /// <param name="posY"></param>
 /// <param name="owner"></param>
 /// <param name="baseBuilding"></param>
 public BarrierBuilding(String name, int posX, int posY,
     Player owner, BaseBuilding baseBuilding, LinkedList<Tile> controlZone)
     : base(name, posX, posY, BARRIER_BUILDING_HEALTH, owner, Globals.BuildingTypes.Barrier, baseBuilding,
     controlZone)
 {
     foreach(Tile t in controlZone)
     {
         t.unitsChanged += BarrierBuilding_unitsChanged;
         foreach(Unit u in t.GetUnits(owner))
         {
             u.Buff = powerBonus;
         }
     }
 }
 /// <summary>
 /// Constructs a new BarrierBuilding
 /// </summary>
 /// <param name="name"></param>
 /// <param name="posX"></param>
 /// <param name="posY"></param>
 /// <param name="owner"></param>
 /// <param name="baseBuilding"></param>
 public BarrierBuilding(String name, int posX, int posY,
                        Player owner, BaseBuilding baseBuilding, LinkedList <Tile> controlZone)
     : base(name, posX, posY, BARRIER_BUILDING_HEALTH, owner, Globals.BuildingTypes.Barrier, baseBuilding,
            controlZone)
 {
     foreach (Tile t in controlZone)
     {
         t.unitsChanged += BarrierBuilding_unitsChanged;
         foreach (Unit u in t.GetUnits(owner))
         {
             u.Buff = powerBonus;
         }
     }
 }
Пример #8
0
        /// <summary>
        /// Constructs a new AgressiveBuilding
        /// </summary>
        /// <param name="name"></param>
        /// <param name="posX"></param>
        /// <param name="posY"></param>
        /// <param name="maxHealth"></param>
        /// <param name="owner"></param>
        /// <param name="baseBuilding"></param>
        public AggressiveBuilding(String name, int posX, int posY, Player owner, BaseBuilding baseBuilding,
                                  LinkedList <Tile> controlZone)
            : base(name, posX, posY, AGGRESSIVE_BUILDING_HEALTH, owner, Globals.BuildingTypes.Aggressive, baseBuilding, controlZone)
        {
            currentTargets = new List <Unit>();

            /*for(int i = 0; i < controlZone.Count; i++)
             * {
             *  controlZone.ElementAt(i).unitsChanged += AggressiveBuilding_unitsChanged;
             * }*/
            foreach (Tile t in controlZone)
            {
                t.unitsChanged += AggressiveBuilding_unitsChanged;
            }
        }
        /// <summary>
        /// Constructs a new AgressiveBuilding
        /// </summary>
        /// <param name="name"></param>
        /// <param name="posX"></param>
        /// <param name="posY"></param>
        /// <param name="maxHealth"></param>
        /// <param name="owner"></param>
        /// <param name="baseBuilding"></param>
        public AggressiveBuilding(String name, int posX, int posY, Player owner, BaseBuilding baseBuilding,
            LinkedList<Tile> controlZone)
            : base(name, posX, posY, AGGRESSIVE_BUILDING_HEALTH, owner, Globals.BuildingTypes.Aggressive, baseBuilding,controlZone)
        {
            currentTargets = new List<Unit>();

            /*for(int i = 0; i < controlZone.Count; i++)
            {
                controlZone.ElementAt(i).unitsChanged += AggressiveBuilding_unitsChanged;
            }*/
            foreach (Tile t in controlZone)
            {
                t.unitsChanged += AggressiveBuilding_unitsChanged;
            }
        }
Пример #10
0
        /// <summary>
        /// Creates a fromBuilding with specified parameters, the unit list will
        /// be initiated but empty and the current health will be set at maxHealth.
        /// Regarding the controlZone the first tile should be the 
        /// tile the fromBuilding is standing on.
        /// </summary>
        /// <param name="name">The name for the fromBuilding TODO Decide if this is
        /// needded</param>
        /// <param name="posX">The x tile coordinate</param>
        /// <param name="posY">The y tile coordinate</param>
        /// <param name="maxHealth">The max health of this fromBuilding</param>
        /// <param name="owner">The player that owns the fromBuilding</param>
        /// <param name="type">The </param>
        /// <param name="baseBuilding">The Base Building this fromBuilding belongs
        /// <param name="controlZone">The nine tiles around the fromBuilding
        /// and the tile the fromBuilding is on.</param>
        /// to</param>
        public Building(String name, int posX, int posY, int maxHealth,
            Player owner, Globals.BuildingTypes type, BaseBuilding baseBuilding,
            LinkedList<Tile> controlZone)
            : base(new Vector2(((float)posX) + 0.5f, ((float)posY) + 0.5f), owner)
        {
            if (maxHealth <= 0)
            {
                throw new ArgumentOutOfRangeException("maxHealth",
                    "The max of health may not be zero or less");

            }

            logger.Trace("Constructing new Building with choosen values");
            this.name = name;
            this.maxHealth = maxHealth;
            this.currentHealth = maxHealth;

            this.units = new List<Unit>();
            this.incomingUnits = new List<Unit>();
            this.type = type;
            this.IsAggressive = true;

            this.baseBuilding = baseBuilding;

            if (baseBuilding != null)
            {
                Accept(baseBuilding);
            }

            this.controlZone = controlZone;

            foreach (Tile t in controlZone)
            {
                t.unitsChanged += UpdateAggressiveness;
            }
        }
 /// <summary>
 /// This function will prevent the real Visit function from being called
 /// with a base fromBuilding.
 /// </summary>
 /// <param name="fromBuilding"></param>
 public void Visit(BaseBuilding building)
 {
     throw new ArgumentException("A BaseBuilding should not be added as a child building to another BaseBuilding");
 }
 /// <summary>
 /// This function will prevent the real Visit function from being called
 /// with a base fromBuilding.
 /// </summary>
 /// <param name="fromBuilding"></param>
 public void Visit(BaseBuilding building)
 {
     throw new ArgumentException("A BaseBuilding should not be added as a child building to another BaseBuilding");
 }
        /// <summary>
        /// Add a fromBuilding to the source buildings owners graph, 
        /// the source fromBuilding will be used to find the correct graph.
        /// </summary>
        /// <param name="buildingType">The type of fromBuilding to build.</param>
        /// <param name="sourceBuilding">The fromBuilding used to build this fromBuilding.</param>
        /// <param name="targetCoordinate">The tile coordinates where the fromBuilding will be built.</param>
        /// <param name="world">The world to build the fromBuilding in.</param>
        public static bool AddBuilding(Globals.BuildingTypes buildingType,
            Building sourceBuilding, Vector2 targetCoordinate, World world, Player owner)
        {
            if (sourceBuilding != null && buildingType != Globals.BuildingTypes.Base && (Math.Abs(((int)sourceBuilding.position.X) - (int)targetCoordinate.X) > MAX_BUILDING_RANGE || (Math.Abs(((int)sourceBuilding.position.Y) - (int)targetCoordinate.Y) > MAX_BUILDING_RANGE)))
            {
                logger.Debug("Building position out of range");
                throw new BuildingOutOfRangeException();
            }
            uint price = owner.unitAcc.CalculateBuildingCostInflation(buildingType);
            if (sourceBuilding != null && (uint)sourceBuilding.CountUnits() < price)
            {
                logger.Debug("Building too expensive");
                return false;
            }

            logger.Info("Building a building at position "+targetCoordinate+" of "+buildingType+".");

            lock (owner.GetGraphs())
            {
                LinkedList<Tile> controlZone = CreateControlZone(targetCoordinate, world);
                //The Base building is handled in another way due to it's nature.
                if (buildingType == Globals.BuildingTypes.Base)
                {
                    logger.Trace("Adding a Base Building and also constructing a new graph");
                    BaseBuilding baseBuilding = new BaseBuilding("Base Buidling",
                    (int)targetCoordinate.X, (int)targetCoordinate.Y, owner, controlZone);

                    world.map.GetTile((int)targetCoordinate.X, (int)targetCoordinate.Y).SetBuilding(baseBuilding);

                    owner.AddGraph(GraphController.Instance.AddBaseBuilding(baseBuilding, sourceBuilding));
                }
                else
                {
                    //The other buildings constructs in similiar ways but they are constructed
                    //as the specified type.
                    Building newBuilding = null;
                    switch (buildingType)
                    {
                        case Globals.BuildingTypes.Aggressive:
                            logger.Trace("Building a new Aggressive building");
                            newBuilding = new AggressiveBuilding("Aggresive Building",
                                (int)targetCoordinate.X, (int)targetCoordinate.Y, owner,
                                GraphController.Instance.GetGraph(sourceBuilding).baseBuilding, controlZone);
                            break;
                        case Globals.BuildingTypes.Barrier:
                            logger.Trace("Building a new Barrier building");
                            newBuilding = new BarrierBuilding("Barrier Building",
                                (int)targetCoordinate.X, (int)targetCoordinate.Y, owner,
                                GraphController.Instance.GetGraph(sourceBuilding).baseBuilding, controlZone);
                            break;
                        case Globals.BuildingTypes.Resource:
                            logger.Trace("Building a new Resource building");
                            newBuilding = new ResourceBuilding("Resource Building",
                                (int)targetCoordinate.X, (int)targetCoordinate.Y, owner,
                                GraphController.Instance.GetGraph(sourceBuilding).baseBuilding, controlZone);
                            break;
                    }

                    world.map.GetTile((int)targetCoordinate.X, (int)targetCoordinate.Y).SetBuilding(newBuilding);
                    newBuilding.Parent = sourceBuilding;
                    GraphController.Instance.AddBuilding(sourceBuilding, newBuilding);
                }
                if (sourceBuilding != null && world.map.GetTile((int)targetCoordinate.X, (int)targetCoordinate.Y).GetBuilding() != null)
                {
                    logger.Info("The building has " + sourceBuilding.CountUnits() + " and the building costs " + price);
                    owner.unitAcc.DestroyUnits(sourceBuilding.units, (int)price);
                    logger.Info("The source building only got " + sourceBuilding.CountUnits() + " units left.");
                }
                else if (world.map.GetTile((int)targetCoordinate.X, (int)targetCoordinate.Y).GetBuilding() == null)
                {
                    throw new Exception("A building was not placed on the tile even though it should have been.");
                }

                SoundsController.playSound("buildingPlacement");
            }

            // Let's update the fog of war!
            /*
            for (int i = -3; i <= 3; i++)
            {
                for (int j = -3; j <= 3; j++)
                {
                    try
                    {
                        world.map.GetTile((int)targetCoordinate.X + j, (int)targetCoordinate.Y + i).MakeVisibleTo(owner);
                    }
                    catch(IndexOutOfRangeException e)
                    {
                    }
                }
            }
             */
            return true;
        }
Пример #14
0
 /// <summary>
 /// Part of visitor pattern
 /// </summary>
 /// <param name="visitor">The Base Building this fromBuilding belongs to
 /// </param>
 public void Accept(BaseBuilding visitor)
 {
     visitor.Visit(this);
 }
Пример #15
0
 /// <summary>
 /// Constructs and initializes a graph with a single basebuilding.
 /// </summary>
 public Graph(BaseBuilding baseBuilding) : this()
 {
     buildings.Add(baseBuilding, defaultWeight);
     this.baseBuilding = baseBuilding;
     TotalWeight      += defaultWeight;
 }
Пример #16
0
        /// <summary>
        /// Part of visitor pattern
        /// </summary>
        /// <param name="visitor">The Base Building this fromBuilding belongs to
        /// </param>

        public void Accept(BaseBuilding visitor)
        {
            visitor.Visit(this);
        }