/** * @file room.c * @ingroup zone * * Room based code * * @author Geoff Davis <geoff@circlemudsquared.org> * @author Greg Buxton <greg@circlemudsquared.org> * * @par Copyright: * Copyright (C) 2006 Geoff Davis <geoff@circlemudsquared.org><br> * Greg Buxton <greg@circlemudsquared.org> * * @par * Copyright (C) 1993, 94 by the Trustees of the Johns Hopkins University<br> * CircleMUD is based on DikuMUD, Copyright (C) 1990, 1991. * * @par * All rights reserved. See license.doc for complete information. * * @package cs * @version 1.0 */ #define __ROOM_C__ #include "sysdep.h" #include "structs.h" #include "utils.h" #include "dao.h" #include "db.h" #include "interpreter.h" #include "main.h" #include "extraDesc.h" #include "room.h" #include "zone.h" /* * Included here */ /* cardinal directions */ const char *dirs[] = { /* 0 */ "north", /* 1 */ "east", /* 2 */ "south", /* 3 */ "west", /* 4 */ "up", /* 5 */ "down", "\n" }; /* SECT_ */ const char *sector_types[] = { /* 00 */ "Inside", /* 01 */ "City", /* 02 */ "Field", /* 03 */ "Forest", /* 04 */ "Hills", /* 05 */ "Mountains", /* 06 */ "WaterSwimmable", /* 07 */ "WaterNotSwimmable", /* 08 */ "InFlight", /* 09 */ "Underwater", "\n" }; int zoneNum_forVnum(int vnum); /** * Convert a room exit to its DAO representation. * @param parentDao the container DAO to contain the exit's DAO * @param exit the room exit to be converted * @return none */ void exitData_toDao(daoData_t *parentDao, int dir, struct room_direction_data *exit) { if (parentDao == NULL) { log("exitData_toDao(): invalid 'parentDao' daoData_t."); } else if (dir < 0 || dir >= NUM_OF_DIRS) { log("exitData_toDao(): invalid 'dir' value %d.", dir); } else if (exit == NULL) { log("exitData_toDao(): invalid 'exit' struct room_direction_data."); } else { /* Declare some working DAO pointers. */ daoData_t *exitDao = NULL, *subContainerDao = NULL; /* Create a container for the room exit. */ exitDao = dao_newChild(parentDao, dirs[dir]); if (exit->general_description && *(exit->general_description) != '\0') { /* Create the description scalar DAO. */ dao_newScalar(exitDao, "description", "%s", exit->general_description); } if (exit->to_room != NOWHERE) { /* Create the destination room scalar DAO. */ dao_newScalar(exitDao, "destinationRoom", "%s:%d", zone_table[(world[exit->to_room].zone)].keyword, world[exit->to_room].number); } if (exit->exit_info != 0) { /* Create the exit flags scalar DAO. */ subContainerDao = dao_newChild(exitDao, "flags"); dao_newScalar(subContainerDao, "closed", "%s", YESNO(EXIT_FLAGGED(exit, EX_CLOSED))); dao_newScalar(subContainerDao, "door", "%s", YESNO(EXIT_FLAGGED(exit, EX_ISDOOR))); dao_newScalar(subContainerDao, "locked", "%s", YESNO(EXIT_FLAGGED(exit, EX_LOCKED))); dao_newScalar(subContainerDao, "pickproof", "%s", YESNO(EXIT_FLAGGED(exit, EX_PICKPROOF))); } if (exit->key != NOTHING) { /* Create the key scalar DAO. */ dao_newScalar(exitDao, "key", "%s:%d", zone_table[zoneNum_forVnum(exit->key)].keyword, exit->key); } if (exit->keyword && *(exit->keyword) != '\0') { /* Create the exit keywords scalar DAO. */ dao_newScalar(exitDao, "keywords", "%s", exit->keyword); } } } /** * Convert a room to its DAO representation. * @param parentDao the container DAO to contain the room's DAO * @param room the room to be converted * @return none */ void roomData_toDao(daoData_t *parentDao, struct room_data *room) { if (parentDao == NULL) { log("roomData_toDao(): invalid 'parentDao' daoData_t."); } else if (room == NULL) { log("roomData_toDao(): invalid 'room' struct room_data."); } else { char temp[MAX_INPUT_LENGTH]; /* Declare an iterator variable. */ register int n = 0; /* Declare some working DAO pointers. */ daoData_t *roomDao = NULL, *subContainerDao = NULL; roomDao = dao_newChild(parentDao, "%d", room->number); dao_newScalar(roomDao, "name", "%s", room->name); dao_newScalar(roomDao, "description", "%s", room->description); sprinttype(room->sector_type, sector_types, temp, sizeof(temp)); dao_newScalar(roomDao, "sectorType", "%s", temp); if (room->room_flags != 0UL) { subContainerDao = dao_newChild(roomDao, "flags"); dao_newScalar(subContainerDao, "dark", "%s", YESNO(IS_SET(room->room_flags, ROOM_DARK))); dao_newScalar(subContainerDao, "death", "%s", YESNO(IS_SET(room->room_flags, ROOM_DEATH))); dao_newScalar(subContainerDao, "noMob", "%s", YESNO(IS_SET(room->room_flags, ROOM_NOMOB))); dao_newScalar(subContainerDao, "indoors", "%s", YESNO(IS_SET(room->room_flags, ROOM_INDOORS))); dao_newScalar(subContainerDao, "peaceful", "%s", YESNO(IS_SET(room->room_flags, ROOM_PEACEFUL))); dao_newScalar(subContainerDao, "soundproof", "%s", YESNO(IS_SET(room->room_flags, ROOM_SOUNDPROOF))); dao_newScalar(subContainerDao, "noTrack", "%s", YESNO(IS_SET(room->room_flags, ROOM_NOTRACK))); dao_newScalar(subContainerDao, "noMagic", "%s", YESNO(IS_SET(room->room_flags, ROOM_NOMAGIC))); dao_newScalar(subContainerDao, "tunnel", "%s", YESNO(IS_SET(room->room_flags, ROOM_TUNNEL))); dao_newScalar(subContainerDao, "private", "%s", YESNO(IS_SET(room->room_flags, ROOM_PRIVATE))); dao_newScalar(subContainerDao, "wizRoom", "%s", YESNO(IS_SET(room->room_flags, ROOM_GODROOM))); dao_newScalar(subContainerDao, "house", "%s", YESNO(IS_SET(room->room_flags, ROOM_HOUSE))); dao_newScalar(subContainerDao, "houseCrash", "%s", YESNO(IS_SET(room->room_flags, ROOM_HOUSE_CRASH))); dao_newScalar(subContainerDao, "atrium", "%s", YESNO(IS_SET(room->room_flags, ROOM_ATRIUM))); dao_newScalar(subContainerDao, "olc", "%s", YESNO(IS_SET(room->room_flags, ROOM_OLC))); } /* Save the extraDescriptions if there are any */ if (room->ex_description != NULL) { extraDescData_listToDao(roomDao, room->ex_description); } /* Reset the subcontainer DAO to NULL. */ subContainerDao = NULL; /* Iterate over the exit array. */ for (n = 0; n < NUM_OF_DIRS; n++) { /* Skip directions for which there is no option. */ if (room->dir_option[n] == NULL) { continue; } if (subContainerDao == NULL) { /* Allocate the 'exitList' container DAO, if necessary. */ subContainerDao = dao_newChild(roomDao, "exits"); } /* Convert each exit to its DAO representation. */ exitData_toDao(subContainerDao, n, room->dir_option[n]); } } }