void
attack_city(piece_info_t *att_obj, loc_t loc)
{
- city_info_t *cityp;
- int att_owner, city_owner;
+ city_info_t *cityp;
+ int att_owner, city_owner;
- cityp = find_city (loc);
- ASSERT (cityp);
+ cityp = find_city (loc);
+ ASSERT (cityp);
- att_owner = att_obj->owner;
- city_owner = cityp->owner;
+ att_owner = att_obj->owner;
+ city_owner = cityp->owner;
- if (irand (2) == 0) { /* attack fails? */
- if (att_owner == USER) {
- comment ("The scum defending the city crushed your attacking blitzkrieger.");
- ksend ("The scum defending the city crushed your attacking blitzkrieger.\n"); //kermyt
- }
- else if (city_owner == USER) {
- ksend ("Your city at %d is under attack.\n",loc_disp(cityp->loc)); //kermyt
- comment ("Your city at %d is under attack.",loc_disp(cityp->loc));
- }
- kill_obj (att_obj, loc);
+ if (irand (2) == 0) { /* attack fails? */
+ if (att_owner == USER) {
+ comment ("The scum defending the city crushed your attacking blitzkrieger.");
+ ksend ("The scum defending the city crushed your attacking blitzkrieger.\n"); //kermyt
}
- else { /* attack succeeded */
- kill_city (cityp);
- cityp->owner = att_owner;
- kill_obj (att_obj, loc);
-
- if (att_owner == USER) {
- ksend ("City at %d has been subjugated!\n",loc_disp(cityp->loc)); //kermyt
- error ("City at %d has been subjugated!",loc_disp(cityp->loc));
-
- extra ("Your army has been dispersed to enforce control.");
- ksend ("Your army has been dispersed to enforce control.\n");
- set_prod (cityp);
- }
- else if (city_owner == USER) {
- ksend("City at %d has been lost to the enemy!\n",loc_disp(cityp->loc)); //kermyt
- comment ("City at %d has been lost to the enemy!",loc_disp(cityp->loc));
- }
+ else if (city_owner == USER) {
+ ksend ("Your city at %d is under attack.\n",loc_disp(cityp->loc)); //kermyt
+ comment ("Your city at %d is under attack.",loc_disp(cityp->loc));
}
- /* let city owner see all results */
- if (city_owner != UNOWNED) scan (MAP(city_owner), loc);
+ kill_obj (att_obj, loc);
+ }
+ else { /* attack succeeded */
+ kill_city (cityp);
+ cityp->owner = att_owner;
+ kill_obj (att_obj, loc);
+
+ if (att_owner == USER) {
+ ksend ("City at %d has been subjugated!\n",loc_disp(cityp->loc)); //kermyt
+ error ("City at %d has been subjugated!",loc_disp(cityp->loc));
+
+ extra ("Your army has been dispersed to enforce control.");
+ ksend ("Your army has been dispersed to enforce control.\n");
+ set_prod (cityp);
+ }
+ else if (city_owner == USER) {
+ ksend("City at %d has been lost to the enemy!\n",loc_disp(cityp->loc)); //kermyt
+ comment ("City at %d has been lost to the enemy!",loc_disp(cityp->loc));
+ }
+ }
+ /* let city owner see all results */
+ if (city_owner != UNOWNED) scan (MAP(city_owner), loc);
}
/*
void
attack_obj(piece_info_t *att_obj, loc_t loc)
{
- void describe(), survive();
+ void describe(), survive();
- piece_info_t *def_obj; /* defender */
- int owner;
+ piece_info_t *def_obj; /* defender */
+ int owner;
- def_obj = find_obj_at_loc (loc);
- ASSERT (def_obj != NULL); /* can't find object to attack? */
+ def_obj = find_obj_at_loc (loc);
+ ASSERT (def_obj != NULL); /* can't find object to attack? */
- if (def_obj->type == SATELLITE) return; /* can't attack a satellite */
-
- while (att_obj->hits > 0 && def_obj->hits > 0) {
- if (irand (2) == 0) /* defender hits? */
- att_obj->hits -= piece_attr[def_obj->type].strength;
- else def_obj->hits -= piece_attr[att_obj->type].strength;
- }
-
- if (att_obj->hits > 0) { /* attacker won? */
- describe (att_obj, def_obj, loc);
- owner = def_obj->owner;
- kill_obj (def_obj, loc); /* kill loser */
- survive (att_obj, loc); /* move attacker */
- }
- else { /* defender won */
- describe (def_obj, att_obj, loc);
- owner = att_obj->owner;
- kill_obj (att_obj, loc);
- survive (def_obj, loc);
- }
- /* show results to first killed */
- scan (MAP(owner), loc);
+ if (def_obj->type == SATELLITE) return; /* can't attack a satellite */
+
+ while (att_obj->hits > 0 && def_obj->hits > 0) {
+ if (irand (2) == 0) /* defender hits? */
+ att_obj->hits -= piece_attr[def_obj->type].strength;
+ else def_obj->hits -= piece_attr[att_obj->type].strength;
+ }
+
+ if (att_obj->hits > 0) { /* attacker won? */
+ describe (att_obj, def_obj, loc);
+ owner = def_obj->owner;
+ kill_obj (def_obj, loc); /* kill loser */
+ survive (att_obj, loc); /* move attacker */
+ }
+ else { /* defender won */
+ describe (def_obj, att_obj, loc);
+ owner = att_obj->owner;
+ kill_obj (att_obj, loc);
+ survive (def_obj, loc);
+ }
+ /* show results to first killed */
+ scan (MAP(owner), loc);
}
void
attack(piece_info_t *att_obj, loc_t loc)
{
- if (map[loc].contents == '*') /* attacking a city? */
- attack_city (att_obj, loc);
- else attack_obj (att_obj, loc); /* attacking a piece */
+ if (map[loc].contents == '*') /* attacking a city? */
+ attack_city (att_obj, loc);
+ else attack_obj (att_obj, loc); /* attacking a piece */
}
/*
void
survive(piece_info_t *obj, loc_t loc)
{
- while (obj_capacity (obj) < obj->count)
- kill_obj (obj->cargo, loc);
+ while (obj_capacity (obj) < obj->count)
+ kill_obj (obj->cargo, loc);
- move_obj (obj, loc);
+ move_obj (obj, loc);
}
void
describe(piece_info_t *win_obj, piece_info_t *lose_obj, loc_t loc)
{
- char buf[STRSIZE];
- char buf2[STRSIZE];
- int diff;
+ char buf[STRSIZE];
+ char buf2[STRSIZE];
+ int diff;
- *buf = '\0';
- *buf2 = '\0';
+ *buf = '\0';
+ *buf2 = '\0';
- if (win_obj->owner != lose_obj->owner) {
- if (win_obj->owner == USER) {
- user_score += piece_attr[lose_obj->type].build_time;
- ksend ("Enemy %s at %d destroyed.\n",piece_attr[lose_obj->type].name,loc_disp(loc)); //kermyt
- topmsg (1, "Enemy %s at %d destroyed.",piece_attr[lose_obj->type].name,loc_disp(loc));
- ksend ("Your %s has %d hits left\n",piece_attr[win_obj->type].name,win_obj->hits); //kermyt
- topmsg (2, "Your %s has %d hits left.", piece_attr[win_obj->type].name, win_obj->hits);
+ if (win_obj->owner != lose_obj->owner) {
+ if (win_obj->owner == USER) {
+ user_score += piece_attr[lose_obj->type].build_time;
+ ksend ("Enemy %s at %d destroyed.\n",piece_attr[lose_obj->type].name,loc_disp(loc)); //kermyt
+ topmsg (1, "Enemy %s at %d destroyed.",piece_attr[lose_obj->type].name,loc_disp(loc));
+ ksend ("Your %s has %d hits left\n",piece_attr[win_obj->type].name,win_obj->hits); //kermyt
+ topmsg (2, "Your %s has %d hits left.", piece_attr[win_obj->type].name, win_obj->hits);
- diff = win_obj->count - obj_capacity (win_obj);
- if (diff > 0) switch (win_obj->cargo->type) {
- case ARMY:
- ksend("%d armies fell overboard and drowned in the assault.\n",diff); //kermyt
- topmsg (3,"%d armies fell overboard and drowned in the assault.",diff);
- break;
- case FIGHTER:
- ksend("%d fighters fell overboard and were lost in the assult.\n",diff); //kermyt
- topmsg (3,"%d fighters fell overboard and were lost in the assault.",diff);
- break;
- }
+ diff = win_obj->count - obj_capacity (win_obj);
+ if (diff > 0) switch (win_obj->cargo->type) {
+ case ARMY:
+ ksend("%d armies fell overboard and drowned in the assault.\n",diff); //kermyt
+ topmsg (3,"%d armies fell overboard and drowned in the assault.",diff);
+ break;
+ case FIGHTER:
+ ksend("%d fighters fell overboard and were lost in the assult.\n",diff); //kermyt
+ topmsg (3,"%d fighters fell overboard and were lost in the assault.",diff);
+ break;
}
- else {
- comp_score += piece_attr[lose_obj->type].build_time;
- ksend ("Your %s at %d destroyed.\n",piece_attr[lose_obj->type].name,loc_disp(loc)); //kermyt
- topmsg (3, "Your %s at %d destroyed.",piece_attr[lose_obj->type].name,loc_disp(loc));
- }
- set_need_delay ();
}
+ else {
+ comp_score += piece_attr[lose_obj->type].build_time;
+ ksend ("Your %s at %d destroyed.\n",piece_attr[lose_obj->type].name,loc_disp(loc)); //kermyt
+ topmsg (3, "Your %s at %d destroyed.",piece_attr[lose_obj->type].name,loc_disp(loc));
+ }
+ set_need_delay ();
+ }
}
+
+/* end */
void
comp_move(int nmoves)
{
- void do_cities(), do_pieces(), check_endgame();
+ void do_cities(), do_pieces(), check_endgame();
- int i;
- piece_info_t *obj;
+ int i;
+ piece_info_t *obj;
- /* Update our view of the world. */
+ /* Update our view of the world. */
- for (i = 0; i < NUM_OBJECTS; i++)
+ for (i = 0; i < NUM_OBJECTS; i++)
for (obj = comp_obj[i]; obj != NULL; obj = obj->piece_link.next)
- scan (comp_map, obj->loc); /* refresh comp's view of world */
+ scan (comp_map, obj->loc); /* refresh comp's view of world */
- for (i = 1; i <= nmoves; i++) { /* for each move we get... */
- comment ("Thinking...");
+ for (i = 1; i <= nmoves; i++) { /* for each move we get... */
+ comment ("Thinking...");
- (void) memcpy (emap, comp_map, MAP_SIZE * sizeof (view_map_t));
- vmap_prune_explore_locs (emap);
+ (void) memcpy (emap, comp_map, MAP_SIZE * sizeof (view_map_t));
+ vmap_prune_explore_locs (emap);
- do_cities (); /* handle city production */
- do_pieces (); /* move pieces */
+ do_cities (); /* handle city production */
+ do_pieces (); /* move pieces */
- if (save_movie) save_movie_screen ();
- check_endgame (); /* see if game is over */
+ if (save_movie) save_movie_screen ();
+ check_endgame (); /* see if game is over */
- topini ();
- (void) redisplay ();
- }
+ topini ();
+ (void) redisplay ();
+ }
}
/*
*/
void
-do_cities(void) {
- int i;
- bool is_lake;
+do_cities(void)
+{
+ int i;
+ bool is_lake;
- for (i = 0; i < NUM_CITY; i++) /* new production */
+ for (i = 0; i < NUM_CITY; i++) /* new production */
if (city[i].owner == COMP) {
- scan (comp_map, city[i].loc);
+ scan (comp_map, city[i].loc);
- if (city[i].prod == NOPIECE)
- comp_prod (&city[i], lake (city[i].loc));
+ if (city[i].prod == NOPIECE)
+ comp_prod (&city[i], lake (city[i].loc));
}
- for (i = 0; i < NUM_CITY; i++) /* produce and change */
+ 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[(int)city[i].prod].build_time) {
- produce (&city[i]);
- comp_prod (&city[i], is_lake);
- }
- /* don't produce ships in lakes */
- else if (city[i].prod > FIGHTER && city[i].prod != SATELLITE && is_lake)
- comp_prod (&city[i], is_lake);
+ is_lake = lake (city[i].loc);
+ if (city[i].work++ >= (long)piece_attr[(int)city[i].prod].build_time) {
+ produce (&city[i]);
+ comp_prod (&city[i], is_lake);
+ }
+ /* don't produce ships in lakes */
+ else if (city[i].prod > FIGHTER && city[i].prod != SATELLITE && is_lake)
+ comp_prod (&city[i], is_lake);
}
}
void
comp_prod(city_info_t *cityp, bool is_lake)
{
- int city_count[NUM_OBJECTS]; /* # of cities producing each piece */
- int cont_map[MAP_SIZE];
- int total_cities;
- count_t i;
- int comp_ac;
- city_info_t *p;
- int need_count, interest;
- scan_counts_t counts;
-
- /* Make sure we have army producers for current continent. */
+ int city_count[NUM_OBJECTS]; /* # of cities producing each piece */
+ int cont_map[MAP_SIZE];
+ int total_cities;
+ count_t i;
+ int comp_ac;
+ city_info_t *p;
+ int need_count, interest;
+ scan_counts_t counts;
+
+ /* Make sure we have army producers for current continent. */
- /* map out city's continent */
- vmap_cont (cont_map, comp_map, cityp->loc, '.');
+ /* map out city's continent */
+ vmap_cont (cont_map, comp_map, cityp->loc, '.');
- /* count items of interest on the continent */
- counts = vmap_cont_scan (cont_map, comp_map);
- comp_ac = 0; /* no army producing computer cities */
+ /* count items of interest on the continent */
+ counts = vmap_cont_scan (cont_map, comp_map);
+ 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;
- }
+ 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;
+ }
}
- /* see if anything of interest is on continent */
- interest = (counts.unexplored || counts.user_cities
- || counts.user_objects[ARMY]
- || counts.unowned_cities);
+ /* see if anything of interest is on continent */
+ interest = (counts.unexplored || counts.user_cities
+ || counts.user_objects[ARMY]
+ || counts.unowned_cities);
- /* we want one more army producer than enemy has cities */
- /* and one more if anything of interest on cont */
- need_count = counts.user_cities - comp_ac + interest;
- if (counts.user_cities) need_count += 1;
+ /* we want one more army producer than enemy has cities */
+ /* and one more if anything of interest on cont */
+ need_count = counts.user_cities - comp_ac + interest;
+ if (counts.user_cities) need_count += 1;
- if (need_count > 0) { /* need an army producer? */
- comp_set_prod (cityp, ARMY);
- return;
- }
+ if (need_count > 0) { /* need an army producer? */
+ comp_set_prod (cityp, ARMY);
+ return;
+ }
- /* Produce armies in new cities if there is a city to attack. */
- if (counts.user_cities && cityp->prod == NOPIECE) {
- comp_set_prod (cityp, ARMY);
- return;
- }
+ /* Produce armies in new cities if there is a city to attack. */
+ if (counts.user_cities && cityp->prod == NOPIECE) {
+ comp_set_prod (cityp, ARMY);
+ return;
+ }
- /* Produce a TT and SAT if we don't have one. */
+ /* Produce a TT and SAT if we don't have one. */
- /* count # of cities producing each piece */
- for (i = 0; i < NUM_OBJECTS; i++)
- city_count[i] = 0;
+ /* count # of cities producing each piece */
+ for (i = 0; i < NUM_OBJECTS; i++)
+ city_count[i] = 0;
- total_cities = 0;
+ total_cities = 0;
- for (i = 0; i < NUM_CITY; i++)
+ for (i = 0; i < NUM_CITY; i++)
if (city[i].owner == COMP && city[i].prod != NOPIECE) {
- city_count[(int)city[i].prod] += 1;
- total_cities += 1;
+ city_count[(int)city[i].prod] += 1;
+ total_cities += 1;
}
- if (total_cities <= 10) ratio = ratio1;
- else if (total_cities <= 20) ratio = ratio2;
- else if (total_cities <= 30) ratio = ratio3;
- else ratio = ratio4;
+ if (total_cities <= 10)
+ ratio = ratio1;
+ else if (total_cities <= 20)
+ ratio = ratio2;
+ else if (total_cities <= 30)
+ ratio = ratio3;
+ else ratio = ratio4;
- /* if we have one army producer, and this is it, return */
- if (city_count[ARMY] == 1 && cityp->prod == ARMY) return;
+ /* if we have one army producer, and this is it, return */
+ if (city_count[ARMY] == 1 && cityp->prod == ARMY) return;
- /* first available non-lake becomes a tt producer */
- if (city_count[TRANSPORT] == 0) {
- if (!is_lake) {
- comp_set_prod (cityp, TRANSPORT);
- return;
- }
- /* if we have one army producer that is not on a lake, */
- /* produce armies here instead */
- if (city_count[ARMY] == 1) {
- for (i = 0; i < NUM_CITY; i++)
- if (city[i].owner == COMP && city[i].prod == ARMY) break;
-
- if (!lake (city[i].loc)) {
- comp_set_prod (cityp, ARMY);
- return;
- }
- }
+ /* first available non-lake becomes a tt producer */
+ if (city_count[TRANSPORT] == 0) {
+ if (!is_lake) {
+ comp_set_prod (cityp, TRANSPORT);
+ return;
}
-#if 0
- /* Now we need a SATELLITE. */
- if (cityp->prod == NOPIECE && city_count[SATELLITE] == 0) {
- comp_set_prod (cityp, SATELLITE);
+ /* if we have one army producer that is not on a lake, */
+ /* produce armies here instead */
+ if (city_count[ARMY] == 1) {
+ for (i = 0; i < NUM_CITY; i++)
+ if (city[i].owner == COMP && city[i].prod == ARMY) break;
+
+ if (!lake (city[i].loc)) {
+ comp_set_prod (cityp, ARMY);
return;
+ }
}
- if (cityp->prod == SATELLITE) return;
- /* "The satellites are out tonight." -- Lori Anderson */
+ }
+#if 0
+ /* Now we need a SATELLITE. */
+ if (cityp->prod == NOPIECE && city_count[SATELLITE] == 0) {
+ comp_set_prod (cityp, SATELLITE);
+ return;
+ }
+ if (cityp->prod == SATELLITE) return;
+ /* "The satellites are out tonight." -- Lori Anderson */
#endif
- /* don't change prod from armies if something on continent */
- if (cityp->prod == ARMY && interest) return;
+ /* don't change prod from armies if something on continent */
+ if (cityp->prod == ARMY && interest) return;
- /* Produce armies in new cities if there is a city to attack. */
- if (counts.unowned_cities && cityp->prod == NOPIECE) {
- comp_set_prod (cityp, ARMY);
- return;
- }
-
- /* Set production to item most needed. Continents with one
- city and nothing interesting may not produce armies. We
- set production for unset cities, and change production for
- cities that produce objects for which we have many city producers.
- Ship producers on lakes also get there production changed. */
+ /* Produce armies in new cities if there is a city to attack. */
+ if (counts.unowned_cities && cityp->prod == NOPIECE) {
+ comp_set_prod (cityp, ARMY);
+ return;
+ }
+
+ /* Set production to item most needed. Continents with one
+ city and nothing interesting may not produce armies. We
+ set production for unset cities, and change production for
+ cities that produce objects for which we have many city producers.
+ Ship producers on lakes also get there production changed. */
- interest = (counts.comp_cities != 1 || interest);
+ interest = (counts.comp_cities != 1 || interest);
- if (cityp->prod == NOPIECE
- || (cityp->prod == ARMY && counts.comp_cities == 1)
- || overproduced (cityp, city_count)
- || (cityp->prod > FIGHTER && is_lake) )
- comp_set_needed (cityp, city_count, interest, is_lake);
+ if (cityp->prod == NOPIECE
+ || (cityp->prod == ARMY && counts.comp_cities == 1)
+ || overproduced (cityp, city_count)
+ || (cityp->prod > FIGHTER && is_lake) )
+ comp_set_needed (cityp, city_count, interest, is_lake);
}
/*
void
comp_set_prod(city_info_t *cityp, int type)
{
- if (cityp->prod == type) return;
+ if (cityp->prod == type) return;
- pdebug ("Changing city prod at %d from %d to %d\n",loc_disp(cityp->loc), cityp->prod, type);
- cityp->prod = type;
- cityp->work = -(piece_attr[type].build_time / 5);
+ pdebug ("Changing city prod at %d from %d to %d\n",loc_disp(cityp->loc), cityp->prod, type);
+ cityp->prod = type;
+ cityp->work = -(piece_attr[type].build_time / 5);
}
/*
bool
overproduced(city_info_t *cityp, int *city_count)
{
- int i;
-
- for (i = 0; i < NUM_OBJECTS; i++) {
- /* return true if changing production would improve balance */
- if (i != cityp->prod
- && ((city_count[(int)cityp->prod] - 1) * ratio[i]
- > (city_count[i] + 1) * ratio[(int)cityp->prod]))
- return true;
- }
- return false;
+ int i;
+
+ for (i = 0; i < NUM_OBJECTS; i++) {
+ /* return true if changing production would improve balance */
+ if (i != cityp->prod
+ && ((city_count[(int)cityp->prod] - 1) * ratio[i]
+ > (city_count[i] + 1) * ratio[(int)cityp->prod]))
+ return true;
+ }
+ return false;
}
/*
void
comp_set_needed(city_info_t *cityp, int *city_count, bool army_ok, bool is_lake)
{
- int best_prod;
- int prod;
+ int best_prod;
+ int prod;
- if (!army_ok) city_count[ARMY] = INFINITY;
+ if (!army_ok) city_count[ARMY] = INFINITY;
- if (is_lake) { /* choose fighter or army */
- comp_set_prod (cityp, need_more (city_count, ARMY, FIGHTER));
- return;
- }
- /* don't choose fighter */
- city_count[FIGHTER] = INFINITY;
+ if (is_lake) { /* choose fighter or army */
+ comp_set_prod (cityp, need_more (city_count, ARMY, FIGHTER));
+ return;
+ }
+ /* don't choose fighter */
+ city_count[FIGHTER] = INFINITY;
- best_prod = ARMY; /* default */
- for (prod = 0; prod < NUM_OBJECTS; prod++) {
- best_prod = need_more (city_count, best_prod, prod);
- }
- comp_set_prod (cityp, best_prod);
+ best_prod = ARMY; /* default */
+ for (prod = 0; prod < NUM_OBJECTS; prod++) {
+ best_prod = need_more (city_count, best_prod, prod);
+ }
+ comp_set_prod (cityp, best_prod);
}
/*
bool
lake(loc_t loc)
{
- int cont_map[MAP_SIZE];
- scan_counts_t counts;
+ int cont_map[MAP_SIZE];
+ scan_counts_t counts;
- vmap_cont (cont_map, emap, loc, '+'); /* map lake */
- counts = vmap_cont_scan (cont_map, emap);
+ vmap_cont (cont_map, emap, loc, '+'); /* map lake */
+ counts = vmap_cont_scan (cont_map, emap);
- return !(counts.unowned_cities || counts.user_cities || counts.unexplored);
+ return !(counts.unowned_cities || counts.user_cities || counts.unexplored);
}
/*
static path_map_t path_map[MAP_SIZE];
void
-do_pieces(void) { /* move pieces */
- void cpiece_move();
-
- int i;
- piece_info_t *obj, *next_obj;
-
- for (i = 0; i < NUM_OBJECTS; i++) { /* loop through obj lists */
- for (obj = comp_obj[move_order[i]]; obj != NULL;
- obj = next_obj) { /* loop through objs in list */
- next_obj = obj->piece_link.next;
- cpiece_move (obj); /* yup; move the object */
- }
+do_pieces(void)
+{
+ void cpiece_move();
+
+ int i;
+ piece_info_t *obj, *next_obj;
+
+ for (i = 0; i < NUM_OBJECTS; i++) { /* loop through obj lists */
+ for (obj = comp_obj[move_order[i]]; obj != NULL;
+ obj = next_obj) { /* loop through objs in list */
+ next_obj = obj->piece_link.next;
+ cpiece_move (obj); /* yup; move the object */
}
+ }
}
/*
void
cpiece_move(piece_info_t *obj)
{
- void move1();
+ void move1();
- bool changed_loc;
- int max_hits;
- loc_t saved_loc;
- city_info_t *cityp;
+ bool changed_loc;
+ int max_hits;
+ loc_t saved_loc;
+ city_info_t *cityp;
- if (obj->type == SATELLITE) {
- move_sat (obj);
- return;
- }
+ if (obj->type == SATELLITE) {
+ move_sat (obj);
+ return;
+ }
- obj->moved = 0; /* not moved yet */
- changed_loc = false; /* not changed yet */
- max_hits = piece_attr[obj->type].max_hits;
-
- if (obj->type == FIGHTER) { /* init fighter range */
- cityp = find_city (obj->loc);
- if (cityp != NULL) obj->range = piece_attr[FIGHTER].range;
- }
+ obj->moved = 0; /* not moved yet */
+ changed_loc = false; /* not changed yet */
+ max_hits = piece_attr[obj->type].max_hits;
+
+ if (obj->type == FIGHTER) { /* init fighter range */
+ cityp = find_city (obj->loc);
+ if (cityp != NULL) obj->range = piece_attr[FIGHTER].range;
+ }
- while (obj->moved < obj_moves (obj)) {
- saved_loc = obj->loc; /* remember starting location */
- move1 (obj);
- if (saved_loc != obj->loc) changed_loc = true;
+ while (obj->moved < obj_moves (obj)) {
+ saved_loc = obj->loc; /* remember starting location */
+ move1 (obj);
+ if (saved_loc != obj->loc) changed_loc = true;
- if (obj->type == FIGHTER && obj->hits > 0) {
- 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", loc_disp(obj->loc));
- ksend ("Fighter at %d crashed and burned\n", loc_disp(obj->loc));
- kill_obj (obj, obj->loc); /* crash & burn */
- }
- }
+ if (obj->type == FIGHTER && obj->hits > 0) {
+ 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", loc_disp(obj->loc));
+ ksend ("Fighter at %d crashed and burned\n", loc_disp(obj->loc));
+ kill_obj (obj, obj->loc); /* crash & burn */
+ }
}
- /* if a boat is in port, damaged, and never moved, fix some damage */
- if (obj->hits > 0 /* live piece? */
- && !changed_loc /* object never changed location? */
- && obj->type != ARMY && obj->type != FIGHTER /* it is a boat? */
- && obj->hits != max_hits /* it is damaged? */
- && comp_map[obj->loc].contents == 'X') /* it is in port? */
+ }
+ /* if a boat is in port, damaged, and never moved, fix some damage */
+ if (obj->hits > 0 /* live piece? */
+ && !changed_loc /* object never changed location? */
+ && obj->type != ARMY && obj->type != FIGHTER /* it is a boat? */
+ && obj->hits != max_hits /* it is damaged? */
+ && comp_map[obj->loc].contents == 'X') /* it is in port? */
obj->hits++; /* fix some damage */
}
void
move1(piece_info_t *obj)
{
- void army_move(), transport_move(), fighter_move(), ship_move();
-
- switch (obj->type) {
- case ARMY: army_move (obj); break;
- case TRANSPORT: transport_move (obj); break;
- case FIGHTER: fighter_move (obj); break;
- default: ship_move (obj); break;
- }
+ void army_move(), transport_move(), fighter_move(), ship_move();
+
+ switch (obj->type) {
+ case ARMY: army_move (obj); break;
+ case TRANSPORT: transport_move (obj); break;
+ case FIGHTER: fighter_move (obj); break;
+ default: ship_move (obj); break;
+ }
}
/*
void
army_move(piece_info_t *obj)
{
- loc_t move_away();
- loc_t find_attack();
- void make_army_load_map(), make_unload_map(), make_tt_load_map();
- void board_ship();
+ loc_t move_away();
+ loc_t find_attack();
+ void make_army_load_map(), make_unload_map(), make_tt_load_map();
+ void board_ship();
- loc_t new_loc;
- path_map_t path_map2[MAP_SIZE];
- loc_t new_loc2;
- int cross_cost = 0; /* cost to enter water */
+ loc_t new_loc;
+ path_map_t path_map2[MAP_SIZE];
+ int cross_cost = 0; /* cost to enter water */
- obj->func = 0; /* army doesn't want a tt */
- if (vmap_at_sea (comp_map, obj->loc)) { /* army can't move? */
- (void) load_army (obj);
- obj->moved = piece_attr[ARMY].speed;
- if (!obj->ship) obj->func = 1; /* load army on ship */
- return;
- }
- if (obj->ship) /* is army on a transport? */
- new_loc = find_attack (obj->loc, army_attack, "+*");
- else new_loc = find_attack (obj->loc, army_attack, ".+*");
+ obj->func = 0; /* army doesn't want a tt */
+ if (vmap_at_sea (comp_map, obj->loc)) { /* army can't move? */
+ (void) load_army (obj);
+ obj->moved = piece_attr[ARMY].speed;
+ if (!obj->ship) obj->func = 1; /* load army on ship */
+ return;
+ }
+ if (obj->ship) /* is army on a transport? */
+ new_loc = find_attack (obj->loc, army_attack, "+*");
+ else new_loc = find_attack (obj->loc, army_attack, ".+*");
- if (new_loc != obj->loc) { /* something to attack? */
- attack (obj, new_loc); /* attack it */
- if (map[new_loc].contents == '.' /* moved to ocean? */
- && obj->hits > 0) { /* object still alive? */
- kill_obj (obj, new_loc);
- scan (user_map, new_loc); /* rescan for user */
- }
- return;
+ if (new_loc != obj->loc) { /* something to attack? */
+ attack (obj, new_loc); /* attack it */
+ if (map[new_loc].contents == '.' /* moved to ocean? */
+ && obj->hits > 0) { /* object still alive? */
+ kill_obj (obj, new_loc);
+ scan (user_map, new_loc); /* rescan for user */
}
- if (obj->ship) {
- if (obj->ship->func == 0) {
- if (!load_army (obj)) ABORT; /* load army on best ship */
- return; /* armies stay on a loading ship */
- }
- make_unload_map (amap, comp_map);
- new_loc = vmap_find_wlobj (path_map, amap, obj->loc, &tt_unload);
- move_objective (obj, path_map, new_loc, " ");
- return;
+ return;
+ }
+ if (obj->ship) {
+ if (obj->ship->func == 0) {
+ if (!load_army (obj)) ABORT; /* load army on best ship */
+ return; /* armies stay on a loading ship */
}
+ make_unload_map (amap, comp_map);
+ new_loc = vmap_find_wlobj (path_map, amap, obj->loc, &tt_unload);
+ move_objective (obj, path_map, new_loc, " ");
+ return;
+ }
- new_loc = vmap_find_lobj (path_map, comp_map, obj->loc, &army_fight);
+ new_loc = vmap_find_lobj (path_map, comp_map, obj->loc, &army_fight);
- if (new_loc != obj->loc) { /* something interesting on land? */
- switch (comp_map[new_loc].contents) {
- case 'A':
- case 'O':
- cross_cost = 60; /* high cost if enemy present */
- break;
- case '*':
- cross_cost = 30; /* medium cost for attackable city */
- break;
- case ' ':
- cross_cost = 14; /* low cost for exploring */
- break;
- default:
- ABORT;
- }
- cross_cost = path_map[new_loc].cost * 2 - cross_cost;
+ if (new_loc != obj->loc) { /* something interesting on land? */
+ switch (comp_map[new_loc].contents) {
+ case 'A':
+ case 'O':
+ cross_cost = 60; /* high cost if enemy present */
+ break;
+ case '*':
+ cross_cost = 30; /* medium cost for attackable city */
+ break;
+ case ' ':
+ cross_cost = 14; /* low cost for exploring */
+ break;
+ default:
+ ABORT;
}
- else cross_cost = INFINITY;
+ cross_cost = path_map[new_loc].cost * 2 - cross_cost;
+ }
+ else cross_cost = INFINITY;
- if (new_loc == obj->loc || cross_cost > 0) {
- /* see if there is something interesting to load */
- make_army_load_map (obj, amap, comp_map);
- new_loc2 = vmap_find_lwobj (path_map2, amap, obj->loc, &army_load, cross_cost);
+ if (new_loc == obj->loc || cross_cost > 0) {
+ loc_t new_loc2;
+ /* see if there is something interesting to load */
+ make_army_load_map (obj, amap, comp_map);
+ new_loc2 = vmap_find_lwobj (path_map2, amap, obj->loc, &army_load, cross_cost);
- if (new_loc2 != obj->loc) { /* found something? */
- board_ship (obj, path_map2, new_loc2);
- return;
- }
+ if (new_loc2 != obj->loc) { /* found something? */
+ board_ship (obj, path_map2, new_loc2);
+ return;
}
+ }
- move_objective (obj, path_map, new_loc, " ");
+ move_objective (obj, path_map, new_loc, " ");
}
/*
void
unmark_explore_locs(view_map_t *xmap)
{
- count_t 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;
+ for (i = 0; i < MAP_SIZE; i++)
+ if (map[i].on_board && xmap[i].contents == ' ')
+ xmap[i].contents = emap[i].contents;
}
/*
void
make_army_load_map(piece_info_t *obj, view_map_t *xmap, view_map_t *vmap)
{
- piece_info_t *p;
- int i;
+ piece_info_t *p;
+ int i;
- (void) memcpy (xmap, vmap, sizeof (view_map_t) * MAP_SIZE);
+ (void) memcpy (xmap, vmap, sizeof (view_map_t) * MAP_SIZE);
- /* mark loading transports or cities building transports */
- for (p = comp_obj[TRANSPORT]; p; p = p->piece_link.next)
+ /* mark loading transports or cities building transports */
+ for (p = comp_obj[TRANSPORT]; p; p = p->piece_link.next)
if (p->func == 0) /* loading tt? */
- xmap[p->loc].contents = '$';
+ xmap[p->loc].contents = '$';
- for (i = 0; i < NUM_CITY; i++)
+ for (i = 0; i < NUM_CITY; i++)
if (city[i].owner == COMP && city[i].prod == TRANSPORT) {
- if (nearby_load (obj, city[i].loc))
- xmap[city[i].loc].contents = 'x'; /* army is nearby so it can load */
- else if (nearby_count (city[i].loc) < piece_attr[TRANSPORT].capacity)
- xmap[city[i].loc].contents = 'x'; /* city needs armies */
+ if (nearby_load (obj, city[i].loc))
+ xmap[city[i].loc].contents = 'x'; /* army is nearby so it can load */
+ else if (nearby_count (city[i].loc) < piece_attr[TRANSPORT].capacity)
+ xmap[city[i].loc].contents = 'x'; /* city needs armies */
}
- if (print_vmap == 'A') print_xzoom (xmap);
+ if (print_vmap == 'A') print_xzoom (xmap);
}
/* Return true if an army is considered near a location for loading. */
count_t
nearby_count(loc_t loc)
{
- piece_info_t *obj;
- int count;
-
- count = 0;
- for (obj = comp_obj[ARMY]; obj; obj = obj->piece_link.next) {
- if (nearby_load (obj, loc)) count += 1;
- }
- return count;
+ piece_info_t *obj;
+ int count;
+
+ count = 0;
+ for (obj = comp_obj[ARMY]; obj; obj = obj->piece_link.next) {
+ if (nearby_load (obj, loc)) count += 1;
+ }
+ return count;
}
/* Make load map for a ship. */
void
make_tt_load_map(view_map_t *xmap, view_map_t *vmap)
{
- piece_info_t *p;
+ piece_info_t *p;
- (void) memcpy (xmap, vmap, sizeof (view_map_t) * MAP_SIZE);
+ (void) memcpy (xmap, vmap, sizeof (view_map_t) * MAP_SIZE);
- /* mark loading armies */
- for (p = comp_obj[ARMY]; p; p = p->piece_link.next)
+ /* mark loading armies */
+ for (p = comp_obj[ARMY]; p; p = p->piece_link.next)
if (p->func == 1) /* loading army? */
- xmap[p->loc].contents = '$';
+ xmap[p->loc].contents = '$';
- if (print_vmap == 'L') print_xzoom (xmap);
+ if (print_vmap == 'L')
+ print_xzoom (xmap);
}
/*
void
make_unload_map(view_map_t *xmap, view_map_t *vmap)
{
- count_t i;
- scan_counts_t counts;
+ count_t i;
+ scan_counts_t counts;
- (void) memcpy (xmap, vmap, sizeof (view_map_t) * MAP_SIZE);
- unmark_explore_locs (xmap);
+ (void) memcpy (xmap, vmap, sizeof (view_map_t) * MAP_SIZE);
+ unmark_explore_locs (xmap);
- for (i = 0; i < MAP_SIZE; i++)
- owncont_map[i] = 0; /* nothing marked */
+ for (i = 0; i < MAP_SIZE; i++)
+ owncont_map[i] = 0; /* nothing marked */
- for (i = 0; i < NUM_CITY; i++)
+ 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, '.');
- for (i = 0; i < MAP_SIZE; i++)
+ for (i = 0; i < MAP_SIZE; i++)
if (strchr ("O*", vmap[i].contents)) {
- int total_cities;
+ int total_cities;
- vmap_cont (tcont_map, xmap, i, '.'); /* map continent */
- counts = vmap_cont_scan (tcont_map, xmap);
+ vmap_cont (tcont_map, xmap, i, '.'); /* map continent */
+ counts = vmap_cont_scan (tcont_map, xmap);
- total_cities = counts.unowned_cities
- + counts.user_cities
- + counts.comp_cities;
+ total_cities = counts.unowned_cities
+ + counts.user_cities
+ + counts.comp_cities;
- if (total_cities > 9) total_cities = 0;
+ if (total_cities > 9) total_cities = 0;
- if (counts.user_cities && counts.comp_cities)
- xmap[i].contents = '0' + total_cities;
+ if (counts.user_cities && counts.comp_cities)
+ xmap[i].contents = '0' + total_cities;
- else if (counts.unowned_cities > counts.user_cities
- && counts.comp_cities == 0)
- xmap[i].contents = '0' + total_cities;
+ else if (counts.unowned_cities > counts.user_cities
+ && counts.comp_cities == 0)
+ xmap[i].contents = '0' + total_cities;
- else if (counts.user_cities == 1 && counts.comp_cities == 0)
- xmap[i].contents = '2';
+ else if (counts.user_cities == 1 && counts.comp_cities == 0)
+ xmap[i].contents = '2';
- else xmap[i].contents = '0';
+ else xmap[i].contents = '0';
}
- if (print_vmap == 'U') print_xzoom (xmap);
+ if (print_vmap == 'U') print_xzoom (xmap);
}
/*
void
board_ship(piece_info_t *obj, path_map_t *pmap, loc_t dest)
{
- if (!load_army (obj)) {
- obj->func = 1; /* loading */
- move_objective (obj, pmap, dest, "t.");
- }
+ if (!load_army (obj)) {
+ obj->func = 1; /* loading */
+ move_objective (obj, pmap, dest, "t.");
+ }
}
/*
piece_info_t *
find_best_tt(piece_info_t *best, loc_t loc)
{
- piece_info_t *p;
+ piece_info_t *p;
- for (p = map[loc].objp; p != NULL; p = p->loc_link.next)
+ for (p = map[loc].objp; p != NULL; p = p->loc_link.next)
if (p->type == TRANSPORT && obj_capacity (p) > p->count) {
- if (!best) best = p;
- else if (p->count >= best->count) best = p;
+ if (!best) best = p;
+ else if (p->count >= best->count) best = p;
}
- return best;
+ return best;
}
/*
bool
load_army(piece_info_t *obj)
{
- piece_info_t *p;
- int i;
- loc_t x_loc;
-
- p = find_best_tt (obj->ship, obj->loc); /* look here first */
-
- for (i = 0; i < 8; i++) { /* try surrounding squares */
- x_loc = obj->loc + dir_offset[i];
- if (map[x_loc].on_board)
- p = find_best_tt (p, x_loc);
-
- }
- if (!p) return false; /* no tt to be found */
-
- if (p->loc == obj->loc) { /* stay in same place */
- obj->moved = piece_attr[ARMY].speed;
- }
- else move_obj (obj, p->loc); /* move to square with ship */
-
- if (p->ship != obj->ship) { /* reload army to new ship */
- disembark (obj);
- embark (p, obj);
- }
- return true;
+ piece_info_t *p;
+ int i;
+ loc_t x_loc;
+
+ p = find_best_tt (obj->ship, obj->loc); /* look here first */
+
+ for (i = 0; i < 8; i++) { /* try surrounding squares */
+ x_loc = obj->loc + dir_offset[i];
+ if (map[x_loc].on_board)
+ p = find_best_tt (p, x_loc);
+
+ }
+ if (!p) return false; /* no tt to be found */
+
+ if (p->loc == obj->loc) { /* stay in same place */
+ obj->moved = piece_attr[ARMY].speed;
+ }
+ else move_obj (obj, p->loc); /* move to square with ship */
+
+ if (p->ship != obj->ship) { /* reload army to new ship */
+ disembark (obj);
+ embark (p, obj);
+ }
+ return true;
}
/*
loc_t
move_away(view_map_t *vmap, loc_t loc, char *terrain)
{
- loc_t new_loc;
- int i;
-
- for (i = 0; i < 8; i++) {
- new_loc = loc + dir_offset[i];
- if (map[new_loc].on_board
- && strchr (terrain, vmap[new_loc].contents))
- return (new_loc);
- }
- return (loc);
+ loc_t new_loc;
+ int i;
+
+ for (i = 0; i < 8; i++) {
+ new_loc = loc + dir_offset[i];
+ if (map[new_loc].on_board
+ && strchr (terrain, vmap[new_loc].contents))
+ return (new_loc);
+ }
+ return (loc);
}
/*
loc_t
find_attack(loc_t loc, char *obj_list, char *terrain)
{
- loc_t new_loc, best_loc;
- int i, best_val;
- char *p;
-
- best_loc = loc; /* nothing found yet */
- best_val = INFINITY;
- for (i = 0; i < 8; i++) {
- new_loc = loc + dir_offset[i];
-
- if (map[new_loc].on_board /* can we move here? */
- && strchr (terrain, map[new_loc].contents)) {
- p = strchr (obj_list, comp_map[new_loc].contents);
- if (p != NULL && p - obj_list < best_val) {
- best_val = p - obj_list;
- best_loc = new_loc;
- }
- }
+ loc_t new_loc, best_loc;
+ int i, best_val;
+ char *p;
+
+ best_loc = loc; /* nothing found yet */
+ best_val = INFINITY;
+ for (i = 0; i < 8; i++) {
+ new_loc = loc + dir_offset[i];
+
+ if (map[new_loc].on_board /* can we move here? */
+ && strchr (terrain, map[new_loc].contents)) {
+ p = strchr (obj_list, comp_map[new_loc].contents);
+ if (p != NULL && p - obj_list < best_val) {
+ best_val = p - obj_list;
+ best_loc = new_loc;
+ }
}
- return (best_loc);
+ }
+ return (best_loc);
}
/*
void
transport_move(piece_info_t *obj)
{
- void tt_do_move();
-
- loc_t new_loc;
-
- /* empty transports can attack */
- if (obj->count == 0) { /* empty? */
- obj->func = 0; /* transport is loading */
- new_loc = find_attack (obj->loc, tt_attack, ".");
- if (new_loc != obj->loc) { /* something to attack? */
- attack (obj, new_loc); /* attack it */
- return;
- }
+ void tt_do_move();
+
+ loc_t new_loc;
+
+ /* empty transports can attack */
+ if (obj->count == 0) { /* empty? */
+ obj->func = 0; /* transport is loading */
+ new_loc = find_attack (obj->loc, tt_attack, ".");
+ if (new_loc != obj->loc) { /* something to attack? */
+ attack (obj, new_loc); /* attack it */
+ return;
}
+ }
- if (obj->count == obj_capacity (obj)) /* full? */
- obj->func = 1; /* unloading */
+ if (obj->count == obj_capacity (obj)) /* full? */
+ obj->func = 1; /* unloading */
- if (obj->func == 0) { /* loading? */
- make_tt_load_map (amap, comp_map);
- new_loc = vmap_find_wlobj (path_map, amap, obj->loc, &tt_load);
+ if (obj->func == 0) { /* loading? */
+ make_tt_load_map (amap, comp_map);
+ new_loc = vmap_find_wlobj (path_map, amap, obj->loc, &tt_load);
- if (new_loc == obj->loc) { /* nothing to load? */
- (void) memcpy (amap, comp_map, MAP_SIZE * sizeof (view_map_t));
- unmark_explore_locs (amap);
- if (print_vmap == 'S') print_xzoom (amap);
- new_loc = vmap_find_wobj (path_map, amap, obj->loc,&tt_explore);
- }
-
- move_objective (obj, path_map, new_loc, "a ");
- }
- else {
- make_unload_map (amap, comp_map);
- new_loc = vmap_find_wlobj (path_map, amap, obj->loc, &tt_unload);
- move_objective (obj, path_map, new_loc, " ");
+ if (new_loc == obj->loc) { /* nothing to load? */
+ (void) memcpy (amap, comp_map, MAP_SIZE * sizeof (view_map_t));
+ unmark_explore_locs (amap);
+ if (print_vmap == 'S') print_xzoom (amap);
+ new_loc = vmap_find_wobj (path_map, amap, obj->loc,&tt_explore);
}
+
+ move_objective (obj, path_map, new_loc, "a ");
+ }
+ else {
+ make_unload_map (amap, comp_map);
+ new_loc = vmap_find_wlobj (path_map, amap, obj->loc, &tt_unload);
+ move_objective (obj, path_map, new_loc, " ");
+ }
}
/*
void
fighter_move(piece_info_t *obj)
{
- loc_t new_loc;
-
- new_loc = find_attack (obj->loc, fighter_attack, ".+");
- if (new_loc != obj->loc) { /* something to attack? */
- attack (obj, new_loc); /* attack it */
- return;
- }
- /* return to base if low on fuel */
- if (obj->range <= find_nearest_city (obj->loc, COMP, &new_loc) + 2) {
- if (new_loc != obj->loc)
- new_loc = vmap_find_dest (path_map, comp_map, obj->loc,
- new_loc, COMP, T_AIR);
- }
- else new_loc = obj->loc;
+ loc_t new_loc;
+
+ new_loc = find_attack (obj->loc, fighter_attack, ".+");
+ if (new_loc != obj->loc) { /* something to attack? */
+ attack (obj, new_loc); /* attack it */
+ return;
+ }
+ /* return to base if low on fuel */
+ if (obj->range <= find_nearest_city (obj->loc, COMP, &new_loc) + 2) {
+ if (new_loc != obj->loc)
+ new_loc = vmap_find_dest (path_map, comp_map, obj->loc,
+ new_loc, COMP, T_AIR);
+ }
+ else new_loc = obj->loc;
- if (new_loc == obj->loc) { /* no nearby city? */
- new_loc = vmap_find_aobj (path_map, comp_map, obj->loc,
- &fighter_fight);
- }
- move_objective (obj, path_map, new_loc, " ");
+ if (new_loc == obj->loc) { /* no nearby city? */
+ new_loc = vmap_find_aobj (path_map, comp_map, obj->loc,
+ &fighter_fight);
+ }
+ move_objective (obj, path_map, new_loc, " ");
}
/*
void
ship_move(piece_info_t *obj)
{
- loc_t new_loc;
- char *adj_list;
+ loc_t new_loc;
+ char *adj_list;
- if (obj->hits < piece_attr[obj->type].max_hits) { /* head to port */
- if (comp_map[obj->loc].contents == 'X') { /* stay in port */
- obj->moved = piece_attr[obj->type].speed;
- return;
- }
- new_loc = vmap_find_wobj (path_map, comp_map, obj->loc, &ship_repair);
- adj_list = ".";
+ if (obj->hits < piece_attr[obj->type].max_hits) { /* head to port */
+ if (comp_map[obj->loc].contents == 'X') { /* stay in port */
+ obj->moved = piece_attr[obj->type].speed;
+ return;
+ }
+ new_loc = vmap_find_wobj (path_map, comp_map, obj->loc, &ship_repair);
+ adj_list = ".";
+ }
+ else {
+ new_loc = find_attack (obj->loc, ship_attack, ".");
+ if (new_loc != obj->loc) { /* something to attack? */
+ attack (obj, new_loc); /* attack it */
+ return;
}
- else {
- new_loc = find_attack (obj->loc, ship_attack, ".");
- if (new_loc != obj->loc) { /* something to attack? */
- attack (obj, new_loc); /* attack it */
- return;
- }
- /* look for an objective */
- (void) memcpy (amap, comp_map, MAP_SIZE * sizeof (view_map_t));
- unmark_explore_locs (amap);
- if (print_vmap == 'S') print_xzoom (amap);
+ /* look for an objective */
+ (void) memcpy (amap, comp_map, MAP_SIZE * sizeof (view_map_t));
+ unmark_explore_locs (amap);
+ if (print_vmap == 'S') print_xzoom (amap);
- new_loc = vmap_find_wobj (path_map, amap, obj->loc,&ship_fight);
- adj_list = ship_fight.objectives;
- }
+ new_loc = vmap_find_wobj (path_map, amap, obj->loc,&ship_fight);
+ adj_list = ship_fight.objectives;
+ }
- move_objective (obj, path_map, new_loc, adj_list);
+ move_objective (obj, path_map, new_loc, adj_list);
}
/*
move_objective(piece_info_t *obj, path_map_t pathmap[],
loc_t new_loc, char *adj_list)
{
- char *terrain;
- char *attack_list;
- int d;
- int reuse; /* true iff we should reuse old map */
- loc_t old_loc;
- loc_t old_dest;
+ char *terrain;
+ int d;
+ int reuse; /* true iff we should reuse old map */
+ loc_t old_loc;
+ loc_t old_dest;
- 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, loc_disp(obj->loc), obj->func);
- return;
- }
- old_loc = obj->loc; /* remember where we are */
- old_dest = new_loc; /* and where we're going */
+ 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, loc_disp(obj->loc), obj->func);
+ return;
+ }
+ old_loc = obj->loc; /* remember where we are */
+ old_dest = new_loc; /* and where we're going */
- d = dist (new_loc, obj->loc);
- reuse = 1; /* try to reuse unless we learn otherwise */
+ d = dist (new_loc, obj->loc);
+ reuse = 1; /* try to reuse unless we learn otherwise */
- if (comp_map[new_loc].contents == ' ' && d == 2) { /* are we exploring? */
- vmap_mark_adjacent (pathmap, obj->loc);
- reuse = 0;
- }
- else vmap_mark_path (pathmap, comp_map, new_loc); /* find routes to destination */
+ if (comp_map[new_loc].contents == ' ' && d == 2) { /* are we exploring? */
+ vmap_mark_adjacent (pathmap, obj->loc);
+ reuse = 0;
+ }
+ else vmap_mark_path (pathmap, comp_map, new_loc); /* find routes to destination */
- /* path terrain and move terrain may differ */
- switch (obj->type) {
- case ARMY: terrain = "+"; break;
- case FIGHTER: terrain = "+.X"; break;
- default: terrain = ".X"; break;
- }
+ /* path terrain and move terrain may differ */
+ switch (obj->type) {
+ case ARMY: terrain = "+"; break;
+ case FIGHTER: terrain = "+.X"; break;
+ default: terrain = ".X"; break;
+ }
+ new_loc = vmap_find_dir (pathmap, comp_map, obj->loc,
+ terrain, adj_list);
+
+ if (new_loc == obj->loc /* path is blocked? */
+ && (obj->type != ARMY || !obj->ship)) { /* don't unblock armies on a ship */
+ vmap_mark_near_path (pathmap, obj->loc);
+ reuse = 0;
new_loc = vmap_find_dir (pathmap, comp_map, obj->loc,
terrain, adj_list);
+ }
- if (new_loc == obj->loc /* path is blocked? */
- && (obj->type != ARMY || !obj->ship)) { /* don't unblock armies on a ship */
- vmap_mark_near_path (pathmap, obj->loc);
- reuse = 0;
- new_loc = vmap_find_dir (pathmap, comp_map, obj->loc,
- terrain, adj_list);
- }
-
- /* encourage army to leave city */
- if (new_loc == obj->loc && map[obj->loc].cityp != NULL
- && obj->type == ARMY) {
- new_loc = move_away (comp_map, obj->loc, "+");
- reuse = 0;
- }
- if (new_loc == obj->loc) {
- obj->moved = piece_attr[obj->type].speed;
+ /* encourage army to leave city */
+ if (new_loc == obj->loc && map[obj->loc].cityp != NULL
+ && obj->type == ARMY) {
+ new_loc = move_away (comp_map, obj->loc, "+");
+ reuse = 0;
+ }
+ if (new_loc == obj->loc) {
+ 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, loc_disp(obj->loc), obj->func);
- }
- else move_obj (obj, new_loc);
+ if (obj->type == ARMY && obj->ship) ;
+ else pdebug ("Cannot move %d at %d toward objective; func=%d\n", obj->type, loc_disp(obj->loc), obj->func);
+ }
+ else move_obj (obj, new_loc);
- /* Try to make more moves using same path map. */
- if (reuse && obj->moved < obj_moves (obj) && obj->loc != old_dest) {
- /* check for immediate attack */
- switch (obj->type) {
- case FIGHTER:
- if (comp_map[old_dest].contents != 'X' /* watch fuel */
- && obj->range <= piece_attr[FIGHTER].range / 2)
- return;
- attack_list = fighter_attack;
- terrain = "+.";
- break;
- case ARMY:
- attack_list = army_attack;
- if (obj->ship) terrain = "+*";
- else terrain = "+.*";
- break;
- case TRANSPORT:
- terrain = ".*";
- if (obj->cargo) attack_list = tt_attack;
- else attack_list = "*O"; /* causes tt to wake up */
- break;
- default:
- attack_list = ship_attack;
- terrain = ".";
- break;
- }
- if (find_attack (obj->loc, attack_list, terrain) != obj->loc)
- return;
+ /* Try to make more moves using same path map. */
+ if (reuse && obj->moved < obj_moves (obj) && obj->loc != old_dest) {
+ char *attack_list;
+ /* check for immediate attack */
+ switch (obj->type) {
+ case FIGHTER:
+ if (comp_map[old_dest].contents != 'X' /* watch fuel */
+ && obj->range <= piece_attr[FIGHTER].range / 2)
+ return;
+ attack_list = fighter_attack;
+ terrain = "+.";
+ break;
+ case ARMY:
+ attack_list = army_attack;
+ if (obj->ship) terrain = "+*";
+ else terrain = "+.*";
+ break;
+ case TRANSPORT:
+ terrain = ".*";
+ if (obj->cargo) attack_list = tt_attack;
+ else attack_list = "*O"; /* causes tt to wake up */
+ break;
+ default:
+ attack_list = ship_attack;
+ terrain = ".";
+ break;
+ }
+ if (find_attack (obj->loc, attack_list, terrain) != obj->loc)
+ return;
- /* clear old path */
- pathmap[old_loc].terrain = T_UNKNOWN;
- for (d = 0; d < 8; d++) {
- new_loc = old_loc + dir_offset[d];
- pathmap[new_loc].terrain = T_UNKNOWN;
- }
- /* pathmap is already marked, but this should work */
- move_objective (obj, pathmap, old_dest, adj_list);
+ /* clear old path */
+ pathmap[old_loc].terrain = T_UNKNOWN;
+ for (d = 0; d < 8; d++) {
+ new_loc = old_loc + dir_offset[d];
+ pathmap[new_loc].terrain = T_UNKNOWN;
}
+ /* pathmap is already marked, but this should work */
+ move_objective (obj, pathmap, old_dest, adj_list);
+ }
}
/*
*/
void
-check_endgame(void) { /* see if game is over */
-
- int nuser_city, ncomp_city;
- int nuser_army, ncomp_army;
- piece_info_t *p;
- int i;
+check_endgame(void)
+{
+ int nuser_city, ncomp_city;
+ int nuser_army, ncomp_army;
+ piece_info_t *p;
+ int i;
- date += 1; /* one more turn has passed */
- if (win != 0) return; /* we already know game is over */
+ date += 1; /* one more turn has passed */
+ if (win != 0) return; /* we already know game is over */
- nuser_city = 0; /* nothing counted yet */
- ncomp_city = 0;
- nuser_army = 0;
- ncomp_army = 0;
+ nuser_city = 0; /* nothing counted yet */
+ ncomp_city = 0;
+ nuser_army = 0;
+ ncomp_army = 0;
- for (i = 0; i < NUM_CITY; i++) {
- if (city[i].owner == USER) nuser_city++;
- else if (city[i].owner == COMP) ncomp_city++;
- }
+ for (i = 0; i < NUM_CITY; i++) {
+ if (city[i].owner == USER) nuser_city++;
+ else if (city[i].owner == COMP) ncomp_city++;
+ }
- for (p = user_obj[ARMY]; p != NULL; p = p->piece_link.next)
- nuser_army++;
+ for (p = user_obj[ARMY]; p != NULL; p = p->piece_link.next)
+ nuser_army++;
- for (p = comp_obj[ARMY]; p != NULL; p = p->piece_link.next)
- ncomp_army++;
+ for (p = comp_obj[ARMY]; p != NULL; p = p->piece_link.next)
+ ncomp_army++;
- if (ncomp_city < nuser_city/3 && ncomp_army < nuser_army/3) {
- clear_screen ();
- prompt ("The computer acknowledges defeat. Do");
- ksend ("The computer acknowledges defeat.");
- error ("you wish to smash the rest of the enemy?");
-
- if (get_chx() != 'Y') empend ();
- announce ("\nThe enemy inadvertantly revealed its code used for");
- announce ("\nreceiving battle information. You can display what");
- announce ("\nthey've learned with the ''E'' command.");
- resigned = true;
- win = 2;
- automove = false;
- }
- else if (ncomp_city == 0 && ncomp_army == 0) {
- clear_screen ();
- announce ("The enemy is incapable of defeating you.\n");
- announce ("You are free to rape the empire as you wish.\n");
- announce ("There may be, however, remnants of the enemy fleet\n");
- announce ("to be routed out and destroyed.\n");
- win = 1;
- automove = false;
- }
- else if (nuser_city == 0 && nuser_army == 0) {
- clear_screen ();
- announce ("You have been rendered incapable of\n");
- announce ("defeating the rampaging enemy fascists! The\n");
- announce ("empire is lost. If you have any ships left, you\n");
- announce ("may attempt to harass enemy shipping.");
- win = 1;
- automove = false;
- }
+ if (ncomp_city < nuser_city/3 && ncomp_army < nuser_army/3) {
+ clear_screen ();
+ prompt ("The computer acknowledges defeat. Do");
+ ksend ("The computer acknowledges defeat.");
+ error ("you wish to smash the rest of the enemy?");
+
+ if (get_chx() != 'Y') empend ();
+ announce ("\nThe enemy inadvertantly revealed its code used for");
+ announce ("\nreceiving battle information. You can display what");
+ announce ("\nthey've learned with the ''E'' command.");
+ resigned = true;
+ win = 2;
+ automove = false;
+ }
+ else if (ncomp_city == 0 && ncomp_army == 0) {
+ clear_screen ();
+ announce ("The enemy is incapable of defeating you.\n");
+ announce ("You are free to rape the empire as you wish.\n");
+ announce ("There may be, however, remnants of the enemy fleet\n");
+ announce ("to be routed out and destroyed.\n");
+ win = 1;
+ automove = false;
+ }
+ else if (nuser_city == 0 && nuser_army == 0) {
+ clear_screen ();
+ announce ("You have been rendered incapable of\n");
+ announce ("defeating the rampaging enemy fascists! The\n");
+ announce ("empire is lost. If you have any ships left, you\n");
+ announce ("may attempt to harass enemy shipping.");
+ win = 1;
+ automove = false;
+ }
}
+
+/* end */
/*
Used for win announcements
*/
-void announce (char *msg) {
+void announce (char *msg)
+{
(void) addstr (msg);
}
trashed and no sector is shown on the screen.
*/
-void kill_display (void) {
- whose_map = UNOWNED;
+void kill_display (void)
+{
+ whose_map = UNOWNED;
}
/*
screen even if the location to be displayed is already on the screen.
*/
-void sector_change (void) {
- change_ok = true;
+void sector_change (void)
+{
+ change_ok = true;
}
/*
sector is not displayed, return -1.
*/
-int cur_sector (void) {
- if (whose_map != USER) return (-1);
- return (save_sector);
+int cur_sector (void)
+{
+ if (whose_map != USER)
+ return (-1);
+ return (save_sector);
}
/*
is not on the screen, we return -1.
*/
-loc_t cur_cursor (void) {
- if (whose_map != USER) return (-1);
- return (save_cursor);
+loc_t cur_cursor (void)
+{
+ if (whose_map != USER)
+ return (-1);
+ return (save_cursor);
}
/*
display_loc (int whose, view_map_t vmap[], loc_t loc)
/* whose is whose map to display; loc is location to display */
{
- if (change_ok || whose != whose_map || !on_screen (loc))
- print_sector (whose, vmap, loc_sector (loc));
+ if (change_ok || whose != whose_map || !on_screen (loc))
+ print_sector (whose, vmap, loc_sector (loc));
- show_loc (vmap, loc);
+ show_loc (vmap, loc);
}
/*
display_locx (int whose, view_map_t vmap[], loc_t loc)
/* whose is whose map to display; loc is location to display */
{
- if (whose == whose_map && on_screen (loc))
- show_loc (vmap, loc);
+ if (whose == whose_map && on_screen (loc))
+ show_loc (vmap, loc);
}
/*
void
show_loc (view_map_t vmap[], loc_t loc)
{
- int r, c;
+ int r, c;
- r = loc_row (loc);
- c = loc_col (loc);
- (void) move (r-ref_row+NUMTOPS, c-ref_col);
- disp_square(&vmap[loc]);
- save_cursor = loc; /* remember cursor location */
- (void) move (r-ref_row+NUMTOPS, c-ref_col);
+ r = loc_row (loc);
+ c = loc_col (loc);
+ (void) move (r-ref_row+NUMTOPS, c-ref_col);
+ disp_square(&vmap[loc]);
+ save_cursor = loc; /* remember cursor location */
+ (void) move (r-ref_row+NUMTOPS, c-ref_col);
}
/*
print_sector(int whose, view_map_t vmap[], int sector)
/* whose is USER or COMP, vmap is map to display, sector is sector to display */
{
- void display_screen();
+ void display_screen();
- int first_row, first_col, last_row, last_col;
- int display_rows, display_cols;
- int r, c;
+ int first_row, first_col, last_row, last_col;
+ int display_rows, display_cols;
+ int r, c;
- save_sector = sector; /* remember last sector displayed */
- change_ok = false; /* we are displaying a new sector */
+ save_sector = sector; /* remember last sector displayed */
+ change_ok = false; /* we are displaying a new sector */
- display_rows = lines - NUMTOPS - 1; /* num lines to display */
- display_cols = cols - NUMSIDES;
+ display_rows = lines - NUMTOPS - 1; /* num lines to display */
+ display_cols = cols - NUMSIDES;
- /* compute row and column edges of sector */
- first_row = sector_row (sector) * ROWS_PER_SECTOR;
- first_col = sector_col (sector) * COLS_PER_SECTOR;
- last_row = first_row + ROWS_PER_SECTOR - 1;
- last_col = first_col + COLS_PER_SECTOR - 1;
+ /* compute row and column edges of sector */
+ first_row = sector_row (sector) * ROWS_PER_SECTOR;
+ first_col = sector_col (sector) * COLS_PER_SECTOR;
+ last_row = first_row + ROWS_PER_SECTOR - 1;
+ last_col = first_col + COLS_PER_SECTOR - 1;
- if (!(whose == whose_map /* correct map is on screen? */
- && ref_row <= first_row /* top row on screen? */
- && ref_col <= first_col /* first col on screen? */
- && ref_row + display_rows - 1 >= last_row /* bot row on screen? */
- && ref_col + display_cols - 1 >= last_col)) /* last col on screen? */
+ if (!(whose == whose_map /* correct map is on screen? */
+ && ref_row <= first_row /* top row on screen? */
+ && ref_col <= first_col /* first col on screen? */
+ && ref_row + display_rows - 1 >= last_row /* bot row on screen? */
+ && ref_col + display_cols - 1 >= last_col)) /* last col on screen? */
(void) clear (); /* erase current screen */
- /* figure out first row and col to print; subtract half
- the extra lines from the first line */
+ /* figure out first row and col to print; subtract half
+ the extra lines from the first line */
- ref_row = first_row - (display_rows - ROWS_PER_SECTOR) / 2;
- ref_col = first_col - (display_cols - COLS_PER_SECTOR) / 2;
+ ref_row = first_row - (display_rows - ROWS_PER_SECTOR) / 2;
+ ref_col = first_col - (display_cols - COLS_PER_SECTOR) / 2;
- /* try not to go past bottom of map */
- if (ref_row + display_rows - 1 > MAP_HEIGHT - 1)
- ref_row = MAP_HEIGHT - 1 - (display_rows - 1);
+ /* try not to go past bottom of map */
+ if (ref_row + display_rows - 1 > MAP_HEIGHT - 1)
+ ref_row = MAP_HEIGHT - 1 - (display_rows - 1);
- /* never go past top of map */
- if (ref_row < 0) ref_row = 0;
+ /* never go past top of map */
+ if (ref_row < 0) ref_row = 0;
- /* same with columns */
- if (ref_col + display_cols - 1 > MAP_WIDTH - 1)
- ref_col = MAP_WIDTH - 1 - (display_cols - 1);
+ /* same with columns */
+ if (ref_col + display_cols - 1 > MAP_WIDTH - 1)
+ ref_col = MAP_WIDTH - 1 - (display_cols - 1);
- if (ref_col < 0) ref_col = 0;
+ if (ref_col < 0) ref_col = 0;
- whose_map = whose; /* remember whose map is displayed */
- display_screen (vmap);
+ whose_map = whose; /* remember whose map is displayed */
+ display_screen (vmap);
- /* print x-coordinates along bottom of screen */
- for (c = ref_col; c < ref_col + display_cols && c < MAP_WIDTH; c++)
+ /* print x-coordinates along bottom of screen */
+ for (c = ref_col; c < ref_col + display_cols && c < MAP_WIDTH; c++)
if (c % 10 == 0) {
- pos_str (lines-1, c-ref_col, "%d", c,0,0,0,0,0,0,0);
- }
- /* print y-coordinates along right of screen */
- for (r = ref_row; r < ref_row + display_rows && r < MAP_HEIGHT; r++) {
- if (r % 2 == 0)
- pos_str (r-ref_row+NUMTOPS, cols-NUMSIDES+1, "%2d", r,0,0,0,0,0,0,0);
- 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 %ld", sector, date);
- for (r = 0; jnkbuf[r] != '\0'; r++) {
- if (r+NUMTOPS >= MAP_HEIGHT) break;
- (void) move (r+NUMTOPS, cols-NUMSIDES+4);
- (void) addch ((chtype)jnkbuf[r]);
+ pos_str (lines-1, c-ref_col, "%d", c,0,0,0,0,0,0,0);
}
+ /* print y-coordinates along right of screen */
+ for (r = ref_row; r < ref_row + display_rows && r < MAP_HEIGHT; r++) {
+ if (r % 2 == 0)
+ pos_str (r-ref_row+NUMTOPS, cols-NUMSIDES+1, "%2d", r,0,0,0,0,0,0,0);
+ 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 %ld", sector, date);
+ for (r = 0; jnkbuf[r] != '\0'; r++) {
+ if (r+NUMTOPS >= MAP_HEIGHT) break;
+ (void) move (r+NUMTOPS, cols-NUMSIDES+4);
+ (void) addch ((chtype)jnkbuf[r]);
+ }
}
/*
static void disp_square(view_map_t *vp)
{
#ifdef A_COLOR
- chtype attr;
-
- switch(vp->contents)
- {
- case '+':
- attr = COLOR_PAIR(COLOR_GREEN);
- break;
- case '.':
- attr = COLOR_PAIR(COLOR_CYAN);
- break;
- case 'a':
- case 'f':
- case 'p':
- case 'd':
- case 'b':
- case 't':
- case 'c':
- case 's':
- case 'z':
- case 'X':
- attr = COLOR_PAIR(COLOR_RED);
- break;
- default:
- attr = COLOR_PAIR(COLOR_WHITE);
- break;
- }
- attron(attr);
+ chtype attr;
+
+ switch(vp->contents)
+ {
+ case '+':
+ attr = COLOR_PAIR(COLOR_GREEN);
+ break;
+ case '.':
+ attr = COLOR_PAIR(COLOR_CYAN);
+ break;
+ case 'a':
+ case 'f':
+ case 'p':
+ case 'd':
+ case 'b':
+ case 't':
+ case 'c':
+ case 's':
+ case 'z':
+ case 'X':
+ attr = COLOR_PAIR(COLOR_RED);
+ break;
+ default:
+ attr = COLOR_PAIR(COLOR_WHITE);
+ break;
+ }
+ attron(attr);
#endif /* A_COLOR */
- (void) addch ((chtype)vp->contents);
+ (void) addch ((chtype)vp->contents);
#ifdef A_COLOR
- attroff(attr);
- attron(COLOR_PAIR(COLOR_WHITE));
+ attroff(attr);
+ attron(COLOR_PAIR(COLOR_WHITE));
#endif /* A_COLOR */
}
void display_screen(view_map_t vmap[])
{
- int display_rows, display_cols;
- int r, c;
- loc_t t;
+ int display_rows, display_cols;
+ int r, c;
+ loc_t t;
- display_rows = lines - NUMTOPS - 1; /* num lines to display */
- display_cols = cols - NUMSIDES;
+ display_rows = lines - NUMTOPS - 1; /* num lines to display */
+ display_cols = cols - NUMSIDES;
- for (r = ref_row; r < ref_row + display_rows && r < MAP_HEIGHT; r++)
+ for (r = ref_row; r < ref_row + display_rows && r < MAP_HEIGHT; r++)
for (c = ref_col; c < ref_col + display_cols && c < MAP_WIDTH; c++) {
- t = row_col_loc (r, c);
- (void) move (r-ref_row+NUMTOPS, c-ref_col);
- disp_square(&vmap[t]);
+ t = row_col_loc (r, c);
+ (void) move (r-ref_row+NUMTOPS, c-ref_col);
+ disp_square(&vmap[t]);
}
}
move_cursor(loc_t *cursor, int offset)
/* cursor is current cursor position, offset is offset to add to cursor */
{
- loc_t t;
- int r, c;
+ loc_t t;
+ int r, c;
- t = *cursor + offset; /* proposed location */
- if (!map[t].on_board) return (false); /* trying to move off map */
- if (!on_screen (t)) return (false); /* loc is off screen */
+ t = *cursor + offset; /* proposed location */
+ if (!map[t].on_board) return (false); /* trying to move off map */
+ if (!on_screen (t)) return (false); /* loc is off screen */
- *cursor = t; /* update cursor position */
- save_cursor = *cursor;
+ *cursor = t; /* update cursor position */
+ save_cursor = *cursor;
- r = loc_row (save_cursor);
- c = loc_col (save_cursor);
- (void) move (r-ref_row+NUMTOPS, c-ref_col);
+ r = loc_row (save_cursor);
+ c = loc_col (save_cursor);
+ (void) move (r-ref_row+NUMTOPS, c-ref_col);
- return (true);
+ return (true);
}
/*
bool on_screen (loc_t loc)
{
- int new_r, new_c;
+ int new_r, new_c;
- new_r = loc_row (loc);
- new_c = loc_col (loc);
+ new_r = loc_row (loc);
+ new_c = loc_col (loc);
- if (new_r < ref_row /* past top of screen */
- || new_r - ref_row > lines - NUMTOPS - 1 /* past bot of screen? */
- || new_c < ref_col /* past left edge of screen? */
- || new_c - ref_col > cols - NUMSIDES) /* past right edge of screen? */
+ if (new_r < ref_row /* past top of screen */
+ || new_r - ref_row > lines - NUMTOPS - 1 /* past bot of screen? */
+ || new_c < ref_col /* past left edge of screen? */
+ || new_c - ref_col > cols - NUMSIDES) /* past right edge of screen? */
return (false);
- return (true);
+ return (true);
}
/* Print a view map for debugging. */
void
print_xzoom(view_map_t *vmap)
{
- print_zoom (vmap);
+ print_zoom (vmap);
#if 0
- prompt ("Hit a key: ",0,0,0,0,0,0,0,0);
- (void) get_chx (); /* wait for user */
+ prompt ("Hit a key: ",0,0,0,0,0,0,0,0);
+ (void) get_chx (); /* wait for user */
#endif
}
void
print_zoom(view_map_t *vmap)
{
- void print_zoom_cell ();
+ void print_zoom_cell ();
- int row_inc, col_inc;
- int r, c;
+ int row_inc, col_inc;
+ int r, c;
- kill_display ();
+ kill_display ();
- row_inc = (MAP_HEIGHT + lines - NUMTOPS - 1) / (lines - NUMTOPS);
- col_inc = (MAP_WIDTH + cols - 1) / (cols - 1);
+ row_inc = (MAP_HEIGHT + lines - NUMTOPS - 1) / (lines - NUMTOPS);
+ col_inc = (MAP_WIDTH + cols - 1) / (cols - 1);
- for (r = 0; r < MAP_HEIGHT; r += row_inc)
+ for (r = 0; r < MAP_HEIGHT; r += row_inc)
for (c = 0; c < MAP_WIDTH; c += col_inc)
- print_zoom_cell (vmap, r, c, row_inc, col_inc);
+ print_zoom_cell (vmap, r, c, row_inc, col_inc);
- pos_str (0, 0, "Round #%d", date,0,0,0,0,0,0,0);
+ pos_str (0, 0, "Round #%d", date,0,0,0,0,0,0,0);
- (void) refresh ();
+ (void) refresh ();
}
/*
print_zoom_cell(view_map_t *vmap,
int row, int col, int row_inc, int col_inc)
{
- int r, c;
- char cell;
+ int r, c;
+ char cell;
- cell = ' ';
- for (r = row; r < row + row_inc; r++)
+ cell = ' ';
+ for (r = row; r < row + row_inc; r++)
for (c = col; c < col + col_inc; c++)
- if (strchr (zoom_list, vmap[row_col_loc(r,c)].contents)
+ if (strchr (zoom_list, vmap[row_col_loc(r,c)].contents)
< strchr (zoom_list, cell))
- cell = vmap[row_col_loc(r,c)].contents;
+ cell = vmap[row_col_loc(r,c)].contents;
- (void) move (row/row_inc + NUMTOPS, col/col_inc);
- (void) addch ((chtype)cell);
+ (void) move (row/row_inc + NUMTOPS, col/col_inc);
+ (void) addch ((chtype)cell);
}
/*
void
print_pzoom(char *s, path_map_t *pmap, view_map_t *vmap)
{
- void print_pzoom_cell();
+ void print_pzoom_cell();
- int row_inc, col_inc;
- int r, c;
+ int row_inc, col_inc;
+ int r, c;
- kill_display ();
+ kill_display ();
- row_inc = (MAP_HEIGHT + lines - NUMTOPS - 1) / (lines - NUMTOPS);
- col_inc = (MAP_WIDTH + cols - 1) / (cols - 1);
+ row_inc = (MAP_HEIGHT + lines - NUMTOPS - 1) / (lines - NUMTOPS);
+ col_inc = (MAP_WIDTH + cols - 1) / (cols - 1);
- for (r = 0; r < MAP_HEIGHT; r += row_inc)
+ for (r = 0; r < MAP_HEIGHT; r += row_inc)
for (c = 0; c < MAP_WIDTH; c += col_inc)
- print_pzoom_cell (pmap, vmap, r, c, row_inc, col_inc);
+ print_pzoom_cell (pmap, vmap, r, c, row_inc, col_inc);
- prompt (s,0,0,0,0,0,0,0,0);
- (void) get_chx (); /* wait for user */
+ prompt (s,0,0,0,0,0,0,0,0);
+ (void) get_chx (); /* wait for user */
- (void) refresh ();
+ (void) refresh ();
}
/*
print_pzoom_cell(path_map_t *pmap, view_map_t *vmap,
int row, int col, int row_inc, int col_inc)
{
- int r, c;
- int sum, d;
- char cell;
+ int r, c;
+ int sum, d;
+ char cell;
- sum = 0;
- d = 0; /* number of squares in cell */
+ sum = 0;
+ d = 0; /* number of squares in cell */
- for (r = row; r < row + row_inc; r++)
+ for (r = row; r < row + row_inc; r++)
for (c = col; c < col + col_inc; c++) {
- sum += pmap[row_col_loc(r,c)].cost;
- d += 1;
+ sum += pmap[row_col_loc(r,c)].cost;
+ d += 1;
}
- sum /= d;
+ sum /= d;
- if (pmap[row_col_loc(row,col)].terrain == T_PATH) cell = '-';
- else if (sum < 0) cell = '!';
- else if (sum == INFINITY/2) cell = 'P';
- else if (sum == INFINITY) cell = ' ';
- else if (sum > INFINITY/2) cell = 'U';
- else {
- sum %= 36;
- if (sum < 10) cell = sum + '0';
- else cell = sum - 10 + 'a';
- }
+ if (pmap[row_col_loc(row,col)].terrain == T_PATH) cell = '-';
+ else if (sum < 0) cell = '!';
+ else if (sum == INFINITY/2) cell = 'P';
+ else if (sum == INFINITY) cell = ' ';
+ else if (sum > INFINITY/2) cell = 'U';
+ else {
+ sum %= 36;
+ if (sum < 10) cell = sum + '0';
+ else cell = sum - 10 + 'a';
+ }
- if (cell == ' ')
- print_zoom_cell (vmap, row, col, row_inc, col_inc);
- else {
- (void) move (row/row_inc + NUMTOPS, col/col_inc);
- (void) addch ((chtype)cell);
- }
+ if (cell == ' ')
+ print_zoom_cell (vmap, row, col, row_inc, col_inc);
+ else {
+ (void) move (row/row_inc + NUMTOPS, col/col_inc);
+ (void) addch ((chtype)cell);
+ }
}
/*
void
display_score(void)
{
- pos_str (1, cols-12, " User Comp",0,0,0,0,0,0,0,0);
- pos_str (2, cols-12, "%5d %5d", user_score, comp_score,0,0,0,0,0,0);
+ pos_str (1, cols-12, " User Comp");
+ pos_str (2, cols-12, "%5d %5d", user_score, comp_score);
}
/*
void
clreol(int linep, int colp)
{
- (void) move (linep, colp);
- (void) clrtoeol();
+ (void) move (linep, colp);
+ (void) clrtoeol();
}
/*
void
ttinit(void)
{
- (void) initscr();
- (void) noecho();
- (void) crmode();
+ (void) initscr();
+ (void) noecho();
+ (void) crmode();
#ifdef A_COLOR
- init_colors();
+ init_colors();
#endif /* A_COLOR */
- lines = LINES;
- cols = COLS;
- if (lines > MAP_HEIGHT + NUMTOPS + 1)
- lines = MAP_HEIGHT + NUMTOPS + 1;
- if (cols > MAP_WIDTH + NUMSIDES)
- cols = MAP_WIDTH + NUMSIDES;
+ lines = LINES;
+ cols = COLS;
+ if (lines > MAP_HEIGHT + NUMTOPS + 1)
+ lines = MAP_HEIGHT + NUMTOPS + 1;
+ if (cols > MAP_WIDTH + NUMSIDES)
+ cols = MAP_WIDTH + NUMSIDES;
}
void
clear_screen(void)
{
- (void) clear ();
- (void) refresh ();
- kill_display ();
+ (void) clear ();
+ (void) refresh ();
+ kill_display ();
}
/*
void
complain(void)
{
- (void) beep ();
+ (void) beep ();
}
/*
void
redisplay(void)
{
- (void) refresh ();
+ (void) refresh ();
}
void
redraw(void)
{
- (void) clearok (curscr, TRUE);
- (void) refresh ();
+ (void) clearok (curscr, TRUE);
+ (void) refresh ();
}
/*
void
delay(void)
{
- int t = delay_time;
- int i = 500;
- (void) refresh ();
- if (t > i) {
- (void) move (LINES - 1, 0);
- }
- for (; t > 0; t -= i) {
- (void) napms ((t > i) ? i : t); /* pause a bit */
- if (t > i) {
+ int t = delay_time;
+ int i = 500;
+ (void) refresh ();
+ if (t > i) {
+ (void) move (LINES - 1, 0);
+ }
+ for (; t > 0; t -= i) {
+ (void) napms ((t > i) ? i : t); /* pause a bit */
+ if (t > i) {
addstr ("*");
refresh ();
- }
- }
+ }
+ }
}
/*
void
close_disp(void)
{
- (void) move (LINES - 1, 0);
- (void) clrtoeol ();
- (void) refresh ();
- (void) endwin ();
+ (void) move (LINES - 1, 0);
+ (void) clrtoeol ();
+ (void) refresh ();
+ (void) endwin ();
}
/*
*/
void
-pos_str1(int row, int col, char *str, ...)
+pos_str(int row, int col, char *str, ...)
{
- va_list ap;
- char junkbuf[STRSIZE];
+ va_list ap;
+ char junkbuf[STRSIZE];
- va_start(ap, str);
- (void) move (row, col);
- vsprintf(junkbuf, str, ap);
- (void) addstr (junkbuf);
- va_end(ap);
+ va_start(ap, str);
+ (void) move (row, col);
+ vsprintf(junkbuf, str, ap);
+ (void) addstr (junkbuf);
+ va_end(ap);
}
void
-pos_str(int row, int col, char *str, ...)
+pos_str1(int row, int col, char *str, ...)
{
- va_list ap;
- char junkbuf[STRSIZE];
+ va_list ap;
+ char junkbuf[STRSIZE];
- va_start(ap, str);
- (void) move (row, col);
- vsprintf(junkbuf, str, ap);
- (void) addstr (junkbuf);
- va_end(ap);
+ va_start(ap, str);
+ (void) move (row, col);
+ vsprintf(junkbuf, str, ap);
+ (void) addstr (junkbuf);
+ va_end(ap);
}
/*
void
print_movie_cell(char *mbuf, int row, int col, int row_inc, int col_inc)
{
- int r, c;
- char cell;
+ int r, c;
+ char cell;
- cell = ' ';
- for (r = row; r < row + row_inc; r++)
+ cell = ' ';
+ for (r = row; r < row + row_inc; r++)
for (c = col; c < col + col_inc; c++)
- if (strchr (zoom_list, mbuf[row_col_loc(r,c)])
+ if (strchr (zoom_list, mbuf[row_col_loc(r,c)])
< strchr (zoom_list, cell))
- cell = mbuf[row_col_loc(r,c)];
+ cell = mbuf[row_col_loc(r,c)];
- (void) move (row/row_inc + NUMTOPS, col/col_inc);
- (void) addch ((chtype)cell);
+ (void) move (row/row_inc + NUMTOPS, col/col_inc);
+ (void) addch ((chtype)cell);
}
+
+/* end */
void
edit(loc_t edit_cursor)
{
- char e_cursor();
- void e_leave(), e_print(), e_random();
- void e_stasis(), e_end(), e_wake(), e_sleep();
- void e_info(), e_prod(), e_help(), e_explore();
- void e_fill(), e_land(), e_city_func(), e_transport();
- void e_attack(), e_repair();
-
- loc_t path_start;
- int path_type;
- char e;
+ char e_cursor();
+ void e_leave(), e_print(), e_random();
+ void e_stasis(), e_end(), e_wake(), e_sleep();
+ void e_info(), e_prod(), e_help(), e_explore();
+ void e_fill(), e_land(), e_city_func(), e_transport();
+ void e_attack(), e_repair();
+
+ loc_t path_start;
+ int path_type;
+ char e;
- path_start = -1; /* not building a path yet */
+ path_start = -1; /* not building a path yet */
- for (;;) { /* until user gives command to leave */
- display_loc_u (edit_cursor); /* position cursor */
- e = e_cursor (&edit_cursor); /* handle cursor movement */
-
- switch (e) {
- case 'B': /* change city production */
- e_prod (edit_cursor);
- break;
- case 'F': /* fill */
- e_fill (edit_cursor);
- break;
- case 'G': /* explore */
- e_explore (edit_cursor);
- break;
- case 'H': /* help */
- e_help ();
- break;
- case 'I': /* directional stasis */
- e_stasis (edit_cursor);
- break;
- case 'K': /* wake up anything and everything */
- e_wake (edit_cursor);
- break;
- case 'L': /* land plane */
- e_land (edit_cursor);
- break;
- case 'M': /* start move to location */
- path_type = NOPIECE;
- e_move (&path_start, edit_cursor);
- break;
- case 'N': /* end move to location */
- e_end (&path_start, edit_cursor, path_type);
- break;
- case 'O': /* leave display mode */
- e_leave ();
- return;
- case 'P': /* print new sector */
- e_print (&edit_cursor);
- break;
- case 'R': /* make piece move randomly */
- e_random (edit_cursor);
- break;
- case 'S': /* sleep */
- e_sleep (edit_cursor);
- break;
- case 'T': /* transport army */
- e_transport (edit_cursor);
- break;
- case 'U': /* repair ship */
- e_repair (edit_cursor);
- break;
- case 'V': /* set city function */
- e_city_func (&path_start, edit_cursor, &path_type);
- break;
- case 'Y': /* set army func to attack */
- e_attack (edit_cursor);
- break;
- case '?': /* request info */
- e_info (edit_cursor);
- break;
- case '\014': /* control-L */
- redraw ();
- break;
- default: /* bad command? */
- huh ();
- break;
- }
+ for (;;) { /* until user gives command to leave */
+ display_loc_u (edit_cursor); /* position cursor */
+ e = e_cursor (&edit_cursor); /* handle cursor movement */
+
+ switch (e) {
+ case 'B': /* change city production */
+ e_prod (edit_cursor);
+ break;
+ case 'F': /* fill */
+ e_fill (edit_cursor);
+ break;
+ case 'G': /* explore */
+ e_explore (edit_cursor);
+ break;
+ case 'H': /* help */
+ e_help ();
+ break;
+ case 'I': /* directional stasis */
+ e_stasis (edit_cursor);
+ break;
+ case 'K': /* wake up anything and everything */
+ e_wake (edit_cursor);
+ break;
+ case 'L': /* land plane */
+ e_land (edit_cursor);
+ break;
+ case 'M': /* start move to location */
+ path_type = NOPIECE;
+ e_move (&path_start, edit_cursor);
+ break;
+ case 'N': /* end move to location */
+ e_end (&path_start, edit_cursor, path_type);
+ break;
+ case 'O': /* leave display mode */
+ e_leave ();
+ return;
+ case 'P': /* print new sector */
+ e_print (&edit_cursor);
+ break;
+ case 'R': /* make piece move randomly */
+ e_random (edit_cursor);
+ break;
+ case 'S': /* sleep */
+ e_sleep (edit_cursor);
+ break;
+ case 'T': /* transport army */
+ e_transport (edit_cursor);
+ break;
+ case 'U': /* repair ship */
+ e_repair (edit_cursor);
+ break;
+ case 'V': /* set city function */
+ e_city_func (&path_start, edit_cursor, &path_type);
+ break;
+ case 'Y': /* set army func to attack */
+ e_attack (edit_cursor);
+ break;
+ case '?': /* request info */
+ e_info (edit_cursor);
+ break;
+ case '\014': /* control-L */
+ redraw ();
+ break;
+ default: /* bad command? */
+ huh ();
+ break;
}
+ }
}
/*
char
e_cursor(loc_t *edit_cursor)
{
- chtype e;
- int p;
+ chtype e;
+ int p;
- /* set up terminal */
- (void) crmode ();
+ /* set up terminal */
+ (void) crmode ();
+ (void) refresh ();
+ e = getch ();
+ topini (); /* clear any error messages */
+
+ for (;;) {
+ p = direction (e);
+ if (p == -1) break;
+
+ if (!move_cursor (edit_cursor, dir_offset[p]))
+ (void) beep ();
+
(void) refresh ();
e = getch ();
- topini (); /* clear any error messages */
-
- for (;;) {
- p = direction (e);
- if (p == -1) break;
-
- if (!move_cursor (edit_cursor, dir_offset[p]))
- (void) beep ();
-
- (void) refresh ();
- e = getch ();
- }
- (void) nocrmode (); /* reset terminal */
- return toupper(e);
+ }
+ (void) nocrmode (); /* reset terminal */
+ return toupper(e);
}
/*
*/
void
-e_leave(void) {
+e_leave(void)
+{
}
/*
void
e_print(loc_t *edit_cursor)
{
- int sector;
+ int sector;
- sector = get_range ("New Sector? ", 0, NUM_SECTORS-1);
+ sector = get_range ("New Sector? ", 0, NUM_SECTORS-1);
- /* position cursor at center of sector */
- *edit_cursor = sector_loc (sector);
- sector_change (); /* allow change of sector */
+ /* position cursor at center of sector */
+ *edit_cursor = sector_loc (sector);
+ sector_change (); /* allow change of sector */
}
/*
void
e_set_func(loc_t loc, long func)
{
- piece_info_t *obj;
- obj = find_obj_at_loc (loc);
- if (obj != NULL && obj->owner == USER) {
- obj->func = func;
- return;
- }
- huh (); /* no object here */
+ piece_info_t *obj;
+ obj = find_obj_at_loc (loc);
+ if (obj != NULL && obj->owner == USER) {
+ obj->func = func;
+ return;
+ }
+ huh (); /* no object here */
}
/* Set the function of a city for some piece. */
void
e_set_city_func(city_info_t *cityp, int type, long func)
{
- cityp->func[type] = func;
+ cityp->func[type] = func;
}
/*
void
e_random(loc_t loc)
{
- e_set_func (loc, RANDOM);
+ e_set_func (loc, RANDOM);
}
void
e_city_random(city_info_t *cityp, int type)
{
- e_set_city_func (cityp, type, RANDOM);
+ e_set_city_func (cityp, type, RANDOM);
}
/*
void
e_fill(loc_t loc)
{
- if (user_map[loc].contents == 'T' || user_map[loc].contents == 'C')
- e_set_func (loc, FILL);
- else huh ();
+ if (user_map[loc].contents == 'T' || user_map[loc].contents == 'C')
+ e_set_func (loc, FILL);
+ else huh ();
}
void
e_city_fill(city_info_t *cityp, int type)
{
- if (type == TRANSPORT || type == CARRIER)
- e_set_city_func (cityp, type, FILL);
- else huh ();
+ if (type == TRANSPORT || type == CARRIER)
+ e_set_city_func (cityp, type, FILL);
+ else huh ();
}
/*
void
e_explore(loc_t loc)
{
- e_set_func (loc, EXPLORE);
+ e_set_func (loc, EXPLORE);
}
void
e_city_explore(city_info_t *cityp, loc_t type)
{
- e_set_city_func (cityp, type, EXPLORE);
+ e_set_city_func (cityp, type, EXPLORE);
}
/*
void
e_land(loc_t loc)
{
- if (user_map[loc].contents == 'F')
- e_set_func (loc, LAND);
- else huh ();
+ if (user_map[loc].contents == 'F')
+ e_set_func (loc, LAND);
+ else huh ();
}
/*
void
e_transport(loc_t loc)
{
- if (user_map[loc].contents == 'A')
- e_set_func (loc, WFTRANSPORT);
- else huh ();
+ if (user_map[loc].contents == 'A')
+ e_set_func (loc, WFTRANSPORT);
+ else huh ();
}
/*
void
e_attack(loc_t loc)
{
- if (user_map[loc].contents == 'A')
- e_set_func (loc, ARMYATTACK);
- else huh ();
+ if (user_map[loc].contents == 'A')
+ e_set_func (loc, ARMYATTACK);
+ else huh ();
}
void
e_city_attack(city_info_t *cityp, int type)
{
- if (type == ARMY)
- e_set_city_func (cityp, type, ARMYATTACK);
- else huh ();
+ if (type == ARMY)
+ e_set_city_func (cityp, type, ARMYATTACK);
+ else huh ();
}
/*
void
e_repair(loc_t loc)
{
- if (strchr ("PDSTBC", user_map[loc].contents))
- e_set_func (loc, REPAIR);
- else huh ();
+ if (strchr ("PDSTBC", user_map[loc].contents))
+ e_set_func (loc, REPAIR);
+ else huh ();
}
void
void
e_stasis(loc_t loc)
{
- char e;
- char *p;
+ char e;
+ char *p;
- if (!isupper (user_map[loc].contents)) huh (); /* no object here */
- else if (user_map[loc].contents == 'X') huh ();
- else {
- e = get_chx(); /* get a direction */
- p = strchr (dirs, e);
-
- if (p == NULL) huh ();
- else e_set_func (loc, (long)(MOVE_N - (p - dirs)));
- }
+ if (!isupper (user_map[loc].contents))
+ huh (); /* no object here */
+ else if (user_map[loc].contents == 'X')
+ huh ();
+ else {
+ e = get_chx(); /* get a direction */
+ p = strchr (dirs, e);
+
+ if (p == NULL)
+ huh ();
+ else
+ e_set_func (loc, (long)(MOVE_N - (p - dirs)));
+ }
}
void
e_city_stasis(city_info_t *cityp, int type)
{
- char e;
- char *p;
+ char e;
+ char *p;
- e = get_chx(); /* get a direction */
- p = strchr (dirs, e);
+ e = get_chx(); /* get a direction */
+ p = strchr (dirs, e);
- if (p == NULL) huh ();
- else e_set_city_func (cityp, type, (long)(MOVE_N - (p - dirs)));
+ if (p == NULL)
+ huh ();
+ else
+ e_set_city_func (cityp, type, (long)(MOVE_N - (p - dirs)));
}
/*
void
e_wake(loc_t loc)
{
- city_info_t *cityp;
- piece_info_t *obj;
- int i;
-
- cityp = find_city (loc);
- if (cityp != NULL) {
- for (i = 0; i < NUM_OBJECTS; i++)
- cityp->func[i] = NOFUNC;
- }
- for (obj = map[loc].objp; obj != NULL; obj = obj->loc_link.next)
- obj->func = NOFUNC;
+ city_info_t *cityp;
+ piece_info_t *obj;
+ int i;
+
+ cityp = find_city (loc);
+ if (cityp != NULL) {
+ for (i = 0; i < NUM_OBJECTS; i++)
+ cityp->func[i] = NOFUNC;
+ }
+ for (obj = map[loc].objp; obj != NULL; obj = obj->loc_link.next)
+ obj->func = NOFUNC;
}
void
e_city_wake(city_info_t *cityp, int type)
{
- e_set_city_func (cityp, type, NOFUNC);
+ e_set_city_func (cityp, type, NOFUNC);
}
/*
void
e_city_func(loc_t *path_start, loc_t loc, int *path_type)
{
- int type;
- char e;
- city_info_t *cityp;
-
- cityp = find_city (loc);
- if (!cityp || cityp->owner != USER) {
- huh ();
- return;
- }
-
- type = get_piece_name();
- if (type == NOPIECE) {
- huh ();
- return;
- }
+ int type;
+ char e;
+ city_info_t *cityp;
+
+ cityp = find_city (loc);
+ if (!cityp || cityp->owner != USER) {
+ huh ();
+ return;
+ }
+
+ type = get_piece_name();
+ if (type == NOPIECE) {
+ huh ();
+ return;
+ }
- e = get_chx ();
+ e = get_chx ();
- switch (e) {
- case 'F': /* fill */
- e_city_fill (cityp, type);
- break;
- case 'G': /* explore */
- e_city_explore (cityp, type);
- break;
- case 'I': /* directional stasis */
- e_city_stasis (cityp, type);
- break;
- case 'K': /* turn off function */
- e_city_wake (cityp, type);
- break;
- case 'M': /* start move to location */
- *path_type = type;
- e_move (path_start, loc);
- break;
- case 'R': /* make piece move randomly */
- e_city_random (cityp, type);
- break;
- case 'U': /* repair ship */
- e_city_repair (cityp, type);
- break;
- case 'Y': /* set army func to attack */
- e_city_attack (cityp, type);
- break;
- default: /* bad command? */
- huh ();
- break;
- }
+ switch (e) {
+ case 'F': /* fill */
+ e_city_fill (cityp, type);
+ break;
+ case 'G': /* explore */
+ e_city_explore (cityp, type);
+ break;
+ case 'I': /* directional stasis */
+ e_city_stasis (cityp, type);
+ break;
+ case 'K': /* turn off function */
+ e_city_wake (cityp, type);
+ break;
+ case 'M': /* start move to location */
+ *path_type = type;
+ e_move (path_start, loc);
+ break;
+ case 'R': /* make piece move randomly */
+ e_city_random (cityp, type);
+ break;
+ case 'U': /* repair ship */
+ e_city_repair (cityp, type);
+ break;
+ case 'Y': /* set army func to attack */
+ e_city_attack (cityp, type);
+ break;
+ default: /* bad command? */
+ huh ();
+ break;
+ }
}
/*
void
e_move(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? */
- else *path_start = loc;
+ if (!isupper(user_map[loc].contents)) huh (); /* nothing there? */
+ else if (user_map[loc].contents == 'X') huh (); /* enemy city? */
+ else *path_start = loc;
}
/*
void
e_end(loc_t *path_start, loc_t loc, int path_type)
{
- city_info_t *cityp;
+ city_info_t *cityp;
- if (*path_start == -1) huh (); /* no path started? */
- else if (path_type == NOPIECE) e_set_func (*path_start, loc);
- else {
- cityp = find_city (*path_start);
- ASSERT (cityp);
- e_set_city_func (cityp, path_type, loc);
- }
-
- *path_start = -1; /* remember no path in progress */
+ if (*path_start == -1) huh (); /* no path started? */
+ else if (path_type == NOPIECE) e_set_func (*path_start, loc);
+ else {
+ cityp = find_city (*path_start);
+ ASSERT (cityp);
+ e_set_city_func (cityp, path_type, loc);
+ }
+
+ *path_start = -1; /* remember no path in progress */
}
/*
void
e_sleep(loc_t loc)
{
- if (user_map[loc].contents == 'O') huh (); /* can't sleep a city */
- else e_set_func (loc, SENTRY);
+ if (user_map[loc].contents == 'O') huh (); /* can't sleep a city */
+ else e_set_func (loc, SENTRY);
}
/*
void
e_info(loc_t edit_cursor)
{
- void e_city_info(loc_t), e_piece_info(loc_t edit_cursor, char ab);
-
- char ab;
-
- ab = user_map[edit_cursor].contents;
-
- if (ab == 'O') e_city_info (edit_cursor);
- else if (ab == 'X' && debug) e_city_info (edit_cursor);
- else if ((ab >= 'A') && (ab <= 'T'))
- e_piece_info (edit_cursor, ab);
- else if ((ab >= 'a') && (ab <= 't') && (debug))
- e_piece_info (edit_cursor, ab);
- else huh ();
+ void e_city_info(loc_t), e_piece_info(loc_t edit_cursor, char ab);
+
+ char ab;
+
+ ab = user_map[edit_cursor].contents;
+
+ if (ab == 'O')
+ e_city_info (edit_cursor);
+ else if (ab == 'X' && debug)
+ e_city_info (edit_cursor);
+ else if ((ab >= 'A') && (ab <= 'T'))
+ e_piece_info (edit_cursor, ab);
+ else if ((ab >= 'a') && (ab <= 't') && (debug))
+ e_piece_info (edit_cursor, ab);
+ else
+ huh ();
}
/*
void
e_piece_info(loc_t edit_cursor, char ab)
{
- piece_info_t *obj;
- int type;
- char *p;
+ piece_info_t *obj;
+ int type;
+ char *p;
- ab = toupper (ab);
- p = strchr (type_chars, ab);
- type = p - type_chars;
+ ab = toupper (ab);
+ p = strchr (type_chars, ab);
+ type = p - type_chars;
- obj = find_obj (type, edit_cursor);
- ASSERT (obj != NULL);
- describe_obj (obj);
+ obj = find_obj (type, edit_cursor);
+ ASSERT (obj != NULL);
+ describe_obj (obj);
}
/*
void
e_city_info(loc_t edit_cursor)
{
- piece_info_t *obj;
- city_info_t *cityp;
- int f, s;
- char func_buf[STRSIZE];
- char temp_buf[STRSIZE];
- char junk_buf2[STRSIZE];
-
- error (""); /* clear line */
-
- f = 0; /* no fighters counted yet */
- for (obj = map[edit_cursor].objp; obj != NULL;
- obj = obj->loc_link.next)
- if (obj->type == FIGHTER) f++;
-
- s = 0; /* no ships counted yet */
- for (obj = map[edit_cursor].objp; obj != NULL;
- obj = obj->loc_link.next)
- if (obj->type >= DESTROYER) s++;
-
- if (f == 1 && s == 1)
- (void) sprintf (jnkbuf, "1 fighter landed, 1 ship docked");
- else if (f == 1)
- (void) sprintf (jnkbuf, "1 fighter landed, %d ships docked", s);
- else if (s == 1)
- (void) sprintf (jnkbuf, "%d fighters landed, 1 ship docked", f);
- else (void) sprintf (jnkbuf, "%d fighters landed, %d ships docked", f, s);
-
- cityp = find_city (edit_cursor);
- ASSERT (cityp != NULL);
-
- *func_buf = 0; /* nothing in buffer */
- for (s = 0; s < NUM_OBJECTS; s++) { /* for each piece */
- if (cityp->func[s] < 0)
- (void) sprintf (temp_buf, "%c:%s; ",
- piece_attr[s].sname,
- func_name[FUNCI(cityp->func[s])]);
- else (void) sprintf (temp_buf, "%c: %d;",
- piece_attr[s].sname,
- loc_disp(cityp->func[s]));
+ piece_info_t *obj;
+ city_info_t *cityp;
+ int f, s;
+ char func_buf[STRSIZE];
+ char temp_buf[STRSIZE];
+ char junk_buf2[STRSIZE];
+
+ error (""); /* clear line */
+
+ f = 0; /* no fighters counted yet */
+ for (obj = map[edit_cursor].objp; obj != NULL;
+ obj = obj->loc_link.next)
+ if (obj->type == FIGHTER) f++;
+
+ s = 0; /* no ships counted yet */
+ for (obj = map[edit_cursor].objp; obj != NULL;
+ obj = obj->loc_link.next)
+ if (obj->type >= DESTROYER) s++;
+
+ if (f == 1 && s == 1)
+ (void) sprintf (jnkbuf, "1 fighter landed, 1 ship docked");
+ else if (f == 1)
+ (void) sprintf (jnkbuf, "1 fighter landed, %d ships docked", s);
+ else if (s == 1)
+ (void) sprintf (jnkbuf, "%d fighters landed, 1 ship docked", f);
+ else
+ (void) sprintf (jnkbuf, "%d fighters landed, %d ships docked", f, s);
+
+ cityp = find_city (edit_cursor);
+ ASSERT (cityp != NULL);
+
+ *func_buf = 0; /* nothing in buffer */
+ for (s = 0; s < NUM_OBJECTS; s++) { /* for each piece */
+ if (cityp->func[s] < 0)
+ (void) sprintf (temp_buf, "%c:%s; ",
+ piece_attr[s].sname,
+ func_name[FUNCI(cityp->func[s])]);
+ else (void) sprintf (temp_buf, "%c: %d;",
+ piece_attr[s].sname,
+ loc_disp(cityp->func[s]));
- (void) strcat (func_buf, temp_buf);
- }
+ (void) strcat (func_buf, temp_buf);
+ }
- (void) sprintf (junk_buf2,
- "City at location %d will complete %s on round %ld",
- loc_disp(cityp->loc),
- piece_attr[(int)cityp->prod].article,
- date + piece_attr[(int)cityp->prod].build_time - cityp->work);
+ (void) sprintf (junk_buf2,
+ "City at location %d will complete %s on round %ld",
+ loc_disp(cityp->loc),
+ piece_attr[(int)cityp->prod].article,
+ date + piece_attr[(int)cityp->prod].build_time - cityp->work);
- info (junk_buf2, jnkbuf, func_buf);
+ info (junk_buf2, jnkbuf, func_buf);
}
/*
void
e_prod(loc_t loc)
{
- city_info_t *cityp;
+ city_info_t *cityp;
- cityp = find_city (loc);
+ cityp = find_city (loc);
- if (cityp == NULL) huh (); /* no city? */
- else set_prod (cityp);
+ if (cityp == NULL) huh (); /* no city? */
+ else set_prod (cityp);
}
/*
*/
void
-e_help(void) {
- help (help_edit, edit_lines);
- prompt ("Press any key to continue: ");
- (void) get_chx ();
+e_help(void)
+{
+ help (help_edit, edit_lines);
+ prompt ("Press any key to continue: ");
+ (void) get_chx ();
}
+
+/* end */
*/
void
-empire(void) {
- void do_command(char);
- void print_zoom();
-
- char order;
- int turn = 0;
-
- ttinit (); /* init tty */
- rndini (); /* init random number generator */
-
- clear_screen (); /* nothing on screen */
- pos_str (7, 0, "EMPIRE, Version 5.00 site Amdahl 1-Apr-1988");
- pos_str (8, 0, "Detailed directions are in EMPIRE.DOC\n");
- (void) redisplay ();
-
- if (!restore_game ()) /* try to restore previous game */
- init_game (); /* otherwise init a new game */
-
- /* Command loop starts here. */
-
- for (;;) { /* until user quits */
- if (automove) { /* don't ask for cmd in auto mode */
- user_move ();
- comp_move (1);
- if (++turn % save_interval == 0)
- save_game ();
- }
- else {
- prompt (""); /* blank top line */
- void redisplay();
- prompt ("Your orders? ");
- order = get_chx (); /* get a command */
- do_command (order);
- }
+empire(void)
+{
+ void do_command(char);
+ void print_zoom();
+
+ char order;
+ int turn = 0;
+
+ ttinit (); /* init tty */
+ rndini (); /* init random number generator */
+
+ clear_screen (); /* nothing on screen */
+ pos_str (7, 0, "EMPIRE, Version 5.00 site Amdahl 1-Apr-1988");
+ pos_str (8, 0, "Detailed directions are in EMPIRE.DOC\n");
+ (void) redisplay ();
+
+ if (!restore_game ()) /* try to restore previous game */
+ init_game (); /* otherwise init a new game */
+
+ /* Command loop starts here. */
+
+ for (;;) { /* until user quits */
+ if (automove) { /* don't ask for cmd in auto mode */
+ user_move ();
+ comp_move (1);
+ if (++turn % save_interval == 0)
+ save_game ();
+ }
+ else {
+ prompt (""); /* blank top line */
+ void redisplay();
+ prompt ("Your orders? ");
+ order = get_chx (); /* get a command */
+ do_command (order);
}
+ }
}
/*
void
do_command(char orders)
{
- void c_debug(char order), c_quit(void), c_sector(void), c_map(void);
- void c_give(void);
-
- char e;
- int ncycle;
-
- switch (orders) {
- case 'A': /* turn on auto move mode */
- automove = true;
- error ("Now in Auto-Mode");
- user_move ();
- comp_move (1);
- save_game ();
- break;
-
- case 'C': /* give a city to the computer */
- c_give ();
- break;
+ void c_debug(char order), c_quit(void), c_sector(void), c_map(void);
+ void c_give(void);
+
+ char e;
+ int ncycle;
+
+ switch (orders) {
+ case 'A': /* turn on auto move mode */
+ automove = true;
+ error ("Now in Auto-Mode");
+ user_move ();
+ comp_move (1);
+ save_game ();
+ break;
+
+ case 'C': /* give a city to the computer */
+ c_give ();
+ break;
- case 'D': /* display round number */
- error ("Round #%d", date);
- break;
-
- case 'E': /* examine enemy map */
- if (resigned) c_examine ();
- else huh (); /* illegal command */
- break;
-
- case 'F': /* print map to file */
- c_map ();
- break;
-
- case 'G': /* give one free enemy move */
- comp_move (1);
- break;
-
- case 'H': /* help */
- help (help_cmd, cmd_lines);
- break;
-
- case 'J': /* edit mode */
- ncycle = cur_sector ();
- if (ncycle == -1) ncycle = 0;
- edit (sector_loc (ncycle));
- break;
-
- case 'M': /* move */
- user_move ();
- comp_move (1);
- save_game ();
- break;
-
- case 'N': /* give enemy free moves */
- ncycle = getint ("Number of free enemy moves: ");
- comp_move (ncycle);
- save_game ();
- break;
-
- case 'P': /* print a sector */
- c_sector ();
- break;
-
- case '\026': /* some interrupt */
- case 'Q': /* quit */
- c_quit ();
- break;
-
- case 'R': /* restore game */
- clear_screen ();
- e = restore_game ();
- break;
-
- case 'S': /* save game */
- save_game ();
- break;
+ case 'D': /* display round number */
+ error ("Round #%d", date);
+ break;
+
+ case 'E': /* examine enemy map */
+ if (resigned) c_examine ();
+ else huh (); /* illegal command */
+ break;
+
+ case 'F': /* print map to file */
+ c_map ();
+ break;
+
+ case 'G': /* give one free enemy move */
+ comp_move (1);
+ break;
+
+ case 'H': /* help */
+ help (help_cmd, cmd_lines);
+ break;
+
+ case 'J': /* edit mode */
+ ncycle = cur_sector ();
+ if (ncycle == -1) ncycle = 0;
+ edit (sector_loc (ncycle));
+ break;
+
+ case 'M': /* move */
+ user_move ();
+ comp_move (1);
+ save_game ();
+ break;
+
+ case 'N': /* give enemy free moves */
+ ncycle = getint ("Number of free enemy moves: ");
+ comp_move (ncycle);
+ save_game ();
+ break;
+
+ case 'P': /* print a sector */
+ c_sector ();
+ break;
+
+ case '\026': /* some interrupt */
+ case 'Q': /* quit */
+ c_quit ();
+ break;
+
+ case 'R': /* restore game */
+ clear_screen ();
+ e = restore_game ();
+ break;
+
+ case 'S': /* save game */
+ save_game ();
+ break;
- case 'T': /* trace: toggle save_movie flag */
- save_movie = !save_movie;
- if (save_movie) comment ("Saving movie screens to 'empmovie.dat'.");
- else comment ("No longer saving movie screens.");
- break;
-
- case 'W': /* watch movie */
- if (resigned || debug) replay_movie ();
- else error ("You cannot watch movie until computer resigns.");
- break;
-
- case 'Z': /* print compressed map */
- print_zoom (user_map);
- break;
-
- case '\014': /* redraw the screen */
- redraw ();
- break;
-
- case '+': /* change debug state */
- e = get_chx();
- if ( e == '+' ) debug = true;
- else if ( e == '-' ) debug = false;
- else huh ();
- break;
-
- default:
- if (debug) c_debug (orders); /* debug */
- else huh (); /* illegal command */
- break;
- }
- e = e; /* keep lint quiet */
+ case 'T': /* trace: toggle save_movie flag */
+ save_movie = !save_movie;
+ if (save_movie) comment ("Saving movie screens to 'empmovie.dat'.");
+ else comment ("No longer saving movie screens.");
+ break;
+
+ case 'W': /* watch movie */
+ if (resigned || debug) replay_movie ();
+ else error ("You cannot watch movie until computer resigns.");
+ break;
+
+ case 'Z': /* print compressed map */
+ print_zoom (user_map);
+ break;
+
+ case '\014': /* redraw the screen */
+ redraw ();
+ break;
+
+ case '+': /* change debug state */
+ e = get_chx();
+ if ( e == '+' ) debug = true;
+ else if ( e == '-' ) debug = false;
+ else huh ();
+ break;
+
+ default:
+ if (debug) c_debug (orders); /* debug */
+ else huh (); /* illegal command */
+ break;
+ }
+ e = e; /* keep lint quiet */
}
/*
*/
void
-c_give(void) {
- int unowned[NUM_CITY];
- count_t i, count;
-
- count = 0; /* nothing in list yet */
- for (i = 0; i < NUM_CITY; i++) {
- if (city[i].owner == UNOWNED) {
- unowned[count] = i; /* remember this city */
- count += 1;
- }
- }
- if (count == 0) {
- error ("There are no unowned cities.");
- ksend ("There are no unowned cities.");
- return;
+c_give(void)
+{
+ int unowned[NUM_CITY];
+ count_t i, count;
+
+ count = 0; /* nothing in list yet */
+ for (i = 0; i < NUM_CITY; i++) {
+ if (city[i].owner == UNOWNED) {
+ unowned[count] = i; /* remember this city */
+ count += 1;
}
- i = irand (count);
- i = unowned[i]; /* get city index */
- city[i].owner = COMP;
- city[i].prod = NOPIECE;
- city[i].work = 0;
- scan (comp_map, city[i].loc);
+ }
+ if (count == 0) {
+ error ("There are no unowned cities.");
+ ksend ("There are no unowned cities.");
+ return;
+ }
+ i = irand (count);
+ i = unowned[i]; /* get city index */
+ city[i].owner = COMP;
+ city[i].prod = NOPIECE;
+ city[i].work = 0;
+ scan (comp_map, city[i].loc);
}
/*
void
c_debug(char order)
{
- char e;
+ char e;
- switch (order) {
- case '#' : c_examine (); break;
- case '%' : c_movie (); break;
+ switch (order) {
+ case '#' : c_examine (); break;
+ case '%' : c_movie (); break;
- case '@': /* change trace state */
- e = get_chx();
- if ( e == '+' ) trace_pmap = true;
- else if ( e == '-' ) trace_pmap = false;
- else huh ();
- break;
-
- case '$': /* change print_debug state */
- e = get_chx();
- if ( e == '+' ) print_debug = true;
- else if ( e == '-' ) print_debug = false;
- else huh ();
- break;
-
- case '&': /* change print_vmap state */
- print_vmap = get_chx();
- break;
-
- default: huh (); break;
- }
+ case '@': /* change trace state */
+ e = get_chx();
+ if ( e == '+' )
+ trace_pmap = true;
+ else if ( e == '-' )
+ trace_pmap = false;
+ else
+ huh ();
+ break;
+
+ case '$': /* change print_debug state */
+ e = get_chx();
+ if ( e == '+' )
+ print_debug = true;
+ else if ( e == '-' )
+ print_debug = false;
+ else
+ huh ();
+ break;
+
+ case '&': /* change print_vmap state */
+ print_vmap = get_chx();
+ break;
+
+ default: huh (); break;
+ }
}
/*
*/
void
-c_quit(void) {
- if (getyn ("QUIT - Are you sure? ")) {
- empend ();
- }
+c_quit(void)
+{
+ if (getyn ("QUIT - Are you sure? ")) {
+ empend ();
+ }
}
/*
*/
void
-c_sector(void) {
- int num;
+c_sector(void)
+{
+ int num;
- num = get_range ("Sector number? ", 0, NUM_SECTORS-1);
- print_sector_u (num);
+ num = get_range ("Sector number? ", 0, NUM_SECTORS-1);
+ print_sector_u (num);
}
/*
*/
void
-c_map(void) {
- FILE *f;
- int i, j;
- char line[MAP_HEIGHT+2];
-
- prompt ("Filename? ");
- get_str (jnkbuf, STRSIZE);
-
- f = fopen (jnkbuf, "w");
- if (f == NULL) {
- error ("I can't open that file.");
- return;
+c_map(void)
+{
+ FILE *f;
+ int i, j;
+ char line[MAP_HEIGHT+2];
+
+ prompt ("Filename? ");
+ get_str (jnkbuf, STRSIZE);
+
+ f = fopen (jnkbuf, "w");
+ if (f == NULL) {
+ error ("I can't open that file.");
+ return;
+ }
+ for (i = 0; i < MAP_WIDTH; i++) { /* for each column */
+ for (j = MAP_HEIGHT-1; j >= 0; j--) { /* for each row */
+ line[MAP_HEIGHT-1-j] = user_map[row_col_loc(j,i)].contents;
}
- for (i = 0; i < MAP_WIDTH; i++) { /* for each column */
- for (j = MAP_HEIGHT-1; j >= 0; j--) { /* for each row */
- line[MAP_HEIGHT-1-j] = user_map[row_col_loc(j,i)].contents;
- }
- j = MAP_HEIGHT-1;
- while (j >= 0 && line[j] == ' ') /* scan off trailing blanks */
- j -= 1;
+ j = MAP_HEIGHT-1;
+ while (j >= 0 && line[j] == ' ') /* scan off trailing blanks */
+ j -= 1;
- line[++j] = '\n';
- line[++j] = 0; /* trailing null */
- (void) fputs (line, f);
- }
- (void) fclose (f);
+ line[++j] = '\n';
+ line[++j] = 0; /* trailing null */
+ (void) fputs (line, f);
+ }
+ (void) fclose (f);
}
/*
*/
void
-c_examine(void) {
- int num;
+c_examine(void)
+{
+ int num;
- num = get_range ("Sector number? ", 0, NUM_SECTORS-1);
- print_sector_c (num);
+ num = get_range ("Sector number? ", 0, NUM_SECTORS-1);
+ print_sector_c (num);
}
/*
*/
void
-c_movie(void) {
- for (;;) {
- comp_move (1);
- print_zoom (comp_map);
- save_game ();
+c_movie(void)
+{
+ for (;;) {
+ comp_move (1);
+ print_zoom (comp_map);
+ save_game ();
#ifdef PROFILE
- if (date == 125) empend();
+ if (date == 125) empend();
#endif
- }
+ }
}
+
+/* end */
pieces on the board.
*/
-void init_game(void) {
- void make_map(void), place_cities(void);
-
- count_t i;
-
- kill_display (); /* nothing on screen */
- automove = false;
- resigned = false;
- debug = false;
- print_debug = false;
- print_vmap = false;
- trace_pmap = false;
- save_movie = false;
- win = 0;
- date = 0; /* no date yet */
- user_score = 0;
- comp_score = 0;
+void init_game(void)
+{
+ void make_map(void), place_cities(void);
+
+ count_t i;
+
+ kill_display (); /* nothing on screen */
+ automove = false;
+ resigned = false;
+ debug = false;
+ print_debug = false;
+ print_vmap = false;
+ trace_pmap = false;
+ save_movie = false;
+ win = 0;
+ date = 0; /* no date yet */
+ user_score = 0;
+ comp_score = 0;
- for (i = 0; i < MAP_SIZE; i++) {
- user_map[i].contents = ' '; /* nothing seen yet */
- user_map[i].seen = 0;
- comp_map[i].contents = ' ';
- comp_map[i].seen = 0;
- }
- for (i = 0; i < NUM_OBJECTS; i++) {
- user_obj[i] = NULL;
- comp_obj[i] = NULL;
+ for (i = 0; i < MAP_SIZE; i++) {
+ user_map[i].contents = ' '; /* nothing seen yet */
+ user_map[i].seen = 0;
+ comp_map[i].contents = ' ';
+ comp_map[i].seen = 0;
+ }
+ for (i = 0; i < NUM_OBJECTS; i++) {
+ user_obj[i] = NULL;
+ comp_obj[i] = NULL;
+ }
+ free_list = NULL; /* nothing free yet */
+ for (i = 0; i < LIST_SIZE; i++) { /* for each object */
+ piece_info_t *obj = &(object[i]);
+ obj->hits = 0; /* mark object as dead */
+ obj->owner = UNOWNED;
+ LINK (free_list, obj, piece_link);
+ }
+
+ make_map (); /* make land and water */
+
+ do {
+ for (i = 0; i < MAP_SIZE; i ++) { /* remove cities */
+ if (map[i].contents == '*')
+ map[i].contents = '+'; /* land */
}
- free_list = NULL; /* nothing free yet */
- for (i = 0; i < LIST_SIZE; i++) { /* for each object */
- piece_info_t *obj = &(object[i]);
- obj->hits = 0; /* mark object as dead */
- obj->owner = UNOWNED;
- LINK (free_list, obj, piece_link);
- }
-
- make_map (); /* make land and water */
-
- do {
- for (i = 0; i < MAP_SIZE; i ++) { /* remove cities */
- if (map[i].contents == '*')
- map[i].contents = '+'; /* land */
- }
- place_cities (); /* place cities on map */
- } while (!select_cities ()); /* choose a city for each player */
+ place_cities (); /* place cities on map */
+ } while
+ (!select_cities ()); /* choose a city for each player */
}
/*
static int height[2][MAP_SIZE];
static int height_count[MAX_HEIGHT+1];
-void make_map(void) {
- int from, to, k;
- 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);
-
- from = 0;
- to = 1;
- for (i = 0; i < SMOOTH; i++) { /* smooth the map */
- for (j = 0; j < MAP_SIZE; j++) {
- sum = height[from][j];
- for (k = 0; k < 8; k++) {
- loc = j + dir_offset[k];
- /* edges get smoothed in a wierd fashion */
- if (loc < 0 || loc >= MAP_SIZE) loc = j;
- sum += height[from][loc];
- }
- height[to][j] = sum / 9;
+void make_map(void)
+{
+ int from, to, k;
+ 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);
+
+ from = 0;
+ to = 1;
+ for (i = 0; i < SMOOTH; i++) { /* smooth the map */
+ for (j = 0; j < MAP_SIZE; j++) {
+ sum = height[from][j];
+ for (k = 0; k < 8; k++) {
+ loc = j + dir_offset[k];
+ /* edges get smoothed in a wierd fashion */
+ if (loc < 0 || loc >= MAP_SIZE) loc = j;
+ sum += height[from][loc];
}
- k = to; /* swap to and from */
- to = from;
- from = k;
+ height[to][j] = sum / 9;
}
-
- /* count the number of cells at each height */
- for (i = 0; i <= MAX_HEIGHT; i++)
- height_count[i] = 0;
-
- for (i = 0; i <= MAP_SIZE; i++)
- height_count[height[from][i]]++;
-
- /* find the water line */
- loc = MAX_HEIGHT; /* default to all water */
- sum = 0;
- for (i = 0; i <= MAX_HEIGHT; i++) {
- sum += height_count[i];
- if (sum * 100 / MAP_SIZE > WATER_RATIO && sum >= NUM_CITY) {
- loc = i; /* this is last height that is water */
- break;
- }
+ k = to; /* swap to and from */
+ to = from;
+ from = k;
+ }
+
+ /* count the number of cells at each height */
+ for (i = 0; i <= MAX_HEIGHT; i++)
+ height_count[i] = 0;
+
+ for (i = 0; i <= MAP_SIZE; i++)
+ height_count[height[from][i]]++;
+
+ /* find the water line */
+ loc = MAX_HEIGHT; /* default to all water */
+ sum = 0;
+ for (i = 0; i <= MAX_HEIGHT; i++) {
+ sum += height_count[i];
+ if (sum * 100 / MAP_SIZE > WATER_RATIO && sum >= NUM_CITY) {
+ loc = i; /* this is last height that is water */
+ break;
}
+ }
- /* 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 */
+ /* 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].objp = NULL; /* nothing in cell yet */
- map[i].cityp = NULL;
+ map[i].objp = NULL; /* nothing in cell yet */
+ map[i].cityp = NULL;
- j = loc_col (i);
- k = loc_row (i);
+ j = loc_col (i);
+ k = loc_row (i);
- map[i].on_board = !(j == 0 || j == MAP_WIDTH-1
- || k == 0 || k == MAP_HEIGHT-1);
- }
+ map[i].on_board = !(j == 0 || j == MAP_WIDTH-1
+ || k == 0 || k == MAP_HEIGHT-1);
+ }
}
/*
/* avoid compiler problems with large automatic arrays */
static loc_t land[MAP_SIZE];
-void place_cities(void) {
- count_t regen_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 */
- while (placed < NUM_CITY) {
- while (num_land == 0) num_land = regen_land (placed);
- i = irand (num_land-1); /* select random piece of land */
- loc = land[i];
+void place_cities(void)
+{
+ count_t regen_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 */
+ while (placed < NUM_CITY) {
+ while (num_land == 0) num_land = regen_land (placed);
+ i = irand (num_land-1); /* select random piece of land */
+ loc = land[i];
- city[placed].loc = loc;
- city[placed].owner = UNOWNED;
- city[placed].work = 0;
- city[placed].prod = NOPIECE;
+ city[placed].loc = loc;
+ city[placed].owner = UNOWNED;
+ city[placed].work = 0;
+ city[placed].prod = NOPIECE;
- for (i = 0; i < NUM_OBJECTS; i++)
- city[placed].func[i] = NOFUNC; /* no function */
+ for (i = 0; i < NUM_OBJECTS; i++)
+ city[placed].func[i] = NOFUNC; /* no function */
- map[loc].contents = '*';
- map[loc].cityp = &(city[placed]);
- placed++;
+ map[loc].contents = '*';
+ map[loc].cityp = &(city[placed]);
+ placed++;
- /* Now remove any land too close to selected land. */
- num_land = remove_land (loc, num_land);
- }
+ /* Now remove any land too close to selected land. */
+ num_land = remove_land (loc, num_land);
+ }
}
/*
count_t regen_land(count_t placed)
{
- count_t num_land;
- count_t i;
-
- num_land = 0;
- for (i = 0; i < MAP_SIZE; i++) {
- if (map[i].on_board && map[i].contents == '+') {
- land[num_land] = i; /* remember piece of land */
- num_land++; /* remember number of pieces */
- }
- }
- if (placed > 0) { /* don't decrement 1st time */
- MIN_CITY_DIST -= 1;
- ASSERT (MIN_CITY_DIST >= 0);
+ count_t num_land;
+ count_t i;
+
+ num_land = 0;
+ for (i = 0; i < MAP_SIZE; i++) {
+ if (map[i].on_board && map[i].contents == '+') {
+ land[num_land] = i; /* remember piece of land */
+ num_land++; /* remember number of pieces */
}
- for (i = 0; i < placed; i++) { /* for each placed city */
- num_land = remove_land (city[i].loc, num_land);
- }
- return (num_land);
+ }
+ if (placed > 0) { /* don't decrement 1st time */
+ MIN_CITY_DIST -= 1;
+ ASSERT (MIN_CITY_DIST >= 0);
+ }
+ for (i = 0; i < placed; i++) { /* for each placed city */
+ num_land = remove_land (city[i].loc, num_land);
+ }
+ return (num_land);
}
/*
count_t remove_land(loc_t loc, count_t num_land)
{
- count_t new, i;
+ count_t new, i;
- new = 0; /* nothing kept yet */
- for (i = 0; i < num_land; i++) {
- if (dist (loc, land[i]) >= MIN_CITY_DIST) {
- land[new] = land[i];
- new++;
- }
+ new = 0; /* nothing kept yet */
+ for (i = 0; i < num_land; i++) {
+ if (dist (loc, land[i]) >= MIN_CITY_DIST) {
+ land[new] = land[i];
+ new++;
}
- return (new);
+ }
+ return (new);
}
/*
static int rank_tab[MAX_CONT]; /* indices to cont_tab in order of rank */
static pair_t pair_tab[MAX_CONT*MAX_CONT]; /* ranked pairs of continents */
-bool select_cities(void) {
- void find_cont(void), make_pair(void);
+bool select_cities(void)
+{
+ void find_cont(void), make_pair(void);
- loc_t compi, useri;
- city_info_t *compp, *userp;
- int comp_cont, user_cont;
- int pair;
+ loc_t compi, useri;
+ city_info_t *compp, *userp;
+ int comp_cont, user_cont;
+ int pair;
- find_cont (); /* find and rank the continents */
- if (ncont == 0) return (false); /* there are no good continents */
+ find_cont (); /* find and rank the continents */
+ if (ncont == 0) return (false); /* there are no good continents */
- make_pair (); /* create list of ranked pairs */
+ make_pair (); /* create list of ranked pairs */
- (void) sprintf (jnkbuf,
- "Choose a difficulty level where 0 is easy and %d is hard: ",
- ncont*ncont-1);
+ (void) sprintf (jnkbuf,
+ "Choose a difficulty level where 0 is easy and %d is hard: ",
+ ncont*ncont-1);
- pair = get_range (jnkbuf, 0, ncont*ncont-1);
- comp_cont = pair_tab[pair].comp_cont;
- user_cont = pair_tab[pair].user_cont;
+ pair = get_range (jnkbuf, 0, ncont*ncont-1);
+ comp_cont = pair_tab[pair].comp_cont;
+ user_cont = pair_tab[pair].user_cont;
- compi = irand ((long)cont_tab[comp_cont].ncity);
- compp = cont_tab[comp_cont].cityp[compi];
+ compi = irand ((long)cont_tab[comp_cont].ncity);
+ compp = cont_tab[comp_cont].cityp[compi];
- do { /* select different user city */
- useri = irand ((long)cont_tab[user_cont].ncity);
- userp = cont_tab[user_cont].cityp[useri];
- } while (userp == compp);
+ do { /* select different user city */
+ useri = irand ((long)cont_tab[user_cont].ncity);
+ userp = cont_tab[user_cont].cityp[useri];
+ } while (userp == compp);
- topmsg(1, "Your city is at %d.", loc_disp(userp->loc));
- delay (); /* let user see output before we set_prod */
+ topmsg(1, "Your city is at %d.", loc_disp(userp->loc));
+ delay (); /* let user see output before we set_prod */
- /* update city and map */
- compp->owner = COMP;
- compp->prod = ARMY;
- compp->work = 0;
- scan (comp_map, compp->loc);
+ /* update city and map */
+ compp->owner = COMP;
+ compp->prod = ARMY;
+ compp->work = 0;
+ scan (comp_map, compp->loc);
- userp->owner = USER;
- userp->work = 0;
- scan (user_map, userp->loc);
- set_prod (userp);
- return (true);
+ userp->owner = USER;
+ userp->work = 0;
+ scan (user_map, userp->loc);
+ set_prod (userp);
+ return (true);
}
/*
city. We rank the continents.
*/
-void find_cont(void) {
- loc_t i;
- loc_t mapi;
+void find_cont(void)
+{
+ loc_t i;
+ loc_t mapi;
- for (i = 0; i < MAP_SIZE; i++) marked[i] = 0; /* nothing marked yet */
+ for (i = 0; i < MAP_SIZE; i++) marked[i] = 0; /* nothing marked yet */
- ncont = 0; /* no continents found yet */
- mapi = 0;
+ ncont = 0; /* no continents found yet */
+ mapi = 0;
- while (ncont < MAX_CONT)
- if (!find_next (&mapi)) return; /* all found */
+ while (ncont < MAX_CONT)
+ if (!find_next (&mapi))
+ return; /* all found */
}
/*
bool find_next(loc_t *mapi)
{
- count_t i;
- long val;
-
- for (;;) {
- if (*mapi >= MAP_SIZE) return (false);
-
- if (!map[*mapi].on_board || marked[*mapi]
- || map[*mapi].contents == '.') *mapi += 1;
- else if (good_cont (*mapi)) {
- rank_tab[ncont] = ncont; /* insert cont in rank tab */
- val = cont_tab[ncont].value;
-
- for (i = ncont; i > 0; i--) { /* bubble up new rank */
- if (val > cont_tab[rank_tab[i-1]].value) {
- rank_tab[i] = rank_tab[i-1];
- rank_tab[i-1] = ncont;
- }
- else break;
- }
- ncont++; /* count continents */
- return (true);
+ count_t i;
+ long val;
+
+ for (;;) {
+ if (*mapi >= MAP_SIZE) return (false);
+
+ if (!map[*mapi].on_board || marked[*mapi]
+ || map[*mapi].contents == '.') *mapi += 1;
+ else if (good_cont (*mapi)) {
+ rank_tab[ncont] = ncont; /* insert cont in rank tab */
+ val = cont_tab[ncont].value;
+
+ for (i = ncont; i > 0; i--) { /* bubble up new rank */
+ if (val > cont_tab[rank_tab[i-1]].value) {
+ rank_tab[i] = rank_tab[i-1];
+ rank_tab[i-1] = ncont;
}
+ else break;
+ }
+ ncont++; /* count continents */
+ return (true);
}
+ }
}
/*
bool good_cont(loc_t mapi)
{
- long val;
+ long val;
- ncity = 0; /* nothing seen yet */
- nland = 0;
- nshore = 0;
+ ncity = 0; /* nothing seen yet */
+ nland = 0;
+ nshore = 0;
- mark_cont (mapi);
+ mark_cont (mapi);
- if (nshore < 1 || ncity < 2) return (false);
+ if (nshore < 1 || ncity < 2) return (false);
- /* The first two cities, one of which must be a shore city,
- don't contribute to the value. Otherwise shore cities are
- worth 3/2 an inland city. A city is worth 1000 times as much
- as land area. */
+ /* The first two cities, one of which must be a shore city,
+ don't contribute to the value. Otherwise shore cities are
+ worth 3/2 an inland city. A city is worth 1000 times as much
+ as land area. */
- if (ncity == nshore) val = (nshore - 2) * 3;
- else val = (nshore-1) * 3 + (ncity - nshore - 1) * 2;
+ if (ncity == nshore) val = (nshore - 2) * 3;
+ else val = (nshore-1) * 3 + (ncity - nshore - 1) * 2;
- val *= 1000; /* cities are worth a lot */
- val += nland;
- cont_tab[ncont].value = val;
- cont_tab[ncont].ncity = ncity;
- return (true);
+ val *= 1000; /* cities are worth a lot */
+ val += nland;
+ cont_tab[ncont].value = val;
+ cont_tab[ncont].ncity = ncity;
+ return (true);
}
/*
static void
mark_cont(loc_t mapi)
{
- int i;
+ int i;
- if (marked[mapi] || map[mapi].contents == '.'
- || !map[mapi].on_board) return;
+ if (marked[mapi] || map[mapi].contents == '.'
+ || !map[mapi].on_board) return;
- marked[mapi] = 1; /* mark this cell seen */
- nland++; /* count land on continent */
+ marked[mapi] = 1; /* mark this cell seen */
+ nland++; /* count land on continent */
- if (map[mapi].contents == '*') { /* a city? */
- cont_tab[ncont].cityp[ncity] = map[mapi].cityp;
- ncity++;
- if (rmap_shore (mapi)) nshore++;
- }
+ if (map[mapi].contents == '*') { /* a city? */
+ cont_tab[ncont].cityp[ncity] = map[mapi].cityp;
+ ncity++;
+ if (rmap_shore (mapi)) nshore++;
+ }
- for (i = 0; i < 8; i++) /* look at surrounding squares */
- mark_cont (mapi + dir_offset[i]);
+ for (i = 0; i < 8; i++) /* look at surrounding squares */
+ mark_cont (mapi + dir_offset[i]);
}
/*
between the user's continent and the computer's continent.
*/
-void make_pair(void) {
- int i, j, k, npair;
- long val;
+void make_pair(void)
+{
+ int i, j, k, npair;
+ long val;
- npair = 0; /* none yet */
+ npair = 0; /* none yet */
- for (i = 0; i < ncont; i++)
+ for (i = 0; i < ncont; i++)
for (j = 0; j < ncont; j++) { /* loop through all continents */
- val = cont_tab[i].value - cont_tab[j].value;
- pair_tab[npair].value = val;
- pair_tab[npair].user_cont = i;
- pair_tab[npair].comp_cont = j;
-
- for (k = npair; k > 0; k--) { /* bubble up new rank */
- if (val > pair_tab[k-1].value) {
- pair_tab[k] = pair_tab[k-1];
- pair_tab[k-1].user_cont = i;
- pair_tab[k-1].comp_cont = j;
- }
- else break;
+ val = cont_tab[i].value - cont_tab[j].value;
+ pair_tab[npair].value = val;
+ pair_tab[npair].user_cont = i;
+ pair_tab[npair].comp_cont = j;
+
+ for (k = npair; k > 0; k--) { /* bubble up new rank */
+ if (val > pair_tab[k-1].value) {
+ pair_tab[k] = pair_tab[k-1];
+ pair_tab[k-1].user_cont = i;
+ pair_tab[k-1].comp_cont = j;
}
- npair++; /* count pairs */
+ else break;
+ }
+ npair++; /* count pairs */
}
}
#define wbuf(buf) if (!xwrite (f, (char *)buf, sizeof (buf))) return
#define wval(val) if (!xwrite (f, (char *)&val, sizeof (val))) return
-void save_game(void) {
- FILE *f; /* file to save game in */
-
- f = fopen (savefile, "w"); /* open for output */
- if (f == NULL) {
- perror ("Cannot save saved game");
- return;
- }
- wbuf (map);
- wbuf (comp_map);
- wbuf (user_map);
- wbuf (city);
- wbuf (object);
- wbuf (user_obj);
- wbuf (comp_obj);
- wval (free_list);
- wval (date);
- wval (automove);
- wval (resigned);
- wval (debug);
- wval (win);
- wval (save_movie);
- wval (user_score);
- wval (comp_score);
-
- (void) fclose (f);
- topmsg (3, "Game saved.");
+void save_game(void)
+{
+ FILE *f; /* file to save game in */
+
+ f = fopen (savefile, "w"); /* open for output */
+ if (f == NULL) {
+ perror ("Cannot save saved game");
+ return;
+ }
+ wbuf (map);
+ wbuf (comp_map);
+ wbuf (user_map);
+ wbuf (city);
+ wbuf (object);
+ wbuf (user_obj);
+ wbuf (comp_obj);
+ wval (free_list);
+ wval (date);
+ wval (automove);
+ wval (resigned);
+ wval (debug);
+ wval (win);
+ wval (save_movie);
+ wval (user_score);
+ wval (comp_score);
+
+ (void) fclose (f);
+ topmsg (3, "Game saved.");
}
/*
#define rbuf(buf) if (!xread (f, (char *)buf, sizeof(buf))) return (false);
#define rval(val) if (!xread (f, (char *)&val, sizeof(val))) return (false);
-int restore_game(void) {
- void read_embark();
+int restore_game(void)
+{
+ void read_embark();
- FILE *f; /* file to save game in */
- long i;
- piece_info_t **list;
- piece_info_t *obj;
-
- f = fopen (savefile, "r"); /* open for input */
- if (f == NULL) {
- perror ("Cannot open saved game");
- return (false);
- }
- rbuf (map);
- rbuf (comp_map);
- rbuf (user_map);
- rbuf (city);
- rbuf (object);
- rbuf (user_obj);
- rbuf (comp_obj);
- rval (free_list);
- rval (date);
- rval (automove);
- rval (resigned);
- rval (debug);
- rval (win);
- rval (save_movie);
- rval (user_score);
- rval (comp_score);
-
- /* Our pointers may not be valid because of source
- changes or other things. We recreate them. */
+ FILE *f; /* file to save game in */
+ long i;
+ piece_info_t **list;
+ piece_info_t *obj;
+
+ f = fopen (savefile, "r"); /* open for input */
+ if (f == NULL) {
+ perror ("Cannot open saved game");
+ return (false);
+ }
+ rbuf (map);
+ rbuf (comp_map);
+ rbuf (user_map);
+ rbuf (city);
+ rbuf (object);
+ rbuf (user_obj);
+ rbuf (comp_obj);
+ rval (free_list);
+ rval (date);
+ rval (automove);
+ rval (resigned);
+ rval (debug);
+ rval (win);
+ rval (save_movie);
+ rval (user_score);
+ rval (comp_score);
+
+ /* Our pointers may not be valid because of source
+ changes or other things. We recreate them. */
- free_list = NULL; /* zero all ptrs */
- for (i = 0; i < MAP_SIZE; i++) {
- map[i].cityp = NULL;
- map[i].objp = NULL;
- }
- for (i = 0; i < LIST_SIZE; i++) {
- object[i].loc_link.next = NULL;
- object[i].loc_link.prev = NULL;
- object[i].cargo_link.next = NULL;
- object[i].cargo_link.prev = NULL;
- object[i].piece_link.next = NULL;
- object[i].piece_link.prev = NULL;
- object[i].ship = NULL;
- object[i].cargo = NULL;
- }
- for (i = 0; i < NUM_OBJECTS; i++) {
- comp_obj[i] = NULL;
- user_obj[i] = NULL;
- }
- /* put cities on map */
- for (i = 0; i < NUM_CITY; i++)
- map[city[i].loc].cityp = &(city[i]);
+ free_list = NULL; /* zero all ptrs */
+ for (i = 0; i < MAP_SIZE; i++) {
+ map[i].cityp = NULL;
+ map[i].objp = NULL;
+ }
+ for (i = 0; i < LIST_SIZE; i++) {
+ object[i].loc_link.next = NULL;
+ object[i].loc_link.prev = NULL;
+ object[i].cargo_link.next = NULL;
+ object[i].cargo_link.prev = NULL;
+ object[i].piece_link.next = NULL;
+ object[i].piece_link.prev = NULL;
+ object[i].ship = NULL;
+ object[i].cargo = NULL;
+ }
+ for (i = 0; i < NUM_OBJECTS; i++) {
+ comp_obj[i] = NULL;
+ user_obj[i] = NULL;
+ }
+ /* put cities on map */
+ for (i = 0; i < NUM_CITY; i++)
+ map[city[i].loc].cityp = &(city[i]);
- /* put pieces in free list or on map and in object lists */
- for (i = 0; i < LIST_SIZE; i++) {
- obj = &(object[i]);
- if (object[i].owner == UNOWNED || object[i].hits == 0) {
- LINK (free_list, obj, piece_link);
- }
- else {
- list = LIST (object[i].owner);
- LINK (list[object[i].type], obj, piece_link);
- LINK (map[object[i].loc].objp, obj, loc_link);
- }
+ /* put pieces in free list or on map and in object lists */
+ for (i = 0; i < LIST_SIZE; i++) {
+ obj = &(object[i]);
+ if (object[i].owner == UNOWNED || object[i].hits == 0) {
+ LINK (free_list, obj, piece_link);
+ }
+ else {
+ list = LIST (object[i].owner);
+ LINK (list[object[i].type], obj, piece_link);
+ LINK (map[object[i].loc].objp, obj, loc_link);
}
+ }
- /* Embark armies and fighters. */
- read_embark (user_obj[TRANSPORT], ARMY);
- read_embark (user_obj[CARRIER], FIGHTER);
- read_embark (comp_obj[TRANSPORT], ARMY);
- read_embark (comp_obj[CARRIER], FIGHTER);
+ /* Embark armies and fighters. */
+ read_embark (user_obj[TRANSPORT], ARMY);
+ read_embark (user_obj[CARRIER], FIGHTER);
+ read_embark (comp_obj[TRANSPORT], ARMY);
+ read_embark (comp_obj[CARRIER], FIGHTER);
- (void) fclose (f);
- kill_display (); /* what we had is no longer good */
- topmsg (3, "Game restored from save file.");
- return (true);
+ (void) fclose (f);
+ kill_display (); /* what we had is no longer good */
+ topmsg (3, "Game restored from save file.");
+ return (true);
}
/*
void read_embark(piece_info_t *list, int piece_type)
{
- void inconsistent(void);
-
- piece_info_t *ship;
- piece_info_t *obj;
- int count;
-
- for (ship = list; ship != NULL; ship = ship->piece_link.next) {
- count = ship->count; /* get # of pieces we need */
- if (count < 0) inconsistent ();
- ship->count = 0; /* nothing on board yet */
- for (obj = map[ship->loc].objp; obj && count;
- obj = obj->loc_link.next) {
- if (obj->ship == NULL && obj->type == piece_type) {
- embark (ship, obj);
- count -= 1;
- }
- }
- if (count) inconsistent ();
+ void inconsistent(void);
+
+ piece_info_t *ship;
+ piece_info_t *obj;
+ int count;
+
+ for (ship = list; ship != NULL; ship = ship->piece_link.next) {
+ count = ship->count; /* get # of pieces we need */
+ if (count < 0) inconsistent ();
+ ship->count = 0; /* nothing on board yet */
+ for (obj = map[ship->loc].objp; obj && count;
+ obj = obj->loc_link.next) {
+ if (obj->ship == NULL && obj->type == piece_type) {
+ embark (ship, obj);
+ count -= 1;
+ }
}
+ if (count) inconsistent ();
+ }
}
-void inconsistent(void) {
- (void) printf ("saved game is inconsistent. Please remove it.\n");
- exit (1);
+void inconsistent(void)
+{
+ (void) printf ("saved game is inconsistent. Please remove it.\n");
+ exit (1);
}
/*
bool xwrite(FILE *f, char *buf, int size)
{
- int bytes;
+ int bytes;
- bytes = fwrite (buf, 1, size, f);
- if (bytes == -1) {
- perror ("Write to save file failed");
- return (false);
- }
- if (bytes != size) {
- perror ("Cannot complete write to save file.\n");
- return (false);
- }
- return (true);
+ bytes = fwrite (buf, 1, size, f);
+ if (bytes == -1) {
+ perror ("Write to save file failed");
+ return (false);
+ }
+ if (bytes != size) {
+ perror ("Cannot complete write to save file.\n");
+ return (false);
+ }
+ return (true);
}
/*
bool xread(FILE *f, char *buf, int size)
{
- int bytes;
-
- bytes = fread (buf, 1, size, f);
- if (bytes == -1) {
- perror ("Read from save file failed");
- return (false);
- }
- if (bytes != size) {
- perror ("Saved file is too short.\n");
- return (false);
- }
- return (true);
+ int bytes;
+
+ bytes = fread (buf, 1, size, f);
+ if (bytes == -1) {
+ perror ("Read from save file failed");
+ return (false);
+ }
+ if (bytes != size) {
+ perror ("Saved file is too short.\n");
+ return (false);
+ }
+ return (true);
}
/*
void
save_movie_screen(void)
{
- FILE *f; /* file to save game in */
- count_t i;
- piece_info_t *p;
-
- f = fopen ("empmovie.dat", "a"); /* open for append */
- if (f == NULL) {
- perror ("Cannot open empmovie.dat");
- return;
- }
-
- for (i = 0; i < MAP_SIZE; i++) {
- if (map[i].cityp) mapbuf[i] = city_char[map[i].cityp->owner];
- else {
- p = find_obj_at_loc (i);
+ FILE *f; /* file to save game in */
+ count_t i;
+ piece_info_t *p;
+
+ f = fopen ("empmovie.dat", "a"); /* open for append */
+ if (f == NULL) {
+ perror ("Cannot open empmovie.dat");
+ return;
+ }
+
+ for (i = 0; i < MAP_SIZE; i++) {
+ if (map[i].cityp) mapbuf[i] = city_char[map[i].cityp->owner];
+ else {
+ p = find_obj_at_loc (i);
- if (!p) mapbuf[i] = map[i].contents;
- else if (p->owner == USER)
- mapbuf[i] = piece_attr[p->type].sname;
- else mapbuf[i] = tolower (piece_attr[p->type].sname);
- }
+ if (!p) mapbuf[i] = map[i].contents;
+ else if (p->owner == USER)
+ mapbuf[i] = piece_attr[p->type].sname;
+ else mapbuf[i] = tolower (piece_attr[p->type].sname);
}
- wbuf (mapbuf);
- (void) fclose (f);
+ }
+ wbuf (mapbuf);
+ (void) fclose (f);
}
/*
void
replay_movie(void)
{
- void print_movie_cell();
+ void print_movie_cell();
- FILE *f; /* file to save game in */
- int row_inc, col_inc;
- int r, c;
- int round;
+ FILE *f; /* file to save game in */
+ int row_inc, col_inc;
+ int r, c;
+ int round;
- f = fopen ("empmovie.dat", "r"); /* open for input */
- if (f == NULL) {
- perror ("Cannot open empmovie.dat");
- return;
- }
- round = 0;
- clear_screen ();
- for (;;) {
- if (fread ((char *)mapbuf, 1, sizeof (mapbuf), f) != sizeof (mapbuf)) break;
- round += 1;
+ f = fopen ("empmovie.dat", "r"); /* open for input */
+ if (f == NULL) {
+ perror ("Cannot open empmovie.dat");
+ return;
+ }
+ round = 0;
+ clear_screen ();
+ for (;;) {
+ if (fread ((char *)mapbuf, 1, sizeof (mapbuf), f) != sizeof (mapbuf))
+ break;
+ round += 1;
- stat_display (mapbuf, round);
+ stat_display (mapbuf, round);
- row_inc = (MAP_HEIGHT + lines - NUMTOPS - 1) / (lines - NUMTOPS);
- col_inc = (MAP_WIDTH + cols - 1) / (cols - 1);
+ row_inc = (MAP_HEIGHT + lines - NUMTOPS - 1) / (lines - NUMTOPS);
+ col_inc = (MAP_WIDTH + cols - 1) / (cols - 1);
- for (r = 0; r < MAP_HEIGHT; r += row_inc)
- for (c = 0; c < MAP_WIDTH; c += col_inc)
+ for (r = 0; r < MAP_HEIGHT; r += row_inc)
+ for (c = 0; c < MAP_WIDTH; c += col_inc)
print_movie_cell (mapbuf, r, c, row_inc, col_inc);
- (void) redisplay ();
- delay ();
- }
- (void) fclose (f);
+ (void) redisplay ();
+ delay ();
+ }
+ (void) fclose (f);
}
/*
void stat_display(char *mbuf, int round)
{
- count_t i;
- int counts[2*NUM_OBJECTS+2];
- int user_cost, comp_cost;
- char *p;
+ count_t i;
+ int counts[2*NUM_OBJECTS+2];
+ int user_cost, comp_cost;
+ char *p;
- (void) bzero ((char *)counts, sizeof (counts));
+ (void) bzero ((char *)counts, sizeof (counts));
- for (i = 0; i < MAP_SIZE; i++) {
- p = strchr (pieces, mbuf[i]);
- if (p) counts[p-pieces] += 1;
- }
- user_cost = 0;
- for (i = 1; i <= NUM_OBJECTS; i++)
- user_cost += counts[i] * piece_attr[i-1].build_time;
+ for (i = 0; i < MAP_SIZE; i++) {
+ p = strchr (pieces, mbuf[i]);
+ if (p) counts[p-pieces] += 1;
+ }
+ user_cost = 0;
+ for (i = 1; i <= NUM_OBJECTS; i++)
+ user_cost += counts[i] * piece_attr[i-1].build_time;
- comp_cost = 0;
- for (i = NUM_OBJECTS+2; i <= 2*NUM_OBJECTS+1; i++)
- comp_cost += counts[i] * piece_attr[i-NUM_OBJECTS-2].build_time;
+ comp_cost = 0;
+ for (i = NUM_OBJECTS+2; i <= 2*NUM_OBJECTS+1; i++)
+ comp_cost += counts[i] * piece_attr[i-NUM_OBJECTS-2].build_time;
- for (i = 0; i < NUM_OBJECTS+1; i++) {
- pos_str (1, (int) i * 6, "%2d %c ", counts[i], pieces[i]);
- pos_str (2,(int) i * 6, "%2d %c ", counts[i+NUM_OBJECTS+1], pieces[i+NUM_OBJECTS+1]);
- }
-
- pos_str (1, (int) i * 6, "%5d", user_cost);
- pos_str (2, (int) i * 6, "%5d", comp_cost);
- pos_str (0, 0, "Round %3d", (round + 1) / 2);
+ for (i = 0; i < NUM_OBJECTS+1; i++) {
+ pos_str (1, (int) i * 6, "%2d %c ", counts[i], pieces[i]);
+ pos_str (2,(int) i * 6, "%2d %c ", counts[i+NUM_OBJECTS+1], pieces[i+NUM_OBJECTS+1]);
+ }
+
+ pos_str (1, (int) i * 6, "%5d", user_cost);
+ pos_str (2, (int) i * 6, "%5d", comp_cost);
+ pos_str (0, 0, "Round %3d", (round + 1) / 2);
}
+/* end */
int argc;
char *argv[];
{
- int c;
- extern char *optarg;
- extern int optind;
- extern int opterr; /* set to 1 to suppress error msg */
- int errflg = 0;
- int wflg, sflg, dflg, Sflg;
- int land;
+ int c;
+ extern char *optarg;
+ extern int optind;
+ extern int opterr; /* set to 1 to suppress error msg */
+ int errflg = 0;
+ int wflg, sflg, dflg, Sflg;
+ int land;
- wflg = 70; /* set defaults */
- sflg = 5;
- dflg = 2000;
- Sflg = 10;
- savefile = "empsave.dat";
+ wflg = 70; /* set defaults */
+ sflg = 5;
+ dflg = 2000;
+ Sflg = 10;
+ savefile = "empsave.dat";
- /*
- * extract command line options
- */
+ /*
+ * extract command line options
+ */
- while ((c = getopt (argc, argv, OPTFLAGS)) != EOF) {
- switch (c) {
- case 'w':
- wflg = atoi (optarg);
- break;
- case 's':
- sflg = atoi (optarg);
- break;
- case 'd':
- dflg = atoi (optarg);
- break;
- case 'S':
- Sflg = atoi (optarg);
- break;
- case 'f':
- savefile = optarg;
- break;
- case '?': /* illegal option? */
- errflg++;
- break;
- }
- }
- if (errflg || (argc-optind) != 0) {
- (void) printf ("empire: usage: empire [-w water] [-s smooth] [-d delay]\n");
- exit (1);
+ while ((c = getopt (argc, argv, OPTFLAGS)) != EOF) {
+ switch (c) {
+ case 'w':
+ wflg = atoi (optarg);
+ break;
+ case 's':
+ sflg = atoi (optarg);
+ break;
+ case 'd':
+ dflg = atoi (optarg);
+ break;
+ case 'S':
+ Sflg = atoi (optarg);
+ break;
+ case 'f':
+ savefile = optarg;
+ break;
+ case '?': /* illegal option? */
+ errflg++;
+ break;
}
+ }
+ if (errflg || (argc-optind) != 0) {
+ (void) printf ("empire: usage: empire [-w water] [-s smooth] [-d delay]\n");
+ exit (1);
+ }
- if (wflg < 10 || wflg > 90) {
- (void) printf ("empire: -w argument must be in the range 0..90.\n");
- exit (1);
- }
- if (sflg < 0) {
- (void) printf ("empire: -s argument must be greater or equal to zero.\n");
- exit (1);
- }
+ if (wflg < 10 || wflg > 90) {
+ (void) printf ("empire: -w argument must be in the range 0..90.\n");
+ exit (1);
+ }
+ if (sflg < 0) {
+ (void) printf ("empire: -s argument must be greater or equal to zero.\n");
+ exit (1);
+ }
- if (dflg < 0 || dflg > 30000) {
- (void) printf ("empire: -d argument must be in the range 0..30000.\n");
- exit (1);
- }
+ if (dflg < 0 || dflg > 30000) {
+ (void) printf ("empire: -d argument must be in the range 0..30000.\n");
+ exit (1);
+ }
- SMOOTH = sflg;
- WATER_RATIO = wflg;
- delay_time = dflg;
- save_interval = Sflg;
+ SMOOTH = sflg;
+ WATER_RATIO = wflg;
+ delay_time = dflg;
+ save_interval = Sflg;
- /* compute min distance between cities */
- land = MAP_SIZE * (100 - WATER_RATIO) / 100; /* available land */
- land /= NUM_CITY; /* land per city */
- MIN_CITY_DIST = isqrt (land); /* distance between cities */
+ /* compute min distance between cities */
+ land = MAP_SIZE * (100 - WATER_RATIO) / 100; /* available land */
+ land /= NUM_CITY; /* land per city */
+ MIN_CITY_DIST = isqrt (land); /* distance between cities */
- empire (); /* call main routine */
- return (0);
+ empire (); /* call main routine */
+ return (0);
}
void
vmap_mark_up_cont(int *cont_map, view_map_t *vmap, loc_t loc, char bad_terrain)
{
- int i, j;
- loc_t new_loc;
- char this_terrain;
- perimeter_t *from, *to;
+ int i, j;
+ loc_t new_loc;
+ char this_terrain;
+ perimeter_t *from, *to;
- from = &p1;
- to = &p2;
+ from = &p1;
+ to = &p2;
- from->len = 1; /* init perimeter */
- from->list[0] = loc;
- cont_map[loc] = 1; /* loc is on continent */
+ from->len = 1; /* init perimeter */
+ from->list[0] = loc;
+ cont_map[loc] = 1; /* loc is on continent */
- while (from->len) {
- to->len = 0; /* nothing in new perimeter yet */
+ while (from->len) {
+ to->len = 0; /* nothing in new perimeter yet */
- for (i = 0; i < from->len; i++) /* expand perimeter */
- FOR_ADJ_ON(from->list[i], new_loc, j)
+ for (i = 0; i < from->len; i++) /* expand perimeter */
+ FOR_ADJ_ON(from->list[i], new_loc, j)
if (!cont_map[new_loc]) {
- /* mark, but don't expand, unexplored territory */
- 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 = '.';
- else this_terrain = map[new_loc].contents;
+ /* mark, but don't expand, unexplored territory */
+ 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 = '.';
+ else this_terrain = map[new_loc].contents;
- if (this_terrain != bad_terrain) { /* on continent? */
- cont_map[new_loc] = 1;
- to->list[to->len] = new_loc;
- to->len += 1;
- }
+ if (this_terrain != bad_terrain) { /* on continent? */
+ cont_map[new_loc] = 1;
+ to->list[to->len] = new_loc;
+ to->len += 1;
}
+ }
}
- SWAP (from, to);
- }
+ SWAP (from, to);
+ }
}
/*
void
rmap_cont(int *cont_map, loc_t loc, char bad_terrain)
{
- (void) bzero ((char *)cont_map, MAP_SIZE * sizeof (int));
- rmap_mark_up_cont (cont_map, loc, bad_terrain);
+ (void) bzero ((char *)cont_map, MAP_SIZE * sizeof (int));
+ rmap_mark_up_cont (cont_map, loc, bad_terrain);
}
/*
static void
rmap_mark_up_cont(int *cont_map, loc_t loc, char bad_terrain)
{
- int i;
- loc_t new_loc;
+ int i;
+ loc_t new_loc;
- if (!map[loc].on_board) return; /* off board */
- if (cont_map[loc]) return; /* already marked */
- if (map[loc].contents == bad_terrain) return; /* off continent */
+ if (!map[loc].on_board) return; /* off board */
+ if (cont_map[loc]) return; /* already marked */
+ if (map[loc].contents == bad_terrain) return; /* off continent */
- cont_map[loc] = 1; /* on continent */
+ cont_map[loc] = 1; /* on continent */
- FOR_ADJ (loc, new_loc, i)
- rmap_mark_up_cont (cont_map, new_loc, bad_terrain);
+ FOR_ADJ (loc, new_loc, i)
+ rmap_mark_up_cont (cont_map, new_loc, bad_terrain);
}
/*
scan_counts_t
vmap_cont_scan(int *cont_map, view_map_t *vmap)
{
- scan_counts_t counts;
- count_t i;
+ scan_counts_t counts;
+ count_t i;
- (void) bzero ((char *)&counts, sizeof (scan_counts_t));
+ (void) bzero ((char *)&counts, sizeof (scan_counts_t));
- for (i = 0; i < MAP_SIZE; i++) {
- if (cont_map[i]) { /* cell on continent? */
- counts.size += 1;
+ for (i = 0; i < MAP_SIZE; i++) {
+ if (cont_map[i]) { /* cell on continent? */
+ counts.size += 1;
- switch (vmap[i].contents) {
- COUNT (' ', counts.unexplored);
- COUNT ('O', counts.user_cities);
- COUNT ('A', counts.user_objects[ARMY]);
- COUNT ('F', counts.user_objects[FIGHTER]);
- COUNT ('P', counts.user_objects[PATROL]);
- COUNT ('D', counts.user_objects[DESTROYER]);
- COUNT ('S', counts.user_objects[SUBMARINE]);
- COUNT ('T', counts.user_objects[TRANSPORT]);
- COUNT ('C', counts.user_objects[CARRIER]);
- COUNT ('B', counts.user_objects[BATTLESHIP]);
- COUNT ('X', counts.comp_cities);
- COUNT ('a', counts.comp_objects[ARMY]);
- COUNT ('f', counts.comp_objects[FIGHTER]);
- COUNT ('p', counts.comp_objects[PATROL]);
- COUNT ('d', counts.comp_objects[DESTROYER]);
- COUNT ('s', counts.comp_objects[SUBMARINE]);
- 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;
- default: /* check for city underneath */
- if (map[i].contents == '*') {
- switch (map[i].cityp->owner) {
- COUNT (USER, counts.user_cities);
- COUNT (COMP, counts.comp_cities);
- COUNT (UNOWNED, counts.unowned_cities);
- }
- }
- }
+ switch (vmap[i].contents) {
+ COUNT (' ', counts.unexplored);
+ COUNT ('O', counts.user_cities);
+ COUNT ('A', counts.user_objects[ARMY]);
+ COUNT ('F', counts.user_objects[FIGHTER]);
+ COUNT ('P', counts.user_objects[PATROL]);
+ COUNT ('D', counts.user_objects[DESTROYER]);
+ COUNT ('S', counts.user_objects[SUBMARINE]);
+ COUNT ('T', counts.user_objects[TRANSPORT]);
+ COUNT ('C', counts.user_objects[CARRIER]);
+ COUNT ('B', counts.user_objects[BATTLESHIP]);
+ COUNT ('X', counts.comp_cities);
+ COUNT ('a', counts.comp_objects[ARMY]);
+ COUNT ('f', counts.comp_objects[FIGHTER]);
+ COUNT ('p', counts.comp_objects[PATROL]);
+ COUNT ('d', counts.comp_objects[DESTROYER]);
+ COUNT ('s', counts.comp_objects[SUBMARINE]);
+ 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;
+ default: /* check for city underneath */
+ if (map[i].contents == '*') {
+ switch (map[i].cityp->owner) {
+ COUNT (USER, counts.user_cities);
+ COUNT (COMP, counts.comp_cities);
+ COUNT (UNOWNED, counts.unowned_cities);
+ }
}
+ }
}
- return counts;
+ }
+ return counts;
}
/*
scan_counts_t
rmap_cont_scan(int *cont_map)
{
- scan_counts_t counts;
- count_t i;
+ scan_counts_t counts;
+ count_t i;
- (void) bzero ((char *)&counts, sizeof (scan_counts_t));
+ (void) bzero ((char *)&counts, sizeof (scan_counts_t));
- for (i = 0; i < MAP_SIZE; i++) {
- if (cont_map[i]) { /* cell on continent? */
- counts.size += 1;
- if (map[i].contents == '*')
- counts.unowned_cities += 1;
- }
+ for (i = 0; i < MAP_SIZE; i++) {
+ if (cont_map[i]) { /* cell on continent? */
+ counts.size += 1;
+ if (map[i].contents == '*')
+ counts.unowned_cities += 1;
}
- return counts;
+ }
+ return counts;
}
/*
bool
map_cont_edge(int *cont_map, loc_t loc)
{
- loc_t i, j;
+ loc_t i, j;
- if (!cont_map[loc]) return false; /* not on continent */
+ if (!cont_map[loc]) return false; /* not on continent */
- FOR_ADJ (loc, j, i)
- if (!cont_map[j]) return true; /* edge of continent */
+ FOR_ADJ (loc, j, i)
+ if (!cont_map[j]) return true; /* edge of continent */
- return false;
+ return false;
}
/*
vmap_find_xobj(path_map_t path_map[], view_map_t *vmap,
loc_t loc, move_info_t *move_info, int start, int expand)
{
- perimeter_t *from;
- perimeter_t *to;
- int cur_cost;
+ perimeter_t *from;
+ perimeter_t *to;
+ int cur_cost;
- from = &p1;
- to = &p2;
+ from = &p1;
+ to = &p2;
- start_perimeter (path_map, from, loc, start);
- cur_cost = 0; /* cost to reach current perimeter */
+ start_perimeter (path_map, from, loc, start);
+ cur_cost = 0; /* cost to reach current perimeter */
- for (;;) {
- to->len = 0; /* nothing in perim yet */
- expand_perimeter (path_map, vmap, move_info, from, expand,
- cur_cost, 1, 1, to, to);
+ for (;;) {
+ to->len = 0; /* nothing in perim yet */
+ expand_perimeter (path_map, vmap, move_info, from, expand,
+ cur_cost, 1, 1, to, to);
- if (trace_pmap)
- print_pzoom ("After xobj loop:", path_map, vmap);
+ if (trace_pmap)
+ print_pzoom ("After xobj loop:", path_map, vmap);
- cur_cost += 1;
- if (to->len == 0 || best_cost <= cur_cost)
- return best_loc;
+ cur_cost += 1;
+ if (to->len == 0 || best_cost <= cur_cost)
+ return best_loc;
- SWAP (from, to);
- }
+ SWAP (from, to);
+ }
}
/* Find an objective for a piece that crosses land and water. */
vmap_find_aobj(path_map_t path_map[], view_map_t *vmap,
loc_t loc, move_info_t *move_info)
{
- return vmap_find_xobj (path_map, vmap, loc, move_info, T_LAND, T_AIR);
+ return vmap_find_xobj (path_map, vmap, loc, move_info, T_LAND, T_AIR);
}
/* Find an objective for a piece that crosses only water. */
vmap_find_wobj(path_map_t path_map[], view_map_t *vmap,
loc_t loc, move_info_t *move_info)
{
- return vmap_find_xobj (path_map, vmap, loc, move_info, T_WATER, T_WATER);
+ return vmap_find_xobj (path_map, vmap, loc, move_info, T_WATER, T_WATER);
}
/* Find an objective for a piece that crosses only land. */
vmap_find_lobj(path_map_t path_map[], view_map_t *vmap,
loc_t loc, move_info_t *move_info)
{
- return vmap_find_xobj (path_map, vmap, loc, move_info, T_LAND, T_LAND);
+ return vmap_find_xobj (path_map, vmap, loc, move_info, T_LAND, T_LAND);
}
/*
vmap_find_lwobj(path_map_t path_map[], view_map_t *vmap,
loc_t loc, move_info_t *move_info, int beat_cost)
{
- perimeter_t *cur_land;
- perimeter_t *cur_water;
- perimeter_t *new_land;
- perimeter_t *new_water;
- int cur_cost;
-
- cur_land = &p1;
- cur_water = &p2;
- new_water = &p3;
- new_land = &p4;
+ perimeter_t *cur_land;
+ perimeter_t *cur_water;
+ perimeter_t *new_land;
+ perimeter_t *new_water;
+ int cur_cost;
+
+ cur_land = &p1;
+ cur_water = &p2;
+ new_water = &p3;
+ new_land = &p4;
- start_perimeter (path_map, cur_land, loc, T_LAND);
- cur_water->len = 0;
- best_cost = beat_cost; /* we can do this well */
- cur_cost = 0; /* cost to reach current perimeter */
-
- for (;;) {
- /* expand current perimeter one cell */
- new_water->len = 0;
- new_land->len = 0;
- expand_perimeter (path_map, vmap, move_info, cur_water,
- T_WATER, cur_cost, 1, 1, new_water, NULL);
-
- expand_perimeter (path_map, vmap, move_info, cur_land,
- T_AIR, cur_cost, 1, 2, new_water, new_land);
+ start_perimeter (path_map, cur_land, loc, T_LAND);
+ cur_water->len = 0;
+ best_cost = beat_cost; /* we can do this well */
+ cur_cost = 0; /* cost to reach current perimeter */
+
+ for (;;) {
+ /* expand current perimeter one cell */
+ new_water->len = 0;
+ new_land->len = 0;
+ expand_perimeter (path_map, vmap, move_info, cur_water,
+ T_WATER, cur_cost, 1, 1, new_water, NULL);
+
+ expand_perimeter (path_map, vmap, move_info, cur_land,
+ T_AIR, cur_cost, 1, 2, new_water, new_land);
- /* expand new water one cell */
- cur_water->len = 0;
- expand_perimeter (path_map, vmap, move_info, new_water,
- T_WATER, cur_cost+1, 1, 1, cur_water, NULL);
+ /* expand new water one cell */
+ cur_water->len = 0;
+ expand_perimeter (path_map, vmap, move_info, new_water,
+ T_WATER, cur_cost+1, 1, 1, cur_water, NULL);
- if (trace_pmap)
- print_pzoom ("After lwobj loop:", path_map, vmap);
+ if (trace_pmap)
+ print_pzoom ("After lwobj loop:", path_map, vmap);
- cur_cost += 2;
- if ( (cur_water->len == 0 && new_land->len == 0) ||
- (best_cost <= cur_cost) ) {
- return best_loc;
- }
-
- SWAP (cur_land, new_land);
+ cur_cost += 2;
+ if ( (cur_water->len == 0 && new_land->len == 0) ||
+ (best_cost <= cur_cost) ) {
+ return best_loc;
}
+
+ SWAP (cur_land, new_land);
+ }
}
#ifdef FUNCTION_WAS_NEVER_CALLED
STATIC int
best_adj(path_map_t *pmap, loc_t loc, int type)
{
- int i;
- loc_t new_loc;
- int best;
+ int i;
+ loc_t new_loc;
+ int best;
- best = INFINITY;
+ best = INFINITY;
- FOR_ADJ (loc, new_loc, i)
+ FOR_ADJ (loc, new_loc, i)
if (pmap[new_loc].terrain == type && pmap[new_loc].cost < best)
- best = pmap[new_loc].cost;
+ best = pmap[new_loc].cost;
- return best;
+ return best;
}
#endif
vmap_find_wlobj(path_map_t path_map[], view_map_t *vmap,
loc_t loc, move_info_t *move_info)
{
- perimeter_t *cur_land;
- perimeter_t *cur_water;
- perimeter_t *new_land;
- perimeter_t *new_water;
- int cur_cost;
-
- cur_land = &p1;
- cur_water = &p2;
- new_water = &p3;
- new_land = &p4;
+ perimeter_t *cur_land;
+ perimeter_t *cur_water;
+ perimeter_t *new_land;
+ perimeter_t *new_water;
+ int cur_cost;
+
+ cur_land = &p1;
+ cur_water = &p2;
+ new_water = &p3;
+ new_land = &p4;
- start_perimeter (path_map, cur_water, loc, T_WATER);
- cur_land->len = 0;
- cur_cost = 0; /* cost to reach current perimeter */
-
- for (;;) {
- /* expand current perimeter one cell */
- new_water->len = 0;
- new_land->len = 0;
- expand_perimeter (path_map, vmap, move_info, cur_water,
- T_AIR, cur_cost, 1, 2, new_water, new_land);
-
- expand_perimeter (path_map, vmap, move_info, cur_land,
- T_LAND, cur_cost, 1, 2, NULL, new_land);
+ start_perimeter (path_map, cur_water, loc, T_WATER);
+ cur_land->len = 0;
+ cur_cost = 0; /* cost to reach current perimeter */
+
+ for (;;) {
+ /* expand current perimeter one cell */
+ new_water->len = 0;
+ new_land->len = 0;
+ expand_perimeter (path_map, vmap, move_info, cur_water,
+ T_AIR, cur_cost, 1, 2, new_water, new_land);
+
+ expand_perimeter (path_map, vmap, move_info, cur_land,
+ T_LAND, cur_cost, 1, 2, NULL, new_land);
- /* expand new water one cell to water */
- cur_water->len = 0;
- expand_perimeter (path_map, vmap, move_info, new_water,
- T_WATER, cur_cost+1, 1, 1, cur_water, NULL);
+ /* expand new water one cell to water */
+ cur_water->len = 0;
+ expand_perimeter (path_map, vmap, move_info, new_water,
+ T_WATER, cur_cost+1, 1, 1, cur_water, NULL);
- if (trace_pmap)
- print_pzoom ("After wlobj loop:", path_map, vmap);
+ if (trace_pmap)
+ print_pzoom ("After wlobj loop:", path_map, vmap);
- cur_cost += 2;
- if ( (cur_water->len == 0 && new_land->len == 0) ||
- (best_cost <= cur_cost) ) {
- return best_loc;
- }
- SWAP (cur_land, new_land);
+ cur_cost += 2;
+ if ( (cur_water->len == 0 && new_land->len == 0) ||
+ (best_cost <= cur_cost) ) {
+ return best_loc;
}
+ SWAP (cur_land, new_land);
+ }
}
/*
STATIC void
start_perimeter(path_map_t *pmap, perimeter_t *perim, loc_t loc, int terrain)
{
+ /* zap the path map */
+ if (!init_done) {
int i;
- /* zap the path map */
- if (!init_done) {
- init_done = 1;
- for (i = 0; i < MAP_SIZE; i++) {
- pmap_init[i].cost = INFINITY; /* everything lies outside perim */
- pmap_init[i].terrain = T_UNKNOWN;
- }
+ init_done = 1;
+ for (i = 0; i < MAP_SIZE; i++) {
+ pmap_init[i].cost = INFINITY; /* everything lies outside perim */
+ pmap_init[i].terrain = T_UNKNOWN;
}
- (void) memcpy ((char *)pmap, (char *)pmap_init, sizeof (pmap_init));
+ }
+ (void) memcpy ((char *)pmap, (char *)pmap_init, sizeof (pmap_init));
- /* put first location in perimeter */
- pmap[loc].cost = 0;
- pmap[loc].inc_cost = 0;
- pmap[loc].terrain = terrain;
+ /* put first location in perimeter */
+ pmap[loc].cost = 0;
+ pmap[loc].inc_cost = 0;
+ pmap[loc].terrain = terrain;
- perim->len = 1;
- perim->list[0] = loc;
+ perim->len = 1;
+ perim->list[0] = loc;
- best_cost = INFINITY; /* no best yet */
- best_loc = loc; /* if nothing found, result is current loc */
+ best_cost = INFINITY; /* no best yet */
+ best_loc = loc; /* if nothing found, result is current loc */
}
/*
/* waterp = pointer to new water perimeter */
/* landp = pointer to new land perimeter */
{
- register long i;
- register int j;
- 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;
- }
- }
- }
+ register long i;
+ register int j;
+ 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;
}
+ }
}
+ }
+ }
}
/* Add a cell to a perimeter list. */
add_cell(path_map_t *pmap, loc_t new_loc,
perimeter_t *perim, int terrain, int cur_cost, int inc_cost)
{
- register path_map_t *pm = &pmap[new_loc];
+ register path_map_t *pm = &pmap[new_loc];
- pm->terrain = terrain;
- pm->inc_cost = inc_cost;
- pm->cost = cur_cost + inc_cost;
+ pm->terrain = terrain;
+ pm->inc_cost = inc_cost;
+ pm->cost = cur_cost + inc_cost;
- perim->list[perim->len] = new_loc;
- perim->len += 1;
+ perim->list[perim->len] = new_loc;
+ perim->len += 1;
}
/* Compute the cost to move to an objective. */
objective_cost(view_map_t *vmap, move_info_t *move_info,
loc_t loc, int base_cost)
{
- char *p;
- int w;
- city_info_t *cityp;
-
- p = strchr (move_info->objectives, vmap[loc].contents);
- if (!p) return INFINITY;
-
- w = move_info->weights[p - move_info->objectives];
- if (w >= 0) return w + base_cost;
-
- switch (w) {
- case W_TT_BUILD:
- /* handle special case of moving to tt building city */
- cityp = find_city (loc);
- if (!cityp) return base_cost + 2; /* tt is already here */
- if (cityp->prod != TRANSPORT) return base_cost + 2; /* just finished a tt */
+ char *p;
+ int w;
+ city_info_t *cityp;
+
+ p = strchr (move_info->objectives, vmap[loc].contents);
+ if (!p) return INFINITY;
+
+ w = move_info->weights[p - move_info->objectives];
+ if (w >= 0) return w + base_cost;
+
+ switch (w) {
+ case W_TT_BUILD:
+ /* handle special case of moving to tt building city */
+ cityp = find_city (loc);
+ if (!cityp) return base_cost + 2; /* tt is already here */
+ if (cityp->prod != TRANSPORT) return base_cost + 2; /* just finished a tt */
- /* compute time to wait for tt to be built */
- w = piece_attr[TRANSPORT].build_time - cityp->work;
- w *= 2; /* had to cross land to get here */
- if (w < base_cost + 2) w = base_cost + 2;
- return w;
-
- default:
- ABORT;
- /* NOTREACHED */
- return -1;
- }
+ /* compute time to wait for tt to be built */
+ w = piece_attr[TRANSPORT].build_time - cityp->work;
+ w *= 2; /* had to cross land to get here */
+ if (w < base_cost + 2) w = base_cost + 2;
+ return w;
+
+ default:
+ ABORT;
+ /* NOTREACHED */
+ return -1;
+ }
}
/*
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 == '%') return T_UNKNOWN; /* magic objective */
- if (vmap[to_loc].contents == ' ') return pmap[from_loc].terrain;
+ if (vmap[to_loc].contents == '+') return T_LAND;
+ if (vmap[to_loc].contents == '.') 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 '*':
- if (map[to_loc].cityp->owner == move_info->city_owner)
- return T_WATER;
- else return T_UNKNOWN; /* cannot cross */
- }
- ABORT;
- /*NOTREACHED*/
- return -1;
+ switch (map[to_loc].contents) {
+ case '.': return T_WATER;
+ case '+': return T_LAND;
+ case '*':
+ if (map[to_loc].cityp->owner == move_info->city_owner)
+ return T_WATER;
+ else return T_UNKNOWN; /* cannot cross */
+ }
+ ABORT;
+ /*NOTREACHED*/
+ return -1;
}
/*
void
vmap_prune_explore_locs(view_map_t *vmap)
{
- path_map_t pmap[MAP_SIZE];
- perimeter_t *from, *to;
- int explored;
- loc_t loc, new_loc;
- count_t i;
- long copied;
-
- (void) bzero (pmap, sizeof (pmap));
- from = &p1;
- to = &p2;
- from->len = 0;
- explored = 0;
+ path_map_t pmap[MAP_SIZE];
+ perimeter_t *from, *to;
+ int explored;
+ loc_t loc, new_loc;
+ count_t i;
+ long copied;
+
+ (void) bzero (pmap, sizeof (pmap));
+ from = &p1;
+ to = &p2;
+ from->len = 0;
+ explored = 0;
- /* build initial path map and perimeter list */
- for (loc = 0; loc < MAP_SIZE; loc++) {
- if (vmap[loc].contents != ' ') explored += 1;
- else { /* add unexplored cell to perim */
- 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 != '.')
- pmap[loc].cost += 1; /* count land */
- else pmap[loc].inc_cost += 1; /* count water */
- }
- if (pmap[loc].cost || pmap[loc].inc_cost) {
- from->list[from->len] = loc;
- from->len += 1;
- }
- }
+ /* build initial path map and perimeter list */
+ for (loc = 0; loc < MAP_SIZE; loc++) {
+ if (vmap[loc].contents != ' ')
+ explored += 1;
+ else { /* add unexplored cell to perim */
+ 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 != '.')
+ pmap[loc].cost += 1; /* count land */
+ else pmap[loc].inc_cost += 1; /* count water */
+ }
+ if (pmap[loc].cost || pmap[loc].inc_cost) {
+ from->list[from->len] = loc;
+ from->len += 1;
+ }
}
+ }
- if (print_vmap == 'I') print_xzoom (vmap);
+ if (print_vmap == 'I')
+ print_xzoom (vmap);
- for (;;) { /* do high probability predictions */
- if (from->len + explored == MAP_SIZE) return;
- to->len = 0;
- copied = 0;
+ for (;;) { /* do high probability predictions */
+ if (from->len + explored == MAP_SIZE) return;
+ to->len = 0;
+ copied = 0;
- for (i = 0; i < from->len; i++) {
- loc = from->list[i];
- if (pmap[loc].cost >= 5)
- expand_prune (vmap, pmap, loc, T_LAND, to, &explored);
- else if (pmap[loc].inc_cost >= 5)
- expand_prune (vmap, pmap, loc, T_WATER, to, &explored);
- else if ((loc < MAP_WIDTH || loc >= MAP_SIZE-MAP_WIDTH) && pmap[loc].cost >= 3)
- expand_prune (vmap, pmap, loc, T_LAND, to, &explored);
- else if ((loc < MAP_WIDTH || loc >= MAP_SIZE-MAP_WIDTH) && pmap[loc].inc_cost >= 3)
- expand_prune (vmap, pmap, loc, T_WATER, to, &explored);
- else if ((loc == 0 || loc == MAP_SIZE-1) && pmap[loc].cost >= 2)
- expand_prune (vmap, pmap, loc, T_LAND, to, &explored);
- else if ((loc == 0 || loc == MAP_SIZE-1) && pmap[loc].inc_cost >= 2)
- expand_prune (vmap, pmap, loc, T_WATER, to, &explored);
- else { /* copy perimeter cell */
- to->list[to->len] = loc;
- to->len += 1;
- copied += 1;
- }
- }
- if (copied == from->len) break; /* nothing expanded */
- SWAP (from, to);
+ for (i = 0; i < from->len; i++) {
+ loc = from->list[i];
+ if (pmap[loc].cost >= 5)
+ expand_prune (vmap, pmap, loc, T_LAND, to, &explored);
+ else if (pmap[loc].inc_cost >= 5)
+ expand_prune (vmap, pmap, loc, T_WATER, to, &explored);
+ else if ((loc < MAP_WIDTH || loc >= MAP_SIZE-MAP_WIDTH) && pmap[loc].cost >= 3)
+ expand_prune (vmap, pmap, loc, T_LAND, to, &explored);
+ else if ((loc < MAP_WIDTH || loc >= MAP_SIZE-MAP_WIDTH) && pmap[loc].inc_cost >= 3)
+ expand_prune (vmap, pmap, loc, T_WATER, to, &explored);
+ else if ((loc == 0 || loc == MAP_SIZE-1) && pmap[loc].cost >= 2)
+ expand_prune (vmap, pmap, loc, T_LAND, to, &explored);
+ else if ((loc == 0 || loc == MAP_SIZE-1) && pmap[loc].inc_cost >= 2)
+ expand_prune (vmap, pmap, loc, T_WATER, to, &explored);
+ else { /* copy perimeter cell */
+ to->list[to->len] = loc;
+ to->len += 1;
+ copied += 1;
+ }
}
+ if (copied == from->len) break; /* nothing expanded */
+ SWAP (from, to);
+ }
- if (print_vmap == 'I') print_xzoom (vmap);
+ if (print_vmap == 'I')
+ print_xzoom (vmap);
- /* one pass for medium probability predictions */
- if (from->len + explored == MAP_SIZE) return;
- to->len = 0;
+ /* one pass for medium probability predictions */
+ if (from->len + explored == MAP_SIZE)
+ return;
+ to->len = 0;
- for (i = 0; i < from->len; i++) {
- loc = from->list[i];
- if (pmap[loc].cost > pmap[loc].inc_cost)
- expand_prune (vmap, pmap, loc, T_LAND, to, &explored);
- else if (pmap[loc].cost < pmap[loc].inc_cost)
- expand_prune (vmap, pmap, loc, T_WATER, to, &explored);
- else { /* copy perimeter cell */
- to->list[to->len] = loc;
- to->len += 1;
- }
+ for (i = 0; i < from->len; i++) {
+ loc = from->list[i];
+ if (pmap[loc].cost > pmap[loc].inc_cost)
+ expand_prune (vmap, pmap, loc, T_LAND, to, &explored);
+ else if (pmap[loc].cost < pmap[loc].inc_cost)
+ expand_prune (vmap, pmap, loc, T_WATER, to, &explored);
+ else { /* copy perimeter cell */
+ to->list[to->len] = loc;
+ to->len += 1;
}
- SWAP (from, to);
+ }
+ SWAP (from, to);
- if (print_vmap == 'I') print_xzoom (vmap);
+ if (print_vmap == 'I') print_xzoom (vmap);
- /* multiple low probability passes */
- for (;;) {
- /* return if very little left to explore */
- if (from->len + explored >= MAP_SIZE - MAP_HEIGHT) {
- if (print_vmap == 'I') print_xzoom (vmap);
- return;
- }
- to->len = 0;
- copied = 0;
+ /* multiple low probability passes */
+ for (;;) {
+ /* return if very little left to explore */
+ if (from->len + explored >= MAP_SIZE - MAP_HEIGHT) {
+ if (print_vmap == 'I') print_xzoom (vmap);
+ return;
+ }
+ to->len = 0;
+ copied = 0;
- for (i = 0; i < from->len; i++) {
- loc = from->list[i];
- if (pmap[loc].cost >= 4 && pmap[loc].inc_cost < 4)
- expand_prune (vmap, pmap, loc, T_LAND, to, &explored);
- else if (pmap[loc].inc_cost >= 4 && pmap[loc].cost < 4)
- expand_prune (vmap, pmap, loc, T_WATER, to, &explored);
- else if ((loc < MAP_WIDTH || loc >= MAP_SIZE-MAP_WIDTH) && pmap[loc].cost > pmap[loc].inc_cost)
- expand_prune (vmap, pmap, loc, T_LAND, to, &explored);
- else if ((loc < MAP_WIDTH || loc >= MAP_SIZE-MAP_WIDTH) && pmap[loc].inc_cost > pmap[loc].cost)
- expand_prune (vmap, pmap, loc, T_WATER, to, &explored);
- else { /* copy perimeter cell */
- to->list[to->len] = loc;
- to->len += 1;
- copied += 1;
- }
- }
- if (copied == from->len) break; /* nothing expanded */
- SWAP (from, to);
+ for (i = 0; i < from->len; i++) {
+ loc = from->list[i];
+ if (pmap[loc].cost >= 4 && pmap[loc].inc_cost < 4)
+ expand_prune (vmap, pmap, loc, T_LAND, to, &explored);
+ else if (pmap[loc].inc_cost >= 4 && pmap[loc].cost < 4)
+ expand_prune (vmap, pmap, loc, T_WATER, to, &explored);
+ else if ((loc < MAP_WIDTH || loc >= MAP_SIZE-MAP_WIDTH) && pmap[loc].cost > pmap[loc].inc_cost)
+ expand_prune (vmap, pmap, loc, T_LAND, to, &explored);
+ else if ((loc < MAP_WIDTH || loc >= MAP_SIZE-MAP_WIDTH) && pmap[loc].inc_cost > pmap[loc].cost)
+ expand_prune (vmap, pmap, loc, T_WATER, to, &explored);
+ else { /* copy perimeter cell */
+ to->list[to->len] = loc;
+ to->len += 1;
+ copied += 1;
+ }
}
- if (print_vmap == 'I') print_xzoom (vmap);
+ if (copied == from->len) break; /* nothing expanded */
+ SWAP (from, to);
+ }
+ if (print_vmap == 'I') print_xzoom (vmap);
}
/*
expand_prune(view_map_t *vmap, path_map_t *pmap,
loc_t loc, int type, perimeter_t *to, int *explored)
{
- int i;
- loc_t new_loc;
+ int i;
+ loc_t new_loc;
- *explored += 1;
+ *explored += 1;
- if (type == T_LAND) vmap[loc].contents = '+';
- else vmap[loc].contents = '.';
+ if (type == T_LAND) vmap[loc].contents = '+';
+ else vmap[loc].contents = '.';
- FOR_ADJ (loc, new_loc, i)
+ FOR_ADJ (loc, new_loc, i)
if (new_loc >= 0 && new_loc < MAP_SIZE && vmap[new_loc].contents == ' ') {
- if (!pmap[new_loc].cost && !pmap[new_loc].inc_cost) {
- to->list[to->len] = new_loc;
- to->len += 1;
- }
- if (type == T_LAND)
- pmap[new_loc].cost += 1;
- else pmap[new_loc].inc_cost += 1;
+ if (!pmap[new_loc].cost && !pmap[new_loc].inc_cost) {
+ to->list[to->len] = new_loc;
+ to->len += 1;
+ }
+ if (type == T_LAND)
+ pmap[new_loc].cost += 1;
+ else pmap[new_loc].inc_cost += 1;
}
}
/* owner = owner of piece being moved */
/* terrain = terrain we can cross */
{
- perimeter_t *from;
- perimeter_t *to;
- int cur_cost;
- int start_terrain;
- move_info_t move_info;
- char old_contents;
-
- old_contents = vmap[dest_loc].contents;
- vmap[dest_loc].contents = '%'; /* mark objective */
- move_info.city_owner = owner;
- move_info.objectives = "%";
- move_info.weights[0] = 1;
-
- from = &p1;
- to = &p2;
+ perimeter_t *from;
+ perimeter_t *to;
+ int cur_cost;
+ int start_terrain;
+ move_info_t move_info;
+ char old_contents;
+
+ old_contents = vmap[dest_loc].contents;
+ vmap[dest_loc].contents = '%'; /* mark objective */
+ move_info.city_owner = owner;
+ move_info.objectives = "%";
+ move_info.weights[0] = 1;
+
+ from = &p1;
+ to = &p2;
- if (terrain == T_AIR) start_terrain = T_LAND;
- else start_terrain = terrain;
+ if (terrain == T_AIR) start_terrain = T_LAND;
+ else start_terrain = terrain;
- start_perimeter (path_map, from, cur_loc, start_terrain);
- cur_cost = 0; /* cost to reach current perimeter */
-
- for (;;) {
- to->len = 0; /* nothing in perim yet */
- expand_perimeter (path_map, vmap, &move_info, from,
- terrain, cur_cost, 1, 1, to, to);
- cur_cost += 1;
- if (to->len == 0 || best_cost <= cur_cost) {
- vmap[dest_loc].contents = old_contents;
- return best_loc;
- }
- SWAP (from, to);
+ start_perimeter (path_map, from, cur_loc, start_terrain);
+ cur_cost = 0; /* cost to reach current perimeter */
+
+ for (;;) {
+ to->len = 0; /* nothing in perim yet */
+ expand_perimeter (path_map, vmap, &move_info, from,
+ terrain, cur_cost, 1, 1, to, to);
+ cur_cost += 1;
+ if (to->len == 0 || best_cost <= cur_cost) {
+ vmap[dest_loc].contents = old_contents;
+ return best_loc;
}
+ SWAP (from, to);
+ }
}
/*
void
vmap_mark_path(path_map_t *path_map, view_map_t *vmap, loc_t dest)
{
- int n;
- loc_t new_dest;
+ int n;
+ 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 */
+ if (path_map[dest].cost == 0) return; /* reached end of path */
+ if (path_map[dest].terrain == T_PATH) return; /* already marked */
- path_map[dest].terrain = T_PATH; /* this square is on path */
+ path_map[dest].terrain = T_PATH; /* this square is on path */
- /* loop to mark adjacent squares on shortest path */
- FOR_ADJ (dest, new_dest, n)
+ /* loop to mark adjacent squares on shortest path */
+ FOR_ADJ (dest, new_dest, n)
if (path_map[new_dest].cost == path_map[dest].cost - path_map[dest].inc_cost)
- vmap_mark_path (path_map, vmap, new_dest);
+ vmap_mark_path (path_map, vmap, new_dest);
}
void
vmap_mark_adjacent(path_map_t path_map[], loc_t loc)
{
- int i;
- loc_t new_loc;
+ int i;
+ loc_t new_loc;
- FOR_ADJ_ON (loc, new_loc, i)
- path_map[new_loc].terrain = T_PATH;
+ FOR_ADJ_ON (loc, new_loc, i)
+ path_map[new_loc].terrain = T_PATH;
}
/*
void
vmap_mark_near_path(path_map_t path_map[], loc_t loc)
{
- int i, j;
- loc_t new_loc, xloc;
- int hit_loc[8];
+ int i, j;
+ loc_t new_loc, xloc;
+ int hit_loc[8];
- (void) bzero ((char *)hit_loc, sizeof(int)*8);
+ (void) bzero ((char *)hit_loc, sizeof(int)*8);
- FOR_ADJ_ON (loc, new_loc, i) {
- FOR_ADJ_ON (new_loc, xloc, j)
- if (xloc != loc && path_map[xloc].terrain == T_PATH) {
- hit_loc[i] = 1;
- break;
- }
- }
- for (i = 0; i < 8; i++)
+ FOR_ADJ_ON (loc, new_loc, i) {
+ FOR_ADJ_ON (new_loc, xloc, j)
+ if (xloc != loc && path_map[xloc].terrain == T_PATH) {
+ hit_loc[i] = 1;
+ break;
+ }
+ }
+ for (i = 0; i < 8; i++)
if (hit_loc[i])
- path_map[loc + dir_offset[i]].terrain = T_PATH;
+ path_map[loc + dir_offset[i]].terrain = T_PATH;
}
/*
vmap_find_dir(path_map_t path_map[], view_map_t *vmap,
loc_t loc, char *terrain, char *adj_char)
{
- int i, count, bestcount;
- loc_t bestloc, new_loc;
- int path_count, bestpath;
- char *p;
+ int i, count, bestcount;
+ loc_t bestloc, new_loc;
+ int path_count, bestpath;
+ char *p;
- if (trace_pmap)
- print_pzoom ("Before vmap_find_dir:", path_map, vmap);
+ if (trace_pmap)
+ print_pzoom ("Before vmap_find_dir:", path_map, vmap);
- bestcount = -INFINITY; /* no best yet */
- bestpath = -1;
- bestloc = loc;
+ bestcount = -INFINITY; /* no best yet */
+ bestpath = -1;
+ bestloc = loc;
- for (i = 0; i < 8; i++) { /* for each adjacent square */
- new_loc = loc + dir_offset[order[i]];
- if (path_map[new_loc].terrain == T_PATH) { /* which is on path */
- p = strchr (terrain, vmap[new_loc].contents);
+ for (i = 0; i < 8; i++) { /* for each adjacent square */
+ new_loc = loc + dir_offset[order[i]];
+ if (path_map[new_loc].terrain == T_PATH) { /* which is on path */
+ p = strchr (terrain, vmap[new_loc].contents);
- if (p != NULL) { /* desirable square? */
- count = vmap_count_adjacent (vmap, new_loc, adj_char);
- path_count = vmap_count_path (path_map, new_loc);
+ if (p != NULL) { /* desirable square? */
+ count = vmap_count_adjacent (vmap, new_loc, adj_char);
+ path_count = vmap_count_path (path_map, new_loc);
- /* remember best location */
- if (count > bestcount
- || (count == bestcount && path_count > bestpath) ) {
- bestcount = count;
- bestpath = path_count;
- bestloc = new_loc;
- }
- }
+ /* remember best location */
+ if (count > bestcount
+ || (count == bestcount && path_count > bestpath) ) {
+ bestcount = count;
+ bestpath = path_count;
+ bestloc = new_loc;
}
+ }
}
- return (bestloc);
+ }
+ return (bestloc);
}
/*
int
vmap_count_adjacent(view_map_t *vmap, loc_t loc, char *adj_char)
{
- int i, count;
- loc_t new_loc;
- char *p;
- int len;
+ int i, count;
+ loc_t new_loc;
+ char *p;
+ int len;
- len = strlen (adj_char);
+ len = strlen (adj_char);
- count = 0;
+ count = 0;
- FOR_ADJ_ON (loc, new_loc, i) {
- p = strchr (adj_char, vmap[new_loc].contents);
- if (p) count += 8 * (len - (p - adj_char));
- }
- return (count);
+ FOR_ADJ_ON (loc, new_loc, i) {
+ p = strchr (adj_char, vmap[new_loc].contents);
+ if (p) count += 8 * (len - (p - adj_char));
+ }
+ return (count);
}
/*
int
vmap_count_path(path_map_t *pmap, loc_t loc)
{
- int i, count;
- loc_t new_loc;
+ int i, count;
+ loc_t new_loc;
- count = 0;
+ count = 0;
- FOR_ADJ_ON (loc, new_loc, i)
+ FOR_ADJ_ON (loc, new_loc, i)
if (pmap[new_loc].terrain == T_PATH)
- count += 1;
+ count += 1;
- return (count);
+ return (count);
}
/*
bool
rmap_shore(loc_t loc)
{
- loc_t i, j;
+ loc_t i, j;
- FOR_ADJ_ON (loc, j, i)
- if (map[j].contents == '.') return (true);
+ FOR_ADJ_ON (loc, j, i)
+ if (map[j].contents == '.') return (true);
- return (false);
+ return (false);
}
bool
vmap_shore(view_map_t *vmap, loc_t loc)
{
- loc_t i, j;
+ loc_t i, j;
- FOR_ADJ_ON (loc, j, i)
- if (vmap[j].contents != ' ' && vmap[j].contents != '+' && map[j].contents == '.')
- return (true);
+ FOR_ADJ_ON (loc, j, i)
+ if (vmap[j].contents != ' ' && vmap[j].contents != '+' && map[j].contents == '.')
+ return (true);
- return (false);
+ return (false);
}
/*
bool
vmap_at_sea(view_map_t *vmap, loc_t loc)
{
- loc_t 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);
+ if (map[loc].contents != '.') return (false);
+ FOR_ADJ_ON (loc, j, i)
+ if (vmap[j].contents == ' ' || vmap[j].contents == '+' || map[j].contents != '.')
+ return (false);
- return (true);
+ return (true);
}
bool
rmap_at_sea (loc_t loc)
{
- loc_t i, j;
+ loc_t i, j;
- if (map[loc].contents != '.') return (false);
- FOR_ADJ_ON (loc, j, i) {
- if (map[j].contents != '.') return (false);
- }
- return (true);
+ if (map[loc].contents != '.') return (false);
+ FOR_ADJ_ON (loc, j, i) {
+ if (map[j].contents != '.') return (false);
+ }
+ return (true);
}
+/* end */
int
find_nearest_city(loc_t loc, int owner, loc_t *city_loc)
{
- loc_t best_loc;
- long best_dist;
- long new_dist, i;
+ loc_t best_loc;
+ long best_dist;
+ long new_dist, i;
- best_dist = INFINITY;
- best_loc = loc;
+ best_dist = INFINITY;
+ best_loc = loc;
- for (i = 0; i < NUM_CITY; i++)
+ for (i = 0; i < NUM_CITY; i++)
if (city[i].owner == owner) {
- new_dist = dist (loc, city[i].loc);
- if (new_dist < best_dist) {
- best_dist = new_dist;
- best_loc = city[i].loc;
- }
+ new_dist = dist (loc, city[i].loc);
+ if (new_dist < best_dist) {
+ best_dist = new_dist;
+ best_loc = city[i].loc;
+ }
}
- *city_loc = best_loc;
- return best_dist;
+ *city_loc = best_loc;
+ return best_dist;
}
/*
city_info_t *find_city(loc_t loc)
{
- return (map[loc].cityp);
+ return (map[loc].cityp);
}
/*
int obj_moves (piece_info_t *obj)
{
- return (piece_attr[obj->type].speed * obj->hits
- + piece_attr[obj->type].max_hits - 1) /* round up */
- / piece_attr[obj->type].max_hits;
+ return (piece_attr[obj->type].speed * obj->hits
+ + piece_attr[obj->type].max_hits - 1) /* round up */
+ / piece_attr[obj->type].max_hits;
}
/*
int obj_capacity(piece_info_t *obj)
{
- return (piece_attr[obj->type].capacity * obj->hits
- + piece_attr[obj->type].max_hits - 1) /* round up */
- / piece_attr[obj->type].max_hits;
+ return (piece_attr[obj->type].capacity * obj->hits
+ + piece_attr[obj->type].max_hits - 1) /* round up */
+ / piece_attr[obj->type].max_hits;
}
/*
piece_info_t *find_obj(int type, loc_t loc)
{
- piece_info_t *p;
+ piece_info_t *p;
- for (p = map[loc].objp; p != NULL; p = p->loc_link.next)
+ for (p = map[loc].objp; p != NULL; p = p->loc_link.next)
if (p->type == type) return (p);
- return (NULL);
+ return (NULL);
}
/*
piece_info_t *find_nfull(int type, loc_t loc)
{
- piece_info_t *p;
+ piece_info_t *p;
- for (p = map[loc].objp; p != NULL; p = p->loc_link.next)
+ for (p = map[loc].objp; p != NULL; p = p->loc_link.next)
if (p->type == type) {
- if (obj_capacity (p) > p->count) return (p);
+ if (obj_capacity (p) > p->count) return (p);
}
- return (NULL);
+ return (NULL);
}
/*
loc_t
find_transport(int owner, loc_t loc)
{
- int i;
- loc_t new_loc;
- piece_info_t *t;
-
- for (i = 0; i < 8; i++) { /* look around */
- new_loc = loc + dir_offset[i];
- t = find_nfull (TRANSPORT, new_loc);
- if (t != NULL && t->owner == owner) return (new_loc);
- }
- return (loc); /* no tt found */
+ int i;
+ loc_t new_loc;
+ piece_info_t *t;
+
+ for (i = 0; i < 8; i++) { /* look around */
+ new_loc = loc + dir_offset[i];
+ t = find_nfull (TRANSPORT, new_loc);
+ if (t != NULL && t->owner == owner) return (new_loc);
+ }
+ return (loc); /* no tt found */
}
/*
piece_info_t *
find_obj_at_loc(loc_t loc)
{
- piece_info_t *p, *best;
+ piece_info_t *p, *best;
- best = map[loc].objp;
- if (best == NULL) return (NULL); /* nothing here */
+ best = map[loc].objp;
+ if (best == NULL) return (NULL); /* nothing here */
- for (p = best->loc_link.next; p != NULL; p = p->loc_link.next)
+ for (p = best->loc_link.next; p != NULL; p = p->loc_link.next)
if (p->type > best->type && p->type != SATELLITE)
- best = p;
+ best = p;
- return (best);
+ return (best);
}
/*
void disembark(piece_info_t *obj)
{
- if (obj->ship) {
- UNLINK (obj->ship->cargo, obj, cargo_link);
- obj->ship->count -= 1;
- obj->ship = NULL;
- }
+ if (obj->ship) {
+ UNLINK (obj->ship->cargo, obj, cargo_link);
+ obj->ship->count -= 1;
+ obj->ship = NULL;
+ }
}
/*
void kill_obj(piece_info_t *obj, loc_t loc)
{
- void kill_one();
+ void kill_one();
- piece_info_t **list;
- view_map_t *vmap;
+ piece_info_t **list;
+ view_map_t *vmap;
- vmap = MAP(obj->owner);
- list = LIST(obj->owner);
+ vmap = MAP(obj->owner);
+ list = LIST(obj->owner);
- while (obj->cargo != NULL) /* kill contents */
- kill_one (list, obj->cargo);
+ while (obj->cargo != NULL) /* kill contents */
+ kill_one (list, obj->cargo);
- kill_one (list, obj);
- scan (vmap, loc); /* scan around new location */
+ kill_one (list, obj);
+ scan (vmap, loc); /* scan around new location */
}
/* kill an object without scanning */
void kill_one(piece_info_t **list, piece_info_t *obj)
{
- UNLINK (list[obj->type], obj, piece_link); /* unlink obj from all lists */
- UNLINK (map[obj->loc].objp, obj, loc_link);
- disembark (obj);
+ UNLINK (list[obj->type], obj, piece_link); /* unlink obj from all lists */
+ UNLINK (map[obj->loc].objp, obj, loc_link);
+ disembark (obj);
- LINK (free_list, obj, piece_link); /* return object to free list */
- obj->hits = 0; /* let all know this object is dead */
- obj->moved = piece_attr[obj->type].speed; /* object has moved */
+ LINK (free_list, obj, piece_link); /* return object to free list */
+ obj->hits = 0; /* let all know this object is dead */
+ obj->moved = piece_attr[obj->type].speed; /* object has moved */
}
/*
void kill_city(city_info_t *cityp)
{
- view_map_t *vmap;
- piece_info_t *p;
- piece_info_t *next_p;
- piece_info_t **list;
- int i;
+ view_map_t *vmap;
+ piece_info_t *p;
+ piece_info_t *next_p;
+ piece_info_t **list;
+ int i;
- /* change ownership of hardware at this location; but not satellites */
- for (p = map[cityp->loc].objp; p; p = next_p) {
- next_p = p->loc_link.next;
+ /* change ownership of hardware at this location; but not satellites */
+ for (p = map[cityp->loc].objp; p; p = next_p) {
+ next_p = p->loc_link.next;
- if (p->type == ARMY) kill_obj (p, cityp->loc);
- else if (p->type != SATELLITE) {
- if (p->type == TRANSPORT) {
- list = LIST(p->owner);
+ if (p->type == ARMY) kill_obj (p, cityp->loc);
+ else if (p->type != SATELLITE) {
+ if (p->type == TRANSPORT) {
+ list = LIST(p->owner);
- while (p->cargo != NULL) /* kill contents */
- kill_one (list, p->cargo);
- }
- list = LIST (p->owner);
- UNLINK (list[p->type], p, piece_link);
- p->owner = (p->owner == USER ? COMP : USER);
- list = LIST (p->owner);
- LINK (list[p->type], p, piece_link);
+ while (p->cargo != NULL) /* kill contents */
+ kill_one (list, p->cargo);
+ }
+ list = LIST (p->owner);
+ UNLINK (list[p->type], p, piece_link);
+ p->owner = (p->owner == USER ? COMP : USER);
+ list = LIST (p->owner);
+ LINK (list[p->type], p, piece_link);
- p->func = NOFUNC;
- }
+ p->func = NOFUNC;
}
+ }
- if (cityp->owner != UNOWNED) {
- vmap = MAP(cityp->owner);
- cityp->owner = UNOWNED;
- cityp->work = 0;
- cityp->prod = NOPIECE;
+ if (cityp->owner != UNOWNED) {
+ vmap = MAP(cityp->owner);
+ cityp->owner = UNOWNED;
+ cityp->work = 0;
+ cityp->prod = NOPIECE;
- for (i = 0; i < NUM_OBJECTS; i++)
- cityp->func[i] = NOFUNC;
+ for (i = 0; i < NUM_OBJECTS; i++)
+ cityp->func[i] = NOFUNC;
- scan (vmap, cityp->loc);
- }
+ scan (vmap, cityp->loc);
+ }
}
/*
void
produce(city_info_t *cityp)
{
- piece_info_t **list;
- piece_info_t *new;
+ piece_info_t **list;
+ piece_info_t *new;
- list = LIST (cityp->owner);
+ list = LIST (cityp->owner);
- cityp->work -= piece_attr[(int)cityp->prod].build_time;
+ cityp->work -= piece_attr[(int)cityp->prod].build_time;
- ASSERT (free_list); /* can we allocate? */
- new = free_list;
- UNLINK (free_list, new, piece_link);
- LINK (list[(int)cityp->prod], new, piece_link);
- LINK (map[cityp->loc].objp, new, loc_link);
- new->cargo_link.next = NULL;
- new->cargo_link.prev = NULL;
+ ASSERT (free_list); /* can we allocate? */
+ new = free_list;
+ UNLINK (free_list, new, piece_link);
+ LINK (list[(int)cityp->prod], new, piece_link);
+ LINK (map[cityp->loc].objp, new, loc_link);
+ new->cargo_link.next = NULL;
+ new->cargo_link.prev = NULL;
- new->loc = cityp->loc;
- new->func = NOFUNC;
- new->hits = piece_attr[(int)cityp->prod].max_hits;
- new->owner = cityp->owner;
- new->type = cityp->prod;
- new->moved = 0;
- new->cargo = NULL;
- new->ship = NULL;
- new->count = 0;
- new->range = piece_attr[(int)cityp->prod].range;
+ new->loc = cityp->loc;
+ new->func = NOFUNC;
+ new->hits = piece_attr[(int)cityp->prod].max_hits;
+ new->owner = cityp->owner;
+ new->type = cityp->prod;
+ new->moved = 0;
+ new->cargo = NULL;
+ new->ship = NULL;
+ new->count = 0;
+ new->range = piece_attr[(int)cityp->prod].range;
- if (new->type == SATELLITE) { /* set random move direction */
- new->func = sat_dir[irand (4)];
- }
+ if (new->type == SATELLITE) { /* set random move direction */
+ new->func = sat_dir[irand (4)];
+ }
}
/*
void move_obj(piece_info_t *obj, loc_t new_loc)
{
- view_map_t *vmap;
- loc_t old_loc;
- piece_info_t *p;
+ view_map_t *vmap;
+ loc_t old_loc;
+ piece_info_t *p;
- ASSERT (obj->hits);
- vmap = MAP(obj->owner);
+ ASSERT (obj->hits);
+ vmap = MAP(obj->owner);
- old_loc = obj->loc; /* save original location */
- obj->moved += 1;
- obj->loc = new_loc;
- obj->range--;
+ old_loc = obj->loc; /* save original location */
+ obj->moved += 1;
+ obj->loc = new_loc;
+ obj->range--;
- disembark (obj); /* remove object from any ship */
+ disembark (obj); /* remove object from any ship */
- UNLINK (map[old_loc].objp, obj, loc_link);
- LINK (map[new_loc].objp, obj, loc_link);
-
- /* move any objects contained in object */
- for (p = obj->cargo; p != NULL; p = p->cargo_link.next) {
- p->loc = new_loc;
- UNLINK (map[old_loc].objp, p, loc_link);
- LINK (map[new_loc].objp, p, loc_link);
- }
+ UNLINK (map[old_loc].objp, obj, loc_link);
+ LINK (map[new_loc].objp, obj, loc_link);
+
+ /* move any objects contained in object */
+ for (p = obj->cargo; p != NULL; p = p->cargo_link.next) {
+ p->loc = new_loc;
+ UNLINK (map[old_loc].objp, p, loc_link);
+ LINK (map[new_loc].objp, p, loc_link);
+ }
- switch (obj->type) { /* board new ship */
- case FIGHTER:
- if (map[obj->loc].cityp == NULL) { /* not in a city? */
- p = find_nfull (CARRIER, obj->loc);
- if (p != NULL) embark (p, obj);
- }
- break;
-
- case ARMY:
- p = find_nfull (TRANSPORT, obj->loc);
- if (p != NULL) embark (p, obj);
- break;
+ switch (obj->type) { /* board new ship */
+ case FIGHTER:
+ if (map[obj->loc].cityp == NULL) { /* not in a city? */
+ p = find_nfull (CARRIER, obj->loc);
+ if (p != NULL) embark (p, obj);
}
+ break;
+
+ case ARMY:
+ p = find_nfull (TRANSPORT, obj->loc);
+ if (p != NULL) embark (p, obj);
+ break;
+ }
- if (obj->type == SATELLITE)
- scan_sat (vmap, obj->loc);
- scan (vmap, obj->loc);
+ if (obj->type == SATELLITE)
+ scan_sat (vmap, obj->loc);
+ scan (vmap, obj->loc);
}
/*
static loc_t
bounce(loc_t loc, loc_t dir1, loc_t dir2, loc_t dir3)
{
- int new_loc;
+ int new_loc;
- new_loc = loc + dir_offset[MOVE_DIR (dir1)];
- if (map[new_loc].on_board) return dir1;
+ new_loc = loc + dir_offset[MOVE_DIR (dir1)];
+ if (map[new_loc].on_board) return dir1;
- new_loc = loc + dir_offset[MOVE_DIR (dir2)];
- if (map[new_loc].on_board) return dir2;
+ new_loc = loc + dir_offset[MOVE_DIR (dir2)];
+ if (map[new_loc].on_board) return dir2;
- return dir3;
+ return dir3;
}
/* Move a satellite one square. */
static void
move_sat1(piece_info_t *obj)
{
- int dir;
- loc_t new_loc;
-
+ int dir;
+ loc_t new_loc;
+
+ dir = MOVE_DIR(obj->func);
+ new_loc = obj->loc + dir_offset[dir];
+
+ if (!map[new_loc].on_board) {
+ switch (obj->func) {
+ case MOVE_NE:
+ obj->func = bounce (obj->loc, MOVE_NW, MOVE_SE, MOVE_SW);
+ break;
+ case MOVE_NW:
+ obj->func = bounce (obj->loc, MOVE_NE, MOVE_SW, MOVE_SE);
+ break;
+ case MOVE_SE:
+ obj->func = bounce (obj->loc, MOVE_SW, MOVE_NE, MOVE_NW);
+ break;
+ case MOVE_SW:
+ obj->func = bounce (obj->loc, MOVE_SE, MOVE_NW, MOVE_NE);
+ break;
+ default: ABORT;
+ }
dir = MOVE_DIR(obj->func);
new_loc = obj->loc + dir_offset[dir];
-
- if (!map[new_loc].on_board) {
- switch (obj->func) {
- case MOVE_NE:
- obj->func = bounce (obj->loc, MOVE_NW, MOVE_SE, MOVE_SW);
- break;
- case MOVE_NW:
- obj->func = bounce (obj->loc, MOVE_NE, MOVE_SW, MOVE_SE);
- break;
- case MOVE_SE:
- obj->func = bounce (obj->loc, MOVE_SW, MOVE_NE, MOVE_NW);
- break;
- case MOVE_SW:
- obj->func = bounce (obj->loc, MOVE_SE, MOVE_NW, MOVE_NE);
- break;
- default: ABORT;
- }
- dir = MOVE_DIR(obj->func);
- new_loc = obj->loc + dir_offset[dir];
- }
- move_obj (obj, new_loc);
+ }
+ move_obj (obj, new_loc);
}
/*
void
move_sat(piece_info_t *obj)
{
- obj->moved = 0;
+ obj->moved = 0;
- while (obj->moved < obj_moves (obj)) {
- move_sat1 (obj);
- if (obj->range == 0) {
- if (obj->owner == USER)
- comment ("Satellite at %d crashed and burned.", loc_disp(obj->loc));
- ksend ("Satellite at %d crashed and burned.", loc_disp(obj->loc));
- kill_obj (obj, obj->loc);
- }
+ while (obj->moved < obj_moves (obj)) {
+ move_sat1 (obj);
+ if (obj->range == 0) {
+ if (obj->owner == USER)
+ comment ("Satellite at %d crashed and burned.", loc_disp(obj->loc));
+ ksend ("Satellite at %d crashed and burned.", loc_disp(obj->loc));
+ kill_obj (obj, obj->loc);
}
+ }
}
/*
bool good_loc(piece_info_t *obj, loc_t loc)
{
- view_map_t *vmap;
- piece_info_t *p;
+ view_map_t *vmap;
+ piece_info_t *p;
- if (!map[loc].on_board) return (false);
+ if (!map[loc].on_board) return (false);
- vmap = MAP (obj->owner);
+ vmap = MAP (obj->owner);
- if (strchr (piece_attr[obj->type].terrain, vmap[loc].contents) != NULL)
- return (true);
+ if (strchr (piece_attr[obj->type].terrain, vmap[loc].contents) != NULL)
+ return (true);
- /* armies can move into unfull transports */
- if (obj->type == ARMY) {
- p = find_nfull (TRANSPORT, loc);
- return (p != NULL && p->owner == obj->owner);
- }
+ /* armies can move into unfull transports */
+ if (obj->type == ARMY) {
+ p = find_nfull (TRANSPORT, loc);
+ return (p != NULL && p->owner == obj->owner);
+ }
- /* ships and fighters can move into cities */
- if (map[loc].cityp && map[loc].cityp->owner == obj->owner)
- return (true);
+ /* ships and fighters can move into cities */
+ if (map[loc].cityp && map[loc].cityp->owner == obj->owner)
+ return (true);
- /* fighters can move onto unfull carriers */
- if (obj->type == FIGHTER) {
- p = find_nfull (CARRIER, loc);
- return (p != NULL && p->owner == obj->owner);
- }
+ /* fighters can move onto unfull carriers */
+ if (obj->type == FIGHTER) {
+ p = find_nfull (CARRIER, loc);
+ return (p != NULL && p->owner == obj->owner);
+ }
- return (false);
+ return (false);
}
void describe_obj(piece_info_t *obj)
{
- char func[STRSIZE];
- char other[STRSIZE];
+ char func[STRSIZE];
+ char other[STRSIZE];
- if (obj->func >= 0) (void) sprintf (func, "%d", loc_disp(obj->func));
- else (void) sprintf (func, func_name[FUNCI(obj->func)]);
+ if (obj->func >= 0) (void) sprintf (func, "%d", loc_disp(obj->func));
+ else (void) sprintf (func, func_name[FUNCI(obj->func)]);
- other[0] = 0;
-
- switch (obj->type) { /* set other information */
- case FIGHTER:
- (void) sprintf (other,"; range = %d",obj->range);
- break;
-
- case TRANSPORT:
- (void) sprintf (other,"; armies = %d",obj->count);
- break;
-
- case CARRIER:
- (void) sprintf (other,"; fighters = %d",obj->count);
- break;
- }
-
- prompt ("%s at %d: moves = %d; hits = %d; func = %s%s",
- piece_attr[obj->type].name,
- loc_disp(obj->loc),
- obj_moves (obj) - obj->moved,
- obj->hits,
- func,
- other);
+ other[0] = 0;
+
+ switch (obj->type) { /* set other information */
+ case FIGHTER:
+ (void) sprintf (other,"; range = %d",obj->range);
+ break;
+
+ case TRANSPORT:
+ (void) sprintf (other,"; armies = %d",obj->count);
+ break;
+
+ case CARRIER:
+ (void) sprintf (other,"; fighters = %d",obj->count);
+ break;
+ }
+
+ prompt ("%s at %d: moves = %d; hits = %d; func = %s%s",
+ piece_attr[obj->type].name,
+ loc_disp(obj->loc),
+ obj_moves (obj) - obj->moved,
+ obj->hits,
+ func,
+ other);
}
/*
void
scan(view_map_t vmap[], loc_t loc)
{
- void update(), check(void);
+ void update(), check(void);
- int i;
- loc_t xloc;
+ int i;
+ loc_t xloc;
#ifdef DEBUG
- check (); /* perform a consistency check */
+ check (); /* perform a consistency check */
#endif
- ASSERT (map[loc].on_board); /* passed loc must be on board */
+ ASSERT (map[loc].on_board); /* passed loc must be on board */
- for (i = 0; i < 8; i++) { /* for each surrounding cell */
- xloc = loc + dir_offset[i];
- update (vmap, xloc);
- }
- update (vmap, loc); /* update current location as well */
+ for (i = 0; i < 8; i++) { /* for each surrounding cell */
+ xloc = loc + dir_offset[i];
+ update (vmap, xloc);
+ }
+ update (vmap, loc); /* update current location as well */
}
/*
void
update(view_map_t vmap[], loc_t loc)
{
- piece_info_t *p;
+ piece_info_t *p;
- vmap[loc].seen = date;
+ vmap[loc].seen = date;
- if (map[loc].cityp) /* is there a city here? */
- vmap[loc].contents = city_char[map[loc].cityp->owner];
+ if (map[loc].cityp) /* is there a city here? */
+ vmap[loc].contents = city_char[map[loc].cityp->owner];
- else {
- p = find_obj_at_loc (loc);
+ else {
+ p = find_obj_at_loc (loc);
- if (p == NULL) /* nothing here? */
- vmap[loc].contents = map[loc].contents;
- else if (p->owner == USER)
- vmap[loc].contents = piece_attr[p->type].sname;
- else vmap[loc].contents = tolower (piece_attr[p->type].sname);
- }
- if (vmap == comp_map)
- display_locx (COMP, comp_map, loc);
- else if (vmap == user_map)
- display_locx (USER, user_map, loc);
+ if (p == NULL) /* nothing here? */
+ vmap[loc].contents = map[loc].contents;
+ else if (p->owner == USER)
+ vmap[loc].contents = piece_attr[p->type].sname;
+ else
+ vmap[loc].contents = tolower (piece_attr[p->type].sname);
+ }
+ if (vmap == comp_map)
+ display_locx (COMP, comp_map, loc);
+ else if (vmap == user_map)
+ display_locx (USER, user_map, loc);
}
/*
void
set_prod(city_info_t *cityp)
{
- int i;
+ int i;
- scan (user_map, cityp->loc);
- display_loc_u (cityp->loc);
+ scan (user_map, cityp->loc);
+ display_loc_u (cityp->loc);
- for (;;) {
- prompt ("What do you want the city at %d to produce? ",loc_disp(cityp->loc));
+ for (;;) {
+ prompt ("What do you want the city at %d to produce? ",loc_disp(cityp->loc));
- i = get_piece_name ();
+ i = get_piece_name ();
- if (i == NOPIECE)
- error ("I don't know how to build those.");
+ if (i == NOPIECE)
+ error ("I don't know how to build those.");
- else {
- cityp->prod = i;
- city->work = -(piece_attr[i].build_time / 5);
- return;
- }
+ else {
+ cityp->prod = i;
+ city->work = -(piece_attr[i].build_time / 5);
+ return;
}
+ }
}
/* Get the name of a type of object. */
int
get_piece_name(void)
{
- char c;
- int i;
+ char c;
+ int i;
- c = get_chx (); /* get the answer */
+ c = get_chx (); /* get the answer */
- for (i = 0; i < NUM_OBJECTS; i++)
+ for (i = 0; i < NUM_OBJECTS; i++)
if (piece_attr[i].sname == c) {
- return i;
+ return i;
}
- return NOPIECE;
+ return NOPIECE;
}
+
+/* end */
void
topini(void)
{
- info (0, 0, 0);
+ info (0, 0, 0);
}
/*
Write a message to one of the top lines.
static void vtopmsg(int line, const char *fmt, va_list varglist)
/* assemble command in printf(3) style, print to a top line */
{
- char junkbuf[STRSIZE];
+ char junkbuf[STRSIZE];
- if (line < 1 || line > NUMTOPS)
- line = 1;
- (void) move (line - 1, 0);
- vsprintf(junkbuf, fmt, varglist);
- (void) addstr (junkbuf);
- (void) clrtoeol();
+ if (line < 1 || line > NUMTOPS)
+ line = 1;
+ (void) move (line - 1, 0);
+ vsprintf(junkbuf, fmt, varglist);
+ (void) addstr (junkbuf);
+ (void) clrtoeol();
}
void
topmsg(int line, char *fmt, ...)
{
- va_list ap;
+ va_list ap;
- va_start(ap, fmt);
- vtopmsg(line, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ vtopmsg(line, fmt, ap);
+ va_end(ap);
}
/*
void
prompt(char *fmt, ...)
{
- va_list ap;
+ va_list ap;
- va_start(ap, fmt);
- vtopmsg(1, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ vtopmsg(1, fmt, ap);
+ va_end(ap);
}
/*
void
error(char *fmt, ...)
{
- va_list ap;
+ va_list ap;
- va_start(ap, fmt);
- vtopmsg(2, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ vtopmsg(2, fmt, ap);
+ va_end(ap);
}
/*
void
extra(char *fmt, ...)
{
- va_list ap;
+ va_list ap;
- va_start(ap, fmt);
- vtopmsg(3, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ vtopmsg(3, fmt, ap);
+ va_end(ap);
}
void
huh(void)
{
- error ("Type H for Help.");
+ error ("Type H for Help.");
}
/*
void
info(char *a, char *b, char *c)
{
- if (need_delay) delay ();
- topmsg (1, a);
- topmsg (2, b);
- topmsg (3, c);
- need_delay = (a || b || c);
+ if (need_delay) delay ();
+ topmsg (1, a);
+ topmsg (2, b);
+ topmsg (3, c);
+ need_delay = (a || b || c);
}
void
-set_need_delay(void) {
- need_delay = 1;
+set_need_delay(void)
+{
+ need_delay = 1;
}
void
comment (char *fmt, ...)
{
- va_list ap;
-
- va_start(ap, fmt);
- if (need_delay) delay ();
- topmsg (1, "");
- topmsg (2, "");
- vtopmsg (3, fmt, ap);
- need_delay = (fmt != 0);
- va_end(ap);
+ va_list ap;
+
+ va_start(ap, fmt);
+ if (need_delay) delay ();
+ topmsg (1, "");
+ topmsg (2, "");
+ vtopmsg (3, fmt, ap);
+ need_delay = (fmt != 0);
+ va_end(ap);
}
void
pdebug(char *fmt, ...)
{
- va_list ap;
+ va_list ap;
- if (!print_debug) return;
+ if (!print_debug) return;
- va_start(ap, fmt);
- if (need_delay) delay ();
- topmsg (1, "");
- topmsg (2, "");
- vtopmsg (3, fmt, ap);
- need_delay = (fmt != 0);
- va_end(ap);
+ va_start(ap, fmt);
+ if (need_delay) delay ();
+ topmsg (1, "");
+ topmsg (2, "");
+ vtopmsg (3, fmt, ap);
+ need_delay = (fmt != 0);
+ va_end(ap);
}
/* kermyt begin */
void
vksend(const char *fmt, va_list varglist)
{
- if(!(my_stream=fopen("info_list.txt","a")))
- {
- error("Cannot open info_list.txt");
- return;
- }
- vfprintf(my_stream, fmt, varglist);
- fclose(my_stream);
+ if(!(my_stream=fopen("info_list.txt","a")))
+ {
+ error("Cannot open info_list.txt");
return;
+ }
+ vfprintf(my_stream, fmt, varglist);
+ fclose(my_stream);
+ return;
}
void
ksend(char *fmt, ...)
{
- va_list ap;
+ va_list ap;
- va_start(ap, fmt);
- vksend(fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ vksend(fmt, ap);
+ va_end(ap);
}
/* kermyt end */
void
get_str(char *buf, int sizep)
{
- (void) echo();
- get_strq(buf, sizep);
- (void) noecho();
+ (void) echo();
+ get_strq(buf, sizep);
+ (void) noecho();
}
/*
void
get_strq(char *buf, int sizep)
{
- sizep = sizep; /* size of buf, currently unused */
-
- (void) nocrmode ();
- (void) refresh ();
- (void) getstr (buf);
- need_delay = false;
- info (0, 0, 0);
- (void) crmode ();
+ sizep = sizep; /* size of buf, currently unused */
+
+ (void) nocrmode ();
+ (void) refresh ();
+ (void) getstr (buf);
+ need_delay = false;
+ info (0, 0, 0);
+ (void) crmode ();
}
/*
char
get_chx(void)
{
- char c;
+ char c;
- c = get_cq ();
+ c = get_cq ();
- if (islower(c))
- return (toupper(c));
- else
- return (c);
+ if (islower(c))
+ return (toupper(c));
+ else
+ return (c);
}
/*
int
getint(char *message)
{
- char buf[STRSIZE];
- char *p;
+ char buf[STRSIZE];
+ char *p;
- for (;;) { /* until we get a legal number */
- prompt (message,0,0,0,0,0,0,0,0);
- get_str (buf, sizeof (buf));
+ for (;;) { /* until we get a legal number */
+ prompt (message,0,0,0,0,0,0,0,0);
+ get_str (buf, sizeof (buf));
- for (p = buf; *p; p++) {
- if (*p < '0' || *p > '9') {
- error ("Please enter an integer.",0,0,0,0,0,0,0,0);
- break;
- }
- }
- if (*p == 0) { /* no error yet? */
- if (p - buf > 7) /* too many digits? */
- error ("Please enter a small integer.",0,0,0,0,0,0,0,0);
- else return (atoi (buf));
- }
+ for (p = buf; *p; p++) {
+ if (*p < '0' || *p > '9') {
+ error ("Please enter an integer.",0,0,0,0,0,0,0,0);
+ break;
+ }
}
+ if (*p == 0) { /* no error yet? */
+ if (p - buf > 7) /* too many digits? */
+ error ("Please enter a small integer.",0,0,0,0,0,0,0,0);
+ else return (atoi (buf));
+ }
+ }
}
/*
char
get_c(void)
{
- char c; /* one char and a null */
+ char c; /* one char and a null */
- (void) echo ();
- c = get_cq ();
- (void) noecho ();
- return (c);
+ (void) echo ();
+ c = get_cq ();
+ (void) noecho ();
+ return (c);
}
/*
char
get_cq(void)
{
- char c;
-
- (void) crmode ();
- (void) refresh ();
- c = getch ();
- topini (); /* clear information lines */
- (void) nocrmode ();
- return (c);
+ char c;
+
+ (void) crmode ();
+ (void) refresh ();
+ c = getch ();
+ topini (); /* clear information lines */
+ (void) nocrmode ();
+ return (c);
}
/*
bool
getyn(char *message)
{
- char c;
+ char c;
- for (;;) {
- prompt (message,0,0,0,0,0,0,0,0);
- c = get_chx ();
+ for (;;) {
+ prompt (message,0,0,0,0,0,0,0,0);
+ c = get_chx ();
- if (c == 'Y') return (true);
- if (c == 'N') return (false);
+ if (c == 'Y') return (true);
+ if (c == 'N') return (false);
- error ("Please answer Y or N.",0,0,0,0,0,0,0,0);
- }
+ error ("Please answer Y or N.",0,0,0,0,0,0,0,0);
+ }
}
/*
int
get_range(char *message, int low, int high)
{
- int result;
+ int result;
- for (;;) {
- result = getint (message);
+ for (;;) {
+ result = getint (message);
- if (result >= low && result <= high) return (result);
+ if (result >= low && result <= high) return (result);
- error ("Please enter an integer in the range %d..%d.",low, high);
- }
+ error ("Please enter an integer in the range %d..%d.",low, high);
+ }
}
/*
void
help(char **text, int nlines)
{
- int i, r, c;
- int text_lines;
+ int i, r, c;
+ int text_lines;
- text_lines = (nlines + 1) / 2; /* lines of text */
+ text_lines = (nlines + 1) / 2; /* lines of text */
- clear_screen ();
+ clear_screen ();
- pos_str (NUMTOPS, 1, text[0]); /* mode */
- pos_str (NUMTOPS, 41, "See empire(6) for more information.");
+ pos_str (NUMTOPS, 1, text[0]); /* mode */
+ pos_str (NUMTOPS, 41, "See empire(6) for more information.");
- for (i = 1; i < nlines; i++) {
- if (i > text_lines)
- pos_str (i - text_lines + NUMTOPS + 1, 41, text[i]);
- else pos_str (i + NUMTOPS + 1, 1, text[i]);
- }
+ for (i = 1; i < nlines; i++) {
+ if (i > text_lines)
+ pos_str (i - text_lines + NUMTOPS + 1, 41, text[i]);
+ else pos_str (i + NUMTOPS + 1, 1, text[i]);
+ }
- pos_str (text_lines + NUMTOPS + 2, 1, "--Piece---Yours-Enemy-Moves-Hits-Cost");
- pos_str (text_lines + NUMTOPS + 2, 41, "--Piece---Yours-Enemy-Moves-Hits-Cost");
-
- for (i = 0; i < NUM_OBJECTS; i++) {
- if (i >= (NUM_OBJECTS+1)/2) {
- r = i - (NUM_OBJECTS+1)/2;
- c = 41;
- }
- else {
- r = i;
- c = 1;
- }
- pos_str1 (r + text_lines + NUMTOPS + 3, c,"%-12s%c %c%6d%5d%6d",
- piece_attr[i].nickname,
- piece_attr[i].sname,
- tolower (piece_attr[i].sname),
- piece_attr[i].speed,
- piece_attr[i].max_hits,
- piece_attr[i].build_time,0,0); //FLAG
+ pos_str (text_lines + NUMTOPS + 2, 1, "--Piece---Yours-Enemy-Moves-Hits-Cost");
+ pos_str (text_lines + NUMTOPS + 2, 41, "--Piece---Yours-Enemy-Moves-Hits-Cost");
+ for (i = 0; i < NUM_OBJECTS; i++) {
+ if (i >= (NUM_OBJECTS+1)/2) {
+ r = i - (NUM_OBJECTS+1)/2;
+ c = 41;
+ }
+ else {
+ r = i;
+ c = 1;
}
- (void) refresh ();
+ pos_str1 (r + text_lines + NUMTOPS + 3, c,"%-12s%c %c%6d%5d%6d",
+ piece_attr[i].nickname,
+ piece_attr[i].sname,
+ tolower (piece_attr[i].sname),
+ piece_attr[i].speed,
+ piece_attr[i].max_hits,
+ piece_attr[i].build_time,0,0); //FLAG
+
+ }
+ (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);
- return nrow + col;
+ 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);
+ return nrow + col;
}
+
+/* end */
extern int get_piece_name(void);
void
-user_move(void) {
- void piece_move();
+user_move(void)
+{
+ void piece_move();
- int i, j, sec, sec_start;
- piece_info_t *obj, *next_obj;
- int prod;
+ int i, j, sec, sec_start;
+ piece_info_t *obj, *next_obj;
+ int prod;
- /* First we loop through objects to update the user's view
- of the world and perform any other necessary processing.
- We would like to have the world view up to date before
- asking the user any questions. This means that we should
- also scan through all cities before possibly asking the
- user what to produce in each city. */
+ /* First we loop through objects to update the user's view
+ of the world and perform any other necessary processing.
+ We would like to have the world view up to date before
+ asking the user any questions. This means that we should
+ also scan through all cities before possibly asking the
+ user what to produce in each city. */
- for (i = 0; i < NUM_OBJECTS; i++)
+ for (i = 0; i < NUM_OBJECTS; i++)
for (obj = user_obj[i]; obj != NULL; obj = obj->piece_link.next) {
- obj->moved = 0; /* nothing moved yet */
- scan (user_map, obj->loc); /* refresh user's view of world */
+ obj->moved = 0; /* nothing moved yet */
+ scan (user_map, obj->loc); /* refresh user's view of world */
}
- /* produce new hardware */
- for (i = 0; i < NUM_CITY; i++)
- if (city[i].owner == USER) {
- scan (user_map, city[i].loc);
- prod = city[i].prod;
-
- if (prod == NOPIECE) { /* need production? */
- set_prod (&(city[i])); /* ask user what to produce */
- }
- else if (city[i].work++ >= (long)piece_attr[prod].build_time) {
- /* kermyt begin */
- ksend("%s has been completed at city %d.\n", piece_attr[prod].article,loc_disp(city[i].loc));
- /* kermyt end */
- comment ("%s has been completed at city %d.\n", piece_attr[prod].article,loc_disp(city[i].loc));
-
- produce (&city[i]);
- /* produce should set object.moved to 0 */
- }
+ /* produce new hardware */
+ for (i = 0; i < NUM_CITY; i++)
+ if (city[i].owner == USER) {
+ scan (user_map, city[i].loc);
+ prod = city[i].prod;
+
+ if (prod == NOPIECE) { /* need production? */
+ set_prod (&(city[i])); /* ask user what to produce */
+ }
+ else if (city[i].work++ >= (long)piece_attr[prod].build_time) {
+ /* kermyt begin */
+ ksend("%s has been completed at city %d.\n", piece_attr[prod].article,loc_disp(city[i].loc));
+ /* kermyt end */
+ comment ("%s has been completed at city %d.\n", piece_attr[prod].article,loc_disp(city[i].loc));
+
+ produce (&city[i]);
+ /* produce should set object.moved to 0 */
+ }
}
- /* move all satellites */
- for (obj = user_obj[SATELLITE]; obj != NULL; obj = next_obj) {
- next_obj = obj->piece_link.next;
- move_sat (obj);
- }
+ /* move all satellites */
+ for (obj = user_obj[SATELLITE]; obj != NULL; obj = next_obj) {
+ next_obj = obj->piece_link.next;
+ move_sat (obj);
+ }
- sec_start = cur_sector (); /* get currently displayed sector */
- if (sec_start == -1) sec_start = 0;
-
- /* loop through sectors, moving every piece in the sector */
- for (i = sec_start; i < sec_start + NUM_SECTORS; i++) {
- sec = i % NUM_SECTORS;
- sector_change (); /* allow screen to be redrawn */
-
- for (j = 0; j < NUM_OBJECTS; j++) /* loop through obj lists */
- for (obj = user_obj[move_order[j]]; obj != NULL;
- obj = next_obj) { /* loop through objs in list */
- next_obj = obj->piece_link.next;
-
- if (!obj->moved) /* object not moved yet? */
- if (loc_sector (obj->loc) == sec) /* object in sector? */
- piece_move (obj); /* yup; move the object */
- }
- if (cur_sector () == sec) { /* is sector displayed? */
- print_sector_u (sec); /* make screen up-to-date */
- redisplay (); /* show it to the user */
- }
+ sec_start = cur_sector (); /* get currently displayed sector */
+ if (sec_start == -1) sec_start = 0;
+
+ /* loop through sectors, moving every piece in the sector */
+ for (i = sec_start; i < sec_start + NUM_SECTORS; i++) {
+ sec = i % NUM_SECTORS;
+ sector_change (); /* allow screen to be redrawn */
+
+ for (j = 0; j < NUM_OBJECTS; j++) /* loop through obj lists */
+ for (obj = user_obj[move_order[j]]; obj != NULL;
+ obj = next_obj) { /* loop through objs in list */
+ next_obj = obj->piece_link.next;
+
+ if (!obj->moved) /* object not moved yet? */
+ if (loc_sector (obj->loc) == sec) /* object in sector? */
+ piece_move (obj); /* yup; move the object */
+ }
+ if (cur_sector () == sec) { /* is sector displayed? */
+ print_sector_u (sec); /* make screen up-to-date */
+ redisplay (); /* show it to the user */
}
- if (save_movie) save_movie_screen ();
+ }
+ if (save_movie) save_movie_screen ();
}
/*
void
piece_move(piece_info_t *obj)
{
- void move_random(), move_fill(), move_land(), move_explore();
- void move_path(), move_dir(), move_armyload(), ask_user();
- void move_armyattack(), move_ttload(), move_repair();
- void move_transport();
-
- bool changed_loc;
- int speed, max_hits;
- int saved_moves;
- bool need_input;
- loc_t saved_loc;
- city_info_t *cityp;
-
- /* set func for piece if on city */
- cityp = find_city (obj->loc);
- if (cityp != NULL)
- if (cityp->func[obj->type] != NOFUNC)
- obj->func = cityp->func[obj->type];
-
- changed_loc = false; /* not changed yet */
- speed = piece_attr[obj->type].speed;
- max_hits = piece_attr[obj->type].max_hits;
- need_input = false; /* don't require user input yet */
-
- while (obj->moved < obj_moves (obj)) {
- saved_moves = obj->moved; /* save moves made */
- saved_loc = obj->loc; /* remember starting location */
-
- if (awake (obj) || need_input){ /* need user input? */
- ask_user (obj);
- topini (); /* clear info lines */
- display_loc_u (obj->loc); /* let user see result */
- (void) redisplay ();
- need_input = false; /* we got it */
- }
+ void move_random(), move_fill(), move_land(), move_explore();
+ void move_path(), move_dir(), move_armyload(), ask_user();
+ void move_armyattack(), move_ttload(), move_repair();
+ void move_transport();
+
+ bool changed_loc;
+ int speed, max_hits;
+ int saved_moves;
+ bool need_input;
+ loc_t saved_loc;
+ city_info_t *cityp;
+
+ /* set func for piece if on city */
+ cityp = find_city (obj->loc);
+ if (cityp != NULL)
+ if (cityp->func[obj->type] != NOFUNC)
+ obj->func = cityp->func[obj->type];
+
+ changed_loc = false; /* not changed yet */
+ speed = piece_attr[obj->type].speed;
+ max_hits = piece_attr[obj->type].max_hits;
+ need_input = false; /* don't require user input yet */
+
+ while (obj->moved < obj_moves (obj)) {
+ saved_moves = obj->moved; /* save moves made */
+ saved_loc = obj->loc; /* remember starting location */
+
+ if (awake (obj) || need_input){ /* need user input? */
+ ask_user (obj);
+ topini (); /* clear info lines */
+ display_loc_u (obj->loc); /* let user see result */
+ (void) redisplay ();
+ need_input = false; /* we got it */
+ }
- if (obj->moved == saved_moves) /* user set function? */
- switch (obj->func) { /* handle preprogrammed function */
- case NOFUNC: break;
- case RANDOM: move_random (obj); break;
- case SENTRY: obj->moved = speed; break;
- case FILL: move_fill (obj); break;
- case LAND: move_land (obj); break;
- case EXPLORE: move_explore (obj); break;
- case ARMYLOAD: move_armyload (obj); break;
- case ARMYATTACK:move_armyattack (obj); break;
- case TTLOAD: move_ttload (obj); break;
- case REPAIR: move_repair (obj); break;
- case WFTRANSPORT: move_transport (obj); break;
-
- case MOVE_N:
- case MOVE_NE:
- case MOVE_E:
- case MOVE_SE:
- case MOVE_S:
- case MOVE_SW:
- case MOVE_W:
- case MOVE_NW:
- move_dir (obj); break;
-
- default: move_path (obj); break;
- }
-
- if (obj->moved == saved_moves) need_input = true;
+ if (obj->moved == saved_moves) /* user set function? */
+ switch (obj->func) { /* handle preprogrammed function */
+ case NOFUNC: break;
+ case RANDOM: move_random (obj); break;
+ case SENTRY: obj->moved = speed; break;
+ case FILL: move_fill (obj); break;
+ case LAND: move_land (obj); break;
+ case EXPLORE: move_explore (obj); break;
+ case ARMYLOAD: move_armyload (obj); break;
+ case ARMYATTACK:move_armyattack (obj); break;
+ case TTLOAD: move_ttload (obj); break;
+ case REPAIR: move_repair (obj); break;
+ case WFTRANSPORT: move_transport (obj); break;
+
+ case MOVE_N:
+ case MOVE_NE:
+ case MOVE_E:
+ case MOVE_SE:
+ case MOVE_S:
+ case MOVE_SW:
+ case MOVE_W:
+ case MOVE_NW:
+ move_dir (obj); break;
+
+ default: move_path (obj); break;
+ }
+
+ if (obj->moved == saved_moves) need_input = true;
- /* handle fighters specially. If in a city or carrier, turn
- is over and reset range to max. Otherwise, if
- range = 0, fighter crashes and burns and turn is over. */
-
- if (obj->type == FIGHTER && obj->hits > 0) {
- if ((user_map[obj->loc].contents == 'O'
- || user_map[obj->loc].contents == 'C')
- && obj->moved > 0) {
- obj->range = piece_attr[FIGHTER].range;
- obj->moved = speed;
- obj->func = NOFUNC;
- comment ("Landing confirmed.");
- }
- else if (obj->range == 0) {
- comment ("Fighter at %d crashed and burned.",loc_disp(obj->loc));
- kill_obj (obj, obj->loc);
- }
- }
-
- if (saved_loc != obj->loc) changed_loc = true;
+ /* handle fighters specially. If in a city or carrier, turn
+ is over and reset range to max. Otherwise, if
+ range = 0, fighter crashes and burns and turn is over. */
+
+ if (obj->type == FIGHTER && obj->hits > 0) {
+ if ((user_map[obj->loc].contents == 'O'
+ || user_map[obj->loc].contents == 'C')
+ && obj->moved > 0) {
+ obj->range = piece_attr[FIGHTER].range;
+ obj->moved = speed;
+ obj->func = NOFUNC;
+ comment ("Landing confirmed.");
+ }
+ else if (obj->range == 0) {
+ comment ("Fighter at %d crashed and burned.",loc_disp(obj->loc));
+ kill_obj (obj, obj->loc);
+ }
}
- /* if a boat is in port, damaged, and never moved, fix some damage */
- if (obj->hits > 0 /* still alive? */
- && !changed_loc /* object never changed location? */
- && obj->type != ARMY && obj->type != FIGHTER /* it is a boat? */
- && obj->hits < max_hits /* it is damaged? */
- && user_map[obj->loc].contents == 'O') /* it is in port? */
+
+ if (saved_loc != obj->loc) changed_loc = true;
+ }
+ /* if a boat is in port, damaged, and never moved, fix some damage */
+ if (obj->hits > 0 /* still alive? */
+ && !changed_loc /* object never changed location? */
+ && obj->type != ARMY && obj->type != FIGHTER /* it is a boat? */
+ && obj->hits < max_hits /* it is damaged? */
+ && user_map[obj->loc].contents == 'O') /* it is in port? */
obj->hits++; /* fix some damage */
}
void move_random(piece_info_t *obj)
{
- loc_t loc_list[8];
- int i, nloc;
- loc_t loc;
-
- nloc = 0;
-
- for (i = 0; i < 8; i++) {
- loc = obj->loc + dir_offset[i];
- if (good_loc (obj, loc)) {
- loc_list[nloc] = loc; /* remember this location */
- nloc++; /* count locations we can move to */
- }
+ loc_t loc_list[8];
+ int i, nloc;
+ loc_t loc;
+
+ nloc = 0;
+
+ for (i = 0; i < 8; i++) {
+ loc = obj->loc + dir_offset[i];
+ if (good_loc (obj, loc)) {
+ loc_list[nloc] = loc; /* remember this location */
+ nloc++; /* count locations we can move to */
}
- if (nloc == 0) return; /* no legal move */
- i = irand ((long)nloc-1); /* choose random direction */
- move_obj (obj, loc_list[i]); /* move the piece */
+ }
+ if (nloc == 0) return; /* no legal move */
+ i = irand ((long)nloc-1); /* choose random direction */
+ move_obj (obj, loc_list[i]); /* move the piece */
}
/*
void move_explore(piece_info_t *obj)
{
- path_map_t path_map[MAP_SIZE];
- loc_t loc;
- char *terrain;
-
- switch (obj->type) {
- case ARMY:
- loc = vmap_find_lobj (path_map, user_map, obj->loc, &user_army);
- terrain = "+";
- break;
- case FIGHTER:
- loc = vmap_find_aobj (path_map, user_map, obj->loc, &user_fighter);
- terrain = "+.O";
- break;
- default:
- loc = vmap_find_wobj (path_map, user_map, obj->loc, &user_ship);
- terrain = ".O";
- break;
- }
+ path_map_t path_map[MAP_SIZE];
+ loc_t loc;
+ char *terrain;
+
+ switch (obj->type) {
+ case ARMY:
+ loc = vmap_find_lobj (path_map, user_map, obj->loc, &user_army);
+ terrain = "+";
+ break;
+ case FIGHTER:
+ loc = vmap_find_aobj (path_map, user_map, obj->loc, &user_fighter);
+ terrain = "+.O";
+ break;
+ default:
+ loc = vmap_find_wobj (path_map, user_map, obj->loc, &user_ship);
+ terrain = ".O";
+ break;
+ }
- if (loc == obj->loc) return; /* nothing to explore */
+ if (loc == obj->loc) return; /* nothing to explore */
- if (user_map[loc].contents == ' ' && path_map[loc].cost == 2)
- vmap_mark_adjacent (path_map, obj->loc);
- else vmap_mark_path (path_map, user_map, loc);
+ if (user_map[loc].contents == ' ' && path_map[loc].cost == 2)
+ vmap_mark_adjacent (path_map, obj->loc);
+ else vmap_mark_path (path_map, user_map, loc);
- loc = vmap_find_dir (path_map, user_map, obj->loc, terrain, " ");
- if (loc != obj->loc) move_obj (obj, loc);
+ loc = vmap_find_dir (path_map, user_map, obj->loc, terrain, " ");
+ if (loc != obj->loc) move_obj (obj, loc);
}
/*
void
move_transport(piece_info_t *obj)
{
- loc_t loc;
+ loc_t loc;
- /* look for an adjacent transport */
- loc = find_transport (USER, obj->loc);
+ /* look for an adjacent transport */
+ loc = find_transport (USER, obj->loc);
- if (loc != obj->loc) {
- move_obj (obj, loc);
- obj->func = NOFUNC;
- }
- else obj->moved = piece_attr[obj->type].speed;
+ if (loc != obj->loc) {
+ move_obj (obj, loc);
+ obj->func = NOFUNC;
+ }
+ else obj->moved = piece_attr[obj->type].speed;
}
/*
void
move_armyload(piece_info_t *obj)
{
- loc_t loc;
- piece_info_t *p;
- int i;
+ loc_t loc;
+ piece_info_t *p;
+ int i;
- ABORT;
+ ABORT;
- /* look for an adjacent transport */
- loc = find_transport (USER, obj->loc);
+ /* look for an adjacent transport */
+ loc = find_transport (USER, obj->loc);
- if (loc != obj->loc) {
- move_obj (obj, loc);
- obj->func = NOFUNC;
- }
- else { /* look for nearest non-full transport */
- (void) memcpy (amap, user_map, sizeof (view_map_t) * MAP_SIZE);
+ if (loc != obj->loc) {
+ move_obj (obj, loc);
+ obj->func = NOFUNC;
+ }
+ else { /* look for nearest non-full transport */
+ (void) memcpy (amap, user_map, sizeof (view_map_t) * MAP_SIZE);
- /* mark loading transports or cities building transports */
- for (p = user_obj[TRANSPORT]; p; p = p->piece_link.next)
- if (p->count < obj_capacity (p)) /* not full? */
+ /* mark loading transports or cities building transports */
+ for (p = user_obj[TRANSPORT]; p; p = p->piece_link.next)
+ if (p->count < obj_capacity (p)) /* not full? */
amap[p->loc].contents = '$';
- for (i = 0; i < NUM_CITY; i++)
- if (city[i].owner == USER && city[i].prod == TRANSPORT)
+ for (i = 0; i < NUM_CITY; i++)
+ if (city[i].owner == USER && city[i].prod == TRANSPORT)
amap[city[i].loc].contents = '$';
- }
+ }
}
/*
void
move_armyattack(piece_info_t *obj)
{
- path_map_t path_map[MAP_SIZE];
- loc_t loc;
+ path_map_t path_map[MAP_SIZE];
+ loc_t loc;
- ASSERT (obj->type == ARMY);
+ ASSERT (obj->type == ARMY);
- loc = vmap_find_lobj (path_map, user_map, obj->loc, &user_army_attack);
+ loc = vmap_find_lobj (path_map, user_map, obj->loc, &user_army_attack);
- if (loc == obj->loc) return; /* nothing to attack */
+ if (loc == obj->loc) return; /* nothing to attack */
- vmap_mark_path (path_map, user_map, loc);
+ vmap_mark_path (path_map, user_map, loc);
- loc = vmap_find_dir (path_map, user_map, obj->loc, "+", "X*a");
- if (loc != obj->loc) move_obj (obj, loc);
+ loc = vmap_find_dir (path_map, user_map, obj->loc, "+", "X*a");
+ if (loc != obj->loc) move_obj (obj, loc);
}
void
move_ttload(piece_info_t *obj)
{
- ABORT;
- obj = obj;
+ ABORT;
+ obj = obj;
}
/*
void
move_repair(piece_info_t *obj)
{
- path_map_t path_map[MAP_SIZE];
- loc_t loc;
+ path_map_t path_map[MAP_SIZE];
+ loc_t loc;
- ASSERT (obj->type > FIGHTER);
+ ASSERT (obj->type > FIGHTER);
- if (obj->hits == piece_attr[obj->type].max_hits) {
- obj->func = NOFUNC;
- return;
- }
+ if (obj->hits == piece_attr[obj->type].max_hits) {
+ obj->func = NOFUNC;
+ return;
+ }
- if (user_map[obj->loc].contents == 'O') { /* it is in port? */
- obj->moved += 1;
- return;
- }
+ if (user_map[obj->loc].contents == 'O') { /* it is in port? */
+ obj->moved += 1;
+ return;
+ }
- loc = vmap_find_wobj (path_map, user_map, obj->loc, &user_ship_repair);
+ loc = vmap_find_wobj (path_map, user_map, obj->loc, &user_ship_repair);
- if (loc == obj->loc) return; /* no reachable city */
+ if (loc == obj->loc) return; /* no reachable city */
- vmap_mark_path (path_map, user_map, loc);
+ vmap_mark_path (path_map, user_map, loc);
- /* try to be next to ocean to avoid enemy pieces */
- loc = vmap_find_dir (path_map, user_map, obj->loc, ".O", ".");
- if (loc != obj->loc) move_obj (obj, loc);
+ /* try to be next to ocean to avoid enemy pieces */
+ loc = vmap_find_dir (path_map, user_map, obj->loc, ".O", ".");
+ if (loc != obj->loc) move_obj (obj, loc);
}
/*
void move_fill(piece_info_t *obj)
{
- if (obj->count == obj_capacity (obj)) /* full? */
- obj->func = NOFUNC; /* awaken full boat */
- else obj->moved = piece_attr[obj->type].speed;
+ if (obj->count == obj_capacity (obj)) /* full? */
+ obj->func = NOFUNC; /* awaken full boat */
+ else obj->moved = piece_attr[obj->type].speed;
}
/*
void
move_land(piece_info_t *obj)
{
- long best_dist;
- loc_t best_loc;
- long new_dist;
- piece_info_t *p;
-
- best_dist = find_nearest_city (obj->loc, USER, &best_loc);
-
- for (p = user_obj[CARRIER]; p != NULL; p = p->piece_link.next) {
- new_dist = dist (obj->loc, p->loc);
- if (new_dist < best_dist) {
- best_dist = new_dist;
- best_loc = p->loc;
- }
+ long best_dist;
+ loc_t best_loc;
+ long new_dist;
+ piece_info_t *p;
+
+ best_dist = find_nearest_city (obj->loc, USER, &best_loc);
+
+ for (p = user_obj[CARRIER]; p != NULL; p = p->piece_link.next) {
+ new_dist = dist (obj->loc, p->loc);
+ if (new_dist < best_dist) {
+ best_dist = new_dist;
+ best_loc = p->loc;
}
- if (best_dist == 0) obj->moved += 1; /* fighter is on a city */
+ }
+ if (best_dist == 0) obj->moved += 1; /* fighter is on a city */
- else if (best_dist <= obj->range)
- move_to_dest (obj, best_loc);
+ else if (best_dist <= obj->range)
+ move_to_dest (obj, best_loc);
- else obj->func = NOFUNC; /* can't reach city or carrier */
+ else obj->func = NOFUNC; /* can't reach city or carrier */
}
/*
void move_dir(piece_info_t *obj)
{
- loc_t loc;
- int dir;
+ loc_t loc;
+ int dir;
- dir = MOVE_DIR (obj->func);
- loc = obj->loc + dir_offset[dir];
+ dir = MOVE_DIR (obj->func);
+ loc = obj->loc + dir_offset[dir];
- if (good_loc (obj, loc))
- move_obj (obj, loc);
+ if (good_loc (obj, loc))
+ move_obj (obj, loc);
}
/*
void move_path(piece_info_t *obj)
{
- if (obj->loc == obj->func)
- obj->func = NOFUNC;
- else move_to_dest (obj, obj->func);
+ if (obj->loc == obj->func)
+ obj->func = NOFUNC;
+ else move_to_dest (obj, obj->func);
}
/*
void move_to_dest(piece_info_t *obj, loc_t dest)
{
- path_map_t path_map[MAP_SIZE];
- int fterrain;
- char *mterrain;
- loc_t new_loc;
+ path_map_t path_map[MAP_SIZE];
+ int fterrain;
+ char *mterrain;
+ loc_t new_loc;
- switch (obj->type) {
- case ARMY:
- fterrain = T_LAND;
- mterrain = "+";
- break;
- case FIGHTER:
- fterrain = T_AIR;
- mterrain = "+.O";
- break;
- default:
- fterrain = T_WATER;
- mterrain = ".O";
- break;
- }
+ switch (obj->type) {
+ case ARMY:
+ fterrain = T_LAND;
+ mterrain = "+";
+ break;
+ case FIGHTER:
+ fterrain = T_AIR;
+ mterrain = "+.O";
+ break;
+ default:
+ fterrain = T_WATER;
+ mterrain = ".O";
+ break;
+ }
- new_loc = vmap_find_dest (path_map, user_map, obj->loc, dest,
- USER, fterrain);
- if (new_loc == obj->loc) return; /* can't get there */
+ new_loc = vmap_find_dest (path_map, user_map, obj->loc, dest,
+ USER, fterrain);
+ if (new_loc == obj->loc) return; /* can't get there */
- vmap_mark_path (path_map, user_map, dest);
- new_loc = vmap_find_dir (path_map, user_map, obj->loc, mterrain, " .");
- if (new_loc == obj->loc) return; /* can't move ahead */
- ASSERT (good_loc (obj, new_loc));
- move_obj (obj, new_loc); /* everything looks good */
+ vmap_mark_path (path_map, user_map, dest);
+ new_loc = vmap_find_dir (path_map, user_map, obj->loc, mterrain, " .");
+ if (new_loc == obj->loc) return; /* can't move ahead */
+ ASSERT (good_loc (obj, new_loc));
+ move_obj (obj, new_loc); /* everything looks good */
}
/*
void ask_user(piece_info_t *obj)
{
- void user_skip(), user_fill(), user_dir(), user_set_dir();
- void user_wake(), user_set_city_func(), user_cancel_auto();
- void user_redraw(), user_random(), user_land(), user_sentry();
- void user_help(), reset_func(), user_explore();
- void user_build(), user_transport();
- void user_armyattack(), user_repair();
+ void user_skip(), user_fill(), user_dir(), user_set_dir();
+ void user_wake(), user_set_city_func(), user_cancel_auto();
+ void user_redraw(), user_random(), user_land(), user_sentry();
+ void user_help(), reset_func(), user_explore();
+ void user_build(), user_transport();
+ void user_armyattack(), user_repair();
- char c;
+ char c;
for (;;) {
display_loc_u (obj->loc); /* display piece to move */
void
reset_func(piece_info_t *obj)
{
- city_info_t *cityp;
+ city_info_t *cityp;
- cityp = find_city (obj->loc);
+ cityp = find_city (obj->loc);
- if (cityp != NULL)
+ if (cityp != NULL)
if (cityp->func[obj->type] != NOFUNC) {
- obj->func = cityp->func[obj->type];
- (void) awake (obj);
+ obj->func = cityp->func[obj->type];
+ (void) awake (obj);
}
}
void
user_skip(piece_info_t *obj)
{
- if (obj->type == ARMY && user_map[obj->loc].contents == 'O')
- move_army_to_city (obj, obj->loc);
- else obj->moved++;
+ if (obj->type == ARMY && user_map[obj->loc].contents == 'O')
+ move_army_to_city (obj, obj->loc);
+ else obj->moved++;
}
/*
void
user_fill(piece_info_t *obj)
{
- if (obj->type != TRANSPORT && obj->type != CARRIER) complain ();
- else obj->func = FILL;
+ if (obj->type != TRANSPORT && obj->type != CARRIER) complain ();
+ else obj->func = FILL;
}
/*
*/
void
-user_help(void) {
- char c;
+user_help(void)
+{
+ char c;
- help (help_user, user_lines);
- prompt ("Press any key to continue: ");
- c = get_chx ();
- c = c; /* keep lint happy */
+ help (help_user, user_lines);
+ prompt ("Press any key to continue: ");
+ c = get_chx ();
+ c = c; /* keep lint happy */
}
/*
void
user_set_dir(piece_info_t *obj)
{
- char c;
-
- c = get_chx ();
- switch (c) {
- case 'Q': obj->func = MOVE_NW; break;
- case 'W': obj->func = MOVE_N ; break;
- case 'E': obj->func = MOVE_NE; break;
- case 'D': obj->func = MOVE_E ; break;
- case 'C': obj->func = MOVE_SE; break;
- case 'X': obj->func = MOVE_S ; break;
- case 'Z': obj->func = MOVE_SW; break;
- case 'A': obj->func = MOVE_W ; break;
- default: complain (); break;
- }
+ char c;
+
+ c = get_chx ();
+ switch (c) {
+ case 'Q': obj->func = MOVE_NW; break;
+ case 'W': obj->func = MOVE_N ; break;
+ case 'E': obj->func = MOVE_NE; break;
+ case 'D': obj->func = MOVE_E ; break;
+ case 'C': obj->func = MOVE_SE; break;
+ case 'X': obj->func = MOVE_S ; break;
+ case 'Z': obj->func = MOVE_SW; break;
+ case 'A': obj->func = MOVE_W ; break;
+ default: complain (); break;
+ }
}
/*
void
user_wake(piece_info_t *obj)
{
- obj->func = NOFUNC;
+ obj->func = NOFUNC;
}
/*
void
user_random(piece_info_t *obj)
{
- obj->func = RANDOM;
+ obj->func = RANDOM;
}
/*
void
user_sentry(piece_info_t *obj)
{
- obj->func = SENTRY;
+ obj->func = SENTRY;
}
/*
void
user_land(piece_info_t *obj)
{
- if (obj->type != FIGHTER) complain ();
- else obj->func = LAND;
+ if (obj->type != FIGHTER)
+ complain ();
+ else
+ obj->func = LAND;
}
/*
void
user_explore(piece_info_t *obj)
{
- obj->func = EXPLORE;
+ obj->func = EXPLORE;
}
/*
void
user_transport(piece_info_t *obj)
{
- if (obj->type != ARMY) complain ();
- else obj->func = WFTRANSPORT;
+ if (obj->type != ARMY)
+ complain ();
+ else
+ obj->func = WFTRANSPORT;
}
/*
void
user_armyattack(piece_info_t *obj)
{
- if (obj->type != ARMY) complain ();
- else obj->func = ARMYATTACK;
+ if (obj->type != ARMY)
+ complain ();
+ else
+ obj->func = ARMYATTACK;
}
/*
void
user_repair(piece_info_t *obj)
{
- if (obj->type == ARMY || obj->type == FIGHTER) complain ();
- else obj->func = REPAIR;
+ if (obj->type == ARMY || obj->type == FIGHTER)
+ complain ();
+ else
+ obj->func = REPAIR;
}
/*
void
user_set_city_func(piece_info_t *obj)
{
- void e_city_fill(), e_city_explore(), e_city_stasis();
- void e_city_wake(), e_city_random(), e_city_repair();
- void e_city_attack();
+ void e_city_fill(), e_city_explore(), e_city_stasis();
+ void e_city_wake(), e_city_random(), e_city_repair();
+ void e_city_attack();
- int type;
- char e;
- city_info_t *cityp;
-
- cityp = find_city (obj->loc);
- if (!cityp || cityp->owner != USER) {
- complain ();
- return;
- }
+ int type;
+ char e;
+ city_info_t *cityp;
+
+ cityp = find_city (obj->loc);
+ if (!cityp || cityp->owner != USER) {
+ complain ();
+ return;
+ }
- type = get_piece_name();
- if (type == NOPIECE) {
- complain ();
- return;
- }
+ type = get_piece_name();
+ if (type == NOPIECE) {
+ complain ();
+ return;
+ }
- e = get_chx ();
+ e = get_chx ();
- switch (e) {
- case 'F': /* fill */
- e_city_fill (cityp, type);
- break;
- case 'G': /* explore */
- e_city_explore (cityp, type);
- break;
- case 'I': /* directional stasis */
- e_city_stasis (cityp, type);
- break;
- case 'K': /* turn off function */
- e_city_wake (cityp, type);
- break;
- case 'R': /* make piece move randomly */
- e_city_random (cityp, type);
- break;
- case 'U': /* repair ship */
- e_city_repair (cityp, type);
- break;
- case 'Y': /* set army func to attack */
- e_city_attack (cityp, type);
- break;
- default: /* bad command? */
- complain ();
- break;
- }
+ switch (e) {
+ case 'F': /* fill */
+ e_city_fill (cityp, type);
+ break;
+ case 'G': /* explore */
+ e_city_explore (cityp, type);
+ break;
+ case 'I': /* directional stasis */
+ e_city_stasis (cityp, type);
+ break;
+ case 'K': /* turn off function */
+ e_city_wake (cityp, type);
+ break;
+ case 'R': /* make piece move randomly */
+ e_city_random (cityp, type);
+ break;
+ case 'U': /* repair ship */
+ e_city_repair (cityp, type);
+ break;
+ case 'Y': /* set army func to attack */
+ e_city_attack (cityp, type);
+ break;
+ default: /* bad command? */
+ complain ();
+ break;
+ }
}
/*
void
user_build(piece_info_t *obj)
{
- city_info_t *cityp;
+ city_info_t *cityp;
- if (user_map[obj->loc].contents != 'O') { /* no user city here? */
- complain ();
- return;
- }
- cityp = find_city (obj->loc);
- ASSERT (cityp != NULL);
- set_prod (cityp);
+ if (user_map[obj->loc].contents != 'O') { /* no user city here? */
+ complain ();
+ return;
+ }
+ cityp = find_city (obj->loc);
+ ASSERT (cityp != NULL);
+ set_prod (cityp);
}
/*
void
user_dir(piece_info_t *obj, int dir)
{
- void user_dir_army(), user_dir_fighter(), user_dir_ship();
+ void user_dir_army(), user_dir_fighter(), user_dir_ship();
- loc_t loc;
+ loc_t loc;
- loc = obj->loc + dir_offset[dir];
+ loc = obj->loc + dir_offset[dir];
- if (good_loc (obj, loc)) {
- move_obj (obj, loc);
- return;
- }
- if (!map[loc].on_board) {
- error ("You cannot move to the edge of the world.");
- delay ();
- return;
- }
- switch (obj->type) {
- case ARMY: user_dir_army (obj, loc); break;
- case FIGHTER: user_dir_fighter (obj, loc); break;
- default: user_dir_ship (obj, loc); break;
- }
+ if (good_loc (obj, loc)) {
+ move_obj (obj, loc);
+ return;
+ }
+ if (!map[loc].on_board) {
+ error ("You cannot move to the edge of the world.");
+ delay ();
+ return;
+ }
+ switch (obj->type) {
+ case ARMY: user_dir_army (obj, loc); break;
+ case FIGHTER: user_dir_fighter (obj, loc); break;
+ default: user_dir_ship (obj, loc); break;
+ }
}
/*
void
user_dir_army(piece_info_t *obj, loc_t loc)
{
- bool enemy_killed;
+ bool enemy_killed;
- enemy_killed = false;
-
- if (user_map[loc].contents == 'O') /* attacking own city */
- move_army_to_city (obj, loc);
-
- else if (user_map[loc].contents == 'T') /* transport full? */
- fatal (obj, 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? */
- if (!getyn ( /* thanks to Craig Hansen for this next message */
- "Troops can't walk on water, sir. Do you really want to go to sea? "))
- return;
-
- if (user_map[obj->loc].contents == 'T')
- {
- 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 == '.')
- {
- comment ("Your army marched dutifully into the sea and drowned.");
- ksend ("Your army marched dutifully into the sea and drowned.\n");
- }
- else { /* attack something at sea */
- enemy_killed = islower (user_map[loc].contents);
- attack (obj, loc);
+ enemy_killed = false;
+
+ if (user_map[loc].contents == 'O') /* attacking own city */
+ move_army_to_city (obj, loc);
+
+ else if (user_map[loc].contents == 'T') /* transport full? */
+ fatal (obj, 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? */
+ if (!getyn ( /* thanks to Craig Hansen for this next message */
+ "Troops can't walk on water, sir. Do you really want to go to sea? "))
+ return;
+
+ if (user_map[obj->loc].contents == 'T')
+ {
+ 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 == '.')
+ {
+ comment ("Your army marched dutifully into the sea and drowned.");
+ ksend ("Your army marched dutifully into the sea and drowned.\n");
+ }
+ else { /* attack something at sea */
+ enemy_killed = islower (user_map[loc].contents);
+ attack (obj, loc);
- if (obj->hits > 0) /* ship won? */
- {
- comment ("Your army regretfully drowns after its successful assault.");
- ksend ("Your army regretfully drowns after it's successful assault.");
- }
- }
- if (obj->hits > 0) {
- kill_obj (obj, loc);
- if (enemy_killed) scan (comp_map, loc);
- }
+ if (obj->hits > 0) /* ship won? */
+ {
+ comment ("Your army regretfully drowns after its successful assault.");
+ ksend ("Your army regretfully drowns after it's successful assault.");
+ }
}
+ if (obj->hits > 0) {
+ kill_obj (obj, loc);
+ if (enemy_killed) scan (comp_map, loc);
+ }
+ }
- else if (isupper (user_map[loc].contents)
- && user_map[loc].contents != 'X') { /* attacking self */
- if (!getyn (
- "Sir, those are our men! Do you really want to attack them? "))
- return;
+ else if (isupper (user_map[loc].contents)
+ && user_map[loc].contents != 'X') { /* attacking self */
+ if (!getyn (
+ "Sir, those are our men! Do you really want to attack them? "))
+ return;
- attack (obj, loc);
- }
+ attack (obj, loc);
+ }
- else attack (obj, loc);
+ else attack (obj, loc);
}
/*
void
user_dir_fighter(piece_info_t *obj, loc_t loc)
{
- if (map[loc].contents == '*')
- fatal (obj, loc,
- "That's never worked before, sir. Do you really want to try? ",
- "Your fighter was shot down.");
+ if (map[loc].contents == '*')
+ fatal (obj, loc,
+ "That's never worked before, sir. Do you really want to try? ",
+ "Your fighter was shot down.");
- else if (isupper (user_map[loc].contents)) {
- if (!getyn (
- "Sir, those are our men! Do you really want to attack them? "))
- return;
+ else if (isupper (user_map[loc].contents)) {
+ if (!getyn ("Sir, those are our men! "
+ "Do you really want to attack them? "))
+ return;
- attack (obj, loc);
- }
+ attack (obj, loc);
+ }
- else attack (obj, loc);
+ else attack (obj, loc);
}
/*
void
user_dir_ship(piece_info_t *obj, loc_t loc)
{
- bool enemy_killed;
+ bool enemy_killed;
- enemy_killed = false;
+ enemy_killed = false;
- if (map[loc].contents == '*') {
- (void) sprintf (jnkbuf, "Your %s broke up on shore.",
- piece_attr[obj->type].name);
+ if (map[loc].contents == '*') {
+ (void) sprintf (jnkbuf, "Your %s broke up on shore.",
+ piece_attr[obj->type].name);
- fatal (obj, loc,
- "That's never worked before, sir. Do you really want to try? ",
- jnkbuf);
- }
+ fatal (obj, loc,
+ "That's never worked before, sir. Do you really want to try? ",
+ jnkbuf);
+ }
+
+ else if (map[loc].contents == '+') { /* moving ashore? */
+ if (!getyn ("Ships need sea to float, sir. Do you really want to go ashore? ")) return;
- else if (map[loc].contents == '+') { /* moving ashore? */
- if (!getyn ("Ships need sea to float, sir. Do you really want to go ashore? ")) return;
-
- if (user_map[loc].contents == '+')
- {
- comment ("Your %s broke up on shore.", piece_attr[obj->type].name);
- ksend ("Your %s broke up on shore.", piece_attr[obj->type].name);
- }
- else { /* attack something on shore */
- enemy_killed = islower (user_map[loc].contents);
- attack (obj, loc);
-
- if (obj->hits > 0) /* ship won? */
- {
- comment ("Your %s breaks up after its successful assault.", piece_attr[obj->type].name);
- ksend ("Your %s breaks up after its successful assault.", piece_attr[obj->type].name);
- }
- }
- if (obj->hits > 0) {
- kill_obj (obj, loc);
- if (enemy_killed) scan (comp_map, loc);
- }
+ if (user_map[loc].contents == '+')
+ {
+ comment ("Your %s broke up on shore.", piece_attr[obj->type].name);
+ ksend ("Your %s broke up on shore.", piece_attr[obj->type].name);
}
+ else { /* attack something on shore */
+ enemy_killed = islower (user_map[loc].contents);
+ attack (obj, loc);
+
+ if (obj->hits > 0) /* ship won? */
+ {
+ comment ("Your %s breaks up after its successful assault.", piece_attr[obj->type].name);
+ ksend ("Your %s breaks up after its successful assault.", piece_attr[obj->type].name);
+ }
+ }
+ if (obj->hits > 0) {
+ kill_obj (obj, loc);
+ if (enemy_killed) scan (comp_map, loc);
+ }
+ }
- else if (isupper (user_map[loc].contents)) { /* attacking self */
- if (!getyn (
- "Sir, those are our men! Do you really want to attack them? "))
- return;
+ else if (isupper (user_map[loc].contents)) { /* attacking self */
+ if (!getyn (
+ "Sir, those are our men! Do you really want to attack them? "))
+ return;
- attack (obj, loc);
- }
+ attack (obj, loc);
+ }
- else attack (obj, loc);
+ else attack (obj, loc);
}
/*
void
move_army_to_city(piece_info_t *obj, loc_t city_loc)
{
- piece_info_t *tt;
+ piece_info_t *tt;
- tt = find_nfull (TRANSPORT, city_loc);
+ tt = find_nfull (TRANSPORT, city_loc);
- if (tt != NULL) move_obj (obj, city_loc);
+ if (tt != NULL) move_obj (obj, city_loc);
- else fatal (obj, city_loc,
- "That's our city, sir! Do you really want to attack the garrison? ",
- "Your rebel army was liquidated.");
+ else fatal (obj, city_loc,
+ "That's our city, sir! Do you really want to attack the garrison? ",
+ "Your rebel army was liquidated.");
}
/*
void
user_cancel_auto(void)
{
- if (!automove)
- comment ("Not in auto mode!");
- else {
- automove = false;
- comment ("Auto mode cancelled.");
- }
+ if (!automove)
+ comment ("Not in auto mode!");
+ else {
+ automove = false;
+ comment ("Auto mode cancelled.");
+ }
}
/*
void
user_redraw (void)
{
- redraw ();
+ redraw ();
}
/*
bool
awake(piece_info_t *obj)
{
- int i;
- char c;
- long t;
+ int i;
+ char c;
+ long t;
- if (obj->type == ARMY && vmap_at_sea (user_map, obj->loc)) {
- obj->moved = piece_attr[ARMY].range;
- return (false);
- }
- if (obj->func == NOFUNC) return (true); /* object is awake */
+ if (obj->type == ARMY && vmap_at_sea (user_map, obj->loc)) {
+ obj->moved = piece_attr[ARMY].range;
+ return (false);
+ }
+ if (obj->func == NOFUNC) return (true); /* object is awake */
- if (obj->type == FIGHTER /* wake fighters */
- && obj->func != LAND /* that aren't returning to base */
- && obj->func < 0 /* and which don't have a path */
- && obj->range <= find_nearest_city (obj->loc, USER, &t) + 2) {
- obj->func = NOFUNC; /* wake piece */
- return (true);
- }
- for (i = 0; i < 8; i++) { /* for each surrounding cell */
- c = user_map[obj->loc+dir_offset[i]].contents;
+ if (obj->type == FIGHTER /* wake fighters */
+ && obj->func != LAND /* that aren't returning to base */
+ && obj->func < 0 /* and which don't have a path */
+ && obj->range <= find_nearest_city (obj->loc, USER, &t) + 2) {
+ obj->func = NOFUNC; /* wake piece */
+ return (true);
+ }
+ 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 (obj->func < 0) obj->func = NOFUNC; /* awaken */
- return (true);
- }
+ if (islower (c) || c == '*' || c == 'X') {
+ if (obj->func < 0) obj->func = NOFUNC; /* awaken */
+ return (true);
}
- return (false);
+ }
+ return (false);
}
/*
void
fatal(piece_info_t *obj, loc_t loc, char *message, char *response)
{
- if (getyn (message)) {
- comment (response);
- kill_obj (obj, loc);
- }
+ if (getyn (message)) {
+ comment (response);
+ kill_obj (obj, loc);
+ }
}
+
+/* end */
void
assert(char *expression, char *file, int line)
{
- char buf[STRSIZE];
+ char buf[STRSIZE];
- (void) move (lines, 0);
- close_disp ();
+ (void) move (lines, 0);
+ close_disp ();
- (void) sprintf (buf, "assert failed: file %s line %d: %s",
- file, line, expression);
+ (void) sprintf (buf, "assert failed: file %s line %d: %s",
+ file, line, expression);
- kill(getpid(), SIGSEGV); /* core dump */
+ kill(getpid(), SIGSEGV); /* core dump */
}
/*
void
empend(void)
{
- close_disp ();
- exit (0);
+ close_disp ();
+ exit (0);
}
static bool in_cargo[LIST_SIZE]; /* true if object in a cargo list */
void
-check(void) {
- void check_cargo(), check_obj(), check_obj_cargo();
+check(void)
+{
+ void check_cargo(), check_obj(), check_obj_cargo();
- long i, j;
- piece_info_t *p;
+ long i, j;
+ piece_info_t *p;
- /* nothing in any list yet */
- for (i = 0; i < LIST_SIZE; i++) {
- in_free[i] = 0;
- in_obj[i] = 0;
- in_loc[i] = 0;
- in_cargo[i] = 0;
- }
+ /* nothing in any list yet */
+ for (i = 0; i < LIST_SIZE; i++) {
+ in_free[i] = 0;
+ in_obj[i] = 0;
+ in_loc[i] = 0;
+ in_cargo[i] = 0;
+ }
- /* Mark all objects in free list. Make sure objects in free list
- have zero hits. */
+ /* Mark all objects in free list. Make sure objects in free list
+ have zero hits. */
- for (p = free_list; p != NULL; p = p->piece_link.next) {
- i = p - object;
- ASSERT (!in_free[i]);
- in_free[i] = 1;
- ASSERT (p->hits == 0);
- if (p->piece_link.prev)
- ASSERT (p->piece_link.prev->piece_link.next == p);
- }
+ for (p = free_list; p != NULL; p = p->piece_link.next) {
+ i = p - object;
+ ASSERT (!in_free[i]);
+ in_free[i] = 1;
+ ASSERT (p->hits == 0);
+ if (p->piece_link.prev)
+ ASSERT (p->piece_link.prev->piece_link.next == p);
+ }
- /* Mark all objects in the map.
- Check that cities are in corect location.
- Check that objects are in correct location,
- have a good owner, and good hits. */
+ /* Mark all objects in the map.
+ Check that cities are in corect location.
+ Check that objects are in correct location,
+ have a good owner, and good hits. */
- for (i = 0; i < MAP_SIZE; i++) {
- if (map[i].cityp) ASSERT (map[i].cityp->loc == i);
+ for (i = 0; i < MAP_SIZE; i++) {
+ if (map[i].cityp) ASSERT (map[i].cityp->loc == i);
- for (p = map[i].objp; p != NULL; p = p->loc_link.next) {
- ASSERT (p->loc == i);
- ASSERT (p->hits > 0);
- ASSERT (p->owner == USER || p->owner == COMP);
+ for (p = map[i].objp; p != NULL; p = p->loc_link.next) {
+ ASSERT (p->loc == i);
+ ASSERT (p->hits > 0);
+ ASSERT (p->owner == USER || p->owner == COMP);
- j = p - object;
- ASSERT (!in_loc[j]);
- in_loc[j] = 1;
+ j = p - object;
+ ASSERT (!in_loc[j]);
+ in_loc[j] = 1;
- if (p->loc_link.prev)
- ASSERT (p->loc_link.prev->loc_link.next == p);
- }
+ if (p->loc_link.prev)
+ ASSERT (p->loc_link.prev->loc_link.next == p);
}
+ }
- /* make sure all cities are on map */
+ /* make sure all cities are on map */
- for (i = 0; i < NUM_CITY; i++)
- ASSERT (map[city[i].loc].cityp == &(city[i]));
+ for (i = 0; i < NUM_CITY; i++)
+ ASSERT (map[city[i].loc].cityp == &(city[i]));
- /* Scan object lists. */
+ /* Scan object lists. */
- check_obj (comp_obj, COMP);
- check_obj (user_obj, USER);
+ check_obj (comp_obj, COMP);
+ check_obj (user_obj, USER);
- /* Scan cargo lists. */
+ /* Scan cargo lists. */
- check_cargo (user_obj[TRANSPORT], ARMY);
- check_cargo (comp_obj[TRANSPORT], ARMY);
- check_cargo (user_obj[CARRIER], FIGHTER);
- check_cargo (comp_obj[CARRIER], FIGHTER);
+ check_cargo (user_obj[TRANSPORT], ARMY);
+ check_cargo (comp_obj[TRANSPORT], ARMY);
+ check_cargo (user_obj[CARRIER], FIGHTER);
+ check_cargo (comp_obj[CARRIER], FIGHTER);
- /* Make sure all objects with ship pointers are in cargo. */
+ /* Make sure all objects with ship pointers are in cargo. */
- check_obj_cargo (comp_obj);
- check_obj_cargo (user_obj);
+ check_obj_cargo (comp_obj);
+ check_obj_cargo (user_obj);
- /* Make sure every object is either free or in loc and obj list. */
+ /* Make sure every object is either free or in loc and obj list. */
- for (i = 0; i < LIST_SIZE; i++)
- ASSERT (in_free[i] != (in_loc[i] && in_obj[i]));
+ for (i = 0; i < LIST_SIZE; i++)
+ ASSERT (in_free[i] != (in_loc[i] && in_obj[i]));
}
/*
void
check_obj(piece_info_t **list, int owner)
{
- long i, j;
- piece_info_t *p;
+ long i, j;
+ piece_info_t *p;
- for (i = 0; i < NUM_OBJECTS; i++)
+ for (i = 0; i < NUM_OBJECTS; i++)
for (p = list[i]; p != NULL; p = p->piece_link.next) {
- ASSERT (p->owner == owner);
- ASSERT (p->type == i);
- ASSERT (p->hits > 0);
+ ASSERT (p->owner == owner);
+ ASSERT (p->type == i);
+ ASSERT (p->hits > 0);
- j = p - object;
- ASSERT (!in_obj[j]);
- in_obj[j] = 1;
+ j = p - object;
+ ASSERT (!in_obj[j]);
+ in_obj[j] = 1;
- if (p->piece_link.prev)
- ASSERT (p->piece_link.prev->piece_link.next == p);
+ if (p->piece_link.prev)
+ ASSERT (p->piece_link.prev->piece_link.next == p);
}
}
void
check_cargo(piece_info_t *list, int cargo_type)
{
- piece_info_t *p, *q;
- long j, count;
+ piece_info_t *p, *q;
+ long j, count;
- for (p = list; p != NULL; p = p->piece_link.next) {
- count = 0;
- for (q = p->cargo; q != NULL; q = q->cargo_link.next) {
- count += 1; /* count items in list */
- ASSERT (q->type == cargo_type);
- ASSERT (q->owner == p->owner);
- ASSERT (q->hits > 0);
- ASSERT (q->ship == p);
- ASSERT (q->loc == p->loc);
+ for (p = list; p != NULL; p = p->piece_link.next) {
+ count = 0;
+ for (q = p->cargo; q != NULL; q = q->cargo_link.next) {
+ count += 1; /* count items in list */
+ ASSERT (q->type == cargo_type);
+ ASSERT (q->owner == p->owner);
+ ASSERT (q->hits > 0);
+ ASSERT (q->ship == p);
+ ASSERT (q->loc == p->loc);
- j = q - object;
- ASSERT (!in_cargo[j]);
- in_cargo[j] = 1;
-
- if (p->cargo_link.prev)
- ASSERT (p->cargo_link.prev->cargo_link.next == p);
- }
- ASSERT (count == p->count);
- }
+ j = q - object;
+ ASSERT (!in_cargo[j]);
+ in_cargo[j] = 1;
+
+ if (p->cargo_link.prev)
+ ASSERT (p->cargo_link.prev->cargo_link.next == p);
+ }
+ ASSERT (count == p->count);
+ }
}
/*
void
check_obj_cargo(piece_info_t **list)
{
- piece_info_t *p;
- long i;
+ piece_info_t *p;
+ long i;
- for (i = 0; i < NUM_OBJECTS; i++)
+ for (i = 0; i < NUM_OBJECTS; i++)
for (p = list[i]; p != NULL; p = p->piece_link.next) {
- if (p->ship) ASSERT (in_cargo[p-object]);
+ if (p->ship) ASSERT (in_cargo[p-object]);
}
}
+
+/* end */