Uint32 turn_callback(Uint32 interval,void* param){ if(param){ render_data_t data = *((render_data_t*)param); if(data.board){ end_turn(data.board); design_health(data.renderer,data.board); if(data.board->player_id == 0){ data.board->player_id = 1; local_count++; } else{ data.board->player_id = 0; local_count++; } if(local_count == 2){ data.board->turn_count++; local_count = 0; } rotate_board(data.board); position_board_elements(data.renderer,data.board); light_index = 0; turn_begin(&data.board->players[data.board->player_id],data.board->turn_count); } return interval; } return 0; }
Uint32 turn_callback(Uint32 interval,void* param){ if(param){ render_data_t data = *((render_data_t*)param); if(data.board){ end_turn(data.board); design_health(data.renderer,data.board); if(data.board->player_id == 0){ data.board->player_id = 1; turn_count++; } else{ data.board->player_id = 0; turn_count++; } if(turn_count % 2 == 0){ if(global_crystals < 10){ global_crystals++; } else{ global_crystals = 10; } } data.board->players[data.board->player_id].pool_of_mana.mana_crystals = global_crystals; rotate_board(data.board); turn_begin(&data.board->players[data.board->player_id]); position_board_elements(data.renderer,data.board); light_index = 0; } return interval; } return 0; }
Report* Fight::start(ls::VM& vm, ls::VM& vm_v1) { Simulator::fight = this; for (auto& team : teams) { for (auto& entity : team->entities) { entities.insert({entity->id, entity}); order.addEntity(entity); entity->ai->compile(vm, vm_v1); } } actions.add(new ActionStartFight()); while (order.getTurn() <= MAX_TURNS) { auto entity = order.current(); Simulator::entity = entity; vm.output = entity->debug_output; vm_v1.output = entity->debug_output; LOG << "Turn of " << entity->name << " (" << entity->id << "), AI " << entity->ai->name << "..." << std::endl; actions.add(new ActionEntityTurn(entity)); entity->start_turn(); try { entity->ai->execute(vm, vm_v1); } catch (ls::vm::ExceptionObj* ex) { LOG << ex->to_string(true); // vm.last_exception = nullptr; // vm_v1.last_exception = nullptr; if (ex->type == ls::vm::Exception::OPERATION_LIMIT_EXCEEDED) { actions.add(new ActionAIError(entity)); // TODO Add Breaker Trophy } // TODO delete ex } vm.operations = 0; entity->end_turn(); actions.add(new ActionEndTurn(entity)); if (is_finished()) { break; } if (order.next()) { actions.add(new ActionNewTurn(order.getTurn())); LOG << "Turn " << order.getTurn() << std::endl; } } Simulator::entity = nullptr; Report* report = new Report(this); report->actions = &actions; return report; }
Game::move Game::move_forward() { if(edit_mode) return MOVE_END; move result = moves_forward.back(); if(id_color(get_pos_id(result.first)) != act_player) end_turn(); make_move(result); moves_forward.pop_back(); return result; }
void Pitch::move_random() { if(blocked || ended) return; Game::move m = game->random_move(); if(m == Game::MOVE_END) { end_turn(); } else { focus = m.first; on_chosen(m.second); } }
void playmp_controller::play_linger_turn() { if (is_host()) { end_turn_enable(true); } while(end_turn_ == END_TURN_NONE) { config cfg; if(network_reader_.read(cfg)) { if(turn_data_.process_network_data(cfg) == turn_info::PROCESS_END_LINGER) { end_turn(); } } play_slice(); } }
void Pitch::on_chosen(int pos) { if(blocked) return; int fid = game->get_pos_id(focus); if(game->get_act_player() != game->id_color(fid) && !game->get_edit_mode()) { end_turn(); } clear_shadows(); if(game->has_ball(fid)) { int i = (game->id_color(fid) == Game::WHITE ? 0 : 1); balls.at(i)->move(ball_pos_to_coord(pos)); } else { footballers.at(fid)->move(pos_to_coord(pos)); } game->make_move(Game::move(focus, pos)); focus = -1; }
bool Game::make_move(const move m) { int fid = get_pos_id(m.first); int pt = m.second; if(fid == NONE && !edit_mode) { end_turn(); return true; } int target_id = get_pos_id(pt); if(has_ball(fid)) { color_spec this_col = id_color(fid); if(target_id == NONE || (id_color(target_id) != this_col)) return false; if(this_col == WHITE) white_ball_owner = target_id; else black_ball_owner = target_id; if(!edit_mode) passed = true; } else { if(target_id != NONE) return false; bm.left.erase(fid); bm.insert(boost::bimap<int, int>::value_type(fid, pt)); if(!edit_mode) ++moves_made; } if(!edit_mode) { moves_history.push_back(m); if(moves_forward.size() > 0 && m != moves_forward.back()) moves_forward.clear(); } return true; }
bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/, bool press) { // hotkey release handling if (!press) { switch(cmd.id) { // release a scroll key, un-apply scrolling in the given direction case HOTKEY_SCROLL_UP: scroll_up(false); break; case HOTKEY_SCROLL_DOWN: scroll_down(false); break; case HOTKEY_SCROLL_LEFT: scroll_left(false); break; case HOTKEY_SCROLL_RIGHT: scroll_right(false); break; default: return false; // nothing else handles a hotkey release } return true; } // hotkey press handling switch(cmd.id) { case HOTKEY_SCROLL_UP: scroll_up(true); break; case HOTKEY_SCROLL_DOWN: scroll_down(true); break; case HOTKEY_SCROLL_LEFT: scroll_left(true); break; case HOTKEY_SCROLL_RIGHT: scroll_right(true); break; case HOTKEY_CYCLE_UNITS: cycle_units(); break; case HOTKEY_CYCLE_BACK_UNITS: cycle_back_units(); break; case HOTKEY_ENDTURN: end_turn(); break; case HOTKEY_UNIT_HOLD_POSITION: unit_hold_position(); break; case HOTKEY_END_UNIT_TURN: end_unit_turn(); break; case HOTKEY_LEADER: goto_leader(); break; case HOTKEY_UNDO: undo(); break; case HOTKEY_REDO: redo(); break; case HOTKEY_TERRAIN_DESCRIPTION: terrain_description(); break; case HOTKEY_UNIT_DESCRIPTION: unit_description(); break; case HOTKEY_RENAME_UNIT: rename_unit(); break; case HOTKEY_SAVE_GAME: save_game(); break; case HOTKEY_SAVE_REPLAY: save_replay(); break; case HOTKEY_SAVE_MAP: save_map(); break; case HOTKEY_LOAD_GAME: load_game(); break; case HOTKEY_TOGGLE_ELLIPSES: toggle_ellipses(); break; case HOTKEY_TOGGLE_GRID: toggle_grid(); break; case HOTKEY_STATUS_TABLE: status_table(); break; case HOTKEY_RECALL: recall(); break; case HOTKEY_LABEL_SETTINGS: label_settings(); break; case HOTKEY_RECRUIT: recruit(); break; case hotkey::HOTKEY_REPEAT_RECRUIT: repeat_recruit(); break; case HOTKEY_SPEAK: speak(); break; case HOTKEY_SPEAK_ALLY: whisper(); break; case HOTKEY_SPEAK_ALL: shout(); break; case HOTKEY_CREATE_UNIT: create_unit(); break; case HOTKEY_CHANGE_SIDE: change_side(); break; case HOTKEY_KILL_UNIT: kill_unit(); break; case HOTKEY_PREFERENCES: preferences(); break; case HOTKEY_OBJECTIVES: objectives(); break; case HOTKEY_UNIT_LIST: unit_list(); break; case HOTKEY_STATISTICS: show_statistics(); break; case HOTKEY_STOP_NETWORK: stop_network(); break; case HOTKEY_START_NETWORK: start_network(); break; case HOTKEY_LABEL_TEAM_TERRAIN: label_terrain(true); break; case HOTKEY_LABEL_TERRAIN: label_terrain(false); break; case HOTKEY_CLEAR_LABELS: clear_labels(); break; case HOTKEY_SHOW_ENEMY_MOVES: show_enemy_moves(false); break; case HOTKEY_BEST_ENEMY_MOVES: show_enemy_moves(true); break; case HOTKEY_DELAY_SHROUD: toggle_shroud_updates(); break; case HOTKEY_UPDATE_SHROUD: update_shroud_now(); break; case HOTKEY_CONTINUE_MOVE: continue_move(); break; case HOTKEY_SEARCH: search(); break; case HOTKEY_HELP: show_help(); break; case HOTKEY_CHAT_LOG: show_chat_log(); break; case HOTKEY_USER_CMD: user_command(); break; case HOTKEY_CUSTOM_CMD: custom_command(); break; case HOTKEY_AI_FORMULA: ai_formula(); break; case HOTKEY_CLEAR_MSG: clear_messages(); break; case HOTKEY_LANGUAGE: change_language(); break; case HOTKEY_REPLAY_PLAY: play_replay(); break; case HOTKEY_REPLAY_RESET: reset_replay(); break; case HOTKEY_REPLAY_STOP: stop_replay(); break; case HOTKEY_REPLAY_NEXT_TURN: replay_next_turn(); break; case HOTKEY_REPLAY_NEXT_SIDE: replay_next_side(); break; case HOTKEY_REPLAY_NEXT_MOVE: replay_next_move(); break; case HOTKEY_REPLAY_SHOW_EVERYTHING: replay_show_everything(); break; case HOTKEY_REPLAY_SHOW_EACH: replay_show_each(); break; case HOTKEY_REPLAY_SHOW_TEAM1: replay_show_team1(); break; case HOTKEY_REPLAY_SKIP_ANIMATION: replay_skip_animation(); break; case HOTKEY_REPLAY_EXIT: replay_exit(); break; case HOTKEY_WB_TOGGLE: whiteboard_toggle(); break; case HOTKEY_WB_EXECUTE_ACTION: whiteboard_execute_action(); break; case HOTKEY_WB_EXECUTE_ALL_ACTIONS: whiteboard_execute_all_actions(); break; case HOTKEY_WB_DELETE_ACTION: whiteboard_delete_action(); break; case HOTKEY_WB_BUMP_UP_ACTION: whiteboard_bump_up_action(); break; case HOTKEY_WB_BUMP_DOWN_ACTION: whiteboard_bump_down_action(); break; case HOTKEY_WB_SUPPOSE_DEAD: whiteboard_suppose_dead(); break; case HOTKEY_SELECT_HEX: select_hex(); break; case HOTKEY_DESELECT_HEX: deselect_hex(); break; case HOTKEY_MOVE_ACTION: move_action(); break; case HOTKEY_SELECT_AND_ACTION: select_and_action(); break; case HOTKEY_ACCELERATED: toggle_accelerated_speed(); break; case LUA_CONSOLE: lua_console(); break; case HOTKEY_ZOOM_IN: zoom_in(); break; case HOTKEY_ZOOM_OUT: zoom_out(); break; case HOTKEY_ZOOM_DEFAULT: zoom_default(); break; case HOTKEY_MAP_SCREENSHOT: map_screenshot(); break; case HOTKEY_QUIT_TO_DESKTOP: quit_confirmation::quit_to_desktop(); break; case HOTKEY_QUIT_GAME: quit_confirmation::quit_to_title(); break; default: return false; } return true; }
/* * Perform the given action. */ static void perform_act(game *g, action a) { player *p, *opp; int old_phase; /* Get player pointers */ p = &g->p[g->turn]; opp = &g->p[!g->turn]; /* Remember current phase */ old_phase = p->phase; /* Switch on action */ switch (a.act) { /* No action, advance phase counter */ case ACT_NONE: { /* Advance phase counter */ p->phase++; /* Take care of bookkeeping */ switch (old_phase) { /* Start of turn */ case PHASE_START: /* Start turn */ start_turn(g); /* Done */ break; /* After support/booster */ case PHASE_AFTER_SB: /* End support phase */ end_support(g); /* Done */ break; /* Refresh hand */ case PHASE_REFRESH: /* Refresh */ refresh_phase(g); /* Done */ break; /* End of turn */ case PHASE_END: /* End current turn */ end_turn(g); /* Done */ break; /* Move to next player */ case PHASE_OVER: /* Player is done */ p->phase = PHASE_NONE; /* Next player */ g->turn = !g->turn; /* Start opponent's turn */ opp->phase = PHASE_START; /* Done (completely) */ return; } /* Clear last played card */ p->last_played = 0; /* Done */ break; } /* Retreat */ case ACT_RETREAT: { /* Retreat */ retreat(g); /* Done */ break; } /* Retrieve a card */ case ACT_RETRIEVE: { /* Set last played */ p->last_played = a.index; /* Retrieve card */ retrieve_card(g, a.arg); /* Done */ break; } /* Play a card */ case ACT_PLAY: { /* Set last played */ p->last_played = a.index; /* Play card */ play_card(g, a.arg, 0, 0); /* Done */ break; } /* Play a card without special effect */ case ACT_PLAY_NO: { /* Set last played */ p->last_played = a.index; /* Play card */ play_card(g, a.arg, 1, 0); /* Done */ break; } /* Announce power */ case ACT_ANN_FIRE: case ACT_ANN_EARTH: { /* Increment phase counter */ p->phase++; /* Announce power */ announce_power(g, a.act - ACT_ANN_FIRE); /* Done */ break; } /* Use card special power */ case ACT_USE: { /* Use card */ use_special(g, a.arg); /* Done */ break; } /* Satisfy opponent's "discard" card */ case ACT_SATISFY: { /* Satisfy requirement */ satisfy_discard(g, a.arg); /* Done */ break; } /* Land a ship */ case ACT_LAND: { /* Set last played */ p->last_played = a.index; /* Land ship */ land_ship(g, a.arg); /* Done */ break; } /* Load a card onto a ship */ case ACT_LOAD: { /* Set last played */ p->last_played = a.index; /* Load card */ load_card(g, a.arg, a.target); /* Done */ break; } /* Play a bluff card */ case ACT_BLUFF: { /* Set last played */ p->last_played = a.index; /* Play bluff */ play_bluff(g, a.arg); /* Done */ break; } /* Reveal a bluff card */ case ACT_REVEAL: { /* Set last played */ p->last_played = a.index; /* Reveal bluff */ reveal_bluff(g, g->turn, a.arg); /* Done */ break; } } }
bool command_executor::execute_command(HOTKEY_COMMAND command, int /*index*/) { switch(command) { case HOTKEY_CYCLE_UNITS: cycle_units(); break; case HOTKEY_CYCLE_BACK_UNITS: cycle_back_units(); break; case HOTKEY_ENDTURN: end_turn(); break; case HOTKEY_UNIT_HOLD_POSITION: unit_hold_position(); break; case HOTKEY_END_UNIT_TURN: end_unit_turn(); break; case HOTKEY_LEADER: goto_leader(); break; case HOTKEY_UNDO: undo(); break; case HOTKEY_REDO: redo(); break; case HOTKEY_UNIT_DESCRIPTION: unit_description(); break; case HOTKEY_RENAME_UNIT: rename_unit(); break; case HOTKEY_SAVE_GAME: save_game(); break; case HOTKEY_SAVE_REPLAY: save_replay(); break; case HOTKEY_SAVE_MAP: save_map(); break; case HOTKEY_LOAD_GAME: load_game(); break; case HOTKEY_TOGGLE_ELLIPSES: toggle_ellipses(); break; case HOTKEY_TOGGLE_GRID: toggle_grid(); break; case HOTKEY_STATUS_TABLE: status_table(); break; case HOTKEY_RECALL: recall(); break; case HOTKEY_RECRUIT: recruit(); break; case hotkey::HOTKEY_REPEAT_RECRUIT: repeat_recruit(); break; case HOTKEY_SPEAK: speak(); break; case HOTKEY_SPEAK_ALLY: whisper(); break; case HOTKEY_SPEAK_ALL: shout(); break; case HOTKEY_CREATE_UNIT: create_unit(); break; case HOTKEY_CHANGE_SIDE: change_side(); break; case HOTKEY_PREFERENCES: preferences(); break; case HOTKEY_OBJECTIVES: objectives(); break; case HOTKEY_UNIT_LIST: unit_list(); break; case HOTKEY_STATISTICS: show_statistics(); break; case HOTKEY_STOP_NETWORK: stop_network(); break; case HOTKEY_START_NETWORK: start_network(); break; case HOTKEY_LABEL_TEAM_TERRAIN: label_terrain(true); break; case HOTKEY_LABEL_TERRAIN: label_terrain(false); break; case HOTKEY_CLEAR_LABELS: clear_labels(); break; case HOTKEY_SHOW_ENEMY_MOVES: show_enemy_moves(false); break; case HOTKEY_BEST_ENEMY_MOVES: show_enemy_moves(true); break; case HOTKEY_DELAY_SHROUD: toggle_shroud_updates(); break; case HOTKEY_UPDATE_SHROUD: update_shroud_now(); break; case HOTKEY_CONTINUE_MOVE: continue_move(); break; case HOTKEY_SEARCH: search(); break; case HOTKEY_HELP: show_help(); break; case HOTKEY_CHAT_LOG: show_chat_log(); break; case HOTKEY_USER_CMD: user_command(); break; case HOTKEY_CUSTOM_CMD: custom_command(); break; case HOTKEY_AI_FORMULA: ai_formula(); break; case HOTKEY_CLEAR_MSG: clear_messages(); break; case HOTKEY_LANGUAGE: change_language(); break; case HOTKEY_PLAY_REPLAY: play_replay(); break; case HOTKEY_RESET_REPLAY: reset_replay(); break; case HOTKEY_STOP_REPLAY: stop_replay(); break; case HOTKEY_REPLAY_NEXT_TURN: replay_next_turn(); break; case HOTKEY_REPLAY_NEXT_SIDE: replay_next_side(); break; case HOTKEY_REPLAY_SHOW_EVERYTHING: replay_show_everything(); break; case HOTKEY_REPLAY_SHOW_EACH: replay_show_each(); break; case HOTKEY_REPLAY_SHOW_TEAM1: replay_show_team1(); break; case HOTKEY_REPLAY_SKIP_ANIMATION: replay_skip_animation(); break; case HOTKEY_WB_TOGGLE: whiteboard_toggle(); break; case HOTKEY_WB_EXECUTE_ACTION: whiteboard_execute_action(); break; case HOTKEY_WB_EXECUTE_ALL_ACTIONS: whiteboard_execute_all_actions(); break; case HOTKEY_WB_DELETE_ACTION: whiteboard_delete_action(); break; case HOTKEY_WB_BUMP_UP_ACTION: whiteboard_bump_up_action(); break; case HOTKEY_WB_BUMP_DOWN_ACTION: whiteboard_bump_down_action(); break; case HOTKEY_WB_SUPPOSE_DEAD: whiteboard_suppose_dead(); break; case HOTKEY_LEFT_MOUSE_CLICK: left_mouse_click(); break; case HOTKEY_RIGHT_MOUSE_CLICK: right_mouse_click(); break; default: return false; } return true; }
/* * Constructs the game object and creates all of the needed objects to start * the game and contains the main game loop. */ Game::Game() : players(), types() { bool quit = false; // Add num_players to the game const int num_players = 2; for (int i = 0; i < num_players; ++i) { Player *p = new Player(i); players.push_back(p); } Tank *t = new Tank(); types.push_back(t); Rock *rock = new Rock(); types.push_back(rock); Paper *paper = new Paper(); types.push_back(paper); Scissors *scissors = new Scissors(); types.push_back(scissors); int scr_x, scr_y; getmaxyx(stdscr, scr_y, scr_x); Panel *panel = new Panel(scr_x, scr_y, 20); Map map(70, 70, scr_x - 20, scr_y, panel, types, players[0], players[1]); /* Main game loop */ while (true) { /* Player 1's turn */ players[0]->reset_units(); map.map_loop(players[0]); clearok(stdscr, true); refresh(); /* End of Player 1's turn */ // Check if Player 1 won int num_bases = players[1]->get_bases().size(); int taken_bases = 0; for (int i = 0; i < num_bases; ++i) { location_t base = players[1]->get_bases()[i]; Unit *unit_ptr = map.get_tile(base.x, base.y)->unit; if (unit_ptr && unit_ptr->get_player() != players[1]) ++taken_bases; } if (taken_bases == num_bases) break; // Show player switching window quit = end_turn(0); if (quit) break; /* Player 2's turn */ map.redraw(scr_x - 20, scr_y); players[1]->reset_units(); map.map_loop(players[1]); clearok(stdscr, true); refresh(); /* End of Player 2's turn */ // Check if Player 1 won num_bases = players[0]->get_bases().size(); taken_bases = 0; for (int i = 0; i < num_bases; ++i) { location_t base = players[0]->get_bases()[i]; Unit *unit_ptr = map.get_tile(base.x, base.y)->unit; if (unit_ptr && unit_ptr->get_player() != players[0]) ++taken_bases; } if (taken_bases == num_bases) break; // Switch to player 1 quit = end_turn(1); if (quit) break; // Redraw screen for Player 1 map.redraw(scr_x - 20, scr_y); } delete panel; panel = 0; }
possible_end_play_signal playmp_controller::play_human_turn(){ LOG_NG << "playmp::play_human_turn...\n"; remove_blindfold(); int cur_ticks = SDL_GetTicks(); show_turn_dialog(); if (!preferences::disable_auto_moves()) { HANDLE_END_PLAY_SIGNAL(execute_gotos()); } if (!linger_ || is_host()) { end_turn_enable(true); } while(!end_turn_) { turn_info_send send_safe(turn_data_); config cfg; if(network_reader_.read(cfg)) { turn_info::PROCESS_DATA_RESULT res; HANDLE_END_PLAY_SIGNAL( res = turn_data_.process_network_data(cfg, skip_replay_) ); //PROCESS_RESTART_TURN_TEMPORARY_LOCAL should be impossible because that's means the currently active side (that's us) left. if (res == turn_info::PROCESS_RESTART_TURN || res == turn_info::PROCESS_RESTART_TURN_TEMPORARY_LOCAL) { // Clean undo stack if turn has to be restarted (losing control) if ( undo_stack_->can_undo() ) { font::floating_label flabel(_("Undoing moves not yet transmitted to the server.")); SDL_Color color = {255,255,255,255}; flabel.set_color(color); SDL_Rect rect = gui_->map_area(); flabel.set_position(rect.w/2, rect.h/2); flabel.set_lifetime(150); flabel.set_clip_rect(rect); font::add_floating_label(flabel); } while( undo_stack_->can_undo() ) undo_stack_->undo(); end_turn_struct ets = {static_cast<unsigned>(gui_->playing_side())}; return possible_end_play_signal(ets); //throw end_turn_exception(gui_->playing_side()); } else if(res == turn_info::PROCESS_END_LINGER) { if(!linger_) replay::process_error("Received unexpected next_scenario durign the game"); else { //we end the turn immidiately to prevent receiving data of the next scenario while we are not playing it. end_turn(); } } } HANDLE_END_PLAY_SIGNAL( play_slice() ); HANDLE_END_PLAY_SIGNAL( check_end_level() ); if (!linger_ && (current_team().countdown_time() > 0) && saved_game_.mp_settings().mp_countdown) { SDL_Delay(1); const int ticks = SDL_GetTicks(); int new_time = current_team().countdown_time()-std::max<int>(1,(ticks - cur_ticks)); if (new_time > 0 ){ current_team().set_countdown_time(new_time); cur_ticks = ticks; if(current_team().is_human() && !beep_warning_time_) { beep_warning_time_ = new_time - WARNTIME + ticks; } if(counting_down()) { think_about_countdown(ticks); } } else { // Clock time ended // If no turn bonus or action bonus -> defeat const int action_increment = saved_game_.mp_settings().mp_countdown_action_bonus; if ( (saved_game_.mp_settings().mp_countdown_turn_bonus == 0 ) && (action_increment == 0 || current_team().action_bonus_count() == 0)) { // Not possible to end level in MP with throw end_level_exception(DEFEAT); // because remote players only notice network disconnection // Current solution end remaining turns automatically current_team().set_countdown_time(10); } return possible_end_play_signal(end_turn_exception().to_struct()); //throw end_turn_exception(); } } gui_->draw(); } return boost::none; }