ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
loop_script.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * 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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ULTIMA8_WORLD_LOOPSCRIPT_H
23 #define ULTIMA8_WORLD_LOOPSCRIPT_H
24 
25 // Script Tokens
26 #define LS_TOKEN_AND '&'
27 #define LS_TOKEN_OR '+'
28 #define LS_TOKEN_NOT '!'
29 #define LS_TOKEN_EQUAL '='
30 #define LS_TOKEN_GREATER '>'
31 #define LS_TOKEN_LESS '<'
32 #define LS_TOKEN_GEQUAL ']'
33 #define LS_TOKEN_LEQUAL '['
34 
35 #define LS_TOKEN_INT '%'
36 
37 #define LS_TOKEN_TRUE 1
38 #define LS_TOKEN_FALSE 0
39 #define LS_TOKEN_NPCNUM '#'
40 #define LS_TOKEN_STATUS '?'
41 #define LS_TOKEN_Q '*'
42 #define LS_TOKEN_FAMILY ':'
43 #define LS_TOKEN_SHAPE '@'
44 #define LS_TOKEN_FRAME '`'
45 
46 #define LS_TOKEN_END '$'
47 
48 //
49 // Generating Loopscripts aka Abusing the C Preprocessor
50 //
51 
52 //
53 // Highlevel Function Like Scripts
54 //
55 // Usage:
56 //
57 // LOOPSCRIPT(script, LS_AND(LS_SHAPE_EQUAL(73), LS_Q_EQUAL(4)));
58 //
59 
60 //
61 // Tokenized Scripts
62 //
63 // Usage:
64 //
65 // const uint8 script[] = {
66 // LS_TOKEN_SHAPE,
67 // LS_TOKEN_INT,
68 // LS_CONSTANT(73),
69 // LS_TOKEN_EQUAL,
70 // LS_TOKEN_Q,
71 // LS_TOKEN_INT,
72 // LS_CONSTANT(4),
73 // LS_TOKEN_EQUAL,
74 // LS_TOKEN_AND,
75 // LS_TOKEN_END
76 // };
77 //
78 
79 #define LOOPSCRIPT(name,tokens) const uint8 name[] = { tokens, LS_TOKEN_END }
80 
81 #define LS_CONSTANT(val) ((uint8)(val)), ((uint8)((val)>>8))
82 #define LS_INT(val) LS_TOKEN_INT, LS_CONSTANT(val)
83 
84 #define LS_OP(left, op, right) left, right, op
85 
86 #define LS_NOT(left) left, LS_TOKEN_NOT
87 #define LS_AND(left,right) left, right, LS_TOKEN_AND
88 #define LS_OR(left,right) left, right, LS_TOKEN_OR
89 
90 #define LS_EQUAL(left,right) left, right, LS_TOKEN_EQUAL
91 #define LS_LEQUAL(left,right) left, right, LS_TOKEN_LEQUAL
92 #define LS_GEQUAL(left,right) left, right, LS_TOKEN_GEQUAL
93 #define LS_LESS(left,right) left, right, LS_TOKEN_LESS
94 #define LS_GREATER(left,right) left, right, LS_TOKEN_GREATER
95 
96 #define LS_FAMILY_EQUAL(val) LS_EQUAL(LS_TOKEN_FAMILY,LS_INT(val))
97 #define LS_NPCNUM_EQUAL(val) LS_EQUAL(LS_TOKEN_NPCNUM,LS_INT(val))
98 #define LS_STATUS_EQUAL(val) LS_EQUAL(LS_TOKEN_STATUS,LS_INT(val))
99 #define LS_Q_EQUAL(val) LS_EQUAL(LS_TOKEN_Q,LS_INT(val))
100 
101 #define LS_SHAPE_EQUAL(val) LS_EQUAL(LS_TOKEN_SHAPE,LS_INT(val))
102 #define LS_SHAPE_EQUAL1(a) LS_TOKEN_SHAPE+1, LS_CONSTANT(a)
103 #define LS_SHAPE_EQUAL2(a,b) LS_TOKEN_SHAPE+2, LS_CONSTANT(a), LS_CONSTANT(b)
104 #define LS_SHAPE_EQUAL3(a,b,c) LS_TOKEN_SHAPE+3, LS_CONSTANT(a), LS_CONSTANT(b), LS_CONSTANT(c)
105 #define LS_SHAPE_EQUAL4(a,b,c,d) LS_TOKEN_SHAPE+4, LS_CONSTANT(a), LS_CONSTANT(b), LS_CONSTANT(c), LS_CONSTANT(d)
106 
107 #define LS_FRAME_EQUAL(val) LS_EQUAL(LS_TOKEN_FRAME,LS_INT(val))
108 #define LS_FRAME_EQUAL1(a) LS_TOKEN_FRAME+1, LS_CONSTANT(a)
109 #define LS_FRAME_EQUAL2(a,b) LS_TOKEN_FRAME+2, LS_CONSTANT(a), LS_CONSTANT(b)
110 #define LS_FRAME_EQUAL3(a,b,c) LS_TOKEN_FRAME+3, LS_CONSTANT(a), LS_CONSTANT(b), LS_CONSTANT(c)
111 #define LS_FRAME_EQUAL4(a,b,c,d) LS_TOKEN_FRAME+4, LS_CONSTANT(a), LS_CONSTANT(b), LS_CONSTANT(c), LS_CONSTANT(d)
112 
113 #endif