Exemplo n.º 1
0
/*
 * Initialize a game.
 */
void init_game(game *g)
{
	player *p_ptr;
	design *d_ptr;
	card *c_ptr;
	int goal[MAX_GOAL];
	int i, j, k, n;
	int num_goal = 0;

	/* Save current random seed */
	g->start_seed = g->random_seed;

#if 0
	sprintf(msg, "start seed: %u\n", g->start_seed);
	message_add(msg);
#endif

	/* Apply campaign options */
	apply_campaign(g);

	/* Game is not simulated */
	g->simulation = 0;

	/* Set size of VP pool */
	g->vp_pool = g->num_players * 12;

	/* Increase size of pool in third expansion */
	if (g->expanded == 3) g->vp_pool += 5;

	/* No game round yet */
	g->round = 0;

	/* No phase or turn */
	g->cur_action = ACT_ROUND_START;
	g->turn = 0;

	/* Clear selected actions */
	for (i = 0; i < MAX_ACTION; i++) g->action_selected[i] = 0;

	/* Game is not over */
	g->game_over = 0;

	/* No cards in deck yet */
	g->deck_size = 0;

	/* Clear goals */
	for (i = 0; i < MAX_GOAL; i++)
	{
		/* Goal is not active */
		g->goal_active[i] = 0;

		/* Goal is not available */
		g->goal_avail[i] = 0;
	}

	/* Clear number of pending takeovers */
	g->num_takeover = 0;

	/* Set Oort Cloud kind to "any" */
	g->oort_kind = GOOD_ANY;

	/* Loop over card designs */
	for (i = 0; i < num_design; i++)
	{
		/* Get design pointer */
		d_ptr = &library[i];

		/* Get number of cards in use */
		n = d_ptr->expand[g->expanded];

		/* Skip promo cards if not included */
		if (!g->promo && (d_ptr->flags & FLAG_PROMO)) n = 0;

		/* Add cards */
		for (j = 0; j < n; j++)
		{
			/* Check for too large deck */
			if (g->deck_size >= MAX_DECK)
			{
				/* Error */
				display_error("Deck is too large!");
				exit(1);
			}

			/* Get card pointer */
			c_ptr = &g->deck[g->deck_size++];

			/* No owner */
			c_ptr->start_owner = c_ptr->owner = -1;

			/* Put location in draw deck */
			c_ptr->start_where = c_ptr->where = WHERE_DECK;

			/* Clear card misc flags */
			c_ptr->misc = 0;

			/* Set card's design */
			c_ptr->d_ptr = d_ptr;

			/* Card is not covering another */
			c_ptr->covering = -1;

			/* No goods on card */
			c_ptr->num_goods = 0;

			/* Card is not followed by any other */
			c_ptr->next = c_ptr->start_next = -1;
		}
	}

	/* Loop over players */
	for (i = 0; i < g->num_players; i++)
	{
		/* Get player pointer */
		p_ptr = &g->p[i];

		/* Clear all claimed goals */
		for (j = 0; j < MAX_GOAL; j++)
		{
			/* Goal is unclaimed */
			p_ptr->goal_claimed[j] = 0;

			/* No progress toward goal */
			p_ptr->goal_progress[j] = 0;
		}

		/* Player has no actions chosen */
		p_ptr->action[0] = p_ptr->prev_action[0] = -1;
		p_ptr->action[1] = p_ptr->prev_action[1] = -1;

		/* Player has not used prestige/search action */
		p_ptr->prestige_action_used = 0;

		/* Player has not used phase bonus */
		p_ptr->phase_bonus_used = 0;

		/* Player has no card to be placed */
		p_ptr->placing = -1;

		/* Player has no cards in any area */
		for (j = 0; j < MAX_WHERE; j++)
		{
			/* Clear list head */
			p_ptr->head[j] = -1;
			p_ptr->start_head[j] = -1;
		}

		/* Player has no bonus military accrued */
		p_ptr->bonus_military = 0;

		/* Player has no bonus settle discount */
		p_ptr->bonus_reduce = 0;

		/* Player has not used any partial hand military powers */
		p_ptr->hand_military_spent = 0;

		/* Player has not spent any military */
		p_ptr->military_spent = 0;

		/* Player has not discarded any end of turn cards */
		p_ptr->end_discard = 0;

		/* No cards played yet */
		p_ptr->table_order = 0;

		/* Player has no prestige */
		p_ptr->prestige = p_ptr->prestige_turn = 0;

		/* Player has no points */
		p_ptr->vp = p_ptr->goal_vp = p_ptr->end_vp = 0;

		/* Player is not the winner */
		p_ptr->winner = 0;

		/* Player has earned no rewards this phase */
		p_ptr->phase_cards = p_ptr->phase_vp = 0;
		p_ptr->phase_prestige = 0;

		/* Player has no fake cards */
		p_ptr->fake_hand = 0;
		p_ptr->fake_discards = 0;
		p_ptr->drawn_round = 0;

		/* Player has not skipped build phases */
		p_ptr->skip_develop = p_ptr->skip_settle = 0;

		/* Clear lowest hand size */
		p_ptr->low_hand = 0;
	}

	/* Check for campaign */
	if (g->camp)
	{
		/* Set aside campaign cards */
		init_campaign(g);
	}

	/* Add goals when expanded */
	if (g->expanded > 0 && g->expanded < 4 && !g->goal_disabled)
	{
		/* No goals available yet */
		n = 0;

		/* Use correct "first" goals */
		if (g->expanded == 1)
		{
			/* First expansion only */
			j = GOAL_FIRST_5_VP;
			k = GOAL_FIRST_SIX_DEVEL;
		}
		else if (g->expanded == 2)
		{
			/* First and second expansion */
			j = GOAL_FIRST_5_VP;
			k = GOAL_FIRST_8_ACTIVE;
		}
		else
		{
			/* All expansions */
			j = GOAL_FIRST_5_VP;
			k = GOAL_FIRST_4_MILITARY;
		}

		/* Add "first" goals to list */
		for (i = j; i <= k; i++)
		{
			/* Add goal to list */
			goal[n++] = i;
		}

		/* Assume no campaign goals */
		k = 0;

		/* Check for campaign goals */
		if (g->camp) num_goal = g->camp->num_goal;

		/* Loop over campaign goals */
		for (i = 0; i < num_goal; i++)
		{
			/* Skip "most" goals */
			if (g->camp->goal[i] > GOAL_FIRST_4_MILITARY) continue;

			/* Goal is active */
			g->goal_active[g->camp->goal[i]] = 1;

			/* Goal is available */
			g->goal_avail[g->camp->goal[i]] = 1;

			/* Remove campaign goal from list */
			for (j = 0; j < n; j++)
			{
				/* Check for match */
				if (goal[j] == g->camp->goal[i])
				{
					/* Remove from list */
					goal[j] = goal[--n];
				}
			}

			/* Count campaign "first" goals */
			k++;
		}

		/* Select four "first" goals at random */
		for (i = k; i < 4; i++)
		{
			/* Choose goal at random */
			j = game_rand(g) % n;

			/* Goal is active */
			g->goal_active[goal[j]] = 1;

			/* Goal is available */
			g->goal_avail[goal[j]] = 1;

			/* Remove chosen goal from list */
			goal[j] = goal[--n];
		}

		/* No goals available yet */
		n = 0;

		/* Use correct "most" goals */
		if (g->expanded == 1)
		{
			/* First expansion only */
			j = GOAL_MOST_MILITARY;
			k = GOAL_MOST_PRODUCTION;
		}
		else if (g->expanded == 2)
		{
			/* First and second expansion */
			j = GOAL_MOST_MILITARY;
			k = GOAL_MOST_REBEL;
		}
		else
		{
			/* All expansions */
			j = GOAL_MOST_MILITARY;
			k = GOAL_MOST_CONSUME;
		}

		/* Add "most" goals to list */
		for (i = j; i <= k; i++)
		{
			/* Add goal to list */
			goal[n++] = i;
		}

		/* Assume no campaign goals */
		k = 0;

		/* Loop over campaign goals */
		for (i = 0; i < num_goal; i++)
		{
			/* Skip "first" goals */
			if (g->camp->goal[i] < GOAL_MOST_MILITARY) continue;

			/* Goal is active */
			g->goal_active[g->camp->goal[i]] = 1;

			/* Goal is available */
			g->goal_avail[g->camp->goal[i]] = 1;

			/* Remove campaign goal from list */
			for (j = 0; j < n; j++)
			{
				/* Check for match */
				if (goal[j] == g->camp->goal[i])
				{
					/* Remove from list */
					goal[j] = goal[--n];
				}
			}

			/* Count campaign goals */
			k++;
		}

		/* Select two "most" goals at random */
		for (i = k; i < 2; i++)
		{
			/* Choose goal at random */
			j = game_rand(g) % n;

			/* Goal is active */
			g->goal_active[goal[j]] = 1;

			/* Goal is available */
			g->goal_avail[goal[j]] = 1;

			/* Remove chosen goal from list */
			goal[j] = goal[--n];
		}
	}
}
Exemplo n.º 2
0
//-------- Begin of function Game::run_campaign --------//
//
void Game::run_campaign()
{
	err_when( cur_campaign );

	Config saveConfig = config;		// save the original config as the campaign will overwrite it.

	int rc = select_campaign_menu();

	//---- while we save the original config, we need to overwrite it with new settings the player has just chosen ---//

	saveConfig.race_id = config.race_id;
	saveConfig.player_nation_color = config.player_nation_color;

	strcpy( saveConfig.player_name, config.player_name );

	saveConfig.campaign_difficulty = config.campaign_difficulty;
	saveConfig.building_size = config.building_size;

	saveConfig.fog_of_war = config.fog_of_war;
	saveConfig.random_event_frequency = config.random_event_frequency;

	//---- create debuggin log if in testing mode -----//

#ifdef DEBUG
	if( misc.is_file_exist("CTEST.SYS") )
	{
		game.debug_log = new LongLog('0');
		game.debug_log->printf( "\n\r---------------------------\n\r" );
	}

	//---------------------------------------//

	char	total_stage_run_count_array[MAX_STAGE];
	char	total_event_run_count_array[MAX_EVENT];
	int   maxStage, maxEvent;

	memset( total_stage_run_count_array, 0, sizeof(total_stage_run_count_array) );
	memset( total_event_run_count_array, 0, sizeof(total_event_run_count_array) );
#endif

	//---------------------------------------//

	while( rc > 0 )
	{
		init_campaign(rc);

		cur_campaign->init_new_campaign();

		game.main_loop_all();

		int autoTestFlag = cur_campaign->auto_test_flag;

		//----- write debug log ---------//

#ifdef DEBUG
		if( game.debug_log )
		{
			game.debug_log->printf( "\n\r---------------------------\n\r" );

			//--- write the execution counters ----//

			int i;
			for( i=0 ; i<cur_campaign->max_stage ; i++ )
			{
				game.debug_log->printf( "Stage %d: %d\n\r", i+1, cur_campaign->stage_run_count_array[i] );		// stage run counters
				total_stage_run_count_array[i] += cur_campaign->stage_run_count_array[i];
			}

			game.debug_log->printf( "\n\r" );

			for( i=0 ; i<cur_campaign->max_event ; i++ )
			{
				game.debug_log->printf( "Event %d: %d\n\r", i+1, cur_campaign->event_run_count_array[i] );		// event run counters
				total_event_run_count_array[i] += cur_campaign->event_run_count_array[i];
			}

			maxStage = cur_campaign->max_stage;
			maxEvent = cur_campaign->max_event;

			game.debug_log->printf( "\n\r---------------------------\n\r" );
		}
#endif

		//-------------------------------------//

		deinit_all();

		if( autoTestFlag )
			rc = 1;
		else
			rc = 0;
	}

	config = saveConfig;

#ifdef DEBUG
	if( game.debug_log )
	{
		//-- write the total of the counters from all games previously run --//

		game.debug_log->printf( "TOTAL\n\r" );

		int i;
		for( i=0 ; i<maxStage ; i++ )
			game.debug_log->printf( "Stage %d: %d\n\r", i+1, total_stage_run_count_array[i] );		// stage run counters

		game.debug_log->printf( "\n\r" );

		for( i=0 ; i<maxEvent ; i++ )
			game.debug_log->printf( "Event %d: %d\n\r", i+1, total_event_run_count_array[i] );		// event run counters

		game.debug_log->printf( "\n\r---------------------------\n\r" );

		//------ delete the log class ------//

		delete game.debug_log;
		game.debug_log = NULL;
	}
#endif
}