File: global_hotspot.cpp

package info (click to toggle)
scummvm 2.7.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 363,784 kB
  • sloc: cpp: 3,622,060; asm: 27,410; python: 10,528; sh: 10,241; xml: 6,752; java: 5,579; perl: 2,570; yacc: 1,635; javascript: 1,016; lex: 539; makefile: 398; ansic: 378; awk: 275; objc: 82; sed: 11; php: 1
file content (149 lines) | stat: -rw-r--r-- 5,138 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "ags/engine/ac/global_hotspot.h"
#include "ags/shared/ac/common.h"
#include "ags/shared/ac/common_defines.h"
#include "ags/shared/ac/character_info.h"
#include "ags/engine/ac/draw.h"
#include "ags/engine/ac/event.h"
#include "ags/shared/ac/game_setup_struct.h"
#include "ags/engine/ac/game_state.h"
#include "ags/engine/ac/global_character.h"
#include "ags/engine/ac/global_translation.h"
#include "ags/engine/ac/hotspot.h"
#include "ags/engine/ac/properties.h"
#include "ags/engine/ac/room_status.h"
#include "ags/engine/ac/string.h"
#include "ags/engine/debugging/debug_log.h"
#include "ags/shared/game/room_struct.h"
#include "ags/engine/script/script.h"

namespace AGS3 {

using namespace AGS::Shared;

void DisableHotspot(int hsnum) {
	if ((hsnum < 1) | (hsnum >= MAX_ROOM_HOTSPOTS))
		quit("!DisableHotspot: invalid hotspot specified");
	_G(croom)->hotspot[hsnum].Enabled = false;
	debug_script_log("Hotspot %d disabled", hsnum);
}

void EnableHotspot(int hsnum) {
	if ((hsnum < 1) | (hsnum >= MAX_ROOM_HOTSPOTS))
		quit("!EnableHotspot: invalid hotspot specified");
	_G(croom)->hotspot[hsnum].Enabled = true;
	debug_script_log("Hotspot %d re-enabled", hsnum);
}

int GetHotspotPointX(int hotspot) {
	if ((hotspot < 0) || (hotspot >= MAX_ROOM_HOTSPOTS))
		quit("!GetHotspotPointX: invalid hotspot");

	if (_GP(thisroom).Hotspots[hotspot].WalkTo.X < 1)
		return -1;

	return _GP(thisroom).Hotspots[hotspot].WalkTo.X;
}

int GetHotspotPointY(int hotspot) {
	if ((hotspot < 0) || (hotspot >= MAX_ROOM_HOTSPOTS))
		quit("!GetHotspotPointY: invalid hotspot");

	if (_GP(thisroom).Hotspots[hotspot].WalkTo.X < 1) // TODO: there was "x" here, why?
		return -1;

	return _GP(thisroom).Hotspots[hotspot].WalkTo.Y;
}

int GetHotspotIDAtScreen(int scrx, int scry) {
	VpPoint vpt = _GP(play).ScreenToRoomDivDown(scrx, scry);
	if (vpt.second < 0) return 0;
	return get_hotspot_at(vpt.first.X, vpt.first.Y);
}

void GetHotspotName(int hotspot, char *buffer) {
	VALIDATE_STRING(buffer);
	if ((hotspot < 0) || (hotspot >= MAX_ROOM_HOTSPOTS))
		quit("!GetHotspotName: invalid hotspot number");

	snprintf(buffer, MAX_MAXSTRLEN, "%s", get_translation(_G(croom)->hotspot[hotspot].Name.GetCStr()));
}

void RunHotspotInteraction(int hotspothere, int mood) {

	int passon = -1, cdata = -1;
	if (mood == MODE_TALK) passon = 4;
	else if (mood == MODE_WALK) passon = 0;
	else if (mood == MODE_LOOK) passon = 1;
	else if (mood == MODE_HAND) passon = 2;
	else if (mood == MODE_PICKUP) passon = 7;
	else if (mood == MODE_CUSTOM1) passon = 8;
	else if (mood == MODE_CUSTOM2) passon = 9;
	else if (mood == MODE_USE) {
		passon = 3;
		cdata = _G(playerchar)->activeinv;
		_GP(play).usedinv = cdata;
	}

	if ((_GP(game).options[OPT_WALKONLOOK] == 0) & (mood == MODE_LOOK));
	else if (_GP(play).auto_use_walkto_points == 0);
	else if ((mood != MODE_WALK) && (_GP(play).check_interaction_only == 0))
		MoveCharacterToHotspot(_GP(game).playercharacter, hotspothere);

	// can't use the setevent functions because this ProcessClick is only
	// executed once in a eventlist
	const char *oldbasename = _G(evblockbasename);
	int   oldblocknum = _G(evblocknum);

	_G(evblockbasename) = "hotspot%d";
	_G(evblocknum) = hotspothere;

	if (_GP(thisroom).Hotspots[hotspothere].EventHandlers != nullptr) {
		if (passon >= 0)
			run_interaction_script(_GP(thisroom).Hotspots[hotspothere].EventHandlers.get(), passon, 5);
		run_interaction_script(_GP(thisroom).Hotspots[hotspothere].EventHandlers.get(), 5);  // any click on hotspot
	} else {
		if (passon >= 0) {
			if (run_interaction_event(&_G(croom)->intrHotspot[hotspothere], passon, 5, (passon == 3))) {
				_G(evblockbasename) = oldbasename;
				_G(evblocknum) = oldblocknum;
				return;
			}
		}
		// run the 'any click on hs' event
		run_interaction_event(&_G(croom)->intrHotspot[hotspothere], 5);
	}

	_G(evblockbasename) = oldbasename;
	_G(evblocknum) = oldblocknum;
}

int GetHotspotProperty(int hss, const char *property) {
	return get_int_property(_GP(thisroom).Hotspots[hss].Properties, _G(croom)->hsProps[hss], property);
}

void GetHotspotPropertyText(int item, const char *property, char *bufer) {
	get_text_property(_GP(thisroom).Hotspots[item].Properties, _G(croom)->hsProps[item], property, bufer);
}

} // namespace AGS3