f2111a376a
- Introduced `life_evolution.gd` to manage life evolution processes. - Implemented `manual_production.gd` for handling production mechanics, including resource management and production steps. - Created `object_batches.gd` to manage batches of objects, including scaling and appending batches. - Developed `object_ledger.gd` for tracking physical amounts, available resources, and binding ownerships. - Added `simulation_module.gd` as a base class for simulation modules, providing a weak reference to the world. - Established `stellar_rules.gd` for managing stellar evolution and destruction mechanics. - Introduced `universe_environment.gd` to calculate environmental parameters based on the current state of the universe.
59 lines
2.5 KiB
GDScript
59 lines
2.5 KiB
GDScript
extends SceneTree
|
|
const Clock = preload("res://world/owniverse/simulation_time.gd")
|
|
var checks: int = 0
|
|
var failures: int = 0
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run")
|
|
|
|
func check(condition: bool, message: String) -> void:
|
|
checks += 1
|
|
if not condition:
|
|
failures += 1
|
|
push_error(message)
|
|
|
|
func fixture():
|
|
var world = load("res://world/owniverse/owniverse.gd").new()
|
|
var global: Node = root.get_node("Global")
|
|
for id in global.OwniverseEntities:
|
|
var entity = load("res://world/owniverse/owniverse_entity.gd").new(global.OwniverseEntities[id])
|
|
world.catalog.entities[id] = entity
|
|
world.state.amount[id] = 0.0
|
|
world.state.stats.total_amount[id] = 0.0
|
|
if entity.group_as != "":
|
|
world.state.amount[entity.group_as] = 0.0
|
|
world.state.stats.total_amount[entity.group_as] = 0.0
|
|
world.catalog.entities["N"].life_product = {}
|
|
world.catalog.entities["N"].product_per_year_type = "H"
|
|
world.catalog.entities["N"].product_per_year_amount = 10.0
|
|
world.catalog.entities["N"].auto = 0.0
|
|
world.state.amount.N = 1.0
|
|
return world
|
|
|
|
func dispose(world) -> void:
|
|
for entity in world.catalog.entities.values():
|
|
entity.free()
|
|
world.free()
|
|
|
|
func run() -> void:
|
|
var world = fixture()
|
|
world.evolution.initialize_life_batches()
|
|
world.catalog.entities.N.cost = {"H": 2.0}
|
|
world.catalog.entities.N.bind = {"S": 3.0}
|
|
world.state.amount.H = 10.0
|
|
world.state.amount.S = 0.0
|
|
world.state.auto_resources = {"H": 10.0}
|
|
world.state.batches.H = [{"amount": 10.0, "start_year": 1.0, "end_year": 2.0}]
|
|
var before: Dictionary = world.state.duplicate(true)
|
|
check(not world.production.try_production(world.state, world.catalog.entities.N, 1.0, true), "Binding failure rejects production")
|
|
check(world.state == before, "Failure preserves costs, batches and budget")
|
|
world.state.amount.S = 10.0
|
|
var old_batches: Array = world.state.batches.H
|
|
check(world.production.try_production(world.state, world.catalog.entities.N, 2.0, true), "Funded production succeeds")
|
|
check(world.state.amount.H == 6.0 and world.state.amount.S == 4.0, "Exact cost and binding")
|
|
check(world.state.auto_resources.H == 6.0, "Exact automatic budget")
|
|
check(old_batches[0].amount == 10.0 and world.state.batches.H[0].amount == 6.0, "Consumed batches isolated")
|
|
print("Transaction: %d checks, %d failures" % [checks, failures])
|
|
dispose(world)
|
|
quit(1 if failures else 0)
|