In orders.gd we have
const player_leaders_orders = {}
This is used first in a function called build_leaders() - still in orders.gd
func build_leaders():
for leader in game.player_leaders:
player_leaders_orders[leader.name] = new_orders()
and
func new_orders():
return {
"priority": ["pawn", "leader", "building"],
"tactics": {
"tactic": "default",
"speed": 0
}
}
This is a dictionary of orders for every leader.
- In a c++ game engine this would be part of the leader constructor.
new_orders()
is just a default value.
Every unit in the game has this dictionary. Only the Main/Unit scene actualy uses it. In godot this could be a part of a _ready() function or just an onready
default value inside unit/leader class.
- build_leaders is a misleading function name. The same name is used four times in different nodes. If something is called "build" it should create an entity from start to finish. And reusing the name is very confusing.
- This was brought up before but everything in this game is a string, and we need to compare them constantly. String compare is not optimal. Plus coding is more difficult because the editor doesn't hint anything. You just have to remember every magic string in the game.
Then we have leaders_cycle. This is a function that is called every 4 seconds from a self-calling function.
func leaders_cycle(): # called every 4 sec
for leader in game.player_leaders:
set_leader(leader, player_leaders_orders[leader.name])
for leader in game.enemy_leaders:
set_leader(leader, enemy_leaders_orders[leader.name])
- Recursion is evil, regardless if its actual function call or just a yield to itself
- what is "set_leader"? Name tells me nothing about what is inside. It definetly will not be setting any leaders.
Now there is a set of functions:
orders.set_leader_tactic
, orders.set_leader_priority
- they handle player input/ AI decision
orders.set_leader
- updates the orders to the unit - why is this delay necessary?
Can the player not just order the unit and have it do what he wants to do?
More on build_leaders() : The other part not mentioned above:
var timer := Timer.new()
timer.wait_time = 1
game.map.add_child(timer)
timer.start()
# warning-ignore:return_value_discarded
timer.connect("timeout", self, "hp_regen_cycle")
This starts a global timer that starts hp_regen_cycle. This in turn causes regeneration to happen. Regeneration also updates items.
- This is spaghetti, no defending it.