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_walkable_area.h"
24 #include "ags/shared/ac/common.h"
25 #include "ags/shared/ac/common_defines.h"
26 #include "ags/engine/ac/draw.h"
27 #include "ags/engine/ac/game_state.h"
28 #include "ags/engine/ac/walkable_area.h"
29 #include "ags/engine/debugging/debug_log.h"
30 #include "ags/shared/game/room_struct.h"
31 #include "ags/globals.h"
32 
33 namespace AGS3 {
34 
35 using namespace AGS::Shared;
36 
GetScalingAt(int x,int y)37 int GetScalingAt(int x, int y) {
38 	int onarea = get_walkable_area_pixel(x, y);
39 	if (onarea < 0)
40 		return 100;
41 
42 	return get_area_scaling(onarea, x, y);
43 }
44 
SetAreaScaling(int area,int min,int max)45 void SetAreaScaling(int area, int min, int max) {
46 	if ((area < 0) || (area > MAX_WALK_AREAS))
47 		quit("!SetAreaScaling: invalid walkalbe area");
48 
49 	if (min > max)
50 		quit("!SetAreaScaling: min > max");
51 
52 	if ((min < 5) || (max < 5) || (min > 200) || (max > 200))
53 		quit("!SetAreaScaling: min and max must be in range 5-200");
54 
55 	// the values are stored differently
56 	min -= 100;
57 	max -= 100;
58 
59 	if (min == max) {
60 		_GP(thisroom).WalkAreas[area].ScalingFar = min;
61 		_GP(thisroom).WalkAreas[area].ScalingNear = NOT_VECTOR_SCALED;
62 	} else {
63 		_GP(thisroom).WalkAreas[area].ScalingFar = min;
64 		_GP(thisroom).WalkAreas[area].ScalingNear = max;
65 	}
66 }
67 
RemoveWalkableArea(int areanum)68 void RemoveWalkableArea(int areanum) {
69 	if ((areanum < 1) | (areanum > 15))
70 		quit("!RemoveWalkableArea: invalid area number specified (1-15).");
71 	_GP(play).walkable_areas_on[areanum] = 0;
72 	redo_walkable_areas();
73 	debug_script_log("Walkable area %d removed", areanum);
74 }
75 
RestoreWalkableArea(int areanum)76 void RestoreWalkableArea(int areanum) {
77 	if ((areanum < 1) | (areanum > 15))
78 		quit("!RestoreWalkableArea: invalid area number specified (1-15).");
79 	_GP(play).walkable_areas_on[areanum] = 1;
80 	redo_walkable_areas();
81 	debug_script_log("Walkable area %d restored", areanum);
82 }
83 
GetWalkableAreaAtScreen(int x,int y)84 int GetWalkableAreaAtScreen(int x, int y) {
85 	VpPoint vpt = _GP(play).ScreenToRoomDivDown(x, y);
86 	if (vpt.second < 0)
87 		return 0;
88 	return GetWalkableAreaAtRoom(vpt.first.X, vpt.first.Y);
89 }
90 
GetWalkableAreaAtRoom(int x,int y)91 int GetWalkableAreaAtRoom(int x, int y) {
92 	int area = get_walkable_area_pixel(x, y);
93 	// IMPORTANT: disabled walkable areas are actually erased completely from the mask;
94 	// see: RemoveWalkableArea() and RestoreWalkableArea().
95 	return area >= 0 && area < (MAX_WALK_AREAS + 1) ? area : 0;
96 }
97 
98 } // namespace AGS3
99