4 * Riven-Wahrk - a reimplementation of the game Riven, by Cyan
5 * Copyright (C) 2009-2010 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/>.
27 using namespace riven
;
29 hspt_record_t::hspt_record_t (file_t
*file
, int addr
) {
31 blstId
= file
->readSShort (addr
);
32 nameRec
= file
->readSShort (addr
+ 2);
33 left
= file
->readSShort (addr
+ 4);
34 top
= file
->readSShort (addr
+ 6);
35 right
= file
->readSShort (addr
+ 8);
36 bottom
= file
->readSShort (addr
+ 10);
38 mouseCursor
= file
->readUShort (addr
+ 14);
39 index
= file
->readUShort (addr
+ 16);
41 isZip
= file
->readUShort (addr
+ 20);
44 script
= new script_t (file
, addr
+ 22);
45 length
= script
->get_size ()*2 + 22; // getSize() returns number of shorts, so *2
49 hspt_record_t
*hotspot_t::findRecord (uint16_t blst
) {
53 std::map
<int,hspt_record_t
>::iterator iter
= records
.end();
57 if (iter
->second
.blstId
== blst
)
58 return &(iter
->second
);
59 } while (iter
!= records
.begin());
63 void hotspot_t::findRecord (int16_t x
, int16_t y
) {
64 if (records
.empty()) {
69 std::map
<int,hspt_record_t
>::iterator iter
= records
.end();
73 if (iter
->second
.isInside(x
,y
))
74 if ((!iter
->second
.isZip
/* || (iter->second.isZip && game::zipMode ) FIXME*/) &&
75 iter
->second
.isEnabled
) {
76 current
= &(iter
->second
);
79 } while (iter
!= records
.begin());
83 void hotspot_t::readBlst (int id
) {
84 file_t
file (resource_t::BLST
, id
);
86 uint16_t count
= file
.readUShort (0);
87 for (int i
=0; i
<count
; i
++) {
90 temp
.enabled
= (file
.readUShort (2 + i
*6 + 2) == 1);
91 temp
.record
= findRecord (file
.readUShort (2 + i
*6 + 4));
92 blst
.insert (std::make_pair (file
.readUShort (2 + i
*6), temp
));
97 hotspot_t::hotspot_t (int id
) {
100 file_t
file (resource_t::HSPT
, id
);
104 uint16_t count
= file
.readUShort (0);
108 for (int i
=0; i
<count
; i
++) {
109 hspt_record_t
temp (&file
, offset
);
110 records
.insert (std::make_pair (temp
.getIndex(), temp
));
111 offset
+= temp
.getLength();
118 void hotspot_t::mouseMove (int16_t x
, int16_t y
) {
124 current
->script
->run_handler (handler_t::MouseWithin
);
128 void hotspot_t::mouseDown () {
130 current
->script
->run_handler (handler_t::MouseDown
);
133 void hotspot_t::mouseUp () {
135 current
->script
->run_handler (handler_t::MouseUp
);