removed empty function
[rocksndiamonds.git] / src / game_em / game.c
1 /* 2007-11-06 03:39:32
2  *
3  * handle interaction between screen and cave
4  */
5
6 #include "main_em.h"
7
8
9 struct CAVE cav;
10 struct LOGIC lev;
11 struct PLAYER ply[MAX_PLAYERS];
12
13 struct EngineSnapshotInfo_EM engine_snapshot_em;
14
15 /* handle input actions for players */
16
17 static void readjoy(byte action, struct PLAYER *ply)
18 {
19   int north = 0, east = 0, south = 0, west = 0;
20   int snap = 0, drop = 0;
21
22   if (game_em.use_single_button && action & (JOY_BUTTON_1 | JOY_BUTTON_2))
23     action |= JOY_BUTTON_1 | JOY_BUTTON_2;
24
25   if (action & JOY_LEFT)
26     west = 1;
27
28   if (action & JOY_RIGHT)
29     east = 1;
30
31   if (action & JOY_UP)
32     north = 1;
33
34   if (action & JOY_DOWN)
35     south = 1;
36
37   if (action & JOY_BUTTON_1)
38     snap = 1;
39
40   if (action & JOY_BUTTON_2)
41     drop = 1;
42
43   /* always update drop action */
44   ply->joy_drop = drop;
45
46   if (ply->joy_stick || (north | east | south | west))  /* (no "| snap"!) */
47   {
48     ply->joy_n = north;
49     ply->joy_e = east;
50     ply->joy_s = south;
51     ply->joy_w = west;
52
53     /* when storing last action, only update snap action with direction */
54     /* (prevents clearing direction if snapping stopped before frame 7) */
55     ply->joy_snap = snap;
56   }
57
58   /* if no direction was stored before, allow setting snap to current state */
59   if (!ply->joy_n &&
60       !ply->joy_e &&
61       !ply->joy_s &&
62       !ply->joy_w)
63     ply->joy_snap = snap;
64
65   /* use bug with snap key (mainly TAS keys) sometimes moving the player */
66   if (game_em.use_snap_key_bug)
67     ply->joy_snap = snap;
68 }
69
70 void InitGameEngine_EM(void)
71 {
72   prepare_em_level();
73
74   game_initscreen();
75
76   RedrawPlayfield_EM(FALSE);
77 }
78
79 void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode)
80 {
81   int i;
82   boolean any_player_dropping = FALSE;
83
84   game_em.random = game_em.random * 129 + 1;
85
86   frame = (frame - 1) & 7;
87
88   for (i = 0; i < MAX_PLAYERS; i++)
89     readjoy(action[i], &ply[i]);
90
91   UpdateEngineValues(screen_x / TILEX, screen_y / TILEY, ply[0].x, ply[0].y);
92
93   if (frame == 7)
94   {
95     logic_players();
96     logic_objects();
97   }
98
99   if (frame == 6)
100   {
101     logic_globals();
102   }
103
104   for (i = 0; i < MAX_PLAYERS; i++)
105     if (ply[i].joy_drop &&
106         ply[i].dynamite &&
107         ply[i].dynamite_cnt > 0 &&
108         ply[i].dynamite_cnt < 5)
109       any_player_dropping = TRUE;
110
111   CheckSingleStepMode_EM(action, frame, game_em.any_player_moving,
112                          game_em.any_player_snapping, any_player_dropping);
113
114   RedrawPlayfield_EM(FALSE);
115 }
116
117 void SaveEngineSnapshotValues_EM(void)
118 {
119   int i;
120
121   engine_snapshot_em.game_em = game_em;
122   engine_snapshot_em.lev = lev;
123
124   engine_snapshot_em.frame = frame;
125   engine_snapshot_em.screen_x = screen_x;
126   engine_snapshot_em.screen_y = screen_y;
127
128   for (i = 0; i < 4; i++)
129     engine_snapshot_em.ply[i] = ply[i];
130 }
131
132 void LoadEngineSnapshotValues_EM(void)
133 {
134   int i;
135
136   game_em = engine_snapshot_em.game_em;
137   lev = engine_snapshot_em.lev;
138
139   frame = engine_snapshot_em.frame;
140   screen_x = engine_snapshot_em.screen_x;
141   screen_y = engine_snapshot_em.screen_y;
142
143   for (i = 0; i < 4; i++)
144     ply[i] = engine_snapshot_em.ply[i];
145 }