Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/archive.h"
#include "pink/objects/actions/action.h"
#include "pink/objects/actors/actor.h"
namespace Pink {
void Action::deserialize(Archive &archive) {
NamedObject::deserialize(archive);
_actor = static_cast<Actor *>(archive.readObject());
}
bool Action::initPalette(Screen *screen) {
return false;
}
void Action::pause(bool paused) {}
Coordinates Action::getCoordinates() {
return Coordinates();
}
} // End of namespace Pink

View File

@@ -0,0 +1,53 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_ACTION_H
#define PINK_ACTION_H
#include "pink/objects/object.h"
#include "pink/objects/walk/walk_mgr.h"
namespace Pink {
class Actor;
class Screen;
class Action : public NamedObject {
public:
void deserialize(Archive &archive) override;
virtual bool initPalette(Screen *screen);
virtual void start() = 0;
virtual void end() = 0;
virtual void pause(bool paused);
virtual Coordinates getCoordinates();
Actor *getActor() const { return _actor; }
protected:
Actor *_actor;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,111 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/debug.h"
#include "common/substream.h"
#include "pink/archive.h"
#include "pink/cel_decoder.h"
#include "pink/screen.h"
#include "pink/pink.h"
#include "pink/objects/actions/action_cel.h"
#include "pink/objects/actors/actor.h"
#include "pink/objects/pages/game_page.h"
namespace Pink {
ActionCEL::~ActionCEL() {
end();
}
void ActionCEL::deserialize(Archive &archive) {
Action::deserialize(archive);
_fileName = archive.readString();
_z = archive.readDWORD();
}
bool ActionCEL::initPalette(Screen *screen) {
loadDecoder();
if (_decoder.getCurFrame() == -1) {
_decoder.decodeNextFrame();
_decoder.rewind();
}
screen->setPalette(_decoder.getPalette());
return true;
}
void ActionCEL::start() {
loadDecoder();
_decoder.start();
this->onStart();
_actor->getPage()->getGame()->getScreen()->addSprite(this);
}
void ActionCEL::end() {
_actor->getPage()->getGame()->getScreen()->removeSprite(this);
_decoder.close();
}
void ActionCEL::pause(bool paused) {
_decoder.pauseVideo(paused);
}
Coordinates ActionCEL::getCoordinates() {
loadDecoder();
Coordinates coords;
coords.point = _decoder.getCenter();
coords.z = getZ();
return coords;
}
void ActionCEL::loadDecoder() {
if (!_decoder.isVideoLoaded()) {
_decoder.loadStream(_actor->getPage()->getResourceStream(_fileName));
Common::Point point = _decoder.getCenter();
_bounds = Common::Rect::center(point.x, point.y, _decoder.getWidth(), _decoder.getHeight());
}
}
void ActionCEL::setFrame(uint frame) {
_decoder.rewind();
for (uint i = 0; i < frame; ++i) {
_decoder.skipFrame();
}
_decoder.clearDirtyRects();
_actor->getPage()->getGame()->getScreen()->addDirtyRect(_bounds);
}
void ActionCEL::decodeNext() {
_decoder.decodeNextFrame();
_actor->getPage()->getGame()->getScreen()->addDirtyRects(this);
}
void ActionCEL::setCenter(Common::Point center) {
_actor->getPage()->getGame()->getScreen()->addDirtyRect(_bounds);
_bounds = Common::Rect::center(center.x, center.y, _decoder.getWidth(), _decoder.getHeight());
_actor->getPage()->getGame()->getScreen()->addDirtyRect(_bounds);
}
} // End of namespace Pink

View File

@@ -0,0 +1,73 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_ACTION_CEL_H
#define PINK_ACTION_CEL_H
#include "pink/cel_decoder.h"
#include "pink/objects/actions/action.h"
namespace Pink {
class CelDecoder;
class ActionCEL : public Action {
public:
~ActionCEL() override;
void deserialize(Archive &archive) override;
bool initPalette(Screen *screen) override;
void start() override;
void end() override;
bool needsUpdate() { return _decoder.needsUpdate(); }
virtual void update() {};
void pause(bool paused) override;
Coordinates getCoordinates() override;
const Common::Rect &getBounds() const { return _bounds; }
uint32 getZ() { return _z; }
CelDecoder *getDecoder() { return &_decoder; }
void setCenter(Common::Point center);
void loadDecoder();
protected:
virtual void onStart() = 0;
void decodeNext();
void setFrame(uint frame);
CelDecoder _decoder;
Common::String _fileName;
Common::Rect _bounds;
uint32 _z;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,42 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/archive.h"
#include "pink/pink.h"
#include "pink/objects/actions/action_hide.h"
#include "pink/objects/actors/actor.h"
namespace Pink {
void ActionHide::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\tActionHide: _name = %s", _name.c_str());
}
void ActionHide::start() {
debugC(6, kPinkDebugActions, "Actor %s has now ActionHide %s", _actor->getName().c_str(), _name.c_str());
_actor->endAction();
}
void ActionHide::end() {
debugC(6, kPinkDebugActions, "ActionHide %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str());
}
} //End of namespace Pink

View File

@@ -0,0 +1,39 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_ACTION_HIDE_H
#define PINK_ACTION_HIDE_H
#include "pink/objects/actions/action.h"
namespace Pink {
class ActionHide : public Action {
public:
void toConsole() const override;
void start() override;
void end() override;
};
} //End of namespace Pink
#endif

View File

@@ -0,0 +1,129 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/random.h"
#include "pink/pink.h"
#include "pink/cel_decoder.h"
#include "pink/objects/actions/action_loop.h"
#include "pink/objects/actors/actor.h"
#include "pink/objects/pages/page.h"
namespace Pink {
void ActionLoop::deserialize(Archive &archive) {
ActionPlay::deserialize(archive);
uint16 style;
_intro = archive.readDWORD();
style = archive.readWORD();
switch (style) {
case kPingPong:
_style = kPingPong;
break;
case kRandom:
_style = kRandom;
break;
default:
_style = kForward;
break;
}
}
void ActionLoop::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\tActionLoop: _name = %s, _fileName = %s, z = %u, _startFrame = %u,"
" _endFrame = %d, _intro = %u, _style = %u",
_name.c_str(), _fileName.c_str(), _z, _startFrame, _stopFrame, _intro, _style);
}
void ActionLoop::update() {
int32 frame = _decoder.getCurFrame();
if (!_inLoop) {
if (frame < (int32)_startFrame) {
decodeNext();
return;
} else
_inLoop = true;
}
switch (_style) {
case kPingPong:
if (_forward) {
if (frame < _stopFrame) {
decodeNext();
} else {
_forward = false;
ActionCEL::setFrame(_stopFrame - 1);
decodeNext();
}
} else {
if (frame > (int32)_startFrame) {
ActionCEL::setFrame(frame - 1);
} else {
_forward = true;
}
decodeNext();
}
break;
case kRandom: {
Common::RandomSource &rnd = _actor->getPage()->getGame()->getRnd();
ActionCEL::setFrame(rnd.getRandomNumberRng(_startFrame, _stopFrame));
decodeNext();
break;
}
case kForward:
if (frame == _stopFrame) {
ActionCEL::setFrame(_startFrame);
}
decodeNext();
break;
default:
break;
}
}
void ActionLoop::onStart() {
if (_intro) {
uint startFrame = _startFrame;
_startFrame = 0;
ActionPlay::onStart();
_startFrame = startFrame;
_inLoop = false;
} else {
ActionPlay::onStart();
_inLoop = true;
}
if (!isTalk())
_actor->endAction();
_forward = true;
}
void ActionLoop::end() {
ActionCEL::end();
debugC(6, kPinkDebugActions, "ActionLoop %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str());
}
} // End of namespace Pink

View File

@@ -0,0 +1,56 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_ACTION_LOOP_H
#define PINK_ACTION_LOOP_H
#include "pink/objects/actions/action_play.h"
namespace Pink {
class ActionLoop : public ActionPlay {
public:
void deserialize(Archive &archive) override;
void toConsole() const override;
void update() override;
void end() override;
protected:
void onStart() override;
virtual bool isTalk() { return false; }
enum Style {
kPingPong = 2,
kRandom = 3,
kForward = 4
};
Style _style;
bool _intro;
bool _inLoop;
bool _forward;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,77 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/debug.h"
#include "pink/archive.h"
#include "pink/cel_decoder.h"
#include "pink/pink.h"
#include "pink/objects/actions/action_play.h"
#include "pink/objects/actors/actor.h"
namespace Pink {
void ActionPlay::deserialize(Archive &archive) {
ActionStill::deserialize(archive);
_stopFrame = archive.readDWORD();
}
void ActionPlay::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\tActionPlay: _name = %s, _fileName = %s, z = %u, _startFrame = %u,"
" _endFrame = %d", _name.c_str(), _fileName.c_str(), _z, _startFrame, _stopFrame);
}
void ActionPlay::end() {
ActionCEL::end();
debugC(6, kPinkDebugActions, "ActionPlay %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str());
}
void ActionPlay::update() {
ActionCEL::update();
if (_decoder.getCurFrame() >= _stopFrame) {
_decoder.setEndOfTrack();
assert(!_decoder.needsUpdate());
_actor->endAction();
} else
decodeNext();
}
void ActionPlay::pause(bool paused) {
ActionCEL::pause(paused);
}
void ActionPlay::onStart() {
debugC(6, kPinkDebugActions, "Actor %s has now ActionPlay %s", _actor->getName().c_str(), _name.c_str());
int32 frameCount = _decoder.getFrameCount();
if ((int32)_startFrame >= frameCount) {
_startFrame = 0;
}
if (_stopFrame == -1 || _stopFrame >= frameCount) {
_stopFrame = frameCount - 1;
}
ActionCEL::setFrame(_startFrame);
// doesn't need to decode startFrame here. Update method will decode
}
} // End of namespace Pink

View File

@@ -0,0 +1,49 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_ACTION_PLAY_H
#define PINK_ACTION_PLAY_H
#include "pink/objects/actions/action_still.h"
namespace Pink {
class ActionPlay : public ActionStill {
public:
void deserialize(Archive &archive) override;
void toConsole() const override;
void end() override;
void update() override;
void pause(bool paused) override;
protected:
void onStart() override;
int32 _stopFrame;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,110 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/cel_decoder.h"
#include "pink/sound.h"
#include "pink/pink.h"
#include "pink/objects/actors/actor.h"
#include "pink/objects/actions/action_play_with_sfx.h"
#include "pink/objects/pages/game_page.h"
#include "pink/objects/sequences/sequencer.h"
namespace Pink {
ActionPlayWithSfx::~ActionPlayWithSfx() {
ActionPlay::end();
for (uint i = 0; i < _sfxArray.size(); ++i) {
delete _sfxArray[i];
}
}
void ActionPlayWithSfx::deserialize(Pink::Archive &archive) {
ActionPlay::deserialize(archive);
_isLoop = archive.readDWORD();
_sfxArray.deserialize(archive);
}
void ActionPlayWithSfx::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\tActionPlayWithSfx: _name = %s, _fileName = %s, z = %u, _startFrame = %u,"
" _endFrame = %d, _isLoop = %u", _name.c_str(), _fileName.c_str(), _z, _startFrame, _stopFrame, _isLoop);
for (uint i = 0; i < _sfxArray.size(); ++i) {
_sfxArray[i]->toConsole();
}
}
void ActionPlayWithSfx::update() {
int currFrame = _decoder.getCurFrame();
if (_isLoop && currFrame == _stopFrame) {
ActionCEL::setFrame(_startFrame);
decodeNext();
} else
ActionPlay::update();
currFrame++;
for (uint i = 0; i < _sfxArray.size(); ++i) {
if (_sfxArray[i]->getFrame() == currFrame)
_sfxArray[i]->play();
}
}
void ActionPlayWithSfx::onStart() {
ActionPlay::onStart();
if (_isLoop)
_actor->endAction();
}
void ActionPlayWithSfx::end() {
ActionCEL::end();
debugC(6, kPinkDebugActions, "ActionPlayWithSfx %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str());
// original bug fix
if (_actor->getPage()->getSequencer() && _actor->getPage()->getSequencer()->isSkipping()) {
for (uint i = 0; i < _sfxArray.size(); ++i) {
_sfxArray[i]->end();
}
}
}
void ActionSfx::deserialize(Pink::Archive &archive) {
_frame = archive.readDWORD();
_volume = archive.readDWORD();
assert(_volume <= 100);
_sfxName = archive.readString();
_sprite = (ActionPlayWithSfx *)archive.readObject();
}
void ActionSfx::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tActionSfx: _sfx = %s, _volume = %u, _frame = %u", _sfxName.c_str(), _volume, _frame);
}
void ActionSfx::play() {
Page *page = _sprite->getActor()->getPage();
if (!_sound.isPlaying()) {
debugC(kPinkDebugActions, "ActionSfx %s of %s is now playing", _sfxName.c_str(), _sprite->getName().c_str());
int8 balance = (_sprite->getDecoder()->getCenter().x * 396875 / 1000000) - 127;
_sound.play(page->getResourceStream(_sfxName), Audio::Mixer::kSFXSoundType, _volume, balance);
}
}
void ActionSfx::end() {
_sound.stop();
}
} // End of namespace Pink

View File

@@ -0,0 +1,77 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_ACTION_PLAY_WITH_SFX_H
#define PINK_ACTION_PLAY_WITH_SFX_H
#include "pink/objects/actions/action_play.h"
#include "pink/sound.h"
namespace Pink {
class ActionSfx;
class ActionPlayWithSfx : public ActionPlay {
public:
ActionPlayWithSfx()
: _isLoop(false) {}
~ActionPlayWithSfx() override;
void deserialize(Archive &archive) override;
void toConsole() const override;
void update() override;
void end() override;
protected:
void onStart() override;
private:
Array<ActionSfx *> _sfxArray;
bool _isLoop;
};
class Page;
class ActionSfx : public Object {
public:
void deserialize(Archive &archive) override;
void toConsole() const override;
void play();
void end();
int32 getFrame() { return _frame; }
private:
ActionPlayWithSfx *_sprite;
Common::String _sfxName;
Sound _sound;
byte _volume;
int32 _frame;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,86 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/debug.h"
#include "pink/archive.h"
#include "pink/pink.h"
#include "pink/screen.h"
#include "pink/sound.h"
#include "pink/objects/actions/action_sound.h"
#include "pink/objects/actors/actor.h"
#include "pink/objects/pages/game_page.h"
namespace Pink {
ActionSound::~ActionSound() {
end();
}
void ActionSound::deserialize(Archive &archive) {
Action::deserialize(archive);
_fileName = archive.readString();
_volume = archive.readDWORD();
assert(_volume <= 100);
_isLoop = (bool)archive.readDWORD();
_isBackground = (bool)archive.readDWORD();
}
void ActionSound::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\tActionSound: _name = %s, _fileName = %s, _volume = %u, _isLoop = %u,"
" _isBackground = %u", _name.c_str(), _fileName.c_str(), _volume, _isLoop, _isBackground);
}
void ActionSound::start() {
Audio::Mixer::SoundType soundType = _isBackground ? Audio::Mixer::kMusicSoundType : Audio::Mixer::kSFXSoundType;
Page *page = _actor->getPage();
if (!_isLoop) {
Screen *screen = page->getGame()->getScreen();
screen->addSound(this);
} else
_actor->endAction();
_sound.play(page->getResourceStream(_fileName), soundType, _volume, 0, _isLoop);
debugC(6, kPinkDebugActions, "Actor %s has now ActionSound %s", _actor->getName().c_str(), _name.c_str());
}
void ActionSound::end() {
_sound.stop();
if (!_isLoop) {
Screen *screen = _actor->getPage()->getGame()->getScreen();
screen->removeSound(this);
}
debugC(6, kPinkDebugActions, "ActionSound %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str());
}
void ActionSound::update() {
if (!_sound.isPlaying())
_actor->endAction();
}
void ActionSound::pause(bool paused) {
_sound.pause(paused);
}
} // End of namespace Pink

View File

@@ -0,0 +1,54 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_ACTION_SOUND_H
#define PINK_ACTION_SOUND_H
#include "pink/objects/actions/action.h"
#include "pink/sound.h"
namespace Pink {
class ActionSound : public Action {
public:
~ActionSound() override;
void deserialize(Archive &archive) override;
void toConsole() const override;
void start() override;
void end() override;
void update();
void pause(bool paused) override;
private:
Common::String _fileName;
Sound _sound;
byte _volume;
bool _isLoop;
bool _isBackground;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,74 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/debug.h"
#include "pink/archive.h"
#include "pink/cel_decoder.h"
#include "pink/pink.h"
#include "pink/objects/actions/action_still.h"
#include "pink/objects/actors/actor.h"
namespace Pink {
void ActionStill::deserialize(Archive &archive) {
ActionCEL::deserialize(archive);
_startFrame = archive.readDWORD();
}
void ActionStill::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\tActionStill: _name = %s, _fileName = %s, _z =%u _startFrame = %u",
_name.c_str(), _fileName.c_str(), _z, _startFrame);
}
void ActionStill::end() {
ActionCEL::end();
debugC(6, kPinkDebugActions, "ActionStill %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str());
}
void ActionStill::pause(bool paused) {}
void ActionStill::onStart() {
debugC(6, kPinkDebugActions, "Actor %s has now ActionStill %s", _actor->getName().c_str(), _name.c_str());
if (_startFrame >= _decoder.getFrameCount())
_startFrame = 0;
setFrame(_startFrame);
_decoder.setEndOfTrack();
assert(!_decoder.needsUpdate());
_actor->endAction();
}
void ActionStill::setFrame(uint frame) {
ActionCEL::setFrame(frame);
decodeNext();
}
void ActionStill::nextFrameLooped() {
if (_decoder.getFrameCount() != 0) {
setFrame((_decoder.getCurFrame() + 1) % _decoder.getFrameCount());
}
}
} // End of namespace Pink

View File

@@ -0,0 +1,51 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_ACTION_STILL_H
#define PINK_ACTION_STILL_H
#include "pink/objects/actions/action_cel.h"
namespace Pink {
class ActionStill : public ActionCEL {
public:
void deserialize(Archive &archive) override;
void toConsole() const override;
void end() override;
void pause(bool paused) override;
void setFrame(uint frame);
void nextFrameLooped();
protected:
void onStart() override;
uint32 _startFrame;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,68 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/archive.h"
#include "pink/cel_decoder.h"
#include "pink/pink.h"
#include "pink/sound.h"
#include "pink/objects/actions/action_talk.h"
#include "pink/objects/actors/actor.h"
#include "pink/objects/pages/game_page.h"
namespace Pink {
void ActionTalk::deserialize(Archive &archive) {
ActionLoop::deserialize(archive);
_vox = archive.readString();
}
void ActionTalk::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\tActionTalk: _name = %s, _fileName = %s, z = %u, _startFrame = %u,"
" _endFrame = %d, _intro = %u, _style = %u, _vox = %s",
_name.c_str(), _fileName.c_str(), _z, _startFrame, _stopFrame, _intro, _style, _vox.c_str());
}
void ActionTalk::update() {
ActionLoop::update();
if (!_sound.isPlaying()) {
_decoder.setEndOfTrack();
assert(!_decoder.needsUpdate());
_actor->endAction();
}
}
void ActionTalk::end() {
ActionPlay::end();
_sound.stop();
}
void ActionTalk::pause(bool paused) {
ActionCEL::pause(paused);
_sound.pause(paused);
}
void ActionTalk::onStart() {
ActionLoop::onStart();
int8 balance = (_decoder.getCenter().x * 51 - 16160) / 320;
_sound.play(_actor->getPage()->getResourceStream(_vox), Audio::Mixer::kSpeechSoundType, 100, balance);
}
} // End of namespace Pink

View File

@@ -0,0 +1,54 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_ACTION_TALK_H
#define PINK_ACTION_TALK_H
#include "pink/objects/actions/action_loop.h"
namespace Pink {
class Sound;
class ActionTalk : public ActionLoop {
public:
void deserialize(Archive &archive) override;
void toConsole() const override;
void update() override;
void end() override;
void pause(bool paused) override;
protected:
void onStart() override;
bool isTalk() override { return true; }
private:
Common::String _vox;
Sound _sound;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,219 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/debug.h"
#include "common/substream.h"
#include "common/unicode-bidi.h"
#include "graphics/paletteman.h"
#include "pink/archive.h"
#include "pink/screen.h"
#include "pink/pink.h"
#include "pink/objects/actors/actor.h"
#include "pink/objects/actions/action_text.h"
#include "pink/objects/pages/page.h"
namespace Pink {
ActionText::ActionText() {
_txtWnd = nullptr;
_macText = nullptr;
_xLeft = _xRight = 0;
_yTop = _yBottom = 0;
_centered = 0;
_scrollBar = 0;
_textRGB = 0;
_backgroundRGB = 0;
_textColorIndex = 0;
_backgroundColorIndex = 0;
}
ActionText::~ActionText() {
end();
}
void ActionText::deserialize(Archive &archive) {
Action::deserialize(archive);
_fileName = archive.readString();
_xLeft = archive.readDWORD();
_yTop = archive.readDWORD();
_xRight = archive.readDWORD();
_yBottom = archive.readDWORD();
_centered = archive.readDWORD();
_scrollBar = archive.readDWORD();
byte r = archive.readByte();
byte g = archive.readByte();
byte b = archive.readByte();
(void)archive.readByte(); // skip Alpha
_textRGB = r << 16 | g << 8 | b;
r = archive.readByte();
g = archive.readByte();
b = archive.readByte();
(void)archive.readByte(); // skip Alpha
_backgroundRGB = r << 16 | g << 8 | b;
}
void ActionText::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\tActionText: _name = %s, _fileName = %s, "
"_xLeft = %u, _yTop = %u, _xRight = %u, _yBottom = %u _centered = %u, _scrollBar = %u, _textColor = %u _backgroundColor = %u",
_name.c_str(), _fileName.c_str(), _xLeft, _yTop, _xRight, _yBottom, _centered, _scrollBar, _textRGB, _backgroundRGB);
}
void ActionText::start() {
findColorsInPalette();
Screen *screen = _actor->getPage()->getGame()->getScreen();
Graphics::TextAlign align = _centered ? Graphics::kTextAlignCenter : Graphics::kTextAlignLeft;
Common::SeekableReadStream *stream = _actor->getPage()->getResourceStream(_fileName);
char *str = new char[stream->size()];
stream->read(str, stream->size());
delete stream;
Common::Language language = _actor->getPage()->getGame()->getLanguage();
screen->getWndManager()._language = language;
switch(language) {
case Common::DA_DNK:
// fall through
case Common::ES_ESP:
// fall through
case Common::FR_FRA:
// fall through
case Common::PT_BRA:
// fall through
case Common::DE_DEU:
// fall through
case Common::IT_ITA:
// fall through
case Common::NL_NLD:
_text = Common::String(str).decode(Common::kWindows1252);
break;
case Common::FI_FIN:
// fall through
case Common::SV_SWE:
_text = Common::String(str).decode(Common::kWindows1257);
break;
case Common::HE_ISR:
_text = Common::String(str).decode(Common::kWindows1255);
if (!_centered) {
align = Graphics::kTextAlignRight;
}
break;
case Common::PL_POL:
_text = Common::String(str).decode(Common::kWindows1250);
break;
case Common::RU_RUS:
_text = Common::String(str).decode(Common::kWindows1251);
break;
case Common::EN_GRB:
// fall through
case Common::EN_ANY:
// fall through
default:
_text = Common::String(str);
break;
}
_text.trim();
delete[] str;
while ( _text.size() > 0 && (_text[ _text.size() - 1 ] == '\n' || _text[ _text.size() - 1 ] == '\r') )
_text.deleteLastChar();
if (_scrollBar) {
_txtWnd = screen->getWndManager().addTextWindow(screen->getTextFont(), _textColorIndex, _backgroundColorIndex,
_xRight - _xLeft, align, nullptr);
_txtWnd->setTextColorRGB(_textRGB);
_txtWnd->enableScrollbar(true);
// it will hide the scrollbar when the text height is smaller than the window height
_txtWnd->setMode(Graphics::kWindowModeDynamicScrollbar);
_txtWnd->move(_xLeft, _yTop);
_txtWnd->resize(_xRight - _xLeft, _yBottom - _yTop);
_txtWnd->setEditable(false);
_txtWnd->setSelectable(false);
_txtWnd->appendText(_text);
screen->addTextWindow(_txtWnd);
} else {
screen->addTextAction(this);
_macText = new Graphics::MacText(_text, &screen->getWndManager(), screen->getTextFont(), _textColorIndex, _backgroundColorIndex, _xRight - _xLeft, align);
}
}
Common::Rect ActionText::getBound() {
return Common::Rect(_xLeft, _yTop, _xRight, _yBottom);
}
void ActionText::end() {
Screen *screen = _actor->getPage()->getGame()->getScreen();
screen->addDirtyRect(this->getBound());
if (_scrollBar && _txtWnd) {
screen->getWndManager().removeWindow(_txtWnd);
screen->removeTextWindow(_txtWnd);
_txtWnd = nullptr;
} else {
screen->removeTextAction(this);
delete _macText;
}
}
void ActionText::draw(Graphics::ManagedSurface *surface) {
int yOffset = 0;
// we need to first fill this area with backgroundColor, in order to wash away the previous text
surface->fillRect(Common::Rect(_xLeft, _yTop, _xRight, _yBottom), _backgroundColorIndex);
if (_centered) {
yOffset = (_yBottom - _yTop) / 2 - _macText->getTextHeight() / 2;
}
_macText->drawToPoint(surface, Common::Rect(0, 0, _xRight - _xLeft, _yBottom - _yTop), Common::Point(_xLeft, _yTop + yOffset));
}
#define BLUE(rgb) ((rgb) & 0xFF)
#define GREEN(rgb) (((rgb) >> 8) & 0xFF)
#define RED(rgb) (((rgb) >> 16) & 0xFF)
void ActionText::findColorsInPalette() {
byte palette[256 * 3];
g_system->getPaletteManager()->grabPalette(palette, 0, 256);
g_paletteLookup->setPalette(palette, 256);
debug(2, "textcolorindex: %06x", _textRGB);
_textColorIndex = g_paletteLookup->findBestColor(RED(_textRGB), GREEN(_textRGB), BLUE(_textRGB));
debug(2, "backgroundColorIndex: %06x", _backgroundRGB);
_backgroundColorIndex = g_paletteLookup->findBestColor(RED(_backgroundRGB), GREEN(_backgroundRGB), BLUE(_backgroundRGB));
}
} // End of namespace Pink

View File

@@ -0,0 +1,77 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_ACTION_TEXT_H
#define PINK_ACTION_TEXT_H
#include "common/events.h"
#include "graphics/macgui/macwindow.h"
#include "graphics/macgui/macmenu.h"
#include "graphics/macgui/mactextwindow.h"
#include "pink/objects/actions/action.h"
namespace Pink {
class ActionText : public Action {
public:
ActionText();
~ActionText() override;
void deserialize(Archive &archive) override;
void toConsole() const override;
void start() override;
void end() override;
void draw(Graphics::ManagedSurface *surface); // only for non-scrollable text
Common::Rect getBound();
private:
void findColorsInPalette();
void loadBorder(Graphics::MacWindow *target, Common::String filename, uint32 flags);
private:
Common::String _fileName;
Common::U32String _text;
Graphics::MacTextWindow *_txtWnd;
Graphics::MacText *_macText;
uint32 _xLeft;
uint32 _yTop;
uint32 _xRight;
uint32 _yBottom;
uint32 _centered;
uint32 _scrollBar;
uint32 _textRGB;
uint32 _backgroundRGB;
byte _textColorIndex;
byte _backgroundColorIndex;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,93 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/archive.h"
#include "pink/cel_decoder.h"
#include "pink/pink.h"
#include "pink/objects/actions/walk_action.h"
#include "pink/objects/actors/actor.h"
namespace Pink {
void WalkAction::deserialize(Archive &archive) {
ActionCEL::deserialize(archive);
uint32 calcFramePositions = archive.readDWORD();
_toCalcFramePositions = calcFramePositions;
}
void WalkAction::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\tWalkAction: _name = %s, _fileName = %s, _calcFramePositions = %u",
_name.c_str(), _fileName.c_str(), _toCalcFramePositions);
}
void WalkAction::onStart() {
if (_toCalcFramePositions) {
_start = _mgr->getStartCoords().point;
_end = _mgr->getEndCoords().point;
if (!_horizontal) {
_end.y = getCoordinates().point.y;
_start.y = _end.y;
_frameCount = _decoder.getFrameCount();
}
else {
_frameCount = (uint)abs(3 * (_start.x - _end.x) / (int)_z);
if (!_frameCount)
_frameCount = 1;
}
setCenter(_start);
_curFrame = 0;
}
}
void WalkAction::update() {
if (_toCalcFramePositions) {
if (_curFrame < _frameCount)
_curFrame++;
const double k = _curFrame / (double) _frameCount;
Common::Point newCenter;
newCenter.x = (_end.x - _start.x) * k + _start.x;
if (_horizontal) {
newCenter.y = (_end.y - _start.y) * k + _start.y;
} else {
newCenter.y = getCoordinates().point.y;
}
if (_decoder.getCurFrame() < (int)_decoder.getFrameCount() - 1)
decodeNext();
else {
setFrame(0);
}
setCenter(newCenter);
if (_curFrame >= _frameCount - 1) {
_decoder.setEndOfTrack();
_actor->endAction();
}
} else {
if (_decoder.getCurFrame() < (int)_decoder.getFrameCount() - 1)
decodeNext();
else {
_decoder.setEndOfTrack();
_actor->endAction();
}
}
}
} // End of namespace Pink

View File

@@ -0,0 +1,55 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_WALK_ACTION_H
#define PINK_WALK_ACTION_H
#include "pink/objects/actions/action_cel.h"
namespace Pink {
class WalkAction : public ActionCEL {
public:
void deserialize(Archive &archive) override;
void toConsole() const override;
void update() override;
void setWalkMgr(WalkMgr *mgr) { _mgr = mgr; }
void setType(bool horizontal) { _horizontal = horizontal; }
protected:
void onStart() override;
private:
WalkMgr *_mgr;
Common::Point _start;
Common::Point _end;
uint _curFrame;
uint _frameCount;
bool _horizontal;
bool _toCalcFramePositions;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,143 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/constants.h"
#include "pink/cursor_mgr.h"
#include "pink/pink.h"
#include "pink/objects/actions/action_cel.h"
#include "pink/objects/actors/actor.h"
#include "pink/objects/actors/lead_actor.h"
#include "pink/objects/pages/game_page.h"
namespace Pink {
Actor::Actor()
: _page(nullptr), _action(nullptr),
_isActionEnded(true) {}
Actor::~Actor() {
for (uint i = 0; i < _actions.size(); ++i) {
delete _actions[i];
}
}
void Actor::deserialize(Archive &archive) {
NamedObject::deserialize(archive);
_page = static_cast<Page *>(archive.readObject());
_actions.deserialize(archive);
}
void Actor::loadState(Archive &archive) {
_action = findAction(archive.readString());
}
void Actor::saveState(Archive &archive) {
Common::String actionName;
if (_action)
actionName = _action->getName();
archive.writeString(actionName);
}
void Actor::init(bool paused) {
if (!_action)
_action = findAction(kIdleAction);
if (!_action) {
_isActionEnded = true;
} else {
_isActionEnded = false;
_action->start();
_action->pause(paused);
}
}
bool Actor::initPalette(Screen *screen) {
for (uint i = 0; i < _actions.size(); ++i) {
if (_actions[i]->initPalette(screen))
return true;
}
return false;
}
void Actor::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "Actor: _name = %s", _name.c_str());
for (uint i = 0; i < _actions.size(); ++i) {
_actions[i]->toConsole();
}
}
void Actor::pause(bool paused) {
if (_action)
_action->pause(paused);
}
void Actor::onMouseOver(Common::Point point, CursorMgr *mgr) {
mgr->setCursor(kDefaultCursor, point, Common::String());
}
void Actor::onMouseOverWithItem(Common::Point point, const Common::String &itemName, CursorMgr *cursorMgr) {
cursorMgr->setCursor(kHoldingItemCursor, point, itemName);
}
Action *Actor::findAction(const Common::String &name) {
for (uint i = 0; i < _actions.size(); ++i) {
if (_actions[i]->getName() == name)
return _actions[i];
}
return nullptr;
}
Common::String Actor::getLocation() const {
return Common::String();
}
void Actor::setAction(Action *newAction) {
if (_action) {
_isActionEnded = true;
_action->end();
}
_action = newAction;
if (newAction) {
_isActionEnded = false;
_action->start();
}
}
void Actor::setAction(Action *newAction, bool loadingSave) {
if (loadingSave) {
_isActionEnded = true;
_action = newAction;
} else {
setAction(newAction);
}
}
InventoryMgr *Actor::getInventoryMgr() const {
return _page->getModule()->getInventoryMgr();
}
Common::String Actor::getPDALink() const {
return Common::String();
}
} // End of namespace Pink

View File

@@ -0,0 +1,100 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_ACTOR_H
#define PINK_ACTOR_H
#include "common/rect.h"
#include "pink/utils.h"
namespace Pink {
class Page;
class Action;
class Sequencer;
class Screen;
class CursorMgr;
class InventoryItem;
class InventoryMgr;
class Actor : public NamedObject {
public:
Actor();
~Actor() override;
void deserialize(Archive &archive) override;
void loadState(Archive &archive);
void saveState(Archive &archive);
virtual void init(bool paused);
bool initPalette(Screen *screen);
void toConsole() const override;
bool isPlaying() const { return !_isActionEnded; }
virtual void pause(bool paused);
void endAction() { _isActionEnded = true; }
virtual bool isSupporting() const { return false; }
virtual bool isCursor() const { return false; }
virtual bool isLeftClickHandlers() const { return false; }
virtual bool isUseClickHandlers(InventoryItem *item) const { return false; }
virtual void onMouseOver(Common::Point point, CursorMgr *mgr);
virtual void onMouseOverWithItem(Common::Point point, const Common::String &itemName, CursorMgr *cursorMgr);
virtual void onTimerMessage() {}
virtual void onLeftClickMessage() {}
virtual void onUseClickMessage(InventoryItem *item, InventoryMgr *mgr) {}
Action *findAction(const Common::String &name);
Action *getAction() { return _action; }
const Action *getAction() const { return _action; }
Page *getPage() { return _page; }
const Page *getPage() const { return _page; }
InventoryMgr *getInventoryMgr() const;
virtual Common::String getPDALink() const;
virtual Common::String getLocation() const;
void setAction(const Common::String &name) { setAction(findAction(name)); }
void setAction(Action *newAction);
void setAction(Action *newAction, bool loadingSave);
protected:
Page *_page;
Action *_action;
Array<Action *> _actions;
bool _isActionEnded;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,49 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/pink.h"
#include "pink/objects/actors/audio_info_pda_button.h"
#include "pink/objects/actors/lead_actor.h"
#include "pink/objects/pages/page.h"
namespace Pink {
void AudioInfoPDAButton::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "AudioInfoPDAButton: _name = %s", _name.c_str());
for (uint i = 0; i < _actions.size(); ++i) {
_actions[i]->toConsole();
}
}
void AudioInfoPDAButton::onMouseOver(Common::Point point, CursorMgr *mgr) {
mgr->setCursor(kClickableFirstFrameCursor, point, Common::String());
}
void AudioInfoPDAButton::onMouseOverWithItem(Common::Point point, const Common::String &itemName, CursorMgr *cursorMgr) {
onMouseOver(point, cursorMgr);
}
void AudioInfoPDAButton::onLeftClickMessage() {
AudioInfoMgr *audioInfoMgr = _page->getLeadActor()->getAudioInfoMgr();
audioInfoMgr->onLeftClick();
}
} // End of namespace Pink

View File

@@ -0,0 +1,46 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_AUDIO_INFO_PDA_BUTTON_H
#define PINK_AUDIO_INFO_PDA_BUTTON_H
#include "common/debug.h"
#include "pink/constants.h"
#include "pink/cursor_mgr.h"
#include "pink/objects/actions/action.h"
#include "pink/objects/actors/actor.h"
namespace Pink {
class AudioInfoPDAButton : public Actor {
public:
void toConsole() const override;
void onMouseOver(Common::Point point, CursorMgr *mgr) override;
void onMouseOverWithItem(Common::Point point, const Common::String &itemName, CursorMgr *cursorMgr) override;
void onLeftClickMessage() override;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,55 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_CURSOR_ACTOR_H
#define PINK_CURSOR_ACTOR_H
#include "common/debug.h"
#include "pink/pink.h"
#include "pink/objects/actions/action_cel.h"
#include "pink/objects/actors/actor.h"
namespace Pink {
class CursorActor : public Actor {
public:
void toConsole() const override {
debugC(6, kPinkDebugLoadingObjects, "CursorActor: _name = %s", _name.c_str());
for (uint i = 0; i < _actions.size(); ++i) {
_actions[i]->toConsole();
}
}
bool isCursor() const override {
return true;
}
void setCursorItem(const Common::String &name, Common::Point point) {
if (!_action || _action->getName() != name)
setAction(name);
static_cast<ActionCEL*>(_action)->setCenter(point);
}
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,50 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_INVENTORY_ACTOR_H
#define PINK_INVENTORY_ACTOR_H
#include "common/debug.h"
#include "pink/objects/actions/action.h"
#include "pink/objects/actors/actor.h"
namespace Pink {
class InventoryActor : public Actor {
public:
void toConsole() const override {
debugC(6, kPinkDebugLoadingObjects, "InventoryActor: _name = %s", _name.c_str());
for (uint i = 0; i < _actions.size(); ++i) {
_actions[i]->toConsole();
}
}
void pause(bool paused) override {}
void init(bool paused) override {
Actor::init(false);
}
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,507 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/archive.h"
#include "pink/cursor_mgr.h"
#include "pink/pink.h"
#include "pink/screen.h"
#include "pink/objects/actions/action.h"
#include "pink/objects/actors/supporting_actor.h"
#include "pink/objects/actors/lead_actor.h"
#include "pink/objects/pages/game_page.h"
#include "pink/objects/sequences/sequence_context.h"
#include "pink/objects/sequences/sequencer.h"
namespace Pink {
LeadActor::LeadActor()
: _state(kReady), _nextState(kUndefined), _stateBeforeInventory(kUndefined),
_stateBeforePDA(kUndefined), _isHaveItem(false), _recipient(nullptr),
_cursorMgr(nullptr), _walkMgr(nullptr), _sequencer(nullptr),
_audioInfoMgr(this) {}
void LeadActor::deserialize(Archive &archive) {
_state = kReady;
Actor::deserialize(archive);
_cursorMgr = static_cast<CursorMgr *>(archive.readObject());
_walkMgr = static_cast<WalkMgr *>(archive.readObject());
_sequencer = static_cast<Sequencer *>(archive.readObject());
}
void LeadActor::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "LeadActor: _name = %s", _name.c_str());
for (uint i = 0; i < _actions.size(); ++i) {
_actions[i]->toConsole();
}
}
void LeadActor::loadState(Archive &archive) {
_state = (State)archive.readByte();
_nextState = (State)archive.readByte();
_stateBeforeInventory = (State)archive.readByte();
_stateBeforePDA = (State)archive.readByte();
_isHaveItem = archive.readByte();
Common::String recipient = archive.readString();
if (!recipient.empty())
_recipient = _page->findActor(recipient);
else
_recipient = nullptr;
_sequencer->loadState(archive);
_walkMgr->loadState(archive);
_page->getGame()->getPdaMgr().loadState(archive);
_audioInfoMgr.loadState(archive);
}
void LeadActor::saveState(Archive &archive) {
archive.writeByte(_state);
archive.writeByte(_nextState);
archive.writeByte(_stateBeforeInventory);
archive.writeByte(_stateBeforePDA);
archive.writeByte(_isHaveItem);
if (_recipient)
archive.writeString(_recipient->getName());
else
archive.writeString(Common::String());
_sequencer->saveState(archive);
_walkMgr->saveState(archive);
_page->getGame()->getPdaMgr().saveState(archive);
_audioInfoMgr.saveState(archive);
}
void LeadActor::init(bool paused) {
if (_state == kUndefined)
_state = kReady;
getInventoryMgr()->setLeadActor(this);
_page->getGame()->setLeadActor(this);
Actor::init(paused);
}
void LeadActor::start(bool isHandler) {
if (isHandler && _state != kPlayingExitSequence) {
_state = kPlayingSequence;
_nextState = kReady;
}
switch (_state) {
case kInventory:
startInventory(1);
break;
case kPDA:
if (_stateBeforePDA == kInventory)
startInventory(1);
_page->getGame()->getScreen()->saveStage();
loadPDA(_page->getGame()->getPdaMgr().getSavedPageName());
break;
default:
forceUpdateCursor();
break;
}
}
void LeadActor::update() {
switch (_state) {
case kMoving:
_walkMgr->update();
// fall through
case kReady:
_sequencer->update();
_cursorMgr->update();
break;
case kPlayingSequence:
_sequencer->update();
if (!_sequencer->isPlaying()) {
_state = _nextState;
_nextState = kUndefined;
forceUpdateCursor();
}
break;
case kInventory:
getInventoryMgr()->update();
break;
case kPDA:
getPage()->getGame()->getPdaMgr().update();
break;
case kPlayingExitSequence:
_sequencer->update();
if (!_sequencer->isPlaying()) {
_state = kUndefined;
_page->getGame()->changeScene();
}
break;
default:
break;
}
}
void LeadActor::loadPDA(const Common::String &pageName) {
if (_state != kPDA) {
if (_state == kMoving)
cancelInteraction();
if (_state != kInventory && !_page->getGame()->getScreen()->isMenuActive())
_page->pause(true);
_stateBeforePDA = _state;
_state = kPDA;
_page->getGame()->getScreen()->saveStage();
}
_page->getGame()->getPdaMgr().setLead(this);
_page->getGame()->getPdaMgr().goToPage(pageName);
}
void LeadActor::onActionClick(Common::CustomEventType action) {
switch (_state) {
case kMoving:
switch (action) {
case kActionSkipWalkAndCancelInteraction:
cancelInteraction();
// fall through
case kActionSkipWalk:
_walkMgr->skip();
break;
default:
break;
}
break;
case kPlayingSequence:
case kPlayingExitSequence:
switch (action) {
case kActionSkipSubSequence:
_sequencer->skipSubSequence();
break;
case kActionSkipSequence:
_sequencer->skipSequence();
break;
case kActionRestartSequence:
_sequencer->restartSequence();
break;
default:
break;
}
break;
default:
break;
}
}
void LeadActor::onLeftButtonClick(Common::Point point) {
switch (_state) {
case kReady:
case kMoving: {
Actor *clickedActor = getActorByPoint(point);
if (!clickedActor)
return;
if (this == clickedActor) {
_audioInfoMgr.stop();
onLeftClickMessage();
} else if (clickedActor->isSupporting()) {
if (isInteractingWith(clickedActor)) {
_recipient = clickedActor;
_audioInfoMgr.stop();
if (!startWalk()) {
if (_isHaveItem)
sendUseClickMessage(clickedActor);
else
sendLeftClickMessage(clickedActor);
}
}
} else
clickedActor->onLeftClickMessage();
break;
}
case kPDA:
_page->getGame()->getPdaMgr().onLeftButtonClick(point);
break;
case kInventory:
getInventoryMgr()->onClick(point);
break;
default:
break;
}
}
void LeadActor::onLeftButtonUp() {
if (_state == kPDA)
_page->getGame()->getPdaMgr().onLeftButtonUp();
}
void LeadActor::onRightButtonClick(Common::Point point) {
if (_state == kReady || _state == kMoving) {
Actor *clickedActor = getActorByPoint(point);
if (clickedActor && isInteractingWith(clickedActor)) {
_audioInfoMgr.start(clickedActor);
}
if (_state == kMoving)
cancelInteraction();
}
}
void LeadActor::onMouseMove(Common::Point point) {
if (_state != kPDA)
updateCursor(point);
else
_page->getGame()->getPdaMgr().onMouseMove(point);
}
void LeadActor::onMouseOverWithItem(Common::Point point, const Common::String &itemName, CursorMgr *cursorMgr) {
_cursorMgr->setCursor(kHoldingItemCursor, point, itemName + kClickable);
}
void LeadActor::onMouseOver(Common::Point point, CursorMgr *mgr) {
if (getInventoryMgr()->isPinkOwnsAnyItems())
_cursorMgr->setCursor(kClickableFirstFrameCursor, point, Common::String());
else
Actor::onMouseOver(point, mgr);
}
void LeadActor::onLeftClickMessage() {
if (_isHaveItem) {
_isHaveItem = false;
_nextState = _state != kMoving ? kUndefined : kReady;
forceUpdateCursor();
} else {
if (_state == kMoving)
cancelInteraction();
startInventory(0);
}
}
void LeadActor::onInventoryClosed(bool isItemClicked) {
_isHaveItem = isItemClicked;
_state = _stateBeforeInventory;
_stateBeforeInventory = kUndefined;
_page->pause(false);
forceUpdateCursor();
}
void LeadActor::onWalkEnd(const Common::String &stopName) {
State oldNextState = _nextState;
_state = kReady;
_nextState = kUndefined;
if (_recipient && oldNextState == kPlayingSequence) {
if (_isHaveItem)
sendUseClickMessage(_recipient);
else
sendLeftClickMessage(_recipient);
} else { // on ESC button
Action *action = findAction(stopName);
assert(action);
setAction(action);
}
}
void LeadActor::onPDAClose() {
_page->initPalette();
_page->getGame()->getScreen()->loadStage();
_state = _stateBeforePDA;
_stateBeforePDA = kUndefined;
if (_state != kInventory)
_page->pause(false);
}
bool LeadActor::isInteractingWith(const Actor *actor) const {
if (!_isHaveItem)
return actor->isLeftClickHandlers();
return actor->isUseClickHandlers(getInventoryMgr()->getCurrentItem());
}
void LeadActor::setNextExecutors(const Common::String &nextModule, const Common::String &nextPage) {
if (_state == kReady || _state == kMoving || _state == kPlayingSequence || _state == kInventory || _state == kPDA) {
_state = kPlayingExitSequence;
_page->getGame()->setNextExecutors(nextModule, nextPage);
}
}
void LeadActor::forceUpdateCursor() {
PinkEngine *vm =_page->getGame();
vm->getScreen()->update(); // we have actions, that should be drawn to properly update cursor
Common::Point point = vm->getEventManager()->getMousePos();
updateCursor(point);
}
void LeadActor::updateCursor(Common::Point point) {
switch (_state) {
case kReady:
case kMoving: {
Actor *actor = getActorByPoint(point);
InventoryItem *item = getInventoryMgr()->getCurrentItem();
if (_isHaveItem) {
if (actor) {
actor->onMouseOverWithItem(point, item->getName(), _cursorMgr);
} else
_cursorMgr->setCursor(kHoldingItemCursor, point, item->getName());
} else if (actor)
actor->onMouseOver(point, _cursorMgr);
else
_cursorMgr->setCursor(kDefaultCursor, point, Common::String());
break;
}
case kPlayingSequence:
case kPlayingExitSequence:
_cursorMgr->setCursor(kNotClickableCursor, point, Common::String());
break;
case kPDA:
case kInventory:
_cursorMgr->setCursor(kDefaultCursor, point, Common::String());
break;
default:
break;
}
}
void LeadActor::sendUseClickMessage(Actor *actor) {
InventoryMgr *mgr = getInventoryMgr();
assert(_state != kPlayingExitSequence);
_nextState = kReady;
_state = kPlayingSequence;
InventoryItem *item = mgr->getCurrentItem();
actor->onUseClickMessage(mgr->getCurrentItem(), mgr);
if (item->getCurrentOwner() != this->_name)
_isHaveItem = false;
forceUpdateCursor();
}
void LeadActor::sendLeftClickMessage(Actor *actor) {
assert(_state != kPlayingExitSequence);
_nextState = kReady;
_state = kPlayingSequence;
actor->onLeftClickMessage();
forceUpdateCursor();
}
WalkLocation *LeadActor::getWalkDestination() {
return _walkMgr->findLocation(_recipient->getLocation());
}
Actor *LeadActor::getActorByPoint(Common::Point point) {
return _page->getGame()->getScreen()->getActorByPoint(point);
}
void LeadActor::startInventory(bool paused) {
if (!getInventoryMgr()->start(paused))
return;
if (!paused) {
_isHaveItem = false;
_stateBeforeInventory = _state;
_state = kInventory;
forceUpdateCursor();
}
_page->pause(true);
}
bool LeadActor::startWalk() {
WalkLocation *location = getWalkDestination();
if (location) {
_state = kMoving;
_nextState = kPlayingSequence;
_walkMgr->start(location);
return true;
}
return false;
}
void LeadActor::cancelInteraction() {
_recipient = nullptr;
_nextState = kReady;
}
Actor *LeadActor::findActor(const Common::String &name) {
return _page->findActor(name);
}
void ParlSqPink::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "ParlSqPink: _name = %s", _name.c_str());
for (uint i = 0; i < _actions.size(); ++i) {
_actions[i]->toConsole();
}
}
WalkLocation *ParlSqPink::getWalkDestination() {
if (_recipient->getName() == kBoy && _page->checkValueOfVariable(kBoyBlocked, kUndefinedValue))
return _walkMgr->findLocation(kSirBaldley);
return LeadActor::getWalkDestination();
}
void PubPink::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "PubPink: _name = %s", _name.c_str());
for (uint i = 0; i < _actions.size(); ++i) {
_actions[i]->toConsole();
}
}
void PubPink::onLeftClickMessage() {
if (!playingMiniGame())
LeadActor::onLeftClickMessage();
}
void PubPink::onVariableSet() {
if (playingMiniGame())
_isHaveItem = true;
}
void PubPink::updateCursor(Common::Point point) {
if (playingMiniGame()) {
Actor *actor = getActorByPoint(point);
assert(actor);
if (_state == kReady && actor->isUseClickHandlers(getInventoryMgr()->getCurrentItem())) {
_cursorMgr->setCursor(kClickableFirstFrameCursor, point, Common::String());
} else
_cursorMgr->setCursor(kDefaultCursor, point, Common::String());
} else {
LeadActor::updateCursor(point);
}
}
void PubPink::sendUseClickMessage(Actor *actor) {
LeadActor::sendUseClickMessage(actor);
if (playingMiniGame())
_isHaveItem = true;
}
WalkLocation *PubPink::getWalkDestination() {
if (playingMiniGame())
return nullptr;
if (_recipient->getName() == kJackson && !_page->checkValueOfVariable(kDrunkLocation, kBolted))
return _walkMgr->findLocation(_page->findActor(kDrunk)->getName());
return LeadActor::getWalkDestination();
}
bool PubPink::playingMiniGame() {
return !(_page->checkValueOfVariable(kFoodPuzzle, kTrueValue) ||
_page->checkValueOfVariable(kFoodPuzzle, kUndefinedValue));
}
void PubPink::onRightButtonClick(Common::Point point) {
if (!playingMiniGame())
LeadActor::onRightButtonClick(point);
}
} // End of namespace Pink

View File

@@ -0,0 +1,162 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_LEAD_ACTOR_H
#define PINK_LEAD_ACTOR_H
#include "common/events.h"
#include "common/rect.h"
#include "common/keyboard.h"
#include "pink/objects/actors/actor.h"
#include "pink/audio_info_mgr.h"
namespace Pink {
class CursorMgr;
class WalkMgr;
class WalkLocation;
class Sequencer;
class SupportingActor;
class InventoryItem;
class LeadActor : public Actor {
public:
LeadActor();
enum State {
kReady = 0,
kMoving = 1,
kPlayingSequence = 2,
kInventory = 3,
kPDA = 4,
kPlayingExitSequence = 6,
kUndefined = 7
};
void deserialize(Archive &archive) override;
void toConsole() const override;
void loadState(Archive &archive);
void saveState(Archive &archive);
void init(bool paused) override;
void start(bool isHandler);
void update();
void loadPDA(const Common::String &pageName);
void onActionClick(Common::CustomEventType action);
void onLeftButtonClick(Common::Point point);
void onLeftButtonUp();
virtual void onRightButtonClick(Common::Point point);
void onMouseMove(Common::Point point);
void onMouseOverWithItem(Common::Point point, const Common::String &itemName, Pink::CursorMgr *cursorMgr) override;
void onMouseOver(Common::Point point, CursorMgr *mgr) override;
void onLeftClickMessage() override;
virtual void onVariableSet() {}
void onInventoryClosed(bool isItemClicked);
void onWalkEnd(const Common::String &stopName);
void onPDAClose();
bool isInteractingWith(const Actor *actor) const;
void setNextExecutors(const Common::String &nextModule, const Common::String &nextPage);
State getState() const { return _state; }
AudioInfoMgr *getAudioInfoMgr() { return &_audioInfoMgr; }
Actor *getActorByPoint(Common::Point point);
Actor *findActor(const Common::String &name);
protected:
void forceUpdateCursor();
virtual void updateCursor(Common::Point point);
virtual void sendUseClickMessage(Actor *actor);
void sendLeftClickMessage(Actor *actor);
virtual WalkLocation *getWalkDestination();
void startInventory(bool paused);
bool startWalk();
void cancelInteraction();
Actor *_recipient;
CursorMgr *_cursorMgr;
WalkMgr *_walkMgr;
Sequencer *_sequencer;
AudioInfoMgr _audioInfoMgr;
State _state;
State _nextState;
State _stateBeforeInventory;
State _stateBeforePDA;
bool _isHaveItem;
};
class ParlSqPink : public LeadActor {
public:
void toConsole() const override;
protected:
WalkLocation *getWalkDestination() override;
};
class PubPink : public LeadActor {
public:
void toConsole() const override;
void onRightButtonClick(Common::Point point) override;
void onLeftClickMessage() override;
void onVariableSet() override;
protected:
void updateCursor(Common::Point point) override;
void sendUseClickMessage(Actor *actor) override;
WalkLocation *getWalkDestination() override;
private:
bool playingMiniGame();
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,95 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/constants.h"
#include "pink/cursor_mgr.h"
#include "pink/pink.h"
#include "pink/objects/pages/page.h"
#include "pink/objects/actors/pda_button_actor.h"
#include "pink/objects/actions/action_cel.h"
namespace Pink {
void PDAButtonActor::deserialize(Archive &archive) {
Actor::deserialize(archive);
_x = archive.readDWORD();
_y = archive.readDWORD();
_hideOnStop = (bool)archive.readDWORD();
_opaque = (bool)archive.readDWORD();
int type = archive.readDWORD();
assert(type != 0 && type != Command::kIncrementFrame && type != Command::kDecrementFrame);
if (_page->getGame()->isPeril()) {
_command.type = (Command::CommandType) type;
} else {
switch (type) {
case 1:
_command.type = Command::kGoToPage;
break;
case 2:
_command.type = Command::kClose;
break;
default:
_command.type = Command::kNull;
break;
}
}
_command.arg = archive.readString();
}
void PDAButtonActor::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "PDAButtonActor: _name = %s, _x = %u _y = %u _hideOnStop = %u, _opaque = %u, _commandType = %u, _arg = %s",
_name.c_str(), _x, _y, _hideOnStop, _opaque, (int)_command.type, _command.arg.c_str());
}
void PDAButtonActor::onLeftClickMessage() {
if (isActive()) {
_page->getGame()->getPdaMgr().execute(_command);
}
}
void PDAButtonActor::onMouseOver(Common::Point point, CursorMgr *mgr) {
if (_command.type == Command::kNull || !isActive())
mgr->setCursor(kPDADefaultCursor, point, Common::String());
else
mgr->setCursor(kPDAClickableFirstFrameCursor, point, Common::String());
}
bool PDAButtonActor::isActive() const {
return _action && _action->getName() != "Inactive";
}
void PDAButtonActor::init(bool paused) {
if (_x != -1 && _y != -1) {
for (uint i = 0; i < _actions.size(); ++i) {
ActionCEL *action = dynamic_cast<ActionCEL*>(_actions[i]);
assert(action);
action->loadDecoder();
Common::Point center;
center.x = _x + action->getDecoder()->getWidth() / 2;
center.y = _y + action->getDecoder()->getHeight() / 2;
action->setCenter(center);
}
}
Actor::init(paused);
}
} // End of namespace Pink

View File

@@ -0,0 +1,76 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_PDA_BUTTON_ACTOR_H
#define PINK_PDA_BUTTON_ACTOR_H
#include "pink/objects/actors/actor.h"
namespace Pink {
struct Command {
enum CommandType {
kGoToPage = 1,
kGoToPreviousPage,
kGoToDomain,
kGoToHelp, // won't be supported
kNavigateToDomain,
kIncrementCountry,
kDecrementCountry,
kIncrementDomain,
kDecrementDomain,
kClose,
kIncrementFrame, // not used
kDecrementFrame, // not used
kNull
};
CommandType type;
Common::String arg;
};
class PDAButtonActor : public Actor {
public:
void deserialize(Archive &archive) override;
void toConsole() const override;
void init(bool paused) override;
void onMouseOver(Common::Point point, CursorMgr *mgr) override;
void onLeftClickMessage() override;
private:
bool isActive() const;
Command _command;
int16 _x;
int16 _y;
bool _hideOnStop;
bool _opaque;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,94 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/pink.h"
#include "pink/utils.h"
#include "pink/constants.h"
#include "pink/cursor_mgr.h"
#include "pink/objects/inventory.h"
#include "pink/objects/actions/action.h"
#include "pink/objects/actors/supporting_actor.h"
namespace Pink {
void SupportingActor::deserialize(Archive &archive) {
Actor::deserialize(archive);
_location = archive.readString();
_pdaLink = archive.readString();
_cursor = archive.readString();
_handlerMgr.deserialize(archive);
}
void SupportingActor::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "SupportingActor: _name = %s, _location=%s, _pdaLink=%s, _cursor=%s",
_name.c_str(), _location.c_str(), _pdaLink.c_str(), _cursor.c_str());
for (uint i = 0; i < _actions.size(); ++i) {
_actions[i]->toConsole();
}
_handlerMgr.toConsole();
}
bool SupportingActor::isLeftClickHandlers() const {
return _handlerMgr.findSuitableHandlerLeftClick(this);
}
bool SupportingActor::isUseClickHandlers(InventoryItem *item) const {
return _handlerMgr.findSuitableHandlerUseClick(this, item->getName());
}
void SupportingActor::onMouseOver(Common::Point point, CursorMgr *mgr) {
if (isLeftClickHandlers()) {
if (!_cursor.empty())
mgr->setCursor(_cursor, point);
else
mgr->setCursor(kClickableFirstFrameCursor, point, Common::String());
} else
Actor::onMouseOver(point, mgr);
}
void SupportingActor::onMouseOverWithItem(Common::Point point, const Common::String &itemName, CursorMgr *cursorMgr) {
Common::String item = itemName;
if (_handlerMgr.findSuitableHandlerUseClick(this, itemName))
item += kClickable;
cursorMgr->setCursor(kHoldingItemCursor, point, item);
}
void SupportingActor::onTimerMessage() {
_handlerMgr.onTimerMessage(this);
}
void SupportingActor::onLeftClickMessage() {
_handlerMgr.onLeftClickMessage(this);
}
void SupportingActor::onUseClickMessage(InventoryItem *item, InventoryMgr *mgr) {
_handlerMgr.onUseClickMessage(this, item, mgr);
}
Common::String SupportingActor::getLocation() const {
return _location;
}
Common::String SupportingActor::getPDALink() const {
return _pdaLink;
}
} // End of namespace Pink

View File

@@ -0,0 +1,64 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_SUPPORTING_ACTOR_H
#define PINK_SUPPORTING_ACTOR_H
#include "pink/objects/actors/actor.h"
#include "pink/objects/handlers/handler_mgr.h"
namespace Pink {
class InventoryItem;
class InventoryMgr;
class SupportingActor : public Actor {
public:
void deserialize(Archive &archive) override;
void toConsole() const override;
bool isSupporting() const override { return true; }
bool isLeftClickHandlers() const override;
bool isUseClickHandlers(InventoryItem *item) const override;
void onMouseOver(Common::Point point, CursorMgr *mgr) override;
void onMouseOverWithItem(Common::Point point, const Common::String &itemName, CursorMgr *cursorMgr) override;
void onTimerMessage() override;
void onLeftClickMessage() override;
void onUseClickMessage(InventoryItem *item, InventoryMgr *mgr) override;
Common::String getPDALink() const override;
Common::String getLocation() const override;
private:
HandlerMgr _handlerMgr;
Common::String _location;
Common::String _pdaLink;
Common::String _cursor;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,100 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/archive.h"
#include "pink/pink.h"
#include "pink/objects/condition.h"
#include "pink/objects/actors/lead_actor.h"
#include "pink/objects/pages/game_page.h"
namespace Pink {
void ConditionVariable::deserialize(Archive &archive) {
_name = archive.readString();
_value = archive.readString();
}
bool ConditionGameVariable::evaluate(const Actor *actor) const {
return actor->getPage()->getModule()->getGame()->checkValueOfVariable(_name, _value);
}
void ConditionGameVariable::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tConditionGameVariable: _name=%s, _value=%s", _name.c_str(), _value.c_str());
}
bool ConditionModuleVariable::evaluate(const Actor *actor) const {
return actor->getPage()->getModule()->checkValueOfVariable(_name, _value);
}
void ConditionModuleVariable::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tConditionModuleVariable: _name=%s, _value=%s", _name.c_str(), _value.c_str());
}
bool ConditionNotModuleVariable::evaluate(const Actor *actor) const {
return !ConditionModuleVariable::evaluate(actor);
}
void ConditionNotModuleVariable::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tConditionNotModuleVariable: _name=%s, _value=%s", _name.c_str(), _value.c_str());
}
bool ConditionPageVariable::evaluate(const Actor *actor) const {
return actor->getPage()->checkValueOfVariable(_name, _value);
}
void ConditionPageVariable::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tConditionPageVariable: _name=%s, _value=%s", _name.c_str(), _value.c_str());
}
bool ConditionNotPageVariable::evaluate(const Actor *actor) const {
return !ConditionPageVariable::evaluate(actor);
}
void ConditionNotPageVariable::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tConditionNotPageVariable: _name=%s, _value=%s", _name.c_str(), _value.c_str());
}
void ConditionInventoryItemOwner::deserialize(Archive &archive) {
_item = archive.readString();
_owner = archive.readString();
}
bool ConditionInventoryItemOwner::evaluate(const Actor *actor) const {
InventoryMgr *mgr = actor->getInventoryMgr();
InventoryItem *item = mgr->findInventoryItem(_item);
if (item)
return item->getCurrentOwner() == _owner;
return false;
}
void ConditionInventoryItemOwner::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tConditionInventoryItemOwner: _item=%s, _owner=%s", _item.c_str(), _owner.c_str());
}
bool ConditionNotInventoryItemOwner::evaluate(const Actor *actor) const {
return !ConditionInventoryItemOwner::evaluate(actor);
}
void ConditionNotInventoryItemOwner::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tConditionNotInventoryItemOwner: _item=%s, _owner=%s", _item.c_str(), _owner.c_str());
}
} // End of namespace Pink

View File

@@ -0,0 +1,104 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_CONDITION_H
#define PINK_CONDITION_H
#include "pink/objects/object.h"
namespace Pink {
class Actor;
class Condition : public Object {
public:
void deserialize(Archive &archive) override = 0;
virtual bool evaluate(const Actor *actor) const = 0;
};
class ConditionVariable : public Condition {
public:
void deserialize(Archive &archive) override;
bool evaluate(const Actor *actor) const override = 0;
protected:
Common::String _name;
Common::String _value;
};
class ConditionGameVariable : public ConditionVariable {
public:
void toConsole() const override;
bool evaluate(const Actor *actor) const override;
};
/*
* It is not used in games and has evaluate method with infinity recursion
class ConditionNotGameVariable : public ConditionGameVariable {
virtual bool evaluate(LeadActor *leadActor);
};
*/
class ConditionModuleVariable : public ConditionVariable {
public:
void toConsole() const override;
bool evaluate(const Actor *actor) const override;
};
class ConditionNotModuleVariable : public ConditionModuleVariable {
public:
void toConsole() const override;
bool evaluate(const Actor *actor) const override;
};
class ConditionPageVariable : public ConditionVariable {
public:
void toConsole() const override;
bool evaluate(const Actor *actor) const override;
};
class ConditionNotPageVariable : public ConditionPageVariable {
public:
void toConsole() const override;
bool evaluate(const Actor *actor) const override;
};
class ConditionInventoryItemOwner : public Condition {
public:
void toConsole() const override;
void deserialize(Archive &archive) override;
bool evaluate(const Actor *actor) const override;
protected:
Common::String _item;
Common::String _owner;
};
class ConditionNotInventoryItemOwner : public ConditionInventoryItemOwner {
public:
void toConsole() const override;
bool evaluate(const Actor *actor) const override;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,178 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/archive.h"
#include "pink/pink.h"
#include "pink/objects/side_effect.h"
#include "pink/objects/condition.h"
#include "pink/objects/actors/actor.h"
#include "pink/objects/handlers/handler.h"
#include "pink/objects/pages/game_page.h"
#include "pink/objects/sequences/sequencer.h"
#include "pink/objects/sequences/sequence.h"
namespace Pink {
void Handler::deserialize(Archive &archive) {
_conditions.deserialize(archive);
_sideEffects.deserialize(archive);
}
bool Handler::isSuitable(const Actor *actor) const {
for (uint i = 0; i < _conditions.size(); ++i) {
if (!_conditions[i]->evaluate(actor))
return false;
}
return true;
}
void Handler::executeSideEffects(Actor *actor) {
for (uint i = 0; i < _sideEffects.size(); ++i) {
_sideEffects[i]->execute(actor);
}
}
void Handler::handle(Actor *actor) {
executeSideEffects(actor);
}
Handler::~Handler() {
for (uint i = 0; i < _sideEffects.size(); ++i) {
delete _sideEffects[i];
}
for (uint i = 0; i < _conditions.size(); ++i) {
delete _conditions[i];
}
}
void HandlerSequences::deserialize(Archive &archive) {
Handler::deserialize(archive);
_sequences.deserialize(archive);
}
void HandlerSequences::handle(Actor *actor) {
Handler::handle(actor);
Sequencer *sequencer = actor->getPage()->getSequencer();
assert(!_sequences.empty());
Common::RandomSource &rnd = actor->getPage()->getGame()->getRnd();
uint index = rnd.getRandomNumber(_sequences.size() - 1);
Sequence *sequence = sequencer->findSequence(_sequences[index]);
assert(sequence);
authorSequence(sequencer, sequence);
}
void HandlerSequences::authorSequence(Sequencer *sequencer, Sequence *sequence) {
sequencer->authorSequence(sequence, false);
}
void HandlerLeftClick::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "HandlerLeftClick:");
debugC(6, kPinkDebugLoadingObjects, "\tSideEffects:");
for (uint i = 0; i < _sideEffects.size(); ++i) {
_sideEffects[i]->toConsole();
}
debugC(6, kPinkDebugLoadingObjects, "\tConditions:");
for (uint i = 0; i < _conditions.size(); ++i) {
_conditions[i]->toConsole();
}
debugC(6, kPinkDebugLoadingObjects, "\tSequences:");
for (uint i = 0; i < _sequences.size(); ++i) {
debugC(6, kPinkDebugLoadingObjects, "\t\t%s", _sequences[i].c_str());
}
}
void HandlerUseClick::deserialize(Archive &archive) {
HandlerSequences::deserialize(archive);
_inventoryItem = archive.readString();
_recipient = archive.readString();
}
void HandlerUseClick::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "HandlerUseClick: _inventoryItem=%s, _recipient=%s", _inventoryItem.c_str(), _recipient.c_str());
debugC(6, kPinkDebugLoadingObjects, "\tSideEffects:");
for (uint i = 0; i < _sideEffects.size(); ++i) {
_sideEffects[i]->toConsole();
}
debugC(6, kPinkDebugLoadingObjects, "\tConditions:");
for (uint i = 0; i < _conditions.size(); ++i) {
_conditions[i]->toConsole();
}
debugC(6, kPinkDebugLoadingObjects, "\tSequences:");
for (uint i = 0; i < _sequences.size(); ++i) {
debugC(6, kPinkDebugLoadingObjects, "\t\t%s", _sequences[i].c_str());
}
}
void HandlerTimerActions::deserialize(Archive &archive) {
Handler::deserialize(archive);
_actions.deserialize(archive);
}
void HandlerTimerActions::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "HandlerTimerActions:");
debugC(6, kPinkDebugLoadingObjects, "\tSideEffects:");
for (uint i = 0; i < _sideEffects.size(); ++i) {
_sideEffects[i]->toConsole();
}
debugC(6, kPinkDebugLoadingObjects, "\tConditions:");
for (uint i = 0; i < _conditions.size(); ++i) {
_conditions[i]->toConsole();
}
debugC(6, kPinkDebugLoadingObjects, "\tActions:");
for (uint i = 0; i < _actions.size(); ++i) {
debugC(6, kPinkDebugLoadingObjects, "\t\t%s", _actions[i].c_str());
}
}
void HandlerTimerActions::handle(Actor *actor) {
Handler::handle(actor);
if (!actor->isPlaying() && !_actions.empty()) {
Common::RandomSource &rnd = actor->getPage()->getGame()->getRnd();
uint index = rnd.getRandomNumber(_actions.size() - 1);
Action *action = actor->findAction(_actions[index]);
assert(action);
actor->setAction(action);
}
}
void HandlerStartPage::authorSequence(Sequencer *sequencer, Sequence *sequence) {
HandlerSequences::authorSequence(sequencer, sequence);
sequence->allowSkipping();
}
void HandlerTimerSequences::authorSequence(Sequencer *sequencer, Sequence *sequence) {
sequencer->authorParallelSequence(sequence, false);
}
} // End of namespace Pink

View File

@@ -0,0 +1,103 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_HANDLER_H
#define PINK_HANDLER_H
#include "common/str-array.h"
#include "pink/objects/object.h"
namespace Pink {
class Condition;
class SideEffect;
class LeadActor;
class Actor;
class Handler : public Object {
public:
~Handler() override;
void deserialize(Archive &archive) override;
virtual void handle(Actor *actor);
bool isSuitable(const Actor *actor) const;
protected:
void executeSideEffects(Actor *actor);
Array<Condition *> _conditions;
Array<SideEffect *> _sideEffects;
};
class Sequence;
class Sequencer;
class HandlerSequences : public Handler {
public:
void deserialize(Archive &archive) override;
void handle(Actor *actor) override;
protected:
virtual void authorSequence(Sequencer *sequencer, Sequence *sequence);
protected:
StringArray _sequences;
};
class HandlerStartPage : public HandlerSequences {
void authorSequence(Sequencer *sequencer, Sequence *sequence) override;
};
class HandlerLeftClick : public HandlerSequences {
public:
void toConsole() const override;
};
class HandlerUseClick : public HandlerSequences {
public:
void deserialize(Archive &archive) override;
void toConsole() const override;
const Common::String &getInventoryItem() const { return _inventoryItem; }
const Common::String &getRecipient() const { return _recipient; }
private:
Common::String _inventoryItem;
Common::String _recipient;
};
class HandlerTimerActions : public Handler {
public:
void toConsole() const override;
void deserialize(Archive &archive) override;
void handle(Actor *actor) override;
private:
StringArray _actions;
};
class HandlerTimerSequences : public HandlerSequences {
void authorSequence(Sequencer *sequencer, Sequence *sequence) override;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,108 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/archive.h"
#include "pink/pink.h"
#include "pink/objects/inventory.h"
#include "pink/objects/handlers/handler.h"
#include "pink/objects/handlers/handler_mgr.h"
namespace Pink {
void HandlerMgr::deserialize(Archive &archive) {
_leftClickHandlers.deserialize(archive);
_useClickHandlers.deserialize(archive);
_timerHandlers.deserialize(archive);
}
void HandlerMgr::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "HandlerMgr:");
for (uint i = 0; i < _leftClickHandlers.size(); ++i) {
_leftClickHandlers[i]->toConsole();
}
for (uint i = 0; i < _useClickHandlers.size(); ++i) {
_useClickHandlers[i]->toConsole();
}
for (uint i = 0; i < _timerHandlers.size(); ++i) {
_timerHandlers[i]->toConsole();
}
}
void HandlerMgr::onTimerMessage(Actor *actor) {
Handler *handler = findSuitableHandlerTimer(actor);
if (handler)
handler->handle(actor);
}
void HandlerMgr::onLeftClickMessage(Actor *actor) {
Handler *handler = findSuitableHandlerLeftClick(actor);
assert(handler);
handler->handle(actor);
}
void HandlerMgr::onUseClickMessage(Actor *actor, InventoryItem *item, InventoryMgr *mgr) {
HandlerUseClick *handler = findSuitableHandlerUseClick(actor, item->getName());
assert(handler);
if (!handler->getRecipient().empty())
mgr->setItemOwner(handler->getRecipient(), item);
handler->handle(actor);
}
Handler *HandlerMgr::findSuitableHandlerTimer(const Actor *actor) {
for (uint i = 0; i < _timerHandlers.size(); ++i) {
if (_timerHandlers[i]->isSuitable(actor))
return _timerHandlers[i];
}
return nullptr;
}
HandlerLeftClick *HandlerMgr::findSuitableHandlerLeftClick(const Actor *actor) const {
for (uint i = 0; i < _leftClickHandlers.size(); ++i) {
if (_leftClickHandlers[i]->isSuitable(actor))
return _leftClickHandlers[i];
}
return nullptr;
}
HandlerUseClick *HandlerMgr::findSuitableHandlerUseClick(const Actor *actor, const Common::String &itemName) const {
for (uint i = 0; i < _useClickHandlers.size(); ++i) {
if (itemName == _useClickHandlers[i]->getInventoryItem() && _useClickHandlers[i]->isSuitable(actor))
return _useClickHandlers[i];
}
return nullptr;
}
HandlerMgr::~HandlerMgr() {
for (uint i = 0; i < _leftClickHandlers.size(); ++i) {
delete _leftClickHandlers[i];
}
for (uint j = 0; j < _useClickHandlers.size(); ++j) {
delete _useClickHandlers[j];
}
for (uint k = 0; k < _timerHandlers.size(); ++k) {
delete _timerHandlers[k];
}
}
} // End of namespace Pink

View File

@@ -0,0 +1,63 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_HANDLER_MGR_H
#define PINK_HANDLER_MGR_H
#include "pink/objects/object.h"
namespace Pink {
class InventoryItem;
class InventoryMgr;
class Handler;
class HandlerLeftClick;
class HandlerUseClick;
class HandlerTimer;
class Actor;
class HandlerMgr : public Object {
public:
~HandlerMgr() override;
void deserialize(Archive &archive) override;
void toConsole() const override;
HandlerUseClick *findSuitableHandlerUseClick(const Actor *actor, const Common::String &itemName) const;
HandlerLeftClick *findSuitableHandlerLeftClick(const Actor *actor) const;
void onTimerMessage(Actor *actor);
void onLeftClickMessage(Actor *actor);
void onUseClickMessage(Actor *actor, InventoryItem *item, InventoryMgr *mgr);
private:
Handler *findSuitableHandlerTimer(const Actor *actor);
Array<HandlerLeftClick *> _leftClickHandlers;
Array<HandlerUseClick *> _useClickHandlers;
Array<Handler *> _timerHandlers;
};
}
#endif

View File

@@ -0,0 +1,222 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/debug.h"
#include "pink/screen.h"
#include "pink/pink.h"
#include "pink/objects/inventory.h"
#include "pink/objects/actions/action.h"
#include "pink/objects/actors/lead_actor.h"
#include "pink/objects/pages/game_page.h"
namespace Pink {
InventoryMgr::InventoryMgr()
: _lead(nullptr), _window(nullptr), _itemActor(nullptr),
_rightArrow(nullptr), _leftArrow(nullptr), _currentItem(nullptr),
_state(kIdle), _isClickedOnItem(false) {}
void InventoryItem::deserialize(Archive &archive) {
NamedObject::deserialize(archive);
_initialOwner = archive.readString();
_currentOwner = _initialOwner;
}
void InventoryItem::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\tInventoryItem: _initialOwner=%s _currentOwner=%s", _initialOwner.c_str(), _currentOwner.c_str());
}
InventoryMgr::~InventoryMgr() {
for (uint i = 0; i < _items.size(); ++i) {
delete _items[i];
}
}
void InventoryMgr::deserialize(Archive &archive) {
_items.deserialize(archive);
}
InventoryItem *InventoryMgr::findInventoryItem(const Common::String &name) {
for (uint i = 0; i < _items.size(); ++i) {
if (_items[i]->getName() == name) {
return _items[i];
}
}
return nullptr;
}
void InventoryMgr::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "InventoryMgr:");
for (uint i = 0; i < _items.size(); ++i) {
_items[i]->toConsole();
}
}
bool InventoryMgr::isPinkOwnsAnyItems() {
if (_currentItem)
return true;
for (uint i = 0; i < _items.size(); ++i) {
if (_items[i]->getCurrentOwner() == _lead->getName()) {
_currentItem = _items[i];
return true;
}
}
return false;
}
void InventoryMgr::setItemOwner(const Common::String &owner, InventoryItem *item) {
if (owner == item->getCurrentOwner())
return;
if (item == _currentItem && _lead->getName() != owner)
_currentItem = nullptr;
else if (_lead->getName() == owner)
_currentItem = item;
item->_currentOwner = owner;
}
bool InventoryMgr::start(bool paused) {
if (!isPinkOwnsAnyItems())
return false;
_window = _lead->getPage()->findActor(kInventoryWindowActor);
_itemActor = _lead->getPage()->findActor(kInventoryItemActor);
_rightArrow = _lead->getPage()->findActor(kInventoryRightArrowActor);
_leftArrow = _lead->getPage()->findActor(kInventoryLeftArrowActor);
if (!paused) {
_window->setAction(kOpenAction);
_state = kOpening;
}
return true;
}
void InventoryMgr::update() {
if (_window->isPlaying())
return;
switch (_state) {
case kOpening:
_state = kReady;
_itemActor->setAction(_currentItem->getName());
_window->setAction(kShowAction);
_leftArrow->setAction(kShowAction);
_rightArrow->setAction(kShowAction);
break;
case kClosing:
_window->setAction(kIdleAction);
_lead->onInventoryClosed(_isClickedOnItem);
_state = kIdle;
_window = nullptr;
_itemActor = nullptr;
_isClickedOnItem = false;
break;
default:
break;
}
}
void InventoryMgr::onClick(Common::Point point) {
if (_state != kReady)
return;
Actor *actor = _lead->getActorByPoint(point);
if (actor == _itemActor || actor == _window) {
if (_itemActor->getAction()->getName() == "WBook") {
_lead->loadPDA("TOC");
return;
}
_isClickedOnItem = true;
close();
} else if (actor == _leftArrow) {
showNextItem(kLeft);
} else if (actor == _rightArrow) {
showNextItem(kRight);
} else
close();
}
void InventoryMgr::close() {
_state = kClosing;
_window->setAction(kCloseAction);
_itemActor->setAction(kIdleAction);
_leftArrow->setAction(kIdleAction);
_rightArrow->setAction(kIdleAction);
}
void InventoryMgr::showNextItem(bool direction) {
int index = 0;
for (uint i = 0; i < _items.size(); ++i) {
if (_currentItem == _items[i]) {
index = i + _items.size();
break;
}
}
for (uint i = 0; i < _items.size(); ++i) {
index = (direction == kLeft) ? index - 1 : index + 1;
if (_items[index % _items.size()]->getCurrentOwner() == _currentItem->getCurrentOwner()) {
_currentItem = _items[index % _items.size()];
_itemActor->setAction(_currentItem->getName());
break;
}
}
}
void InventoryMgr::loadState(Archive &archive) {
_state = (State)archive.readByte();
_isClickedOnItem = archive.readByte();
for (uint i = 0; i < _items.size(); ++i) {
_items[i]->_currentOwner = archive.readString();
}
const Common::String currItemName = archive.readString();
if (currItemName.empty()) {
_currentItem = nullptr;
_isClickedOnItem = 0;
} else {
_currentItem = findInventoryItem(currItemName);
}
}
void InventoryMgr::saveState(Archive &archive) {
archive.writeByte(_state);
archive.writeByte(_isClickedOnItem);
for (uint i = 0; i < _items.size(); ++i) {
archive.writeString(_items[i]->_currentOwner);
}
if (_currentItem)
archive.writeString(_currentItem->getName());
else
archive.writeString(Common::String());
}
} // End of namespace Pink

View File

@@ -0,0 +1,101 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_INVENTORY_H
#define PINK_INVENTORY_H
#include "common/rect.h"
#include "pink/utils.h"
namespace Pink {
class InventoryItem : public NamedObject {
public:
void deserialize(Archive &archive) override;
void toConsole() const override;
const Common::String &getCurrentOwner() const { return _currentOwner; }
friend class InventoryMgr;
private:
Common::String _initialOwner;
Common::String _currentOwner;
};
class LeadActor;
class Actor;
class InventoryMgr : public Object {
public:
InventoryMgr();
~InventoryMgr() override;
void deserialize(Archive &archive) override;
void toConsole() const override;
void loadState(Archive &archive);
void saveState(Archive &archive);
void update();
void onClick(Common::Point point);
bool start(bool paused);
void setLeadActor(LeadActor *lead) { _lead = lead; }
InventoryItem *findInventoryItem(const Common::String &name);
bool isPinkOwnsAnyItems();
void setItemOwner(const Common::String &owner, InventoryItem *item);
InventoryItem *getCurrentItem() { return _currentItem; }
friend class Console;
private:
void close();
enum Direction {
kLeft = 0,
kRight = 1
};
void showNextItem(bool direction);
LeadActor *_lead;
Actor *_window;
Actor *_itemActor;
Actor *_rightArrow;
Actor *_leftArrow;
InventoryItem *_currentItem;
Array<InventoryItem *> _items;
enum State {
kIdle = 0,
kOpening = 1,
kReady = 2,
kClosing = 3
} _state;
bool _isClickedOnItem;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,111 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/pink.h"
#include "pink/objects/module.h"
#include "pink/objects/pages/game_page.h"
#include "pink/objects/actors/lead_actor.h"
namespace Pink {
ModuleProxy::ModuleProxy(const Common::String &name)
: NamedObject(name) {}
ModuleProxy::ModuleProxy() {}
Module::Module(PinkEngine *game, const Common::String &name)
: NamedObject(name), _game(game), _page(nullptr) {}
Module::~Module() {
for (uint i = 0; i < _pages.size(); ++i) {
delete _pages[i];
}
}
void Module::load(Archive &archive) {
archive.mapObject(this);
NamedObject::deserialize(archive);
archive.skipString(); // skip directory
_invMgr.deserialize(archive);
_pages.deserialize(archive);
}
void Module::init(bool isLoadingSave, const Common::String &pageName) {
// 0 0 - new game
// 0 1 - module changed
// 1 0 - from save
if (!pageName.empty())
_page = findPage(pageName);
if (!_page)
_page = _pages[0];
_page->init(isLoadingSave);
}
void Module::changePage(const Common::String &pageName) {
_page->unload();
_page = findPage(pageName);
_page->init(false);
}
GamePage *Module::findPage(const Common::String &pageName) const {
for (uint i = 0; i < _pages.size(); ++i) {
if (_pages[i]->getName() == pageName)
return _pages[i];
}
return nullptr;
}
bool Module::checkValueOfVariable(const Common::String &variable, const Common::String &value) const {
if (!_variables.contains(variable))
return value == kUndefinedValue;
return _variables[variable] == value;
}
void Module::loadState(Archive &archive) {
_invMgr.loadState(archive);
_variables.deserialize(archive);
for (uint i = 0; i < _pages.size(); ++i) {
_pages[i]->loadState(archive);
}
_page = findPage(archive.readString());
_page->loadManagers();
_page->getLeadActor()->loadState(archive);
}
void Module::saveState(Archive &archive) {
_invMgr.saveState(archive);
_variables.serialize(archive);
for (uint i = 0; i < _pages.size(); ++i) {
_pages[i]->saveState(archive);
}
archive.writeString(_page->getName());
_page->getLeadActor()->saveState(archive);
}
} // End of namespace Pink

View File

@@ -0,0 +1,80 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_MODULE_H
#define PINK_MODULE_H
#include "common/debug.h"
#include "common/hash-str.h"
#include "pink/archive.h"
#include "pink/objects/object.h"
#include "pink/objects/inventory.h"
namespace Pink {
class ModuleProxy : public NamedObject {
public:
ModuleProxy();
ModuleProxy(const Common::String &name);
};
class PinkEngine;
class GamePage;
class Module : public NamedObject {
public:
Module(PinkEngine *game, const Common::String &name);
~Module() override;
void loadState(Archive &archive);
void saveState(Archive &archive);
void load(Archive &archive) override;
void init(bool isLoadingSave, const Common::String &pageName);
void changePage(const Common::String &pageName);
PinkEngine *getGame() const { return _game; }
InventoryMgr *getInventoryMgr() { return &_invMgr; }
const InventoryMgr *getInventoryMgr() const { return &_invMgr; }
bool checkValueOfVariable(const Common::String &variable, const Common::String &value) const;
void setVariable(Common::String &variable, Common::String &value) { _variables[variable] = value; }
GamePage *getPage() { return _page; }
const GamePage *getPage() const { return _page; }
friend class Console;
private:
GamePage *findPage(const Common::String &pageName) const;
PinkEngine *_game;
GamePage *_page;
Array<GamePage *> _pages;
InventoryMgr _invMgr;
StringMap _variables;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,32 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/objects/object.h"
namespace Pink {
void Object::load(Archive &) {}
void Object::deserialize(Archive &) {}
void Object::toConsole() const {}
} // End of namespace Pink

View File

@@ -0,0 +1,56 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_OBJECT_H
#define PINK_OBJECT_H
#include "common/str.h"
#include "pink/archive.h"
namespace Pink {
class Object {
public:
virtual ~Object() {};
virtual void load(Archive &);
virtual void deserialize(Archive &);
virtual void toConsole() const;
};
class NamedObject : public Object {
public:
NamedObject() {}
NamedObject(const Common::String &name)
: _name(name) {}
void deserialize(Archive &archive) override { _name = archive.readString(); }
const Common::String &getName() const { return _name; }
protected:
Common::String _name;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,201 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/cursor_mgr.h"
#include "pink/pink.h"
#include "pink/objects/actors/lead_actor.h"
#include "pink/objects/handlers/handler.h"
#include "pink/objects/pages/game_page.h"
#include "pink/objects/sequences/sequencer.h"
#include "pink/objects/walk/walk_mgr.h"
namespace Pink {
GamePage::GamePage()
: _module(nullptr), _cursorMgr(nullptr), _walkMgr(nullptr),
_sequencer(nullptr), _isLoaded(false), _memFile(nullptr) {}
GamePage::~GamePage() {
clear();
delete _memFile;
}
void GamePage::toConsole() const {
Page::toConsole();
_walkMgr->toConsole();
_sequencer->toConsole();
for (uint i = 0; i < _handlers.size(); ++i) {
_handlers[i]->toConsole();
}
}
void GamePage::deserialize(Archive &archive) {
Page::deserialize(archive);
_module = static_cast<Module *>(archive.readObject());
assert(dynamic_cast<Module *>(_module) != nullptr);
}
void GamePage::load(Archive &archive) {
debugC(6, kPinkDebugLoadingObjects, "GamePage load");
archive.mapObject(_cursorMgr);
archive.mapObject(_walkMgr);
archive.mapObject(_sequencer);
Page::load(archive);
_leadActor = static_cast<LeadActor *>(archive.readObject());
_walkMgr->deserialize(archive);
_sequencer->deserialize(archive);
_handlers.deserialize(archive);
}
void GamePage::init(bool isLoadingSave) {
if (!_isLoaded)
loadManagers();
toConsole();
initPalette();
LeadActor::State state = _leadActor->getState();
bool paused = (state == LeadActor::kInventory || state == LeadActor::kPDA);
for (uint i = 0; i < _actors.size(); ++i) {
_actors[i]->init(paused);
}
bool isHandler = false;
if (!isLoadingSave)
isHandler = initHandler();
_leadActor->start(isHandler);
}
bool GamePage::initHandler() {
for (uint i = 0; i < _handlers.size(); ++i) {
if (_handlers[i]->isSuitable(_leadActor)) {
_handlers[i]->handle(_leadActor);
return true;
}
}
return false;
}
void GamePage::loadManagers() {
_isLoaded = true;
_cursorMgr = new CursorMgr(_module->getGame(), this);
_walkMgr = new WalkMgr;
_sequencer = new Sequencer(this);
debugC(6, kPinkDebugGeneral, "ResMgr init");
_resMgr.init(_module->getGame(), this);
if (_memFile != nullptr) {
loadStateFromMem();
delete _memFile;
_memFile = nullptr;
}
}
bool GamePage::checkValueOfVariable(const Common::String &variable, const Common::String &value) const {
if (!_variables.contains(variable))
return value == kUndefinedValue;
return _variables[variable] == value;
}
void GamePage::setVariable(Common::String &variable, Common::String &value) {
_variables[variable] = value;
_leadActor->onVariableSet();
}
void GamePage::loadStateFromMem() {
Archive archive(static_cast<Common::SeekableReadStream *>(_memFile));
_variables.deserialize(archive);
for (uint i = 0; i < _actors.size(); ++i) {
_actors[i]->loadState(archive);
}
}
void GamePage::saveStateToMem() {
_memFile = new Common::MemoryReadWriteStream(DisposeAfterUse::YES);
Archive archive(static_cast<Common::WriteStream *>(_memFile));
_variables.serialize(archive);
for (uint i = 0; i < _actors.size(); ++i) {
_actors[i]->saveState(archive);
}
}
void GamePage::loadState(Archive &archive) {
uint size = archive.readDWORD();
if (size) {
_memFile = new Common::MemoryReadWriteStream(DisposeAfterUse::YES);
for (uint i = 0; i < size; ++i) {
_memFile->writeByte(archive.readByte());
}
}
}
void GamePage::saveState(Archive &archive) {
if (this == _module->getPage()) {
saveStateToMem();
archive.writeDWORD(_memFile->size());
archive.write(_memFile->getData(), _memFile->size());
delete _memFile;
_memFile = nullptr;
} else {
if (_memFile != nullptr) {
archive.writeDWORD(_memFile->size());
archive.write(_memFile->getData(), _memFile->size());
} else {
archive.writeDWORD(0);
}
}
}
void GamePage::unload() {
_leadActor->setAction(_leadActor->findAction(kIdleAction));
saveStateToMem();
clear();
_isLoaded = false;
}
void GamePage::clear() {
Page::clear();
_variables.clear(true);
for (uint i = 0; i < _handlers.size(); ++i) {
delete _handlers[i];
}
_handlers.clear();
delete _cursorMgr; _cursorMgr = nullptr;
delete _sequencer; _sequencer = nullptr;
delete _walkMgr; _walkMgr = nullptr;
}
} // End of namespace Pink

View File

@@ -0,0 +1,79 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_GAME_PAGE_H
#define PINK_GAME_PAGE_H
#include "common/memstream.h"
#include "pink/objects/pages/page.h"
namespace Pink {
class CursorMgr;
class HandlerSequences;
class GamePage : public Page {
public:
GamePage();
~GamePage() override;
void toConsole() const override;
void deserialize(Archive &archive) override;
void loadState(Archive &archive);
void saveState(Archive &archive);
void load(Archive &archive) override;
void unload();
void loadManagers();
void init(bool isLoadingSave);
Sequencer *getSequencer() override { return _sequencer; }
WalkMgr *getWalkMgr() override { return _walkMgr; }
Module *getModule() override { return _module; }
const Module *getModule() const override { return _module; }
bool checkValueOfVariable(const Common::String &variable, const Common::String &value) const override;
void setVariable(Common::String &variable, Common::String &value) override;
void clear() override;
friend class Console;
private:
bool initHandler();
void loadStateFromMem();
void saveStateToMem();
bool _isLoaded;
Common::MemoryReadWriteStream *_memFile;
Module *_module;
CursorMgr *_cursorMgr;
WalkMgr *_walkMgr;
Sequencer *_sequencer;
Array<HandlerSequences *> _handlers;
StringMap _variables;
};
}
#endif

View File

@@ -0,0 +1,84 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/screen.h"
#include "pink/pink.h"
#include "pink/objects/actors/lead_actor.h"
#include "pink/objects/pages/page.h"
namespace Pink {
Page::~Page() {
clear();
}
void Page::load(Archive &archive) {
debugC(6, kPinkDebugLoadingObjects, "Page load");
archive.mapObject(this);
NamedObject::deserialize(archive);
archive.skipString(); //skip directory
_actors.deserialize(archive);
}
Actor *Page::findActor(const Common::String &name) {
for (uint i = 0; i < _actors.size(); ++i) {
if (_actors[i]->getName() == name) {
return _actors[i];
}
}
return nullptr;
}
void Page::toConsole() const {
for (uint i = 0; i < _actors.size(); ++i) {
_actors[i]->toConsole();
}
}
void Page::init() {
initPalette();
for (uint i = 0; i < _actors.size(); ++i) {
_actors[i]->init(false);
}
}
void Page::initPalette() {
for (uint i = 0; i < _actors.size(); ++i) {
if (_actors[i]->initPalette(getGame()->getScreen()))
break;
}
}
void Page::clear() {
for (uint i = 0; i < _actors.size(); ++i) {
delete _actors[i];
}
_actors.clear();
_resMgr.clear();
}
void Page::pause(bool paused) {
for (uint i = 0; i < _actors.size(); ++i) {
_actors[i]->pause(paused);
}
}
} // End of namespace Pink

View File

@@ -0,0 +1,72 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_PAGE_H
#define PINK_PAGE_H
#include "pink/resource_mgr.h"
#include "pink/objects/module.h"
namespace Pink {
class Archive;
class Actor;
class LeadActor;
class WalkMgr;
class Sequencer;
class Page : public NamedObject {
public:
~Page() override;
void toConsole() const override;
void load(Archive &archive) override;
void init();
void initPalette();
Actor *findActor(const Common::String &name);
LeadActor *getLeadActor() { return _leadActor; }
Common::SeekableReadStream *getResourceStream(const Common::String &fileName) { return _resMgr.getResourceStream(fileName); }
virtual void clear();
void pause(bool paused);
PinkEngine *getGame() { return _resMgr.getGame(); }
virtual Sequencer *getSequencer() { return nullptr; }
virtual WalkMgr *getWalkMgr() { return nullptr; }
virtual Module *getModule() { return nullptr; }
virtual const Module *getModule() const { return nullptr; }
virtual bool checkValueOfVariable(const Common::String &variable, const Common::String &value) const { return 0; }
virtual void setVariable(Common::String &variable, Common::String &value) {}
protected:
Array<Actor *> _actors;
ResourceMgr _resMgr;
LeadActor *_leadActor;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,35 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/pda_mgr.h"
#include "pink/objects/actors/actor.h"
#include "pink/objects/pages/pda_page.h"
#include "pink/pink.h"
namespace Pink {
PDAPage::PDAPage(const Common::String& name, PinkEngine *vm) {
_name = name;
_resMgr.init(vm, this);
init();
}
} // End of namespace Pink

View File

@@ -0,0 +1,38 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_PDA_PAGE_H
#define PINK_PDA_PAGE_H
#include "pink/objects/pages/page.h"
namespace Pink {
class PDAMgr;
class PDAPage : public Page {
public:
PDAPage(const Common::String& name, PinkEngine* vm);
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,62 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/debug.h"
#include "pink/archive.h"
#include "pink/pink.h"
#include "pink/objects/actors/supporting_actor.h"
#include "pink/objects/pages/game_page.h"
#include "pink/objects/sequences/seq_timer.h"
#include "pink/objects/sequences/sequencer.h"
namespace Pink {
SeqTimer::SeqTimer()
: _sequencer(nullptr), _updatesToMessage(0), _period(0),
_range(0) {}
void SeqTimer::deserialize(Archive &archive) {
_actor = archive.readString();
_period = archive.readDWORD();
_range = archive.readDWORD();
_sequencer = static_cast<Sequencer *>(archive.readObject());
}
void SeqTimer::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\tSeqTimer: _actor=%s _period=%u _range=%u", _actor.c_str(), _period, _range);
}
void SeqTimer::update() {
Page *page = _sequencer->getPage();
Common::RandomSource &rnd = page->getGame()->getRnd();
if (_updatesToMessage--)
return;
_updatesToMessage = _range ? _period + rnd.getRandomNumber(_range) : _period;
Actor *actor = page->findActor(_actor);
if (actor && !_sequencer->findState(_actor)) {
actor->onTimerMessage();
}
}
} // End of namespace Pink

View File

@@ -0,0 +1,50 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_SEQ_TIMER_H
#define PINK_SEQ_TIMER_H
#include "pink/objects/object.h"
namespace Pink {
class Sequencer;
class SeqTimer : public Object {
public:
SeqTimer();
void deserialize(Archive &archive) override;
void toConsole() const override;
void update();
private:
Common::String _actor;
Sequencer *_sequencer;
int _period;
int _range;
int _updatesToMessage;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,180 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/debug.h"
#include "pink/archive.h"
#include "pink/pink.h"
#include "pink/sound.h"
#include "pink/objects/actors/actor.h"
#include "pink/objects/pages/game_page.h"
#include "pink/objects/sequences/sequence.h"
#include "pink/objects/sequences/sequence_context.h"
#include "pink/objects/sequences/sequencer.h"
namespace Pink {
Sequence::Sequence()
: _canBeSkipped(false), _context(nullptr),
_sequencer(nullptr) {}
Sequence::~Sequence() {
for (uint i = 0; i < _items.size(); ++i) {
delete _items[i];
}
}
void Sequence::deserialize(Archive &archive) {
NamedObject::deserialize(archive);
_sequencer = static_cast<Sequencer *>(archive.readObject());
_items.deserialize(archive);
}
void Sequence::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tSequence %s", _name.c_str());
debugC(6, kPinkDebugLoadingObjects, "\t\t\tItems:");
for (uint i = 0; i < _items.size(); ++i) {
_items[i]->toConsole();
}
}
void Sequence::start(bool loadingSave) {
uint nextItemIndex = _context->getNextItemIndex();
if (nextItemIndex >= _items.size() ||
!_items[nextItemIndex]->execute(_context->getSegment(), this, loadingSave)) {
debugC(6, kPinkDebugScripts, "Sequence %s ended", _name.c_str());
end();
return;
}
uint i = nextItemIndex + 1;
while (i < _items.size()) {
if (_items[i]->isLeader()) {
break;
}
_items[i++]->execute(_context->getSegment(), this, loadingSave);
}
_context->execute(i, loadingSave);
}
void Sequence::update() {
if (!_context->getActor()->isPlaying()) {
debugC(6, kPinkDebugScripts, "SubSequence of %s Sequence ended", _name.c_str());
start(0);
}
}
void Sequence::end() {
_context->setActor(nullptr);
_canBeSkipped = 1;
_sequencer->removeContext(_context);
}
void Sequence::restart() {
_context->setNextItemIndex(0);
_context->clearDefaultActions();
start(0);
}
void Sequence::skip() {
if (_context->getNextItemIndex() >= _items.size())
return;
for (int i = _items.size() - 1; i >= 0; --i) {
if (_items[i]->isLeader()) {
_context->setNextItemIndex(i);
_context->clearDefaultActions();
for (int j = 0; j < i; ++j) {
_items[j]->skip(this);
}
start(0);
break;
}
}
}
void Sequence::skipSubSequence() {
if (_context->getNextItemIndex() < _items.size())
this->start(0);
}
void Sequence::forceEnd() {
skip();
end();
}
void Sequence::init(bool loadingSave) {
start(loadingSave);
}
void SequenceAudio::deserialize(Archive &archive) {
Sequence::deserialize(archive);
_soundName = archive.readString();
}
void SequenceAudio::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tSequenceAudio %s : _sound = %s", _name.c_str(), _soundName.c_str());
debugC(6, kPinkDebugLoadingObjects, "\t\t\tItems:");
for (uint i = 0; i < _items.size(); ++i) {
_items[i]->toConsole();
}
}
void SequenceAudio::start(bool loadingSave) {
Sequence::start(loadingSave);
uint index = _context->getNextItemIndex();
if (index < _items.size()) {
_leader = (SequenceItemLeaderAudio *)_items[index];
} else {
_leader = nullptr;
}
}
void SequenceAudio::end() {
_sound.stop();
Sequence::end();
}
void SequenceAudio::update() {
if (!_sound.isPlaying())
end();
else if (_leader && _leader->getSample() <= _sound.getCurrentSample())
start(0);
}
void SequenceAudio::init(bool loadingSave) {
_leader = nullptr;
_sound.play(_sequencer->getPage()->getResourceStream(_soundName), Audio::Mixer::kMusicSoundType);
start(loadingSave);
}
void SequenceAudio::restart() {
_leader = nullptr;
_sound.play(_sequencer->getPage()->getResourceStream(_soundName), Audio::Mixer::kMusicSoundType);
Sequence::restart();
}
void SequenceAudio::skip() {
end();
}
} // End of namespace Pink

View File

@@ -0,0 +1,98 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_SEQUENCE_H
#define PINK_SEQUENCE_H
#include "pink/sound.h"
#include "pink/objects/sequences/sequence_item.h"
namespace Pink {
class Sequencer;
class SequenceItem;
class SequenceContext;
class Sequence : public NamedObject {
public:
Sequence();
~Sequence() override;
void deserialize(Archive &archive) override ;
void toConsole() const override;
public:
virtual void init(bool loadingSave);
virtual void start(bool loadingSave);
virtual void end();
virtual void restart();
void forceEnd();
virtual void update();
virtual void skipSubSequence();
virtual void skip();
void allowSkipping() { _canBeSkipped = true; }
bool isSkippingAllowed() { return _canBeSkipped; }
SequenceContext *getContext() const { return _context; }
Sequencer *getSequencer() const { return _sequencer; }
Common::Array<SequenceItem *> &getItems() { return _items; }
void setContext(SequenceContext *context) { _context = context; }
protected:
SequenceContext *_context;
Sequencer *_sequencer;
Array<SequenceItem *> _items;
bool _canBeSkipped;
};
class SequenceAudio : public Sequence {
public:
SequenceAudio()
: _leader(nullptr) {}
void deserialize(Archive &archive) override;
void toConsole() const override;
void init(bool loadingSave) override;
void start(bool loadingSave) override;
void end() override;
void update() override;
void restart() override;
void skipSubSequence() override {}
void skip() override;
private:
SequenceItemLeaderAudio *_leader;
Common::String _soundName;
Sound _sound;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,97 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/debug.h"
#include "pink/pink.h"
#include "pink/objects/actors/actor.h"
#include "pink/objects/pages/game_page.h"
#include "pink/objects/sequences/sequence.h"
#include "pink/objects/sequences/sequence_context.h"
#include "pink/objects/sequences/sequencer.h"
namespace Pink {
void SequenceActorState::execute(uint segment, Sequence *sequence, bool loadingSave) const {
Actor *actor = sequence->getSequencer()->getPage()->findActor(this->actorName);
if (actor && _segment != segment && !defaultActionName.empty()) {
Action *action = actor->findAction(defaultActionName);
if (action && actor->getAction() != action) {
actor->setAction(action, loadingSave);
}
}
}
SequenceContext::SequenceContext(Sequence *sequence)
: _sequence(sequence), _nextItemIndex(0),
_segment(1), _actor(nullptr) {
sequence->setContext(this);
Common::Array<SequenceItem *> &items = sequence->getItems();
debug(kPinkDebugScripts, "SequenceContext for %s", _sequence->getName().c_str());
for (uint i = 0; i < items.size(); ++i) {
bool found = 0;
for (uint j = 0; j < _states.size(); ++j) {
if (items[i]->getActor() == _states[j].actorName) {
found = 1;
break;
}
}
if (!found) {
debug(kPinkDebugScripts, "%s", items[i]->getActor().c_str());
_states.push_back(SequenceActorState(items[i]->getActor()));
}
}
}
void SequenceContext::execute(uint nextItemIndex, bool loadingSave) {
for (uint j = 0; j < _states.size(); ++j) {
_states[j].execute(_segment, _sequence, loadingSave);
}
_nextItemIndex = nextItemIndex;
_segment++;
}
void SequenceContext::clearDefaultActions() {
for (uint i = 0; i < _states.size(); ++i) {
_states[i].defaultActionName.clear();
}
}
SequenceActorState *SequenceContext::findState(const Common::String &actor) {
for (uint i = 0; i < _states.size(); ++i) {
if (_states[i].actorName == actor)
return &_states[i];
}
return nullptr;
}
bool SequenceContext::isConflictingWith(SequenceContext *context) {
for (uint i = 0; i < _states.size(); ++i) {
if (context->findState(_states[i].actorName))
return true;
}
return false;
}
} // End of namespace Pink

View File

@@ -0,0 +1,75 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_SEQUENCE_CONTEXT_H
#define PINK_SEQUENCE_CONTEXT_H
#include "common/array.h"
namespace Pink {
class Sequence;
class Sequencer;
struct SequenceActorState {
SequenceActorState(const Common::String &actor)
: actorName(actor), _segment(0) {}
void execute(uint segment, Sequence *sequence, bool loadingSave) const;
Common::String actorName;
Common::String defaultActionName;
uint _segment;
};
class Actor;
class SequenceContext {
public:
SequenceContext(Sequence *sequence);
void execute(uint nextItemIndex, bool loadingSave);
bool isConflictingWith(SequenceContext *context);
void clearDefaultActions();
SequenceActorState *findState(const Common::String &actor);
Sequence *getSequence() const { return _sequence; }
Actor *getActor() const { return _actor; }
uint getNextItemIndex() const { return _nextItemIndex; }
uint getSegment() const { return _segment; }
void setActor(Actor *actor) { _actor = actor; }
void setNextItemIndex(uint index) { _nextItemIndex = index; }
private:
Sequence *_sequence;
Actor *_actor;
Common::Array<SequenceActorState> _states;
uint _nextItemIndex;
uint _segment;
};
}
#endif

View File

@@ -0,0 +1,99 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/debug.h"
#include "pink/archive.h"
#include "pink/pink.h"
#include "pink/objects/actions/action.h"
#include "pink/objects/actors/actor.h"
#include "pink/objects/pages/game_page.h"
#include "pink/objects/sequences/sequence_item.h"
#include "pink/objects/sequences/sequence.h"
#include "pink/objects/sequences/sequencer.h"
#include "pink/objects/sequences/sequence_context.h"
namespace Pink {
void SequenceItem::deserialize(Archive &archive) {
_actor = archive.readString();
_action = archive.readString();
}
void SequenceItem::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\t\t\tSequenceItem: _actor=%s, _action=%s", _actor.c_str(), _action.c_str());
}
bool SequenceItem::execute(uint segment, Sequence *sequence, bool loadingSave) {
Actor *actor = sequence->getSequencer()->getPage()->findActor(_actor);
Action *action;
if (!actor || !(action = actor->findAction(_action)))
return false;
actor->setAction(action, loadingSave);
SequenceContext *context = sequence->getContext();
SequenceActorState *state = context->findState(_actor);
if (state)
state->_segment = segment;
if (isLeader())
context->setActor(actor);
return true;
}
bool SequenceItem::isLeader() {
return false;
}
bool SequenceItemLeader::isLeader() {
return true;
}
void SequenceItemLeader::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\t\t\tSequenceItemLeader: _actor=%s, _action=%s", _actor.c_str(), _action.c_str());
}
void SequenceItemLeaderAudio::deserialize(Archive &archive) {
SequenceItem::deserialize(archive);
_sample = archive.readDWORD();
}
void SequenceItemLeaderAudio::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\t\t\tSequenceItemLeaderAudio: _actor=%s, _action=%s _sample=%d", _actor.c_str(), _action.c_str(), _sample);
}
bool SequenceItemDefaultAction::execute(uint segment, Sequence *sequence, bool loadingSave) {
SequenceActorState *state = sequence->getContext()->findState(_actor);
if (state)
state->defaultActionName = _action;
return true;
}
void SequenceItemDefaultAction::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\t\t\tSequenceItemDefaultAction: _actor=%s, _action=%s", _actor.c_str(), _action.c_str());
}
void SequenceItemDefaultAction::skip(Sequence *sequence) {
execute(0, sequence, 1);
}
} // End of namespace Pink

View File

@@ -0,0 +1,78 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_SEQUENCE_ITEM_H
#define PINK_SEQUENCE_ITEM_H
#include "pink/objects/object.h"
namespace Pink {
class Sequence;
class SequenceItem : public Object {
public:
void deserialize(Archive &archive) override;
void toConsole() const override;
virtual bool execute(uint segment, Sequence *sequence, bool loadingSave);
virtual bool isLeader();
virtual void skip(Sequence *sequence) {};
const Common::String &getActor() const { return _actor; }
protected:
Common::String _actor;
Common::String _action;
};
class SequenceItemLeader : public SequenceItem {
public:
void toConsole() const override;
bool isLeader() override;
};
class SequenceItemLeaderAudio : public SequenceItemLeader {
public:
SequenceItemLeaderAudio()
: _sample(0) {}
void deserialize(Archive &archive) override;
void toConsole() const override;
uint32 getSample() { return _sample; }
private:
uint32 _sample;
};
class SequenceItemDefaultAction : public SequenceItem {
public:
void toConsole() const override;
bool execute(uint segment, Sequence *sequence, bool loadingSave) override;
void skip(Sequence *sequence) override;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,215 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/debug.h"
#include "pink/archive.h"
#include "pink/pink.h"
#include "pink/objects/actors/lead_actor.h"
#include "pink/objects/pages/game_page.h"
#include "pink/objects/sequences/sequencer.h"
#include "pink/objects/sequences/sequence.h"
#include "pink/objects/sequences/sequence_context.h"
#include "pink/objects/sequences/seq_timer.h"
namespace Pink {
Sequencer::Sequencer(GamePage *page)
: _context(nullptr), _page(page), _time(0), _isSkipping(false) {}
Sequencer::~Sequencer() {
for (uint i = 0; i < _sequences.size(); ++i) {
delete _sequences[i];
}
for (uint i = 0; i < _timers.size(); ++i) {
delete _timers[i];
}
delete _context;
for (uint i = 0; i < _parallelContexts.size(); ++i) {
delete _parallelContexts[i];
}
}
void Sequencer::deserialize(Archive &archive) {
_sequences.deserialize(archive);
_timers.deserialize(archive);
}
Sequence *Sequencer::findSequence(const Common::String &name) {
for (uint i = 0; i < _sequences.size(); ++i) {
if (_sequences[i]->getName() == name)
return _sequences[i];
}
return nullptr;
}
void Sequencer::authorSequence(Sequence *sequence, bool loadingSave) {
if (_context)
_context->getSequence()->forceEnd();
if (sequence) {
SequenceContext *context = new SequenceContext(sequence);
SequenceContext *conflict;
while ((conflict = findConflictingContextWith(context)) != nullptr) {
conflict->getSequence()->forceEnd();
}
_context = context;
sequence->init(loadingSave);
debugC(5, kPinkDebugScripts, "Main Sequence %s started", sequence->getName().c_str());
}
}
void Sequencer::authorParallelSequence(Sequence *sequence, bool loadingSave) {
if (_context && _context->getSequence() == sequence)
return;
for (uint i = 0; i < _parallelContexts.size(); ++i) {
if (_parallelContexts[i]->getSequence() == sequence)
return;
}
const Common::String leadName = _page->getLeadActor()->getName();
SequenceContext *context = new SequenceContext(sequence);
if (!context->findState(leadName) && !findConflictingContextWith(context)) {
_parallelContexts.push_back(context);
sequence->init(loadingSave);
debugC(6, kPinkDebugScripts, "Parallel Sequence %s started", sequence->getName().c_str());
} else
delete context;
}
void Sequencer::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "Sequencer:");
for (uint i = 0; i < _sequences.size(); ++i) {
_sequences[i]->toConsole();
}
for (uint i = 0; i < _timers.size(); ++i) {
_timers[i]->toConsole();
}
}
void Sequencer::update() {
if (_context)
_context->getSequence()->update();
for (uint i = 0; i < _parallelContexts.size(); ++i) {
_parallelContexts[i]->getSequence()->update();
}
uint time = _page->getGame()->getTotalPlayTime();
if (time - _time > kTimersUpdateTime) {
_time = time;
for (uint i = 0; i < _timers.size(); ++i) {
_timers[i]->update();
}
}
}
void Sequencer::removeContext(SequenceContext *context) {
if (context == _context) {
delete _context;
_context = nullptr;
return;
}
for (uint i = 0; i < _parallelContexts.size(); ++i) {
if (context == _parallelContexts[i]) {
delete _parallelContexts[i];
_parallelContexts.remove_at(i);
break;
}
}
}
void Sequencer::skipSubSequence() {
if (_context) {
_isSkipping = true;
_context->getSequence()->skipSubSequence();
_isSkipping = false;
}
}
void Sequencer::restartSequence() {
if (_context) {
_isSkipping = true;
_context->getSequence()->restart();
_isSkipping = false;
}
}
void Sequencer::skipSequence() {
if (_context && _context->getSequence()->isSkippingAllowed()) {
_isSkipping = true;
_context->getSequence()->skip();
_isSkipping = false;
}
}
void Sequencer::loadState(Archive &archive) {
Sequence *sequence = findSequence(archive.readString());
authorSequence(sequence, 1);
uint size = archive.readWORD();
for (uint i = 0; i < size; ++i) {
sequence = findSequence(archive.readString());
authorParallelSequence(sequence, 1);
}
}
void Sequencer::saveState(Archive &archive) {
Common::String sequenceName;
if (_context)
sequenceName = _context->getSequence()->getName();
archive.writeString(sequenceName);
archive.writeWORD(_parallelContexts.size());
for (uint i = 0; i < _parallelContexts.size(); ++i) {
archive.writeString(_parallelContexts[i]->getSequence()->getName());
}
}
SequenceContext *Sequencer::findConflictingContextWith(SequenceContext *context) {
if (_context && _context->isConflictingWith(context)) {
return _context;
}
for (uint i = 0; i < _parallelContexts.size(); ++i) {
if (_parallelContexts[i]->isConflictingWith(context))
return _parallelContexts[i];
}
return nullptr;
}
SequenceActorState *Sequencer::findState(const Common::String &name) {
SequenceActorState *state = nullptr;
if (_context && (state = _context->findState(name)))
return state;
for (uint i = 0; i < _parallelContexts.size(); ++i) {
state = _parallelContexts[i]->findState(name);
if (state)
break;
}
return state;
}
} // End of namespace Pink

View File

@@ -0,0 +1,80 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_SEQUENCER_H
#define PINK_SEQUENCER_H
#include "pink/objects/object.h"
namespace Pink {
class Sequence;
class SequenceContext;
class GamePage;
class SeqTimer;
struct SequenceActorState;
class Sequencer : public Object {
public:
Sequencer(GamePage *page);
~Sequencer() override;
void toConsole() const override;
void deserialize(Archive &archive) override;
public:
void loadState(Archive &archive);
void saveState(Archive &archive);
bool isPlaying() { return _context != nullptr; }
bool isSkipping() { return _isSkipping; }
void update();
void authorSequence(Sequence *sequence, bool loadingSave);
void authorParallelSequence(Sequence *sequence, bool loadingSave);
void skipSubSequence();
void restartSequence();
void skipSequence();
void removeContext(SequenceContext *context);
SequenceContext *findConflictingContextWith(SequenceContext *context);
Sequence *findSequence(const Common::String &name);
SequenceActorState *findState(const Common::String &name);
GamePage *getPage() const { return _page; }
private:
SequenceContext *_context;
GamePage *_page;
Common::Array<SequenceContext *> _parallelContexts;
Array<Sequence *> _sequences;
Array<SeqTimer *> _timers;
uint _time;
bool _isSkipping;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,130 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/hash-str.h"
#include "pink/archive.h"
#include "pink/pink.h"
#include "pink/objects/side_effect.h"
#include "pink/objects/actors/lead_actor.h"
#include "pink/objects/pages/game_page.h"
#include "pink/objects/walk/walk_location.h"
#include "pink/objects/walk/walk_mgr.h"
namespace Pink {
void SideEffectExit::deserialize(Archive &archive) {
_nextModule = archive.readString();
_nextPage = archive.readString();
}
void SideEffectExit::execute(Actor *actor) {
actor->getPage()->getLeadActor()->setNextExecutors(_nextModule, _nextPage);
}
void SideEffectExit::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tSideEffectExit: _nextModule=%s, _nextPage=%s", _nextModule.c_str(), _nextPage.c_str());
}
void SideEffectLocation::deserialize(Archive &archive) {
_location = archive.readString();
}
void SideEffectLocation::execute(Actor *actor) {
WalkMgr *mgr = actor->getPage()->getWalkMgr();
WalkLocation *location = mgr->findLocation(_location);
if (location)
mgr->setCurrentWayPoint(location);
}
void SideEffectLocation::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tSideEffectLocation: _location=%s", _location.c_str());
}
void SideEffectInventoryItemOwner::deserialize(Archive &archive) {
_item = archive.readString();
_owner = archive.readString();
}
void SideEffectInventoryItemOwner::execute(Actor *actor) {
InventoryMgr *mgr = actor->getInventoryMgr();
InventoryItem *item = mgr->findInventoryItem(_item);
mgr->setItemOwner(_owner, item);
}
void SideEffectInventoryItemOwner::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tSideEffectInventoryItemOwner: _item=%s, _owner=%s", _item.c_str(), _owner.c_str());
}
void SideEffectVariable::deserialize(Pink::Archive &archive) {
_name = archive.readString();
_value = archive.readString();
}
void SideEffectGameVariable::execute(Actor *actor) {
actor->getPage()->getGame()->setVariable(_name, _value);
}
void SideEffectGameVariable::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tSideEffectGameVariable: _name=%s, _value=%s", _name.c_str(), _value.c_str());
}
void SideEffectModuleVariable::execute(Actor *actor) {
actor->getPage()->getModule()->setVariable(_name, _value);
}
void SideEffectModuleVariable::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tSideEffectModuleVariable: _name=%s, _value=%s", _name.c_str(), _value.c_str());
}
void SideEffectPageVariable::execute(Actor *actor) {
actor->getPage()->setVariable(_name, _value);
}
void SideEffectPageVariable::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\t\tSideEffectPageVariable: _name=%s, _value=%s", _name.c_str(), _value.c_str());
}
void SideEffectRandomPageVariable::deserialize(Archive &archive) {
_name = archive.readString();
_values.deserialize(archive);
}
void SideEffectRandomPageVariable::execute(Actor *actor) {
assert(!_values.empty());
Common::RandomSource &rnd = actor->getPage()->getGame()->getRnd();
uint index = rnd.getRandomNumber(_values.size() - 1);
actor->getPage()->setVariable(_name, _values[index]);
}
void SideEffectRandomPageVariable::toConsole() const {
Common::String values("{");
for (uint i = 0; i < _values.size(); ++i) {
values += _values[i];
values += ',';
}
values += '}';
debugC(6, kPinkDebugLoadingObjects, "\t\tSideEffectRandomPageVariable: _name=%s, _values=%s", _name.c_str(), values.c_str());
}
} // End of namespace Pink

View File

@@ -0,0 +1,111 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_SIDE_EFFECT_H
#define PINK_SIDE_EFFECT_H
#include "pink/utils.h"
#include "pink/objects/object.h"
namespace Pink {
class Actor;
class SideEffect : public Object {
public:
void deserialize(Archive &archive) override = 0;
virtual void execute(Actor *actor) = 0;
};
class SideEffectExit : public SideEffect {
public:
void deserialize(Archive &archive) override;
void toConsole() const override;
void execute(Actor *actor) override;
private:
Common::String _nextModule;
Common::String _nextPage;
};
class SideEffectLocation : public SideEffect {
public:
void deserialize(Archive &archive) override;
void execute(Actor *actor) override;
void toConsole() const override;
private:
Common::String _location;
};
class SideEffectInventoryItemOwner : public SideEffect {
public:
void deserialize(Archive &archive) override;
void execute(Actor *actor) override;
void toConsole() const override;
private:
Common::String _item;
Common::String _owner;
};
class SideEffectVariable : public SideEffect {
public:
void deserialize(Archive &archive) override;
void execute(Actor *actor) override = 0;
protected:
Common::String _name;
Common::String _value;
};
class SideEffectGameVariable : public SideEffectVariable {
public:
void toConsole() const override;
void execute(Actor *actor) override;
};
class SideEffectModuleVariable : public SideEffectVariable {
public:
void toConsole() const override;
void execute(Actor *actor) override;
};
class SideEffectPageVariable : public SideEffectVariable {
public:
void toConsole() const override;
void execute(Actor *actor) override;
};
class SideEffectRandomPageVariable : public SideEffect {
public:
void deserialize(Archive &archive) override;
void toConsole() const override;
void execute(Actor *actor) override;
private:
Common::String _name;
StringArray _values;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,43 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/debug.h"
#include "pink/archive.h"
#include "pink/pink.h"
#include "pink/objects/walk/walk_location.h"
namespace Pink {
void WalkLocation::deserialize(Pink::Archive &archive) {
NamedObject::deserialize(archive);
_neighbors.deserialize(archive);
}
void WalkLocation::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "\tWalkLocation: _name =%s", _name.c_str());
debugC(6, kPinkDebugLoadingObjects, "\tNeighbors:");
for (uint i = 0; i < _neighbors.size(); ++i) {
debugC(6, kPinkDebugLoadingObjects, "\t\t%s", _neighbors[i].c_str());
}
}
} // End of namespace Pink

View File

@@ -0,0 +1,40 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_WALK_LOCATION_H
#define PINK_WALK_LOCATION_H
#include "pink/utils.h"
namespace Pink {
class WalkLocation : public NamedObject {
public:
void deserialize(Archive &archive) override;
void toConsole() const override;
Common::StringArray &getNeigbors() { return _neighbors;}
private:
StringArray _neighbors;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,175 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "math/utils.h"
#include "pink/archive.h"
#include "pink/cel_decoder.h"
#include "pink/pink.h"
#include "pink/objects/actions/walk_action.h"
#include "pink/objects/actors/lead_actor.h"
#include "pink/objects/walk/walk_location.h"
namespace Pink {
WalkMgr::WalkMgr()
: _isWalking(false), _leadActor(nullptr),
_destination(nullptr) {}
WalkMgr::~WalkMgr() {
for (uint i = 0; i < _locations.size(); ++i) {
delete _locations[i];
}
}
void WalkMgr::deserialize(Pink::Archive &archive) {
_leadActor = static_cast<LeadActor *>(archive.readObject());
_locations.deserialize(archive);
}
WalkLocation *WalkMgr::findLocation(const Common::String &name) {
for (uint i = 0; i < _locations.size(); ++i) {
if (_locations[i]->getName() == name)
return _locations[i];
}
return nullptr;
}
void WalkMgr::toConsole() const {
debugC(6, kPinkDebugLoadingObjects, "WalkMgr:");
for (uint i = 0; i < _locations.size(); ++i) {
_locations[i]->toConsole();
}
}
void WalkMgr::start(WalkLocation *destination) {
if (_current.name.empty()) {
_current.name = _locations[0]->getName();
_current.coords = getLocationCoordinates(_locations[0]->getName());
}
_destination = destination;
if (_isWalking)
return;
if (_current.name == _destination->getName()) {
end();
} else {
_isWalking = true;
WalkLocation *currentLocation = findLocation(_current.name);
WalkShortestPath path(this);
WalkLocation *nextLocation = path.next(currentLocation, _destination);
initNextWayPoint(nextLocation);
_leadActor->setAction(getWalkAction());
}
}
void WalkMgr::initNextWayPoint(WalkLocation *location) {
_next.name = location->getName();
_next.coords = getLocationCoordinates(location->getName());
}
WalkAction *WalkMgr::getWalkAction() {
Common::String walkActionName;
bool horizontal = false;
if (_current.coords.z == _next.coords.z) {
if (_next.coords.point.x > _current.coords.point.x) {
walkActionName = Common::String::format("%dRight", _current.coords.z);
} else
walkActionName = Common::String::format("%dLeft", _next.coords.z);
horizontal = true;
} else
walkActionName = Common::String::format("%dTo%d", _current.coords.z, _next.coords.z);
WalkAction *action = (WalkAction *)_leadActor->findAction(walkActionName);
if (action) {
action->setWalkMgr(this);
action->setType(horizontal);
}
return action;
}
double WalkMgr::getLengthBetweenLocations(WalkLocation *first, WalkLocation *second) {
Coordinates firstCoord = getLocationCoordinates(first->getName());
Coordinates secondCoord = getLocationCoordinates(second->getName());
return Math::hypotenuse(secondCoord.point.x - firstCoord.point.x, secondCoord.point.y - firstCoord.point.y);
}
Coordinates WalkMgr::getLocationCoordinates(const Common::String &locationName) {
Action *action = _leadActor->findAction(locationName);
return action->getCoordinates();
}
void WalkMgr::setCurrentWayPoint(WalkLocation *location) {
_current.name = location->getName();
_current.coords = getLocationCoordinates(_current.name);
}
void WalkMgr::update() {
if (_leadActor->isPlaying())
return;
WalkShortestPath path(this);
_current = _next;
WalkLocation *next = path.next(findLocation(_current.name), _destination);
if (next) {
initNextWayPoint(next);
_leadActor->setAction(getWalkAction());
} else
end();
}
void WalkMgr::end() {
_isWalking = false;
_leadActor->onWalkEnd(_destination->getName());
}
void WalkMgr::loadState(Archive &archive) {
_isWalking = archive.readByte();
_current.name = archive.readString();
if (!_current.name.empty()) {
_current.coords = getLocationCoordinates(_current.name);
}
if (_isWalking) {
_next.name = archive.readString();
_destination = findLocation(archive.readString());
_next.coords = getLocationCoordinates(_next.name);
}
}
void WalkMgr::saveState(Archive &archive) {
archive.writeByte(_isWalking);
archive.writeString(_current.name);
if (_isWalking) {
archive.writeString(_next.name);
archive.writeString(_destination->getName());
}
}
void WalkMgr::skip() {
initNextWayPoint(_destination);
_current = _next;
end();
}
} // End of namespace Pink

View File

@@ -0,0 +1,85 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_WALK_MGR_H
#define PINK_WALK_MGR_H
#include "common/rect.h"
#include "pink/objects/object.h"
#include "pink/objects/walk/walk_shortest_path.h"
#include "pink/utils.h"
namespace Pink {
class WalkLocation;
class LeadActor;
class WalkAction;
struct Coordinates {
Common::Point point;
int z;
};
class WalkMgr : public Object {
public:
WalkMgr();
~WalkMgr() override;
void deserialize(Archive &archive) override;
void toConsole() const override;
WalkLocation *findLocation(const Common::String &name);
void start(WalkLocation *destination);
void update();
double getLengthBetweenLocations(WalkLocation *first, WalkLocation *second);
void setCurrentWayPoint(WalkLocation *location);
void loadState(Archive &archive);
void saveState(Archive &archive);
void skip();
const Coordinates &getStartCoords() { return _current.coords; }
const Coordinates &getEndCoords() { return _next.coords; }
private:
struct WayPoint {
Common::String name;
Coordinates coords;
};
Coordinates getLocationCoordinates(const Common::String &locationName);
void end();
void initNextWayPoint(WalkLocation *location);
WalkAction *getWalkAction();
LeadActor *_leadActor;
WalkLocation *_destination;
Array<WalkLocation *> _locations;
WayPoint _current;
WayPoint _next;
bool _isWalking;
};
} // End of namespace Pink
#endif

View File

@@ -0,0 +1,157 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "pink/objects/walk/walk_location.h"
#include "pink/objects/walk/walk_mgr.h"
namespace Pink {
WalkShortestPath::WalkShortestPath(WalkMgr *manager)
: _manager(manager)
{}
WalkLocation *WalkShortestPath::next(WalkLocation *start, WalkLocation *destination) {
if (start == destination)
return nullptr;
add(start, 0.0, nullptr);
while (build() != destination) {}
return getNearestNeighbor(destination);
}
void WalkShortestPath::add(WalkLocation *wl, double val, WalkLocation *nearest) {
_locations.push_back(wl);
_visited.push_back(wl);
_weight.push_back(val);
_nearestNeigbor.push_back(nearest);
}
WalkLocation *WalkShortestPath::build() {
WalkLocation *nearest = nullptr;
WalkLocation *location = nullptr;
double len = -1.0;
addLocationsToVisit();
for (uint i = 0; i < _toVisit.size(); ++i) {
double curLen = getLengthToNearestNeigbor(_toVisit[i]);
if (curLen < 0) {
remove(_toVisit[i]);
continue;
}
curLen += getWeight(_toVisit[i]);
if (len < 0.0 || len > curLen) {
len = curLen;
location = _toVisit[i];
nearest = getNearestNeighbor(_toVisit[i]);
if (!nearest)
nearest = findNearestNeighbor(_toVisit[i]);
}
}
WalkLocation *neighbor = findNearestNeighbor(location);
if (neighbor)
add(neighbor, len, nearest);
return neighbor;
}
WalkLocation *WalkShortestPath::getNearestNeighbor(WalkLocation *location) {
for(uint i = 0; i < _visited.size(); ++i) {
if (_visited[i] == location)
return _nearestNeigbor[i];
}
return nullptr;
}
void WalkShortestPath::addLocationsToVisit() {
_toVisit.resize(_locations.size());
for (uint i = 0; i < _locations.size(); ++i) {
_toVisit[i] = _locations[i];
}
}
double WalkShortestPath::getLengthToNearestNeigbor(WalkLocation *location) {
double minLength = -1.0;
Common::StringArray &neighbors = location->getNeigbors();
for (uint i = 0; i < neighbors.size(); ++i) {
WalkLocation *neighbor = _manager->findLocation(neighbors[i]);
if (!isLocationVisited(neighbor)) {
double length = _manager->getLengthBetweenLocations(location, neighbor);
if (minLength >= 0.0) {
if (length < minLength)
minLength = length;
} else
minLength = length;
}
}
return minLength;
}
WalkLocation *WalkShortestPath::findNearestNeighbor(WalkLocation *location) {
double minLength = -1.0;
WalkLocation *nearest = nullptr;
Common::StringArray &neighbors = location->getNeigbors();
for (uint i = 0; i < neighbors.size(); ++i) {
WalkLocation *neighbor = _manager->findLocation(neighbors[i]);
if (!isLocationVisited(neighbor)) {
double length = _manager->getLengthBetweenLocations(location, neighbor);
if (minLength >= 0.0) {
if (length < minLength) {
nearest = neighbor;
minLength = length;
}
} else {
nearest = neighbor;
minLength = length;
}
}
}
return nearest;
}
double WalkShortestPath::getWeight(WalkLocation *location) {
for (uint i = 0; i < _locations.size(); ++i) {
if (_locations[i] == location)
return _weight[i];
}
return 0.0;
}
bool WalkShortestPath::isLocationVisited(WalkLocation *location) {
for (uint i = 0; i < _visited.size(); ++i) {
if (_visited[i] == location)
return true;
}
return false;
}
void WalkShortestPath::remove(WalkLocation *location) {
for (uint i = 0; i < _locations.size(); ++i) {
if (_locations[i] == location) {
_locations.remove_at(i);
_weight.remove_at(i);
break;
}
}
}
} // End of namespace Pink

View File

@@ -0,0 +1,59 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PINK_WALK_SHORTEST_PATH_H
#define PINK_WALK_SHORTEST_PATH_H
#include "common/array.h"
namespace Pink {
class WalkLocation;
class WalkMgr;
class WalkShortestPath {
public:
WalkShortestPath(WalkMgr *manager);
WalkLocation *next(WalkLocation *start, WalkLocation *destination);
private:
void add(WalkLocation *wl, double val, WalkLocation *nearest);
void remove(WalkLocation *location);
WalkLocation *build();
WalkLocation *getNearestNeighbor(WalkLocation *location);
WalkLocation *findNearestNeighbor(WalkLocation *location);
double getLengthToNearestNeigbor(WalkLocation *location);
double getWeight(WalkLocation *location);
void addLocationsToVisit();
bool isLocationVisited(WalkLocation *location);
WalkMgr *_manager;
Common::Array<WalkLocation *> _locations;
Common::Array<WalkLocation *> _toVisit;
Common::Array<double> _weight;
Common::Array<WalkLocation *> _visited;
Common::Array<WalkLocation *> _nearestNeigbor;
};
} // End of namespace Pink
#endif