class_name NightPlan extends Resource ## One night (the plan's NightDefinition): its title, the hint shown at dusk, an optional length, ## and groups of enemies, each arriving at a time into the night. Where is not planned: every ## enemy arrives at its own random point along the farm's edge (WaveDirector). ## game/resources/nights/night_.tres, for n in 1..GameConfig.campaign_nights ## (FarmSim.night_plan_path), are the vacation's nights; game/resources/scenarios/ holds debug ## plans. ## time seconds after nightfall when the group's first enemy arrives ## count how many arrive ## every seconds between them ## type enemy type: "thief", "crow", "breaker", or "ufo" ## target what they're after: "crops", "animals", "supplies", or "any" (GameConfig.target_weights) ## The plans are the nights' designs; GameConfig.wave_count_scale and wave_spacing_scale scale ## every group when the night is played (count_scale x the enemies, spacing_scale x the time ## between them), so the whole vacation's pressure is tuned in one place. A plan can set its own ## scales instead (night 1 plays as designed, at 1 and 1). enemy_speed_scale and enemy_hp_scale ## make tonight's enemies faster and tougher than GameConfig.enemy_types says (WaveDirector hands ## them to EnemySystem at nightfall). @export var title: String = "" ## What the HUD tells the player at dusk about tonight. @export_multiline var dusk_hint: String = "" ## Seconds the night lasts; 0 uses GameConfig.night_length. @export var night_length: float = 0.0 ## This night's own scales; 0 uses GameConfig.wave_count_scale / wave_spacing_scale. @export var count_scale: float = 0.0 @export var spacing_scale: float = 0.0 ## Tonight's enemies move at speed x this (fleeing and carrying too, as shares of it), and arrive ## with HP x this, rounded down but never below the type's own (a 1 HP crow stays one hit). @export var enemy_speed_scale: float = 1.0 @export var enemy_hp_scale: float = 1.0 @export var groups: Array[Dictionary] = [] ## The scales this night is played at: its own, or the config's. func count_scale_in(config: GameConfig) -> float: return count_scale if count_scale > 0.0 else config.wave_count_scale func spacing_scale_in(config: GameConfig) -> float: return spacing_scale if spacing_scale > 0.0 else config.wave_spacing_scale ## A group's enemies and the seconds between them, scaled. static func scaled_count(g: Dictionary, count_scale: float = 1.0) -> int: return maxi(roundi(int(g.get("count", 1)) * count_scale), 1) static func scaled_every(g: Dictionary, spacing_scale: float = 1.0) -> float: return float(g.get("every", 2.0)) * spacing_scale func total(count_scale: float = 1.0) -> int: var n := 0 for g in groups: n += scaled_count(g, count_scale) return n ## What's wrong with the plan (empty when it's fine): unknown enemy types, a target the type ## doesn't take, arrivals outside the night (as scaled), or an enemy scale that isn't positive. func problems(length: float, count_scale: float = 1.0, spacing_scale: float = 1.0) -> PackedStringArray: var out := PackedStringArray() if groups.is_empty(): out.append("no groups") if enemy_speed_scale <= 0.0 or enemy_hp_scale <= 0.0: out.append("enemy scales must be positive") for k in groups.size(): var g: Dictionary = groups[k] var where := "group %d" % (k + 1) var type := String(g.get("type", "")) var t := EnemySystem.TYPE_NAMES.find(type) if t < 0: out.append("%s: unknown enemy type '%s'" % [where, type]) continue var target := String(g.get("target", "any")) var allowed := {"crow": ["crops", "any"], "thief": ["animals", "supplies", "any"], "breaker": ["any"], "ufo": ["any"]} if not (allowed[type] as Array).has(target): out.append("%s: a %s doesn't go for '%s'" % [where, type, target]) if int(g.get("count", 0)) < 1 or float(g.get("every", 0.0)) <= 0.0: out.append("%s: count and spacing must be positive" % where) var last := float(g.get("time", 0.0)) + (scaled_count(g, count_scale) - 1) * scaled_every(g, spacing_scale) if float(g.get("time", -1.0)) < 0.0 or last >= length: out.append("%s: arrivals (%.0f..%.0f s) outside the %.0f s night" % [where, float(g.get("time", 0.0)), last, length]) return out ## How many of each enemy type (EnemySystem type id -> count), scaled. func type_counts(count_scale: float = 1.0) -> Dictionary: var out := {} for g in groups: var t := maxi(EnemySystem.TYPE_NAMES.find(String(g.get("type", "thief"))), 0) out[t] = int(out.get(t, 0)) + scaled_count(g, count_scale) return out