(pln_dropoff): Restructure for clarity and to avoid `might be used

uninitialized' warning.
This commit is contained in:
Markus Armbruster 2004-03-04 15:45:34 +00:00
parent bebca811de
commit 7cd66c0f70
2 changed files with 49 additions and 50 deletions

View file

@ -395,8 +395,8 @@ extern int pln_onewaymission(struct sctstr *, int *, int *);
extern void pln_newlanding(struct emp_qelem *, coord, coord, int); extern void pln_newlanding(struct emp_qelem *, coord, coord, int);
extern int can_be_on_ship(int, int); extern int can_be_on_ship(int, int);
extern int put_plane_on_ship(struct plnstr *, struct shpstr *); extern int put_plane_on_ship(struct plnstr *, struct shpstr *);
extern void pln_dropoff(struct emp_qelem *, struct ichrstr *, coord, extern void pln_dropoff(struct emp_qelem *, struct ichrstr *,
coord, s_char *, int); coord, coord, void *, int);
extern void pln_sel(struct nstr_item *, struct emp_qelem *, extern void pln_sel(struct nstr_item *, struct emp_qelem *,
struct sctstr *, int, int, int, int); struct sctstr *, int, int, int, int);
extern int pln_arm(struct emp_qelem *, int, int, struct ichrstr *, extern int pln_arm(struct emp_qelem *, int, int, struct ichrstr *,

View file

@ -208,12 +208,13 @@ pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
void void
pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty, pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
s_char *ptr, int type) void *ptr, int type)
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct plist *plp; struct plist *plp;
int amt; int amt;
struct shpstr *ship; struct sctstr *sectp;
struct shpstr *sp;
int there; int there;
int max; int max;
struct mchrstr *mp; struct mchrstr *mp;
@ -225,54 +226,52 @@ pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
plp = (struct plist *)qp; plp = (struct plist *)qp;
amt += plp->misc; amt += plp->misc;
} }
if (type == EF_SECTOR && if (type == EF_SECTOR) {
(((struct sctstr *)ptr)->sct_type == SCT_WATER) && sectp = ptr;
ip->i_vtype == V_SHELL) { if (sectp->sct_type == SCT_WATER && ip->i_vtype == V_SHELL) {
((struct sctstr *)ptr)->sct_mines += amt; /* aerial mining */
pr("%d mines laid in %s.\n", amt, sectp->sct_mines += amt;
xyas(((struct sctstr *)ptr)->sct_x, pr("%d mines laid in %s.\n", amt,
((struct sctstr *)ptr)->sct_y, player->cnum)); xyas(sectp->sct_x, sectp->sct_y, player->cnum));
if (amt > 0 && if (amt > 0
map_set(player->cnum, ((struct sctstr *)ptr)->sct_x, && map_set(player->cnum, sectp->sct_x, sectp->sct_y, 'X', 0))
((struct sctstr *)ptr)->sct_y, 'X', 0)) writemap(player->cnum);
writemap(player->cnum); putsect(sectp);
return;
}
there = sectp->sct_item[ip->i_vtype];
max = 32767;
} else {
sp = ptr;
there = sp->shp_item[ip->i_vtype];
mp = &mchr[(int)sp->shp_type];
max = vl_find(ip->i_vtype, mp->m_vtype,
mp->m_vamt, (int)mp->m_nv);
}
there += amt;
if (there > max) {
pr("%d excess %s discarded\n", max - there, ip->i_name);
amt = max - there;
there = max;
}
pr("%d %s landed safely", amt, ip->i_name);
if (type == EF_SECTOR) {
sectp = ptr;
sectp->sct_item[ip->i_vtype] = there;
if (sectp->sct_own != player->cnum)
wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n",
cname(player->cnum), amt, ip->i_name,
xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
pr(" at %s\n", xyas(tx, ty, player->cnum));
putsect((struct sctstr *)ptr); putsect((struct sctstr *)ptr);
} else { } else {
if (type == EF_SHIP) { struct shpstr *sp = (struct shpstr *)ptr;
ship = (struct shpstr *)ptr; sp->shp_item[ip->i_vtype] = there;
there = ship->shp_item[ip->i_vtype]; if (sp->shp_own != player->cnum)
mp = &mchr[(int)ship->shp_type]; wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n",
max = vl_find(ip->i_vtype, mp->m_vtype, cname(player->cnum), amt, ip->i_name, sp->shp_uid);
mp->m_vamt, (int)mp->m_nv); pr(" on carrier #%d\n", sp->shp_uid);
} else { putship(sp->shp_uid, sp);
there = ((struct sctstr *)ptr)->sct_item[ip->i_vtype];
max = 32767;
}
there += amt;
if (there > max) {
pr("%d excess %s discarded\n", max - there, ip->i_name);
amt = max - there;
there = max;
}
pr("%d %s landed safely", amt, ip->i_name);
if (type == EF_SECTOR) {
struct sctstr *sectp = (struct sctstr *)ptr;
sectp->sct_item[ip->i_vtype] = there;
if (sectp->sct_own != player->cnum)
wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n",
cname(player->cnum), amt, ip->i_name,
xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
pr(" at %s\n", xyas(tx, ty, player->cnum));
putsect((struct sctstr *)ptr);
} else {
struct shpstr *sp = (struct shpstr *)ptr;
sp->shp_item[ip->i_vtype] = there;
if (sp->shp_own != player->cnum)
wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n",
cname(player->cnum), amt, ip->i_name, sp->shp_uid);
pr(" on carrier #%d\n", ship->shp_uid);
putship(ship->shp_uid, ship);
}
} }
} }