]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/plnsub.c
Improve launch diagnostic messages, switch off supply
[empserver] / src / lib / subs / plnsub.c
index 3bbe049f352926d284320f7d686ac0b76b7238f4..fd178aa99c2ae297d81f14aef2e6b0106d0f6f30 100644 (file)
@@ -54,7 +54,6 @@
 #include "ship.h"
 #include "xy.h"
 
-static int pln_equip(struct plist *, struct ichrstr *, char);
 static int fit_plane_on_ship(struct plnstr *, struct shpstr *);
 
 /*
@@ -275,7 +274,7 @@ pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
     amt = 0;
     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
        plp = (struct plist *)qp;
-       amt += plp->misc;
+       amt += plp->load;
     }
     if (cno < 0) {
        getsect(tx, ty, &sect);
@@ -340,7 +339,7 @@ pln_mine(struct emp_qelem *list, coord tx, coord ty)
     amt = 0;
     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
        plp = (struct plist *)qp;
-       amt += plp->misc;
+       amt += plp->load;
 
     }
     if (amt > 0) {
@@ -360,6 +359,7 @@ pln_mine(struct emp_qelem *list, coord tx, coord ty)
 /*
  * Has PP's type capabilities satisfying WANTFLAGS and NOWANTFLAGS?
  * A plane type is capable unless
+ * - it lacks all of the P_B, P_T in WANTFLAGS, or
  * - it lacks all of the P_F, P_ESC in WANTFLAGS, or
  * - it lacks all of the P_E, P_L, P_K in WANTFLAGS, or
  * - it lacks any of the other capabilities in WANTFLAGS, or
@@ -370,6 +370,12 @@ pln_capable(struct plnstr *pp, int wantflags, int nowantflags)
 {
     int flags = plchr[(int)pp->pln_type].pl_flags;
 
+    if (wantflags & (P_B | P_T)) {
+       if ((flags & wantflags & (P_B | P_T)) == 0)
+           return 0;
+       wantflags &= ~(P_B | P_T);
+    }
+
     if (wantflags & (P_F | P_ESC)) {
        if ((flags & wantflags & (P_F | P_ESC)) == 0)
            return 0;
@@ -573,8 +579,7 @@ pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
        plane.pln_mission = 0;
        putplane(plane.pln_uid, &plane);
        plp = malloc(sizeof(struct plist));
-       plp->misc = 0;
-       plp->bombs = 0;
+       plp->load = 0;
        plp->pcp = pcp;
        plp->plane = plane;
        emp_insque(&plp->queue, list);
@@ -607,7 +612,7 @@ pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip)
     }
 }
 
-static int
+int
 pln_equip(struct plist *plp, struct ichrstr *ip, char mission)
 {
     struct plchrstr *pcp;
@@ -643,49 +648,63 @@ pln_equip(struct plist *plp, struct ichrstr *ip, char mission)
     item[I_PETROL] -= pcp->pl_fuel;
     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 (nuk_on_plane(pp) >= 0)
+           break;
+       itype = I_SHELL;
        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;
+       load *= 2;
        break;
     case 'm':          /* mine */
        if ((pcp->pl_flags & P_MINE) == 0)
            break;
        itype = I_SHELL;
-       needed = (load * 2) / ip->i_lbs;
+       load *= 2;
+       break;
+    case 'd':          /* drop */
+       if (!(pcp->pl_flags & P_C) || CANT_HAPPEN(!ip))
+           break;
+       itype = ip->i_uid;
+       if (pcp->pl_flags & P_V)
+           load *= 2;
        break;
     case 'a':          /* paradrop */
-       if ((pcp->pl_flags & (P_V | P_C)) == 0)
+       if (!(pcp->pl_flags & P_P))
            break;
        itype = I_MILIT;
-       needed = load / ip->i_lbs;
+       if (pcp->pl_flags & P_V)
+           load *= 2;
        break;
     case 'r':          /* reconnaissance */
     case 'e':          /* escort */
+    case 'i':          /* missile interception */
+       if (CANT_HAPPEN(!(pcp->pl_flags & P_M)
+                       || !(pcp->pl_flags & (P_N | P_O))))
+           break;
+       if (load)
+           itype = I_SHELL;
        break;
     default:
        CANT_REACH();
+       load = 0;
     }
-    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) {
+       needed = load / ichr[itype].i_lbs;
+       if (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 0
        /* Supply is broken somewhere, so don't use it for now */
        if (itype == I_SHELL && item[itype] < needed)
@@ -700,11 +719,9 @@ pln_equip(struct plist *plp, struct ichrstr *ip, char mission)
            return -1;
        }
        item[itype] -= needed;
+       plp->load = 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,