コード例 #1
0
ファイル: table_info.cpp プロジェクト: lijianping/repast
/*
 * 说明:
 *     根据楼层名,初始化房间下拉列表,先该楼层下的房间信息
 * 参数:
 *    hwnd [in] 父窗口句柄
 *    floor_name [in] 楼层名称
 *    id   [in] 下拉列表的编号
 * 返回值:
 *    成功返回true,
 */
bool InitRoomCombo(HWND hwnd,const char *floor_name, UINT id)
{
	CComboBox room_name(hwnd, id);
	RoomInfo room_info;
	room_info.GetRoomName(floor_name);  // 获取楼层下的房间名称记录集
	room_name.DeleteAllString();
	while (!room_info.IsEOF())
	{
		room_name.AddString(room_info.room_name());
	} 
	return true;
}
コード例 #2
0
/* 
 * game_loop
 *   DESCRIPTION: Main event loop for the adventure game.
 *   INPUTS: none
 *   OUTPUTS: none
 *   RETURN VALUE: GAME_QUIT if the player quits, or GAME_WON if they have won
 *   SIDE EFFECTS: drives the display, etc.
 */
static game_condition_t
game_loop ()
{
    /* 
     * Variables used to carry information between event loop ticks; see
     * initialization below for explanations of purpose.
     */
    struct timeval start_time, tick_time;

    struct timeval cur_time; /* current time (during tick)      */
    cmd_t cmd;               /* command issued by input control */
    int32_t enter_room;      /* player has changed rooms        */

    /* Record the starting time--assume success. */
    (void)gettimeofday (&start_time, NULL);

    /* Calculate the time at which the first event loop tick should occur. */
    tick_time = start_time;
    if ((tick_time.tv_usec += TICK_USEC) > 1000000) {
	tick_time.tv_sec++;
	tick_time.tv_usec -= 1000000;
    }

    /* The player has just entered the first room. */
    enter_room = 1;

    /* The main event loop. */
    while (1) {
	/* 
	 * Update the screen, preparing the VGA palette and photo-drawing
	 * routines and drawing a new room photo first if the player has
	 * entered a new room, then showing the screen (and status bar,
	 * once you have it working).
	 */
	if (enter_room) {
	    /* Reset the view window to (0,0). */
	    game_info.map_x = game_info.map_y = 0;
	    set_view_window (game_info.map_x, game_info.map_y);

	    /* Discard any partially-typed command. */
	    reset_typed_command ();
	    
	    /* Adjust colors and photo drawing for the current room photo. */
	    prep_room (game_info.where);

	    /* Draw the room (calls show. */
	    redraw_room ();

	    /* Only draw once on entry. */
	    enter_room = 0;
	}

	show_screen ();
	//lock status_msg to prevent changes
	(void)pthread_mutex_lock (&msg_lock);
	room_t* curr_room = game_info.where; // This is the current room pointer
	// Now call fill_status_bar with all the possible strings as params
	fill_status_bar(room_name(curr_room), get_typed_command(), status_msg);
	(void)pthread_mutex_unlock (&msg_lock); //unlock
	// Calculate game time
	display_time_on_tux (cur_time.tv_sec - start_time.tv_sec);
	/*
	 * Wait for tick.  The tick defines the basic timing of our
	 * event loop, and is the minimum amount of time between events.
	 */
	do {
	    if (gettimeofday (&cur_time, NULL) != 0) {
		/* Panic!  (should never happen) */
		clear_mode_X ();
		shutdown_input ();
		perror ("gettimeofday");
		exit (3);
	    }
	} while (!time_is_after (&cur_time, &tick_time));

	/*
	 * Advance the tick time.  If we missed one or more ticks completely, 
	 * i.e., if the current time is already after the time for the next 
	 * tick, just skip the extra ticks and advance the clock to the one
	 * that we haven't missed.
	 */
	do {
	    if ((tick_time.tv_usec += TICK_USEC) > 1000000) {
		tick_time.tv_sec++;
		tick_time.tv_usec -= 1000000;
	    }
	} while (time_is_after (&cur_time, &tick_time));

	/*
	 * Handle asynchronous events.  These events use real time rather
	 * than tick counts for timing, although the real time is rounded
	 * off to the nearest tick by definition.
	 */
	/* (none right now...) */

	/* 
	 * Handle synchronous events--in this case, only player commands. 
	 * Note that typed commands that move objects may cause the room
	 * to be redrawn.
	 */
	
	cmd = get_command ();
	switch (cmd) {
	    case CMD_UP:    move_photo_down ();  break;
	    case CMD_RIGHT: move_photo_left ();  break;
	    case CMD_DOWN:  move_photo_up ();    break;
	    case CMD_LEFT:  move_photo_right (); break;
	    case CMD_MOVE_LEFT:   
		enter_room = (TC_CHANGE_ROOM == 
			      try_to_move_left (&game_info.where));
		break;
	    case CMD_ENTER:
		enter_room = (TC_CHANGE_ROOM ==
			      try_to_enter (&game_info.where));
		break;
	    case CMD_MOVE_RIGHT:
		enter_room = (TC_CHANGE_ROOM == 
			      try_to_move_right (&game_info.where));
		break;
	    case CMD_TYPED:
		if (handle_typing ()) {
		    enter_room = 1;
		}
		break;
	    case CMD_QUIT: return GAME_QUIT;
	    default: break;
	}
	// Repeat the same thing for the tux
	cmd = get_tux_command();
	switch (cmd) {
	    case CMD_UP:    move_photo_down ();  break;
	    case CMD_RIGHT: move_photo_left ();  break;
	    case CMD_DOWN:  move_photo_up ();    break;
	    case CMD_LEFT:  move_photo_right (); break;
	    case CMD_MOVE_LEFT:   
		enter_room = (TC_CHANGE_ROOM == 
			      try_to_move_left (&game_info.where));
		break;
	    case CMD_ENTER:
		enter_room = (TC_CHANGE_ROOM ==
			      try_to_enter (&game_info.where));
		break;
	    case CMD_MOVE_RIGHT:
		enter_room = (TC_CHANGE_ROOM == 
			      try_to_move_right (&game_info.where));
		break;
	    case CMD_QUIT: return GAME_QUIT;
	    default: break;
	}
	/* If player wins the game, their room becomes NULL. */
	if (NULL == game_info.where) {
	    return GAME_WON;
	}
    } /* end of the main event loop */
}
コード例 #3
0
ファイル: dump_nightmare.c プロジェクト: Lundex/wileymud
void dump_as_nightmare(zones *Zones, rooms *Rooms, shops *Shops)
{
    FILE                                   *ofp,
                                           *fp2;
    char                                    filename[256],
                                            domainname[256],
                                            dirname[256],
                                            subdirname[256];
    char                                    mudpath[256],
                                            roomname[256],
                                            mudname[256],
                                            doorname[256],
                                            outpath[256];
    int                                     i,
                                            j,
                                            k,
                                            x;
    int                                     LowRoom,
                                            HighRoom;
    pair                                   *ZoneSort;
    char                                   *TmpDesc,
                                           *HackDesc;

/* Ensure that each domain exists in our directory structure. */
    ZoneSort = (pair *)get_mem(Zones->Count, sizeof(pair));
    bzero(ZoneSort, sizeof(pair) * Zones->Count);
    for (i = 0; i < Zones->Count; i++) {
	sprintf(domainname, "%s_%d", remap_name(Zones->Zone[i].Name), Zones->Zone[i].Number);
	sprintf(dirname, "%s/%s%s/%s", OutputDir, NIGHTMARE_SUBDIR, NIGHTMARE_DOMAIN,
		domainname);
	sprintf(filename, "mkdir -p %s", dirname);
	system(filename);
	sprintf(filename, "%s/README", dirname);
	ofp = open_file(filename, "w");
	fprintf(ofp, "#ZONEDATA\n");
	fprintf(ofp, "Name\t%s~\n", Zones->Zone[i].Name);
	fprintf(ofp, "Author\tThe Wiley Gang~\n");
	LowRoom = INT_MAX;
	HighRoom = INT_MIN;
	for (j = 0; j < Rooms->Count; j++) {
	    if ((remap_zone_vnum(Zones, Rooms->Room[j].Zone) == i) ||
		((Rooms->Room[j].Number >= (!i ? 0 : Zones->Zone[i - 1].Top + 1))&&
		 (Rooms->Room[j].Number <= Zones->Zone[i].Top)
		)) {
		LowRoom = min(LowRoom, Rooms->Room[j].Number);
		HighRoom = max(HighRoom, Rooms->Room[j].Number);
	    }
	}
	ZoneSort[i].x = i;
	ZoneSort[i].y = LowRoom;
	fprintf(ofp, "VNUMs\t%d %d\n", LowRoom, HighRoom);
	fprintf(ofp, "Time\t%d\n", Zones->Zone[i].Time);
	fprintf(ofp, "Mode\t%d\n", Zones->Zone[i].Mode);
	fprintf(ofp, "End\n\n");
	fclose(ofp);
/* There, now we have some setup work to do... */
	sprintf(subdirname, "%s/adm", dirname);
	sprintf(filename, "mkdir -p %s/adm", dirname);
	system(filename);
	sprintf(filename, "%s/README", subdirname);
	ofp = open_file(filename, "w");
	fprintf(ofp, "                         /domains/%s/adm\n", domainname);
	fprintf(ofp, "               The Administrative Directory for %s\n", domainname);
	fprintf(ofp, "\n");
	fprintf(ofp, "This directory contains all files necessary for domain\n");
	fprintf(ofp, "administration.  The following files are required for any standard\n");
	fprintf(ofp, "domain, but not for secondary domains or realms:\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "void.c - The place people go when their environment is destructed\n");
	fprintf(ofp, "freezer.c - The place people go when they go net-dead\n");
	fprintf(ofp, "cache.c - The place hidden items go to hide\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "The access object is used in any realm or domain which is giving out\n");
	fprintf(ofp, "access which is nonstandard.  This is traditionally handled through\n");
	fprintf(ofp, "the 'grant' command.\n");
	fclose(ofp);

	sprintf(filename, "%s/access.c", subdirname);
	ofp = open_file(filename, "w");
	fprintf(ofp, "/*    %s/%s/adm/access.c\n", NIGHTMARE_DOMAIN, domainname);
	fprintf(ofp, " *    From the Nightmare V Object Library\n");
	fprintf(ofp, " *    the access object for the %s domain\n", domainname);
	fprintf(ofp, " *    created by Descartes of Borg 960302\n");
	fprintf(ofp, " */\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "#include <lib.h>\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "inherit LIB_ACCESS;\n");
	fclose(ofp);

	sprintf(filename, "%s/cache.c", subdirname);
	ofp = open_file(filename, "w");
	fprintf(ofp, "/*    /domains/%s/adm/cache.c\n", domainname);
	fprintf(ofp, " *    from the Nightmare V Object Library\n");
	fprintf(ofp, " *    room where hidden objects are stored\n");
	fprintf(ofp, " *    created by Descartes of Borg 960302\n");
	fprintf(ofp, " */\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "#include <lib.h>\n");
	fprintf(ofp, "#include <room.h>\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "inherit LIB_ROOM;\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "void create() {\n");
	fprintf(ofp, "    room::create();\n");
	fprintf(ofp, "    SetShort( \"The cache\");\n");
	fprintf(ofp, "    SetLong( \"Things are hidden here.\");\n");
	fprintf(ofp,
		"    SetProperties( ([ \"storage room\" : 1, \"logout\" : ROOM_START ]) );\n");
	fprintf(ofp, "}\n");
	fclose(ofp);

	sprintf(filename, "%s/freezer.c", subdirname);
	ofp = open_file(filename, "w");
	fprintf(ofp, "/*    /domains/%s/adm/freezer.c\n", domainname);
	fprintf(ofp, " *    from the Nightmare V Object Library\n");
	fprintf(ofp, " *    room that stores net-dead people\n");
	fprintf(ofp, " *    created by Descartes of Borg 960302\n");
	fprintf(ofp, " */\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "#include <lib.h>\n");
	fprintf(ofp, "#include <config.h>\n");
	fprintf(ofp, "#include <rooms.h>\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "inherit LIB_ROOM;\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "static private object *Old;\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "void create() {\n");
	fprintf(ofp, "    room::create();\n");
	fprintf(ofp, "    SetNoClean(1);\n");
	fprintf(ofp, "    SetProperties(([ \"login\" : ROOM_START, \"no teleport\" : 1 ]));\n");
	fprintf(ofp, "    SetShort( \"The freezer\");\n");
	fprintf(ofp, "    SetLong( \"The local freezer.  Go down to leave.\");\n");
	fprintf(ofp, "    SetObviousExits(\"d\");\n");
	fprintf(ofp, "    SetExits( ([ \"down\" : ROOM_START ]) );\n");
	fprintf(ofp, "    Old = ({});\n");
	fprintf(ofp, "    call_out(\"clean_room\", MAX_NET_DEAD_TIME);\n");
	fprintf(ofp, "}\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "static void clean_room() {\n");
	fprintf(ofp, "    object *clean_me;\n");
	fprintf(ofp, "    object ob;\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "    foreach(ob in filter(all_inventory(), (: !living($1) :)))\n");
	fprintf(ofp, "      ob->eventDestruct();\n");
	fprintf(ofp, "    if( !sizeof(filter(all_inventory(), (: living :))) ) {\n");
	fprintf(ofp, "        Old = ({});\n");
	fprintf(ofp, "        call_out((: clean_room :), MAX_NET_DEAD_TIME);\n");
	fprintf(ofp, "        return;\n");
	fprintf(ofp, "    }\n");
	fprintf(ofp, "    clean_me = (all_inventory() & Old);\n");
	fprintf(ofp, "    Old = all_inventory() - clean_me;\n");
	fprintf(ofp, "    foreach(ob in clean_me) ob->eventDestruct();\n");
	fprintf(ofp, "    call_out((: clean_room :), MAX_NET_DEAD_TIME);\n");
	fprintf(ofp, "}\n");
	fclose(ofp);

	sprintf(filename, "%s/void.c", subdirname);
	ofp = open_file(filename, "w");
	fprintf(ofp, "/*    /domains/%s/adm/void.c\n", domainname);
	fprintf(ofp, " *    from the Nightmare V Object Library\n");
	fprintf(ofp, " *    place where people go when their environments accidentally are\n");
	fprintf(ofp, " *    destructed\n");
	fprintf(ofp, " *    created by Descartes of Borg 960302\n");
	fprintf(ofp, " */\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "#include <lib.h>\n");
	fprintf(ofp, "#include <rooms.h>\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "inherit LIB_ROOM;\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "void create() {\n");
	fprintf(ofp, "    room::create();\n");
	fprintf(ofp, "    SetShort(\"the void\");\n");
	fprintf(ofp, "    SetLong(\"The void.  Go down to get out.\");\n");
	fprintf(ofp, "    SetExits( ([ \"down\" : ROOM_START ]) );\n");
	fprintf(ofp, "}\n");
	fclose(ofp);

	sprintf(filename, "mkdir -p %s/etc", dirname);
	system(filename);

/* These are unused at present and might not always be needed... */

	sprintf(filename, "mkdir -p %s/armour", dirname);
	system(filename);
	sprintf(filename, "mkdir -p %s/fish", dirname);
	system(filename);
	sprintf(filename, "mkdir -p %s/meal", dirname);
	system(filename);
	sprintf(filename, "mkdir -p %s/npc", dirname);
	system(filename);
	sprintf(filename, "mkdir -p %s/save", dirname);
	system(filename);
	sprintf(filename, "mkdir -p %s/weapon", dirname);
	system(filename);

/* This is the virtual room server */

	sprintf(subdirname, "%s/virtual", dirname);
	sprintf(filename, "mkdir -p %s/virtual", dirname);
	system(filename);
	sprintf(filename, "%s/README", subdirname);
	ofp = open_file(filename, "w");
	fprintf(ofp, "                       /domains/%s/virtual\n", domainname);
	fprintf(ofp, "                 Virtual Rooms for the %s Domain\n", domainname);
	fprintf(ofp, "\n");
	fprintf(ofp, "Here is a virtual grid server setup for a 25 by 25 room grid.\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "What happens is when some objects references an object in\n");
	fprintf(ofp, "/domains/%s/virtual/grassland/ but finds no file there, it\n",
		domainname);
	fprintf(ofp, "calls compile_object() in /domains/%s/virtual/server.c.  That\n",
		domainname);
	fprintf(ofp, "function returns an object which serves as the non-existent object.\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "The virtual server looks at the file name like:\n");
	fprintf(ofp, "/domains/%s/virtual/grassland/15,12\n", domainname);
	fprintf(ofp, "\n");
	fprintf(ofp, "That tells it to clone /domains/%s/virtual/grassland.c and pass it\n",
		domainname);
	fprintf(ofp,
		"15, 12 as the argument to create().  Thus grassland.c is able to set up\n");
	fprintf(ofp,
		"exits and such for its location at 15, 12 on the virtual grassland grid.\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "You can thus write your own virtual grid, say for a forest, simply by\n");
	fprintf(ofp, "writing a forest.c like the grassland.c given here.\n");
	fprintf(ofp, "\n");
	fclose(ofp);

	sprintf(filename, "mkdir -p %s/virtual/grassland", dirname);
	system(filename);

	sprintf(filename, "%s/grassland.c", subdirname);
	ofp = open_file(filename, "w");
	fprintf(ofp, "/*    /domains/%s/virtual/grassland.c\n", domainname);
	fprintf(ofp, " *    from the Nightmare V Object Library\n");
	fprintf(ofp, " *    created by Descartes of Borg 960302\n");
	fprintf(ofp, " */\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "#include <lib.h>\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "inherit LIB_ROOM;\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "static private int XPosition, YPosition;\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "static void SetLongAndItems();\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "varargs static void create(int x, int y) {\n");
	fprintf(ofp, "    string n, s, e, w;\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "    SetNoReplace(1);\n");
	fprintf(ofp, "    room::create();\n");
	fprintf(ofp, "    XPosition = x;\n");
	fprintf(ofp, "    YPosition = y;\n");
	fprintf(ofp, "    SetClimate(\"temperate\");\n");
	fprintf(ofp, "    SetProperties( ([ \"light\" : 2 ]) );\n");
	fprintf(ofp,
		"    SetShort(x == 25 ? \"the edge of a grassy plain\" : \"endless grasslands\");\n");
	fprintf(ofp, "    SetLongAndItems();\n");
	fprintf(ofp, "    if( x == 25 ) e = __DIR__ + random(25) + \",\" + y;\n");
	fprintf(ofp, "    else e = __DIR__ + (x+1) + \",\" + y;\n");
	fprintf(ofp, "    if( x == 1 ) w = __DIR__ + random(25) + \",\" + y;\n");
	fprintf(ofp, "    else w = __DIR__ + (x-1) + \",\" + y;\n");
	fprintf(ofp, "    if( y == 25 ) n = __DIR__ + x + \",\" + random(25);\n");
	fprintf(ofp, "    else n = __DIR__ + x + \",\" + (y+1);\n");
	fprintf(ofp, "    if( y == 1 ) s = __DIR__ + x+ \",\" + random(25);\n");
	fprintf(ofp, "    else s = __DIR__ + x + \",\" + (y-1);\n");
	fprintf(ofp,
		"    SetGoMessage(\"The grass abruptly ends at a great VOID!  You cannot pass.\");\n");
	fprintf(ofp, "    if( n ) AddExit(\"north\", __DIR__ + n);\n");
	fprintf(ofp, "    if( s ) AddExit(\"south\", __DIR__ + s);\n");
	fprintf(ofp, "    if( e ) AddExit(\"east\", __DIR__ + e);\n");
	fprintf(ofp, "    if( w ) AddExit(\"west\", __DIR__ + w);\n");
	fprintf(ofp, "}\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "static void SetLongAndItems() {\n");
	fprintf(ofp, "    mapping inv, items;\n");
	fprintf(ofp, "    string str;\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "    inv = ([]);\n");
	fprintf(ofp,
		"    str = \"You stand amidst an endless sea of tall grasses, gently waving\"\n");
	fprintf(ofp,
		"        \" in the breeze.  Quiet, peaceful, hypnotic.  You might as well\"\n");
	fprintf(ofp, "        \" become one of the beckoning blades...\";\n");
	fprintf(ofp,
		"    items = ([ \"grassland\" : \"The peaceful ocean of grass goes on forever.\",\n");
	fprintf(ofp,
		"        \"grass\" : \"It seems soft yet strong, edible if you were a cow.\" ]);\n");
	fprintf(ofp, "    if( !random(50) ) {\n");
	fprintf(ofp,
		"        str += \"  A small circle of stones and some burnt wood stands out\"\n");
	fprintf(ofp, "            \" from the grass a bit.\";\n");
	fprintf(ofp, "        items[({ \"stones\", \"rocks\" })] =\n");
	fprintf(ofp,
		"            \"They are smallish stones, set close in a circle to prevent\"\n");
	fprintf(ofp,
		"            \" a fire within from spreading to the sometimes dry grass\"\n");
	fprintf(ofp, "            \" which is all around you.\";\n");
	fprintf(ofp,
		"        items[({ \"twigs\", \"sticks\", \"kindling\", \"wood\", \"burnt wood\" })] =\n");
	fprintf(ofp,
		"              \"Though long since burnt to nothing, scattered kindling \"\n");
	fprintf(ofp,
		"              \"and burnt wood lie about as a memory of travellers who have \"\n");
	fprintf(ofp, "              \"passed through\";\n");
	fprintf(ofp, "        if( random(2) ) {\n");
	fprintf(ofp, "            string thing;\n");
	fprintf(ofp, "\n");
	fprintf(ofp,
		"            foreach(thing in ({ \"twigs\", \"sticks\", \"kindling\", \"wood\" }))\n");
	fprintf(ofp, "              SetSearch(thing, function(object who, string str) {\n");
	fprintf(ofp, "                  object ob;\n");
	fprintf(ofp, "                  string thing2;\n");
	fprintf(ofp, "\n");
	fprintf(ofp,
		"                  if( !(ob = new(DIR_STANDARD_DOMAIN \"/etc/pole\")) )\n");
	fprintf(ofp, "                    return 0;\n");
	fprintf(ofp, "                  who->eventPrint(\"You find a fishing pole!\");\n");
	fprintf(ofp,
		"                  eventPrint((string)who->GetName() + \" finds a fishing pole \"\n");
	fprintf(ofp, "                             \"among the abandoned campsite.\", who);\n");
	fprintf(ofp,
		"                  foreach(thing2 in ({ \"twigs\", \"sticks\", \"kindling\", \"wood\"}))\n");
	fprintf(ofp, "                    RemoveSearch(thing2);\n");
	fprintf(ofp, "                  if( !((int)ob->eventMove(this_player())) ) {\n");
	fprintf(ofp, "                      who->eventPrint(\"You drop the pole!\");\n");
	fprintf(ofp,
		"                      eventPrint((string)who->GetName() + \" drops the pole.\",\n");
	fprintf(ofp, "                                 who);\n");
	fprintf(ofp, "                      ob->eventMove(this_object());\n");
	fprintf(ofp, "                  }\n");
	fprintf(ofp, "                  return 1;\n");
	fprintf(ofp, "              });\n");
	fprintf(ofp, "        }\n");
	fprintf(ofp, "    }\n");
	fprintf(ofp, "    else if( !random(10) )\n");
	fprintf(ofp, "      SetSmell(\"default\", \"You smell a distant camp fire.\");\n");
	fprintf(ofp, "    if( !random(25) )\n");
	fprintf(ofp, "      inv[DIR_STANDARD_DOMAIN \"/npc/traveller\"] = random(3) + 1;\n");
	fprintf(ofp, "    else if( !random(4) )\n");
	fprintf(ofp,
		"      SetListen(\"default\", \"You hear voices whispering in the distance.\");\n");
	fprintf(ofp, "    SetLong(str);\n");
	fprintf(ofp, "    SetItems(items);\n");
	fprintf(ofp, "    SetInventory(inv);\n");
	fprintf(ofp, "}\n");
	fclose(ofp);

	sprintf(filename, "%s/server.c", subdirname);
	ofp = open_file(filename, "w");
	fprintf(ofp, "/*    /domains/%s/virtual/server.c\n", domainname);
	fprintf(ofp, " *    from the Nightmare V Object Library\n");
	fprintf(ofp, " *    created by Descartes of Borg 960302\n");
	fprintf(ofp, " */\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "object compile_object(string file) {\n");
	fprintf(ofp, "    string *path;\n");
	fprintf(ofp, "    object ob;\n");
	fprintf(ofp, "    int x, y;\n");
	fprintf(ofp, "\n");
	fprintf(ofp, "    if( previous_object() != master() ) return 0;\n");
	fprintf(ofp, "    path = explode(file, \"/\");\n");
	fprintf(ofp, "    if( sizeof(path) != 5 ) return 0;\n");
	fprintf(ofp, "    if( file_size(__DIR__ + path[3] + \".c\") < 1 ) return 0;\n");
	fprintf(ofp, "    if( sscanf(path[4], \"%%d,%%d\", x, y) != 2 ) return 0;\n");
	fprintf(ofp, "    if( !(ob = new(__DIR__ + path[3], x, y)) ) return 0;\n");
	fprintf(ofp, "    return ob;\n");
	fprintf(ofp, "}\n");
	fclose(ofp);

/* Ye GODS that be alot of setup.... ok, time for the meat now! */

	sprintf(subdirname, "%s/room", dirname);
	sprintf(filename, "mkdir -p %s/room", dirname);
	system(filename);
	sprintf(mudpath, "%s/%s/room", NIGHTMARE_DOMAIN, domainname);

	for (j = 0; j < Rooms->Count; j++) {
	    if ((remap_zone_vnum(Zones, Rooms->Room[j].Zone) == i) ||
		((Rooms->Room[j].Number >= (!i ? 0 : Zones->Zone[i - 1].Top + 1))&&
		 (Rooms->Room[j].Number <= Zones->Zone[i].Top)
		)) {
		sprintf(roomname, "%s_%d.c", remap_name(Rooms->Room[j].Name),
			Rooms->Room[j].Number);
		sprintf(filename, "%s/%s", subdirname, roomname);
		sprintf(mudname, "%s/%s", mudpath, roomname);
		ofp = open_file(filename, "w");

#ifdef DEBUG
		fprintf(stderr, "Dumping %s\n", filename);
#endif
		fprintf(ofp, "// Automated conversion of WileyMUD by Quixadhal\n");
		fprintf(ofp, "// Original:   WileyMUD III, Room [#%d]\n",
			Rooms->Room[j].Number);
		fprintf(ofp, "// Target:     Nightmare IVr2.5, %s\n", mudname);
		fprintf(ofp, "// Performed:  %s\n", timestamp());
		fprintf(ofp, "\n");

/* Setup basic file now... */

		fprintf(ofp, "#include <lib.h>\n");
		fprintf(ofp, "\n");
		fprintf(ofp, "inherit LIB_ROOM;\n");
		fprintf(ofp, "\n");

		fprintf(ofp, "static void create() {\n");
		fprintf(ofp, "    room::create();\n");
		if (Rooms->Room[j].Flags & ROOM_DARK)
		    fprintf(ofp, "    SetProperty(\"light\", 0);\n");
		else
		    fprintf(ofp, "    SetProperty(\"light\", 2);\n");

/* Climate is a poor substitute for sector types... adjust manually. */

		if (Rooms->Room[j].Flags & ROOM_INDOORS)
		    fprintf(ofp, "    SetClimate(\"indoors\");\n");
		else
		    switch (Rooms->Room[j].Sector) {
			case SECT_INDOORS:
			    fprintf(ofp, "    SetClimate(\"indoors\");\n");
			    break;
			case SECT_FOREST:
			    fprintf(ofp, "    SetClimate(\"tropical\");\n");
			    break;
			case SECT_HILLS:
			    fprintf(ofp, "    SetClimate(\"arid\");\n");
			    break;
			case SECT_MOUNTAIN:
			    fprintf(ofp, "    SetClimate(\"arctic\");\n");
			    break;
		    }

		fprintf(ofp, "\n");
		fprintf(ofp, "    SetShort(\"%s\");\n", Rooms->Room[j].Name);
		TmpDesc = my_strdup(Rooms->Room[j].Description);

		if (!(HackDesc = (char *)strtok(TmpDesc, "\n")))
		    fprintf(ofp, "    SetLong(\"%s\");\n", TmpDesc);
		else {
		    fprintf(ofp, "    SetLong(\"%s\"\n", HackDesc);
		    while ((HackDesc = (char *)strtok(NULL, "\n")))
			if (HackDesc)
			    fprintf(ofp, "        \" %s\"\n", HackDesc);
		    fprintf(ofp, "        );\n");
		}
		free(TmpDesc);

		fprintf(ofp, "\n");
		k = 0;
		if (Rooms->Room[j].Flags & ROOM_NOATTACK) {
		    k = 1;
		    fprintf(ofp, "    SetProperty(\"no attack\", 1);\n");
		}
		if (Rooms->Room[j].Flags & ROOM_NOSTEAL) {
		    k = 1;
		    fprintf(ofp, "    SetProperty(\"no steal\", 1);\n");
		}
		if (Rooms->Room[j].Flags & ROOM_NOSUMMON) {
		    k = 1;
		    fprintf(ofp, "    SetProperty(\"no teleport\", 1);\n");
		}
		if (Rooms->Room[j].Flags & ROOM_NOMAGIC) {
		    k = 1;
		    fprintf(ofp, "    SetProperty(\"no magic\", 1);\n");
		}
		if (k)
		    fprintf(ofp, "\n");

		if (Rooms->Room[j].ExtraCount > 0) {
		    fprintf(ofp, "    SetItems( ([\n");
		    for (k = 0; k < Rooms->Room[j].ExtraCount; k++) {
			if (Rooms->Room[j].Extra[k].Keyword->Count > 0) {
			    if (Rooms->Room[j].Extra[k].Keyword->Count > 1)
				fprintf(ofp, "        ({ \"%s\"",
					Rooms->Room[j].Extra[k].Keyword->Word[0]);
			    else
				fprintf(ofp, "        \"%s\"",
					Rooms->Room[j].Extra[k].Keyword->Word[0]);
			    for (x = 1; x < Rooms->Room[j].Extra[k].Keyword->Count; x++)
				fprintf(ofp, ", \"%s\"",
					Rooms->Room[j].Extra[k].Keyword->Word[x]);
			    if (Rooms->Room[j].Extra[k].Keyword->Count > 1)
				fprintf(ofp, " }) :\n");
			    else
				fprintf(ofp, " :\n");

			    TmpDesc = my_strdup(Rooms->Room[j].Extra[k].Description);

			    if (!(HackDesc = (char *)strtok(TmpDesc, "\n")))
				fprintf(ofp, "        \"%s\"\n", TmpDesc);
			    else {
				fprintf(ofp, "        \"%s\"\n", HackDesc);
				while ((HackDesc = (char *)strtok(NULL, "\n")))
				    if (HackDesc)
					fprintf(ofp, "        \" %s\"\n", HackDesc);
			    }
			    free(TmpDesc);
			    if (k < Rooms->Room[j].ExtraCount - 1)
				fprintf(ofp, "        ,\n");
			}
		    }
		    fprintf(ofp, "        ]) );\n");
		}

		if (Rooms->Room[j].ExitCount > 0) {
		    fprintf(ofp, "    SetExits( ([\n");
		    for (k = 0; k < Rooms->Room[j].ExitCount; k++) {
			/*
			 * Unlike extra descriptions, exits have an implied keyword of their direction. Thus, even if
			 * Count < 1, the exit will still be valid. 
			 */
			switch (Rooms->Room[j].Exit[k].Error) {
			    case EXIT_OK:
			    case EXIT_NON_EUCLIDEAN:
			    case EXIT_ONE_WAY:
				if (Rooms->Room[j].Exit[k].Keyword->Count > 0) {
				    fprintf(ofp, "        ({ \"%s\"",
					    exit_name_lower(Rooms->Room[j].Exit[k].Direction));
				    for (x = 0; x < Rooms->Room[j].Exit[k].Keyword->Count; x++)
					fprintf(ofp, ", \"%s\"",
						Rooms->Room[j].Exit[k].Keyword->Word[x]);
				    fprintf(ofp, " }) :\n");
				} else {
				    fprintf(ofp, "        \"%s\" :\n",
					    exit_name_lower(Rooms->Room[j].Exit[k].Direction));
				}
				sprintf(outpath, "%s/%s_%d/room", NIGHTMARE_DOMAIN,
					remap_name(Zones->Zone[remap_zone_vnum(Zones,
									       Rooms->Room
									       [remap_room_vnum
										 
										 
										 
										 
										 
										 
										 
										 
										 
										 
										 
										 (Rooms,
										  Rooms->
										  Room[j].Exit
										  [k].
										  Room)].Zone)].
						   Name), Rooms->Room[remap_room_vnum(Rooms,
										      Rooms->
										      Room[j].
										      Exit[k].
										      Room)].
					Zone);
				fprintf(ofp, "        \"%s/%s_%d\"\n", outpath,
					remap_name(room_name
						   (Rooms, Rooms->Room[j].Exit[k].Room)),
					Rooms->Room[j].Exit[k].Room);
				if (k < Rooms->Room[j].ExitCount - 1)
				    fprintf(ofp, "        ,\n");
				/*
				 * Keys would require that objects be done... ignore. Descriptions are not supported in 
				 * Nightmare... you would have to add it as an AddItem call, but then it would be "look 
				 * at north" instead of "look north".... ignore for now. 
				 */
				break;
			}
		    }
		    fprintf(ofp, "        ]) );\n");
		}

		/*
		 * NOW, we can go setup the doors... we need a default door as well. 
		 */

		if (Rooms->Room[j].ExitCount > 0) {
		    for (k = 0; k < Rooms->Room[j].ExitCount; k++) {
			switch (Rooms->Room[j].Exit[k].Type) {
			    case EXIT_OPEN:
			    case EXIT_OPEN_ALIAS:
				break;
			    default:
				sprintf(doorname, "%s/etc/%s_%d_%s_door.c", dirname,
					remap_name(room_name
						   (Rooms, Rooms->Room[j].Exit[k].Room)),
					Rooms->Room[j].Exit[k].Room,
					exit_name_lower(Rooms->Room[j].Exit[k].Direction));
				fprintf(ofp, "    SetDoor( \"%s\", \"%s\" );\n",
					exit_name_lower(Rooms->Room[j].Exit[k].Direction),
					doorname);
				fp2 = open_file(doorname, "w");
				fprintf(fp2, "/*    /domains/%s/etc/%s_%d_%s_door.c\n",
					domainname,
					remap_name(room_name
						   (Rooms, Rooms->Room[j].Exit[k].Room)),
					Rooms->Room[j].Exit[k].Room,
					exit_name_lower(Rooms->Room[j].Exit[k].Direction));
				fprintf(fp2, " *    from Nightmare LPMud\n");
				fprintf(fp2, " *    created by Descartes of Borg 951027\n");
				fprintf(fp2, " */\n");
				fprintf(fp2, "\n");
				fprintf(fp2, "#include <lib.h>\n");
				fprintf(fp2, "\n");
				fprintf(fp2, "inherit LIB_DOOR;\n");
				fprintf(fp2, "\n");
				fprintf(fp2, "static void create() {\n");
				fprintf(fp2, "    door::create();\n");
				fprintf(fp2, "    SetId(\"%s\", \"door\");\n",
					exit_name_lower(Rooms->Room[j].Exit[k].Direction));
				fprintf(fp2,
					"    SetShort(\"%s\", \"a cracked wooden door\");\n",
					exit_name_lower(Rooms->Room[j].Exit[k].Direction));
				fprintf(fp2,
					"    SetLong(\"%s\", \"The door is cracked and has seen better days.\"\n",
					exit_name_lower(Rooms->Room[j].Exit[k].Direction));
				fprintf(fp2, "    SetId(\"%s\", \"door\");\n",
					exit_name_lower(RevDir
							[Rooms->Room[j].Exit[k].Direction]));
				fprintf(fp2,
					"    SetShort(\"%s\", \"a cracked wooden door\");\n",
					exit_name_lower(RevDir
							[Rooms->Room[j].Exit[k].Direction]));
				fprintf(fp2,
					"    SetLong(\"%s\", \"The door is cracked and has seen better days.\"\n",
					exit_name_lower(RevDir
							[Rooms->Room[j].Exit[k].Direction]));
				fprintf(fp2, "    SetClosed(1);\n");
				fprintf(fp2, "}\n");
				fclose(fp2);
				if (k < Rooms->Room[j].ExitCount - 1)
				    fprintf(ofp, "        ,\n");
				/*
				 * Keys would require that objects be done... ignore. Descriptions are not supported in 
				 * Nightmare... you would have to add it as an AddItem call, but then it would be "look 
				 * at north" instead of "look north".... ignore for now. 
				 */
				break;
			}
		    }
		}
		fprintf(ofp, "}\n");
		fclose(ofp);
	    }
	}
    }
}
コード例 #4
0
ファイル: adventure.c プロジェクト: ASalesman/ECE391-MP2
/*
 * status_thread
 *   DESCRIPTION: Function executed by status message helper thread.
 *                Waits for a message to be displayed, then shows the
 *                message for 1.5 seconds before deleting it.  If a
 *                new message has appeared in the meantime, restarts the
 *                clock and tries again.
 *   INPUTS: none (ignored)
 *   OUTPUTS: none
 *   RETURN VALUE: NULL
 *   SIDE EFFECTS: Changes the status message to an empty string.
 */
static void*
status_thread (void* ignore)
{
	struct timespec ts; /* absolute wake-up time */

	while (1) {

		/*
		 * Wait for a message to appear.  Note that we must check the
		 * condition after acquiring the lock, and that pthread_cond_wait
		 * yields the lock, then reacquires the lock before returning.
		 */
		(void)pthread_mutex_lock (&msg_lock);
		while ('\0' == status_msg[0]) {
			print_status_text(room_name(game_info.where), STATUS_ROOM_COLOR,
			                  STATUS_BG_COLOR, ALIGN_LEFT, 1);
			print_status_text(get_typed_command(), STATUS_COMMAND_COLOR,
			                  STATUS_BG_COLOR, ALIGN_RIGHT, 0);
			pthread_cond_wait (&msg_cv, &msg_lock);
		}

		/*
		 * A message is present: if we stop before the timeout
		 * passes, assume that a new one has been posted; if the
		 * timeout passes, clear the message and wait for a new one.
		 */
		do {
			/* Get the current time. */
			clock_gettime (CLOCK_REALTIME, &ts);
			const char *command = get_typed_command();
			int alignment = ALIGN_CENTER;
			if (command[0] != '\0') {
				alignment = ALIGN_LEFT;
			}
			print_status_text(status_msg, STATUS_FG_COLOR, STATUS_BG_COLOR,
			                  alignment, 1);
			print_status_text(command, STATUS_COMMAND_COLOR, STATUS_BG_COLOR,
			                  ALIGN_RIGHT, 0);

			/* Add 1.5 seconds to it. */
			if (500000000 <= ts.tv_nsec) {
				ts.tv_sec += 2;
				ts.tv_nsec -= 500000000;
			} else {
				ts.tv_sec += 1;
				ts.tv_nsec += 500000000;
			}

			/*
			 * And go to sleep.  If we wake up due to anything but a
			 * timeout, we assume (possibly incorrectly) that a new
			 * message has appeared and try to wait 1.5 seconds again.
			 */
		} while (ETIMEDOUT !=
		         pthread_cond_timedwait (&msg_cv, &msg_lock, &ts));

		/*
		 * Clear the message, then release the lock (remember that
		 * pthread_cond_timedwait reacquires the lock before returning).
		 */
		status_msg[0] = '\0';
		(void)pthread_mutex_unlock (&msg_lock);
	}

	/* This code never executes--the thread should always be cancelled. */
	return NULL;
}
コード例 #5
0
ファイル: table_info.cpp プロジェクト: lijianping/repast
/*
 * @ brief: 台号信息处理函数
 * @ param: hwnd [in] 窗口句柄
 * @ param: msg [in] 消息类型
 **/
BOOL CALLBACK ChildTableInfoProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case WM_INITDIALOG:
		{
			CListView table_list(hwnd, IDC_L_TABLE_INFO);
			table_list.SetSelectAndGrid(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
			table_list.InsertColumn(1,80,"房间名称");
			table_list.InsertColumn(2,100,"台    号");
			table_list.InsertColumn(2,60,"人    数");
			try {

				InitFloorName(hwnd, IDC_TABLE_FLOOR_COMBO);//初始化左边第一个“楼层”下拉列表
				InitFloorName(hwnd, IDC_C_FLOOR_NAME);//初始化游标第二个“楼层”下拉列表
				CComboBox floor_combo(hwnd, IDC_TABLE_FLOOR_COMBO);
				std::string floor_name;
				floor_combo.GetComboBoxText(floor_name);
			    InitTableList(hwnd, IDC_L_TABLE_INFO, floor_name.c_str(), 0);
				InitRoomCombo(hwnd,floor_name.c_str(),IDC_C_ROOM_NAME);//根据楼层名,初始化房间下拉列表
			} catch (Err &err) {
				MessageBox(hwnd, err.what(), TEXT("基础信息管理"), MB_ICONERROR);
				return FALSE;
			}
			return TRUE;
		}
	case  WM_NOTIFY:
		{
			switch(LOWORD(wParam))
			{
			case IDC_L_TABLE_INFO:
				{
					if (((LPNMHDR)lParam)->code == NM_CLICK){      // 点击列表中的一项
						int index = -1;
						CEdit num, no;
						CComboBox room_name, floor_name;
						CListView table_list;
						table_list.Initialization(hwnd, IDC_L_TABLE_INFO);
						index = table_list.GetSelectionMark();
						if (-1 == index) {
							MessageBox(hwnd, TEXT("请先在左侧选择一个台号!"), TEXT("基础信息管理"), MB_ICONINFORMATION);
							break;
						}
						
						room_name.Initialization(hwnd, IDC_C_ROOM_NAME);
						no.Initialization(hwnd, IDC_E_TABLE_NO);
						num.Initialization(hwnd, IDC_E_TABLE_NUM);
						CComboBox combo(hwnd, IDC_TABLE_FLOOR_COMBO);
						std::string name;
						combo.GetComboBoxText(name);
						floor_name.Initialization(hwnd, IDC_C_FLOOR_NAME);
						floor_name.DeleteAllString();
						InitFloorName(hwnd,IDC_C_FLOOR_NAME);
					    floor_name.SetCurSel(floor_name.FindString(name.c_str()));
						
						InitRoomCombo(hwnd,name.c_str(),IDC_C_ROOM_NAME);
						room_name.SetCurSel(room_name.FindString(table_list.GetItem(index, 0).c_str()));
						no.SetEditText(table_list.GetItem(index, 1).c_str());
						num.SetEditText(table_list.GetItem(index, 2).c_str());
					}
					break;
				}
			}
			return TRUE;
		}
	case WM_COMMAND:
		{
			switch (LOWORD(wParam))
			{
			case IDC_B_ADD_TABLE:
				{
					try {
					    if(AddTable(hwnd))
						{
							MessageBox(hwnd, TEXT("添加台号信息成功"), TEXT("基础信息管理 "), MB_ICONINFORMATION);
						}
					} catch (Err &err) {
						MessageBox(hwnd, err.what(), TEXT("基础信息管理 "), MB_ICONERROR);
						return FALSE;
					}
					break;
				}
			case IDC_B_DISHPATCH_TABLE:
				{
					try
					{
						if (UpdateTable(hwnd))
						{
							MessageBox(hwnd, TEXT("修改台号信息成功"), TEXT("基础信息管理"), MB_OK);
						}
					}
					catch (Err &err)
					{
						MessageBox(hwnd, err.what(), TEXT("基础信息管理"), MB_ICONERROR);
					}
					break;
				}
			case IDC_B_DELETE_TABLE:
				{
				try
					{
						if (DeleteTable(hwnd))
						{
								MessageBox(hwnd, TEXT("删除台号信息成功"), TEXT("基础信息管理"), MB_OK);
						}
					}
					catch (Err &err)
					{
						MessageBox(hwnd, err.what(), TEXT("基础信息管理"), MB_ICONERROR);
					}
					break;
				}
			case IDC_TABLE_FLOOR_COMBO://点击左边第一个”楼层“下拉列表
				{
					if (HIWORD(wParam) == CBN_SELCHANGE) {
						try {
							CComboBox combo(hwnd, IDC_TABLE_FLOOR_COMBO);
							std::string floor_name;
							combo.GetComboBoxText(floor_name);
							CComboBox room(hwnd, IDC_C_ROOM_NAME);
							room.DeleteAllString();//清空“房间”下拉列表,然后在插入新的数据
							InitTableList(hwnd, IDC_L_TABLE_INFO, floor_name.c_str(), 0);
						} catch (Err &err) {
							MessageBox(hwnd, err.what(), TEXT("基础信息管理"), MB_ICONERROR);
							return FALSE;
						}
					    CEdit edit;
						// 清空右侧编辑框数据
						edit.Initialization(hwnd, IDC_E_TABLE_NO);
						edit.Empty();
						edit.Initialization(hwnd, IDC_E_TABLE_NUM);
						edit.Empty();
					}
					break;
				}
			case IDC_C_FLOOR_NAME://点击第二个“楼层”下拉列表
				{
					if (HIWORD(wParam) == CBN_SELCHANGE)
					{
						try
						{
							CComboBox combo(hwnd, IDC_C_FLOOR_NAME);
							std::string floor_name_str;
							combo.GetComboBoxText(floor_name_str);
							CComboBox room_name(hwnd, IDC_C_ROOM_NAME);
							RoomInfo room_info;
							room_info.GetRoomName(floor_name_str.c_str());  // 获取楼层下的房间名称记录集
							room_name.DeleteAllString();
							while (!room_info.IsEOF())
							{
								room_name.AddString(room_info.room_name());
							} 
						}
						catch (Err &err)
						{
							MessageBox(hwnd, err.what(), TEXT("基础信息管理"), MB_ICONERROR);
							return FALSE;
						}			
					}
					break;
				}	
			case IDC_B_TABLE_CANCLE:
				{
					EndDialog(hwnd,0);
					break;
				}

			}	

			return TRUE;
		}
	case WM_CLOSE:
		{
			EndDialog(hwnd,0);
			return TRUE;
		}
	}
	return FALSE;
}