void read_stdin(t_lemin *l) { int i; char *line; char *prev; i = 0; line = NULL; prev = NULL; l->listrooms = NULL; l->listtubes = NULL; while (get_next_line(0, &line)) { if (line[0] != '#') { check_stdin(l, line, prev, i); i++; } prev = line; } link_rooms(l); define_rooms_weight(l); handle_stdout(l); lemin_loop(l); }
static void fill_rooms(t_arr *rooms, char *line, enum e_read status) { char *name; t_uint x; t_uint y; if (!ft_strchr(line, ' ')) { link_rooms(rooms, line); return ; } name = line; while (*line && *line != ' ') line++; if (!*line) error(E_INVALID, "Weird room."); *line++ = 0; x = (t_uint)ft_atoi(line); while (*line && *line != ' ') line++; if (!*line) error(E_INVALID, "Weird room."); y = (t_uint)ft_atoi(++line); ft_arrpush(rooms, new_room(name, x, y, status), status == R_START ? 0 : -1); }
void on_build() { object start_room, spawn; ROOM_MAP( 3, 4, 1, "ccc" "ccc" "aab" "aab") ROOM_KEY( "a", "start", "The Main Room", "This is the farmhouse's cozy living area." ) ROOM_KEY( "b", "pantry", "The Pantry", "A small side room where food is stored." ) ROOM_KEY( "c", "garden", "The Garden", "Behind the farmhouse is a small vegetable garden." ) start_room = find_room("start", this_object()); object silo = clone_object( "/scn/furni/veg_silo" ); silo->move( find_room("garden", this_object()) ); silo->set_coord( MAKE_C(1,1,0) ); make_outside_exit( start_room, MAKE_C(2,1,0) ); link_rooms( "start", "pantry", MAKE_C(11,3,0), "east" ); link_rooms( "pantry", "garden", MAKE_C(3,0,0), "north" ); object ob; ob = clone_object( "/scn/furni/larder" ); ob->move( find_room("pantry", this_object()) ); ob->set_x(2); ob->set_y(6); set_larder( ob ); spawn = clone_object( "/obj/work_spot" ); spawn->move( start_room ); spawn->set_work_name( "farmer" ); spawn->set_work_ai( "farmer" ); spawn->set_home( this_object() ); spawn->set_num_positions( 1 ); spawn->set_coord( MAKE_C(5,3,0) ); }
void WorldController::make_world() { mysqlpp::StoreQueryResult res; db::DBManager::get_instance()->get_zones(res); for (size_t i = 0; i < res.num_rows(); ++i) { Zone *z = new Zone(res[i][0], std::string(res[i][1].c_str()), std::string(res[i][2].c_str())); zones[res[i][0]] = z; } res.clear(); db::DBManager::get_instance()->get_rooms(res); for (size_t i = 0; i < res.num_rows(); ++i) { std::string name; std::string desc; if (res[i][2] == "NULL") { name = ""; } else { name = std::string(res[i][2].c_str()); } if (res[i][3] == "NULL") { desc = ""; } else { desc = std::string(res[i][3].c_str()); } Room *r = new Room(res[i][0], name, desc, zones[res[i][1]]); rooms[res[i][0]] = r; /** * Utilitzem un *petit hack* aqui. * 1) Problema a l'hora de crear totes les rooms: Per crear una room * que esta linkada amb un altre, necesitem tenir un punter a aquest * altre, per tant necesitem que aquesta altre ja estigui feta. * Que es abans, ou o gallina? => No es pot fer de cop. * 2) Solucio: primer es creen totes les rooms sense links, i despres * es linken. * 3) Problema: en la fase de creacio dels objectes rooms sense links, * que es l'unica vegada que es llegeix la bd, necesitem guardar la info * de quins links tenen cada room. Com ho fem? * - Utilitzar estrucutra de dades adicional: seria lo mes correcte, * pero menys pro. * - Aprofitar la clase Room modificanla una mica. Ara guarda un punter * per cada sortida que te, un punter a Room. El que necesitem * guardar es just aixo, per en comptes de punters a rooms hem de * guardar les id's de les rooms. * Pero aixi embrutariem la clase Room, que ja esta be. * - Aprofitar la clase Room sense modificarla, utilitzan directament * els punters a Room per guardar la nostra info (ids de rooms). * Al cap davall els punters son ints de 4 bytes, ja ens serveixen. * Pero el compilador es queixa una mica si li fiquem un int a pelo * sense ser un Room*, per aixo fem el cast. */ if (res[i][4] != mysqlpp::null) { int v = res[i][4]; r->add_exit("n", (Room *)v); } if (res[i][5] != mysqlpp::null) { int v = res[i][5]; r->add_exit("ne", (Room *)v); } if (res[i][6] != mysqlpp::null) { int v = res[i][6]; r->add_exit("e", (Room *)v); } if (res[i][7] != mysqlpp::null) { int v = res[i][7]; r->add_exit("se", (Room *)v); } if (res[i][8] != mysqlpp::null) { int v = res[i][8]; r->add_exit("s", (Room *)v); } if (res[i][9] != mysqlpp::null) { int v = res[i][9]; r->add_exit("so", (Room *)v); } if (res[i][10] != mysqlpp::null) { int v = res[i][10]; r->add_exit("o", (Room *)v); } if (res[i][11] != mysqlpp::null) { int v = res[i][11]; r->add_exit("no", (Room *)v); } } link_rooms(); }
/* Build link connections */ v_iterate(links, iter) { link = vl_iter_pval(iter); if (vh_iget(link, "NOLINK")) continue; if (vh_iget(link, "NOPATH")) continue; oneway = vh_iget(link, "ONEWAY"); len = vh_iget(link, "LEN"); if (len) uselen++; from = vh_pget(link, "FROM"); to = vh_pget(link, "TO"); /* From -> to */ reach = vh_create(); cmd = NULL; goflag = vh_iget(link, "GO"); dir = vh_iget(link, "TO_DIR"); if ((cmdto = vh_pget(link, "TO_CMD")) != NULL) { vh_pstore(reach, "CMD", cmdto); } else { if (goflag) cmd = dirinfo[goflag].sname; if (cmd == NULL) cmd = dirinfo[dir].sname; add_attr(reach, "CMD", cmd); } vh_pstore(reach, "FROM", from); vh_pstore(reach, "TO", to); vh_pstore(reach, "NEED", vh_pget(link, "NEED")); vh_pstore(reach, "BEFORE", vh_pget(link, "BEFORE")); vh_pstore(reach, "AFTER", vh_pget(link, "AFTER")); vh_istore(reach, "LEN", V_MAX(len, 1)); vh_pstore(reach, "LEAVE", vh_pget(link, "LEAVE")); vh_istore(reach, "LEAVEALL", vh_iget(link, "LEAVEALL")); link_rooms(from, to, reach); if (TASK_VERBOSE) { indent(1); list = vh_pget(reach, "CMD"); printf("link '%s' to '%s' (%s)", vh_sgetref(from, "DESC"), vh_sgetref(to, "DESC"), vl_join(list, ". ")); if (len > 1) printf(" (dist %d)", len); printf("\n"); } /* To -> from if not one-way */ if (!oneway) { reach = vh_create(); cmd = NULL; goflag = dirinfo[goflag].odir; dir = vh_iget(link, "FROM_DIR"); if ((cmdfrom = vh_pget(link, "FROM_CMD")) != NULL) { vh_pstore(reach, "CMD", cmdfrom); } else if (cmdto != NULL) { vh_pstore(reach, "CMD", cmdto); } else { if (goflag) cmd = dirinfo[goflag].sname; if (cmd == NULL) cmd = dirinfo[dir].sname; add_attr(reach, "CMD", cmd); } vh_pstore(reach, "FROM", to); vh_pstore(reach, "TO", from); vh_pstore(reach, "NEED", vh_pget(link, "NEED")); vh_pstore(reach, "BEFORE", vh_pget(link, "BEFORE")); vh_pstore(reach, "AFTER", vh_pget(link, "AFTER")); vh_pstore(reach, "LEAVE", vh_pget(link, "LEAVE")); vh_istore(reach, "LEAVEALL", vh_iget(link, "LEAVEALL")); vh_istore(reach, "LEN", V_MAX(len, 1)); link_rooms(to, from, reach); if (TASK_VERBOSE) { indent(1); list = vh_pget(reach, "CMD"); printf("link '%s' to '%s' (%s)", vh_sgetref(to, "DESC"), vh_sgetref(from, "DESC"), vl_join(list, ". ")); if (len > 1) printf(" (dist %d)", len); printf("\n"); } } }