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
128 lines
4.0 KiB
GDScript
128 lines
4.0 KiB
GDScript
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()
|