Actually, this is entirely possible, it just uglies up your class file a
little bit... you say you have the classes loading from an external
file, and if you have Ivan's OLC installed, you can take a look at how
they converted the social_table from a static value to a dynamic
array... basically, when the socials are saved, they take a look at how
many are currently in existence, say 157... they open the social.txt for
writing and put 157 on the first line, then all the social data
following it... later on when the mud boots, the first value it reads in
is assigned to maxSocial, and the social_table array is declared as
such:

social_table = malloc (sizeof(struct social_type) * (maxSocial+1));

thus allocating it the right amount of memory space... they say they go
maxSocial+1 to make it backward compatible, and assign the last slot's
'name' field to str_dup("");, so that you can simply loop them until
social_table[x].name[0] == '\0'...

later on, when someone creates a new social (or class in your case),
this happens:

struct social_type *new_table;

maxSocial++;
new_table = realloc (social_table, sizeof(struct social_type) *
(maxSocial + 1));

social_table = new_table;

realloc simply creates a new array of n elements (maxSocial+1 after
incrementing maxSocial to make room for the new addition), and uses
social_table in the call to place the contents of the existing
social_table into the new_table and free social_table, and then
reassigns the social_table pointer to new_table, thus giving you a new
social_table that's 1 element larger, and when it saves, it places the
new maxSocial value (158 now) at the top of the social.txt file, so it
knows how big to make the array the next time the mud is loaded...

so it should be entirely possible to copy that sort of thing and apply
it to your class_table... just declare an external maxClass value (or
MAX_CLASS if you want to save yourself some editing of the code, but
that sort of breaks convention because all caps are generally constant
values), and read in the value of it from the first line in your
class.txt (or whatever) file, create your table via malloc, and load all
the data into it from the subsequent lines of the file... you can resize
it on the fly w/ realloc, and write the new maxClass value back to the
file when you save it again...

Richard Lindsey 

-----Original Message-----
From: Tristan M [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 27, 2004 6:25 AM
To: [email protected]
Subject: changing MAX_CLASS to an external value

i think  i worded that subject correctly...anyway, what i want to do is
load 
my classes from a file. ive put together my own class editor which works

perfectly(prolly littered with memory leaks i dont kno about tho:p)
except 
that now that classes load from a file, i want to change all those 
MAX_CLASS's around to maxClass, which is set when load_class is executed

during the boot, and changed if classes are created online...so for
example 
in merc.h:

...
...
struct  skill_type
{
    char *      name;                   /* Name of skill
*/
    sh_int      skill_level[MAX_CLASS]; <--- change this to [maxClass]
    sh_int      rating[MAX_CLASS];<--- change this to [maxClass]
    SPELL_FUN * spell_fun;              /* Spell pointer (for spells)
*/
    sh_int      target;                 /* Legal targets
*/
    sh_int      minimum_position;       /* Position for caster / user
*/
...
...

so i changed the [MAX_CLASS] 's to [maxClass] just to see what would
happen 
and this came out:
rom24\src\merc.h(1838) : error C2057: expected constant expression
rom24\src\merc.h(1839) : error C2057: expected constant expression
rom24\src\merc.h(1839) : error C2229: struct 'skill_type' has an illegal

zero-sized array
rom24\src\merc.h(1840) : error C2229: struct 'skill_type' has an illegal

zero-sized array

and i probably sound like a newb asking this, but thats ok.


-- 
ROM mailing list
[email protected]
http://www.rom.org/cgi-bin/mailman/listinfo/rom

Reply via email to