public void RefreshPassable(LogicGameObject gameObject) { if (gameObject.IsStaticObject()) { int tileX = gameObject.GetTileX(); int tileY = gameObject.GetTileY(); if (tileX >= 0 && tileY >= 0) { int sizeX = gameObject.GetWidthInTiles(); int sizeY = gameObject.GetHeightInTiles(); for (int i = 0; i < sizeY; i++) { for (int j = 0; j < sizeX; j++) { LogicTile tile = this.GetTile(tileX + j, tileY + i); Debugger.DoAssert(tile != null, "illegal tile index"); tile.RefreshPassableFlag(); } } this.UpdateRoomIndices(); } } }
public void RemoveGameObject(LogicGameObject gameObject) { if (gameObject.IsStaticObject()) { int tileX = gameObject.GetTileX(); int tileY = gameObject.GetTileY(); if (tileX >= 0 && tileY >= 0) { int sizeX = gameObject.GetWidthInTiles(); int sizeY = gameObject.GetHeightInTiles(); for (int i = 0; i < sizeY; i++) { for (int j = 0; j < sizeX; j++) { this.m_tiles[(tileX + j) + this.m_sizeX * (tileY + i)].RemoveGameObject(gameObject); } } if (!gameObject.IsPassable()) { this.UpdateRoomIndices(); } } } }
/// <summary> /// Refreshes passable of the specified <see cref="LogicGameObject"/> instance.. /// </summary> public void RefreshPassable(LogicGameObject gameObject) { if (gameObject.IsStaticObject()) { int tileX = gameObject.GetTileX(); int tileY = gameObject.GetTileY(); if (tileX >= 0) { if (tileY >= 0) { int sizeX = gameObject.GetWidthInTiles(); int sizeY = gameObject.GetHeightInTiles(); for (int i = 0; i < sizeY; i++) { for (int j = 0; j < sizeX; j++) { this.GetTile(tileX + j, tileY + i).RefreshPassableFlag(); } } if (!gameObject.IsPassable()) { this.UpdateRoomIndices(); } } } } }
/// <summary> /// Called when the specified gameobject has been moved. /// </summary> public void GameObjectMoved(LogicGameObject gameObject, int oldTileX, int oldTileY) { if (gameObject.IsStaticObject()) { int tileX = gameObject.GetTileX(); int tileY = gameObject.GetTileY(); if (tileX >= 0) { if (tileY >= 0) { int sizeX = gameObject.GetWidthInTiles(); int sizeY = gameObject.GetHeightInTiles(); for (int i = 0; i < sizeY; i++) { for (int j = 0; j < sizeX; j++) { this.GetTile(oldTileX + j, oldTileY + i).RemoveGameObject(gameObject); this.GetTile(tileX + j, tileY + i).AddGameObject(gameObject); } } if (!gameObject.IsPassable()) { this.UpdateRoomIndices(); } } } } }
public void RefreshSubTiles() { this.m_passableFlag &= 0xF0; this.m_pathFinderCost = 0; for (int i = 0; i < this.m_gameObjects.Size(); i++) { LogicGameObject gameObject = this.m_gameObjects[i]; this.m_pathFinderCost = LogicMath.Max(this.m_pathFinderCost, gameObject.PathFinderCost()); if (!gameObject.IsPassable()) { int width = gameObject.GetWidthInTiles(); int height = gameObject.GetWidthInTiles(); if (width == 1 || height == 1) { this.m_passableFlag |= 0xF; } else { int edge = gameObject.PassableSubtilesAtEdge(); int startX = 2 * (this.m_tileX - gameObject.GetTileX()); int startY = 2 * (this.m_tileY - gameObject.GetTileY()); int endX = 2 * width - edge; int endY = 2 * height - edge; for (int j = 0; j < 2; j++) { int offset = j; int x = startX + j; for (int k = 0; k < 2; k++) { int y = startY + k; if (y < endY && x < endX && x >= edge && y >= edge) { this.m_passableFlag |= (byte)(1 << offset); } offset += 2; } } } } } }
public override int Execute(LogicLevel level) { LogicRect playArea = level.GetPlayArea(); LogicArrayList <LogicGameObject> gameObjects = new LogicArrayList <LogicGameObject>(); LogicArrayList <LogicGameObject> staticObjects = new LogicArrayList <LogicGameObject>(); LogicGameObjectFilter filter = new LogicGameObjectFilter(); filter.AddGameObjectType(LogicGameObjectType.BUILDING); filter.AddGameObjectType(LogicGameObjectType.TRAP); filter.AddGameObjectType(LogicGameObjectType.DECO); LogicArrayList <LogicGameObject> buildings = level.GetGameObjectManager().GetGameObjects(LogicGameObjectType.BUILDING); LogicArrayList <LogicGameObject> obstacles = level.GetGameObjectManager().GetGameObjects(LogicGameObjectType.OBSTACLE); staticObjects.AddAll(obstacles); for (int i = 0; i < buildings.Size(); i++) { LogicBuilding building = (LogicBuilding)buildings[i]; if (building.IsLocked()) { filter.AddIgnoreObject(building); staticObjects.Add(building); } } level.GetGameObjectManager().GetGameObjects(gameObjects, filter); for (int i = 0; i < gameObjects.Size(); i++) { LogicGameObject gameObject = gameObjects[i]; LogicVector2 editModePosition = gameObject.GetPositionLayout(this.m_layoutId, true); if (editModePosition.m_x != -1 && editModePosition.m_y != -1) { int newX = editModePosition.m_x + this.m_x; int newY = editModePosition.m_y + this.m_y; int width = gameObject.GetWidthInTiles(); int height = gameObject.GetHeightInTiles(); if (newX < playArea.GetStartX() || newY < playArea.GetStartY() || newX + width > playArea.GetEndX() || newY + height > playArea.GetEndY()) { return(-1); } if (this.m_layoutId <= 3 && this.m_layoutId != 1) { for (int j = 0; j < staticObjects.Size(); j++) { LogicGameObject staticObject = staticObjects[j]; if (staticObject != gameObject) { int staticX = staticObject.GetTileX(); int staticY = staticObject.GetTileY(); int staticWidth = staticObject.GetWidthInTiles(); int staticHeight = staticObject.GetHeightInTiles(); if (staticX != -1 && staticY != -1) { if (newX + width > staticX && newY + height > staticY && newX < staticX + staticWidth && newY < staticY + staticHeight) { return(-1); } } } } } } } for (int i = 0; i < gameObjects.Size(); i++) { LogicGameObject gameObject = gameObjects[i]; LogicVector2 editModePosition = gameObject.GetPositionLayout(this.m_layoutId, true); if (editModePosition.m_x != -1 && editModePosition.m_y != -1) { gameObject.SetPositionLayoutXY(editModePosition.m_x + this.m_x, editModePosition.m_y + this.m_y, this.m_layoutId, true); } } filter.Destruct(); return(0); }
public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null) { LogicGameObjectType gameObjectType = gameObject.GetGameObjectType(); if (gameObjectType == LogicGameObjectType.BUILDING || gameObjectType == LogicGameObjectType.TRAP || gameObjectType == LogicGameObjectType.DECO) { if (gameObjectType != LogicGameObjectType.BUILDING || ((LogicBuildingData)gameObject.GetData()).GetVillageType() == level.GetVillageType()) { if (gameObjectType == LogicGameObjectType.BUILDING) { if (((LogicBuilding)gameObject).GetWallIndex() != 0) { return(-21); } } int x = gameObject.GetTileX(); int y = gameObject.GetTileY(); int width = gameObject.GetWidthInTiles(); int height = gameObject.GetHeightInTiles(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { LogicObstacle tallGrass = level.GetTileMap().GetTile(this.m_x + i, this.m_y + j).GetTallGrass(); if (tallGrass != null) { level.GetGameObjectManager().RemoveGameObject(tallGrass); } } } if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, width, height, gameObject)) { gameObject.SetPositionXY(this.m_x << 9, this.m_y << 9); if (this.m_x != x || this.m_y != y) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar != null) { if (homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetChallengeBaseCooldownEnabledTownHall() && gameObject.GetGameObjectType() != LogicGameObjectType.DECO) { level.SetLayoutCooldownSecs(level.GetActiveLayout(level.GetVillageType()), LogicDataTables.GetGlobals().GetChallengeBaseSaveCooldown()); } } } return(0); } return(-3); } return(-32); } return(-1); } return(-2); }
/// <summary> /// Refreshes sub tiles. /// </summary> public void RefreshSubTiles() { this._passableFlag &= 0xF0; for (int i = 0; i < this._gameObjects.Count; i++) { LogicGameObject gameObject = this._gameObjects[i]; this._pathFinderCost = LogicMath.Max(this._pathFinderCost, gameObject.GetPathFinderCost()); if (!gameObject.IsPassable()) { int width = gameObject.GetWidthInTiles(); if (width == 1) { this._passableFlag |= 0xF0; } else { int tileX = gameObject.GetTileX(); int tileY = gameObject.GetTileY(); int edge = gameObject.PassableSubtilesAtEdge(); int startX = 2 * width - edge; int startY = 2 * width - edge; int endX = 2 * (width - edge); int endY = 2 * (width - edge); // RIP /* do * { * v11 = v20 + v19; * v12 = -1; * v13 = v20; * do * { * v14 = 2 * (v28 - v27) + v12 + 1; * v16 = __OFSUB__(v14, v9); * v15 = v14 - v9 < 0; * if ( v14 < v9 ) * { * v16 = __OFSUB__(v11, v10); * v15 = v11 - v10 < 0; * } * if ( v15 ^ v16 ) * { * v18 = __OFSUB__(v11, v8); * v17 = v11 - v8 < 0; * if ( v11 >= v8 ) * { * v18 = __OFSUB__(v14, v8); * v17 = v14 - v8 < 0; * } * if ( !(v17 ^ v18) ) *(_BYTE *)(v1 + 8) |= 1 << v13; * } ++v12; * v13 += 2; * } * while ( v12 < 1 ); * v19 = v29; * v16 = __OFSUB__(v20, 1); * v15 = v20++ - 1 < 0; * } * while ( v15 ^ v16 ); */ } } } }