From 5fe3417c5057ec6b53da92ef50fbef5fc12f4679 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 22 Aug 2013 14:46:41 -0400 Subject: [PATCH] More type cleanliness; introducing count_t. --- attack.c | 10 +-- compmove.c | 76 ++++++++++----------- display.c | 20 +++--- edit.c | 52 +++++++------- empire.c | 2 +- empire.h | 8 ++- game.c | 58 ++++++++-------- map.c | 196 ++++++++++++++++++++++++++--------------------------- math.c | 2 +- object.c | 45 ++++++------ usermove.c | 43 ++++++------ 11 files changed, 261 insertions(+), 251 deletions(-) diff --git a/attack.c b/attack.c index 440295b..7ffa41e 100644 --- a/attack.c +++ b/attack.c @@ -29,7 +29,7 @@ if any. void attack_city (att_obj, loc) piece_info_t *att_obj; -long loc; +loc_t loc; { city_info_t *cityp; int att_owner, city_owner; @@ -81,7 +81,7 @@ First we have to figure out what is being attacked. void attack_obj (att_obj, loc) piece_info_t *att_obj; -long loc; +loc_t loc; { void describe(), survive(); @@ -118,7 +118,7 @@ long loc; void attack (att_obj, loc) piece_info_t *att_obj; -long loc; +loc_t loc; { if (map[loc].contents == '*') /* attacking a city? */ attack_city (att_obj, loc); @@ -135,7 +135,7 @@ location. void survive (obj, loc) piece_info_t *obj; -long loc; +loc_t loc; { while (obj_capacity (obj) < obj->count) kill_obj (obj->cargo, loc); @@ -146,7 +146,7 @@ long loc; void describe (win_obj, lose_obj, loc) piece_info_t *win_obj, *lose_obj; -long loc; +loc_t loc; { char buf[STRSIZE]; char buf2[STRSIZE]; diff --git a/compmove.c b/compmove.c index 79de535..1a9b627 100644 --- a/compmove.c +++ b/compmove.c @@ -23,11 +23,11 @@ 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 lake( loc_t 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); +int nearby_load( piece_info_t *obj, loc_t loc ); +int nearby_count( loc_t loc ); +void move_objective(piece_info_t *obj,path_map_t pathmap[],loc_t new_loc,char *adj_list); void comp_move (nmoves) @@ -140,7 +140,7 @@ int is_lake; int city_count[NUM_OBJECTS]; /* # of cities producing each piece */ int cont_map[MAP_SIZE]; int total_cities; - long i; + count_t i; int comp_ac; city_info_t *p; int need_count, interest; @@ -156,12 +156,12 @@ int is_lake; comp_ac = 0; /* no army producing computer cities */ for (i = 0; i < MAP_SIZE; i++) - if (cont_map[i]) { /* for each cell of continent */ - if (comp_map[i].contents == 'X') { - p = find_city (i); - ASSERT (p != NULL && p->owner == COMP); - if (p->prod == ARMY) comp_ac += 1; - } + if (cont_map[i]) { /* for each cell of continent */ + if (comp_map[i].contents == 'X') { + p = find_city (i); + ASSERT (p != NULL && p->owner == COMP); + if (p->prod == ARMY) comp_ac += 1; + } } /* see if anything of interest is on continent */ interest = (counts.unexplored || counts.user_cities @@ -356,7 +356,7 @@ have unexplored territory on the edges. int lake (loc) -long loc; +loc_t loc; { int cont_map[MAP_SIZE]; scan_counts_t counts; @@ -404,7 +404,7 @@ piece_info_t *obj; int changed_loc; int max_hits; - long saved_loc; + loc_t saved_loc; city_info_t *cityp; if (obj->type == SATELLITE) { @@ -496,14 +496,14 @@ void army_move (obj) piece_info_t *obj; { - long move_away(); - long find_attack(); + loc_t move_away(); + loc_t find_attack(); void make_army_load_map(), make_unload_map(), make_tt_load_map(); void board_ship(); - long new_loc; + loc_t new_loc; path_map_t path_map2[MAP_SIZE]; - long new_loc2; + loc_t new_loc2; int cross_cost; /* cost to enter water */ obj->func = 0; /* army doesn't want a tt */ @@ -580,11 +580,11 @@ void unmark_explore_locs (xmap) view_map_t *xmap; { - long i; + count_t i; for (i = 0; i < MAP_SIZE; i++) - if (map[i].on_board && xmap[i].contents == ' ') - xmap[i].contents = emap[i].contents; + if (map[i].on_board && xmap[i].contents == ' ') + xmap[i].contents = emap[i].contents; } /* @@ -624,7 +624,7 @@ view_map_t *vmap; int nearby_load (obj, loc) piece_info_t *obj; -long loc; +loc_t loc; { return obj->func == 1 && dist (obj->loc, loc) <= 2; } @@ -633,7 +633,7 @@ long loc; int nearby_count (loc) -long loc; +loc_t loc; { piece_info_t *obj; int count; @@ -699,7 +699,7 @@ make_unload_map (xmap, vmap) view_map_t *xmap; view_map_t *vmap; { - long i; + count_t i; scan_counts_t counts; (void) memcpy (xmap, vmap, sizeof (view_map_t) * MAP_SIZE); @@ -750,7 +750,7 @@ void board_ship (obj, pmap, dest) piece_info_t *obj; path_map_t *pmap; -long dest; +loc_t dest; { if (!load_army (obj)) { obj->func = 1; /* loading */ @@ -767,7 +767,7 @@ one of the ships to become more full. piece_info_t * find_best_tt (best, loc) piece_info_t *best; -long loc; +loc_t loc; { piece_info_t *p; @@ -789,7 +789,7 @@ piece_info_t *obj; { piece_info_t *p; int i; - long x_loc; + loc_t x_loc; p = find_best_tt (obj->ship, obj->loc); /* look here first */ @@ -818,13 +818,13 @@ Return the first location we find adjacent to the current location of the correct terrain. */ -long +loc_t move_away (vmap, loc, terrain) view_map_t *vmap; -long loc; +loc_t loc; char *terrain; { - long new_loc; + loc_t new_loc; int i; for (i = 0; i < 8; i++) { @@ -844,13 +844,13 @@ If there is an object we can attack, we return the location of the best of these. */ -long +loc_t find_attack (loc, obj_list, terrain) -long loc; +loc_t loc; char *obj_list; char *terrain; { - long new_loc, best_loc; + loc_t new_loc, best_loc; int i, best_val; char *p; @@ -889,7 +889,7 @@ piece_info_t *obj; { void tt_do_move(); - long new_loc; + loc_t new_loc; /* empty transports can attack */ if (obj->count == 0) { /* empty? */ @@ -940,7 +940,7 @@ void fighter_move (obj) piece_info_t *obj; { - long new_loc; + loc_t new_loc; new_loc = find_attack (obj->loc, fighter_attack, ".+"); if (new_loc != obj->loc) { /* something to attack? */ @@ -973,7 +973,7 @@ void ship_move (obj) piece_info_t *obj; { - long new_loc; + loc_t new_loc; char *adj_list; if (obj->hits < piece_attr[obj->type].max_hits) { /* head to port */ @@ -1011,15 +1011,15 @@ void move_objective (obj, pathmap, new_loc, adj_list) piece_info_t *obj; path_map_t pathmap[]; -long new_loc; +loc_t new_loc; char *adj_list; { char *terrain; char *attack_list; int d; int reuse; /* true iff we should reuse old map */ - long old_loc; - long old_dest; + loc_t old_loc; + loc_t old_dest; if (new_loc == obj->loc) { obj->moved = piece_attr[obj->type].speed; diff --git a/display.c b/display.c index ab34b9f..78c36a0 100644 --- a/display.c +++ b/display.c @@ -28,9 +28,9 @@ static int save_sector; /* the currently displayed sector */ 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 void show_loc(view_map_t vmap[],loc_t loc); static void disp_square(view_map_t *vp); -int on_screen(long loc); +int on_screen(loc_t loc); #ifdef A_COLOR void init_colors(void) @@ -149,7 +149,7 @@ Return the current position of the cursor. If the user's map is not on the screen, we return -1. */ -long cur_cursor (void) { +loc_t cur_cursor (void) { if (whose_map != USER) return (-1); return (save_cursor); } @@ -167,7 +167,7 @@ void display_loc (whose, vmap, loc) int whose; /* whose map to display */ view_map_t vmap[]; -long loc; /* location to display */ +loc_t loc; /* location to display */ { if (change_ok || whose != whose_map || !on_screen (loc)) print_sector (whose, vmap, loc_sector (loc)); @@ -183,7 +183,7 @@ void display_locx (whose, vmap, loc) int whose; /* whose map to display */ view_map_t vmap[]; -long loc; /* location to display */ +loc_t loc; /* location to display */ { if (whose == whose_map && on_screen (loc)) show_loc (vmap, loc); @@ -196,7 +196,7 @@ Display a location which exists on the screen. void show_loc (vmap, loc) view_map_t vmap[]; -long loc; +loc_t loc; { int r, c; @@ -358,7 +358,7 @@ view_map_t vmap[]; { int display_rows, display_cols; int r, c; - long t; + loc_t t; display_rows = lines - NUMTOPS - 1; /* num lines to display */ display_cols = cols - NUMSIDES; @@ -379,10 +379,10 @@ We display the cursor on the screen, if possible. int move_cursor (cursor, offset) -long *cursor; /* current cursor position */ +loc_t *cursor; /* current cursor position */ int offset; /* offset to add to cursor */ { - long t; + loc_t t; int r, c; t = *cursor + offset; /* proposed location */ @@ -404,7 +404,7 @@ See if a location is displayed on the screen. */ int on_screen (loc) -long loc; +loc_t loc; { int new_r, new_c; diff --git a/edit.c b/edit.c index efc387d..047c9ff 100644 --- a/edit.c +++ b/edit.c @@ -16,12 +16,12 @@ edit.c -- Routines to handle edit mode commands. #include "empire.h" #include "extern.h" -void e_move(long *path_start, long loc); +void e_move(loc_t *path_start, loc_t loc); extern int get_piece_name(void); void edit(edit_cursor) -long edit_cursor; +loc_t edit_cursor; { char e_cursor(); void e_leave(), e_print(), e_random(); @@ -30,7 +30,7 @@ long edit_cursor; void e_fill(), e_land(), e_city_func(), e_transport(); void e_attack(), e_repair(); - long path_start; + loc_t path_start; int path_type; char e; @@ -114,7 +114,7 @@ fast. char e_cursor (edit_cursor) -long *edit_cursor; +loc_t *edit_cursor; { chtype e; int p; @@ -154,7 +154,7 @@ Print new sector. void e_print (edit_cursor) -long *edit_cursor; +loc_t *edit_cursor; { int sector; @@ -171,7 +171,7 @@ Set the function of a piece. void e_set_func (loc, func) -long loc; +loc_t loc; long func; { piece_info_t *obj; @@ -200,7 +200,7 @@ Set a piece to move randomly. void e_random (loc) -long loc; +loc_t loc; { e_set_func (loc, RANDOM); } @@ -219,7 +219,7 @@ Put a ship in fill mode. void e_fill (loc) -long loc; +loc_t loc; { if (user_map[loc].contents == 'T' || user_map[loc].contents == 'C') e_set_func (loc, FILL); @@ -242,7 +242,7 @@ Set a piece to explore. void e_explore (loc) -long loc; +loc_t loc; { e_set_func (loc, EXPLORE); } @@ -261,7 +261,7 @@ Set a fighter to land. void e_land (loc) -long loc; +loc_t loc; { if (user_map[loc].contents == 'F') e_set_func (loc, LAND); @@ -273,7 +273,7 @@ Set an army's function to TRANSPORT. void e_transport (loc) -long loc; +loc_t loc; { if (user_map[loc].contents == 'A') e_set_func (loc, WFTRANSPORT); @@ -286,7 +286,7 @@ Set an army's function to ATTACK. void e_attack (loc) -long loc; +loc_t loc; { if (user_map[loc].contents == 'A') e_set_func (loc, ARMYATTACK); @@ -309,7 +309,7 @@ Set a ship's function to REPAIR. void e_repair (loc) -long loc; +loc_t loc; { if (strchr ("PDSTBC", user_map[loc].contents)) e_set_func (loc, REPAIR); @@ -334,7 +334,7 @@ static char dirs[] = "WEDCXZAQ"; void e_stasis (loc) -long loc; +loc_t loc; { char e; char *p; @@ -371,7 +371,7 @@ Wake up anything and everything. void e_wake (loc) -long loc; +loc_t loc; { city_info_t *cityp; piece_info_t *obj; @@ -401,8 +401,8 @@ the function itself. void e_city_func (path_start, loc, path_type) -long *path_start; -long loc; +loc_t *path_start; +loc_t loc; int *path_type; { int type; @@ -461,8 +461,8 @@ Beginning of move to location. void e_move (path_start, loc) -long *path_start; -long loc; +loc_t *path_start; +loc_t loc; { if (!isupper(user_map[loc].contents)) huh (); /* nothing there? */ else if (user_map[loc].contents == 'X') huh (); /* enemy city? */ @@ -475,8 +475,8 @@ End of move to location. void e_end (path_start, loc, path_type) -long *path_start; -long loc; +loc_t *path_start; +loc_t loc; int path_type; { city_info_t *cityp; @@ -498,7 +498,7 @@ Put a piece to sleep. void e_sleep (loc) -long loc; +loc_t loc; { if (user_map[loc].contents == 'O') huh (); /* can't sleep a city */ else e_set_func (loc, SENTRY); @@ -510,7 +510,7 @@ Print out information about a piece. void e_info (edit_cursor) -long edit_cursor; +loc_t edit_cursor; { void e_city_info(), e_piece_info(); @@ -533,7 +533,7 @@ Print info about a piece. void e_piece_info (edit_cursor, ab) -long edit_cursor; +loc_t edit_cursor; char ab; { piece_info_t *obj; @@ -555,7 +555,7 @@ Display info on a city. void e_city_info (edit_cursor) -long edit_cursor; +loc_t edit_cursor; { piece_info_t *obj; city_info_t *cityp; @@ -615,7 +615,7 @@ Change city production. void e_prod (loc) -long loc; +loc_t loc; { city_info_t *cityp; diff --git a/empire.c b/empire.c index 161019f..99c6f0c 100644 --- a/empire.c +++ b/empire.c @@ -190,7 +190,7 @@ it as the computers. void c_give () { int unowned[NUM_CITY]; - long i, count; + count_t i, count; count = 0; /* nothing in list yet */ for (i = 0; i < NUM_CITY; i++) { diff --git a/empire.h b/empire.h index 3a588d0..5e499f1 100644 --- a/empire.h +++ b/empire.h @@ -20,6 +20,10 @@ empire.h -- type and constant declarations typedef unsigned char uchar; +typedef long loc_t; /* represent a board location in 4-digit form */ + +typedef long count_t; /* for iterating over or counting board locations */ + #define ASSERT(x) if (!(x)) assert ("x", __FILE__, __LINE__); #define ABORT assert ("aborting", __FILE__, __LINE__) @@ -59,7 +63,7 @@ typedef unsigned char uchar; #define LIST_SIZE 5000 /* max number of pieces on board */ typedef struct city_info { - long loc; /* location of city */ + loc_t loc; /* location of city */ uchar owner; /* UNOWNED, USER, COMP */ long func[NUM_OBJECTS]; /* function for each object */ long work; /* units of work performed */ @@ -115,7 +119,7 @@ typedef struct piece_info { link_t cargo_link; /* linked list of cargo pieces */ int owner; /* owner of piece */ int type; /* type of piece */ - long loc; /* location of piece */ + loc_t loc; /* location of piece */ long func; /* programmed type of movement */ short hits; /* hits left */ int moved; /* moves made */ diff --git a/game.c b/game.c index 2cec490..ae747ce 100644 --- a/game.c +++ b/game.c @@ -17,10 +17,10 @@ game.c -- Routines to initialize, save, and restore a game. #include "empire.h" #include "extern.h" -long remove_land(long loc, long num_land); +count_t remove_land(loc_t loc, count_t num_land); int select_cities(void); -int find_next(long *mapi); -int good_cont(long mapi); +int find_next(loc_t *mapi); +int good_cont(loc_t mapi); int xread(FILE *f, char *buf, int size); int xwrite(FILE *f, char *buf, int size); void stat_display( char *mbuf, int round); @@ -34,7 +34,7 @@ pieces on the board. void init_game (void) { void make_map(void), place_cities(void); - long i; + count_t i; kill_display (); /* nothing on screen */ automove = FALSE; @@ -98,7 +98,8 @@ static int height_count[MAX_HEIGHT+1]; void make_map (void) { int from, to, k; - long i, j, sum, loc; + count_t i, j, sum; + loc_t loc; for (i = 0; i < MAP_SIZE; i++) /* fill map with random sand */ height[0][i] = irand (MAX_HEIGHT); @@ -165,13 +166,14 @@ for a city, we remove land cells which are too close to the city. */ /* avoid compiler problems with large automatic arrays */ -static long land[MAP_SIZE]; +static loc_t land[MAP_SIZE]; void place_cities (void) { - long regen_land(); + count_t regen_land(); - long placed, i, loc; - long num_land; + count_t placed, i; + loc_t loc; + count_t num_land; num_land = 0; /* nothing in land array yet */ placed = 0; /* nothing placed yet */ @@ -203,11 +205,11 @@ put all land in the list, decrement the min_city_dist, and then remove any land which is too close to a city. */ -long regen_land (placed) -long placed; +count_t regen_land (placed) +count_t placed; { - long num_land; - long i; + count_t num_land; + count_t i; num_land = 0; for (i = 0; i < MAP_SIZE; i++) { @@ -230,10 +232,11 @@ long placed; Remove land that is too close to a city. */ -long remove_land (loc, num_land) -long loc, num_land; +count_t remove_land (loc, num_land) +loc_t loc; +count_t num_land; { - long new, i; + count_t new, i; new = 0; /* nothing kept yet */ for (i = 0; i < num_land; i++) { @@ -298,7 +301,7 @@ static pair_t pair_tab[MAX_CONT*MAX_CONT]; /* ranked pairs of continents */ int select_cities (void) { void find_cont(void), make_pair(void); - long compi, useri; + loc_t compi, useri; city_info_t *compp, *userp; int comp_cont, user_cont; int pair; @@ -346,8 +349,8 @@ city. We rank the continents. */ void find_cont (void) { - long i; - long mapi; + loc_t i; + loc_t mapi; for (i = 0; i < MAP_SIZE; i++) marked[i] = 0; /* nothing marked yet */ @@ -364,9 +367,10 @@ If there are no more continents, we return false. */ int find_next (mapi) -long *mapi; +loc_t *mapi; { - long i, val; + count_t i; + long val; for (;;) { if (*mapi >= MAP_SIZE) return (FALSE); @@ -397,11 +401,11 @@ continent contains 2 cities and a shore city, we set the value of the continent and return true. Otherwise we return false. */ -static long ncity, nland, nshore; -static void mark_cont(long); +static count_t ncity, nland, nshore; +static void mark_cont(loc_t); int good_cont (mapi) -long mapi; +loc_t mapi; { long val; @@ -437,7 +441,7 @@ cities for the continent. We then examine each surrounding cell. static void mark_cont (mapi) -long mapi; +loc_t mapi; { int i; @@ -714,7 +718,7 @@ void save_movie_screen (void) { FILE *f; /* file to save game in */ - long i; + count_t i; piece_info_t *p; f = fopen ("empmovie.dat", "a"); /* open for append */ @@ -798,7 +802,7 @@ void stat_display (mbuf, round) char *mbuf; int round; { - long i; + count_t i; int counts[2*NUM_OBJECTS+2]; int user_cost, comp_cost; char *p; diff --git a/map.c b/map.c index fb7de1f..a35ef53 100644 --- a/map.c +++ b/map.c @@ -29,12 +29,12 @@ real_maps, path_maps, and cont_maps. } STATIC void expand_perimeter(path_map_t *pmap,view_map_t *vmap,move_info_t *move_info,perimeter_t *curp,int type,int cur_cost,int inc_wcost,int inc_lcost,perimeter_t *waterp,perimeter_t *landp); -STATIC void expand_prune(view_map_t *vmap,path_map_t *pmap,long loc,int type,perimeter_t *to,int *explored); -STATIC int objective_cost(view_map_t *vmap,move_info_t *move_info,long loc,int base_cost); -STATIC int terrain_type(path_map_t *pmap,view_map_t *vmap,move_info_t *move_info,long from_loc,long to_loc); -STATIC void start_perimeter(path_map_t *pmap,perimeter_t *perim,long loc,int terrain); -STATIC void add_cell(path_map_t *pmap,long new_loc,perimeter_t *perim,int terrain,int cur_cost,int inc_cost); -STATIC int vmap_count_path (path_map_t *pmap,long loc); +STATIC void expand_prune(view_map_t *vmap,path_map_t *pmap,loc_t loc,int type,perimeter_t *to,int *explored); +STATIC int objective_cost(view_map_t *vmap,move_info_t *move_info,loc_t loc,int base_cost); +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); +STATIC void start_perimeter(path_map_t *pmap,perimeter_t *perim,loc_t loc,int terrain); +STATIC void add_cell(path_map_t *pmap,loc_t new_loc,perimeter_t *perim,int terrain,int cur_cost,int inc_cost); +STATIC int vmap_count_path (path_map_t *pmap,loc_t loc); static perimeter_t p1; /* perimeter list for use as needed */ static perimeter_t p2; @@ -42,7 +42,7 @@ static perimeter_t p3; static perimeter_t p4; static int best_cost; /* cost and location of best objective */ -static long best_loc; +static loc_t best_loc; /* Map out a continent. We are given a location on the continent. @@ -56,7 +56,7 @@ void vmap_cont (cont_map, vmap, loc, bad_terrain) int *cont_map; view_map_t *vmap; -long loc; +loc_t loc; char bad_terrain; { (void) bzero ((char *)cont_map, MAP_SIZE * sizeof (int)); @@ -73,11 +73,11 @@ void vmap_mark_up_cont (cont_map, vmap, loc, bad_terrain) int *cont_map; view_map_t *vmap; -long loc; +loc_t loc; char bad_terrain; { int i, j; - long new_loc; + loc_t new_loc; char this_terrain; perimeter_t *from, *to; @@ -126,7 +126,7 @@ static void rmap_mark_up_cont(); void rmap_cont (cont_map, loc, bad_terrain) int *cont_map; -long loc; +loc_t loc; char bad_terrain; { (void) bzero ((char *)cont_map, MAP_SIZE * sizeof (int)); @@ -144,11 +144,11 @@ Someday this should be tweaked to use perimeter lists. static void rmap_mark_up_cont (cont_map, loc, bad_terrain) int *cont_map; -long loc; +loc_t loc; char bad_terrain; { int i; - long new_loc; + loc_t new_loc; if (!map[loc].on_board) return; /* off board */ if (cont_map[loc]) return; /* already marked */ @@ -174,7 +174,7 @@ int *cont_map; view_map_t *vmap; { scan_counts_t counts; - long i; + count_t i; (void) bzero ((char *)&counts, sizeof (scan_counts_t)); @@ -229,7 +229,7 @@ rmap_cont_scan (cont_map) int *cont_map; { scan_counts_t counts; - long i; + count_t i; (void) bzero ((char *)&counts, sizeof (scan_counts_t)); @@ -250,9 +250,9 @@ Return TRUE if a location is on the edge of a continent. int map_cont_edge (cont_map, loc) int *cont_map; -long loc; +loc_t loc; { - long i, j; + loc_t i, j; if (!cont_map[loc]) return FALSE; /* not on continent */ @@ -294,11 +294,11 @@ the information must be consistent with the needs of 'vmap_mark_path'. /* Find an objective over a single type of terrain. */ -long +loc_t vmap_find_xobj (path_map, vmap, loc, move_info, start, expand) path_map_t path_map[]; view_map_t *vmap; -long loc; +loc_t loc; move_info_t *move_info; int start; int expand; @@ -331,11 +331,11 @@ int expand; /* Find an objective for a piece that crosses land and water. */ -long +loc_t vmap_find_aobj (path_map, vmap, loc, move_info) path_map_t path_map[]; view_map_t *vmap; -long loc; +loc_t loc; move_info_t *move_info; { return vmap_find_xobj (path_map, vmap, loc, move_info, T_LAND, T_AIR); @@ -343,11 +343,11 @@ move_info_t *move_info; /* Find an objective for a piece that crosses only water. */ -long +loc_t vmap_find_wobj (path_map, vmap, loc, move_info) path_map_t path_map[]; view_map_t *vmap; -long loc; +loc_t loc; move_info_t *move_info; { return vmap_find_xobj (path_map, vmap, loc, move_info, T_WATER, T_WATER); @@ -355,11 +355,11 @@ move_info_t *move_info; /* Find an objective for a piece that crosses only land. */ -long +loc_t vmap_find_lobj (path_map, vmap, loc, move_info) path_map_t path_map[]; view_map_t *vmap; -long loc; +loc_t loc; move_info_t *move_info; { return vmap_find_xobj (path_map, vmap, loc, move_info, T_LAND, T_LAND); @@ -377,11 +377,11 @@ We have different objectives depending on whether the objective is being approached from the land or the water. */ -long +loc_t vmap_find_lwobj (path_map, vmap, loc, move_info, beat_cost) path_map_t path_map[]; view_map_t *vmap; -long loc; +loc_t loc; move_info_t *move_info; int beat_cost; { @@ -438,11 +438,11 @@ with the lowest cost. STATIC int best_adj (pmap, loc, type) path_map_t *pmap; -long loc; +loc_t loc; int type; { int i; - long new_loc; + loc_t new_loc; int best; best = INFINITY; @@ -466,11 +466,11 @@ expand to land or water (army moving off tt or tt moving on water), but the second time, we only expand water (tt taking its second move). */ -long +loc_t vmap_find_wlobj (path_map, vmap, loc, move_info) path_map_t path_map[]; view_map_t *vmap; -long loc; +loc_t loc; move_info_t *move_info; { perimeter_t *cur_land; @@ -530,7 +530,7 @@ STATIC void start_perimeter (pmap, perim, loc, terrain) path_map_t *pmap; perimeter_t *perim; -long loc; +loc_t loc; int terrain; { int i; @@ -587,39 +587,39 @@ perimeter_t *landp; /* pointer to new land perimeter */ { register long i; register int j; - long new_loc; + loc_t new_loc; int obj_cost; register int new_type; for (i = 0; i < curp->len; i++) /* for each perimeter cell... */ - FOR_ADJ_ON (curp->list[i], new_loc, j) {/* for each adjacent cell... */ - register path_map_t *pm = pmap + new_loc; - - if (pm->cost == INFINITY) { - new_type = terrain_type (pmap, vmap, move_info, curp->list[i], new_loc); - - if (new_type == T_LAND && (type & T_LAND)) - add_cell (pmap, new_loc, landp, new_type, cur_cost, inc_lcost); - else if (new_type == T_WATER && (type & T_WATER)) - add_cell (pmap, new_loc, waterp, new_type, cur_cost, inc_wcost); - else if (new_type == T_UNKNOWN) { /* unreachable cell? */ - pm->terrain = new_type; - pm->cost = cur_cost + INFINITY/2; - pm->inc_cost = INFINITY/2; - } - if (pmap[new_loc].cost != INFINITY) { /* did we expand? */ - obj_cost = objective_cost (vmap, move_info, new_loc, cur_cost); - if (obj_cost < best_cost) { - best_cost = obj_cost; - best_loc = new_loc; - if (new_type == T_UNKNOWN) { - pm->cost=cur_cost+2; - pm->inc_cost = 2; + FOR_ADJ_ON (curp->list[i], new_loc, j) {/* for each adjacent cell... */ + register path_map_t *pm = pmap + new_loc; + + if (pm->cost == INFINITY) { + new_type = terrain_type (pmap, vmap, move_info, curp->list[i], new_loc); + + if (new_type == T_LAND && (type & T_LAND)) + add_cell (pmap, new_loc, landp, new_type, cur_cost, inc_lcost); + else if (new_type == T_WATER && (type & T_WATER)) + add_cell (pmap, new_loc, waterp, new_type, cur_cost, inc_wcost); + else if (new_type == T_UNKNOWN) { /* unreachable cell? */ + pm->terrain = new_type; + pm->cost = cur_cost + INFINITY/2; + pm->inc_cost = INFINITY/2; + } + if (pmap[new_loc].cost != INFINITY) { /* did we expand? */ + obj_cost = objective_cost (vmap, move_info, new_loc, cur_cost); + if (obj_cost < best_cost) { + best_cost = obj_cost; + best_loc = new_loc; + if (new_type == T_UNKNOWN) { + pm->cost=cur_cost+2; + pm->inc_cost = 2; + } } } } } - } } /* Add a cell to a perimeter list. */ @@ -627,7 +627,7 @@ perimeter_t *landp; /* pointer to new land perimeter */ STATIC void add_cell (pmap, new_loc, perim, terrain, cur_cost, inc_cost) path_map_t *pmap; -long new_loc; +loc_t new_loc; perimeter_t *perim; int terrain; int cur_cost; @@ -649,7 +649,7 @@ STATIC int objective_cost (vmap, move_info, loc, base_cost) view_map_t *vmap; move_info_t *move_info; -long loc; +loc_t loc; int base_cost; { char *p; @@ -691,8 +691,8 @@ terrain_type (pmap, vmap, move_info, from_loc, to_loc) path_map_t *pmap; view_map_t *vmap; move_info_t *move_info; -long from_loc; -long to_loc; +loc_t from_loc; +loc_t to_loc; { if (vmap[to_loc].contents == '+') return T_LAND; if (vmap[to_loc].contents == '.') return T_WATER; @@ -749,8 +749,8 @@ view_map_t *vmap; path_map_t pmap[MAP_SIZE]; perimeter_t *from, *to; int explored; - long loc, new_loc; - long i; + loc_t loc, new_loc; + count_t i; long copied; (void) bzero (pmap, sizeof (pmap)); @@ -874,13 +874,13 @@ STATIC void expand_prune (vmap, pmap, loc, type, to, explored) view_map_t *vmap; path_map_t *pmap; -long loc; +loc_t loc; int type; perimeter_t *to; int *explored; { int i; - long new_loc; + loc_t new_loc; *explored += 1; @@ -908,12 +908,12 @@ origin. This is similar to 'find_objective' except that we know our destination. */ -long +loc_t vmap_find_dest (path_map, vmap, cur_loc, dest_loc, owner, terrain) path_map_t path_map[]; view_map_t vmap[]; -long cur_loc; /* current location of piece */ -long dest_loc; /* destination of piece */ +loc_t cur_loc; /* current location of piece */ +loc_t dest_loc; /* destination of piece */ int owner; /* owner of piece being moved */ int terrain; /* terrain we can cross */ { @@ -971,10 +971,10 @@ void vmap_mark_path (path_map, vmap, dest) path_map_t *path_map; view_map_t *vmap; -long dest; +loc_t dest; { int n; - long new_dest; + loc_t new_dest; if (path_map[dest].cost == 0) return; /* reached end of path */ if (path_map[dest].terrain == T_PATH) return; /* already marked */ @@ -997,10 +997,10 @@ invoked to decide which squares are actually valid. void vmap_mark_adjacent (path_map, loc) path_map_t path_map[]; -long loc; +loc_t loc; { int i; - long new_loc; + loc_t new_loc; FOR_ADJ_ON (loc, new_loc, i) path_map[new_loc].terrain = T_PATH; @@ -1015,10 +1015,10 @@ to a location on the existing shortest path. void vmap_mark_near_path (path_map, loc) path_map_t path_map[]; -long loc; +loc_t loc; { int i, j; - long new_loc, xloc; + loc_t new_loc, xloc; int hit_loc[8]; (void) bzero ((char *)hit_loc, sizeof(int)*8); @@ -1064,16 +1064,16 @@ center of the best path. static int order[] = {NORTHWEST, NORTHEAST, SOUTHWEST, SOUTHEAST, WEST, EAST, NORTH, SOUTH}; -long +loc_t vmap_find_dir (path_map, vmap, loc, terrain, adj_char) path_map_t path_map[]; view_map_t *vmap; -long loc; +loc_t loc; char *terrain; char *adj_char; { int i, count, bestcount; - long bestloc, new_loc; + loc_t bestloc, new_loc; int path_count, bestpath; char *p; @@ -1115,11 +1115,11 @@ is the most interesting. int vmap_count_adjacent (vmap, loc, adj_char) view_map_t *vmap; -long loc; +loc_t loc; char *adj_char; { int i, count; - long new_loc; + loc_t new_loc; char *p; int len; @@ -1141,10 +1141,10 @@ Count the number of adjacent cells that are on the path. int vmap_count_path (pmap, loc) path_map_t *pmap; -long loc; +loc_t loc; { int i, count; - long new_loc; + loc_t new_loc; count = 0; @@ -1162,12 +1162,12 @@ cell contains water and is on the board. int rmap_shore (loc) -long loc; +loc_t loc; { - long i, j; + loc_t i, j; FOR_ADJ_ON (loc, j, i) - if (map[j].contents == '.') return (TRUE); + if (map[j].contents == '.') return (TRUE); return (FALSE); } @@ -1175,13 +1175,13 @@ long loc; int vmap_shore (vmap, loc) view_map_t *vmap; -long loc; +loc_t loc; { - long i, j; + loc_t i, j; FOR_ADJ_ON (loc, j, i) - if (vmap[j].contents != ' ' && vmap[j].contents != '+' && map[j].contents == '.') - return (TRUE); + if (vmap[j].contents != ' ' && vmap[j].contents != '+' && map[j].contents == '.') + return (TRUE); return (FALSE); } @@ -1194,28 +1194,28 @@ which cannot be moved to are treated as ocean. int vmap_at_sea (vmap, loc) view_map_t *vmap; -long loc; +loc_t loc; { - long i, j; + loc_t 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); + FOR_ADJ_ON (loc, j, i) + if (vmap[j].contents == ' ' || vmap[j].contents == '+' || map[j].contents != '.') + return (FALSE); return (TRUE); } int rmap_at_sea (loc) -long loc; +loc_t loc; { - long i, j; + loc_t i, j; if (map[loc].contents != '.') return (FALSE); - FOR_ADJ_ON (loc, j, i) { - if (map[j].contents != '.') return (FALSE); - } + FOR_ADJ_ON (loc, j, i) { + if (map[j].contents != '.') return (FALSE); + } return (TRUE); } diff --git a/math.c b/math.c index d68eb12..22e8164 100644 --- a/math.c +++ b/math.c @@ -59,7 +59,7 @@ the max of the absolute differnce between the x and y coordinates. int dist (a, b) -long a, b; +loc_t a, b; { int ax, ay, bx, by; diff --git a/object.c b/object.c index 5f2afd9..ef6c984 100644 --- a/object.c +++ b/object.c @@ -25,11 +25,12 @@ Distances are computed as straight-line distances. int find_nearest_city (loc, owner, city_loc) -long loc; +loc_t loc; int owner; -long *city_loc; +loc_t *city_loc; { - long best_dist, best_loc; + loc_t best_loc; + long best_dist; long new_dist, i; best_dist = INFINITY; @@ -52,7 +53,7 @@ Given the location of a city, return the index of that city. */ city_info_t *find_city (loc) -long loc; +loc_t loc; { return (map[loc].cityp); } @@ -93,7 +94,7 @@ list of objects at the given location for one of the given type. piece_info_t *find_obj (type, loc) int type; -long loc; +loc_t loc; { piece_info_t *p; @@ -109,7 +110,7 @@ Find a non-full item of the appropriate type at the given location. piece_info_t *find_nfull (type, loc) int type; -long loc; +loc_t loc; { piece_info_t *p; @@ -125,13 +126,13 @@ Look around a location for an unfull transport. Return the location of the transport if there is one. */ -long +loc_t find_transport (owner, loc) int owner; -long loc; +loc_t loc; { int i; - long new_loc; + loc_t new_loc; piece_info_t *t; for (i = 0; i < 8; i++) { /* look around */ @@ -149,7 +150,7 @@ We prefer transports and carriers to other objects. piece_info_t * find_obj_at_loc (loc) -long loc; +loc_t loc; { piece_info_t *p, *best; @@ -196,7 +197,7 @@ anything in the object, it is killed as well. void kill_obj (obj, loc) piece_info_t *obj; -long loc; +loc_t loc; { void kill_one(); @@ -328,10 +329,10 @@ etc. void move_obj (obj, new_loc) piece_info_t *obj; -long new_loc; +loc_t new_loc; { view_map_t *vmap; - long old_loc; + loc_t old_loc; piece_info_t *p; ASSERT (obj->hits); @@ -382,9 +383,9 @@ We start off with some preliminary routines. /* Return next direction for a sattellite to travel. */ -static long +static loc_t bounce (loc, dir1, dir2, dir3) -long loc, dir1, dir2, dir3; +loc_t loc, dir1, dir2, dir3; { int new_loc; @@ -404,7 +405,7 @@ move_sat1 (obj) piece_info_t *obj; { int dir; - long new_loc; + loc_t new_loc; dir = MOVE_DIR(obj->func); new_loc = obj->loc + dir_offset[dir]; @@ -463,7 +464,7 @@ move onto transports, and fighters may move onto cities or carriers. int good_loc (obj, loc) piece_info_t *obj; -long loc; +loc_t loc; { view_map_t *vmap; piece_info_t *p; @@ -540,12 +541,12 @@ on top. void scan (vmap, loc) view_map_t vmap[]; -long loc; +loc_t loc; { void update(), check(void); int i; - long xloc; + loc_t xloc; #ifdef DEBUG check (); /* perform a consistency check */ @@ -566,10 +567,10 @@ Scan a portion of the board for a satellite. void scan_sat (vmap, loc) view_map_t *vmap; -long loc; +loc_t loc; { int i; - long xloc; + loc_t xloc; ASSERT (map[loc].on_board); @@ -592,7 +593,7 @@ char city_char[] = {'*', 'O', 'X'}; void update (vmap, loc) view_map_t vmap[]; -long loc; +loc_t loc; { piece_info_t *p; diff --git a/usermove.c b/usermove.c index 0b57746..8059f4b 100644 --- a/usermove.c +++ b/usermove.c @@ -16,9 +16,9 @@ usermove.c -- Let the user move her troops. #include "empire.h" #include "extern.h" -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); +void fatal(piece_info_t *obj,loc_t loc,char *message,char *response); +void move_to_dest(piece_info_t *obj,loc_t dest); +void move_army_to_city(piece_info_t *obj,loc_t city_loc); int awake(piece_info_t *obj); extern int get_piece_name(void); @@ -114,7 +114,7 @@ piece_info_t *obj; int speed, max_hits; int saved_moves; int need_input; - long saved_loc; + loc_t saved_loc; city_info_t *cityp; /* set func for piece if on city */ @@ -208,9 +208,9 @@ move the piece to a random adjacent square. void move_random (obj) piece_info_t *obj; { - long loc_list[8]; + loc_t loc_list[8]; int i, nloc; - long loc; + loc_t loc; nloc = 0; @@ -236,7 +236,7 @@ void move_explore (obj) piece_info_t *obj; { path_map_t path_map[MAP_SIZE]; - long loc; + loc_t loc; char *terrain; switch (obj->type) { @@ -274,7 +274,7 @@ void move_transport (obj) piece_info_t *obj; { - long loc; + loc_t loc; /* look for an adjacent transport */ loc = find_transport (USER, obj->loc); @@ -298,7 +298,7 @@ void move_armyload (obj) piece_info_t *obj; { - long loc; + loc_t loc; piece_info_t *p; int i; @@ -334,7 +334,7 @@ move_armyattack (obj) piece_info_t *obj; { path_map_t path_map[MAP_SIZE]; - long loc; + loc_t loc; ASSERT (obj->type == ARMY); @@ -365,7 +365,7 @@ move_repair (obj) piece_info_t *obj; { path_map_t path_map[MAP_SIZE]; - long loc; + loc_t loc; ASSERT (obj->type > FIGHTER); @@ -415,7 +415,8 @@ void move_land (obj) piece_info_t *obj; { - long best_dist, best_loc; + long best_dist; + loc_t best_loc; long new_dist; piece_info_t *p; @@ -445,7 +446,7 @@ we wake it up. void move_dir (obj) piece_info_t *obj; { - long loc; + loc_t loc; int dir; dir = MOVE_DIR (obj->func); @@ -479,12 +480,12 @@ move. void move_to_dest (obj, dest) piece_info_t *obj; -long dest; +loc_t dest; { path_map_t path_map[MAP_SIZE]; int fterrain; char *mterrain; - long new_loc; + loc_t new_loc; switch (obj->type) { case ARMY: @@ -841,7 +842,7 @@ int dir; { void user_dir_army(), user_dir_fighter(), user_dir_ship(); - long loc; + loc_t loc; loc = obj->loc + dir_offset[dir]; @@ -870,7 +871,7 @@ necessary, and attack if necessary. void user_dir_army (obj, loc) piece_info_t *obj; -long loc; +loc_t loc; { int enemy_killed; @@ -935,7 +936,7 @@ three cases: attacking a city, attacking ourself, attacking the enemy. void user_dir_fighter (obj, loc) piece_info_t *obj; -long loc; +loc_t loc; { if (map[loc].contents == '*') fatal (obj, loc, @@ -962,7 +963,7 @@ a city, attacking self, attacking enemy. void user_dir_ship (obj, loc) piece_info_t *obj; -long loc; +loc_t loc; { int enemy_killed; @@ -1021,7 +1022,7 @@ if she really wants to attack the city. void move_army_to_city (obj, city_loc) piece_info_t *obj; -long city_loc; +loc_t city_loc; { piece_info_t *tt; @@ -1106,7 +1107,7 @@ print out the response and kill the object. void fatal (obj, loc, message, response) piece_info_t *obj; -long loc; +loc_t loc; char *message; char *response; { -- 2.43.0