How do I design this kind of feature?

Started by
9 comments, last by SYJourney 7 years, 11 months ago

Thanks for the advice. After reviewing all of it, here's a rough sketch of what I'm using now:

Item effects such as in the OP and similiar sequences of events will be scripted. For the scripts I use my own syntax which translates to how I handle messages in game. The way I will create the scripts is by using a GUI where you can drag and drop more abstract tasks into a structure, edit their properties etc.

In the c++ code I have an interface 'ITask' which declares an 'update' and an 'is_done' method. Every component in my game that receives these tasks has a container which calls update on all it's tasks and removes them once they are done. This way I can treat all actions as happening over a certain period of time. Actions which occur once just always return true for 'is_done'. Then I also have some special implementations of 'ITask' which are composed of other tasks. For example 'TaskSequence' which is a queue of tasks, updates it's front task and is done when the queue is empty. Or 'TaskBranch' which evaluates an 'ICondition' once and then delegates to it's sub-'ITask' mapped to the result. So essentially the core of my design is that all of these are 'ITask's, so I can combine asynchronous/synchronous processing, branching logic (and whatever else I can come up with) arbitrarily.

This topic is closed to new replies.

Advertisement