]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/mslsub.c
Get rid of msl_launch_mindam()
[empserver] / src / lib / subs / mslsub.c
index 3345b2a5cc40bd6ef97b3645e439fe5b8f6752f9..8e48692ec2aa035c41efb90b74c2dd3c7028616a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -26,7 +26,7 @@
  *  ---
  *
  *  mslsub.c: Missile subroutine stuff
- * 
+ *
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  *     Steve McClure, 1996-2000
@@ -42,6 +42,7 @@
 #include "nat.h"
 #include "news.h"
 #include "nsc.h"
+#include "nuke.h"
 #include "optlist.h"
 #include "path.h"
 #include "plane.h"
 #include "ship.h"
 #include "xy.h"
 
-int
-msl_equip(struct plnstr *pp, char mission)
-{
-    struct plist pl;
-
-    memset(&pl, 0, sizeof(struct plist));
-    pl.pcp = plchr + pp->pln_type;
-    pl.plane = *pp;
-    return mission_pln_equip(&pl, 0, 0, mission);
-}
-
 int
 msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item,
        int snews_item, char *what, coord x, coord y, int victim)
@@ -72,9 +62,9 @@ msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item,
     struct sctstr sect;
     int sublaunch = 0;
     struct plchrstr *pcp = plchr + pp->pln_type;
-    int hitchance = pln_hitchance(pp, hardtarget, type);
+    int hitchance;
     char *from;
-    int dam, dummyi;
+    int dam;
 
     mpr(pp->pln_own, "Preparing to launch %s at %s %s %s%s\n",
        prplane(pp),
@@ -106,19 +96,16 @@ msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item,
               * (1 - techfact(pp->pln_tech, 1.0)))) {
        mpr(pp->pln_own, "KABOOOOM!  Missile explodes %s!\n", from);
        if (chance(0.33)) {
-           dam = pln_damage(pp, pp->pln_x, pp->pln_y,
-                            'p', &dummyi, 1) / 2;
-           if (dam) {
-               if (pp->pln_ship >= 0) {
-                   shipdamage(&ship, dam);
-                   putship(ship.shp_uid, &ship);
-               } else {
-                   pr("Explosion damages %s %d%%",
-                      xyas(pp->pln_x, pp->pln_y, pp->pln_own), dam);
-                   getsect(pp->pln_x, pp->pln_y, &sect);
-                   sectdamage(&sect, dam);
-                   putsect(&sect);
-               }
+           dam = pln_damage(pp, 'p', 1) / 2;
+           if (pp->pln_ship >= 0) {
+               shipdamage(&ship, dam);
+               putship(ship.shp_uid, &ship);
+           } else {
+               pr("Explosion damages %s %d%%",
+                  xyas(pp->pln_x, pp->pln_y, pp->pln_own), dam);
+               getsect(pp->pln_x, pp->pln_y, &sect);
+               sectdamage(&sect, dam);
+               putsect(&sect);
            }
        }
        return 0;
@@ -129,16 +116,12 @@ msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item,
     putplane(pp->pln_uid, pp);
     mpr(pp->pln_own, "\tSHWOOOOOSH!  Missile launched!\n");
 
-    if (pp->pln_nuketype != -1)
-       mpr(pp->pln_own, "\tArming nuclear warheads...\n");
-
     if (pcp->pl_flags & P_T)
        mpr(victim, "Incoming %s missile sighted at %s...\n",
            sublaunch ? "sub-launched" : cname(pp->pln_own),
            xyas(x, y, victim));
 
-    if (opt_PINPOINTMISSILE == 0 ||
-       (pcp->pl_flags & P_T && !(pcp->pl_flags & P_MAR))) {
+    if ((pcp->pl_flags & P_T && !(pcp->pl_flags & P_MAR))) {
        if (msl_intercept(x, y, pp->pln_own, pcp->pl_def,
                          sublaunch, P_N, P_O)) {
            return 0;
@@ -150,13 +133,16 @@ msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item,
        }
     }
 
-    if (pp->pln_nuketype != -1)
-       hitchance = 100;
-
-    mpr(pp->pln_own, "\t%d%% hitchance...", hitchance);
-    hit = (roll(100) <= hitchance);
+    if (nuk_on_plane(pp) >= 0) {
+       mpr(pp->pln_own, "\tArming nuclear warheads...\n");
+       hit = 1;
+    } else {
+       hitchance = pln_hitchance(pp, hardtarget, type);
+       hit = (roll(100) <= hitchance);
+       mpr(pp->pln_own, "\t%d%% hitchance...%s\n", hitchance,
+           hit ? "HIT!" : "miss");
+    }
 
-    mpr(pp->pln_own, hit ? "HIT!\n" : "miss\n");
     if (pcp->pl_flags & P_T)
        mpr(victim, "...Incoming %s missile %s\n",
            sublaunch ? "" : cname(pp->pln_own),
@@ -194,6 +180,9 @@ msl_sel(struct emp_qelem *list, coord x, coord y, natid victim,
            continue;
        if (mission && plane.pln_mission != mission)
            continue;
+       if (mission &&
+           plane.pln_radius < mapdist(x, y, plane.pln_opx, plane.pln_opy))
+           continue;
        if (getrel(getnatp(plane.pln_own), victim) >= NEUTRAL)
            continue;
        /* missiles go one way, so we can use all the range */
@@ -207,8 +196,7 @@ msl_sel(struct emp_qelem *list, coord x, coord y, natid victim,
            continue;
        /* got a valid interceptor */
        irv = malloc(sizeof(*irv));
-       irv->bombs = 0;
-       irv->misc = 0;
+       irv->load = 0;
        irv->pcp = &plchr[(int)plane.pln_type];
        irv->plane = plane;
        emp_insque(&irv->queue, list);
@@ -230,7 +218,7 @@ msl_intercept(coord x, coord y, natid bombown, int hardtarget,
     struct emp_qelem *next;
     struct plist *ip;
     int icount = 0;
-    short destroyed = 0;
+    short destroyed;
     char *att_name;
     char *def_name;
     int news_item;
@@ -241,9 +229,9 @@ msl_intercept(coord x, coord y, natid bombown, int hardtarget,
        att_name = "satellite";
        def_name = "a-sat missile";
        news_item = N_SAT_KILL;
+       CANT_HAPPEN(sublaunch);
        mpr(sect.sct_own, "%s has positioned a satellite over %s\n",
-           sublaunch ? "someone" : cname(bombown),
-           xyas(x, y, sect.sct_own));
+           cname(bombown), xyas(x, y, sect.sct_own));
     } else if (wantflags == P_N && nowantflags == P_O) {
        att_name = "warhead";
        def_name = "abm";
@@ -268,7 +256,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, 0, 0, 'i') < 0) {
+       if (mission_pln_equip(ip, NULL, 'i') < 0) {
            emp_remque(qp);
            free(qp);
            continue;
@@ -287,7 +275,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, 0, 0, 'i') < 0) {
+       if (mission_pln_equip(ip, NULL, 'i') < 0) {
            emp_remque(qp);
            free(qp);
            continue;
@@ -308,12 +296,13 @@ msl_intercept(coord x, coord y, natid bombown, int hardtarget,
     }
     if (icount == 0) {
        mpr(sect.sct_own, "No %ss launched to intercept.\n", def_name);
-       return destroyed;
+       return 0;
     }
 
     /* attempt to destroy incoming missile */
 
-    while (!QEMPTY(intlist)) {
+    destroyed = 0;
+    while (!destroyed && !QEMPTY(intlist)) {
        qp = intlist->q_forw;
        ip = (struct plist *)qp;
        pp = &ip->plane;
@@ -333,8 +322,7 @@ msl_intercept(coord x, coord y, natid bombown, int hardtarget,
                def_name, who, att_name, cname(sect.sct_own));
        }
 
-       if (!destroyed &&
-           msl_hit(pp, hardtarget, EF_PLANE, news_item, news_item,
+       if (msl_hit(pp, hardtarget, EF_PLANE, news_item, news_item,
                    att_name, x, y, bombown)) {
            mpr(bombown, "%s destroyed by %s %s!\n",
                att_name, cname(pp->pln_own), def_name);
@@ -348,8 +336,6 @@ msl_intercept(coord x, coord y, natid bombown, int hardtarget,
        putplane(pp->pln_uid, pp);
        emp_remque(qp);
        free(qp);
-       if (destroyed)
-           break;
     }
     /* Clean out what is left in the list */
     while (!QEMPTY(intlist)) {
@@ -358,66 +344,12 @@ msl_intercept(coord x, coord y, natid bombown, int hardtarget,
        free(qp);
     }
     if (destroyed)
-       return destroyed;
+       return 1;
     if (icount) {
        mpr(bombown, "%s made it through %s defenses!\n",
            att_name, def_name);
        mpr(sect.sct_own, "%s made it through %s defenses!\n",
            att_name, def_name);
     }
-    return destroyed;
-}
-
-/* Keep launching missiles on list until mindam damage has been done */
-int
-msl_launch_mindam(struct emp_qelem *list, coord x, coord y, int hardtarget,
-                 int type, int mindam, char *whatp, int victim,
-                 int mission)
-{
-    struct emp_qelem *qp;
-    struct emp_qelem *next;
-    struct plist *plp;
-    int newdam, dam = 0;
-    int nukedam = 0;
-    int news_item;
-    int snews_item;
-
-    if (type == EF_SHIP) {
-       news_item = N_SHP_MISS;
-       snews_item = N_SHP_SMISS;
-    } else if (type == EF_LAND) {
-       news_item = N_LND_MISS;
-       snews_item = N_LND_SMISS;
-    } else {
-       news_item = N_SCT_MISS;
-       snews_item = N_SCT_SMISS;
-    }
-
-    for (qp = list->q_back; qp != list && dam < mindam && !nukedam;
-        qp = next) {
-       next = qp->q_back;
-       plp = (struct plist *)qp;
-
-       if (mission_pln_equip(plp, 0, 0, 'p') >= 0) {
-           if (msl_hit(&plp->plane,
-                       hardtarget, type, news_item, snews_item,
-                       whatp, x, y, victim)) {
-               newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 1);
-               if (nukedam) {
-                   if (mission == MI_INTERDICT && type == EF_SECTOR)
-                       dam += nukedam;
-               } else
-                   dam += newdam;
-           } else {
-               /* Missiles that miss have to hit somewhere! */
-               newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 0);
-               collateral_damage(x, y, newdam);
-           }
-           plp->plane.pln_effic = 0;
-           putplane(plp->plane.pln_uid, &plp->plane);
-           emp_remque(qp);
-           free(qp);
-       }
-    }
-    return dam;
+    return 0;
 }