Re: Time Question

From: Niese-Petersen (Tenp@CRIS.COM)
Date: 08/08/97

On Sat, 9 Aug 1997, <Pure Krome> wrote:

> G'Day all.
>     can someone explain exatly (not in five words, becuase i know what
> the line DOES), but what each part of the line does, so i know HOW the
> line DOES what it does.
>   if (!IS_AFFECTED(ch, AFF_POISON) &&
>       (((long) (time(0) - st->last_logon)) >= SECS_PER_REAL_HOUR)) //
> <-- This Line
>  {
>     GET_HIT(ch) = GET_MAX_HIT(ch);
>     GET_MOVE(ch) = GET_MAX_MOVE(ch);
>   }
> It's caclulating how long they have been away for, right? and this
> determs if they need to be cured, recover health, etc.

Lets split it up in parts:

!IS_AFFECTED(ch, AFF_POISON) should be easy enough.

IS_AFFECTED(ch, <bit-vector>) return True is <bit-vector> is set, or False
is not set. By adding a ! infront of the test You are testing on
"NOT TRUE" . Remember IF will be activated if the expression is TRUE.

So if ch is not affected by posion then !False is True (Confused ? :) )

&& --- means AND. So since there are two expressions in the IF it has
to end up with TRUE AND TRUE = TRUE (Which activate the IF)

(((long) (time(0) - st->last_logon)) >= SECS_PER_REAL_HOUR)
Let us split that one up too.

time(0) gives us the current time..

st->last_logon is the last time the character was loged on.
(notice here the st and not ch, since st is the spare from load_char and
ch is what we are populating from it)

So time(0) - st->last_logon will give how much time the player have been
off since last logon.

(long) makes sure the result becomes a long variable.

SECS_PER_REAL_HOUR is a constant which you can find in structs.h (If I
recall right. Havent looked at the code for some time now. RL is a killer
:) )

So it test if the time period the player was off is >= (larger or equal)
of how long an real hour is.

So if the player is not affcted by poison and was off for an hour or
more, then make the current hitpoints and movementpoints be set to max.

Clear now ? :)

Erik Niese-Petersen
AKA Quint the Typo Dane
(Freelance coder for StrangeMUD 9332)

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

This archive was generated by hypermail 2b30 : 12/08/00 PST