UFO: Alien Invasion
Doxygen documentation generating
q_shared.h
Go to the documentation of this file.
1 
8 /*
9 All original material Copyright (C) 2002-2023 UFO: Alien Invasion.
10 
11 Original file from Quake 2 v3.21: quake2-2.31/game/q_shared.h
12 Copyright (C) 1997-2001 Id Software, Inc.
13 
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License
16 as published by the Free Software Foundation; either version 2
17 of the License, or (at your option) any later version.
18 
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 
23 See the GNU General Public License for more details.
24 
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 
29 */
30 
31 #pragma once
32 
33 #include "../shared/ufotypes.h"
34 #include "../shared/shared.h"
35 #include "../shared/mathlib.h"
36 #include "../shared/defines.h"
37 #include "../common/list.h"
38 
39 #include "inv_shared.h"
40 #include "chr_shared.h"
41 #include "q_sizes.h"
42 
43 #ifdef DEDICATED_ONLY
44 /* no gettext support for dedicated servers */
45 # define _(String) String
46 # define ngettext(x, y, cnt) x
47 #endif
48 
49 /*
50 ==============================================================
51 SYSTEM SPECIFIC
52 ==============================================================
53 */
54 
55 /* this is only here so the functions in q_shared.c can link */
56 void Sys_Error(const char* error, ...) __attribute__((noreturn, format(__printf__, 1, 2)));
57 void Com_Printf(const char* msg, ...) __attribute__((format(__printf__, 1, 2)));
58 void Com_DPrintf(int level, const char* msg, ...) __attribute__((format(__printf__, 2, 3)));
59 
60 #define TEAM_NO_ACTIVE -1
61 #define TEAM_CIVILIAN 0
62 #define TEAM_PHALANX 1
63 #define TEAM_ALIEN 7
64 #define TEAM_MAX_HUMAN TEAM_ALIEN - 1
65 
66 /*
67 ==========================================================
68 ELEMENTS COMMUNICATED ACROSS THE NET
69 ==========================================================
70 */
71 
73 #define EVENT_INSTANTLY 0x80
74 
79 typedef enum {
85 
89 
96 
106 
112 
119 
125 
126  /* func_breakables */
132 
134 
139 
141 
143 } event_t;
144 
145 typedef enum {
172 
174 
176 } entity_type_t;
177 
178 typedef enum {
181 
183 
184  CAMERA_ENSURE_32BIT = 0x7FFFFFFF
185 } camera_type_t;
186 
187 #define DOOR_ROTATION_ANGLE 90
188 
189 typedef enum {
199 
202 
203 extern const char* pa_format[PA_NUM_EVENTS];
204 
206 typedef int32_t shoot_types_t;
211 #define ST_RIGHT 0
212 
216 #define ST_RIGHT_REACTION 1
217 
221 #define ST_LEFT 2
222 
226 #define ST_LEFT_REACTION 3
227 
231 #define ST_HEADGEAR 4
232 
236 #define ST_NUM_SHOOT_TYPES 5
237 
239 #define IS_SHOT_REACTION(x) ((x) == ST_RIGHT_REACTION || (x) == ST_LEFT_REACTION)
240 
241 #define IS_SHOT_LEFT(x) ((x) == ST_LEFT || (x) == ST_LEFT_REACTION)
242 
243 #define IS_SHOT_RIGHT(x) ((x) == ST_RIGHT || (x) == ST_RIGHT_REACTION)
244 
245 #define IS_SHOT_HEADGEAR(x) ((x) == ST_HEADGEAR)
246 
247 /* shoot flags */
248 #define SF_IMPACT 1
249 #define SF_BODY 2
250 #define SF_BOUNCING 4
251 #define SF_BOUNCED 8
253 /* is used in events where two edicts can be send, one actor and one receiver - but one of them can
254  * be nullptr, e.g. in a case where the actor is a trigger */
255 #define SKIP_LOCAL_ENTITY (-1)
256 
257 #define MAX_DEATH 3
259 /* State flags - transferred as short (so max 16 bits please) */
260 /* public states */
261 #define STATE_PUBLIC 0x00FF
262 #define STATE_DEAD 0x0003
263 #define STATE_CROUCHED 0x0004
264 #define STATE_PANIC 0x0008
265 
266 #define STATE_RAGE 0x0010
267 #define STATE_INSANE 0x0020
268 #define STATE_STUN 0x0043
269 #define STATE_DAZED 0x0080
271 /* private states */
272 #define STATE_REACTION 0x0300
273 #define STATE_SHAKEN 0x0400
274 #define STATE_XVI 0x0800
276 #define GRAVITY 500.0
277 
278 #define MAX_SKILL 100
279 #define MAX_MAXHP 255
280 #define MIN_TU 39
281 #define WEIGHT_LIGHT 0.2f
282 #define WEIGHT_HEAVY 0.5f
283 #define WEIGHT_NORMAL_PENALTY 0.3f
284 #define WEIGHT_HEAVY_PENALTY 0.6f
285 #define WEIGHT_FACTOR 1000.0f
286 
287 #define GET_ENCUMBRANCE_PENALTY(weight, max) (1.0f - ((weight) > (max) * WEIGHT_FACTOR * WEIGHT_HEAVY ? WEIGHT_HEAVY_PENALTY : (weight) > (max) * WEIGHT_FACTOR * WEIGHT_LIGHT ? WEIGHT_NORMAL_PENALTY : 0.0f))
288 
289 #define GET_ACC( ab, sk, pn ) ((pn) - (((float)(ab) - 10) / (MAX_SKILL / 2) + ((float)(sk) - 10) / (MAX_SKILL / 2)) / 2)
290 #define GET_MORALE( ab ) (std::min((100 + (ab) * 150/MAX_SKILL), 255))
291 #define GET_TU( ab, md ) (MIN_TU * (md) + (ab) * 20 / MAX_SKILL)
292 
293 #define DOOR_OPEN_REVERSE 4
294 #define GET_SLIDING_DOOR_SHIFT_VECTOR(dir, speed, vecout) \
295  do { const bool reverse = (dir) & DOOR_OPEN_REVERSE; VectorClear(vecout); vecout[dir & 3] = reverse ? -speed : speed; } while (0);
296 
297 /* For a RMA with 50 tiles we need about 1k. So let's take 2k */
298 #define MAX_TILESTRINGS 8
299 #define MAX_CLIENTS 256 /* absolute limit */
300 #define MAX_GENERAL (MAX_CLIENTS*2) /* general config strings */
301 #define MAX_ENTITYSTRINGS 2
302 
309 #define CS_NAME 0
310 #define CS_MAPTITLE 1
311 #define CS_MAXCLIENTS 2
312 #define CS_MAPCHECKSUM 3
313 #define CS_MAXSOLDIERSPERTEAM 4
314 #define CS_MAXSOLDIERSPERPLAYER 5
315 #define CS_ENABLEMORALE 6
316 #define CS_MAXTEAMS 7
317 #define CS_PLAYERCOUNT 8
318 #define CS_VERSION 9
319 #define CS_UFOCHECKSUM 10
320 #define CS_OBJECTAMOUNT 11
321 #define CS_LIGHTMAP 12
322 #define CS_MAPZONE 13
323 #define CS_VICTORY_CONDITIONS 14
324 #define CS_ENTITYSTRING 15
325 #define CS_TILES (CS_ENTITYSTRING+MAX_ENTITYSTRINGS)
326 #define CS_POSITIONS (CS_TILES+MAX_TILESTRINGS)
327 #define CS_MODELS (CS_POSITIONS+MAX_TILESTRINGS)
328 #define CS_PLAYERNAMES (CS_MODELS+MAX_MODELS)
329 #define CS_GENERAL (CS_PLAYERNAMES+MAX_CLIENTS)
330 #define MAX_CONFIGSTRINGS (CS_GENERAL+MAX_GENERAL)
331 
333 #define MAX_GAMETYPES 16
334 
335 #define MAX_CVARLISTINGAMETYPE 16
336 typedef struct cvarlist_s {
337  char name[MAX_VAR];
338  char value[MAX_VAR];
339 } cvarlist_t;
340 
341 typedef struct gametype_s {
342  char id[MAX_VAR];
343  char name[MAX_VAR];
346 } gametype_t;
347 
355 class TerrainDef /* a single entry in the table */
356 {
357 public:
361  char terrainName[20];
363  float rainChance;
364  float snowChance;
365 
366  TerrainDef() : rgbRed(128), rgbGreen(255), rgbBlue(0), survivalChance(2.5f), rainChance(0.2f), snowChance(0.1f) {
367  strcpy(terrainName, "grass");
368  }
369  TerrainDef(byte _rgbRed, byte _rgbGreen, byte _rgbBlue, const char* _terrainName, float _survivalChance, float _rainChance, float _snowChance) {
370  rgbRed = _rgbRed;
371  rgbGreen = _rgbGreen;
372  rgbBlue = _rgbBlue;
373  strcpy(terrainName, _terrainName);
374  survivalChance = _survivalChance;
375  rainChance = _rainChance;
376  snowChance = _snowChance;
377  }
378 };
379 
388 #define MAX_TERRAINDEFS 16
390 {
392 
393  inline const TerrainDef* findByColor(const byte* const color) const {
394  return findByColor(color[0], color[1], color[2]);
395  }
396  inline const TerrainDef* findByColor(byte red, byte green, byte blue) const {
397  for (int i = 0; i < MAX_TERRAINDEFS; i++) {
398  const TerrainDef* p = terrainDefTable[i];
399  if (!p)
400  break;
401  if (p->rgbRed == red && p->rgbGreen == green && p->rgbBlue == blue)
402  return p;
403  }
404  return nullptr;
405  }
406  inline const TerrainDef* findByName(const char* tname) const {
407  for (int i = 0; i < MAX_TERRAINDEFS; i++) {
408  const TerrainDef* p = terrainDefTable[i];
409  if (!p)
410  break;
411  if (Q_streq(p->terrainName, tname))
412  return p;
413  }
414  return nullptr;
415  }
416 public:
418  terrainDefTable[0] = nullptr;
419  }
421  for (int i = 0; i < MAX_TERRAINDEFS; i++) {
422  if (terrainDefTable[i])
423  delete terrainDefTable[i];
424  }
425  }
426 
427  bool add(const TerrainDef* tdef);
428  const char* getWeather (const byte* const color);
429 
435  inline float getSurvivalChance(const byte* const color) const {
436  const TerrainDef* p = findByColor(color);
437  return p ? p->survivalChance : 0.0;
438  }
439  inline float getRainChance(const byte* const color) const {
440  const TerrainDef* p = findByColor(color);
441  return p ? p->rainChance : 0.0;
442  }
443  inline float getSnowChance(const byte* const color) const {
444  const TerrainDef* p = findByColor(color);
445  return p ? p->snowChance : 0.0;
446  }
447 
455  inline const char* getTerrainName(const byte* const color) const {
456  const TerrainDef* p = findByColor(color);
457  return p ? p->terrainName : "grass";
458  }
459 };
460 
461 typedef struct mapDef_s {
462  /* general */
463  char* id;
464  char* mapTheme;
466  char* description;
470  char* size;
471  char* civTeam;
473  /* multiplayer */
474  bool multiplayer;
475  int teams;
479  /* singleplayer */
480  bool campaign;
482  int hwclass;
483  int maxAliens;
484  bool hurtAliens;
497  char* onwin;
498  char* onlose;
499 } mapDef_t;
500 
501 #define MapDef_ForeachCondition(var, condition) \
502  for (int var##__loopvar = 0; (var) = nullptr, var##__loopvar < Com_GetMapDefNumber(); var##__loopvar++) \
503  if ((var) = Com_GetMapDefByIDX(var##__loopvar), !(condition)) {} else
504 
505 #define MapDef_Foreach(var) MapDef_ForeachCondition(var, 1)
506 int Com_GetMapDefNumber(void);
508 mapDef_t* Com_GetMapDefinitionByID(const char* mapDefID);
509 
515 typedef struct csi_s {
518  int numODs;
519 
522 
525  int numIDs;
526 
528  int damNormal, damBlast, damFire;
529  int damShock;
532  int damLaser, damPlasma, damParticle;
536  int damSmoke;
541  int numEDs;
542 
545  int numDTs;
546 
550 
553  const teamDef_t* alienTeams[MAX_TEAMS_PER_MISSION];
554  const chrTemplate_t* alienChrTemplates[MAX_TEAMS_PER_MISSION];
556 
561 
563 
564  ugv_t ugvs[MAX_UGV];
565  int numUGV;
566 
568  int numGTs;
569 
572  int numMDs;
573 
575 } csi_t;
576 
577 extern csi_t csi;
578 
580 #define REJ_PASSWORD_REQUIRED_OR_INCORRECT "Password required or incorrect."
581 #define BAD_RCON_PASSWORD "Bad rcon_password."
582 #define REJ_BANNED "Banned."
583 #define REJ_SERVER_FULL "Server is full."
584 #define REJ_SERVER_VERSION_MISMATCH "The server is running a different version of the game."
585 #define REJ_GAME_ALREADY_STARTED "Game has started already."
586 #define REJ_CONNECTION_REFUSED "Connection refused."
587 
588 #define SV_CMD_CONNECT "connect"
589 #define SV_CMD_RCON "rcon"
590 #define SV_CMD_STATUS "status"
591 #define SV_CMD_TEAMINFO "teaminfo"
592 #define SV_CMD_INFO "info"
593 #define SV_CMD_PRINT "print"
594 
595 /* unused */
596 #define SV_CMD_ACK "ack"
597 #define CL_CMD_PING "ping"
598 #define CL_CMD_ECHO "echo"
599 /* unused end */
600 
601 #define CL_PRECACHE "precache"
602 #define CL_SPAWNSOLDIERS "spawnsoldiers"
603 #define CL_STARTMATCH "startmatch"
604 
605 #define CL_CMD_COMMAND "cmd"
606 #define CL_CMD_CLIENT_CONNECT "client_connect"
607 
608 #define NET_STATE_NEW "new"
609 #define NET_STATE_BEGIN "begin"
610 #define NET_STATE_STARTMATCH "startmatch"
611 #define NET_STATE_DISCONNECT "disconnect"
612 #define NET_STATE_INFO "info"
float victoryBonusPerAlien
Definition: q_shared.h:468
int damPlasma
Definition: q_shared.h:532
int numTeamDefs
Definition: q_shared.h:549
int hwclass
Definition: q_shared.h:482
#define MAX_CHARACTER_TEMPLATES
Definition: chr_shared.h:229
char * missionBriefing
Definition: q_shared.h:469
#define MAX_CVARLISTINGAMETYPE
Definition: q_shared.h:335
int numDTs
Definition: q_shared.h:545
#define MAX_UGV
Definition: chr_shared.h:227
char * size
Definition: q_shared.h:470
linkedList_t * bodyTemplates
Definition: q_shared.h:560
float getSnowChance(const byte *const color) const
Definition: q_shared.h:443
char * mapTheme
Definition: q_shared.h:464
int Com_GetMapDefNumber(void)
float rainChance
Definition: q_shared.h:363
int damStunGas
Definition: q_shared.h:533
linkedList_t * terrains
Definition: q_shared.h:486
byte rgbGreen
Definition: q_shared.h:359
float survivalChance
Definition: q_shared.h:362
linkedList_t * actorNames
Definition: q_shared.h:562
#define MAX_TEAMDEFS
Definition: chr_shared.h:228
linkedList_t * aircraft
Definition: q_shared.h:492
int numChrTemplates
Definition: q_shared.h:559
int damIncendiary
Definition: q_shared.h:537
#define MAX_GAMETYPES
Definition: q_shared.h:333
int numAlienTeams
Definition: q_shared.h:555
TerrainDef(byte _rgbRed, byte _rgbGreen, byte _rgbBlue, const char *_terrainName, float _survivalChance, float _rainChance, float _snowChance)
Definition: q_shared.h:369
char terrainName[20]
Definition: q_shared.h:361
int timesAlreadyUsed
Definition: q_shared.h:490
float getRainChance(const byte *const color) const
Definition: q_shared.h:439
inventory definition for our menus
Definition: inv_shared.h:371
char * victoryCondition
Definition: q_shared.h:467
int numMDs
Definition: q_shared.h:572
int num_cvars
Definition: q_shared.h:345
#define __attribute__(x)
Definition: cxx.h:37
linkedList_t * gameTypes
Definition: q_shared.h:476
#define MAX_IMPLANTS
Definition: inv_shared.h:38
void Sys_Error(const char *error,...) __attribute__((noreturn
bool hurtAliens
Definition: q_shared.h:484
#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&#39;t be recognized.
Definition: q_shared.h:388
int numImplants
Definition: q_shared.h:521
#define MAX_INVDEFS
Definition: inv_shared.h:368
int damStunElectro
Definition: q_shared.h:535
bool storyRelated
Definition: q_shared.h:489
float snowChance
Definition: q_shared.h:364
int numUGV
Definition: q_shared.h:565
#define MAX_DAMAGETYPES
Definition: inv_shared.h:258
#define MAX_VAR
Definition: shared.h:36
int32_t shoot_types_t
Available shoot types - also see the ST_ constants.
Definition: q_shared.h:206
#define MAX_OBJDEFS
Definition: inv_shared.h:37
TerrainDef()
Definition: q_shared.h:366
bool multiplayer
Definition: q_shared.h:474
csi_t csi
Definition: common.cpp:39
event_t
Possible event values.
Definition: q_shared.h:79
player_action_t
Definition: q_shared.h:189
float getSurvivalChance(const byte *const color) const
Translate color value to terrain type and then to survival probability.
Definition: q_shared.h:435
const char * pa_format[PA_NUM_EVENTS]
Player action format strings for netchannel transfer.
Definition: q_shared.cpp:34
int numODs
Definition: q_shared.h:518
int teams
Definition: q_shared.h:475
int numIDs
Definition: q_shared.h:525
char * onwin
Definition: q_shared.h:497
TerrainDefs terrainDefs
Definition: q_shared.h:574
linkedList_t * ufos
Definition: q_shared.h:491
bool add(const TerrainDef *tdef)
Translate color value to terrain type to random weather code.
Definition: q_shared.cpp:53
QGL_EXTERN GLuint index
Definition: r_gl.h:110
int damShock
Definition: q_shared.h:529
static const vec4_t green
Definition: cp_geoscape.cpp:56
mapDef_t * Com_GetMapDefByIDX(int index)
QGL_EXTERN GLfloat f
Definition: r_gl.h:114
common object-, inventory-, container- and firemode-related functions headers.
const TerrainDef * findByColor(byte red, byte green, byte blue) const
Definition: q_shared.h:396
char * onlose
Definition: q_shared.h:498
char * civTeam
Definition: q_shared.h:471
bool campaign
Definition: q_shared.h:480
The csi structure is the client-server-information structure which contains all the static data neede...
Definition: q_shared.h:515
static const vec4_t red
Definition: cp_geoscape.cpp:58
QGL_EXTERN GLint i
Definition: r_gl.h:113
const TerrainDef * findByName(const char *tname) const
Definition: q_shared.h:406
linkedList_t * populations
Definition: q_shared.h:487
const char * getWeather(const byte *const color)
Translate color value to terrain type to random weather code.
Definition: q_shared.cpp:78
const TerrainDef * terrainDefTable[MAX_TERRAINDEFS]
Definition: q_shared.h:391
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
linkedList_t * params
Definition: q_shared.h:465
#define MAX_TEAMS_PER_MISSION
Definition: inv_shared.h:618
camera_type_t
Definition: q_shared.h:178
const TerrainDef * findByColor(const byte *const color) const
Definition: q_shared.h:393
int numEDs
Definition: q_shared.h:541
Defines all attributes of objects used in the inventory.
Definition: inv_shared.h:264
byte rgbRed
Definition: q_shared.h:358
entity_type_t
Definition: q_shared.h:145
Terrain property table entry Terrain is defined by the file map_earth_terrain.png in pics/geoscape...
Definition: q_shared.h:355
byte rgbBlue
Definition: q_shared.h:360
char * id
Definition: q_shared.h:463
#define Q_streq(a, b)
Definition: shared.h:136
~TerrainDefs()
Definition: q_shared.h:420
#define MAX_EQUIPDEFS
Definition: inv_shared.h:603
int damSmoke
Definition: q_shared.h:536
void Com_Printf(const char *msg,...) __attribute__((format(__printf__
uint8_t byte
Definition: ufotypes.h:34
mapDef_t * Com_GetMapDefinitionByID(const char *mapDefID)
Definition: scripts.cpp:3598
char * description
Definition: q_shared.h:466
int numGTs
Definition: q_shared.h:568
#define MAX_MAPDEFS
Definition: inv_shared.h:39
bool singleplayer
Definition: q_shared.h:481
Defines a type of UGV/Robot.
Definition: chr_shared.h:245
void void Com_DPrintf(int level, const char *msg,...) __attribute__((format(__printf__
void format(__printf__, 1, 2)))
level_locals_t level
Definition: g_main.cpp:38
int damNormal
Definition: q_shared.h:528
int maxAliens
Definition: q_shared.h:483
linkedList_t * cultures
Definition: q_shared.h:488
const char * getTerrainName(const byte *const color) const
Translate color value to terrain type.
Definition: q_shared.h:455