]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/fortdef.c
Update copyright notice
[empserver] / src / lib / subs / fortdef.c
index 2c3b5d36c88d93fd003dc289d41780cf9c6707cc..f595a703dbcc3595a003877e61ea518513139b3d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2005, 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
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *  fortdef.c: Fort defends an area.
- * 
+ *
  *  Known contributors to this file:
- *    
+ *
  */
+
 /*
  * The base routines can also be used for general purposes.
  * Noisy tells whther to send teles, print things, etc.
  * Defending tells whether they are being defensive, or offensive.
  */
 
-#include "misc.h"
-#include "xy.h"
+#include <config.h>
+
+#include "file.h"
 #include "nat.h"
-#include "sect.h"
-#include "ship.h"
-#include "land.h"
 #include "news.h"
-#include "nsc.h"
-#include "file.h"
 #include "optlist.h"
 #include "prototypes.h"
+#include "sect.h"
+#include "ship.h"
 
 #define        NOISY   1
 
+static int sb(natid, natid, struct sctstr *, coord, coord, int, int);
+
 /*
  * See if any nearby ships will open up on the attacker
  * Return damage done to attacker, if any.
@@ -66,12 +67,10 @@ int
 sd(natid att, natid own, coord x, coord y, int noisy, int defending,
    int usesubs)
 {
-    int nshot;
-    double range;
+    int range;
     double eff;
     struct shpstr ship;
     struct nstr_item ni;
-    int shell;
     int dam, rel, rel2;
 
     if (own == 0)
@@ -90,36 +89,23 @@ sd(natid att, natid own, coord x, coord y, int noisy, int defending,
        rel2 = getrel(getnatp(ship.shp_own), att);
        if ((ship.shp_own != own) && ((rel != ALLIED) || (rel2 != AT_WAR)))
            continue;
-       if (ship.shp_effic < 60)
-           continue;
-       if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && (!usesubs))
+       if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && !usesubs)
            continue;
-       range = techfact(ship.shp_tech,
-                        ship.shp_frnge * ship.shp_effic / 200.0);
-       range = (double)roundrange(range);
+       range = roundrange(shp_fire_range(&ship));
        if (range < ni.curdist)
            continue;
-       /* must have gun, shell, and milit to fire */
-       shell = ship.shp_item[I_SHELL];
-       if (shell < ship.shp_glim)
-           shell += supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
-                                  I_SHELL, shell - ship.shp_glim);
-       nshot = min(min(ship.shp_item[I_GUN], shell), ship.shp_item[I_MILIT]);
-       nshot = min(nshot, ship.shp_glim);
-       if (nshot <= 0)
-           continue;
-       ship.shp_item[I_SHELL] = shell - nshot;
+       dam = shp_fire(&ship);
        putship(ship.shp_uid, &ship);
+       if (dam < 0)
+           continue;
        if (defending)
            nreport(ship.shp_own, N_FIRE_BACK, att, 1);
        else
            nreport(ship.shp_own, N_FIRE_S_ATTACK, att, 1);
-       dam = seagun(ship.shp_effic, nshot);
        eff *= (1.0 - (0.01 * dam));
        if (noisy) {
            pr_beep();
-           pr("Incoming shell%s %d damage!\n",
-              nshot == 1 ? " does" : "s do", dam);
+           pr("Incoming shells do %d damage!\n", dam);
        }
        if (noisy || (ship.shp_own != own)) {
            if (ship.shp_own == own)
@@ -134,43 +120,18 @@ sd(natid att, natid own, coord x, coord y, int noisy, int defending,
                else
                    wu(0, ship.shp_own,
                       "%s supported %s attacks against %s at %s, doing %d damage.\n",
-                      prship(&ship), cname(own), cname(att), xyas(x, y,
-                                                                  ship.
-                                                                  shp_own),
-                      dam);
+                      prship(&ship), cname(own), cname(att),
+                      xyas(x, y, ship.shp_own), dam);
            }
        }
     }
-    return (int)100 - (eff * 100);
-}
-
-/*
- * Determine if any nearby gun-equipped sectors are within
- * range and able to fire at an attacker.  Firing sectors
- * need to have guns, shells, and military.  Sector being
- * attacked is x,y -- attacker is at ax,ay.
- */
-#if 0
-/* defdef isn't called anywhere, and uses wrong
- * number of arguments for dd */
-int
-defdef(att, def_own, defval, ax, ay)
-natid att;
-natid def_own;
-int defval;
-coord ax;
-coord ay;
-{
-    return dd(att, def_own, defval, ax, ay, NOISY, 1);
+    return (int)(100 - eff * 100);
 }
-#endif
 
 int
 dd(natid att, natid def_own, coord ax, coord ay, int noisy, int defending)
 {
     int dam, rel, rel2;
-    double tech;
-    double range;
     struct sctstr firing;
     struct nstr_sect ns;
 
@@ -180,7 +141,6 @@ dd(natid att, natid def_own, coord ax, coord ay, int noisy, int defending)
        return 0;
     if (att == def_own)
        return 0;
-    tech = tfactfire(def_own, 1.0);
     dam = 0;
     snxtsct_dist(&ns, ax, ay, 8);
     while (nxtsct(&ns, &firing) && dam < 80) {
@@ -188,23 +148,9 @@ dd(natid att, natid def_own, coord ax, coord ay, int noisy, int defending)
            continue;
        if (firing.sct_own == 0)
            continue;
-       if (firing.sct_effic < (u_char)FORTEFF)
-           continue;
        rel = getrel(getnatp(firing.sct_own), def_own);
        rel2 = getrel(getnatp(firing.sct_own), att);
-       if ((firing.sct_own != def_own) &&
-           ((rel != ALLIED) || (rel2 != AT_WAR)))
-           continue;
-
-       range = tfactfire(def_own, 7.0);
-       if (firing.sct_effic > 59)
-           range++;
-       /* Here we round down the range, and then add 1 to it
-          to determine if we could possibly hit the sector.  If
-          we do, we call sb where the range is re-calculated and
-          the percentages are checked. */
-       range = (double)((int)(range) + 1);
-       if (range < ns.curdist)
+       if (firing.sct_own != def_own && (rel != ALLIED || rel2 != AT_WAR))
            continue;
        /* XXX defdef damage is additive, but ship or land unit damage isn't */
        dam += sb(att, def_own, &firing, ax, ay, noisy, defending);
@@ -216,56 +162,32 @@ dd(natid att, natid def_own, coord ax, coord ay, int noisy, int defending)
  *
  * See if the sector being fired at will defend itself.
  */
-int
+static int
 sb(natid att, natid def, struct sctstr *sp, coord tx, coord ty, int noisy,
    int defending)
 {
     int damage;
     natid own;
-    int shell;
-    double range;
-    int range2, gun;
-
-    if (sp->sct_type != SCT_FORTR) {
-       /* XXX I don't like this restriction */
-       return 0;
-    }
-
-    if (sp->sct_effic < (u_char)FORTEFF)
-       return 0;
+    int range, range2;
 
     own = sp->sct_own;
     if (own == 0)
        return 0;
     if (att == own)
        return 0;
-    range = tfactfire(own, 7.0);
-    if (sp->sct_effic > 59)
-       range++;
-    range = (double)roundrange(range);
-    range2 = mapdist((int)sp->sct_x, (int)sp->sct_y, tx, ty);
+    range = roundrange(fortrange(sp));
+    range2 = mapdist(sp->sct_x, sp->sct_y, tx, ty);
     if (range < range2)
        return 0;
-    gun = sp->sct_item[I_GUN];
-    if (gun == 0)
-       return 0;
-    shell = sp->sct_item[I_SHELL];
-    if (shell <= 0)
-       shell += supply_commod(sp->sct_own, sp->sct_x, sp->sct_y, I_SHELL,
-                              1);
-    if (shell <= 0)
-       return 0;
-    sp->sct_item[I_SHELL] = shell - 1;
+    damage = fort_fire(sp);
     putsect(sp);
-    damage = landgun((int)sp->sct_effic, gun);
+    if (damage < 0)
+       return 0;
     if (sp->sct_own != def)
        wu(0, sp->sct_own,
           "%s fired on %s in %s in defense of %s, doing %d damage!\n",
-          xyas(sp->sct_x, sp->sct_y, sp->sct_own), cname(att), xyas(tx,
-                                                                    ty,
-                                                                    sp->
-                                                                    sct_own),
-          cname(def), damage);
+          xyas(sp->sct_x, sp->sct_y, sp->sct_own), cname(att),
+          xyas(tx, ty, sp->sct_own), cname(def), damage);
     if (defending)
        nreport(sp->sct_own, N_FIRE_BACK, att, 1);
     else