Refactor: clean up unused code and improve variable initialization in evolution and entity management
This commit is contained in:
@@ -5,9 +5,9 @@ var evolution: OwniverseEvolution = OwniverseEvolution.new()
|
||||
|
||||
signal unlock_item(item_id: String)
|
||||
|
||||
var current_year: float = 0
|
||||
var current_year: float = 0.0
|
||||
var current_speed: int = 1
|
||||
var current_speed_in_years: float = 1
|
||||
var current_speed_in_years: float = 1.0
|
||||
|
||||
var entities: Dictionary[String, OwniverseEntity] = {}
|
||||
var entity_groups: Dictionary[String, Array] = {}
|
||||
@@ -21,24 +21,15 @@ var locked_entities: Array = []
|
||||
var cumulative_amount: Dictionary[String, float] = {}
|
||||
var current_amount: Dictionary[String, float] = {}
|
||||
|
||||
#var batch_count: int = 40
|
||||
#var entity_batches = {}
|
||||
|
||||
|
||||
func cycle(year_delta: float) -> void:
|
||||
# all owniverse activity should be called here
|
||||
_auto_production(year_delta)
|
||||
#_entity_evolution(year_delta)
|
||||
|
||||
_check_locked_items()
|
||||
|
||||
#var v = _get_distribution(current_amount)
|
||||
evolution.update_distribution(current_amount)
|
||||
|
||||
#for k in current_amount:
|
||||
#if current_amount[k] != 0:
|
||||
#print(k, "|", current_amount[k])
|
||||
|
||||
|
||||
#region auto production and evolution
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ var gamma: float
|
||||
var blast: int
|
||||
var life_product: Dictionary = {}
|
||||
var product_per_year_type: String = ""
|
||||
var product_per_year_amount: float = 0.0
|
||||
var product_per_year_amount: float = 0
|
||||
var voids: int
|
||||
var output_or: Dictionary = {}
|
||||
var output_and: Dictionary = {}
|
||||
@@ -41,14 +41,16 @@ func _init(values: Dictionary) -> void:
|
||||
mass = float(values.mass)
|
||||
space = int(values.space)
|
||||
lifespan = float(values.lifespan)
|
||||
lifespan_delta = lifespan / Global.batch_count / 2 # need for proper math
|
||||
lifespan_delta = lifespan / Global.batch_count / 2 if lifespan > 10 else lifespan
|
||||
auto = float(values.auto)
|
||||
gamma = float(values.gamma)
|
||||
blast = int(values.blast)
|
||||
|
||||
life_product = _parse_and_string(values.life_product)
|
||||
for key in life_product.keys():
|
||||
product_per_year_type = key
|
||||
product_per_year_amount = life_product[key] / lifespan if lifespan != 0 else 0
|
||||
#print(id, " | ", lifespan_delta, " | ", lifespan)
|
||||
|
||||
voids = int(values.voids)
|
||||
output_or = _parse_or_string(values.output)
|
||||
|
||||
@@ -2,13 +2,31 @@ extends Node
|
||||
|
||||
class_name OwniverseEvolution
|
||||
|
||||
const FLOAT_THRESHOLD: float = 1.0E14
|
||||
# TODO to save !!!
|
||||
var state: Dictionary = {
|
||||
'year': 0.0,
|
||||
'energy': 1E14,
|
||||
}
|
||||
|
||||
var entities: Dictionary[String, OwniverseEntity] = {}
|
||||
|
||||
var producing_entities: Array[OwniverseEntity] = []
|
||||
var auto_producing_entities: Array[OwniverseEntity] = []
|
||||
var auto_production_rest: Dictionary[String, float] = {}
|
||||
|
||||
# TODO to save !!!
|
||||
var auto_production_rest: Dictionary = {
|
||||
'H': 0.0,
|
||||
'S': 0.0,
|
||||
'auto': 0.0,
|
||||
}
|
||||
|
||||
var evolving_entities: Array[OwniverseEntity] = []
|
||||
|
||||
# TODO to save !!!
|
||||
var batches: Dictionary[String, Array] = {}
|
||||
# TODO to save !!!
|
||||
var amount: Dictionary[String, float] = {}
|
||||
|
||||
|
||||
var distribution: Dictionary[String, float] = {}
|
||||
|
||||
@@ -27,6 +45,9 @@ func add(entity: OwniverseEntity, year: float, amount: float):
|
||||
}
|
||||
_batch_array.append(_batch)
|
||||
|
||||
print('---------')
|
||||
print(batches)
|
||||
|
||||
|
||||
func process(from_year: float, to_year: float) -> void:
|
||||
# производим
|
||||
@@ -68,33 +89,42 @@ func produce(from_year: float, to_year: float):
|
||||
var _time_delta = to_year - from_year
|
||||
# get entity array for production
|
||||
for _entity: OwniverseEntity in producing_entities:
|
||||
var _to_produce: float = 0
|
||||
var _new_batch_array:= []
|
||||
var _to_produce: float = 0.0
|
||||
for _batch: Dictionary in batches[_entity.id]:
|
||||
_to_produce += _batch.amount
|
||||
# production
|
||||
_to_produce *= _time_delta * _entity.product_per_year_amount
|
||||
var _auto_production_part: float = 0
|
||||
if _entity.auto > 0:
|
||||
_auto_production_part = _entity.auto * _to_produce
|
||||
var _auto_production_part: float = _entity.auto * _to_produce
|
||||
_to_produce -= _auto_production_part
|
||||
auto_production_rest.auto += _auto_production_part
|
||||
|
||||
# and rest
|
||||
# energy = wasted vs rest !!
|
||||
|
||||
auto_production_rest[_entity.product_per_year_type] += _to_produce
|
||||
print("auto prod rest: ", auto_production_rest)
|
||||
auto_production_rest["H"] = produce_hs("H", auto_production_rest["H"])
|
||||
auto_production_rest["S"] = produce_hs("S", auto_production_rest["S"])
|
||||
|
||||
|
||||
func produce_hs(entity_id: String, value: float) -> float:
|
||||
var _to_produce:float = floorf(value)
|
||||
amount[entity_id] += _to_produce
|
||||
# TODO double double math
|
||||
if _to_produce > state["energy"]:
|
||||
_to_produce = state["energy"]
|
||||
state["energy"] -= _to_produce
|
||||
return value - _to_produce
|
||||
|
||||
func produce_auto() -> float:
|
||||
return 0.0
|
||||
|
||||
func init_entity(entity: OwniverseEntity) -> void:
|
||||
entities[entity.id] = entity
|
||||
amount[entity.id] = 0.0
|
||||
if entity.product_per_year_type != "":
|
||||
producing_entities.append(entity)
|
||||
|
||||
if entity.lifespan > 0:
|
||||
evolving_entities.append(entity)
|
||||
|
||||
if entity.auto > 0:
|
||||
auto_producing_entities.append(entity)
|
||||
auto_production_rest[entity.id] = 0
|
||||
|
||||
batches[entity.id] = []
|
||||
|
||||
|
||||
@@ -111,3 +141,9 @@ func update_distribution(_distribute_by: Dictionary[String, float]) -> void:
|
||||
|
||||
for id in distribution:
|
||||
distribution[id] /= _total
|
||||
|
||||
#func _add_float(a: float, b: Array[float]) -> Array[float]:
|
||||
#if a < FLOAT_THRESHOLD:
|
||||
#return [a+b[0], 0]
|
||||
#else:
|
||||
#return [a+b[0], 0]
|
||||
|
||||
Reference in New Issue
Block a user