Heya all... I've got a problem/question/something.... I'm coding an
empire system to put into my MUD, similar to clans. I'm going to parse
them from a file similar to a world file. Now, I've written the function
to load them, but I'm confused as to what I need to do now :) From what
I've seen, the world files, mob files, obj files, etc. all use the CREATE
macro. I want to be able to access the empires by using something
similar to an array, such as emp[GET_EMP(ch)].treasury to access the
treasury of the characters empire(that's assuming I put a struct
empire_data *emp; at the top of the function). The empire they're in is
stored as an 'int' in the pfile, and I've defined the empires as follows:
#define EMP_FED 0
#define EMP_VUL 1
#define EMP_ROM 2
#define EMP_KLI 3
#define EMP_CRD 4
#define EMP_JEM 5
#define EMP_BJR 6
#define EMP_BRG 7
#define EMP_FER 8
#define NUM_EMPS 9
How am I going to be able to access the fields of the empires similar to
how I stated above? Am I going to need to use CREATE(), malloc(), or
calloc()? I've been told no by a few people, but I just don't see how
I'm going to be able to access them. If anyone can tell me, I'd
appreciate it, and if you'd like, when I finish, I'll send it your way.
Thanks,
-Phillip
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
/Empire boot functions follows:\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
/* load the empires */
void init_empires(FILE * fl)
{
extern int top_of_p_table;
extern struct player_index_element *player_table;
struct char_file_u chdata;
int number, leaderid, members, treasury, ships, planets, p, i;
char line[256], plan[1024], allies[256], norelat[256], war[256],
name[128];
struct empire_data *emp;
if((fopen(fl, "ro")) != NULL){
for(i = 0; i < NUM_EMPS; i++){
if(sscanf(line, "#%d~", number) != 1) {
log("SYSERR: Format error in empire number: Expecting #%d~");
exit(1);
}
if(sscanf(line, "%d %s~", leaderid, name) != 1){
log("SYSERR: Format error in empire leader id/name: Expecting %d
%s~");
exit(1);
}
if(sscanf(line, "%s %s %s~", allies, norelat, war) != 1){
log("SYSERR: Format error in empire flags: Expecting %s %s %s~");
exit(1);
}
if(sscanf(line, "%s", plan) != 1){
log("SYSERR: Format error in empire plan: Expecting %s");
exit(1);
}
}
fclose(fl);
}
else {
sprintf(buf, "SYSERR: Unable to open file %s", EMP_FILE);
log(buf);
exit(1);
return;
}
emp[number].id = number;
emp[number].leader = leaderid;
emp[number].name = name;
emp[number].allies = asciiflag_conv(allies);
emp[number].norelat = asciiflag_conv(norelat);
emp[number].wars = asciiflag_conv(war);
emp[number].plan = plan;
for (p = 0; p <= top_of_p_table; p++){
load_char((player_table + p)->name, &chdata);
if(GET_EMP(chdata.player.empire) == number) {
emp[number].members++;
}
}
}
Phillip Ames | Implementor of Apocalypse MUD
kirk47@juno.com | telnet://oberon.krans.com:1701
ICQ: 8778335 | AOL IM: Grathol
http://members.xoom.com/Gowron/index.html
___________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]
+------------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
| http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
+------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST