feat(management): Improve production filter logic with new criteria and performance optimizations

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Claude Code 2026-04-07 21:13:55 -07:00
parent 2ec26a39b4
commit ad145cd965

View file

@ -61,19 +61,22 @@ static func is_building_buildable(
# Internal helpers
# ---------------------------------------------------------------------------
static func _str_field(d: Dictionary, key: String) -> String:
if d.has(key) and d[key] is String:
return d[key]
return ""
static func _unit_allowed(unit: Dictionary, player: RefCounted) -> bool:
# Tech gate — check value is a non-empty String before comparing
var tech_req: String = unit["tech_required"] as String if unit.has("tech_required") and unit["tech_required"] is String else ""
var tech_req: String = _str_field(unit, "tech_required")
if not tech_req.is_empty() and not player.has_tech(tech_req):
return false
# Race gate — unit may list a required race
var race_req: String = unit["race_required"] as String if unit.has("race_required") and unit["race_required"] is String else ""
var race_req: String = _str_field(unit, "race_required")
if not race_req.is_empty() and race_req != player.race_id:
return false
# School gate — if unit belongs to a school, player must have that school
var school_val: String = unit["school"] as String if unit.has("school") and unit["school"] is String else ""
var school_val: String = _str_field(unit, "school")
if not school_val.is_empty() and school_val not in player.schools:
return false
@ -83,23 +86,18 @@ static func _unit_allowed(unit: Dictionary, player: RefCounted) -> bool:
static func _building_allowed(
bld: Dictionary, city: RefCounted, player: RefCounted
) -> bool:
# Already built
var bld_id: String = bld.get("id", "")
if bld_id in city.buildings:
if _str_field(bld, "id") in city.buildings:
return false
# Tech gate — check value is a non-empty String before comparing
var tech_req: String = bld["tech_required"] as String if bld.has("tech_required") and bld["tech_required"] is String else ""
var tech_req: String = _str_field(bld, "tech_required")
if not tech_req.is_empty() and not player.has_tech(tech_req):
return false
# School gate
var school_val: String = bld["school"] as String if bld.has("school") and bld["school"] is String else ""
var school_val: String = _str_field(bld, "school")
if not school_val.is_empty() and school_val not in player.schools:
return false
# Building prereq (e.g. Cathedral requires Sanctuary)
var prereq_bld: String = bld["requires_building"] as String if bld.has("requires_building") and bld["requires_building"] is String else ""
var prereq_bld: String = _str_field(bld, "requires_building")
if not prereq_bld.is_empty() and prereq_bld not in city.buildings:
return false
@ -133,16 +131,13 @@ static func is_item_buildable(
static func _item_allowed(
item: Dictionary, city: RefCounted, player: RefCounted
) -> bool:
# Tech gate — check value is a non-empty String before comparing
var tech_req: String = item["tech_required"] as String if item.has("tech_required") and item["tech_required"] is String else ""
var tech_req: String = _str_field(item, "tech_required")
if not tech_req.is_empty() and not player.has_tech(tech_req):
return false
# Building gate
var bld_req: String = item["building_required"] as String if item.has("building_required") and item["building_required"] is String else ""
var bld_req: String = _str_field(item, "building_required")
if not bld_req.is_empty() and bld_req not in city.buildings:
return false
# School gate
var school_val: String = item["school"] as String if item.has("school") and item["school"] is String else ""
var school_val: String = _str_field(item, "school")
if not school_val.is_empty() and school_val not in player.schools:
return false
return true