]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/laun.c
Update copyright notice
[empserver] / src / lib / commands / laun.c
index 996188b88792587f27f9110ea75d0ae041b65cef..2cc523ce830e66434202e04a9b98b5631094e2e6 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
  *  ---
  *
  *  laun.c: Launch missiles from land or sea
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Ken Stevens, 1995
  *     Steve McClure, 1998-2000
+ *     Markus Armbruster, 2005-2008
  */
 
 #include <config.h>
@@ -57,13 +58,11 @@ laun(void)
     struct nstr_item nstr;
     struct plnstr plane;
     struct shpstr ship;
-    struct sctstr sect;
     int sublaunch;
     struct plchrstr *pcp;
-    int rel, retval, gone;
-    struct natstr *natp;
+    int retval, gone;
 
-    if (!snxtitem(&nstr, EF_PLANE, player->argp[1]))
+    if (!snxtitem(&nstr, EF_PLANE, player->argp[1], NULL))
        return RET_SYN;
     while (nxtitem(&nstr, &plane)) {
        if (plane.pln_own != player->cnum)
@@ -94,43 +93,17 @@ laun(void)
            }
        }
 
+       if (plane.pln_effic < 40) {
+           pr("%s is damaged (%d%%)\n", prplane(&plane), plane.pln_effic);
+           continue;
+       }
+       if (!pln_airbase_ok(&plane, 1, 1))
+           continue;
        sublaunch = 0;
        if (plane.pln_ship >= 0) {
            getship(plane.pln_ship, &ship);
-           if (!ship.shp_own) {
-               pr("%s: ship #%d was sunk!\n",
-                  prplane(&plane), ship.shp_uid);
-               plane.pln_effic = 0;
-               putplane(plane.pln_uid, &plane);
-               continue;
-           }
-           natp = getnatp(ship.shp_own);
-           rel = getrel(natp, player->cnum);
-           if (ship.shp_own != player->cnum && rel != ALLIED) {
-               pr("%s: you or an ally do not own ship #%d\n",
-                  prplane(&plane), ship.shp_uid);
-               plane.pln_effic = 0;
-               putplane(plane.pln_uid, &plane);
-               continue;
-           }
            if (mchr[(int)ship.shp_type].m_flags & M_SUB)
                sublaunch = 1;
-       } else {
-           sublaunch = 0;
-           getsect(plane.pln_x, plane.pln_y, &sect);
-           natp = getnatp(sect.sct_own);
-           rel = getrel(natp, player->cnum);
-           if (sect.sct_own && sect.sct_own != player->cnum
-               && rel != ALLIED) {
-               pr("%s: you or an ally do not own sector %s!\n",
-                  prplane(&plane), xyas(plane.pln_x, plane.pln_y,
-                                        player->cnum));
-               continue;
-           }
-       }
-       if (plane.pln_effic < 60) {
-           pr("%s is damaged (%d%%)\n", prplane(&plane), plane.pln_effic);
-           continue;
        }
        pr("%s at %s; range %d, eff %d%%\n", prplane(&plane),
           xyas(plane.pln_x, plane.pln_y, player->cnum),
@@ -171,10 +144,6 @@ launch_as(struct plnstr *pp)
     int dam, nukedam;
     natid oldown;
 
-    if (msl_equip(pp) < 0) {
-       pr("%s not enough petrol or shells!\n", prplane(pp));
-       return RET_FAIL;
-    }
     cp = getstarg(player->argp[2], "Target sector? ", buf);
     if (!check_plane_ok(pp))
        return RET_FAIL;
@@ -189,7 +158,7 @@ launch_as(struct plnstr *pp)
        return RET_FAIL;
     }
     goodtarget = 0;
-    snxtitem_dist(&ni, EF_PLANE, sx, sy, 0);
+    snxtitem_xy(&ni, EF_PLANE, sx, sy);
     while (!goodtarget && nxtitem(&ni, &plane)) {
        if (!plane.pln_own)
            continue;
@@ -202,9 +171,15 @@ launch_as(struct plnstr *pp)
        pr("No satellites there!\n");
        return RET_FAIL;
     }
+    if (msl_equip(pp, 'p') < 0) {
+       pr("%s not enough petrol or shells!\n", prplane(pp));
+       return RET_FAIL;
+    }
     if (msl_hit(pp, pln_def(&plane), EF_PLANE, N_SAT_KILL, N_SAT_KILL,
                prplane(&plane), sx, sy, plane.pln_own)) {
        dam = pln_damage(pp, sx, sy, 'p', &nukedam, 1);
+       if (CANT_HAPPEN(nukedam))
+           return RET_OK;
        oldown = plane.pln_own;
        planedamage(&plane, dam);
        pr("Hit satellite for %d%% damage!\n", dam);
@@ -280,7 +255,7 @@ launch_missile(struct plnstr *pp, int sublaunch)
        pr("Range too great; try again!\n");
        return RET_FAIL;
     }
-    if (msl_equip(pp) < 0) {
+    if (msl_equip(pp, 'p') < 0) {
        pr("%s not enough shells!\n", prplane(pp));
        return RET_FAIL;
     }
@@ -300,10 +275,15 @@ launch_missile(struct plnstr *pp, int sublaunch)
        }
        if (!msl_hit(pp, SECT_HARDTARGET, EF_SECTOR, N_SCT_MISS,
                     N_SCT_SMISS, "sector", sx, sy, sect.sct_own)) {
+#if 0
            /*
-              dam = pln_damage(pp, sect.sct_x, sect.sct_y, 's', &nukedam, 0);
-              collateral_damage(sect.sct_x, sect.sct_y, dam, 0);
+            * FIXME want collateral damage on miss (which can't
+            * happen for nuclear war heads), but we get here too when
+            * launch fails or missile is intercepted
             */
+           dam = pln_damage(pp, sect.sct_x, sect.sct_y, 's', &nukedam, 0);
+           collateral_damage(sect.sct_x, sect.sct_y, dam, 0);
+#endif
            return RET_OK;
        }
        dam = pln_damage(pp, sect.sct_x, sect.sct_y, 's', &nukedam, 1);
@@ -331,19 +311,16 @@ launch_missile(struct plnstr *pp, int sublaunch)
                     target_ship.shp_x, target_ship.shp_y,
                     target_ship.shp_own)) {
            pr("splash\n");
-           /*
-              dam = pln_damage(pp,target_ship.shp_x,target_ship.shp_y,'p',&nukedam, 0);
-              collateral_damage(target_ship.shp_x, target_ship.shp_y, dam, 0);
-            */
+#if 0 /* FIXME see above */
+           dam = pln_damage(pp,target_ship.shp_x,target_ship.shp_y,'p',&nukedam, 0);
+           collateral_damage(target_ship.shp_x, target_ship.shp_y, dam, 0);
+#endif
            return RET_OK;
        }
-       dam =
-           pln_damage(pp, target_ship.shp_x, target_ship.shp_y, 'p',
-                      &nukedam, 1);
+       dam = pln_damage(pp, target_ship.shp_x, target_ship.shp_y, 'p',
+                        &nukedam, 1);
        if (!nukedam) {
            check_retreat_and_do_shipdamage(&target_ship, dam);
-           if (target_ship.shp_effic < SHIP_MINEFF)
-               pr("\t%s sunk!\n", prship(&target_ship));
            putship(target_ship.shp_uid, &target_ship);
        }
        getship(target_ship.shp_uid, &target_ship);
@@ -390,6 +367,10 @@ launch_sat(struct plnstr *pp, int sublaunch)
        return RET_SYN;
     if (!check_plane_ok(pp))
        return RET_FAIL;
+    if (msl_equip(pp, 'r') < 0) {
+       pr("%s not enough petrol!\n", prplane(pp));
+       return RET_FAIL;
+    }
     pp->pln_theta = 0;
     pp->pln_flags |= PLN_SYNCHRONOUS;
     if (*p == 0 || *p == 'n')
@@ -403,8 +384,8 @@ launch_sat(struct plnstr *pp, int sublaunch)
     i = pp->pln_tech + pp->pln_effic;
     if (chance(1.0 - (i / (i + 50.0)))) {
        dir = (random() % 6) + 1;
-       sx += diroff[dir][0];
-       sy += diroff[dir][1];
+       sx = xnorm(sx + diroff[dir][0]);
+       sy = ynorm(sy + diroff[dir][1]);
        pr("Your trajectory was a little off.\n");
     }
     nreport(player->cnum, N_LAUNCH, 0, 1);