From 10815a2803f4907fc80bab0a7ef52ed4e63d51e7 Mon Sep 17 00:00:00 2001 From: John Zaitseff Date: Thu, 25 Aug 2011 14:48:31 +1000 Subject: [PATCH] Move some global variables to intf.c and intf.h Move the keycode_company, printable_map_val, chtype_map_val, keycode_game_move, printable_game_move and chtype_game_move global variables to intf.c and intf.h. --- src/globals.c | 19 ++++++------------- src/globals.h | 19 ------------------- src/intf.c | 13 +++++++++++++ src/intf.h | 30 ++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 32 deletions(-) diff --git a/src/globals.c b/src/globals.c index f8fc0c9..bc251a5 100644 --- a/src/globals.c +++ b/src/globals.c @@ -41,8 +41,8 @@ const char *company_name[MAX_COMPANIES] = { /* TRANSLATORS: The eight company names do NOT have to be literal translations of the English names. In fact, if possible, the names should start with successive letters of your alphabet (in - English, "A" to "H"). No company name should be more than 24 - characters (column positions, to be precise) long. */ + English, for example, "A" to "H"). No company name should be more + than 24 characters (column positions, to be precise) long. */ N_("Altair Starways"), N_("Betelgeuse, Ltd"), N_("Capella Freight Co"), @@ -93,10 +93,10 @@ const char *default_printable_map_val = // Default printable output representations for each move const char *default_printable_game_move = /* TRANSLATORS: This string is used to display the game moves - (choices). There must be exactly 20 characters before the ASCII - vertical line. The first character corresponds to the first - character in the "input|GameMoves" string, and so on. Do not - change or translate anything after the vertical line. */ + (choices). There must be exactly 20 characters (NUMBER_MOVES) + before the ASCII vertical line. The first character corresponds + to the first character in the "input|GameMoves" string, and so on. + Do not change or translate anything after the vertical line. */ N_("abcdefghijklmnopqrst|output|GameMoves"); @@ -128,13 +128,6 @@ player_info_t player[MAX_PLAYERS]; // Array of players map_val_t galaxy_map[MAX_X][MAX_Y]; // Map of the galaxy move_rec_t game_move[NUMBER_MOVES]; // Current moves -wchar_t *keycode_company; // Keycodes for each company -wchar_t *keycode_game_move; // Keycodes for each game move -wchar_t *printable_map_val; // Printable output for each map value -wchar_t *printable_game_move; // Printable output for each game move -chtype *chtype_map_val[MAX_COMPANIES + 3]; // as chtype strings -chtype *chtype_game_move[NUMBER_MOVES]; // as chtype strings - int max_turn; // Max. number of turns in game int turn_number; // Current turn (1 to max_turn) int number_players; // Number of players diff --git a/src/globals.h b/src/globals.h index 53dc727..9d0c626 100644 --- a/src/globals.h +++ b/src/globals.h @@ -128,15 +128,6 @@ typedef enum map_val { #define MAP_TO_COMPANY(m) ((m) - MAP_A) #define IS_MAP_COMPANY(m) ((m) >= MAP_A && (m) <= MAP_LAST) -#define MAP_TO_INDEX(m) \ - (((m) == MAP_EMPTY) ? 0 : \ - (((m) == MAP_OUTPOST) ? 1 : \ - (((m) == MAP_STAR) ? 2 : \ - ((m) - MAP_A + 3)))) - -#define PRINTABLE_MAP_VAL(m) printable_map_val[MAP_TO_INDEX(m)] -#define CHTYPE_MAP_VAL(m) chtype_map_val[MAP_TO_INDEX(m)] - // Information about a move typedef struct move_rec { @@ -144,9 +135,6 @@ typedef struct move_rec { int y; } move_rec_t; -#define PRINTABLE_GAME_MOVE(m) (printable_game_move[m]) -#define CHTYPE_GAME_MOVE(m) (chtype_game_move[m]) - // Player moves / selection values typedef enum selection { @@ -195,13 +183,6 @@ extern player_info_t player[MAX_PLAYERS]; // Array of players extern map_val_t galaxy_map[MAX_X][MAX_Y]; // Map of the galaxy extern move_rec_t game_move[NUMBER_MOVES]; // Current moves -extern wchar_t *keycode_company; // Keycodes for each company -extern wchar_t *keycode_game_move; // Keycodes for each game move -extern wchar_t *printable_map_val; // Printable output for each map value -extern wchar_t *printable_game_move; // Printable output for each game move -extern chtype *chtype_map_val[MAX_COMPANIES + 3]; // as chtype strings -extern chtype *chtype_game_move[NUMBER_MOVES]; // as chtype strings - extern int max_turn; // Max. number of turns in game extern int turn_number; // Current turn (1 to max_turn) extern int number_players; // Number of players diff --git a/src/intf.c b/src/intf.c index 1ef3b0b..bbbc74d 100644 --- a/src/intf.c +++ b/src/intf.c @@ -179,6 +179,19 @@ chtype attr_error_highlight; // Error window highlighted string chtype attr_error_waitforkey; // "Press any key", error window +/************************************************************************ +* Game printing global variable definitions * +************************************************************************/ + +wchar_t *keycode_company; // Keycodes for each company +wchar_t *printable_map_val; // Printable output for each map value +chtype *chtype_map_val[MAX_COMPANIES + 3]; // as chtype strings + +wchar_t *keycode_game_move; // Keycodes for each game move +wchar_t *printable_game_move; // Printable output for each game move +chtype *chtype_game_move[NUMBER_MOVES]; // as chtype strings + + /************************************************************************ * Module-specific variables * ************************************************************************/ diff --git a/src/intf.h b/src/intf.h index f829a42..ede44af 100644 --- a/src/intf.h +++ b/src/intf.h @@ -169,6 +169,36 @@ extern chtype attr_error_highlight; // Error window highlighted string extern chtype attr_error_waitforkey; // "Press any key", error window +/************************************************************************ +* Game printing macros and global variable declarations * +************************************************************************/ + +// Macros and variables for printing the galaxy map + +#define MAP_TO_INDEX(m) \ + (((m) == MAP_EMPTY) ? 0 : \ + (((m) == MAP_OUTPOST) ? 1 : \ + (((m) == MAP_STAR) ? 2 : \ + ((m) - MAP_A + 3)))) + +#define PRINTABLE_MAP_VAL(m) printable_map_val[MAP_TO_INDEX(m)] +#define CHTYPE_MAP_VAL(m) chtype_map_val[MAP_TO_INDEX(m)] + +extern wchar_t *keycode_company; // Keycodes for each company +extern wchar_t *printable_map_val; // Printable output for each map value +extern chtype *chtype_map_val[MAX_COMPANIES + 3]; // as chtype strings + + +// Macros and variables for printing the current game moves + +#define PRINTABLE_GAME_MOVE(m) (printable_game_move[m]) +#define CHTYPE_GAME_MOVE(m) (chtype_game_move[m]) + +extern wchar_t *keycode_game_move; // Keycodes for each game move +extern wchar_t *printable_game_move; // Printable output for each game move +extern chtype *chtype_game_move[NUMBER_MOVES]; // as chtype strings + + /************************************************************************ * Basic text input/output function prototypes * ************************************************************************/