update to version 1.4.0

- remove trailing spaces
This commit is contained in:
creme 2020-02-11 18:32:43 +01:00
parent f170a6bf9a
commit 9b40f1080d
Signed by: creme
GPG Key ID: C147C3B7FBDF08D0
7 changed files with 101 additions and 107 deletions

View File

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

9
README
View File

@ -27,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"
@ -50,4 +50,3 @@ first published in Creative Computing magazine.
-Beej
beej@ecst.csuchico.edu

130
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.
@ -28,17 +28,17 @@ 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) {
@ -60,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)
{
@ -68,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);
}
@ -82,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;
};
@ -105,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)
{
@ -119,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;
}
@ -142,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;
@ -156,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];
@ -181,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])){
@ -193,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]]*
@ -214,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';
@ -227,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
@ -240,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){
@ -251,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 */
@ -266,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);{
@ -299,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 ;
}
@ -319,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

@ -3,12 +3,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 v2 for more details.
**
**
** You should have received a copy of the GNU General Public License
** along with this program;
*/

View File

@ -1,8 +1,8 @@
.TH STARLANES 6 "29 March 1996" "Starlanes V1.2.2"
.TH STARLANES 6 "11 February 2020" "Starlanes V1.4.0"
.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,19 +1,19 @@
/*
** starlanes v1.3.0 (29-Mar-1997) -- a space-age stock trading game
** starlanes v1.4.0 (11-Feb-2020) -- a space-age stock trading game
**
** 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.
@ -30,7 +30,7 @@
#include <unistd.h>
#include <ncurses.h>
#include <termios.h>
#include "common.h"
#include "common.h"
@ -161,8 +161,8 @@ void usage(void);
char placemove(); */
/* global variables */
char *VERSION = "1.3.0";
char *VERSION_DATE = "1-June-2004";
char *VERSION = "1.4.0";
char *VERSION_DATE = "11-February-2020";
char *ident = "$Id: starlanes.c 1.2.2 29-Mar-1997 beej@ecst.csuchico.edu $";
@ -210,7 +210,7 @@ int main(int argc, char *argv[])
/* 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 ");
@ -416,9 +416,9 @@ 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();
refresh();
noecho();raw();
do {
Difficulty = getch()-'0';
@ -426,7 +426,7 @@ void get_num_players(void)
addch(Difficulty+'0');
}
else */ sologame=0;
srand(getpid()); /* reseed the dumb random number generator */
turn = rand()%numplayers;
@ -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
*/
@ -562,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);
@ -725,7 +725,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
@ -764,7 +764,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');
@ -777,7 +777,7 @@ 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 */
merge_announce(cb,cs);
@ -802,7 +802,7 @@ 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 */
map[move-MAPX] = cnum + 'A'; /*company represented by A is 0 and so on */
drawmap(move-MAPX,cnum+'A');
@ -867,7 +867,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;
@ -985,7 +985,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();
@ -1181,7 +1181,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 +1374,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 +1500,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 +1564,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.2.2 29 March 1996 6
Starlanes V1.4.0 11 February 2020 6