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/debug.h"
24 
25 #include "pink/archive.h"
26 #include "pink/pink.h"
27 #include "pink/objects/actions/action.h"
28 #include "pink/objects/actors/actor.h"
29 #include "pink/objects/pages/game_page.h"
30 #include "pink/objects/sequences/sequence_item.h"
31 #include "pink/objects/sequences/sequence.h"
32 #include "pink/objects/sequences/sequencer.h"
33 #include "pink/objects/sequences/sequence_context.h"
34 
35 namespace Pink {
36 
deserialize(Archive & archive)37 void SequenceItem::deserialize(Archive &archive) {
38 	_actor = archive.readString();
39 	_action = archive.readString();
40 }
41 
toConsole()42 void SequenceItem::toConsole() {
43 	debugC(6, kPinkDebugLoadingObjects, "\t\t\t\tSequenceItem: _actor=%s, _action=%s", _actor.c_str(), _action.c_str());
44 }
45 
execute(uint segment,Sequence * sequence,bool loadingSave)46 bool SequenceItem::execute(uint segment, Sequence *sequence, bool loadingSave) {
47 	Actor *actor = sequence->getSequencer()->getPage()->findActor(_actor);
48 	Action *action;
49 	if (!actor || !(action = actor->findAction(_action)))
50 		return false;
51 
52 	actor->setAction(action, loadingSave);
53 
54 	SequenceContext *context = sequence->getContext();
55 	SequenceActorState *state = context->findState(_actor);
56 	if (state)
57 		state->_segment = segment;
58 	if (isLeader())
59 		context->setActor(actor);
60 	return true;
61 }
62 
isLeader()63 bool SequenceItem::isLeader() {
64 	return false;
65 }
66 
isLeader()67 bool SequenceItemLeader::isLeader() {
68 	return true;
69 }
70 
toConsole()71 void SequenceItemLeader::toConsole() {
72 	debugC(6, kPinkDebugLoadingObjects, "\t\t\t\tSequenceItemLeader: _actor=%s, _action=%s", _actor.c_str(), _action.c_str());
73 }
74 
75 
deserialize(Archive & archive)76 void SequenceItemLeaderAudio::deserialize(Archive &archive) {
77 	SequenceItem::deserialize(archive);
78 	_sample = archive.readDWORD();
79 }
80 
toConsole()81 void SequenceItemLeaderAudio::toConsole() {
82 	debugC(6, kPinkDebugLoadingObjects, "\t\t\t\tSequenceItemLeaderAudio: _actor=%s, _action=%s _sample=%d", _actor.c_str(), _action.c_str(), _sample);
83 }
84 
execute(uint segment,Sequence * sequence,bool loadingSave)85 bool SequenceItemDefaultAction::execute(uint segment, Sequence *sequence, bool loadingSave) {
86 	SequenceActorState *state = sequence->getContext()->findState(_actor);
87 	if (state)
88 		state->defaultActionName = _action;
89 	return true;
90 }
91 
toConsole()92 void SequenceItemDefaultAction::toConsole() {
93 	debugC(6, kPinkDebugLoadingObjects, "\t\t\t\tSequenceItemDefaultAction: _actor=%s, _action=%s", _actor.c_str(), _action.c_str());
94 }
95 
skip(Sequence * sequence)96 void SequenceItemDefaultAction::skip(Sequence *sequence) {
97 	execute(0, sequence, 1);
98 }
99 
100 } // End of namespace Pink
101