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 "mohawk/riven_stacks/rspit.h"
24
25 #include "mohawk/riven.h"
26 #include "mohawk/riven_card.h"
27 #include "mohawk/riven_graphics.h"
28 #include "mohawk/riven_inventory.h"
29 #include "mohawk/riven_video.h"
30
31 namespace Mohawk {
32 namespace RivenStacks {
33
RSpit(MohawkEngine_Riven * vm)34 RSpit::RSpit(MohawkEngine_Riven *vm) :
35 RivenStack(vm, kStackRspit) {
36
37 REGISTER_COMMAND(RSpit, xrshowinventory);
38 REGISTER_COMMAND(RSpit, xrhideinventory);
39 REGISTER_COMMAND(RSpit, xrcredittime);
40 REGISTER_COMMAND(RSpit, xrwindowsetup);
41 }
42
xrcredittime(const ArgumentArray & args)43 void RSpit::xrcredittime(const ArgumentArray &args) {
44 // Nice going, you used the trap book on Tay.
45
46 // The game chooses what ending based on agehn for us,
47 // so we just have to play the video and credits.
48 // For the record, when agehn == 4, Gehn will thank you for
49 // showing him the rebel age and then leave you to die.
50 // Otherwise, the rebels burn the book. Epic fail either way.
51
52 if (_vm->_vars["agehn"] == 4) {
53 runEndGame(1, 1500, 712);
54 } else {
55 runEndGame(1, 1500, 0);
56 }
57 }
58
xrshowinventory(const ArgumentArray & args)59 void RSpit::xrshowinventory(const ArgumentArray &args) {
60 }
61
xrhideinventory(const ArgumentArray & args)62 void RSpit::xrhideinventory(const ArgumentArray &args) {
63 }
64
rebelPrisonWindowTimer()65 void RSpit::rebelPrisonWindowTimer() {
66 // Randomize a video out in the middle of Tay
67 uint16 movie = _vm->_rnd->getRandomNumberRng(2, 13);
68 _vm->getCard()->playMovie(movie);
69 RivenVideo *video = _vm->_video->openSlot(movie);
70 video->playBlocking();
71
72 // Ensure the next video starts after this one ends
73 uint32 timeUntilNextVideo = _vm->_rnd->getRandomNumberRng(38, 58) * 1000;
74
75 // Save the time in case we leave the card and return
76 _vm->_vars["rvillagetime"] = timeUntilNextVideo + _vm->getTotalPlayTime();
77
78 // Reinstall this timer with the new time
79 installTimer(TIMER(RSpit, rebelPrisonWindowTimer), timeUntilNextVideo);
80 }
81
xrwindowsetup(const ArgumentArray & args)82 void RSpit::xrwindowsetup(const ArgumentArray &args) {
83 // Randomize what effect happens when you look out into the middle of Tay
84
85 uint32 villageTime = _vm->_vars["rvillagetime"];
86
87 // If we have time leftover from a previous run, set up the timer again
88 if (_vm->getTotalPlayTime() < villageTime) {
89 installTimer(TIMER(RSpit, rebelPrisonWindowTimer), villageTime - _vm->getTotalPlayTime());
90 return;
91 }
92
93 uint32 timeUntilNextVideo;
94
95 // Randomize the time until the next video
96 if (_vm->_rnd->getRandomNumber(2) == 0 && _vm->_vars["rrichard"] == 0) {
97 // In this case, a rebel is placed on a bridge
98 // The video itself is handled by the scripts later on
99 _vm->_vars["rrebelview"] = 0;
100 timeUntilNextVideo = _vm->_rnd->getRandomNumberRng(38, 58) * 1000;
101 } else {
102 // Otherwise, just a random video from the timer
103 _vm->_vars["rrebelview"] = 1;
104 timeUntilNextVideo = _vm->_rnd->getRandomNumber(20) * 1000;
105 }
106
107 // We don't set rvillagetime here because the scripts later just reset it to 0
108 // Of course, because of this, you can't return to the window twice and expect
109 // the timer to reinstall itself...
110
111 // Install our timer and we're on our way
112 installTimer(TIMER(RSpit, rebelPrisonWindowTimer), timeUntilNextVideo);
113 }
114
115 } // End of namespace RivenStacks
116 } // End of namespace Mohawk
117