1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 2016 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 */
21 //-------------------------------------------------------------------------
22 
23 #ifndef gamedef_h_
24 #define gamedef_h_
25 
26 #include "actors.h"
27 #include "build.h"  // hashtable_t
28 #include "cheats.h"
29 #include "common.h"  // tokenlist
30 #include "player.h"  // projectile_t
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 enum
37 {
38     LABEL_ANY    = -1,
39     LABEL_DEFINE = 1,
40     LABEL_STATE  = 2,
41     LABEL_ACTOR  = 4,
42     LABEL_ACTION = 8,
43     LABEL_AI     = 16,
44     LABEL_MOVE   = 32,
45     LABEL_EVENT  = 0x40,
46 };
47 
48 #define LABEL_HASPARM2  1
49 #define LABEL_ISSTRING  2
50 
51 // "magic" number for { and }, overrides line number in compiled code for later detection
52 #define VM_IFELSE_MAGIC 31337
53 #define VM_INSTMASK 0xfff
54 #define VM_DECODE_LINE_NUMBER(xxx) ((int)((xxx) >> 12))
55 
56 #define C_CUSTOMERROR(Text, ...)                                                                                                           \
57     do                                                                                                                                     \
58     {                                                                                                                                      \
59         C_ReportError(-1);                                                                                                                 \
60         initprintf("%s:%d: error: " Text "\n", g_scriptFileName, g_lineNumber, ##__VA_ARGS__);                                             \
61         g_errorCnt++;                                                                                                                      \
62     } while (0)
63 
64 #define C_CUSTOMWARNING(Text, ...)                                                                                                         \
65     do                                                                                                                                     \
66     {                                                                                                                                      \
67         C_ReportError(-1);                                                                                                                 \
68         initprintf("%s:%d: warning: " Text "\n", g_scriptFileName, g_lineNumber, ##__VA_ARGS__);                                           \
69         g_warningCnt++;                                                                                                                    \
70     } while (0)
71 
72 extern intptr_t const * insptr;
73 extern void VM_ScriptInfo(intptr_t const *ptr, int range);
74 
75 extern hashtable_t h_gamefuncs;
76 
77 extern hashtable_t h_gamevars;
78 extern hashtable_t h_labels;
79 
80 extern int32_t g_aimAngleVarID;   // var ID of "AUTOAIMANGLE"
81 extern int32_t g_angRangeVarID;   // var ID of "ANGRANGE"
82 extern int32_t g_returnVarID;     // var ID of "RETURN"
83 extern int32_t g_weaponVarID;     // var ID of "WEAPON"
84 extern int32_t g_worksLikeVarID;  // var ID of "WORKSLIKE"
85 extern int32_t g_zRangeVarID;     // var ID of "ZRANGE"
86 
87 #include "events_defs.h"
88 extern intptr_t apScriptEvents[MAXEVENTS];
89 
90 extern char g_scriptFileName[BMAX_PATH];
91 
92 extern const uint32_t CheatFunctionFlags[];
93 extern const uint8_t  CheatFunctionIDs[];
94 
95 extern int32_t g_errorCnt;
96 extern int32_t g_lineNumber;
97 extern int32_t g_scriptVersion;
98 extern int32_t g_totalLines;
99 extern int32_t g_warningCnt;
100 extern uint32_t g_scriptcrc;
101 extern int32_t otherp;
102 
103 extern intptr_t *g_scriptPtr;
104 
105 typedef struct
106 {
107     const char *name;
108     int lId, flags, maxParm2;
109 } memberlabel_t;
110 
111 extern const memberlabel_t ActorLabels[];
112 extern const memberlabel_t InputLabels[];
113 extern const memberlabel_t PalDataLabels[];
114 extern const memberlabel_t PlayerLabels[];
115 extern const memberlabel_t ProjectileLabels[];
116 extern const memberlabel_t SectorLabels[];
117 extern const memberlabel_t TileDataLabels[];
118 extern const memberlabel_t TsprLabels[];
119 extern const memberlabel_t UserdefsLabels[];
120 extern const memberlabel_t WallLabels[];
121 
122 int32_t C_AllocQuote(int32_t qnum);
123 void C_InitQuotes(void);
124 
125 extern int32_t g_numProjectiles;
126 
127 typedef struct {
128     int spriteNum;
129     int playerNum;
130     int playerDist;
131     int flags;
132 
133     union {
134         spritetype * pSprite;
135         uspritetype *pUSprite;
136     };
137 
138     int32_t *     pData;
139     DukePlayer_t *pPlayer;
140     actor_t *     pActor;
141 } vmstate_t;
142 
143 extern vmstate_t vm;
144 
145 void G_DoGameStartup(const int32_t *params);
146 void C_DefineMusic(int volumeNum, int levelNum, const char *fileName);
147 
148 void C_DefineVolumeFlags(int32_t vol, int32_t flags);
149 void C_UndefineVolume(int32_t vol);
150 void C_UndefineSkill(int32_t skill);
151 void C_UndefineLevel(int32_t vol, int32_t lev);
152 void C_ReportError(int32_t iError);
153 void C_Compile(const char *filenam);
154 
155 extern int32_t g_errorLineNum;
156 extern int32_t g_tw;
157 
158 typedef struct {
159     const char* token;
160     int32_t val;
161 } tokenmap_t;
162 
163 extern char const * VM_GetKeywordForID(int32_t id);
164 
165 enum ScriptError_t
166 {
167     ERROR_CLOSEBRACKET,
168     ERROR_EXCEEDSMAXTILES,
169     ERROR_EXPECTEDKEYWORD,
170     ERROR_FOUNDWITHIN,
171     ERROR_ISAKEYWORD,
172     ERROR_OPENBRACKET,
173     ERROR_NOTAGAMEVAR,
174     ERROR_PARAMUNDEFINED,
175     ERROR_SYNTAXERROR,
176     ERROR_VARREADONLY,
177     ERROR_VARTYPEMISMATCH,
178     WARNING_BADGAMEVAR,
179     WARNING_DUPLICATEDEFINITION,
180     WARNING_LABELSONLY,
181     WARNING_VARMASKSKEYWORD,
182 };
183 
184 enum ScriptKeywords_t
185 {
186     CON_ELSE,               // 0
187     CON_ACTOR,              // 1
188     CON_ADDAMMO,            // 2
189     CON_IFRND,              // 3
190     CON_ENDA,               // 4
191     CON_IFCANSEE,           // 5
192     CON_IFHITWEAPON,        // 6
193     CON_ACTION,             // 7
194     CON_IFPDISTL,           // 8
195     CON_IFPDISTG,           // 9
196     CON_DEFINELEVELNAME,    // 10
197     CON_STRENGTH,           // 11
198     CON_BREAK,              // 12
199     CON_SHOOT,              // 13
200     CON_PALFROM,            // 14
201     CON_SOUND,              // 15
202     CON_FALL,               // 16
203     CON_STATE,              // 17
204     CON_ENDS,               // 18
205     CON_DEFINE,             // 19
206     CON_COMMENT,            // 20 deprecated
207     CON_IFAI,               // 21
208     CON_KILLIT,             // 22
209     CON_ADDWEAPON,          // 23
210     CON_AI,                 // 24
211     CON_ADDPHEALTH,         // 25
212     CON_IFDEAD,             // 26
213     CON_IFSQUISHED,         // 27
214     CON_SIZETO,             // 28
215     CON_LEFTBRACE,          // 29
216     CON_RIGHTBRACE,         // 30
217     CON_SPAWN,              // 31
218     CON_MOVE,               // 32
219     CON_IFWASWEAPON,        // 33
220     CON_IFACTION,           // 34
221     CON_IFACTIONCOUNT,      // 35
222     CON_RESETACTIONCOUNT,   // 36
223     CON_DEBRIS,             // 37
224     CON_PSTOMP,             // 38
225     CON_BLOCKCOMMENT,       // 39 deprecated
226     CON_CSTAT,              // 40
227     CON_IFMOVE,             // 41
228     CON_RESETPLAYER,        // 42
229     CON_IFONWATER,          // 43
230     CON_IFINWATER,          // 44
231     CON_IFCANSHOOTTARGET,   // 45
232     CON_IFCOUNT,            // 46
233     CON_RESETCOUNT,         // 47
234     CON_ADDINVENTORY,       // 48
235     CON_IFACTORNOTSTAYPUT,  // 49
236     CON_HITRADIUS,          // 50
237     CON_IFP,                // 51
238     CON_COUNT,              // 52
239     CON_IFACTOR,            // 53
240     CON_MUSIC,              // 54
241     CON_INCLUDE,            // 55
242     CON_IFSTRENGTH,         // 56
243     CON_DEFINESOUND,        // 57
244     CON_GUTS,               // 58
245     CON_IFSPAWNEDBY,        // 59
246     CON_GAMESTARTUP,        // 60
247     CON_WACKPLAYER,         // 61
248     CON_IFGAPZL,            // 62
249     CON_IFHITSPACE,         // 63
250     CON_IFOUTSIDE,          // 64
251     CON_IFMULTIPLAYER,      // 65
252     CON_OPERATE,            // 66
253     CON_IFINSPACE,          // 67
254     CON_DEBUG,              // 68
255     CON_ENDOFGAME,          // 69
256     CON_IFBULLETNEAR,       // 70
257     CON_IFRESPAWN,          // 71
258     CON_IFFLOORDISTL,       // 72
259     CON_IFCEILINGDISTL,     // 73
260     CON_SPRITEPAL,          // 74
261     CON_IFPINVENTORY,       // 75
262     CON_BETANAME,           // 76
263     CON_CACTOR,             // 77
264     CON_IFPHEALTHL,         // 78
265     CON_DEFINEQUOTE,        // 79
266     CON_QUOTE,              // 80
267     CON_IFINOUTERSPACE,     // 81
268     CON_IFNOTMOVING,        // 82
269     CON_RESPAWNHITAG,       // 83
270     CON_TIP,                // 84
271     CON_IFSPRITEPAL,        // 85
272     CON_MONEY,              // 86
273     CON_SOUNDONCE,          // 87
274     CON_ADDKILLS,           // 88
275     CON_STOPSOUND,          // 89
276     CON_IFAWAYFROMWALL,     // 90
277     CON_IFCANSEETARGET,     // 91
278     CON_GLOBALSOUND,        // 92
279     CON_LOTSOFGLASS,        // 93
280     CON_IFGOTWEAPONCE,      // 94
281     CON_GETLASTPAL,         // 95
282     CON_PKICK,              // 96
283     CON_MIKESND,            // 97
284     CON_USERACTOR,          // 98
285     CON_SIZEAT,             // 99
286     CON_ADDSTRENGTH,        // 100
287     CON_CSTATOR,            // 101
288     CON_MAIL,               // 102
289     CON_PAPER,              // 103
290     CON_TOSSWEAPON,         // 104
291     CON_SLEEPTIME,          // 105
292     CON_NULLOP,             // 106
293     CON_DEFINEVOLUMENAME,   // 107
294     CON_DEFINESKILLNAME,    // 108
295     CON_IFNOSOUNDS,         // 109
296     CON_CLIPDIST,           // 110
297     CON_IFANGDIFFL,         // 111
298     CON_IFNOCOVER,          // 112
299     CON_IFHITTRUCK,         // 113
300     CON_IFTIPCOW,           // 114
301     CON_ISDRUNK,            // 115
302     CON_ISEAT,              // 116
303     CON_DESTROYIT,          // 117
304     CON_LARRYBIRD,          // 118
305     CON_STRAFELEFT,         // 119
306     CON_STRAFERIGHT,        // 120
307     CON_IFACTORHEALTHG,     // 121
308     CON_IFACTORHEALTHL,     // 122
309     CON_SLAPPLAYER,         // 123
310     CON_IFPDRUNK,           // 124
311     CON_TEARITUP,           // 125
312     CON_SMACKBUBBA,         // 126
313     CON_SOUNDTAGONCE,       // 127
314     CON_SOUNDTAG,           // 128
315     CON_IFSOUNDID,          // 129
316     CON_IFSOUNDDIST,        // 130
317     CON_IFONMUD,            // 131
318     CON_IFCOOP,             // 132
319     CON_IFMOTOFAST,         // 133
320     CON_IFWIND,             // 134
321     CON_SMACKSPRITE,        // 135
322     CON_IFONMOTO,           // 136
323     CON_IFONBOAT,           // 137
324     CON_FAKEBUBBA,          // 138
325     CON_MAMATRIGGER,        // 139
326     CON_MAMASPAWN,          // 140
327     CON_MAMAQUAKE,          // 141
328     CON_MAMAEND,            // 142
329     CON_NEWPIC,             // 143
330     CON_GARYBANJO,          // 144
331     CON_MOTOLOOPSND,        // 145
332     CON_IFSIZEDOWN,         // 146
333     CON_RNDMOVE,            // 147
334     CON_GAMEVAR,            // 148
335     CON_IFVARL,             // 149
336     CON_IFVARG,             // 150
337     CON_SETVARVAR,          // 151
338     CON_SETVAR,             // 152
339     CON_ADDVARVAR,          // 153
340     CON_ADDVAR,             // 154
341     CON_IFVARVARL,          // 155
342     CON_IFVARVARG,          // 156
343     CON_ADDLOGVAR,          // 157
344     CON_ONEVENT,            // 158
345     CON_ENDEVENT,           // 159
346     CON_IFVARE,             // 160
347     CON_IFVARVARE,          // 161
348     CON_IFFINDNEWSPOT,      // 162
349     CON_LEAVETRAX,          // 163
350     CON_LEAVEDROPPINGS,     // 164
351     CON_DEPLOYBIAS,         // 165
352     CON_IFPUPWIND,          // 166
353     CON_END
354 };
355 // KEEPINSYNC with the keyword list in lunatic/con_lang.lua
356 
357 #ifdef __cplusplus
358 }
359 #endif
360 
361 #endif // gamedef_h_
362