]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/mobility.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / update / mobility.c
index 333421a2e0fa0d7c2cb15335e38ed6eb8b0e2786..a3586e3f4f3f483e2e7bc15c04badec4e9cf2f87 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  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.
  *
  *  ---
  *
@@ -32,8 +32,9 @@
  *     Steve McClure, 1998-1999
  */
 
+#include <config.h>
+
 #include "misc.h"
-#include "var.h"
 #include "sect.h"
 #include "ship.h"
 #include "land.h"
 #include "nat.h"
 #include "file.h"
 #include "optlist.h"
-#include "mission.h"
 #include "update.h"
 #include "gen.h"
 #include "subs.h"
 #include "optlist.h"
+#include "server.h"
+
 
-extern int timestamp_fixing;
-extern int update_pending;
-int do_upd_checking = 0;
+int updating_mob = 1;
 
-static void do_mob_land(register struct lndstr *, register int);
-static void do_mob_plane(register struct plnstr *, register int);
-static void do_mob_sect(register struct sctstr *sp, register int etus);
-static void do_mob_ship(register struct shpstr *, register int);
+static int timestamp_fixing;
+static int do_upd_checking = 0;
 
-int
-increase_mob(time_t * counter, float mult)
+static void do_mob_land(struct lndstr *, int);
+static void do_mob_plane(struct plnstr *, int);
+static void do_mob_sect(struct sctstr *sp, int etus);
+static void do_mob_ship(struct shpstr *, int);
+
+static int
+increase_mob(time_t *counter, float mult)
 {
     time_t secs;
     time_t now;
     time_t left;
-    extern long s_p_etu;
-    extern int updating_mob;
     int newetus;
     float newmob;
     int inewmob;
@@ -92,7 +93,7 @@ increase_mob(time_t * counter, float mult)
     *counter = *counter - left;
 
     if (updating_mob)
-       return (newetus);
+       return newetus;
     return 0;
 }
 
@@ -154,9 +155,8 @@ update_all_mob(void)
 }
 
 void
-sct_do_upd_mob(register struct sctstr *sp)
+sct_do_upd_mob(struct sctstr *sp)
 {
-    extern float sect_mob_scale;
     int etus;
 
     if (do_upd_checking || timestamp_fixing || update_pending)
@@ -174,9 +174,8 @@ sct_do_upd_mob(register struct sctstr *sp)
 }
 
 void
-shp_do_upd_mob(register struct shpstr *sp)
+shp_do_upd_mob(struct shpstr *sp)
 {
-    extern float ship_mob_scale;
     int etus;
 
     if (do_upd_checking || timestamp_fixing || update_pending)
@@ -191,9 +190,8 @@ shp_do_upd_mob(register struct shpstr *sp)
 }
 
 void
-lnd_do_upd_mob(register struct lndstr *lp)
+lnd_do_upd_mob(struct lndstr *lp)
 {
-    extern float land_mob_scale;
     int etus;
 
     if (do_upd_checking || timestamp_fixing || update_pending)
@@ -209,9 +207,8 @@ lnd_do_upd_mob(register struct lndstr *lp)
 }
 
 void
-pln_do_upd_mob(register struct plnstr *pp)
+pln_do_upd_mob(struct plnstr *pp)
 {
-    extern float plane_mob_scale;
     int etus;
 
     if (do_upd_checking || timestamp_fixing || update_pending)
@@ -227,10 +224,10 @@ pln_do_upd_mob(register struct plnstr *pp)
 }
 
 void
-mob_sect(register int etus)
+mob_sect(int etus)
 {
-    register struct sctstr *sp;
-    register int n;
+    struct sctstr *sp;
+    int n;
     time_t now;
 
     time(&now);
@@ -244,11 +241,9 @@ mob_sect(register int etus)
 }
 
 static void
-do_mob_sect(register struct sctstr *sp, register int etus)
+do_mob_sect(struct sctstr *sp, int etus)
 {
-    extern float sect_mob_scale;
-    extern int sect_mob_max;
-    register int value;
+    int value;
 
     if (sp->sct_own == 0)
        return;
@@ -267,10 +262,10 @@ do_mob_sect(register struct sctstr *sp, register int etus)
 }
 
 void
-mob_ship(register int etus)
+mob_ship(int etus)
 {
-    register struct shpstr *sp;
-    register int n;
+    struct shpstr *sp;
+    int n;
     time_t now;
 
     time(&now);
@@ -284,15 +279,12 @@ mob_ship(register int etus)
 }
 
 static void
-do_mob_ship(register struct shpstr *sp, register int etus)
+do_mob_ship(struct shpstr *sp, int etus)
 {
-    extern int ship_mob_max;
-    extern float ship_mob_scale;
     int newfuel = 0;
-    register int value;
+    int value;
     int can_add, have_fuel_for, total_add;
     double d;
-    extern int fuel_mult;
 
     if (sp->shp_own == 0)
        return;
@@ -373,17 +365,17 @@ do_mob_ship(register struct shpstr *sp, register int etus)
        d *= (double)mchr[(int)sp->shp_type].m_fuelu;
        d /= (double)fuel_mult;
        sp->shp_fuel -= (u_char)ldround(d, 1);
-       sp->shp_fuel = (u_char)min(sp->shp_fuel,
+       sp->shp_fuel = (u_char)MIN(sp->shp_fuel,
                                   mchr[(int)sp->shp_type].m_fuelc);
        sp->shp_mobil += (s_char)total_add;
     }
 }
 
 void
-mob_land(register int etus)
+mob_land(int etus)
 {
-    register struct lndstr *lp;
-    register int n;
+    struct lndstr *lp;
+    int n;
     time_t now;
 
     time(&now);
@@ -397,51 +389,30 @@ mob_land(register int etus)
 }
 
 static void
-do_mob_land(register struct lndstr *lp, register int etus)
+do_mob_land(struct lndstr *lp, int etus)
 {
-    extern int land_mob_max;
-    extern float land_mob_scale;
     int newfuel = 0;
-    register int value;
+    int value;
     int can_add, have_fuel_for, total_add;
     double d;
-    extern int fuel_mult;
 
     if (lp->lnd_own == 0)
        return;
 
     if (lp->lnd_mobil >= land_mob_max) {
        lp->lnd_mobil = land_mob_max;
-       return;
-    }
-
-    /*
-     * Give damaged units a break. When at low
-     * efficiency, units can go to -100 mob when
-     * marching 1 step, making them slower than
-     * normal mil. This helps take the curse off.
-     * If MOB_ACCESS is on, we don't do this, as it would
-     * be too much of an advantage.  So, we just add double
-     * the small amount of mob if we are < 0 instead.
-     */
-
-    if (!opt_MOB_ACCESS) {
-       if (lp->lnd_mobil < 0)
-           lp->lnd_mobil /= 2;
+       if (lp->lnd_harden >= land_mob_max) {
+           lp->lnd_harden = land_mob_max;
+           return;
+       }
     }
 
     if (opt_FUEL == 0) {       /* just some bits and pieces */
-       if (opt_MOB_ACCESS) {
-           if (lp->lnd_mobil < 0)
-               value =
-                   lp->lnd_mobil + (2 * ((float)etus * land_mob_scale));
-           else
-               value = lp->lnd_mobil + ((float)etus * land_mob_scale);
-       } else {
-           value = lp->lnd_mobil + ((float)etus * land_mob_scale);
-       }
-       if (value > land_mob_max)
+       value = lp->lnd_mobil + ((float)etus * land_mob_scale);
+       if (value > land_mob_max) {
+           lnd_fortify(lp, value - land_mob_max);
            value = land_mob_max;
+       }
        lp->lnd_mobil = value;
 
        return;                 /* Done! */
@@ -449,17 +420,11 @@ do_mob_land(register struct lndstr *lp, register int etus)
 
     /* opt_FUEL in force ... */
     if (lp->lnd_fuelu == 0) {
-       if (opt_MOB_ACCESS) {
-           if (lp->lnd_mobil < 0)
-               value =
-                   lp->lnd_mobil + (2 * ((float)etus * land_mob_scale));
-           else
-               value = lp->lnd_mobil + ((float)etus * land_mob_scale);
-       } else {
-           value = lp->lnd_mobil + ((float)etus * land_mob_scale);
-       }
-       if (value > land_mob_max)
+       value = lp->lnd_mobil + ((float)etus * land_mob_scale);
+       if (value > land_mob_max) {
+           lnd_fortify(lp, value - land_mob_max);
            value = land_mob_max;
+       }
        lp->lnd_mobil = value;
 
     } else {
@@ -513,24 +478,21 @@ do_mob_land(register struct lndstr *lp, register int etus)
        d *= (double)lp->lnd_fuelu;
        d /= (double)fuel_mult;
        lp->lnd_fuel -= (u_char)ldround(d, 1);
-       lp->lnd_fuel = (u_char)min(lp->lnd_fuel, lp->lnd_fuelc);
+       lp->lnd_fuel = (u_char)MIN(lp->lnd_fuel, lp->lnd_fuelc);
        if (total_add + lp->lnd_mobil > land_mob_max) {
            total_add = land_mob_max - lp->lnd_mobil;
        }
+       /* no automatic fortification here, as it would cost fuel */
 
-       if (opt_MOB_ACCESS) {
-           if (lp->lnd_mobil < 0)
-               lp->lnd_mobil += (s_char)total_add;
-       }
        lp->lnd_mobil += (s_char)total_add;
     }
 }
 
 void
-mob_plane(register int etus)
+mob_plane(int etus)
 {
-    register struct plnstr *pp;
-    register int n;
+    struct plnstr *pp;
+    int n;
     time_t now;
 
     time(&now);
@@ -544,11 +506,9 @@ mob_plane(register int etus)
 }
 
 static void
-do_mob_plane(register struct plnstr *pp, register int etus)
+do_mob_plane(struct plnstr *pp, int etus)
 {
-    extern int plane_mob_max;
-    extern float plane_mob_scale;
-    register int value;
+    int value;
 
     if (pp->pln_own == 0)
        return;