static D_EXIT *load_exit( lua_State *L ) { D_EXIT *e; if( !L ) return NULL; if( ( e = new_exit() ) == NULL ) return NULL; lua_pushstring( L, "name" ); lua_gettable( L, -2 ); e->name = strdup( luaL_checkstring( L, -1 ) ); lua_pop( L, 1 ); lua_pushstring( L, "desc" ); lua_gettable( L, -2 ); e->desc = strdup( luaL_checkstring( L, -1 ) ); lua_pop( L, 1 ); lua_pushstring( L, "dest" ); lua_gettable( L, -2 ); e->destVnum = (int)luaL_checknumber( L, -1 ); lua_pop( L, 1 ); lua_pushstring( L, "state" ); lua_gettable( L, -2 ); const char *state = luaL_checkstring( L, -1 ); //temporary if( !strcasecmp( state, "STATE_OPEN" ) ) e->state = STATE_OPEN; else if( !strcasecmp( state, "STATE_DOOR_OPEN" ) ) e->state = STATE_DOOR_OPEN; else if( !strcasecmp( state, "STATE_DOOR_CLOSED" ) ) e->state = STATE_DOOR_CLOSED; else if( !strcasecmp( state, "STATE_DOOR_CLOSED_LOCKED" ) ) e->state = STATE_DOOR_CLOSED_LOCKED; else if( !strcasecmp( state, "STATE_DOOR_CLOSED_BROKEN" ) ) e->state = STATE_DOOR_CLOSED_BROKEN; else if( !strcasecmp( state, "STATE_DOOR_OPEN_BROKEN" ) ) e->state = STATE_DOOR_OPEN_BROKEN; else { bug( "Error: Invalid exit state \"%s\".", state ); e->state = STATE_OPEN; //default } lua_pop( L, 1 ); return e; }
/*************************************************************************** * change_exit * * change the values of an exit ***************************************************************************/ static bool change_exit(struct char_data *ch, const char *argument, int door) { struct room_index_data *room; char command[MAX_INPUT_LENGTH]; char arg[MAX_INPUT_LENGTH]; int value; EDIT_ROOM(ch, room); /* set the exit flags - needs full argument */ if ((value = flag_value(exit_flags, argument)) != NO_FLAG) { struct room_index_data *pToRoom; int rev; if (!room->exit[door]) { send_to_char("Exit does not exist.\n\r", ch); return false; } /* this room */ TOGGLE_BIT(room->exit[door]->rs_flags, value); room->exit[door]->exit_info = room->exit[door]->rs_flags; /* connected room */ pToRoom = room->exit[door]->u1.to_room; rev = rev_dir[door]; if (pToRoom->exit[rev] != NULL) { pToRoom->exit[rev]->rs_flags = room->exit[door]->rs_flags; pToRoom->exit[rev]->exit_info = room->exit[door]->exit_info; } send_to_char("Exit flag toggled.\n\r", ch); return true; } /* parse the arguments */ argument = one_argument(argument, command); one_argument(argument, arg); if (command[0] == '\0' && argument[0] == '\0') { move_char(ch, door, true); return false; } if (command[0] == '?') { show_help(ch->desc, "OLC_EXIT", NULL); return false; } if (!str_cmp(command, "delete")) { struct room_index_data *pToRoom; int rev; if (!room->exit[door]) { send_to_char("REdit: Cannot delete a null exit.\n\r", ch); return false; } /* remove ToRoom exit */ rev = rev_dir[door]; pToRoom = room->exit[door]->u1.to_room; if (pToRoom->exit[rev]) { free_exit(pToRoom->exit[rev]); pToRoom->exit[rev] = NULL; } /* remove this exit */ free_exit(room->exit[door]); room->exit[door] = NULL; send_to_char("Exit unlinked.\n\r", ch); return true; } if (!str_cmp(command, "link")) { struct exit_data *pExit; struct room_index_data *toRoom; if (arg[0] == '\0' || !is_number(arg)) { send_to_char("Syntax: [direction] link [vnum]\n\r", ch); return false; } value = parse_int(arg); if (!(toRoom = get_room_index(value))) { send_to_char("REdit: Cannot link to non-existant room.\n\r", ch); return false; } if (!IS_BUILDER(ch, toRoom->area)) { send_to_char("REdit: Cannot link to that area.\n\r", ch); return false; } if (toRoom->exit[rev_dir[door]]) { send_to_char("REdit: Remote side's exit already exists.\n\r", ch); return false; } if (!room->exit[door]) room->exit[door] = new_exit(); room->exit[door]->u1.to_room = toRoom; room->exit[door]->orig_door = door; door = rev_dir[door]; pExit = new_exit(); pExit->u1.to_room = room; pExit->orig_door = door; toRoom->exit[door] = pExit; send_to_char("Two-way link established.\n\r", ch); return true; } if (!str_cmp(command, "dig")) { char buf[MAX_STRING_LENGTH]; if (arg[0] == '\0' || !is_number(arg)) { send_to_char("Syntax: [direction] dig <vnum>\n\r", ch); return false; } redit_create(ch, arg); sprintf(buf, "link %s", arg); change_exit(ch, buf, door); return true; } if (!str_cmp(command, "room")) { struct room_index_data *toRoom; if (arg[0] == '\0' || !is_number(arg)) { send_to_char("Syntax: [direction] room [vnum]\n\r", ch); return false; } value = parse_int(arg); if (!(toRoom = get_room_index(value))) { send_to_char("REdit: Cannot link to non-existant room.\n\r", ch); return false; } if (!room->exit[door]) room->exit[door] = new_exit(); room->exit[door]->u1.to_room = toRoom; room->exit[door]->orig_door = door; send_to_char("One-way link established.\n\r", ch); return true; } if (!str_cmp(command, "key")) { struct objectprototype *key; if (arg[0] == '\0' || !is_number(arg)) { send_to_char("Syntax: [direction] key [vnum]\n\r", ch); return false; } if (!room->exit[door]) { send_to_char("Exit does not exist.\n\r", ch); return false; } value = parse_int(arg); if (!(key = objectprototype_getbyvnum(value))) { send_to_char("REdit: Key doesn't exist.\n\r", ch); return false; } if (key->item_type != ITEM_KEY) { send_to_char("REdit: Object is not a key.\n\r", ch); return false; } room->exit[door]->key = value; send_to_char("Exit key set.\n\r", ch); return true; } if (!str_cmp(command, "name")) { if (arg[0] == '\0') { send_to_char("Syntax: [direction] name [string]\n\r", ch); send_to_char(" [direction] name none\n\r", ch); return false; } if (!room->exit[door]) { send_to_char("Exit does not exist.\n\r", ch); return false; } free_string(room->exit[door]->keyword); if (str_cmp(arg, "none")) room->exit[door]->keyword = str_dup(arg); else room->exit[door]->keyword = str_dup(""); send_to_char("Exit name set.\n\r", ch); return true; } if (!str_prefix(command, "description")) { if (arg[0] == '\0') { if (!room->exit[door]) { send_to_char("Exit does not exist.\n\r", ch); return false; } string_append(ch, &room->exit[door]->description); return true; } send_to_char("Syntax: [direction] desc\n\r", ch); return false; } return false; }
// Added by SinaC 2003 for Circle style void load_room_circle( FILE *fp ) { ROOM_INDEX_DATA *pRoomIndex; log_stringf(" ROOMS"); if ( area_last == NULL ) { bug( "Load_room_circle: no #AREA seen yet."); exit( 1 ); } for ( ; ; ) { int vnum; char letter; int door; int iHash; char *ln; int x1, x2, x3, x4, x5, x6; letter = fread_letter( fp ); if ( letter != '#' ) { bug( "Load_room_circle: # not found."); exit( 1 ); } vnum = fread_number( fp ); if ( vnum == 0 ) break; fBootDb = FALSE; if ( get_room_index( vnum ) != NULL ) { bug( "Load_room_circle: vnum %d duplicated.", vnum ); exit( 1 ); } fBootDb = TRUE; // pRoomIndex = (ROOM_INDEX_DATA *) alloc_perm( sizeof(*pRoomIndex) ); pRoomIndex = new_room_index(); pRoomIndex->guild = 0; /* Not a guild */ pRoomIndex->owner = str_dup(""); pRoomIndex->people = NULL; pRoomIndex->contents = NULL; pRoomIndex->extra_descr = NULL; pRoomIndex->area = area_last; pRoomIndex->vnum = vnum; pRoomIndex->name = fread_string( fp ); pRoomIndex->description = fread_string( fp ); /* Area number */ fread_number( fp ); pRoomIndex->bstat(flags) = fread_flag_circle(fp); pRoomIndex->bstat(sector) = fread_number(fp); pRoomIndex->bstat(maxsize) = SIZE_NOSIZE; pRoomIndex->bstat(light) = 0; for ( door = 0; door < MAX_DIR; door++ ) // Modified by SinaC 2003 pRoomIndex->exit[door] = NULL; // Modified by SinaC 2003 /* defaults */ pRoomIndex->bstat(healrate) = 100; pRoomIndex->bstat(manarate) = 100; // Added by SinaC 2003 for mental user pRoomIndex->bstat(psprate) = 100; for ( ; ; ) { EXIT_DATA *pexit; int locks; EXTRA_DESCR_DATA *ed; letter = fread_letter( fp ); if ( letter == 'S' ) break; switch ( letter ) { case 'D' : door = fread_number( fp ); if ( door < 0 || door >= MAX_DIR ) { // Modified by SinaC 2003 bug( "Load_room_circle: vnum %d has bad door number.", vnum ); exit( 1 ); } if ( door == DIR_SPECIAL ) log_stringf("DIR_SPECIAL found for room vnum: %d.", vnum ); // pexit = (EXIT_DATA *) alloc_perm( sizeof(*pexit) ); pexit = new_exit(); pexit->description = fread_string( fp ); pexit->keyword = fread_string( fp ); pexit->exit_info = 0; pexit->rs_flags = 0; /* OLC */ locks = fread_number(fp); pexit->key = fread_number(fp); pexit->u1.vnum = fread_number(fp); pexit->orig_door = door; /* OLC */ switch ( locks ) { case 1: pexit->exit_info = pexit->rs_flags = EX_ISDOOR; break; case 2: pexit->exit_info = pexit->rs_flags = EX_ISDOOR | EX_PICKPROOF; break; default: pexit->exit_info = pexit->rs_flags = locks; break; } convert_exit_circle(pexit); // SinaC 2003 if ( IS_SET( pexit->exit_info, EX_CLIMB ) ) log_stringf("Room [%d], exit [%d] has CLIMB flag.", vnum, door ); pRoomIndex->exit[door] = pexit; pRoomIndex->old_exit[door] = pexit; break; case 'E' : // ed = (EXTRA_DESCR_DATA *) alloc_perm( sizeof(*ed) ); ed = new_extra_descr(); ed->keyword = fread_string( fp ); ed->description = fread_string( fp ); ed->next = pRoomIndex->extra_descr; pRoomIndex->extra_descr = ed; break; default : bug( "Load_room_circle: vnum %d has unknown flag.", vnum ); exit( 1 ); } } while (1) { letter = fread_letter( fp ); if ( letter == 'T' ) { // Script int scriptVnum = fread_number( fp ); char buf[MAX_STRING_LENGTH]; sprintf( buf, "room%d", scriptVnum ); pRoomIndex->program = hash_get_prog(buf); if (!pRoomIndex->program) bug("Can't find program for room vnum %d.", pRoomIndex->vnum); else { if ( get_root_class( pRoomIndex->program ) != default_room_class ) { bug("program for mob vnum %d is not a room program.", pRoomIndex->vnum); pRoomIndex->program = NULL; } else if ( pRoomIndex->program->isAbstract ) bug("program for room vnum %d is an ABSTRACT class.", pRoomIndex->vnum ); } } else { ungetc(letter,fp); break; } } convert_room_circle(pRoomIndex); iHash = vnum % MAX_KEY_HASH; pRoomIndex->next = room_index_hash[iHash]; room_index_hash[iHash] = pRoomIndex; top_vnum_room = top_vnum_room < vnum ? vnum : top_vnum_room; /* OLC */ assign_area_vnum( vnum ); /* OLC */ } return; }
void exits_editor(Client *conn, const char *argument) { char arg[100]; argument = one_argument(argument, arg); if (!str_prefix(arg, "show")) { conn->editing->show(conn); return; } if (!str_cmp(arg, "Q")) { finish_editing(conn); return; } Exit **exits = (Exit **) conn->editing->data; if (!str_cmp(arg, "A") || !str_prefix(arg, "create")) { if (!argument || !*argument) { xwriteln(conn, "~CCreate an exit in which direction?~x"); return; } long dir = value_lookup(direction_table, argument); if (dir == -1) { xwritelnf(conn, "~C'%s' is not a valid direction.~x", argument); return; } if (exits[dir] != 0) { xwriteln(conn, "~CThere is already an exit in that direction.~x"); return; } exits[dir] = new_exit(); exits[dir]->fromRoom = (Room *) conn->editing->next->data; Editor *edit = build_exit_editor(exits[dir]); edit->next = conn->editing; conn->editing = edit; conn->editing->show(conn); return; } if (!str_cmp(arg, "D") || !str_prefix(arg, "delete")) { if (!argument || !*argument) { xwriteln(conn, "~CCreate an exit in which direction?~x"); return; } const Lookup *dir; int count = 0; int num = atoi(argument); for (dir = direction_table; dir->name != 0; dir++) { if (exits[dir->value] != 0) { count++; } if ((num != 0 && num == count) || !str_prefix(argument, dir->name)) { break; } } if (dir->name == 0) { xwritelnf(conn, "~C'%s' is not a valid direction.~x", argument); return; } if (exits[dir->value] == 0) { xwriteln(conn, "~CThere is no exit in that direction.~x"); return; } destroy_exit(exits[dir->value]); exits[dir->value] = 0; conn->editing->show(conn); return; } if (!str_cmp(arg, "E") || !str_prefix(arg, "edit")) { if (!argument || !*argument) { xwriteln(conn, "~CWhich direction do you wish to edit?~x"); return; } int count = 0; const Lookup *dir; int num = atoi(argument); for (dir = direction_table; dir->name != 0; dir++) { if (exits[dir->value] != 0) { count++; } if ((num != 0 && num == count) || !str_prefix(argument, dir->name)) { break; } } if (dir->name == 0) { xwritelnf(conn, "~C'%s' is not a valid direction.~x", argument); return; } if (exits[dir->value] == 0) { xwriteln(conn, "~CThere is no exit in that direction.~x"); return; } Editor *ed = build_exit_editor(exits[dir->value]); ed->next = conn->editing; conn->editing = ed; conn->editing->show(conn); return; } }