void ft_free_map(t_map map) { map.room = free_room(map.room); map.pipes = free_pipes(map.pipes); free(map.room); free(map.pipes); }
t_room *free_room(t_room *room) { t_room *tmp; if (room == NULL) return (NULL); else { tmp = room->next; free(room->name); free(room); return (free_room(tmp)); } }
/* This procedure frees up the strings and/or the structures attatched to a * descriptor, sets all flags back to how they should be. */ void cleanup_olc(struct descriptor_data *d, byte cleanup_type) { /* Clean up WHAT? */ if (d->olc == NULL) return; /* Check for a room. free_room doesn't perform sanity checks, we must be * careful here. */ if (OLC_ROOM(d)) { switch (cleanup_type) { case CLEANUP_ALL: /* free(OLC_SCRIPT(d)) equivalent */ free_proto_script(OLC_ROOM(d), WLD_TRIGGER); free_room(OLC_ROOM(d)); break; case CLEANUP_STRUCTS: free(OLC_ROOM(d)); break; case CLEANUP_CONFIG: free_config(OLC_CONFIG(d)); break; default: /* The caller has screwed up. */ log("SYSERR: cleanup_olc: Unknown type!"); break; } } /* Check for an existing object in the OLC. The strings aren't part of the * prototype any longer. They get added with strdup(). */ if (OLC_OBJ(d)) { free_object_strings(OLC_OBJ(d)); free(OLC_OBJ(d)); } /* Check for a mob. free_mobile() makes sure strings are not in the * prototype. */ if (OLC_MOB(d)) free_mobile(OLC_MOB(d)); /* Check for a zone. cleanup_type is irrelevant here, free() everything. */ if (OLC_ZONE(d)) { if (OLC_ZONE(d)->builders) free(OLC_ZONE(d)->builders); if (OLC_ZONE(d)->name) free(OLC_ZONE(d)->name); if (OLC_ZONE(d)->cmd) free(OLC_ZONE(d)->cmd); free(OLC_ZONE(d)); } /* Check for a shop. free_shop doesn't perform sanity checks, we must be * careful here. OLC_SHOP(d) is a _copy_ - no pointers to the original. Just * go ahead and free it all. */ if (OLC_SHOP(d)) free_shop(OLC_SHOP(d)); /* Check for a quest. */ if (OLC_QUEST(d)) { switch (cleanup_type) { case CLEANUP_ALL: free_quest(OLC_QUEST(d)); break; case CLEANUP_STRUCTS: free(OLC_QUEST(d)); break; default: break; } } /*. Check for aedit stuff -- M. Scott */ if (OLC_ACTION(d)) { switch(cleanup_type) { case CLEANUP_ALL: free_action(OLC_ACTION(d)); break; case CLEANUP_STRUCTS: free(OLC_ACTION(d)); break; default: /* Caller has screwed up */ break; } } /* Used for cleanup of Hedit */ if (OLC_HELP(d)) { switch(cleanup_type) { case CLEANUP_ALL: free_help(OLC_HELP(d)); break; case CLEANUP_STRUCTS: free(OLC_HELP(d)); break; default: break; } } if (OLC_IBT(d)) { free_olc_ibt(OLC_IBT(d)); OLC_IBT(d) = NULL; } if (OLC_MSG_LIST(d)) { free_message_list(OLC_MSG_LIST(d)); OLC_MSG_LIST(d) = NULL; OLC_MSG(d) = NULL; } /* Free storage if allocated (tedit, aedit, and trigedit). This is the command * list - it's been copied to disk already, so just free it -Welcor. */ if (OLC_STORAGE(d)) { free(OLC_STORAGE(d)); OLC_STORAGE(d) = NULL; } /* Free this one regardless. If we've left olc, we've either made a fresh * copy of it in the trig index, or we lost connection. Either way, we need * to get rid of this. */ if (OLC_TRIG(d)) { free_trigger(OLC_TRIG(d)); OLC_TRIG(d) = NULL; } /* Free this one regardless. If we've left olc, we've either copied the * * preferences to the player, or we lost connection. Either way, we need * * to get rid of this. */ if(OLC_PREFS(d)) { /*. There is nothing else really to free, except this... .*/ free(OLC_PREFS(d)); OLC_PREFS(d) = NULL; } /* OLC_SCRIPT is always set as trig_proto of OLC_OBJ/MOB/ROOM. Therefore it * should not be free'd here. */ /* Restore descriptor playing status. */ if (d->character) { REMOVE_BIT_AR(PLR_FLAGS(d->character), PLR_WRITING); act("$n stops using OLC.", TRUE, d->character, NULL, NULL, TO_ROOM); if (cleanup_type == CLEANUP_CONFIG) mudlog(BRF, ADMLVL_IMMORT, TRUE, "OLC: %s stops editing the game configuration", GET_NAME(d->character)); else if (STATE(d) == CON_TEDIT) mudlog(BRF, ADMLVL_IMMORT, TRUE, "OLC: %s stops editing text files.", GET_NAME(d->character)); else if (STATE(d) == CON_HEDIT) mudlog(CMP, ADMLVL_IMMORT, TRUE, "OLC: %s stops editing help files.", GET_NAME(d->character)); else mudlog(CMP, ADMLVL_IMMORT, TRUE, "OLC: %s stops editing zone %d allowed zone %d", GET_NAME(d->character), zone_table[OLC_ZNUM(d)].number, GET_OLC_ZONE(d->character)); STATE(d) = CON_PLAYING; } free(d->olc); d->olc = NULL; }
/* * This procedure frees up the strings and/or the structures * attatched to a descriptor, sets all flags back to how they * should be. */ void cleanup_olc(struct descriptor_data *d, byte cleanup_type) { /* * Clean up WHAT? */ if (d->olc == NULL) return; /* * Check for a room. free_room doesn't perform * sanity checks, we must be careful here. */ if (OLC_ROOM(d)) { switch (cleanup_type) { case CLEANUP_ALL: free_room(OLC_ROOM(d)); break; case CLEANUP_STRUCTS: free(OLC_ROOM(d)); break; default: /* The caller has screwed up. */ log("SYSERR: cleanup_olc: Unknown type!"); break; } } /* * Check for an existing object in the OLC. The strings * aren't part of the prototype any longer. They get added * with strdup(). */ if (OLC_OBJ(d)) { free_object_strings(OLC_OBJ(d)); free(OLC_OBJ(d)); } /* * Check for a mob. free_mobile() makes sure strings are not in * the prototype. */ if (OLC_MOB(d)) free_mobile(OLC_MOB(d)); /* * Check for a zone. cleanup_type is irrelevant here, free() everything. */ if (OLC_ZONE(d)) { free(OLC_ZONE(d)->name); free(OLC_ZONE(d)->cmd); free(OLC_ZONE(d)); } /* * Check for a shop. free_shop doesn't perform sanity checks, we must * be careful here. */ if (OLC_SHOP(d)) { switch (cleanup_type) { case CLEANUP_ALL: free_shop(OLC_SHOP(d)); break; case CLEANUP_STRUCTS: free(OLC_SHOP(d)); break; default: /* The caller has screwed up but we already griped above. */ break; } } /* Triggers */ #if 0 /* * this is the command list - it's been copied to disk already, * so just free it -- Welcor */ if (OLC_STORAGE(d)) { free(OLC_STORAGE(d)); OLC_STORAGE(d) = NULL; } /* * Free this one regardless. If we've left olc, we've either made * a fresh copy of it in the trig index, or we lost connection. * Either way, we need to get rid of this. */ if (OLC_TRIG(d)) { free_trigger(OLC_TRIG(d)); OLC_STORAGE(d) = NULL; } #endif /* * Restore descriptor playing status. */ if (d->character) { REMOVE_BIT_AR(PLR_FLAGS(d->character), PLR_WRITING); STATE(d) = CON_PLAYING; act("$n stops using OLC.", TRUE, d->character, NULL, NULL, TO_ROOM); mudlog(CMP, LVL_IMMORT, TRUE, "OLC: %s stops editing zone %d allowed zone %d", GET_NAME(d->character), zone_table[OLC_ZNUM(d)].number, GET_OLC_ZONE(d->character)); } free(d->olc); d->olc = NULL; }
/************************************************************************\ ** Description : ** ** Removes a room from memory, updates the world list, and moves ** ** all of the objects, mobiles, and players to the void. ** ** ** ** Return Value: ** ** TRUE if successful...otherwise, FALSE. ** ** ** ** Parameters : ** ** rnum : The real number of the room requested to delete. ** \************************************************************************/ int remove_room_from_memory(room_rnum rnum) { struct char_data *tch; struct obj_data *obj; struct room_data *room; int i, j; if (rnum <= 0 || rnum > top_of_world) return FALSE; room = &world[rnum]; add_to_save_list(zone_table[room->zone].number, SL_WLD); log("GenOLC: delete_room: Deleting room #%d (%s).", room->number, room->name); /* * Dump the contents of this room into the void. We could also just * exract the people, mobs, and objects here. */ for (obj = world[rnum].contents; obj; obj = obj->next_content) { obj_from_room(obj); obj_to_room(obj, 0); } for (tch = world[rnum].people; tch; tch = tch->next_in_room) { char_from_room(tch); char_to_room(tch, 0); } free_room(room); /* * Change any exit going to this room to go to the void. This way, * the builders know when they type show errors. */ for (i = top_of_world; i >= 0; i--) for (j = 0; j < NUM_OF_DIRS; j++) if (W_EXIT(i, j) == NULL) continue; else if (W_EXIT(i, j)->to_room > rnum) W_EXIT(i, j)->to_room--; else if (W_EXIT(i, j)->to_room == rnum) W_EXIT(i, j)->to_room = 0; /* * Find what zone the room was in so we can update the loading table. */ for (i = 0; i <= top_of_zone_table; i++) for (j = 0; ZCMD(i, j).command != 'S'; j++) switch (ZCMD(i, j).command) { case 'M': case 'O': if (ZCMD(i, j).arg3 == rnum) ZCMD(i, j).command = '*'; /* Cancel Command */ else if (ZCMD(i, j).arg3 > rnum) ZCMD(i, j).arg3--; break; case 'D': case 'R': if (ZCMD(i, j).arg1 == rnum) ZCMD(i, j).command = '*'; /* Cancel Command */ else if (ZCMD(i, j).arg1 > rnum) ZCMD(i, j).arg1--; break; case 'G': case 'P': case 'E': case '*': /* Known zone entries we don't use here. */ break; default: mudlog(BRF, LVL_GOD, TRUE, "SYSERR: GenOLC: delete_room: Unknown zone entry found!"); } /* * Now we actually move the rooms down. */ for (i = rnum; i < top_of_world; i++) { world[i] = world[i + 1]; for (tch = world[i].people; tch; tch = tch->next_in_room) IN_ROOM(tch) -= (IN_ROOM(tch) != NOWHERE); /* Redundant Check? */ for (obj = world[i].contents; obj; obj = obj->next_content) IN_ROOM(obj) -= (IN_ROOM(obj) != NOWHERE); } top_of_world--; RECREATE(world, struct room_data, top_of_world + 1); return (TRUE); }