added optional button to restart game (door, panel and touch variants)
[rocksndiamonds.git] / src / tape.h
1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
5 //                  Holger Schemel
6 //                  info@artsoft.org
7 //                  https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
9 // tape.h
10 // ============================================================================
11
12 #ifndef TAPE_H
13 #define TAPE_H
14
15
16 // values for TapeTogglePause()
17 #define TAPE_TOGGLE_AUTOMATIC   0
18 #define TAPE_TOGGLE_MANUAL      (1 << 0)
19 #define TAPE_TOGGLE_PLAY_PAUSE  (1 << 1)
20
21 // values for tape properties
22 #define MAX_TAPE_LEN            (10000 * FRAMES_PER_SECOND) // max.time x fps
23
24 // values for tape action array positions
25 #define TAPE_ACTION_LX          (MAX_PLAYERS + 0)
26 #define TAPE_ACTION_LY          (MAX_PLAYERS + 1)
27 #define TAPE_ACTION_BUTTON      (MAX_PLAYERS + 2)
28
29 #define MAX_TAPE_ACTIONS        (MAX_PLAYERS + 3)
30
31 // values for tape actions stored in tape file
32 #define TAPE_USE_KEY_ACTIONS_ONLY       0
33 #define TAPE_USE_MOUSE_ACTIONS_ONLY     1
34 #define TAPE_USE_KEY_AND_MOUSE_ACTIONS  2
35
36 #define TAPE_ACTIONS_DEFAULT            TAPE_USE_KEY_ACTIONS_ONLY
37
38 // values for tape properties stored in tape file
39 #define TAPE_PROPERTY_NONE              0
40 #define TAPE_PROPERTY_EM_RANDOM_BUG     (1 << 0)
41 #define TAPE_PROPERTY_GAME_SPEED        (1 << 1)
42 #define TAPE_PROPERTY_PAUSE_MODE        (1 << 2)
43 #define TAPE_PROPERTY_SINGLE_STEP       (1 << 3)
44 #define TAPE_PROPERTY_SNAPSHOT          (1 << 4)
45 #define TAPE_PROPERTY_REPLAYED          (1 << 5)
46 #define TAPE_PROPERTY_TAS_KEYS          (1 << 6)
47 #define TAPE_PROPERTY_SMALL_GRAPHICS    (1 << 7)
48
49 // values for score tape basename length (date, time, name hash, no extension)
50 #define MAX_SCORE_TAPE_BASENAME_LEN     24
51
52 // some positions in the video tape control window
53 #define VIDEO_DISPLAY1_XPOS     5
54 #define VIDEO_DISPLAY1_YPOS     5
55 #define VIDEO_DISPLAY2_XPOS     5
56 #define VIDEO_DISPLAY2_YPOS     41
57 #define VIDEO_DISPLAY_XSIZE     90
58 #define VIDEO_DISPLAY_YSIZE     31
59 #define VIDEO_BUTTON_XSIZE      18
60 #define VIDEO_BUTTON_YSIZE      18
61 #define VIDEO_CONTROL_XPOS      5
62 #define VIDEO_CONTROL_YPOS      77
63 #define VIDEO_CONTROL_XSIZE     VIDEO_DISPLAY_XSIZE
64 #define VIDEO_CONTROL_YSIZE     VIDEO_BUTTON_YSIZE
65
66 // values for video tape control
67 #define VIDEO_STATE_PLAY_OFF    (1 << 0)
68 #define VIDEO_STATE_PLAY_ON     (1 << 1)
69 #define VIDEO_STATE_REC_OFF     (1 << 2)
70 #define VIDEO_STATE_REC_ON      (1 << 3)
71 #define VIDEO_STATE_PAUSE_OFF   (1 << 4)
72 #define VIDEO_STATE_PAUSE_ON    (1 << 5)
73 #define VIDEO_STATE_DATE_OFF    (1 << 6)
74 #define VIDEO_STATE_DATE_ON     (1 << 7)
75 #define VIDEO_STATE_TIME_OFF    (1 << 8)
76 #define VIDEO_STATE_TIME_ON     (1 << 9)
77 #define VIDEO_STATE_FRAME_OFF   (1 << 10)
78 #define VIDEO_STATE_FRAME_ON    (1 << 11)
79 #define VIDEO_STATE_FFWD_OFF    (1 << 12)
80 #define VIDEO_STATE_FFWD_ON     (1 << 13)
81 #define VIDEO_STATE_WARP_OFF    (1 << 14)
82 #define VIDEO_STATE_WARP_ON     (1 << 15)
83 #define VIDEO_STATE_WARP2_OFF   (1 << 16)
84 #define VIDEO_STATE_WARP2_ON    (1 << 17)
85 #define VIDEO_STATE_PBEND_OFF   (1 << 18)
86 #define VIDEO_STATE_PBEND_ON    (1 << 19)
87 #define VIDEO_STATE_1STEP_OFF   (1 << 20)
88 #define VIDEO_STATE_1STEP_ON    (1 << 21)
89
90 #define VIDEO_PRESS_PLAY_ON     (1 << 22)
91 #define VIDEO_PRESS_PLAY_OFF    (1 << 23)
92 #define VIDEO_PRESS_REC_ON      (1 << 24)
93 #define VIDEO_PRESS_REC_OFF     (1 << 25)
94 #define VIDEO_PRESS_PAUSE_ON    (1 << 26)
95 #define VIDEO_PRESS_PAUSE_OFF   (1 << 27)
96 #define VIDEO_PRESS_STOP_ON     (1 << 28)
97 #define VIDEO_PRESS_STOP_OFF    (1 << 29)
98 #define VIDEO_PRESS_EJECT_ON    (1 << 30)
99 #define VIDEO_PRESS_EJECT_OFF   (1 << 31)
100
101 #define VIDEO_STATE_PLAY(x)  ((x) ? VIDEO_STATE_PLAY_ON : VIDEO_STATE_PLAY_OFF)
102 #define VIDEO_STATE_REC(x)   ((x) ? VIDEO_STATE_REC_ON  : VIDEO_STATE_REC_OFF)
103 #define VIDEO_STATE_PAUSE(x) ((x) ? VIDEO_STATE_PAUSE_ON: VIDEO_STATE_PAUSE_OFF)
104 #define VIDEO_STATE_DATE(x)  ((x) ? VIDEO_STATE_DATE_ON : VIDEO_STATE_DATE_OFF)
105 #define VIDEO_STATE_TIME(x)  ((x) ? VIDEO_STATE_TIME_ON : VIDEO_STATE_TIME_OFF)
106 #define VIDEO_STATE_FRAME(x) ((x) ? VIDEO_STATE_FRAME_ON: VIDEO_STATE_FRAME_OFF)
107 #define VIDEO_STATE_FFWD(x)  ((x) ? VIDEO_STATE_FFWD_ON : VIDEO_STATE_FFWD_OFF)
108 #define VIDEO_STATE_WARP(x)  ((x) ? VIDEO_STATE_WARP_ON : VIDEO_STATE_WARP_OFF)
109 #define VIDEO_STATE_WARP2(x) ((x) ? VIDEO_STATE_WARP2_ON: VIDEO_STATE_WARP2_OFF)
110 #define VIDEO_STATE_PBEND(x) ((x) ? VIDEO_STATE_PBEND_ON: VIDEO_STATE_PBEND_OFF)
111 #define VIDEO_STATE_1STEP(x) ((x) ? VIDEO_STATE_1STEP_ON: VIDEO_STATE_1STEP_OFF)
112
113 #define VIDEO_PRESS_PLAY(x)  ((x) ? VIDEO_PRESS_PLAY_ON : VIDEO_PRESS_PLAY_OFF)
114 #define VIDEO_PRESS_REC(x)   ((x) ? VIDEO_PRESS_REC_ON  : VIDEO_PRESS_REC_OFF)
115 #define VIDEO_PRESS_PAUSE(x) ((x) ? VIDEO_PRESS_PAUSE_ON: VIDEO_PRESS_PAUSE_OFF)
116 #define VIDEO_PRESS_STOP(x)  ((x) ? VIDEO_PRESS_STOP_ON : VIDEO_PRESS_STOP_OFF)
117 #define VIDEO_PRESS_EJECT(x) ((x) ? VIDEO_PRESS_EJECT_ON: VIDEO_PRESS_EJECT_OFF)
118
119 // tags to draw video display labels or symbols only
120 // (negative values to prevent misinterpretation in DrawVideoDisplay(), where
121 // the variable "value" is also used for tape length -- better fix this)
122 #define VIDEO_DISPLAY_DEFAULT           0
123 #define VIDEO_DISPLAY_LABEL_ONLY        -1
124 #define VIDEO_DISPLAY_SYMBOL_ONLY       -2
125
126
127 struct TapeButtonInfo
128 {
129   struct XY eject;
130   struct XY stop;
131   struct XY pause;
132   struct XY record;
133   struct XY play;
134   struct XY insert_solution;
135   struct XY play_solution;
136 };
137
138 struct TapeSymbolInfo
139 {
140   struct XY eject;
141   struct XY stop;
142   struct XY pause;
143   struct XY record;
144   struct XY play;
145   struct XY fast_forward;
146   struct XY warp_forward;
147   struct XY warp_forward_blind;
148   struct XY pause_before_end;
149   struct XY single_step;
150 };
151
152 struct TapeLabelInfo
153 {
154   struct XY eject;
155   struct XY stop;
156   struct XY pause;
157   struct XY record;
158   struct XY play;
159   struct XY fast_forward;
160   struct XY warp_forward;
161   struct XY warp_forward_blind;
162   struct XY pause_before_end;
163   struct XY single_step;
164   struct XY date;
165   struct XY time;
166 };
167
168 struct TapeTextInfo
169 {
170   struct TextPosInfo date;
171   struct TextPosInfo date_yyyy;
172   struct TextPosInfo date_yy;
173   struct TextPosInfo date_mon;
174   struct TextPosInfo date_mm;
175   struct TextPosInfo date_dd;
176
177   struct TextPosInfo time;
178   struct TextPosInfo time_hh;
179   struct TextPosInfo time_mm;
180   struct TextPosInfo time_ss;
181
182   struct TextPosInfo frame;
183 };
184
185 struct TapeInfo
186 {
187   int file_version;     // file format version the tape is stored with
188   int game_version;     // game release version the tape was created with
189   int engine_version;   // game engine version the tape was recorded with
190
191   char score_tape_basename[MAX_FILENAME_LEN + 1];
192   char level_identifier[MAX_FILENAME_LEN + 1];
193   int level_nr;
194   unsigned int random_seed;
195   unsigned int date;
196   unsigned int counter;
197   unsigned int length;
198   unsigned int length_frames;
199   unsigned int length_seconds;
200   unsigned int delay_played;
201   boolean pause_before_end;
202   boolean recording, playing, pausing;
203   boolean fast_forward;
204   boolean warp_forward;
205   boolean deactivate_display;
206   boolean auto_play;
207   boolean auto_play_level_solved;
208   boolean auto_play_level_fixed;
209   boolean auto_play_level_not_fixable;
210   boolean quick_resume;
211   boolean single_step;
212   boolean changed;
213   boolean player_participates[MAX_PLAYERS];
214   int num_participating_players;
215   int centered_player_nr_next;
216   boolean set_centered_player;
217
218   // flags to indicate which game actions are stored in this tape
219   boolean use_key_actions;
220   boolean use_mouse_actions;
221
222   // bits to indicate which tape properties are stored in this tape
223   byte property_bits;
224
225   // visible playfield size when recording this tape (for team mode)
226   int scr_fieldx;
227   int scr_fieldy;
228
229   struct
230   {
231     byte action[MAX_TAPE_ACTIONS];
232     byte delay;
233   } pos[MAX_TAPE_LEN];
234
235   struct TapeButtonInfo button;
236   struct TapeSymbolInfo symbol;
237   struct TapeLabelInfo label;
238   struct TapeTextInfo text;
239
240   boolean show_game_buttons;    // show game buttons in tape viewport
241
242   boolean no_info_chunk;        // used to identify old tape file format
243   boolean no_valid_file;        // set when tape file missing or invalid
244 };
245
246
247 void DrawVideoDisplay(unsigned int, unsigned int);
248 void DrawCompleteVideoDisplay(void);
249
250 void TapeDeactivateDisplayOn(void);
251 void TapeDeactivateDisplayOff(boolean);
252
253 void TapeSetDateFromEpochSeconds(time_t);
254 void TapeSetDateFromNow(void);
255
256 void TapeStartRecording(int);
257 void TapeHaltRecording(void);
258 void TapeStopRecording(void);
259 boolean TapeAddAction(byte *);
260 void TapeRecordAction(byte *);
261 void TapeTogglePause(boolean);
262 void TapeStartPlaying(void);
263 void TapeStopPlaying(void);
264 byte *TapePlayAction(void);
265 void TapeStop(void);
266 void TapeStopGame(void);
267 void TapeStopTape(void);
268 void TapeErase(void);
269 unsigned int GetTapeLengthFrames(void);
270 unsigned int GetTapeLengthSeconds(void);
271 void TapeQuickSave(void);
272 void TapeQuickLoad(void);
273 void TapeRestartGame(void);
274 void TapeReplayAndPauseBeforeEnd(void);
275
276 boolean hasSolutionTape(void);
277 boolean InsertSolutionTape(void);
278 boolean PlaySolutionTape(void);
279 boolean PlayScoreTape(int);
280
281 void UndoTape(void);
282 void FixTape_ForceSinglePlayer(void);
283
284 int AutoPlayTapes(void);
285 int AutoPlayTapesContinue(void);
286 void PatchTapes(void);
287
288 void CreateTapeButtons(void);
289 void FreeTapeButtons(void);
290 void MapTapeEjectButton(void);
291 void MapTapeWarpButton(void);
292 void MapTapeButtons(void);
293 void UnmapTapeButtons(void);
294 void RedrawTapeButtons(void);
295 void RedrawOrRemapTapeButtons(void);
296
297 void HandleTapeButtonKeys(Key);
298
299 #endif