On Mon, 4 Sep 2000 23:57:04 -0700, Peter Ajamian <peter@pajamian.dhs.org> wrote: >I hope you're not trying to re-invent the wheel, there's a very good >exits snippet on the developer site (I should know, I wrote it ;) ), >it's at... Heh... not reinventing the wheel, more like adding some options to it. My code allows an unlimited number of exits, that can have different names... like Tavern, Smithy... the imps wanted itto have more realistic towns and such. > >Sure you can pass references in C, show me some of the relevent code and >I'll show you how. Here's the relevant code: structs.h /* room-related structures ************************************************/ struct room_direction_data { char *general_description; /* When look DIR. */ char *keyword; /* for open/close */ sh_int /*bitvector_t*/ exit_info; /* Exit info */ obj_vnum key; /* Key's number (-1 for no key) */ room_rnum to_room; /* Where direction leads (NOWHERE) */ }; struct extra_exit_data { struct room_direction_data *exit; struct extra_exit_data *next; }; struct room_data { -snip- struct extra_exit_data *extra_exits; -snip- }; struct descriptor_data { -snip- struct room_direction_data *exit_being_worked_on; int extra_exit; }; redit.c //this was also cut from the redit_parse switch statment, it shows the prompt from any //given selection, then sets the olc mode so it will go into the right case in handle_exit_choices void handle_exit_menu(struct descriptor_data *d, char *arg) { struct room_direction_data *exit = d->exit_being_worked_on; struct extra_exit_data *exits_list = NULL, *last_exit = NULL; -snip- case '6': /* * Delete an exit. */ OLC_VAL(d) = 1; if( d->extra_exit ) { last_exit = exits_list = OLC_ROOM(d)->extra_exits; while( exits_list ) { if( exits_list->exit == exit ) { if( OLC_ROOM(d)->extra_exits == exits_list ) OLC_ROOM(d)->extra_exits = OLC_ROOM(d)->extra_exits->next; else last_exit->next = exits_list->next; break; } last_exit = exits_list; exits_list = exits_list->next; } } if (exit->keyword) free(exit->keyword); if (exit->general_description) free(exit->general_description); if (exit) { free(exit); exit = NULL; } /*This is where the actual problem lies, setting exit_being_worked_on to NULL still leaves the normal exit pointers in struct room_data pointing off into space*/ d->exit_being_worked_on = NULL; OLC_MODE(d) = REDIT_MAIN_MENU; redit_disp_menu(d); break; default: SEND_TO_Q("Try again : ", d); return; } } void redit_disp_exit_menu(struct descriptor_data *d, struct room_direction_data *exit) { /* * if exit doesn't exist, alloc/create it */ if (exit == NULL) CREATE(exit, struct room_direction_data, 1); //set exit_being_worked_on to point to whichever exit the builder has chosen d->exit_being_worked_on = exit; -snip- } void redit_parse(struct descriptor_data *d, char *arg) { -snip- case '5': OLC_VAL(d) = NORTH; d->extra_exit = 0; redit_disp_exit_menu(d, OLC_EXIT(d)); break; case '6': OLC_VAL(d) = EAST; d->extra_exit = 0; redit_disp_exit_menu(d, OLC_EXIT(d)); break; case '7': OLC_VAL(d) = SOUTH; d->extra_exit = 0; redit_disp_exit_menu(d, OLC_EXIT(d)); break; case '8': OLC_VAL(d) = WEST; d->extra_exit = 0; redit_disp_exit_menu(d, OLC_EXIT(d)); break; case '9': OLC_VAL(d) = UP; d->extra_exit = 0; redit_disp_exit_menu(d, OLC_EXIT(d)); break; case 'a': case 'A': OLC_VAL(d) = DOWN; d->extra_exit = 0; redit_disp_exit_menu(d, OLC_EXIT(d)); break; -snip- } Think that's all the stuff important to this problem. I tried passing the exit in as a reference to redit_disp_exit_menu and my compiler yelled at me, so I thought C didn't support reference parameters... Also, this is the second time I posted this... but the first tie didn't go through after like 3 hours so I'm posting it again... sorry if it ends up on there twice. +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 04/11/01 PDT