public static bool FindPoint(LogicTileMap tileMap, LogicVector2 pos1, LogicVector2 pos2, LogicVector2 pos3, LogicVector2 pos4) { pos1.Set(pos2.m_x, pos2.m_y); pos1.Substract(pos3); int length = pos1.GetLength(); pos1.m_x = (pos1.m_x << 7) / length; pos1.m_y = (pos1.m_y << 7) / length; pos4.Set(pos3.m_x, pos3.m_y); int radius = LogicMath.Clamp(length / 128, 10, 25); for (int i = 0; i < radius; i++) { if (tileMap.IsPassablePathFinder(pos4.m_x >> 8, pos4.m_y >> 8)) { pos4.m_x = (int)((pos4.m_x & 0xFFFFFF00) | 128); pos4.m_y = (int)((pos4.m_y & 0xFFFFFF00) | 128); return(true); } pos4.Add(pos1); } return(false); }
public LogicPathFinderOld(LogicTileMap tileMap) : base(tileMap) { if (tileMap != null) { this.m_mapWidth = 2 * tileMap.GetSizeX(); this.m_mapHeight = 2 * tileMap.GetSizeY(); } else { this.m_mapWidth = 3; this.m_mapHeight = 4; } this.m_savedPaths = new LogicSavedPath[LogicPathFinderOld.SAVED_PATHS]; for (int i = 0, j = this.m_mapWidth * 4; i < LogicPathFinderOld.SAVED_PATHS; i++) { this.m_savedPaths[i] = new LogicSavedPath(j); } int size = this.m_mapWidth * this.m_mapHeight; this.m_pathState = new int[size]; this.m_heapBuffer = new int[size]; this.m_parentBuffer = new int[size]; this.m_pathBuffer = new int[size]; this.m_pathCost = new int[size]; this.ResetCostStrategyToDefault(); }
public void AddTombstoneIfNeeded() { if (!this.m_ejected && this.m_level.GetTombStoneCount() < 40) { int tileX = this.GetTileX(); int tileY = this.GetTileY(); LogicTileMap tileMap = this.m_level.GetTileMap(); LogicTile tile = tileMap.GetTile(tileX, tileY); if (!this.TileOkForTombstone(tile)) { int minDistance = 0; int closestTileX = -1; int closestTileY = -1; for (int i = -1; i < 2; i++) { int offsetX = ((i + tileX) << 9) | 256; int offsetY = 256 - (tileY << 9); for (int j = -1; j < 2; j++, offsetY -= 512) { tile = tileMap.GetTile(tileX + i, tileY + j); if (this.TileOkForTombstone(tile)) { int distanceX = this.GetX() - offsetX; int distanceY = this.GetY() + offsetY; int distance = distanceX * distanceX + distanceY * distanceY; if (minDistance == 0 || distance < minDistance) { minDistance = distance; closestTileX = tileX + i; closestTileY = tileY + j; } } } } if (minDistance == 0) { return; } tileX = closestTileX; tileY = closestTileY; } LogicObstacleData tombstoneData = this.GetCharacterData().GetTombstone(); if (tombstoneData != null) { LogicObstacle tombstone = (LogicObstacle)LogicGameObjectFactory.CreateGameObject(tombstoneData, this.m_level, this.m_villageType); tombstone.SetInitialPosition(tileX << 9, tileY << 9); this.GetGameObjectManager().AddGameObject(tombstone, -1); } } }
/// <summary> /// Initializes a new instance of the <see cref="LogicPathFinderOld"/> class. /// </summary> public LogicPathFinderOld(LogicTileMap tileMap) : base(tileMap) { this._sizeX = 3; this._sizeY = 4; if (tileMap != null) { this._sizeX = 2 * tileMap.GetSizeX(); this._sizeY = 2 * tileMap.GetSizeY(); } int arraySize = this._sizeX * this._sizeY; this._heapBuffer = new int[arraySize]; this._pathBuffer = new int[arraySize]; this._savedPaths = new LogicSavedPath[30]; for (int i = 0; i < 30; i++) { this._savedPaths[i] = new LogicSavedPath(4 * this._sizeX); } }
private void Spawn() { int free = LogicMath.Min(LogicMath.Min(this.m_spawnCount, this.m_maxSpawned - this.m_spawned.Size()), this.m_maxLifetimeSpawns - this.m_lifeTimeSpawns); if (free > 0) { int x = this.m_parent.GetX(); int y = this.m_parent.GetY(); int tileX = this.m_parent.GetTileX(); int tileY = this.m_parent.GetTileY(); int width = this.m_parent.GetWidthInTiles(); int height = this.m_parent.GetHeightInTiles(); int levelWidth = this.m_parent.GetLevel().GetWidthInTiles(); int levelHeight = this.m_parent.GetLevel().GetHeightInTiles(); int startTileX = LogicMath.Clamp(tileX - this.m_radius, 0, levelWidth); int startTileY = LogicMath.Clamp(tileY - this.m_radius, 0, levelHeight); int endTileX = LogicMath.Clamp(tileX + this.m_radius + width, 0, levelWidth); int endTileY = LogicMath.Clamp(tileY + this.m_radius + height, 0, levelHeight); int radius = (this.m_radius << 9) * (this.m_radius << 9); int possibility = (endTileX - startTileX) * (endTileY - startTileY); LogicArrayList <LogicTile> spawnPoints = new LogicArrayList <LogicTile>(possibility); LogicTileMap tileMap = this.m_parent.GetLevel().GetTileMap(); int spawnPointUpStartX = x + (width << 9); int spawnPointUpStartY = y + (height << 9); int tmp4 = y - 256 - (startTileY << 9); int startMidX = (startTileX << 9) | 256; int startMidY = (startTileY << 9) | 256; for (int i = startTileX, j = startMidX; i < endTileX; i++, j += 512) { int tmp1 = j >= spawnPointUpStartX ? -spawnPointUpStartX + j + 1 : 0; int tmp2 = j >= x ? tmp1 : x - j; tmp2 *= tmp2; for (int k = startTileY, l = startMidY, m = tmp4; k < endTileY; k++, l += 512, m -= 512) { LogicTile tile = tileMap.GetTile(i, k); if (tile.GetGameObjectCount() == 0) { int tmp3 = y <= l ? l < spawnPointUpStartY ? 0 : -spawnPointUpStartY + l + 1 : m; tmp3 *= tmp3; if (tmp2 + tmp3 <= radius) { spawnPoints.Add(tile); } } } } for (int i = free; i > 0 && spawnPoints.Size() > 0; i--, ++this.m_lifeTimeSpawns) { int idx = this.m_randomizer.Rand(spawnPoints.Size()); LogicTile tile = spawnPoints[idx]; LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(this.m_spawnData, this.m_parent.GetLevel(), this.m_parent.GetVillageType()); gameObject.SetInitialPosition(tile.GetX() << 9, tile.GetY() << 9); this.m_parent.GetGameObjectManager().AddGameObject(gameObject, -1); this.m_spawned.Add(gameObject.GetGlobalID()); spawnPoints.Remove(idx); } } }
/// <summary> /// Initializes a new instance of the <see cref="LogicPathFinderNew"/> class. /// </summary> public LogicPathFinderNew(LogicTileMap tileMap) : base(tileMap) { }
/// <summary> /// Destructs this instance. /// </summary> public virtual void Destruct() { this._tileMap = null; }
/// <summary> /// Initializes a new instance of the <see cref="LogicPathFinder"/> class. /// </summary> public LogicPathFinder(LogicTileMap tileMap) { this._tileMap = tileMap; }
public void PushTrap(LogicVector2 position, int time, int id, bool ignorePrevPush, bool verifyPushPosition) { if (this.m_pushTime <= 0 || ignorePrevPush) { if (this.m_parent != null && this.m_parent.GetJump() <= 0 && !this.m_parent.GetParent().IsHero()) { LogicGameObject parent = this.m_parent.GetParent(); if (!parent.IsHero()) { if (id != 0 && !ignorePrevPush) { int idx = -1; for (int k = 0; k < 3; k++) { if (this.m_preventsPushId[k] == id) { return; } if (this.m_preventsPushTime[k] == 0) { idx = k; } } if (idx == -1) { return; } this.m_preventsPushId[idx] = id; this.m_preventsPushTime[idx] = 1500; } this.m_pushTime = time; this.m_pushInitTime = time; this.m_pushBackStartPosition.m_x = this.m_position.m_x; this.m_pushBackStartPosition.m_y = this.m_position.m_y; this.m_pushBackEndPosition.m_x = this.m_position.m_x + position.m_x; this.m_pushBackEndPosition.m_y = this.m_position.m_y + position.m_y; if (verifyPushPosition) { int pushBackEndPositionX = this.m_pushBackEndPosition.m_x; int pushBackEndPositionY = this.m_pushBackEndPosition.m_y; if (LogicMath.Max(LogicMath.Abs(position.m_x), LogicMath.Abs(position.m_y)) != 0) { LogicTileMap tileMap = parent.GetLevel().GetTileMap(); if (!tileMap.IsPassablePathFinder(pushBackEndPositionX >> 8, pushBackEndPositionY >> 8)) { LogicVector2 pos = new LogicVector2(); LogicRandom rnd = new LogicRandom(pushBackEndPositionX + pushBackEndPositionY); tileMap.GetNearestPassablePosition(pushBackEndPositionX + rnd.Rand(512) - 256, pushBackEndPositionY + rnd.Rand(512) - 256, pos, 2048); pushBackEndPositionX = pos.m_x; pushBackEndPositionY = pos.m_y; } if (!tileMap.IsPassablePathFinder(pushBackEndPositionX >> 8, pushBackEndPositionY >> 8)) { Debugger.Warning("PushTrap->ended on inmovable"); } } this.m_pushBackEndPosition.m_x = pushBackEndPositionX; this.m_pushBackEndPosition.m_y = pushBackEndPositionY; } this.m_ignorePush = verifyPushPosition; int angle = position.GetAngle(); this.m_direction = angle + (angle <= 180 ? 180 : -180); } } } }
public bool MoveTo(int x, int y, LogicTileMap tileMap, bool defaultEndPoint) { this.ClearPath(); if (this.m_parent != null) { if (this.m_parent.GetParent().IsFrozen()) { return(false); } } this.m_wall = null; this.m_wallCount = 0; this.m_pathStartPosition.m_x = this.m_position.m_x >> 8; this.m_pathStartPosition.m_y = this.m_position.m_y >> 8; this.m_pathEndPosition.m_x = x >> 8; this.m_pathEndPosition.m_y = y >> 8; this.m_pathStartPosition.m_x = LogicMath.Clamp(this.m_pathStartPosition.m_x, 0, 99); this.m_pathStartPosition.m_y = LogicMath.Clamp(this.m_pathStartPosition.m_y, 0, 99); this.m_pathEndPosition.m_x = LogicMath.Clamp(this.m_pathEndPosition.m_x, 0, 99); this.m_pathEndPosition.m_y = LogicMath.Clamp(this.m_pathEndPosition.m_y, 0, 99); LogicPathFinder pathFinder; if (this.m_parent == null) { pathFinder = this.m_pathFinder; pathFinder.ResetCostStrategyToDefault(); } else { bool resetStrategyCost = true; int strategyCost = 256; LogicGameObject parent = this.m_parent.GetParent(); LogicHitpointComponent hitpointComponent = parent.GetHitpointComponent(); if (hitpointComponent != null) { if (hitpointComponent.GetTeam() == 1) { resetStrategyCost = false; strategyCost = 768; } } if (this.m_parent.CanJumpWall()) { resetStrategyCost = false; strategyCost = 16; } if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER) { LogicCharacter character = (LogicCharacter)parent; if (character.IsWallBreaker()) { resetStrategyCost = false; strategyCost = 128; } } pathFinder = tileMap.GetPathFinder(); if (resetStrategyCost) { pathFinder.ResetCostStrategyToDefault(); } else { pathFinder.SetCostStrategy(true, strategyCost); } pathFinder.FindPath(this.m_pathStartPosition, this.m_pathEndPosition, true); pathFinder.GetPathLength(); int pathLength = pathFinder.GetPathLength(); this.m_path.EnsureCapacity(pathLength + 1); if (pathLength != 0 && defaultEndPoint) { LogicVector2 pathPoint = new LogicVector2(x, y); this.CheckWall(pathPoint); this.m_path.Add(pathPoint); } if (LogicDataTables.GetGlobals().UseNewPathFinder()) { LogicTileMap pathFinderTileMap = pathFinder.GetTileMap(); int width = 2 * pathFinderTileMap.GetSizeX(); int height = 2 * pathFinderTileMap.GetSizeY(); int startTileIdx = this.m_pathStartPosition.m_x + width * this.m_pathStartPosition.m_y; int endTileIdx = this.m_pathEndPosition.m_x + width * this.m_pathEndPosition.m_y; if (!defaultEndPoint) { LogicVector2 pathPoint = new LogicVector2((endTileIdx % width) << 8, (endTileIdx / height) << 8); this.CheckWall(pathPoint); this.m_path.Add(pathPoint); } if (pathLength > 0 && !pathFinder.IsLineOfSightClear()) { int iterationCount = 0; while (endTileIdx != startTileIdx && endTileIdx != -1) { endTileIdx = pathFinder.GetParent(endTileIdx); if (endTileIdx != startTileIdx && endTileIdx != -1) { LogicVector2 pathPoint = new LogicVector2((endTileIdx % width) << 8, (endTileIdx / height) << 8); pathPoint.m_x += 128; pathPoint.m_y += 128; this.CheckWall(pathPoint); this.m_path.Add(pathPoint); if (iterationCount >= 100000) { Debugger.Warning("LMSystem: iteration count > 100000"); break; } } iterationCount += 1; } } } else { for (int i = -pathLength, j = 0; j + i != 0; j++) { LogicVector2 pathPoint = new LogicVector2(); pathFinder.GetPathPoint(pathPoint, i + j); if (i + j == -1 && this.m_pathStartPosition.Equals(pathPoint)) { pathPoint.Destruct(); pathPoint = null; } else { if (j != 0 || !this.m_pathStartPosition.Equals(pathPoint)) { pathPoint.m_x = (pathPoint.m_x << 8) | 128; pathPoint.m_y = (pathPoint.m_y << 8) | 128; } else { pathPoint.m_x = x; pathPoint.m_y = y; } this.CheckWall(pathPoint); this.m_path.Add(pathPoint); } } } } this.CalculatePathLength(); if (this.m_path.Size() > 0) { this.CalculateDirection(this.m_pathDistance); return(true); } return(false); }
public void SetPosition(int x, int y) { if (this.m_parent != null) { if (!this.m_parent.IsFlying() && !this.m_parent.IsUnderground() && this.m_parent.GetJump() <= 0 && !this.m_ignorePush) { this.ValidatePos(); if (this.m_position.m_x >> 8 == x >> 8) { if ((this.m_position.m_y ^ (uint)y) < 256) { goto set; } } LogicTileMap tileMap = this.m_parent.GetParent().GetLevel().GetTileMap(); int pathFinderX = x >> 8; int pathFinderY = y >> 8; if (!tileMap.IsPassablePathFinder(pathFinderX, pathFinderY)) { LogicTile tile = tileMap.GetTile(pathFinderX / 2, pathFinderY / 2); if (LogicDataTables.GetGlobals().JumpWhenHitJumpable()) { bool allowJump = false; for (int i = 0; i < tile.GetGameObjectCount(); i++) { LogicGameObject gameObject = tile.GetGameObject(i); if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (building.GetHitWallDelay() > 0) { allowJump = true; } } } if (allowJump) { this.m_position.m_x = x; this.m_position.m_y = y; this.m_parent.EnableJump(128); return; } } if (LogicDataTables.GetGlobals().SlideAlongObstacles()) { throw new NotImplementedException(); // TODO: Implement this. } else { x = LogicMath.Clamp(x, (int)(this.m_position.m_x & 0xFFFFFF00), this.m_position.m_x | 0xFF); y = LogicMath.Clamp(y, (int)(this.m_position.m_y & 0xFFFFFF00), this.m_position.m_y | 0xFF); } this.m_position.m_x = x; this.m_position.m_y = y; this.ValidatePos(); return; } } } set: this.m_position.m_x = x; this.m_position.m_y = y; }