1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "common/hash-str.h"
24
25 #include "pink/archive.h"
26 #include "pink/pink.h"
27 #include "pink/objects/side_effect.h"
28 #include "pink/objects/actors/lead_actor.h"
29 #include "pink/objects/pages/game_page.h"
30 #include "pink/objects/walk/walk_location.h"
31 #include "pink/objects/walk/walk_mgr.h"
32
33 namespace Pink {
34
deserialize(Archive & archive)35 void SideEffectExit::deserialize(Archive &archive) {
36 _nextModule = archive.readString();
37 _nextPage = archive.readString();
38 }
39
execute(Actor * actor)40 void SideEffectExit::execute(Actor *actor) {
41 actor->getPage()->getLeadActor()->setNextExecutors(_nextModule, _nextPage);
42 }
43
toConsole()44 void SideEffectExit::toConsole() {
45 debugC(6, kPinkDebugLoadingObjects, "\t\tSideEffectExit: _nextModule=%s, _nextPage=%s", _nextModule.c_str(), _nextPage.c_str());
46 }
47
deserialize(Archive & archive)48 void SideEffectLocation::deserialize(Archive &archive) {
49 _location = archive.readString();
50 }
51
execute(Actor * actor)52 void SideEffectLocation::execute(Actor *actor) {
53 WalkMgr *mgr = actor->getPage()->getWalkMgr();
54 WalkLocation *location = mgr->findLocation(_location);
55 if (location)
56 mgr->setCurrentWayPoint(location);
57 }
58
toConsole()59 void SideEffectLocation::toConsole() {
60 debugC(6, kPinkDebugLoadingObjects, "\t\tSideEffectLocation: _location=%s", _location.c_str());
61 }
62
deserialize(Archive & archive)63 void SideEffectInventoryItemOwner::deserialize(Archive &archive) {
64 _item = archive.readString();
65 _owner = archive.readString();
66 }
67
execute(Actor * actor)68 void SideEffectInventoryItemOwner::execute(Actor *actor) {
69 InventoryMgr *mgr = actor->getInventoryMgr();
70 InventoryItem *item = mgr->findInventoryItem(_item);
71 mgr->setItemOwner(_owner, item);
72 }
73
toConsole()74 void SideEffectInventoryItemOwner::toConsole() {
75 debugC(6, kPinkDebugLoadingObjects, "\t\tSideEffectInventoryItemOwner: _item=%s, _owner=%s", _item.c_str(), _owner.c_str());
76 }
77
deserialize(Pink::Archive & archive)78 void SideEffectVariable::deserialize(Pink::Archive &archive) {
79 _name = archive.readString();
80 _value = archive.readString();
81 }
82
execute(Actor * actor)83 void SideEffectGameVariable::execute(Actor *actor) {
84 actor->getPage()->getGame()->setVariable(_name, _value);
85 }
86
toConsole()87 void SideEffectGameVariable::toConsole() {
88 debugC(6, kPinkDebugLoadingObjects, "\t\tSideEffectGameVariable: _name=%s, _value=%s", _name.c_str(), _value.c_str());
89 }
90
execute(Actor * actor)91 void SideEffectModuleVariable::execute(Actor *actor) {
92 actor->getPage()->getModule()->setVariable(_name, _value);
93 }
94
toConsole()95 void SideEffectModuleVariable::toConsole() {
96 debugC(6, kPinkDebugLoadingObjects, "\t\tSideEffectModuleVariable: _name=%s, _value=%s", _name.c_str(), _value.c_str());
97 }
98
execute(Actor * actor)99 void SideEffectPageVariable::execute(Actor *actor) {
100 actor->getPage()->setVariable(_name, _value);
101 }
102
toConsole()103 void SideEffectPageVariable::toConsole() {
104 debugC(6, kPinkDebugLoadingObjects, "\t\tSideEffectPageVariable: _name=%s, _value=%s", _name.c_str(), _value.c_str());
105 }
106
deserialize(Archive & archive)107 void SideEffectRandomPageVariable::deserialize(Archive &archive) {
108 _name = archive.readString();
109 _values.deserialize(archive);
110 }
111
execute(Actor * actor)112 void SideEffectRandomPageVariable::execute(Actor *actor) {
113 assert(!_values.empty());
114
115 Common::RandomSource &rnd = actor->getPage()->getGame()->getRnd();
116 uint index = rnd.getRandomNumber(_values.size() - 1);
117
118 actor->getPage()->setVariable(_name, _values[index]);
119 }
120
toConsole()121 void SideEffectRandomPageVariable::toConsole() {
122 Common::String values("{");
123 for (uint i = 0; i < _values.size(); ++i) {
124 values += _values[i];
125 values += ',';
126 }
127 values += '}';
128 debugC(6, kPinkDebugLoadingObjects, "\t\tSideEffectRandomPageVariable: _name=%s, _values=%s", _name.c_str(), values.c_str());
129 }
130
131 } // End of namespace Pink
132