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 "kyra/engine/kyra_lok.h"
24 #include "kyra/graphics/animator_lok.h"
25 #include "kyra/engine/timer.h"
26
27 namespace Kyra {
28
29 #define TimerV1(x) new Common::Functor1Mem<int, void, KyraEngine_LoK>(this, &KyraEngine_LoK::x)
30
setupTimers()31 void KyraEngine_LoK::setupTimers() {
32 for (int i = 0; i <= 4; ++i)
33 _timer->addTimer(i, 0, -1, 1);
34
35 _timer->addTimer(5, 0, 5, 1);
36 _timer->addTimer(6, 0, 7, 1);
37 _timer->addTimer(7, 0, 8, 1);
38 _timer->addTimer(8, 0, 9, 1);
39 _timer->addTimer(9, 0, 7, 1);
40
41 for (int i = 10; i <= 13; ++i)
42 _timer->addTimer(i, 0, 420, 1);
43
44 _timer->addTimer(14, TimerV1(timerAsWillowispTimeout), 600, 1);
45 _timer->addTimer(15, TimerV1(timerUpdateHeadAnims), 11, 1);
46 _timer->addTimer(16, TimerV1(timerTulipCreator), 7200, 1);
47 _timer->addTimer(17, TimerV1(timerRubyCreator), 7200, 1);
48 _timer->addTimer(18, TimerV1(timerAsInvisibleTimeout), 600, 1);
49 _timer->addTimer(19, TimerV1(timerRedrawAmulet), 600, 1);
50
51 _timer->addTimer(20, 0, 7200, 1);
52 _timer->addTimer(21, TimerV1(timerLavenderRoseCreator), 18000, 1);
53 _timer->addTimer(22, 0, 7200, 1);
54
55 _timer->addTimer(23, 0, 10800, 1);
56 _timer->addTimer(24, TimerV1(timerAcornCreator), 10800, 1);
57 _timer->addTimer(25, 0, 10800, 1);
58 _timer->addTimer(26, TimerV1(timerBlueberryCreator), 10800, 1);
59 _timer->addTimer(27, 0, 10800, 1);
60
61 _timer->addTimer(28, 0, 21600, 1);
62 _timer->addTimer(29, 0, 7200, 1);
63 _timer->addTimer(30, 0, 10800, 1);
64
65 _timer->addTimer(31, TimerV1(timerFadeText), -1, 1);
66 _timer->addTimer(32, TimerV1(timerWillowispFrameTimer), 9, 1);
67 _timer->addTimer(33, TimerV1(timerInvisibleFrameTimer), 3, 1);
68 }
69
timerUpdateHeadAnims(int timerNum)70 void KyraEngine_LoK::timerUpdateHeadAnims(int timerNum) {
71 static const int8 frameTable[] = {
72 4, 5, 4, 5, 4, 5, 0, 1,
73 4, 5, 4, 4, 6, 4, 8, 1,
74 9, 4, -1
75 };
76
77 if (_talkingCharNum < 0)
78 return;
79
80 _currHeadShape = frameTable[_currentHeadFrameTableIndex];
81 ++_currentHeadFrameTableIndex;
82
83 if (frameTable[_currentHeadFrameTableIndex] == -1)
84 _currentHeadFrameTableIndex = 0;
85
86 _animator->animRefreshNPC(0);
87 _animator->animRefreshNPC(_talkingCharNum);
88 }
89
timerTulipCreator(int timerNum)90 void KyraEngine_LoK::timerTulipCreator(int timerNum) {
91 if (_currentCharacter->sceneId == 0x1C)
92 return;
93
94 setItemCreationFlags(17, 3);
95 }
96
timerRubyCreator(int timerNum)97 void KyraEngine_LoK::timerRubyCreator(int timerNum) {
98 if (_currentCharacter->sceneId == 0x23)
99 return;
100
101 setItemCreationFlags(22, 4);
102 }
103
timerLavenderRoseCreator(int timerNum)104 void KyraEngine_LoK::timerLavenderRoseCreator(int timerNum) {
105 if (_currentCharacter->sceneId == 0x06)
106 return;
107
108 setItemCreationFlags(0, 4);
109 }
110
timerAcornCreator(int timerNum)111 void KyraEngine_LoK::timerAcornCreator(int timerNum) {
112 if (_currentCharacter->sceneId == 0x1F)
113 return;
114
115 setItemCreationFlags(72, 5);
116 }
117
timerBlueberryCreator(int timerNum)118 void KyraEngine_LoK::timerBlueberryCreator(int timerNum) {
119 if (_currentCharacter->sceneId == 0x28)
120 return;
121
122 setItemCreationFlags(26, 7);
123 }
124
setItemCreationFlags(int offset,int count)125 void KyraEngine_LoK::setItemCreationFlags(int offset, int count) {
126 int rndNr = _rnd.getRandomNumberRng(0, count);
127
128 for (int i = 0; i <= count; i++) {
129 if (!queryGameFlag(rndNr + offset)) {
130 setGameFlag(rndNr + offset);
131 break;
132 } else {
133 rndNr++;
134 if (rndNr > count)
135 rndNr = 0;
136 }
137 }
138 }
139
timerFadeText(int timerNum)140 void KyraEngine_LoK::timerFadeText(int timerNum) {
141 _fadeText = true;
142 }
143
timerWillowispFrameTimer(int timerNum)144 void KyraEngine_LoK::timerWillowispFrameTimer(int timerNum) {
145 if (_brandonStatusBit & 2)
146 _brandonStatusBit0x02Flag = 1;
147 }
148
timerInvisibleFrameTimer(int timerNum)149 void KyraEngine_LoK::timerInvisibleFrameTimer(int timerNum) {
150 if (_brandonStatusBit & 0x20)
151 _brandonStatusBit0x20Flag = 1;
152 }
153
setTextFadeTimerCountdown(int16 countdown)154 void KyraEngine_LoK::setTextFadeTimerCountdown(int16 countdown) {
155 if (countdown == -1)
156 countdown = 32000;
157
158 _timer->setCountdown(31, countdown * 60);
159 }
160
timerAsInvisibleTimeout(int timerNum)161 void KyraEngine_LoK::timerAsInvisibleTimeout(int timerNum) {
162 if (_brandonStatusBit & 0x20) {
163 checkAmuletAnimFlags();
164 _timer->setCountdown(18, -1);
165 }
166 }
167
timerAsWillowispTimeout(int timerNum)168 void KyraEngine_LoK::timerAsWillowispTimeout(int timerNum) {
169 if (_brandonStatusBit & 0x2) {
170 checkAmuletAnimFlags();
171 _timer->setCountdown(14, -1);
172 }
173 }
174
timerRedrawAmulet(int timerNum)175 void KyraEngine_LoK::timerRedrawAmulet(int timerNum) {
176 if (queryGameFlag(0xF1)) {
177 drawAmulet();
178 _timer->setCountdown(19, -1);
179 }
180 }
181
setWalkspeed(uint8 newSpeed)182 void KyraEngine_LoK::setWalkspeed(uint8 newSpeed) {
183 if (!_timer)
184 return;
185
186 static const uint8 speeds[] = { 11, 9, 6, 5, 3 };
187
188 assert(newSpeed < ARRAYSIZE(speeds));
189 _timer->setDelay(5, speeds[newSpeed]);
190 }
191
192 } // End of namespace Kyra
193