/// <summary> /// This method will update the pointers to the Cell in the GameWorld that is occuppied by the Unit. /// </summary> /// <param name="unit">The unit who's location is being updated.</param> public void updateUnitLocation(Unit unit) { if (!unit.getCell().contains(unit.x, unit.y)) { Cell newCell = gw.map.getCell((int)Math.Floor(unit.x), (int)Math.Floor(unit.y)); Cell oldCell = unit.getCell(); oldCell.removeUnit(); // NOTE: doesn't check if newCell is already occupied. unit.setCell(newCell); newCell.setUnit(unit); } }
/// <summary> /// This method will update the pointers to the Cell in the GameWorld that is occuppied by the Unit. /// </summary> /// <param name="unit">The unit who's location is being updated.</param> public void updateUnitLocation(Unit unit) { if (!unit.getCell().contains(unit.x, unit.y)) { Cell newCell = gw.map.getCell((int)Math.Floor(unit.x), (int)Math.Floor(unit.y)); Cell oldCell = unit.getCell(); oldCell.removeUnit(); // NOTE: doesn't check if newCell is already occupied. unit.setCell(newCell); newCell.setUnit(unit); // Update the visibility map. this.visMapLogic.updateVisMap(unit); // Update the Cells that the unit is observing. updateCellsUnitIsObserving(unit); // Notify all observers of the cell that a unit has moved onto the cell. newCell.notify(new ZRTSModel.GameEvent.GameEvent(newCell, unit, unit, ZRTSModel.GameEvent.GameEvent.EventType.MoveEvent)); } }