public void Initialize(PlayerAI t_playerAI) { m_playerAI = t_playerAI; m_player = m_playerAI.GetPlayer(); m_mapGrid = m_playerAI.m_mapGrid; }
void DefendCity() { bool newTargetCity = true; if (m_targetObj != null) { City targetCity = m_targetObj.GetComponent <City>(); if (targetCity.GetOwnerID() == m_playerAI.GetID()) { newTargetCity = false; } } if (newTargetCity) { List <GameObject> targetCities = m_playerAI.GetPlayer().GetCities(); City targetCity = null; foreach (GameObject city in targetCities) { if (targetCity == null) { targetCity = city.GetComponent <City>(); break; } } if (targetCity != null) { m_targetObj = targetCity.gameObject; m_targetTile = targetCity.GetOriginTile(); } } if (m_targetObj != null) { List <BorderTile> borderTiles = m_targetObj.GetComponent <City>().GetBorderTiles(); m_targetTile = borderTiles[Random.Range(0, borderTiles.Count)].m_tile; List <Tile> nearbyTiles = Tile.GetTilesInRange(m_unit.GetCurrentTile(), m_unit.GetVisionRange()); foreach (Tile tile in nearbyTiles) { Unit unit = tile.GetUnitInTile(); if (unit != null) { if (unit.GetUnitType() == UnitType.CombatUnit) { if (unit.GetOwnerID() != m_playerAI.GetID()) { m_targetObj = unit.gameObject; m_targetTile = unit.GetCurrentTile(); break; } } } } m_unit.SetPath(m_playerAI.m_mapGrid.CreatePath(m_unit.GetCurrentTile(), m_targetTile, m_unit), m_targetTile); } }