Wolves with a den, fishing, and a mixed diet

Wolves
- Den: a boulder cave at the foot of the rim, sited from the seed (away
  from the sea and spawn, mouth toward the valley, clearing in front)
- Grace period: no wolves days 1-2; they move in on day 3 and howl; hunting
  from night 4; pack of 2, 3 from day 6, 4 from day 9; replaced by day
- Wary pack hunters: circle and dart in one at a time; a lit campfire is a
  safe zone, a torch makes them hesitate, walls block bites (line of
  sight); hit one and the pack turns; hurt wolves flee; a lone wolf is
  timid; by day they defend the den; home at dawn
- Glowing eyes, synthesised howls, can't sleep with wolves prowling
- Wolf pelt and Wolf Cloak (+25 warmth)
- Animals take a committed detour around obstacles

Fishing
- Fishing rod (workbench); cast a float onto the lake, 1.5 s to land a bite
- Perch and rarer trout; faster bites at dawn/dusk and in rain; grill them
- Visible fish near the shore that jump with splash rings

Mixed diet
- Foods belong to meat, fish or greens; each level runs down over ~1.5 days
- One group low: no healing; two low: Malnourished (health drains);
  all three good: Balanced diet (heal x1.5); HUD diet bars; saved

Tests: test_wolves and test_fishing_diet; run_all.sh covers 9 suites
This commit is contained in:
Paul Bailey
2026-11-04 11:32:16 +00:00
parent 67bf85523d
commit f174221268
23 changed files with 2069 additions and 21 deletions

127
scripts/fishing/bobber.gd Normal file
View File

@@ -0,0 +1,127 @@
extends Node3D
## A cast fishing float.
##
## flying -> it arcs out from the rod tip.
## floating -> it landed on deep enough water; a fish bites after a while
## (sooner at dawn and dusk, and in the rain).
## biting -> the float dips; you have BITE_WINDOW seconds to reel in
## (Actions.reel), or the fish gets away and you wait again.
## landed -> it fell on dry ground: nothing will bite. Reel in and try again.
## Walking too far away snaps the line.
##
## A line is drawn from the rod tip each frame (hands.gd gives the tip).
const BITE_WINDOW := 1.5
const MIN_DEPTH := 0.5 ## water this deep under the float, or no fish
const LINE_LENGTH := 26.0
var world: Node3D
var player: Node3D
var state := "flying"
var velocity := Vector3.ZERO
var fish := "" ## what's on the line while biting
var wait_left := 0.0
var bite_left := 0.0
var rng := RandomNumberGenerator.new()
var tip := Vector3.ZERO ## rod tip, world space (set by hands.gd)
var _t := 0.0
var _mesh: MeshInstance3D
var _line: MeshInstance3D
var _imesh: ImmediateMesh
func setup(w: Node3D, p: Node3D, from: Vector3, vel: Vector3, seed: int) -> void:
world = w
player = p
velocity = vel
position = from
tip = from
rng.seed = seed
_mesh = MeshInstance3D.new()
_mesh.mesh = ItemDB.mesh_for("bobber")
_mesh.material_override = ItemDB.item_material()
_mesh.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
add_child(_mesh)
_imesh = ImmediateMesh.new()
_line = MeshInstance3D.new()
_line.mesh = _imesh
_line.top_level = true
_line.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
var lm := StandardMaterial3D.new()
lm.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
lm.albedo_color = Color(0.9, 0.9, 0.85, 0.7)
lm.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
_line.material_override = lm
add_child(_line)
func _physics_process(delta: float) -> void:
step(delta)
func _process(_delta: float) -> void:
_draw_line()
## How long until the next bite (seconds).
func _next_wait() -> float:
var h: float = world.day_night.hours()
var k := 1.0
if (h > 5.0 and h < 8.5) or (h > 17.0 and h < 20.5):
k *= 0.6 # fish feed at dawn and dusk
if world.weather.precip > 0.3:
k *= 0.8
return rng.randf_range(5.0, 14.0) * k
func _pick_fish() -> String:
var h: float = world.day_night.hours()
var trout := 0.4 if (h > 5.0 and h < 8.5) or (h > 17.0 and h < 20.5) else 0.22
return "trout" if rng.randf() < trout else "perch"
func step(dt: float) -> void:
_t += dt
var terrain: Node3D = world.terrain
if global_position.distance_to(player.global_position) > LINE_LENGTH + 4.0:
Actions.notify.emit("The line snapped")
world.end_fishing()
return
match state:
"flying":
velocity.y -= 9.8 * dt
var p := global_position + velocity * dt
var ground: float = terrain.sample_height(p.x, p.z)
if p.y <= terrain.water_level and ground < terrain.water_level - MIN_DEPTH:
p.y = terrain.water_level
state = "floating"
wait_left = _next_wait()
elif p.y <= ground + 0.03:
p.y = ground + 0.03
state = "landed"
Actions.notify.emit("Cast into the water (deeper than this)" if ground < terrain.water_level else "Cast into the water")
global_position = p
"floating":
wait_left -= dt
_mesh.position.y = sin(_t * 2.2) * 0.012
if wait_left <= 0.0:
state = "biting"
fish = _pick_fish()
bite_left = BITE_WINDOW
Actions.notify.emit("Bite! Click to reel in")
"biting":
bite_left -= dt
# The float bobs hard and goes under.
_mesh.position.y = -0.06 + sin(_t * 18.0) * 0.03
if bite_left <= 0.0:
state = "floating"
fish = ""
wait_left = _next_wait() * 1.3
_mesh.position.y = 0.0
Actions.notify.emit("It got away")
func _draw_line() -> void:
_imesh.clear_surfaces()
_imesh.surface_begin(Mesh.PRIMITIVE_LINE_STRIP)
var a := tip
var b := global_position + Vector3(0, 0.1, 0)
for i in range(13):
var k := i / 12.0
var p := a.lerp(b, k)
p.y -= sin(k * PI) * 0.06 * a.distance_to(b) * (0.3 if state == "biting" else 1.0) # slack
_imesh.surface_add_vertex(p)
_imesh.surface_end()

View File

@@ -0,0 +1,126 @@
extends Node3D
## Fish you can see in the lake, so it's clear there's something to catch.
## Purely visual (the catch comes from bobber.gd).
##
## - A few swim slow loops just under the surface over water at least 0.8 m
## deep, including the shelf near the shore where you'll be standing.
## - Every few seconds one jumps: a leap out of the water and a spreading
## splash ring. That's the cue that tells you where to cast.
const SCALE := 1.6 ## drawn bigger than the item so they read at a distance
var terrain: Node3D
var _fish: Array = [] ## [MeshInstance3D, centre, radius, speed, phase, depth]
var _rng := RandomNumberGenerator.new()
var _jump_left := 3.0
var _jumping := -1 ## index of the fish mid-leap, or -1
var _jump_t := 0.0
var _rings: Array = [] ## [MeshInstance3D, age]
static var _ring_mesh: Mesh
func setup(t: Node3D, count: int = 14) -> void:
terrain = t
_rng.seed = t.noise_seed + 501
var lake: Vector2 = t.lake_center
var tries := 0
while _fish.size() < count and tries < 600:
tries += 1
var a := _rng.randf() * TAU
# Bias toward the outer, shallower ring so some swim near the shore.
var r: float = sqrt(_rng.randf()) * t.lake_radius * 0.7
var c := Vector2(lake.x + cos(a) * r, lake.y + sin(a) * r)
var loop := _rng.randf_range(1.2, 3.0)
var ok := true
for k in range(8):
var q := c + Vector2(cos(k * TAU / 8.0), sin(k * TAU / 8.0)) * loop
if t.sample_height(q.x, q.y) > t.water_level - 0.8:
ok = false
break
if not ok:
continue
var mi := MeshInstance3D.new()
mi.mesh = ItemDB.mesh_for("trout" if _rng.randf() < 0.3 else "perch")
mi.material_override = ItemDB.item_material()
mi.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
mi.scale = Vector3.ONE * SCALE
add_child(mi)
_fish.append([mi, c, loop, _rng.randf_range(0.25, 0.5) * (1.0 if _rng.randf() < 0.5 else -1.0),
_rng.randf() * TAU, _rng.randf_range(0.2, 0.35)])
## Where fish `i` is in its loop at time `t`.
func _swim_pos(i: int, t: float) -> Vector3:
var f: Array = _fish[i]
var a: float = t * f[3] + f[4]
var p: Vector2 = (f[1] as Vector2) + Vector2(cos(a), sin(a)) * float(f[2])
return Vector3(p.x, terrain.water_level - f[5] + sin(t * 1.3 + f[4]) * 0.04, p.y)
func _process(delta: float) -> void:
var t := Time.get_ticks_msec() / 1000.0
for i in range(_fish.size()):
if i == _jumping:
continue
var f: Array = _fish[i]
var mi: MeshInstance3D = f[0]
mi.position = _swim_pos(i, t)
var a: float = t * f[3] + f[4]
# Face along the loop (fish mesh's head is +X), with a little wiggle.
var tangent := Vector2(-sin(a), cos(a)) * signf(f[3])
mi.rotation = Vector3(0, atan2(-tangent.y, tangent.x) + sin(t * 6.0 + f[4]) * 0.15, 0)
_update_jump(delta, t)
_update_rings(delta)
func _update_jump(dt: float, t: float) -> void:
if _fish.is_empty():
return
if _jumping < 0:
_jump_left -= dt
if _jump_left <= 0.0:
_jumping = _rng.randi() % _fish.size()
_jump_t = 0.0
_ring(_swim_pos(_jumping, t))
return
# A 0.8 s arc, half a metre up, nose up then nose down.
_jump_t += dt
var k := _jump_t / 0.8
var mi: MeshInstance3D = _fish[_jumping][0]
var base := _swim_pos(_jumping, t)
mi.position = base + Vector3(0, sin(clampf(k, 0.0, 1.0) * PI) * 0.55 + 0.25, 0)
mi.rotation.z = lerpf(1.0, -1.0, clampf(k, 0.0, 1.0))
if k >= 1.0:
_ring(base)
mi.rotation.z = 0.0
_jumping = -1
_jump_left = _rng.randf_range(3.0, 8.0)
## A splash ring that spreads and fades on the surface.
func _ring(at: Vector3) -> void:
if _ring_mesh == null:
var tm := TorusMesh.new()
tm.inner_radius = 0.42
tm.outer_radius = 0.5
tm.rings = 24
tm.ring_segments = 4
var m := StandardMaterial3D.new()
m.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
m.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
m.albedo_color = Color(0.9, 0.95, 1.0, 0.8)
tm.material = m
_ring_mesh = tm
var mi := MeshInstance3D.new()
mi.mesh = _ring_mesh
mi.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
mi.position = Vector3(at.x, terrain.water_level + 0.02, at.z)
mi.scale = Vector3(0.4, 0.05, 0.4)
add_child(mi)
_rings.append([mi, 0.0])
func _update_rings(dt: float) -> void:
for r in _rings.duplicate():
r[1] += dt
var mi: MeshInstance3D = r[0]
var s: float = 0.4 + r[1] * 1.6
mi.scale = Vector3(s, 0.05, s)
mi.transparency = clampf(r[1] / 1.6, 0.0, 1.0)
if r[1] >= 1.6:
mi.queue_free()
_rings.erase(r)