#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 # global class table is necessarily populated, the same hazard PlanetSetups.gd
# works around. # works around.
const WORLD_GEN = preload("res://world/WorldGen.gd") 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() # Autoload singleton - the one thing that survives change_scene_to_file()
@ -676,6 +677,7 @@ func reset_new_game() -> void:
planet_capture.clear() planet_capture.clear()
vessel_targets.clear() vessel_targets.clear()
reset_waves() reset_waves()
reset_quests(true)
reset_progression() reset_progression()
reset_formation() reset_formation()
@ -2545,6 +2547,7 @@ func _process(delta: float) -> void:
_advance_repairs(delta) _advance_repairs(delta)
_advance_resource_converters(delta) _advance_resource_converters(delta)
_advance_distorder_drain(delta) _advance_distorder_drain(delta)
_advance_quests()
for e in extractors: for e in extractors:
e.mining_progress = float(e.get("mining_progress", 0.0)) + delta * EXTRACTOR_RATE e.mining_progress = float(e.get("mining_progress", 0.0)) + delta * EXTRACTOR_RATE
var whole: int = int(floor(float(e.mining_progress))) var whole: int = int(floor(float(e.mining_progress)))
@ -2878,6 +2881,177 @@ func _arrive(t: Dictionary) -> void:
t.progress = 1.0 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 ------------------------------------------------------ # --- paying for things ------------------------------------------------------
# #
# EVERY payment draws on the bank AND on what the ships are carrying. The # 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

View file

@ -129,6 +129,11 @@ func _on_enter_pressed() -> void:
GameState.planet_name = current_planet.planet_name GameState.planet_name = current_planet.planet_name
GameState.planet_id = current_planet.planet_id GameState.planet_id = current_planet.planet_id
GameState.planet_definition_id = current_planet.definition_id GameState.planet_definition_id = current_planet.definition_id
# #133: quests ask about worlds LANDED ON, which is a different question
# from the ones flown past that explored_chunks answers. Recorded at the
# moment of committing to the descent - the same moment the three lines
# above are written - so the two can never disagree.
GameState.note_planet_visited(current_planet.planet_id, current_planet.definition_id)
var tween: Tween = create_tween() var tween: Tween = create_tween()
tween.tween_property(fade_rect, "color:a", 1.0, fade_duration) tween.tween_property(fade_rect, "color:a", 1.0, fade_duration)

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=16 format=3] [gd_scene load_steps=19 format=3]
[ext_resource type="Script" path="res://controllers/GameController.gd" id="1"] [ext_resource type="Script" path="res://controllers/GameController.gd" id="1"]
[ext_resource type="PackedScene" path="res://surface/SurfaceBackground.tscn" id="3"] [ext_resource type="PackedScene" path="res://surface/SurfaceBackground.tscn" id="3"]
@ -13,6 +13,9 @@
[ext_resource type="Script" path="res://controllers/LaserController.gd" id="16"] [ext_resource type="Script" path="res://controllers/LaserController.gd" id="16"]
[ext_resource type="Script" path="res://ui/SpeedFader.gd" id="17"] [ext_resource type="Script" path="res://ui/SpeedFader.gd" id="17"]
[ext_resource type="Script" path="res://surface/CaptureLabel.gd" id="15"] [ext_resource type="Script" path="res://surface/CaptureLabel.gd" id="15"]
[ext_resource type="Script" path="res://ui/NarrationBanner.gd" id="banner"]
[ext_resource type="Script" path="res://world/QuestDirector.gd" id="quest_dir"]
[ext_resource type="Script" path="res://ui/QuestTracker.gd" id="quest_hud"]
[node name="PlanetSurface" type="Node2D"] [node name="PlanetSurface" type="Node2D"]
script = ExtResource("1") script = ExtResource("1")
@ -45,6 +48,9 @@ zoom = Vector2(1, 1)
[node name="SurfaceController" type="Node2D" parent="."] [node name="SurfaceController" type="Node2D" parent="."]
script = ExtResource("5") script = ExtResource("5")
[node name="QuestDirector" type="Node" parent="."]
script = ExtResource("quest_dir")
[node name="UI" type="CanvasLayer" parent="."] [node name="UI" type="CanvasLayer" parent="."]
layer = 1 layer = 1
@ -111,6 +117,27 @@ horizontal_alignment = 1
text = "" text = ""
script = ExtResource("15") script = ExtResource("15")
[node name="NarrationBanner" type="Control" parent="UI"]
visible = false
mouse_filter = 2
anchor_right = 1.0
offset_left = 60.0
offset_right = -60.0
offset_top = 300.0
offset_bottom = 428.0
script = ExtResource("banner")
[node name="QuestTracker" type="Control" parent="UI"]
visible = false
mouse_filter = 2
anchor_left = 1.0
anchor_right = 1.0
offset_left = -440.0
offset_right = -24.0
offset_top = 350.0
offset_bottom = 482.0
script = ExtResource("quest_hud")
[node name="ExitButton" type="Control" parent="UI"] [node name="ExitButton" type="Control" parent="UI"]
anchor_top = 1.0 anchor_top = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0

View file

@ -34,8 +34,10 @@ func _initialize() -> void:
# #108: reset_new_game() arms the prologue, and the prologue opens with a # #108: reset_new_game() arms the prologue, and the prologue opens with a
# convoy rather than the game's own starting fleet. This test is about # convoy rather than the game's own starting fleet. This test is about
# what the GAME starts from, which is where the prologue hands over - # what the GAME starts from, which is where the prologue hands over -
# see test_intro_scene.gd for the prologue itself. # see test_intro_scene.gd for the prologue itself. The quest chain goes
# with it: its briefings are dialogs, and a dialog stops the tree (#128).
game_state.intro_active = false game_state.intro_active = false
game_state.reset_quests()
func _process(delta: float) -> bool: func _process(delta: float) -> bool:
@ -102,8 +104,10 @@ func _process(delta: float) -> bool:
# --- B. what actually flies ---------------------------------- # --- B. what actually flies ----------------------------------
game_state.reset_new_game() game_state.reset_new_game()
# ... and again here: this is the reset the scene below is built # ... and again here: this is the reset the scene below is built
# from, so the prologue has to be off for THIS one too. # from, so the prologue has to be off for THIS one too - and the
# quest chain with it.
game_state.intro_active = false game_state.intro_active = false
game_state.reset_quests()
scene = load("res://world/Main.tscn").instantiate() scene = load("res://world/Main.tscn").instantiate()
root.add_child(scene) root.add_child(scene)
fleet = scene.get_node("Fleet") fleet = scene.get_node("Fleet")

334
tests/test_quest_chain.gd Normal file
View file

@ -0,0 +1,334 @@
extends SceneTree
# Headless test: run with
# godot --headless -s res://tests/test_quest_chain.gd
# Forgejo #129 (#131, #132, #133): the quest chain.
#
# The chain is a campaign, so most of what can go wrong with it is not a
# crash - it is a quest that cannot be finished, one that finishes itself,
# or one that asks for something the player has no way to reach yet. Those
# are what is checked here, against the real catalogue rather than a fixture:
# a chain that passes with test data and strands the player is exactly the
# failure this is for.
#
# Covers:
# A. the model: a fresh game is on the first quest, and every entry in the
# catalogue is well formed and reachable
# B. no quest counts as done before it is done, and every goal kind is
# answerable
# C. progress LATCHES - collecting and then spending does not un-complete
# D. a quest is announced before it can complete, so an already-satisfied
# goal still gets read out
# E. the whole chain can be walked, and the ore quest really is finished by
# collecting ore
# F. #133 - the mothership quest's answer is that the World Ship is out of
# reach, and exploration is what follows
# G. research points only come from conquest, so no quest may ask for a
# doctrine that costs them before the conquest quest
# H. quests do not run during the prologue
# I. lines survive having nobody to say them: a quest finished with no
# banner alive is read out by the next one that is
# J. a planet surface carries the chain too - a quest finished down there
# is announced down there, not on the way back up
# K. landing is recorded, both the planet and the kind of world it was
const QUESTS = preload("res://core/Quests.gd")
var game_state: Node
var stage: int = 0
var elapsed: float = 0.0
var scene: Node
var tracker: Control
var narration: Control
func _initialize() -> void:
# GameState is an autoload: a bare GameState.<instance member> does not
# compile in a SceneTree script, so the node is fetched by name instead.
game_state = root.get_node("GameState")
game_state.reset_new_game()
game_state.intro_active = false
func _fail(message: String) -> bool:
print("TEST_QUEST_CHAIN: FAIL (%s)" % message)
quit(1)
return true
# Which skill-tree nodes cost research points, which only conquest supplies.
func _costs_research_points(id: String) -> bool:
return int(game_state.skill_node(id).get("research_points", 0)) > 0
func _catalogue_cases() -> bool:
# --- A. the catalogue is well formed ---------------------------------
if QUESTS.count() < 8:
return _fail("a chain of %d is not a campaign" % QUESTS.count())
var seen: Dictionary = {}
for i in range(QUESTS.count()):
var quest: Dictionary = QUESTS.at(i)
for field in ["id", "title", "objective", "goal", "brief", "done"]:
if not quest.has(field):
return _fail("quest %d has no %s" % [i, field])
if field != "goal" and String(quest[field]).strip_edges() == "":
return _fail("quest %s has an empty %s" % [quest.id, field])
if seen.has(quest.id):
return _fail("two quests share the id %s" % quest.id)
seen[quest.id] = true
# Every goal must be one this build can actually answer. An unknown
# kind reads as never-done and would strand the player there.
var progress: Vector2i = game_state.quest_progress(quest)
if progress.y <= 0:
return _fail("quest %s has a goal of zero, so it is already done" % quest.id)
# --- B. and nothing is complete on a fresh game ------------------
if game_state.quest_goal_met(quest):
return _fail("quest %s counts as done on a brand new game" % quest.id)
# The things a goal names must exist.
var goal: Dictionary = quest.goal
match String(goal.kind):
QUESTS.GOAL_BUILDING:
if game_state.building_definition(String(goal.building)) == null:
return _fail("quest %s asks for a building that does not exist: %s" \
% [quest.id, goal.building])
QUESTS.GOAL_FLEET_VESSEL, QUESTS.GOAL_VESSEL_UNLOCKED:
if game_state.vessel_definition(String(goal.vessel)) == null:
return _fail("quest %s asks for a vessel that does not exist: %s" \
% [quest.id, goal.vessel])
QUESTS.GOAL_RESOURCE:
if not (String(goal.resource) in game_state.resource_types()):
return _fail("quest %s asks for a resource that does not exist: %s" \
% [quest.id, goal.resource])
print("catalogue: %d quests, all well formed and none already done" % QUESTS.count())
# --- F. the hinge ----------------------------------------------------
var mothership: Dictionary = QUESTS.by_id("mothership")
if mothership.is_empty():
return _fail("there is no mothership quest - #129 turns on it")
var answer: String = String(mothership.done).to_lower()
if not ("world ship" in answer):
return _fail("the mothership quest's answer never mentions the World Ship")
if not ("further" in answer or "far" in answer or "carry" in answer):
return _fail("the mothership quest does not say the World Ship is out of reach")
# And what follows it is a search.
var after: Dictionary = QUESTS.at(QUESTS.CHAIN.find(mothership) + 1)
if String(after.goal.kind) != QUESTS.GOAL_EXPLORE:
return _fail("the quest after the mothership is %s, not exploration" % after.id)
print("the mothership answers with distance, and exploration follows it")
# --- G. nothing asks for points before conquest ----------------------
var conquest_at: int = -1
for i in range(QUESTS.count()):
if String(QUESTS.at(i).goal.kind) == QUESTS.GOAL_CONQUERED:
conquest_at = i
break
if conquest_at < 0:
return _fail("no quest ever conquers a planet, so research points are unreachable")
for i in range(conquest_at):
var quest: Dictionary = QUESTS.at(i)
if String(quest.goal.kind) != QUESTS.GOAL_BUILDING:
continue
var research: String = game_state.research_for_building(String(quest.goal.building))
if research != "" and _costs_research_points(research):
return _fail("quest %s needs %s, which costs research points, before any planet is taken" \
% [quest.id, research])
print("no quest needs research points before the conquest quest at %d" % conquest_at)
# --- H. not during the prologue --------------------------------------
game_state.reset_new_game()
if not game_state.intro_active:
return _fail("a new game is not in the prologue")
game_state._advance_quests()
if game_state.quest_announced or not game_state.quest_messages.is_empty():
return _fail("a quest spoke up during the prologue")
game_state.intro_active = false
print("the chain holds its tongue while the prologue runs")
# --- D. announced before it can complete -----------------------------
game_state.bank_inventory.deposit(GameState.RESOURCE_ORE, 500)
game_state._advance_quests()
if game_state.quest_index != 0:
return _fail("the first quest completed before it was ever announced")
if game_state.quest_messages.is_empty():
return _fail("the first quest was not announced")
var brief: String = String(game_state.take_quest_messages()[0].line)
if brief != String(QUESTS.at(0).brief):
return _fail("the first quest announced something other than its own brief")
game_state._advance_quests()
if game_state.quest_index != 1:
return _fail("a satisfied quest did not complete on the frame after it was announced")
print("a quest is read out first, then completed: \"%s\"" % brief.substr(0, 48))
# --- C. and it stays complete ----------------------------------------
game_state.bank_inventory.withdraw(GameState.RESOURCE_ORE, 500)
if game_state.available_resource(GameState.RESOURCE_ORE) != 0:
return _fail("the test failed to spend the ore it just banked")
game_state._advance_quests()
if game_state.quest_index < 1:
return _fail("spending the ore put the chain back on the ore quest")
print("spending the ore did not un-complete the quest that asked for it")
# --- E. the whole chain walks ----------------------------------------
var guard: int = 0
while not game_state.quest_chain_complete() and guard < QUESTS.count() * 4:
guard += 1
game_state.complete_active_quest()
if not game_state.quest_chain_complete():
return _fail("the chain would not walk to its end")
if not game_state.active_quest().is_empty():
return _fail("there is still an active quest after the chain ended")
game_state._advance_quests()
print("the chain walks to the end and stops there")
return false
func _process(delta: float) -> bool:
elapsed += delta
match stage:
0:
if _catalogue_cases():
return true
# --- E (second half). the ore quest, really collected --------
game_state.reset_new_game()
game_state.intro_active = false
scene = load("res://world/Main.tscn").instantiate()
root.add_child(scene)
current_scene = scene
tracker = scene.get_node("UI/QuestTracker")
narration = scene.get_node("UI/NarrationBanner")
elapsed = 0.0
stage = 1
return false
1:
if elapsed < 0.3:
return false
# The opening brief is up, which has stopped the game (#128).
if not narration.is_speaking():
return _fail("the first quest never reached the banner")
if not paused:
return _fail("a quest line did not stop the game")
print("the first quest arrives as a dialog and stops the game")
while narration.dismiss():
pass
if paused:
return _fail("acknowledging every line left the game stopped")
# --- the HUD ------------------------------------------------
elapsed = 0.0
stage = 2
return false
2:
if elapsed < 0.3:
return false
if not tracker.visible:
return _fail("the objective tracker never came up")
var quest: Dictionary = game_state.active_quest()
if tracker.title_label.text != String(quest.title):
return _fail("the tracker shows \"%s\", the quest is \"%s\"" \
% [tracker.title_label.text, quest.title])
if tracker.objective_label.text != String(quest.objective):
return _fail("the tracker does not show the objective")
if tracker.progress != Vector2i(0, 5):
return _fail("the tracker reads %s, expected 0 of 5" % tracker.progress)
print("tracker: \"%s\" - %s (%d/%d)" % [tracker.title_label.text,
tracker.objective_label.text, tracker.progress.x, tracker.progress.y])
# Collect what the quest asked for, the way the game does.
game_state.collect_cargo(5)
elapsed = 0.0
stage = 3
return false
3:
if elapsed < 0.3:
return false
if String(game_state.active_quest().get("id", "")) != "mothership":
return _fail("collecting 5 ore did not finish the ore quest (on %s)" \
% game_state.active_quest().get("id", "<none>"))
if not narration.is_speaking():
return _fail("finishing a quest said nothing")
print("5 ore collected: the chain moved on to \"%s\"" \
% game_state.active_quest().title)
while narration.dismiss():
pass
# --- I. a line said with no banner alive --------------------
scene.free()
scene = null
game_state.complete_active_quest()
if game_state.quest_messages.is_empty():
return _fail("a quest finished with no banner and dropped its line")
scene = load("res://world/Main.tscn").instantiate()
root.add_child(scene)
current_scene = scene
narration = scene.get_node("UI/NarrationBanner")
elapsed = 0.0
stage = 4
return false
4:
if elapsed < 0.3:
return false
if not narration.is_speaking():
return _fail("the line queued with no banner alive was never said")
print("a quest finished off-scene is read out by the next banner that exists")
while narration.dismiss():
pass
# --- J. and the same on a planet surface ---------------------
scene.free()
game_state.planet_name = "Quest Test"
game_state.planet_id = "quest:test"
game_state.planet_definition_id = "rocky"
scene = load("res://surface/PlanetSurface.tscn").instantiate()
root.add_child(scene)
current_scene = scene
narration = scene.get_node_or_null("UI/NarrationBanner")
tracker = scene.get_node_or_null("UI/QuestTracker")
if narration == null or tracker == null:
return _fail("a planet surface has no banner and no objective tracker")
game_state.complete_active_quest()
elapsed = 0.0
stage = 5
return false
5:
if elapsed < 0.3:
return false
if not narration.is_speaking():
return _fail("a quest finished on a surface said nothing down there")
print("a quest finished on a surface is announced on the surface")
# The tracker is an ordinary HUD node, so it is frozen along with
# everything else behind a dialog (#128) and comes up as the line
# closes. Acknowledged first, then looked at.
while narration.dismiss():
pass
elapsed = 0.0
stage = 6
return false
6:
if elapsed < 0.3:
return false
if not tracker.visible:
return _fail("the objective tracker is missing on a planet surface")
print("the surface carries the tracker too: \"%s\"" % tracker.title_label.text)
# --- K. landing is recorded ----------------------------------
game_state.reset_quests()
game_state.note_planet_visited("quest:one", "rocky")
game_state.note_planet_visited("quest:one", "rocky")
game_state.note_planet_visited("quest:two", "gas_giant")
if game_state.visited_planets.size() != 2:
return _fail("landing twice on one planet counted as two worlds")
if game_state.visited_planet_kinds.size() != 2:
return _fail("two kinds of world were not recorded as two kinds")
var kinds: Dictionary = {"kind": QUESTS.GOAL_PLANET_KINDS, "count": 3}
if game_state.quest_goal_met({"goal": kinds}):
return _fail("a three-world survey passed on two worlds")
game_state.note_planet_visited("quest:three", "research_lab")
if not game_state.quest_goal_met({"goal": kinds}):
return _fail("a three-world survey did not pass on three kinds of world")
print("landings recorded: %d planets across %d kinds of world" \
% [game_state.visited_planets.size(), game_state.visited_planet_kinds.size()])
print("TEST_QUEST_CHAIN: PASS")
quit(0)
return true
return false

View file

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

132
ui/QuestTracker.gd Normal file
View file

@ -0,0 +1,132 @@
extends Control
# Forgejo #132: the standing objective, on the HUD.
#
# The banner (#128/#127) says a quest ONCE, stops the game while it is read,
# and then is gone. That is right for the sentence and wrong for the task -
# a player who put the game down mid-flight has nowhere to look up what they
# were doing. This is that place: small, always the current quest, and never
# in the way.
#
# Same idiom as the wave alert: a neon panel drawn out of geometry, no art,
# no textures. It sits under the alert on the right so the two stack rather
# than argue, and it stands down whenever a full-screen panel is open - the
# HUD's own rule for anything sitting behind a menu (see IconButton).
const GLOW: Color = Color(0.42, 0.86, 0.95)
const TEXT: Color = Color(0.80, 0.94, 1.0)
const DONE: Color = Color(0.55, 1.0, 0.68)
const CUT: float = 14.0
const PAD: float = 16.0
const TITLE_SIZE: int = 20
const OBJECTIVE_SIZE: int = 24
const BAR_HEIGHT: float = 8.0
var title_label: Label
var objective_label: Label
var count_label: Label
var progress: Vector2i = Vector2i.ZERO
var shown_id: String = ""
func _ready() -> void:
mouse_filter = Control.MOUSE_FILTER_IGNORE
visible = false
title_label = _make_label(TITLE_SIZE, GLOW)
objective_label = _make_label(OBJECTIVE_SIZE, TEXT)
objective_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
count_label = _make_label(TITLE_SIZE, TEXT)
count_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
resized.connect(_layout)
_layout()
func _make_label(font_size: int, colour: Color) -> Label:
var label: Label = Label.new()
label.mouse_filter = Control.MOUSE_FILTER_IGNORE
label.add_theme_font_size_override("font_size", font_size)
label.add_theme_color_override("font_color", colour)
label.add_theme_color_override("font_outline_color", Color(0.01, 0.03, 0.07, 0.95))
label.add_theme_constant_override("outline_size", 3)
label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
add_child(label)
return label
func _layout() -> void:
if title_label == null:
return
var inner: float = maxf(size.x - PAD * 2.0, 0.0)
title_label.position = Vector2(PAD, PAD * 0.4)
title_label.size = Vector2(inner, float(TITLE_SIZE) * 1.3)
count_label.position = title_label.position
count_label.size = title_label.size
objective_label.position = Vector2(PAD, PAD * 0.4 + float(TITLE_SIZE) * 1.4)
objective_label.size = Vector2(inner,
maxf(size.y - objective_label.position.y - PAD - BAR_HEIGHT, 0.0))
# Open panels take the whole screen and this would sit on top of one. Same
# question IconButton._blocked_by_modal asks, for the same reason.
func _behind_a_panel() -> bool:
for menu in get_tree().get_nodes_in_group("modal_menus"):
if menu.is_visible_in_tree():
return true
return false
func _process(_delta: float) -> void:
var quest: Dictionary = GameState.active_quest()
var wanted: bool = not quest.is_empty() and not GameState.intro_active \
and not _behind_a_panel()
if not wanted:
if visible:
visible = false
return
var id: String = String(quest.id)
var now: Vector2i = GameState.quest_progress(quest)
if id == shown_id and now == progress and visible:
return
shown_id = id
progress = now
title_label.text = String(quest.get("title", ""))
objective_label.text = String(quest.get("objective", ""))
# A one-of-one goal is a yes/no, and "0 / 1" reads as a broken counter
# rather than as a task not started.
count_label.text = "%d / %d" % [progress.x, progress.y] if progress.y > 1 else ""
visible = true
queue_redraw()
func _frame() -> PackedVector2Array:
return PackedVector2Array([
Vector2(CUT, 0.0), Vector2(size.x, 0.0),
Vector2(size.x, size.y - CUT), Vector2(size.x - CUT, size.y),
Vector2(0.0, size.y), Vector2(0.0, CUT),
])
func _draw() -> void:
if not visible:
return
var frame: PackedVector2Array = _frame()
draw_colored_polygon(frame, Color(0.02, 0.07, 0.11, 0.66))
NeonDraw.draw_glowing_polygon(self, frame, Color(GLOW, 0.85), 0.75)
# A tick down the left edge, so the panel reads as clipped to the side of
# the screen rather than floating in the middle of it.
NeonDraw.draw_glowing_line(self, Vector2(PAD * 0.35, CUT + 4.0),
Vector2(PAD * 0.35, size.y - CUT - 4.0), Color(GLOW, 0.5), 0.6, 0.35)
# The bar along the bottom edge. Drawn for every goal, including the
# yes/no ones - it is the one thing on the panel that says "this is a
# task with a state" without needing to be read.
var track: Rect2 = Rect2(Vector2(PAD, size.y - PAD * 0.6 - BAR_HEIGHT),
Vector2(maxf(size.x - PAD * 2.0, 0.0), BAR_HEIGHT))
draw_rect(track, Color(GLOW, 0.16))
var filled: float = 0.0 if progress.y <= 0 \
else clampf(float(progress.x) / float(progress.y), 0.0, 1.0)
if filled <= 0.0:
return
var lit: Rect2 = Rect2(track.position, Vector2(track.size.x * filled, track.size.y))
draw_rect(lit, Color(DONE if filled >= 1.0 else GLOW, 0.85))

1
ui/QuestTracker.gd.uid Normal file
View file

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

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=31 format=3] [gd_scene load_steps=33 format=3]
[ext_resource type="Script" path="res://world/Starfield.gd" id="1"] [ext_resource type="Script" path="res://world/Starfield.gd" id="1"]
[ext_resource type="Script" path="res://vessels/Fleet.gd" id="2"] [ext_resource type="Script" path="res://vessels/Fleet.gd" id="2"]
@ -39,6 +39,8 @@
[ext_resource type="Script" path="res://controllers/GasBombController.gd" id="29"] [ext_resource type="Script" path="res://controllers/GasBombController.gd" id="29"]
[ext_resource type="Script" path="res://controllers/LaserController.gd" id="30"] [ext_resource type="Script" path="res://controllers/LaserController.gd" id="30"]
[ext_resource type="Script" path="res://ui/SpeedFader.gd" id="31"] [ext_resource type="Script" path="res://ui/SpeedFader.gd" id="31"]
[ext_resource type="Script" path="res://world/QuestDirector.gd" id="quest_dir"]
[ext_resource type="Script" path="res://ui/QuestTracker.gd" id="quest_hud"]
[sub_resource type="ShaderMaterial" id="1"] [sub_resource type="ShaderMaterial" id="1"]
shader = ExtResource("5") shader = ExtResource("5")
@ -101,6 +103,9 @@ script = ExtResource("14")
[node name="IntroDirector" type="Node2D" parent="."] [node name="IntroDirector" type="Node2D" parent="."]
script = ExtResource("37") script = ExtResource("37")
[node name="QuestDirector" type="Node" parent="."]
script = ExtResource("quest_dir")
[node name="GarrisonField" type="Node2D" parent="."] [node name="GarrisonField" type="Node2D" parent="."]
script = ExtResource("34") script = ExtResource("34")
@ -273,6 +278,17 @@ offset_top = 188.0
offset_bottom = 252.0 offset_bottom = 252.0
script = ExtResource("32") script = ExtResource("32")
[node name="QuestTracker" type="Control" parent="UI"]
visible = false
mouse_filter = 2
anchor_left = 1.0
anchor_right = 1.0
offset_left = -440.0
offset_right = -24.0
offset_top = 268.0
offset_bottom = 400.0
script = ExtResource("quest_hud")
[node name="Joystick" type="Control" parent="UI"] [node name="Joystick" type="Control" parent="UI"]
mouse_filter = 2 mouse_filter = 2
script = ExtResource("13") script = ExtResource("13")

27
world/QuestDirector.gd Normal file
View file

@ -0,0 +1,27 @@
extends Node
# Forgejo #132: the voice of the quest chain.
#
# GameState walks the chain and QUEUES what it wants said (see
# GameState.quest_messages); this node is the thing that says it. The split
# is not ceremony: quests advance in the autoload, which keeps running on a
# planet surface where there is no narration banner at all, so a line
# emitted straight at a banner would simply be lost down there. Queued and
# drained, a quest finished on a surface is read out on the way back up.
#
# Draining every waiting line at once is safe: the banner queues lines
# itself and shows them one at a time, and each one stops the game until it
# is acknowledged (#128).
@onready var narration: Control = get_node_or_null("../UI/NarrationBanner")
func _process(_delta: float) -> void:
if narration == null:
return
# The prologue owns the banner while it runs. A quest line arriving in
# the middle of the convoy being torn apart would be read as part of it.
if GameState.intro_active:
return
for message in GameState.take_quest_messages():
narration.say(String(message.line), String(message.speaker))

View file

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