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