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 150 151 152 153 154 155 156 157 158 159
|
/* 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_region.h"
#include "ags/shared/ac/common.h"
#include "ags/shared/ac/game_version.h"
#include "ags/engine/ac/game_state.h"
#include "ags/engine/ac/region.h"
#include "ags/engine/ac/room.h"
#include "ags/engine/ac/room_status.h"
#include "ags/engine/ac/dynobj/cc_region.h"
#include "ags/engine/debugging/debug_log.h"
#include "ags/shared/game/room_struct.h"
#include "ags/shared/gfx/bitmap.h"
#include "ags/engine/script/script.h"
#include "ags/globals.h"
namespace AGS3 {
using namespace AGS::Shared;
int GetRegionIDAtRoom(int xxx, int yyy) {
// if the co-ordinates are off the edge of the screen,
// correct them to be just within
// this fixes walk-off-screen problems
xxx = room_to_mask_coord(xxx);
yyy = room_to_mask_coord(yyy);
if (_G(loaded_game_file_version) >= kGameVersion_262) { // Version 2.6.2+
if (xxx >= _GP(thisroom).RegionMask->GetWidth())
xxx = _GP(thisroom).RegionMask->GetWidth() - 1;
if (yyy >= _GP(thisroom).RegionMask->GetHeight())
yyy = _GP(thisroom).RegionMask->GetHeight() - 1;
if (xxx < 0)
xxx = 0;
if (yyy < 0)
yyy = 0;
}
int hsthere = _GP(thisroom).RegionMask->GetPixel(xxx, yyy);
if (hsthere <= 0 || hsthere >= MAX_ROOM_REGIONS) return 0;
if (_G(croom)->region_enabled[hsthere] == 0) return 0;
return hsthere;
}
void SetAreaLightLevel(int area, int brightness) {
if ((area < 0) || (area > MAX_ROOM_REGIONS))
quit("!SetAreaLightLevel: invalid region");
if (brightness < -100) brightness = -100;
if (brightness > 100) brightness = 100;
_GP(thisroom).Regions[area].Light = brightness;
// disable RGB tint for this area
_GP(thisroom).Regions[area].Tint = 0;
debug_script_log("Region %d light level set to %d", area, brightness);
}
void SetRegionTint(int area, int red, int green, int blue, int amount, int luminance) {
if ((area < 0) || (area > MAX_ROOM_REGIONS))
quit("!SetRegionTint: invalid region");
if ((red < 0) || (red > 255) || (green < 0) || (green > 255) ||
(blue < 0) || (blue > 255)) {
quit("!SetRegionTint: RGB values must be 0-255");
}
// originally the value was passed as 0
// TODO: find out which versions had this; fixup only for past versions in the future!
if (amount == 0)
amount = 100;
if ((amount < 1) || (amount > 100))
quit("!SetRegionTint: amount must be 1-100");
if ((luminance < 0) || (luminance > 100))
quit("!SetRegionTint: luminance must be 0-100");
debug_script_log("Region %d tint set to %d,%d,%d", area, red, green, blue);
/*red -= 100;
green -= 100;
blue -= 100;*/
_GP(thisroom).Regions[area].Tint = (red & 0xFF) |
((green & 0xFF) << 8) |
((blue & 0XFF) << 16) |
((amount & 0xFF) << 24);
_GP(thisroom).Regions[area].Light = (luminance * 25) / 10;
}
void DisableRegion(int hsnum) {
if ((hsnum < 0) || (hsnum >= MAX_ROOM_REGIONS))
quit("!DisableRegion: invalid region specified");
_G(croom)->region_enabled[hsnum] = 0;
debug_script_log("Region %d disabled", hsnum);
}
void EnableRegion(int hsnum) {
if ((hsnum < 0) || (hsnum >= MAX_ROOM_REGIONS))
quit("!EnableRegion: invalid region specified");
_G(croom)->region_enabled[hsnum] = 1;
debug_script_log("Region %d enabled", hsnum);
}
void DisableGroundLevelAreas(int alsoEffects) {
if ((alsoEffects < 0) || (alsoEffects > 1))
quit("!DisableGroundLevelAreas: invalid parameter: must be 0 or 1");
_GP(play).ground_level_areas_disabled = GLED_INTERACTION;
if (alsoEffects)
_GP(play).ground_level_areas_disabled |= GLED_EFFECTS;
debug_script_log("Ground-level areas disabled");
}
void EnableGroundLevelAreas() {
_GP(play).ground_level_areas_disabled = 0;
debug_script_log("Ground-level areas re-enabled");
}
void RunRegionInteraction(int regnum, int mood) {
if ((regnum < 0) || (regnum >= MAX_ROOM_REGIONS))
quit("!RunRegionInteraction: invalid region speicfied");
if ((mood < 0) || (mood > 2))
quit("!RunRegionInteraction: invalid event specified");
// NOTE: for Regions the mode has specific meanings (NOT verbs):
// 0 - stands on region, 1 - walks onto region, 2 - walks off region
const auto obj_evt = ObjectEvent("region%d", regnum,
RuntimeScriptValue().SetScriptObject(&_G(scrRegion)[regnum], &_GP(ccDynamicRegion)), mood);
if (_G(loaded_game_file_version) > kGameVersion_272) {
run_interaction_script(obj_evt, _GP(thisroom).Regions[regnum].EventHandlers.get(), mood);
} else {
run_interaction_event(obj_evt, &_G(croom)->intrRegion[regnum], mood);
}
}
} // namespace AGS3
|