]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/mission.c
Consistently use int for mission type parameters
[empserver] / src / lib / subs / mission.c
index b63f01af2a594409f70cf5905d25550abd7a9025..cef5c47b854f0d118dfeb19f259032fe46985110 100644 (file)
@@ -389,7 +389,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
     struct plchrstr *pcp;
     int dam = 0, dam2;
     natid plane_owner = 0;
-    int md, range, air_dam = 0;
+    int md, range, air_dam, sublaunch;
     double hitchance, vrange;
     int targeting_ships = *s == 's'; /* "subs" or "ships" FIXME gross! */
 
@@ -547,19 +547,37 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
            break;
        }
     }
-    if (!QEMPTY(&missiles)) {
-       /* I arbitrarily chose 100 mindam -KHS */
-       dam +=
-           msl_launch_mindam(&missiles, x, y, hardtarget, EF_SECTOR, 100,
-                             "sector", victim, mission);
-       qp = missiles.q_forw;
-       while (qp != (&missiles)) {
-           newqp = qp->q_forw;
-           emp_remque(qp);
-           free(qp);
-           qp = newqp;
+
+    /*
+     * Missiles, except for interdiction of ships or land units,
+     * because that happens elsewhere, in shp_missile_interdiction()
+     * and lnd_missile_interdiction().
+     */
+    air_dam = 0;
+    for (qp = missiles.q_back; qp != &missiles; qp = newqp) {
+       newqp = qp->q_back;
+       plp = (struct plist *)qp;
+
+       if (air_dam < 100
+           && !CANT_HAPPEN(hardtarget != SECT_HARDTARGET
+                           || (plp->pcp->pl_flags & P_MAR))
+           && mission_pln_equip(plp, NULL, 'p') >= 0) {
+           if (msl_launch(&plp->plane, EF_SECTOR, "sector", x, y, victim,
+                          &sublaunch) < 0)
+               goto use_up_msl;
+           if (!msl_hit(&plp->plane, SECT_HARDTARGET, EF_SECTOR,
+                       N_SCT_MISS, N_SCT_SMISS, sublaunch, victim))
+               CANT_REACH();
+           dam2 = pln_damage(&plp->plane, 'p', 1);
+           air_dam += dam2;
+       use_up_msl:
+           plp->plane.pln_effic = 0;
+           putplane(plp->plane.pln_uid, &plp->plane);
        }
+       emp_remque(qp);
+       free(qp);
     }
+    dam += air_dam;
 
     if (QEMPTY(&bombers)) {
        qp = list->q_forw;
@@ -593,6 +611,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
            add_airport(&airp, plp->plane.pln_x, plp->plane.pln_y);
     }
 
+    air_dam = 0;
     for (qp = airp.q_forw; qp != (&airp); qp = qp->q_forw) {
        struct airport *air;
        char buf[512];
@@ -712,7 +731,7 @@ cando(int mission, int type)
 }
 
 char *
-mission_name(short mission)
+mission_name(int mission)
 {
     switch (mission) {
     case MI_INTERDICT:
@@ -900,44 +919,29 @@ mission_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;
-       }
-       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 / ichr[I_MILIT].i_lbs;
+       itype = I_SHELL;
        break;
     case 'i':          /* missile interception */
-       if (load) {
+       if (load)
            itype = I_SHELL;
-           needed = load;
-       }
        break;
-    case 'r':          /* reconnaissance */
     case 'e':          /* escort */
-    case 0:                    /* plane interception */
+    case 0:            /* plane interception */
+       load = 0;
        break;
     default:
        CANT_REACH();
+       load = 0;
     }
-    if (itype != I_NONE && needed <= 0)
-       return -1;
+
     if (itype != I_NONE) {
+       needed = load / ichr[itype].i_lbs;
+       if (needed <= 0)
+           return -1;
+       if (CANT_HAPPEN(nuk_on_plane(pp) >= 0))
+           return -1;
        if (itype == I_SHELL && item[itype] < needed) {
            if (pp->pln_ship >= 0)
                shp_supply(&ship, I_SHELL, needed);
@@ -949,11 +953,9 @@ mission_pln_equip(struct plist *plp, struct ichrstr *ip, char mission)
        if (item[itype] < needed)
            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)
        putship(ship.shp_uid, &ship);
     else if (pp->pln_land >= 0)
@@ -1031,7 +1033,6 @@ air_damage(struct emp_qelem *bombers, coord x, coord y, int mission,
     struct plnstr *pp;
     int newdam, dam = 0;
     int hitchance;
-    int nukedam;
 
     for (qp = bombers->q_forw; qp != bombers; qp = qp->q_forw) {
        plp = (struct plist *)qp;
@@ -1040,7 +1041,7 @@ air_damage(struct emp_qelem *bombers, coord x, coord y, int mission,
        if ((mission == MI_SINTERDICT) && !(plp->pcp->pl_flags & P_A))
            continue;
 
-       if (!plp->bombs)
+       if (!plp->load)
            continue;
 
        newdam = 0;
@@ -1070,24 +1071,14 @@ air_damage(struct emp_qelem *bombers, coord x, coord y, int mission,
            hitchance = 100;
        else if (hardtarget != SECT_HARDTARGET)
            wu(0, pp->pln_own, "\t\t%d%% hitchance...", hitchance);
-       /* Always calculate damage */
        if (roll(100) <= hitchance) {
-           newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 1);
-           if (nukedam) {
-               if (mission == MI_INTERDICT) {
-                   wu(0, pp->pln_own,
-                      "\t\tnuclear warhead on plane %s does %d damage to %s %s\n",
-                      prplane(pp), nukedam, cname(victim), s);
-                   dam += nukedam;
-               }
-           } else {
-               wu(0, pp->pln_own,
-                  "\t\thit %s %s for %d damage\n",
-                  cname(victim), s, newdam);
-               dam += newdam;
-           }
+           newdam = pln_damage(&plp->plane, 'p', 1);
+           wu(0, pp->pln_own,
+              "\t\thit %s %s for %d damage\n",
+              cname(victim), s, newdam);
+           dam += newdam;
        } else {
-           newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 0);
+           newdam = pln_damage(&plp->plane, 'p', 0);
            wu(0, pp->pln_own, "missed\n");
            if (mission == MI_SINTERDICT) {
                mpr(victim,