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

Method destroy_unit

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

Destroys a unit. Removes any traces of it. If the unit is a rocket or factory, also destroys units in its garrison.

(&mut self, id: UnitID)

Source from the content-addressed store, hash-verified

927 ///
928 /// If the unit is a rocket or factory, also destroys units in its garrison.
929 fn destroy_unit(&mut self, id: UnitID) {
930 match self.unit(id)
931 .expect("Unit does not exist and cannot be destroyed.")
932 .location() {
933 OnMap(loc) => {
934 self.my_planet_mut().units_by_loc.remove(&loc);
935 },
936 InSpace => {
937 // Units only die in space after a landing on their turn.
938 // Thus we are guaranteed that my_unit() will find the unit.
939 for utd_id in self.my_unit(id).unwrap().structure_garrison()
940 .expect("only rockets can die in space") {
941 self.my_team_mut().units_in_space.remove(&utd_id);
942 }
943 self.my_team_mut().units_in_space.remove(&id);
944 return;
945 },
946 _ => panic!("Unit is in ???, this should not be possible"),
947 };
948
949 // If this unit's garrison is visible, destroy those units too.
950 let unit_type = self.unit(id).unwrap().unit_type();
951 if unit_type == UnitType::Rocket || unit_type == UnitType::Factory {
952 let units_to_destroy = self.unit_mut(id).unwrap()
953 .structure_garrison().unwrap();
954 for utd_id in units_to_destroy.iter() {
955 self.my_planet_mut().units.remove(&utd_id);
956 }
957 }
958
959 self.my_planet_mut().units.remove(&id);
960 }
961
962 /// Disintegrates the unit and removes it from the map. If the unit is a
963 /// factory or a rocket, also disintegrates any units garrisoned inside it.

Callers 7

disintegrate_unitMethod · 0.80
damage_unitMethod · 0.80
land_rocketMethod · 0.80
test_unit_disintegrateFunction · 0.80
test_worker_harvestFunction · 0.80

Calls 8

locationMethod · 0.80
my_planet_mutMethod · 0.80
structure_garrisonMethod · 0.80
my_unitMethod · 0.80
my_team_mutMethod · 0.80
unit_typeMethod · 0.80
unit_mutMethod · 0.80
unitMethod · 0.45

Tested by 4

test_unit_disintegrateFunction · 0.64
test_worker_harvestFunction · 0.64