4 * Riven-Wahrk - a reimplementation of the game Riven, by Cyan
5 * Copyright (C) 2009 Tyler Genter <tylergenter@gmail.com>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 HsptRecord::HsptRecord (File
*file
, int addr
, Game
*game
) {
30 blstId
= file
->readSShort (addr
);
31 nameRec
= file
->readSShort (addr
+ 2);
32 left
= file
->readSShort (addr
+ 4);
33 top
= file
->readSShort (addr
+ 6);
34 right
= file
->readSShort (addr
+ 8);
35 bottom
= file
->readSShort (addr
+ 10);
37 mouseCursor
= file
->readUShort (addr
+ 14);
38 index
= file
->readUShort (addr
+ 16);
40 isZip
= file
->readUShort (addr
+ 20);
43 script
= new Script (file
, addr
+ 22, game
);
44 length
= script
->getSize ()*2 + 22; // getSize() returns number of shorts, so *2
48 HsptRecord
*Hotspot::findRecord (uint16_t blst
) {
52 map
<int,HsptRecord
>::iterator iter
= records
.end();
56 if (iter
->second
.blstId
== blst
)
57 return &(iter
->second
);
58 } while (iter
!= records
.begin());
62 void Hotspot::findRecord (int16_t x
, int16_t y
) {
63 if (records
.empty()) {
68 map
<int,HsptRecord
>::iterator iter
= records
.end();
72 if (iter
->second
.isInside(x
,y
))
73 if ((!iter
->second
.isZip
|| (iter
->second
.isZip
&& game
->zipMode
)) &&
74 iter
->second
.isEnabled
) {
75 current
= &(iter
->second
);
78 } while (iter
!= records
.begin());
82 void Hotspot::readBlst (int id
) {
83 File
file (game
->getStack(), Resource::BLST
, id
);
85 uint16_t count
= file
.readUShort (0);
86 for (int i
=0; i
<count
; i
++) {
89 temp
.enabled
= (file
.readUShort (2 + i
*6 + 2) == 1);
90 temp
.record
= findRecord (file
.readUShort (2 + i
*6 + 4));
91 blst
.insert (make_pair (file
.readUShort (2 + i
*6), temp
));
96 Hotspot::Hotspot (Game
*gameIn
, int id
) {
100 File
file (game
->getStack(), Resource::HSPT
, id
);
104 uint16_t count
= file
.readUShort (0);
108 for (int i
=0; i
<count
; i
++) {
109 HsptRecord
temp (&file
, offset
, game
);
110 records
.insert (make_pair (temp
.getIndex(), temp
));
111 offset
+= temp
.getLength();
118 void Hotspot::mouseMove (int16_t x
, int16_t y
) {
124 current
->script
->runHandler (Handler::MouseWithin
);
128 void Hotspot::mouseDown () {
130 current
->script
->runHandler (Handler::MouseDown
);
133 void Hotspot::mouseUp () {
135 current
->script
->runHandler (Handler::MouseUp
);