void trigedit_setup_existing(struct descriptor_data *d, int rtrg_num) { struct trig_data *trig; struct cmdlist_element *c; /* * Allocate a scratch trigger structure */ CREATE(trig, struct trig_data, 1); trig_data_copy(trig, trig_index[rtrg_num]->proto); /* convert cmdlist to a char string */ c = trig->cmdlist; CREATE(OLC_STORAGE(d), char, MAX_CMD_LENGTH); strcpy(OLC_STORAGE(d), ""); while (c) { strcat(OLC_STORAGE(d), c->cmd); strcat(OLC_STORAGE(d), "\r\n"); c = c->next; } /* now trig->cmdlist is something to pass to the text editor */ /* it will be converted back to a real cmdlist_element list later */ OLC_TRIG(d) = trig; OLC_VAL(d) = 0; /* Has changed flag. (It hasn't so far, we just made it.) */ trigedit_disp_menu(d); }
/* copy an entire script from one holder (mob/obj/room) to another */ void script_copy(void *dst, void *src, int type) { struct script_data *s_src = NULL; struct script_data *s_dst = NULL; trig_data *t_src, *t_dst; /* find the scripts of the source and destination */ switch (type) { case MOB_TRIGGER: s_src = SCRIPT((struct char_data *)src); s_dst = SCRIPT((struct char_data *)dst); ((struct char_data *)dst)->proto_script = ((struct char_data *)src)->proto_script; break; case OBJ_TRIGGER: s_src = SCRIPT((struct obj_data *)src); s_dst = SCRIPT((struct obj_data *)dst); ((struct obj_data *)dst)->proto_script = ((struct obj_data *)src)->proto_script; break; case WLD_TRIGGER: s_src = SCRIPT((struct room_data *)src); s_dst = SCRIPT((struct room_data *)dst); ((struct room_data *)dst)->proto_script = ((struct room_data *)src)->proto_script; break; default: mlog("SYSERR: Unknown type code sent to script_copy()!"); break; } /* * make sure the dst doesnt already have a script * if it does, delete it */ if (s_dst) extract_script(s_dst); /* copy the scrip data */ s_dst->types = s_src->types; t_src = TRIGGERS(s_src); while (t_src) { CREATE(t_dst, trig_data, 1); if (!TRIGGERS(s_dst)) TRIGGERS(s_dst) = t_dst; trig_data_copy(t_dst, t_src); t_dst = t_dst->next; t_src = t_src->next; } }
/* save the zone's triggers to internal memory and to disk */ void trigedit_save(struct descriptor_data *d) { char *name=NULL; char *trgarglist=NULL; char *code=NULL; int trig_rnum, i; int found = 0; char *s; trig_data *proto; trig_data *trig = OLC_TRIG(d); trig_data *live_trig; struct cmdlist_element *cmd, *next_cmd; struct index_data **new_index; struct descriptor_data *dsc; int zone, top; char buf[MAX_CMD_LENGTH]; char bitBuf[MAX_INPUT_LENGTH]; char *trg_replace = "REPLACE INTO %s (" "znum, " "vnum, " "name, " "attach_type, " "flags, " "numarg, " "arglist, " "code) " "VALUES (%d, %d, '%s', %d, '%s', %d, '%s', '%s');"; if ((trig_rnum = real_trigger(OLC_NUM(d))) != -1) { proto = trig_index[trig_rnum]->proto; for (cmd = proto->cmdlist; cmd; cmd = next_cmd) { next_cmd = cmd->next; if (cmd->cmd) free(cmd->cmd); free(cmd); } if (proto->arglist) free(proto->arglist); if (proto->name) free(proto->name); /* Recompile the command list from the new script */ s = OLC_STORAGE(d); CREATE(trig->cmdlist, struct cmdlist_element, 1); trig->cmdlist->cmd = str_dup(strtok(s, "\n\r")); cmd = trig->cmdlist; while ((s = strtok(NULL, "\n\r"))) { CREATE(cmd->next, struct cmdlist_element, 1); cmd = cmd->next; cmd->cmd = str_dup(s); } /* make the prorotype look like what we have */ trig_data_copy(proto, trig); /* go through the mud and replace existing triggers */ live_trig = trigger_list; while (live_trig) { if (GET_TRIG_RNUM(live_trig) == trig_rnum) { if (live_trig->arglist) { free(live_trig->arglist); live_trig->arglist = NULL; } if (live_trig->name) { free(live_trig->name); live_trig->name = NULL; } if (proto->arglist) live_trig->arglist = str_dup(proto->arglist); if (proto->name) live_trig->name = str_dup(proto->name); live_trig->cmdlist = proto->cmdlist; live_trig->curr_state = live_trig->cmdlist; live_trig->trigger_type = proto->trigger_type; live_trig->attach_type = proto->attach_type; live_trig->narg = proto->narg; live_trig->data_type = proto->data_type; live_trig->depth = 0; live_trig->wait_event = NULL; if (GET_TRIG_WAIT(live_trig)) event_cancel(GET_TRIG_WAIT(live_trig)); free_varlist(live_trig->var_list); } live_trig = live_trig->next_in_world; } } else {