extends SceneTree var checks := 0 var failures := 0 class Budget: extends RefCounted var resources := {&"gold":100000, &"materials":100000} func get_resource(id: StringName) -> int: return resources.get(id, 0) func can_afford(cost: Dictionary) -> bool: for id: Variant in cost: if resources.get(id, 0) < cost[id]: return false return true func spend(cost: Dictionary) -> bool: if not can_afford(cost): return false for id: Variant in cost: resources[id] -= cost[id] return true func expect(ok: bool, message: String) -> void: checks += 1 if not ok: failures += 1; push_error(message) func _initialize() -> void: for entry: Array in [["premium_room",Vector2i(4,1),0,2],["staff_dormitory",Vector2i(2,1),1,2],["black_market",Vector2i(4,2),0,-5]]: var definition: FacilityDefinition = load("res://data/facilities/expansion/%s.tres" % entry[0]) expect(definition.footprint == entry[1] and definition.layer == entry[2], "canonical dimensions and layer: " + entry[0]) for rotation: int in [0,90,180,270]: var world := WorldService.new() world.reset({&"min_x":-10,&"max_x":10,&"min_y":-10,&"max_y":10}) var origin := Vector3i(0,entry[3],entry[2]) var size: Vector2i = entry[1] if rotation in [90,270]: size = Vector2i(size.y,size.x) var expected := world.cells_for_footprint(origin,size) world.set_support(origin,0,true) for cell: Vector3i in expected: if cell.y < 0: world.set_excavated(cell,true) var budget := Budget.new() var construction := ConstructionService.new(world,budget) var started := construction.start_construction(definition,origin,rotation) expect(started.is_success(), "canonical construction accepted: %s rotation %d" % [entry[0],rotation]) if not started.is_success(): continue var job := construction.get_jobs()[0] expect(job.reserved_cells == expected, "reservation has exact rotated original footprint") for minute in range(1,definition.build_minutes+1): construction.advance_one_minute(minute) var completed := construction.get_facility(job.facility_instance_id) expect(job.state == ConstructionJob.State.COMPLETED and completed.get(&"occupied_cells",[]) == expected and world.get_entity_cells(job.facility_instance_id).size() == expected.size(), "completion keeps original footprint") expect(budget.get_resource(&"gold") == 100000-int(definition.construction_cost[&"gold"]), "dimension correction does not multiply construction payment") var restored := ConstructionService.new(world,budget) expect(restored.restore_snapshot(construction.create_snapshot()), "completed original-size construction restores") print("Original facility dimensions: %d checks, %d failures" % [checks,failures]);quit(failures)