コード例 #1
0
        /// <summary>
        /// Creates a unit.
        /// </summary>
        /// <param name="position">Position of unit.</param>
        /// <param name="owner">Owner of this unit.</param>
        public Unit(Player owner, Vector2 position, Entity baseEntity) : base(position, owner)
        {
            this.BaseEntity   = baseEntity;
            this.returnToBase = (baseEntity != null);

            this.DisperseDistance = 1.5f;
            this.position         = position;
            this.angle            = 0;
            this.isDead           = false;
            this.owner            = owner;
            this.rand             = new Random(id++);

            this.IsAggressive = true;

            world.GetMap().GetTile((int)position.X, (int)position.Y).AddUnit(this);
            world.AddUnit(this);
        }
コード例 #2
0
        //############## Construction ##############//
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="p_world"></param>
        public AIView(World p_world)
        {
            log = Utility.Logger.LoggerFactory.GetLogger();
            //LoggerFactory.globalThreshold = LogLevel.FATAL;

            world = p_world;
            mapHeight = world.GetMap().map.GetLength(1);
            mapWidth = world.GetMap().map.GetLength(0);

            myBuildings = new List<Building>();

            opponents = world.players; //Remove the AI player when it has called RegisterPlayer

            friendlyPoints = new List<Vector2>();
            resourcePoints = new List<Vector2>();
            enemyPoints = new List<Vector2>();
        }
コード例 #3
0
        /// <summary>
        /// Returns the Tile located in the given coordinates provided that it is visible.
        /// If it is not visible, null is returned.
        /// </summary>
        /// <param name="coords"></param>
        /// <param name="world"></param>
        /// <returns></returns>
        public static Tile GetTileAt(Vector2 coords, World world)
        {
            //log.Fatal("Accessing Tile at "+coords.X+","+coords.Y);
            Tile tempTile = world.GetMap().GetTile((int)coords.X, (int)coords.Y);

            ///* Uncomment when fog of war is properly implemented
            //if (tempTile.IsVisible(ai))
            //{
            //    return tempTile;
            //}

            return(tempTile);
        }
コード例 #4
0
        /// <summary>
        /// Returns the Tile located in the given coordinates provided that it is visible.
        /// If it is not visible, null is returned.
        /// </summary>
        /// <param name="coords"></param>
        /// <param name="world"></param>
        /// <returns></returns>
        public static Tile GetTileAt(Vector2 coords, World world)
        {
            //log.Fatal("Accessing Tile at "+coords.X+","+coords.Y);
            Tile tempTile = world.GetMap().GetTile((int)coords.X, (int)coords.Y);

            ///* Uncomment when fog of war is properly implemented
            //if (tempTile.IsVisible(ai))
            //{
            //    return tempTile;
            //}

            return tempTile;
        }
コード例 #5
0
        /// <summary>
        /// Returns two points with the interval of wich the building can be built in.
        /// The points is returned inclusively, both points are valid coordinates. 
        /// </summary>
        /// <param name="sourceBuildingPosition"></param>
        /// <param name="world"></param>
        /// <returns>First in the list is the upperLeft point and the last is the lowerRight point.</returns>
        public static List<Point> GetValidBuildingInterval(Vector2 sourceBuildingPosition, World world)
        {
            List<Point> retur = new List<Point>(2);
            Point upperLeft = new Point(
                (int)MathHelper.Clamp(sourceBuildingPosition.X - MAX_BUILDING_RANGE, 1, world.GetMap().width-2),
                (int)MathHelper.Clamp(sourceBuildingPosition.Y - MAX_BUILDING_RANGE, 1, world.GetMap().height-2));
            Point lowerRight = new Point(
                (int)MathHelper.Clamp(sourceBuildingPosition.X + MAX_BUILDING_RANGE, 1, world.GetMap().width-2),
                (int)MathHelper.Clamp(sourceBuildingPosition.Y + MAX_BUILDING_RANGE, 1, world.GetMap().height-2));

            retur.Add(upperLeft);
            retur.Add(lowerRight);

            return retur;
        }
コード例 #6
0
        /// <summary>
        /// Create the list of tiles that the fromBuilding is surrounded with and the
        /// tile it is placed on.
        /// </summary>
        /// <param name="middleTile">The coordinates for the tile the fromBuilding is built on.</param>
        /// <param name="world">The world the fromBuilding is being built in.</param>
        /// <returns></returns>
        public static LinkedList<Tile> CreateControlZone(Vector2 middleTile, World world)
        {
            LinkedList<Tile> retur = new LinkedList<Tile>();

            //Iterate over the tiles that shall be added to the list
            for (int dx = -1; dx <= 1; dx++)
            {
                for (int dy = -1; dy <= 1; dy++)
                {
                    //The tile the fromBuilding is standing on shall be first in the
                    //linked list.
                    if (dx == 0 && dy == 0)
                    {
                        retur.AddFirst(world.GetMap().GetTile(dx + (int)middleTile.X, dy + (int)middleTile.Y));
                    }
                    //The other tiles shall be appended to the list
                    else
                    {
                        try
                        {
                            retur.AddLast(world.GetMap().GetTile(dx + (int)middleTile.X, dy + (int)middleTile.Y));
                        }
                        catch (IndexOutOfRangeException e)
                        {
                            logger.Error(e.Message);
                            //The fromBuilding is being built close to an edge
                            //the exception is not handled.
                        }
                    }
                }
            }
            return retur;
        }