Subversion Repositories eduke32

Rev

Rev 2664 | Rev 3267 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1677 terminx 1
//-------------------------------------------------------------------------
2
/*
3
Copyright (C) 2010 EDuke32 developers and contributors
4
 
5
This file is part of EDuke32.
6
 
7
EDuke32 is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License version 2
9
as published by the Free Software Foundation.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 
15
See the GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
*/
21
//-------------------------------------------------------------------------
22
 
23
#ifndef __gamevars_h__
24
#define __gamevars_h__
25
 
1909 terminx 26
#include "gamedef.h"
27
 
1677 terminx 28
// store global game definitions
29
enum GamevarFlags_t {
30
    MAXGAMEVARS        = 2048,       // must be a power of two
31
    MAXVARLABEL        = 26,
32
    GAMEVAR_PERPLAYER  = 0x00000001, // per-player variable
33
    GAMEVAR_PERACTOR   = 0x00000002, // per-actor variable
1857 terminx 34
    GAMEVAR_USER_MASK  = (GAMEVAR_PERPLAYER|GAMEVAR_PERACTOR),
1677 terminx 35
    GAMEVAR_RESET      = 0x00000008, // marks var for to default
36
    GAMEVAR_DEFAULT    = 0x00000100, // allow override
37
    GAMEVAR_SECRET     = 0x00000200, // don't dump...
38
    GAMEVAR_NODEFAULT  = 0x00000400, // don't reset on actor spawn
39
    GAMEVAR_SYSTEM     = 0x00000800, // cannot change mode flags...(only default value)
40
    GAMEVAR_READONLY   = 0x00001000, // values are read-only (no setvar allowed)
41
    GAMEVAR_INTPTR     = 0x00002000, // plValues is a pointer to an int32_t
42
    GAMEVAR_SHORTPTR   = 0x00008000, // plValues is a pointer to a short
43
    GAMEVAR_CHARPTR    = 0x00010000, // plValues is a pointer to a char
1857 terminx 44
    GAMEVAR_PTR_MASK   = (GAMEVAR_INTPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR),
1677 terminx 45
    GAMEVAR_NORESET    = 0x00020000, // var values are not reset when restoring map state
46
    GAMEVAR_SPECIAL    = 0x00040000, // flag for structure member shortcut vars
47
    GAMEVAR_NOMULTI    = 0x00080000, // don't attach to multiplayer packets
1909 terminx 48
    GAMEVAR_NONGLOBAL  = (GAMEVAR_INTPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR|GAMEVAR_SPECIAL|MAXGAMEVARS<<1),
1677 terminx 49
};
50
 
51
enum GamearrayFlags_t {
52
    MAXGAMEARRAYS      = (MAXGAMEVARS>>2), // must be lower than MAXGAMEVARS
53
    MAXARRAYLABEL      = MAXVARLABEL,
54
    GAMEARRAY_NORMAL   = 0,
55
    GAMEARRAY_NORESET  = 0x00000001,
56
};
57
 
58
#pragma pack(push,1)
59
typedef struct {
60
    union {
61
        intptr_t lValue;
62
        intptr_t *plValues;     // array of values when 'per-player', or 'per-actor'
63
    } val;
64
    intptr_t lDefault;
65
    uintptr_t dwFlags;
66
    char *szLabel;
67
} gamevar_t;
68
 
69
typedef struct {
70
    char *szLabel;
2664 terminx 71
    intptr_t *plValues;     // array of values
1677 terminx 72
    intptr_t size;
73
    intptr_t bReset;
74
} gamearray_t;
75
#pragma pack(pop)
76
 
2689 helixhorne 77
#define GAR_ELTSZ (sizeof(aGameArrays[0].plValues[0]))
78
 
1677 terminx 79
extern gamevar_t aGameVars[MAXGAMEVARS];
80
extern gamearray_t aGameArrays[MAXGAMEARRAYS];
81
extern int32_t g_gameVarCount;
82
extern int32_t g_gameArrayCount;
83
 
84
int32_t __fastcall Gv_GetVar(register int32_t id,register int32_t iActor,register int32_t iPlayer);
85
int32_t __fastcall Gv_GetVarX(register int32_t id);
86
int32_t Gv_GetVarByLabel(const char *szGameLabel,int32_t lDefault,int32_t iActor,int32_t iPlayer);
87
int32_t Gv_NewArray(const char *pszLabel,int32_t asize);
2005 terminx 88
int32_t Gv_NewVar(const char *pszLabel,intptr_t lValue,uint32_t dwFlags);
1677 terminx 89
int32_t Gv_ReadSave(int32_t fil,int32_t newbehav);
90
void __fastcall A_ResetVars(register int32_t iActor);
91
void __fastcall Gv_SetVar(register int32_t id,register int32_t lValue,register int32_t iActor,register int32_t iPlayer);
92
void __fastcall Gv_SetVarX(register int32_t id,register int32_t lValue);
93
void G_FreeMapState(int32_t mapnum);
94
void Gv_DumpValues(void);
95
void Gv_Init(void);
96
void Gv_InitWeaponPointers(void);
97
void Gv_RefreshPointers(void);
98
void Gv_RefreshPointers(void);
99
void Gv_ResetSystemDefaults(void);
100
void Gv_ResetVars(void);
101
void Gv_WriteSave(FILE *fil,int32_t newbehav);
1909 terminx 102
 
103
static inline void __fastcall Gv_AddVar(register int32_t id, register int32_t lValue)
104
{
105
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
106
    {
107
    default:
108
        aGameVars[id].val.lValue += lValue;
109
        return;
110
    case GAMEVAR_PERPLAYER:
111
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
112
        aGameVars[id].val.plValues[vm.g_p] += lValue;
113
        return;
114
    case GAMEVAR_PERACTOR:
115
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
116
        aGameVars[id].val.plValues[vm.g_i] += lValue;
117
        return;
118
    case GAMEVAR_INTPTR:
119
        *((int32_t *)aGameVars[id].val.lValue) += (int32_t)lValue;
120
        return;
121
    case GAMEVAR_SHORTPTR:
122
        *((int16_t *)aGameVars[id].val.lValue) += (int16_t)lValue;
123
        return;
124
    case GAMEVAR_CHARPTR:
125
        *((uint8_t *)aGameVars[id].val.lValue) +=(uint8_t)lValue;
126
        return;
127
    }
128
}
129
 
130
static inline void __fastcall Gv_SubVar(register int32_t id, register int32_t lValue)
131
{
132
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
133
    {
134
    default:
135
        aGameVars[id].val.lValue -= lValue;
136
        return;
137
    case GAMEVAR_PERPLAYER:
138
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
139
        aGameVars[id].val.plValues[vm.g_p] -= lValue;
140
        return;
141
    case GAMEVAR_PERACTOR:
142
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
143
        aGameVars[id].val.plValues[vm.g_i] -= lValue;
144
        return;
145
    case GAMEVAR_INTPTR:
146
        *((int32_t *)aGameVars[id].val.lValue) -= (int32_t)lValue;
147
        return;
148
    case GAMEVAR_SHORTPTR:
149
        *((int16_t *)aGameVars[id].val.lValue) -= (int16_t)lValue;
150
        return;
151
    case GAMEVAR_CHARPTR:
152
        *((uint8_t *)aGameVars[id].val.lValue) -=(uint8_t)lValue;
153
        return;
154
    }
155
}
156
 
157
static inline void __fastcall Gv_MulVar(register int32_t id, register int32_t lValue)
158
{
159
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
160
    {
161
    default:
162
        aGameVars[id].val.lValue *= lValue;
163
        return;
164
    case GAMEVAR_PERPLAYER:
165
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
166
        aGameVars[id].val.plValues[vm.g_p] *= lValue;
167
        return;
168
    case GAMEVAR_PERACTOR:
169
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
170
        aGameVars[id].val.plValues[vm.g_i] *= lValue;
171
        return;
172
    case GAMEVAR_INTPTR:
173
        *((int32_t *)aGameVars[id].val.lValue) *= (int32_t)lValue;
174
        return;
175
    case GAMEVAR_SHORTPTR:
176
        *((int16_t *)aGameVars[id].val.lValue) *= (int16_t)lValue;
177
        return;
178
    case GAMEVAR_CHARPTR:
179
        *((uint8_t *)aGameVars[id].val.lValue) *=(uint8_t)lValue;
180
        return;
181
    }
182
}
183
 
184
static inline void __fastcall Gv_DivVar(register int32_t id, register int32_t lValue)
185
{
186
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
187
    {
188
    default:
189
        aGameVars[id].val.lValue /= lValue;
190
        return;
191
    case GAMEVAR_PERPLAYER:
192
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
193
        aGameVars[id].val.plValues[vm.g_p] /= lValue;
194
        return;
195
    case GAMEVAR_PERACTOR:
196
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
197
        aGameVars[id].val.plValues[vm.g_i] /= lValue;
198
        return;
199
    case GAMEVAR_INTPTR:
200
        *((int32_t *)aGameVars[id].val.lValue) /= (int32_t)lValue;
201
        return;
202
    case GAMEVAR_SHORTPTR:
203
        *((int16_t *)aGameVars[id].val.lValue) /= (int16_t)lValue;
204
        return;
205
    case GAMEVAR_CHARPTR:
206
        *((uint8_t *)aGameVars[id].val.lValue) /=(uint8_t)lValue;
207
        return;
208
    }
209
}
210
 
211
static inline void __fastcall Gv_ModVar(register int32_t id, register int32_t lValue)
212
{
213
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
214
    {
215
    default:
216
        aGameVars[id].val.lValue %= lValue;
217
        return;
218
    case GAMEVAR_PERPLAYER:
219
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
220
        aGameVars[id].val.plValues[vm.g_p] %= lValue;
221
        return;
222
    case GAMEVAR_PERACTOR:
223
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
224
        aGameVars[id].val.plValues[vm.g_i] %= lValue;
225
        return;
226
    case GAMEVAR_INTPTR:
227
        *((int32_t *)aGameVars[id].val.lValue) %= (int32_t)lValue;
228
        return;
229
    case GAMEVAR_SHORTPTR:
230
        *((int16_t *)aGameVars[id].val.lValue) %= (int16_t)lValue;
231
        return;
232
    case GAMEVAR_CHARPTR:
233
        *((uint8_t *)aGameVars[id].val.lValue) %=(uint8_t)lValue;
234
        return;
235
    }
236
}
237
 
238
static inline void __fastcall Gv_AndVar(register int32_t id, register int32_t lValue)
239
{
240
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
241
    {
242
    default:
243
        aGameVars[id].val.lValue &= lValue;
244
        return;
245
    case GAMEVAR_PERPLAYER:
246
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
247
        aGameVars[id].val.plValues[vm.g_p] &= lValue;
248
        return;
249
    case GAMEVAR_PERACTOR:
250
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
251
        aGameVars[id].val.plValues[vm.g_i] &= lValue;
252
        return;
253
    case GAMEVAR_INTPTR:
254
        *((int32_t *)aGameVars[id].val.lValue) &= (int32_t)lValue;
255
        return;
256
    case GAMEVAR_SHORTPTR:
257
        *((int16_t *)aGameVars[id].val.lValue) &= (int16_t)lValue;
258
        return;
259
    case GAMEVAR_CHARPTR:
260
        *((uint8_t *)aGameVars[id].val.lValue) &=(uint8_t)lValue;
261
        return;
262
    }
263
}
264
 
265
static inline void __fastcall Gv_XorVar(register int32_t id, register int32_t lValue)
266
{
267
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
268
    {
269
    default:
270
        aGameVars[id].val.lValue ^= lValue;
271
        return;
272
    case GAMEVAR_PERPLAYER:
273
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
274
        aGameVars[id].val.plValues[vm.g_p] ^= lValue;
275
        return;
276
    case GAMEVAR_PERACTOR:
277
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
278
        aGameVars[id].val.plValues[vm.g_i] ^= lValue;
279
        return;
280
    case GAMEVAR_INTPTR:
281
        *((int32_t *)aGameVars[id].val.lValue) ^= (int32_t)lValue;
282
        return;
283
    case GAMEVAR_SHORTPTR:
284
        *((int16_t *)aGameVars[id].val.lValue) ^= (int16_t)lValue;
285
        return;
286
    case GAMEVAR_CHARPTR:
287
        *((uint8_t *)aGameVars[id].val.lValue) ^=(uint8_t)lValue;
288
        return;
289
    }
290
}
291
 
292
static inline void __fastcall Gv_OrVar(register int32_t id, register int32_t lValue)
293
{
294
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
295
    {
296
    default:
297
        aGameVars[id].val.lValue |= lValue;
298
        return;
299
    case GAMEVAR_PERPLAYER:
300
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
301
        aGameVars[id].val.plValues[vm.g_p] |= lValue;
302
        return;
303
    case GAMEVAR_PERACTOR:
304
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
305
        aGameVars[id].val.plValues[vm.g_i] |= lValue;
306
        return;
307
    case GAMEVAR_INTPTR:
308
        *((int32_t *)aGameVars[id].val.lValue) |= (int32_t)lValue;
309
        return;
310
    case GAMEVAR_SHORTPTR:
311
        *((int16_t *)aGameVars[id].val.lValue) |= (int16_t)lValue;
312
        return;
313
    case GAMEVAR_CHARPTR:
314
        *((uint8_t *)aGameVars[id].val.lValue) |=(uint8_t)lValue;
315
        return;
316
    }
317
}
318
 
1677 terminx 319
#endif