25 #include "advancedDetector.h" 26 #include "audio/audiostream.h" 27 #include "audio/mixer.h" 28 #include "common/array.h" 29 #include "common/error.h" 30 #include "common/file.h" 31 #include "common/fs.h" 32 #include "common/hashmap.h" 33 #include "common/memstream.h" 34 #include "common/random.h" 35 #include "common/scummsys.h" 36 #include "common/serializer.h" 37 #include "common/system.h" 38 #include "common/text-to-speech.h" 39 #include "common/util.h" 40 #include "engines/engine.h" 41 #include "macs2/events.h" 42 #include "macs2/macs2_constants.h" 43 #include "macs2/scriptexecutor.h" 70 virtual int readBuffer(int16 *buffer,
const int numSamples);
94 struct Macs2GameDescription;
119 Common::Point getBottomMiddleOffset(uint16 scale = 100)
const;
126 uint32 _frameIndex = 0;
133 uint16 _unknown0C = 0;
134 uint8 _unknown0E = 0;
135 uint8 _unknown0F = 0;
166 bool isValid()
const {
return _blob.
size() >= 14; }
169 uint16 sequencePosition()
const {
return READ_LE_UINT16(&_blob[0x02]); }
170 uint16 repeatCounter()
const {
return READ_LE_UINT16(&_blob[0x04]); }
171 uint16 loopStartPosition()
const {
return READ_LE_UINT16(&_blob[0x06]); }
172 uint16 delayCounter()
const {
return READ_LE_UINT16(&_blob[0x08]); }
173 uint16 sequenceLength()
const {
return READ_LE_UINT16(&_blob[0x0A]) + 1; }
176 uint32 frameDataOffset()
const {
return 0x0B + sequenceLength(); }
177 uint16 frameCount()
const {
178 uint32 off = frameDataOffset();
179 if (off + 2 > _blob.
size())
181 return READ_LE_UINT16(&_blob[off]);
194 bool getFrameInfo(uint16 index,
FrameInfo &out)
const {
195 uint32 pos = frameDataOffset() + 2;
196 for (uint16 i = 0; i <= index; i++) {
197 if (pos + 10 > _blob.
size())
199 int16 ox = (int16)READ_LE_UINT16(&_blob[pos]);
200 int16 oy = (int16)READ_LE_UINT16(&_blob[pos + 2]);
201 uint16 unk = READ_LE_UINT16(&_blob[pos + 4]);
202 uint16 w = READ_LE_UINT16(&_blob[pos + 6]);
203 uint16 h = READ_LE_UINT16(&_blob[pos + 8]);
205 if (w == 0 || h == 0 || pos + (uint32)w * h > _blob.
size())
208 out = {ox, oy, unk, w, h, &_blob[pos]};
211 pos += (uint32)w * h;
226 uint16 _overrideValue;
231 #define AREA_OVERRIDE_MIN 200 232 #define AREA_OVERRIDE_MAX 239 233 #define AREA_OVERRIDE_COUNT (AREA_OVERRIDE_MAX - AREA_OVERRIDE_MIN + 1) 239 Music *_adlib =
nullptr;
255 void readResourceFile();
259 void readExecutable();
271 void changeScene(uint32 newSceneIndex,
bool executeScript =
true);
279 uint32 _mapImageFileOffset = 0;
283 int64 _mapSubSceneTableFilePos = 0;
294 byte _pal[256 * 3] = {0};
295 byte _palVanilla[256 * 3] = {0};
305 uint16 _areaOverrides[AREA_OVERRIDE_COUNT] = {0};
306 uint16 _pathfindingPoints[32];
310 bool getPathfindingOverride(uint16 index, uint16 &result);
311 void setPathfindingOverride(uint16 index, uint16 overrideValue);
315 static inline bool isWalkabilityBlocking(uint16 value) {
316 return (int16)value >= 0xC8;
318 static inline bool isWalkabilityWalkable(uint16 value) {
319 return (int16)value < 0xC8;
323 uint16 getPathfindingOverride2(uint16 index);
324 void removePathfindingOverride(uint16 index);
326 uint16 getWalkabilityAt(int16 y, int16 x);
327 bool isPathWalkable(int16 y1, int16 x1, int16 y2, int16 x2);
328 void snapToWalkablePosition(int16 *pTargetY, int16 *pTargetX, int16 charY, int16 charX);
329 int getPathfindingNodeCount()
const {
return (
int)_numPathfindingPoints; }
331 int walkableDistance(
int nodeA,
int nodeB);
332 int computeMinCostToReachable(
int nodeIndex,
int prevNode, uint16 actorIndex,
const bool *reachable,
int nodeCount,
const Common::Point &finalDest);
342 uint16 numOverlayGlyphs = 0;
343 uint16 maxOverlayGlyphHeight = 0;
344 uint16 numPanelGlyphs = 0;
345 uint16 maxPanelGlyphHeight = 0;
346 bool loadOverlayFont(uint8 resourceIndex, uint16 executingObjectID);
348 uint16 numGlyphs = 79;
349 uint16 maxGlyphHeight;
354 bool findGlyph(
char c,
GlyphData &out)
const;
364 uint32 _mapSceneOffsets[256] = {0};
371 void setCursorMode(Script::MouseMode newMode);
372 void nextCursorMode();
376 uint16 _numPathfindingPoints;
377 uint16 _walkDepthThresholdY;
378 uint16 _walkDepthScaleFactor;
379 uint16 _walkBaseSpeedPct;
385 uint16 _scenePaletteMode;
388 uint16 _paletteDarkenPercent;
390 void applyPaletteDarkening();
394 void applyScenePaletteEffect();
401 void updateBackgroundAnimationPalette();
405 bool _movementFinishedFlag =
false;
409 bool loadAnimationFromSceneData(uint16 objectIndex, uint16 slotIndex, uint8 arrayIndex,
bool shouldMirror =
false, uint16 executingScriptObjectId = 0);
413 void sortObjectsByDepth(uint16 objectIndex);
415 void loadSongFromSceneData(uint8 dataIndex);
416 Music *getAdlib()
const {
return _adlib; }
418 uint16 scaledMusicVolume(uint16 gameAttenuation)
const;
420 void clearCurrentSoundData();
421 void playCurrentSound();
422 void stopCurrentSound();
423 bool hasCurrentSound()
const {
return !_currentSoundData.empty(); }
424 bool isCurrentSoundPlaying()
const;
432 uint32 _sceneTimerParams[4] = {0};
438 bool _clipRectDirty =
false;
445 void runScriptExecutor(
bool firstRun =
false) {
446 _scriptExecutor->run(firstRun);
449 bool _runScheduled =
false;
452 bool _scheduledRunIsInitScene =
false;
456 uint16 _gameSpeedMode = 0;
457 void setGameSpeedMode(uint16 mode);
463 enum class InputMode { None,
466 InputMode _inputMode = InputMode::None;
469 uint32 _inputFrameCounter = 0;
470 uint32 _inputPlaybackEndFrame = 0;
474 void stopInputRecording();
475 void recordInputFrame(uint16 mouseX, uint16 mouseY, uint16 buttons);
476 bool readInputFrame(uint16 &mouseX, uint16 &mouseY, uint16 &buttons);
482 void scheduleRun(
bool initScene =
false);
500 void loadTranslation();
505 uint32 getFeatures()
const;
507 bool isDemo()
const {
return getFeatures() &
ADGF_DEMO; }
515 return (f == kSupportsLoadingDuringRuntime) ||
516 (f == kSupportsSavingDuringRuntime) ||
517 (f == kSupportsReturnToLauncher) ||
518 (f == kSupportsChangingOptionsDuringRuntime);
521 void syncSoundSettings()
override;
554 bool tick()
override;
556 void sayText(
const Common::String &text, Common::TextToSpeechManager::Action action = Common::TextToSpeechManager::INTERRUPT_NO_REPEAT)
const;
559 bool hotspotDirty()
const override;
560 void rebuildHotspotSnapshot()
const;
570 uint16 orientation = 0;
573 int currentSceneIndex = -1;
574 uint16 numHotspots = 0;
579 bool mapModeActive =
false;
585 #define SHOULD_QUIT ::Macs2::g_engine->shouldQuit() 589 #endif // MACS2_MACS2H Definition: managed_surface.h:51
virtual int readBuffer(int16 *buffer, const int numSamples)
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: macs2.h:526
EngineFeature
Definition: engine.h:282
bool hasFeature(EngineFeature f) const override
Definition: macs2.h:514
virtual Audio::Timestamp getLength() const
Definition: gameobjects.h:86
virtual bool isStereo() const
Definition: advancedDetector.h:164
virtual int getRate() const
Definition: timestamp.h:83
Definition: scriptexecutor.h:99
Definition: serializer.h:80
Definition: audiostream.h:212
bool shouldQuit() const override
Definition: macs2.h:248
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Definition: macs2.h:543
virtual bool endOfData() const
size_type size() const
Definition: array.h:316
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: macs2.h:523
Definition: memstream.h:43
Definition: debugtools.h:25
virtual bool seek(const Audio::Timestamp &where)
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
Definition: macs2.h:539
Add "-demo" to gameid.
Definition: advancedDetector.h:157