Re: GUILD related layout

From: Tony Robbins (
Date: 03/28/01

Quoting Web Remedies Network <webremedies@HOME.COM>:

> Here's what I have so far.
> struct trainer_data {
>  int spell_num;
>  int percent;
>  int cost;
>  struct trainer_data *next;
> };
>  struct trainer_data trn_skills[MAX_SKILLS +
> 1]
> 1-> MAX_SPELLS = (all spells found in game)
> MAX_SPELLS + 1 -> MAX_SKILLS = (all skills found
> in game)
> Now for running through the structure in terms
> of *next, I was
> thinking of something along the lines of:
>  struct trainer_data *trainer_pointer = &trn_skills[MAX_SKILLS+1] - OR
>  should this be: struct trainer_data
> *trainer_pointer = &trn_skills[1]

It sounds like here you're jumping between the
semantics of linked list and array handling.
Realistically, you can use one or the other (or both),
and only really need one of them.

Since you're putting in the potential for any mob to
teach a skill, you'll likely want to save the data as
an E-Spec.

Anyway, the structure you've created is fine, but
instead of an array, you might lean toward:

struct trainer_data *train;

Then, I'd recommend saving the data as an E-Spec, which
you can look up in parse_espec.  It will take some
modification, but on loading it, you could:

struct trainer_data *new_train;

CREATE(new_train, struct trainer_data, 1);

new_train->next = mob->train_skills;
new_train->... = /* parsed values */
mob->train_skills = new_train;

By doing this, you'll only allocate as much memory as
you need, and the only difference is you'll have to
step through the list and be careful when removing
stuff from the list.  It also means that in Oasis,
using numbers in the interface won't translate as
easily to array values.  To make it a little easier to
remove stuff from the list, you might think about
adding a "struct trainer_data *prev;" and linking it
properly that way.  Then, when you go to remove
something from the list:

this_train->prev->next = this_train->next;
this_train->next->prev = this_train->prev;

Of course, a little more error checking would be

> but how does one properly link the next pointer
> for the next values when
> some trainers may have 2 spells and 1 skill to
> teach while others may
> have 30.   The reason I ask, is I want to know
> if the below is either
> a waste of time, and or memory.

See above for the most part.  What you had, would
consume extra memory for no particular reason.  For
example, realize that you created the array to the size
of MAX_SKILLS + 1, and then also included a 'spell_num'
variable.  Exercising some logic, you can realize a way
to do this without using as much information.

Anyway, if you want some more info, e-mail me directly
or continue it on the list....


   | FAQ: |
   | Archives: |

This archive was generated by hypermail 2b30 : 12/04/01 PST