From dc9be872e90303e776c5cb318437a4db79019ebc Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 25 Jul 2006 15:19:49 +0000 Subject: [PATCH] Joe Well's patch for variable-sized worlds. --- compmove.c | 10 +++++----- edit.c | 4 ++-- empire.h | 8 +++++++- extern.h | 3 ++- game.c | 5 ++--- map.c | 4 +++- term.c | 23 ++++++++++++++++++++++- usermove.c | 6 +++--- 8 files changed, 46 insertions(+), 17 deletions(-) diff --git a/compmove.c b/compmove.c index e4ebd89..462e46b 100644 --- a/compmove.c +++ b/compmove.c @@ -275,7 +275,7 @@ int type; { if (cityp->prod == type) return; - pdebug ("Changing city prod at %d from %d to %d\n",cityp->loc, cityp->prod, type,0,0,0,0,0); + pdebug ("Changing city prod at %d from %d to %d\n",loc_disp(cityp->loc), cityp->prod, type,0,0,0,0,0); cityp->prod = type; cityp->work = -(piece_attr[type].build_time / 5); } @@ -437,8 +437,8 @@ piece_info_t *obj; if (comp_map[obj->loc].contents == 'X') obj->moved = piece_attr[FIGHTER].speed; else if (obj->range == 0) { - pdebug ("Fighter at %d crashed and burned\n", obj->loc,0,0,0,0,0,0,0); - ksend ("Fighter at %d crashed and burned\n", obj->loc,0,0,0,0,0,0,0); + pdebug ("Fighter at %d crashed and burned\n", loc_disp(obj->loc),0,0,0,0,0,0,0); + ksend ("Fighter at %d crashed and burned\n", loc_disp(obj->loc),0,0,0,0,0,0,0); kill_obj (obj, obj->loc); /* crash & burn */ } } @@ -1031,7 +1031,7 @@ char *adj_list; if (new_loc == obj->loc) { obj->moved = piece_attr[obj->type].speed; obj->range -= 1; - pdebug ("No destination found for %d at %d; func=%d\n", obj->type, obj->loc, obj->func,0,0,0,0,0); + pdebug ("No destination found for %d at %d; func=%d\n", obj->type, loc_disp(obj->loc), obj->func,0,0,0,0,0); return; } old_loc = obj->loc; /* remember where we are */ @@ -1074,7 +1074,7 @@ char *adj_list; obj->moved = piece_attr[obj->type].speed; if (obj->type == ARMY && obj->ship) ; - else pdebug ("Cannot move %d at %d toward objective; func=%d\n", obj->type, obj->loc, obj->func,0,0,0,0,0); + else pdebug ("Cannot move %d at %d toward objective; func=%d\n", obj->type, loc_disp(obj->loc), obj->func,0,0,0,0,0); } else move_obj (obj, new_loc); diff --git a/edit.c b/edit.c index 30d141b..093a5de 100644 --- a/edit.c +++ b/edit.c @@ -603,14 +603,14 @@ long edit_cursor; func_name[FUNCI(cityp->func[s])]); else (void) sprintf (temp_buf, "%c: %ld;", piece_attr[s].sname, - cityp->func[s]); + loc_disp(cityp->func[s])); (void) strcat (func_buf, temp_buf); } (void) sprintf (junk_buf2, "City at location %ld will complete %s on round %ld", - cityp->loc, + loc_disp(cityp->loc), piece_attr[(int)cityp->prod].article, date + piece_attr[(int)cityp->prod].build_time - cityp->work); diff --git a/empire.h b/empire.h index 38c49e9..b7007fa 100644 --- a/empire.h +++ b/empire.h @@ -59,7 +59,6 @@ typedef unsigned char uchar; /* Information we maintain about cities. */ -#define NUM_CITY 70 #define UNOWNED 0 #define USER 1 #define COMP 2 @@ -205,12 +204,19 @@ it tells whether or not a square is on the board. 'user_map' describes the user's view of the world. 'comp_map' describes the computer's view of the world. + +As of the 1.7 version, MAP_WIDTH and MAP_HEIGHT are now free paramaters. +You can change them and the code will adjust properly. */ #define MAP_WIDTH 100 #define MAP_HEIGHT 60 #define MAP_SIZE (MAP_WIDTH * MAP_HEIGHT) +/* #define NUM_CITY 70 */ +/* #define NUM_CITY (MAP_SIZE / 85) */ +#define NUM_CITY ((100 * (MAP_WIDTH + MAP_HEIGHT)) / 228) + typedef struct real_map { /* a cell of the actual map */ char contents; /* '+', '.', or '*' */ uchar on_board; /* TRUE iff on the board */ diff --git a/extern.h b/extern.h index c72db74..bac6b74 100644 --- a/extern.h +++ b/extern.h @@ -1,4 +1,4 @@ -/* $Id: extern.h,v 1.5 2002/04/19 09:17:01 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ +/* $Id: extern.h,v 1.6 2002/08/01 18:58:21 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ /* * Copyright (C) 1987, 1988 Chuck Simmons @@ -234,6 +234,7 @@ void ver (); char upper (char c); void tupper (char *str); void check (); +int loc_disp (int loc); /* randon routines we use */ long time(); diff --git a/game.c b/game.c index 1ffbc80..db36375 100644 --- a/game.c +++ b/game.c @@ -329,7 +329,7 @@ int select_cities () { userp = cont_tab[user_cont].cityp[useri]; } while (userp == compp); - addprintf ("Your city is at %d.", userp->loc,0,0,0,0,0,0,0); + addprintf ("Your city is at %d.", loc_disp(userp->loc),0,0,0,0,0,0,0); delay (); /* let user see output before we set_prod */ /* update city and map */ @@ -403,12 +403,11 @@ continent and return true. Otherwise we return false. */ static long ncity, nland, nshore; +static void mark_cont(); int good_cont (mapi) long mapi; { - static void mark_cont(); - long val; ncity = 0; /* nothing seen yet */ diff --git a/map.c b/map.c index 854c073..886241f 100644 --- a/map.c +++ b/map.c @@ -1,4 +1,4 @@ -/* $Id: map.c,v 1.4 2000/07/28 05:12:53 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ +/* $Id: map.c,v 1.5 2002/04/19 09:17:01 esr Exp esr $ - (c) Copyright 1987, 1988 Chuck Simmons */ /* * Copyright (C) 1987, 1988 Chuck Simmons @@ -1205,6 +1205,7 @@ long loc; { long i, j; + if (map[loc].contents != '.') return (FALSE); FOR_ADJ_ON (loc, j, i) if (vmap[j].contents == ' ' || vmap[j].contents == '+' || map[j].contents != '.') return (FALSE); @@ -1218,6 +1219,7 @@ long loc; { long i, j; + if (map[loc].contents != '.') return (FALSE); FOR_ADJ_ON (loc, j, i) { if (map[j].contents != '.') return (FALSE); } diff --git a/term.c b/term.c index a8c17eb..7c380be 100644 --- a/term.c +++ b/term.c @@ -454,5 +454,26 @@ int nlines; (void) refresh (); } +#define COL_DIGITS ((MAP_WIDTH <= 100) ? 2 : ((MAP_WIDTH <= 1000 ? 3 : (1 / 0)))) - +int +loc_disp (int loc) +{ + int row = loc / MAP_WIDTH; + int nrow = row; + int col = loc % MAP_WIDTH; + ASSERT (loc == (row * MAP_WIDTH) + col); + int i; + for (i = COL_DIGITS; i > 0; i--) { + nrow *= 10; } + move (LINES - 1, 0); + /* + { + char junkbuf[STRSIZE]; + (void) snprintf (junkbuf, STRSIZE, "loc: %d, row: %d, col: %d, nrow: %d, nrow+col: %d", loc, row, col, nrow, nrow + col); + (void) addstr (junkbuf); + napms(500); + } + */ + return nrow + col; +} diff --git a/usermove.c b/usermove.c index 27f0426..7b3edac 100644 --- a/usermove.c +++ b/usermove.c @@ -54,9 +54,9 @@ user_move () { } else if (city[i].work++ >= (long)piece_attr[prod].build_time) { /* kermyt begin */ - ksend1("%s has been completed at city %d.\n", piece_attr[prod].article,city[i].loc,0,0,0,0,0,0); + ksend1("%s has been completed at city %d.\n", piece_attr[prod].article,loc_disp(city[i].loc),0,0,0,0,0,0); /* kermyt end */ - comment1 ("%s has been completed at city %d.\n", piece_attr[prod].article,city[i].loc,0,0,0,0,0,0); + comment1 ("%s has been completed at city %d.\n", piece_attr[prod].article,loc_disp(city[i].loc),0,0,0,0,0,0); produce (&city[i]); /* produce should set object.moved to 0 */ @@ -183,7 +183,7 @@ piece_info_t *obj; comment ("Landing confirmed.",0,0,0,0,0,0,0,0); } else if (obj->range == 0) { - comment ("Fighter at %d crashed and burned.",obj->loc,0,0,0,0,0,0,0); + comment ("Fighter at %d crashed and burned.",loc_disp(obj->loc),0,0,0,0,0,0,0); kill_obj (obj, obj->loc); } } -- 2.43.0