1 /**
2 * @file
3 * @brief Header for script parsing functions
4 */
5
6 /*
7 Copyright (C) 2002-2013 UFO: Alien Invasion.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18 See the GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 */
25
26 #pragma once
27
28 #include "common.h"
29
30 #ifndef ALIGN_PTR
31 #define ALIGN_PTR(value,size) (void*)(((uintptr_t)value + (size - 1)) & (~(size - 1)))
32 #endif
33
34 #define MEMBER_SIZEOF(TYPE, MEMBER) sizeof(((TYPE *)0)->MEMBER)
35
36 /**
37 * @brief Allow to add extra bit into the type
38 * @note If valueTypes_t is bigger than 63 the mask must be changed
39 * @sa valueTypes_t
40 */
41 #define V_BASETYPEMASK 0x3F
42
43 /**
44 * @brief possible values for parsing functions
45 * @sa vt_names
46 * @sa vt_sizes
47 */
48 typedef enum {
49 V_NULL,
50 V_BOOL,
51 V_CHAR,
52 V_INT,
53 V_INT2,
54 V_FLOAT,
55 V_POS,
56 V_VECTOR,
57 V_COLOR,
58 V_STRING,
59 V_TRANSLATION_STRING, /**< remove _ but don't translate */
60 V_LONGSTRING, /**< not buffer safe - use this only for menu node data array values! */
61 V_ALIGN,
62 V_BLEND,
63 V_STYLE,
64 V_FADE,
65 V_SHAPE_SMALL, /**< space a weapon allocates in the inventory shapes, w, h */
66 V_SHAPE_BIG, /**< inventory shape, x, y, w, h */
67 V_DAMAGE,
68 V_DATE,
69 V_RELABS, /**< relative (e.g. 1.50) and absolute (e.g. +15) values */
70 V_HUNK_STRING, /**< store the string in a mem pool */
71 V_TEAM, /**< team string to int mapper */
72 V_UFO, /**< @brief Valid ufo types
73 * @note Use the same values for the names as we are already using in the scriptfiles
74 * here, otherwise they are not translatable because they don't appear in the po files
75 * @note Every ufotype (id) that doesn't have nogeoscape set to true must have an assembly
76 * in the ufocrash[dn].ump files */
77 V_UFOCRASHED,
78 V_AIRCRAFTTYPE,
79 V_LIST,
80
81 V_NUM_TYPES,
82 V_ENSURE32BIT = 0xffffffff
83 } valueTypes_t;
84
85 extern const char *const vt_names[];
86
87 /** @brief We need this here for checking the boundaries from script values */
88
89 /** possible align values - see also align_names */
90 typedef enum {
91 ALIGN_UL,
92 ALIGN_UC,
93 ALIGN_UR,
94 ALIGN_CL,
95 ALIGN_CC,
96 ALIGN_CR,
97 ALIGN_LL,
98 ALIGN_LC,
99 ALIGN_LR,
100 ALIGN_UL_RSL,
101 ALIGN_UC_RSL,
102 ALIGN_UR_RSL,
103 ALIGN_CL_RSL,
104 ALIGN_CC_RSL,
105 ALIGN_CR_RSL,
106 ALIGN_LL_RSL,
107 ALIGN_LC_RSL,
108 ALIGN_LR_RSL,
109
110 ALIGN_LAST
111 } align_t;
112
113 /** possible blend modes - see also blend_names */
114 typedef enum {
115 BLEND_REPLACE,
116 BLEND_ONE,
117 BLEND_BLEND,
118 BLEND_ADD,
119 BLEND_FILTER,
120 BLEND_INVFILTER,
121
122 BLEND_LAST
123 } blend_t;
124
125 typedef enum {
126 STYLE_FACING, /**< rotates a sprint into the camera direction */
127 STYLE_ROTATED, /**< use the particle angles vector */
128 STYLE_BEAM,
129 STYLE_LINE,
130 STYLE_AXIS,
131 STYLE_CIRCLE,
132
133 STYLE_LAST
134 } style_t;
135
136 typedef enum {
137 FADE_NONE,
138 FADE_IN,
139 FADE_OUT,
140 FADE_SIN,
141 FADE_SAW,
142
143 FADE_LAST
144 } fade_t;
145
146 /**
147 * @brief All different types of UFOs.
148 */
149 typedef enum {
150 UFO_SCOUT,
151 UFO_FIGHTER,
152 UFO_HARVESTER,
153 UFO_CORRUPTER,
154 UFO_BOMBER,
155 UFO_CARRIER,
156 UFO_SUPPLY,
157 UFO_GUNBOAT,
158 UFO_RIPPER,
159 UFO_MOTHERSHIP,
160
161 UFO_MAX
162 } ufoType_t;
163
164 extern const char *const align_names[];
165 extern const char *const blend_names[];
166 extern const char *const style_names[];
167 extern const char *const fade_names[];
168 extern const char *const longlines_names[];
169 extern const char *const air_slot_type_strings[];
170
171 /** used e.g. in our parsers */
172 typedef struct value_s {
173 const char *string;
174 valueTypes_t type;
175 size_t ofs;
176 size_t size;
177 } value_t;
178
Com_GetValue(void * const object,value_t const * const value)179 template<typename T> inline T& Com_GetValue(void* const object, value_t const* const value)
180 {
181 return *reinterpret_cast<T*>(reinterpret_cast<byte*>(object) + value->ofs);
182 }
183
Com_GetValue(void const * const object,value_t const * const value)184 template<typename T> inline T const& Com_GetValue(void const* const object, value_t const* const value)
185 {
186 return Com_GetValue<T>(const_cast<void*>(object), value);
187 }
188
189 typedef enum {
190 RESULT_ERROR = -1,
191 RESULT_WARNING = -2,
192 RESULT_OK = 0
193 } resultStatus_t;
194
195 #ifdef DEBUG
196 int Com_SetValueDebug(void *base, const void *set, valueTypes_t type, int ofs, size_t size, const char* file, int line);
197 #define Com_SetValue(base, set, type, ofs, size) Com_SetValueDebug(base, set, type, ofs, size, __FILE__, __LINE__)
198 #else
199 int Com_SetValue(void *base, const void *set, valueTypes_t type, int ofs, size_t size);
200 #endif
201 int Com_EParseValue(void *base, const char *token, valueTypes_t type, int ofs, size_t size);
202 bool Com_ParseBlock(const char *name, const char** text, void *base, const value_t *values, memPool_t *mempool);
203 bool Com_ParseBlockToken(const char *name, const char** text, void *base, const value_t *values, memPool_t *mempool, const char *token);
204 bool Com_ParseList(const char** text, linkedList_t** list);
205 void *Com_AlignPtr(const void *memory, valueTypes_t type);
206 const char *Com_ValueToStr(const void *base, const valueTypes_t type, const int ofs);
207 const char *Com_GetLastParseError(void);
208 resultStatus_t Com_ParseValue(void *base, const char *token, valueTypes_t type, int ofs, size_t size, size_t *writtenBytes);
209 bool Com_ParseBoolean(const char *token);
210
211 /*==============================================================
212 SCRIPT PARSING
213 ==============================================================*/
214
215 extern const char *const name_strings[];
216
217 #define SND_VOLUME_FOOTSTEPS 0.4f
218
219 /** @brief Different terrain definitions for footsteps and particles */
220 typedef struct terrainType_s {
221 const char *texture; /**< script id is the texture name/path */
222 const char *footstepSound; /**< sound to play when walking on this terrain type */
223 const char *particle; /**< particle to spawn when walking on this type of terrain */
224 float bounceFraction; /**< the impact on the bounce fraction given in the weapon definition */
225 float footstepVolume; /**< footstep sound volume */
226 struct terrainType_s *hash_next; /**< next entry in the hash list */
227 } terrainType_t;
228
229 const terrainType_t *Com_GetTerrainType(const char *textureName);
230
231 /**
232 * @brief list of script aliases to register
233 * @note must be terminated with a nullptr ({nullptr, -1}) entry!
234 * @sa saveEmployeeConstants[]
235 */
236 typedef struct constListEntry_s {
237 const char *name;
238 int value;
239 } constListEntry_t;
240
241 bool Com_GetConstInt(const char *name, int *value);
242 bool Com_GetConstIntFromNamespace(const char *space, const char *variable, int *value);
243 const char* Com_GetConstVariable(const char *space, int value);
244 bool Com_UnregisterConstVariable(const char *name);
245 void Com_RegisterConstInt(const char *name, int value);
246 void Com_RegisterConstList(const constListEntry_t constList[]);
247 bool Com_UnregisterConstList(const constListEntry_t constList[]);
248
249 void Com_ParseScripts(bool onlyServer);
250 const char *Com_EParse(const char** text, const char *errhead, const char *errinfo, char *target = 0, size_t size = 0);
251 const char *Com_GetRandomMapAssemblyNameForCraft(const char *craftID);
252 const char *Com_GetRandomMapAssemblyNameForCrashedCraft(const char *craftID);
253 ufoType_t Com_UFOShortNameToID(const char *token);
254 const char* Com_UFOTypeToShortName(ufoType_t type);
255 const char* Com_UFOCrashedTypeToShortName(ufoType_t type);
256 int Com_GetScriptChecksum(void);
257 void Com_Shutdown(void);
258
259 #include "../game/q_shared.h"
260
261 const ugv_t *Com_GetUGVByIDSilent(const char *ugvID);
262 const ugv_t *Com_GetUGVByID(const char *ugvID);
263 const char* Com_DropShipTypeToShortName(humanAircraftType_t type);
264 humanAircraftType_t Com_DropShipShortNameToID(const char *token);
265 void Com_GetCharacterValues(const char *teamDefition, character_t *chr);
266 bool Com_GetCharacterModel(character_t *chr);
267 const char* Com_GetActorSound(teamDef_t *td, int gender, actorSound_t soundType);
268 const teamDef_t *Com_GetTeamDefinitionByID(const char *team);
269 const chrTemplate_t *Com_GetCharacterTemplateByID(const char *chrTemplate);
270