Grid Sage Forums

Grid Sage Forums

  • November 23, 2024, 07:49:48 AM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

LINKS: Website | Steam | Wiki

Author Topic: New here, some questions about time/energy :)  (Read 5079 times)

Xaron

  • Unaware
  • *
  • Supported Cogmind Alpha Access 2015-2017 (Prime Tier)
  • Posts: 12
    • View Profile
New here, some questions about time/energy :)
« on: January 13, 2017, 07:17:43 AM »

Hey there,

first, congrats for this gem of a game! :)

Currently I'm in the process to starting to develop kind of an own rogue-like as some questions came up about that which I would like to ask here because you've solved them quite nicely. ;)

1) Time/Energy system
I understand the way you're doing that and it's great. I still don't get when a new turn starts!
Does it start when all actors have used their energy? So the player does his move, then all actors use their energy and the next turn starts?

Can it happen that energy is saved for later or is there a cap of energy you cannot cross?

2) Slow moving projectiles
Let's take missiles for instance. Once fired, do they continue to move to the player even though he doesn't take any action (and no new turn is generated?)?

3) Enemy movement
As far as I understand it, enemies never can move as long as the player hasn't done some action, right? Or is there kind of an elapsed time where a turn just ends and a new one starts, no matter if the player did some action or not?

Thanks and keep up the great work!
Logged

Shadowfury333

  • Derelict
  • **
  • Supported Cogmind Alpha Access 2015-2017 (Prime Tier)
  • Posts: 45
    • View Profile
Re: New here, some questions about time/energy :)
« Reply #1 on: January 13, 2017, 02:26:57 PM »

While I can't speak to how Cogmind specifically handles energy, I can (sourcing from DoomRL and the T-Engine documentation) speak to the general theory.

The system has a threshold value, above which actors can act. Any action subtracts its own duration from that actor's energy, and the system would be refilling that energy in a loop constantly. When it's the player's turn to act (that is, they have the highest energy score and its above the threshold, use some arbitrary but consistent tiebreaker if two actors are tied for energy), then this loop is paused until input is received, but the process is basically the same for all actors. There are no fixed turns, nor is there a point when turns "start", the game just goes around the table to find whoever has the required energy, and then they can act immediately.

If you must consider it in terms of turns, at least as far as implementation details go, the procedure is basically:

Code: ("a turn") [Select]
foreach actor
  actor.energy += 1

foreach actor
  if actor.energy > threshold
    if actor.type == player
      //handle input
    else
      //do AI stuff

looped forever as the game is running.


For a concrete example, let's use 100 as our threshold, set movement and shooting to take 10 energy units. Let's have a player and an enemy:

At start, let's give them a random starting energy between 0 and 9, say 6 for the player and 1 for the enemy. Eventually, after 45 checks around the table and subsequent additions to the energy totals of both actors, the system will have given enough energy for one to act:

Player energy: 101
Enemy energy: 96

Now the player can act, and right now anything they do reduces their energy by 10:

Player energy: 101 -> 91
Enemy energy: 96

At this point, it's back to the energy refill loop, until someone goes above 50:

Player energy: 96
Enemy energy: 101

Now the enemy acts, and this continues.

If, for instance, the player had an alternate fire that cost 17 energy, then this situation would occur:

Player energy: 101 -> 84
Enemy energy: 96

Wait for 5 time units:

Player energy: 89
Enemy energy: 91 -> 91

Wait for 10 time units:

Player energy: 99
Enemy energy: 101 -> 91

Then the player gets to go again (after giving all actors another 2 energy).


For a more interesting example, let's have 2 enemies, one of which takes 5 units to move. For starting conditions:

Player energy: 3
Slow Enemy energy: 6
Fast Enemy energy: 2

In this case, the slow enemy goes first:

Player energy: 98
Slow Enemy energy: 101 -> 91
Fast Enemy energy: 97

Then the player gets above 50 next:

Player energy: 101 -> 91
Slow Enemy energy: 94
Fast Enemy energy: 100

And then the Fast enemy gets above 50, but maintains energy advantage:

Player energy: 92
Slow Enemy energy: 95
Fast Enemy energy: 101 -> 96

Player energy: 97
Slow Enemy energy: 100
Fast Enemy energy: 101 -> 96

Player energy: 98
Slow Enemy energy: 101 -> 91
Fast Enemy energy: 97

And then the player gets to act again.


I hope that wasn't too complicated, though I realize there were a lot of examples there, and it should cover questions 1 and 3.

As for question 2, that varies from game to game. most roguelikes (Cogmind included AFAICT) have the animations attached to weapons fire be essentially a visual flair, but no additional time/energy/turns is/are used for the projectile itself, nor is there a way for the player to avoid a slow projectile by moving out of the way after it is fired. The only exception I'm aware of is ToME, where projectiles can hang in the air between player actions, depending on timing, so fast characters can avoid previously fired projectiles. AFAIK ToME projectiles are actors in their own right with their own energy counter.
« Last Edit: January 13, 2017, 02:53:23 PM by Shadowfury333 »
Logged

DDarkray

  • Cyborg
  • ***
  • Shared a Confirmed Combat Win Shared a Confirmed Stealth Win Wiki Contributor Bug Hunter Weekly Seed Participant
  • Posts: 206
    • View Profile
Re: New here, some questions about time/energy :)
« Reply #2 on: January 13, 2017, 04:23:43 PM »

The game manual explains the time system this way:

Quote
Turns and the time required to perform actions are measured in time units. One absolute turn is equivalent to 100 units of time. Robots are given 100 time units each turn, and placed in a queue ordered by the amount of time units they have. A given robot can continue to act until it has <= 0 time, at which point its turn is over, and it is placed back in the queue. Taking a time-costly action can cause a robot’s time units to become negative, in which case it will be longer before that robot can act again.

So if moving 1 space costs 25 time units (I'll abbreviate it as TU), you can move up to 4 spaces until the end of your turn. Your turn does not end until all your 100 TU is used up. If you use a more time-consuming action like picking up an item from the ground (100 TU), your turn ends immediately). But if you fire a weapon (200 TU), you must wait 2 whole turns until you can act again.

Meanwhile, your enemy steps in around the corner, moving 6 spaces (150 TU in total)  and then open fire (200 TU). How could he do that? Well, you have to wait for a while to recharge, so by the time he moved 4 spaces (100 TU), you're still in the waitlist for 100 TU. So he got to move an another 2 spaces (50 TU) and then fire. By the time it's your turn, he's on the waitlist for 150 TU, so you can either fire a shot or run away.
Logged

Widmo

  • Derelict
  • **
  • Shared a Confirmed Stealth Win Wiki Contributor Bug Hunter Supported Cogmind Alpha Access 2015-2017 (Prime Tier) Weekly Seed Participant
  • Posts: 83
    • View Profile
Re: New here, some questions about time/energy :)
« Reply #3 on: January 13, 2017, 05:57:11 PM »

You may wish to pay a visit to RogueBasin if you have not done so already. It has a small collection of articles on this subject:
http://www.roguebasin.com/index.php?title=Articles#Time_management
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 4477
    • View Profile
    • Cogmind
Re: New here, some questions about time/energy :)
« Reply #4 on: January 13, 2017, 07:27:00 PM »

In addition to Widmo's link (which is where I started years ago :P), you can also check out our more recent FAQ Friday on Time Systems over on r/roguelikedev, where both myself and other devs shared how our systems work.

To your questions, in short:
  • As you'll read in some of the other articles, turns are essentially a part of the queue as well, and "happen" every 100 ticks. They represent increments of absolute time, while in effect all actors are essentially acting on their own timelines irrespective of actions by other actors. In many traditional turn-based games the core concept is that turns pass back and forth between one or more sides, while in energy-based roguelikes that's not the case.
  • As others have pointed out, projectiles aren't turn-based, just visual fluff, which is how most roguelikes handle it. (There are relatively few RLs in which projectiles are also turn-based.)
  • Right, that's the standard way roguelikes work. Pure turn-based "wait as long to decide as you want." Real-time cutoff is a concept only used in multiplayer roguelikes to keep the game flow going (but honestly ends up not being very "roguelike" as a result).
Thanks to everyone else for providing other input!

While I already did a writeup on my system for that FAQ, I've also wanted to one day write a full article for my dev blog--haven't covered that topic there yet.
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

zxc

  • Cogmind
  • *****
  • 1st place in the High Scores category during Alpha Challenge 2015 1st place in the Best Escapes category during Alpha Challenge 2015 Shared a Confirmed Combat Win Shared a Confirmed Stealth Win Kyzrati Patron Bug Hunter Participated in the Alpha Challenge 2015 Achievement leader in at least one category during Alpha Challenge 2015 Wiki Contributor Weekly Seed Participant
  • Posts: 726
    • View Profile
Re: New here, some questions about time/energy :)
« Reply #5 on: January 13, 2017, 11:02:01 PM »

Just want to say that TOME4 does turn-based projectiles. It can be messy but cool.
Logged

Xaron

  • Unaware
  • *
  • Supported Cogmind Alpha Access 2015-2017 (Prime Tier)
  • Posts: 12
    • View Profile
Re: New here, some questions about time/energy :)
« Reply #6 on: January 14, 2017, 12:39:32 PM »

Awesome, thanks so much for clarification and all your time trying to explain this to me! :)

Turn based projectiles might be cool too, because I'd like to make kind of a submarine based (in the future like Schleichfahrt/Archimedean Dynasty) one where torpedoes play quite a role. I'm still not sure how to handle that...

Cheers - Xaron
« Last Edit: January 14, 2017, 01:01:07 PM by Xaron »
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 4477
    • View Profile
    • Cogmind
Re: New here, some questions about time/energy :)
« Reply #7 on: January 14, 2017, 05:50:26 PM »

Yep, I can see turn-based torpedoes being an appropriate and fun mechanic for a game like that. Fortunately it's not too hard to implement: in this case projectiles themselves are simply an object like the other actors/entities, so they get a turn (or place in the timeline--however you decide to handle time) as well.
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

Xaron

  • Unaware
  • *
  • Supported Cogmind Alpha Access 2015-2017 (Prime Tier)
  • Posts: 12
    • View Profile
Re: New here, some questions about time/energy :)
« Reply #8 on: January 15, 2017, 07:16:34 AM »

Thanks again! :) Well I might give it a try, I always wanted to make an atmospheric game playing in the distant future (very dark atmosphere). :)

Your game cogmind is an incredible good inspiration and fun, thanks for creating it! And thanks for your help.

Logged

Shadowfury333

  • Derelict
  • **
  • Supported Cogmind Alpha Access 2015-2017 (Prime Tier)
  • Posts: 45
    • View Profile
Re: New here, some questions about time/energy :)
« Reply #9 on: January 16, 2017, 02:25:21 PM »

So...why use the term "turn"?

It sounds like the only meaning it has is that every actor gets +100 energy units when they come up in the queue. I guess given that it's neither looping through all the actors to update energy units before checking to see who has the most energy to act at any given time step, nor adding just 1 energy unit every go around the queue (which would do the same thing, just slower), it's kind of a turn.

Assuming I'm right about the meaning of turn, it sounds like the main difference is that actors get energy roughly equal to their usual action energy cost. Granted, the only other energy-based setup whose implementation I'm familiar with is DoomRL, but the only difference I'm aware of between that and Cogmind is that the energy gained every time an actor comes up in DoomRL is about 1/10th the usual action energy cost.
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 4477
    • View Profile
    • Cogmind
Re: New here, some questions about time/energy :)
« Reply #10 on: January 16, 2017, 08:59:57 PM »

Turns have a much more important meaning than that, because they still represent the passage of absolute time, on which many mechanics are based. All of your energy upkeep and generation, heat generation and dissipation, tons of item effects etc. are based on the passage of time, irregardless of what actions you're taking (or not taking).

Think also of all the places turn counters appear in the game--time-based events, many interactive machine timer countdowns, machine destabilization delayed explosions, all kinds of stuff!
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

Shadowfury333

  • Derelict
  • **
  • Supported Cogmind Alpha Access 2015-2017 (Prime Tier)
  • Posts: 45
    • View Profile
Re: New here, some questions about time/energy :)
« Reply #11 on: January 17, 2017, 12:16:16 AM »

Oh, fair enough. I guess I just assumed it was more granular than it is, and that the counters on items were counting some arbitrary "second", but I expected energy was passed around in smaller chunks. Basically, I figured absolute time passed all the time, rather than every interval of 100 being particularly meaningful, and that counters and such just rounded up the remaining time units for their display.

Granted, it's not a huge difference either way in practice.
Logged

Xaron

  • Unaware
  • *
  • Supported Cogmind Alpha Access 2015-2017 (Prime Tier)
  • Posts: 12
    • View Profile
Re: New here, some questions about time/energy :)
« Reply #12 on: March 17, 2017, 03:09:07 AM »

Thanks again for all this input. Just to let you know that I just started with kind of a stealth sonar approach like RL, not with submarines but using sonar as your only way to "see" the world around you. I can post a small working HTML5 prototype if you want to take a look (dunno if that's allowed here ;) I don't want to advertise anything!)?
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 4477
    • View Profile
    • Cogmind
Re: New here, some questions about time/energy :)
« Reply #13 on: March 17, 2017, 04:41:09 AM »

You can post anything you want in the General & Off-Topic board! This one's for Cogmind discussion :)

(I'm totally cool with people putting their own projects/games or whatever else in that one, though.)
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

Xaron

  • Unaware
  • *
  • Supported Cogmind Alpha Access 2015-2017 (Prime Tier)
  • Posts: 12
    • View Profile
Re: New here, some questions about time/energy :)
« Reply #14 on: March 17, 2017, 04:48:17 AM »

Thanks, will do that then! :) Much appreciated!
Logged