void Game::player_move(int xdif, int ydif) { // TODO: Remove this? if (xdif < -1 || xdif > 1 || ydif < -1 || ydif > 1) { debugmsg("Game::player_move called with [%d, %d]", xdif, ydif); return; } int newx = player->pos.x + xdif, newy = player->pos.y + ydif; Entity* ent = entities.entity_at(newx, newy); std::string tername = map->get_name(newx, newy); if (ent) { player->attack(ent); } else if (player->can_move_to(map, newx, newy)) { player->move_to(map, newx, newy); } else if (map->open(newx, newy)) { add_msg("You open the %s.", tername.c_str()); player->use_ap(100); } std::vector<Item> *items = map->items_at(player->pos); // TODO: Ensure the player has the sense of sight if (!items->empty()) { std::string item_message = "You see here " + list_items(items); add_msg( item_message ); } }
int main(int argc, char **argv) { bool show_all = false; int dirs = 0, i; const char *dirarray[DIRMAX] = { NULL }; enum arg_index ret; while ((ret = arg_parser(argc, argv, ls_args)) != ARG_DONE) { switch (ret) { case ARG_help: display_help_text(argv[0], usage_str, desc_str, ls_args); return 0; case ARG_all: show_all = true; break; case ARG_EXTRA: if (dirs < sizeof(dirarray)) { dirarray[dirs++] = argarg; } else { fprintf(stderr, "%s: To many directories given to ls\n", argv[0]); return 1; } break; default: return 0; } } if (dirs == 0) { dirarray[dirs++] = "./"; } for (i = 0; i < dirs; i++) { DIR *directory = opendir(dirarray[i]); if (directory == NULL) { perror(*argv); return 1; } list_items(directory, show_all); printf("\n"); } }
void GUI::ListDialog(wxWindow* parent, wxString title, const wxArrayString& param_items) { if(param_items.empty()) return; wxArrayString list_items(param_items); // Create the window wxDialog* dlg = newd wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxRESIZE_BORDER | wxCAPTION | wxCLOSE_BOX); wxSizer* sizer = newd wxBoxSizer(wxVERTICAL); wxListBox* item_list = newd wxListBox(dlg, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, nullptr, wxLB_SINGLE); item_list->SetMinSize(wxSize(500, 300)); for(size_t i = 0; i != list_items.GetCount();) { wxString str = list_items[i]; size_t pos = str.find(wxT("\n")); if(pos != wxString::npos) { // Split string! item_list->Append(str.substr(0, pos)); list_items[i] = str.substr(pos+1); continue; } item_list->Append(list_items[i]); ++i; } sizer->Add(item_list, 1, wxEXPAND); wxSizer* stdsizer = newd wxBoxSizer(wxHORIZONTAL); stdsizer->Add(newd wxButton(dlg, wxID_OK, wxT("OK")), wxSizerFlags(1).Center()); sizer->Add(stdsizer, wxSizerFlags(0).Center()); dlg->SetSizerAndFit(sizer); // Show the window dlg->ShowModal(); delete dlg; }
int main(int argc, char **argv) { static bool show_series = false, show_all = false, use_cache = true; static int i_sid = 0; static char usage_str[] = "[SID[:PID]]"; static struct opt_table opts[] = { OPT_WITH_ARG("--items-list|-i", opt_set_intval, NULL, &i_sid, "List episodes in a series. Requires a SID as a parameter."), OPT_WITHOUT_ARG("--series-list|-s", opt_set_bool, &show_series, "List the series available. The first element is the SID."), OPT_WITHOUT_ARG("--all|-a", opt_set_bool, &show_all, "List all items in all non-empty series."), OPT_WITHOUT_ARG("--force|-f", opt_set_invbool, &use_cache, "Force bypass the cached metadata."), OPT_WITHOUT_ARG("--help|-h", opt_usage_and_exit, usage_str, "Show this message."), OPT_ENDTABLE }; opt_register_table(opts, NULL); if(!opt_parse(&argc, argv, opt_log_stderr)) { /* opt_parse will print an error to stderr. */ exit(1); } if (!show_all && !show_series && !i_sid && (argc == 1)) { opt_usage_and_exit(usage_str); } struct iv_series *index; struct iv_config *config; int return_val = 0; cache_dir = xdg_user_dir_lookup_with_fallback("CACHE", "/tmp"); if(NULL == (config = iviewiir_configure())) { fprintf(stderr, "Couldn't configure iviewiir, exiting\n"); return 1; } int index_len = iviewiir_index(config, &index); if(0 >= index_len) { fprintf(stderr, "No items in index, exiting\n"); return_val = 1; goto config_cleanup; } /* Check if they want everything listed */ if(show_all) { list_all(config, index, index_len); return_val = 0; goto index_cleanup; } /* Check if they wanted a series list. */ if(show_series) { int i; for(i=0; i<index_len; i++) { /* Heuristic to trim out empty series. */ if((int)9e6 < index[i].id) { continue; } printf("%d - %s\n", index[i].id, index[i].title); } return_val = 0; goto index_cleanup; } /* Check if they want an episode list. */ if(i_sid) { return_val = list_items(config, index, index_len, i_sid); goto index_cleanup; } /* If we've reached here and there are no arguments, print help message. */ if (argc == 1) { opt_usage_and_exit(usage_str); } /* Otherwise, if they supplied a SID or SID:PID tuple, download the PID */ int i = 1; while(i < argc) { if(NULL != strchr(argv[i], ':')) { // SID:PID const unsigned long sid = strtoul(strtok(argv[i], ":"), NULL, 10); const unsigned int pid = strtoul(strtok(NULL, ":"), NULL, 10); return_val += download_item(config, index, index_len, sid, pid); } else { // Check if it's a valid SID const unsigned int sid = strtoul(argv[i], NULL, 10); struct iv_episode *items; // Fetch episode lists for the SID debug("sid: %d\n", sid); int series_index; if(-1 == (series_index = iv_find_series(sid, index, index_len, NULL))) { printf("No such series"); return_val += 1; continue; } // Fetch items in series ssize_t items_len = iv_easy_series(config, &index[series_index], &items); if(1 > items_len) { printf("No items in series.\n"); return_val += 1; continue; } for(i=0; i<items_len; i++) { return_val += download_item(config, index, index_len, sid, items[i].id); } iv_destroy_series(items, items_len); } i++; } index_cleanup: iv_destroy_index(index, index_len); config_cleanup: iv_destroy_config(config); free(cache_dir); return return_val; }
void Game::pickup_items(int posx, int posy) { if (!w_hud) { debugmsg("pickup_items() - w_hud is NULL!"); return; } cuss::interface i_pickup; if (!i_pickup.load_from_file("cuss/i_pickup.cuss")) { debugmsg("Couldn't open cuss/i_pickup.cuss"); return; } int weight_after = player->current_weight(), volume_after = player->current_volume(); std::vector<Item> *available = map->items_at(posx, posy); std::vector<bool> pick_up; std::vector<std::string> pickup_strings, weight_strings, volume_strings; for (int i = 0; i < available->size(); i++) { pick_up.push_back(false); weight_strings.push_back( itos( (*available)[i].get_weight() ) ); volume_strings.push_back( itos( (*available)[i].get_volume() ) ); } int offset = 0; cuss::element *ele_list_items = i_pickup.find_by_name("list_items"); if (!ele_list_items) { debugmsg("No element 'list_items' in i_pickup.cuss"); return; } int offset_size = ele_list_items->sizey; bool done = false; pickup_strings = get_pickup_strings(available, &pick_up); // Set interface data i_pickup.set_data("weight_current", player->current_weight()); i_pickup.set_data("weight_maximum", player->maximum_weight()); i_pickup.set_data("volume_current", player->current_volume()); i_pickup.set_data("volume_maximum", player->maximum_volume()); for (int i = 0; i < offset_size && i < pickup_strings.size(); i++) { i_pickup.add_data("list_items", pickup_strings[i]); i_pickup.add_data("list_weight", weight_strings[i]); i_pickup.add_data("list_volume", volume_strings[i]); } while (!done) { i_pickup.set_data("weight_after", weight_after); i_pickup.set_data("volume_after", volume_after); i_pickup.draw(w_hud); long ch = getch(); if (ch >= 'A' && ch <= 'Z') { ch = ch - 'A' + 'a'; // Convert uppercase letters to lowercase } if (ch >= 'a' && ch - 'a' < available->size()) { int index = ch - 'a'; pick_up[index] = !pick_up[index]; bool pu = pick_up[index]; Item *it = &( (*available)[index] ); pickup_strings[index] = pickup_string(it, ch, pu); i_pickup.set_data("list_items", pickup_strings); if (pu) { weight_after += it->get_weight(); volume_after += it->get_volume(); } else { weight_after -= it->get_weight(); volume_after -= it->get_volume(); } i_pickup.clear_data("list_items" ); i_pickup.clear_data("list_weight"); i_pickup.clear_data("list_volume"); std::stringstream weight_ss, volume_ss; weight_ss << (pu ? "<c=green>" : "<c=ltgray>") << it->get_weight() << "<c=/>"; volume_ss << (pu ? "<c=green>" : "<c=ltgray>") << it->get_volume() << "<c=/>"; weight_strings[index] = weight_ss.str(); volume_strings[index] = volume_ss.str(); for (int i = offset * offset_size; i < (offset + 1) * offset_size && i < pickup_strings.size(); i++) { i_pickup.add_data("list_items", pickup_strings[i]); i_pickup.add_data("list_weight", weight_strings[i]); i_pickup.add_data("list_volume", volume_strings[i]); } } else if (ch == '<' && offset > 0) { offset--; i_pickup.clear_data("list_items" ); i_pickup.clear_data("list_weight"); i_pickup.clear_data("list_volume"); for (int i = offset * offset_size; i < (offset + 1) * offset_size && i < pickup_strings.size(); i++) { i_pickup.add_data("list_items", pickup_strings[i]); i_pickup.add_data("list_weight", weight_strings[i]); i_pickup.add_data("list_volume", volume_strings[i]); } } else if (ch == '>' && available->size() > (offset + 1) * offset_size) { offset++; i_pickup.clear_data("list_items" ); i_pickup.clear_data("list_weight"); i_pickup.clear_data("list_volume"); for (int i = offset * offset_size; i < (offset + 1) * offset_size && i < pickup_strings.size(); i++) { i_pickup.add_data("list_items", pickup_strings[i]); i_pickup.add_data("list_weight", weight_strings[i]); i_pickup.add_data("list_volume", volume_strings[i]); } } else if (ch == KEY_ESC) { return; } else if (ch == '\n') { done = true; } } // TODO: Code for multi-turn pickup std::vector<Item> items_gotten; for (int i = 0; i < available->size(); i++) { if (pick_up[i]) { items_gotten.push_back( (*available)[i] ); player->add_item( (*available)[i] ); available->erase(available->begin() + i); pick_up.erase(pick_up.begin() + i); } } std::string message = "You pick up " + list_items(&items_gotten); add_msg(message); }
void Game::do_action(Interface_action act) { switch (act) { case IACTION_MOVE_N: player_move( 0, -1); break; case IACTION_MOVE_S: player_move( 0, 1); break; case IACTION_MOVE_W: player_move(-1, 0); break; case IACTION_MOVE_E: player_move( 1, 0); break; case IACTION_MOVE_NW: player_move(-1, -1); break; case IACTION_MOVE_NE: player_move( 1, -1); break; case IACTION_MOVE_SW: player_move(-1, 1); break; case IACTION_MOVE_SE: player_move( 1, 1); break; case IACTION_PAUSE: player->pause(); break; case IACTION_MOVE_UP: if (!map->has_flag(TF_STAIRS_UP, player->pos)) { add_msg("You cannot go up here."); player_move_vertical(1); } else { player_move_vertical(1); } break; case IACTION_MOVE_DOWN: if (!map->has_flag(TF_STAIRS_DOWN, player->pos)) { add_msg("You cannot go down here."); player_move_vertical(-1); } else { player_move_vertical(-1); } break; case IACTION_PICK_UP: // TODO: Interface for picking up >1 item if (map->item_count(player->pos) == 0) { add_msg("No items here."); } else if (map->item_count(player->pos) == 1) { std::vector<Item> *items = map->items_at(player->pos); std::string message = "You pick up " + list_items(items); player->add_item( (*items)[0] ); items->clear(); add_msg(message); } else { pickup_items(player->pos); } break; case IACTION_OPEN: { Point dir = input_direction(input()); if (dir.x == -2) { // Error add_msg("Invalid direction."); } else { Tripoint open = player->pos + dir; std::string tername = map->get_name(open); if (map->open(open)) { add_msg("You open the %s.", tername.c_str()); player->use_ap(100); } else { add_msg("You cannot open a %s.", tername.c_str()); } } } break; case IACTION_CLOSE: { Point dir = input_direction(input()); if (dir.x == -2) { // Error add_msg("Invalid direction."); } else { Tripoint close = player->pos + dir; std::string tername = map->get_name(close); if (map->close(close)) { add_msg("You close the %s.", tername.c_str()); player->use_ap(100); } else { add_msg("You cannot close a %s.", tername.c_str()); } } } break; case IACTION_SMASH: { Point dir = input_direction(input()); if (dir.x == -2) { // Error add_msg("Invalid direction."); } else { Tripoint sm = player->pos + dir; add_msg("You smash the %s.", map->get_name(sm).c_str()); map->smash(sm, player->std_attack().roll_damage()); player->use_ap(100); } } break; case IACTION_INVENTORY: { Item it = player->inventory_single(); Item_action act = it.show_info(); if (act == IACT_DROP) { add_msg( player->drop_item_message(it) ); player->remove_item_uid(it.get_uid()); map->add_item(it, player->pos); } else if (act == IACT_WIELD) { add_msg( player->wield_item_message(it) ); player->wield_item_uid(it.get_uid()); } else if (act == IACT_WEAR) { add_msg( player->wear_item_message(it) ); player->wear_item_uid(it.get_uid()); } } break; case IACTION_DROP: { std::vector<Item> dropped = player->drop_items(); std::stringstream message; message << "You drop " << list_items(&dropped); for (int i = 0; i < dropped.size(); i++) { map->add_item(dropped[i], player->pos); } add_msg( message.str() ); } break; case IACTION_WIELD: { Item it = player->inventory_single(); add_msg( player->sheath_weapon_message() ); player->sheath_weapon(); add_msg( player->wield_item_message(it) ); player->wield_item_uid(it.get_uid()); } break; case IACTION_WEAR: { Item it = player->inventory_single(); add_msg( player->wear_item_message(it) ); player->wear_item_uid(it.get_uid()); } break; case IACTION_RELOAD: { Item it = player->inventory_single(); player->reload_prep(it.get_uid()); } break; case IACTION_RELOAD_EQUIPPED: player->reload_prep(player->weapon.get_uid()); break; case IACTION_THROW: { Item it = player->inventory_single(); if (!it.is_real()) { add_msg("Never mind."); } else { Point target = target_selector(); if (target.x == -1) { // We canceled add_msg("Never mind."); } else { player->remove_item_uid(it.get_uid(), 1); Ranged_attack att = player->throw_item(it); launch_projectile(it, att, player->pos, target); } } } break; case IACTION_FIRE: if (!player->weapon.is_real()) { add_msg("You are not wielding anything."); } else if (player->weapon.get_item_class() != ITEM_CLASS_LAUNCHER) { add_msg("You cannot fire %s.", player->weapon.get_name_indefinite().c_str()); } else if (player->weapon.charges == 0 || !player->weapon.ammo) { add_msg("You need to reload %s.", player->weapon.get_name_definite().c_str()); } else { Point target = target_selector(); if (target.x == -1) { // We canceled add_msg("Never mind."); } else { Ranged_attack att = player->fire_weapon(); launch_projectile(Item(), att, player->pos, target); } } break; case IACTION_MESSAGES_SCROLL_BACK: i_hud.add_data("text_messages", -1); break; case IACTION_MESSAGES_SCROLL_FORWARD: i_hud.add_data("text_messages", 1); break; case IACTION_VIEW_WORLDMAP: { Point p = map->get_center_point(); worldmap->draw(p.x, p.y); } break; case IACTION_QUIT: if (query_yn("Commit suicide?")) { game_over = true; player->action_points = 0; } break; } }