private void HandlerMouse_LeftButton_GeneralArea(MouseState mouse) { // try to drop selected item if (_itemSelected != null) { Tile tileUnderAgent = _currentMap.GetTile(_selectedCreature.PositionGet()); if (!tileUnderAgent.MyInventory.Full() && _selectedCreature.GetStatBasic(Creature.StatBasic.AP, true) >= _selectedCreature.GetAPActionCost(APCostTypes.ItemDrop)) { // drop item //tileUnderAgent.MyInventory.ItemAddToList(_selectedItem); ActionItemDrop action = new ActionItemDrop(_selectedCreature, _itemSelected); _myGame.ExecuteAction(action); _itemSelected = null; } } // try to select tenant else { Coords selectedHex = ClickedHex(new Vector2(mouse.X, mouse.Y), _myDrawer.ScreenAnchor); _selectedCreature = _currentMap.TenancyMap[selectedHex.X, selectedHex.Y]; if (_selectedCreature != null) { _selectedCreature.MyMoveRangeCalculator.Update(); } } }
public Item ItemPick() { Tile currentTile = _inhabitedMap.GetTile(this._positionTile); if (currentTile.MyInventory.Size() > 0 && !_myInventoryBackpack.Full()) { Item newAcquisition = currentTile.MyInventory.GetItem(0); currentTile.InventoryRemoveItem(newAcquisition); this.InventoryAddItem(newAcquisition); return(newAcquisition); } return(null); }
private void DrawTerrain(SpriteBatch spriteBatch) { int tilesize = Constants.TileSize; int offset = tilesize / 4; BitArray[] accessibilityMap = null; if (_myInterface.SelectedCreature != null) { accessibilityMap = _myInterface.SelectedCreature.MyMoveRangeCalculator.CurrentRangeMap; } for (int i = 0; i < _currentMap.BoundX; ++i) { for (int j = 0; j < _currentMap.BoundY; ++j) { Vector2 pos = new Vector2(i * tilesize + (j % 2) * (tilesize / 2), j * tilesize - j * offset) + _screenAnchor; Rectangle rect = ZoomTransform(new Rectangle((int)pos.X, (int)pos.Y, tilesize, tilesize)); Int16 visibilityTracker = _currentMap.MyVisibilityTracker.VisibilityCheck(new Coords(i, j), _myGame.PlayerTeam); // Draw tile if explored; fogged if explored but unseen; otherwise draw unexplored graphic if (visibilityTracker >= 0) { Tile currentTile = _currentMap.GetTile(i, j); spriteBatch.Draw(_tiles[(sbyte)currentTile.MyBitmap], rect, Color.White); if (visibilityTracker == 0) // fog { spriteBatch.Draw(_tiles[(sbyte)SpriteTile.HexFog], rect, Color.White); } else if (currentTile.MyInventory != null && currentTile.MyInventory.Size() > 0) { spriteBatch.Draw(_items[(sbyte)currentTile.MyInventory.GetItem(0).ItemBitmap], rect, Color.White); } // Draw green overlay if tile is accessible at current turn if (accessibilityMap != null) { if (!accessibilityMap[i][j]) { Color fillColor = Color.Gray; fillColor.A = 200; spriteBatch.Draw(_tiles[(sbyte)SpriteTile.HexFilled], rect, fillColor); } } } else // unexplored { spriteBatch.Draw(_tiles[(sbyte)SpriteTile.HexUnexplored], rect, Color.White); } // Draws grid if (Constants.ShowGrid) { spriteBatch.Draw(_tiles[(sbyte)SpriteTile.Hex], rect, Color.White); } // Draws coordinate numbers if (Constants.ShowCoordinates) { spriteBatch.DrawString(_font, "(" + i + "," + j + ")", ZoomTransform(pos + new Vector2(Constants.TileSize / 3, Constants.TileSize / 3)), Color.Black); } } } }
private void CalculateMoveRange(Coords origin, UInt16[] moveCosts, UInt16 availableAP) { _currentOrigin = origin; for (int i = 0; i < _currentMap.BoundX; ++i) { for (int j = 0; j < _currentMap.BoundY; ++j) { _APCount[i, j] = -1; _directionMap[i, j] = null; } } _APCount[origin.X, origin.Y] = availableAP; // WARNING: Code repetition with influence maps / A* Queue<Coords> currentQueue = new Queue<Coords>(); Queue<Coords> nextQueue = new Queue<Coords>(); currentQueue.Enqueue(origin); UInt32 currentDistance = 0; // main loop // Stopping conditions: the two queues are exhausted, OR InfluenceMapMaxDistance is reached while ( ((currentQueue.Count > 0) & (nextQueue.Count > 0)) | (currentDistance < Constants.InfluenceMapMaxDistance) ) { // Checks if it's time to start the next pass if (currentQueue.Count == 0) { currentQueue = nextQueue; nextQueue = new Queue<Coords>(); currentDistance++; continue; } Coords currentCoords = currentQueue.Peek(); //Coords delta1 = currentCoords - origin; Tile currentTile = _currentMap.GetTile(currentCoords); // Analyzes the neighbors of the current Tile for possible additions to nextQueue for (byte i = 0; i < 6; i++) { Direction currentDir = (Direction)i; Coords toCheck = StaticMathFunctions.CoordsNeighboringInDirection(currentCoords, currentDir); if (_currentMap.CheckInBounds(toCheck)) { Tile targetTile = _currentMap.GetTile(toCheck); UInt16 cost = moveCosts[(sbyte)targetTile.MyTerrainType]; if (cost > 0 && _currentMap.TenancyMap[toCheck.X, toCheck.Y] == null) // ignore impassable terrain and ignore occupied tiles { // checks if this approach is cheaper than the best approach so far Int32 currentAPleft = _APCount[toCheck.X, toCheck.Y]; Int32 potentialAPleft = _APCount[currentCoords.X, currentCoords.Y] - cost; if (currentAPleft < potentialAPleft) { _APCount[toCheck.X, toCheck.Y] = (UInt16)potentialAPleft; _directionMap[toCheck.X, toCheck.Y] = currentDir; nextQueue.Enqueue(toCheck); } } } } currentQueue.Dequeue(); } for (int i = 0; i < _currentMap.BoundX; ++i) { for (int j = 0; j < _currentMap.BoundY; ++j) { _rangeMap[i][j] = _APCount[i, j] >= 0; } } //return rangeMap; }