ScummVM API documentation
schedule.h
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 modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22/*
23 * This code is based on original Hugo Trilogy source code
24 *
25 * Copyright (c) 1989-1995 David P. Gray
26 *
27 */
28
29#ifndef HUGO_SCHEDULE_H
30#define HUGO_SCHEDULE_H
31
32#include "common/file.h"
33
34namespace Hugo {
35
39enum Action { // Parameters:
40 ANULL = 0xff, // Special NOP used to 'delete' events in DEL_EVENTS
41 ASCHEDULE = 0, // 0 - Ptr to action list to be rescheduled
42 START_OBJ, // 1 - Object number
43 INIT_OBJXY, // 2 - Object number, x,y
44 PROMPT, // 3 - index of prompt & response string, ptrs to action
45 // lists. First if response matches, 2nd if not.
46 BKGD_COLOR, // 4 - new background color
47 INIT_OBJVXY, // 5 - Object number, vx, vy
48 INIT_CARRY, // 6 - Object number, carried status
49 INIT_HF_COORD, // 7 - Object number (gets hero's 'feet' coordinates)
50 NEW_SCREEN, // 8 - New screen number
51 INIT_OBJSTATE, // 9 - Object number, new object state
52 INIT_PATH, // 10 - Object number, new path type
53 COND_R, // 11 - Conditional on object state - req state, 2 act_lists
54 TEXT, // 12 - Simple text box
55 SWAP_IMAGES, // 13 - Swap 2 object images
56 COND_SCR, // 14 - Conditional on current screen
57 AUTOPILOT, // 15 - Set object to home in on another (stationary) object
58 INIT_OBJ_SEQ, // 16 - Object number, sequence index to set curr_seqPtr to
59 SET_STATE_BITS, // 17 - Objnum, mask to OR with obj states word
60 CLEAR_STATE_BITS, // 18 - Objnum, mask to ~AND with obj states word
61 TEST_STATE_BITS, // 19 - Objnum, mask to test obj states word
62 DEL_EVENTS, // 20 - Action type to delete all occurrences of
63 GAMEOVER, // 21 - Disable hero & commands. Game is over
64 INIT_HH_COORD, // 22 - Object number (gets hero's actual coordinates)
65 EXIT, // 23 - Exit game back to DOS
66 BONUS, // 24 - Get score bonus for an action
67 COND_BOX, // 25 - Conditional on object within bounding box
68 SOUND, // 26 - Set currently playing sound
69 ADD_SCORE, // 27 - Add object's value to current score
70 SUB_SCORE, // 28 - Subtract object's value from current score
71 COND_CARRY, // 29 - Conditional on carrying object
72 INIT_MAZE, // 30 - Start special maze hotspot processing
73 EXIT_MAZE, // 31 - Exit special maze processing
74 INIT_PRIORITY, // 32 - Initialize fbg field
75 INIT_SCREEN, // 33 - Initialize screen field of object
76 AGSCHEDULE, // 34 - Global schedule - lasts over new screen
77 REMAPPAL, // 35 - Remappe palette - palette index, color
78 COND_NOUN, // 36 - Conditional on noun appearing in line
79 SCREEN_STATE, // 37 - Set new screen state - used for comments
80 INIT_LIPS, // 38 - Position lips object for supplied object
81 INIT_STORY_MODE, // 39 - Set story mode TRUE/FALSE (user can't type)
82 WARN, // 40 - Same as TEXT but can't dismiss box by typing
83 COND_BONUS, // 41 - Conditional on bonus having been scored
84 TEXT_TAKE, // 42 - Issue text box with "take" info string
85 YESNO, // 43 - Prompt user for Yes or No
86 STOP_ROUTE, // 44 - Skip any route in progress (hero still walks)
87 COND_ROUTE, // 45 - Conditional on route in progress
88 INIT_JUMPEXIT, // 46 - Initialize status.jumpexit
89 INIT_VIEW, // 47 - Initialize viewx, viewy, dir
90 INIT_OBJ_FRAME, // 48 - Object number, seq,frame to set curr_seqPtr to
91 OLD_SONG = 49 // Added by Strangerke - Set currently playing sound, old way: that is, using a string index instead of a reference in a file
92};
93
94struct act0 { // Type 0 - Schedule
95 Action _actType; // The type of action
96 int _timer; // Time to set off the action
97 uint16 _actIndex; // Ptr to an action list
98};
99
100struct act1 { // Type 1 - Start an object
101 Action _actType; // The type of action
102 int _timer; // Time to set off the action
103 int _objIndex; // The object number
104 int _cycleNumb; // Number of times to cycle
105 Cycle _cycle; // Direction to start cycling
106};
107
108struct act2 { // Type 2 - Initialize an object coords
109 Action _actType; // The type of action
110 int _timer; // Time to set off the action
111 int _objIndex; // The object number
112 int _x, _y; // Coordinates
113};
114
115struct act3 { // Type 3 - Prompt user for text
116 Action _actType; // The type of action
117 int _timer; // Time to set off the action
118 uint16 _promptIndex; // Index of prompt string
119 int *_responsePtr; // Array of indexes to valid response string(s) (terminate list with -1)
120 uint16 _actPassIndex; // Ptr to action list if success
121 uint16 _actFailIndex; // Ptr to action list if failure
122 bool _encodedFl; // (HUGO 1 DOS ONLY) Whether response is encoded or not
123};
124
125struct act4 { // Type 4 - Set new background color
126 Action _actType; // The type of action
127 int _timer; // Time to set off the action
128 long _newBackgroundColor; // New color
129};
130
131struct act5 { // Type 5 - Initialize an object velocity
132 Action _actType; // The type of action
133 int _timer; // Time to set off the action
134 int _objIndex; // The object number
135 int _vx, _vy; // velocity
136};
137
138struct act6 { // Type 6 - Initialize an object carrying
139 Action _actType; // The type of action
140 int _timer; // Time to set off the action
141 int _objIndex; // The object number
142 bool _carriedFl; // carrying
143};
144
145struct act7 { // Type 7 - Initialize an object to hero's coords
146 Action _actType; // The type of action
147 int _timer; // Time to set off the action
148 int _objIndex; // The object number
149};
150
151struct act8 { // Type 8 - switch to new screen
152 Action _actType; // The type of action
153 int _timer; // Time to set off the action
154 int _screenIndex; // The new screen number
155};
156
157struct act9 { // Type 9 - Initialize an object state
158 Action _actType; // The type of action
159 int _timer; // Time to set off the action
160 int _objIndex; // The object number
161 byte _newState; // New state
162};
163
164struct act10 { // Type 10 - Initialize an object path type
165 Action _actType; // The type of action
166 int _timer; // Time to set off the action
167 int _objIndex; // The object number
168 int _newPathType; // New path type
169 int8 _vxPath, _vyPath; // Max delta velocities e.g. for CHASE
170};
171
172struct act11 { // Type 11 - Conditional on object's state
173 Action _actType; // The type of action
174 int _timer; // Time to set off the action
175 int _objIndex; // The object number
176 byte _stateReq; // Required state
177 uint16 _actPassIndex; // Ptr to action list if success
178 uint16 _actFailIndex; // Ptr to action list if failure
179};
180
181struct act12 { // Type 12 - Simple text box
182 Action _actType; // The type of action
183 int _timer; // Time to set off the action
184 int _stringIndex; // Index (enum) of string in strings.dat
185};
186
187struct act13 { // Type 13 - Swap first object image with second
188 Action _actType; // The type of action
189 int _timer; // Time to set off the action
190 int _objIndex1; // Index of first object
191 int _objIndex2; // 2nd
192};
193
194struct act14 { // Type 14 - Conditional on current screen
195 Action _actType; // The type of action
196 int _timer; // Time to set off the action
197 int _objIndex; // The required object
198 int _screenReq; // The required screen number
199 uint16 _actPassIndex; // Ptr to action list if success
200 uint16 _actFailIndex; // Ptr to action list if failure
201};
202
203struct act15 { // Type 15 - Home in on an object
204 Action _actType; // The type of action
205 int _timer; // Time to set off the action
206 int _objIndex1; // The object number homing in
207 int _objIndex2; // The object number to home in on
208 int8 _dx, _dy; // Max delta velocities
209};
210
211// Note: Don't set a sequence at time 0 of a new screen, it causes
212// problems clearing the boundary bits of the object! timer > 0 is safe
213struct act16 { // Type 16 - Set curr_seqPtr to seq
214 Action _actType; // The type of action
215 int _timer; // Time to set off the action
216 int _objIndex; // The object number
217 int _seqIndex; // The index of seq array to set to
218};
219
220struct act17 { // Type 17 - SET obj individual state bits
221 Action _actType; // The type of action
222 int _timer; // Time to set off the action
223 int _objIndex; // The object number
224 int _stateMask; // The mask to OR with current obj state
225};
226
227struct act18 { // Type 18 - CLEAR obj individual state bits
228 Action _actType; // The type of action
229 int _timer; // Time to set off the action
230 int _objIndex; // The object number
231 int _stateMask; // The mask to ~AND with current obj state
232};
233
234struct act19 { // Type 19 - TEST obj individual state bits
235 Action _actType; // The type of action
236 int _timer; // Time to set off the action
237 int _objIndex; // The object number
238 int _stateMask; // The mask to AND with current obj state
239 uint16 _actPassIndex; // Ptr to action list (all bits set)
240 uint16 _actFailIndex; // Ptr to action list (not all set)
241};
242
243struct act20 { // Type 20 - Remove all events with this type of action
244 Action _actType; // The type of action
245 int _timer; // Time to set off the action
246 Action _actTypeDel; // The action type to remove
247};
248
249struct act21 { // Type 21 - Gameover. Disable hero & commands
250 Action _actType; // The type of action
251 int _timer; // Time to set off the action
252};
253
254struct act22 { // Type 22 - Initialize an object to hero's coords
255 Action _actType; // The type of action
256 int _timer; // Time to set off the action
257 int _objIndex; // The object number
258};
259
260struct act23 { // Type 23 - Exit game back to DOS
261 Action _actType; // The type of action
262 int _timer; // Time to set off the action
263};
264
265struct act24 { // Type 24 - Get bonus score
266 Action _actType; // The type of action
267 int _timer; // Time to set off the action
268 int _pointIndex; // Index into points array
269};
270
271struct act25 { // Type 25 - Conditional on bounding box
272 Action _actType; // The type of action
273 int _timer; // Time to set off the action
274 int _objIndex; // The required object number
275 int _x1, _y1, _x2, _y2; // The bounding box
276 uint16 _actPassIndex; // Ptr to action list if success
277 uint16 _actFailIndex; // Ptr to action list if failure
278};
279
280struct act26 { // Type 26 - Play a sound
281 Action _actType; // The type of action
282 int _timer; // Time to set off the action
283 int16 _soundIndex; // Sound index in data file
284};
285
286struct act27 { // Type 27 - Add object's value to score
287 Action _actType; // The type of action
288 int _timer; // Time to set off the action
289 int _objIndex; // object number
290};
291
292struct act28 { // Type 28 - Subtract object's value from score
293 Action _actType; // The type of action
294 int _timer; // Time to set off the action
295 int _objIndex; // object number
296};
297
298struct act29 { // Type 29 - Conditional on object carried
299 Action _actType; // The type of action
300 int _timer; // Time to set off the action
301 int _objIndex; // The required object number
302 uint16 _actPassIndex; // Ptr to action list if success
303 uint16 _actFailIndex; // Ptr to action list if failure
304};
305
306struct act30 { // Type 30 - Start special maze processing
307 Action _actType; // The type of action
308 int _timer; // Time to set off the action
309 byte _mazeSize; // Size of (square) maze
310 int _x1, _y1, _x2, _y2; // Bounding box of maze
311 int _x3, _x4; // Extra x points for perspective correction
312 byte _firstScreenIndex; // First (top left) screen of maze
313};
314
315struct act31 { // Type 31 - Exit special maze processing
316 Action _actType; // The type of action
317 int _timer; // Time to set off the action
318};
319
320struct act32 { // Type 32 - Init fbg field of object
321 Action _actType; // The type of action
322 int _timer; // Time to set off the action
323 int _objIndex; // The object number
324 byte _priority; // Value of foreground/background field
325};
326
327struct act33 { // Type 33 - Init screen field of object
328 Action _actType; // The type of action
329 int _timer; // Time to set off the action
330 int _objIndex; // The object number
331 int _screenIndex; // Screen number
332};
333
334struct act34 { // Type 34 - Global Schedule
335 Action _actType; // The type of action
336 int _timer; // Time to set off the action
337 uint16 _actIndex; // Ptr to an action list
338};
339
340struct act35 { // Type 35 - Remappe palette
341 Action _actType; // The type of action
342 int _timer; // Time to set off the action
343 int16 _oldColorIndex; // Old color index, 0..15
344 int16 _newColorIndex; // New color index, 0..15
345};
346
347struct act36 { // Type 36 - Conditional on noun mentioned
348 Action _actType; // The type of action
349 int _timer; // Time to set off the action
350 uint16 _nounIndex; // The required noun (list)
351 uint16 _actPassIndex; // Ptr to action list if success
352 uint16 _actFailIndex; // Ptr to action list if failure
353};
354
355struct act37 { // Type 37 - Set new screen state
356 Action _actType; // The type of action
357 int _timer; // Time to set off the action
358 int _screenIndex; // The screen number
359 byte _newState; // The new state
360};
361
362struct act38 { // Type 38 - Position lips
363 Action _actType; // The type of action
364 int _timer; // Time to set off the action
365 int _lipsObjIndex; // The LIPS object
366 int _objIndex; // The object to speak
367 byte _dxLips; // Relative offset of x
368 byte _dyLips; // Relative offset of y
369};
370
371struct act39 { // Type 39 - Init story mode
372 Action _actType; // The type of action
373 int _timer; // Time to set off the action
374 bool _storyModeFl; // New state of story_mode flag
375};
376
377struct act40 { // Type 40 - Unsolicited text box
378 Action _actType; // The type of action
379 int _timer; // Time to set off the action
380 int _stringIndex; // Index (enum) of string in strings.dat
381};
382
383struct act41 { // Type 41 - Conditional on bonus scored
384 Action _actType; // The type of action
385 int _timer; // Time to set off the action
386 int _bonusIndex; // Index into bonus list
387 uint16 _actPassIndex; // Index of the action list if scored for the first time
388 uint16 _actFailIndex; // Index of the action list if already scored
389};
390
391struct act42 { // Type 42 - Text box with "take" string
392 Action _actType; // The type of action
393 int _timer; // Time to set off the action
394 int _objIndex; // The object taken
395};
396
397struct act43 { // Type 43 - Prompt user for Yes or No
398 Action _actType; // The type of action
399 int _timer; // Time to set off the action
400 int _promptIndex; // index of prompt string
401 uint16 _actYesIndex; // Ptr to action list if YES
402 uint16 _actNoIndex; // Ptr to action list if NO
403};
404
405struct act44 { // Type 44 - Stop any route in progress
406 Action _actType; // The type of action
407 int _timer; // Time to set off the action
408};
409
410struct act45 { // Type 45 - Conditional on route in progress
411 Action _actType; // The type of action
412 int _timer; // Time to set off the action
413 int _routeIndex; // Must be >= current status.rindex
414 uint16 _actPassIndex; // Ptr to action list if en-route
415 uint16 _actFailIndex; // Ptr to action list if not
416};
417
418struct act46 { // Type 46 - Init status.jumpexit
419 Action _actType; // The type of action
420 int _timer; // Time to set off the action
421 bool _jumpExitFl; // New state of jumpexit flag
422};
423
424struct act47 { // Type 47 - Init viewx,viewy,dir
425 Action _actType; // The type of action
426 int _timer; // Time to set off the action
427 int _objIndex; // The object
428 int16 _viewx; // object.viewx
429 int16 _viewy; // object.viewy
430 int16 _direction; // object.dir
431};
432
433struct act48 { // Type 48 - Set curr_seqPtr to frame n
434 Action _actType; // The type of action
435 int _timer; // Time to set off the action
436 int _objIndex; // The object number
437 int _seqIndex; // The index of seq array to set to
438 int _frameIndex; // The index of frame to set to
439};
440
441struct act49 { // Added by Strangerke - Type 49 - Play a song (DOS way)
442 Action _actType; // The type of action
443 int _timer; // Time to set off the action
444 uint16 _songIndex; // Song index in string array
445};
446
447union Act {
448 act0 _a0;
449 act1 _a1;
450 act2 _a2;
451 act3 _a3;
452 act4 _a4;
453 act5 _a5;
454 act6 _a6;
455 act7 _a7;
456 act8 _a8;
457 act9 _a9;
458 act10 _a10;
459 act11 _a11;
460 act12 _a12;
461 act13 _a13;
462 act14 _a14;
463 act15 _a15;
464 act16 _a16;
465 act17 _a17;
466 act18 _a18;
467 act19 _a19;
468 act20 _a20;
469 act21 _a21;
470 act22 _a22;
471 act23 _a23;
472 act24 _a24;
473 act25 _a25;
474 act26 _a26;
475 act27 _a27;
476 act28 _a28;
477 act29 _a29;
478 act30 _a30;
479 act31 _a31;
480 act32 _a32;
481 act33 _a33;
482 act34 _a34;
483 act35 _a35;
484 act36 _a36;
485 act37 _a37;
486 act38 _a38;
487 act39 _a39;
488 act40 _a40;
489 act41 _a41;
490 act42 _a42;
491 act43 _a43;
492 act44 _a44;
493 act45 _a45;
494 act46 _a46;
495 act47 _a47;
496 act48 _a48;
497 act49 _a49;
498};
499
500struct Event {
501 Act *_action; // Ptr to action to perform
502 bool _localActionFl; // true if action is only for this screen
503 uint32 _time; // (absolute) time to perform action
504 struct Event *_prevEvent; // Chain to previous event
505 struct Event *_nextEvent; // Chain to next event
506};
507
511struct Point {
512 byte _score; // The value of the point
513 bool _scoredFl; // Whether scored yet
514};
515
517public:
519 virtual ~Scheduler();
520
521 virtual void decodeString(char *line) = 0;
522 virtual void runScheduler() = 0;
523
524 int16 calcMaxPoints() const;
525
526 void freeScheduler();
527 void initCypher();
528 void initEventQueue();
529 void insertActionList(const uint16 actIndex);
530 void loadActListArr(Common::ReadStream &in);
531 void loadAlNewscrIndex(Common::ReadStream &in);
532 void loadPoints(Common::SeekableReadStream &in);
533 void loadScreenAct(Common::SeekableReadStream &in);
534 void newScreen(const int screenIndex);
535 void processBonus(const int bonusIndex);
536 virtual void processMaze(const int x1, const int x2, const int y1, const int y2);
537 void restoreSchedulerData(Common::ReadStream *in);
538 void restoreScreen(const int screenIndex);
539 void saveSchedulerData(Common::WriteStream *out);
540 void waitForRefresh();
541
542protected:
543 HugoEngine *_vm;
544 static const int kFilenameLength = 12; // Max length of a DOS file name
545 static const int kMaxEvents = 50; // Max events in event queue
546 static const int kShiftSize = 8; // Place hero this far inside bounding box
547
548 Common::String _cypher;
549
550 uint16 _actListArrSize;
551 uint16 _alNewscrIndex;
552 uint16 _screenActsSize;
553 uint16 **_screenActs;
554
555 byte _numBonuses;
556 Point *_points;
557
558 uint32 _curTick; // Current system time in ticks
559 uint32 _oldTime; // The previous wall time in ticks
560 uint32 _refreshTimeout;
561
562 Event *_freeEvent; // Free list of event structures
563 Event *_headEvent; // Head of list (earliest time)
564 Event *_tailEvent; // Tail of list (latest time)
565 Event _events[kMaxEvents]; // Statically declare event structures
566
567 Act **_actListArr;
568
569 virtual const char *getCypher() const = 0;
570
571 virtual uint32 getTicks() = 0;
572
573 virtual void promptAction(Act *action) = 0;
574
575 Event *doAction(Event *curEvent);
576 Event *getQueue();
577
578 uint32 getDosTicks(const bool updateFl);
579 uint32 getWinTicks() const;
580
581 void delEventType(const Action actTypeDel);
582 void delQueue(Event *curEvent);
583 void findAction(const Act* action, int16* index, int16* subElem);
584 void insertAction(Act *action);
585 void readAct(Common::ReadStream &in, Act &curAct);
586 void restoreActions(Common::ReadStream *f);
587 void restoreEvents(Common::ReadStream *f);
588 void restorePoints(Common::ReadStream *in);
589 void saveActions(Common::WriteStream* f) const;
590 void saveEvents(Common::WriteStream *f);
591 void savePoints(Common::WriteStream *out) const;
592 void screenActions(const int screenNum);
593
594};
595
596class Scheduler_v1d : public Scheduler {
597public:
599 ~Scheduler_v1d() override;
600
601 void decodeString(char *line) override;
602 void runScheduler() override;
603
604protected:
605 const char *getCypher() const override;
606 uint32 getTicks() override;
607 void promptAction(Act *action) override;
608};
609
611public:
613 ~Scheduler_v2d() override;
614
615 void decodeString(char *line) override;
616
617protected:
618 const char *getCypher() const override;
619
620 void promptAction(Act *action) override;
621};
622
624public:
626 ~Scheduler_v3d() override;
627
628protected:
629 const char *getCypher() const override;
630};
631
633public:
635 ~Scheduler_v1w() override;
636
637 void runScheduler() override;
638 void processMaze(const int x1, const int x2, const int y1, const int y2) override;
639
640protected:
641 uint32 getTicks() override;
642
643};
644} // End of namespace Hugo
645#endif //HUGO_SCHEDULE_H
Definition: stream.h:385
Definition: stream.h:745
Definition: str.h:59
Definition: stream.h:77
Definition: hugo.h:219
Definition: schedule.h:596
Definition: schedule.h:632
Definition: schedule.h:610
Definition: schedule.h:623
Definition: schedule.h:516
Definition: console.h:27
Action
Definition: schedule.h:39
Cycle
Definition: game.h:64
Definition: schedule.h:500
Definition: schedule.h:511
Definition: schedule.h:94
Definition: schedule.h:164
Definition: schedule.h:172
Definition: schedule.h:181
Definition: schedule.h:187
Definition: schedule.h:194
Definition: schedule.h:203
Definition: schedule.h:213
Definition: schedule.h:220
Definition: schedule.h:227
Definition: schedule.h:234
Definition: schedule.h:100
Definition: schedule.h:243
Definition: schedule.h:249
Definition: schedule.h:254
Definition: schedule.h:260
Definition: schedule.h:265
Definition: schedule.h:271
Definition: schedule.h:280
Definition: schedule.h:286
Definition: schedule.h:292
Definition: schedule.h:298
Definition: schedule.h:108
Definition: schedule.h:306
Definition: schedule.h:315
Definition: schedule.h:320
Definition: schedule.h:327
Definition: schedule.h:334
Definition: schedule.h:340
Definition: schedule.h:347
Definition: schedule.h:355
Definition: schedule.h:362
Definition: schedule.h:371
Definition: schedule.h:115
Definition: schedule.h:377
Definition: schedule.h:383
Definition: schedule.h:391
Definition: schedule.h:397
Definition: schedule.h:405
Definition: schedule.h:410
Definition: schedule.h:418
Definition: schedule.h:424
Definition: schedule.h:433
Definition: schedule.h:441
Definition: schedule.h:125
Definition: schedule.h:131
Definition: schedule.h:138
Definition: schedule.h:145
Definition: schedule.h:151
Definition: schedule.h:157
Definition: schedule.h:447