]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/move.c
Fix trailing whitespace
[empserver] / src / lib / common / move.c
index eddc0780679799f4b3fcc840601bba1a11f88885..3257acb97ecf45c9d08d29e11ad16e36a0f192a9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  move.c: Misc. move routines
- * 
+ *
  *  Known contributors to this file:
- *     
+ *     Markus Armbruster, 2006
  */
 
 #include <config.h>
 
 #include "misc.h"
-#include "xy.h"
-#include "sect.h"
-#include "path.h"
 #include "nat.h"
-#include "common.h"
+#include "path.h"
+#include "sect.h"
+#include "xy.h"
 
 double
-sector_mcost(struct sctstr *sp, int do_bonus)
+sector_mcost(struct sctstr *sp, int mobtype)
 {
-    double d;
+    double base, cost;
 
-    d = dchr[sp->sct_type].d_mcst;
-    if (d <= 0)
+    base = dchr[sp->sct_type].d_mob0;
+    if (base < 0)
        return -1.0;
 
-    if (do_bonus == MOB_MOVE || do_bonus == MOB_MARCH) {
-       d = d / (1.0 + sp->sct_road / 122.0);
-    } else if (do_bonus == MOB_RAIL) {
-       if (sp->sct_rail <= 0)
+    /* linear function in eff, d_mob0 at 0%, d_mob1 at 100% */
+    base += (dchr[sp->sct_type].d_mob1 - base) * sp->sct_effic / 100;
+    if (CANT_HAPPEN(base < 0))
+       base = 0;
+
+    if (mobtype == MOB_MOVE || mobtype == MOB_MARCH) {
+       /* linear function in road, base at 0%, base/10 at 100% */
+       cost = base;
+       if (intrchr[INT_ROAD].in_enable)
+           cost -= base * 0.009 * sp->sct_road;
+    } else if (mobtype == MOB_RAIL) {
+       if (!intrchr[INT_RAIL].in_enable || sp->sct_rail <= 0)
            return -1.0;
-       d = d / (1.0 + sp->sct_rail / 100.0);
+       /* linear function in rail, base at 0%, base/100 at 100% */
+       cost = base - base * 0.0099 * sp->sct_rail;
     } else {
-       if (d < 2.0)
-           d = 2.0;
+       CANT_REACH();
+       cost = base;
     }
-    if (d < 1.0)
-       d = 1.0;
-    if (dchr[sp->sct_type].d_mcst < 25)
-       d = (d * 100.0 - sp->sct_effic) / 500.0;
-    else
-       d = (d * 10.0 - sp->sct_effic) / 115;
+    if (CANT_HAPPEN(cost < 0))
+       cost = 0;
+
+    if (mobtype == MOB_MOVE)
+       return MAX(cost, 0.001);
+    if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0)
+       /* slow down land units in newly taken sectors */
+       return cost + 0.2;
+    return MAX(cost, 0.02);
+}
 
-    if (do_bonus == MOB_MOVE)
-       return MAX(d, MIN_MOBCOST);
-    if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0
-       && do_bonus != MOB_RAIL)
-       return MAX(d, LND_MINMOBCOST);
-    return MAX(d, 0.01);
+double
+speed_factor(double effspd, int tech)
+{
+    return 480.0 / (effspd + techfact(tech, effspd));
 }