Sunday, 17 February 2008

Resting & The Passage of Time

For the last two weeks I have been writing code to handle resting and the passing of time. Like all things to do with scripting and creating new mechanics however, the exercise has taken longer than I first thought it would do. This is mainly to do with the fact that determining who the main PC is when possessing a companion can be quite difficult, especially when using the in-game "rest" command.

There are also other conditions to consider that can affect the rest and recovery of HPs, spells, prayers and general recovery, such as lack of food, nearby monsters, or simply not being allowed. Lastly, of course, is the fact that in a multi-player game, one player may initiate a rest period, but you will not want every player to then add more time just because they choose to rest straight afterwards. It all gets very confusing as you can imagine, but I believe I have finally come to a conclusion with all this and have just a few minor details to finish coding before it is done. Throughout this time, I have been in touch with people on the NWN2 forums, and I can thank Jassper for his explanation of such things as to what constitutes a party or a faction or just a single person. This has an impact on which characters are treated when a player presses the rest button.

Waiting or Resting

When a player presses the rest button within the game, they will be requesting one of two things: Either to Wait or to Rest. Both of these options are displayed within a GUI (Graphical User Interface), allowing the player to choose which option they prefer. However, there are a few conditions that will prevent the REST GUI from being displayed, such as nearby enemies or being within a "No Rest Allowed" zone, such as city streets or active dungeons. In these cases, the player will have to continue with their adventures or find another place to rest/wait.

If the player is able to initiate the REST GUI so that the options are displayed, then they may still be restricted to being able to wait only. This will be the case if the PCs do not have any food (and therefore cannot gain the benefits of resting) or they have already rested within the last eight hours (not tired enough). The player will receive both an audio (gong sound) and a visual feedback if they are too hungry to rest (first image above), but the GUI will still open within half a second of this warning (second image) allowing the PCs to wait if they so desire.

WAITING: Depending upon the time of the day that the player chooses to wait, then they will be offered to wait until dusk or wait until dawn. As long as the GUI has displayed (meaning the PC is outside of any current restrictions), then they will always be able to choose the wait option. The current time of day the option is selected will also determine how many hours pass until the dawn or dusk, and will also count as time towards their PC's next available time before they can rest. In other words, if there are six hours until dawn and they choose to wait, then six hours will be removed from their eight hours wait time between resting. With waiting, the PC does not recover any HPs, spells or general health - only time passes and costs a food ration. If the PCs do not carry any food, then they may suffer from some hunger damage (in which case there would be no good reason to wait to try to rest, as resting cannot be done on an empty stomach anyway). NB: Having the Survival skill will help prevent some hunger damage if none of the players characters carry any rations.

The image to the left shows the player having chosen to wait until dusk without having any food to eat first. The screen has now turned darker (dusk), the result of a hunger check is displayed because they did not have any food, and the number of hours passed has been shown along with the new current time and date.

RESTING: As long as all the right conditions are met, then a player may choose to rest his characters instead of waiting. The conditions to allow resting are: (a) Not to have already rested within the last eight hours and (b) To carry food (normally rations), one of which is used up on resting. There are also audio and visual warnings to help warn players if any of their characters do not carry items that may be required to help study for prayers (Holy Book) or learn spells (Spell Book). Resting will always give some HPs back (according to the place of rest), and may help towards recovering from an ailment (poison or disease), but will not allow PCs to recover their prayer or spell abilities if they are missing vital objects required for the task. Resting is always considered eight hours. (However, see the note on Amorphous & Personal Times next.)

Amorphous & Personal Times

To help keep time flow reasonably standard and in the control of the players, I have currently opted for 15 minutes real time = 1 hour game time. This would mean a player would have to play for two hours real time before the eight hours restriction has passed by in game time before the PCs can learn either their prayers or spells again. Note, however, that if the wait option can be selected, then they will be able to overcome even this real time restriction. However, to be able to rest after this wait time, it would still mean the PCs are effectively camped outside in an open area, do not have any enemies nearby, can feed themselves and have access to their objects of study. This also precludes any other restrictions the DM may place upon the PCs, such as other environmental (severe weather) or personal restrictions (cursed?). The bottom line is, resting will not be readily available, unless the players are in a safe area and well prepared.

When it comes to calculating the eight hour delay before further prayer or spell recovery, each PC will have a personal eight hour window of time, starting from the moment that they last rested. Most of the time, (if players choose to rest at the same time), it also means all PCs in the game will be ready to recover spells at the same time. However, having personal time may allow players to plan certain usage of spells more tactically.

Note, however, actual time will only move forward in chunks for all PCs within the world when the wait option is selected. Actual time for rest is otherwise "swallowed up" by the time scale differential between real time and game time and balanced by each individual PCs own eight hour time window.

E.g. One player may choose to rest his or her characters at 9.00 a.m. game time. (No time is moved forward using this option.) Another player chooses to do the same. All PCs controlled by these two players have a personal time stamp placed upon them, from which they must wait another eight hours (5.00 p.m. game time) before they can learn their prayers or spells again. A third player does not need to rest because they have a full complement of spells, but does need to do so after another real time hour of game play (which would equate to about 2.00 p.m in game time). He or she may choose to rest at this time, whereas the previous players could not. (Again, no time is moved forward when selected.) However, the players now decide that the other PCs belonging to the other two players do need to recover their spells (again) and therefore try to find a place where they can wait until dusk (6.00 p.m in four hours time). Any player can choose to select this option from the GUI and the actual time for the game will move forward for all PCs. If successful, then the time will move forward enough for the players to allow their PCs to learn their prayers or spells again. (6.00 p.m. is after 5.0 p.m.) Alternatively, the players could have opted to continue playing without choosing the wait option (or may have been forced to keep playing because of circumstances) and would have been able to rest again when the game time reached 5.00 p.m. after about another 45 minutes real time.

I still have a little more coding left to do, and will give another update on this when I have finished it, and include any more details as I think of them. In the meanwhile, if you have any questions, please add them as a comment below.

No comments: