UFO: Alien Invasion
Loading...
Searching...
No Matches
q_shared.cpp
Go to the documentation of this file.
1
5
6/*
7All original material Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9Original file from Quake 2 v3.21: quake2-2.31/game/q_shared.c
10Copyright (C) 1997-2001 Id Software, Inc.
11
12This program is free software; you can redistribute it and/or
13modify it under the terms of the GNU General Public License
14as published by the Free Software Foundation; either version 2
15of the License, or (at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
21See the GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License
24along with this program; if not, write to the Free Software
25Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27*/
28
29#include "q_shared.h"
30
34const char* pa_format[] =
35{
36 "",
37 "s",
38 "g",
39 "s",
41 "gbbl",
42 "s",
43 "bbbbbb",
44 "sss",
45 "ss"
46};
48
53bool 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
78const 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}
Terrain property table entry Terrain is defined by the file map_earth_terrain.png in pics/geoscape....
Definition q_shared.h:356
byte rgbRed
Definition q_shared.h:358
byte rgbGreen
Definition q_shared.h:359
byte rgbBlue
Definition q_shared.h:360
char terrainName[20]
Definition q_shared.h:361
const TerrainDef * findByName(const char *tname) const
Definition q_shared.h:406
float getSnowChance(const byte *const color) const
Definition q_shared.h:443
bool add(const TerrainDef *tdef)
Translate color value to terrain type to random weather code.
Definition q_shared.cpp:53
const char * getWeather(const byte *const color)
Translate color value to terrain type to random weather code.
Definition q_shared.cpp:78
const TerrainDef * findByColor(const byte *const color) const
Definition q_shared.h:393
const TerrainDef * terrainDefTable[MAX_TERRAINDEFS]
Definition q_shared.h:391
float getRainChance(const byte *const color) const
Definition q_shared.h:439
float frand(void)
Return random values between 0 and 1.
Definition mathlib.cpp:506
#define EQUAL_EPSILON
Definition mathlib.h:40
const char * pa_format[]
Player action format strings for netchannel transfer.
Definition q_shared.cpp:34
Common header file.
#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
Definition q_shared.h:200
QGL_EXTERN GLint i
Definition r_gl.h:113
#define lengthof(x)
Definition shared.h:105
#define CASSERT(x)
Definition shared.h:107