From: Eric S. Raymond Date: Sun, 25 Aug 2013 19:37:42 +0000 (-0400) Subject: Abstract out some map characters. X-Git-Tag: 1.11~12 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=92a74b11e6765d161accbccc9ad3ac52ed4f1d64;p=vms-empire.git Abstract out some map characters. --- diff --git a/attack.c b/attack.c index 968bcd4..e313187 100644 --- a/attack.c +++ b/attack.c @@ -114,7 +114,7 @@ attack_obj(piece_info_t *att_obj, loc_t loc) void attack(piece_info_t *att_obj, loc_t loc) { - if (map[loc].contents == '*') /* attacking a city? */ + if (map[loc].contents == MAP_CITY) /* attacking a city? */ attack_city (att_obj, loc); else attack_obj (att_obj, loc); /* attacking a piece */ } diff --git a/compmove.c b/compmove.c index 39b2780..6aa588d 100644 --- a/compmove.c +++ b/compmove.c @@ -146,7 +146,7 @@ comp_prod(city_info_t *cityp, bool is_lake) /* Make sure we have army producers for current continent. */ /* map out city's continent */ - vmap_cont (cont_map, comp_map, cityp->loc, '.'); + vmap_cont (cont_map, comp_map, cityp->loc, MAP_SEA); /* count items of interest on the continent */ counts = vmap_cont_scan (cont_map, comp_map); @@ -350,7 +350,7 @@ lake(loc_t loc) int cont_map[MAP_SIZE]; scan_counts_t counts; - vmap_cont (cont_map, emap, loc, '+'); /* map lake */ + vmap_cont (cont_map, emap, loc, MAP_LAND); /* map lake */ counts = vmap_cont_scan (cont_map, emap); return !(counts.unowned_cities || counts.user_cities || counts.unexplored); @@ -505,7 +505,7 @@ army_move(piece_info_t *obj) if (new_loc != obj->loc) { /* something to attack? */ attack (obj, new_loc); /* attack it */ - if (map[new_loc].contents == '.' /* moved to ocean? */ + if (map[new_loc].contents == MAP_SEA /* moved to ocean? */ && obj->hits > 0) { /* object still alive? */ kill_obj (obj, new_loc); scan (user_map, new_loc); /* rescan for user */ @@ -531,7 +531,7 @@ army_move(piece_info_t *obj) case 'O': cross_cost = 60; /* high cost if enemy present */ break; - case '*': + case MAP_CITY: cross_cost = 30; /* medium cost for attackable city */ break; case ' ': @@ -687,13 +687,13 @@ make_unload_map(view_map_t *xmap, view_map_t *vmap) for (i = 0; i < NUM_CITY; i++) if (city[i].owner == COMP) - vmap_mark_up_cont (owncont_map, xmap, city[i].loc, '.'); + vmap_mark_up_cont (owncont_map, xmap, city[i].loc, MAP_SEA); for (i = 0; i < MAP_SIZE; i++) if (strchr ("O*", vmap[i].contents)) { int total_cities; - vmap_cont (tcont_map, xmap, i, '.'); /* map continent */ + vmap_cont (tcont_map, xmap, i, MAP_SEA); /* map continent */ counts = vmap_cont_scan (tcont_map, xmap); total_cities = counts.unowned_cities diff --git a/display.c b/display.c index debf257..7811815 100644 --- a/display.c +++ b/display.c @@ -316,10 +316,10 @@ static void disp_square(view_map_t *vp) switch(vp->contents) { - case '+': + case MAP_LAND: attr = COLOR_PAIR(COLOR_GREEN); break; - case '.': + case MAP_SEA: attr = COLOR_PAIR(COLOR_CYAN); break; case 'a': diff --git a/empire.c b/empire.c index 7acb8ef..9238e05 100644 --- a/empire.c +++ b/empire.c @@ -167,14 +167,18 @@ do_command(char orders) case '+': /* change debug state */ e = get_chx(); - if ( e == '+' ) debug = true; - else if ( e == '-' ) debug = false; + if ( e == '+' ) + debug = true; + else if ( e == '-' ) + debug = false; else huh (); break; default: - if (debug) c_debug (orders); /* debug */ - else huh (); /* illegal command */ + if (debug) + c_debug (orders); /* debug */ + else + huh (); /* illegal command */ break; } } diff --git a/empire.h b/empire.h index 3a60468..8f028f3 100644 --- a/empire.h +++ b/empire.h @@ -199,14 +199,14 @@ You can change them and the code will adjust properly. #define NUM_CITY ((100 * (MAP_WIDTH + MAP_HEIGHT)) / 228) typedef struct real_map { /* a cell of the actual map */ - char contents; /* '+', '.', or '*' */ + char contents; /* MAP_LAND, MAP_SEA, or MAP_CITY */ bool on_board; /* TRUE iff on the board */ city_info_t *cityp; /* ptr to city at this location */ piece_info_t *objp; /* list of objects at this location */ } real_map_t; typedef struct view_map { /* a cell of one player's world view */ - char contents; /* '+', '.', '*', 'A', 'a', etc */ + char contents; /* MAP_LAND, MAP_SEA, MAP_CITY, 'A', 'a', etc */ long seen; /* date when last updated */ } view_map_t; @@ -264,4 +264,8 @@ typedef struct { enum win_t {no_win, wipeout_win, ratio_win}; +#define MAP_LAND '+' +#define MAP_SEA '.' +#define MAP_CITY '*' + /* end */ diff --git a/game.c b/game.c index f0de9d2..0a73e2a 100644 --- a/game.c +++ b/game.c @@ -71,8 +71,8 @@ void init_game(void) do { for (i = 0; i < MAP_SIZE; i ++) { /* remove cities */ - if (map[i].contents == '*') - map[i].contents = '+'; /* land */ + if (map[i].contents == MAP_CITY) + map[i].contents = MAP_LAND; /* land */ } place_cities (); /* place cities on map */ } while @@ -145,8 +145,8 @@ void make_map(void) /* mark the land and water */ for (i = 0; i < MAP_SIZE; i ++) { if (height[from][i] > loc) - map[i].contents = '+'; /* land */ - else map[i].contents = '.'; /* water */ + map[i].contents = MAP_LAND; + else map[i].contents = MAP_SEA; map[i].objp = NULL; /* nothing in cell yet */ map[i].cityp = NULL; @@ -193,7 +193,7 @@ void place_cities(void) for (i = 0; i < NUM_OBJECTS; i++) city[placed].func[i] = NOFUNC; /* no function */ - map[loc].contents = '*'; + map[loc].contents = MAP_CITY; map[loc].cityp = &(city[placed]); placed++; @@ -215,7 +215,7 @@ count_t regen_land(count_t placed) num_land = 0; for (i = 0; i < MAP_SIZE; i++) { - if (map[i].on_board && map[i].contents == '+') { + if (map[i].on_board && map[i].contents == MAP_LAND) { land[num_land] = i; /* remember piece of land */ num_land++; /* remember number of pieces */ } @@ -378,7 +378,8 @@ bool find_next(loc_t *mapi) if (*mapi >= MAP_SIZE) return (false); if (!map[*mapi].on_board || marked[*mapi] - || map[*mapi].contents == '.') *mapi += 1; + || map[*mapi].contents == MAP_SEA) + *mapi += 1; else if (good_cont (*mapi)) { rank_tab[ncont] = ncont; /* insert cont in rank tab */ val = cont_tab[ncont].value; @@ -445,13 +446,15 @@ mark_cont(loc_t mapi) { int i; - if (marked[mapi] || map[mapi].contents == '.' - || !map[mapi].on_board) return; + if (marked[mapi] + || map[mapi].contents == MAP_SEA + || !map[mapi].on_board) + return; marked[mapi] = 1; /* mark this cell seen */ nland++; /* count land on continent */ - if (map[mapi].contents == '*') { /* a city? */ + if (map[mapi].contents == MAP_CITY) { /* a city? */ cont_tab[ncont].cityp[ncity] = map[mapi].cityp; ncity++; if (rmap_shore (mapi)) nshore++; diff --git a/map.c b/map.c index dca7c81..3abc9fe 100644 --- a/map.c +++ b/map.c @@ -90,8 +90,10 @@ vmap_mark_up_cont(int *cont_map, view_map_t *vmap, loc_t loc, char bad_terrain) if (vmap[new_loc].contents == ' ') cont_map[new_loc] = 1; else { - if (vmap[new_loc].contents == '+') this_terrain = '+'; - else if (vmap[new_loc].contents == '.') this_terrain = '.'; + if (vmap[new_loc].contents == MAP_LAND) + this_terrain = MAP_LAND; + else if (vmap[new_loc].contents == MAP_SEA) + this_terrain = MAP_SEA; else this_terrain = map[new_loc].contents; if (this_terrain != bad_terrain) { /* on continent? */ @@ -186,11 +188,11 @@ vmap_cont_scan(int *cont_map, view_map_t *vmap) COUNT ('t', counts.comp_objects[TRANSPORT]); COUNT ('c', counts.comp_objects[CARRIER]); COUNT ('b', counts.comp_objects[BATTLESHIP]); - COUNT ('*', counts.unowned_cities); - case '+': break; - case '.': break; + COUNT (MAP_CITY, counts.unowned_cities); + case MAP_LAND: break; + case MAP_SEA: break; default: /* check for city underneath */ - if (map[i].contents == '*') { + if (map[i].contents == MAP_CITY) { switch (map[i].cityp->owner) { COUNT (USER, counts.user_cities); COUNT (COMP, counts.comp_cities); @@ -219,7 +221,7 @@ rmap_cont_scan(int *cont_map) for (i = 0; i < MAP_SIZE; i++) { if (cont_map[i]) { /* cell on continent? */ counts.size += 1; - if (map[i].contents == '*') + if (map[i].contents == MAP_CITY) counts.unowned_cities += 1; } } @@ -637,18 +639,19 @@ STATIC int terrain_type(path_map_t *pmap, view_map_t *vmap, move_info_t *move_info, loc_t from_loc, loc_t to_loc) { - if (vmap[to_loc].contents == '+') return T_LAND; - if (vmap[to_loc].contents == '.') return T_WATER; + if (vmap[to_loc].contents == MAP_LAND) return T_LAND; + if (vmap[to_loc].contents == MAP_SEA) return T_WATER; if (vmap[to_loc].contents == '%') return T_UNKNOWN; /* magic objective */ if (vmap[to_loc].contents == ' ') return pmap[from_loc].terrain; switch (map[to_loc].contents) { - case '.': return T_WATER; - case '+': return T_LAND; - case '*': + case MAP_SEA: return T_WATER; + case MAP_LAND: return T_LAND; + case MAP_CITY: if (map[to_loc].cityp->owner == move_info->city_owner) return T_WATER; - else return T_UNKNOWN; /* cannot cross */ + else + return T_UNKNOWN; /* cannot cross */ } ABORT; /*NOTREACHED*/ @@ -709,7 +712,7 @@ vmap_prune_explore_locs(view_map_t *vmap) FOR_ADJ (loc, new_loc, i) { if (new_loc < 0 || new_loc >= MAP_SIZE); /* ignore off map */ else if (vmap[new_loc].contents == ' '); /* ignore adjacent unexplored */ - else if (map[new_loc].contents != '.') + else if (map[new_loc].contents != MAP_SEA) pmap[loc].cost += 1; /* count land */ else pmap[loc].inc_cost += 1; /* count water */ } @@ -825,8 +828,10 @@ expand_prune(view_map_t *vmap, path_map_t *pmap, *explored += 1; - if (type == T_LAND) vmap[loc].contents = '+'; - else vmap[loc].contents = '.'; + if (type == T_LAND) + vmap[loc].contents = MAP_LAND; + else + vmap[loc].contents = MAP_SEA; FOR_ADJ (loc, new_loc, i) if (new_loc >= 0 && new_loc < MAP_SIZE && vmap[new_loc].contents == ' ') { @@ -1090,7 +1095,8 @@ rmap_shore(loc_t loc) loc_t i, j; FOR_ADJ_ON (loc, j, i) - if (map[j].contents == '.') return (true); + if (map[j].contents == MAP_SEA) + return (true); return (false); } @@ -1101,7 +1107,9 @@ vmap_shore(view_map_t *vmap, loc_t loc) loc_t i, j; FOR_ADJ_ON (loc, j, i) - if (vmap[j].contents != ' ' && vmap[j].contents != '+' && map[j].contents == '.') + if (vmap[j].contents != ' ' && + vmap[j].contents != MAP_LAND && + map[j].contents == MAP_SEA) return (true); return (false); @@ -1117,9 +1125,12 @@ vmap_at_sea(view_map_t *vmap, loc_t loc) { loc_t i, j; - if (map[loc].contents != '.') return (false); + if (map[loc].contents != MAP_SEA) + return (false); FOR_ADJ_ON (loc, j, i) - if (vmap[j].contents == ' ' || vmap[j].contents == '+' || map[j].contents != '.') + if (vmap[j].contents == ' ' + || vmap[j].contents == MAP_LAND + || map[j].contents != MAP_SEA) return (false); return (true); @@ -1130,9 +1141,11 @@ rmap_at_sea (loc_t loc) { loc_t i, j; - if (map[loc].contents != '.') return (false); + if (map[loc].contents != MAP_SEA) + return (false); FOR_ADJ_ON (loc, j, i) { - if (map[j].contents != '.') return (false); + if (map[j].contents != MAP_SEA) + return (false); } return (true); } diff --git a/object.c b/object.c index 0283c44..5a88e5a 100644 --- a/object.c +++ b/object.c @@ -555,7 +555,7 @@ contents starting with armies, then fighters, then boats, and the city type. */ -char city_char[] = {'*', 'O', 'X'}; +char city_char[] = {MAP_CITY, 'O', 'X'}; void update(view_map_t vmap[], loc_t loc) diff --git a/usermove.c b/usermove.c index 7189bb1..7ac54eb 100644 --- a/usermove.c +++ b/usermove.c @@ -853,7 +853,7 @@ user_dir_army(piece_info_t *obj, loc_t loc) "Sorry, sir. There is no more room on the transport. Do you insist? ", "Your army jumped into the briny and drowned."); - else if (map[loc].contents == '.') { /* going for a swim? */ + else if (map[loc].contents == MAP_SEA) { /* going for a swim? */ bool enemy_killed = false; if (!getyn ( /* thanks to Craig Hansen for this next message */ @@ -865,7 +865,7 @@ user_dir_army(piece_info_t *obj, loc_t loc) comment ("Your army jumped into the briny and drowned."); ksend ("Your army jumped into the briny and drowned.\n"); } - else if (user_map[loc].contents == '.') + else if (user_map[loc].contents == MAP_SEA) { comment ("Your army marched dutifully into the sea and drowned."); ksend ("Your army marched dutifully into the sea and drowned.\n"); @@ -907,7 +907,7 @@ three cases: attacking a city, attacking ourself, attacking the enemy. void user_dir_fighter(piece_info_t *obj, loc_t loc) { - if (map[loc].contents == '*') + if (map[loc].contents == MAP_CITY) fatal (obj, loc, "That's never worked before, sir. Do you really want to try? ", "Your fighter was shot down."); @@ -932,7 +932,7 @@ a city, attacking self, attacking enemy. void user_dir_ship(piece_info_t *obj, loc_t loc) { - if (map[loc].contents == '*') { + if (map[loc].contents == MAP_CITY) { (void) sprintf (jnkbuf, "Your %s broke up on shore.", piece_attr[obj->type].name); @@ -941,12 +941,12 @@ user_dir_ship(piece_info_t *obj, loc_t loc) jnkbuf); } - else if (map[loc].contents == '+') { /* moving ashore? */ + else if (map[loc].contents == MAP_LAND) { /* moving ashore? */ bool enemy_killed = false; if (!getyn ("Ships need sea to float, sir. Do you really want to go ashore? ")) return; - if (user_map[loc].contents == '+') + if (user_map[loc].contents == MAP_LAND) { comment ("Your %s broke up on shore.", piece_attr[obj->type].name); ksend ("Your %s broke up on shore.", piece_attr[obj->type].name); @@ -1056,7 +1056,7 @@ awake(piece_info_t *obj) for (i = 0; i < 8; i++) { /* for each surrounding cell */ c = user_map[obj->loc+dir_offset[i]].contents; - if (islower (c) || c == '*' || c == 'X') { + if (islower (c) || c == MAP_CITY || c == 'X') { if (obj->func < 0) obj->func = NOFUNC; /* awaken */ return (true); }