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

Method take_damage

battlecode-engine/src/unit.rs:542–552  ·  view source on GitHub ↗

Take the amount of damage given, returning true if the unit has died. Returns false if the unit is still alive.

(&mut self, mut damage: i32)

Source from the content-addressed store, hash-verified

540 /// Take the amount of damage given, returning true if the unit has died.
541 /// Returns false if the unit is still alive.
542 pub(crate) fn take_damage(&mut self, mut damage: i32) -> bool {
543 if damage < 0 {
544 self.be_healed((-damage) as u32);
545 return false;
546 }
547 if self.unit_type() == UnitType::Knight {
548 damage = cmp::max(damage - self.defense as i32, 0);
549 }
550 self.health -= cmp::min(damage, self.health as i32) as u32;
551 self.health == 0
552 }
553
554 /// Increases the unit's current health by the given amount, without healing
555 /// beyond the unit's maximum health. Returns true if unit is healed to max.

Callers 3

damage_unitMethod · 0.80
test_repairFunction · 0.80

Calls 2

be_healedMethod · 0.80
unit_typeMethod · 0.80

Tested by 2

test_repairFunction · 0.64