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_room.h"
24 #include "ags/shared/ac/common.h"
25 #include "ags/engine/ac/character.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_game.h"
33 #include "ags/engine/ac/move_list.h"
34 #include "ags/engine/ac/properties.h"
35 #include "ags/engine/ac/room.h"
36 #include "ags/engine/ac/room_status.h"
37 #include "ags/engine/debugging/debug_log.h"
38 #include "ags/engine/debugging/debugger.h"
39 #include "ags/engine/script/script.h"
40 #include "ags/shared/util/math.h"
41 #include "ags/globals.h"
42
43 namespace AGS3 {
44
45 using namespace Shared;
46
SetAmbientTint(int red,int green,int blue,int opacity,int luminance)47 void SetAmbientTint(int red, int green, int blue, int opacity, int luminance) {
48 if ((red < 0) || (green < 0) || (blue < 0) ||
49 (red > 255) || (green > 255) || (blue > 255) ||
50 (opacity < 0) || (opacity > 100) ||
51 (luminance < 0) || (luminance > 100))
52 quit("!SetTint: invalid parameter. R,G,B must be 0-255, opacity & luminance 0-100");
53
54 debug_script_log("Set _GP(ambient) tint RGB(%d,%d,%d) %d%%", red, green, blue, opacity);
55
56 _GP(play).rtint_enabled = opacity > 0;
57 _GP(play).rtint_red = red;
58 _GP(play).rtint_green = green;
59 _GP(play).rtint_blue = blue;
60 _GP(play).rtint_level = opacity;
61 _GP(play).rtint_light = (luminance * 25) / 10;
62 }
63
SetAmbientLightLevel(int light_level)64 void SetAmbientLightLevel(int light_level) {
65 light_level = Math::Clamp(light_level, -100, 100);
66
67 _GP(play).rtint_enabled = light_level != 0;
68 _GP(play).rtint_level = 0;
69 _GP(play).rtint_light = light_level;
70 }
71
NewRoom(int nrnum)72 void NewRoom(int nrnum) {
73 if (nrnum < 0)
74 quitprintf("!NewRoom: room change requested to invalid room number %d.", nrnum);
75
76 if (_G(displayed_room) < 0) {
77 // called from game_start; change the room where the game will start
78 _G(playerchar)->room = nrnum;
79 return;
80 }
81
82
83 debug_script_log("Room change requested to room %d", nrnum);
84 EndSkippingUntilCharStops();
85
86 can_run_delayed_command();
87
88 if (_GP(play).stop_dialog_at_end != DIALOG_NONE) {
89 if (_GP(play).stop_dialog_at_end == DIALOG_RUNNING)
90 _GP(play).stop_dialog_at_end = DIALOG_NEWROOM + nrnum;
91 else {
92 quitprintf("!NewRoom: two NewRoom/RunDialog/StopDialog requests within dialog; last was called in \"%s\", line %d",
93 _GP(last_in_dialog_request_script_pos).Section.GetCStr(), _GP(last_in_dialog_request_script_pos).Line);
94 }
95 return;
96 }
97
98 get_script_position(_GP(last_in_dialog_request_script_pos));
99
100 if (_G(in_leaves_screen) >= 0) {
101 // NewRoom called from the Player Leaves Screen event -- just
102 // change which room it will go to
103 _G(in_leaves_screen) = nrnum;
104 } else if (_G(in_enters_screen)) {
105 setevent(EV_NEWROOM, nrnum);
106 return;
107 } else if (_G(in_inv_screen)) {
108 _G(inv_screen_newroom) = nrnum;
109 return;
110 } else if ((_G(inside_script) == 0) & (_G(in_graph_script) == 0)) {
111 // Compatibility: old games had a *possibly unintentional* effect:
112 // if a character was walking, and a "change room" is called
113 // *NOT* from a script, but by some other trigger,
114 // they ended up forced to a walkable area in the next room.
115 if (_G(loaded_game_file_version) < kGameVersion_300) {
116 _G(new_room_placeonwalkable) = is_char_walking_ndirect(_G(playerchar));
117 }
118
119 new_room(nrnum, _G(playerchar));
120 return;
121 } else if (_G(inside_script)) {
122 _G(curscript)->queue_action(ePSANewRoom, nrnum, "NewRoom");
123 // we might be within a MoveCharacterBlocking -- the room
124 // change should abort it
125 if (is_char_walking_ndirect(_G(playerchar))) {
126 // nasty hack - make sure it doesn't move the character
127 // to a walkable area
128 _G(mls)[_G(playerchar)->walking].direct = 1;
129 StopMoving(_GP(game).playercharacter);
130 }
131 } else if (_G(in_graph_script))
132 _G(gs_to_newroom) = nrnum;
133 }
134
135
NewRoomEx(int nrnum,int newx,int newy)136 void NewRoomEx(int nrnum, int newx, int newy) {
137 Character_ChangeRoom(_G(playerchar), nrnum, newx, newy);
138 }
139
NewRoomNPC(int charid,int nrnum,int newx,int newy)140 void NewRoomNPC(int charid, int nrnum, int newx, int newy) {
141 if (!is_valid_character(charid))
142 quit("!NewRoomNPC: invalid character");
143 if (charid == _GP(game).playercharacter)
144 quit("!NewRoomNPC: use NewRoomEx with the player character");
145
146 Character_ChangeRoom(&_GP(game).chars[charid], nrnum, newx, newy);
147 }
148
ResetRoom(int nrnum)149 void ResetRoom(int nrnum) {
150 if (nrnum == _G(displayed_room))
151 quit("!ResetRoom: cannot reset current room");
152 if ((nrnum < 0) | (nrnum >= MAX_ROOMS))
153 quit("!ResetRoom: invalid room number");
154
155 if (isRoomStatusValid(nrnum)) {
156 RoomStatus *roomstat = getRoomStatus(nrnum);
157 roomstat->FreeScriptData();
158 roomstat->FreeProperties();
159 roomstat->beenhere = 0;
160 }
161
162 debug_script_log("Room %d reset to original state", nrnum);
163 }
164
HasPlayerBeenInRoom(int roomnum)165 int HasPlayerBeenInRoom(int roomnum) {
166 if ((roomnum < 0) || (roomnum >= MAX_ROOMS))
167 return 0;
168 if (isRoomStatusValid(roomnum))
169 return getRoomStatus(roomnum)->beenhere;
170 else
171 return 0;
172 }
173
CallRoomScript(int value)174 void CallRoomScript(int value) {
175 can_run_delayed_command();
176
177 if (!_G(inside_script))
178 quit("!CallRoomScript: not inside a script???");
179
180 _GP(play).roomscript_finished = 0;
181 RuntimeScriptValue rval_null;
182 _G(curscript)->run_another("on_call", kScInstRoom, 1, RuntimeScriptValue().SetInt32(value), rval_null);
183 }
184
HasBeenToRoom(int roomnum)185 int HasBeenToRoom(int roomnum) {
186 if ((roomnum < 0) || (roomnum >= MAX_ROOMS))
187 quit("!HasBeenToRoom: invalid room number specified");
188
189 if (isRoomStatusValid(roomnum))
190 return getRoomStatus(roomnum)->beenhere;
191 else
192 return 0;
193 }
194
GetRoomPropertyText(const char * property,char * bufer)195 void GetRoomPropertyText(const char *property, char *bufer) {
196 get_text_property(_GP(thisroom).Properties, _G(croom)->roomProps, property, bufer);
197 }
198
SetBackgroundFrame(int frnum)199 void SetBackgroundFrame(int frnum) {
200 if ((frnum < -1) || (frnum != -1 && (size_t)frnum >= _GP(thisroom).BgFrameCount))
201 quit("!SetBackgrondFrame: invalid frame number specified");
202 if (frnum < 0) {
203 _GP(play).bg_frame_locked = 0;
204 return;
205 }
206
207 _GP(play).bg_frame_locked = 1;
208
209 if (frnum == _GP(play).bg_frame) {
210 // already on this frame, do nothing
211 return;
212 }
213
214 _GP(play).bg_frame = frnum;
215 on_background_frame_change();
216 }
217
GetBackgroundFrame()218 int GetBackgroundFrame() {
219 return _GP(play).bg_frame;
220 }
221
222 } // namespace AGS3
223