P4 hazards: food spoilage with rot speed setting, smoking rack and salt, food poisoning, harsher blizzards, hard winters with lake ice, lightning on trees, snow on roofs (protocol 11)

This commit is contained in:
Paul Bailey
2026-11-05 11:49:13 +00:00
parent 657c3140fe
commit 3389ec9a21
27 changed files with 1541 additions and 56 deletions

View File

@@ -32,7 +32,7 @@ signal clock(day: int, time: float) ## the server's time of day
const Identity = preload("res://scripts/net/identity.gd")
const ServerConfig = preload("res://scripts/net/server_config.gd")
const PROTOCOL := 10 ## 3: shared world; 4: the server decides; 5: wildlife; 6: rules and chat (M2.6); 7: the alpha, broken doors; 8: the bear; 9: crows and foxes; 10: the barrow (P3)
const PROTOCOL := 11 ## 3: shared world; 4: the server decides; 5: wildlife; 6: rules and chat (M2.6); 7: the alpha, broken doors; 8: the bear; 9: crows and foxes; 10: the barrow (P3); 11: food spoilage, lightning (P4)
const DEFAULT_PORT := 24242
const HANDSHAKE_TIMEOUT := 10.0
const JOIN_TIMEOUT := 20.0 ## includes the server building its terrain on first join

View File

@@ -226,7 +226,7 @@ func _on_died(peer: int) -> void:
var at: Vector3 = pos + off
at.y = w.terrain.sample_height(at.x, at.z) + 0.05
w.drop_item(st.id, int(st.count), Transform3D(Basis(Vector3.UP, rng.randf() * TAU), at),
{"dur": int(st.dur)} if st.has("dur") else {})
Inventory.extra_of(st))
p.inventory.load_data(Inventory.new(p.inventory.size()).to_data())
# ("keep": you keep everything.)
# They stay down on the death screen for a few seconds, then ask to respawn.
@@ -369,7 +369,7 @@ func _run(p: Node3D, what: String, a: Array) -> void:
var left: int = p.inventory.add_stack(p.cursor)
if left > 0:
w.drop_item(p.cursor.id, left, Transform3D(Basis(), p.global_position + Vector3(0, 0.1, 0)),
{"dur": int(p.cursor.dur)} if p.cursor.has("dur") else {})
Inventory.extra_of(p.cursor))
p.cursor = null
"debug_give":
if cheats and not ItemDB.get_item(_s(a, 0)).is_empty():

View File

@@ -69,6 +69,11 @@ static func difficulty(k: String) -> float:
var d: Variant = v("difficulty")
return float(DIFFICULTY.get(String(d) if d != null else "normal", DIFFICULTY.normal)[k])
## How fast food rots: "normal", "slow" (half speed) or "off".
static func rot() -> String:
var r: Variant = v("rot")
return String(r) if r != null else "normal"
static func grace_days() -> int:
var g: Variant = v("wolf_grace_days")
return clampi(int(g), 0, 10) if g != null else 3

View File

@@ -23,6 +23,7 @@ const DEFAULTS := {
"day_length_minutes": 20,
"wolf_grace_days": 3,
"difficulty": "normal",
"rot": "normal",
"autosave_minutes": 2,
"backups_kept": 10,
"backup_hours": 6,
@@ -32,7 +33,7 @@ const DEFAULTS := {
}
## Settings sent to players when they join (never the password or the lists).
const PUBLIC := ["server_name", "motd", "max_players", "worldlet", "pvp", "raiding", "locks",
"death_penalty", "sleep", "pause_when_empty", "day_length_minutes", "wolf_grace_days", "difficulty"]
"death_penalty", "sleep", "pause_when_empty", "day_length_minutes", "wolf_grace_days", "difficulty", "rot"]
var path := DEFAULT_PATH
var data: Dictionary = {} ## what's in server.json (saved)
@@ -146,6 +147,7 @@ const SETTABLE := {
"sleep": ["all_online", "half", "anyone", "off"],
"pause_when_empty": ["false", "true"],
"difficulty": ["easy", "normal", "hard"],
"rot": ["normal", "slow", "off"],
"wolf_grace_days": "0-10",
"motd": "text",
"server_name": "text",

View File

@@ -365,6 +365,21 @@ func _s2c_node(uid: String, hp: float, point: Vector3, from: Vector3) -> void:
n.apply_remote(hp, point, from)
received += 1
## Lightning struck a tree (hazards.gd, P4): everyone sees it burn. (It
## falls later through _s2c_node, like any felled tree.)
func struck(n: Node3D) -> void:
_all("_s2c_strike", [String(n.uid)])
@rpc("authority", "call_remote", "reliable")
func _s2c_strike(uid: String) -> void:
if not is_client():
return
var n: Node3D = world.props.resource_nodes.get(uid)
var hz: Node = world.get_node_or_null("Hazards")
if n != null and is_instance_valid(n) and hz != null:
hz.show_strike(n)
received += 1
@rpc("authority", "call_remote", "reliable")
func _s2c_regrown(uid: String) -> void:
if not is_client():