Welcome to the Builder Academy

Question Redid parse_simple_mobile

More
30 Jun 2016 02:26 - 30 Jun 2016 02:27 #6047 by Liko
Hello,
I redid parse_simple_mobile to be like how objects handles obj files. This should allow adding new stats and stuff easier.
Code:
static void parse_simple_mob(FILE *mob_f, int i, int nr) { int j, t[10], retval; char line[READ_SIZE]; mob_proto[i].real_abils.str = 11; mob_proto[i].real_abils.intel = 11; mob_proto[i].real_abils.wis = 11; mob_proto[i].real_abils.dex = 11; mob_proto[i].real_abils.con = 11; mob_proto[i].real_abils.cha = 11; if (!get_line(mob_f, line)) { log("SYSERR: Format error in mob #%d, file ended after S flag!", nr); exit(1); } if ((retval = sscanf(line, " %d %d %d %dd%d+%d %dd%d+%d ", t, t + 1, t + 2, t + 3, t + 4, t + 5, t + 6, t + 7, t + 8)) != 9) { if (retval == 7) { t[7] = 0; t[8] = 0; } else if (retval == 8) t[8] = 0; else { log("SYSERR: Format error in mob #%d, first line after S flag. Expecting 8 args, but has %d.", nr, retval); exit(1); } } GET_LEVEL(mob_proto + i) = t[0]; GET_HITROLL(mob_proto + i) = 20 - t[1]; GET_AC(mob_proto + i) = 10 * t[2]; /* max hit = 0 is a flag that H, M, V is xdy+z */ GET_MAX_HIT(mob_proto + i) = 0; GET_HIT(mob_proto + i) = t[3]; GET_MANA(mob_proto + i) = t[4]; GET_MOVE(mob_proto + i) = t[5]; GET_MAX_MANA(mob_proto + i) = 10; GET_MAX_MOVE(mob_proto + i) = 50; mob_proto[i].mob_specials.damnodice = t[6]; mob_proto[i].mob_specials.damsizedice = t[7]; GET_DAMROLL(mob_proto + i) = t[8]; if (!get_line(mob_f, line)) { log("SYSERR: Format error in mob #%d, second line after S flag\n" "...expecting line of form '# #', but file ended!", nr); exit(1); } if((retval = sscanf(line, " %d %d ", t, t + 1)) != 2) { if(retval == 0) { t[0] = 0; } else if(retval == 1) { t[0] = 0; t[1] = 0; } else { log("SYSERR: Format error in mob #%d, third line after S flag\n" "...expecting 2 arguments, but has %d", nr, retval); exit(1); } } GET_GOLD(mob_proto + i) = t[0]; GET_EXP(mob_proto + i) = t[1]; if (!get_line(mob_f, line)) { log("SYSERR: Format error in last line of mob #%d\n" "...expecting line of form '# # #', but file ended!", nr); exit(1); } if((retval = sscanf(line, " %d %d %d %lli ", t, t + 1, t + 2)) != 3) { if(retval == 0) { t[0] = 0; } else if(retval == 1) { t[0] = 0; t[1] = 0; } else if(retval == 2) { t[1] = 0; t[2] = 0; } else { log("SYSERR: Format error in mob #%d, third line after S flag\n" "...expecting 3 arguments, but has %d", nr, retval); exit(1); } } GET_POS(mob_proto + i) = t[0]; GET_DEFAULT_POS(mob_proto + i) = t[1]; GET_SEX(mob_proto + i) = t[2]; GET_CLASS(mob_proto + i) = 0; GET_WEIGHT(mob_proto + i) = 200; GET_HEIGHT(mob_proto + i) = 198; /* These are now save applies; base save numbers for MOBs are now from the * warrior save table. */ for (j = 0; j < NUM_OF_SAVING_THROWS; j++) GET_SAVE(mob_proto + i, j) = 0; }

This should work right out of the box.

Enjoy - Liko

Randian(0.0.0)
Owner/Developer
Last edit: 30 Jun 2016 02:27 by Liko.
The following user(s) said Thank You: thomas

Please Log in or Create an account to join the conversation.

Time to create page: 0.192 seconds