MCPcopy Index your code
hub / github.com/battlecode/battlecode-2018 / process_factories

Method process_factories

battlecode-engine/src/world.rs:1889–1917  ·  view source on GitHub ↗

Process the end of the turn for factories. If a factory added a unit to its garrison, also mark that unit down in the game world. Note that factores cannot be built on Mars, so we only process Earth.

(&mut self)

Source from the content-addressed store, hash-verified

1887 ///
1888 /// Note that factores cannot be built on Mars, so we only process Earth.
1889 fn process_factories(&mut self) {
1890 let planet = Planet::Earth;
1891 let mut factory_ids: Vec<UnitID> = vec![];
1892 for unit in self.get_planet(planet).units.values().into_iter() {
1893 if unit.unit_type() == UnitType::Factory {
1894 factory_ids.push(unit.id());
1895 }
1896 }
1897
1898 for factory_id in factory_ids {
1899 let (unit_type, team) = {
1900 let factory = self.get_planet_mut(planet).units.get_mut(&factory_id).unwrap();
1901 let new_unit_type = factory.process_factory_round();
1902 if new_unit_type.is_none() {
1903 continue;
1904 }
1905 (new_unit_type.unwrap(), factory.team())
1906 };
1907 self.viewer_changes.push(ViewerDelta::ProductionDone { factory_id, unit_type});
1908
1909 let id = self.id_generator.next_id();
1910 let level = self.get_team(team).research.get_level(&unit_type);
1911 let new_unit = Unit::new(id, team, unit_type, level, InGarrison(factory_id))
1912 .expect("research_level is valid");
1913
1914 self.get_planet_mut(planet).units.insert(id, new_unit);
1915 self.get_planet_mut(planet).units.get_mut(&factory_id).unwrap().load(id);
1916 }
1917 }
1918
1919 // ************************************************************************
1920 // *************************** ROCKET METHODS *****************************

Callers 1

end_roundMethod · 0.80

Calls 10

get_planetMethod · 0.80
unit_typeMethod · 0.80
idMethod · 0.80
get_planet_mutMethod · 0.80
process_factory_roundMethod · 0.80
next_idMethod · 0.80
get_levelMethod · 0.80
get_teamMethod · 0.80
teamMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected