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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef MADS_SEQUENCE_H
24 #define MADS_SEQUENCE_H
25 
26 #include "common/scummsys.h"
27 #include "common/array.h"
28 #include "common/rect.h"
29 #include "mads/action.h"
30 
31 namespace MADS {
32 
33 class SpriteSlot;
34 
35 enum SequenceTrigger {
36 	SEQUENCE_TRIGGER_EXPIRE = 0,	// Trigger when the sequence finishes
37 	SEQUENCE_TRIGGER_LOOP = 1,		// Trigger when the sequence loops
38 	SEQUENCE_TRIGGER_SPRITE = 2		// Trigger when sequence reaches specific sprite
39 };
40 
41 enum SpriteAnimType { ANIMTYPE_NONE = 0, ANIMTYPE_CYCLED = 1, ANIMTYPE_PING_PONG = 2, ANIMTYPE_STAMP = 9 };
42 
43 #define SEQUENCE_ENTRY_SUBSET_MAX 5
44 
45 struct SequenceSubEntries {
46 	int _count;
47 	SequenceTrigger _mode[SEQUENCE_ENTRY_SUBSET_MAX];
48 	int _frameIndex[SEQUENCE_ENTRY_SUBSET_MAX];
49 	int _trigger[SEQUENCE_ENTRY_SUBSET_MAX];
50 };
51 
52 struct SequenceEntry {
53 	bool _active;
54 	int8 _spritesIndex;
55 	bool _flipped;
56 
57 	int _frameIndex;
58 	int _frameStart;
59 	int _numSprites;
60 
61 	SpriteAnimType _animType;
62 	int _frameInc;
63 
64 	int _depth;
65 	int _scale;
66 	int _dynamicHotspotIndex;
67 
68 	bool _nonFixed;
69 	uint32 _flags;
70 
71 	Common::Point _position;
72 	Common::Point _posDiff;
73 	Common::Point _posSign;
74 	Common::Point _posAccum;
75 	int _triggerCountdown;
76 	bool _doneFlag;
77 	SequenceSubEntries _entries;
78 	TriggerMode _triggerMode;
79 
80 	ActionDetails _actionNouns;
81 	int _numTicks;
82 	int _extraTicks;
83 	uint32 _timeout;
84 
85 	SequenceEntry();
86 };
87 
88 class MADSEngine;
89 
90 class SequenceList {
91 private:
92 	MADSEngine *_vm;
93 	Common::Array<SequenceEntry> _entries;
94 public:
95 	SequenceList(MADSEngine *vm);
96 
97 	SequenceEntry &operator[](int index) { return _entries[index]; }
98 	void clear();
99 	bool addSubEntry(int index, SequenceTrigger mode, int frameIndex, int trigger);
100 	int add(int spriteListIndex, bool flipped, int frameIndex, int triggerCountdown, int delayTicks,
101 		int extraTicks, int numTicks, int msgX, int msgY, bool nonFixed, int scale, int depth,
102 		int frameInc, SpriteAnimType animType, int numSprites, int frameStart);
103 
104 	int addTimer(int timeout, int endTrigger);
105 	void remove(int seqIndex);
106 	int findByTrigger(int trigger);
107 	void setSpriteSlot(int seqIndex, SpriteSlot &spriteSlot);
108 	bool loadSprites(int seqIndex);
109 	void tick();
110 	void delay(uint32 priorFrameTime, uint32 currentTime);
111 	void setAnimRange(int seqIndex, int startVal, int endVal);
112 	void scan();
113 	void setDepth(int seqIndex, int depth);
114 	void setPosition(int seqIndex, const Common::Point &pt);
115 	int addSpriteCycle(int srcSpriteIdx, bool flipped, int numTicks,
116 		int triggerCountdown = 0, int timeoutTicks = 0, int extraTicks = 0);
117 	int addReverseSpriteCycle(int srcSpriteIdx, bool flipped, int numTicks,
118 		int triggerCountdown = 0, int timeoutTicks = 0, int extraTicks = 0);
119 
120 	int startCycle(int srcSpriteIdx, bool flipped, int cycleIndex);
121 	int startPingPongCycle(int srcSpriteIndex, bool flipped, int numTicks,
122 		int triggerCountdown = 0, int timeoutTicks = 0, int extraTicks = 0);
123 	void updateTimeout(int destSeqIndex, int srcSeqIndex);
124 	void setScale(int spriteIdx, int scale);
125 	void setMsgLayout(int seqIndex);
126 	void setDone(int seqIndex);
127 	void setMotion(int seqIndex, int flags, int deltaX, int deltaY);
128 
129 	int addStampCycle(int srcSpriteIdx, bool flipped, int sprite);
130 	void setSeqPlayer(int idx, bool flag);
131 };
132 
133 } // End of namespace MADS
134 
135 #endif /* MADS_SEQUENCE_H */
136