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 "ags/engine/ac/global_hotspot.h"
24 #include "ags/shared/ac/common.h"
25 #include "ags/shared/ac/common_defines.h"
26 #include "ags/shared/ac/character_info.h"
27 #include "ags/engine/ac/draw.h"
28 #include "ags/engine/ac/event.h"
29 #include "ags/shared/ac/game_setup_struct.h"
30 #include "ags/engine/ac/game_state.h"
31 #include "ags/engine/ac/global_character.h"
32 #include "ags/engine/ac/global_translation.h"
33 #include "ags/engine/ac/hotspot.h"
34 #include "ags/engine/ac/properties.h"
35 #include "ags/engine/ac/room_status.h"
36 #include "ags/engine/ac/string.h"
37 #include "ags/engine/debugging/debug_log.h"
38 #include "ags/shared/game/room_struct.h"
39 #include "ags/engine/script/script.h"
40
41 namespace AGS3 {
42
43 using namespace AGS::Shared;
44
45
46
47
48
49
50
DisableHotspot(int hsnum)51 void DisableHotspot(int hsnum) {
52 if ((hsnum < 1) | (hsnum >= MAX_ROOM_HOTSPOTS))
53 quit("!DisableHotspot: invalid hotspot specified");
54 _G(croom)->hotspot_enabled[hsnum] = 0;
55 debug_script_log("Hotspot %d disabled", hsnum);
56 }
57
EnableHotspot(int hsnum)58 void EnableHotspot(int hsnum) {
59 if ((hsnum < 1) | (hsnum >= MAX_ROOM_HOTSPOTS))
60 quit("!EnableHotspot: invalid hotspot specified");
61 _G(croom)->hotspot_enabled[hsnum] = 1;
62 debug_script_log("Hotspot %d re-enabled", hsnum);
63 }
64
GetHotspotPointX(int hotspot)65 int GetHotspotPointX(int hotspot) {
66 if ((hotspot < 0) || (hotspot >= MAX_ROOM_HOTSPOTS))
67 quit("!GetHotspotPointX: invalid hotspot");
68
69 if (_GP(thisroom).Hotspots[hotspot].WalkTo.X < 1)
70 return -1;
71
72 return _GP(thisroom).Hotspots[hotspot].WalkTo.X;
73 }
74
GetHotspotPointY(int hotspot)75 int GetHotspotPointY(int hotspot) {
76 if ((hotspot < 0) || (hotspot >= MAX_ROOM_HOTSPOTS))
77 quit("!GetHotspotPointY: invalid hotspot");
78
79 if (_GP(thisroom).Hotspots[hotspot].WalkTo.X < 1) // TODO: there was "x" here, why?
80 return -1;
81
82 return _GP(thisroom).Hotspots[hotspot].WalkTo.Y;
83 }
84
GetHotspotIDAtScreen(int scrx,int scry)85 int GetHotspotIDAtScreen(int scrx, int scry) {
86 VpPoint vpt = _GP(play).ScreenToRoomDivDown(scrx, scry);
87 if (vpt.second < 0) return 0;
88 return get_hotspot_at(vpt.first.X, vpt.first.Y);
89 }
90
GetHotspotName(int hotspot,char * buffer)91 void GetHotspotName(int hotspot, char *buffer) {
92 VALIDATE_STRING(buffer);
93 if ((hotspot < 0) || (hotspot >= MAX_ROOM_HOTSPOTS))
94 quit("!GetHotspotName: invalid hotspot number");
95
96 strcpy(buffer, get_translation(_GP(thisroom).Hotspots[hotspot].Name.GetCStr()));
97 }
98
RunHotspotInteraction(int hotspothere,int mood)99 void RunHotspotInteraction(int hotspothere, int mood) {
100
101 int passon = -1, cdata = -1;
102 if (mood == MODE_TALK) passon = 4;
103 else if (mood == MODE_WALK) passon = 0;
104 else if (mood == MODE_LOOK) passon = 1;
105 else if (mood == MODE_HAND) passon = 2;
106 else if (mood == MODE_PICKUP) passon = 7;
107 else if (mood == MODE_CUSTOM1) passon = 8;
108 else if (mood == MODE_CUSTOM2) passon = 9;
109 else if (mood == MODE_USE) {
110 passon = 3;
111 cdata = _G(playerchar)->activeinv;
112 _GP(play).usedinv = cdata;
113 }
114
115 if ((_GP(game).options[OPT_WALKONLOOK] == 0) & (mood == MODE_LOOK));
116 else if (_GP(play).auto_use_walkto_points == 0);
117 else if ((mood != MODE_WALK) && (_GP(play).check_interaction_only == 0))
118 MoveCharacterToHotspot(_GP(game).playercharacter, hotspothere);
119
120 // can't use the setevent functions because this ProcessClick is only
121 // executed once in a eventlist
122 const char *oldbasename = _G(evblockbasename);
123 int oldblocknum = _G(evblocknum);
124
125 _G(evblockbasename) = "hotspot%d";
126 _G(evblocknum) = hotspothere;
127
128 if (_GP(thisroom).Hotspots[hotspothere].EventHandlers != nullptr) {
129 if (passon >= 0)
130 run_interaction_script(_GP(thisroom).Hotspots[hotspothere].EventHandlers.get(), passon, 5, (passon == 3));
131 run_interaction_script(_GP(thisroom).Hotspots[hotspothere].EventHandlers.get(), 5); // any click on hotspot
132 } else {
133 if (passon >= 0) {
134 if (run_interaction_event(&_G(croom)->intrHotspot[hotspothere], passon, 5, (passon == 3))) {
135 _G(evblockbasename) = oldbasename;
136 _G(evblocknum) = oldblocknum;
137 return;
138 }
139 }
140 // run the 'any click on hs' event
141 run_interaction_event(&_G(croom)->intrHotspot[hotspothere], 5);
142 }
143
144 _G(evblockbasename) = oldbasename;
145 _G(evblocknum) = oldblocknum;
146 }
147
GetHotspotProperty(int hss,const char * property)148 int GetHotspotProperty(int hss, const char *property) {
149 return get_int_property(_GP(thisroom).Hotspots[hss].Properties, _G(croom)->hsProps[hss], property);
150 }
151
GetHotspotPropertyText(int item,const char * property,char * bufer)152 void GetHotspotPropertyText(int item, const char *property, char *bufer) {
153 get_text_property(_GP(thisroom).Hotspots[item].Properties, _G(croom)->hsProps[item], property, bufer);
154 }
155
156 } // namespace AGS3
157