]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/mission.c
Don't unlimber when guns unsuccessfully try to fire
[empserver] / src / lib / subs / mission.c
index 6465633e8b0180e4bebb723ff454186efd3e571d..2f147f471e2683317155a1735e1eabb75a09bd7a 100644 (file)
@@ -70,7 +70,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 int mission_pln_arm(struct emp_qelem *, coord, coord, int,
-                          int, struct ichrstr *, int, int, int *);
+                          int, struct ichrstr *, int, int);
 static void mission_pln_sel(struct emp_qelem *, int, int, int);
 static int perform_mission(coord, coord, natid, struct emp_qelem *, int,
                           char *, int);
@@ -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(&sect, coll, list);
+       sectdamage(&sect, coll);
        putsect(&sect);
        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;
 }
@@ -344,10 +344,10 @@ build_mission_list_type(struct genlist *mi, coord x, coord y, int mission,
                if (getrel(getnatp(gp->own), sect.sct_own) > AT_WAR) {
 
                    /*
-                    * If the player->owner of the unit isn't at war
+                    * If the owner of the unit isn't at war
                     * with the victim, and doesn't own the
                     * sect being acted upon, and isn't the
-                    * old player->owner of that sect, bounce them.
+                    * old owner of that sect, bounce them.
                     */
                    if (sect.sct_type != SCT_WATER &&
                        sect.sct_own != gp->own &&
@@ -408,10 +408,11 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
     struct sctstr sect;
     struct mchrstr *mcp;
     struct plchrstr *pcp;
-    int dam = 0, dam2, mission_flags, tech;
+    int dam = 0, dam2, mission_flags;
     natid plane_owner = 0;
     int md, range, air_dam = 0;
     double prb, hitchance, vrange;
+    int targeting_ships = *s == 's'; /* "subs" or "ships" FIXME gross! */
 
     getsect(x, y, &sect);
 
@@ -436,6 +437,10 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
                (md > land_max_interdiction_range))
                continue;
 
+           /* Too ponderous for interdiction fire */
+           if (lchr[(int)lp->lnd_type].l_flags & L_HEAVY)
+               continue;
+
            range = roundrange(lnd_fire_range(lp));
            if (md > range)
                continue;
@@ -445,12 +450,12 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
            if (dam2 < 0)
                continue;
 
-           if (sect.sct_type == SCT_WATER) {
+           if (targeting_ships) {
                if (chance(lnd_acc(lp) / 100.0))
                    dam2 = ldround(dam2 / 2.0, 1);
            }
            dam += dam2;
-           if (sect.sct_type == SCT_WATER)
+           if (targeting_ships)
                nreport(lp->lnd_own, N_SHP_SHELL, victim, 1);
            else
                nreport(lp->lnd_own, N_SCT_SHELL, victim, 1);
@@ -487,10 +492,8 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
                    continue;
            }
            if (mcp->m_flags & M_SUB) {
-/* If we aren't shooting at "subs" or "ships" don't fire at all from
-   a sub. */
-               if (*s != 's')
-                   continue;
+               if (!targeting_ships)
+                   continue;   /* subs interdict only ships */
                range = roundrange(torprange(sp));
                if (md > range)
                    continue;
@@ -547,7 +550,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
                if (chance(prb))
                    dam2 /= 2;
                dam += dam2;
-               if (sect.sct_type == SCT_WATER)
+               if (targeting_ships)
                    nreport(sp->shp_own, N_SHP_SHELL, victim, 1);
                else
                    nreport(sp->shp_own, N_SCT_SHELL, victim, 1);
@@ -644,19 +647,18 @@ 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);
 
-       tech = 0;
        mission_flags = 0;
        mission_flags |= P_X;   /* stealth (shhh) */
        mission_flags |= P_H;   /* gets turned off if not all choppers */
 
        mission_flags = mission_pln_arm(&b, air->x, air->y, 2 * md, 'p', 0,
-                                       0, mission_flags, &tech);
+                                       0, mission_flags);
 
        if (QEMPTY(&b))
            continue;
 
        mission_flags = mission_pln_arm(&e, air->x, air->y, 2 * md, 'p', 0,
-                                       P_F | P_ESC, mission_flags, &tech);
+                                       P_F | P_ESC, mission_flags);
 
        pp = BestAirPath(buf, air->x, air->y, x, y);
        if (CANT_HAPPEN(!pp))
@@ -669,7 +671,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 +=
@@ -681,7 +683,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
 
     if (air_dam > 0) {
        dam += air_dam;
-       if (sect.sct_type == SCT_WATER)
+       if (targeting_ships)
            nreport(plane_owner, N_SHP_BOMB, victim, 1);
        else
            nreport(plane_owner, N_SCT_BOMB, victim, 1);
@@ -926,24 +928,25 @@ mission_pln_sel(struct emp_qelem *list, int wantflags, int nowantflags,
 static int
 mission_pln_arm(struct emp_qelem *list, coord x, coord y, int dist,
                int mission, struct ichrstr *ip, int flags,
-               int mission_flags, int *tech)
+               int mission_flags)
 {
     struct emp_qelem *qp;
     struct emp_qelem *next;
     struct plist *plp;
+    struct plnstr *pp;
 
-    if (*tech == 0)
-       *tech = 9999;
     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;
@@ -954,8 +957,6 @@ mission_pln_arm(struct emp_qelem *list, coord x, coord y, int dist,
            if (plp->pcp->pl_flags & P_I)
                mission_flags |= P_I;
        }
-       if (*tech > plp->plane.pln_tech)
-           *tech = plp->plane.pln_tech;
        if (!(plp->pcp->pl_flags & P_H))
            /* no stealth on this mission */
            mission_flags &= ~P_H;
@@ -971,13 +972,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);
-
+       pp->pln_flags |= PLN_LAUNCHED;
+       pp->pln_mobil -= pln_mobcost(dist, pp, flags);
+       putplane(pp->pln_uid, pp);
     }
     return mission_flags;
 }
@@ -993,7 +990,6 @@ mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags,
     struct shpstr ship;
     struct sctstr sect;
     i_type itype;
-    int rval;
     short *item;
 
     pp = &plp->plane;
@@ -1012,53 +1008,46 @@ mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags,
        return -1;
     }
     item[I_PETROL] -= pcp->pl_fuel;
-    rval = 0;
     if (!(flags & P_F)) {
        load = pln_load(pp);
        itype = I_NONE;
        needed = 0;
        switch (mission) {
-       case 's':
-       case 'p':
+       case 's':               /* strategic bomb */
+       case 'p':               /* pinpoint bomb */
            if (pp->pln_nuketype == -1) {
                itype = I_SHELL;
                needed = load;
            }
            break;
-       case 't':
+       case 't':               /* transport */
+       case 'd':               /* drop */
            if ((pcp->pl_flags & P_C) == 0 || ip == 0)
                break;
            itype = ip->i_uid;
            needed = (load * 2) / ip->i_lbs;
            break;
-       case 'd':
-           if ((pcp->pl_flags & P_C) == 0 || ip == 0)
-               break;
-           itype = ip->i_uid;
-           needed = (load * 2) / ip->i_lbs;
-           break;
-       case 'a':
+       case 'a':               /* paradrop */
            if ((pcp->pl_flags & (P_V | P_C)) == 0)
                break;
            itype = I_MILIT;
            needed = load / ip->i_lbs;
            break;
-       case 'n':
-           if (pp->pln_nuketype == -1)
-               rval = -1;
-           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;
        }
-       if (rval < 0 || (itype != I_NONE && needed <= 0)) {
+       if (itype != I_NONE && needed <= 0)
            return -1;
-       }
        if (itype != I_NONE) {
            if (itype == I_SHELL && item[itype] < needed)
                item[itype] += supply_commod(plp->plane.pln_own,
@@ -1080,7 +1069,7 @@ mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags,
        putland(land.lnd_uid, &land);
     else
        putsect(&sect);
-    return rval;
+    return 0;
 }
 
 /*
@@ -1222,7 +1211,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 */
@@ -1243,7 +1232,7 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list,
            struct emp_qelem *esc_list)
 {
     int dam = 0, cn;
-    int mission_flags, tech, combat = 0, rel, dist, z;
+    int mission_flags, combat = 0, rel, dist, z;
     struct emp_qelem *qp, interceptors, airp, i, empty, *next;
     struct plist *plp;
     struct genlist *glp;
@@ -1353,7 +1342,6 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list,
            /* Split off the interceptors at this base into i */
            divide(&interceptors, &i, air->x, air->y);
 
-           tech = 0;
            mission_flags = 0;
            mission_flags |= P_X;       /* stealth (shhh) */
            /* gets turned off if not all choppers */
@@ -1372,8 +1360,8 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list,
                continue;
            }
            mission_flags =
-               mission_pln_arm(&i, air->x, air->y, 2 * dist, 'r', 0, P_F,
-                               mission_flags, &tech);
+               mission_pln_arm(&i, air->x, air->y, 2 * dist, 0, 0, P_F,
+                               mission_flags);
 
            /* Did we run out of interceptors? */
            if (QEMPTY(&i))
@@ -1387,8 +1375,10 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list,
            }
 
            path = BestAirPath(buf, air->x, air->y, x, y);
-           if (CANT_HAPPEN(!path))
+           if (CANT_HAPPEN(!path)) {
+               pln_put(&i);
                continue;
+           }
            wu(0, cn, "Flying %s mission from %s\n",
               mission_name(MI_AIR_DEFENSE), xyas(air->x, air->y, cn));
            if (air->own && (air->own != cn)) {
@@ -1400,7 +1390,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))
@@ -1430,6 +1420,8 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list,
 
            pln_put(&i);
        }
+       if (CANT_HAPPEN(!QEMPTY(&interceptors)))
+           pln_put(&interceptors);
     }
 
     /* We have to free all of these, if they are still there, otherwise they get