Subversion Repositories eduke32

Rev

Rev 1857 | Rev 2005 | 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;
71
    int32_t *plValues;     // array of values
72
    intptr_t size;
73
    intptr_t bReset;
74
} gamearray_t;
75
#pragma pack(pop)
76
 
77
extern gamevar_t aGameVars[MAXGAMEVARS];
78
extern gamearray_t aGameArrays[MAXGAMEARRAYS];
79
extern int32_t g_gameVarCount;
80
extern int32_t g_gameArrayCount;
81
 
82
int32_t __fastcall Gv_GetVar(register int32_t id,register int32_t iActor,register int32_t iPlayer);
83
int32_t __fastcall Gv_GetVarX(register int32_t id);
84
int32_t Gv_GetVarByLabel(const char *szGameLabel,int32_t lDefault,int32_t iActor,int32_t iPlayer);
85
int32_t Gv_NewArray(const char *pszLabel,int32_t asize);
86
int32_t Gv_NewVar(const char *pszLabel,int32_t lValue,uint32_t dwFlags);
87
int32_t Gv_ReadSave(int32_t fil,int32_t newbehav);
88
void __fastcall A_ResetVars(register int32_t iActor);
89
void __fastcall Gv_SetVar(register int32_t id,register int32_t lValue,register int32_t iActor,register int32_t iPlayer);
90
void __fastcall Gv_SetVarX(register int32_t id,register int32_t lValue);
91
void G_FreeMapState(int32_t mapnum);
92
void Gv_DumpValues(void);
93
void Gv_Init(void);
94
void Gv_InitWeaponPointers(void);
95
void Gv_RefreshPointers(void);
96
void Gv_RefreshPointers(void);
97
void Gv_ResetSystemDefaults(void);
98
void Gv_ResetVars(void);
99
void Gv_WriteSave(FILE *fil,int32_t newbehav);
1909 terminx 100
 
101
static inline void __fastcall Gv_AddVar(register int32_t id, register int32_t lValue)
102
{
103
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
104
    {
105
    default:
106
        aGameVars[id].val.lValue += lValue;
107
        return;
108
    case GAMEVAR_PERPLAYER:
109
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
110
        aGameVars[id].val.plValues[vm.g_p] += lValue;
111
        return;
112
    case GAMEVAR_PERACTOR:
113
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
114
        aGameVars[id].val.plValues[vm.g_i] += lValue;
115
        return;
116
    case GAMEVAR_INTPTR:
117
        *((int32_t *)aGameVars[id].val.lValue) += (int32_t)lValue;
118
        return;
119
    case GAMEVAR_SHORTPTR:
120
        *((int16_t *)aGameVars[id].val.lValue) += (int16_t)lValue;
121
        return;
122
    case GAMEVAR_CHARPTR:
123
        *((uint8_t *)aGameVars[id].val.lValue) +=(uint8_t)lValue;
124
        return;
125
    }
126
}
127
 
128
static inline void __fastcall Gv_SubVar(register int32_t id, register int32_t lValue)
129
{
130
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
131
    {
132
    default:
133
        aGameVars[id].val.lValue -= lValue;
134
        return;
135
    case GAMEVAR_PERPLAYER:
136
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
137
        aGameVars[id].val.plValues[vm.g_p] -= lValue;
138
        return;
139
    case GAMEVAR_PERACTOR:
140
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
141
        aGameVars[id].val.plValues[vm.g_i] -= lValue;
142
        return;
143
    case GAMEVAR_INTPTR:
144
        *((int32_t *)aGameVars[id].val.lValue) -= (int32_t)lValue;
145
        return;
146
    case GAMEVAR_SHORTPTR:
147
        *((int16_t *)aGameVars[id].val.lValue) -= (int16_t)lValue;
148
        return;
149
    case GAMEVAR_CHARPTR:
150
        *((uint8_t *)aGameVars[id].val.lValue) -=(uint8_t)lValue;
151
        return;
152
    }
153
}
154
 
155
static inline void __fastcall Gv_MulVar(register int32_t id, register int32_t lValue)
156
{
157
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
158
    {
159
    default:
160
        aGameVars[id].val.lValue *= lValue;
161
        return;
162
    case GAMEVAR_PERPLAYER:
163
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
164
        aGameVars[id].val.plValues[vm.g_p] *= lValue;
165
        return;
166
    case GAMEVAR_PERACTOR:
167
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
168
        aGameVars[id].val.plValues[vm.g_i] *= lValue;
169
        return;
170
    case GAMEVAR_INTPTR:
171
        *((int32_t *)aGameVars[id].val.lValue) *= (int32_t)lValue;
172
        return;
173
    case GAMEVAR_SHORTPTR:
174
        *((int16_t *)aGameVars[id].val.lValue) *= (int16_t)lValue;
175
        return;
176
    case GAMEVAR_CHARPTR:
177
        *((uint8_t *)aGameVars[id].val.lValue) *=(uint8_t)lValue;
178
        return;
179
    }
180
}
181
 
182
static inline void __fastcall Gv_DivVar(register int32_t id, register int32_t lValue)
183
{
184
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
185
    {
186
    default:
187
        aGameVars[id].val.lValue /= lValue;
188
        return;
189
    case GAMEVAR_PERPLAYER:
190
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
191
        aGameVars[id].val.plValues[vm.g_p] /= lValue;
192
        return;
193
    case GAMEVAR_PERACTOR:
194
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
195
        aGameVars[id].val.plValues[vm.g_i] /= lValue;
196
        return;
197
    case GAMEVAR_INTPTR:
198
        *((int32_t *)aGameVars[id].val.lValue) /= (int32_t)lValue;
199
        return;
200
    case GAMEVAR_SHORTPTR:
201
        *((int16_t *)aGameVars[id].val.lValue) /= (int16_t)lValue;
202
        return;
203
    case GAMEVAR_CHARPTR:
204
        *((uint8_t *)aGameVars[id].val.lValue) /=(uint8_t)lValue;
205
        return;
206
    }
207
}
208
 
209
static inline void __fastcall Gv_ModVar(register int32_t id, register int32_t lValue)
210
{
211
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
212
    {
213
    default:
214
        aGameVars[id].val.lValue %= lValue;
215
        return;
216
    case GAMEVAR_PERPLAYER:
217
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
218
        aGameVars[id].val.plValues[vm.g_p] %= lValue;
219
        return;
220
    case GAMEVAR_PERACTOR:
221
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
222
        aGameVars[id].val.plValues[vm.g_i] %= lValue;
223
        return;
224
    case GAMEVAR_INTPTR:
225
        *((int32_t *)aGameVars[id].val.lValue) %= (int32_t)lValue;
226
        return;
227
    case GAMEVAR_SHORTPTR:
228
        *((int16_t *)aGameVars[id].val.lValue) %= (int16_t)lValue;
229
        return;
230
    case GAMEVAR_CHARPTR:
231
        *((uint8_t *)aGameVars[id].val.lValue) %=(uint8_t)lValue;
232
        return;
233
    }
234
}
235
 
236
static inline void __fastcall Gv_AndVar(register int32_t id, register int32_t lValue)
237
{
238
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
239
    {
240
    default:
241
        aGameVars[id].val.lValue &= lValue;
242
        return;
243
    case GAMEVAR_PERPLAYER:
244
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
245
        aGameVars[id].val.plValues[vm.g_p] &= lValue;
246
        return;
247
    case GAMEVAR_PERACTOR:
248
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
249
        aGameVars[id].val.plValues[vm.g_i] &= lValue;
250
        return;
251
    case GAMEVAR_INTPTR:
252
        *((int32_t *)aGameVars[id].val.lValue) &= (int32_t)lValue;
253
        return;
254
    case GAMEVAR_SHORTPTR:
255
        *((int16_t *)aGameVars[id].val.lValue) &= (int16_t)lValue;
256
        return;
257
    case GAMEVAR_CHARPTR:
258
        *((uint8_t *)aGameVars[id].val.lValue) &=(uint8_t)lValue;
259
        return;
260
    }
261
}
262
 
263
static inline void __fastcall Gv_XorVar(register int32_t id, register int32_t lValue)
264
{
265
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
266
    {
267
    default:
268
        aGameVars[id].val.lValue ^= lValue;
269
        return;
270
    case GAMEVAR_PERPLAYER:
271
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
272
        aGameVars[id].val.plValues[vm.g_p] ^= lValue;
273
        return;
274
    case GAMEVAR_PERACTOR:
275
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
276
        aGameVars[id].val.plValues[vm.g_i] ^= lValue;
277
        return;
278
    case GAMEVAR_INTPTR:
279
        *((int32_t *)aGameVars[id].val.lValue) ^= (int32_t)lValue;
280
        return;
281
    case GAMEVAR_SHORTPTR:
282
        *((int16_t *)aGameVars[id].val.lValue) ^= (int16_t)lValue;
283
        return;
284
    case GAMEVAR_CHARPTR:
285
        *((uint8_t *)aGameVars[id].val.lValue) ^=(uint8_t)lValue;
286
        return;
287
    }
288
}
289
 
290
static inline void __fastcall Gv_OrVar(register int32_t id, register int32_t lValue)
291
{
292
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK))
293
    {
294
    default:
295
        aGameVars[id].val.lValue |= lValue;
296
        return;
297
    case GAMEVAR_PERPLAYER:
298
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return;
299
        aGameVars[id].val.plValues[vm.g_p] |= lValue;
300
        return;
301
    case GAMEVAR_PERACTOR:
302
        if ((unsigned)vm.g_i > MAXSPRITES-1) return;
303
        aGameVars[id].val.plValues[vm.g_i] |= lValue;
304
        return;
305
    case GAMEVAR_INTPTR:
306
        *((int32_t *)aGameVars[id].val.lValue) |= (int32_t)lValue;
307
        return;
308
    case GAMEVAR_SHORTPTR:
309
        *((int16_t *)aGameVars[id].val.lValue) |= (int16_t)lValue;
310
        return;
311
    case GAMEVAR_CHARPTR:
312
        *((uint8_t *)aGameVars[id].val.lValue) |=(uint8_t)lValue;
313
        return;
314
    }
315
}
316
 
1677 terminx 317
#endif