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

Method attack

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

Commands a robot to attack a unit, dealing the robot's standard amount of damage. Healers cannot attack, and should use `heal()` instead. NoSuchUnit - the unit does not exist (inside the vision range). TeamNotAllowed - the unit is not on the current player's team. InappropriateUnitType - the unit is not a robot, or is a healer. UnitNotOnMap - the unit or target is not on the map. OutOfRange - th

(&mut self, robot_id: UnitID, target_id: UnitID)

Source from the content-addressed store, hash-verified

1134 /// * OutOfRange - the target location is not in range.
1135 /// * Overheated - the unit is not ready to attack.
1136 pub fn attack(&mut self, robot_id: UnitID, target_id: UnitID) -> Result<(), GameError> {
1137 self.ok_if_can_attack(robot_id, target_id)?;
1138 self.ok_if_attack_ready(robot_id)?;
1139 let damage = self.my_unit_mut(robot_id).unwrap().use_attack();
1140 if self.my_unit(robot_id).unwrap().unit_type() == UnitType::Mage {
1141 let epicenter = self.unit(target_id).unwrap().location().map_location().unwrap();
1142 for direction in Direction::all().iter() {
1143 self.damage_location(epicenter.add(*direction), damage);
1144 }
1145 }
1146 self.damage_unit(target_id, damage);
1147 Ok(())
1148 }
1149
1150 // ************************************************************************
1151 // ************************* RESEARCH METHODS *****************************

Callers 4

run.pyFile · 0.45
run.pyFile · 0.45
applyMethod · 0.45
examplefuncsplayerFunction · 0.45

Calls 12

ok_if_can_attackMethod · 0.80
use_attackMethod · 0.80
my_unit_mutMethod · 0.80
unit_typeMethod · 0.80
my_unitMethod · 0.80
map_locationMethod · 0.80
locationMethod · 0.80
damage_locationMethod · 0.80
damage_unitMethod · 0.80
ok_if_attack_readyMethod · 0.45
unitMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected