evolution
This commit is contained in:
@@ -2,23 +2,81 @@ extends Node
|
||||
|
||||
class_name OwniverseEvolution
|
||||
|
||||
var batch_count: int = 40
|
||||
var entities: Dictionary[String, OwniverseEntity] = {}
|
||||
var producing_entities: Array[OwniverseEntity] = []
|
||||
var evolving_entities: Array[OwniverseEntity] = []
|
||||
|
||||
var batches: Dictionary[String, Array] = {}
|
||||
|
||||
var distribution: Dictionary[String, float] = {}
|
||||
|
||||
|
||||
func evolute():
|
||||
pass
|
||||
|
||||
func add_to_batch(enitity: OwniverseEntity, amount: float, year: float) -> void:
|
||||
var to_year: float = year + enitity.lifespan
|
||||
var _entity_batches: Array[OwniverseBatch] = batches[enitity.id]
|
||||
if _entity_batches.size() == 0 or _entity_batches[-1].to_year <= to_year:
|
||||
_entity_batches.append(OwniverseBatch.new(to_year, enitity.lifespan_cycle))
|
||||
func add(entity: OwniverseEntity, year: float, amount: float):
|
||||
var _batch_array:Array = batches[entity.id]
|
||||
var _from_year: float = year + entity.lifespan - entity.lifespan_delta
|
||||
var _to_year: float = year + entity.lifespan + entity.lifespan_delta
|
||||
if _batch_array.size() != 0 and _batch_array[-1].to_year > year + entity.lifespan:
|
||||
_batch_array[-1].amount += amount
|
||||
else:
|
||||
var _batch := {
|
||||
'from_year': _from_year,
|
||||
'to_year': _to_year,
|
||||
'amount': amount,
|
||||
}
|
||||
_batch_array.append(_batch)
|
||||
|
||||
_entity_batches[-1].add(amount)
|
||||
|
||||
func process(from_year: float, to_year: float) -> void:
|
||||
# производим
|
||||
# эволюционируем
|
||||
# записываем новые
|
||||
var _to_produce:= {}
|
||||
var _to_evolute:= {}
|
||||
for _entity_id in batches:
|
||||
_to_produce[_entity_id] = 0
|
||||
_to_evolute[_entity_id] = 0
|
||||
var _new_batch_array:= []
|
||||
for _batch: Dictionary in batches[_entity_id]:
|
||||
# production
|
||||
_to_produce[_entity_id] += _batch.amount
|
||||
# evolution
|
||||
if _batch.to_year < to_year:
|
||||
_to_produce[_entity_id] += _batch.amount
|
||||
else:
|
||||
var _max_from_year: float = max(from_year, _batch.from_year)
|
||||
var _min_to_year: float = min(to_year, _batch.to_year)
|
||||
var _part_of_amount: float = _batch.amount \
|
||||
* (_min_to_year - _max_from_year) \
|
||||
/ (_batch.to_year - _batch.from_year)
|
||||
_to_evolute[_entity_id] += _part_of_amount
|
||||
var _rest_of_amount: float = _batch.amount - _part_of_amount
|
||||
|
||||
if _rest_of_amount > 0:
|
||||
_new_batch_array.append({
|
||||
'from_year': _batch._from_year,
|
||||
'to_year': _batch._to_year,
|
||||
'amount': _rest_of_amount,
|
||||
})
|
||||
|
||||
# entity level
|
||||
batches[_entity_id] = _new_batch_array
|
||||
|
||||
|
||||
func produce(from_year: float, to_year: float):
|
||||
for batch_name in batches:
|
||||
pass
|
||||
|
||||
|
||||
func init_entity(entity: OwniverseEntity) -> void:
|
||||
entities[entity.id] = entity
|
||||
if entity.product_per_year_type != "":
|
||||
producing_entities.append(entity)
|
||||
|
||||
if entity.lifespan > 0:
|
||||
evolving_entities.append(entity)
|
||||
|
||||
batches[entity.id] = []
|
||||
|
||||
|
||||
func update_distribution(_distribute_by: Dictionary[String, float]) -> void:
|
||||
distribution = {}
|
||||
@@ -33,4 +91,3 @@ func update_distribution(_distribute_by: Dictionary[String, float]) -> void:
|
||||
|
||||
for id in distribution:
|
||||
distribution[id] /= _total
|
||||
|
||||
|
||||
Reference in New Issue
Block a user