]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/move.c
Update copyright notice
[empserver] / src / lib / common / move.c
index be010557f4e8c850f49c6cf3678f3ba0e6a59d77..cee3fb4b0ecb56613fd738345cd80820341962a6 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
  *  ---
  *
  *  move.c: Misc. move routines
- * 
+ *
  *  Known contributors to this file:
- *     
+ *     Markus Armbruster, 2006-2008
  */
 
 #include <config.h>
 
 #include "misc.h"
-#include "xy.h"
-#include "sect.h"
-#include "path.h"
 #include "nat.h"
-#include "common.h"
+#include "optlist.h"
+#include "path.h"
+#include "sect.h"
+#include "xy.h"
 
 double
 sector_mcost(struct sctstr *sp, int mobtype)
@@ -49,6 +48,12 @@ sector_mcost(struct sctstr *sp, int mobtype)
     if (base < 0)
        return -1.0;
 
+    if (mobtype == MOB_RAIL && opt_RAILWAYS) {
+       if (!SCT_HAS_RAIL(sp))
+           return -1;
+       mobtype = MOB_MARCH;
+    }
+
     /* 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))
@@ -84,3 +89,33 @@ speed_factor(double effspd, int tech)
 {
     return 480.0 / (effspd + techfact(tech, effspd));
 }
+
+/* Minimal efficiency for railway and railway extension (opt_RAILWAYS) */
+#define SCT_RAIL_EFF 5
+#define SCT_RAIL_EXT_EFF 60
+
+/* Is sector SP a railway? */
+#define SCT_IS_RAILWAY(sp) \
+    (dchr[(sp)->sct_type].d_mob1 == 0 && (sp)->sct_effic >= SCT_RAIL_EFF)
+/* May sector SP have a railway extension? */
+#define SCT_MAY_HAVE_RAIL_EXT(sp) \
+    ((sp)->sct_effic >= SCT_RAIL_EXT_EFF)
+/* Does railway sector SP extend railway track into sector TOSP? */
+#define SCT_EXTENDS_RAIL(sp, tosp) \
+    ((sp)->sct_own == (tosp)->sct_own && SCT_MAY_HAVE_RAIL_EXT(tosp))
+
+int
+sct_rail_track(struct sctstr *sp)
+{
+    int i, res;
+    struct sctstr *nsp;
+
+    res = !!SCT_IS_RAILWAY(sp);
+    for (i = DIR_FIRST; i <= DIR_LAST; i++) {
+       nsp = getsectp(sp->sct_x + diroff[i][0],
+                      sp->sct_y + diroff[i][1]);
+       if (SCT_IS_RAILWAY(nsp) && SCT_EXTENDS_RAIL(nsp, sp))
+           res++;
+    }
+    return res;
+}