ret_code_t inv_block(void) { SaHpiRdrT rdr_entry; SaHpiResourceIdT rptid; SaHpiInstrumentIdT rdrnum; SaHpiRdrTypeT type; SaErrorT rv; char buf[256]; ret_code_t ret; term_def_t *term; int res; ret = ask_rpt(&rptid); if (ret != HPI_SHELL_OK) return(ret); type = SAHPI_INVENTORY_RDR; ret = ask_rdr(rptid, type, &rdrnum); if (ret != HPI_SHELL_OK) return(ret); inv_block_env.rptid = rptid; inv_block_env.rdrnum = rdrnum; rv = saHpiRdrGetByInstrumentId(Domain->sessionId, rptid, type, rdrnum, &rdr_entry); if (rv != SA_OK) { printf("saHpiRdrGetByInstrumentId error %s\n", oh_lookup_error(rv)); printf("ERROR!!! Can not get rdr: ResourceId=%d RdrType=%d RdrNum=%d\n", rptid, type, rdrnum); return(HPI_SHELL_CMD_ERROR); }; show_inventory(Domain->sessionId, rptid, rdrnum, ui_print); for (;;) { block_type = INV_COM; res = get_new_command("inventory block ==> "); if (res == 2) { unget_term(); return HPI_SHELL_OK; }; term = get_next_term(); if (term == NULL) continue; snprintf(buf, 256, "%s", term->term); if ((strcmp(buf, "q") == 0) || (strcmp(buf, "quit") == 0)) break; }; block_type = MAIN_COM; return HPI_SHELL_OK; }
//Deals with the use of a potion void useYourPotion(Player *target) { int userChoice = 0; int id = 0; printf("Select the item your want to USE by pressing the corresponding number :"); userChoice = userInputInt(); //Catch the type of potion the player wants to use id = useItem_return_id(target->inventory, userChoice); //Act depending on the type of the potion switch(id){ case HEALTH_POTION: //Conditions depending on the health of the player if((target->health + POTION_LIFE) <= target->maxHP){ target->health += POTION_LIFE; useItem_remove_id(target->inventory, userChoice); } //Cannot drink a potion if the health is full else if (target->health == target->maxHP){ printf("Your life is full, you don't need health potion !"); Sleep(1000); } //Cannot go over the maximum HP of the player else{ target->health = target->maxHP; useItem_remove_id(target->inventory, userChoice); } break; //The three other potions have a time Effect to deal with case STRENGTH_POTION: //Cannot have more than one potion at a time if(target->potion == 0){ //Call the time Effect potion handleTimeEffect(target, POTION_STRENGTH, 0, 0); useItem_remove_id(target->inventory, userChoice); target->potion = TIME_EFFECT+1; } else{ printf("You can only have one potion at a time !\n"); Sleep(2000); } break; case DEFENSE_POTION: if(target->potion == 0){ handleTimeEffect(target, 0, POTION_DEFENSE, 0); useItem_remove_id(target->inventory, userChoice); target->potion = TIME_EFFECT+1; } else{ printf("You can only have one potion at a time !\n"); Sleep(2000); } break; case GHOST_POTION: if(target->potion == 0){ handleTimeEffect(target, 0, 0, POTION_DODGE); useItem_remove_id(target->inventory, userChoice); target->potion = TIME_EFFECT+1; } else{ printf("You can only have one potion at a time !\n"); Sleep(2000); } break; default: break; } show_inventory(target); }
ret_code_t inv_block_show(void) { return(show_inventory(Domain->sessionId, inv_block_env.rptid, inv_block_env.rdrnum, ui_print)); }
void start_game(playerType *player, roomBase *roomdb, objectBase *objectdb, enemyBase *enemydb) { player->quit = 0; player->n_object_ids = 0; player->health = 100; int test_coordinates[2] = { 0, 0 }; int input_size = 0; char input_command[INPUT_LENGTH] = { 0 }; char input_parameter[INPUT_LENGTH] = { 0 }; player->current_room = get_room_from_id(player->starting_room_id, roomdb); set_player_coordinates(player->current_room->coordinates, player); show_room_content(player->current_room, objectdb); while( ! player->quit ) { input_size = player_input(player, input_command, input_parameter); if( COMP_STR(input_command, "exit") || COMP_STR(input_command, "quit") || feof(stdin) ) { printf("Thanks for playing, have a nice day!\n"); player->quit = 1; } else if( COMP_STR(input_command, "look") ) { show_room_content(player->current_room, objectdb); } else if( COMP_STR(input_command, "health") ) { printf("Player HP: %d\n", player->health); } else if( COMP_STR(input_command, "inventory" ) ) { show_inventory(player, objectdb); } else if( COMP_STR(input_command, "examine" ) ) { examine_object(input_parameter, player, objectdb); } else if( COMP_STR(input_command, "take" ) ) { take_object(input_parameter, player, objectdb); } else if( COMP_STR(input_command, "use" ) ) { use_object(input_parameter, player, objectdb, roomdb, enemydb); } else if( COMP_STR(input_command, "north" ) ) { test_coordinates[0] = player->coordinates[0]; test_coordinates[1] = player->coordinates[1] + 1; go_to_room(player, roomdb, test_coordinates, objectdb, enemydb); } else if( COMP_STR(input_command, "south" ) ) { test_coordinates[0] = player->coordinates[0]; test_coordinates[1] = player->coordinates[1] - 1; go_to_room(player, roomdb, test_coordinates, objectdb, enemydb); } else if( COMP_STR(input_command, "east" ) ) { test_coordinates[0] = player->coordinates[0] + 1; test_coordinates[1] = player->coordinates[1]; go_to_room(player, roomdb, test_coordinates, objectdb, enemydb); } else if( COMP_STR(input_command, "west" ) ) { test_coordinates[0] = player->coordinates[0] - 1; test_coordinates[1] = player->coordinates[1]; go_to_room(player, roomdb, test_coordinates, objectdb, enemydb); } else if( COMP_STR(input_command, "help" ) ) { printf("Commands: %s\n", COMMANDS_LIST); } else { if( input_size > 0 ) /* check that the user hasn't simply just pressed enter */ printf("I don't understand that. Type \"help\" for a list of recognised commands\n"); } } }
void _read_command() { const std::string move_keys = "lkjhyubn12346789"; const std::string travel_keys = "LKJHYUBN"; char key = io::getchar(); if (char_in(key, move_keys)) { move_player(key); return; } else if (char_in(key, travel_keys)) { _start_travel(tolower(key), false); return; } if (key == ',') { do_player_pickup(player.pos.x, player.pos.y); } else if (key == 'i') { statestack_push(STATE_INVENTORY); show_inventory(); statestack_pop(); } else if (key == 'd') { statestack_push(STATE_DROP); show_inventory(); statestack_pop(); } else if (key == 'q') { statestack_push(STATE_QUAF_POTION); show_inventory(); statestack_pop(); } else if (key == 'e') { if (!_eat_item_on_floor()) { statestack_push(STATE_EAT_FOOD); show_inventory(); statestack_pop(); } } else if (key == 'w') { statestack_push(STATE_WIELD); show_inventory(); statestack_pop(); } else if (key == '.') { player.ap -= player.speed; } else if (key == 'x') { init_target_cursor(player.pos.x, player.pos.y, 0); statestack_push(STATE_EXAMINE); } else if (key == 'r') { statestack_push(STATE_READ_SCROLL); show_inventory(); statestack_pop(); } else if (key == 'c') { append_msg_log("Which direction?"); statestack_push(STATE_CLOSE_DOOR); } else if (key == 'C') { if (!autochat()) { append_msg_log("Talk to whom?"); statestack_push(STATE_CHAT); } } else if (key == 'z') { draw_spell_list(); } else if (key == 'Z') { statestack_push(STATE_ZAP_WAND); show_inventory(); } else if (key == '<') { if (upstairs_at(current_dungeon, player.pos.x, player.pos.y)) { append_msg_log("You walk up the stairs."); _take_stairs(get_stairs_at(current_dungeon, player.pos.x, player.pos.y)); player.ap -= player.speed; } else { append_msg_log("You can't walk up here!"); } } else if (key == '>') { if (downstairs_at(current_dungeon, player.pos.x, player.pos.y)) { append_msg_log("You walk down the stairs."); _take_stairs(get_stairs_at(current_dungeon, player.pos.x, player.pos.y)); player.ap -= player.speed; } else { append_msg_log("You can't walk down here!"); } } else if (key == '@') { show_character_sheet(); } else if (key == '\t') { move_player_towards_closest_enemy(); } else if (key == 'g') { item_t* book = item_t::create_item_by_type(ITEM_TYPE_WEAPON); item_t* scroll = item_t::create_item("scroll of identify"); add_item_to_dungeon(current_dungeon, book, player.pos.x, player.pos.y); add_item_to_dungeon(current_dungeon, scroll, player.pos.x, player.pos.y); // create_effect(&player, EF_FLAME_CLOUDS, 10, 0); // cloud_machine_t* machine = new cloud_machine_t; // machine->frequency = 100; // machine->max_clouds_per_tick = 9; // machine->cloud_energy = 100; // machine->cloud_entropy = 0; // machine->variance = 0; // machine->pos = player.pos; // machine->radius = 1; // machine->type = CLOUD_FLAME; // machine->life = 5; // machine->cloud_symbol = '*'; // machine->cloud_color_cycle = { color_red, color_light_red }; // // current_dungeon->cloud_system.add_gas_machine(machine, true); // item_t* weapon = item_t::create_item_by_type(ITEM_TYPE_WEAPON); // add_item_to_dungeon(current_dungeon, weapon, player.pos.x, player.pos.y); } else if (key == 's') { //item_t* scroll = item_t::create_item_by_type(ITEM_TYPE_SCROLL); //add_item_to_dungeon(current_dungeon, scroll, player.pos.x, player.pos.y); hide(); } else if (key == 'Q') { if (yesno("Do you wish to quit the game?", true)) { _game_running = false; } } else if (key == 'S') { if (yesno("Save and quit?", true)) { save_game(); _game_running = false; } } else if (key == 'M') { show_message_history(); } }
// Controls the player input void ctrl_player(WINDOWLIST * lw, PLAYER * p) { char input; set_inputmode(IM_PLAYING); if (g_fld[p->x][p->y] != ENT_PLAYER) { g_fld[p->x][p->y] = ENT_PLAYER; } input = (char) getch(); if (input == cfg->up) { p->ch = '^'; if (p->y > CON_FIELDMINY) { mv_player(lw, p, DIR_UP); } else { set_winchar(lw->w_field, p->x, p->y, A_BOLD, CP_WHITEBLACK, p->ch); } } else if (input == cfg->down) { p->ch = 'v'; if (p->y < CON_FIELDMAXY) { mv_player(lw, p, DIR_DOWN); } else { set_winchar(lw->w_field, p->x, p->y, A_BOLD, CP_WHITEBLACK, p->ch); } } else if (input == cfg->left) { p->ch = '<'; if (p->x > CON_FIELDMINX) { mv_player(lw, p, DIR_LEFT); } else { set_winchar(lw->w_field, p->x, p->y, A_BOLD, CP_WHITEBLACK, p->ch); } } else if (input == cfg->right) { p->ch = '>'; if (p->x < CON_FIELDMAXX) { mv_player(lw, p, DIR_RIGHT); } else { set_winchar(lw->w_field, p->x, p->y, A_BOLD, CP_WHITEBLACK, p->ch); } } else if (input == cfg->use) { set_player_dmg(lw->w_field, p, 10); // Just for testing purposes } else if (input == cfg->nextw) { // Next weapon } else if (input == cfg->prevw) { // Previous weapon } else if (input == cfg->inv) { show_inventory(); redrawwin(lw->w_field); redrawwin(lw->w_game); redrawwin(lw->w_status); wrefresh(lw->w_field); wrefresh(lw->w_game); wrefresh(lw->w_status); } else if (input == '\n') { p->quit = true; } else if (input == 'p') // Just for debug purposes, will be removed later on { int t_freeze; t_freeze = pause_game(); set_inputmode(IM_KEYPRESS); while(getch() != '\n'); resume_game(t_freeze); } else if (input == ERR) { /* Since we use nodelay(), getch() returns ERR when no key is pressed * (instead of blocking everything else), however this leads to 100% * cpu usage. Thus, usleep is used to calm down the cpu. */ usleep(500); } if (p->hp == 0) { write_log(LOG_INFO, "%s:\n\tPlayer is dead, stopping game ...\n", __func__); p->quit = true; } }