redid set handling, again. did other stuff
[riven-wahrk.git] / src / hotspot.cpp
blob1596298d48e969907a0dfbf9cd8f409c6743fac6
2 /*
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/>.
22 #include <iostream>
24 #include "hotspot.h"
25 #include "game.h"
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);
42 isEnabled = true;
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) {
50 if (records.empty())
51 return NULL;
53 std::map<int,hspt_record_t>::iterator iter = records.end();
55 do {
56 iter--;
57 if (iter->second.blstId == blst)
58 return &(iter->second);
59 } while (iter != records.begin());
60 return NULL;
63 void hotspot_t::findRecord (int16_t x, int16_t y) {
64 if (records.empty()) {
65 current = NULL;
66 return;
69 std::map<int,hspt_record_t>::iterator iter = records.end();
71 do {
72 iter--;
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);
77 return;
79 } while (iter != records.begin());
80 current = NULL;
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++) {
89 BlstRecord temp;
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);
102 current = NULL;
104 uint16_t count = file.readUShort (0);
106 int offset = 2;
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();
114 readBlst (id);
118 void hotspot_t::mouseMove (int16_t x, int16_t y) {
120 findRecord (x, y);
121 if (!current)
122 return;
124 current->script->run_handler (handler_t::MouseWithin);
128 void hotspot_t::mouseDown () {
129 if (current)
130 current->script->run_handler (handler_t::MouseDown);
133 void hotspot_t::mouseUp () {
134 if (current)
135 current->script->run_handler (handler_t::MouseUp);