]> git.pond.sub.org Git - empserver/blobdiff - src/lib/global/land.c
Fix trailing whitespace
[empserver] / src / lib / global / land.c
index b2f7a7f323e824d5b9760cd004aa77a1d185e591..a96ff3d2f6e25e1ccb0ddf84e453bd0d4a711a22 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
@@ -26,7 +26,7 @@
  *  ---
  *
  *  land.c: Land unit characteristics
- * 
+ *
  *  Known contributors to this file:
  *     Thomas Ruschak, 1992
  *     Ken Stevens, 1995
 
 #include <config.h>
 
+#include <math.h>
 #include "misc.h"
 #include "land.h"
 
 /*
  * Table of land unit types
  * Initialized on startup from land.config and deity custom config (if any).
+ * Terminated by a sentinel with null l_name.
  */
-struct lchrstr lchr[N_MAXLAND + 1];
+struct lchrstr lchr[LND_TYPE_MAX + 2];
+
+#define logx(a, b) (log((a)) / log((b)))
+#define LND_ATTDEF(b, t) (((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0)))  \
+                         > 127 ? 127 :                                 \
+                         ((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0))))
+#define LND_SPD(b, t) ((b * (1.0 + ((sqrt(t) / 100.0) * 2.1))) > 127   \
+                      ? 127 : (b * (1.0 + ((sqrt(t) / 100.0) * 2.1))))
+#define LND_VUL(b, t) ((b * (1.0 - ((sqrt(t) / 100.0) * 1.1))) < 0     \
+                      ? 0 : (b * (1.0 - ((sqrt(t) / 100.0) * 1.1))))
+#define LND_FRG(b, t) ((t) ?                                \
+                      ((b) * (logx((t), 35.0) < 1.0 ? 1.0 : \
+                              logx((t), 35.0))) : (b))
+#define LND_DAM(b, t) ((t) ?                                \
+                      ((b) * (logx((t), 60.0) < 1.0 ? 1.0 : \
+                              logx((t), 60.0))) : (b))
+#define LND_ACC(b, t) ((b * (1.0 - ((sqrt(t) / 100.0) * 1.1))) < 0     \
+                      ? 0 : (b * (1.0 - ((sqrt(t) / 100.0) * 1.1))))
+#define LND_AAF(b, t) ((b * (1.0 + ((sqrt(t) / 100.0) * 3.0))) > 127   \
+                      ? 127 : (b * (1.0 + ((sqrt(t) / 100.0) * 3.0))))
+
+float
+l_att(struct lchrstr *lcp, int tech)
+{
+    return LND_ATTDEF(lcp->l_att, MAX(0, tech - lcp->l_tech));
+}
+
+float
+l_def(struct lchrstr *lcp, int tech)
+{
+    return LND_ATTDEF(lcp->l_def, MAX(0, tech - lcp->l_tech));
+}
+
+int
+l_vul(struct lchrstr *lcp, int tech)
+{
+    return LND_VUL(lcp->l_vul, MAX(0, tech - lcp->l_tech));
+}
+
+int
+l_spd(struct lchrstr *lcp, int tech)
+{
+    return LND_SPD(lcp->l_spd, MAX(0, tech - lcp->l_tech));
+}
+
+int
+l_frg(struct lchrstr *lcp, int tech)
+{
+    return LND_FRG(lcp->l_frg, MAX(0, tech - lcp->l_tech));
+}
+
+int
+l_acc(struct lchrstr *lcp, int tech)
+{
+    return LND_ACC(lcp->l_acc, MAX(0, tech - lcp->l_tech));
+}
+
+int
+l_dam(struct lchrstr *lcp, int tech)
+{
+    return LND_DAM(lcp->l_dam, MAX(0, tech - lcp->l_tech));
+}
+
+int
+l_aaf(struct lchrstr *lcp, int tech)
+{
+    return LND_AAF(lcp->l_aaf, MAX(0, tech - lcp->l_tech));
+}
+
+float
+lnd_att(struct lndstr *lp)
+{
+    return l_att(lchr + lp->lnd_type, lp->lnd_tech);
+}
+
+float
+lnd_def(struct lndstr *lp)
+{
+    return l_def(lchr + lp->lnd_type, lp->lnd_tech);
+}
+
+int
+lnd_vul(struct lndstr *lp)
+{
+    return l_vul(lchr + lp->lnd_type, lp->lnd_tech);
+}
+
+int
+lnd_spd(struct lndstr *lp)
+{
+    return l_spd(lchr + lp->lnd_type, lp->lnd_tech);
+}
+
+int
+lnd_vis(struct lndstr *lp)
+{
+    return lchr[lp->lnd_type].l_vis;
+}
+
+int
+lnd_frg(struct lndstr *lp)
+{
+    return l_frg(lchr + lp->lnd_type, lp->lnd_tech);
+}
+
+int
+lnd_acc(struct lndstr *lp)
+{
+    return l_acc(lchr + lp->lnd_type, lp->lnd_tech);
+}
+
+int
+lnd_dam(struct lndstr *lp)
+{
+    return l_dam(lchr + lp->lnd_type, lp->lnd_tech);
+}
+
+int
+lnd_aaf(struct lndstr *lp)
+{
+    return l_aaf(lchr + lp->lnd_type, lp->lnd_tech);
+}