Beispiel #1
0
static void run_penalty_kick_shootout() {

  show_message("PENALTY KICK SHOOT-OUT!");
  step();

  // power off robots and move them out of the field
  int i;
  for (i = 0; i < NUM_ROBOTS; i++) {
    // keep RED_PLAYER_1 and BLUE_GOAL_KEEPER for the shootout
    if (i != ATTACKER && i != GOALIE) {
      // make them zombies
      set_controller(i, "void");

      if (robot_translation[i]) {
        // move them out of the field but preserve elevation
        double elevation = wb_supervisor_field_get_sf_vec3f(robot_translation[i])[Y];
        double out_of_field[3] = { 1.0 * i, elevation, 5.0 };
        wb_supervisor_field_set_sf_vec3f(robot_translation[i], out_of_field);
      }
    }
  }

  // inform robots of the penalty kick shootout
  control_data.secondaryState = STATE2_PENALTYSHOOT;

  // five penalty shots per team
  for (i = 0; i < 5; i++) {
    run_penalty_kick(60);
    if (check_victory(5 - i)) return;
    run_finished_state();
    swap_teams_and_scores();
    run_penalty_kick(60);
    if (check_victory(4 - i)) return;
    run_finished_state();
    swap_teams_and_scores();
  }
  
  if (match_type == FINAL) {
    show_message("SUDDEN DEATH SHOOT-OUT!");
    
    // sudden death shots
    while (1) {
      run_penalty_kick(120);
      run_finished_state();
      swap_teams_and_scores();
      run_penalty_kick(120);
      if (check_victory(0)) return;
      run_finished_state();
      swap_teams_and_scores();
    }
  }
}
void playsingle_controller::check_time_over(){
	bool time_left = gamestate_.tod_manager_.next_turn(gamestate_.gamedata_);
	it_is_a_new_turn_ = true;
	if(!time_left) {
		LOG_NG << "firing time over event...\n";
		set_scontext_synced_base sync;
		pump().fire("time over");
		LOG_NG << "done firing time over event...\n";
		//if turns are added while handling 'time over' event
		if (gamestate_.tod_manager_.is_time_left()) {
			return;
		}

		if(non_interactive()) {
			LOG_AIT << "time over (draw)\n";
			ai_testing::log_draw();
		}

		check_victory();
		if (is_regular_game_end()) {
			return;
		}
		end_level_data e;
		e.proceed_to_next_level = false;
		e.is_victory = false;
		set_end_level_data(e);
	}
}
possible_end_play_signal playsingle_controller::check_time_over() {
    bool b = gamestate_.tod_manager_.next_turn(*resources::gamedata);
    it_is_a_new_turn_ = true;
    if(!b) {

        LOG_NG << "firing time over event...\n";
        game_events::fire("time over");
        LOG_NG << "done firing time over event...\n";
        //if turns are added while handling 'time over' event
        if (gamestate_.tod_manager_.is_time_left()) {
            return boost::none;
        }

        if(non_interactive()) {
            LOG_AIT << "time over (draw)\n";
            ai_testing::log_draw();
        }

        HANDLE_END_PLAY_SIGNAL( check_victory() );

        get_end_level_data().proceed_to_next_level = false;

        end_level_struct els = {DEFEAT};
        return possible_end_play_signal (els);
        //throw end_level_exception(DEFEAT);
    }
    return boost::none;
}
Beispiel #4
0
void play_controller::finish_side_turn()
{
    whiteboard_manager_->on_finish_side_turn(current_side());

    {   //Block for set_scontext_synced
        set_scontext_synced sync(1);
        // Ending the turn commits all moves.
        undo_stack().clear();
        gamestate().board_.end_turn(current_side());
        const std::string turn_num = std::to_string(turn());
        const std::string side_num = std::to_string(current_side());

        // Clear shroud, in case units had been slowed for the turn.
        actions::clear_shroud(current_side());

        pump().fire("side_turn_end");
        pump().fire("side_"+ side_num + "_turn_end");
        pump().fire("side_turn_" + turn_num + "_end");
        pump().fire("side_" + side_num + "_turn_" + turn_num + "_end");
        // This is where we refog, after all of a side's events are done.
        actions::recalculate_fog(current_side());
        check_victory();
        sync.do_final_checkup();
    }

    mouse_handler_.deselect_hex();
    resources::gameboard->unit_id_manager().reset_fake();
    gamestate_->init_side_done() = false;
}
Beispiel #5
0
void			my_init_serveur(t_server *s_info) {
  fd_set		readfds;
  int			i = 0;
  time_t		*t;
  struct timeval	*time;

  create_socket_s(s_info);
  s_info->graph = 0;
  my_prompt_welc(s_info);
  s_info->list = NULL;
  s_info->egg = NULL;
  create_ele_fct(s_info);
  while (check_victory(s_info) != 1) {
    time->tv_sec= 1;
    FD_ZERO(&readfds);
    FD_SET(socket_s, &readfds);
    parc_sock(s_info);
    s_info->list = parse_list(s_info);
    i = 0;
    while (socket_com[i].socket != -2) {
      if (socket_com[i].socket != -1)
	FD_SET(socket_com[i].socket, &readfds);
      i++;
    }
    select_s(s_info, &readfds, time);
  }
}
void playsingle_controller::play_human_turn() {
	show_turn_dialog();
	execute_gotos();

	end_turn_enable(true);
	while(!end_turn_) {
		play_slice();
		check_victory();
		gui_->draw();
	}
}
Beispiel #7
0
int		incantation(char **av, t_client *cl, t_kernel *kernel)
{
  int		check;
  t_case	*c;

  (void)av;
  check = 0;
  c = get_case(kernel, cl->player->pos.y, cl->player->pos.x);
  if (check_case_for_incantation(c, cl->player->level))
    check = 1;
  finish_elevation(c, cl->player->level + check);
  send_finish_elevation_to_graphic(kernel, c, cl->player, check);
  return (check_victory(kernel));
}
// @save: It isn't mean this is loaded game. it mean whether execute auto-save. 
//        false: this is first turn of loaded game, true: this isn't first turn or this isn't loaded game.
void playsingle_controller::play_turn(bool save)
{
	gui_->new_turn();
	gui_->invalidate_game_status();
	events::raise_draw_event();


	play_side();

	check_victory();

	// Time has run out
	check_time_over();

	finish_turn();
}
Beispiel #9
0
int 	main(int argc, char **argv)
{
	t_env	e;

	if ((e.key = ftok(argv[0], 'a')) < 0)
	{
		perror("ftok");
		exit(1);
	}
	// printf("e.key : %d\n", e.key);
	if (argc == 2)
	{
		init_env(&e, argv[1]);
		while (1)
		{
			printf("ICI\n");
			op_sem_proberen(&e);
			printf("LA\n");
			// printf("heya\n");
			if ((*((int*)(e.addr + sizeof(int)))) == 0)
			{
				check_start(&e);
				op_sem_verhogen(&e);
				continue ;
			}
			printf("hey0\n");
			test_print(&e);
			if (check_elim(&e))
				player_lost(&e);
			msg_read(&e);
			printf("hey1\n");
			begin_turn(&e);
			op_sem_verhogen(&e);
			if ((*((int*)(e.addr + sizeof(int)))) == 1 && check_victory(&e))
			{
				printf("VICTOIRRRRRRRRE team : %d\n", e.team);
				kill_player(&e);
			}	
			printf("leader : %d\n", e.leader);
			usleep(500000);
		}
	}
	else
		printf("Usage : %s [team]\n", argv[0]);
	return (0);
}
// @save: It isn't mean this is loaded game. it mean whether execute auto-save. 
//        false: this is first turn of loaded game, true: this isn't first turn or this isn't loaded game.
void playsingle_controller::play_turn(bool save)
{
	gui_->new_turn();
	gui_->invalidate_game_status();
	events::raise_draw_event();

	for (player_number_ = first_player_; player_number_ <= int(teams_.size()); ++player_number_) {
		unit_display::player_number_ = player_number_;
		// If a side is empty skip over it.
		if (current_team().is_empty()) continue;
		try {
			save_blocker blocker;
			init_side(player_number_ - 1, false, save || (player_number_ != first_player_));
		} catch (end_turn_exception) {
			if (current_team().is_network() == false) {
				turn_info turn_data(player_number_, replay_sender_, undo_stack_);
				recorder.end_turn();
				turn_data.sync_network();
			}
			continue;
		}

		// If a side is dead end the turn.
		if (current_team().is_human() && side_units(player_number_) == 0) {
			turn_info turn_data(player_number_, replay_sender_, undo_stack_);
			recorder.end_turn();
			turn_data.sync_network();
			continue;
		}

		play_side(player_number_, save);

		finish_side_turn();

		check_victory();

		//if loading a savegame, network turns might not have reset this yet
		loading_game_ = false;
	}

	// Time has run out
	check_time_over();

	finish_turn();
}
void playsingle_controller::check_time_over(){
	bool b = tod_manager_.next_turn();
	it_is_a_new_turn_ = true;
	if(!b) {

		LOG_NG << "firing time over event...\n";
		game_events::fire("time over");
		LOG_NG << "done firing time over event...\n";
		//if turns are added while handling 'time over' event
		if (tod_manager_.is_time_left()) {
			return;
		}

		if(non_interactive()) {
			LOG_AIT << "time over (draw)\n";
			ai_testing::log_draw();
		}

		check_victory();
		throw end_level_exception(DEFEAT);
	}
}
void playsingle_controller::play_turn(bool save)
{
	resources::whiteboard->on_gamestate_change();
	gui_->new_turn();
	gui_->invalidate_game_status();
	events::raise_draw_event();

	LOG_NG << "turn: " << turn() << "\n";

	if(non_interactive())
		std::cout << "Turn " << turn() << ":" << std::endl;


	for (player_number_ = first_player_; player_number_ <= int(teams_.size()); ++player_number_)
	{
		// If a side is empty skip over it.
		if (current_team().is_empty()) continue;
		try {
			save_blocker blocker;
			init_side(player_number_ - 1);
		} catch (end_turn_exception) {
			if (current_team().is_network() == false) {
				turn_info turn_data(player_number_, replay_sender_);
				recorder.end_turn();
				turn_data.sync_network();
			}
			continue;
		}

		if (replaying_) {
			LOG_NG << "doing replay " << player_number_ << "\n";
			replaying_ = ::do_replay(player_number_);
			LOG_NG << "result of replay: " << (replaying_?"true":"false") << "\n";
		} else {
			// If a side is dead end the turn, but play at least side=1's
			// turn in case all sides are dead
			if (current_team().is_human() && side_units(player_number_) == 0
				&& (resources::units->size() != 0 || player_number_ != 1))
			{
				turn_info turn_data(player_number_, replay_sender_);
				recorder.end_turn();
				turn_data.sync_network();
				continue;
			}
			ai_testing::log_turn_start(player_number_);
			play_side(player_number_, save);
		}

		finish_side_turn();

		if(non_interactive()) {
			std::cout << " Player " << player_number_ << ": " <<
				current_team().villages().size() << " Villages" <<
				std::endl;
			ai_testing::log_turn_end(player_number_);
		}

		check_victory();

		//if loading a savegame, network turns might not have reset this yet
		loading_game_ = false;
	}

	finish_turn();

	// Time has run out
	check_time_over();
}
Beispiel #13
0
possible_end_play_signal playsingle_controller::play_turn()
{
    whiteboard_manager_->on_gamestate_change();
    gui_->new_turn();
    gui_->invalidate_game_status();
    events::raise_draw_event();

    LOG_NG << "turn: " << turn() << "\n";

    if(non_interactive()) {
        LOG_AIT << "Turn " << turn() << ":" << std::endl;
    }

    for (player_number_ = first_player_; player_number_ <= int(gamestate_.board_.teams().size()); ++player_number_)
    {
        // If a side is empty skip over it.
        if (current_team().is_empty()) continue;

        possible_end_play_signal signal;
        {
            save_blocker blocker;
            signal = init_side();
        }

        if (signal) {
            switch (boost::apply_visitor(get_signal_type(), *signal)) {
            case END_TURN:
                if (current_team().is_network() == false) {
                    turn_data_.send_data();
                    recorder.end_turn();
                    turn_data_.sync_network();
                }
                continue;
            case END_LEVEL:
                return signal;
            }
        }

        if (replaying_) {
            LOG_NG << "doing replay " << player_number_ << "\n";
            HANDLE_END_PLAY_SIGNAL ( replaying_ = ::do_replay() == REPLAY_FOUND_END_TURN );
            LOG_NG << "result of replay: " << (replaying_?"true":"false") << "\n";
        } else {
            ai_testing::log_turn_start(player_number_);
            PROPOGATE_END_PLAY_SIGNAL ( play_side() );
        }

        finish_side_turn();

        if(non_interactive()) {
            LOG_AIT << " Player " << player_number_ << ": " <<
                    current_team().villages().size() << " Villages" <<
                    std::endl;
            ai_testing::log_turn_end(player_number_);
        }

        HANDLE_END_PLAY_SIGNAL ( check_victory() );

        //if loading a savegame, network turns might not have reset this yet
        loading_game_ = false;
    }
    //If the loop exits due to the last team having been processed,
    //player_number_ will be 1 too high
    if(player_number_ > static_cast<int>(gamestate_.board_.teams().size()))
        player_number_ = gamestate_.board_.teams().size();

    finish_turn();

    // Time has run out
    PROPOGATE_END_PLAY_SIGNAL ( check_time_over() );
    return boost::none;
}
Beispiel #14
0
void play_controller::do_init_side()
{
    set_scontext_synced sync;
    log_scope("player turn");
    // In case we might end up calling sync:network during the side turn events,
    // and we don't want do_init_side to be called when a player drops.
    gamestate_->init_side_done() = true;
    init_side_done_now_ = true;

    const std::string turn_num = std::to_string(turn());
    const std::string side_num = std::to_string(current_side());

    gamestate().gamedata_.get_variable("side_number") = current_side();

    // We might have skipped some sides because they were empty so it is not enough to check for side_num==1
    if(!gamestate().tod_manager_.has_turn_event_fired())
    {
        pump().fire("turn_" + turn_num);
        pump().fire("new_turn");
        gamestate().tod_manager_.turn_event_fired();
    }

    pump().fire("side_turn");
    pump().fire("side_" + side_num + "_turn");
    pump().fire("side_turn_" + turn_num);
    pump().fire("side_" + side_num + "_turn_" + turn_num);

    // We want to work out if units for this player should get healed,
    // and the player should get income now.
    // Healing/income happen if it's not the first turn of processing,
    // or if we are loading a game.
    if (turn() > 1) {
        gamestate().board_.new_turn(current_side());
        current_team().new_turn();

        // If the expense is less than the number of villages owned
        // times the village support capacity,
        // then we don't have to pay anything at all
        int expense = gamestate().board_.side_upkeep(current_side()) -
                      current_team().support();
        if(expense > 0) {
            current_team().spend_gold(expense);
        }

        calculate_healing(current_side(), !is_skipping_replay());
    }

    // Prepare the undo stack.
    undo_stack().new_side_turn(current_side());

    pump().fire("turn_refresh");
    pump().fire("side_" + side_num + "_turn_refresh");
    pump().fire("turn_" + turn_num + "_refresh");
    pump().fire("side_" + side_num + "_turn_" + turn_num + "_refresh");

    // Make sure vision is accurate.
    actions::clear_shroud(current_side(), true);
    init_side_end();
    check_victory();
    sync.do_final_checkup();
}
Beispiel #15
0
int		check_end(int **grid)
{
	return (check_victory(grid) || check_lose(grid));
}