public Map GenerateVillage(UInt16 width, UInt16 height)
        {
            // We need a reasonable amount of space to construct the map
            if ((width < 20) || (height < 20))
            {
                return null;
            }

            // Initializes map (currently to an all-grass space);
            Map canvas = new Map(width, height, (Int32)_randomator.NSidedDice(1000, 1));
            // Initializes a double array where we keep track of which areas of the map are complete
            //BitArray[,] painted = new BitArray[width, height];
            BitArray[] painted = new BitArray[width];
            for (int i = 0; i < width; ++i)
            {
                painted[i] = new BitArray(height);
            }

            // Put roads through the middle of the map; later we'll improve the algo
            UInt16 halfwidth = (UInt16)(width * 0.5);
            FillRectangleWithTiles(canvas, new Coords(CoordsType.Tile, halfwidth, 0), new Coords(CoordsType.Tile, halfwidth, height - 1), Constants.TileGeneratorRoadPaved);
            for (int i = 0; i < height; ++i)
            {
                painted[halfwidth][i] = true;
            }

            UInt16 halfheight = (UInt16)(height * 0.5);
            FillRectangleWithTiles(canvas, new Coords(CoordsType.Tile, 0, halfheight), new Coords(CoordsType.Tile, width - 1, halfheight), Constants.TileGeneratorRoadPaved);
            for (int i = 0; i < width; ++i)
            {
                painted[i][halfheight] = true;
            }

            // Put a house or two
            GenerateRectangularRoom(canvas, new Coords(CoordsType.Tile, halfwidth + 1, 10), new Coords(CoordsType.Tile, halfwidth + 5, 15));
            FurnishRectangularLivingRoom(canvas, new Coords(CoordsType.Tile, halfwidth + 1, 10), new Coords(CoordsType.Tile, halfwidth + 5, 15));
            GenerateRectangularRoom(canvas, new Coords(CoordsType.Tile, 6, halfheight - 5), new Coords(CoordsType.Tile, 12, halfheight - 1));
            FurnishRectangularWorkshop(canvas, new Coords(CoordsType.Tile, 6, halfheight - 5), new Coords(CoordsType.Tile, 12, halfheight - 1));

            // put a well somewhere
            canvas.CreateItem(new Coords(CoordsType.Tile, 20, 20), Constants.ItemGeneratorWell);

            // Apple tree!
            canvas.CreateItem(new Coords(CoordsType.Tile, 30, 5), Constants.ItemGeneratorTreeApple);

            canvas.AnalyzeTileAccessibility();

            return canvas;
        }
        // Generates a rectangular room
        private void GenerateRectangularRoom(Map homeMap, Coords topLeft, Coords bottomRight)
        {
            Coords difference = bottomRight - topLeft;
            if (!(difference.X > 1 && difference.Y > 1))
            {
                return;
            }

            // Walls
            FillRectangleWithTiles(homeMap, topLeft, new Coords(CoordsType.Tile, topLeft.X, bottomRight.Y), Constants.TileGeneratorWallStone);
            FillRectangleWithTiles(homeMap, topLeft, new Coords(CoordsType.Tile, bottomRight.X, topLeft.Y), Constants.TileGeneratorWallStone);
            FillRectangleWithTiles(homeMap, new Coords(CoordsType.Tile, topLeft.X, bottomRight.Y), bottomRight, Constants.TileGeneratorWallStone);
            FillRectangleWithTiles(homeMap, new Coords(CoordsType.Tile, bottomRight.X, topLeft.Y), bottomRight, Constants.TileGeneratorWallStone);

            // Floor
            this.FillRectangleWithTiles(homeMap, new Coords(CoordsType.Tile, topLeft.X + 1, topLeft.Y + 1),
                new Coords(CoordsType.Tile, bottomRight.X - 1, bottomRight.Y - 1), Constants.TileGeneratorFloorDirt);

            // Open door. For now by default door is in the top-left corner.
            Coords doorSpot = new Coords(CoordsType.Tile, topLeft.X + 1, topLeft.Y);
            homeMap.SetTile(doorSpot, new TilePassable(homeMap, doorSpot, Constants.TileGeneratorFloorDirt));
        }
 // Furnishes a rectangular room with appropriate furniture
 private void FurnishRectangularWorkshop(Map homeMap, Coords topLeft, Coords bottomRight)
 {
     // put a bed in the middle of it
     Coords toolTableLocation = new Coords(CoordsType.Tile, (Int32)((bottomRight.X + topLeft.X) * 0.5), (Int32)((bottomRight.Y + topLeft.Y) * 0.5));
     homeMap.CreateItem(toolTableLocation, Constants.ItemGeneratorToolTable);
 }
 // Furnishes a rectangular room with appropriate furniture
 private void FurnishRectangularLivingRoom(Map homeMap, Coords topLeft, Coords bottomRight)
 {
     // put a bed in the middle of it
     Coords bedLocation = new Coords(CoordsType.Tile, (Int32)((bottomRight.X + topLeft.X) * 0.5), (Int32)((bottomRight.Y + topLeft.Y) * 0.5));
     homeMap.CreateItem(bedLocation, Constants.ItemGeneratorBed);
 }
        public Creature(Map currentMap, Coords startPos, UInt16 ID, Team team, CreatureGenerator generator)
        {
            this._name = generator.name;
            this._myTeam = team;

            this._myInventory = new Inventory(this);
            this._myBitmap = generator.creatureBitmaps;
            this._radiusX = Constants.StandardUnitRadiusX;
            this._radiusY = Constants.StandardUnitRadiusY;

            this._inhabitedMap = currentMap;
            this._uniqueID = ID;
            this._inhabitedMap.MenagerieAddCreatureTo(ID, this);

            this._myCollider = _inhabitedMap.MyCollider;
            this._myVisibilityTracker = _inhabitedMap.MyVisibilityTracker;
            this._myPathfinder = _inhabitedMap.MyPathfinder;

            this._creatureBrain = new BrainRandomWalk();
            _creatureBrain.MyCreature = this;

            this._fieldOfView = new BitArray[currentMap.BoundX];
            for (int i = 0; i < currentMap.BoundX; ++i)
            {
                _fieldOfView[i] = new BitArray(currentMap.BoundY);
            }

            _statHPMax = generator.StatHPMax;
            _statHP = _statHPMax;
            _statDamage = generator.StatDamage;
            _statArmor = generator.StatArmor;
            _statSightRange = generator.StatSight;
            _statAttackTime = generator.StatAttackTime;
            _statAttackRange = generator.StatAttackRange;

            _moveSpeedMax = generator.StatMoveSpeed;
            this._moveSpeedCurrent = 0;
            _moveAcceleration = _moveSpeedMax / 10;

            Tile temp = this._inhabitedMap.GetTile(startPos);
            this.PositionDouble = new Vector(temp.PixelTopLeft() + new Coords(CoordsType.Pixel, _radiusX, _radiusY));

            this._inhabitedMap.MyCollider.RegisterCreature(this);
        }
 protected Tile(Map home, Coords position, TileGenerator generator)
     : this(home, position)
 {
     this._myName = generator.name;
     //this._visibilityCoefficient = generator.visibilityCoefficient;
     this._myBitmap = generator.tileBitmap;
 }
        // Creates the creature at startPos on the Map
        public Creature(Map currentMap, SpriteBatchCreature myBitmap, Coords startPos, UInt32 ID, UInt16 sightRange, Brain mind)
        {
            this._myInventory = new Inventory(this);
            this._myBitmap = myBitmap;
            this._radiusX = Constants.StandardUnitRadiusX;
            this._radiusY = Constants.StandardUnitRadiusY;

            this._statSightRange = sightRange;
            this._inhabitedMap = currentMap;
            this._myCollider = _inhabitedMap.MyCollider;
            this._myVisibilityTracker = _inhabitedMap.MyVisibilityTracker;
            this._myPathfinder = _inhabitedMap.MyPathfinder;

            this._uniqueID = ID;
            this._inhabitedMap.MenagerieAddCreatureTo(ID, this);

            this._creatureBrain = mind;
            mind.MyCreature = this;

            this._fieldOfView = new BitArray[currentMap.BoundX];
            for (int i = 0; i < currentMap.BoundX; ++i)
            {
                _fieldOfView[i] = new BitArray(currentMap.BoundY);
            }

            Tile temp = this.InhabitedMap.GetTile(startPos);
            this.PositionDouble = new Vector(temp.PixelTopLeft() + new Coords(CoordsType.Pixel, _radiusX, _radiusY));

            /*
            this.MyBody = new UInt16[] {Constants.StatsMax, Constants.StatsMax, Constants.StatsMax, Constants.StatsMax,
                Constants.StatsMax, Constants.StatsMax};
            */

            this._inhabitedMap.MyCollider.RegisterCreature(this);

            this._moveSpeedCurrent = 0;
        }
        public Painter(MainFrame frame, Map assignedMap, float zoom)
        {
            this._zoom = zoom;
            this._currentMap = assignedMap;
            this._mainFrame = frame;
            assignedMap.MyPainter = this;
            this._creaturesToDraw = new List<Creature>();
            this._itemsToDraw = new List<Item>();

            this.ImportSprites();
            this.RescaleSprites();
        }
        private void MainFrame_Load(object sender, System.EventArgs e)
        {
            _timer = new Timer();
            _timer.Interval = Constants.defaultTimerPeriod;
            _timer.Tick += new System.EventHandler(MainFrame_Tick);

            _zoom = Constants.ZoomDefault;

            WorldGeneration generator = new WorldGeneration(907);

            _currentMap = generator.GenerateVillage(Constants.MapSize, Constants.MapSize);
            _painter = new Painter(this, _currentMap, _zoom);

            _currentMap.AnalyzeTileAccessibility();

            Team team1 = new Team(Color.Red);
            Team team2 = new Team(Color.Blue);

            for (int j = 0; j < 2; ++j)
            {
                for (int i = 0; i < 5; ++i)
                {
                    _currentMap.SpawnCreature(new Coords(CoordsType.Tile, i, j), team1, Constants.CreatureGeneratorGnome);
                }
            }

            for (int j = 0; j < 2; ++j)
            {
                for (int i = 0; i < 5; ++i)
                {
                    _currentMap.SpawnCreature(new Coords(CoordsType.Tile, i, _currentMap.BoundY-1-j), team2, Constants.CreatureGeneratorGnome);
                }
            }

            _currentMap.SpawnPlayer(Constants.PlayerStartPos);
            //_player = _currentMap.PlayerReference;

            //_screenAnchor = this.TransformCenterAtPlayer();

            _scheduler = new Scheduler(_currentMap);
            _ledger = new Ledger(_scheduler);
            _timer.Start();
        }
 public TilePassable(Map home, Coords position, TileGenerator generator)
     : base(home, position, generator)
 {
     this._myInventory = new Inventory(this);
 }
 public TilePassable(Map home, Coords position, String name, float visibilityCoefficient, SpriteTile myBitmap)
     : base(home, position, name, visibilityCoefficient, myBitmap)
 {
     this._myInventory = new Inventory(this);
 }
 public TileImpassable(Map home, Coords position, String name, float visibilityCoefficient, SpriteTile myBitmap)
     : base(home, position, name, visibilityCoefficient, myBitmap)
 {
 }
 public TileImpassable(Map home, Coords position, TileGenerator generator)
     : base(home, position, generator)
 {
 }
 protected Tile(Map home, Coords position, String name, float visibilityCoefficient, SpriteTile myBitmap)
     : this(home, position)
 {
     this._myName = name;
     //this._visibilityCoefficient = visibilityCoefficient;
     this._myBitmap = myBitmap;
 }
        // Fills a space with tiles of "tileType"
        private void FillRectangleWithTiles(Map homeMap, Coords topLeft, Coords bottomRight, TileGenerator tileType)
        {
            Coords difference = bottomRight - topLeft;
            if (!(difference.X > -1 && difference.Y > -1))
            {
                return;
            }

            // There should be a more elegant way of dealing with the "Is it passable or impassable?" problem.
            if (tileType.passable)
            {
                for (int i = 0; i < difference.X + 1; ++i)
                {
                    for (int j = 0; j < difference.Y + 1; ++j)
                    {
                        Coords currentCoords = new Coords(CoordsType.Tile, topLeft.X + i, topLeft.Y + j);
                        homeMap.SetTile(currentCoords, new TilePassable(homeMap, currentCoords, tileType));
                    }
                }
            }
            else
            {
                for (int i = 0; i < difference.X + 1; ++i)
                {
                    for (int j = 0; j < difference.Y + 1; ++j)
                    {
                        Coords currentCoords = new Coords(CoordsType.Tile, topLeft.X + i, topLeft.Y + j);
                        homeMap.SetTile(currentCoords, new TileImpassable(homeMap, currentCoords, tileType));
                    }
                }
            }
        }
        // Constructor. Map and source are necessarily passed. The influence function can be made to  
        // have a default value.
        public InfluenceSourceMap(Map currentMap, Coords source, InfluenceSpreadFunction f)
        {
            this._currentMap = currentMap;
            this._source = source;
            this._f = f;

            // zero our the floats
            this._influenceMap = new float[_currentMap.BoundX, _currentMap.BoundY];
        }
 public Scheduler(Map gamemap)
 {
     this._gameMap = gamemap;
 }
 private Tile(Map home, Coords position)
 {
     this.InhabitedMap = home;
     this.Position = position;
 }