/* * Idea by: Cris Jacobin <*****@*****.**> */ room_rnum duplicate_room(room_vnum dest_vnum, room_rnum orig) { int new_rnum, znum; struct room_data nroom; if (orig == NOWHERE || orig > top_of_world) { log("SYSERR: GenOLC: copy_room: Given bad original real room."); return -1; } else if ((znum = real_zone_by_thing(dest_vnum)) == NOWHERE) { log("SYSERR: GenOLC: copy_room: No such destination zone."); return -1; } /* * add_room will make its own copies of strings. */ if ((new_rnum = add_room(&nroom)) == NOWHERE) { log("SYSERR: GenOLC: copy_room: Problem adding room."); return -1; } nroom = world[new_rnum]; nroom.number = dest_vnum; nroom.zone = znum; /* So the people and objects aren't in two places at once... */ nroom.contents = NULL; nroom.people = NULL; return new_rnum; }
void get_rooms(t_env *env) { t_args *tmp; char start; char end; t_args *prev; tmp = env->a_start; while (tmp) { if (start != 1 && tmp != env->a_start) start = is_start(prev); if (end != 1 && tmp != env->a_start) end = is_end(prev); if (is_room(tmp, env, 1) != -1) { add_room(env, ft_strsplit(tmp->data, ' '), start, end); start = 0; end = 0; } else if (is_command(tmp) != 1 && is_com(tmp) != 1 && \ is_ants(tmp, env) != 1) break ; prev = tmp; tmp = tmp->next; } }
//------ user functions -------- //params: u_id, sp_id, room int add_user(char* u_id,char* sp_id,char* name) { room_node* q = find_room(name); if (q == NULL){ add_room(name); q = find_room(name); } if (q->num_users > 0 && strcmp(q->users->u_id,u_id) == 0) { if (strcmp(q->users->sp_ids->sp_id,sp_id) == 0) //duplicate return 0; sp_id_node* sp_iter = q->users->sp_ids; for (; sp_iter->next != NULL; sp_iter = sp_iter->next) { if (strcmp(sp_iter->next->sp_id,sp_id) == 0) return 0; } sp_id_node* insert = malloc(sizeof(sp_id_node)); strcpy(insert->sp_id,sp_id); insert->next = NULL; insert->prev = sp_iter; sp_iter->next = insert; q->users->next->num_ids++; return 1; } user_node* u_iter = q->users; for (; q->users != NULL && u_iter->next != NULL; u_iter = u_iter->next) { if (strcmp(u_id,u_iter->next->u_id) == 0) { if (strcmp(u_iter->next->sp_ids->sp_id,sp_id) == 0) //duplicate return 0; sp_id_node* sp_iter = u_iter->next->sp_ids; for (; sp_iter->next != NULL; sp_iter = sp_iter->next) { if (strcmp(sp_iter->next->sp_id,sp_id) == 0) return 0; } sp_id_node* insert = malloc(sizeof(sp_id_node)); strcpy(insert->sp_id,sp_id); insert->next = NULL; insert->prev = sp_iter; sp_iter->next = insert; u_iter->next->num_ids++; return 1; } } user_node* insert = malloc(sizeof(user_node)); strcpy(insert->u_id,u_id); sp_id_node* sin = malloc(sizeof(sp_id_node)); strcpy(sin->sp_id,sp_id); insert->sp_ids = sin; insert->num_ids = 1; if (q->num_users == 0) q->users = insert; else { insert->next = u_iter->next; u_iter->next = insert; insert->prev = u_iter; } q->num_users++; return 1; }
void on_get_room_info (int fd, struct message *msg) { printf ("on_get_room_info\n"); struct room_info room; memcpy (&room, msg->buff, sizeof (room)); add_room (&room); }
void on_update_room (int fd, struct message *msg) { printf ("on_update_room\n"); struct room_info troom; memcpy (&troom, msg->buff, sizeof (troom)); del_room (troom.index); if (troom.state1 != EMPTY || troom.state2 != EMPTY) add_room (&troom); }
static gboolean find_rooms (gpointer data) { TpTestsRoomListChan *self = TP_TESTS_ROOM_LIST_CHAN (data); GPtrArray *rooms; rooms = g_ptr_array_new_with_free_func ((GDestroyNotify) g_value_array_free); /* Find 2 rooms */ add_room (rooms); add_room (rooms); tp_svc_channel_type_room_list_emit_got_rooms (self, rooms); g_ptr_array_set_size (rooms, 0); /* Find 1 room */ add_room (rooms); tp_svc_channel_type_room_list_emit_got_rooms (self, rooms); g_ptr_array_unref (rooms); return FALSE; }
//------ msg functions -------- //params: msg_timestamp, u_id, room, mess int add_msg(lamport* ts, char* u_id, char* room, char* mess){ room_node* root = find_room(room); if (root == NULL) { add_room(room); root = find_room(room); } msg_node* insert = malloc(sizeof(msg_node)); insert->timestamp = ts; strcpy(insert->mess,mess); strcpy(insert->u_id,u_id); insert->num_likes = 0; //check if first in chatroom if (root->num_msgs == 0) { insert->prev = NULL; insert->next = NULL; root->msgs = insert; root->num_msgs++; return 1; } //check if oldest message if (cmp_timestamp(ts,root->msgs->timestamp) < 0) { insert->prev = NULL; insert->next = root->msgs; insert->next->prev = insert; root->msgs = insert; root->num_msgs++; return 1; } //check all other msg for where next->ts > insert msg_node* iter = root->msgs; for (; iter->next != NULL; iter = iter->next) { // next is newer than insert if (cmp_timestamp(ts,iter->next->timestamp) < 0) { insert->next = iter->next; insert->prev = iter; iter->next = insert; insert->next->prev = insert; root->num_msgs++; return 1; } else if (cmp_timestamp(ts,iter->next->timestamp) == 0) return 0; } //insert is newest insert->prev = iter; insert->next = NULL; iter->next = insert; root->num_msgs++; return 1; }
TEST(Map, AddRoom) { auto test_map = tez::map(10, 20); std::default_random_engine random(1984); tez::room test_room = tez::simple_room_generator(bklib::make_random_wrapper(random)).generate(); test_map.add_room(test_room, 0, 0); for (auto const& i : test_room) { EXPECT_EQ(*i, test_map.at(i.x, i.y).type); } }
int check_room(t_lem_env *env, char *s) { if (is_link(s) && env->fonction[env->r.state + 1](env, s)) return (ft_add_state(env)); if (ft_strcmp("##start", s) == 0 && check_start(env, s)) return (1); if (ft_strcmp("##end", s) == 0 && check_end(env, s)) return (1); if (is_room(s) && add_room(env, s)) { env->r.nbline += add_file(env, s); return (1); } return (ft_error(env, 1)); }
static void generate_rooms(cell_t *cell_array, room_t *room_array, int *total_rooms) { int result; room_t *current_room; while((*total_rooms) < MAX_ROOMS) { current_room = room_array + (*total_rooms); result = add_room(cell_array , current_room); if(result == 0) { add_room_to_map(cell_array, current_room); (*total_rooms)++; } else if((*total_rooms) >= MIN_ROOMS) { return; } } }
void Lobby_Layer::show_app_list() { if (!room_list_view_) { return; } room_list_view_->removeAllChildren(); size_t n = room_list_.size(); if (n >0 && n < 3 ) { room_list_view_->setContentSize(Size (n * 240, 200)); } for (auto i : room_list_) { add_room(room_list_view_, i.c_str()); } }
void cre(int socket, char *roomname) { char *name; if ((name = malloc(sizeof(char)*strlen(roomname))) == NULL) { perror("Malloc failed"); write(socket, "Server: there was an error. Please, resend your message.", MAX_PACK_SIZE); return; } memset(name, 0, strlen(name)); strcpy(name, roomname); box *temp; if ((temp = get_room(rooms, name)) != NULL) { write(socket, "Room already exists", MAX_PACK_SIZE); return; } temp = NULL; if ((temp = add_room(rooms, name)) == NULL) { write(socket, "Problem creating room", MAX_PACK_SIZE); return; } }
void makeroguerooms(struct level *lev) { int x,y; /* Rogue levels are structured 3 by 3, with each section containing * a room or an intersection. The minimum width is 2 each way. * One difference between these and "real" Rogue levels: real Rogue * uses 24 rows and NitroHack only 23. So we cheat a bit by making the * second row of rooms not as deep. * * Each normal space has 6/7 rows and 25 columns in which a room may * actually be placed. Walls go from rows 0-5/6 and columns 0-24. * Not counting walls, the room may go in * rows 1-5 and columns 1-23 (numbering starting at 0). A room * coordinate of this type may be converted to a level coordinate * by adding 1+28*x to the column, and 7*y to the row. (The 1 * is because column 0 isn't used [we only use 1-78]). * Room height may be 2-4 (2-5 on last row), length 2-23 (not * counting walls) */ #define here r[x][y] lev->nroom = 0; for (y=0; y<3; y++) for(x=0; x<3; x++) { /* Note: we want to insure at least 1 room. So, if the * first 8 are all dummies, force the last to be a room. */ if (!rn2(5) && (lev->nroom || (x<2 && y<2))) { /* Arbitrary: dummy rooms may only go where real * ones do. */ here.real = FALSE; here.rlx = rn1(22, 2); here.rly = rn1((y==2)?4:3, 2); } else { here.real = TRUE; here.dx = rn1(22, 2); /* 2-23 long, plus walls */ here.dy = rn1((y==2)?4:3, 2); /* 2-5 high, plus walls */ /* boundaries of room floor */ here.rlx = rnd(23 - here.dx + 1); here.rly = rnd(((y==2) ? 5 : 4)- here.dy + 1); lev->nroom++; } here.doortable = 0; } miniwalk(rn2(3), rn2(3)); lev->nroom = 0; for (y=0; y<3; y++) for(x=0; x<3; x++) { if (here.real) { /* Make a room */ int lowx, lowy, hix, hiy; r[x][y].nroom = lev->nroom; smeq[lev->nroom] = lev->nroom; lowx = 1 + 26*x + here.rlx; lowy = 7*y + here.rly; hix = 1 + 26*x + here.rlx + here.dx - 1; hiy = 7*y + here.rly + here.dy - 1; /* Strictly speaking, it should be lit only if above * level 10, but since Rogue rooms are only * encountered below level 10, use !rn2(7). */ add_room(lev, lowx, lowy, hix, hiy, (boolean) !rn2(7), OROOM, FALSE); } } /* Now, add connecting corridors. */ for (y=0; y<3; y++) for(x=0; x<3; x++) { if (here.doortable & DOWN) roguecorr(lev, x, y, DOWN); if (here.doortable & RIGHT) roguecorr(lev, x, y, RIGHT); if (here.doortable & LEFT) impossible ("left end of %d, %d never connected?",x,y); if (here.doortable & UP) impossible ("up end of %d, %d never connected?",x,y); } }
static void User_command() { char command[130]; char client_group[13]; char mess[SPREAD_MESS_LEN]; char group[MAX_ROOM_LEN - strlen("CR#_")]; char groups[10][MAX_GROUP_NAME]; int num_groups; unsigned int mess_len; int ret; int srv; int i; for( i=0; i < sizeof(command); i++ ) command[i] = 0; if( fgets( command, 130, stdin ) == NULL ) Bye(); switch( command[0] ) { case 'u': ret = sscanf( &command[2], "%s", u_id); if (ret < 1 ) printf("invalid username\n"); break; case 'c': ret = sscanf( &command[2], "%d", &srv); if ( ret < 1 || isValidServer(srv) != 1) { //isValid sets server_num printf("invalid server index\n"); break; } ret = sprintf( client_group, "client_group%d",server_num); if (ret < 1) { printf("Error connecting to server-client group\n"); break; } ret = SP_join(Mbox, client_group); if (ret < 0) SP_error( ret ); sprintf( server_priv_group, "server%d", server_num); break; case 'j': //check if already in room if (strlen(chatroom) > 0) { clear_room(chatroom); } else { ret = sscanf( &command[2], "%s", chatroom ); if( ret < 1 ) { printf(" invalid chatroom name \n"); break;} add_room(chatroom); } if (strlen(u_id) > 0 && isValidServer(server_num)) { //need valid username + server for chatroom ret = sprintf ( group, "%s%d_%s","CR",server_num,chatroom); if (ret < 1) { printf("Error creating chatroom name <%s> from group <%s>\n",chatroom,group); break; } ret = SP_join( Mbox, group ); //join CR#_<group> spread group if( ret < 0 ) SP_error( ret ); } else { printf("Invalid username or server number, cannot join chatroom\n"); break;} join_chatroom* send = (join_chatroom*)mess; send->type = TYPE_JOIN_CHATROOM; send->source = SOURCE_CLIENT; strncpy(send->u_id,u_id,MAX_NAME_LEN); strncpy(send->chatroom,chatroom,MAX_ROOM_LEN); //send <group> as chatroom spread name ret = SP_multicast( Mbox, AGREED_MESS, server_priv_group, 1, sizeof(join_chatroom), mess ); if( ret < 0 ) { SP_error( ret ); Bye(); } break; /* case 'x':{ char ms[6]; add_room(chatroom); set_max_msgs(25); int maxi = 40; for (int i = 1; i <= maxi;i++) { struct lamport* ts = malloc(sizeof(lamport)); ts->server_id = 1; ts->index = i; sprintf(ms,"%s%d","asdfd",i); add_message(ts,u_id,chatroom,ms); if (i % 3 == 0 || i % 4 == 1 || i % 6 == 2) { i++; maxi++; struct lamport* ls = malloc(sizeof(lamport)); ls->server_id = 1; ls->index = i; add_like(LIKE,ls,u_id,chatroom,ts); if (i % 6 == 2){ i++;maxi++; char newu[MAX_NAME_LEN]; sprintf(newu,"%sx",u_id); struct lamport* qs = malloc(sizeof(lamport)); qs->server_id = 1; qs->index = i; add_like(LIKE,qs,newu,chatroom,ts); } } if (i % 4 == 1) { i++; maxi++; struct lamport* ls = malloc(sizeof(lamport)); ls->server_id = 1; ls->index = i; add_like(UNLIKE,ls,u_id,chatroom,ts); } } printf("== %s ==\n",chatroom); print_room(chatroom); break;} */ case 'a': { char text[MAX_MESS_LEN]; printf("enter message: "); if (fgets(text, MAX_MESS_LEN, stdin) == NULL) Bye(); if (strlen(chatroom) < 1){ printf("Please join a chatroom\n"); break; } message* dat = (message*)mess; dat->type = TYPE_SEND_MSG; dat->source = SOURCE_CLIENT; strncpy(dat->u_id,u_id,MAX_NAME_LEN); strncpy(dat->chatroom,chatroom,MAX_ROOM_LEN); strncpy(dat->mess,text,MAX_MESS_LEN); ret= SP_multicast( Mbox, AGREED_MESS, server_priv_group, 1, sizeof(message), mess ); if( ret < 0 ) { SP_error( ret ); Bye(); } break; } case 'l': { if (strlen(chatroom) < 1){ printf("Please join a chatroom\n"); break;} int linenum; ret = sscanf( &command[2], "%d", &linenum ); printf("Liking line %d.....\n",linenum); if( ret < 1 ) { printf(" invalid linenum \n"); break;} lamport* stamp = get_msg_stamp(linenum); printf("%d. index %d?\n",linenum,stamp->index); like* dat = (like*)mess; dat->type = TYPE_LIKE_MSG; dat->source = SOURCE_CLIENT; dat->msg_timestamp.server_id = stamp->server_id; dat->msg_timestamp.index = stamp->index; strncpy(dat->u_id,u_id,MAX_NAME_LEN); strncpy(dat->chatroom,chatroom,MAX_ROOM_LEN); dat->like_state = LIKE; ret = SP_multicast( Mbox, AGREED_MESS, server_priv_group, 1, sizeof(like), mess); if (ret < 0) { SP_error(ret); Bye; } break; } case 'r': { if (strlen(chatroom) < 1){ printf("Please join a chatroom\n"); break;} int linenum; ret = sscanf( &command[2], "%d", linenum ); if( ret < 1 ) { printf(" invalid linenum \n"); break;} lamport* stamp = get_msg_stamp(linenum); printf("%d. index %d?\n",linenum,stamp->index); like* dat = (like*)mess; dat->type = TYPE_LIKE_MSG; dat->source = SOURCE_CLIENT; dat->msg_timestamp.server_id = stamp->server_id; dat->msg_timestamp.index = stamp->index; strncpy(dat->u_id,u_id,MAX_NAME_LEN); strncpy(dat->chatroom,chatroom,MAX_ROOM_LEN); dat->like_state = UNLIKE; ret = SP_multicast( Mbox, AGREED_MESS, server_priv_group, 1, sizeof(like), mess); if (ret < 0) { SP_error(ret); Bye; } break; } case 'h': printf("history not implemented\n"); break; case 'v': printf("network view not implemented\n"); break; case 'q': Bye(); break; default: printf("\nUnknown commnad\n"); Print_menu(); break; } printf(" \n > "); fflush(stdout); }
static void Read_message() { static char mess[SPREAD_MESS_LEN]; char sender[MAX_GROUP_NAME]; char target_groups[MAX_MEMBERS][MAX_GROUP_NAME]; membership_info memb_info; vs_set_info vssets[MAX_VSSETS]; unsigned int my_vsset_index; int num_vs_sets; char members[MAX_MEMBERS][MAX_GROUP_NAME]; int num_groups; int service_type; int16 mess_type; int endian_mismatch; int i,j; int ret; service_type = 0; ret = SP_receive( Mbox, &service_type, sender, 100, &num_groups, target_groups, &mess_type, &endian_mismatch, sizeof(mess), mess ); if( ret < 0 ) { if ( (ret == GROUPS_TOO_SHORT) || (ret == BUFFER_TOO_SHORT) ) { service_type = DROP_RECV; printf("\n========Buffers or Groups too Short=======\n"); ret = SP_receive( Mbox, &service_type, sender, MAX_MEMBERS, &num_groups, target_groups, &mess_type, &endian_mismatch, sizeof(mess), mess ); } } if (ret < 0 ) { if( ! To_exit ) { SP_error( ret ); printf("\n============================\n"); printf("\nBye.\n"); } exit( 0 ); } if( Is_regular_mess( service_type ) ) { //printf("message from %s, of type %d, (endian %d) to %d groups \n(%d bytes): %s\n", sender, mess_type, endian_mismatch, num_groups, ret, mess ); typecheck* type = (typecheck*)mess; if (type->type == TYPE_JOIN_CHATROOM) { join_chatroom* dat = (join_chatroom*)mess; ret = add_user(dat->u_id,dat->sp_id,dat->chatroom); } else if (type->type == TYPE_LEAVE_CHATROOM) { leave_chatroom* dat = (leave_chatroom*)mess; rm_user(dat->sp_id); } else if (type->type == TYPE_SEND_MSG) { message* dat = (message*)mess; if (strlen(chatroom) == 0) add_room(chatroom); lamport* ts = malloc(sizeof(lamport)); ts->server_id = dat->timestamp.server_id; ts->index = dat->timestamp.index; printf("[%d,%d]\n",ts->server_id,ts->index); add_message(ts, dat->u_id, dat->chatroom, dat->mess); } else if (type->type == TYPE_LIKE_MSG) { like* dat = (like*)mess; lamport* lts = malloc(sizeof(lamport)); lamport* mts = malloc(sizeof(lamport)); lts->server_id = dat->timestamp.server_id; lts->index = dat->timestamp.index; mts->server_id = dat->timestamp.server_id; mts->index = dat->timestamp.index; ret = add_like(dat->like_state, lts, dat->u_id, chatroom, mts); printf("~~~~~~~~ %d:[%d,%d | %d,%d] %d %s %s \n",ret, lts->server_id,lts->index,mts->server_id,mts->index,dat->like_state,dat->u_id,chatroom); } master_print(); }else if( Is_membership_mess( service_type ) ) { ret = SP_get_memb_info( mess, service_type, &memb_info ); if (ret < 0) { printf("BUG: membership message does not have valid body\n"); SP_error( ret ); exit( 1 ); } if ( Is_reg_memb_mess( service_type ) ) { printf("Received REGULAR membership for group %s with %d members, where I am member %d:\n", sender, num_groups, mess_type ); for( i=0; i < num_groups; i++ ) printf("\t%s\n", &target_groups[i][0] ); printf("grp id is %d %d %d\n",memb_info.gid.id[0], memb_info.gid.id[1], memb_info.gid.id[2] ); if( Is_caused_join_mess( service_type ) ) { printf("Due to the JOIN of %s\n", memb_info.changed_member ); }else if( Is_caused_leave_mess( service_type ) ){ printf("Due to the LEAVE of %s\n", memb_info.changed_member ); }else if( Is_caused_disconnect_mess( service_type ) ){ printf("Due to the DISCONNECT of %s\n", memb_info.changed_member ); }else if( Is_caused_network_mess( service_type ) ){ printf("Due to NETWORK change with %u VS sets\n", memb_info.num_vs_sets); num_vs_sets = SP_get_vs_sets_info( mess, &vssets[0], MAX_VSSETS, &my_vsset_index ); if (num_vs_sets < 0) { printf("BUG: membership message has more then %d vs sets. Recompile with larger MAX_VSSETS\n", MAX_VSSETS); SP_error( num_vs_sets ); exit( 1 ); } for( i = 0; i < num_vs_sets; i++ ) { printf("%s VS set %d has %u members:\n", (i == my_vsset_index) ? ("LOCAL") : ("OTHER"), i, vssets[i].num_members ); ret = SP_get_vs_set_members(mess, &vssets[i], members, MAX_MEMBERS); if (ret < 0) { printf("VS Set has more then %d members. Recompile with larger MAX_MEMBERS\n", MAX_MEMBERS); SP_error( ret ); exit( 1 ); } for( j = 0; j < vssets[i].num_members; j++ ) printf("\t%s\n", members[j] ); } } }else if( Is_transition_mess( service_type ) ) { printf("received TRANSITIONAL membership for group %s\n", sender ); }else if( Is_caused_leave_mess( service_type ) ){ printf("received membership message that left group %s\n", sender ); }else printf("received incorrecty membership message of type 0x%x\n", service_type ); } else if ( Is_reject_mess( service_type ) ) { printf("REJECTED message from %s, of servicetype 0x%x messtype %d, (endian %d) to %d groups \n(%d bytes): %s\n", sender, service_type, mess_type, endian_mismatch, num_groups, ret, mess ); }else printf("received message of unknown message type 0x%x with ret %d\n", service_type, ret); printf("\n"); fflush(stdout); }
int main(int argc, char **argv) { int key; t_map *g_map; t_game *snake; srand(time(NULL)); if (argc < 3) return (-1); snake = malloc(sizeof(t_game)); g_map = malloc(sizeof(t_map)); g_map->x_max = ft_atoi(argv[2]); g_map->y_max = ft_atoi(argv[1]); if (g_map->x_max < 3 || g_map->y_max < 3) return (-1); g_map->x_map = rand_a_b(3, g_map->x_max + 1); g_map->y_map = rand_a_b(3, g_map->y_max + 1); // ft_putnbr(g_map->x_map); // ft_putchar('\n'); // ft_putnbr(g_map->y_map); // ft_putchar('\n'); snake->x_s = 1; snake->y_s = 1; // ft_putnbr(snake->x_s); // ft_putchar('\n'); // ft_putnbr(snake->y_s); // ft_putchar('\n'); snake->pv_s = 13; g_map->map = map_create(g_map->x_map, g_map->y_map); ft_putendl("placement du heros"); g_map->map[snake->x_s][snake->y_s] = 's'; ft_putendl("affichage"); //free_all(snake, g_map); while (1) { key = 2; key = getarrowkey(); aff_map(g_map); aff_pv(snake); ft_putstr("POSITION:"); ft_putnbr(snake->x_s); ft_putchar(' '); ft_putnbr(snake->y_s); ft_putchar('\n'); ft_putstr("MAP"); ft_putnbr(g_map->x_map); ft_putchar(' '); ft_putnbr(g_map->x_map); if (key == 1) { if (go_left(snake, g_map)) { add_room(g_map); g_map = g_map->next; } } else if (key == 2) { if (go_up(snake, g_map)) { add_room(g_map); g_map = g_map->next; } } else if (key == 3) { if (go_down(snake, g_map)) { add_room(g_map); g_map = g_map->next; } } else if (key == 4) { if (go_right(snake, g_map)) { add_room(g_map); g_map = g_map->next; } } else if (key == 5) { free_all(snake, g_map); return (0); } usleep(100000); system("CLEAR"); } return (0); }
int main() { fp = fopen("log.txt", "w"); log_time(); fprintf(fp, "Start Programm\n"); int target_floor, target_room; int view_flag = 1; building *building_list = (building *) malloc(sizeof(building)); log_time(); fprintf(fp, "init building_list\n"); init(building_list); add_floor(building_list, FALSE); add_room(building_list, FALSE); add_room(building_list, FALSE); add_room(building_list, FALSE); while (1) { fflush(fp); if (view_flag) view_building(building_list, TRUE); else { view_room(building_list, target_floor, target_room); } switch (input_cmd()) { case 1: { // [1] 건물 확장 switch (input_extend_cmd()) { case 1: { // [1] 층 확장 add_floor(building_list, TRUE); break; } case 2: { // [2] 방 확장 add_room(building_list, TRUE); break; } } break; } case 2: { // [2] View 변환 if (view_flag) { printf("특정 방 내부 보여주기 로 View가 변환되었습니다.\n"); printf("층과 호수를 입력하세요\n"); if (tts_flag) { system("pico2wave -w test.wav \"Translated the view into the specific room viewing.\""); system("aplay -q test.wav"); system("pico2wave -w test.wav \"Input floor number and room number\""); system("aplay -q test.wav"); } scanf("%d %d", &target_floor, &target_room); view_flag = 0; } else { printf("전체 방 보여주기 로 View가 변환되었습니다.\n"); if (tts_flag) { system("pico2wave -w test.wav \"Translated the view into the total room viewing.\""); system("aplay -q test.wav"); } view_flag = 1; } break; } case 3: { // [3] 방 별 칸 변환 change_space(building_list); break; } case 4: { // [4] 칸 별 사람 이름 변환 change_name(building_list); break; } case 5: { search_name(building_list); break; } case 6: { // [6] TTS ON/OFF if (tts_flag) { printf("TTS를 사용하지않습니다.\n"); tts_flag = 0; } else { printf("TTS를 사용합니다.\n"); system("pico2wave -w test.wav \"From now, Use text to speach.\""); system("aplay -q test.wav"); tts_flag = 1; } break; } case 7: { // [5] 종료 printf("\n프로그램을 종료합니다.\n"); if (tts_flag) { system("pico2wave -w test.wav \"Exit Program.\""); system("aplay -q test.wav"); } return 0; break; } } } return 0; }
static void join_map(struct level *lev, schar bg_typ, schar fg_typ) { struct mkroom *croom, *croom2; int i, j; int sx, sy; coord sm, em; enum rng rng = rng_for_level(&lev->z); /* first, use flood filling to find all of the regions that need joining */ for (i = 1; i <= WIDTH; i++) for (j = 1; j < HEIGHT; j++) { if (lev->locations[i][j].typ == fg_typ && lev->locations[i][j].roomno == NO_ROOM) { min_rx = max_rx = i; min_ry = max_ry = j; n_loc_filled = 0; flood_fill_rm(lev, i, j, lev->nroom + ROOMOFFSET, FALSE, FALSE); if (n_loc_filled > 3) { add_room(lev, min_rx, min_ry, max_rx, max_ry, FALSE, OROOM, TRUE); lev->rooms[lev->nroom - 1].irregular = TRUE; if (lev->nroom >= (MAXNROFROOMS * 2)) goto joinm; } else { /* * it's a tiny hole; erase it from the map to avoid * having the player end up here with no way out. */ for (sx = min_rx; sx <= max_rx; sx++) for (sy = min_ry; sy <= max_ry; sy++) if ((int)lev->locations[sx][sy].roomno == lev->nroom + ROOMOFFSET) { lev->locations[sx][sy].typ = bg_typ; lev->locations[sx][sy].roomno = NO_ROOM; } } } } joinm: /* * Ok, now we can actually join the regions with fg_typ's. * The rooms are already sorted due to the previous loop, * so don't call sort_rooms(), which can screw up the roomno's * validity in the level->locations structure. */ for (croom = &lev->rooms[0], croom2 = croom + 1; croom2 < &lev->rooms[lev->nroom];) { /* pick random starting and end locations for "corridor" */ if (!somexy(lev, croom, &sm, rng) || !somexy(lev, croom2, &em, rng)) { /* ack! -- the level is going to be busted */ /* arbitrarily pick centers of both rooms and hope for the best */ impossible("No start/end room loc in join_map."); sm.x = croom->lx + ((croom->hx - croom->lx) / 2); sm.y = croom->ly + ((croom->hy - croom->ly) / 2); em.x = croom2->lx + ((croom2->hx - croom2->lx) / 2); em.y = croom2->ly + ((croom2->hy - croom2->ly) / 2); } dig_corridor(lev, &sm, &em, FALSE, fg_typ, bg_typ); /* choose next region to join */ /* only increment croom if croom and croom2 are non-overlapping */ if (croom2->lx > croom->hx || ((croom2->ly > croom->hy || croom2->hy < croom->ly) && mklev_rn2(3, lev))) { croom = croom2; } croom2++; /* always increment the next room */ } }
/* * Idea by: Cris Jacobin <*****@*****.**> */ room_rnum duplicate_room(room_vnum dest_vnum, room_rnum orig) { int new_rnum, znum; struct room_data nroom; #if CIRCLE_UNSIGNED_INDEX if (orig == NOWHERE || orig > top_of_world) { #else if (orig < 0 || orig > top_of_world) { #endif log("SYSERR: GenOLC: copy_room: Given bad original real room."); return NOWHERE; } else if ((znum = real_zone_by_thing(dest_vnum)) == NOWHERE) { log("SYSERR: GenOLC: copy_room: No such destination zone."); return NOWHERE; } /* * add_room will make its own copies of strings. */ if ((new_rnum = add_room(&nroom)) == NOWHERE) { log("SYSERR: GenOLC: copy_room: Problem adding room."); return NOWHERE; } nroom = world[new_rnum]; nroom.number = dest_vnum; nroom.zone = znum; /* So the people and objects aren't in two places at once... */ nroom.contents = NULL; nroom.people = NULL; return new_rnum; } /* -------------------------------------------------------------------------- */ /* * Copy strings over so bad things don't happen. We do not free the * existing strings here because copy_room() did a shallow copy previously * and we'd be freeing the very strings we're copying. If this function * is used elsewhere, be sure to free_room_strings() the 'dest' room first. */ int copy_room_strings(struct room_data *dest, struct room_data *source) { int i; if (dest == NULL || source == NULL) { log("SYSERR: GenOLC: copy_room_strings: NULL values passed."); return FALSE; } dest->description = str_udup(source->description); dest->name = str_udup(source->name); for (i = 0; i < NUM_OF_DIRS; i++) { if (!R_EXIT(source, i)) continue; CREATE(R_EXIT(dest, i), struct room_direction_data, 1); *R_EXIT(dest, i) = *R_EXIT(source, i); if (R_EXIT(source, i)->general_description) R_EXIT(dest, i)->general_description = strdup(R_EXIT(source, i)->general_description); if (R_EXIT(source, i)->keyword) R_EXIT(dest, i)->keyword = strdup(R_EXIT(source, i)->keyword); } if (source->ex_description) copy_ex_descriptions(&dest->ex_description, source->ex_description); return TRUE; }