/// <summary> /// Initializes a player of the Terran race. /// </summary> /// <param name="player">The player to be initialized.</param> private void TerranInitializer(Player player) { if (player == null) { throw new ArgumentNullException("player"); } /// Add a Terran Command Center to the position of the start location. Scenario scenario = player.StartLocation.Scenario; //Starport commandCenter = new Starport(); CommandCenter commandCenter = new CommandCenter(); scenario.AddElementToScenario(commandCenter); player.AddBuilding(commandCenter); commandCenter.AttachToMap(scenario.Map.GetQuadTile(player.QuadraticStartPosition.Location)); /// TEST: Add a Terran Comsat Station //ComsatStation comsatStation = new ComsatStation(); //scenario.AddElementToScenario(comsatStation); //player.AddAddon(comsatStation); //comsatStation.AttachToMap(scenario.Map.GetQuadTile(player.QuadraticStartPosition.Location + new RCIntVector(4, 1))); /// TEST END /// Find place for the given number of SCVs using an EntityNeighbourhoodIterator. EntityNeighbourhoodIterator cellIterator = new EntityNeighbourhoodIterator(commandCenter); IEnumerator <ICell> cellEnumerator = cellIterator.GetEnumerator(); for (int scvCount = 0; scvCount < NUM_OF_SCVS; scvCount++) { /// Create the next SCV //Wraith scv = new Wraith(); SCV scv = new SCV(); //Unit scv = scvCount % 2 == 0 ? (Unit)new SCV() : (Unit)new Marine(); scenario.AddElementToScenario(scv); player.AddUnit(scv); /// Search a place for the new SCV on the map. bool scvPlacedSuccessfully = false; while (cellEnumerator.MoveNext()) { if (scv.AttachToMap(cellEnumerator.Current.MapCoords)) { scvPlacedSuccessfully = true; break; } } /// Remove the SCV and stop initializing if there is no more place on the map. if (!scvPlacedSuccessfully) { player.RemoveUnit(scv); scenario.RemoveElementFromScenario(scv); scv.Dispose(); break; } } }