int save_mobiles(zone_rnum rznum) { zone_vnum vznum; FILE *mobfd; room_vnum i; mob_rnum rmob; int written; char mobfname[64], usedfname[64]; if (rznum < 0 || rznum > top_of_zone_table) { log("SYSERR: GenOLC: save_mobiles: Invalid real zone number %d. (0-%d)", rznum, top_of_zone_table); return FALSE; } vznum = zone_table[rznum].number; sprintf(mobfname, "%s%d.new", MOB_PREFIX, vznum); if ((mobfd = fopen(mobfname, "w")) == NULL) { mudlog("SYSERR: GenOLC: Cannot open mob file for writing.", BRF, LVL_GOD, TRUE); return FALSE; } for (i = vznum * 100; i <= zone_table[rznum].top; i++) { if ((rmob = real_mobile(i)) == NOBODY) continue; check_mobile_strings(&mob_proto[rmob]); if (write_mobile_record(i, &mob_proto[rmob], mobfd) < 0) log("SYSERR: GenOLC: Error writing mobile #%d.", i); } fputs("$\n", mobfd); written = ftell(mobfd); fclose(mobfd); sprintf(usedfname, "%s%d.mob", MOB_PREFIX, vznum); remove(usedfname); rename(mobfname, usedfname); remove_from_save_list(vznum, SL_MOB); log("GenOLC: '%s' saved, %d bytes written.", usedfname, written); return written; }
int save_mobiles(zone_rnum rznum) { zone_vnum vznum; FILE *mobfd; room_vnum i; mob_rnum rmob; int written; char mobfname[64], usedfname[64]; #if CIRCLE_UNSIGNED_INDEX if (rznum == NOWHERE || rznum > top_of_zone_table) { #else if (rznum < 0 || rznum > top_of_zone_table) { #endif log("SYSERR: GenOLC: save_mobiles: Invalid real zone number %d. (0-%d)", rznum, top_of_zone_table); return FALSE; } vznum = zone_table[rznum].number; snprintf(mobfname, sizeof(mobfname), "%s%d.new", MOB_PREFIX, vznum); if ((mobfd = fopen(mobfname, "w")) == NULL) { mudlog(BRF, LVL_GOD, TRUE, "SYSERR: GenOLC: Cannot open mob file for writing."); return FALSE; } for (i = genolc_zone_bottom(rznum); i <= zone_table[rznum].top; i++) { if ((rmob = real_mobile(i)) == NOBODY) continue; check_mobile_strings(&mob_proto[rmob]); if (write_mobile_record(i, &mob_proto[rmob], mobfd) < 0) log("SYSERR: GenOLC: Error writing mobile #%d.", i); } fputs("$\n", mobfd); written = ftell(mobfd); fclose(mobfd); snprintf(usedfname, sizeof(usedfname), "%s%d.mob", MOB_PREFIX, vznum); remove(usedfname); rename(mobfname, usedfname); if (in_save_list(vznum, SL_MOB)) remove_from_save_list(vznum, SL_MOB); log("GenOLC: '%s' saved, %d bytes written.", usedfname, written); return written; } int write_mobile_espec(mob_vnum mvnum, struct char_data *mob, FILE *fd) { if (GET_ATTACK(mob) != 0) fprintf(fd, "BareHandAttack: %d\n", GET_ATTACK(mob)); if (GET_STR(mob) != 11) fprintf(fd, "Str: %d\n", GET_STR(mob)); if (GET_ADD(mob) != 0) fprintf(fd, "StrAdd: %d\n", GET_ADD(mob)); if (GET_DEX(mob) != 11) fprintf(fd, "Dex: %d\n", GET_DEX(mob)); if (GET_INT(mob) != 11) fprintf(fd, "Int: %d\n", GET_INT(mob)); if (GET_WIS(mob) != 11) fprintf(fd, "Wis: %d\n", GET_WIS(mob)); if (GET_CON(mob) != 11) fprintf(fd, "Con: %d\n", GET_CON(mob)); if (GET_CHA(mob) != 11) fprintf(fd, "Cha: %d\n", GET_CHA(mob)); if (GET_SAVE(mob, SAVING_PARA) != 0) fprintf(fd, "SavingPara: %d\n", GET_SAVE(mob, SAVING_PARA)); if (GET_SAVE(mob, SAVING_ROD) != 0) fprintf(fd, "SavingRod: %d\n", GET_SAVE(mob, SAVING_ROD)); if (GET_SAVE(mob, SAVING_PETRI) != 0) fprintf(fd, "SavingPetri: %d\n", GET_SAVE(mob, SAVING_PETRI)); if (GET_SAVE(mob, SAVING_BREATH) != 0) fprintf(fd, "SavingBreath: %d\n", GET_SAVE(mob, SAVING_BREATH)); if (GET_SAVE(mob, SAVING_SPELL) != 0) fprintf(fd, "SavingSpell: %d\n", GET_SAVE(mob, SAVING_SPELL)); fputs("E\n", fd); return TRUE; } int write_mobile_record(mob_vnum mvnum, struct char_data *mob, FILE *fd) { char ldesc[MAX_STRING_LENGTH]; char ddesc[MAX_STRING_LENGTH]; char buf[MAX_STRING_LENGTH]; ldesc[MAX_STRING_LENGTH - 1] = '\0'; ddesc[MAX_STRING_LENGTH - 1] = '\0'; strip_cr(strncpy(ldesc, GET_LDESC(mob), MAX_STRING_LENGTH - 1)); strip_cr(strncpy(ddesc, GET_DDESC(mob), MAX_STRING_LENGTH - 1)); int n = snprintf(buf, MAX_STRING_LENGTH, "#%d\n" "%s%c\n" "%s%c\n" "%s%c\n" "%s%c\n", mvnum, GET_ALIAS(mob), STRING_TERMINATOR, GET_SDESC(mob), STRING_TERMINATOR, ldesc, STRING_TERMINATOR, ddesc, STRING_TERMINATOR ); if(n < MAX_STRING_LENGTH) { fprintf(fd, "%s", convert_from_tabs(buf)); fprintf(fd, "%d %d %d %d %d %d %d %d %d E\n" "%d %d %d %dd%d+%d %dd%d+%d\n", MOB_FLAGS(mob)[0], MOB_FLAGS(mob)[1], MOB_FLAGS(mob)[2], MOB_FLAGS(mob)[3], AFF_FLAGS(mob)[0], AFF_FLAGS(mob)[1], AFF_FLAGS(mob)[2], AFF_FLAGS(mob)[3], GET_ALIGNMENT(mob), GET_LEVEL(mob), 20 - GET_HITROLL(mob), GET_AC(mob) / 10, GET_HIT(mob), GET_MANA(mob), GET_MOVE(mob), GET_NDD(mob), GET_SDD(mob), GET_DAMROLL(mob)); fprintf(fd, "%d %d\n" "%d %d %d\n", GET_GOLD(mob), GET_EXP(mob), GET_POS(mob), GET_DEFAULT_POS(mob), GET_SEX(mob) ); if (write_mobile_espec(mvnum, mob, fd) < 0) log("SYSERR: GenOLC: Error writing E-specs for mobile #%d.", mvnum); script_save_to_disk(fd, mob, MOB_TRIGGER); #if CONFIG_GENOLC_MOBPROG if (write_mobile_mobprog(mvnum, mob, fd) < 0) log("SYSERR: GenOLC: Error writing MobProgs for mobile #%d.", mvnum); #endif } else { mudlog(BRF,LVL_BUILDER,TRUE, "SYSERR: Could not save mobile #%d due to size (%d > maximum of %d)", mvnum, n, MAX_STRING_LENGTH); } return TRUE; }