From 681a6cd172520341cfab756f8e6f9779f0373051 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 19 Apr 2002 09:17:02 +0000 Subject: [PATCH] Walt Stoneburner's cleanup patch. --- Makefile | 7 ++++--- README | 8 ++++++-- compmove.c | 16 ++++++++++------ display.c | 9 +++++---- edit.c | 9 +++++---- empire.h | 16 ++++++++++------ extern.h | 4 +++- game.c | 8 +++++++- main.c | 6 ++++-- map.c | 14 ++++++++++---- math.c | 1 + usermove.c | 2 ++ 12 files changed, 67 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index cbd2773..86e1b69 100644 --- a/Makefile +++ b/Makefile @@ -13,13 +13,14 @@ VERS=1.2 # Change the line below for your system. If you are on a Sun or Vax, # you may want BSD. +SYS = LINUX #SYS = BSD -SYS = SYSV +#SYS = SYSV # Use -g to compile the program for debugging. -DEBUG = -g -DDEBUG -#DEBUG = -O +#DEBUG = -g -DDEBUG -Wall +DEBUG = -O2 # Use -p to profile the program. #PROFILE = -p -DPROFILE diff --git a/README b/README index 6c82544..76d7b32 100644 --- a/README +++ b/README @@ -7,15 +7,19 @@ * and warranty information. */ -C Empire Sources +C Empire Sources (now called vms-empire). Here's my change-log. +1.3: Fri Apr 19 05:13:33 EDT 2002 + Walt Stoneburner's clenup patch addressing all compiler errors and + warnings, both in debug and in production mode; works with GCC v3.0.3. + 1.2: Fri Jul 28 01:10:00 EDT 2000 The victory-odds table in previous versions was seriously buggy. I folded in corrections from Michael Self. I also took changes from James T. Jordan , who wrote some - speedups, added ANSI prototypes, and cleaned + speedups, added ANSI prototypes, and cleaned up code. 1.1: I colorized and speed-tuned this and added a save-interval option. diff --git a/compmove.c b/compmove.c index 21e40e7..e4ebd89 100644 --- a/compmove.c +++ b/compmove.c @@ -30,6 +30,10 @@ For each move the user wants us to make, we do the following: static view_map_t emap[MAP_SIZE]; /* pruned explore map */ int load_army(piece_info_t *obj); +int lake( long loc ); +int overproduced( city_info_t *cityp, int *city_count ); +int nearby_load( piece_info_t *obj, long loc ); +int nearby_count( long loc ); void move_objective(piece_info_t *obj,path_map_t pathmap[],long new_loc,char *adj_list); void @@ -96,7 +100,7 @@ do_cities () { for (i = 0; i < NUM_CITY; i++) /* produce and change */ if (city[i].owner == COMP) { is_lake = lake (city[i].loc); - if (city[i].work++ >= (long)piece_attr[city[i].prod].build_time) { + if (city[i].work++ >= (long)piece_attr[(int)city[i].prod].build_time) { produce (&city[i]); comp_prod (&city[i], is_lake); } @@ -197,7 +201,7 @@ int is_lake; for (i = 0; i < NUM_CITY; i++) if (city[i].owner == COMP && city[i].prod != NOPIECE) { - city_count[city[i].prod] += 1; + city_count[(int)city[i].prod] += 1; total_cities += 1; } if (total_cities <= 10) ratio = ratio1; @@ -253,9 +257,9 @@ int is_lake; interest = (counts.comp_cities != 1 || interest); if (cityp->prod == NOPIECE - || cityp->prod == ARMY && counts.comp_cities == 1 + || (cityp->prod == ARMY && counts.comp_cities == 1) || overproduced (cityp, city_count) - || cityp->prod > FIGHTER && is_lake) + || (cityp->prod > FIGHTER && is_lake) ) comp_set_needed (cityp, city_count, interest, is_lake); } @@ -290,8 +294,8 @@ int *city_count; for (i = 0; i < NUM_OBJECTS; i++) { /* return true if changing production would improve balance */ if (i != cityp->prod - && ((city_count[cityp->prod] - 1) * ratio[i] - > (city_count[i] + 1) * ratio[cityp->prod])) + && ((city_count[(int)cityp->prod] - 1) * ratio[i] + > (city_count[i] + 1) * ratio[(int)cityp->prod])) return (TRUE); } return (FALSE); diff --git a/display.c b/display.c index bf99a28..59e4907 100644 --- a/display.c +++ b/display.c @@ -1,4 +1,4 @@ -/* $Id: display.c,v 1.6 1994/12/01 15:54:31 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ +/* $Id: display.c,v 1.7 2000/07/28 05:12:50 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ /* * Copyright (C) 1987, 1988 Chuck Simmons @@ -36,7 +36,8 @@ static int save_cursor; /* currently displayed cursor position */ static int change_ok = TRUE; /* true if new sector may be displayed */ static void show_loc(view_map_t vmap[],long loc); -static disp_square(view_map_t *vp); +static void disp_square(view_map_t *vp); +int on_screen(long loc); #ifdef A_COLOR void init_colors() @@ -232,7 +233,7 @@ int sector; /* sector to display */ else pos_str (r-ref_row+NUMTOPS, cols-NUMSIDES+1, " ",0,0,0,0,0,0,0,0); } /* print round number */ - (void) sprintf (jnkbuf, "Sector %d Round %d", sector, date); + (void) sprintf (jnkbuf, "Sector %d Round %ld", sector, date); for (r = 0; jnkbuf[r] != '\0'; r++) { if (r+NUMTOPS >= MAP_HEIGHT) break; (void) move (r+NUMTOPS, cols-NUMSIDES+4); @@ -249,7 +250,7 @@ pretty. */ -static int disp_square(vp) +static void disp_square(vp) view_map_t *vp; { #ifdef A_COLOR diff --git a/edit.c b/edit.c index e532e52..30d141b 100644 --- a/edit.c +++ b/edit.c @@ -23,6 +23,7 @@ edit.c -- Routines to handle edit mode commands. #include "extern.h" void e_move(long *path_start, long loc); +extern int get_piece_name(); void edit(edit_cursor) @@ -600,7 +601,7 @@ long edit_cursor; (void) sprintf (temp_buf, "%c:%s; ", piece_attr[s].sname, func_name[FUNCI(cityp->func[s])]); - else (void) sprintf (temp_buf, "%c: %d;", + else (void) sprintf (temp_buf, "%c: %ld;", piece_attr[s].sname, cityp->func[s]); @@ -608,10 +609,10 @@ long edit_cursor; } (void) sprintf (junk_buf2, - "City at location %d will complete %s on round %d", + "City at location %ld will complete %s on round %ld", cityp->loc, - piece_attr[cityp->prod].article, - date + piece_attr[cityp->prod].build_time - cityp->work); + piece_attr[(int)cityp->prod].article, + date + piece_attr[(int)cityp->prod].build_time - cityp->work); info (junk_buf2, jnkbuf, func_buf); } diff --git a/empire.h b/empire.h index adc0691..38c49e9 100644 --- a/empire.h +++ b/empire.h @@ -21,19 +21,23 @@ empire.h -- type and constant declarations #endif /* Redefine some functions for portability. */ - -#ifndef SYSV +#ifdef LINUX +#include +#elif SYSV +char *memset(); +char *memcpy(); +#define bzero(dst,len) memset(dst,0,len) +#else #define memcpy(dst,src,len) bcopy((src),(dst),(len)) #define strchr(s,c) index(s,c) typedef char chtype; #define beep() (putchar('\7')) #define napms(d) (usleep((d)*1000)) -#else -char *memset(); -char *memcpy(); -#define bzero(dst,len) memset(dst,0,len) #endif + + + typedef unsigned char uchar; #define ASSERT(x) if (!(x)) assert ("x", __FILE__, __LINE__); diff --git a/extern.h b/extern.h index f41786a..c14019a 100644 --- a/extern.h +++ b/extern.h @@ -1,4 +1,4 @@ -/* $Id: extern.h,v 1.3 1994/12/01 15:54:36 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ +/* $Id: extern.h,v 1.4 2000/07/28 05:12:52 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ /* * Copyright (C) 1987, 1988 Chuck Simmons @@ -239,4 +239,6 @@ long time(); void exit(); void perror(); void srand(); +#ifndef LINUX char *strcpy(); +#endif diff --git a/game.c b/game.c index a5e20db..a42f0f3 100644 --- a/game.c +++ b/game.c @@ -23,6 +23,12 @@ game.c -- Routines to initialize, save, and restore a game. #include "extern.h" long remove_land(long loc, long num_land); +int select_cities(); +int find_next(long *mapi); +int good_cont(long mapi); +int xread(FILE *f, char *buf, int size); +int xwrite(FILE *f, char *buf, int size); +void stat_display( char *mbuf, int round); /* Initialize a new game. Here we generate a new random map, put cities @@ -794,7 +800,7 @@ The "xxxxx" field is the cumulative cost of building the hardware. /* in declared order, with city first */ static char *pieces = "OAFPDSTCBZXafpdstcbz"; -stat_display (mbuf, round) +void stat_display (mbuf, round) char *mbuf; int round; { diff --git a/main.c b/main.c index 1a49384..9b600e8 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.2 1990/03/29 23:22:23 eric Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ +/* $Id: main.c,v 1.3 1994/12/01 15:54:38 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ /* * Copyright (C) 1987, 1988 Chuck Simmons @@ -26,12 +26,14 @@ options: */ #include +#include +#include #include "empire.h" #include "extern.h" #define OPTFLAGS "w:s:d:S:" -main (argc, argv) +int main (argc, argv) int argc; char *argv[]; { diff --git a/map.c b/map.c index 4f7d7a6..854c073 100644 --- a/map.c +++ b/map.c @@ -1,4 +1,4 @@ -/* $Id: map.c,v 1.3 1994/12/01 15:54:39 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ +/* $Id: map.c,v 1.4 2000/07/28 05:12:53 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ /* * Copyright (C) 1987, 1988 Chuck Simmons @@ -427,7 +427,8 @@ int beat_cost; print_pzoom ("After lwobj loop:", path_map, vmap); cur_cost += 2; - if (cur_water->len == 0 && new_land->len == 0 || best_cost <= cur_cost) { + if ( (cur_water->len == 0 && new_land->len == 0) || + (best_cost <= cur_cost) ) { return best_loc; } @@ -435,6 +436,7 @@ int beat_cost; } } +#ifdef FUNCTION_WAS_NEVER_CALLED /* Return the cost to reach the adjacent cell of the correct type with the lowest cost. @@ -458,6 +460,7 @@ int type; return best; } +#endif /* Find an objective moving from water to land. @@ -511,7 +514,8 @@ move_info_t *move_info; print_pzoom ("After wlobj loop:", path_map, vmap); cur_cost += 2; - if (cur_water->len == 0 && new_land->len == 0 || best_cost <= cur_cost) { + if ( (cur_water->len == 0 && new_land->len == 0) || + (best_cost <= cur_cost) ) { return best_loc; } SWAP (cur_land, new_land); @@ -681,6 +685,7 @@ int base_cost; default: ABORT; /* NOTREACHED */ + return -1; } } @@ -711,6 +716,7 @@ long to_loc; } ABORT; /*NOTREACHED*/ + return -1; } /* @@ -1096,7 +1102,7 @@ char *adj_char; /* remember best location */ if (count > bestcount - || count == bestcount && path_count > bestpath) { + || (count == bestcount && path_count > bestpath) ) { bestcount = count; bestpath = path_count; bestloc = new_loc; diff --git a/math.c b/math.c index 9ec635c..5ae5c0e 100644 --- a/math.c +++ b/math.c @@ -22,6 +22,7 @@ Other routines include: dist (a, b) -- returns the straight-line distance between two locations. */ +#include #include "empire.h" #include "extern.h" diff --git a/usermove.c b/usermove.c index ef802cb..27f0426 100644 --- a/usermove.c +++ b/usermove.c @@ -19,6 +19,8 @@ usermove.c -- Let the user move her troops. void fatal(piece_info_t *obj,long loc,char *message,char *response); void move_to_dest(piece_info_t *obj,long dest); void move_army_to_city(piece_info_t *obj,long city_loc); +int awake(piece_info_t *obj); +extern int get_piece_name(); void user_move () { -- 2.43.0