Exemple #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;

	/* 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

	/* 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;

	/* First game round */
	g->round = 1;

	/* No phase or turn */
	g->cur_action = -1;
	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 < MAX_DESIGN; i++)
	{
		/* Get design pointer */
		d_ptr = &library[i];

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

		/* Add cards */
		for (j = 0; j < n; j++)
		{
			/* 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;

			/* Card is not unpaid */
			c_ptr->unpaid = 0;

			/* Card's location is not known */
			c_ptr->known = 0;

			/* Clear used power list */
			for (k = 0; k < MAX_POWER; k++) c_ptr->used[k] = 0;

			/* Card has not produced */
			c_ptr->produced = 0;

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

			/* Card is not covered by a good */
			c_ptr->covered = -1;

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

	/* Add goals when expanded */
	if (g->expanded && !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;
		}

		/* Select four "first" goals at random */
		for (i = 0; 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;
		}

		/* Select two "most" goals at random */
		for (i = 0; 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];
		}
	}

	/* 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 start world */
		p_ptr->start = -1;

		/* 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 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 = p_ptr->total_fake = 0;
	       	p_ptr->fake_discards = 0;
	}
}
Exemple #2
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];
		}
	}
}