]> git.pond.sub.org Git - empserver/blob - src/lib/global/land.c
New unit stat development functions
[empserver] / src / lib / global / land.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program 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 2 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, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  land.c: Land unit characteristics
29  * 
30  *  Known contributors to this file:
31  *     Thomas Ruschak, 1992
32  *     Ken Stevens, 1995
33  *     Steve McClure, 1998-2000
34  */
35
36 #include <config.h>
37
38 #include <math.h>
39 #include "misc.h"
40 #include "land.h"
41
42 /*
43  * Table of land unit types
44  * Initialized on startup from land.config and deity custom config (if any).
45  * Terminated by a sentinel with null l_name.
46  */
47 struct lchrstr lchr[LND_TYPE_MAX + 2];
48
49 #define logx(a, b) (log((a)) / log((b)))
50 #define LND_ATTDEF(b, t) (((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0)))   \
51                           > 127 ? 127 :                                 \
52                           ((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0))))
53 #define LND_SPD(b, t) ((b * (1.0 + ((sqrt(t) / 100.0) * 2.1))) > 127    \
54                        ? 127 : (b * (1.0 + ((sqrt(t) / 100.0) * 2.1))))
55 #define LND_VUL(b, t) ((b * (1.0 - ((sqrt(t) / 100.0) * 1.1))) < 0      \
56                        ? 0 : (b * (1.0 - ((sqrt(t) / 100.0) * 1.1))))
57 #define LND_VIS(b, t) (b)
58 #define LND_SPY(b, t) (b)
59 #define LND_RAD(b, t) (b)
60 #define LND_FRG(b, t) ((t) ?                                 \
61                        ((b) * (logx((t), 35.0) < 1.0 ? 1.0 : \
62                                logx((t), 35.0))) : (b))
63 #define LND_DAM(b, t) ((t) ?                                 \
64                        ((b) * (logx((t), 60.0) < 1.0 ? 1.0 : \
65                                logx((t), 60.0))) : (b))
66 #define LND_ACC(b, t) ((b * (1.0 - ((sqrt(t) / 100.0) * 1.1))) < 0      \
67                        ? 0 : (b * (1.0 - ((sqrt(t) / 100.0) * 1.1))))
68 #define LND_AMM(b, t) (b)
69 #define LND_AAF(b, t) ((b * (1.0 + ((sqrt(t) / 100.0) * 3.0))) > 127    \
70                        ? 127 : (b * (1.0 + ((sqrt(t) / 100.0) * 3.0))))
71 #define LND_FC(b, t)  (b)
72 #define LND_FU(b, t)  (b)
73 #define LND_XPL(b, t) (b)
74 #define LND_MXL(b, t) (b)
75
76 float
77 l_att(struct lchrstr *lcp, int tech)
78 {
79     return LND_ATTDEF(lcp->l_att, MAX(0, tech - lcp->l_tech));
80 }
81
82 float
83 l_def(struct lchrstr *lcp, int tech)
84 {
85     return LND_ATTDEF(lcp->l_def, MAX(0, tech - lcp->l_tech));
86 }
87
88 int
89 l_vul(struct lchrstr *lcp, int tech)
90 {
91     return LND_VUL(lcp->l_vul, MAX(0, tech - lcp->l_tech));
92 }
93
94 int
95 l_spd(struct lchrstr *lcp, int tech)
96 {
97     return LND_SPD(lcp->l_spd, MAX(0, tech - lcp->l_tech));
98 }
99
100 int
101 l_frg(struct lchrstr *lcp, int tech)
102 {
103     return LND_FRG(lcp->l_frg, MAX(0, tech - lcp->l_tech));
104 }
105
106 int
107 l_acc(struct lchrstr *lcp, int tech)
108 {
109     return LND_ACC(lcp->l_acc, MAX(0, tech - lcp->l_tech));
110 }
111
112 int
113 l_dam(struct lchrstr *lcp, int tech)
114 {
115     return LND_DAM(lcp->l_dam, MAX(0, tech - lcp->l_tech));
116 }
117
118 int
119 l_aaf(struct lchrstr *lcp, int tech)
120 {
121     return LND_AAF(lcp->l_aaf, MAX(0, tech - lcp->l_tech));
122 }