aboutsummaryrefslogtreecommitdiff
path: root/engines/mads/animation.h
blob: 5faa47841eb6bcbe49f10adadfa8a92b07ef031f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef MADS_ANIMATION_H
#define MADS_ANIMATION_H

#include "common/scummsys.h"
#include "common/array.h"
#include "common/rect.h"
#include "mads/msurface.h"
#include "mads/scene_data.h"
#include "mads/font.h"
#include "mads/user_interface.h"

namespace MADS {

enum AnimFlag { 
	ANIMFLAG_DITHER				= 0x0001,	// Dither to 16 colors
	ANIMFLAG_CUSTOM_FONT		= 0x0020,	// Load ccustom font 
	ANIMFLAG_LOAD_BACKGROUND	= 0x0100,	// Load background
	ANIMFLAG_LOAD_BACKGROUND_ONLY = 0x0200	// Load background only
};

class MADSEngine;
class Scene;

class AnimMessage {
public:
	int16 _soundId;
	Common::String _msg;
	Common::Point _pos;
	byte _rgb1[3], _rgb2[3];
	int _flags;
	int _startFrame, _endFrame;
	int _kernelMsgIndex;

	/**
	 * Loads data for the message from a stream
	 */
	void load(Common::SeekableReadStream *f);
};

class AnimFrameEntry {
public:
	int _frameNumber;
	int _seqIndex;
	SpriteSlotSubset _spriteSlot;

	/**
	 * Loads data for the record
	 */
	void load(Common::SeekableReadStream *f, bool uiFlag);
};

class AnimMiscEntry {
public:
	int _soundId;
	int _msgIndex;
	int _numTicks;
	Common::Point _posAdjust;
	int _field8;

	/**
	* Loads data for the record
	*/
	void load(Common::SeekableReadStream *f);
};

#define ANIM_SPAWN_COUNT 2

class AnimUIEntry {
public:
	int _probability;
	int _imageCount;
	int _firstImage;
	int _lastImage;
	int _counter;
	int _spawn[ANIM_SPAWN_COUNT];
	int _spawnFrame[ANIM_SPAWN_COUNT];
	int _sound;
	int _soundFrame;

	/**
	 * Loads the data for the record
	 */
	void load(Common::SeekableReadStream *f);
};

class AAHeader {
public:
	int _spriteSetsCount;
	int _miscEntriesCount;
	int _frameEntriesCount;
	int _messagesCount;
	byte _flags;
	int _animMode;
	int _roomNumber;
	bool _manualFlag;
	int _spritesIndex;
	Common::Point _scrollPosition;
	uint32 _scrollTicks;
	Common::String _interfaceFile;
	Common::StringArray _spriteSetNames;
	Common::String _lbmFilename;
	Common::String _spritesFilename;
	Common::String _soundName;
	Common::String _dsrName;
	Common::String _fontResource;

	/**
	 * Loads the data for a animation file header
	 */
	void load(Common::SeekableReadStream *f);
};

class Animation {
private:
	MADSEngine *_vm;
	Scene *_scene;

	Common::Array<AnimMiscEntry> _miscEntries;
	Common::Array<SpriteAsset *> _spriteSets;
	Font *_font;

	int _currentFrame;
	bool _freeFlag;
	bool _skipLoad;
	int _unkIndex;
	Common::Point _unkList[2];
	uint32 _nextFrameTimer;
	uint32 _nextScrollTimer;
	int _messageCtr;
	int _trigger;
	TriggerMode _triggerMode;
	ActionDetails _actionDetails;

	/**
	 * Load data for a given frame
	 * @param frameNumber	Frame number
	 */
	void loadFrame(int frameNumber);

	bool drawFrame(SpriteAsset &spriteSet, const Common::Point &pt, int frameNumber);

	/**
	 * Load the user interface display for an animation
	 */
	void loadInterface(UserInterface &interfaceSurface, MSurface &depthSurface,
		AAHeader &header, int flags, Common::Array<PaletteCycle> *palCycles, SceneInfo *sceneInfo);

	/**
	 * Returns true if there is a scroll required
	 */
	bool hasScroll() const;
protected:
	Animation(MADSEngine *vm, Scene *scene);
public:
	AAHeader _header;
	Common::Array<int> _spriteListIndexes;
	Common::Array<AnimFrameEntry> _frameEntries;
	Common::Array<AnimUIEntry> _uiEntries;
	Common::Array<AnimMessage> _messages;
	bool _resetFlag;
	int _oldFrameEntry;

	static Animation *init(MADSEngine *vm, Scene *scene);
	/*
	 * Destructor
	 */
	~Animation();

	/**
	 * Loads animation data
	 */
	void load(UserInterface &interfaceSurface, MSurface &depthSurface, const Common::String &resName,
		int flags, Common::Array<PaletteCycle> *palCycles, SceneInfo *sceneInfo);

	/**
	 * Preload animation data for the scene
	 */
	void preLoad(const Common::String &resName, int level);

	/**
	 * Setups up a loaded animation for playback
	 */
	void startAnimation(int abortTimers);

	/**
	 * Update the animation
	 */
	void update();

	void setNextFrameTimer(int frameNumber);
	void setCurrentFrame(int frameNumber);
	int getCurrentFrame() const { return _currentFrame; }

	bool freeFlag() const { return _freeFlag; }
	bool getAnimMode() const { return _header._animMode; }
	int roomNumber() const { return _header._roomNumber; }
};

} // End of namespace MADS

#endif /* MADS_ANIMATION_H */