(get_leader, pr_leader_change): New.
(set_leader, set_flagship): Replace with get_leader() and pr_leader_change().
This commit is contained in:
parent
69d6b01429
commit
c6577ef2c5
3 changed files with 48 additions and 42 deletions
|
@ -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 would_abandon(struct sctstr *, i_type, int, struct lndstr *);
|
||||||
extern int nav_map(int, int, int);
|
extern int nav_map(int, int, int);
|
||||||
extern void switch_leader(struct emp_qelem *list, int uid);
|
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 count_pop(int);
|
||||||
extern int scuttle_tradeship(struct shpstr *, int);
|
extern int scuttle_tradeship(struct shpstr *, int);
|
||||||
extern void scuttle_ship(struct shpstr *);
|
extern void scuttle_ship(struct shpstr *);
|
||||||
|
|
|
@ -42,8 +42,6 @@
|
||||||
#include "empobj.h"
|
#include "empobj.h"
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
|
|
||||||
static int set_leader(struct emp_qelem *list, struct lndstr **leaderp);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
march(void)
|
march(void)
|
||||||
{
|
{
|
||||||
|
@ -52,7 +50,8 @@ march(void)
|
||||||
double minmob, maxmob;
|
double minmob, maxmob;
|
||||||
int together;
|
int together;
|
||||||
char *cp = NULL;
|
char *cp = NULL;
|
||||||
struct lndstr *lnd = NULL; /* leader */
|
int leader_uid;
|
||||||
|
struct lndstr *lnd; /* leader */
|
||||||
int dir;
|
int dir;
|
||||||
int stopping = 0;
|
int stopping = 0;
|
||||||
int skip = 0;
|
int skip = 0;
|
||||||
|
@ -70,7 +69,9 @@ march(void)
|
||||||
pr("No lands\n");
|
pr("No lands\n");
|
||||||
return RET_FAIL;
|
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]) {
|
if (player->argp[2]) {
|
||||||
strcpy(buf, player->argp[2]);
|
strcpy(buf, player->argp[2]);
|
||||||
if (!(cp = lnd_path(together, lnd, buf)))
|
if (!(cp = lnd_path(together, lnd, buf)))
|
||||||
|
@ -87,7 +88,10 @@ march(void)
|
||||||
pr("No lands left\n");
|
pr("No lands left\n");
|
||||||
return RET_OK;
|
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;
|
stopping = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -106,7 +110,10 @@ march(void)
|
||||||
pr("No lands left\n");
|
pr("No lands left\n");
|
||||||
return RET_OK;
|
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;
|
stopping = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -145,7 +152,11 @@ march(void)
|
||||||
switch_leader(&land_list, -1);
|
switch_leader(&land_list, -1);
|
||||||
else
|
else
|
||||||
switch_leader(&land_list, atoi(player->argp[1]));
|
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;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
lnd_list(&land_list);
|
lnd_list(&land_list);
|
||||||
|
@ -184,20 +195,18 @@ march(void)
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
void
|
||||||
set_leader(struct emp_qelem *list, struct lndstr **leaderp)
|
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)
|
struct empobj *
|
||||||
pr("Leader is ");
|
get_leader(struct emp_qelem *list)
|
||||||
else if ((*leaderp)->lnd_uid != llp->unit.land.lnd_uid)
|
{
|
||||||
pr("Changing leader to ");
|
return &((struct ulist *)(list->q_back))->unit.gen;
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
*leaderp = &llp->unit.land;
|
|
||||||
pr("%s\n", prland(&llp->unit.land));
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -41,8 +41,6 @@
|
||||||
#include "empobj.h"
|
#include "empobj.h"
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
|
|
||||||
static int set_flagship(struct emp_qelem *list, struct shpstr **flagshipp);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
navi(void)
|
navi(void)
|
||||||
{
|
{
|
||||||
|
@ -51,7 +49,8 @@ navi(void)
|
||||||
double minmob, maxmob;
|
double minmob, maxmob;
|
||||||
int together;
|
int together;
|
||||||
char *cp = NULL;
|
char *cp = NULL;
|
||||||
struct shpstr *shp = NULL; /* flagship */
|
int leader_uid;
|
||||||
|
struct shpstr *shp; /* flagship */
|
||||||
int dir;
|
int dir;
|
||||||
int stopping = 0;
|
int stopping = 0;
|
||||||
int skip = 0;
|
int skip = 0;
|
||||||
|
@ -71,7 +70,9 @@ navi(void)
|
||||||
pr("No ships\n");
|
pr("No ships\n");
|
||||||
return RET_FAIL;
|
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]) {
|
if (player->argp[2]) {
|
||||||
strcpy(buf, player->argp[2]);
|
strcpy(buf, player->argp[2]);
|
||||||
if (!(cp = shp_path(together, shp, buf)))
|
if (!(cp = shp_path(together, shp, buf)))
|
||||||
|
@ -94,7 +95,10 @@ navi(void)
|
||||||
}
|
}
|
||||||
return RET_OK;
|
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;
|
stopping = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -119,7 +123,10 @@ navi(void)
|
||||||
}
|
}
|
||||||
return RET_OK;
|
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;
|
stopping = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -170,7 +177,11 @@ navi(void)
|
||||||
switch_leader(&ship_list, -1);
|
switch_leader(&ship_list, -1);
|
||||||
else
|
else
|
||||||
switch_leader(&ship_list, atoi(player->argp[1]));
|
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;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
shp_list(&ship_list);
|
shp_list(&ship_list);
|
||||||
|
@ -284,19 +295,3 @@ nav_map(int x, int y, int show_designations)
|
||||||
pr("%s\n", wmap[i]);
|
pr("%s\n", wmap[i]);
|
||||||
return RET_OK;
|
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;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue