The Cove's wreck: driftwood and salt on the beach, the captain's sea chest (a treasure map, nails, salt; once each), each player's own X on the map; online too
This commit is contained in:
@@ -664,9 +664,9 @@ func _scatter_pickups() -> void:
|
||||
rng.seed = world_seed + 6
|
||||
# Order matters: new kinds go at the END so existing saves keep their ids.
|
||||
var want := {"stick": 260, "stone": 170, "flint": 80, "mushroom": 110, "feather": 70, "fiber": 150,
|
||||
"iron_nugget": 70, "clay": 60, "salt": 40}
|
||||
"iron_nugget": 70, "clay": 60, "salt": 40, "driftwood": 45}
|
||||
var radius: Dictionary = {"stick": 0.35, "stone": 0.25, "flint": 0.25, "mushroom": 0.25, "feather": 0.25, "fiber": 0.45,
|
||||
"iron_nugget": 0.25, "clay": 0.3, "salt": 0.25}
|
||||
"iron_nugget": 0.25, "clay": 0.3, "salt": 0.25, "driftwood": 0.5}
|
||||
for id: String in want:
|
||||
# Fibre grows as a plant (wild flax) you pick, 2 fibre a clump.
|
||||
var mesh: Mesh = ItemMeshes.build("fiber_plant") if id == "fiber" else ItemDB.mesh_for(id)
|
||||
@@ -709,10 +709,17 @@ func _scatter_pickups() -> void:
|
||||
var shore: float = 1.0 - smoothstep(terrain.water_level + 0.4, terrain.water_level + 1.8, h)
|
||||
chance = shore * 0.95 if by_lake else 0.0
|
||||
"salt":
|
||||
# Crusts on the cliff tops above the sea (P4).
|
||||
# Crusts on the cliff tops above the sea (P4), or (the Cove)
|
||||
# on the sand just above the waterline.
|
||||
chance = 0.95 if terrain.sea_weight(x, z) > 0.6 and _near_rim(x, z) > 0.35 else 0.0
|
||||
if terrain.beach_weight(x, z) > 0.6 and h < terrain.water_level + 1.2:
|
||||
chance = 0.6
|
||||
"driftwood":
|
||||
# Washed up along a beach (the Cove), near the waterline:
|
||||
# what a boat's hull is made of.
|
||||
chance = 0.95 if terrain.beach_weight(x, z) > 0.6 and h < terrain.water_level + 1.6 else 0.0
|
||||
# A few right by the spawn so the first craft is quick.
|
||||
if Vector2(x - _spawn.x, z - _spawn.z).length() < 18.0 and not id in ["iron_nugget", "clay", "salt"]:
|
||||
if Vector2(x - _spawn.x, z - _spawn.z).length() < 18.0 and not id in ["iron_nugget", "clay", "salt", "driftwood"]:
|
||||
chance += 0.5
|
||||
if keep > chance:
|
||||
continue
|
||||
|
||||
@@ -55,6 +55,7 @@ var _pieces: Node3D
|
||||
var hud: CanvasLayer
|
||||
var pier: Node3D ## the Cove's pier (scripts/world/pier.gd), or null
|
||||
var tunnel: Node3D ## the cliff tunnel (scripts/world/tunnel.gd, J1), or null
|
||||
var wreck: Node3D ## the Cove's wreck (scripts/world/wreck.gd, 0.6.0), or null
|
||||
var sea_cave: Node3D ## the Cove's end of it (scripts/world/sea_cave.gd), or null
|
||||
var traveling := false ## on the way to another worldlet (the scene is about to change)
|
||||
var _session_time := 0.0 ## seconds played since the last save
|
||||
@@ -365,6 +366,15 @@ func _on_terrain_ready() -> void:
|
||||
props.pier = pr
|
||||
else:
|
||||
pr.free()
|
||||
# The wreck (0.6.0): on the Cove's beach, with the sea chest's treasure maps.
|
||||
var wk := preload("res://scripts/world/wreck.gd").new()
|
||||
wk.name = "Wreck"
|
||||
add_child(wk)
|
||||
if not menu_mode and wk.place(self):
|
||||
wreck = wk
|
||||
props.keep_clear.append([wk.global_position, 9.0])
|
||||
else:
|
||||
wk.free()
|
||||
# The journey's ways on (J1): the Valley's cliff tunnel and the Cove's sea
|
||||
# cave. On a server too (J3): the server decides the digging and the
|
||||
# crossings, and every player's game has the same rock to see and walk.
|
||||
@@ -690,6 +700,7 @@ func collect_save() -> Dictionary:
|
||||
"barrow": barrow.save_data() if barrow != null else {},
|
||||
"stones": stones.save_data() if stones != null else {},
|
||||
"tunnel": tunnel.to_data() if tunnel != null else {},
|
||||
"wreck": wreck.to_data() if wreck != null else {},
|
||||
"map": map_data(),
|
||||
}
|
||||
|
||||
@@ -706,6 +717,7 @@ func _shared_state(harvested: Dictionary, regrow: Dictionary, taken: Array, drop
|
||||
"barrow": barrow.save_data() if barrow != null else {},
|
||||
"stones": stones.save_data() if stones != null else {},
|
||||
"tunnel": tunnel.to_data() if tunnel != null else {},
|
||||
"wreck": wreck.to_data() if wreck != null else {},
|
||||
}
|
||||
|
||||
## The live pieces (placed and not being removed).
|
||||
@@ -839,6 +851,8 @@ func _apply_save(s: Dictionary, with_player: bool) -> void:
|
||||
stones.load_data(s.get("stones", {}))
|
||||
if tunnel != null:
|
||||
tunnel.load_data(s.get("tunnel", {}))
|
||||
if wreck != null:
|
||||
wreck.load_data(s.get("wreck", {}))
|
||||
if with_player:
|
||||
load_map_data(String(s.get("map", "")))
|
||||
# The bear (bear_range.gd): applied when it's set up, after loading.
|
||||
@@ -971,6 +985,12 @@ func map_marks() -> Array:
|
||||
add.call("pier", (pier.start + pier.end) * 0.5, "The pier")
|
||||
if sea_cave != null:
|
||||
add.call("cave", sea_cave.global_position, "Sea cave")
|
||||
if wreck != null:
|
||||
add.call("wreck", wreck.global_position, "The wreck")
|
||||
# Your X: shown while you carry the map (even where you haven't been).
|
||||
var x := treasure_spot(my_id())
|
||||
if x != Vector3.INF and player.inventory.count("treasure_map") > 0:
|
||||
out.append({"kind": "treasure", "pos": x, "label": "X"})
|
||||
for piece in all_pieces():
|
||||
var id: String = String(piece.get("item_id"))
|
||||
if piece.is_in_group("bed"):
|
||||
@@ -983,6 +1003,70 @@ func map_marks() -> Array:
|
||||
add.call("grave", piece.global_position, "Your things")
|
||||
return out
|
||||
|
||||
# --- the pirate treasure (0.6.0, docs/WORLDLETS_DESIGN.md §5) ----------------------
|
||||
|
||||
var _treasure_spots: Dictionary = {} ## player id -> Vector3 (worked out once)
|
||||
|
||||
## Where player `id`'s treasure is buried (each player's map has its own X):
|
||||
## a dry, gentle spot in the Cove's hills, picked from the world's seed and
|
||||
## the player's id, clear of the water, the stream and the other places.
|
||||
## INF where there's no treasure (no wreck in this land).
|
||||
func treasure_spot(id: String) -> Vector3:
|
||||
if wreck == null:
|
||||
return Vector3.INF
|
||||
if _treasure_spots.has(id):
|
||||
return _treasure_spots[id]
|
||||
var spots := treasure_spots()
|
||||
var at: Vector3 = Vector3.INF if spots.is_empty() else spots[posmod(hash(id), spots.size())]
|
||||
_treasure_spots[id] = at
|
||||
return at
|
||||
|
||||
## The world's hiding places for treasure: up to 12, at least 25 m apart,
|
||||
## picked from its seed (so each player's X is one of these, and different
|
||||
## players' are usually far apart).
|
||||
var _hiding: Array = []
|
||||
func treasure_spots() -> Array:
|
||||
if not _hiding.is_empty() or wreck == null:
|
||||
return _hiding
|
||||
var t: Node3D = terrain
|
||||
var rng := RandomNumberGenerator.new()
|
||||
rng.seed = t.noise_seed * 7919 + 2024
|
||||
var avoid: Array = [wreck.global_position, _spawn]
|
||||
for n in [den, pier, sea_cave]:
|
||||
if n != null and n.is_inside_tree():
|
||||
avoid.append(n.global_position if n != pier else (pier.start + pier.end) * 0.5)
|
||||
for _try in range(3000):
|
||||
if _hiding.size() >= 12:
|
||||
break
|
||||
var a := rng.randf() * TAU
|
||||
var r: float = sqrt(rng.randf()) * t.play_radius * 0.85
|
||||
var x: float = cos(a) * r
|
||||
var z: float = sin(a) * r
|
||||
if not t.inside_boundary(x, z, 14.0) or t.beach_weight(x, z) > 0.3 or t.near_stream(x, z, 4.0):
|
||||
continue
|
||||
var h: float = t.sample_height(x, z)
|
||||
if h < t.water_level + 2.0 or t.sample_normal(x, z).y < 0.92 or h > t.snow_height - 6.0:
|
||||
continue
|
||||
if avoid.any(func(q): return Vector2(q.x - x, q.z - z).length() < 22.0):
|
||||
continue
|
||||
if _hiding.any(func(q): return Vector2(q.x - x, q.z - z).length() < 25.0):
|
||||
continue
|
||||
_hiding.append(Vector3(x, h, z))
|
||||
return _hiding
|
||||
|
||||
## The id of the player at this game (yours; a server's character's own).
|
||||
func my_id() -> String:
|
||||
return String(Net.get_identity().player_id)
|
||||
|
||||
## Right-click with the treasure map: your X goes on your map, and it opens.
|
||||
func read_map(p: Node3D) -> void:
|
||||
if wreck == null:
|
||||
Actions.notify.emit("The X is in the hills above the Cove: read it there")
|
||||
return
|
||||
Actions.notify.emit("X marks the spot, in the hills above the bay: it's on your map now (N). Take a pickaxe")
|
||||
if hud != null and hud.map != null and not hud.map.is_open():
|
||||
hud.map.open()
|
||||
|
||||
## In the cliff tunnel (J1): no daylight, no weather, sheltered.
|
||||
func underground_at(p: Vector3) -> bool:
|
||||
return tunnel != null and tunnel.contains(p)
|
||||
|
||||
149
scripts/world/wreck.gd
Normal file
149
scripts/world/wreck.gd
Normal file
@@ -0,0 +1,149 @@
|
||||
extends Node3D
|
||||
## The Cove's wreck (docs/WORLDLETS_DESIGN.md §5, 0.6.0): an old ship driven
|
||||
## up on the sand at the far end of the bay from the sea cave, her bow in the
|
||||
## shallows, one side stove in. Inside, the captain's sea chest: a torn
|
||||
## treasure map and a few useful things, **once for each player** (single-
|
||||
## player and online alike: who's had theirs is saved with the Cove).
|
||||
##
|
||||
## Placed from the terrain alone, like the pier, so it's the same for
|
||||
## everyone; only `opened` (who's had their share) is saved.
|
||||
|
||||
const Pier = preload("res://scripts/world/pier.gd")
|
||||
const OAK := Color(0.36, 0.25, 0.16)
|
||||
const DARK := Color(0.24, 0.17, 0.11)
|
||||
const WET := Color(0.2, 0.18, 0.15)
|
||||
const IRON := Color(0.22, 0.22, 0.24)
|
||||
## What's in the sea chest, for each player once.
|
||||
const LOOT := {"treasure_map": 1, "nails": 4, "salt": 2}
|
||||
|
||||
var world: Node3D
|
||||
var opened: Array = [] ## the player ids who've had their share
|
||||
var chest: StaticBody3D
|
||||
var front := Vector3.ZERO ## where you stand to reach into the chest
|
||||
|
||||
func place(w: Node3D) -> bool:
|
||||
world = w
|
||||
var t: Node3D = w.terrain
|
||||
if not w.has_place("wreck") or not t._has_beach:
|
||||
return false
|
||||
# The far end of the beach from the sea cave, where the sand meets the water.
|
||||
var a := deg_to_rad(t.beach_angle_deg - t.beach_half_width_deg * 0.8)
|
||||
var dir := Vector2(cos(a), sin(a))
|
||||
var r: float = t._shore_d() - t._rim_offset(dir.x, dir.y)
|
||||
var at2 := dir * (r - 1.0)
|
||||
var at := Vector3(at2.x, maxf(t.sample_height(at2.x, at2.y), t.water_level - 0.3), at2.y)
|
||||
# Bow out to sea (+Z local), a little askew, heeled over on her side.
|
||||
var out := Vector3(dir.x, 0.0, dir.y).rotated(Vector3.UP, 0.35)
|
||||
global_transform = Transform3D(Basis.looking_at(-out, Vector3.UP), at)
|
||||
_build()
|
||||
add_to_group("wreck")
|
||||
return true
|
||||
|
||||
func _build() -> void:
|
||||
var st := SurfaceTool.new()
|
||||
st.begin(Mesh.PRIMITIVE_TRIANGLES)
|
||||
var body := StaticBody3D.new()
|
||||
body.name = "Hull"
|
||||
add_child(body)
|
||||
var heel := Basis(Vector3(0, 0, 1), deg_to_rad(-14.0))
|
||||
var parts: Array = [
|
||||
# [centre, size, colour] in the hull's frame (+Z the bow, +X starboard)
|
||||
[Vector3(0, 0.12, 0), Vector3(0.35, 0.25, 9.0), DARK], # keel
|
||||
[Vector3(-1.45, 0.75, 0), Vector3(0.14, 1.3, 8.2), OAK], # port side, whole
|
||||
[Vector3(1.45, 0.75, 2.6), Vector3(0.14, 1.3, 3.0), OAK], # starboard, forward
|
||||
[Vector3(1.45, 0.55, -3.0), Vector3(0.14, 0.9, 2.2), OAK], # starboard, aft (stove in between)
|
||||
[Vector3(0, 0.75, -4.1), Vector3(2.9, 1.3, 0.14), OAK], # transom
|
||||
[Vector3(0, 0.05, 0), Vector3(2.8, 0.1, 7.6), WET], # bilge boards
|
||||
[Vector3(0, 1.8, 1.4), Vector3(0.22, 2.6, 0.22), DARK], # mast stump
|
||||
]
|
||||
for p in parts:
|
||||
var c: Vector3 = heel * p[0]
|
||||
Pier._box(st, c, p[1], p[2])
|
||||
var cs := CollisionShape3D.new()
|
||||
var box := BoxShape3D.new()
|
||||
box.size = p[1]
|
||||
cs.shape = box
|
||||
cs.transform = Transform3D(heel, c)
|
||||
body.add_child(cs)
|
||||
# Ribs over the open hull, some broken off short.
|
||||
for i in range(6):
|
||||
var z := -3.4 + i * 1.3
|
||||
for side in [-1.0, 1.0]:
|
||||
if side > 0.0 and z > -1.8 and z < 1.0:
|
||||
continue # (the stove-in side)
|
||||
var h := 1.9 if (i + int(side)) % 3 != 0 else 1.2
|
||||
Pier._box(st, heel * Vector3(side * 1.3, h * 0.5 + 0.5, z), Vector3(0.12, h, 0.14), DARK)
|
||||
# Planks strewn on the sand on the open side.
|
||||
var rng := RandomNumberGenerator.new()
|
||||
rng.seed = 919
|
||||
for i in range(5):
|
||||
var off := Vector3(2.6 + rng.randf() * 2.5, 0.05, -2.0 + rng.randf() * 4.0)
|
||||
Pier._box(st, off, Vector3(0.3, 0.06, 1.6 + rng.randf()), OAK.darkened(rng.randf() * 0.3))
|
||||
st.generate_normals()
|
||||
var mi := MeshInstance3D.new()
|
||||
mi.name = "Ship"
|
||||
mi.mesh = st.commit()
|
||||
var mat := StandardMaterial3D.new()
|
||||
mat.vertex_color_use_as_albedo = true
|
||||
mat.roughness = 0.95
|
||||
mi.material_override = mat
|
||||
add_child(mi)
|
||||
# The captain's sea chest, wedged inside by the break.
|
||||
chest = StaticBody3D.new()
|
||||
chest.name = "SeaChest"
|
||||
chest.collision_layer = 1 | 2
|
||||
chest.set_script(preload("res://scripts/world/wreck_chest.gd"))
|
||||
chest.wreck = self
|
||||
var cst := SurfaceTool.new()
|
||||
cst.begin(Mesh.PRIMITIVE_TRIANGLES)
|
||||
Pier._box(cst, Vector3(0, 0.25, 0), Vector3(0.9, 0.5, 0.55), Color(0.3, 0.2, 0.12))
|
||||
Pier._box(cst, Vector3(0, 0.55, 0), Vector3(0.92, 0.12, 0.57), Color(0.27, 0.18, 0.1))
|
||||
for x in [-0.32, 0.32]:
|
||||
Pier._box(cst, Vector3(x, 0.32, 0), Vector3(0.06, 0.64, 0.6), IRON)
|
||||
cst.generate_normals()
|
||||
var cmi := MeshInstance3D.new()
|
||||
cmi.mesh = cst.commit()
|
||||
cmi.material_override = mat
|
||||
chest.add_child(cmi)
|
||||
var ccs := CollisionShape3D.new()
|
||||
var cb := BoxShape3D.new()
|
||||
cb.size = Vector3(0.9, 0.62, 0.55)
|
||||
ccs.shape = cb
|
||||
ccs.position = Vector3(0, 0.31, 0)
|
||||
chest.add_child(ccs)
|
||||
add_child(chest)
|
||||
chest.transform = Transform3D(heel * Basis(Vector3.UP, 0.4), heel * Vector3(0.5, 0.12, -0.4))
|
||||
front = global_transform * (heel * Vector3(2.4, 0.0, -0.4))
|
||||
front.y = world.terrain.sample_height(front.x, front.z)
|
||||
|
||||
# --- the sea chest -------------------------------------------------------------
|
||||
|
||||
## Whether player `id` has had their share of the chest.
|
||||
func had(id: String) -> bool:
|
||||
return id in opened
|
||||
|
||||
## Gives player `p` (id `id`) their share: the map and the rest, once.
|
||||
## Returns false (and says why) when they've had it, or their bag's too full.
|
||||
func open_for(p: Node, id: String) -> bool:
|
||||
if had(id):
|
||||
Actions.tell(p, "The sea chest's empty: you've had what was in it")
|
||||
return false
|
||||
for item in LOOT:
|
||||
if p.inventory.space_for(item) < int(LOOT[item]):
|
||||
Actions.tell(p, "Make room in your bag first")
|
||||
return false
|
||||
for item in LOOT:
|
||||
p.inventory.add(item, int(LOOT[item]))
|
||||
opened.append(id)
|
||||
Actions.tell(p, "In the captain's sea chest: a torn treasure map, %d nails and %d salt. Right-click the map to read it" % [
|
||||
int(LOOT.nails), int(LOOT.salt)])
|
||||
Sfx.at("door_open", chest.global_position)
|
||||
if Net.is_server():
|
||||
WorldNet.mark_changed()
|
||||
return true
|
||||
|
||||
func to_data() -> Dictionary:
|
||||
return {"opened": opened.duplicate()}
|
||||
|
||||
func load_data(d: Dictionary) -> void:
|
||||
opened = (d.get("opened", []) as Array).duplicate()
|
||||
1
scripts/world/wreck.gd.uid
Normal file
1
scripts/world/wreck.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dydutxxckscny
|
||||
23
scripts/world/wreck_chest.gd
Normal file
23
scripts/world/wreck_chest.gd
Normal file
@@ -0,0 +1,23 @@
|
||||
extends StaticBody3D
|
||||
## The wreck's sea chest (wreck.gd): what you look at and press E on. Online,
|
||||
## your game asks the server, which gives you your share once.
|
||||
|
||||
var wreck: Node3D
|
||||
|
||||
func interact_prompt(player: Node) -> String:
|
||||
if wreck.had(_id(player)):
|
||||
return "The captain's sea chest (empty: you've had what was in it)"
|
||||
return "[E] Open the captain's sea chest"
|
||||
|
||||
func interact(player: Node) -> void:
|
||||
if wreck.world.is_online():
|
||||
PlayerNet.ask("wreck_chest", [])
|
||||
return
|
||||
wreck.open_for(player, _id(player))
|
||||
|
||||
## Whose share: the player's id (a server's character, or, at home, yours).
|
||||
static func _id(player: Node) -> String:
|
||||
var pid: Variant = player.get("player_id")
|
||||
if pid != null and not String(pid).is_empty():
|
||||
return String(pid)
|
||||
return String(Net.get_identity().player_id)
|
||||
1
scripts/world/wreck_chest.gd.uid
Normal file
1
scripts/world/wreck_chest.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://oeh0v78qjmnh
|
||||
Reference in New Issue
Block a user