1 /*
2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
5 *
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * ---
20 *
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
24 *
25 * ---
26 *
27 * land.c: Land unit characteristics
28 *
29 * Known contributors to this file:
30 * Thomas Ruschak, 1992
31 * Ken Stevens, 1995
32 * Steve McClure, 1998-2000
33 */
34
35 #include <config.h>
36
37 #include <math.h>
38 #include "misc.h"
39 #include "land.h"
40
41 /*
42 * Table of land unit types
43 * Initialized on startup from land.config and deity custom config (if any).
44 * Terminated by a sentinel with null l_name.
45 */
46 struct lchrstr lchr[LCHR_SZ];
47
48 #define logx(a, b) (log((a)) / log((b)))
49 #define LND_ATTDEF(b, t) (((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0))) \
50 > 127 ? 127 : \
51 ((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0))))
52 #define LND_SPD(b, t) ((b * (1.0 + ((sqrt(t) / 100.0) * 2.1))) > 127 \
53 ? 127 : (b * (1.0 + ((sqrt(t) / 100.0) * 2.1))))
54 #define LND_VUL(b, t) ((b * (1.0 - ((sqrt(t) / 100.0) * 1.1))) < 0 \
55 ? 0 : (b * (1.0 - ((sqrt(t) / 100.0) * 1.1))))
56 #define LND_FRG(b, t) ((t) ? \
57 ((b) * (logx((t), 35.0) < 1.0 ? 1.0 : \
58 logx((t), 35.0))) : (b))
59 #define LND_DAM(b, t) ((t) ? \
60 ((b) * (logx((t), 60.0) < 1.0 ? 1.0 : \
61 logx((t), 60.0))) : (b))
62 #define LND_ACC(b, t) ((b * (1.0 - ((sqrt(t) / 100.0) * 1.1))) < 0 \
63 ? 0 : (b * (1.0 - ((sqrt(t) / 100.0) * 1.1))))
64 #define LND_AAF(b, t) ((b * (1.0 + ((sqrt(t) / 100.0) * 3.0))) > 127 \
65 ? 127 : (b * (1.0 + ((sqrt(t) / 100.0) * 3.0))))
66
67 float
l_att(struct lchrstr * lcp,int tech)68 l_att(struct lchrstr *lcp, int tech)
69 {
70 return LND_ATTDEF(lcp->l_att, MAX(0, tech - lcp->l_tech));
71 }
72
73 float
l_def(struct lchrstr * lcp,int tech)74 l_def(struct lchrstr *lcp, int tech)
75 {
76 return LND_ATTDEF(lcp->l_def, MAX(0, tech - lcp->l_tech));
77 }
78
79 int
l_vul(struct lchrstr * lcp,int tech)80 l_vul(struct lchrstr *lcp, int tech)
81 {
82 return LND_VUL(lcp->l_vul, MAX(0, tech - lcp->l_tech));
83 }
84
85 int
l_spd(struct lchrstr * lcp,int tech)86 l_spd(struct lchrstr *lcp, int tech)
87 {
88 return LND_SPD(lcp->l_spd, MAX(0, tech - lcp->l_tech));
89 }
90
91 int
l_frg(struct lchrstr * lcp,int tech)92 l_frg(struct lchrstr *lcp, int tech)
93 {
94 return LND_FRG(lcp->l_frg, MAX(0, tech - lcp->l_tech));
95 }
96
97 int
l_acc(struct lchrstr * lcp,int tech)98 l_acc(struct lchrstr *lcp, int tech)
99 {
100 return LND_ACC(lcp->l_acc, MAX(0, tech - lcp->l_tech));
101 }
102
103 int
l_dam(struct lchrstr * lcp,int tech)104 l_dam(struct lchrstr *lcp, int tech)
105 {
106 return LND_DAM(lcp->l_dam, MAX(0, tech - lcp->l_tech));
107 }
108
109 int
l_aaf(struct lchrstr * lcp,int tech)110 l_aaf(struct lchrstr *lcp, int tech)
111 {
112 return LND_AAF(lcp->l_aaf, MAX(0, tech - lcp->l_tech));
113 }
114
115 float
lnd_att(struct lndstr * lp)116 lnd_att(struct lndstr *lp)
117 {
118 return l_att(lchr + lp->lnd_type, lp->lnd_tech);
119 }
120
121 float
lnd_def(struct lndstr * lp)122 lnd_def(struct lndstr *lp)
123 {
124 return l_def(lchr + lp->lnd_type, lp->lnd_tech);
125 }
126
127 int
lnd_vul(struct lndstr * lp)128 lnd_vul(struct lndstr *lp)
129 {
130 return l_vul(lchr + lp->lnd_type, lp->lnd_tech);
131 }
132
133 int
lnd_spd(struct lndstr * lp)134 lnd_spd(struct lndstr *lp)
135 {
136 return l_spd(lchr + lp->lnd_type, lp->lnd_tech);
137 }
138
139 int
lnd_vis(struct lndstr * lp)140 lnd_vis(struct lndstr *lp)
141 {
142 return lchr[lp->lnd_type].l_vis;
143 }
144
145 int
lnd_frg(struct lndstr * lp)146 lnd_frg(struct lndstr *lp)
147 {
148 return l_frg(lchr + lp->lnd_type, lp->lnd_tech);
149 }
150
151 int
lnd_acc(struct lndstr * lp)152 lnd_acc(struct lndstr *lp)
153 {
154 return l_acc(lchr + lp->lnd_type, lp->lnd_tech);
155 }
156
157 int
lnd_dam(struct lndstr * lp)158 lnd_dam(struct lndstr *lp)
159 {
160 return l_dam(lchr + lp->lnd_type, lp->lnd_tech);
161 }
162
163 int
lnd_aaf(struct lndstr * lp)164 lnd_aaf(struct lndstr *lp)
165 {
166 return l_aaf(lchr + lp->lnd_type, lp->lnd_tech);
167 }
168