Re: [SEMI-NEWBIE/LONG] Cycling a linked list for characters

From: Welcor (welcor@dune.net)
Date: 03/04/02


From: "Surgeon" <webremedies@CA.INTER.NET>
>     I am currently in the process of "trying" to make one of my first
> snippets for the CircleMUD community, but running into a bit of problems
in
> terms of cycling an object for more than one char.  For
> example (in relation to what's below) if I was to create a couch, with
> an infinite player limit and infinite weight restriction how would I
> properly go about cycling that object for ALL the characters on it.  This
is
> what I am currently tampering with now.
>
Apart from the fact that I've never heard of 'cycling' in this sense,
I think you're on the right track.

struct obj_data {
...
  struct rest_object_data *furniture;  /* object can be sat in */
...
};

Set this to NULL for all non-furniture.
Easy accessor macros:

OBJ_IS_FURNITURE(obj)  (obj->furniture != NULL)
OBJ_IS_SAT_IN_BY(obj)  (obj->furniture ? obj->furniture->sat_in_by : NULL)

> struct rest_object_data {
>  long weight_capacity;  /* how much weight can object hold -1 infinite*/
>  int player_capacity;   /* how many players can use this object -1 " */

+  int current_chars;     /* how many there now [1]*/
+  long current_weight;   /* how much is there now [1]*/

>  int regen_bonus;         /* bonus regen per tick */
>  int rest_type[4];          /* POS's: sleep, rest, kneel, sit */

I'd use

bitvector_t rest_type;

here. All you need is yes/no, anyhow. And you could use those 12 bytes
better elsewhere.

>  struct char_data *rested_on_by;  /* This is where I need assistance */

Change this to use your example below:
struct example *sat_in_by;

>  struct rest_object_data *next;

Are you making all rest objects sit in their own list ? If not
(which I recommend), ditch this.

> };
>
> Two problems I can forsee:
>
>     One:  I am planning on writing extra bits to the object files
obviously
> for all fields, rest_type[1] being sleep position, 1 (can be slept on), 0
if
> not.  Just so as to provide a way for builders to make furniture restable
> upon in some ways while restricting others.

I'd suggest you add a new section in your object files for this
(much the same way affects are saved;
-8<--
A
<location> <value>
-8<--)
I'd save it like:
R
<max weight> <max people> <regen rate> <bitvector>

>    Two:  I am somewhat left blinded as to how I would go about cycling
> ONE object for the amount of chars that are currently resting on it.
Would
> I have to create a whole new structure all together similar to the
> below inorder to succesfully shuffle through the chars?
>
>  struct example {
>     struct char_data *rested_on_by;
>     struct example *next;
> };
>
> And then replace the first instance of *rested_on_by (at the top) with:
> struct example *resting_plist;
>
> And then cycle through example independantly?
>

I'd do that. You might also set up a pointer in the char_data structure:

  struct obj_data *sitting_in;   /* Current restingplace */

This would make it easier to check for regen bonuses in limits.c

Welcor

[1] As I see it, you have two options, when it concerns weight and
number of chars:

1. count people, carried + personal weight whenever someone sits
   on the object. This option will cost some processing, depending
   on how many people are currently sitting in/on the object.
   The processing needed would be unnoticable when few people
   are using the same beds.
2. Keep a count of weight and people, and change it when people
   stand/rest/drop an item/get an item/eat an item/etc.
   This option will demand many changes in the code, but won't
   be very hard on processing power, and those two extra values
   would be unnoticable on the memory footprint.

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT