1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "pink/constants.h"
#include "pink/cursor_mgr.h"
#include "pink/objects/actions/action.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(1) {}
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 = 1;
} else {
_isActionEnded = 0;
_action->start();
_action->pause(paused);
}
}
bool Actor::initPalette(Director *director) {
for (uint i = 0; i < _actions.size(); ++i) {
if (_actions[i]->initPalette(director))
return true;
}
return false;
}
void Actor::toConsole() {
debug("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(const Common::Point point, CursorMgr *mgr) {
mgr->setCursor(kDefaultCursor, point, Common::String());
}
void Actor::onMouseOverWithItem(const 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;
}
const Common::String &Actor::getLocation() const {
static const Common::String empty;
return empty;
}
void Actor::setAction(Action *newAction) {
if (_action) {
_isActionEnded = 1;
_action->end();
}
_action = newAction;
if (newAction) {
_isActionEnded = 0;
_action->start();
}
}
void Actor::setAction(Action *newAction, bool loadingSave) {
if (loadingSave) {
_isActionEnded = 1;
_action = newAction;
} else {
setAction(newAction);
}
}
InventoryMgr *Actor::getInventoryMgr() const {
return _page->getModule()->getInventoryMgr();
}
const Common::String &Actor::getPDALink() const {
static const Common::String empty;
return empty;
}
} // End of namespace Pink
|