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 * plane.c: Plane characteristics
28 *
29 * Known contributors to this file:
30 * Dave Pare, 1986
31 * Jeff Bailey
32 * Thomas Ruschak, 1992
33 * Ken Stevens, 1995
34 * Steve McClure, 1998
35 */
36
37 #include <config.h>
38
39 #include <math.h>
40 #include "misc.h"
41 #include "plane.h"
42
43 /*
44 * Table of plane types
45 * Initialized on startup from plane.config and deity custom config (if any).
46 * Terminated by a sentinel with null pl_name.
47 */
48 struct plchrstr plchr[PLCHR_SZ];
49
50 #define logx(a, b) (log((a)) / log((b)))
51 #define PLN_ATTDEF(b, t) (b + ((b?1:0) * ((t/20)>10?10:(t/20))))
52 #define PLN_ACC(b, t) (b * (1.0 - (sqrt(t) / 50.)))
53 #define PLN_RAN(b, t) (t ? (b + (logx(t, 2.0))) : b)
54 #define PLN_LOAD(b, t) (t ? (b * (logx(t, 50.0) < 1.0 ? 1.0 : \
55 logx(t, 50.0))) : b)
56
57 int
pl_att(struct plchrstr * pcp,int tech)58 pl_att(struct plchrstr *pcp, int tech)
59 {
60 return PLN_ATTDEF(pcp->pl_att, MAX(0, tech - pcp->pl_tech));
61 }
62
63 int
pl_def(struct plchrstr * pcp,int tech)64 pl_def(struct plchrstr *pcp, int tech)
65 {
66 return PLN_ATTDEF(pcp->pl_def, MAX(0, tech - pcp->pl_tech));
67 }
68
69 int
pl_acc(struct plchrstr * pcp,int tech)70 pl_acc(struct plchrstr *pcp, int tech)
71 {
72 return PLN_ACC(pcp->pl_acc, MAX(0, tech - pcp->pl_tech));
73 }
74
75 int
pl_range(struct plchrstr * pcp,int tech)76 pl_range(struct plchrstr *pcp, int tech)
77 {
78 return PLN_RAN(pcp->pl_range, MAX(0, tech - pcp->pl_tech));
79 }
80
81 int
pl_load(struct plchrstr * pcp,int tech)82 pl_load(struct plchrstr *pcp, int tech)
83 {
84 return PLN_LOAD(pcp->pl_load, MAX(0, tech - pcp->pl_tech));
85 }
86
87 int
pln_att(struct plnstr * pp)88 pln_att(struct plnstr *pp)
89 {
90 return pl_att(plchr + pp->pln_type, pp->pln_tech);
91 }
92
93 int
pln_def(struct plnstr * pp)94 pln_def(struct plnstr *pp)
95 {
96 return pl_def(plchr + pp->pln_type, pp->pln_tech);
97 }
98
99 int
pln_acc(struct plnstr * pp)100 pln_acc(struct plnstr *pp)
101 {
102 return pl_acc(plchr + pp->pln_type, pp->pln_tech);
103 }
104
105 int
pln_range_max(struct plnstr * pp)106 pln_range_max(struct plnstr *pp)
107 {
108 return pl_range(plchr + pp->pln_type, pp->pln_tech);
109 }
110
111 int
pln_load(struct plnstr * pp)112 pln_load(struct plnstr *pp)
113 {
114 return pl_load(plchr + pp->pln_type, pp->pln_tech);
115 }
116