Godot Version
4.4
Question
I work on my first project, turn based tactical game on grid.
I have following scene structure so far:
-
Main Scene called BattleBoard.
It can instantiate unit scene
It has child node TileMap with a grid
It has child node for UI
In general, player actions related to selecting, moving, attack orders -
Unit scene
It has many inherited scenes for specific actual units, like tanks and soldiers (they will hold actual sprites, sounds, animations, unit stats and specific attack logic, like instantiating projectiles)
By itself, it acts like an interface that inherited scenes are implementing.
It works generally quite well so far, but I do not know what would be best practice to organize AI logic , that would control how enemy soldiers are moving and attacking.
So far I have this:
- Player moves their units and clicks End Turn in BattleBoard.
- BattleBoard has a method that will trigger (one by one) AI_Activate that sits in Unit scene. By default it is empty, but each enemy like Melee Brawler will override this method with a sequence action that says for example “move to closest player unit”, “attack” and “retreat”. Since I do not want to keep complicated logic in actual units like Brawler, they just store a pattern of this sequence and actual implementation of them sits in Unit scene, so every enemy can invoke them.
This is not ideal because for once, Unit scene needs to have access to state of the game that sits in BattleBoard and its children Tiles. And such structure causes me to use signal to go both up and down. Example:
Logic for AI turn sits in Brawler → Brawler attacks → uses Unit attack method → signals up to BattleBoard that it should move Brawler to position X and perform attack, BattleBoard checks if actions are valid, then performs attack (going back to Unit->Brawler to see if it needs to instantiate projectiles etc and then making actual attack there, waiting for signal up that this is finished), then signal down back to Brawler that action was fully done.
I think I have a wrong place to organize AI logic. It feels instead of signaling up and down like crazy, I should be calling the moves from some other place. But if I have all AI logic in BattleBoard, then it becomes a very big , very complicated scene with massive script . Should I add some node in between ?