evolution

This commit is contained in:
Kirill
2026-08-02 22:56:54 +03:00
parent 6d846ec813
commit 8e565e5ac0
7 changed files with 263 additions and 236 deletions
+39 -35
View File
@@ -21,8 +21,8 @@ var locked_entities: Array = []
var cumulative_amount: Dictionary[String, float] = {}
var current_amount: Dictionary[String, float] = {}
var batch_count: int = 40
var entity_batches = {}
#var batch_count: int = 40
#var entity_batches = {}
func cycle(year_delta: float) -> void:
@@ -54,10 +54,6 @@ func _auto_production(year_delta: float) -> void:
_count_amount(item, _cycle_production[item])
func _entity_evolution(year_delta: float) -> void:
print("evolution: ", year_delta)
pass
func _get_distribution(source: Dictionary) -> Dictionary:
var distribution: Dictionary = {}
var total: float = 0
@@ -74,20 +70,21 @@ func _get_distribution(source: Dictionary) -> Dictionary:
#region Production
func produce(item_id: String, amount: float) -> void:
var entity: OwniverseEntity = entities[item_id]
var _entity: OwniverseEntity = entities[item_id]
var entity_transaction = {}
for elem in entity.cost:
if current_amount[elem] < amount * entity.cost[elem]:
for elem in _entity.cost:
if current_amount[elem] < amount * _entity.cost[elem]:
return
if entity.cost[elem] == 0: continue
if _entity.cost[elem] == 0: continue
entity_transaction[elem] = -amount * entity.cost[elem]
entity_transaction[elem] = -amount * _entity.cost[elem]
for elem in entity_transaction:
_process_enitity(elem, entity_transaction[elem])
_process_enitity(item_id, amount)
evolution.add(_entity, current_year, amount)
func automated_production(_delta: float) -> void:
@@ -164,12 +161,13 @@ func load_data() -> bool:
if game_data == {}:
return false
if !game_data.has_all(["cumulative_amount", "current_amount",
"entity_batches", "year",
if !game_data.has_all(["cumulative_amount", "current_amount"
#, "entity_batches"
, "year",
]):
return false
entity_batches = game_data["entity_batches"]
#entity_batches = game_data["entity_batches"]
cumulative_amount = game_data["cumulative_amount"]
current_amount = game_data["current_amount"]
current_year = game_data["year"]
@@ -185,36 +183,42 @@ func save_data() -> void:
game_data["year"] = current_year
game_data["cumulative_amount"] = cumulative_amount
game_data["current_amount"] = current_amount
game_data["entity_batches"] = entity_batches
#game_data["entity_batches"] = entity_batches
SaveManager.save_data("owniverse", "qwerty", game_data)
func init_enitities() -> void:
for entity_id in Global.OwniverseEntities:
var entity = OwniverseEntity.new(Global.OwniverseEntities[entity_id])
entities[entity_id] = entity
var _auto_production := []
for _entity_id in Global.OwniverseEntities:
var _entity = OwniverseEntity.new(Global.OwniverseEntities[_entity_id])
entities[_entity_id] = _entity
current_amount[entity_id] = 0
cumulative_amount[entity_id] = 0
if entity.group_as != "":
current_amount[entity.group_as] = 0
cumulative_amount[entity.group_as] = 0
current_amount[_entity_id] = 0
cumulative_amount[_entity_id] = 0
if _entity.group_as != "":
current_amount[_entity.group_as] = 0
cumulative_amount[_entity.group_as] = 0
if entity.unlock != {}:
locked_entities.append(entity)
if _entity.unlock != {}:
locked_entities.append(_entity)
evolution.init_entity(_entity)
if entity.product_per_year_type != "":
auto_production.append(entity)
if _entity.product_per_year_type != "":
auto_production.append(_entity)
_auto_production.append(_entity.id)
# groups
if entity.group_as != "":
if !entity_groups.has(entity.group_as):
entity_groups[entity.group_as] = []
entity_groups[entity.group_as].append(entity_id)
if _entity.group_as != "":
if !entity_groups.has(_entity.group_as):
entity_groups[_entity.group_as] = []
entity_groups[_entity.group_as].append(_entity_id)
if entity.event_group != "":
if !entity_event_groups.has(entity.event_group):
entity_event_groups[entity.event_group] = []
entity_event_groups[entity.event_group].append(entity_id)
if _entity.event_group != "":
if !entity_event_groups.has(_entity.event_group):
entity_event_groups[_entity.event_group] = []
entity_event_groups[_entity.event_group].append(_entity_id)
#evolution.init_batches(_auto_production)
#endregion
-32
View File
@@ -1,32 +0,0 @@
extends Node
class_name OwniverseBatch
var from_year: float
var to_year: float
var amount: float = 0
func process(year: float) -> float:
var _amount: float = 0
if year < to_year: return 0
if year >= to_year:
_amount = amount
amount = 0
return _amount
_amount = clampf(amount * (year - from_year) / (to_year - from_year), 0, amount)
amount -= _amount
from_year = year + 1
return _amount
func add(delta: float) -> void:
amount += delta
func _init(year: float, year_delta: float) -> void:
from_year = year - year_delta
to_year = year + year_delta
-1
View File
@@ -1 +0,0 @@
uid://cs0mllvnraida
+2 -3
View File
@@ -9,7 +9,7 @@ var bind: Dictionary = {}
var mass: float
var space: int
var lifespan: float
var lifespan_cycle: float
var lifespan_delta: float
var auto: float
var gamma: float
var blast: int
@@ -41,8 +41,7 @@ func _init(values: Dictionary) -> void:
mass = float(values.mass)
space = int(values.space)
lifespan = float(values.lifespan)
lifespan_cycle = lifespan / Global.batch_count # need for proper math
print(id, "", lifespan, " | ", lifespan_cycle)
lifespan_delta = lifespan / Global.batch_count / 2 # need for proper math
auto = float(values.auto)
gamma = float(values.gamma)
blast = int(values.blast)
+68 -11
View File
@@ -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