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/dynobj/cc_hotspot.h"
24 #include "ags/engine/ac/hotspot.h"
25 #include "ags/engine/ac/game_state.h"
26 #include "ags/engine/ac/global_hotspot.h"
27 #include "ags/engine/ac/global_translation.h"
28 #include "ags/engine/ac/properties.h"
29 #include "ags/engine/ac/room.h"
30 #include "ags/engine/ac/room_status.h"
31 #include "ags/engine/ac/string.h"
32 #include "ags/shared/game/room_struct.h"
33 #include "ags/shared/gfx/bitmap.h"
34 #include "ags/engine/script/runtime_script_value.h"
35 #include "ags/shared/debugging/out.h"
36 #include "ags/engine/script/script_api.h"
37 #include "ags/engine/script/script_runtime.h"
38 #include "ags/engine/ac/dynobj/script_string.h"
39 #include "ags/globals.h"
40 
41 namespace AGS3 {
42 
43 using namespace AGS::Shared;
44 
45 
46 
47 
48 
49 
Hotspot_SetEnabled(ScriptHotspot * hss,int newval)50 void Hotspot_SetEnabled(ScriptHotspot *hss, int newval) {
51 	if (newval)
52 		EnableHotspot(hss->id);
53 	else
54 		DisableHotspot(hss->id);
55 }
56 
Hotspot_GetEnabled(ScriptHotspot * hss)57 int Hotspot_GetEnabled(ScriptHotspot *hss) {
58 	return _G(croom)->hotspot_enabled[hss->id];
59 }
60 
Hotspot_GetID(ScriptHotspot * hss)61 int Hotspot_GetID(ScriptHotspot *hss) {
62 	return hss->id;
63 }
64 
Hotspot_GetWalkToX(ScriptHotspot * hss)65 int Hotspot_GetWalkToX(ScriptHotspot *hss) {
66 	return GetHotspotPointX(hss->id);
67 }
68 
Hotspot_GetWalkToY(ScriptHotspot * hss)69 int Hotspot_GetWalkToY(ScriptHotspot *hss) {
70 	return GetHotspotPointY(hss->id);
71 }
72 
GetHotspotAtScreen(int xx,int yy)73 ScriptHotspot *GetHotspotAtScreen(int xx, int yy) {
74 	return &_G(scrHotspot)[GetHotspotIDAtScreen(xx, yy)];
75 }
76 
GetHotspotAtRoom(int x,int y)77 ScriptHotspot *GetHotspotAtRoom(int x, int y) {
78 	return &_G(scrHotspot)[get_hotspot_at(x, y)];
79 }
80 
Hotspot_GetName(ScriptHotspot * hss,char * buffer)81 void Hotspot_GetName(ScriptHotspot *hss, char *buffer) {
82 	GetHotspotName(hss->id, buffer);
83 }
84 
Hotspot_GetName_New(ScriptHotspot * hss)85 const char *Hotspot_GetName_New(ScriptHotspot *hss) {
86 	return CreateNewScriptString(get_translation(_GP(thisroom).Hotspots[hss->id].Name.GetCStr()));
87 }
88 
Hotspot_IsInteractionAvailable(ScriptHotspot * hhot,int mood)89 bool Hotspot_IsInteractionAvailable(ScriptHotspot *hhot, int mood) {
90 
91 	_GP(play).check_interaction_only = 1;
92 	RunHotspotInteraction(hhot->id, mood);
93 	int ciwas = _GP(play).check_interaction_only;
94 	_GP(play).check_interaction_only = 0;
95 	return (ciwas == 2);
96 }
97 
Hotspot_RunInteraction(ScriptHotspot * hss,int mood)98 void Hotspot_RunInteraction(ScriptHotspot *hss, int mood) {
99 	RunHotspotInteraction(hss->id, mood);
100 }
101 
Hotspot_GetProperty(ScriptHotspot * hss,const char * property)102 int Hotspot_GetProperty(ScriptHotspot *hss, const char *property) {
103 	return get_int_property(_GP(thisroom).Hotspots[hss->id].Properties, _G(croom)->hsProps[hss->id], property);
104 }
105 
Hotspot_GetPropertyText(ScriptHotspot * hss,const char * property,char * bufer)106 void Hotspot_GetPropertyText(ScriptHotspot *hss, const char *property, char *bufer) {
107 	get_text_property(_GP(thisroom).Hotspots[hss->id].Properties, _G(croom)->hsProps[hss->id], property, bufer);
108 
109 }
110 
Hotspot_GetTextProperty(ScriptHotspot * hss,const char * property)111 const char *Hotspot_GetTextProperty(ScriptHotspot *hss, const char *property) {
112 	return get_text_property_dynamic_string(_GP(thisroom).Hotspots[hss->id].Properties, _G(croom)->hsProps[hss->id], property);
113 }
114 
Hotspot_SetProperty(ScriptHotspot * hss,const char * property,int value)115 bool Hotspot_SetProperty(ScriptHotspot *hss, const char *property, int value) {
116 	return set_int_property(_G(croom)->hsProps[hss->id], property, value);
117 }
118 
Hotspot_SetTextProperty(ScriptHotspot * hss,const char * property,const char * value)119 bool Hotspot_SetTextProperty(ScriptHotspot *hss, const char *property, const char *value) {
120 	return set_text_property(_G(croom)->hsProps[hss->id], property, value);
121 }
122 
get_hotspot_at(int xpp,int ypp)123 int get_hotspot_at(int xpp, int ypp) {
124 	int onhs = _GP(thisroom).HotspotMask->GetPixel(room_to_mask_coord(xpp), room_to_mask_coord(ypp));
125 	if (onhs <= 0 || onhs >= MAX_ROOM_HOTSPOTS) return 0;
126 	if (_G(croom)->hotspot_enabled[onhs] == 0) return 0;
127 	return onhs;
128 }
129 
130 //=============================================================================
131 //
132 // Script API Functions
133 //
134 //=============================================================================
135 
Sc_GetHotspotAtRoom(const RuntimeScriptValue * params,int32_t param_count)136 RuntimeScriptValue Sc_GetHotspotAtRoom(const RuntimeScriptValue *params, int32_t param_count) {
137 	API_SCALL_OBJ_PINT2(ScriptHotspot, _GP(ccDynamicHotspot), GetHotspotAtRoom);
138 }
139 
140 // ScriptHotspot *(int xx, int yy)
Sc_GetHotspotAtScreen(const RuntimeScriptValue * params,int32_t param_count)141 RuntimeScriptValue Sc_GetHotspotAtScreen(const RuntimeScriptValue *params, int32_t param_count) {
142 	API_SCALL_OBJ_PINT2(ScriptHotspot, _GP(ccDynamicHotspot), GetHotspotAtScreen);
143 }
144 
Sc_Hotspot_GetDrawingSurface(const RuntimeScriptValue * params,int32_t param_count)145 RuntimeScriptValue Sc_Hotspot_GetDrawingSurface(const RuntimeScriptValue *params, int32_t param_count) {
146 	ScriptDrawingSurface *ret_obj = Room_GetDrawingSurfaceForMask(kRoomAreaHotspot);
147 	return RuntimeScriptValue().SetDynamicObject(ret_obj, ret_obj);
148 }
149 
150 // void (ScriptHotspot *hss, char *buffer)
Sc_Hotspot_GetName(void * self,const RuntimeScriptValue * params,int32_t param_count)151 RuntimeScriptValue Sc_Hotspot_GetName(void *self, const RuntimeScriptValue *params, int32_t param_count) {
152 	API_OBJCALL_VOID_POBJ(ScriptHotspot, Hotspot_GetName, char);
153 }
154 
155 // int  (ScriptHotspot *hss, const char *property)
Sc_Hotspot_GetProperty(void * self,const RuntimeScriptValue * params,int32_t param_count)156 RuntimeScriptValue Sc_Hotspot_GetProperty(void *self, const RuntimeScriptValue *params, int32_t param_count) {
157 	API_OBJCALL_INT_POBJ(ScriptHotspot, Hotspot_GetProperty, const char);
158 }
159 
160 // void  (ScriptHotspot *hss, const char *property, char *bufer)
Sc_Hotspot_GetPropertyText(void * self,const RuntimeScriptValue * params,int32_t param_count)161 RuntimeScriptValue Sc_Hotspot_GetPropertyText(void *self, const RuntimeScriptValue *params, int32_t param_count) {
162 	API_OBJCALL_VOID_POBJ2(ScriptHotspot, Hotspot_GetPropertyText, const char, char);
163 }
164 
165 // const char* (ScriptHotspot *hss, const char *property)
Sc_Hotspot_GetTextProperty(void * self,const RuntimeScriptValue * params,int32_t param_count)166 RuntimeScriptValue Sc_Hotspot_GetTextProperty(void *self, const RuntimeScriptValue *params, int32_t param_count) {
167 	API_CONST_OBJCALL_OBJ_POBJ(ScriptHotspot, const char, _GP(myScriptStringImpl), Hotspot_GetTextProperty, const char);
168 }
169 
Sc_Hotspot_SetProperty(void * self,const RuntimeScriptValue * params,int32_t param_count)170 RuntimeScriptValue Sc_Hotspot_SetProperty(void *self, const RuntimeScriptValue *params, int32_t param_count) {
171 	API_OBJCALL_BOOL_POBJ_PINT(ScriptHotspot, Hotspot_SetProperty, const char);
172 }
173 
Sc_Hotspot_SetTextProperty(void * self,const RuntimeScriptValue * params,int32_t param_count)174 RuntimeScriptValue Sc_Hotspot_SetTextProperty(void *self, const RuntimeScriptValue *params, int32_t param_count) {
175 	API_OBJCALL_BOOL_POBJ2(ScriptHotspot, Hotspot_SetTextProperty, const char, const char);
176 }
177 
Sc_Hotspot_IsInteractionAvailable(void * self,const RuntimeScriptValue * params,int32_t param_count)178 RuntimeScriptValue Sc_Hotspot_IsInteractionAvailable(void *self, const RuntimeScriptValue *params, int32_t param_count) {
179 	API_OBJCALL_BOOL_PINT(ScriptHotspot, Hotspot_IsInteractionAvailable);
180 }
181 
182 // void  (ScriptHotspot *hss, int mood)
Sc_Hotspot_RunInteraction(void * self,const RuntimeScriptValue * params,int32_t param_count)183 RuntimeScriptValue Sc_Hotspot_RunInteraction(void *self, const RuntimeScriptValue *params, int32_t param_count) {
184 	API_OBJCALL_VOID_PINT(ScriptHotspot, Hotspot_RunInteraction);
185 }
186 
187 // int (ScriptHotspot *hss)
Sc_Hotspot_GetEnabled(void * self,const RuntimeScriptValue * params,int32_t param_count)188 RuntimeScriptValue Sc_Hotspot_GetEnabled(void *self, const RuntimeScriptValue *params, int32_t param_count) {
189 	API_OBJCALL_INT(ScriptHotspot, Hotspot_GetEnabled);
190 }
191 
192 // void (ScriptHotspot *hss, int newval)
Sc_Hotspot_SetEnabled(void * self,const RuntimeScriptValue * params,int32_t param_count)193 RuntimeScriptValue Sc_Hotspot_SetEnabled(void *self, const RuntimeScriptValue *params, int32_t param_count) {
194 	API_OBJCALL_VOID_PINT(ScriptHotspot, Hotspot_SetEnabled);
195 }
196 
197 // int (ScriptHotspot *hss)
Sc_Hotspot_GetID(void * self,const RuntimeScriptValue * params,int32_t param_count)198 RuntimeScriptValue Sc_Hotspot_GetID(void *self, const RuntimeScriptValue *params, int32_t param_count) {
199 	API_OBJCALL_INT(ScriptHotspot, Hotspot_GetID);
200 }
201 
202 // const char* (ScriptHotspot *hss)
Sc_Hotspot_GetName_New(void * self,const RuntimeScriptValue * params,int32_t param_count)203 RuntimeScriptValue Sc_Hotspot_GetName_New(void *self, const RuntimeScriptValue *params, int32_t param_count) {
204 	API_CONST_OBJCALL_OBJ(ScriptHotspot, const char, _GP(myScriptStringImpl), Hotspot_GetName_New);
205 }
206 
207 // int (ScriptHotspot *hss)
Sc_Hotspot_GetWalkToX(void * self,const RuntimeScriptValue * params,int32_t param_count)208 RuntimeScriptValue Sc_Hotspot_GetWalkToX(void *self, const RuntimeScriptValue *params, int32_t param_count) {
209 	API_OBJCALL_INT(ScriptHotspot, Hotspot_GetWalkToX);
210 }
211 
212 // int (ScriptHotspot *hss)
Sc_Hotspot_GetWalkToY(void * self,const RuntimeScriptValue * params,int32_t param_count)213 RuntimeScriptValue Sc_Hotspot_GetWalkToY(void *self, const RuntimeScriptValue *params, int32_t param_count) {
214 	API_OBJCALL_INT(ScriptHotspot, Hotspot_GetWalkToY);
215 }
216 
217 
218 
RegisterHotspotAPI()219 void RegisterHotspotAPI() {
220 	ccAddExternalStaticFunction("Hotspot::GetAtRoomXY^2", Sc_GetHotspotAtRoom);
221 	ccAddExternalStaticFunction("Hotspot::GetAtScreenXY^2", Sc_GetHotspotAtScreen);
222 	ccAddExternalStaticFunction("Hotspot::GetDrawingSurface", Sc_Hotspot_GetDrawingSurface);
223 	ccAddExternalObjectFunction("Hotspot::GetName^1", Sc_Hotspot_GetName);
224 	ccAddExternalObjectFunction("Hotspot::GetProperty^1", Sc_Hotspot_GetProperty);
225 	ccAddExternalObjectFunction("Hotspot::GetPropertyText^2", Sc_Hotspot_GetPropertyText);
226 	ccAddExternalObjectFunction("Hotspot::GetTextProperty^1", Sc_Hotspot_GetTextProperty);
227 	ccAddExternalObjectFunction("Hotspot::SetProperty^2", Sc_Hotspot_SetProperty);
228 	ccAddExternalObjectFunction("Hotspot::SetTextProperty^2", Sc_Hotspot_SetTextProperty);
229 	ccAddExternalObjectFunction("Hotspot::IsInteractionAvailable^1", Sc_Hotspot_IsInteractionAvailable);
230 	ccAddExternalObjectFunction("Hotspot::RunInteraction^1", Sc_Hotspot_RunInteraction);
231 	ccAddExternalObjectFunction("Hotspot::get_Enabled", Sc_Hotspot_GetEnabled);
232 	ccAddExternalObjectFunction("Hotspot::set_Enabled", Sc_Hotspot_SetEnabled);
233 	ccAddExternalObjectFunction("Hotspot::get_ID", Sc_Hotspot_GetID);
234 	ccAddExternalObjectFunction("Hotspot::get_Name", Sc_Hotspot_GetName_New);
235 	ccAddExternalObjectFunction("Hotspot::get_WalkToX", Sc_Hotspot_GetWalkToX);
236 	ccAddExternalObjectFunction("Hotspot::get_WalkToY", Sc_Hotspot_GetWalkToY);
237 }
238 
239 } // namespace AGS3
240