internal void StartScene(byte room, Actor a = null, int objectNr = 0)
{
StopTalk();
FadeOut(_switchRoomEffect2);
_newEffect = _switchRoomEffect;
if (CurrentScript != 0xFF)
{
if (_slots[CurrentScript].Where == WhereIsObject.Room || _slots[CurrentScript].Where == WhereIsObject.FLObject)
{
//nukeArrays(CurrentScript);
CurrentScript = 0xFF;
}
else if (_slots[CurrentScript].Where == WhereIsObject.Local)
{
//if (slots[CurrentScript].cutsceneOverride && _game.version >= 5)
// error("Script %d stopped with active cutscene/override in exit", slots[CurrentScript].number);
//nukeArrays(CurrentScript);
CurrentScript = 0xFF;
}
}
if (VariableNewRoom.HasValue)
_variables[VariableNewRoom.Value] = room;
RunExitScript();
KillScriptsAndResources();
if (_game.Version >= 4)
{
StopCycle(0);
}
for (var i = 1; i < Actors.Length; i++)
{
Actors[i].Hide();
}
if (Game.Version >= 7)
{
// Set the shadow palette(s) to all black. This fixes
// bug #795940, and actually makes some sense (after all,
// shadows tend to be rather black, don't they? ;-)
Array.Clear(_shadowPalette, 0, _shadowPalette.Length);
}
else
{
for (var i = 0; i < 256; i++)
{
Gdi.RoomPalette[i] = (byte)i;
if (_shadowPalette != null)
_shadowPalette[i] = (byte)i;
}
if (Game.Version < 5)
{
SetDirtyColors(0, 255);
}
}
Variables[VariableRoom.Value] = room;
_fullRedraw = true;
_currentRoom = room;
if (room >= 0x80 && Game.Version < 7)
_roomResource = _resourceMapper[room & 0x7F];
else
_roomResource = room;
if (VariableRoomResource.HasValue)
Variables[VariableRoomResource.Value] = _roomResource;
if (room != 0)
ResourceManager.LoadRoom(room);
if (room != 0 && _game.Version == 5 && room == _roomResource)
Variables[VariableRoomFlag.Value] = 1;
ClearRoomObjects();
if (_currentRoom == 0)
{
if (roomData != null)
{
_ignoreEntryExitScript = true;
roomData.ExitScript.Data = new byte[0];
//roomData.Objects.Clear();
}
return;
}
roomData = _resManager.GetRoom(_roomResource);
_ignoreEntryExitScript = false;
if (roomData.HasPalette)
{
SetCurrentPalette(0);
}
Gdi.NumZBuffer = GetNumZBuffers();
Gdi.TransparentColor = roomData.TransparentColor;
ResetRoomSubBlocks();
ResetRoomObjects();
_drawingObjects.Clear();
if (Game.Version >= 7)
{
// Resize main virtual screen in V7 games. This is necessary
// because in V7, rooms may be higher than one screen, so we have
// to accomodate for that.
_mainVirtScreen = new VirtScreen(MainVirtScreen.TopLine, ScreenWidth, roomData.Header.Height - MainVirtScreen.TopLine, MainVirtScreen.PixelFormat, 2, true);
}
Gdi.SetMaskHeight(roomData.Header.Height);
if (VariableRoomWidth.HasValue && VariableRoomHeight.HasValue)
{
Variables[VariableRoomWidth.Value] = roomData.Header.Width;
Variables[VariableRoomHeight.Value] = roomData.Header.Height;
}
if (VariableCameraMinX.HasValue)
{
_variables[VariableCameraMinX.Value] = ScreenWidth / 2;
}
if (VariableCameraMaxX.HasValue)
{
_variables[VariableCameraMaxX.Value] = roomData.Header.Width - (ScreenWidth / 2);
}
if (Game.Version >= 7)
{
Variables[VariableCameraMinY.Value] = ScreenHeight / 2;
Variables[VariableCameraMaxY.Value] = roomData.Header.Height - (ScreenHeight / 2);
SetCameraAt(new Point((ScreenWidth / 2), (ScreenHeight / 2)));
}
else
{
_camera.Mode = CameraMode.Normal;
_camera.CurrentPosition.X = _camera.DestinationPosition.X = (ScreenWidth / 2);
_camera.CurrentPosition.Y = _camera.DestinationPosition.Y = (ScreenHeight / 2);
}
if (_roomResource == 0)
return;
Gdi.ClearGfxUsageBits();
if (_game.Version >= 5 && a != null)
{
var where = GetWhereIsObject(objectNr);
if (where != WhereIsObject.Room && where != WhereIsObject.FLObject)
throw new NotSupportedException(string.Format("StartScene: Object {0} is not in room {1}", objectNr, _currentRoom));
Point pos;
int dir;
GetObjectXYPos(objectNr, out pos, out dir);
a.PutActor(pos, _currentRoom);
a.SetDirection(dir + 180);
a.StopActorMoving();
if (Game.GameId == Scumm.IO.GameId.SamNMax)
{
Camera.CurrentPosition.X = Camera.DestinationPosition.X = a.Position.X;
SetCameraAt(a.Position);
}
}
ShowActors();
EgoPositioned = false;
TownsResetPalCycleFields();
RunEntryScript();
if (Game.Version >= 1 && Game.Version <= 2)
{
RunScript(5, false, false, new int[0]);
}
else if ((Game.Version >= 5) && (Game.Version <= 6))
{
if (a != null && !EgoPositioned)
{
var pos = GetObjectXYPos(objectNr);
a.PutActor(pos, _currentRoom);
a.Moving = 0;
}
}
else if (_game.Version >= 7)
{
if (Camera.ActorToFollow != 0)
{
a = Actors[Camera.ActorToFollow];
SetCameraAt(a.Position);
}
}
_doEffect = true;
// Hint the backend about the virtual keyboard during copy protection screens
if (_game.GameId == GameId.Monkey2)
{
if (room == 108)
_inputManager.ShowVirtualKeyboard();
else
_inputManager.HideVirtualKeyboard();
}
else if (_game.GameId == GameId.Monkey1 && _game.Variant == "ega")
{ // this is my estimation that the room code is 90 (untested)
if (room == 90)
_inputManager.ShowVirtualKeyboard();
else
_inputManager.HideVirtualKeyboard();
}
}