I am working on a game where the currently loaded level is stored in data structure, which also stores the player object, as well as a vector of all enemy entities. A gamecontroller class holdes exactly one instance of the mentioned level data-structure and drives the game.
The problem I am facing is, that I want to implement an AI for all enemy entities and I just don't know how or where to put implementation in terms of data sharing.
There are several different types of AI which are all based on simple finite-state-machines, where each FSM needs to store some data based on its agent type.
My current idea is to make a super-class for all enemy entities which contains a virtual void update(const MapClass&) = 0;
which later gets called on each enemy entity and passes the whole map data structure as reference so the AI can make modifications (make its move).
The problem with my current plan though, is that an entity contained in the whole map data-structure would call a member-method receiving the very map-object, where it is stored in, which as far as I know could cause some issues with recursive calls.
Another solution I thought of, is just passing the map data-structure as a const& and then returning a Move-object from the previously mentioned update()
-method which tells the controller, who is calling the update on the AI agents, to make changes to the environment.
So the update-method would now be virtual Move update(const Map&) = 0;
, returning a Move object which gets passed to an appropriate handler in the controller.
This however still does not eliminate the recursive thing i mentioned above, so I was wondering, wether there is a good design-pattern on how to implement AI in game with one central data-structure like mine.
I hope my question is somewhat clear, but if any code snippets are requested for better understanding, I will make sure to add them to this post.
Aucun commentaire:
Enregistrer un commentaire