UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
q_shared.cpp
Go to the documentation of this file.
1 
6 /*
7 All original material Copyright (C) 2002-2020 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 };
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 }
CASSERT(lengthof(pa_format)==PA_NUM_EVENTS)
Common header file.
Terrain property table entry Terrain is defined by the file map_earth_terrain.png in pics/geoscape...
Definition: q_shared.h:355
char terrainName[20]
Definition: q_shared.h:361
byte rgbBlue
Definition: q_shared.h:360
const char * getWeather(const byte *const color)
Translate color value to terrain type to random weather code.
Definition: q_shared.cpp:78
const TerrainDef * findByName(const char *tname) const
Definition: q_shared.h:406
#define MAX_TERRAINDEFS
Terrain property table Terrain is defined by the file map_earth_terrain.png in pics/geoscape. It is a map of the world where the different terrainTypes are drawn in different colors. The colors used in that map must have the exact RGB values as in the table, or they won't be recognized.
Definition: q_shared.h:388
const char * pa_format[]
Player action format strings for netchannel transfer.
Definition: q_shared.cpp:34
bool add(const TerrainDef *tdef)
Translate color value to terrain type to random weather code.
Definition: q_shared.cpp:53
const TerrainDef * findByColor(const byte *const color) const
Definition: q_shared.h:393
float getSnowChance(const byte *const color) const
Definition: q_shared.h:443
const TerrainDef * terrainDefTable[MAX_TERRAINDEFS]
Definition: q_shared.h:391
byte rgbRed
Definition: q_shared.h:358
#define EQUAL_EPSILON
Definition: mathlib.h:40
float frand(void)
Return random values between 0 and 1.
Definition: mathlib.cpp:506
QGL_EXTERN GLint i
Definition: r_gl.h:113
float getRainChance(const byte *const color) const
Definition: q_shared.h:439
#define lengthof(x)
Definition: shared.h:105
uint8_t byte
Definition: ufotypes.h:34
byte rgbGreen
Definition: q_shared.h:359