#129 (#131, #132, #133): a quest chain, and a World Ship out of reach

Sixteen quests that walk a new game through the things it contains: ore,
the mothership, exploration, a yard and a second hull, planetfall and
conquest, extractors, gas, freight, power, the lab, a new vessel type, an
outpost, and a survey.

The chain turns on the second quest. The fleet builds the mothership to
call the World Ship and hears nothing - and the array is not at fault. The
breach put them further out than that signal will carry, so every quest
after it is a search that has to be flown rather than transmitted.

Three pieces:

  Quests.gd  the chain, as data and nothing else. Two rules it obeys:
             nothing may ask for something unreachable - research points
             come only from conquering a planet, so every doctrine that
             costs them sits after the conquest quest - and a quest names
             one goal, with the research it implies said in the brief
             rather than split into an errand of its own.
  GameState  how far along the chain the player is, and the answer to each
             goal kind. Progress latches for free: the chain is walked one
             quest at a time, so collecting five ore and spending it cannot
             un-complete the quest that asked for five - by then nothing is
             asking. It lives here so a quest finished on a planet surface
             is still finished after take-off.
  the HUD    QuestTracker, the standing objective, in the wave alert's
             idiom; QuestDirector, which reads the lines out.

Lines are QUEUED by GameState and drained by the director rather than
emitted at a banner, because quests advance in the autoload, which runs on
a planet surface too - where a line emitted straight at a banner would be
lost. Both scenes now carry a banner, a tracker and a director, so a quest
finished underground is announced underground.

The chain is armed by reset_new_game(), the same gate the prologue uses -
the only door into a real game - so instantiating a scene is not by itself
a reason to start briefing somebody.
This commit is contained in:
Loïc Wisniewski 2026-08-28 14:41:03 +02:00
commit 397983b611
13 changed files with 917 additions and 4 deletions

View file

@ -9,6 +9,7 @@ const PLANET_DEFINITIONS = preload("res://planets/PlanetDefinitions.gd")
# global class table is necessarily populated, the same hazard PlanetSetups.gd
# works around.
const WORLD_GEN = preload("res://world/WorldGen.gd")
const QUESTS = preload("res://core/Quests.gd")
# Autoload singleton - the one thing that survives change_scene_to_file()
@ -676,6 +677,7 @@ func reset_new_game() -> void:
planet_capture.clear()
vessel_targets.clear()
reset_waves()
reset_quests(true)
reset_progression()
reset_formation()
@ -2545,6 +2547,7 @@ func _process(delta: float) -> void:
_advance_repairs(delta)
_advance_resource_converters(delta)
_advance_distorder_drain(delta)
_advance_quests()
for e in extractors:
e.mining_progress = float(e.get("mining_progress", 0.0)) + delta * EXTRACTOR_RATE
var whole: int = int(floor(float(e.mining_progress)))
@ -2878,6 +2881,177 @@ func _arrive(t: Dictionary) -> void:
t.progress = 1.0
# --- quests (#129, #131) ---------------------------------------------------
# The chain lives in Quests.gd; what lives here is how far along it the
# player is, and the answer to "is this one done yet".
#
# Progress LATCHES, and it latches for free: the chain is walked one quest
# at a time, and the moment a goal is met the index moves on and never comes
# back. So collecting five ore and then spending it cannot un-complete the
# quest that asked for five ore - by the time it is spent, nothing is
# asking any more. That is why goals are allowed to be phrased against
# current holdings rather than against a running total nobody would keep in
# step.
#
# It sits in GameState with everything else that has to survive the
# Main.tscn <-> PlanetSurface.tscn swap - a quest completed on a surface
# must still be completed after take-off.
signal quest_started(id: String)
signal quest_completed(id: String)
# Whether this playthrough has a quest chain at all. Armed by
# reset_new_game(), which is the only door into a real game (the main menu's
# Play, and start_dev_game on top of it) - exactly the gate intro_active
# already uses. Without it, every scene ever instantiated would open on the
# first quest's briefing, including the ones in the test suite that only
# want a world to look at.
var quests_armed: bool = false
var quest_index: int = 0
# Whether the current quest has been ANNOUNCED. Kept apart from the index so
# a quest that is already satisfied the moment it starts still gets a frame
# on screen with its own name on it, rather than being skipped silently.
var quest_announced: bool = false
# Lines the chain wants said, waiting for something that can say them.
#
# Queued here rather than emitted straight at a banner because quests
# advance in this autoload, which runs on the planet surface too - where
# there is no narration banner at all. A line emitted there would simply be
# lost. QuestDirector drains this whenever it is alive, so a quest completed
# underground is read out on the way back up.
var quest_messages: Array = []
# Which planets have been LANDED ON, and which kinds of world they were.
# Distinct from explored_chunks, which is only about having flown past.
var visited_planets: Dictionary = {}
var visited_planet_kinds: Dictionary = {}
func reset_quests(armed: bool = false) -> void:
quests_armed = armed
quest_index = 0
quest_announced = false
quest_messages.clear()
visited_planets.clear()
visited_planet_kinds.clear()
# Called when the fleet actually sets down on a world.
func note_planet_visited(id: String, definition_id: String) -> void:
if id != "":
visited_planets[id] = true
if definition_id != "":
visited_planet_kinds[definition_id] = true
func quest_count() -> int:
return QUESTS.count()
func quest_chain_complete() -> bool:
return quest_index >= QUESTS.count()
# The quest the player is on, or {} once the chain is done.
func active_quest() -> Dictionary:
return QUESTS.at(quest_index)
# How far along one quest is, as (have, need). One line per goal kind, and
# every one of them is answered from state this autoload already holds - a
# goal that needed a node to ask would be a goal that stops working on a
# planet surface.
func quest_progress(quest: Dictionary) -> Vector2i:
if quest.is_empty():
return Vector2i.ZERO
var goal: Dictionary = quest.get("goal", {})
match String(goal.get("kind", "")):
QUESTS.GOAL_RESOURCE:
var want: int = int(goal.get("amount", 1))
return Vector2i(mini(available_resource(String(goal.get("resource",
RESOURCE_ORE))), want), want)
QUESTS.GOAL_BUILDING:
return Vector2i(1 if has_building_of_type(String(goal.get("building", ""))) else 0, 1)
QUESTS.GOAL_FLEET_VESSEL:
var need: int = int(goal.get("count", 1))
return Vector2i(mini(vessel_count_in_fleet(String(goal.get("vessel", ""))),
need), need)
QUESTS.GOAL_VESSEL_UNLOCKED:
return Vector2i(1 if vessel_is_unlocked(String(goal.get("vessel", ""))) else 0, 1)
QUESTS.GOAL_EXPLORE:
var sectors: int = int(goal.get("sectors", 1))
return Vector2i(mini(explored_chunks.size(), sectors), sectors)
QUESTS.GOAL_PLANET_VISITS:
var visits: int = int(goal.get("count", 1))
return Vector2i(mini(visited_planets.size(), visits), visits)
QUESTS.GOAL_PLANET_KINDS:
var kinds: int = int(goal.get("count", 1))
return Vector2i(mini(visited_planet_kinds.size(), kinds), kinds)
QUESTS.GOAL_CONQUERED:
var wanted: int = int(goal.get("count", 1))
var held: int = 0
for key in planet_capture:
if bool(planet_capture[key].get("conquered", false)):
held += 1
return Vector2i(mini(held, wanted), wanted)
# An unknown goal kind must not be quietly "already done" - that would
# run the whole chain off in one frame.
return Vector2i(0, 1)
func quest_goal_met(quest: Dictionary) -> bool:
if quest.is_empty():
return false
var progress: Vector2i = quest_progress(quest)
return progress.x >= progress.y
func say_quest_line(text: String) -> void:
if text.strip_edges() == "":
return
quest_messages.append({"line": text, "speaker": QUESTS.SPEAKER})
# Hands over every line waiting to be said, and empties the queue. Drained
# rather than read so two directors could never read the same line twice.
func take_quest_messages() -> Array:
var taken: Array = quest_messages.duplicate()
quest_messages.clear()
return taken
# Ends the current quest whether or not its goal was met. The chain's only
# way forward, used by _advance_quests below and by the tests.
func complete_active_quest() -> bool:
var quest: Dictionary = active_quest()
if quest.is_empty():
return false
say_quest_line(String(quest.get("done", "")))
quest_index += 1
quest_announced = false
quest_completed.emit(String(quest.id))
return true
func _advance_quests() -> void:
# The prologue is already talking, and the fleet in it is not the
# player's. The chain starts when the prologue hands over.
if not quests_armed or intro_active or quest_chain_complete():
return
var quest: Dictionary = active_quest()
if not quest_announced:
quest_announced = true
say_quest_line(String(quest.get("brief", "")))
quest_started.emit(String(quest.id))
# Deliberately no completion check this frame: a quest whose goal
# happens to be met already still gets read out before it closes.
return
if quest_goal_met(quest):
complete_active_quest()
# --- paying for things ------------------------------------------------------
#
# EVERY payment draws on the bank AND on what the ships are carrying. The

190
core/Quests.gd Normal file
View file

@ -0,0 +1,190 @@
extends RefCounted
# Forgejo #129 / #133: the quest chain.
#
# One place, in order, and nothing but data. GameState answers each goal and
# QuestDirector reads each line out; neither of them knows what the quests
# ARE, so adding one here is the whole job of adding one.
#
# Two rules the chain obeys, both learned from the game rather than chosen:
#
# 1. Nothing here may ask for something the player cannot yet reach. The
# sharp edge is RESEARCH POINTS - they come only from conquering a
# planet (GameState.mark_point_captured), so every node with a
# research_points cost sits after `conquest` below. Ore-only nodes -
# Shipyards, Logistics - may come before it.
# 2. A quest names ONE goal, and the brief says what it will take. Asking
# for a gas burner is asking for the Power Systems research too; that
# belongs in the sentence, not in a second entry, or the chain turns
# into a list of errands.
#
# The whole story turns on `mothership`: the fleet builds a transmitter,
# calls the World Ship, and hears nothing - not because the array is weak
# but because the breach put them further out than anyone has been. Every
# quest after it is a search.
# There is nobody left to talk to, so the quests are the ship talking to
# itself - the same voice the prologue ends on (IntroDirector.SHIP_LOG).
const SPEAKER: String = "KESTREL - LOG"
# Goal kinds. Each is one line in GameState.quest_progress().
const GOAL_RESOURCE: String = "resource"
const GOAL_BUILDING: String = "building"
const GOAL_FLEET_VESSEL: String = "fleet_vessel"
const GOAL_VESSEL_UNLOCKED: String = "vessel_unlocked"
const GOAL_EXPLORE: String = "explore"
const GOAL_PLANET_VISITS: String = "planet_visits"
const GOAL_PLANET_KINDS: String = "planet_kinds"
const GOAL_CONQUERED: String = "conquered"
const CHAIN: Array = [
{
"id": "first_ore",
"title": "SALVAGE",
"objective": "Break asteroids for 5 ore",
"goal": {"kind": GOAL_RESOURCE, "resource": "ore", "amount": 5},
"brief": "Hull intact. Reactor holding. Everything else we had is on the other side of that hole. There is ore in the rocks out here - break some, and we can start again.",
"done": "Five ore in the hold. It is not much. It is a beginning.",
},
{
"id": "mothership",
"title": "A PLACE TO STAND",
"objective": "Build the mothership",
"goal": {"kind": GOAL_BUILDING, "building": "mothership"},
"brief": "A hull is not a base. Build the mothership - it is the only thing in the plans with a transmitter big enough to call the World Ship.",
# The hinge of the whole chain (#129): the answer to "we built the
# transmitter" is that the transmitter was never the problem.
"done": "Mothership online. Calling the World Ship. Calling. Nothing comes back - and the array is not at fault. Wherever the breach put us, it is further out than that signal will ever carry. We find their trail ourselves, or we do not find them.",
},
{
"id": "chart",
"title": "DEAD RECKONING",
"objective": "Chart 30 sectors",
"goal": {"kind": GOAL_EXPLORE, "sectors": 30},
"brief": "So we search. Fly, and let the map fill in behind us - whatever is left of their course is somewhere in it.",
"done": "Thirty sectors charted. No sign of the World Ship, but the sky behind us is no longer blank.",
},
{
"id": "crafter",
"title": "A YARD OF OUR OWN",
"objective": "Build a ship crafter",
"goal": {"kind": GOAL_BUILDING, "building": "ship_crafter"},
"brief": "One hull will not chart a sky. Spend ore on the Shipyards doctrine, then put a ship crafter down: ore goes in, vessels come out.",
"done": "The yard is live. We can build our own now.",
},
{
"id": "second_hull",
"title": "A SECOND HULL",
"objective": "Fly two vessels at once",
"goal": {"kind": GOAL_FLEET_VESSEL, "vessel": "interceptor", "count": 2},
"brief": "Order an interceptor at the yard and crew it. Two guns is not a fleet, but it is twice what we flew out of the breach with.",
"done": "Two hulls in formation. It has been a while since this ship flew with company.",
},
{
"id": "planetfall",
"title": "PLANETFALL",
"objective": "Land on a planet",
"goal": {"kind": GOAL_PLANET_VISITS, "count": 1},
"brief": "There are worlds out here. Bring the fleet in close to one and take it down - there is more on a surface than there is in all this dark.",
"done": "Down on solid ground. Whatever else this place is, it is somewhere.",
},
{
"id": "conquest",
"title": "GROUND HELD",
"objective": "Take every capture point on one planet",
"goal": {"kind": GOAL_CONQUERED, "count": 1},
"brief": "Something got to this surface before us and it is still holding it. Take every point on the planet - what we pull out of their positions is worth more than the ore is.",
# Says out loud where research points come from, because nothing
# else in the game does.
"done": "Planet secured. Their equipment reads out as research data - the first we have had. Every doctrine worth having is going to cost some.",
},
{
"id": "extractor",
"title": "STANDING MINE",
"objective": "Build an extractor on a planet",
"goal": {"kind": GOAL_BUILDING, "building": "extractor"},
"brief": "Research Logistics and put an extractor down on a surface. It keeps digging whether we are standing over it or not.",
"done": "The extractor is cutting. Ore will be there when we come back for it.",
},
{
"id": "gas",
"title": "THE HEAVY AIR",
"objective": "Bring back 25 gas",
"goal": {"kind": GOAL_RESOURCE, "resource": "gas", "amount": 25},
"brief": "The banded worlds are full of gas, and gas is the only thing out here that burns. Take the fleet into one and fill the tanks.",
"done": "Twenty-five units of gas aboard. Now we need something that can burn it.",
},
{
"id": "hub",
"title": "FREIGHT",
"objective": "Build a transport hub",
"goal": {"kind": GOAL_BUILDING, "building": "transport_hub"},
"brief": "Carrying every load by hand does not scale. Research Freight Handling and build a hub - its transporters run the routes without us.",
"done": "The hub is running its own traffic. That is our hands back.",
},
{
"id": "burner",
"title": "POWER",
"objective": "Build a gas burner",
"goal": {"kind": GOAL_BUILDING, "building": "gas_burner"},
"brief": "Research Power Systems and build a gas burner. Gas in, energy out - and energy is what the better weapons run on.",
"done": "The burner is lit. There is power on this fleet for the first time since the breach.",
},
{
"id": "lab",
"title": "SHIP SCIENCE",
"objective": "Build a ship lab",
"goal": {"kind": GOAL_BUILDING, "building": "ship_lab"},
"brief": "Research Vessel Science and build a ship lab. Every hull we fly can be made better there, and there are hulls in the archive we have never built.",
"done": "The lab is open.",
},
{
"id": "shield",
"title": "A NEW HULL",
"objective": "Unlock the shield vessel",
"goal": {"kind": GOAL_VESSEL_UNLOCKED, "vessel": "shield"},
"brief": "The archive has a shield hull in it. Unlock it at the lab - the fleet has been taking every hit on the paint so far.",
"done": "Shield hull unlocked. There is more than one design in that archive.",
},
{
"id": "outpost",
"title": "FORWARD BASES",
"objective": "Build an outpost",
"goal": {"kind": GOAL_BUILDING, "building": "outpost"},
"brief": "We cannot be everywhere. Research Forward Bases and build an outpost - vessels stationed there hold ground we are not standing on.",
"done": "The outpost is crewed. That is one place we no longer have to fly back to.",
},
{
"id": "worlds",
"title": "THE SURVEY",
"objective": "Land on three different kinds of world",
"goal": {"kind": GOAL_PLANET_KINDS, "count": 3},
"brief": "Rock, gas, and whatever else is out here. Set down on three different kinds of world - if the World Ship passed this way, it passed something.",
"done": "Three kinds of world surveyed. Every one of them empty of anything that came through with us.",
},
{
"id": "trail",
"title": "THE TRAIL",
"objective": "Chart 150 sectors",
"goal": {"kind": GOAL_EXPLORE, "sectors": 150},
"brief": "Then we widen it. A hundred and fifty sectors, and every one of them looked at properly. They are out there.",
"done": "A hundred and fifty sectors charted, and no trail. The search does not stop because the list ran out.",
},
]
static func count() -> int:
return CHAIN.size()
static func at(index: int) -> Dictionary:
if index < 0 or index >= CHAIN.size():
return {}
return CHAIN[index]
static func by_id(id: String) -> Dictionary:
for quest in CHAIN:
if String(quest.id) == id:
return quest
return {}

1
core/Quests.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://cv5jwd8f74a2f