UFO: Alien Invasion
Toggle main menu visibility
Loading...
Searching...
No Matches
q_shared.cpp
Go to the documentation of this file.
1
5
6
/*
7
All original material Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9
Original file from Quake 2 v3.21: quake2-2.31/game/q_shared.c
10
Copyright (C) 1997-2001 Id Software, Inc.
11
12
This program is free software; you can redistribute it and/or
13
modify it under the terms of the GNU General Public License
14
as published by the Free Software Foundation; either version 2
15
of the License, or (at your option) any later version.
16
17
This program is distributed in the hope that it will be useful,
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
21
See the GNU General Public License for more details.
22
23
You should have received a copy of the GNU General Public License
24
along with this program; if not, write to the Free Software
25
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27
*/
28
29
#include "
q_shared.h
"
30
34
const
char
*
pa_format
[] =
35
{
36
""
,
37
"s"
,
38
"g"
,
39
"s"
,
41
"gbbl"
,
42
"s"
,
43
"bbbbbb"
,
44
"sss"
,
45
"ss"
46
};
47
CASSERT
(
lengthof
(
pa_format
) ==
PA_NUM_EVENTS
);
48
53
bool
TerrainDefs::add
(
const
TerrainDef
* tdef) {
54
/* check for duplicate color code */
55
if
(
findByColor
(tdef->
rgbRed
, tdef->
rgbGreen
, tdef->
rgbBlue
))
56
return
false
;
57
58
/* check for duplicate name */
59
if
(
findByName
(tdef->
terrainName
))
60
return
false
;
61
62
for
(
int
i
= 0;
i
<
MAX_TERRAINDEFS
- 1;
i
++) {
63
if
(!
terrainDefTable
[
i
]) {
64
terrainDefTable
[
i
] = tdef;
65
terrainDefTable
[
i
+ 1] =
nullptr
;
66
return
true
;
67
}
68
}
69
return
false
;
70
}
71
78
const
char
*
TerrainDefs::getWeather
(
const
byte
*
const
color)
79
{
80
const
float
rainChance =
getRainChance
(color);
81
const
float
snowChance =
getSnowChance
(color);
82
const
float
weatherChance = rainChance + snowChance;
83
if
(
frand
() < weatherChance) {
84
/* we have weather today */
85
if
(snowChance <
EQUAL_EPSILON
||
frand
() < rainChance / weatherChance)
86
return
"1"
;
/* rain */
87
return
"2"
;
/* snow */
88
}
89
/* clear blue sky */
90
return
"0"
;
91
}
TerrainDef
Terrain property table entry Terrain is defined by the file map_earth_terrain.png in pics/geoscape....
Definition
q_shared.h:356
TerrainDef::rgbRed
byte rgbRed
Definition
q_shared.h:358
TerrainDef::rgbGreen
byte rgbGreen
Definition
q_shared.h:359
TerrainDef::rgbBlue
byte rgbBlue
Definition
q_shared.h:360
TerrainDef::terrainName
char terrainName[20]
Definition
q_shared.h:361
TerrainDefs::findByName
const TerrainDef * findByName(const char *tname) const
Definition
q_shared.h:406
TerrainDefs::getSnowChance
float getSnowChance(const byte *const color) const
Definition
q_shared.h:443
TerrainDefs::add
bool add(const TerrainDef *tdef)
Translate color value to terrain type to random weather code.
Definition
q_shared.cpp:53
TerrainDefs::getWeather
const char * getWeather(const byte *const color)
Translate color value to terrain type to random weather code.
Definition
q_shared.cpp:78
TerrainDefs::findByColor
const TerrainDef * findByColor(const byte *const color) const
Definition
q_shared.h:393
TerrainDefs::terrainDefTable
const TerrainDef * terrainDefTable[MAX_TERRAINDEFS]
Definition
q_shared.h:391
TerrainDefs::getRainChance
float getRainChance(const byte *const color) const
Definition
q_shared.h:439
frand
float frand(void)
Return random values between 0 and 1.
Definition
mathlib.cpp:506
EQUAL_EPSILON
#define EQUAL_EPSILON
Definition
mathlib.h:40
pa_format
const char * pa_format[]
Player action format strings for netchannel transfer.
Definition
q_shared.cpp:34
q_shared.h
Common header file.
MAX_TERRAINDEFS
#define MAX_TERRAINDEFS
Terrain property table Terrain is defined by the file map_earth_terrain.png in pics/geoscape....
Definition
q_shared.h:388
PA_NUM_EVENTS
@ PA_NUM_EVENTS
Definition
q_shared.h:200
i
QGL_EXTERN GLint i
Definition
r_gl.h:113
lengthof
#define lengthof(x)
Definition
shared.h:105
CASSERT
#define CASSERT(x)
Definition
shared.h:107
src
game
q_shared.cpp
Generated on __DATE__ __TIME__ for UFO: Alien Invasion by
1.17.0