Re: Incorporating lifespan in act.informative.c [LONG]

From: Tony Robbins (robbinwa@mailbox.orst.edu)
Date: 12/11/00


Quoting Surgeon <webremedies@HOME.COM>:

[snip]
> =] Ok thanks alot to all that posted,
> just curious as to how one goes about checking
> the descriptor to make
> sure the zone inwhich they are executing the
> command has a lifespan.

Ok, well, you want to know what zone a character is in.
You say have a character's descriptor (I doubt this,
you probably have a char_data reference, but we'll
trust what you've stated).  descriptors are often
called ``d'' in CircleMUD's source code, so we'll call
it d.

d has a member called character, which is a char_data
structure.  It is referenced as: d->character

char_data has a member called in_room.  It is a
room_rnum.  It is referenced as: d->character->in_room
-or-
IN_ROOM(d->character) if know the macros in utils.h.

room_rnums are the indices of the world[] array.  The
world array is of types room_data.  room_data has a
member called zone, which is a zone_rnum.  So we have:
world[IN_ROOM(d->character)].zone

zone_rnums are the indices of the zone_table[] array.
The zone_table array is of times zone_data.  zone_data
has a member called lifespan, which is an int.
So we have:
zone_table[world[IN_ROOM(d->character)].zone].lifespan

There's the variable you're looking to compare.  You
also know the various structures you should know.
They're in structs.h, if you don't already know, and
you should read them.  Because you're trying to code.

Oh, and you should realize that the arrays above and
other variables might be in an EXTERNal file from what
you're working with.  Somebody else showed you how to
pull them out of another file.

> ie: what I will need to do is, if lifespan
> excists and is greater then
> or equal to 0 and less then 500 I need to
> increment lifespan, just no
> clue as to how one checks to make sure
> everything is ok.
> a for loop? out on a limb on this one.

Comparison Operators:
x greater than y : x > y
x less than y : x < y
x greater than or equal to y : x >= y

Math Operators:
(obvious) : + - / *
pre-increment : ++(variable)
post-increment : (variable)++
pre-decrement: --(variable)
post-decrement: (variable)--

Pre- and post-whatever are important depending on what
you're doing, in regard to order of operations.

Logical operators:
and : &&
or : ||

From what I've put above, you should be able to see how
you would say (pseudo-code, a good tool):

if (
[lifespan of zone of room of character of descriptor]
is greater than or equal to zero AND
[lifespan of zone of room of character of descriptor]
is less than five-hundred] ) then
increment
[lifespan of zone of room of character of descriptor]


> *so I how do I make sure the zone has an olc
> structure, from where the
> command is being entered by the char, and also
> what steps should be
> taken to change the value of lifespan for
> instance. *

Unless you're using some OLC you've written yourself or
gotten from someone else, Oasis and Obuild don't have
olc structures in zones.  A descriptor might have an
olc structure, and it might not.  If they don't, it has
been free()'d and set to NULL.  If they do, it should
hold some value.  You can set up a comparison to test
this.

I believe that the problem you are having is not
knowing C and not knowing the code.  You can learn to
read CircleMUD code without learning C, but it's hard,
and you trip yourself up a lot.  You can learn C and
never use it for CircleMUD, and most people do that.
But without knowing proper C syntax and the critical
structures that are used throughout the code, you will
not be able to create anything new or original on your
own.

This e-mail is a really long RTFC message, and I
apologize for that.  Don't take offense to it, just
realize that I just spent 15 or 20 minutes putting
together something that would explain itself with some
C knowledge and time spent with the source.

-k.

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 04/11/01 PDT