]> git.pond.sub.org Git - empserver/blob - src/lib/global/ship.c
Fix trailing whitespace
[empserver] / src / lib / global / ship.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  *  ship.c: Ship 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 "ship.h"
43
44 /*
45  * Table of ship types
46  * Initialized on startup from ship.config and deity custom config (if any).
47  * Terminated by a sentinel with null m_name.
48  */
49 struct mchrstr mchr[SHP_TYPE_MAX + 2];
50
51 #define logx(a, b) (log((a)) / log((b)))
52 #define SHP_DEF(b, t) (t ? (b * (logx(t, 40.0) < 1.0 ? 1.0 : \
53                                  logx(t, 40.0))) : b)
54 #define SHP_SPD(b, t) (t ? (b * (logx(t, 35.0) < 1.0 ? 1.0 : \
55                                  logx(t, 35.0))) : b)
56 #define SHP_VIS(b, t) (b * (1 - (sqrt(t) / 50)))
57 #define SHP_RNG(b, t) (t ? (b * (logx(t, 35.0) < 1.0 ? 1.0 : \
58                                  logx(t, 35.0))) : b)
59 #define SHP_FIR(b, t) (t ? (b * (logx(t, 60.0) < 1.0 ? 1.0 : \
60                                  logx(t, 60.0))) : b)
61
62 int
63 m_armor(struct mchrstr *mcp, int tech)
64 {
65     return SHP_DEF(mcp->m_armor, MAX(0, tech - mcp->m_tech));
66 }
67
68 int
69 m_speed(struct mchrstr *mcp, int tech)
70 {
71     return SHP_SPD(mcp->m_speed, MAX(0, tech - mcp->m_tech));
72 }
73
74 int
75 m_visib(struct mchrstr *mcp, int tech)
76 {
77     return SHP_VIS(mcp->m_visib, MAX(0, tech - mcp->m_tech));
78 }
79
80 int
81 m_frnge(struct mchrstr *mcp, int tech)
82 {
83     return SHP_RNG(mcp->m_frnge, MAX(0, tech - mcp->m_tech));
84 }
85
86 int
87 m_glim(struct mchrstr *mcp, int tech)
88 {
89     return SHP_FIR(mcp->m_glim, MAX(0, tech - mcp->m_tech));
90 }
91
92 int
93 shp_armor(struct shpstr *sp)
94 {
95     return m_armor(mchr + sp->shp_type, sp->shp_tech);
96 }
97
98 int
99 shp_speed(struct shpstr *sp)
100 {
101     return m_speed(mchr + sp->shp_type, sp->shp_tech);
102 }
103
104 int
105 shp_visib(struct shpstr *sp)
106 {
107     return m_visib(mchr + sp->shp_type, sp->shp_tech);
108 }
109
110 int
111 shp_frnge(struct shpstr *sp)
112 {
113     return m_frnge(mchr + sp->shp_type, sp->shp_tech);
114 }
115
116 int
117 shp_glim(struct shpstr *sp)
118 {
119     return m_glim(mchr + sp->shp_type, sp->shp_tech);
120 }