From c686d2f548e49564aa4d343264cc245a5905e136 Mon Sep 17 00:00:00 2001 From: John Zaitseff Date: Mon, 18 Jul 2011 20:16:24 +1000 Subject: [PATCH] Rename sel_val_t to selection_t; add values useful for exchange_stock() --- src/globals.h | 16 +++++++++++++--- src/move.c | 13 +++++++------ src/move.h | 4 ++-- src/trader.c | 2 +- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/globals.h b/src/globals.h index 0826a06..4d3ce7a 100644 --- a/src/globals.h +++ b/src/globals.h @@ -122,6 +122,10 @@ typedef enum map_val { #define IS_MAP_COMPANY(m) ((m) >= MAP_A && (m) <= MAP_LAST) #define PRINTABLE_MAP_VAL(m) ((char) (m)) +#define COMPANY_TO_KEY(i) ((i) + 'A') +#define KEY_TO_COMPANY(k) ((k) - 'A') +#define IS_COMPANY_KEY(k) ((k) >= 'A' && (k) < COMPANY_TO_KEY(MAX_COMPANIES)) + // Information about a move typedef struct move_rec { @@ -135,16 +139,22 @@ typedef struct move_rec { // Player moves / selection values -typedef enum sel_val { +typedef enum selection { + SEL_COMPANY_FIRST = 0, + SEL_COMPANY_LAST = MAX_COMPANIES - 1, + SEL_MOVE_FIRST = 0, SEL_MOVE_LAST = NUMBER_MOVES - 1, - SEL_MOVE_NUMBER_MOVES = NUMBER_MOVES, SEL_BANKRUPT, // Player wishes to give up SEL_SAVE, // Save and end the game SEL_QUIT, // Just end the game + + SEL_BANK, // Visit the Trading Bank + SEL_EXIT, // Exit the Stock Exchange + SEL_NONE = -1 // Nothing yet selected -} sel_val_t; +} selection_t; // Company names diff --git a/src/move.c b/src/move.c index fca269f..605604e 100644 --- a/src/move.c +++ b/src/move.c @@ -130,9 +130,9 @@ void select_moves (void) /*----------------------------------------------------------------------- - Function: get_move - Wait for the player to enter their move + Function: get_move - Wait for the player to enter their move Arguments: (none) - Returns: sel_val_t - Choice selected by player + Returns: selection_t - Choice selected by player This function displays the galaxy map and the current moves, then waits for the player to select one of the moves. On entry, current_player @@ -144,10 +144,10 @@ void select_moves (void) window) are left on the screen: they are closed in process_move(). */ -sel_val_t get_move (void) +selection_t get_move (void) { int i, x, y; - sel_val_t selection = SEL_NONE; + selection_t selection = SEL_NONE; if (quit_selected || abort_game) { @@ -257,6 +257,7 @@ sel_val_t get_move (void) default: beep(); + break; } } } @@ -399,7 +400,7 @@ sel_val_t get_move (void) move" and galaxy map windows are still open. */ -void process_move (sel_val_t selection) +void process_move (selection_t selection) { if (! quit_selected && ! abort_game) { switch(selection) { @@ -936,7 +937,7 @@ void adjust_values (void) int which; // Declare a company bankrupt! - if (randf() < COMPANY_BANKRUPTCY) { + if (randf() > (1.0 - COMPANY_BANKRUPTCY)) { which = randi(MAX_COMPANIES); if (company[which].on_map) { diff --git a/src/move.h b/src/move.h index 45136e2..3f23462 100644 --- a/src/move.h +++ b/src/move.h @@ -37,8 +37,8 @@ ************************************************************************/ extern void select_moves (void); -extern sel_val_t get_move (void); -extern void process_move (sel_val_t selection); +extern selection_t get_move (void); +extern void process_move (selection_t selection); extern void next_player (void); diff --git a/src/trader.c b/src/trader.c index cddcff4..8f5e5e2 100644 --- a/src/trader.c +++ b/src/trader.c @@ -70,7 +70,7 @@ int main (int argc, char *argv[]) // Play the actual game init_game(); while (! quit_selected && ! abort_game && turn_number <= max_turn) { - sel_val_t selection; + selection_t selection; select_moves(); selection = get_move();