H9: Boathook swings damage players; unarmed bots brawl
- Harvest.swing traces the swing as a shot is traced (Weapons.trace, lag compensated). A player reached before terrain, a solid, a prop's grown box or a built piece takes the boathook's damage through Weapons.damage_player, so armor, the kill feed and stats count it. A level swing meets the head and takes the headshot multiplier, as a shot does. - Unarmed bots go for an opponent in view within BOT_BRAWL_METRES (6 m) and swing within BOT_SWING_METRES; inside a hut they swing back without walking in. - Tests: harvest +5 (hit, armor first, out of reach, wall between, player in front of a tree), bot brain +2 (closes in and lands hits; leaves a distant opponent alone). - test_world_replication: an unarmed bot now meets the scripted player early on seed 2, so the test gives it full armor on landing so it lives to build; all assertions unchanged. Closes #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -226,3 +226,96 @@ func test_every_swing_reports_itself_hit_or_miss() -> void:
|
||||
Harvest.swing(player, sim.ground, sim.props, events, sim.structures)
|
||||
assert_eq(events.size(), 1, "not again until the boathook is ready")
|
||||
|
||||
|
||||
|
||||
# H9: swings hit players.
|
||||
|
||||
## A sim with an attacker at (100, 0, 100) facing +z and a victim `gap` metres from
|
||||
## the attacker's body along +z.
|
||||
func _duel(gap: float) -> Simulation:
|
||||
var sim: Simulation = _world([])
|
||||
var attacker: SimEntity = sim.entities.find(1)
|
||||
attacker.drop_state = Drop.NONE
|
||||
attacker.on_ground = true
|
||||
var victim: SimEntity = sim.entities.find(sim.add_player())
|
||||
victim.drop_state = Drop.NONE
|
||||
victim.on_ground = true
|
||||
victim.position = attacker.position + Vector3(0.0, 0.0, Tuning.PLAYER_RADIUS * 2.0 + gap)
|
||||
return sim
|
||||
|
||||
|
||||
## Health and armor a boathook hit takes, headshot or not.
|
||||
func _boathook(headshot: bool) -> int:
|
||||
var def: ItemDef = ItemCatalog.boathook()
|
||||
return roundi(def.damage * (def.headshot_multiplier if headshot else 1.0))
|
||||
|
||||
|
||||
func _hits_on(sim: Simulation, victim: int) -> Array[Dictionary]:
|
||||
var hits: Array[Dictionary] = []
|
||||
for event: Dictionary in sim.events:
|
||||
if event["type"] == "player_hit" and event["victim"] == victim:
|
||||
hits.append(event)
|
||||
return hits
|
||||
|
||||
|
||||
func test_a_swing_damages_a_player_in_reach() -> void:
|
||||
var sim: Simulation = _duel(1.0)
|
||||
var victim: SimEntity = sim.entities.find(2)
|
||||
var start: int = victim.health
|
||||
_swing_for(sim, 1)
|
||||
var hits: Array[Dictionary] = _hits_on(sim, 2)
|
||||
assert_eq(hits.size(), 1, "one hit")
|
||||
assert_true(hits[0]["headshot"], "a level swing from the eye meets the head")
|
||||
assert_eq(victim.health, start - _boathook(true))
|
||||
assert_eq(hits[0]["player"], 1, "the kill feed knows who")
|
||||
assert_eq(hits[0]["item"], ItemCatalog.boathook().code, "and with what")
|
||||
assert_eq(victim.last_attacker, 1)
|
||||
assert_eq(victim.last_cause, SimEntity.CAUSE_WEAPON)
|
||||
|
||||
|
||||
func test_armor_takes_a_swing_first() -> void:
|
||||
var sim: Simulation = _duel(1.0)
|
||||
var victim: SimEntity = sim.entities.find(2)
|
||||
victim.armor = 50
|
||||
var start: int = victim.health
|
||||
# Looking down a little, at the body.
|
||||
_swing_for(sim, 1, -0.35)
|
||||
var hits: Array[Dictionary] = _hits_on(sim, 2)
|
||||
assert_eq(hits.size(), 1)
|
||||
assert_false(hits[0]["headshot"])
|
||||
assert_eq(victim.armor, 50 - _boathook(false))
|
||||
assert_eq(victim.health, start)
|
||||
|
||||
|
||||
func test_a_player_out_of_reach_is_missed() -> void:
|
||||
var sim: Simulation = _duel(Harvest.reach() + 0.3)
|
||||
var victim: SimEntity = sim.entities.find(2)
|
||||
var start: int = victim.health
|
||||
_swing_for(sim, Harvest.swing_interval_ticks() * 2)
|
||||
assert_eq(_hits_on(sim, 2).size(), 0)
|
||||
assert_eq(victim.health, start)
|
||||
|
||||
|
||||
func test_a_wall_between_stops_the_swing() -> void:
|
||||
var sim: Simulation = _duel(1.5)
|
||||
var attacker: SimEntity = sim.entities.find(1)
|
||||
var victim: SimEntity = sim.entities.find(2)
|
||||
var start: int = victim.health
|
||||
# A fixed solid between them, as a point of interest's wall would be.
|
||||
var wall_z: float = attacker.position.z + Tuning.PLAYER_RADIUS + 0.5
|
||||
sim.ground.add_solid(AABB(Vector3(95.0, -1.0, wall_z), Vector3(10.0, 4.0, 0.3)))
|
||||
_swing_for(sim, Harvest.swing_interval_ticks() * 2)
|
||||
assert_eq(_hits_on(sim, 2).size(), 0)
|
||||
assert_eq(victim.health, start)
|
||||
|
||||
|
||||
func test_a_player_in_front_of_a_tree_takes_the_swing_not_the_tree() -> void:
|
||||
var sim: Simulation = _world([_pine_ahead(2.2)])
|
||||
sim.entities.find(1).drop_state = Drop.NONE
|
||||
var victim: SimEntity = sim.entities.find(sim.add_player())
|
||||
victim.drop_state = Drop.NONE
|
||||
victim.position = Vector3(100.0, 0.0, 100.0 + Tuning.PLAYER_RADIUS * 2.0 + 0.6)
|
||||
var start: int = victim.health
|
||||
assert_eq(_swing_for(sim, 1), 0, "no harvest")
|
||||
assert_eq(victim.health, start - _boathook(true))
|
||||
assert_eq(sim.props.health[0], 200, "the tree is untouched")
|
||||
|
||||
Reference in New Issue
Block a user