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)
| 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 ***************************** |
no test coverage detected