diff --git a/include/plane.h b/include/plane.h index 7b1936a6..2133f362 100644 --- a/include/plane.h +++ b/include/plane.h @@ -73,7 +73,7 @@ struct plnstr { float pln_theta; /* position in orbital sine wave */ }; -#define PLN_LAUNCHED bit(0) /* A satellite that's in orbit */ +#define PLN_LAUNCHED bit(0) /* Flying (satellite: in orbit) */ #define PLN_SYNCHRONOUS bit(1) /* A satellite in geo-synchronous orbit */ #define PLN_AIRBURST bit(2) /* Airburst the nuke we're armed with */ @@ -160,9 +160,7 @@ extern void ac_combat_headers(natid, natid); extern void ac_airtoair(struct emp_qelem *, struct emp_qelem *); extern int ac_flak_dam(int, int, int); extern void ac_encounter(struct emp_qelem *, struct emp_qelem *, coord, - coord, char *, int, int, - struct emp_qelem *, struct emp_qelem *); -extern int ac_isflying(struct plnstr *, struct emp_qelem *); + coord, char *, int, int); extern void sam_intercept(struct emp_qelem *, struct emp_qelem *, natid, natid, coord, coord, int); diff --git a/include/prototypes.h b/include/prototypes.h index 5fa5cb37..1a127da7 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -402,8 +402,8 @@ extern void stop_service(void); extern int confirm(char *); extern int askyn(char *); /* bridgefall.c */ -extern void bridge_damaged(struct sctstr *, struct emp_qelem *); -extern void bridgefall(struct sctstr *, struct emp_qelem *); +extern void bridge_damaged(struct sctstr *); +extern void bridgefall(struct sctstr *); /* bsanct.c */ extern void bsanct(void); /* caploss.c */ @@ -468,7 +468,7 @@ extern int roundrange(double); extern int shipsatxy(coord, coord, int, int); extern int carriersatxy(coord, coord, natid); extern int unitsatxy(coord, coord, int, int); -extern int planesatxy(coord, coord, int, int, struct emp_qelem *); +extern int planesatxy(coord, coord, int, int); extern int asw_shipsatxy(coord, coord, int, int, struct plnstr *, struct shiplist **); extern int num_shipsatxy(coord, coord, int, int); @@ -484,7 +484,7 @@ extern int bmaps_intersect(natid, natid); 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, struct emp_qelem *); +extern int collateral_damage(coord, coord, int); extern int mission_pln_equip(struct plist *, struct ichrstr *, int, char); extern int ground_interdict(coord, coord, natid, char *); extern int unit_interdict(coord, coord, natid, char *, int, int); @@ -559,7 +559,6 @@ extern int pln_arm(struct emp_qelem *, int, char, struct ichrstr *, extern int pln_mobcost(int, struct plnstr *, int); extern void pln_put(struct emp_qelem *); extern void pln_put1(struct plist *); -extern void pln_removedupes(struct emp_qelem *, struct emp_qelem *); extern void take_plane_off_ship(struct plnstr *, struct shpstr *); extern void take_plane_off_land(struct plnstr *, struct lndstr *); extern void plane_sweep(struct emp_qelem *, coord, coord); @@ -630,8 +629,8 @@ extern int sct_prewrite(int, void *); extern void item_prewrite(short *); extern int issector(char *); /* sectdamage.c */ -extern int sect_damage(struct sctstr *, int, struct emp_qelem *); -extern int sectdamage(struct sctstr *, int, struct emp_qelem *); +extern int sect_damage(struct sctstr *, int); +extern int sectdamage(struct sctstr *, int); /* ship.c */ extern char *prship(struct shpstr *); extern int shp_postread(int, void *); diff --git a/src/lib/commands/bomb.c b/src/lib/commands/bomb.c index f475d47d..b645a138 100644 --- a/src/lib/commands/bomb.c +++ b/src/lib/commands/bomb.c @@ -147,8 +147,8 @@ bomb(void) } mission_flags = pln_arm(&esc_list, 2 * ap_to_target, mission, ip, P_F | P_ESC, mission_flags); - ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags, - 0, 0, 0); + ac_encounter(&bomb_list, &esc_list, ax, ay, + flightpath, mission_flags, 0); if (QEMPTY(&bomb_list)) { pr("No planes got through fighter defenses\n"); } else if (target.sct_type == SCT_SANCT) { @@ -218,7 +218,7 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target) } else { nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB); } - nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list); + nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0); nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0); retry: p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ", @@ -369,9 +369,9 @@ eff_bomb(struct emp_qelem *list, struct sctstr *target) "%s bombing raid did %d%% damage in %s\n", cname(player->cnum), oldeff - target->sct_effic, xyas(target->sct_x, target->sct_y, target->sct_own)); - bridge_damaged(target, list); + bridge_damaged(target); putsect(§); - collateral_damage(target->sct_x, target->sct_y, dam, list); + collateral_damage(target->sct_x, target->sct_y, dam); } static void @@ -447,7 +447,7 @@ comm_bomb(struct emp_qelem *list, struct sctstr *target) cname(player->cnum), b, ip->i_name, xyas(target->sct_x, target->sct_y, target->sct_own)); putsect(§); - collateral_damage(target->sct_x, target->sct_y, dam, list); + collateral_damage(target->sct_x, target->sct_y, dam); } static void @@ -559,7 +559,7 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target) /* Bombs that miss have to land somewhere! */ dam = pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p', &nukedam, 0); - collateral_damage(target->sct_x, target->sct_y, dam, list); + collateral_damage(target->sct_x, target->sct_y, dam); dam = 0; } if (dam <= 0) /* dam == 0 if only nukes were delivered */ @@ -586,7 +586,7 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target) prship(&ship), xyas(target->sct_x, target->sct_y, player->cnum)); } - collateral_damage(target->sct_x, target->sct_y, dam / 2, list); + collateral_damage(target->sct_x, target->sct_y, dam / 2); next: ; } @@ -615,7 +615,7 @@ plane_bomb(struct emp_qelem *list, struct sctstr *target) plp = (struct plist *)qp; if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T))) continue; - nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list); + nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0); if (nplanes == 0) { pr("%s could not find any planes!\n", prplane(&plp->plane)); continue; @@ -632,7 +632,7 @@ plane_bomb(struct emp_qelem *list, struct sctstr *target) continue; } if (*q == '?') { - planesatxy(target->sct_x, target->sct_y, 0, 0, list); + planesatxy(target->sct_x, target->sct_y, 0, 0); continue; } if (*q == 'd') @@ -643,8 +643,7 @@ plane_bomb(struct emp_qelem *list, struct sctstr *target) if (getplane(n, &plane) && plane.pln_x == target->sct_x && plane.pln_y == target->sct_y && - ((plane.pln_flags & PLN_LAUNCHED) == 0) && - (!ac_isflying(&plane, list))) + !(plane.pln_flags & PLN_LAUNCHED)) planeno = n; else pr("Plane #%d not spotted\n", n); @@ -667,7 +666,7 @@ plane_bomb(struct emp_qelem *list, struct sctstr *target) /* Bombs that miss have to land somewhere! */ dam = pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p', &nukedam, 0); - collateral_damage(target->sct_x, target->sct_y, dam, list); + collateral_damage(target->sct_x, target->sct_y, dam); dam = 0; } if (dam <= 0) /* dam == 0 if only nukes were delivered */ @@ -694,7 +693,7 @@ plane_bomb(struct emp_qelem *list, struct sctstr *target) cname(player->cnum), dam, prplane(&plane), xyas(target->sct_x, target->sct_y, own)); putplane(plane.pln_uid, &plane); - collateral_damage(target->sct_x, target->sct_y, dam, list); + collateral_damage(target->sct_x, target->sct_y, dam); next: ; } @@ -781,7 +780,7 @@ land_bomb(struct emp_qelem *list, struct sctstr *target) /* Bombs that miss have to land somewhere! */ dam = pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p', &nukedam, 0); - collateral_damage(target->sct_x, target->sct_y, dam, list); + collateral_damage(target->sct_x, target->sct_y, dam); dam = 0; } if (dam <= 0) /* dam == 0 if only nukes were delivered */ @@ -798,7 +797,7 @@ land_bomb(struct emp_qelem *list, struct sctstr *target) retreat_land(&land, 'b'); nreport(player->cnum, N_UNIT_BOMB, own, 1); putland(land.lnd_uid, &land); - collateral_damage(target->sct_x, target->sct_y, dam, list); + collateral_damage(target->sct_x, target->sct_y, dam); next: ; } @@ -830,7 +829,7 @@ strat_bomb(struct emp_qelem *list, struct sctstr *target) cname(player->cnum), PERCENT_DAMAGE(dam), xyas(target->sct_x, target->sct_y, target->sct_own)); - sectdamage(target, dam, list); + sectdamage(target, dam); pr("did %d damage in %s\n", PERCENT_DAMAGE(dam), xyas(target->sct_x, target->sct_y, player->cnum)); diff --git a/src/lib/commands/desi.c b/src/lib/commands/desi.c index 54be0688..07f33ae0 100644 --- a/src/lib/commands/desi.c +++ b/src/lib/commands/desi.c @@ -132,7 +132,7 @@ desi(void) if (opt_EASY_BRIDGES == 0) { /* may cause a bridge fall */ if (n != SCT_BHEAD) continue; - bridgefall(§, 0); + bridgefall(§); } } if (changed) diff --git a/src/lib/commands/drop.c b/src/lib/commands/drop.c index 4b32a14e..fbfffcfe 100644 --- a/src/lib/commands/drop.c +++ b/src/lib/commands/drop.c @@ -124,8 +124,8 @@ drop(void) } mission_flags = pln_arm(&esc_list, 2 * ap_to_target, 'd', ip, P_ESC | P_F, mission_flags); - ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags, - 0, 0, 0); + ac_encounter(&bomb_list, &esc_list, ax, ay, + flightpath, mission_flags, 0); if (QEMPTY(&bomb_list)) { pr("No planes got through fighter defenses\n"); } else { diff --git a/src/lib/commands/fly.c b/src/lib/commands/fly.c index 598fef08..ed55fbca 100644 --- a/src/lib/commands/fly.c +++ b/src/lib/commands/fly.c @@ -136,8 +136,8 @@ fly(void) } mission_flags = pln_arm(&esc_list, ap_to_target, 't', ip, P_ESC | P_F, mission_flags); - ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags, - 0, 0, 0); + ac_encounter(&bomb_list, &esc_list, ax, ay, + flightpath, mission_flags, 0); if (QEMPTY(&bomb_list)) { pr("No planes got through fighter defenses\n"); } else { diff --git a/src/lib/commands/laun.c b/src/lib/commands/laun.c index 39131968..996188b8 100644 --- a/src/lib/commands/laun.c +++ b/src/lib/commands/laun.c @@ -321,7 +321,7 @@ launch_missile(struct plnstr *pp, int sublaunch) cname(player->cnum), dam, xyas(sx, sy, sect.sct_own)); } - sectdamage(§, dam, 0); + sectdamage(§, dam); putsect(§); } } /* end PINPOINTMISSILE conditional */ @@ -414,6 +414,7 @@ launch_sat(struct plnstr *pp, int sublaunch) } pp->pln_x = sx; pp->pln_y = sy; + CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED); pp->pln_flags |= PLN_LAUNCHED; pp->pln_mobil = pp->pln_mobil > dist ? pp->pln_mobil - dist : 0; putplane(pp->pln_uid, pp); diff --git a/src/lib/commands/mfir.c b/src/lib/commands/mfir.c index 58e2cb41..4d3fd893 100644 --- a/src/lib/commands/mfir.c +++ b/src/lib/commands/mfir.c @@ -467,7 +467,7 @@ multifire(void) pr("Shells hit sector %s for %d damage.\n", xyas(x, y, player->cnum), dam); if (target != targ_bogus) - sectdamage(&vsect, dam, 0); + sectdamage(&vsect, dam); break; case targ_ship: nreport(player->cnum, N_SHP_SHELL, vict, 1); @@ -600,7 +600,7 @@ do_defdam(struct emp_qelem *list, double odds) vict = fp->victim; pr("Return fire hit sector %s for %d damage.\n", xyas(fp->x, fp->y, player->cnum), dam); - sectdamage(§, dam, 0); + sectdamage(§, dam); putsect(§); if (vict) wu(0, vict, "Return fire hit sector %s for %d damage.\n", diff --git a/src/lib/commands/para.c b/src/lib/commands/para.c index e11c20e0..9c976b2b 100644 --- a/src/lib/commands/para.c +++ b/src/lib/commands/para.c @@ -105,8 +105,8 @@ para(void) } mission_flags = pln_arm(&esc_list, 2 * ap_to_target, 'a', &ichr[I_MILIT], P_ESC | P_F, mission_flags); - ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags, - 0, 0, 0); + ac_encounter(&bomb_list, &esc_list, ax, ay, + flightpath, mission_flags, 0); if (QEMPTY(&bomb_list)) { pr("No planes got through fighter defenses\n"); } else { diff --git a/src/lib/commands/reco.c b/src/lib/commands/reco.c index ebcf597f..fcd4d135 100644 --- a/src/lib/commands/reco.c +++ b/src/lib/commands/reco.c @@ -118,8 +118,8 @@ reco(void) if (*player->argp[0] == 's') mission_flags |= PM_S; - ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags, - 0, 0, 0); + ac_encounter(&bomb_list, &esc_list, ax, ay, + flightpath, mission_flags, 0); if (QEMPTY(&bomb_list)) { pr("No planes got through fighter defenses\n"); } else { diff --git a/src/lib/commands/sabo.c b/src/lib/commands/sabo.c index c12c6ad9..7911dfc8 100644 --- a/src/lib/commands/sabo.c +++ b/src/lib/commands/sabo.c @@ -103,7 +103,7 @@ sabo(void) land.lnd_own = 0; putland(land.lnd_uid, &land); - sectdamage(§, dam, 0); + sectdamage(§, dam); putsect(§); land.lnd_own = player->cnum; diff --git a/src/lib/common/ef_verify.c b/src/lib/common/ef_verify.c index fac43103..fb677145 100644 --- a/src/lib/common/ef_verify.c +++ b/src/lib/common/ef_verify.c @@ -40,6 +40,7 @@ #include "file.h" #include "misc.h" #include "nsc.h" +#include "plane.h" #include "product.h" static void verify_fail(int, int, struct castr *, int, char *, ...) @@ -163,6 +164,26 @@ verify_row(int type, int row) return ret_val; } +static void +pln_zap_transient_flags(void) +{ + int i; + struct plnstr *pp; + + /* laziness: assumes plane file is EFF_MEM */ + for (i = 0; (pp = getplanep(i)) != NULL; i++) { + if (pp->pln_flags & PLN_LAUNCHED + && (plchr[pp->pln_type].pl_flags & (P_M | P_O)) != P_O) { + pp->pln_flags &= ~PLN_LAUNCHED; + verify_fail(EF_PLANE, i, NULL, 0, "stuck in the air (patched)"); + /* + * Can't putplane() here, because pln_prewrite() crashes + * without a valid player. + */ + } + } +} + int ef_verify() { @@ -188,5 +209,6 @@ ef_verify() } } + pln_zap_transient_flags(); return retval; } diff --git a/src/lib/subs/aircombat.c b/src/lib/subs/aircombat.c index 9c833d9b..3b87878f 100644 --- a/src/lib/subs/aircombat.c +++ b/src/lib/subs/aircombat.c @@ -64,16 +64,13 @@ static void ac_doflak(struct emp_qelem *, struct sctstr *); static void ac_landflak(struct emp_qelem *, coord, coord); static void ac_shipflak(struct emp_qelem *, coord, coord); static void ac_fireflak(struct emp_qelem *, natid, int); -static void getilist(struct emp_qelem *, natid, - struct emp_qelem *, struct emp_qelem *, - struct emp_qelem *, struct emp_qelem *); +static void getilist(struct emp_qelem *, natid); static int do_evade(struct emp_qelem *, struct emp_qelem *); void ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, coord x, coord y, char *path, int mission_flags, - int no_air_defense, struct emp_qelem *obomb, - struct emp_qelem *oesc) + int no_air_defense) { int val, non_missiles; int rel; @@ -135,7 +132,6 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, } } - pln_removedupes(bomb_list, esc_list); while ((dir = mypath[myp++]) && !QEMPTY(bomb_list)) { if ((val = diridx(dir)) == DIR_STOP) break; @@ -247,8 +243,7 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, continue; if (unfriendly[sect.sct_own] && !gotilist[sect.sct_own]) { - getilist(&ilist[sect.sct_own], sect.sct_own, - bomb_list, esc_list, obomb, oesc); + getilist(&ilist[sect.sct_own], sect.sct_own); gotilist[sect.sct_own]++; } if (rel > HOSTILE) @@ -307,8 +302,7 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, if (unfriendly[cn]) { /* They are unfriendly too */ if (!gotilist[cn]) { - getilist(&ilist[cn], cn, bomb_list, esc_list, obomb, - oesc); + getilist(&ilist[cn], cn); gotilist[cn]++; } PR(plane_owner, "Flying over %s ships in %s\n", @@ -336,8 +330,7 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, if (unfriendly[cn]) { /* They are unfriendly too */ if (!gotilist[cn]) { - getilist(&ilist[cn], cn, bomb_list, esc_list, obomb, - oesc); + getilist(&ilist[cn], cn); gotilist[cn]++; } PR(plane_owner, "Flying over %s land units in %s\n", @@ -416,6 +409,8 @@ sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list, free(dqp); continue; } + CANT_HAPPEN(dplp->plane.pln_flags & PLN_LAUNCHED); + dplp->plane.pln_flags |= PLN_LAUNCHED; if (first) { first = 0; PR(plane_owner, "%s launches SAMs!\n", cname(def_own)); @@ -481,7 +476,8 @@ ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, dist = mapdist(x, y, pp->pln_x, pp->pln_y) * 2; if (pp->pln_range < dist) continue; - if (mission_pln_equip(plp, 0, P_F, 0) < 0) { + if (CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED) + || mission_pln_equip(plp, 0, P_F, 0) < 0) { emp_remque(qp); free(qp); continue; @@ -489,6 +485,7 @@ ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, /* got one; delete from def_list, add to int_list */ emp_remque(qp); emp_insque(qp, &int_list); + pp->pln_flags |= PLN_LAUNCHED; pp->pln_mobil -= pln_mobcost(dist, pp, P_F); putplane(pp->pln_uid, pp); icount++; @@ -983,36 +980,11 @@ ac_flak_dam(int guns, int def, int pl_flags) return dam; } -/* - * See if this plane is flying in this list - */ -int -ac_isflying(struct plnstr *plane, struct emp_qelem *list) -{ - struct emp_qelem *qp; - struct emp_qelem *next; - struct plnstr *pp; - struct plist *plp; - - if (!list) - return 0; - for (qp = list->q_forw; qp != list; qp = next) { - next = qp->q_forw; - plp = (struct plist *)qp; - pp = &plp->plane; - if (plane->pln_uid == pp->pln_uid) - return 1; - } - return 0; -} - - /* * Get a list of planes available for interception duties. */ static void -getilist(struct emp_qelem *list, natid own, struct emp_qelem *a, - struct emp_qelem *b, struct emp_qelem *c, struct emp_qelem *d) +getilist(struct emp_qelem *list, natid own) { struct plchrstr *pcp; struct plnstr plane; @@ -1027,6 +999,8 @@ getilist(struct emp_qelem *list, natid own, struct emp_qelem *a, pcp = &plchr[(int)plane.pln_type]; if ((pcp->pl_flags & P_F) == 0) continue; + if (plane.pln_flags & PLN_LAUNCHED) + continue; if (plane.pln_mission != 0) continue; if (plane.pln_mobil <= 0) @@ -1035,16 +1009,6 @@ getilist(struct emp_qelem *list, natid own, struct emp_qelem *a, continue; if (!pln_airbase_ok(&plane, 0, 0)) continue; - /* Finally, is it in the list of planes already in - flight? */ - if (ac_isflying(&plane, a)) - continue; - if (ac_isflying(&plane, b)) - continue; - if (ac_isflying(&plane, c)) - continue; - if (ac_isflying(&plane, d)) - continue; /* got one! */ ip = malloc(sizeof(*ip)); ip->bombs = 0; diff --git a/src/lib/subs/attsub.c b/src/lib/subs/attsub.c index 4c9decae..5183b2a5 100644 --- a/src/lib/subs/attsub.c +++ b/src/lib/subs/attsub.c @@ -650,7 +650,7 @@ att_approach(struct combat *off, struct combat *def) } if (off->type == EF_SECTOR) { getsect(off->x, off->y, §); - sectdamage(§, dam, 0); + sectdamage(§, dam); putsect(§); pr("Enemy fleet at %s does %d damage to %s\n", xyas(def->x, def->y, player->cnum), dam, prcom(0, off)); diff --git a/src/lib/subs/bridgefall.c b/src/lib/subs/bridgefall.c index edf0e7f7..f407f32f 100644 --- a/src/lib/subs/bridgefall.c +++ b/src/lib/subs/bridgefall.c @@ -49,7 +49,7 @@ #include "sect.h" #include "xy.h" -static void knockdown(struct sctstr *, struct emp_qelem *); +static void knockdown(struct sctstr *); /* * Check bridges at and around SP after damage to SP. @@ -60,7 +60,7 @@ static void knockdown(struct sctstr *, struct emp_qelem *); * left to the caller. */ void -bridge_damaged(struct sctstr *sp, struct emp_qelem *list) +bridge_damaged(struct sctstr *sp) { int des; @@ -69,13 +69,13 @@ bridge_damaged(struct sctstr *sp, struct emp_qelem *list) des = sp->sct_type; if (des == SCT_BSPAN || des == SCT_BTOWER) - knockdown(sp, list); + knockdown(sp); if ((des == SCT_BHEAD || des == SCT_BTOWER) && !opt_EASY_BRIDGES) - bridgefall(sp, list); + bridgefall(sp); } void -bridgefall(struct sctstr *sp, struct emp_qelem *list) +bridgefall(struct sctstr *sp) { int i; int j; @@ -112,7 +112,7 @@ bridgefall(struct sctstr *sp, struct emp_qelem *list) } } if (j > 6) { - knockdown(§, list); + knockdown(§); putsect(§); } } @@ -121,7 +121,7 @@ bridgefall(struct sctstr *sp, struct emp_qelem *list) /* Knock down a bridge span. Note that this does NOT write the * sector out to the database, it's up to the caller to do that. */ static void -knockdown(struct sctstr *sp, struct emp_qelem *list) +knockdown(struct sctstr *sp) { struct lndstr land; struct plnstr plane; @@ -165,9 +165,6 @@ knockdown(struct sctstr *sp, struct emp_qelem *list) continue; if (plane.pln_ship >= 0) continue; - /* Is this plane flying in this list? */ - if (ac_isflying(&plane, list)) - continue; np = getnatp(plane.pln_own); if (np->nat_flags & NF_BEEP) mpr(plane.pln_own, "\07"); diff --git a/src/lib/subs/detonate.c b/src/lib/subs/detonate.c index e027eb4a..f92ac6a1 100644 --- a/src/lib/subs/detonate.c +++ b/src/lib/subs/detonate.c @@ -105,7 +105,7 @@ detonate(struct nukstr *np, coord x, coord y, int airburst) } if (opt_FALLOUT) fallout = sect.sct_fallout; - sect_damage(§, damage, 0); + sect_damage(§, damage); if (sect.sct_x == x && sect.sct_y == y) retval = damage; if (opt_FALLOUT) { diff --git a/src/lib/subs/list.c b/src/lib/subs/list.c index 96ce5d2d..3c9574c1 100644 --- a/src/lib/subs/list.c +++ b/src/lib/subs/list.c @@ -162,8 +162,7 @@ unitsatxy(coord x, coord y, int wantflags, int nowantflags) } int -planesatxy(coord x, coord y, int wantflags, int nowantflags, - struct emp_qelem *list) +planesatxy(coord x, coord y, int wantflags, int nowantflags) { int first; int planes; @@ -179,9 +178,6 @@ planesatxy(coord x, coord y, int wantflags, int nowantflags, continue; if (plane.pln_flags & PLN_LAUNCHED) continue; - /* Is this plane one of the ones flying somewhere? */ - if (ac_isflying(&plane, list)) - continue; plp = &plchr[(int)plane.pln_type]; if (first) { pr(" # owner eff type\n"); diff --git a/src/lib/subs/lndsub.c b/src/lib/subs/lndsub.c index 1029adee..395ffcf2 100644 --- a/src/lib/subs/lndsub.c +++ b/src/lib/subs/lndsub.c @@ -799,7 +799,7 @@ lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy, MI_INTERDICT); if (dam) { mpr(victim, "missile interdiction mission does %d damage!\n", dam); - collateral_damage(newx, newy, dam, 0); + collateral_damage(newx, newy, dam); } qp = msl_list.q_forw; while (qp != msl_list.q_forw) { diff --git a/src/lib/subs/mission.c b/src/lib/subs/mission.c index c8ee9cfd..580cdea9 100644 --- a/src/lib/subs/mission.c +++ b/src/lib/subs/mission.c @@ -108,13 +108,13 @@ ground_interdict(coord x, coord y, natid victim, char *s) cname(cn), newdam); } if (dam) { - collateral_damage(x, y, dam, 0); + collateral_damage(x, y, dam); } return dam; } int -collateral_damage(coord x, coord y, int dam, struct emp_qelem *list) +collateral_damage(coord x, coord y, int dam) { int coll; struct sctstr sect; @@ -129,7 +129,7 @@ collateral_damage(coord x, coord y, int dam, struct emp_qelem *list) return 0; mpr(sect.sct_own, "%s takes %d%% collateral damage\n", xyas(x, y, sect.sct_own), coll); - sectdamage(§, coll, list); + sectdamage(§, coll); putsect(§); return coll; } @@ -201,7 +201,7 @@ unit_interdict(coord x, coord y, natid victim, char *s, int hardtarget, } } if (dam) { - collateral_damage(x, y, dam, 0); + collateral_damage(x, y, dam); } return dam; } @@ -668,7 +668,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list, xyas(air->x, air->y, air->own)); } - ac_encounter(&b, &e, air->x, air->y, pp, mission_flags, 0, 0, 0); + ac_encounter(&b, &e, air->x, air->y, pp, mission_flags, 0); if (!QEMPTY(&b)) air_dam += @@ -930,17 +930,20 @@ mission_pln_arm(struct emp_qelem *list, coord x, coord y, int dist, struct emp_qelem *qp; struct emp_qelem *next; struct plist *plp; + struct plnstr *pp; for (qp = list->q_forw; qp != list; qp = next) { next = qp->q_forw; plp = (struct plist *)qp; + pp = &plp->plane; - if (plp->plane.pln_x != x) + if (pp->pln_x != x) continue; - if (plp->plane.pln_y != y) + if (pp->pln_y != y) continue; - if (mission_pln_equip(plp, ip, flags, mission) < 0) { + if (CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED) + || mission_pln_equip(plp, ip, flags, mission) < 0) { emp_remque(qp); free(qp); continue; @@ -966,13 +969,9 @@ mission_pln_arm(struct emp_qelem *list, coord x, coord y, int dist, mission_flags &= ~P_MINE; } - /* - * Mob costs for missions are 1/2 normal - * Not anymore. :) - */ -/* plp->plane.pln_mobil -= pln_mobcost(dist,&plp->plane,flags)/2;*/ - plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags); - + CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED); + pp->pln_flags |= PLN_LAUNCHED; + pp->pln_mobil -= pln_mobcost(dist, pp, flags); } return mission_flags; } @@ -1217,7 +1216,7 @@ air_damage(struct emp_qelem *bombers, coord x, coord y, int mission, } /* Now, even though we missed, the bombs land somewhere. */ - collateral_damage(x, y, newdam, bombers); + collateral_damage(x, y, newdam); } /* use up missiles */ @@ -1396,7 +1395,7 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, /* Now, fly the planes to the sector */ emp_initque(&empty); ac_encounter(&i, &empty, air->x, air->y, - path, mission_flags, 1, bomb_list, esc_list); + path, mission_flags, 1); /* If none made it, continue */ if (QEMPTY(&i)) diff --git a/src/lib/subs/mslsub.c b/src/lib/subs/mslsub.c index 3f4bb5e4..4b1a0cdd 100644 --- a/src/lib/subs/mslsub.c +++ b/src/lib/subs/mslsub.c @@ -116,7 +116,7 @@ msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item, pr("Explosion damages %s %d%%", xyas(pp->pln_x, pp->pln_y, pp->pln_own), dam); getsect(pp->pln_x, pp->pln_y, §); - sectdamage(§, dam, 0); + sectdamage(§, dam); putsect(§); } } @@ -406,7 +406,7 @@ msl_launch_mindam(struct emp_qelem *list, coord x, coord y, int hardtarget, } else { /* Missiles that miss have to hit somewhere! */ newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 0); - collateral_damage(x, y, newdam, 0); + collateral_damage(x, y, newdam); } plp->plane.pln_effic = 0; putplane(plp->plane.pln_uid, &plp->plane); diff --git a/src/lib/subs/plnsub.c b/src/lib/subs/plnsub.c index d54643fc..1c5c8ad5 100644 --- a/src/lib/subs/plnsub.c +++ b/src/lib/subs/plnsub.c @@ -553,11 +553,14 @@ pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip, struct emp_qelem *qp; struct emp_qelem *next; struct plist *plp; + struct plnstr *pp; for (qp = list->q_forw; qp != list; qp = next) { next = qp->q_forw; plp = (struct plist *)qp; - if (pln_equip(plp, ip, flags, mission) < 0) { + pp = &plp->plane; + if ((pp->pln_flags & PLN_LAUNCHED) + || pln_equip(plp, ip, flags, mission) < 0) { emp_remque(qp); free(qp); continue; @@ -584,8 +587,11 @@ pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip, mission_flags &= ~P_MINE; /* FIXME no effect */ } - plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags); - pr("%s equipped\n", prplane(&plp->plane)); + CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED); + pp->pln_flags |= PLN_LAUNCHED; + pp->pln_mobil -= pln_mobcost(dist, pp, flags); + putplane(pp->pln_uid, pp); + pr("%s equipped\n", prplane(pp)); } return mission_flags; } @@ -742,8 +748,16 @@ pln_put1(struct plist *plp) struct sctstr sect; pp = &plp->plane; - if (!pp->pln_own) { - /* crashed */ + + if (CANT_HAPPEN((pp->pln_flags & PLN_LAUNCHED) + && (plchr[pp->pln_type].pl_flags & P_M) + && pp->pln_effic >= PLANE_MINEFF)) + pp->pln_effic = 0; /* bug: missile launched but not used up */ + + if (!(pp->pln_flags & PLN_LAUNCHED)) + ; /* never took off */ + else if (pp->pln_effic < PLANE_MINEFF) { + /* destroyed */ if (pp->pln_ship >= 0) { getship(pp->pln_ship, &ship); take_plane_off_ship(pp, &ship); @@ -775,42 +789,12 @@ pln_put1(struct plist *plp) pp->pln_effic = 0; } } + pp->pln_flags &= ~PLN_LAUNCHED; putplane(pp->pln_uid, pp); emp_remque(&plp->queue); free(plp); } -void -pln_removedupes(struct emp_qelem *bomb_list, struct emp_qelem *esc_list) -{ - struct emp_qelem *bomb; - struct emp_qelem *esc; - struct plist *bombp; - struct plist *escp; - - if (QEMPTY(bomb_list) || QEMPTY(esc_list)) - return; - bomb = bomb_list->q_forw; - while (bomb != bomb_list) { - if (QEMPTY(esc_list)) { - bomb = bomb_list; - continue; - } - esc = esc_list->q_forw; - bombp = (struct plist *)bomb; - while (esc != esc_list) { - escp = (struct plist *)esc; - if (escp->plane.pln_uid == bombp->plane.pln_uid) { - emp_remque(esc); - free(esc); - esc = esc_list; - } else - esc = esc->q_forw; - } - bomb = bomb->q_forw; - } -} - /* * Fit a plane of PP's type on ship SP. * Adjust SP's plane counters. diff --git a/src/lib/subs/sect.c b/src/lib/subs/sect.c index 1b90c03c..541b9b9b 100644 --- a/src/lib/subs/sect.c +++ b/src/lib/subs/sect.c @@ -68,7 +68,7 @@ sct_prewrite(int id, void *ptr) struct sctstr *sp = ptr; struct sctstr sect; - bridge_damaged(sp, NULL); + bridge_damaged(sp); checksect(sp); getsect(sp->sct_x, sp->sct_y, §); return 1; diff --git a/src/lib/subs/sectdamage.c b/src/lib/subs/sectdamage.c index a14dad48..920f45aa 100644 --- a/src/lib/subs/sectdamage.c +++ b/src/lib/subs/sectdamage.c @@ -49,7 +49,7 @@ #include "xy.h" int -sect_damage(struct sctstr *sp, int dam, struct emp_qelem *list) +sect_damage(struct sctstr *sp, int dam) { int eff; @@ -69,13 +69,13 @@ sect_damage(struct sctstr *sp, int dam, struct emp_qelem *list) if (sp->sct_mobil > 0) sp->sct_mobil = damage(sp->sct_mobil, dam); item_damage(dam, sp->sct_item); - bridge_damaged(sp, list); + bridge_damaged(sp); putsect(sp); return eff; } int -sectdamage(struct sctstr *sp, int dam, struct emp_qelem *list) +sectdamage(struct sctstr *sp, int dam) { struct nstr_item ni; struct lndstr land; @@ -87,7 +87,7 @@ sectdamage(struct sctstr *sp, int dam, struct emp_qelem *list) /* the damage accordingly. Makes forts a pain */ dam = ldround(dam / sector_strength(sp), 1); - eff = sect_damage(sp, PERCENT_DAMAGE(dam), list); + eff = sect_damage(sp, PERCENT_DAMAGE(dam)); /* Damage all the land units in the sector */ /* Units don't take full damage */ @@ -114,9 +114,6 @@ sectdamage(struct sctstr *sp, int dam, struct emp_qelem *list) continue; if (plane.pln_ship >= 0) continue; - /* Is this plane flying in this list? */ - if (ac_isflying(&plane, list)) - continue; planedamage(&plane, dam); putplane(plane.pln_uid, &plane); } diff --git a/src/lib/update/revolt.c b/src/lib/update/revolt.c index 8684eaa2..e9ef4e46 100644 --- a/src/lib/update/revolt.c +++ b/src/lib/update/revolt.c @@ -271,7 +271,7 @@ guerrilla(struct sctstr *sp) wu(0, sp->sct_own, "Production %s disrupted by terrorists in %s\n", effadv(n), ownxy(sp)); - sect_damage(sp, n / 10, 0); + sect_damage(sp, n / 10); /*logerror("(#%d) che blew up %s for %d", sp->sct_own, */ /*ownxy(sp), n); */ recruit++;