On Thu, 12 Dec 1996, Nic Suzor wrote: :just wondering, if anyone has made oasis able to edit mobprogs, or even :just save them without editing features, could they be so kind as to share :their code? i have mobprogs working, but most of my builders build offline, :and i dont want to lose all the progs when someone edits a mob... Below is the snipped sections of code that I put into my olc to incorporate mobprogs. Please notice that I have also installed the improved editor so if it doesn't seem to work please look there first. It may not be pretty, and if you improve on this please let me know. #define GET_MPROG(mob) (mob_index[(mob)->nr].mobprogs) #define GET_MPROG_TYPE(mob) (mob_index[(mob)->nr].progtypes) void medit_disp_mprog(struct descriptor_data *d); void medit_change_mprog(struct descriptor_data *d); char* medit_get_mprog_type(struct mob_prog_data *mprog); /*-------------------------------------------------------------------*\ utility functions \*-------------------------------------------------------------------*/ void medit_setup_new(struct descriptor_data *d) { struct char_data *mob; /*. Alloc some mob shaped space .*/ CREATE(mob, struct char_data, 1); CREATE(mob->mob_specials.mob_attacks, struct mob_attacks_data, 1); init_mobile(mob); mob->player_specials = &dummy_mob; GET_MOB_RNUM(mob) = -1; /*. default strings .*/ GET_ALIAS(mob) = strdup("mob unfinished"); GET_SDESC(mob) = strdup("the unfinished mob"); GET_LDESC(mob) = strdup("An unfinished mob stands here.\r\n"); GET_DDESC(mob) = strdup("It looks, err, unfinished.\r\n"); OLC_MPROGL(d) = NULL; OLC_MPROG(d)= NULL; GET_STR(mob) = 50; GET_DEX(mob) = 50; GET_AGI(mob) = 50; GET_INT(mob) = 50; GET_WIS(mob) = 50; GET_CON(mob) = 50; OLC_MOB(d) = mob; OLC_VAL(d) = 0; /*. Has changed flag .*/ medit_disp_menu(d); } /*-------------------------------------------------------------------*/ void medit_setup_existing(struct descriptor_data *d, int rmob_num) { struct char_data *mob; MPROG_DATA *temp; MPROG_DATA *head; /*. Alloc some mob shaped space .*/ CREATE(mob, struct char_data, 1); copy_mobile(mob, mob_proto + rmob_num); if (GET_MPROG(mob)) CREATE(OLC_MPROGL(d), MPROG_DATA, 1); head = OLC_MPROGL(d); for (temp = GET_MPROG(mob); temp;temp = temp->next) { OLC_MPROGL(d)->type = temp->type; OLC_MPROGL(d)->arglist = str_dup(temp->arglist); OLC_MPROGL(d)->comlist = str_dup(temp->comlist); if (temp->next) { CREATE(OLC_MPROGL(d)->next, MPROG_DATA, 1); OLC_MPROGL(d) = OLC_MPROGL(d)->next; } } OLC_MPROGL(d) = head; OLC_MPROG(d) = OLC_MPROGL(d); OLC_MOB(d) = mob; medit_disp_menu(d); } /*-------------------------------------------------------------------*/ /*. Save new/edited mob to memory .*/ #define ZCMD zone_table[zone].cmd[cmd_no] void medit_save_internally(struct descriptor_data *d) { /* ADD this bit to the end of medit_save_internally */ GET_MPROG(OLC_MOB(d)) = OLC_MPROGL(d); if (OLC_MPROGL(d)) GET_MPROG_TYPE(OLC_MOB(d)) = OLC_MPROGL(d)->type; else GET_MPROG_TYPE(OLC_MOB(d)) = 0; OLC_MPROGL(d) = NULL; } /*-------------------------------------------------------------------*/ /*. Save ALL mobiles for a zone to their .mob file, mobs are all saved in Extended format, regardless of whether they have any extended fields. Thanks to Samedi for ideas on this bit of code.*/ void medit_save_to_disk(struct descriptor_data *d) { mob_prog = mob_index[rmob_num].mobprogs; /* ADD THIS to the end of medit_save_to_disk */ /*. Deal with Mob Progs .*/ while(mob_prog) { strcpy(buf1, mob_prog->arglist); strip_string(buf1); strcpy(buf2, mob_prog->comlist); strip_string(buf2); fprintf(mob_file, "%s %s~\n%s", medit_get_mprog_type(mob_prog), buf1, buf2); mob_prog=mob_prog->next; if (!mob_prog) fprintf(mob_file, "~\n|\n"); else fprintf(mob_file, "~\n"); } } } } /*-------------------------------------------------------------------*/ /*. Get Mob Prog Type.*/ char* medit_get_mprog_type(struct mob_prog_data *mprog) { switch (mprog->type) { case IN_FILE_PROG: return ">in_file_prog"; break; case ACT_PROG: return ">act_prog"; break; case SPEECH_PROG: return ">speech_prog"; break; case RAND_PROG: return ">rand_prog"; break; case FIGHT_PROG: return ">fight_prog"; break; case HITPRCNT_PROG: return ">hitprcnt_prog"; break; case DEATH_PROG: return ">death_prog"; break; case ENTRY_PROG: return ">entry_prog"; break; case GREET_PROG: return ">greet_prog"; break; case ALL_GREET_PROG: return ">all_greet_prog"; break; case GIVE_PROG: return ">give_prog"; break; case BRIBE_PROG: return ">bribe_prog"; break; case SHOUT_PROG: return ">shout_prog"; break; case HOLLER_PROG: return ">holler_prog"; break; case TELL_PROG: return ">tell_prog"; break; case TIME_PROG: return ">time_prog"; break; } return ">UNKNOWN"; } /*-------------------------------------------------------------------*/ /*. Display Mob Progs .*/ void medit_disp_mprog(struct descriptor_data *d) { struct mob_prog_data *mprog = OLC_MPROGL(d); d->edit_number2 = 1; send_to_char("[H[J", d->character); while (mprog) { sprintf (buf, "%d) %s %s\r\n", d->edit_number2, medit_get_mprog_type(mprog), (mprog->arglist ? mprog->arglist : "NONE")); send_to_char(buf, d->character); d->edit_number2++; mprog=mprog->next; } sprintf (buf, "%d) Create New Mob Prog\r\n", d->edit_number2); send_to_char(buf, d->character); sprintf (buf, "%d) Purge Mob Prog\r\n", d->edit_number2 + 1); send_to_char(buf, d->character); send_to_char("Enter number to edit [0 to exit]: ", d->character); OLC_MODE(d) = MEDIT_MPROG; } /*-------------------------------------------------------------------*/ /*. Change Mob Progs .*/ void medit_change_mprog(struct descriptor_data *d) { send_to_char("[H[J", d->character); sprintf(buf, "1) Type: %s\r\n", medit_get_mprog_type(OLC_MPROG(d))); send_to_char(buf, d->character); sprintf(buf, "2) Args: %s\r\n", (OLC_MPROG(d)->arglist ? OLC_MPROG(d)->arglist : "NONE")); send_to_char(buf, d->character); sprintf(buf, "3) Commands:\r\n%s\r\n\r\n", (OLC_MPROG(d)->comlist ? OLC_MPROG(d)->comlist : "NONE")); send_to_char(buf, d->character); send_to_char("Enter number to edit [0 to exit]: ", d->character); OLC_MODE(d) = MEDIT_CHANGE_MPROG; } /*-------------------------------------------------------------------*/ /*. Change Mob Prog Type.*/ void medit_disp_mprog_types(struct descriptor_data *d) { int i; get_char_cols(d->character); send_to_char("[H[J", d->character); for (i = 0; i < NUM_PROGS-1; i++) { sprintf(buf, "%s%2d%s) %s\r\n", grn, i, nrm, mobprog_types[i] ); send_to_char(buf, d->character); } send_to_char("Enter mob prog type : ", d->character); OLC_MODE(d) = MEDIT_MPROG_TYPE; } /*-------------------------------------------------------------------*/ /*. Display main menu .*/ void medit_disp_menu(struct descriptor_data * d) { struct char_data *mob; mob = OLC_MOB(d); get_char_cols(d->character); /*** Add a menu option for mob progs... */ "%sP%s) Mob Progs : %s%s\r\n" OLC_MODE(d) = MEDIT_MAIN_MENU; } /************************************************************************** The GARGANTAUN event handler **************************************************************************/ void medit_parse(struct descriptor_data * d, char *arg) { int i; case 'p': case 'P': OLC_MODE(d) = MEDIT_MPROG; medit_disp_mprog(d); return; /*-------------------------------------------------------------------*/ case MEDIT_MPROG_COMLIST: /*. We should never get here .*/ cleanup_olc(d, CLEANUP_ALL); mudlog("SYSERR: OLC: medit_parse(): Reached MPROG_COMLIST case!",'G',COM_BUILDER,TRUE); break; /*-------------------------------------------------------------------*/ case MEDIT_MPROG: { i=atoi(arg); if (i == 0) medit_disp_menu(d); else if (i == d->edit_number2) { struct mob_prog_data *temp; CREATE(temp, struct mob_prog_data, 1); temp->next = OLC_MPROGL(d); temp->type = -1; temp->arglist = NULL; temp->comlist = NULL; OLC_MPROG(d) = temp; OLC_MPROGL(d) = temp; OLC_MODE(d) = MEDIT_CHANGE_MPROG; medit_change_mprog (d); } else if (i < d->edit_number2) { struct mob_prog_data *temp; int x=1; for (temp = OLC_MPROGL(d);temp && x < i;temp=temp->next) x++; OLC_MPROG(d) = temp; OLC_MODE(d) = MEDIT_CHANGE_MPROG; medit_change_mprog (d); } else if (i == d->edit_number2+1) { send_to_char ("Which mob prog do you want to purge? ", d->character); OLC_MODE(d) = MEDIT_PURGE_MPROG; } else medit_disp_menu(d); } return; case MEDIT_PURGE_MPROG: { struct mob_prog_data *temp; int x=1; i=atoi(arg); if (i <= 0 || i >= d->edit_number2) { medit_disp_mprog (d); return; } for (temp = OLC_MPROGL(d);temp && x < i;temp=temp->next) x++; OLC_MPROG(d) = temp; REMOVE_FROM_LIST(OLC_MPROG(d), OLC_MPROGL(d), next) free(OLC_MPROG(d)->arglist); free(OLC_MPROG(d)->comlist); free(OLC_MPROG(d)); OLC_MPROG(d) = NULL; OLC_VAL(d) = 1; medit_disp_mprog (d); } return; case MEDIT_CHANGE_MPROG: { i=atoi(arg); if (i == 1) medit_disp_mprog_types(d); else if (i == 2) { send_to_char ("Enter new arg list: ", d->character); OLC_MODE(d) = MEDIT_MPROG_ARGS; } else if (i == 3) { send_to_char("Enter new mob prog commands:\r\n", d->character); /*. Pass control to modify.c .*/ OLC_MODE(d) = MEDIT_MPROG_COMLIST; d->backstr = NULL; if (OLC_MPROG(d)->comlist) { SEND_TO_Q(OLC_MPROG(d)->comlist, d); d->backstr = str_dup(OLC_MPROG(d)->comlist); } d->str = &OLC_MPROG(d)->comlist; d->max_str = MAX_STRING_LENGTH; d->mail_to = 0; OLC_VAL(d) = 1; } else medit_disp_mprog(d); } return; case MEDIT_MPROG_TYPE: OLC_MPROG(d)->type = (1 << MAX(0, MIN(atoi(arg), NUM_PROGS-1))); OLC_VAL(d) = 1; medit_change_mprog(d); return; case MEDIT_MPROG_ARGS: OLC_MPROG(d)->arglist = str_dup(arg); OLC_VAL(d) = 1; medit_change_mprog(d); return; } /*. End of medit_parse() .*/ -- Dez. _____________________________ Datatimes Text DBA Contractor 749-2784 751-6400 _____________________________ +-----------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://cspo.queensu.ca/~fletcher/Circle/list_faq.html | +-----------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/18/00 PST