1
0
mirror of https://git.zap.org.au/git/trader.git synced 2024-12-04 14:46:45 -05:00

Rework the handling of character renditions

Rather than querying use_color each and every time a rendition is used,
do it once in init_screen(), assigning the renditions to global
variables.
This commit is contained in:
John Zaitseff 2011-07-23 09:47:13 +10:00
parent 5f2298b07f
commit fc60a9fef1
7 changed files with 412 additions and 342 deletions

View File

@ -89,12 +89,12 @@ void exchange_stock (void)
selection = SEL_NONE;
// Display (or refresh) the Stock Exchange window
wbkgd(curwin, ATTR_NORMAL_WINDOW);
wbkgd(curwin, attr_normal_window);
werase(curwin);
box(curwin, 0, 0);
center(curwin, 1, ATTR_TITLE, " Interstellar Stock Exchange ");
center2(curwin, 2, ATTR_NORMAL, ATTR_HIGHLIGHT, "Player: ", "%s",
center(curwin, 1, attr_title, " Interstellar Stock Exchange ");
center2(curwin, 2, attr_normal, attr_highlight, "Player: ", "%s",
player[current_player].name);
all_off_map = true;
@ -106,7 +106,7 @@ void exchange_stock (void)
}
if (all_off_map) {
center(curwin, 8, ATTR_NORMAL, "No companies on the map");
center(curwin, 8, attr_normal, "No companies on the map");
} else {
char *buf = malloc(BUFSIZE);
if (buf == NULL) {
@ -116,17 +116,17 @@ void exchange_stock (void)
// Handle the locale's currency symbol
snprintf(buf, BUFSIZE, "share (%s)", lconvinfo.currency_symbol);
wattrset(curwin, ATTR_SUBTITLE);
wattrset(curwin, attr_subtitle);
mvwprintw(curwin, 4, 2, " %-22s %12s %10s %10s %10s ",
"", "Price per", "", "Shares", "Shares");
mvwprintw(curwin, 5, 2, " %-22s %12s %10s %10s %10s ",
"Company", buf, "Return (%)", "issued", "left");
wattrset(curwin, ATTR_NORMAL);
wattrset(curwin, attr_normal);
for (line = 6, i = 0; i < MAX_COMPANIES; i++) {
if (company[i].on_map) {
mvwaddch(curwin, line, 2, PRINTABLE_MAP_VAL(COMPANY_TO_MAP(i))
| ATTR_CHOICE);
| attr_choice);
l_strfmon(buf, BUFSIZE, "%!12n", company[i].share_price);
mvwprintw(curwin, line, 4, "%-22s %12s %10.2f %'10ld %'10ld ",
company[i].name, buf, company[i].share_return
@ -142,31 +142,31 @@ void exchange_stock (void)
wrefresh(curwin);
// Show menu of choices for the player
newtxwin(6, WIN_COLS, 18, WCENTER(WIN_COLS), true, ATTR_NORMAL_WINDOW);
newtxwin(6, WIN_COLS, 18, WCENTER(WIN_COLS), true, attr_normal_window);
wmove(curwin, 3, 2);
attrpr(curwin, ATTR_KEYCODE, "<1>");
attrpr(curwin, attr_keycode, "<1>");
waddstr(curwin, " Display stock portfolio");
wmove(curwin, 4, 2);
attrpr(curwin, ATTR_KEYCODE, "<2>");
attrpr(curwin, attr_keycode, "<2>");
waddstr(curwin, " Display galaxy map");
wmove(curwin, 3, 40);
attrpr(curwin, ATTR_KEYCODE, "<3>");
attrpr(curwin, attr_keycode, "<3>");
waddstr(curwin, " Visit the Trading Bank");
wmove(curwin, 4, 40);
attrpr(curwin, ATTR_KEYCODE, "<4>");
attrpr(curwin, attr_keycode, "<4>");
waddstr(curwin, " Exit the Stock Exchange");
mvwaddstr(curwin, 1, 18, "Enter selection ");
waddstr(curwin, "[");
attrpr(curwin, ATTR_HIGHLIGHT, "Company letter");
attrpr(curwin, attr_highlight, "Company letter");
waddstr(curwin, "/");
attrpr(curwin, ATTR_KEYCODE, "1");
attrpr(curwin, attr_keycode, "1");
waddstr(curwin, "-");
attrpr(curwin, ATTR_KEYCODE, "4");
attrpr(curwin, attr_keycode, "4");
waddstr(curwin, "]: ");
curs_set(CURS_ON);
@ -269,40 +269,40 @@ void visit_bank (void)
// Show the informational part of the Bank
newtxwin(10, WIN_COLS - 4, 5, WCENTER(WIN_COLS - 4), true,
ATTR_NORMAL_WINDOW);
attr_normal_window);
center(curwin, 1, ATTR_TITLE, " Interstellar Trading Bank ");
center(curwin, 1, attr_title, " Interstellar Trading Bank ");
l_strfmon(buf, BUFSIZE, "%18n", player[current_player].cash);
center2(curwin, 3, ATTR_NORMAL, ATTR_HIGHLIGHT, "Current cash: ",
center2(curwin, 3, attr_normal, attr_highlight, "Current cash: ",
" %s ", buf);
l_strfmon(buf, BUFSIZE, "%18n", player[current_player].debt);
center2(curwin, 4, ATTR_NORMAL, ATTR_HIGHLIGHT, "Current debt: ",
center2(curwin, 4, attr_normal, attr_highlight, "Current debt: ",
" %s ", buf);
center2(curwin, 5, ATTR_NORMAL, ATTR_HIGHLIGHT, "Interest rate: ",
center2(curwin, 5, attr_normal, attr_highlight, "Interest rate: ",
" %17.2f%% ", interest_rate * 100.0);
l_strfmon(buf, BUFSIZE, "%18n", credit_limit);
center2(curwin, 7, ATTR_HIGHLIGHT, ATTR_TITLE, "Credit limit: ",
center2(curwin, 7, attr_highlight, attr_title, "Credit limit: ",
" %s ", buf);
wrefresh(curwin);
// Show menu of choices for the player
newtxwin(7, WIN_COLS - 4, 15, WCENTER(WIN_COLS - 4), true,
ATTR_NORMAL_WINDOW);
attr_normal_window);
center2(curwin, 3, ATTR_KEYCODE, ATTR_NORMAL, "<1>", " Borrow money ");
center2(curwin, 4, ATTR_KEYCODE, ATTR_NORMAL, "<2>", " Repay debt ");
center2(curwin, 5, ATTR_KEYCODE, ATTR_NORMAL, "<3>", " Exit from the Bank");
center2(curwin, 3, attr_keycode, attr_normal, "<1>", " Borrow money ");
center2(curwin, 4, attr_keycode, attr_normal, "<2>", " Repay debt ");
center2(curwin, 5, attr_keycode, attr_normal, "<3>", " Exit from the Bank");
mvwaddstr(curwin, 1, 24, "Enter selection ");
waddstr(curwin, "[");
attrpr(curwin, ATTR_KEYCODE, "1");
attrpr(curwin, attr_keycode, "1");
waddstr(curwin, "-");
attrpr(curwin, ATTR_KEYCODE, "3");
attrpr(curwin, attr_keycode, "3");
waddstr(curwin, "]: ");
curs_set(CURS_ON);
@ -340,13 +340,13 @@ void visit_bank (void)
case '1':
// Borrow money from the Bank
if (credit_limit == 0.0) {
newtxwin(7, 50, 8, WCENTER(50), true, ATTR_ERROR_WINDOW);
newtxwin(7, 50, 8, WCENTER(50), true, attr_error_window);
center(curwin, 1, ATTR_ERROR_TITLE, " Insufficient Credit Limit ");
center(curwin, 3, ATTR_ERROR_HIGHLIGHT,
center(curwin, 1, attr_error_title, " Insufficient Credit Limit ");
center(curwin, 3, attr_error_highlight,
"The Bank will not lend you any more money");
wait_for_key(curwin, 5, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, 5, attr_error_waitforkey);
deltxwin();
} else {
@ -354,7 +354,7 @@ void visit_bank (void)
int ret;
wbkgd(curwin, ATTR_NORMAL_WINDOW);
wbkgd(curwin, attr_normal_window);
werase(curwin);
box(curwin, 0, 0);
@ -380,7 +380,7 @@ void visit_bank (void)
ret = gettxdouble(curwin, &val, 0.0, credit_limit + ROUNDING_AMOUNT,
0.0, credit_limit, 3, x, getmaxx(curwin) - x - n,
ATTR_INPUT_FIELD);
attr_input_field);
if (ret == OK && val > ROUNDING_AMOUNT) {
player[current_player].cash += val;
@ -392,23 +392,23 @@ void visit_bank (void)
case '2':
// Repay a debt
if (player[current_player].debt == 0.0) {
newtxwin(7, 50, 8, WCENTER(50), true, ATTR_ERROR_WINDOW);
newtxwin(7, 50, 8, WCENTER(50), true, attr_error_window);
center(curwin, 1, ATTR_ERROR_TITLE, " No Debt ");
center(curwin, 3, ATTR_ERROR_HIGHLIGHT,
center(curwin, 1, attr_error_title, " No Debt ");
center(curwin, 3, attr_error_highlight,
"You have no debt to repay");
wait_for_key(curwin, 5, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, 5, attr_error_waitforkey);
deltxwin();
} else if (player[current_player].cash == 0.0) {
newtxwin(7, 60, 8, WCENTER(60), true, ATTR_ERROR_WINDOW);
newtxwin(7, 60, 8, WCENTER(60), true, attr_error_window);
center(curwin, 1, ATTR_ERROR_TITLE, " No Cash ");
center(curwin, 3, ATTR_ERROR_HIGHLIGHT,
center(curwin, 1, attr_error_title, " No Cash ");
center(curwin, 3, attr_error_highlight,
"You have no cash with which to repay the debt!");
wait_for_key(curwin, 5, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, 5, attr_error_waitforkey);
deltxwin();
} else {
@ -416,7 +416,7 @@ void visit_bank (void)
int ret;
wbkgd(curwin, ATTR_NORMAL_WINDOW);
wbkgd(curwin, attr_normal_window);
werase(curwin);
box(curwin, 0, 0);
@ -444,7 +444,7 @@ void visit_bank (void)
ret = gettxdouble(curwin, &val, 0.0, max + ROUNDING_AMOUNT, 0.0,
max, 3, x, getmaxx(curwin) - x - n,
ATTR_INPUT_FIELD);
attr_input_field);
if (ret == OK) {
player[current_player].cash -= val;
@ -498,65 +498,65 @@ void trade_shares (int num, bool *bid_used)
// Show the informational part of the trade window
newtxwin(9, WIN_COLS - 4, 5, WCENTER(WIN_COLS - 4), true,
ATTR_NORMAL_WINDOW);
attr_normal_window);
center(curwin, 1, ATTR_TITLE, " Stock Transaction in %s ",
center(curwin, 1, attr_title, " Stock Transaction in %s ",
company[num].name);
mvwaddstr(curwin, 3, 2, "Shares issued: ");
attrpr(curwin, ATTR_HIGHLIGHT, "%'12ld", company[num].stock_issued);
attrpr(curwin, attr_highlight, "%'12ld", company[num].stock_issued);
mvwaddstr(curwin, 4, 2, "Shares left: ");
attrpr(curwin, ATTR_HIGHLIGHT, "%'12ld",
attrpr(curwin, attr_highlight, "%'12ld",
company[num].max_stock - company[num].stock_issued);
mvwaddstr(curwin, 5, 2, "Price per share: ");
l_strfmon(buf, BUFSIZE, "%12n", company[num].share_price);
attrpr(curwin, ATTR_HIGHLIGHT, "%12s", buf);
attrpr(curwin, attr_highlight, "%12s", buf);
mvwaddstr(curwin, 6, 2, "Return: ");
attrpr(curwin, ATTR_HIGHLIGHT, "%11.2f%%",
attrpr(curwin, attr_highlight, "%11.2f%%",
company[num].share_return * 100.0);
mvwaddstr(curwin, 3, 38, "Current holdings: ");
attrpr(curwin, ATTR_HIGHLIGHT, " %'16ld ",
attrpr(curwin, attr_highlight, " %'16ld ",
player[current_player].stock_owned[num]);
mvwaddstr(curwin, 4, 38, "Percentage owned: ");
attrpr(curwin, ATTR_HIGHLIGHT, " %'15.2f%% ", ownership * 100.0);
attrpr(curwin, attr_highlight, " %'15.2f%% ", ownership * 100.0);
wmove(curwin, 6, 38);
attrpr(curwin, ATTR_HIGHLIGHT, "Current cash: ");
attrpr(curwin, attr_highlight, "Current cash: ");
l_strfmon(buf, BUFSIZE, "%16n", player[current_player].cash);
attrpr(curwin, ATTR_TITLE, " %16s ", buf);
attrpr(curwin, attr_title, " %16s ", buf);
wrefresh(curwin);
// Show menu of choices for the player
newtxwin(7, WIN_COLS - 4, 14, WCENTER(WIN_COLS - 4), true,
ATTR_NORMAL_WINDOW);
attr_normal_window);
wmove(curwin, 3, 2);
attrpr(curwin, ATTR_KEYCODE, "<1>");
attrpr(curwin, attr_keycode, "<1>");
waddstr(curwin, " Buy stock from company");
wmove(curwin, 4, 2);
attrpr(curwin, ATTR_KEYCODE, "<2>");
attrpr(curwin, attr_keycode, "<2>");
waddstr(curwin, " Sell stock back to company");
wmove(curwin, 3, 38);
attrpr(curwin, ATTR_KEYCODE, "<3>");
attrpr(curwin, attr_keycode, "<3>");
waddstr(curwin, " Bid company to issue more shares");
wmove(curwin, 4, 38);
attrpr(curwin, ATTR_KEYCODE, "<4>");
attrpr(curwin, attr_keycode, "<4>");
waddstr(curwin, " Exit to the Stock Exchange");
mvwaddstr(curwin, 1, 24, "Enter selection ");
waddstr(curwin, "[");
attrpr(curwin, ATTR_KEYCODE, "1");
attrpr(curwin, attr_keycode, "1");
waddstr(curwin, "-");
attrpr(curwin, ATTR_KEYCODE, "4");
attrpr(curwin, attr_keycode, "4");
waddstr(curwin, "]: ");
curs_set(CURS_ON);
@ -597,41 +597,41 @@ void trade_shares (int num, bool *bid_used)
maxshares = player[current_player].cash / company[num].share_price;
if (company[num].max_stock - company[num].stock_issued == 0) {
newtxwin(7, 50, 8, WCENTER(50), true, ATTR_ERROR_WINDOW);
newtxwin(7, 50, 8, WCENTER(50), true, attr_error_window);
center(curwin, 1, ATTR_ERROR_TITLE, " No Shares Available ");
center(curwin, 3, ATTR_ERROR_HIGHLIGHT,
center(curwin, 1, attr_error_title, " No Shares Available ");
center(curwin, 3, attr_error_highlight,
"No more shares are available for purchase");
wait_for_key(curwin, 5, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, 5, attr_error_waitforkey);
deltxwin();
} else if (maxshares <= 0) {
newtxwin(7, 50, 8, WCENTER(50), true, ATTR_ERROR_WINDOW);
newtxwin(7, 50, 8, WCENTER(50), true, attr_error_window);
center(curwin, 1, ATTR_ERROR_TITLE, " Insufficient Cash ");
center(curwin, 3, ATTR_ERROR_HIGHLIGHT,
center(curwin, 1, attr_error_title, " Insufficient Cash ");
center(curwin, 3, attr_error_highlight,
"Not enough cash to purchase shares");
wait_for_key(curwin, 5, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, 5, attr_error_waitforkey);
deltxwin();
} else {
maxshares = MIN(maxshares, company[num].max_stock -
company[num].stock_issued);
wbkgd(curwin, ATTR_NORMAL_WINDOW);
wbkgd(curwin, attr_normal_window);
werase(curwin);
box(curwin, 0, 0);
center3(curwin, 2, ATTR_NORMAL, ATTR_NORMAL, ATTR_HIGHLIGHT,
center3(curwin, 2, attr_normal, attr_normal, attr_highlight,
"You can purchase up to ", " shares.", "%'ld", maxshares);
mvwprintw(curwin, 4, 10, "How many shares do you wish to purchase? ");
x = getcurx(curwin);
ret = gettxlong(curwin, &val, 0, maxshares, 0, maxshares, 4, x,
getmaxx(curwin) - x - 10, ATTR_INPUT_FIELD);
getmaxx(curwin) - x - 10, attr_input_field);
if (ret == OK) {
player[current_player].cash -= val * company[num].share_price;
@ -645,28 +645,28 @@ void trade_shares (int num, bool *bid_used)
// Sell stock back to company
maxshares = player[current_player].stock_owned[num];
if (maxshares == 0) {
newtxwin(7, 50, 8, WCENTER(50), true, ATTR_ERROR_WINDOW);
newtxwin(7, 50, 8, WCENTER(50), true, attr_error_window);
center(curwin, 1, ATTR_ERROR_TITLE, " No Shares ");
center(curwin, 3, ATTR_ERROR_HIGHLIGHT,
center(curwin, 1, attr_error_title, " No Shares ");
center(curwin, 3, attr_error_highlight,
"You do not have any shares to sell");
wait_for_key(curwin, 5, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, 5, attr_error_waitforkey);
deltxwin();
} else {
wbkgd(curwin, ATTR_NORMAL_WINDOW);
wbkgd(curwin, attr_normal_window);
werase(curwin);
box(curwin, 0, 0);
center3(curwin, 2, ATTR_NORMAL, ATTR_NORMAL, ATTR_HIGHLIGHT,
center3(curwin, 2, attr_normal, attr_normal, attr_highlight,
"You can sell up to ", " shares.", "%'ld", maxshares);
mvwprintw(curwin, 4, 10, "How many shares do you wish to sell? ");
x = getcurx(curwin);
ret = gettxlong(curwin, &val, 0, maxshares, 0, maxshares, 4, x,
getmaxx(curwin) - x - 10, ATTR_INPUT_FIELD);
getmaxx(curwin) - x - 10, attr_input_field);
if (ret == OK) {
company[num].stock_issued -= val;
@ -687,24 +687,24 @@ void trade_shares (int num, bool *bid_used)
*bid_used = true;
if (maxshares == 0) {
newtxwin(8, 50, 8, WCENTER(50), true, ATTR_ERROR_WINDOW);
newtxwin(8, 50, 8, WCENTER(50), true, attr_error_window);
center(curwin, 1, ATTR_ERROR_TITLE, " No Shares Issued ");
center(curwin, 3, ATTR_ERROR_HIGHLIGHT, "%s", company[num].name);
center(curwin, 4, ATTR_ERROR_HIGHLIGHT,
center(curwin, 1, attr_error_title, " No Shares Issued ");
center(curwin, 3, attr_error_highlight, "%s", company[num].name);
center(curwin, 4, attr_error_highlight,
"has refused to issue more shares");
wait_for_key(curwin, 6, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, 6, attr_error_waitforkey);
deltxwin();
} else {
newtxwin(8, 50, 8, WCENTER(50), true, ATTR_NORMAL_WINDOW);
newtxwin(8, 50, 8, WCENTER(50), true, attr_normal_window);
center(curwin, 1, ATTR_TITLE, " Shares Issued ");
center(curwin, 3, ATTR_HIGHLIGHT, "%s", company[num].name);
center(curwin, 4, ATTR_HIGHLIGHT, "has issued %'ld more shares",
center(curwin, 1, attr_title, " Shares Issued ");
center(curwin, 3, attr_highlight, "%s", company[num].name);
center(curwin, 4, attr_highlight, "has issued %'ld more shares",
maxshares);
wait_for_key(curwin, 6, ATTR_WAITFORKEY);
wait_for_key(curwin, 6, attr_waitforkey);
deltxwin();
}
break;

View File

@ -167,27 +167,27 @@ bool load_game (int num)
if (errno == ENOENT) {
// File not found
newtxwin(7, 40, 9, WCENTER(40), true, ATTR_ERROR_WINDOW);
newtxwin(7, 40, 9, WCENTER(40), true, attr_error_window);
center(curwin, 1, ATTR_ERROR_TITLE, " Game Not Found ");
center(curwin, 3, ATTR_ERROR_HIGHLIGHT,
center(curwin, 1, attr_error_title, " Game Not Found ");
center(curwin, 3, attr_error_highlight,
"Game %d has not been saved to disk", num);
wait_for_key(curwin, 5, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, 5, attr_error_waitforkey);
deltxwin();
} else {
// Some other file error
saved_errno = errno;
newtxwin(9, 70, 9, WCENTER(70), true, ATTR_ERROR_WINDOW);
newtxwin(9, 70, 9, WCENTER(70), true, attr_error_window);
center(curwin, 1, ATTR_ERROR_TITLE, " Game Not Loaded ");
center(curwin, 3, ATTR_ERROR_HIGHLIGHT,
center(curwin, 1, attr_error_title, " Game Not Loaded ");
center(curwin, 3, attr_error_highlight,
"Game %d could not be loaded from disk", num);
center(curwin, 5, ATTR_ERROR_NORMAL, "File %s: %s", filename,
center(curwin, 5, attr_error_normal, "File %s: %s", filename,
strerror(saved_errno));
wait_for_key(curwin, 7, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, 7, attr_error_waitforkey);
deltxwin();
}
@ -334,15 +334,15 @@ bool save_game (int num)
} else {
// Data directory could not be created
newtxwin(9, 70, 7, WCENTER(70), true, ATTR_ERROR_WINDOW);
newtxwin(9, 70, 7, WCENTER(70), true, attr_error_window);
center(curwin, 1, ATTR_ERROR_TITLE, " Game Not Saved ");
center(curwin, 3, ATTR_ERROR_HIGHLIGHT,
center(curwin, 1, attr_error_title, " Game Not Saved ");
center(curwin, 3, attr_error_highlight,
"Game %d could not be saved to disk", num);
center(curwin, 5, ATTR_ERROR_NORMAL, "Directory %s: %s",
center(curwin, 5, attr_error_normal, "Directory %s: %s",
data_dir, strerror(saved_errno));
wait_for_key(curwin, 7, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, 7, attr_error_waitforkey);
deltxwin();
free(buf);
@ -359,15 +359,15 @@ bool save_game (int num)
// File could not be opened for writing
saved_errno = errno;
newtxwin(9, 70, 7, WCENTER(70), true, ATTR_ERROR_WINDOW);
newtxwin(9, 70, 7, WCENTER(70), true, attr_error_window);
center(curwin, 1, ATTR_ERROR_TITLE, " Game Not Saved ");
center(curwin, 3, ATTR_ERROR_HIGHLIGHT,
center(curwin, 1, attr_error_title, " Game Not Saved ");
center(curwin, 3, attr_error_highlight,
"Game %d could not be saved to disk", num);
center(curwin, 5, ATTR_ERROR_NORMAL, "File %s: %s", filename,
center(curwin, 5, attr_error_normal, "File %s: %s", filename,
strerror(saved_errno));
wait_for_key(curwin, 7, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, 7, attr_error_waitforkey);
deltxwin();
free(buf);

View File

@ -110,8 +110,8 @@ void init_game (void)
{
// Try to load an old game, if possible
if (game_num != 0) {
newtxwin(5, 30, 6, WCENTER(30), true, ATTR_STATUS_WINDOW);
center(curwin, 2, ATTR_STATUS_WINDOW, "Loading game %d... ", game_num);
newtxwin(5, 30, 6, WCENTER(30), true, attr_status_window);
center(curwin, 2, attr_status_window, "Loading game %d... ", game_num);
wrefresh(curwin);
game_loaded = load_game(game_num);
@ -137,8 +137,8 @@ void init_game (void)
game_num = choice;
// Try to load the game, if possible
newtxwin(5, 30, 9, WCENTER(30), true, ATTR_STATUS_WINDOW);
center(curwin, 2, ATTR_STATUS_WINDOW,
newtxwin(5, 30, 9, WCENTER(30), true, attr_status_window);
center(curwin, 2, attr_status_window,
"Loading game %d... ", game_num);
wrefresh(curwin);
@ -207,13 +207,13 @@ void init_game (void)
first_player = randi(number_players);
current_player = first_player;
newtxwin(7, 50, 8, WCENTER(50), true, ATTR_NORMAL_WINDOW);
newtxwin(7, 50, 8, WCENTER(50), true, attr_normal_window);
center(curwin, 2, ATTR_NORMAL, "The first player to go is");
center(curwin, 3, ATTR_HIGHLIGHT, "%s",
center(curwin, 2, attr_normal, "The first player to go is");
center(curwin, 3, attr_highlight, "%s",
player[first_player].name);
wait_for_key(curwin, 5, ATTR_WAITFORKEY);
wait_for_key(curwin, 5, attr_waitforkey);
deltxwin();
txrefresh();
}
@ -235,16 +235,16 @@ static int ask_number_players (void)
// Ask for the number of players
newtxwin(5, 62, 3, WCENTER(62), true, ATTR_NORMAL_WINDOW);
newtxwin(5, 62, 3, WCENTER(62), true, attr_normal_window);
mvwaddstr(curwin, 2, 2, "Enter number of players ");
waddstr(curwin, "[");
attrpr(curwin, ATTR_KEYCODE, "1");
attrpr(curwin, attr_keycode, "1");
waddstr(curwin, "-");
attrpr(curwin, ATTR_KEYCODE, "%d", MAX_PLAYERS);
attrpr(curwin, attr_keycode, "%d", MAX_PLAYERS);
waddstr(curwin, "]");
waddstr(curwin, " or ");
attrpr(curwin, ATTR_KEYCODE, "<C>");
attrpr(curwin, attr_keycode, "<C>");
waddstr(curwin, " to continue a game: ");
curs_set(CURS_ON);
@ -297,16 +297,16 @@ int ask_game_number (void)
// Ask which game to load
newtxwin(5, 54, 6, WCENTER(54), true, ATTR_NORMAL_WINDOW);
newtxwin(5, 54, 6, WCENTER(54), true, attr_normal_window);
mvwaddstr(curwin, 2, 2, "Enter game number ");
waddstr(curwin, "[");
attrpr(curwin, ATTR_KEYCODE, "1");
attrpr(curwin, attr_keycode, "1");
waddstr(curwin, "-");
attrpr(curwin, ATTR_KEYCODE, "9");
attrpr(curwin, attr_keycode, "9");
waddstr(curwin, "]");
waddstr(curwin, " or ");
attrpr(curwin, ATTR_KEYCODE, "<CTRL><C>");
attrpr(curwin, attr_keycode, "<CTRL><C>");
waddstr(curwin, " to cancel: ");
curs_set(CURS_ON);
@ -352,7 +352,7 @@ void ask_player_names (void)
// Ask for the player's name
newtxwin(5, WIN_COLS - 4, 9, WCENTER(WIN_COLS - 4), true,
ATTR_NORMAL_WINDOW);
attr_normal_window);
mvwaddstr(curwin, 2, 2, "Please enter your name: ");
@ -362,7 +362,7 @@ void ask_player_names (void)
player[0].name = NULL;
while (true) {
int ret = gettxstr(curwin, &player[0].name, NULL, false,
2, x, w, ATTR_INPUT_FIELD);
2, x, w, attr_input_field);
if (ret == OK && strlen(player[0].name) != 0) {
break;
} else {
@ -370,9 +370,9 @@ void ask_player_names (void)
}
}
newtxwin(5, 44, 6, WCENTER(44), true, ATTR_NORMAL_WINDOW);
newtxwin(5, 44, 6, WCENTER(44), true, attr_normal_window);
mvwaddstr(curwin, 2, 2, "Do you need any instructions?");
if (answer_yesno(curwin, ATTR_KEYCODE)) {
if (answer_yesno(curwin, attr_keycode)) {
show_help();
}
@ -384,9 +384,9 @@ void ask_player_names (void)
int cur, len, i;
newtxwin(number_players + 5, WIN_COLS - 4, 9, WCENTER(WIN_COLS - 4),
true, ATTR_NORMAL_WINDOW);
true, attr_normal_window);
center(curwin, 1, ATTR_TITLE, " Enter Player Names ");
center(curwin, 1, attr_title, " Enter Player Names ");
for (i = 0; i < number_players; i++) {
player[i].name = NULL;
@ -401,7 +401,7 @@ void ask_player_names (void)
done = false;
while (! done) {
int ret = gettxstr(curwin, &player[cur].name, &modified, true,
3 + cur, x, w, ATTR_INPUT_FIELD);
3 + cur, x, w, attr_input_field);
switch (ret) {
case OK:
@ -467,9 +467,9 @@ void ask_player_names (void)
}
}
newtxwin(5, 50, 6, WCENTER(50), true, ATTR_NORMAL_WINDOW);
newtxwin(5, 50, 6, WCENTER(50), true, attr_normal_window);
mvwaddstr(curwin, 2, 2, "Does any player need instructions?");
if (answer_yesno(curwin, ATTR_KEYCODE)) {
if (answer_yesno(curwin, attr_keycode)) {
show_help();
}
}
@ -498,13 +498,13 @@ void end_game (void)
err_exit_nomem();
}
newtxwin(7, 40, 9, WCENTER(40), true, ATTR_ERROR_WINDOW);
newtxwin(7, 40, 9, WCENTER(40), true, attr_error_window);
center(curwin, 1, ATTR_ERROR_TITLE, " Game Over ");
center(curwin, 3, ATTR_ERROR_HIGHLIGHT, "The game is over after %d turns",
center(curwin, 1, attr_error_title, " Game Over ");
center(curwin, 3, attr_error_highlight, "The game is over after %d turns",
turn_number - 1);
wait_for_key(curwin, 5, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, 5, attr_error_waitforkey);
deltxwin();
for (i = 0; i < number_players; i++) {
@ -514,13 +514,13 @@ void end_game (void)
if (number_players == 1) {
l_strfmon(buf, BUFSIZE, "%1n", total_value(0));
newtxwin(9, 60, 8, WCENTER(60), true, ATTR_NORMAL_WINDOW);
newtxwin(9, 60, 8, WCENTER(60), true, attr_normal_window);
center(curwin, 1, ATTR_TITLE, " Total Value ");
center2(curwin, 4, ATTR_NORMAL, ATTR_HIGHLIGHT,
center(curwin, 1, attr_title, " Total Value ");
center2(curwin, 4, attr_normal, attr_highlight,
"Your total value was ", "%s", buf);
wait_for_key(curwin, 7, ATTR_WAITFORKEY);
wait_for_key(curwin, 7, attr_waitforkey);
deltxwin();
} else {
// Sort players on the basis of total value
@ -530,25 +530,25 @@ void end_game (void)
qsort(player, number_players, sizeof(player_info_t), cmp_player);
newtxwin(number_players + 10, WIN_COLS - 4, 3, WCENTER(WIN_COLS - 4),
true, ATTR_NORMAL_WINDOW);
true, attr_normal_window);
center(curwin, 1, ATTR_TITLE, " Game Winner ");
center2(curwin, 3, ATTR_NORMAL, ATTR_HIGHLIGHT, "The winner is ",
center(curwin, 1, attr_title, " Game Winner ");
center2(curwin, 3, attr_normal, attr_highlight, "The winner is ",
"%s", player[0].name);
if (player[0].sort_value == 0.0) {
center2(curwin, 4, ATTR_NORMAL, ATTR_BLINK, "who is ",
center2(curwin, 4, attr_normal, attr_blink, "who is ",
"*** BANKRUPT ***");
} else {
l_strfmon(buf, BUFSIZE, "%1n", player[0].sort_value);
center2(curwin, 4, ATTR_NORMAL, ATTR_HIGHLIGHT,
center2(curwin, 4, attr_normal, attr_highlight,
"with a value of ", "%s", buf);
}
int w = getmaxx(curwin) - 33;
wattrset(curwin, ATTR_SUBTITLE);
wattrset(curwin, attr_subtitle);
snprintf(buf, BUFSIZE, "Total Value (%s)", lconvinfo.currency_symbol);
mvwprintw(curwin, 6, 2, "%5s %-*.*s %18s ", "", w, w, "Player", buf);
wattrset(curwin, ATTR_NORMAL);
wattrset(curwin, attr_normal);
for (i = 0; i < number_players; i++) {
l_strfmon(buf, BUFSIZE, "%!18n", player[i].sort_value);
@ -556,7 +556,7 @@ void end_game (void)
ordinal[i + 1], w, w, player[i].name, buf);
}
wait_for_key(curwin, getmaxy(curwin) - 2, ATTR_WAITFORKEY);
wait_for_key(curwin, getmaxy(curwin) - 2, attr_waitforkey);
deltxwin();
}
@ -572,7 +572,7 @@ void show_map (bool closewin)
int n, x, y;
newtxwin(MAX_Y + 4, WIN_COLS, 1, WCENTER(WIN_COLS), true, ATTR_MAP_WINDOW);
newtxwin(MAX_Y + 4, WIN_COLS, 1, WCENTER(WIN_COLS), true, attr_map_window);
// Draw various borders
mvwaddch(curwin, 2, 0, ACS_LTEE);
@ -580,13 +580,13 @@ void show_map (bool closewin)
mvwaddch(curwin, 2, getmaxx(curwin) - 1, ACS_RTEE);
// Display current player and turn number
wattrset(curwin, ATTR_MAPWIN_TITLE);
wattrset(curwin, attr_mapwin_title);
mvwaddstr(curwin, 1, 2, " ");
waddstr(curwin, "Player: ");
n = getmaxx(curwin) - getcurx(curwin) - 4;
wattrset(curwin, ATTR_MAPWIN_HIGHLIGHT);
wattrset(curwin, attr_mapwin_highlight);
wprintw(curwin, "%-*.*s", n, n, player[current_player].name);
wattrset(curwin, ATTR_MAPWIN_TITLE);
wattrset(curwin, attr_mapwin_title);
waddstr(curwin, " ");
if (turn_number != max_turn) {
@ -602,7 +602,7 @@ void show_map (bool closewin)
mvwaddstr(curwin, 1, getmaxx(curwin) - (len1 + len2) - 6, " ");
waddstr(curwin, initial);
attrpr(curwin, ATTR_MAPWIN_HIGHLIGHT, "%s", buf);
attrpr(curwin, attr_mapwin_highlight, "%s", buf);
waddstr(curwin, " ");
free(buf);
@ -612,11 +612,11 @@ void show_map (bool closewin)
int len = strlen(buf);
mvwaddstr(curwin, 1, getmaxx(curwin) - len - 6, " ");
attrpr(curwin, ATTR_MAPWIN_BLINK, "%s", buf);
attrpr(curwin, attr_mapwin_blink, "%s", buf);
waddstr(curwin, " ");
}
wattrset(curwin, ATTR_MAP_WINDOW);
wattrset(curwin, attr_map_window);
// Display the actual map
for (y = 0; y < MAX_Y; y++) {
@ -626,22 +626,22 @@ void show_map (bool closewin)
switch (m) {
case MAP_EMPTY:
waddch(curwin, PRINTABLE_MAP_VAL(m) | ATTR_MAP_EMPTY);
waddch(curwin, PRINTABLE_MAP_VAL(m) | attr_map_empty);
break;
case MAP_OUTPOST:
waddch(curwin, PRINTABLE_MAP_VAL(m) | ATTR_MAP_OUTPOST);
waddch(curwin, PRINTABLE_MAP_VAL(m) | attr_map_outpost);
break;
case MAP_STAR:
waddch(curwin, PRINTABLE_MAP_VAL(m) | ATTR_MAP_STAR);
waddch(curwin, PRINTABLE_MAP_VAL(m) | attr_map_star);
break;
default:
waddch(curwin, PRINTABLE_MAP_VAL(m) | ATTR_MAP_COMPANY);
waddch(curwin, PRINTABLE_MAP_VAL(m) | attr_map_company);
break;
}
waddch(curwin, ' ' | ATTR_MAP_EMPTY);
waddch(curwin, ' ' | attr_map_empty);
}
}
@ -651,9 +651,9 @@ void show_map (bool closewin)
wrefresh(curwin);
newtxwin(WIN_LINES - MAX_Y - 5, WIN_COLS, MAX_Y + 5, WCENTER(WIN_COLS),
true, ATTR_NORMAL_WINDOW);
true, attr_normal_window);
wait_for_key(curwin, 2, ATTR_WAITFORKEY);
wait_for_key(curwin, 2, attr_waitforkey);
deltxwin(); // Wait for key window
deltxwin(); // Galaxy map window
@ -674,15 +674,15 @@ void show_status (int num)
assert(num >= 0 && num < number_players);
newtxwin(MAX_COMPANIES + 15, WIN_COLS, 1, WCENTER(WIN_COLS), true,
ATTR_NORMAL_WINDOW);
attr_normal_window);
center(curwin, 1, ATTR_TITLE, " Stock Portfolio ");
center2(curwin, 2, ATTR_NORMAL, ATTR_HIGHLIGHT, "Player: ", "%s",
center(curwin, 1, attr_title, " Stock Portfolio ");
center2(curwin, 2, attr_normal, attr_highlight, "Player: ", "%s",
player[num].name);
val = total_value(num);
if (val == 0.0) {
center(curwin, 11, ATTR_BLINK, "* * * B A N K R U P T * * *");
center(curwin, 11, attr_blink, "* * * B A N K R U P T * * *");
} else {
char *buf = malloc(BUFSIZE);
@ -700,17 +700,17 @@ void show_status (int num)
}
if (none) {
center(curwin, 8, ATTR_NORMAL, "No companies on the map");
center(curwin, 8, attr_normal, "No companies on the map");
} else {
// Handle the locale's currency symbol
snprintf(buf, BUFSIZE, "share (%s)", lconvinfo.currency_symbol);
wattrset(curwin, ATTR_SUBTITLE);
wattrset(curwin, attr_subtitle);
mvwprintw(curwin, 4, 2, " %-22s %12s %10s %10s %10s ",
"", "Price per", "", "Holdings", "Company");
mvwprintw(curwin, 5, 2, " %-22s %12s %10s %10s %10s ",
"Company", buf, "Return (%)", "(shares)", "owner (%)");
wattrset(curwin, ATTR_NORMAL);
wattrset(curwin, attr_normal);
for (line = 6, i = 0; i < MAX_COMPANIES; i++) {
if (company[i].on_map) {
@ -730,24 +730,24 @@ void show_status (int num)
line = 15;
l_strfmon(buf, BUFSIZE, "%18n", player[num].cash);
center2(curwin, line++, ATTR_NORMAL, ATTR_HIGHLIGHT, "Current cash: ",
center2(curwin, line++, attr_normal, attr_highlight, "Current cash: ",
" %s ", buf);
if (player[num].debt != 0.0) {
l_strfmon(buf, BUFSIZE, "%18n", player[num].debt);
center2(curwin, line++, ATTR_NORMAL, ATTR_HIGHLIGHT,
center2(curwin, line++, attr_normal, attr_highlight,
"Current debt: ", " %s ", buf);
center2(curwin, line++, ATTR_NORMAL, ATTR_HIGHLIGHT,
center2(curwin, line++, attr_normal, attr_highlight,
"Interest rate: ", " %17.2f%% ", interest_rate * 100.0);
}
l_strfmon(buf, BUFSIZE, "%18n", val);
center2(curwin, line + 1, ATTR_HIGHLIGHT, ATTR_TITLE,
center2(curwin, line + 1, attr_highlight, attr_title,
"Total value: ", " %s ", buf);
free(buf);
}
wait_for_key(curwin, getmaxy(curwin) - 2, ATTR_WAITFORKEY);
wait_for_key(curwin, getmaxy(curwin) - 2, attr_waitforkey);
deltxwin();
txrefresh();
}

View File

@ -175,16 +175,16 @@ void show_help (void)
// Display a page of instructions
werase(curwin);
wbkgd(curwin, ATTR_NORMAL_WINDOW);
wbkgd(curwin, attr_normal_window);
box(curwin, 0, 0);
center(curwin, 1, ATTR_TITLE, " How to Play ");
center(curwin, 2, ATTR_NORMAL, "Page %d of %d", curpage + 1, numpages);
center(curwin, 1, attr_title, " How to Play ");
center(curwin, 2, attr_normal, "Page %d of %d", curpage + 1, numpages);
wmove(curwin, 4, 2);
// Process the help text string
const char *s = help_text[curpage];
int curattr = ATTR_NORMAL;
int curattr = attr_normal;
while (*s != '\0') {
switch (*s) {
@ -201,47 +201,47 @@ void show_help (void)
break;
case 'N':
curattr = ATTR_NORMAL;
curattr = attr_normal;
wattrset(curwin, curattr);
break;
case 'B':
curattr = ATTR_NORMAL | A_BOLD;
curattr = attr_normal | A_BOLD;
wattrset(curwin, curattr);
break;
case 'H':
curattr = ATTR_HIGHLIGHT;
curattr = attr_highlight;
wattrset(curwin, curattr);
break;
case 'K':
curattr = ATTR_KEYCODE;
curattr = attr_keycode;
wattrset(curwin, curattr);
break;
case 'e':
curattr = ATTR_MAP_EMPTY;
curattr = attr_map_empty;
wattrset(curwin, curattr);
break;
case 'o':
curattr = ATTR_MAP_OUTPOST;
curattr = attr_map_outpost;
wattrset(curwin, curattr);
break;
case 's':
curattr = ATTR_MAP_STAR;
curattr = attr_map_star;
wattrset(curwin, curattr);
break;
case 'c':
curattr = ATTR_MAP_COMPANY;
curattr = attr_map_company;
wattrset(curwin, curattr);
break;
case 'k':
curattr = ATTR_MAP_CHOICE;
curattr = attr_map_choice;
wattrset(curwin, curattr);
break;
@ -323,7 +323,7 @@ void show_help (void)
s++;
}
center(curwin, 21, ATTR_WAITFORKEY, (curpage == 0) ?
center(curwin, 21, attr_waitforkey, (curpage == 0) ?
"[ Press <SPACE> to continue ] " :
"[ Press <SPACE> to continue or <BACKSPACE> for the previous page ] ");

View File

@ -47,7 +47,41 @@ typedef struct txwin {
************************************************************************/
WINDOW *curwin = NULL; // Top-most (current) window
bool use_color = false; // True to use colour in Star Traders
// Character renditions (attributes) used by Star Traders
chtype attr_root_window; // Root window (behind all others)
chtype attr_game_title; // One-line game title at top
chtype attr_normal_window; // Normal window background
chtype attr_title; // Normal window title
chtype attr_subtitle; // Normal window subtitle
chtype attr_normal; // Normal window text
chtype attr_highlight; // Normal window highlighted string
chtype attr_blink; // Blinking text in normal window
chtype attr_keycode; // Make keycodes like <1> stand out
chtype attr_choice; // Make map/company choices stand out
chtype attr_input_field; // Background for input text field
chtype attr_waitforkey; // "Press any key", normal window
chtype attr_map_window; // Map window background
chtype attr_mapwin_title; // Map window title (player name, turn)
chtype attr_mapwin_highlight; // Map window title highlight
chtype attr_mapwin_blink; // Map window title blinking text
chtype attr_map_empty; // On map, empty space
chtype attr_map_outpost; // On map, outpost
chtype attr_map_star; // On map, star
chtype attr_map_company; // On map, company
chtype attr_map_choice; // On map, a choice of moves
chtype attr_status_window; // Status window background
chtype attr_error_window; // Error message window background
chtype attr_error_title; // Error window title
chtype attr_error_normal; // Error window ordinary text
chtype attr_error_highlight; // Error window highlighted string
chtype attr_error_waitforkey; // "Press any key", error window
/************************************************************************
@ -99,8 +133,6 @@ void init_screen (void)
MIN_COLS, MIN_LINES);
}
use_color = ! option_no_color && has_colors();
// Initialise variables controlling the stack of windows
curwin = stdscr;
topwin = NULL;
@ -110,35 +142,101 @@ void init_screen (void)
curs_set(CURS_OFF);
raw();
// Initialise all colour pairs used; see intf.h for more comments
if (use_color) {
// Initialise all character renditions used in the game
if (! option_no_color && has_colors()) {
start_color();
init_pair(BLACK_ON_WHITE, COLOR_BLACK, COLOR_WHITE);
init_pair(BLUE_ON_BLACK, COLOR_BLUE, COLOR_BLACK);
init_pair(GREEN_ON_BLACK, COLOR_GREEN, COLOR_BLACK);
init_pair(CYAN_ON_BLUE, COLOR_CYAN, COLOR_BLUE);
init_pair(RED_ON_BLACK, COLOR_RED, COLOR_BLACK);
init_pair(YELLOW_ON_BLACK, COLOR_YELLOW, COLOR_BLACK);
init_pair(YELLOW_ON_BLUE, COLOR_YELLOW, COLOR_BLUE);
init_pair(YELLOW_ON_CYAN, COLOR_YELLOW, COLOR_CYAN);
init_pair(WHITE_ON_BLACK, COLOR_WHITE, COLOR_BLACK);
init_pair(WHITE_ON_BLUE, COLOR_WHITE, COLOR_BLUE);
init_pair(WHITE_ON_RED, COLOR_WHITE, COLOR_RED);
init_pair(1, COLOR_BLACK, COLOR_WHITE);
init_pair(2, COLOR_BLUE, COLOR_BLACK);
init_pair(3, COLOR_GREEN, COLOR_BLACK);
init_pair(4, COLOR_CYAN, COLOR_BLUE);
init_pair(5, COLOR_RED, COLOR_BLACK);
init_pair(6, COLOR_YELLOW, COLOR_BLACK);
init_pair(7, COLOR_YELLOW, COLOR_BLUE);
init_pair(8, COLOR_YELLOW, COLOR_CYAN);
init_pair(9, COLOR_WHITE, COLOR_BLACK);
init_pair(10, COLOR_WHITE, COLOR_BLUE);
init_pair(11, COLOR_WHITE, COLOR_RED);
bkgd(ATTR_ROOT_WINDOW);
attr_root_window = COLOR_PAIR(9);
attr_game_title = COLOR_PAIR(8) | A_BOLD;
attr_normal_window = COLOR_PAIR(10);
attr_title = COLOR_PAIR(6) | A_BOLD;
attr_subtitle = COLOR_PAIR(9);
attr_normal = attr_normal_window;
attr_highlight = COLOR_PAIR(7) | A_BOLD;
attr_blink = COLOR_PAIR(7) | A_BOLD | A_BLINK;
attr_keycode = COLOR_PAIR(6) | A_BOLD;
attr_choice = COLOR_PAIR(11) | A_BOLD;
attr_input_field = COLOR_PAIR(9);
attr_waitforkey = COLOR_PAIR(4);
attr_map_window = COLOR_PAIR(9);
attr_mapwin_title = COLOR_PAIR(10);
attr_mapwin_highlight = COLOR_PAIR(7) | A_BOLD;
attr_mapwin_blink = COLOR_PAIR(7) | A_BOLD | A_BLINK;
attr_map_empty = COLOR_PAIR(2) | A_BOLD;
attr_map_outpost = COLOR_PAIR(3) | A_BOLD;
attr_map_star = COLOR_PAIR(6) | A_BOLD;
attr_map_company = COLOR_PAIR(5) | A_BOLD;
attr_map_choice = COLOR_PAIR(11) | A_BOLD;
attr_status_window = COLOR_PAIR(1);
attr_error_window = COLOR_PAIR(11);
attr_error_title = COLOR_PAIR(6) | A_BOLD;
attr_error_normal = attr_error_window;
attr_error_highlight = COLOR_PAIR(11) | A_BOLD;
attr_error_waitforkey = COLOR_PAIR(11);
} else {
// No colour is to be used
attr_root_window = A_NORMAL;
attr_game_title = A_REVERSE | A_BOLD;
attr_normal_window = A_NORMAL;
attr_title = A_REVERSE;
attr_subtitle = A_REVERSE;
attr_normal = attr_normal_window;
attr_highlight = A_BOLD;
attr_blink = A_BOLD | A_BLINK;
attr_keycode = A_REVERSE;
attr_choice = A_REVERSE;
attr_input_field = A_BOLD | '_';
attr_waitforkey = A_NORMAL;
attr_map_window = A_NORMAL;
attr_mapwin_title = A_NORMAL;
attr_mapwin_highlight = A_BOLD;
attr_mapwin_blink = A_BOLD | A_BLINK;
attr_map_empty = A_NORMAL;
attr_map_outpost = A_NORMAL;
attr_map_star = A_BOLD;
attr_map_company = A_BOLD;
attr_map_choice = A_REVERSE;
attr_status_window = A_REVERSE;
attr_error_window = A_REVERSE;
attr_error_title = A_BOLD;
attr_error_normal = attr_error_window;
attr_error_highlight = A_REVERSE;
attr_error_waitforkey = A_REVERSE;
}
bkgd(attr_root_window);
clear();
move(0, 0);
for (int i = 0; i < COLS; i++) {
addch(ATTR_GAME_TITLE | ' ');
addch(attr_game_title | ' ');
}
center(stdscr, 0, ATTR_GAME_TITLE, PACKAGE_NAME);
center(stdscr, 0, attr_game_title, PACKAGE_NAME);
attrset(ATTR_ROOT_WINDOW);
attrset(attr_root_window);
refresh();
}

View File

@ -110,74 +110,46 @@ typedef enum curs_type {
#endif
/*
Colour pairs used in Star Traders. This list MUST be synchronised with
the initialisation of colour pairs in init_screen().
X/Open Curses only lists the following colours: black, blue, green,
cyan, red, magenta, yellow, white. Most implementations allow these
colours plus bold versions (for the foreground).
*/
enum color_pairs {
DEFAULT_COLORS = 0,
BLACK_ON_WHITE,
BLUE_ON_BLACK,
GREEN_ON_BLACK,
CYAN_ON_BLUE,
RED_ON_BLACK,
YELLOW_ON_BLACK,
YELLOW_ON_BLUE,
YELLOW_ON_CYAN,
WHITE_ON_BLACK,
WHITE_ON_BLUE,
WHITE_ON_RED
};
// Colour and non-colour character rendition selection
#define ATTR(color, nocolor) (use_color ? (color) : (nocolor))
/*
Character renditions (attributes) used in Star Traders
*/
#define ATTR_ROOT_WINDOW ATTR(COLOR_PAIR(WHITE_ON_BLACK), A_NORMAL)
#define ATTR_GAME_TITLE ATTR(COLOR_PAIR(YELLOW_ON_CYAN) | A_BOLD, A_REVERSE | A_BOLD)
#define ATTR_NORMAL_WINDOW ATTR(COLOR_PAIR(WHITE_ON_BLUE), A_NORMAL)
#define ATTR_TITLE ATTR(COLOR_PAIR(YELLOW_ON_BLACK) | A_BOLD, A_REVERSE)
#define ATTR_SUBTITLE ATTR(COLOR_PAIR(WHITE_ON_BLACK), A_REVERSE)
#define ATTR_NORMAL ATTR_NORMAL_WINDOW
#define ATTR_HIGHLIGHT ATTR(COLOR_PAIR(YELLOW_ON_BLUE) | A_BOLD, A_BOLD)
#define ATTR_BLINK ATTR(COLOR_PAIR(YELLOW_ON_BLUE) | A_BOLD | A_BLINK, A_BOLD | A_BLINK)
#define ATTR_KEYCODE ATTR(COLOR_PAIR(YELLOW_ON_BLACK) | A_BOLD, A_REVERSE)
#define ATTR_CHOICE ATTR(COLOR_PAIR(WHITE_ON_RED) | A_BOLD, A_REVERSE)
#define ATTR_INPUT_FIELD ATTR(COLOR_PAIR(WHITE_ON_BLACK), A_BOLD | '_')
#define ATTR_WAITFORKEY ATTR(COLOR_PAIR(CYAN_ON_BLUE), A_NORMAL)
#define ATTR_MAP_WINDOW ATTR(COLOR_PAIR(WHITE_ON_BLACK), A_NORMAL)
#define ATTR_MAPWIN_TITLE ATTR(COLOR_PAIR(WHITE_ON_BLUE), A_NORMAL)
#define ATTR_MAPWIN_HIGHLIGHT ATTR(COLOR_PAIR(YELLOW_ON_BLUE) | A_BOLD, A_BOLD)
#define ATTR_MAPWIN_BLINK ATTR(COLOR_PAIR(YELLOW_ON_BLUE) | A_BOLD | A_BLINK, A_BOLD | A_BLINK)
#define ATTR_MAP_EMPTY ATTR(COLOR_PAIR(BLUE_ON_BLACK) | A_BOLD, A_NORMAL)
#define ATTR_MAP_OUTPOST ATTR(COLOR_PAIR(GREEN_ON_BLACK) | A_BOLD, A_NORMAL)
#define ATTR_MAP_STAR ATTR(COLOR_PAIR(YELLOW_ON_BLACK) | A_BOLD, A_BOLD)
#define ATTR_MAP_COMPANY ATTR(COLOR_PAIR(RED_ON_BLACK) | A_BOLD, A_BOLD)
#define ATTR_MAP_CHOICE ATTR(COLOR_PAIR(WHITE_ON_RED) | A_BOLD, A_REVERSE)
#define ATTR_STATUS_WINDOW ATTR(COLOR_PAIR(BLACK_ON_WHITE), A_REVERSE)
#define ATTR_ERROR_WINDOW ATTR(COLOR_PAIR(WHITE_ON_RED), A_REVERSE)
#define ATTR_ERROR_TITLE ATTR(COLOR_PAIR(YELLOW_ON_BLACK) | A_BOLD, A_BOLD)
#define ATTR_ERROR_NORMAL ATTR_ERROR_WINDOW
#define ATTR_ERROR_HIGHLIGHT ATTR(COLOR_PAIR(WHITE_ON_RED) | A_BOLD, A_REVERSE)
#define ATTR_ERROR_WAITFORKEY ATTR(COLOR_PAIR(WHITE_ON_RED), A_REVERSE)
/************************************************************************
* Global variable declarations *
************************************************************************/
extern WINDOW *curwin; // Top-most (current) window
extern bool use_color; // True to use colour in Star Traders
// Character renditions (attributes) used by Star Traders
extern chtype attr_root_window; // Root window (behind all others)
extern chtype attr_game_title; // One-line game title at top
extern chtype attr_normal_window; // Normal window background
extern chtype attr_title; // Normal window title
extern chtype attr_subtitle; // Normal window subtitle
extern chtype attr_normal; // Normal window text
extern chtype attr_highlight; // Normal window highlighted string
extern chtype attr_blink; // Blinking text in normal window
extern chtype attr_keycode; // Make keycodes like <1> stand out
extern chtype attr_choice; // Make map/company choices stand out
extern chtype attr_input_field; // Background for input text field
extern chtype attr_waitforkey; // "Press any key", normal window
extern chtype attr_map_window; // Map window background
extern chtype attr_mapwin_title; // Map window title (player name, turn)
extern chtype attr_mapwin_highlight; // Map window title highlight
extern chtype attr_mapwin_blink; // Map window title blinking text
extern chtype attr_map_empty; // On map, empty space
extern chtype attr_map_outpost; // On map, outpost
extern chtype attr_map_star; // On map, star
extern chtype attr_map_company; // On map, company
extern chtype attr_map_choice; // On map, a choice of moves
extern chtype attr_status_window; // Status window background
extern chtype attr_error_window; // Error message window background
extern chtype attr_error_title; // Error window title
extern chtype attr_error_normal; // Error window ordinary text
extern chtype attr_error_highlight; // Error window highlighted string
extern chtype attr_error_waitforkey; // "Press any key", error window
/************************************************************************

View File

@ -221,44 +221,44 @@ selection_t get_move (void)
// Display current move choices on the galaxy map
for (i = 0; i < NUMBER_MOVES; i++) {
mvwaddch(curwin, game_move[i].y + 3, game_move[i].x * 2 + 2,
MOVE_TO_KEY(i) | ATTR_MAP_CHOICE);
MOVE_TO_KEY(i) | attr_map_choice);
}
wrefresh(curwin);
// Show menu of choices for the player
newtxwin(5, WIN_COLS, 19, WCENTER(WIN_COLS), false, 0);
while (selection == SEL_NONE) {
wbkgd(curwin, ATTR_NORMAL_WINDOW);
wbkgd(curwin, attr_normal_window);
werase(curwin);
box(curwin, 0, 0);
wmove(curwin, 2, 2);
attrpr(curwin, ATTR_KEYCODE, "<1>");
attrpr(curwin, attr_keycode, "<1>");
waddstr(curwin, " Display stock portfolio");
wmove(curwin, 3, 2);
attrpr(curwin, ATTR_KEYCODE, "<2>");
attrpr(curwin, attr_keycode, "<2>");
waddstr(curwin, " Declare bankruptcy");
wmove(curwin, 2, 42);
attrpr(curwin, ATTR_KEYCODE, "<3>");
attrpr(curwin, attr_keycode, "<3>");
waddstr(curwin, " Save and end the game");
wmove(curwin, 3, 42);
attrpr(curwin, ATTR_KEYCODE, "<CTRL><C>");
attrpr(curwin, attr_keycode, "<CTRL><C>");
waddstr(curwin, " Quit the game");
mvwaddstr(curwin, 1, 9, "Select move ");
waddstr(curwin, "[");
attrpr(curwin, ATTR_CHOICE, "%c", MOVE_TO_KEY(0));
attrpr(curwin, attr_choice, "%c", MOVE_TO_KEY(0));
waddstr(curwin, "-");
attrpr(curwin, ATTR_CHOICE, "%c", MOVE_TO_KEY(NUMBER_MOVES - 1));
attrpr(curwin, attr_choice, "%c", MOVE_TO_KEY(NUMBER_MOVES - 1));
waddstr(curwin, "/");
attrpr(curwin, ATTR_KEYCODE, "1");
attrpr(curwin, attr_keycode, "1");
waddstr(curwin, "-");
attrpr(curwin, ATTR_KEYCODE, "3");
attrpr(curwin, attr_keycode, "3");
waddstr(curwin, "/");
attrpr(curwin, ATTR_KEYCODE, "<CTRL><C>");
attrpr(curwin, attr_keycode, "<CTRL><C>");
waddstr(curwin, "]: ");
curs_set(CURS_ON);
@ -273,7 +273,7 @@ selection_t get_move (void)
curs_set(CURS_OFF);
waddstr(curwin, "Move ");
attrpr(curwin, ATTR_CHOICE, "%c", key);
attrpr(curwin, attr_choice, "%c", key);
} else {
switch (key) {
case '1':
@ -324,18 +324,18 @@ selection_t get_move (void)
}
// Clear the menu choices (but not the prompt!)
wattrset(curwin, ATTR_NORMAL);
wattrset(curwin, attr_normal);
for (y = 2; y < 4; y++) {
wmove(curwin, y, 2);
for (x = 2; x < getmaxx(curwin) - 2; x++) {
waddch(curwin, ' ' | ATTR_NORMAL);
waddch(curwin, ' ' | attr_normal);
}
}
wrefresh(curwin);
// Ask the player to confirm their choice
mvwaddstr(curwin, 2, 22, "Are you sure?");
if (! answer_yesno(curwin, ATTR_KEYCODE)) {
if (! answer_yesno(curwin, attr_keycode)) {
selection = SEL_NONE;
}
@ -345,8 +345,8 @@ selection_t get_move (void)
if (game_loaded) {
// Save the game to the same game number
newtxwin(5, 30, 7, WCENTER(30), true, ATTR_STATUS_WINDOW);
center(curwin, 2, ATTR_STATUS_WINDOW,
newtxwin(5, 30, 7, WCENTER(30), true, attr_status_window);
center(curwin, 2, attr_status_window,
"Saving game %d... ", game_num);
wrefresh(curwin);
@ -361,17 +361,17 @@ selection_t get_move (void)
bool done;
// Ask which game to save
newtxwin(6, 54, 8, WCENTER(54), true, ATTR_NORMAL_WINDOW);
newtxwin(6, 54, 8, WCENTER(54), true, attr_normal_window);
center(curwin, 1, ATTR_TITLE, " Save Game ");
center(curwin, 1, attr_title, " Save Game ");
mvwaddstr(curwin, 3, 2, "Enter game number ");
waddstr(curwin, "[");
attrpr(curwin, ATTR_KEYCODE, "1");
attrpr(curwin, attr_keycode, "1");
waddstr(curwin, "-");
attrpr(curwin, ATTR_KEYCODE, "9");
attrpr(curwin, attr_keycode, "9");
waddstr(curwin, "]");
waddstr(curwin, " or ");
attrpr(curwin, ATTR_KEYCODE, "<CTRL><C>");
attrpr(curwin, attr_keycode, "<CTRL><C>");
waddstr(curwin, " to cancel: ");
curs_set(CURS_ON);
@ -408,8 +408,8 @@ selection_t get_move (void)
game_num = key - '0';
// Try to save the game, if possible
newtxwin(5, 30, 7, WCENTER(30), true, ATTR_STATUS_WINDOW);
center(curwin, 2, ATTR_STATUS_WINDOW,
newtxwin(5, 30, 7, WCENTER(30), true, attr_status_window);
center(curwin, 2, attr_status_window,
"Saving game %d... ", game_num);
wrefresh(curwin);
@ -641,42 +641,42 @@ void bankrupt_player (bool forced)
longname = (strlen(player[current_player].name) > 20);
if (forced) {
newtxwin(longname ? 9 : 8, 54, 7, WCENTER(54), true, ATTR_ERROR_WINDOW);
newtxwin(longname ? 9 : 8, 54, 7, WCENTER(54), true, attr_error_window);
} else {
newtxwin(longname ? 8 : 7, 50, 7, WCENTER(50), true, ATTR_ERROR_WINDOW);
newtxwin(longname ? 8 : 7, 50, 7, WCENTER(50), true, attr_error_window);
}
center(curwin, 1, ATTR_ERROR_TITLE, " Bankruptcy Court ");
center(curwin, 1, attr_error_title, " Bankruptcy Court ");
if (forced) {
if (longname) {
center(curwin, 3, ATTR_ERROR_HIGHLIGHT, "%s",
center(curwin, 3, attr_error_highlight, "%s",
player[current_player].name);
center(curwin, 4, ATTR_ERROR_HIGHLIGHT,
center(curwin, 4, attr_error_highlight,
"has been declared bankrupt by the");
center(curwin, 5, ATTR_ERROR_HIGHLIGHT,
center(curwin, 5, attr_error_highlight,
"Interstellar Trading Bank");
} else {
center(curwin, 3, ATTR_ERROR_HIGHLIGHT,
center(curwin, 3, attr_error_highlight,
"%s has been declared bankrupt",
player[current_player].name);
center(curwin, 4, ATTR_ERROR_HIGHLIGHT,
center(curwin, 4, attr_error_highlight,
"by the Interstellar Trading Bank");
}
} else {
if (longname) {
center(curwin, 3, ATTR_ERROR_HIGHLIGHT, "%s",
center(curwin, 3, attr_error_highlight, "%s",
player[current_player].name);
center(curwin, 4, ATTR_ERROR_HIGHLIGHT,
center(curwin, 4, attr_error_highlight,
"has declared bankruptcy");
} else {
center(curwin, 3, ATTR_ERROR_HIGHLIGHT,
center(curwin, 3, attr_error_highlight,
"%s has declared bankruptcy",
player[current_player].name);
}
}
wait_for_key(curwin, getmaxy(curwin) - 2, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, getmaxy(curwin) - 2, attr_error_waitforkey);
deltxwin();
txrefresh();
@ -742,14 +742,14 @@ void try_start_new_company (int x, int y)
} else {
// Create the new company
newtxwin(8, 50, 7, WCENTER(50), true, ATTR_NORMAL_WINDOW);
newtxwin(8, 50, 7, WCENTER(50), true, attr_normal_window);
center(curwin, 1, ATTR_TITLE, " New Company ");
center(curwin, 3, ATTR_NORMAL, "A new company has been formed!");
center2(curwin, 4, ATTR_NORMAL, ATTR_HIGHLIGHT, "Its name is ",
center(curwin, 1, attr_title, " New Company ");
center(curwin, 3, attr_normal, "A new company has been formed!");
center2(curwin, 4, attr_normal, attr_highlight, "Its name is ",
"%s", company[i].name);
wait_for_key(curwin, 6, ATTR_WAITFORKEY);
wait_for_key(curwin, 6, attr_waitforkey);
deltxwin();
txrefresh();
@ -807,27 +807,27 @@ void merge_companies (map_val_t a, map_val_t b)
// Display information about the merger
newtxwin(number_players + 14, WIN_COLS - 4, 9 - number_players,
WCENTER(WIN_COLS - 4), true, ATTR_NORMAL_WINDOW);
WCENTER(WIN_COLS - 4), true, attr_normal_window);
center(curwin, 1, ATTR_TITLE, " Company Merger ");
center3(curwin, 3, ATTR_HIGHLIGHT, ATTR_HIGHLIGHT, ATTR_NORMAL,
center(curwin, 1, attr_title, " Company Merger ");
center3(curwin, 3, attr_highlight, attr_highlight, attr_normal,
company[bb].name, company[aa].name, " has just merged into ");
center(curwin, 5, ATTR_NORMAL, "Please note the following transactions:");
center(curwin, 5, attr_normal, "Please note the following transactions:");
center2(curwin, 7, ATTR_NORMAL, ATTR_HIGHLIGHT, " Old stock: ",
center2(curwin, 7, attr_normal, attr_highlight, " Old stock: ",
"%-20s", company[bb].name);
center2(curwin, 8, ATTR_NORMAL, ATTR_HIGHLIGHT, " New stock: ",
center2(curwin, 8, attr_normal, attr_highlight, " New stock: ",
"%-20s", company[aa].name);
// Handle the locale's currency symbol
snprintf(buf, BUFSIZE, "Bonus (%s)", lconvinfo.currency_symbol);
int w = getmaxx(curwin) - 52;
wattrset(curwin, ATTR_SUBTITLE);
wattrset(curwin, attr_subtitle);
mvwprintw(curwin, 10, 2, " %-*.*s %8s %8s %8s %12s ", w, w,
"Player", "Old", "New", "Total", buf);
wattrset(curwin, ATTR_NORMAL);
wattrset(curwin, attr_normal);
total_new = 0;
for (line = 11, i = 0; i < number_players; i++) {
@ -871,7 +871,7 @@ void merge_companies (map_val_t a, map_val_t b)
}
}
wait_for_key(curwin, getmaxy(curwin) - 2, ATTR_WAITFORKEY);
wait_for_key(curwin, getmaxy(curwin) - 2, attr_waitforkey);
deltxwin(); // "Company merger" window
txrefresh();
@ -958,18 +958,18 @@ void adjust_values (void)
if (company[which].on_map) {
if (randf() < ALL_ASSETS_TAKEN) {
newtxwin(10, 60, 6, WCENTER(60), true, ATTR_ERROR_WINDOW);
newtxwin(10, 60, 6, WCENTER(60), true, attr_error_window);
center(curwin, 1, ATTR_ERROR_TITLE, " Bankruptcy Court ");
center(curwin, 3, ATTR_ERROR_HIGHLIGHT, "%s has been declared",
center(curwin, 1, attr_error_title, " Bankruptcy Court ");
center(curwin, 3, attr_error_highlight, "%s has been declared",
company[which].name);
center(curwin, 4, ATTR_ERROR_HIGHLIGHT,
center(curwin, 4, attr_error_highlight,
"bankrupt by the Interstellar Trading Bank.");
center(curwin, 6, ATTR_ERROR_WINDOW,
center(curwin, 6, attr_error_window,
"All assets have been taken to repay outstanding loans.");
wait_for_key(curwin, 8, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, 8, attr_error_waitforkey);
deltxwin();
txrefresh();
@ -988,30 +988,30 @@ void adjust_values (void)
}
}
newtxwin(14, 60, 4, WCENTER(60), true, ATTR_ERROR_WINDOW);
newtxwin(14, 60, 4, WCENTER(60), true, attr_error_window);
center(curwin, 1, ATTR_ERROR_TITLE, " Bankruptcy Court ");
center(curwin, 3, ATTR_ERROR_HIGHLIGHT, "%s has been declared",
center(curwin, 1, attr_error_title, " Bankruptcy Court ");
center(curwin, 3, attr_error_highlight, "%s has been declared",
company[which].name);
center(curwin, 4, ATTR_ERROR_HIGHLIGHT,
center(curwin, 4, attr_error_highlight,
"bankrupt by the Interstellar Trading Bank.");
center2(curwin, 6, ATTR_ERROR_NORMAL, ATTR_ERROR_HIGHLIGHT,
center2(curwin, 6, attr_error_normal, attr_error_highlight,
"The Bank has agreed to pay stock holders ",
"%4.2f%%", rate * 100.0);
center(curwin, 7, ATTR_ERROR_NORMAL,
center(curwin, 7, attr_error_normal,
"of the share value on each share owned.");
l_strfmon(buf, BUFSIZE, "%12n", company[which].share_price);
center2(curwin, 9, ATTR_ERROR_NORMAL, ATTR_ERROR_HIGHLIGHT,
center2(curwin, 9, attr_error_normal, attr_error_highlight,
"Old share value: ", "%s", buf);
l_strfmon(buf, BUFSIZE, "%12n", company[which].share_price
* rate);
center2(curwin, 10, ATTR_ERROR_NORMAL, ATTR_ERROR_HIGHLIGHT,
center2(curwin, 10, attr_error_normal, attr_error_highlight,
"Amount paid per share: ", "%s", buf);
wait_for_key(curwin, 12, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, 12, attr_error_waitforkey);
deltxwin();
txrefresh();
@ -1101,19 +1101,19 @@ void adjust_values (void)
impounded = MIN(player[current_player].cash,
player[current_player].debt);
newtxwin(8, 60, 7, WCENTER(60), true, ATTR_ERROR_WINDOW);
center(curwin, 1, ATTR_ERROR_TITLE, " Interstellar Trading Bank ");
newtxwin(8, 60, 7, WCENTER(60), true, attr_error_window);
center(curwin, 1, attr_error_title, " Interstellar Trading Bank ");
l_strfmon(buf, BUFSIZE, "%1n", player[current_player].debt);
center(curwin, 3, ATTR_ERROR_HIGHLIGHT,
center(curwin, 3, attr_error_highlight,
"Your debt has amounted to %s", buf);
l_strfmon(buf, BUFSIZE, "%1n", impounded);
center3(curwin, 4, ATTR_ERROR_NORMAL, ATTR_ERROR_NORMAL,
ATTR_ERROR_HIGHLIGHT, "The Bank has impounded ",
center3(curwin, 4, attr_error_normal, attr_error_normal,
attr_error_highlight, "The Bank has impounded ",
" from your cash", "%s", buf);
wait_for_key(curwin, 6, ATTR_ERROR_WAITFORKEY);
wait_for_key(curwin, 6, attr_error_waitforkey);
deltxwin();
txrefresh();