(get_leader, pr_leader_change): New.

(set_leader, set_flagship): Replace with get_leader() and
pr_leader_change().
This commit is contained in:
Ron Koenderink 2006-12-31 12:31:18 +00:00
parent 69d6b01429
commit c6577ef2c5
3 changed files with 48 additions and 42 deletions

View file

@ -63,6 +63,8 @@ extern int want_to_abandon(struct sctstr *, i_type, int, struct lndstr *);
extern int would_abandon(struct sctstr *, i_type, int, struct lndstr *);
extern int nav_map(int, int, int);
extern void switch_leader(struct emp_qelem *list, int uid);
extern struct empobj *get_leader(struct emp_qelem *list);
extern void pr_leader_change(struct empobj *leader);
extern int count_pop(int);
extern int scuttle_tradeship(struct shpstr *, int);
extern void scuttle_ship(struct shpstr *);

View file

@ -42,8 +42,6 @@
#include "empobj.h"
#include "unit.h"
static int set_leader(struct emp_qelem *list, struct lndstr **leaderp);
int
march(void)
{
@ -52,7 +50,8 @@ march(void)
double minmob, maxmob;
int together;
char *cp = NULL;
struct lndstr *lnd = NULL; /* leader */
int leader_uid;
struct lndstr *lnd; /* leader */
int dir;
int stopping = 0;
int skip = 0;
@ -70,7 +69,9 @@ march(void)
pr("No lands\n");
return RET_FAIL;
}
set_leader(&land_list, &lnd);
lnd = (struct lndstr *)get_leader(&land_list);
leader_uid = lnd->lnd_uid;
pr("Leader is %s\n", prland(lnd));
if (player->argp[2]) {
strcpy(buf, player->argp[2]);
if (!(cp = lnd_path(together, lnd, buf)))
@ -87,7 +88,10 @@ march(void)
pr("No lands left\n");
return RET_OK;
}
if (set_leader(&land_list, &lnd)) {
lnd = (struct lndstr *)get_leader(&land_list);
if (lnd->lnd_uid != leader_uid) {
leader_uid = lnd->lnd_uid;
pr_leader_change((struct empobj *)lnd);
stopping = 1;
continue;
}
@ -106,7 +110,10 @@ march(void)
pr("No lands left\n");
return RET_OK;
}
if (set_leader(&land_list, &lnd)) {
lnd = (struct lndstr *)get_leader(&land_list);
if (lnd->lnd_uid != leader_uid) {
leader_uid = lnd->lnd_uid;
pr_leader_change((struct empobj *)lnd);
stopping = 1;
continue;
}
@ -145,7 +152,11 @@ march(void)
switch_leader(&land_list, -1);
else
switch_leader(&land_list, atoi(player->argp[1]));
set_leader(&land_list, &lnd);
lnd = (struct lndstr *)get_leader(&land_list);
if (lnd->lnd_uid != leader_uid) {
leader_uid = lnd->lnd_uid;
pr_leader_change((struct empobj *)lnd);
}
break;
case 'i':
lnd_list(&land_list);
@ -184,20 +195,18 @@ march(void)
return RET_OK;
}
static int
set_leader(struct emp_qelem *list, struct lndstr **leaderp)
void
pr_leader_change(struct empobj *leader)
{
struct ulist *llp = (struct ulist *)(list->q_back);
pr("Changing %s to %s\n",
leader->ef_type == EF_SHIP ? "flagship" : "leader",
obj_nameof(leader));
}
if (!*leaderp)
pr("Leader is ");
else if ((*leaderp)->lnd_uid != llp->unit.land.lnd_uid)
pr("Changing leader to ");
else
return 0;
*leaderp = &llp->unit.land;
pr("%s\n", prland(&llp->unit.land));
return 1;
struct empobj *
get_leader(struct emp_qelem *list)
{
return &((struct ulist *)(list->q_back))->unit.gen;
}
void

View file

@ -41,8 +41,6 @@
#include "empobj.h"
#include "unit.h"
static int set_flagship(struct emp_qelem *list, struct shpstr **flagshipp);
int
navi(void)
{
@ -51,7 +49,8 @@ navi(void)
double minmob, maxmob;
int together;
char *cp = NULL;
struct shpstr *shp = NULL; /* flagship */
int leader_uid;
struct shpstr *shp; /* flagship */
int dir;
int stopping = 0;
int skip = 0;
@ -71,7 +70,9 @@ navi(void)
pr("No ships\n");
return RET_FAIL;
}
set_flagship(&ship_list, &shp);
shp = (struct shpstr *)get_leader(&ship_list);
leader_uid = shp->shp_uid;
pr("Flagship is %s\n", prship(shp));
if (player->argp[2]) {
strcpy(buf, player->argp[2]);
if (!(cp = shp_path(together, shp, buf)))
@ -94,7 +95,10 @@ navi(void)
}
return RET_OK;
}
if (set_flagship(&ship_list, &shp)) {
shp = (struct shpstr *)get_leader(&ship_list);
if (shp->shp_uid != leader_uid) {
leader_uid = shp->shp_uid;
pr_leader_change((struct empobj *)shp);
stopping = 1;
continue;
}
@ -119,7 +123,10 @@ navi(void)
}
return RET_OK;
}
if (set_flagship(&ship_list, &shp)) {
shp = (struct shpstr *)get_leader(&ship_list);
if (shp->shp_uid != leader_uid) {
leader_uid = shp->shp_uid;
pr_leader_change((struct empobj *)shp);
stopping = 1;
continue;
}
@ -170,7 +177,11 @@ navi(void)
switch_leader(&ship_list, -1);
else
switch_leader(&ship_list, atoi(player->argp[1]));
set_flagship(&ship_list, &shp);
shp = (struct shpstr *)get_leader(&ship_list);
if (shp->shp_uid != leader_uid) {
leader_uid = shp->shp_uid;
pr_leader_change((struct empobj *)shp);
}
break;
case 'i':
shp_list(&ship_list);
@ -284,19 +295,3 @@ nav_map(int x, int y, int show_designations)
pr("%s\n", wmap[i]);
return RET_OK;
}
static int
set_flagship(struct emp_qelem *list, struct shpstr **flagshipp)
{
struct ulist *mlp = (struct ulist *)(list->q_back);
if (!*flagshipp)
pr("Flagship is ");
else if ((*flagshipp)->shp_uid != mlp->unit.ship.shp_uid)
pr("Changing flagship to ");
else
return 0;
*flagshipp = &mlp->unit.ship;
pr("%s\n", prship(&mlp->unit.ship));
return 1;
}