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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 */
21 //-------------------------------------------------------------------------
22 
23 #ifndef EDUKE32_MACROS_H_
24 #define EDUKE32_MACROS_H_
25 
26 #include "mmulti.h"
27 
28 // Macros, some from SW source
29 
30 #define BGSTRETCH (ud.bgstretch ? 1024 : 0)
31 
32 #define WIN_IS_PRESSED ( KB_KeyPressed( sc_RightWin ) || KB_KeyPressed( sc_LeftWin ) )
33 #define ALT_IS_PRESSED ( KB_KeyPressed( sc_RightAlt ) || KB_KeyPressed( sc_LeftAlt ) )
34 #define SHIFTS_IS_PRESSED ( KB_KeyPressed( sc_RightShift ) || KB_KeyPressed( sc_LeftShift ) )
35 
36 #ifndef EDUKE32_STANDALONE
37 #define RANDOMSCRAP(s, i) A_InsertSprite(s->sectnum,s->x+(krand()&255)-128,s->y+(krand()&255)-128,s->z-ZOFFSET3-(krand()&8191),\
38     SCRAP6+(krand()&15),-8,48,48,krand()&2047,(krand()&63)+64,-512-(krand()&2047),i,5)
39 #endif
40 
41 #define GTFLAGS(x) (g_gametypeFlags[ud.coop] & x)
42 
43 #define TRAVERSE_SPRITE_SECT(l, o, n)    (o) = (l); ((o) != -1) && ((n) = nextspritesect[o]); (o) = (n)
44 #define TRAVERSE_SPRITE_STAT(l, o, n)    (o) = (l); ((o) != -1) && ((n) = nextspritestat[o]); (o) = (n)
45 #define TRAVERSE_CONNECT(i)              i = 0; i != -1; i = connectpoint2[i]
46 
47 #define TEST(flags,mask) ((flags) & (mask))
48 #define SET(flags,mask) ((flags) |= (mask))
49 #define RESET(flags,mask) ((flags) &= ~(mask))
50 #define FLIP(flags,mask) ((flags) ^= (mask))
51 
52 // mask definitions
53 
54 #define BIT(shift)     (1u<<(shift))
55 
56 #define TEST_SYNC_KEY(bits, sync_num) (!!TEST((bits), BIT(sync_num)))
57 
58 #ifndef EDUKE32_STANDALONE
59 #define AFLAMABLE(X) (X==BOX||X==TREE1||X==TREE2||X==TIRE||X==CONE)
60 #endif
61 #define rnd(X) ((krand()>>8)>=(255-(X)))
62 
63 //
64 // NETWORK - REDEFINABLE SHARED (SYNC) KEYS BIT POSITIONS
65 //
66 
67 #define SK_JUMP         0
68 #define SK_CROUCH       1
69 #define SK_FIRE         2
70 #define SK_AIM_UP       3
71 #define SK_AIM_DOWN     4
72 #define SK_RUN          5
73 #define SK_LOOK_LEFT    6
74 #define SK_LOOK_RIGHT   7
75 // weapons take up 4 bits...
76 #define SK_WEAPON_BITS  8
77 #define SK_WEAPON_BITS1 9
78 #define SK_WEAPON_BITS2 10
79 #define SK_WEAPON_BITS3 11
80 #define SK_WEAPON_MASK ((1 << SK_WEAPON_BITS) | (1 << SK_WEAPON_BITS1) | (1 << SK_WEAPON_BITS2) | (1 << SK_WEAPON_BITS3))
81 #define SK_STEROIDS     12
82 #define SK_LOOK_UP      13
83 #define SK_LOOK_DOWN    14
84 #define SK_NIGHTVISION  15
85 #define SK_MEDKIT       16
86 #define SK_MULTIFLAG    17
87 #define SK_CENTER_VIEW  18
88 #define SK_HOLSTER      19
89 #define SK_INV_LEFT     20
90 #define SK_PAUSE        21
91 #define SK_QUICK_KICK   22
92 #define SK_AIMMODE      23
93 #define SK_HOLODUKE     24
94 #define SK_JETPACK      25
95 #define SK_GAMEQUIT     26
96 #define SK_INV_RIGHT    27
97 #define SK_TURNAROUND   28
98 #define SK_OPEN         29
99 #define SK_INVENTORY    30
100 #define SK_ESCAPE       31
101 
102 // rotatesprite flags
103 #define ROTATE_SPRITE_TRANSLUCENT   (BIT(0))
104 #define ROTATE_SPRITE_VIEW_CLIP     (BIT(1)) // clip to view
105 #define ROTATE_SPRITE_YFLIP         (BIT(2))
106 #define ROTATE_SPRITE_IGNORE_START_MOST (BIT(3)) // don't clip to startumost
107 #define ROTATE_SPRITE_SCREEN_CLIP   (BIT(1)|BIT(3)) // use window
108 #define ROTATE_SPRITE_CORNER        (BIT(4)) // place sprite from upper left corner
109 #define ROTATE_SPRITE_TRANS_FLIP    (BIT(5))
110 #define ROTATE_SPRITE_NON_MASK      (BIT(6)) // non masked sprites
111 #define ROTATE_SPRITE_ALL_PAGES     (BIT(7)) // copies to all pages
112 
113 #define RS_SCALE                    BIT(16)
114 
115 // system defines for status bits
116 #define CEILING_STAT_PLAX           BIT(0)
117 #define CEILING_STAT_SLOPE          BIT(1)
118 #define CEILING_STAT_SWAPXY         BIT(2)
119 #define CEILING_STAT_SMOOSH         BIT(3)
120 #define CEILING_STAT_XFLIP          BIT(4)
121 #define CEILING_STAT_YFLIP          BIT(5)
122 #define CEILING_STAT_RELATIVE       BIT(6)
123 #define CEILING_STAT_TYPE_MASK     (BIT(7)|BIT(8))
124 #define CEILING_STAT_MASKED         BIT(7)
125 #define CEILING_STAT_TRANS          BIT(8)
126 #define CEILING_STAT_TRANS_FLIP     (BIT(7)|BIT(8))
127 #define CEILING_STAT_FAF_BLOCK_HITSCAN      BIT(15)
128 
129 #define FLOOR_STAT_PLAX           BIT(0)
130 #define FLOOR_STAT_SLOPE          BIT(1)
131 #define FLOOR_STAT_SWAPXY         BIT(2)
132 #define FLOOR_STAT_SMOOSH         BIT(3)
133 #define FLOOR_STAT_XFLIP          BIT(4)
134 #define FLOOR_STAT_YFLIP          BIT(5)
135 #define FLOOR_STAT_RELATIVE       BIT(6)
136 #define FLOOR_STAT_TYPE_MASK     (BIT(7)|BIT(8))
137 #define FLOOR_STAT_MASKED         BIT(7)
138 #define FLOOR_STAT_TRANS          BIT(8)
139 #define FLOOR_STAT_TRANS_FLIP     (BIT(7)|BIT(8))
140 #define FLOOR_STAT_FAF_BLOCK_HITSCAN      BIT(15)
141 
142 
143 //cstat, bit 0: 1 = Blocking sprite (use with clipmove, getzrange)    "B"
144 //       bit 1: 1 = 50/50 transluscence, 0 = normal                   "T"
145 //       bit 2: 1 = x-flipped, 0 = normal                             "F"
146 //       bit 3: 1 = y-flipped, 0 = normal                             "F"
147 //       bits 5-4: 00 = FACE sprite (default)                         "R"
148 //                 01 = WALL sprite (like masked walls)
149 //                 10 = FLOOR sprite (parallel to ceilings&floors)
150 //                 11 = SPIN sprite (face sprite that can spin 2draw style - not done yet)
151 //       bit 6: 1 = 1-sided sprite, 0 = normal                        "1"
152 //       bit 7: 1 = Real centered centering, 0 = foot center          "C"
153 //       bit 8: 1 = Blocking sprite (use with hitscan)                "H"
154 //       bit 9: reserved
155 //       bit 10: reserved
156 //       bit 11: 1 = determine shade based only on its own shade member (see CON's spritenoshade command), i.e.
157 //                   don't take over shade from parallaxed ceiling/nonparallaxed floor
158 //                   (NOTE: implemented on the game side)
159 //       bit 12: reserved
160 //       bit 13: reserved
161 //       bit 14: reserved
162 //       bit 15: 1 = Invisible sprite, 0 = not invisible
163 #define CSTAT_SPRITE_NOSHADE        BIT(11)
164 #define CSTAT_SPRITE_BREAKABLE (CSTAT_SPRITE_BLOCK_HITSCAN)
165 
166 #define SP(i)  sprite[i].yvel
167 #define SX(i)  sprite[i].x
168 #define SY(i)  sprite[i].y
169 #define SZ(i)  sprite[i].z
170 #define SS(i)  sprite[i].shade
171 #define PN(i)  sprite[i].picnum
172 #define SA(i)  sprite[i].ang
173 //#define SV  sprite[i].xvel
174 //#define ZV  sprite[i].zvel
175 //#define RX  sprite[i].xrepeat
176 //#define RY  sprite[i].yrepeat
177 #define OW(i)  sprite[i].owner
178 #define CS(i)  sprite[i].cstat
179 #define SH(i)  sprite[i].extra
180 //#define CX  sprite[i].xoffset
181 //#define CY  sprite[i].yoffset
182 //#define CD  sprite[i].clipdist
183 //#define PL  sprite[i].pal
184 #define SLT(i)  sprite[i].lotag
185 #define SHT(i)  sprite[i].hitag
186 #define SECT(i) sprite[i].sectnum
187 
188 #define T1(i)  actor[i].t_data[0]
189 #define T2(i)  actor[i].t_data[1]
190 #define T3(i)  actor[i].t_data[2]
191 #define T4(i)  actor[i].t_data[3]
192 #define T5(i)  actor[i].t_data[4]
193 #define T6(i)  actor[i].t_data[5]
194 
195 #endif
196