From 0fe43096bc199f4da6f827d10d97cdc15cb384a1 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 13 Sep 2009 21:35:17 -0400 Subject: [PATCH] Simplify calling of pln_arm() & friends pln_arm(), pln_equip(), mission_pln_arm() mission_pln_equip() took a mission parameter encoding the kind of sortie (strategic bomb, pinpoint bomb, transport, ...), a flag parameter to further specify the plane's role, and a parameter ip to specify the load. The flags argument was always either P_F (intercept), P_F | P_ESC (escort), or zero (any other role). With non-zero flags, mission and ip argument were not used in any way. Use mission 'e' and null load for escorts, and remove flags. Intercept can still be identified by mission zero. Also change pln_mobcost() to take a mission parameter instead of flags, so that pln_arm() and mission_pln_arm() can simply pass on their mission. --- include/prototypes.h | 6 +- src/lib/commands/bomb.c | 4 +- src/lib/commands/drop.c | 4 +- src/lib/commands/fly.c | 4 +- src/lib/commands/para.c | 4 +- src/lib/commands/reco.c | 4 +- src/lib/subs/aircombat.c | 6 +- src/lib/subs/mission.c | 123 +++++++++++++++++------------------ src/lib/subs/mslsub.c | 8 +-- src/lib/subs/plnsub.c | 136 +++++++++++++++++++-------------------- 10 files changed, 147 insertions(+), 152 deletions(-) diff --git a/include/prototypes.h b/include/prototypes.h index 5f7ad297..c570ee2a 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -476,7 +476,7 @@ extern int share_bmap(natid, natid, struct nstr_sect *, char, char *); /* mission.c */ extern char *mission_name(short); extern int collateral_damage(coord, coord, int); -extern int mission_pln_equip(struct plist *, struct ichrstr *, int, char); +extern int mission_pln_equip(struct plist *, struct ichrstr *, char); extern int ground_interdict(coord, coord, natid, char *); extern int unit_interdict(coord, coord, natid, char *, int, int); extern int off_support(coord, coord, natid, natid); @@ -547,8 +547,8 @@ extern int pln_airbase_ok(struct plnstr *, int, int); extern int carrier_planes(struct shpstr *, int); extern void pln_sel(struct nstr_item *, struct emp_qelem *, struct sctstr *, int, int, int, int); -extern void pln_arm(struct emp_qelem *, int, char, struct ichrstr *, int); -extern int pln_mobcost(int, struct plnstr *, int); +extern void pln_arm(struct emp_qelem *, int, char, struct ichrstr *); +extern int pln_mobcost(int, struct plnstr *, char); extern void pln_put(struct emp_qelem *); extern void pln_put1(struct plist *); extern void plane_sweep(struct emp_qelem *, coord, coord); diff --git a/src/lib/commands/bomb.c b/src/lib/commands/bomb.c index 9f4db369..66a30e1d 100644 --- a/src/lib/commands/bomb.c +++ b/src/lib/commands/bomb.c @@ -137,12 +137,12 @@ bomb(void) /* * now arm and equip the bombers, transports, whatever. */ - pln_arm(&bomb_list, 2 * ap_to_target, mission, ip, 0); + pln_arm(&bomb_list, 2 * ap_to_target, mission, ip); if (QEMPTY(&bomb_list)) { pr("No planes could be equipped for the mission.\n"); return RET_FAIL; } - pln_arm(&esc_list, 2 * ap_to_target, mission, ip, P_F | P_ESC); + pln_arm(&esc_list, 2 * ap_to_target, 'e', NULL); ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, 0); if (QEMPTY(&bomb_list)) { pr("No planes got through fighter defenses\n"); diff --git a/src/lib/commands/drop.c b/src/lib/commands/drop.c index c1ea70eb..b3c14009 100644 --- a/src/lib/commands/drop.c +++ b/src/lib/commands/drop.c @@ -110,12 +110,12 @@ drop(void) */ pln_arm(&bomb_list, 2 * ap_to_target, wantflags & P_MINE ? 'm' : 'd', - ip, 0); + ip); if (QEMPTY(&bomb_list)) { pr("No planes could be equipped for the mission.\n"); return RET_FAIL; } - pln_arm(&esc_list, 2 * ap_to_target, 'd', ip, P_ESC | P_F); + pln_arm(&esc_list, 2 * ap_to_target, 'e', NULL); ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, 0); if (QEMPTY(&bomb_list)) { pr("No planes got through fighter defenses\n"); diff --git a/src/lib/commands/fly.c b/src/lib/commands/fly.c index bc5c445b..4a9bb91b 100644 --- a/src/lib/commands/fly.c +++ b/src/lib/commands/fly.c @@ -111,12 +111,12 @@ fly(void) /* * now arm and equip the bombers, transports, whatever. */ - pln_arm(&bomb_list, ap_to_target, 't', ip, 0); + pln_arm(&bomb_list, ap_to_target, 't', ip); if (QEMPTY(&bomb_list)) { pr("No planes could be equipped for the mission.\n"); return RET_FAIL; } - pln_arm(&esc_list, ap_to_target, 't', ip, P_ESC | P_F); + pln_arm(&esc_list, ap_to_target, 'e', NULL); ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, 0); if (QEMPTY(&bomb_list)) { pr("No planes got through fighter defenses\n"); diff --git a/src/lib/commands/para.c b/src/lib/commands/para.c index 081a8b0c..869b38ef 100644 --- a/src/lib/commands/para.c +++ b/src/lib/commands/para.c @@ -90,12 +90,12 @@ para(void) /* * now arm and equip the bombers, transports, whatever. */ - pln_arm(&bomb_list, 2 * ap_to_target, 'a', &ichr[I_MILIT], 0); + pln_arm(&bomb_list, 2 * ap_to_target, 'a', &ichr[I_MILIT]); if (QEMPTY(&bomb_list)) { pr("No planes could be equipped for the mission.\n"); return RET_FAIL; } - pln_arm(&esc_list, 2 * ap_to_target, 'a', &ichr[I_MILIT], P_ESC | P_F); + pln_arm(&esc_list, 2 * ap_to_target, 'e', NULL); ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, 0); if (QEMPTY(&bomb_list)) { pr("No planes got through fighter defenses\n"); diff --git a/src/lib/commands/reco.c b/src/lib/commands/reco.c index 65e94c8b..b0a6f457 100644 --- a/src/lib/commands/reco.c +++ b/src/lib/commands/reco.c @@ -97,12 +97,12 @@ reco(void) /* * now arm and equip the bombers, transports, whatever. */ - pln_arm(&bomb_list, ap_to_target, 'r', NULL, 0); + pln_arm(&bomb_list, ap_to_target, 'r', NULL); if (QEMPTY(&bomb_list)) { pr("No planes could be equipped for the mission.\n"); return RET_FAIL; } - pln_arm(&esc_list, ap_to_target, 'r', NULL, P_F | P_ESC); + pln_arm(&esc_list, ap_to_target, 'e', NULL); ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, *player->argp[0] == 's' ? PM_R | PM_S : PM_R); if (QEMPTY(&bomb_list)) { diff --git a/src/lib/subs/aircombat.c b/src/lib/subs/aircombat.c index 46161828..bf6022df 100644 --- a/src/lib/subs/aircombat.c +++ b/src/lib/subs/aircombat.c @@ -295,7 +295,7 @@ sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list, && pp->pln_radius < mapdist(x, y, pp->pln_opx, pp->pln_opy)) continue; if (CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED) - || mission_pln_equip(dplp, NULL, P_F, 0) < 0) { + || mission_pln_equip(dplp, NULL, 0) < 0) { emp_remque(dqp); free(dqp); continue; @@ -369,7 +369,7 @@ ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, && pp->pln_radius < mapdist(x, y, pp->pln_opx, pp->pln_opy)) continue; if (CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED) - || mission_pln_equip(plp, NULL, P_F, 0) < 0) { + || mission_pln_equip(plp, NULL, 0) < 0) { emp_remque(qp); free(qp); continue; @@ -378,7 +378,7 @@ ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, emp_remque(qp); emp_insque(qp, &int_list); pp->pln_flags |= PLN_LAUNCHED; - pp->pln_mobil -= pln_mobcost(dist, pp, P_F); + pp->pln_mobil -= pln_mobcost(dist, pp, 0); putplane(pp->pln_uid, pp); icount++; if (icount > att_count) diff --git a/src/lib/subs/mission.c b/src/lib/subs/mission.c index 03dea906..d94c7058 100644 --- a/src/lib/subs/mission.c +++ b/src/lib/subs/mission.c @@ -71,7 +71,7 @@ static void divide(struct emp_qelem *, struct emp_qelem *, coord, coord); static int dosupport(struct genlist *, coord, coord, natid, natid); static int find_airport(struct emp_qelem *, coord, coord); static void mission_pln_arm(struct emp_qelem *, coord, coord, int, - int, struct ichrstr *, int); + int, struct ichrstr *); static void mission_pln_sel(struct emp_qelem *, int, int, int); static int perform_mission(coord, coord, natid, struct emp_qelem *, int, char *, int); @@ -610,12 +610,12 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list, /* Split off the escorts at this base into e */ divide(&escorts, &e, air->x, air->y); - mission_pln_arm(&b, air->x, air->y, 2 * md, 'p', NULL, 0); + mission_pln_arm(&b, air->x, air->y, 2 * md, 'p', NULL); if (QEMPTY(&b)) continue; - mission_pln_arm(&e, air->x, air->y, 2 * md, 'p', NULL, P_F | P_ESC); + mission_pln_arm(&e, air->x, air->y, 2 * md, 'e', NULL); pp = BestAirPath(buf, air->x, air->y, x, y); if (CANT_HAPPEN(!pp)) @@ -840,7 +840,7 @@ mission_pln_sel(struct emp_qelem *list, int wantflags, int nowantflags, */ static void mission_pln_arm(struct emp_qelem *list, coord x, coord y, int dist, - int mission, struct ichrstr *ip, int flags) + int mission, struct ichrstr *ip) { struct emp_qelem *qp; struct emp_qelem *next; @@ -858,21 +858,20 @@ mission_pln_arm(struct emp_qelem *list, coord x, coord y, int dist, continue; if (CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED) - || mission_pln_equip(plp, ip, flags, mission) < 0) { + || mission_pln_equip(plp, ip, mission) < 0) { emp_remque(qp); free(qp); continue; } pp->pln_flags |= PLN_LAUNCHED; - pp->pln_mobil -= pln_mobcost(dist, pp, flags); + pp->pln_mobil -= pln_mobcost(dist, pp, mission); putplane(pp->pln_uid, pp); } } int -mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags, - char mission) +mission_pln_equip(struct plist *plp, struct ichrstr *ip, char mission) { struct plchrstr *pcp; struct plnstr *pp; @@ -899,64 +898,62 @@ mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags, return -1; } item[I_PETROL] -= pcp->pl_fuel; - if (!(flags & P_F)) { - load = pln_load(pp); - itype = I_NONE; - needed = 0; - switch (mission) { - case 's': /* strategic bomb */ - case 'p': /* pinpoint bomb */ - if (nuk_on_plane(pp) < 0) { - itype = I_SHELL; - needed = load; - } - break; - case 't': /* transport */ - case 'd': /* drop */ - if (!(pcp->pl_flags & P_C) || !ip) - break; - itype = ip->i_uid; - needed = (load * 2) / ip->i_lbs; - break; - case 'a': /* paradrop */ - if ((pcp->pl_flags & (P_V | P_C)) == 0) - break; - itype = I_MILIT; - needed = load / ip->i_lbs; - break; - case 'i': /* missile interception */ - if (load) { - itype = I_SHELL; - needed = load; - } - break; - case 'r': /* reconnaissance */ - case 0: /* plane interception */ - break; - default: - CANT_REACH(); - break; + load = pln_load(pp); + itype = I_NONE; + needed = 0; + switch (mission) { + case 's': /* strategic bomb */ + case 'p': /* pinpoint bomb */ + if (nuk_on_plane(pp) < 0) { + itype = I_SHELL; + needed = load; } - if (itype != I_NONE && needed <= 0) - return -1; - if (itype != I_NONE) { - if (itype == I_SHELL && item[itype] < needed) { - if (pp->pln_ship >= 0) - shp_supply(&ship, I_SHELL, needed); - else if (pp->pln_land >= 0) - lnd_supply(&land, I_SHELL, needed); - else - sct_supply(§, I_SHELL, needed); - } - if (item[itype] < needed) - return -1; - item[itype] -= needed; + break; + case 't': /* transport */ + case 'd': /* drop */ + if (!(pcp->pl_flags & P_C) || !ip) + break; + itype = ip->i_uid; + needed = (load * 2) / ip->i_lbs; + break; + case 'a': /* paradrop */ + if ((pcp->pl_flags & (P_V | P_C)) == 0) + break; + itype = I_MILIT; + needed = load / ip->i_lbs; + break; + case 'i': /* missile interception */ + if (load) { + itype = I_SHELL; + needed = load; } - if (itype == I_SHELL && (mission == 's' || mission == 'p')) - plp->bombs = needed; - else - plp->misc = needed; + break; + case 'r': /* reconnaissance */ + case 'e': /* escort */ + case 0: /* plane interception */ + break; + default: + CANT_REACH(); } + if (itype != I_NONE && needed <= 0) + return -1; + if (itype != I_NONE) { + if (itype == I_SHELL && item[itype] < needed) { + if (pp->pln_ship >= 0) + shp_supply(&ship, I_SHELL, needed); + else if (pp->pln_land >= 0) + lnd_supply(&land, I_SHELL, needed); + else + sct_supply(§, I_SHELL, needed); + } + if (item[itype] < needed) + return -1; + item[itype] -= needed; + } + if (itype == I_SHELL && (mission == 's' || mission == 'p')) + plp->bombs = needed; + else + plp->misc = needed; if (pp->pln_ship >= 0) putship(ship.shp_uid, &ship); else if (pp->pln_land >= 0) diff --git a/src/lib/subs/mslsub.c b/src/lib/subs/mslsub.c index a8ec1b4f..b982d12e 100644 --- a/src/lib/subs/mslsub.c +++ b/src/lib/subs/mslsub.c @@ -61,7 +61,7 @@ msl_equip(struct plnstr *pp, char mission) memset(&pl, 0, sizeof(struct plist)); pl.pcp = plchr + pp->pln_type; pl.plane = *pp; - return mission_pln_equip(&pl, NULL, 0, mission); + return mission_pln_equip(&pl, NULL, mission); } int @@ -271,7 +271,7 @@ msl_intercept(coord x, coord y, natid bombown, int hardtarget, if (pp->pln_own != sect.sct_own) continue; pcp = ip->pcp; - if (mission_pln_equip(ip, NULL, 0, 'i') < 0) { + if (mission_pln_equip(ip, NULL, 'i') < 0) { emp_remque(qp); free(qp); continue; @@ -290,7 +290,7 @@ msl_intercept(coord x, coord y, natid bombown, int hardtarget, ip = (struct plist *)qp; pp = &ip->plane; pcp = ip->pcp; - if (mission_pln_equip(ip, NULL, 0, 'i') < 0) { + if (mission_pln_equip(ip, NULL, 'i') < 0) { emp_remque(qp); free(qp); continue; @@ -401,7 +401,7 @@ msl_launch_mindam(struct emp_qelem *list, coord x, coord y, int hardtarget, next = qp->q_back; plp = (struct plist *)qp; - if (mission_pln_equip(plp, NULL, 0, 'p') >= 0) { + if (mission_pln_equip(plp, NULL, 'p') >= 0) { if (msl_hit(&plp->plane, hardtarget, type, news_item, snews_item, whatp, x, y, victim)) { diff --git a/src/lib/subs/plnsub.c b/src/lib/subs/plnsub.c index 661529ab..3bbe049f 100644 --- a/src/lib/subs/plnsub.c +++ b/src/lib/subs/plnsub.c @@ -54,7 +54,7 @@ #include "ship.h" #include "xy.h" -static int pln_equip(struct plist *, struct ichrstr *, int, char); +static int pln_equip(struct plist *, struct ichrstr *, char); static int fit_plane_on_ship(struct plnstr *, struct shpstr *); /* @@ -582,8 +582,7 @@ pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap, } void -pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip, - int flags) +pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip) { struct emp_qelem *qp; struct emp_qelem *next; @@ -596,20 +595,20 @@ pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip, pp = &plp->plane; getplane(pp->pln_uid, pp); if ((pp->pln_flags & PLN_LAUNCHED) - || pln_equip(plp, ip, flags, mission) < 0) { + || pln_equip(plp, ip, mission) < 0) { emp_remque(qp); free(qp); continue; } pp->pln_flags |= PLN_LAUNCHED; - pp->pln_mobil -= pln_mobcost(dist, pp, flags); + pp->pln_mobil -= pln_mobcost(dist, pp, mission); putplane(pp->pln_uid, pp); pr("%s equipped\n", prplane(pp)); } } static int -pln_equip(struct plist *plp, struct ichrstr *ip, int flags, char mission) +pln_equip(struct plist *plp, struct ichrstr *ip, char mission) { struct plchrstr *pcp; struct plnstr *pp; @@ -642,71 +641,70 @@ pln_equip(struct plist *plp, struct ichrstr *ip, int flags, char mission) return -1; } item[I_PETROL] -= pcp->pl_fuel; - if ((flags & P_F) == 0) { - load = pln_load(pp); - itype = I_NONE; - needed = 0; - switch (mission) { - case 's': /* strategic bomb */ - case 'p': /* pinpoint bomb */ - if (nuk_on_plane(pp) < 0) { - itype = I_SHELL; - needed = load; - } - break; - case 't': /* transport */ - case 'd': /* drop */ - if (!(pcp->pl_flags & P_C) || !ip) - break; - itype = ip->i_uid; - needed = (load * 2) / ip->i_lbs; - break; - case 'm': /* mine */ - if ((pcp->pl_flags & P_MINE) == 0) - break; + load = pln_load(pp); + itype = I_NONE; + needed = 0; + switch (mission) { + case 's': /* strategic bomb */ + case 'p': /* pinpoint bomb */ + if (nuk_on_plane(pp) < 0) { itype = I_SHELL; - needed = (load * 2) / ip->i_lbs; + needed = load; + } + break; + case 't': /* transport */ + case 'd': /* drop */ + if (!(pcp->pl_flags & P_C) || !ip) break; - case 'a': /* paradrop */ - if ((pcp->pl_flags & (P_V | P_C)) == 0) - break; - itype = I_MILIT; - needed = load / ip->i_lbs; + itype = ip->i_uid; + needed = (load * 2) / ip->i_lbs; + break; + case 'm': /* mine */ + if ((pcp->pl_flags & P_MINE) == 0) break; - case 'r': /* reconnaissance */ + itype = I_SHELL; + needed = (load * 2) / ip->i_lbs; + break; + case 'a': /* paradrop */ + if ((pcp->pl_flags & (P_V | P_C)) == 0) break; - default: - CANT_REACH(); - } - if (itype != I_NONE && needed <= 0) { - pr("%s can't contribute to mission\n", prplane(pp)); - return -1; - } - if (itype == I_CIVIL && pp->pln_own != own) { - pr("You don't control those civilians!\n"); - return -1; - } - if (itype != I_NONE) { -#if 0 - /* Supply is broken somewhere, so don't use it for now */ - if (itype == I_SHELL && item[itype] < needed) - item[itype] += supply_commod(plp->plane.pln_own, - plp->plane.pln_x, - plp->plane.pln_y, - I_SHELL, needed); -#endif - abandon_needed = !!would_abandon(§, itype, needed, NULL); - if (item[itype] < needed + abandon_needed) { - pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp)); - return -1; - } - item[itype] -= needed; - } - if (itype == I_SHELL && (mission == 's' || mission == 'p')) - plp->bombs = needed; - else - plp->misc = needed; + itype = I_MILIT; + needed = load / ip->i_lbs; + break; + case 'r': /* reconnaissance */ + case 'e': /* escort */ + break; + default: + CANT_REACH(); } + if (itype != I_NONE && needed <= 0) { + pr("%s can't contribute to mission\n", prplane(pp)); + return -1; + } + if (itype == I_CIVIL && pp->pln_own != own) { + pr("You don't control those civilians!\n"); + return -1; + } + if (itype != I_NONE) { +#if 0 + /* Supply is broken somewhere, so don't use it for now */ + if (itype == I_SHELL && item[itype] < needed) + item[itype] += supply_commod(plp->plane.pln_own, + plp->plane.pln_x, + plp->plane.pln_y, + I_SHELL, needed); +#endif + abandon_needed = !!would_abandon(§, itype, needed, NULL); + if (item[itype] < needed + abandon_needed) { + pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp)); + return -1; + } + item[itype] -= needed; + } + if (itype == I_SHELL && (mission == 's' || mission == 'p')) + plp->bombs = needed; + else + plp->misc = needed; if (pp->pln_ship >= 0) { if (pp->pln_own != ship.shp_own) { wu(0, ship.shp_own, @@ -1034,13 +1032,13 @@ pln_identchance(struct plnstr *pp, int hardtarget, int type) } int -pln_mobcost(int dist, struct plnstr *pp, int flags) +pln_mobcost(int dist, struct plnstr *pp, char mission) { double cost; cost = 20.0 / (pp->pln_effic / 100.0); - if ((flags & P_F) || (flags & P_ESC)) - cost /= 2; + if (mission == 'e' || mission == 0) + cost /= 2; /* escort or intercept */ return ldround(cost * dist / pln_range_max(pp) + 5, 1); }