major cleanup of preprocessor hell
[rocksndiamonds.git] / src / game_em / input.c
1 /* 2000-08-13T15:29:40Z
2  *
3  * handle input from x11 and keyboard and joystick
4  */
5
6 #include "main_em.h"
7
8
9 unsigned int RandomEM;
10
11 struct LEVEL lev;
12 struct PLAYER ply[MAX_PLAYERS];
13
14 short **Boom;
15 short **Cave;
16 short **Next;
17 short **Draw;
18
19 static short *Index[4][HEIGHT];
20 static short Array[4][HEIGHT][WIDTH];
21
22 extern int screen_x;
23 extern int screen_y;
24
25 struct EngineSnapshotInfo_EM engine_snapshot_em;
26
27 void game_init_vars(void)
28 {
29   int x, y;
30
31   RandomEM = 1684108901;
32
33   for (y = 0; y < HEIGHT; y++)
34     for (x = 0; x < WIDTH; x++)
35       Array[0][y][x] = ZBORDER;
36   for (y = 0; y < HEIGHT; y++)
37     for (x = 0; x < WIDTH; x++)
38       Array[1][y][x] = ZBORDER;
39   for (y = 0; y < HEIGHT; y++)
40     for (x = 0; x < WIDTH; x++)
41       Array[2][y][x] = ZBORDER;
42   for (y = 0; y < HEIGHT; y++)
43     for (x = 0; x < WIDTH; x++)
44       Array[3][y][x] = Xblank;
45
46   for (y = 0; y < HEIGHT; y++)
47     Index[0][y] = Array[0][y];
48   for (y = 0; y < HEIGHT; y++)
49     Index[1][y] = Array[1][y];
50   for (y = 0; y < HEIGHT; y++)
51     Index[2][y] = Array[2][y];
52   for (y = 0; y < HEIGHT; y++)
53     Index[3][y] = Array[3][y];
54
55   Cave = Index[0];
56   Next = Index[1];
57   Draw = Index[2];
58   Boom = Index[3];
59 }
60
61 void InitGameEngine_EM()
62 {
63   prepare_em_level();
64
65   game_initscreen();
66   game_animscreen();
67 }
68
69 void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode)
70 {
71   int i;
72   boolean player_is_dropping = FALSE;
73
74   RandomEM = RandomEM * 129 + 1;
75
76   frame = (frame - 1) & 7;
77
78   for (i = 0; i < MAX_PLAYERS; i++)
79     readjoy(action[i], &ply[i]);
80
81   UpdateEngineValues(screen_x / TILEX, screen_y / TILEY);
82
83   if (frame == 7)
84   {
85     synchro_1();
86     synchro_2();
87   }
88
89   if (frame == 6)
90   {
91     synchro_3();
92     sound_play();
93
94     if (!warp_mode)             /* do not redraw values in warp mode */
95       DrawGameDoorValues_EM();
96   }
97
98   for (i = 0; i < MAX_PLAYERS; i++)
99     if (ply[i].joy_drop &&
100         ply[i].dynamite &&
101         ply[i].dynamite_cnt > 0 &&
102         ply[i].dynamite_cnt < 5)
103       player_is_dropping = TRUE;
104
105   CheckSingleStepMode_EM(action, frame, game_em.any_player_moving,
106                          player_is_dropping);
107
108   game_animscreen();
109
110   blitscreen();
111 }
112
113 /* read input device for players */
114
115 void readjoy(byte action, struct PLAYER *ply)
116 {
117   int north = 0, east = 0, south = 0, west = 0;
118   int snap = 0, drop = 0;
119
120   if (action & JOY_LEFT)
121     west = 1;
122
123   if (action & JOY_RIGHT)
124     east = 1;
125
126   if (action & JOY_UP)
127     north = 1;
128
129   if (action & JOY_DOWN)
130     south = 1;
131
132   if (action & JOY_BUTTON_1)
133     snap = 1;
134
135   if (action & JOY_BUTTON_2)
136     drop = 1;
137
138   ply->joy_snap = snap;
139   ply->joy_drop = drop;
140
141   if (ply->joy_stick || (north | east | south | west))
142   {
143     ply->joy_n = north;
144     ply->joy_e = east;
145     ply->joy_s = south;
146     ply->joy_w = west;
147   }
148 }
149
150 void SaveEngineSnapshotValues_EM()
151 {
152   int i, j, k;
153
154   engine_snapshot_em.game_em = game_em;
155   engine_snapshot_em.lev = lev;
156
157   engine_snapshot_em.RandomEM = RandomEM;
158   engine_snapshot_em.frame = frame;
159
160   engine_snapshot_em.screen_x = screen_x;
161   engine_snapshot_em.screen_y = screen_y;
162
163   engine_snapshot_em.Boom = Boom;
164   engine_snapshot_em.Cave = Cave;
165   engine_snapshot_em.Next = Next;
166   engine_snapshot_em.Draw = Draw;
167
168   for (i = 0; i < 4; i++)
169     engine_snapshot_em.ply[i] = ply[i];
170
171   for (i = 0; i < 4; i++)
172     for (j = 0; j < HEIGHT; j++)
173       for (k = 0; k < WIDTH; k++)
174         engine_snapshot_em.Array[i][j][k] = Array[i][j][k];
175 }
176
177 void LoadEngineSnapshotValues_EM()
178 {
179   int i, j, k;
180
181   game_em = engine_snapshot_em.game_em;
182   lev = engine_snapshot_em.lev;
183
184   RandomEM = engine_snapshot_em.RandomEM;
185   frame = engine_snapshot_em.frame;
186
187   screen_x = engine_snapshot_em.screen_x;
188   screen_y = engine_snapshot_em.screen_y;
189
190   Boom = engine_snapshot_em.Boom;
191   Cave = engine_snapshot_em.Cave;
192   Next = engine_snapshot_em.Next;
193   Draw = engine_snapshot_em.Draw;
194
195   for (i = 0; i < 4; i++)
196     ply[i] = engine_snapshot_em.ply[i];
197
198   for (i = 0; i < 4; i++)
199     for (j = 0; j < HEIGHT; j++)
200       for (k = 0; k < WIDTH; k++)
201         Array[i][j][k] = engine_snapshot_em.Array[i][j][k];
202 }