Compare commits

..

5 Commits

10 changed files with 307 additions and 227 deletions

View File

@ -39,3 +39,8 @@ fakeinstall:
@echo chown root:root $(INSTALLDIR)/man/man6/starlanes.6
@echo chmod 755 $(INSTALLDIR)/bin/starlanes
@echo chmod 444 $(INSTALLDIR)/man/man6/starlanes.6

12
README
View File

@ -8,8 +8,7 @@ I removed the AI, at least for now
(feel free to add it back if you figure out how to properly fix it)
I also changed the company names slightly, and adjusted the stats for no reason
most importantly, after experiencing troubles where someone accidentally closed
the final stats screen, I modified it to only close when pressing Y (doesn't
matter if lower or uppercase)
the final stats screen, I modified it to only close when pressing Y (doesn't matter if lower or uppercase)
there are still plenty of warnings left to fix,
but they don't affect the gameplay
@ -28,12 +27,12 @@ one. Hence the make file may need adjusting.
For instance sometimes the curses program is
called plain curses and sometimes ncurses
It also expects there to be a /man/man6/ directory
in which case you should
in which case you should
Please, if you have any problems while installing
let me, David, know ("dejvid@zamir.net" and
Please, if you have any problems while installing
let me, David, know ("dejvid@zamir.net" and
"dejvid@barnsdle.demon.co.uk") even if you
solve them.
solve them.
Of course you can always just change to the directory where
you installed starlanes and type "./starlanes"
@ -51,3 +50,4 @@ first published in Creative Computing magazine.
-Beej
beej@ecst.csuchico.edu

131
ai.c
View File

@ -5,12 +5,12 @@
** 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.
@ -22,22 +22,23 @@
#include "common.h"
/*
int move;
char map[120]; */
/*
/*
**void generate_nme(nme)
**used in place of getting name from humans
**used in place of getting name from humans
*/
#define up_obj(move) (((move)-MAPX < 0)?OFFMAP:map[(move)-MAPX])
#define down_obj(move) (((move)+MAPX >= MAPX*MAPY)?OFFMAP:map[(move)+MAPX])
#define left_obj(move) (((move)%MAPX)?map[(move)-1]:OFFMAP)
#define right_obj(move) (((move)%MAPX == MAPX-1)?OFFMAP:map[(move)+1])
void generate_nme(char *nme)
{
void generate_nme(char *nme)
{
static int nmeNmr=0;
switch(nmeNmr) {
@ -59,7 +60,7 @@ enum investstatus { none,small ,signif,main };// type;
/* getfarmove gets the charecter value of a location 2 steps away.
** It makes no distiction between an empty space and an off map
** location
** location
*/
char getfarmove(enum farcompass fcom, char *map, int loc)
{
@ -67,13 +68,13 @@ char getfarmove(enum farcompass fcom, char *map, int loc)
static int MAPY=My;
char ch;
switch(fcom) {
case NorthW: if ((loc-1*MAPX )< 0) ch=SPACE;
case NorthW: if ((loc-1*MAPX )< 0) ch=SPACE;
else {
ch=left_obj(loc-1*MAPX);
}
break;
case FNorth: if ((loc-2*MAPX )< 0) ch=SPACE; else ch=map[loc-2*MAPX];break;
case NorthE: if ((loc-1*MAPX )< 0) ch=SPACE;
case NorthE: if ((loc-1*MAPX )< 0) ch=SPACE;
else {
ch=right_obj(loc-1*MAPX);
}
@ -81,19 +82,19 @@ char getfarmove(enum farcompass fcom, char *map, int loc)
case FEast: if ((loc%MAPX)!=((loc+2)%MAPX)) ch=map[loc+2];
else ch=SPACE ;
break;
case SouthE: if ((loc+MAPX )> (MAPX*MAPY)) ch=SPACE;
case SouthE: if ((loc+MAPX )> (MAPX*MAPY)) ch=SPACE;
else {
ch=right_obj(loc+1*MAPX);
}
case FSouth: if ((loc+2*MAPX) > (MAPX*MAPY)) ch=SPACE; else ch=map[loc-2*MAPX];break;
/*(((loc)+2*MAPX > MAPX*MAPY)?SPACE:map[(loc)+2*MAPX]);break;*/
case SouthW: if ((loc+MAPX )> (MAPX*MAPY)) ch=SPACE;
case SouthW: if ((loc+MAPX )> (MAPX*MAPY)) ch=SPACE;
else {
ch=left_obj(loc+1*MAPX);
}
case FWest: if ((loc%MAPX)!=((loc-2)%MAPX)) ch=map[loc-2];
else ch=SPACE ;
break;
break;
/*if ((loc%MAPX)!=(loc-2)%MAPX))) ch=map[(loc)-2];else ch=SPACE;break;*/
default: ch= '?';break;
};
@ -104,13 +105,13 @@ enum compass revdir(enum compass dir)
{
enum compass rev;
switch(dir) {
case North:rev=South; break;
case East:rev=West; break;
case West:rev=East; break;
case South:rev=North; break;
case North:rev=South; break;
case East:rev=West; break;
case West:rev=East; break;
case South:rev=North; break;
}
return rev;
}
}
int onestep(enum compass dir, int loc)
{
@ -118,16 +119,16 @@ int onestep(enum compass dir, int loc)
switch(dir) {
case North:if ((loc)-Mx < 0) newloc=-1;
else newloc=loc-Mx;
break;
break;
case South:if ((loc)+Mx > Mx*My) newloc=-1;
else newloc=loc+Mx;
break;
break;
case West: if ((loc)%Mx ==0)newloc=-1;
else newloc=loc-1;
break;
break;
case East: if ((loc)%Mx ==Mx-1)newloc=-1;
else newloc=loc+1;
break;
break;
}
return newloc;
}
@ -141,7 +142,7 @@ int onestep(enum compass dir, int loc)
*/
char placemove(PLAYER *pla,int *move, COMPANY *co, int turn,char *map, int Difficulty)
{
{
static int MAPX=Mx ,MAPY=My;
char mvch; long moveval[NUMMOVES]; int neighb[4];int nc, ncom;
enum compass dir;
@ -155,10 +156,10 @@ char placemove(PLAYER *pla,int *move, COMPANY *co, int turn,char *map, int Diffi
mvch= '1';
curMax=-1000;
if ((Difficulty>1 )||(rand()%100>50))
for (curCo=0;curCo<=NUMCO;curCo++){
tothold[curCo] =0;
for (curCo=0;curCo<=NUMCO;curCo++){
tothold[curCo] =0;
/*finds the proportion of holdings relativ to other players*/
for (curpl=0;curpl<MAXPLAYERS;curpl++)
for (curpl=0;curpl<MAXPLAYERS;curpl++)
tothold[curCo]=pla[curpl].holdings[curCo] +tothold[curCo];
if (tothold[curCo]==0) coholdings[curCo]=0;
else coholdings[curCo]=pla[turn].holdings[curCo]/tothold[curCo];
@ -180,8 +181,8 @@ char placemove(PLAYER *pla,int *move, COMPANY *co, int turn,char *map, int Diffi
if (locs[dir]== STAR) moveval[mvop]=moveval[mvop]+STARCOST ;
if (locs[dir]== BLACKHOLE) moveval[mvop]=moveval[mvop]+BLACKHOLECOST ;
if (locs[dir]== NEWCO) {
moveval[mvop]=moveval[mvop]+NEWCOCOST ;
}
moveval[mvop]=moveval[mvop]+NEWCOCOST ;
}
if iscompany(locs[dir]) {
nc=locs[dir]-'A';
if ((ncom==0)||(nc!=neighb[1])){
@ -192,20 +193,20 @@ char placemove(PLAYER *pla,int *move, COMPANY *co, int turn,char *map, int Diffi
}
if (ncom==0) if (moveval[mvop]>100) moveval[mvop]*=FOUNDER_BONUS; else moveval[mvop]=0 ;
/*need to check here whether company eliminated by black hole */
else if (ncom==1){
else if (ncom==1){
/*if company next door and holding is minimal then value will be reversed*/
moveval[mvop]=moveval[mvop]*( coholdings[neighb[1]]-0.25)*tothold[ncom];
moveval[mvop]=moveval[mvop]*( coholdings[neighb[1]]-0.25)*tothold[ncom];
}
else if (ncom>1){
else if (ncom>1){
/*calculate value of merger*/
smallC=1;
smallC=1;
bigC=1;
for (curCo=2;curCo<=ncom;curCo++){
if (co[neighb[curCo]].price<co[neighb[smallC]].price)
smallC= curCo;
if (co[neighb[curCo]].price>co[neighb[bigC]].price)
bigC= curCo;
}
bigC= curCo;
}
sgain=co[neighb[smallC]].price*tothold[neighb[smallC]]*
(coholdings[neighb[smallC]]-0.25)/2;/*bonus*/
sgain+=co[bigC].price*tothold[neighb[smallC]]*
@ -213,7 +214,7 @@ char placemove(PLAYER *pla,int *move, COMPANY *co, int turn,char *map, int Diffi
bgain=(moveval[mvop]+co[neighb[smallC]].price)*
tothold[neighb[bigC]]*(coholdings[neighb[bigC]]-0.25);
moveval[mvop]=sgain+bgain;
}
if (moveval[mvop]>curMax) {
intchar= mvop +(int)'1';
@ -226,8 +227,8 @@ char placemove(PLAYER *pla,int *move, COMPANY *co, int turn,char *map, int Diffi
}
/*
** distantblackhole starts at the black hole, moves two away and then
/*
** distantblackhole starts at the black hole, moves two away and then
** looks at the three ajacent points for companies. It then increases
** the risk factor for any companies found. It isn't
** always able to detect when the route between the black hole
@ -239,7 +240,7 @@ void distantblackhole(COMPANY *co,char *map,int loc)
int step,cloc;
enum compass dir,end;
int neighb[4], ncom, new,isnew,curCo;
for (dir=North;dir<=South;dir++){
step =onestep(dir, loc);
if (step>-1) if (map[step]==SPACE){
@ -250,7 +251,7 @@ void distantblackhole(COMPANY *co,char *map,int loc)
cloc= onestep(end, step);
if iscompany(map[cloc]) {
new=map[cloc]-'A';
isnew=1;
isnew=1;
curCo=0;
while ((curCo<=ncom) && (isnew==1)){
if (curCo==ncom) /* no need to check if co already found if first */
@ -265,32 +266,32 @@ void distantblackhole(COMPANY *co,char *map,int loc)
}
}
curCo=1;
while (curCo<=ncom){
co[neighb[curCo]].risk+= BLACKHOLECOST/2;
while (curCo<=ncom){
co[neighb[curCo]].risk+= BLACKHOLECOST/2;
curCo++;
}
}
}
}
}
/*
/*
**ai_buy_sell not only choses the most promising investments but
**actually executes the sales
**actually executes the sales
*/
void ai_buy_sell(PLAYER *pl, COMPANY *co, int turn,char *map, int Difficulty)
{
int curloc,curCo,BuyCo,SecCo,amt ;
int curloc,curCo,BuyCo,SecCo,amt ;
static int MAPX=Mx , MAPY=My;
int localpt, localris;
enum compass dir;
enum compass dir;
int neighb[4];
int nc, ncom,smallC,bigC;
int nc, ncom,smallC,bigC;
char locs[South];
for(curCo=0;curCo<NUMCO;curCo++) { /*reset values*/
co[curCo].potential=co[curCo].risk=0;
}
}
for (curloc=1;curloc<=(Mx*My);curloc++){
if (map[curloc]==BLACKHOLE) distantblackhole(co,map,curloc);
if (map[curloc]==SPACE);{
@ -298,12 +299,12 @@ void ai_buy_sell(PLAYER *pl, COMPANY *co, int turn,char *map, int Difficulty)
locs[South] = down_obj(curloc);
locs[West] = left_obj(curloc);
locs[East] = right_obj(curloc);
localris=0;
localris=0;
localpt=NEWCOCOST; /*the gain from the point itself */
for(dir=North;dir<=South;dir++){
for(dir=North;dir<=South;dir++){
if (locs[dir]== STAR) localpt=localpt+STARCOST ;/*First check the value or */
if ((Difficulty>2 )||(rand()%100>50))
if (locs[dir]== BLACKHOLE)
if (locs[dir]== BLACKHOLE)
localris=localris+BLACKHOLECOST;/*loss from the point*/
if (locs[dir]== NEWCO) localpt=localpt+NEWCOCOST ;
}
@ -318,63 +319,63 @@ void ai_buy_sell(PLAYER *pl, COMPANY *co, int turn,char *map, int Difficulty)
}
}
}
if (ncom==1 ){
if (ncom==1 ){
co[nc].potential=co[nc].potential+localpt;
co[nc].risk=co[nc].risk+localris;
co[nc].risk=co[nc].risk+localris;
}
else if (ncom>1){
smallC=1;
else if (ncom>1){
smallC=1;
bigC=1;
for (curCo=2;curCo<=ncom;curCo++){
if (co[neighb[curCo]].price<co[neighb[smallC]].price)
smallC= curCo;
if (co[neighb[curCo]].price>co[neighb[bigC]].price)
bigC= curCo;
}
bigC= curCo;
}
/* bonus ignored for now*/
co[neighb[bigC]].potential=co[neighb[bigC]].potential+(co[neighb[smallC]].price);
co[neighb[smallC]].potential=co[neighb[smallC]].potential+co[neighb[bigC]].price/2;
}
}
SecCo=BuyCo=-1 ;
for(curCo=0;curCo<NUMCO;curCo++) /*Find the co with greatest potential*/
if (co[curCo].price>0) {
co[curCo].netpot=(co[curCo].potential+co[curCo].risk)/
(co[curCo].price);
(co[curCo].price);
if ((co[curCo].netpot>0)){
if (BuyCo==-1) BuyCo=curCo;
else {
if (co[curCo].netpot>co[BuyCo].netpot) {
SecCo=BuyCo;
SecCo=BuyCo;
BuyCo=curCo;
}
else {
if (SecCo==-1) SecCo=curCo;
else if (co[curCo].netpot>co[SecCo].netpot)
SecCo=curCo;
else if (co[curCo].netpot>co[SecCo].netpot)
SecCo=curCo;
}
}
}
}
}
if ((Difficulty>2 )||((Difficulty>1 )&&(rand()%100>50)) )
for(curCo=0;curCo<NUMCO;curCo++){ /*sell all*/
pl[turn].cash += pl[turn].holdings[curCo]*co[curCo].price;
pl[turn].holdings[curCo]=0;
}
}
if (BuyCo>-1){ /*now buy shares in the company with the best prospects*/
if (co[BuyCo].risk<0) { /*don't put all your eggs into one basket*/
amt= pl[turn].cash/(co[BuyCo].price*2);
pl[turn].cash += (-amt * co[BuyCo].price);
pl[turn].holdings[BuyCo] += amt;
if (SecCo>-1){
if (SecCo>-1){
amt= pl[turn].cash/co[SecCo].price;
pl[turn].cash += (-amt * co[SecCo].price);
pl[turn].holdings[SecCo] += amt;
}
}
else {
amt= pl[turn].cash/co[BuyCo].price;
amt= pl[turn].cash/co[BuyCo].price;
pl[turn].cash += (-amt * co[BuyCo].price);
pl[turn].holdings[BuyCo] += amt;
}

View File

@ -1,14 +1,16 @@
Version 1.4.2 released 2020 by ~creme
creme@envs.net
Version 1.4.2 by ~jan6, 2020
change company names to default
added a terminal bell on the start of each turn, to notify players
Version 1.4.1 by ~jan6, 2020
Version 1.4.1 released 2020 by ~creme
creme@envs.net
restored original stats,
moved modded stats to separate file (rename to common.h use)
change game-settings to default
fixed text overflow bug caused by extending company names in 1.4.0,
the bug pushed 5th company (Eridani) off-screen,
because of too long lines wrapping around
@ -29,7 +31,7 @@ Stripped the binary (about halving final size)
Version 1.3.0 released 2004 by David Barnsdale
Version 1.3.0 released 2004 by David Barnsdale
dejvid@barnsdle.demon.co.uk and dejvid@zamir.net
AI implemented. All AI related stuff placed in "ai.c".

View File

@ -1,63 +0,0 @@
/*
** 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 v2 for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program;
*/
#define OFFMAP '-' /* space character */
#define SPACE '.' /* space character */
#define NEWCO '+' /* new company character */
#define STAR '*' /* star character */
#define BLACKHOLE '@' /* black hole character */
#define NUMCO 5 /* number of companies (don't change) */
#define INIT_CO_COST 100 /* initial company start cost */
#define FOUNDER_BONUS 5 /* founder gets this much stock */
#define NUMMOVES 5 /* number of moves options a player gets */
#define MAXPLAYERS 4 /* total number of players a game can have */
#define STARCOST 500 /* company's price increase near star */
#define BLACKHOLECOST -500 /* price increase near black hole */
#define NEWCOCOST 100 /* company's price increase near new co */
#define Mx 12 /* x dimension of map */
#define My 10 /* y dimension of map */
/* macros to look at surrounding spaces on the map: */
#define iscompany(c) ((c)>='A'&&(c)<='Z')
#define ripe(c) ((c)==STAR||(c)==NEWCO)
#define co_near(move) (iscompany(up_obj(move))||iscompany(down_obj(move))||iscompany(left_obj(move))||iscompany(right_obj(move)))
#define s_or_bh(c) ((c)==SPACE||(c)==BLACKHOLE)
/* player and company structures: */
typedef struct {
char name[100];
int holdings[NUMCO];
long int svalue; /* stock value -- not always accurate!! */
long int cash;
int ishuman;
} PLAYER;
typedef struct {
char name[100];
int price;
int size;
int potential;
int risk; /* value related to chance of being swallowed by Black Hole */
int netpot; /* potential - risk */
} COMPANY;
MPANY;

1
common.h Symbolic link
View File

@ -0,0 +1 @@
common.h.modded

67
common.h.modded Normal file
View File

@ -0,0 +1,67 @@
/*
** 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 v2 for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program;
*/
#define OFFMAP '?' /* space character */
#define SPACE '`' /* space character */
#define NEWCO '+' /* new company character */
#define STAR '*' /* star character */
#define BLACKHOLE '@' /* black hole character */
#define END_PERCENT 45 /* end when this much of the map is full */
#define INIT_CASH 600 /* initial player cash */
#define SPLIT_PRICE 300 /* when stocks split 2-1 */
#define NUMCO 5 /* number of companies (don't change) */
#define INIT_CO_COST 9 /* initial company start cost */
#define FOUNDER_BONUS 5 /* founder gets this much stock */
#define NUMMOVES 6 /* number of moves options a player gets */
#define MAXPLAYERS 4 /* total number of players a game can have */
#define STARCOST 26 /* company's price increase near star */
#define BLACKHOLECOST -25 /* price increase near black hole */
#define NEWCOCOST 10 /* company's price increase near new co */
#define Mx 12 /* x dimension of map */
#define My 10 /* y dimension of map */
/* macros to look at surrounding spaces on the map: */
#define iscompany(c) ((c)>='A'&&(c)<='Z')
#define ripe(c) ((c)==STAR||(c)==NEWCO)
#define co_near(move) (iscompany(up_obj(move))||iscompany(down_obj(move))||iscompany(left_obj(move))||iscompany(right_obj(move)))
#define s_or_bh(c) ((c)==SPACE||(c)==BLACKHOLE)
/* player and company structures: */
typedef struct {
char name[100];
int holdings[NUMCO];
long int svalue; /* stock value -- not always accurate!! */
long int cash;
int ishuman;
} PLAYER;
typedef struct {
char name[100];
int price;
int size;
int potential;
int risk; /* value related to chance of being swallowed by Black Hole */
int netpot; /* potential - risk */
} COMPANY;

66
common.h.orig Normal file
View File

@ -0,0 +1,66 @@
/*
** 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 v2 for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program;
*/
#define OFFMAP '-' /* space character */
#define SPACE '.' /* space character */
#define NEWCO '+' /* new company character */
#define STAR '*' /* star character */
#define BLACKHOLE '@' /* black hole character */
#define END_PERCENT 55 /* end when this much of the map is full */
#define INIT_CASH 6000 /* initial player cash */
#define SPLIT_PRICE 3000 /* when stocks split 2-1 */
#define NUMCO 5 /* number of companies (don't change) */
#define INIT_CO_COST 100 /* initial company start cost */
#define FOUNDER_BONUS 5 /* founder gets this much stock */
#define NUMMOVES 5 /* number of moves options a player gets */
#define MAXPLAYERS 4 /* total number of players a game can have */
#define STARCOST 500 /* company's price increase near star */
#define BLACKHOLECOST -500 /* price increase near black hole */
#define NEWCOCOST 100 /* company's price increase near new co */
#define Mx 12 /* x dimension of map */
#define My 10 /* y dimension of map */
/* macros to look at surrounding spaces on the map: */
#define iscompany(c) ((c)>='A'&&(c)<='Z')
#define ripe(c) ((c)==STAR||(c)==NEWCO)
#define co_near(move) (iscompany(up_obj(move))||iscompany(down_obj(move))||iscompany(left_obj(move))||iscompany(right_obj(move)))
#define s_or_bh(c) ((c)==SPACE||(c)==BLACKHOLE)
/* player and company structures: */
typedef struct {
char name[100];
int holdings[NUMCO];
long int svalue; /* stock value -- not always accurate!! */
long int cash;
int ishuman;
} PLAYER;
typedef struct {
char name[100];
int price;
int size;
int potential;
int risk; /* value related to chance of being swallowed by Black Hole */
int netpot; /* potential - risk */
} COMPANY;

View File

@ -1,8 +1,8 @@
.TH STARLANES 6 "12 February 2020" "Starlanes V1.4.2"
.TH STARLANES 6 "29 March 1996" "Starlanes V1.2.2"
.SH NAME
starlanes \- the game of starlanes
.SH SYNOPSIS
.BR "starlanes " [ -v | c | m ]
.BR "starlanes " [ -v | c | m ]
.SH DESCRIPTION
.B Starlanes
is a game of interstellar commerce for 1 to 4 players. Players take

View File

@ -1,5 +1,5 @@
/*
** starlanes v1.4.2 (12-Feb-2020) -- a space-age stock trading game
** starlanes v1.4.0 (29-Mar-1997) -- a space-age stock trading game
**
** Copyright (C) 1997 Brian "Beej" Hall
** with modifications by David Barnsdale 2004 and by ~jan6 2020
@ -30,7 +30,7 @@
#include <unistd.h>
#include <ncurses.h>
#include <termios.h>
#include "common.h"
#include "common.h"
@ -94,14 +94,14 @@
/* misc stuff: */
#define INIT_CO_COST 100 /* initial company start cost */
#define INIT_CASH 6000 /* initial player cash */
#define SPLIT_PRICE 3000 /* when stocks split 2-1 */
//#define INIT_CO_COST 100 /* initial company start cost */
//#define INIT_CASH 6000 /* initial player cash */
//#define SPLIT_PRICE 3000 /* when stocks split 2-1 */
/* #define NUMMOVES 5 number of different moves a player gets */
//#define NUMMOVES 5 /* number of different moves a player gets */
#define END_PERCENT 54 /* end when this much of the map is full */
//#define END_PERCENT 55 /* end when this much of the map is full */
#define DEF_LINES 25 /* default number of lines on screen */
#define DEF_COLUMNS 80 /* default number of columns on screen */
@ -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.4.2";
char *VERSION_DATE = "12-February-2020";
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,7 +204,7 @@ int main(int argc, char *argv[])
else
usage();
break;
default:usage();
default: usage();
}
/* initscr */
@ -251,6 +251,7 @@ int main(int argc, char *argv[])
//ai_buy_sell(pl,co,turn,map,Difficulty);
//}
turn = (++turn)%numplayers;
fprintf(stderr,"\x07");
}
} while (!done);
@ -314,11 +315,11 @@ void initialize(void)
for(i=0;i<NUMCO;i++) {
switch(i) {
case 0: strcpy(co[i].name, "Altair Starways");break;
case 1: strcpy(co[i].name, "Beetlejuice, Ltd.");break;
case 2: strcpy(co[i].name, "Capella Freight Co.");break;
case 3: strcpy(co[i].name, "Denebola Shippers");break;
case 4: strcpy(co[i].name, "Eridani Expediters");break;
case 0: strcpy(co[i].name, "Altar & Stairway, Ltd.");break;
case 1: strcpy(co[i].name, "Beatles & Juice Co. ");break;
case 2: strcpy(co[i].name, "Capella Fright, Ltd. ");break;
case 3: strcpy(co[i].name, "Denebola Dice Shippers");break;
case 4: strcpy(co[i].name, "Eridani Expert Export ");break;
}
co[i].size = co[i].price = 0;
}
@ -327,10 +328,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 +362,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);
}
/*
@ -416,7 +416,7 @@ void get_num_players(void)
/* if (numplayers == 0){
numplayers=4;
sologame=1;
sprintf(s,"Please enter level (1 easiest,3 hardest)");
sprintf(s,"Please enter level (1 easiest,3 hardest)");
center(stdscr,COLUMNS ,11,s);
refresh();
noecho();raw();
@ -443,12 +443,12 @@ void get_num_players(void)
my_mvwgetstr(stdscr,plnmr+12+sologame,49,20,0,pl[plnmr].name);
/*getstr(pl[plnmr].name);*/
if (pl[plnmr].name[0] == '\0') plnmr--;
// }
// }
}
nonl();
}
/*
** showmap() -- draws the map in the map window
*/
@ -468,16 +468,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 +496,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);
@ -522,7 +522,7 @@ void show_coinfo(void)
werase(coinfo);
wattron(coinfo,COINFO_TITLE);
mvwprintw(coinfo,0,0," %-19s %5s %8s ","Company","Price","Holdings");
mvwprintw(coinfo,0,0," %-22s %5s %8s","Company","Price","Holdings");
wattroff(coinfo,COINFO_TITLE);
wmove(coinfo,2,0);
@ -537,10 +537,11 @@ void show_coinfo(void)
}
wattron(coinfo,attrs);
// wprintw(coinfo," %-19s ",co[i].name);
wprintw(coinfo," %-22s ",co[i].name);
wprintw(coinfo," %-22s ",co[i].name);
wattroff(coinfo,attrs);
wprintw(coinfo,"$%-4d ",co[i].price);
wprintw(coinfo,"$%-4d ",co[i].price);
/*if (pl[turn].holdings[i] == 0) wattron(coinfo,A_BLINK);*/
// wprintw(coinfo,"%-5d\n\n\r",pl[turn].holdings[i]);
wprintw(coinfo,"%-5d\n\n\r",pl[turn].holdings[i]);
/*if (pl[turn].holdings[i] == 0) wattroff(coinfo,A_BLINK);*/
gotco = 1;
@ -628,8 +629,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];
@ -778,10 +778,10 @@ void do_merge(int *c1, int *c2, int *o1, int *o2)
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,7 +803,7 @@ void calc_cost(int cnum, int move, int n, int s, int w, int e)
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++;
@ -950,7 +950,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);
@ -1026,8 +1026,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:");
@ -1071,22 +1070,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);
@ -1181,7 +1182,7 @@ int count_used_sectors(void)
for(i=maptotal=0;i<MAPX*MAPY;i++) /* must be enough room to move */
if (map[i] != SPACE)
maptotal++;
return maptotal;
}
@ -1374,7 +1375,7 @@ int order_compare(const void *v1, const void *v2)
p1 = *((int *)v1);
p2 = *((int *)v2);
nw1 = pl[p1].svalue + pl[p1].cash;
nw2 = pl[p2].svalue + pl[p2].cash;
@ -1500,10 +1501,10 @@ void show_company_holdings(char *title)
wprintw(stand,"%-5d %-5d ",pl[order[plNo]].holdings[1],pl[order[plNo]].holdings[2]);
wprintw(stand,"%-5d %-5d",pl[order[plNo]].holdings[3],pl[order[plNo]].holdings[4]);
}
center(stand,60,5+numplayers, s);
center(stand,60,7+numplayers,"Press any key to continue...");
wnoutrefresh(stand);
@ -1564,7 +1565,7 @@ void shutdown(void)
printf("Starlanes for ncurses v%s Copyright by Brian \"Beej\" Hall 1997 \n",VERSION);
printf("Update: David Barnsdale 2004\n");
printf("Update: jan6 2020\n");
}
/*

View File

@ -391,6 +391,6 @@ BUGS
Starlanes V1.4.2 12 February 2020 6
Starlanes V1.2.2 29 March 1996 6