Пример #1
0
void recall_result::do_check_before()
{
	LOG_AI_ACTIONS << " check_before " << *this << std::endl;
	const game_info& s_info = get_subjective_info();
	const game_info& info = get_info();

	const unit_map& s_units = s_info.units;
	const unit_map& units = info.units;

	const team& s_my_team = get_my_team(s_info);
	const team& my_team = get_my_team(info);

	//Unit available for recalling?
	if ( !test_available_for_recalling(s_my_team) ||
	    (is_execution() && using_subjective_info() &&
	     !test_available_for_recalling(my_team, true)))
	{
		return;
	}

	//Enough gold?
	if (!test_enough_gold(s_my_team) ||
	    (is_execution() && using_subjective_info() &&
	     !test_enough_gold(my_team, true)))
	{
		return;
	}

	//Leader present?
	const unit *s_my_leader = get_leader(s_units);

	if (!s_my_leader ||
	    (is_execution() && using_subjective_info() &&
	     !get_leader(units, true)))
	{
		return;
	}

	//Leader on keep?
	const gamemap& s_map = s_info.map;
	const gamemap& map = info.map;

	if (!test_leader_on_keep(s_map, *s_my_leader) ||
	    (is_execution() && using_subjective_info() &&
	     !test_leader_on_keep(map, *s_my_leader, true)))
	{
		return;
	}

	//Try to get suitable recall location. Is suitable location available ?
	if (!test_suitable_recall_location(s_map, s_units, *s_my_leader) ||
	    (is_execution() && using_subjective_info() &&
	     !test_suitable_recall_location(map, units, *s_my_leader, true)))
	{
		return;
	}

}
Пример #2
0
static char *
unit_move_getpath(struct emp_qelem *list, int suppress_map, char *path)
{
    struct empobj *leader = get_leader(list);
    double minmob, maxmob;
    struct emp_qelem *qp;
    struct ulist *ulp;
    char prompt[64];

    minmob = HUGE_VAL;
    maxmob = -HUGE_VAL;
    for (qp = list->q_back; qp != list; qp = qp->q_back) {
	ulp = (struct ulist *)qp;
	if (ulp->mobil < minmob)
	    minmob = ulp->mobil;
	if (ulp->mobil > maxmob)
	    maxmob = ulp->mobil;
    }
    if (!suppress_map)
	nav_map(leader->x, leader->y,
		leader->ef_type == EF_SHIP
		? !(mchr[leader->type].m_flags & M_SUB) : 1);
    snprintf(prompt, sizeof(prompt), "<%.1f:%.1f: %s> ",
	     maxmob, minmob,
	     xyas(leader->x, leader->y, player->cnum));
    return getstring(prompt, path);
}
Пример #3
0
std::vector<std::string> Company::get_all_members() const
{
    std::vector<std::string> all_members;
    all_members.push_back(get_leader());
    all_members.push_back(get_medical());
    all_members.insert(all_members.end(), get_members().begin(), get_members().end());
    return all_members;
}
Пример #4
0
void leader_list_manager::set_gender_combo(gui::combo* combo)
{
	gender_combo_ = combo;

	if(gender_combo_ != NULL) {
		if(!leaders_.empty()) {
			update_gender_list(get_leader());
		}
	}
}
Пример #5
0
int main(int argc, int *argv[])
{
	bool quit = false;	/* quit flag */
	int i, j;
	int play_stat = 0;
	Timer fps;		/* cap frame rate */
	SDL_Event event;
	SDL_Surface *mouseother;
	SDL_Surface *wintitle[3];
	SDL_Surface *screen;		 /* main screen */
	SDL_Surface *chessboard;	 /* chess board */
	Button pieces[CHESSBOARD_ROW][CHESSBOARD_COLUMN] = {{0}};
	SDL_Surface *piece_stat_img[PIECE_STAT + 1] = {NULL}; /* pieces image */
	int mouse_map[CHESSBOARD_ROW][CHESSBOARD_COLUMN] = {{0}}; /* click or not */
	int pieces_map[CHESSBOARD_ROW][CHESSBOARD_COLUMN] = {{0}}; /* pieces state */
	
	/* Init SDL lib*/
	if(SDL_Init(SDL_INIT_EVERYTHING) == -1){
		return 1;
	}
	
	/* Init screen */
	screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
	if(screen == NULL){
		return 1;
	}
	SDL_WM_SetCaption("XO_OX", NULL);
	
	/* Load resource */
	piece_stat_img[1] = load_image("xooxres/chess1.png");
	piece_stat_img[2] = load_image("xooxres/chess2.png");
	piece_stat_img[3] = piece_stat_img[1]; /* for special show, but no time to do */
	piece_stat_img[4] = piece_stat_img[2]; /* for special show, but no time to do */
	chessboard = load_image("xooxres/chessboard.png");
	mouseother = load_image("xooxres/mouseother.png");
	wintitle[0] = load_image("xooxres/wintitle1.png");
	wintitle[1] = load_image("xooxres/wintitle2.png");
	wintitle[2] = load_image("xooxres/wintitle3.png");

	/* Init timer */
	timer_init(&fps);

	/* Init button */
	for(i = 0; i < CHESSBOARD_ROW; i++){
		for(j = 0; j < CHESSBOARD_COLUMN; j++){
			button_init(&pieces[i][j], SUBBOARD_WIDTH  * i, SUBBOARD_HEIGHT  * j, SUBBOARD_WIDTH , SUBBOARD_HEIGHT );
			button_set_stat_img(&pieces[i][j], BUTTON_MOUSEOVER, NULL);
			button_set_stat_img(&pieces[i][j], BUTTON_MOUSEOUT, mouseother);
			button_set_stat_img(&pieces[i][j], BUTTON_MOUSEUP, mouseother);
			button_set_stat_img(&pieces[i][j], BUTTON_MOUSEDOWN, mouseother);
		}
	}

	/* Main loop */
	while(quit == false){
		/* timer start */
		timer_start(&fps); 
		while(SDL_PollEvent(&event)){
			/* Pieces input handle */
			pieces_handle_event(pieces, mouse_map, &event);
			
			/* User quit */
			if(event.type == SDL_QUIT){
				quit = true;
			}
		}
		/* logic function */
		play_stat = mouse_to_piece_map(mouse_map, pieces_map);
		/* show chessboard */
		subchessboard_show(piece_stat_img[get_leader()], mouseother, mouse_map, screen);
		/* show pieces */
		pieces_show(piece_stat_img, pieces_map, screen);
		/*  */
		if(play_stat != 0){
			printf("play_stat = %d\n", play_stat);
			apply_surface((SCREEN_WIDTH - wintitle[play_stat - 1]->w) / 2, (SCREEN_HEIGHT - wintitle[play_stat - 1]->h) / 2, wintitle[play_stat - 1], screen);
		}

		/* Update screen */
		if(SDL_Flip(screen) == -1){
			return 1;
		}
		
		if(play_stat != 0){
			SDL_Delay(3000);
			quit = true;
		}
		/* cap frame rate */
		if(timer_get_ticks(&fps) < 1000 / FRAME_PER_SECOND){
			SDL_Delay((1000 / FRAME_PER_SECOND) - timer_get_ticks(&fps));
		}
	}

	/* Free resource */
	SDL_FreeSurface(chessboard);
	SDL_FreeSurface(mouseother);
	for(i = 0; i < 2; i++){
		SDL_FreeSurface(piece_stat_img[i]);
	}
	for(i = 0; i < 3; i++){
		SDL_FreeSurface(wintitle[i]);
	}
	
	SDL_Quit();
	return 0;
}
Пример #6
0
int
unit_move(struct emp_qelem *list)
{
    struct empobj *leader = get_leader(list);
    int leader_uid = leader->uid;
    int type = leader->ef_type;
    int moved, suppress_map, dir, stopping;
    char *cp;
    char path[1024];

    unit_rad_map_set(list);

    pr("%s is %s\n",
	type == EF_SHIP ? "Flagship" : "Leader",
	unit_nameof(leader));

    cp = "";
    if (player->argp[2]) {
	strcpy(path, player->argp[2]);
	cp = unit_move_route(leader, path, sizeof(path));
	if (!cp)
	    cp = "";
    }

    moved = suppress_map = 0;
    for (;;) {
	/*
	 * Invariants:
	 * - shp_may_nav() true for all ships
	 * - lnd_may_mar() true for all land units
	 * - leader is up-to-date
	 * Implies all are in the same sector
	 */
	if (!*cp) {
	    cp = unit_move_getpath(list, suppress_map, path);
	    if (!cp) {
		if (type == EF_SHIP) {
		    shp_nav_stay_behind(list, player->cnum);
		    shp_nav_put(list, player->cnum);
		} else {
		    lnd_mar_stay_behind(list, player->cnum);
		    lnd_mar_put(list, player->cnum);
		}
		return RET_FAIL;
	    }
	    cp = unit_move_route(leader, path, sizeof(path));
	    if (!cp || !*cp)
		cp = "h";
	    suppress_map = 0;
	} else if ((dir = chkdir(*cp, DIR_STOP, DIR_LAST)) >= 0) {
	    cp++;
	    if (type == EF_SHIP)
		stopping = shp_nav_dir(list, dir, player->cnum)
		    || shp_nav_gauntlet(list, 1, player->cnum);
	    else {
		if (!moved && !lnd_abandon_askyn(list)) {
		    lnd_mar_put(list, player->cnum);
		    return RET_FAIL;
		}
		stopping = lnd_mar_dir(list, dir, player->cnum)
		    || lnd_mar_gauntlet(list, 1, player->cnum);
	    }
	    if (dir == DIR_STOP) {
		CANT_HAPPEN(!QEMPTY(list));
		return RET_OK;
	    }
	    moved = 1;
	    if (stopping)
		cp = "";
	} else {
	    cp = unit_move_non_dir(list, cp, &suppress_map);
	    if (!cp) {
		direrr("`%c' to stop", ", `%c' to view", NULL);
		pr(", `i' to list %s, `f' to change %s,\n",
		   type == EF_SHIP ? "ships" : "units",
		   type == EF_SHIP ? "flagship" : "leader");
		pr("`r' to radar, %s`l' to look, `M' to map, `B' to bmap,\n",
		   type == EF_SHIP ? "`s' to sonar, " : "");
		pr("`d' to drop mines, and `m' to minesweep\n");
		cp = "";
	    }
	}

	if (type == EF_SHIP)
	    shp_nav_stay_behind(list, player->cnum);
	else
	    lnd_mar_stay_behind(list, player->cnum);

	if (QEMPTY(list)) {
	    pr("No %s left\n", type == EF_SHIP ? "ships" : "lands");
	    return RET_OK;
	}

	leader = get_leader(list);
	if (leader->uid != leader_uid) {
	    leader_uid = leader->uid;
	    pr("Changing %s to %s\n",
	       leader->ef_type == EF_SHIP ? "flagship" : "leader",
	       unit_nameof(leader));
	}
	unit_rad_map_set(list);
    }
}
Пример #7
0
static char *
unit_move_non_dir(struct emp_qelem *list, char *cp, int *map_shown)
{
    struct empobj *leader = get_leader(list);
    int bmap = 0, stopping;
    char leader_str[32];

    *map_shown = 0;
    sprintf(leader_str, "%d", leader->uid);

    switch (*cp) {
    case 'B':
	bmap = 'b';
	/* fall through */
    case 'M':
	cp = unit_move_parse(cp, leader_str);
	display_region_map(bmap, leader->ef_type, leader->x, leader->y,
			   player->argp[1], player->argp[2]);
	*map_shown = 1;
	break;
    case 'f':
	cp = unit_move_parse(cp, NULL);
	switch_leader(list, player->argp[1]);
	break;
    case 'i':
	cp++;
	unit_list(list);
	break;
    case 'm':
	cp++;
	if (leader->ef_type == EF_SHIP)
	    stopping = shp_sweep(list, 1, 1, player->cnum);
	else
	    stopping = lnd_sweep(list, 1, 1, player->cnum);
	if (stopping)
	    cp = "";
	break;
    case 'r':
	cp = unit_move_parse(cp, leader_str);
	radar(leader->ef_type);
	player->btused++;	/* FIXME use player_coms[].c_cost */
	*map_shown = 1;
	break;
    case 'l':
	cp = unit_move_parse(cp, leader_str);
	do_look(leader->ef_type);
	player->btused++;	/* FIXME likewise */
	break;
    case 's':
	if (leader->ef_type != EF_SHIP)
	    return NULL;
	cp = unit_move_parse(cp, leader_str);
	sona();
	player->btused++;	/* FIXME likewise */
	*map_shown = 1;
	break;
    case 'd':
	cp = unit_move_parse(cp, NULL);
	if (!player->argp[1]) {
	    player->argp[1] = leader_str;
	    player->argp[2] = "1";
	} else if (!player->argp[2]) {
	    player->argp[2] = player->argp[1];
	    player->argp[1] = leader_str;
	}
	if (leader->ef_type == EF_SHIP)
	    mine();
	else
	    landmine();
	player->btused++;	/* FIXME likewise */
	*map_shown = 1;
	break;
    case 'v':
	cp++;
	unit_view(list);
	break;
    default:
	return NULL;
    }

    return cp;
}