public void ExchangeEnemyInformation(List <IEnemy> enemies) { Vector3 shipPosition = ShipController.Position; int index = 0; // Check if there are any enemies to add IEnemyInfo enemyInfo = null; for (index = 0; index < EnemyInformationSet.Count; ++index) { // Check the distance of the enemy from the ship enemyInfo = EnemyInformationSet[index]; if (IGameManager.DistanceSquared(enemyInfo.Position, shipPosition) < Manager.ResourceRangeSqr) { // If the enemy is close enough to the ship, generate a new enemy enemies.Add(enemyInfo.GenerateEnemy()); // Remove the enemy information from the cell EnemyInformationSet.RemoveAt(index); --index; } } // Gather all the enemies we're removing IEnemy enemy = null; Vector3 enemyPosition; for (index = 0; index < enemies.Count; ++index) { enemy = enemies[index]; if (enemy.gameObject.activeSelf == false) { // If the enemy is inactive, remove it from the manager's list enemies.RemoveAt(index); --index; } else { // Check if the enemy is in this cell, but too far away from the ship... enemyPosition = enemy.transform.position; if ((IGameManager.DistanceSquared(enemyPosition, shipPosition) > Manager.ResourceRangeSqr) && (IsInCell(enemyPosition) == true)) { // Generate the enemy's information EnemyInformationSet.Add(enemy.GenerateInfo()); // Destroy the enemy, enemy.Destroy(null); // Remove the enemy from the manager's list enemies.RemoveAt(index); --index; } } } }
public override void Activate() { // Check if this cell is new if (currentState == IGridCell.State.InactiveNew) { // FIXME: for testing purposes, spawning objects at a random location IEnemy objectToSpawn = null; IEnemyInfo newInfo = null; for (int index = 0; index < numObjectsToSpawn; ++index) { // Get a random object objectToSpawn = null; if (spawnObjects.Length > 0) { objectToSpawn = spawnObjects[Random.Range(0, spawnObjects.Length)]; } // Check if there's an object to spawn if (objectToSpawn != null) { // Grab a random location Vector3 cloneLocation = Position; cloneLocation.x = Random.Range(CellRange.xMin, CellRange.xMax); cloneLocation.y = Random.Range(CellRange.yMin, CellRange.yMax); // Grab a random rotation Quaternion cloneRotation = Quaternion.Euler(0, 0, (Random.value * 360f)); // Generate a new enemy information newInfo = objectToSpawn.GenerateNewInfo(cloneLocation, cloneRotation); if (newInfo != null) { // Add this enemy information to the information set EnemyInformationSet.Add(newInfo); } } } } // Update the state currentState = IGridCell.State.Active; }
public override void Activate() { //Debug.Log(string.Format("Activating Cell ({0} x {1}) from State {2}", X, Y, currentState)); // Check if this cell is new if (currentState == IGridCell.State.InactiveNew) { // Check if there's an object to spawn if (spawnObject != null) { // Generate a new enemy information IEnemyInfo newInfo = spawnObject.GenerateNewInfo(Position, Quaternion.identity); if (newInfo != null) { // Add this enemy information to the information set EnemyInformationSet.Add(newInfo); } } } // Update the state CellObject.SetActive(true); currentState = IGridCell.State.Active; }
public bool TryGetEnemyInfo(string id, out IEnemyInfo enemyInfo) { return(_enemyUnitsById.TryGetValue(id, out enemyInfo)); }