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

Method land_rocket

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

Lands the rocket, damaging the units in adjacent squares. The rocket is destroyed if it lands on a factory, rocket, or impassable terrain. Also resets the amount of karbonite at that location if the rocket successfully lands.

(&mut self, rocket_id: UnitID, destination: MapLocation)

Source from the content-addressed store, hash-verified

1987 /// Also resets the amount of karbonite at that location if the rocket
1988 /// successfully lands.
1989 fn land_rocket(&mut self, rocket_id: UnitID, destination: MapLocation) {
1990 let blast_damage = self.my_unit(rocket_id).unwrap().rocket_blast_damage().unwrap();
1991 if self.my_planet().units_by_loc.contains_key(&destination) {
1992 let victim_id = *self.my_planet().units_by_loc.get(&destination).unwrap();
1993 let should_destroy_rocket = match self.unit(victim_id).unwrap().unit_type() {
1994 UnitType::Rocket => true,
1995 UnitType::Factory => true,
1996 _ => false,
1997 };
1998 self.destroy_unit(victim_id);
1999 if should_destroy_rocket {
2000 self.destroy_unit(rocket_id);
2001 } else {
2002 self.my_unit_mut(rocket_id).unwrap().land_rocket(destination);
2003 self.move_from_space(rocket_id);
2004 self.my_planet_mut().karbonite[destination.y as usize][destination.x as usize] = 0;
2005 }
2006
2007 } else {
2008 self.my_unit_mut(rocket_id).unwrap().land_rocket(destination);
2009 self.move_from_space(rocket_id);
2010 self.my_planet_mut().karbonite[destination.y as usize][destination.x as usize] = 0;
2011 }
2012
2013 for dir in Direction::all() {
2014 self.damage_location(destination.add(dir), blast_damage);
2015 }
2016 }
2017
2018 fn process_rockets(&mut self, team: Team) {
2019 let landings = self.get_team(team).rocket_landings.landings_on(self.round);

Callers 4

process_rocketsMethod · 0.45
test_rocket_successFunction · 0.45
test_rocket_failureFunction · 0.45
test_rocket_unloadFunction · 0.45

Calls 11

rocket_blast_damageMethod · 0.80
my_unitMethod · 0.80
my_planetMethod · 0.80
unit_typeMethod · 0.80
destroy_unitMethod · 0.80
my_unit_mutMethod · 0.80
move_from_spaceMethod · 0.80
my_planet_mutMethod · 0.80
damage_locationMethod · 0.80
unitMethod · 0.45
addMethod · 0.45

Tested by 3

test_rocket_successFunction · 0.36
test_rocket_failureFunction · 0.36
test_rocket_unloadFunction · 0.36