Files
Battle-for-Tismo/data/technology.gd
T
adrien c49899a2fd Initial commit
Server-authoritative Godot 4.6 strategy game.

Includes the headless WebSocket game server, the browser client, and
Nix packaging (server and web-export derivations plus a NixOS module)
for deployment.
2026-09-15 14:48:34 +02:00

59 lines
2.0 KiB
GDScript

class_name Technology
extends Resource
## A technology a civilisation can unlock by spending accumulated research
## points. Concrete instances live under res://data/technologies and are edited
## in the inspector.
##
## Technologies form a tree through `prerequisites`: a technology can only be
## researched once every prerequisite is already known. A technology has no
## levels and applies its effects in full as soon as it is researched.
@export var name : String
@export_multiline var description : String
## Research points needed to unlock this technology.
@export var cost : float = 0.0
## Technologies that must be researched first. Compared by resource path, so
## resources loaded independently still match.
@export var prerequisites : Array[Technology] = []
## Bonuses this technology grants once researched. Effects are evaluated at
## level 1, the only level a technology has. See BuildingEffect for the stats.
@export var effects : Array[BuildingEffect] = []
## Total contribution to `stat` from every effect this technology carries.
func effect_value(stat: String) -> float:
var total := 0.0
for effect in effects:
if effect.stat == stat:
total += effect.value_at(1)
return total
## Position of this technology within a catalogue, matched by resource path
## first so independently loaded instances still resolve. Returns -1 when the
## technology is not in the catalogue.
func catalogue_index(catalogue: Array) -> int:
for i in catalogue.size():
var candidate: Variant = catalogue[i]
if candidate == self:
return i
if candidate is Technology and not resource_path.is_empty() \
and (candidate as Technology).resource_path == resource_path:
return i
return -1
## True when every prerequisite appears in `researched`, a set of catalogue
## indices. Always true when there are no prerequisites.
func prerequisites_met(catalogue: Array, researched: Dictionary) -> bool:
for prerequisite in prerequisites:
var index := prerequisite.catalogue_index(catalogue)
if index < 0 or not researched.has(index):
return false
return true