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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef ULTIMA8_WORLD_LOOPSCRIPT_H
24 #define ULTIMA8_WORLD_LOOPSCRIPT_H
25 
26 // Script Tokens
27 #define LS_TOKEN_AND            '&'
28 #define LS_TOKEN_OR             '+'
29 #define LS_TOKEN_NOT            '!'
30 #define LS_TOKEN_EQUAL          '='
31 #define LS_TOKEN_GREATER        '>'
32 #define LS_TOKEN_LESS           '<'
33 #define LS_TOKEN_GEQUAL         ']'
34 #define LS_TOKEN_LEQUAL         '['
35 
36 #define LS_TOKEN_INT            '%'
37 
38 #define LS_TOKEN_TRUE           1
39 #define LS_TOKEN_FALSE          0
40 #define LS_TOKEN_NPCNUM         '#'
41 #define LS_TOKEN_STATUS         '?'
42 #define LS_TOKEN_Q              '*'
43 #define LS_TOKEN_FAMILY         ':'
44 #define LS_TOKEN_SHAPE          '@'
45 #define LS_TOKEN_FRAME          '`'
46 
47 #define LS_TOKEN_END            '$'
48 
49 //
50 // Generating Loopscripts aka Abusing the C Preprocessor
51 //
52 
53 //
54 // Highlevel Function Like Scripts
55 //
56 // Usage:
57 //
58 // LOOPSCRIPT(script, LS_AND(LS_SHAPE_EQUAL(73), LS_Q_EQUAL(4)));
59 //
60 
61 //
62 // Tokenized Scripts
63 //
64 // Usage:
65 //
66 // const uint8 script[] = {
67 //	LS_TOKEN_SHAPE,
68 //	LS_TOKEN_INT,
69 //	LS_CONSTANT(73),
70 //	LS_TOKEN_EQUAL,
71 //	LS_TOKEN_Q,
72 //	LS_TOKEN_INT,
73 //	LS_CONSTANT(4),
74 //	LS_TOKEN_EQUAL,
75 //	LS_TOKEN_AND,
76 //	LS_TOKEN_END
77 // };
78 //
79 
80 #define LOOPSCRIPT(name,tokens) const uint8 name[] = { tokens, LS_TOKEN_END }
81 
82 #define LS_CONSTANT(val)            ((uint8)(val)), ((uint8)((val)>>8))
83 #define LS_INT(val)                 LS_TOKEN_INT, LS_CONSTANT(val)
84 
85 #define LS_OP(left, op, right)      left, right, op
86 
87 #define LS_NOT(left)                left, LS_TOKEN_NOT
88 #define LS_AND(left,right)          left, right, LS_TOKEN_AND
89 #define LS_OR(left,right)           left, right, LS_TOKEN_OR
90 
91 #define LS_EQUAL(left,right)        left, right, LS_TOKEN_EQUAL
92 #define LS_LEQUAL(left,right)       left, right, LS_TOKEN_LEQUAL
93 #define LS_GEQUAL(left,right)       left, right, LS_TOKEN_GEQUAL
94 #define LS_LESS(left,right)         left, right, LS_TOKEN_LESS
95 #define LS_GREATER(left,right)      left, right, LS_TOKEN_GREATER
96 
97 #define LS_FAMILY_EQUAL(val)        LS_EQUAL(LS_TOKEN_FAMILY,LS_INT(val))
98 #define LS_NPCNUM_EQUAL(val)        LS_EQUAL(LS_TOKEN_NPCNUM,LS_INT(val))
99 #define LS_STATUS_EQUAL(val)        LS_EQUAL(LS_TOKEN_STATUS,LS_INT(val))
100 #define LS_Q_EQUAL(val)             LS_EQUAL(LS_TOKEN_Q,LS_INT(val))
101 
102 #define LS_SHAPE_EQUAL(val)         LS_EQUAL(LS_TOKEN_SHAPE,LS_INT(val))
103 #define LS_SHAPE_EQUAL1(a)          LS_TOKEN_SHAPE+1, LS_CONSTANT(a)
104 #define LS_SHAPE_EQUAL2(a,b)        LS_TOKEN_SHAPE+2, LS_CONSTANT(a), LS_CONSTANT(b)
105 #define LS_SHAPE_EQUAL3(a,b,c)      LS_TOKEN_SHAPE+3, LS_CONSTANT(a), LS_CONSTANT(b), LS_CONSTANT(c)
106 #define LS_SHAPE_EQUAL4(a,b,c,d)    LS_TOKEN_SHAPE+4, LS_CONSTANT(a), LS_CONSTANT(b), LS_CONSTANT(c), LS_CONSTANT(d)
107 
108 #define LS_FRAME_EQUAL(val)         LS_EQUAL(LS_TOKEN_FRAME,LS_INT(val))
109 #define LS_FRAME_EQUAL1(a)          LS_TOKEN_FRAME+1, LS_CONSTANT(a)
110 #define LS_FRAME_EQUAL2(a,b)        LS_TOKEN_FRAME+2, LS_CONSTANT(a), LS_CONSTANT(b)
111 #define LS_FRAME_EQUAL3(a,b,c)      LS_TOKEN_FRAME+3, LS_CONSTANT(a), LS_CONSTANT(b), LS_CONSTANT(c)
112 #define LS_FRAME_EQUAL4(a,b,c,d)    LS_TOKEN_FRAME+4, LS_CONSTANT(a), LS_CONSTANT(b), LS_CONSTANT(c), LS_CONSTANT(d)
113 
114 #endif
115