Author Topic: question regarding time management  (Read 7637 times)

hsw2201

  • Newcomer
  • Posts: 5
  • Karma: +0/-0
    • View Profile
    • Email
question regarding time management
« on: November 15, 2015, 05:24:22 AM »
Hello there!
Although I'm in an environment which access to programming tools are almost impossible(I'm currently in mandatory service in army), I'm trying to design my own RL-thing.
So I'm now thinking about time management(Or turn scheduling, whatever) with global variable for turns. Say, one "turn" is 10 "clicks". And every action has [ready time],[wait time], [click-based total cost]. For example when @ moves A to adjacent tile B, action "MOVE" will be executed. And "MOVE" is consists of 8 clicks of ready time and 12 clicks of wait time for standard. Total cost is 20 clicks = 2.0 turns. @ spends 8 clicks at A, and then spends 12 clicks at B.
Other monsters or NPCs will use same click based actions simultaneously, so time will passes 1 click at a time for everyone. I think this is quite good, and I want to stick with this system. So problem is, which data structure should I use to implement this? I have some little experience in C++, but not so fluent. Thanks!

Tzan

  • Rogueliker
  • ***
  • Posts: 193
  • Karma: +0/-0
    • View Profile
Re: question regarding time management
« Reply #1 on: November 15, 2015, 04:32:15 PM »
You should take a look at two things: Vector and List.

A Vector is a dynamically resized array.
You would need to check each unit in the entire Vector every click, to see if any unit was up to act on that click.
You would just add a unit to the Vector and not care where it got placed.
You could add the player at the head of the Vector, so the player will always win ties for who is up to act that click.

List is a doubly linked list
So when you add an element you do it as an Insertion Sort priority que.
You use the click that the unit is up to act next as the value to check and insert at the right place.
When you get the next unit up to act, the List is already sorted so you just get the unit at the head of the list.

For a turn based game it doesn't really matter which you use, just pick the one you feel comfortable with.

hsw2201

  • Newcomer
  • Posts: 5
  • Karma: +0/-0
    • View Profile
    • Email
Re: question regarding time management
« Reply #2 on: November 19, 2015, 10:52:26 AM »
You should take a look at two things: Vector and List.

A Vector is a dynamically resized array.
You would need to check each unit in the entire Vector every click, to see if any unit was up to act on that click.
You would just add a unit to the Vector and not care where it got placed.
You could add the player at the head of the Vector, so the player will always win ties for who is up to act that click.

List is a doubly linked list
So when you add an element you do it as an Insertion Sort priority que.
You use the click that the unit is up to act next as the value to check and insert at the right place.
When you get the next unit up to act, the List is already sorted so you just get the unit at the head of the list.

For a turn based game it doesn't really matter which you use, just pick the one you feel comfortable with.
Vector seems nice. I don't know I'm on a right path, but... maybe I can use vector as a list of Actor objects(pc, npc, etc.) and each Actor has its own queue of actions. So every click, front of that queue executed and if I iterate vector from front to end, then (global variable) CLICK++ executed!
Since vector will store Actors of that level only, there seems no problem....right? ;)

Tzan

  • Rogueliker
  • ***
  • Posts: 193
  • Karma: +0/-0
    • View Profile
Re: question regarding time management
« Reply #3 on: November 19, 2015, 04:47:31 PM »
Looks like you understand perfectly.

hsw2201

  • Newcomer
  • Posts: 5
  • Karma: +0/-0
    • View Profile
    • Email
Re: question regarding time management
« Reply #4 on: November 20, 2015, 11:35:13 AM »
Looks like you understand perfectly.
Thank you very much! ;D ;D