/// <summary> /// Places one unit. /// </summary> public bool PlaceOneUnit() { if (this._placePositionX == -1 && this._placePositionY == -1) { int widthArea = this._level.GetPlayArea().GetStartX(); int width = this._level.GetWidthInTiles(); if (width > 0) { int tileIdx = -1; int tmp = width / 2; for (int x = 0; x < width; x++) { if (widthArea >= 2) { int middleX = (widthArea - 1) / 2; int square = (tmp - x) * (tmp - x); for (int y = 0; y != widthArea - 1; y++, middleX--) { if (tileIdx == -1 || square + middleX * middleX < tileIdx) { if (this._level.GetTileMap().GetTile(x, y).GetPassableFlag() == 1) { this._placePositionX = x; this._placePositionY = y; tileIdx = square + middleX * middleX; } } } } } } } if (this._placePositionX == -1 && this._placePositionY == -1) { Debugger.Error("LogicNpcAttack::placeOneUnit - No attack position found!"); } else { LogicArrayList <LogicDataSlot> units = this._npcAvatar.GetUnits(); for (int i = 0; i < units.Count; i++) { LogicDataSlot slot = units[i]; if (slot.GetCount() > 0) { slot.SetCount(slot.GetCount() - 1); LogicCharacter character = LogicPlaceAttackerCommand.PlaceAttacker(this._npcAvatar, (LogicCharacterData)slot.GetData(), this._level, this._placePositionX, this._placePositionY); if (!this._unitsDeployed) { character.GetListener().MapUnlocked(); } // character.GetCombatComponent().SetPreferredTarget(this._buildingClass, 100, 0); this._unitsDeployed = true; return(true); } } } return(false); }
public bool PlaceOneUnit() { if (this.m_placePositionX == -1 && this.m_placePositionY == -1) { int startAreaY = this.m_level.GetPlayArea().GetStartY(); int widthInTiles = this.m_level.GetWidthInTiles(); int minDistance = -1; for (int i = 0; i < widthInTiles; i++) { int centerY = (startAreaY - 1) / 2; for (int j = 0; j < startAreaY - 1; j++, centerY--) { int distance = ((widthInTiles >> 1) - i) * ((widthInTiles >> 1) - i) + centerY * centerY; if (minDistance == -1 || distance < minDistance) { LogicTile tile = this.m_level.GetTileMap().GetTile(i, j); if (tile.GetPassableFlag() != 0) { this.m_placePositionX = i; this.m_placePositionY = j; minDistance = distance; } } } } } if (this.m_placePositionX == -1 && this.m_placePositionY == -1) { Debugger.Error("LogicNpcAttack::placeOneUnit - No attack position found!"); } else { LogicArrayList <LogicDataSlot> units = this.m_npcAvatar.GetUnits(); for (int i = 0; i < units.Size(); i++) { LogicDataSlot slot = units[i]; if (slot.GetCount() > 0) { LogicCharacter character = LogicPlaceAttackerCommand.PlaceAttacker(this.m_npcAvatar, (LogicCharacterData)slot.GetData(), this.m_level, this.m_placePositionX << 9, this.m_placePositionY << 9); if (!this.m_unitsDeployStarted) { character.GetListener().MapUnlocked(); } character.GetCombatComponent().SetPreferredTarget(this.m_buildingClass, 100, false); this.m_unitsDeployStarted = true; return(true); } } } return(false); }