Jump to content
  • Advertisement
Sign in to follow this  

Thoughts about me action system theory.

This topic is 1240 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to create a specific action system for a semi turn based game. Example of 3 units.
time(0) Unit 1: move cost 20 (time), the unit moves immediately but then has to wait for 20 (time).
time(0) Unit 2: Turn cost 5 (time), the unit turns and has to wait 5(time)
time(0) Unit 3: Shoot cost 15 (time), the unit shoots and has to wait 15 (time).
time(5) Unit 2: Shoot cost 10(time), faster weapon then Unit 3.
time(15) Unit 2: Move cost 15(time)
time(15) Unit 3: Shoot cost 15(time)
time(20) Unit 1: Dances ?(time), joking, you get the point.
Now I am brainstorming how to set this system up. 
The most basic thing is giving each unit a action timer. When a action is performed this timer increased. Hold a list of Units and skip to the unit that has the lowest time on the list. Then decrease all times on the list by that amount. Set a new action for this unit and repeat. This seems solid but when I have a lot of units the list grows big. And have to change the complete list every time a action is performed.


I could setup a Action class that holds the time and unit but since it still holds the unit there would not be any improvement I guess. So a reference to the unit maybe? If I store all units in a list I can access them by a int, traversing a list (or a hashmap perhaps) of two ints would be a lot faster.


When A unit can act it chooses a action by a method, performs it and returns the value to store in the action list. When a  unit with the lowest time is chosen it updates the list.


I love to hear some opinions about it, perhaps there is a much better solution. I know premature optimization isn't a good thing but if I later have to change things around then I have to make changes deeper and deeper in my code.

Share this post

Link to post
Share on other sites

every unit has an actiontype, and an action countdown counter.


when you update a unit:

if counter=0, select new action, set action type and counter. example: shoot,  15 turns.  so action=shoot, and counter is set to 15.

else decrement counter.


you can also use a global clock or turn counter, and store when the action ends, instead of how many time units left until it ends - same difference.

Share this post

Link to post
Share on other sites

Some of the Final Fantasy games did this, some even displayed a meter of when their turn would come up.


I wouldn't really worry about the performance of re-ordering one thing in the queue/list/array, you're not doing it every frame, and you most likely aren't going to have thousands of things in the list.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!