slight whitespace editing and such

This commit is contained in:
jan6 2020-02-12 23:16:12 +00:00
parent 879739764a
commit 4c037162d5
1 changed files with 72 additions and 73 deletions

View File

@ -3,17 +3,17 @@
**
** Copyright (C) 1997 Brian "Beej" Hall
** with modifications by David Barnsdale 2004 and by ~jan6 2020
**
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
@ -128,7 +128,7 @@ void color_setup(void);
void get_num_players(void);
void showmap(void);
void drawmap(int loc, char c);
int get_move(void); /*called by main */
int get_move(void); /*called by main */
void show_coinfo(void);
void more_coinfo(void);
void do_move(int move);
@ -136,22 +136,22 @@ void do_merge(int *c1, int *c2, int *o1, int *o2);
void holding_bonus(void);
void holding_bonus(void);
void buy_sell(void);
int check_endgame(void);
int count_used_sectors(void);
int check_endgame(void);
int count_used_sectors(void);
void calc_cost(int cnum, int move, int n, int s, int w, int e);
void new_co_announce(int newc);
void suck_announce(int conum, int grown);
void merge_announce(int c1, int c2);
void xaction_announce(int c1, int c2);
void split_announce(int conum);
int co_avail(void);
int co_avail(void);
void clear_general(char *s,int blink);
void center(WINDOW *win, int width, int row, char *s);
int my_mvwgetstr(WINDOW *win, int y, int x, int max, int restricted, char *s);
int my_mvwgetstr(WINDOW *win, int y, int x, int max, int restricted, char *s);
void redraw(void);
void show_standings(char *title);
void show_company_holdings(char *title);
int order_compare(const void *v1, const void *v2);
int order_compare(const void *v1, const void *v2);
void quit_yn(void);
void shutdown(void);
void usage(void);
@ -161,36 +161,36 @@ void usage(void);
char placemove(); */
/* global variables */
char *VERSION = "1.3.0";
char *VERSION_DATE = "1-June-2004";
char *VERSION = "1.4.1";
char *VERSION_DATE = "13-February-2020";
char *ident = "$Id: starlanes.c 1.2.2 29-Mar-1997 beej@ecst.csuchico.edu $";
/* These two varibles must be cordinated with ai.c */
/* These probably could be constants but untill I'm
sure they stay as variables. */
int MAPX = Mx; /* x dimension of map */
int MAPY = My; /* y dimension of map */
int MAPX = Mx; /* x dimension of map */
int MAPY = My; /* y dimension of map */
int LINES; /* lines in screen */
int COLUMNS; /* columns in screen */
char *map; /* pointer to the map data */
//char *mapc; /* copy of map for ai */
PLAYER *pl; /* pointer to array of players */
COMPANY *co; /* pointer to array of companies */
int numplayers,turn; /* number of players, whose turn it is */
WINDOW *mapwin,*general,*coinfo; /* pointers to the windows */
int color; /* true if we want color */
int sologame=0; /* set to true if nmr of playes is 0*/
int Difficulty;
int LINES; /* lines in screen */
int COLUMNS; /* columns in screen */
char *map; /* pointer to the map data *//*
char *mapc; /* copy of map for ai */
PLAYER *pl; /* pointer to array of players */
COMPANY *co; /* pointer to array of companies */
int numplayers,turn; /* number of players, whose turn it is */
WINDOW *mapwin,*general,*coinfo; /* pointers to the windows */
int color; /* true if we want color */
int sologame=0; /* set to true if nmr of playes is 0*/
int Difficulty;
int main(int argc, char *argv[])
{
int done = 0,move, colorforce=0, monoforce=0;
switch(argc)
{
case 1: break;
case 2: if (argv[1][1] == 'v') {
case 1: break;
case 2: if (argv[1][1] == 'v') {
fprintf(stderr,"Starlanes for ncurses v%s Copyright (C) by Brian \"Beej\" Hall %s\n",VERSION,VERSION_DATE);
fprintf(stderr,"\nStarlanes comes with ABSOLUTELY NO WARRANTY. This is free\n");
fprintf(stderr,"software, and you are welcome to redistribute it under\n");
@ -204,13 +204,13 @@ int main(int argc, char *argv[])
else
usage();
break;
default:usage();
default: usage();
}
/* initscr */
initscr();
start_color();
if (colorforce)
color = 1;
else if (monoforce)
@ -228,7 +228,7 @@ int main(int argc, char *argv[])
/* num players */
get_num_players();
clear();
attron(color?(YELLOW_ON_BLUE|A_BOLD):A_REVERSE);
mvprintw(0,0," StarLanes ");
@ -327,10 +327,9 @@ void initialize(void)
for(i=0;i<MAXPLAYERS;i++) {
pl[i].name[0] = '\0';
pl[i].ishuman=1;
pl[i].ishuman=1;
pl[i].cash = INIT_CASH;
for(j=0;j<NUMCO;j++)
pl[i].holdings[j] = 0;
for(j=0;j<NUMCO;j++) pl[i].holdings[j] = 0;
}
/* create the windows: */
@ -362,20 +361,20 @@ void initialize(void)
void color_setup(void)
{
init_pair(1, COLOR_BLUE, COLOR_BLACK);
init_pair(2, COLOR_RED, COLOR_BLACK);
init_pair(3, COLOR_GREEN, COLOR_BLACK);
init_pair(4, COLOR_YELLOW, COLOR_BLACK);
init_pair(1, COLOR_BLUE, COLOR_BLACK);
init_pair(2, COLOR_RED, COLOR_BLACK);
init_pair(3, COLOR_GREEN, COLOR_BLACK);
init_pair(4, COLOR_YELLOW, COLOR_BLACK);
init_pair(5, COLOR_MAGENTA, COLOR_BLACK);
init_pair(6, COLOR_CYAN, COLOR_BLACK);
init_pair(7, COLOR_WHITE, COLOR_BLACK);
init_pair(8, COLOR_YELLOW, COLOR_BLUE);
init_pair(9, COLOR_WHITE, COLOR_BLUE);
init_pair(10, COLOR_BLACK, COLOR_YELLOW);
init_pair(11, COLOR_BLACK, COLOR_WHITE);
init_pair(12, COLOR_BLACK, COLOR_RED);
init_pair(13, COLOR_BLACK, COLOR_BLUE);
init_pair(14, COLOR_BLACK, COLOR_GREEN);
init_pair(6, COLOR_CYAN, COLOR_BLACK);
init_pair(7, COLOR_WHITE, COLOR_BLACK);
init_pair(8, COLOR_YELLOW, COLOR_BLUE);
init_pair(9, COLOR_WHITE, COLOR_BLUE);
init_pair(10, COLOR_BLACK, COLOR_YELLOW);
init_pair(11, COLOR_BLACK, COLOR_WHITE);
init_pair(12, COLOR_BLACK, COLOR_RED);
init_pair(13, COLOR_BLACK, COLOR_BLUE);
init_pair(14, COLOR_BLACK, COLOR_GREEN);
}
/*
@ -468,16 +467,16 @@ void showmap(void)
for(i=0;i<MAPY;i++)
for(j=0;j<MAPX;j++) {
switch(map[j+i*MAPX]) {
case SPACE: attrs = MAP_SPACE;break;
case STAR: attrs = MAP_STAR;break;
case NEWCO: attrs = MAP_NEWCO;break;
case SPACE : attrs = MAP_SPACE;break;
case STAR : attrs = MAP_STAR;break;
case NEWCO : attrs = MAP_NEWCO;break;
case BLACKHOLE: attrs = MAP_BLACKHOLE;break;
case 'A': attrs = CO_A;break;
case 'B': attrs = CO_B;break;
case 'C': attrs = CO_C;break;
case 'D': attrs = CO_D;break;
case 'E': attrs = CO_E;break;
default: attrs = A_NORMAL;
default : attrs = A_NORMAL;
}
wattron(mapwin,attrs);
mvwaddch(mapwin,i+1,j*3+2,map[j+i*MAPX]);
@ -496,16 +495,16 @@ void drawmap(int loc, char c)
int attrs;
switch(c) {
case SPACE: attrs = MAP_SPACE;break;
case STAR: attrs = MAP_STAR;break;
case NEWCO: attrs = MAP_NEWCO;break;
case SPACE : attrs = MAP_SPACE;break;
case STAR : attrs = MAP_STAR;break;
case NEWCO : attrs = MAP_NEWCO;break;
case BLACKHOLE: attrs = MAP_BLACKHOLE;break;
case 'A': attrs = CO_A;break;
case 'B': attrs = CO_B;break;
case 'C': attrs = CO_C;break;
case 'D': attrs = CO_D;break;
case 'E': attrs = CO_E;break;
default: attrs = A_NORMAL;
default : attrs = A_NORMAL;
}
wattron(mapwin,attrs);
mvwaddch(mapwin,loc/MAPX+1,(loc%MAPX)*3+2,c);
@ -563,10 +562,10 @@ void show_coinfo(void)
int get_move(void)
{
char s[80],c;
int move[NUMMOVES],i,j,ok,splat;
int move[NUMMOVES],i,j,ok,splat;
/* move[] is the numbered options that are shown on the screen
i represents each of the random place points while j
represents the already chosen points which must be
represents the already chosen points which must be
checked to avoid duplicates. */
wattron(mapwin,A_REVERSE);
@ -629,8 +628,7 @@ int get_move(void)
} while(c<1 || c>NUMMOVES);
echo();
for(i=0;i<NUMMOVES;i++)
mvwaddch(mapwin,move[i]/MAPX+1,(move[i]%MAPX)*3+2,SPACE);
for(i=0;i<NUMMOVES;i++) mvwaddch(mapwin,move[i]/MAPX+1,(move[i]%MAPX)*3+2,SPACE);
wnoutrefresh(mapwin);
return move[c-1];
@ -726,7 +724,7 @@ void do_move(int move)
calc_cost(newc_type-'A',move,north,south,west,east);
if (co[newc_type-'A'].price <= 0) /* black holed */
suck_announce(newc_type-'A',1);
else {
else {
if (co[newc_type-'A'].price > SPLIT_PRICE)
split_announce(newc_type-'A');
else
@ -765,7 +763,7 @@ void do_merge(int *c1, int *c2, int *o1, int *o2)
cb = t;
}
for(i=0;i<MAPX*MAPY;i++)
for(i=0;i<MAPX*MAPY;i++)
if (map[i] == cs+'A') {
map[i] = cb+'A';
drawmap(i,cb+'A');
@ -778,11 +776,11 @@ void do_merge(int *c1, int *c2, int *o1, int *o2)
co[cb].size += co[cs].size;
co[cb].price += co[cs].price;
co[cs].size = 0;
wnoutrefresh(mapwin); /* show the players what's up */
wnoutrefresh(mapwin); /* show the players what's up */
merge_announce(cb,cs);
xaction_announce(cb,cs); /*annouces and executes the transactions */
xaction_announce(cb,cs); /* annouces and executes the transactions */
if (co[cb].price > SPLIT_PRICE)
split_announce(cb);
}
@ -803,8 +801,8 @@ void calc_cost(int cnum, int move, int n, int s, int w, int e)
if (s == BLACKHOLE) co[cnum].price += BLACKHOLECOST;
if (w == BLACKHOLE) co[cnum].price += BLACKHOLECOST;
if (e == BLACKHOLE) co[cnum].price += BLACKHOLECOST;
if (n == NEWCO) { /* starter companies */
if (n == NEWCO) { /* starter companies */
map[move-MAPX] = cnum + 'A'; /*company represented by A is 0 and so on */
drawmap(move-MAPX,cnum+'A');
co[cnum].size++;
@ -868,7 +866,7 @@ void suck_announce(int conum, int grown)
}
}
wnoutrefresh(mapwin);
for(i=0;i<numplayers;i++) /* ditch all player holdings */
pl[i].holdings[conum] = 0;
@ -951,7 +949,7 @@ void xaction_announce(int c1, int c2)
mvwprintw(general,3+i,4," %-20s ", pl[i].name);
wattroff(general,A_BOLD);
wprintw(general,"%-5d %-5d %5d ",
pl[i].holdings[c2],newshares,totalholdings);
pl[i].holdings[c2],newshares,totalholdings); //continues previous line
wattron(general,A_BOLD);
wprintw(general,"$%-5d",bonus);
wattroff(general,A_BOLD);
@ -986,7 +984,7 @@ void split_announce(int conum)
center(general,COLUMNS-2,6,"Press any key to continue...");
co[conum].price = (int)(((float)(co[conum].price)/2.0) + 0.5);
for(i=0;i<numplayers;i++)
for(i=0;i<numplayers;i++)
pl[i].holdings[conum] *= 2;
show_coinfo();
@ -1027,8 +1025,7 @@ void buy_sell(void)
if (cocount == 0) return; /* no companies yet */
sprintf(s," %s (Cash: $%ld) ",pl[turn].name,pl[turn].cash);
clear_general(s,0);
sprintf(s," %s (Cash: $%ld) ",pl[turn].name,pl[turn].cash); clear_general(s,0);
center(general,COLUMNS-2,1,"Arrow keys to select a company, return to trade, escape when done:");
@ -1072,22 +1069,24 @@ void buy_sell(void)
break;
case 'q':
case 'Q':
case CTRL_C:quit_yn();
case CTRL_C :
quit_yn();
wmove(general,cursor+3,strlen(co[cos[cursor]].name)+20);
wnoutrefresh(general);
break;
case KEY_UP:
case KEY_UP :
case '8':
case 'k':
case 'K': newcur = cursor?cursor-1:cocount-1;break;
case KEY_DOWN:
case KEY_DOWN :
case '5':
case 'j':
case 'J': newcur = cursor<cocount-1?cursor+1:0;break;
case KEY_RIGHT:
case 6:
case CR :
case LF : max = pl[turn].cash / co[cos[cursor]].price;
case LF :
max = pl[turn].cash / co[cos[cursor]].price;
min = -pl[turn].holdings[cos[cursor]];
sprintf(s,"Amount (%d to %d): ",min,max);
mvwprintw(general,cursor+3,40,s);