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:
+28
-3
@@ -7,6 +7,11 @@
|
||||
## grown by Tuning.HARVEST_AIM_SLACK, the ray enters, unless terrain or another solid is
|
||||
## in the way first. Each hit does Tuning.HARVEST_DAMAGE to the prop and gives the
|
||||
## player Tuning.HARVEST_PER_HIT of the prop's material, up to Tuning.MATERIAL_CAP.
|
||||
##
|
||||
## A swing also fights. The same ray is traced as a shot is (Weapons.trace, with lag
|
||||
## compensation), and another player it reaches 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 like any other hit.
|
||||
class_name Harvest
|
||||
extends RefCounted
|
||||
|
||||
@@ -95,16 +100,19 @@ static func _prop_hit(player: SimEntity, ground: SimGround, props: PropSet) -> V
|
||||
|
||||
## Swings if the player can and isn't cooling down. Returns the prop hit, or -1.
|
||||
## Appends "harvest" and "prop_destroyed" events to `events`. A built piece nearer than
|
||||
## any prop takes the hit instead, losing Tuning.HARVEST_DAMAGE and giving nothing.
|
||||
static func swing(player: SimEntity, ground: SimGround, props: PropSet, events: Array[Dictionary], structures: StructureSet = null) -> int:
|
||||
## any prop takes the hit instead, losing Tuning.HARVEST_DAMAGE and giving nothing. With
|
||||
## `sim`, a player nearer than both takes the hit instead (see the class notes).
|
||||
static func swing(player: SimEntity, ground: SimGround, props: PropSet, events: Array[Dictionary], structures: StructureSet = null, sim: Simulation = null) -> int:
|
||||
if player.action_cooldown > 0 or not can_swing(player):
|
||||
return -1
|
||||
player.action_cooldown = swing_interval_ticks()
|
||||
# Every swing, hit or miss, for whoever draws or hears it.
|
||||
events.append({"type": "swing", "player": player.id, "from": eye(player), "direction": look_direction(player)})
|
||||
var hit: Vector2 = _prop_hit(player, ground, props)
|
||||
var piece_hit: Vector2 = _piece_hit(player, ground, structures) if structures != null else Vector2(1.0, 0.0)
|
||||
if sim != null and _hit_player(sim, player, minf(hit.x, piece_hit.x)):
|
||||
return -1
|
||||
if structures != null:
|
||||
var piece_hit: Vector2 = _piece_hit(player, ground, structures)
|
||||
if piece_hit.y != 0.0 and piece_hit.x <= hit.x:
|
||||
events.append({"type": "piece_hit", "player": player.id, "piece": int(piece_hit.y), "amount": Tuning.HARVEST_DAMAGE})
|
||||
structures.damage(int(piece_hit.y), Tuning.HARVEST_DAMAGE, "boathook", ground, events)
|
||||
@@ -118,3 +126,20 @@ static func swing(player: SimEntity, ground: SimGround, props: PropSet, events:
|
||||
if props.damage(prop, Tuning.HARVEST_DAMAGE):
|
||||
events.append({"type": "prop_destroyed", "prop": prop})
|
||||
return prop
|
||||
|
||||
|
||||
## Traces the swing for players. If one is hit nearer than `nearest` (the fraction of
|
||||
## the swing where a prop or piece would be hit), damages them and returns true.
|
||||
static func _hit_player(sim: Simulation, player: SimEntity, nearest: float) -> bool:
|
||||
var from: Vector3 = eye(player)
|
||||
var to: Vector3 = from + look_direction(player) * reach()
|
||||
var hit: Weapons.Hit = Weapons.trace(sim, from, to, player.id, Weapons.view_time(player, sim.tick))
|
||||
if hit.kind != Weapons.HIT_PLAYER or hit.fraction > nearest:
|
||||
return false
|
||||
var def: ItemDef = ItemCatalog.boathook()
|
||||
var amount: int = def.damage
|
||||
if hit.headshot:
|
||||
amount = roundi(amount * def.headshot_multiplier)
|
||||
sim.events.append({"type": "impact", "player": player.id, "item": def.code, "point": hit.point, "hit": hit.kind, "target": hit.target})
|
||||
Weapons.damage_player(sim, sim.entities.find(hit.target), amount, player.id, hit.headshot, def.code)
|
||||
return true
|
||||
|
||||
@@ -249,7 +249,7 @@ func _apply_command(player: SimEntity, command: PlayerCommand) -> void:
|
||||
Building.act(self, player, command)
|
||||
return
|
||||
if player.selected == BOATHOOK_SLOT:
|
||||
Harvest.swing(player, ground, props, events, structures)
|
||||
Harvest.swing(player, ground, props, events, structures, self)
|
||||
else:
|
||||
var def: ItemDef = Inventory.held_def(player)
|
||||
if def != null and def.kind == ItemDef.CONSUMABLE:
|
||||
|
||||
@@ -290,6 +290,10 @@ const BOT_AIM_WANDER_TICKS: int = 12
|
||||
const BOT_BLOOM_PAUSE_DEGREES: float = 3.0
|
||||
## Bots notice items lying within this distance.
|
||||
const BOT_LOOT_SIGHT_METRES: float = 12.0
|
||||
## A bot with no gun goes for an opponent in view this close with its boathook, in
|
||||
## metres, and swings once its eye is this far from the opponent's body.
|
||||
const BOT_BRAWL_METRES: float = 6.0
|
||||
const BOT_SWING_METRES: float = 2.3
|
||||
## The most weapons a bot carries; its other slots are for consumables.
|
||||
const BOT_MAX_WEAPONS: int = 3
|
||||
## Ground counts as safe from the next tide level when it stands this far above it.
|
||||
|
||||
Reference in New Issue
Block a user