Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
/* 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 "titanic/core/background.h"
namespace Titanic {
BEGIN_MESSAGE_MAP(CBackground, CGameObject)
ON_MESSAGE(StatusChangeMsg)
ON_MESSAGE(SetFrameMsg)
ON_MESSAGE(VisibleMsg)
END_MESSAGE_MAP()
CBackground::CBackground() : CGameObject(), _startFrame(0), _endFrame(0), _isBlocking(false) {
}
void CBackground::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
file->writeNumberLine(_startFrame, indent);
file->writeNumberLine(_endFrame, indent);
file->writeQuotedLine(_string1, indent);
file->writeQuotedLine(_string2, indent);
file->writeNumberLine(_isBlocking, indent);
CGameObject::save(file, indent);
}
void CBackground::load(SimpleFile *file) {
file->readNumber();
_startFrame = file->readNumber();
_endFrame = file->readNumber();
_string1 = file->readString();
_string2 = file->readString();
_isBlocking = file->readNumber();
CGameObject::load(file);
}
bool CBackground::StatusChangeMsg(CStatusChangeMsg *msg) {
setVisible(true);
if (_isBlocking) {
playMovie(_startFrame, _endFrame, MOVIE_WAIT_FOR_FINISH);
} else {
playMovie(_startFrame, _endFrame, 0);
}
return true;
}
bool CBackground::SetFrameMsg(CSetFrameMsg *msg) {
loadFrame(msg->_frameNumber);
return true;
}
bool CBackground::VisibleMsg(CVisibleMsg *msg) {
setVisible(!_visible);
return true;
}
} // End of namespace Titanic

View File

@@ -0,0 +1,58 @@
/* 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/>.
*
*/
#ifndef TITANIC_BACKGROUND_H
#define TITANIC_BACKGROUND_H
#include "titanic/core/game_object.h"
#include "titanic/messages/messages.h"
namespace Titanic {
class CBackground : public CGameObject {
DECLARE_MESSAGE_MAP;
bool StatusChangeMsg(CStatusChangeMsg *msg);
bool SetFrameMsg(CSetFrameMsg *msg);
bool VisibleMsg(CVisibleMsg *msg);
protected:
int _startFrame;
int _endFrame;
CString _string1;
CString _string2;
bool _isBlocking;
public:
CLASSDEF;
CBackground();
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
};
} // End of namespace Titanic
#endif /* TITANIC_BACKGROUND_H */

View File

@@ -0,0 +1,55 @@
/* 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 "titanic/core/click_responder.h"
namespace Titanic {
BEGIN_MESSAGE_MAP(CClickResponder, CGameObject)
ON_MESSAGE(MouseButtonDownMsg)
END_MESSAGE_MAP()
void CClickResponder::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
file->writeQuotedLine(_message, indent);
file->writeQuotedLine(_soundName, indent);
CGameObject::save(file, indent);
}
void CClickResponder::load(SimpleFile *file) {
file->readNumber();
_message = file->readString();
_soundName = file->readString();
CGameObject::load(file);
}
bool CClickResponder::MouseButtonDownMsg(CMouseButtonDownMsg *msg) {
if (!_soundName.empty())
playSound(_soundName);
if (!_message.empty())
petDisplayMessage(_message);
return true;
}
} // End of namespace Titanic

View File

@@ -0,0 +1,50 @@
/* 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/>.
*
*/
#ifndef TITANIC_CLICK_RESPONDER_H
#define TITANIC_CLICK_RESPONDER_H
#include "titanic/core/game_object.h"
namespace Titanic {
class CClickResponder : public CGameObject {
DECLARE_MESSAGE_MAP;
bool MouseButtonDownMsg(CMouseButtonDownMsg *msg);
protected:
CString _message, _soundName;
public:
CLASSDEF;
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
};
} // End of namespace Titanic
#endif /* TITANIC_CLICK_RESPONDER_H */

View File

@@ -0,0 +1,36 @@
/* 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 "titanic/core/dont_save_file_item.h"
namespace Titanic {
EMPTY_MESSAGE_MAP(CDontSaveFileItem, CFileItem);
void CDontSaveFileItem::save(SimpleFile *file, int indent) {
file->writeNumberLine(0, indent);
}
void CDontSaveFileItem::load(SimpleFile *file) {
file->readNumber();
}
} // End of namespace Titanic

View File

@@ -0,0 +1,52 @@
/* 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/>.
*
*/
#ifndef TITANIC_DONT_SAVE_FILE_ITEM_H
#define TITANIC_DONT_SAVE_FILE_ITEM_H
#include "titanic/core/file_item.h"
namespace Titanic {
class CDontSaveFileItem : public CFileItem {
DECLARE_MESSAGE_MAP;
public:
CLASSDEF;
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
/**
* Returns true if the item is a file item
*/
bool isFileItem() const override { return false; }
};
} // End of namespace Titanic
#endif /* TITANIC_DONT_SAVE_FILE_ITEM_H */

View File

@@ -0,0 +1,191 @@
/* 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 "titanic/core/drop_target.h"
#include "titanic/carry/carry.h"
namespace Titanic {
BEGIN_MESSAGE_MAP(CDropTarget, CGameObject)
ON_MESSAGE(DropObjectMsg)
ON_MESSAGE(MouseDragStartMsg)
ON_MESSAGE(EnterViewMsg)
ON_MESSAGE(VisibleMsg)
ON_MESSAGE(DropZoneLostObjectMsg)
END_MESSAGE_MAP()
CDropTarget::CDropTarget() : CGameObject(), _itemFrame(0),
_itemMatchStartsWith(false), _hideItem(false), _dropEnabled(false), _dropFrame(0),
_dragFrame(0), _dragCursorId(CURSOR_ARROW), _dropCursorId(CURSOR_HAND),
_clipFlags(20) {
}
void CDropTarget::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
file->writePoint(_pos1, indent);
file->writeNumberLine(_itemFrame, indent);
file->writeQuotedLine(_itemMatchName, indent);
file->writeNumberLine(_itemMatchStartsWith, indent);
file->writeQuotedLine(_soundName, indent);
file->writeNumberLine(_hideItem, indent);
file->writeQuotedLine(_itemName, indent);
file->writeNumberLine(_dropEnabled, indent);
file->writeNumberLine(_dropFrame, indent);
file->writeNumberLine(_dragFrame, indent);
file->writeQuotedLine(_clipName, indent);
file->writeNumberLine(_dragCursorId, indent);
file->writeNumberLine(_dropCursorId, indent);
file->writeNumberLine(_clipFlags, indent);
CGameObject::save(file, indent);
}
void CDropTarget::load(SimpleFile *file) {
file->readNumber();
_pos1 = file->readPoint();
_itemFrame = file->readNumber();
_itemMatchName = file->readString();
_itemMatchStartsWith = file->readNumber();
_soundName = file->readString();
_hideItem = file->readNumber();
_itemName = file->readString();
_dropEnabled = file->readNumber();
_dropFrame = file->readNumber();
_dragFrame = file->readNumber();
_clipName = file->readString();
_dragCursorId = (CursorId)file->readNumber();
_dropCursorId = (CursorId)file->readNumber();
_clipFlags = file->readNumber();
CGameObject::load(file);
}
bool CDropTarget::DropObjectMsg(CDropObjectMsg *msg) {
if (!_itemName.empty()) {
if (msg->_item->getName() != _itemName) {
if (findByName(_itemName, true))
return false;
}
}
if (!msg->_item->isEquals(_itemMatchName, _itemMatchStartsWith))
return false;
msg->_item->detach();
msg->_item->addUnder(this);
msg->_item->setPosition(Point(_bounds.left, _bounds.top));
msg->_item->loadFrame(_itemFrame);
if (_hideItem)
msg->_item->setVisible(false);
_itemName = msg->_item->getName();
CDropZoneGotObjectMsg gotMsg(this);
gotMsg.execute(msg->_item);
playSound(_soundName);
if (_clipName.empty()) {
loadFrame(_dropFrame);
} else {
playClip(_clipName, _clipFlags);
}
_cursorId = _dropCursorId;
return true;
}
bool CDropTarget::MouseDragStartMsg(CMouseDragStartMsg *msg) {
CTreeItem *dragItem = msg->_dragItem;
if (!checkStartDragging(msg))
return false;
msg->_dragItem = dragItem;
CGameObject *obj = dynamic_cast<CGameObject *>(findByName(_itemName));
if (_itemName.empty() || _dropEnabled || !obj)
return false;
CDropZoneLostObjectMsg lostMsg;
lostMsg._object = this;
lostMsg.execute(obj);
loadFrame(_dragFrame);
_cursorId = _dragCursorId;
if (obj->_visible) {
msg->execute(obj);
} else {
msg->_dragItem = obj;
CPassOnDragStartMsg passMsg(msg->_mousePos, 1);
passMsg.execute(obj);
obj->setVisible(true);
}
return true;
}
bool CDropTarget::EnterViewMsg(CEnterViewMsg *msg) {
if (!_itemName.empty()) {
CGameObject *obj = dynamic_cast<CGameObject *>(findByName(_itemName));
if (!obj) {
loadFrame(_dragFrame);
_cursorId = _dragCursorId;
} else if (_clipName.empty()) {
loadFrame(_dropFrame);
_cursorId = _dropCursorId;
} else {
playClip(_clipName, _clipFlags);
_cursorId = _dropCursorId;
}
}
return true;
}
bool CDropTarget::VisibleMsg(CVisibleMsg *msg) {
setVisible(msg->_visible);
_dropEnabled = !msg->_visible;
return true;
}
bool CDropTarget::DropZoneLostObjectMsg(CDropZoneLostObjectMsg *msg) {
if (!_itemName.empty()) {
CGameObject *obj = dynamic_cast<CGameObject *>(findByName(_itemName));
if (obj) {
if (msg->_object) {
obj->detach();
obj->addUnder(msg->_object);
} else if (dynamic_cast<CCarry *>(obj)) {
obj->petAddToInventory();
}
obj->setVisible(true);
CDropZoneLostObjectMsg lostMsg(this);
lostMsg.execute(obj);
}
loadFrame(_dragFrame);
_cursorId = _dragCursorId;
}
return true;
}
} // End of namespace Titanic

View File

@@ -0,0 +1,68 @@
/* 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/>.
*
*/
#ifndef TITANIC_DROP_TARGET_H
#define TITANIC_DROP_TARGET_H
#include "titanic/core/game_object.h"
namespace Titanic {
class CDropTarget : public CGameObject {
DECLARE_MESSAGE_MAP;
bool DropObjectMsg(CDropObjectMsg *msg);
bool MouseDragStartMsg(CMouseDragStartMsg *msg);
bool EnterViewMsg(CEnterViewMsg *msg);
bool VisibleMsg(CVisibleMsg *msg);
bool DropZoneLostObjectMsg(CDropZoneLostObjectMsg *msg);
protected:
Point _pos1;
int _itemFrame;
CString _itemMatchName;
bool _itemMatchStartsWith;
CString _soundName;
bool _hideItem;
CString _itemName;
bool _dropEnabled;
int _dropFrame;
int _dragFrame;
CString _clipName;
CursorId _dragCursorId;
CursorId _dropCursorId;
uint _clipFlags;
public:
CLASSDEF;
CDropTarget();
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
};
} // End of namespace Titanic
#endif /* TITANIC_DROP_TARGET_H */

View File

@@ -0,0 +1,48 @@
/* 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 "titanic/core/file_item.h"
namespace Titanic {
EMPTY_MESSAGE_MAP(CFileItem, CTreeItem);
void CFileItem::save(SimpleFile *file, int indent) {
file->writeNumberLine(0, indent);
CTreeItem::save(file, indent);
}
void CFileItem::load(SimpleFile *file) {
file->readNumber();
CTreeItem::load(file);
}
CString CFileItem::formFilename() const {
return "";
}
CString CFileItem::getFilename() const {
//dynamic_cast<CFileItem *>(getRoot())->formDataPath();
return _filename;
}
} // End of namespace Titanic

View File

@@ -0,0 +1,66 @@
/* 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/>.
*
*/
#ifndef TITANIC_FILE_ITEM_H
#define TITANIC_FILE_ITEM_H
#include "titanic/support/string.h"
#include "titanic/core/list.h"
#include "titanic/core/tree_item.h"
namespace Titanic {
class CFileItem: public CTreeItem {
DECLARE_MESSAGE_MAP;
private:
CString _filename;
public:
CLASSDEF;
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
/**
* Returns true if the item is a file item
*/
bool isFileItem() const override { return true; }
/**
* Form a filename for the file item
*/
CString formFilename() const;
/**
* Get a string?
*/
CString getFilename() const;
};
} // End of namespace Titanic
#endif /* TITANIC_FILE_ITEM_H */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,56 @@
/* 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 "titanic/core/game_object_desc_item.h"
namespace Titanic {
CGameObjectDescItem::CGameObjectDescItem(): CTreeItem() {
}
void CGameObjectDescItem::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
_clipList.save(file, indent);
file->writeQuotedLine(_name, indent);
file->writeQuotedLine(_string2, indent);
_list1.save(file, indent);
_list2.save(file, indent);
CTreeItem::save(file, indent);
}
void CGameObjectDescItem::load(SimpleFile *file) {
int val = file->readNumber();
if (val != 1) {
if (val)
_clipList.load(file);
_name = file->readString();
_string2 = file->readString();
_list1.load(file);
_list1.load(file);
}
CTreeItem::load(file);
}
} // End of namespace Titanic

View File

@@ -0,0 +1,60 @@
/* 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/>.
*
*/
#ifndef TITANIC_GAME_OBJECT_DESK_ITEM_H
#define TITANIC_GAME_OBJECT_DESK_ITEM_H
#include "titanic/support/movie_clip.h"
#include "titanic/core/tree_item.h"
#include "titanic/core/list.h"
namespace Titanic {
class CGameObjectDescItem : public CTreeItem {
protected:
CString _name;
CString _string2;
List<ListItem> _list1;
List<ListItem> _list2;
CMovieClipList _clipList;
public:
CLASSDEF;
CGameObjectDescItem();
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
/**
* Gets the name of the item, if any
*/
const CString getName() const override { return _name; }
};
} // End of namespace Titanic
#endif /* TITANIC_GAME_OBJECT_DESK_ITEM_H */

View File

@@ -0,0 +1,205 @@
/* 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 "titanic/core/link_item.h"
#include "titanic/core/node_item.h"
#include "titanic/core/project_item.h"
#include "titanic/core/view_item.h"
namespace Titanic {
EMPTY_MESSAGE_MAP(CLinkItem, CNamedItem);
Movement CLinkItem::getMovementFromCursor(CursorId cursorId) {
if (cursorId == CURSOR_MOVE_LEFT)
return TURN_LEFT;
else if (cursorId == CURSOR_MOVE_RIGHT)
return TURN_RIGHT;
else if (cursorId == CURSOR_MOVE_FORWARD || cursorId == CURSOR_MOVE_THROUGH ||
cursorId == CURSOR_DOWN || cursorId == CURSOR_LOOK_UP ||
cursorId == CURSOR_LOOK_DOWN || cursorId == CURSOR_MAGNIFIER)
return MOVE_FORWARDS;
else if (cursorId == CURSOR_BACKWARDS)
return MOVE_BACKWARDS;
else
return MOVE_NONE;
}
CLinkItem::CLinkItem() : CNamedItem() {
_roomNumber = -1;
_nodeNumber = -1;
_viewNumber = -1;
_linkMode = 0;
_cursorId = CURSOR_ARROW;
_name = "Link";
}
CString CLinkItem::formName() {
CViewItem *view = findView();
CNodeItem *node = view->findNode();
CRoomItem *room = node->findRoom();
CViewItem *destView = getDestView();
CNodeItem *destNode = destView->findNode();
CRoomItem *destRoom = destNode->findRoom();
switch (_linkMode) {
case 1:
return CString::format("_PANL,%d,%s,%s", node->_nodeNumber,
view->getName().c_str(), destView->getName().c_str());
case 2:
return CString::format("_PANR,%d,%s,%s", node->_nodeNumber,
view->getName().c_str(), destView->getName().c_str());
case 3:
return CString::format("_TRACK,%d,%s,%d,%s",
node->_nodeNumber, view->getName().c_str(),
destNode->_nodeNumber, destView->getName().c_str());
case 4:
return CString::format("_EXIT,%d,%d,%s,%d,%d,%s",
room->_roomNumber, node->_nodeNumber, view->getName().c_str(),
destRoom->_roomNumber, destNode->_nodeNumber, destView->getName().c_str());
default:
return getName().c_str();
}
}
void CLinkItem::save(SimpleFile *file, int indent) {
file->writeNumberLine(2, indent);
file->writeQuotedLine("L", indent);
file->writeNumberLine(_cursorId, indent + 1);
file->writeNumberLine(_linkMode, indent + 1);
file->writeNumberLine(_roomNumber, indent + 1);
file->writeNumberLine(_nodeNumber, indent + 1);
file->writeNumberLine(_viewNumber, indent + 1);
file->writeQuotedLine("Hotspot", indent + 1);
file->writeNumberLine(_bounds.left, indent + 2);
file->writeNumberLine(_bounds.top, indent + 2);
file->writeNumberLine(_bounds.right, indent + 2);
file->writeNumberLine(_bounds.bottom, indent + 2);
CNamedItem::save(file, indent);
}
void CLinkItem::load(SimpleFile *file) {
int val = file->readNumber();
file->readBuffer();
switch (val) {
case 2:
_cursorId = (CursorId)file->readNumber();
// Intentional fall-through
case 1:
_linkMode = file->readNumber();
// Intentional fall-through
case 0:
_roomNumber = file->readNumber();
_nodeNumber = file->readNumber();
_viewNumber = file->readNumber();
file->readBuffer();
_bounds.left = file->readNumber();
_bounds.top = file->readNumber();
_bounds.right = file->readNumber();
_bounds.bottom = file->readNumber();
break;
default:
break;
}
CNamedItem::load(file);
if (val < 2) {
switch (_linkMode) {
case 2:
_cursorId = CURSOR_MOVE_LEFT;
break;
case 3:
_cursorId = CURSOR_MOVE_RIGHT;
break;
case 5:
_cursorId = CURSOR_MOVE_FORWARD;
break;
default:
_cursorId = CURSOR_MOVE_THROUGH;
break;
}
}
}
bool CLinkItem::connectsTo(CViewItem *destView) const {
CNodeItem *destNode = destView->findNode();
CRoomItem *destRoom = destNode->findRoom();
return _viewNumber == destView->_viewNumber &&
_nodeNumber == destNode->_nodeNumber &&
_roomNumber == destRoom->_roomNumber;
}
void CLinkItem::setDestination(int roomNumber, int nodeNumber,
int viewNumber, int linkMode) {
_roomNumber = roomNumber;
_nodeNumber = nodeNumber;
_viewNumber = viewNumber;
_linkMode = linkMode;
_name = formName();
}
CViewItem *CLinkItem::getDestView() const {
return getRoot()->findView(_roomNumber, _nodeNumber, _viewNumber);
}
CNodeItem *CLinkItem::getDestNode() const {
return getDestView()->findNode();
}
CRoomItem *CLinkItem::getDestRoom() const {
return getDestNode()->findRoom();
}
CMovieClip *CLinkItem::getClip() const {
return findRoom()->findClip(getName());
}
Movement CLinkItem::getMovement() const {
if (_bounds.isEmpty())
return MOVE_NONE;
return getMovementFromCursor(_cursorId);
}
bool CLinkItem::findPoint(Quadrant quadrant, Point &pt) {
if (_bounds.isEmpty())
return false;
pt = _bounds.getPoint(quadrant);
return true;
}
} // End of namespace Titanic

View File

@@ -0,0 +1,116 @@
/* 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/>.
*
*/
#ifndef TITANIC_LINK_ITEM_H
#define TITANIC_LINK_ITEM_H
#include "titanic/support/mouse_cursor.h"
#include "titanic/core/named_item.h"
#include "titanic/support/movie_clip.h"
#include "titanic/messages/messages.h"
namespace Titanic {
class CViewItem;
class CNodeItem;
class CRoomItem;
class CLinkItem : public CNamedItem {
DECLARE_MESSAGE_MAP;
private:
/**
* Returns a new name for the link item, based on the
* current values for it's destination
*/
CString formName();
protected:
int _roomNumber;
int _nodeNumber;
int _viewNumber;
int _linkMode;
public:
Rect _bounds;
CursorId _cursorId;
public:
static Movement getMovementFromCursor(CursorId cursorId);
public:
CLASSDEF;
CLinkItem();
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
/**
* Returns true if the given item connects to another specified view
*/
bool connectsTo(CViewItem *destView) const override;
/**
* Set the destination for the link item
*/
virtual void setDestination(int roomNumber, int nodeNumber,
int viewNumber, int linkMode);
/**
* Get the destination view for the link item
*/
virtual CViewItem *getDestView() const;
/**
* Get the destination node for the link item
*/
virtual CNodeItem *getDestNode() const;
/**
* Get the destination view for the link item
*/
virtual CRoomItem *getDestRoom() const;
/**
* Get the movie clip, if any, that's used when the link is used
*/
CMovieClip *getClip() const;
/**
* Get the movement, if any, the cursor represents
*/
Movement getMovement() const;
/**
* Returns a point that falls within the link. Used for simulating
* mouse clicks for movement when arrow keys are pressed
* @param quadrant Quadrant (edge) to return point for
* @param pt Return point
* @returns True if a point was found
*/
bool findPoint(Quadrant quadrant, Point &pt);
};
} // End of namespace Titanic
#endif /* TITANIC_LINK_ITEM_H */

View File

@@ -0,0 +1,34 @@
/* 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 "titanic/core/list.h"
namespace Titanic {
void ListItem::save(SimpleFile *file, int indent) {
file->writeNumberLine(0, indent);
}
void ListItem::load(SimpleFile *file) {
file->readNumber();
}
} // End of namespace Titanic

163
engines/titanic/core/list.h Normal file
View File

@@ -0,0 +1,163 @@
/* 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/>.
*
*/
#ifndef TITANIC_LIST_H
#define TITANIC_LIST_H
#include "common/scummsys.h"
#include "common/list.h"
#include "titanic/support/simple_file.h"
#include "titanic/core/saveable_object.h"
namespace Titanic {
/**
* Base list item class
*/
class ListItem: public CSaveableObject {
public:
CLASSDEF;
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
};
/**
* List item macro for managed pointers an item
*/
#define PTR_LIST_ITEM(T) class T##ListItem : public ListItem { \
public: T *_item; \
T##ListItem() : _item(nullptr) {} \
T##ListItem(T *item) : _item(item) {} \
virtual ~T##ListItem() { delete _item; } \
}
template<typename T>
class PtrListItem : public ListItem {
public:
T *_item;
public:
PtrListItem() : _item(nullptr) {}
PtrListItem(T *item) : _item(item) {}
~PtrListItem() override { delete _item; }
};
template<typename T>
class List : public CSaveableObject, public Common::List<T *> {
public:
~List() override { destroyContents(); }
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override {
file->writeNumberLine(0, indent);
// Write out number of items
file->writeQuotedLine("L", indent);
file->writeNumberLine(Common::List<T *>::size(), indent);
// Iterate through writing entries
typename Common::List<T *>::iterator i;
for (i = Common::List<T *>::begin(); i != Common::List<T *>::end(); ++i) {
ListItem *item = *i;
item->saveHeader(file, indent);
item->save(file, indent + 1);
item->saveFooter(file, indent);
}
}
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override {
file->readNumber();
file->readBuffer();
Common::List<T *>::clear();
uint count = file->readNumber();
for (uint idx = 0; idx < count; ++idx) {
// Validate the class start header
if (!file->isClassStart())
error("Unexpected class end");
// Get item's class name and use it to instantiate an item
CString className = file->readString();
T *newItem = dynamic_cast<T *>(CSaveableObject::createInstance(className));
if (!newItem)
error("Could not create instance of %s", className.c_str());
// Load the item's data and add it to the list
newItem->load(file);
Common::List<T *>::push_back(newItem);
// Validate the class end footer
if (file->isClassStart())
error("Unexpected class start");
}
}
/**
* Clear the list and destroy any items in it
*/
void destroyContents() {
typename Common::List<T *>::iterator i;
for (i = Common::List<T *>::begin();
i != Common::List<T *>::end(); ++i) {
CSaveableObject *obj = *i;
delete obj;
}
Common::List<T *>::clear();
}
/**
* Add a new item to the list of the type the list contains
*/
T *add() {
T *item = new T();
Common::List<T *>::push_back(item);
return item;
}
bool contains(const T *item) const {
for (typename Common::List<T *>::const_iterator i = Common::List<T *>::begin();
i != Common::List<T *>::end(); ++i) {
if (*i == item)
return true;
}
return false;
}
};
} // End of namespace Titanic
#endif /* TITANIC_LIST_H */

View File

@@ -0,0 +1,80 @@
/* 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 "titanic/core/mail_man.h"
namespace Titanic {
void CMailMan::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
file->writeNumberLine(_value, indent);
CGameObject::save(file, indent);
}
void CMailMan::load(SimpleFile *file) {
file->readNumber();
_value = file->readNumber();
CGameObject::load(file);
}
CGameObject *CMailMan::getFirstObject() const {
return dynamic_cast<CGameObject *>(getFirstChild());
}
CGameObject *CMailMan::getNextObject(CGameObject *prior) const {
if (!prior || prior->getParent() != this)
return nullptr;
return dynamic_cast<CGameObject *>(prior->getNextSibling());
}
void CMailMan::addMail(CGameObject *obj, uint destRoomFlags) {
obj->detach();
obj->addUnder(this);
setMailDest(obj, destRoomFlags);
}
void CMailMan::setMailDest(CGameObject *obj, uint roomFlags) {
obj->_destRoomFlags = roomFlags;
obj->_roomFlags = 0;
obj->_isPendingMail = true;
}
CGameObject *CMailMan::findMail(uint roomFlags) const {
for (CGameObject *obj = getFirstObject(); obj; obj = getNextObject(obj)) {
if (obj->_isPendingMail && obj->_destRoomFlags == roomFlags)
return obj;
}
return nullptr;
}
void CMailMan::sendMail(uint currRoomFlags, uint newRoomFlags) {
for (CGameObject *obj = getFirstObject(); obj; obj = getNextObject(obj)) {
if (obj->_isPendingMail && obj->_destRoomFlags == currRoomFlags) {
obj->_isPendingMail = false;
obj->_roomFlags = newRoomFlags;
break;
}
}
}
} // End of namespace Titanic

View File

@@ -0,0 +1,83 @@
/* 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/>.
*
*/
#ifndef TITANIC_MAIL_MAN_H
#define TITANIC_MAIL_MAN_H
#include "titanic/core/game_object.h"
namespace Titanic {
class CMailMan : public CGameObject {
public:
int _value;
public:
CLASSDEF;
CMailMan() : CGameObject(), _value(1) {}
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
/**
* Get the first game object stored in the PET
*/
CGameObject *getFirstObject() const;
/**
* Get the next game object stored in the PET following
* the passed game object
*/
CGameObject *getNextObject(CGameObject *prior) const;
/**
* Add an object to the mail list
*/
void addMail(CGameObject *obj, uint destRoomFlags);
/**
* Sets the mail destination for an object
*/
static void setMailDest(CGameObject *obj, uint roomFlags);
/**
* Scan the mail list for a specified item
*/
CGameObject *findMail(uint roomFlags) const;
/**
* Sends a pending mail object to a given destination
*/
void sendMail(uint currRoomFlags, uint newRoomFlags);
void resetValue() { _value = 0; }
};
} // End of namespace Titanic
#endif /* TITANIC_MAIL_MAN_H */

View File

@@ -0,0 +1,50 @@
/* 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 "titanic/core/message_target.h"
namespace Titanic {
const MSGMAP *CMessageTarget::getMessageMap() const {
return getThisMessageMap();
}
const MSGMAP *CMessageTarget::getThisMessageMap() {
static const ClassDef *nullDef = nullptr;
static const MSGMAP_ENTRY _messageEntries[] = {
{ (PMSG)nullptr, &nullDef }
};
static const MSGMAP messageMap = { nullptr, &_messageEntries[0] };
return &messageMap;
}
void CMessageTarget::save(SimpleFile *file, int indent) {
file->writeNumberLine(0, indent);
CSaveableObject::save(file, indent);
}
void CMessageTarget::load(SimpleFile *file) {
file->readNumber();
CSaveableObject::load(file);
}
} // End of namespace Titanic

View File

@@ -0,0 +1,106 @@
/* 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/>.
*
*/
#ifndef TITANIC_MESSAGE_TARGET_H
#define TITANIC_MESSAGE_TARGET_H
#include "titanic/core/saveable_object.h"
namespace Titanic {
class CMessageTarget;
class CMessage;
typedef bool (CMessageTarget::*PMSG)(CMessage *msg);
struct MSGMAP_ENTRY {
PMSG _fn;
const ClassDef * const *_class;
};
struct MSGMAP {
const MSGMAP *(* pFnGetBaseMap)();
const MSGMAP_ENTRY *lpEntries;
};
#define DECLARE_MESSAGE_MAP \
protected: \
static const MSGMAP *getThisMessageMap(); \
const MSGMAP *getMessageMap() const override
#define BEGIN_MESSAGE_MAP(theClass, baseClass) \
const MSGMAP *theClass::getMessageMap() const \
{ return getThisMessageMap(); } \
const MSGMAP *theClass::getThisMessageMap() \
{ \
typedef theClass ThisClass; \
typedef baseClass TheBaseClass; \
typedef bool (theClass::*FNPTR)(CMessage *msg); \
static const MSGMAP_ENTRY _messageEntries[] = {
#define ON_MESSAGE(msgClass) \
{ static_cast<PMSG>((FNPTR)&ThisClass::msgClass), &C##msgClass::_type },
#define END_MESSAGE_MAP() \
{ (PMSG)nullptr, nullptr } \
}; \
static const MSGMAP messageMap = \
{ &TheBaseClass::getThisMessageMap, &_messageEntries[0] }; \
return &messageMap; \
}
#define EMPTY_MESSAGE_MAP(theClass, baseClass) \
const MSGMAP *theClass::getMessageMap() const \
{ return getThisMessageMap(); } \
const MSGMAP *theClass::getThisMessageMap() \
{ \
typedef baseClass TheBaseClass; \
static const MSGMAP_ENTRY _messageEntries[] = { \
{ (PMSG)nullptr, nullptr } \
}; \
static const MSGMAP messageMap = \
{ &TheBaseClass::getThisMessageMap, &_messageEntries[0] }; \
return &messageMap; \
} \
enum { DUMMY }
class CMessageTarget: public CSaveableObject {
protected:
static const MSGMAP *getThisMessageMap();
virtual const MSGMAP *getMessageMap() const;
public:
CLASSDEF;
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
};
} // End of namespace Titanic
#endif /* TITANIC_MESSAGE_TARGET_H */

View File

@@ -0,0 +1,68 @@
/* 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 "titanic/core/multi_drop_target.h"
#include "titanic/support/string_parser.h"
#include "titanic/carry/carry.h"
namespace Titanic {
BEGIN_MESSAGE_MAP(CMultiDropTarget, CDropTarget)
ON_MESSAGE(DropObjectMsg)
END_MESSAGE_MAP()
void CMultiDropTarget::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
file->writeQuotedLine(_dropFrames, indent);
file->writeQuotedLine(_dropNames, indent);
CDropTarget::save(file, indent);
}
void CMultiDropTarget::load(SimpleFile *file) {
file->readNumber();
_dropFrames = file->readString();
_dropNames = file->readString();
CDropTarget::load(file);
}
bool CMultiDropTarget::DropObjectMsg(CDropObjectMsg *msg) {
CStringParser parser1(_dropFrames);
CStringParser parser2(_dropNames);
CString separatorChars = ",";
// WORKAROUND: The original didn't break out of loop if a drop target
// succeeded, nor did it return the item to the inventory if incorrect
while (parser2.parse(_itemMatchName, separatorChars)) {
_dropFrame = parser1.readInt();
if (CDropTarget::DropObjectMsg(msg))
return true;
parser1.skipSeparators(separatorChars);
parser2.skipSeparators(separatorChars);
}
msg->_item->petAddToInventory();
return true;
}
} // End of namespace Titanic

View File

@@ -0,0 +1,52 @@
/* 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/>.
*
*/
#ifndef TITANIC_MULTI_DROP_TARGET_H
#define TITANIC_MULTI_DROP_TARGET_H
#include "titanic/core/drop_target.h"
namespace Titanic {
class CMultiDropTarget : public CDropTarget {
DECLARE_MESSAGE_MAP;
bool DropObjectMsg(CDropObjectMsg *msg);
public:
CString _dropFrames;
CString _dropNames;
public:
CLASSDEF;
CMultiDropTarget() : CDropTarget(), _dropFrames("1,2") {}
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
};
} // End of namespace Titanic
#endif /* TITANIC_CLICK_RESPONDER_H */

View File

@@ -0,0 +1,91 @@
/* 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 "titanic/core/named_item.h"
#include "titanic/core/node_item.h"
#include "titanic/core/room_item.h"
#include "titanic/core/view_item.h"
namespace Titanic {
EMPTY_MESSAGE_MAP(CNamedItem, CTreeItem);
CString CNamedItem::dumpItem(int indent) const {
CString result = CTreeItem::dumpItem(indent);
result += " " + _name;
return result;
}
void CNamedItem::save(SimpleFile *file, int indent) {
file->writeNumberLine(0, indent);
file->writeQuotedLine(_name, indent);
CTreeItem::save(file, indent);
}
void CNamedItem::load(SimpleFile *file) {
int val = file->readNumber();
if (!val)
_name = file->readString();
CTreeItem::load(file);
}
bool CNamedItem::isEquals(const CString &name, bool startsWith) const {
if (startsWith) {
return getName().left(name.size()).compareToIgnoreCase(name) == 0;
} else {
return getName().compareToIgnoreCase(name) == 0;
}
}
CViewItem *CNamedItem::findView() const {
for (CTreeItem *parent = getParent(); parent; parent = parent->getParent()) {
CViewItem *view = dynamic_cast<CViewItem *>(parent);
if (view)
return view;
}
error("Couldn't find parent view");
}
CNodeItem *CNamedItem::findNode() const {
for (CTreeItem *parent = getParent(); parent; parent = parent->getParent()) {
CNodeItem *node = dynamic_cast<CNodeItem *>(parent);
if (node)
return node;
}
error("Couldn't find parent node");
}
CRoomItem *CNamedItem::findRoom() const {
for (CTreeItem *parent = getParent(); parent; parent = parent->getParent()) {
CRoomItem *room = dynamic_cast<CRoomItem *>(parent);
if (room)
return room;
}
error("Couldn't find parent node");
}
} // End of namespace Titanic

View File

@@ -0,0 +1,83 @@
/* 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/>.
*
*/
#ifndef TITANIC_NAMED_ITEM_H
#define TITANIC_NAMED_ITEM_H
#include "titanic/core/tree_item.h"
namespace Titanic {
class CViewItem;
class CNodeItem;
class CRoomItem;
class CNamedItem: public CTreeItem {
DECLARE_MESSAGE_MAP;
public:
CString _name;
public:
CLASSDEF;
/**
* Dump the item
*/
CString dumpItem(int indent) const override;
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
/**
* Gets the name of the item, if any
*/
const CString getName() const override { return _name; }
/**
* Returns true if the item's name matches a passed name
*/
bool isEquals(const CString &name, bool startsWith = false) const override;
/**
* Find a parent node for the item
*/
virtual CViewItem *findView() const;
/**
* Find a parent node for the item
*/
virtual CNodeItem *findNode() const;
/**
* Find a parent room item for the item
*/
virtual CRoomItem *findRoom() const;
};
} // End of namespace Titanic
#endif /* TITANIC_NAMED_ITEM_H */

View File

@@ -0,0 +1,62 @@
/* 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 "titanic/core/node_item.h"
#include "titanic/core/room_item.h"
namespace Titanic {
EMPTY_MESSAGE_MAP(CNodeItem, CNamedItem);
CNodeItem::CNodeItem() : CNamedItem(), _nodeNumber(0) {
}
void CNodeItem::save(SimpleFile *file, int indent) {
file->writeNumberLine(0, indent);
file->writeQuotedLine("N", indent);
file->writeNumberLine(_nodePos.x, indent + 1);
file->writeNumberLine(_nodePos.y, indent + 1);
file->writeQuotedLine("N", indent);
file->writeNumberLine(_nodeNumber, indent + 1);
CNamedItem::save(file, indent);
}
void CNodeItem::load(SimpleFile *file) {
file->readNumber();
file->readBuffer();
_nodePos.x = file->readNumber();
_nodePos.y = file->readNumber();
file->readBuffer();
_nodeNumber = file->readNumber();
CNamedItem::load(file);
}
void CNodeItem::getPosition(double &xp, double &yp, double &zp) {
CRoomItem *room = findRoom();
room->calcNodePosition(_nodePos, xp, yp);
zp = 0.0;
}
} // End of namespace Titanic

View File

@@ -0,0 +1,56 @@
/* 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/>.
*
*/
#ifndef TITANIC_NODE_ITEM_H
#define TITANIC_NODE_ITEM_H
#include "titanic/core/named_item.h"
namespace Titanic {
class CNodeItem : public CNamedItem {
DECLARE_MESSAGE_MAP;
public:
int _nodeNumber;
Point _nodePos;
public:
CLASSDEF;
CNodeItem();
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
/**
* Gets the relative position of the node within the owning room
*/
void getPosition(double &xp, double &yp, double &zp);
};
} // End of namespace Titanic
#endif /* TITANIC_FILE_ITEM_H */

View File

@@ -0,0 +1,651 @@
/* 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 "titanic/core/dont_save_file_item.h"
#include "titanic/core/node_item.h"
#include "titanic/core/project_item.h"
#include "titanic/core/view_item.h"
#include "titanic/events.h"
#include "titanic/game_manager.h"
#include "titanic/pet_control/pet_control.h"
#include "titanic/titanic.h"
#include "common/file.h"
#include "common/savefile.h"
#include "graphics/scaler.h"
#include "graphics/thumbnail.h"
namespace Titanic {
#define CURRENT_SAVEGAME_VERSION 1
#define MINIMUM_SAVEGAME_VERSION 1
static const char *const SAVEGAME_STR = "TNIC";
#define SAVEGAME_STR_SIZE 4
EMPTY_MESSAGE_MAP(CProjectItem, CFileItem);
/*------------------------------------------------------------------------*/
void TitanicSavegameHeader::clear() {
_version = 0;
_saveName = "";
_thumbnail = nullptr;
_year = _month = _day = 0;
_hour = _minute = 0;
_totalFrames = 0;
}
/*------------------------------------------------------------------------*/
void CFileListItem::save(SimpleFile *file, int indent) {
file->writeNumberLine(0, indent);
file->writeQuotedLine(_name, indent);
ListItem::save(file, indent);
}
void CFileListItem::load(SimpleFile *file) {
file->readNumber();
_name = file->readString();
ListItem::load(file);
}
/*------------------------------------------------------------------------*/
CProjectItem::CProjectItem() : _nextRoomNumber(0), _nextMessageNumber(0),
_nextObjectNumber(0), _gameManager(nullptr) {
}
void CProjectItem::save(SimpleFile *file, int indent) {
file->writeNumberLine(6, indent);
file->writeQuotedLine("Next Avail. Object Number", indent);
file->writeNumberLine(_nextObjectNumber, indent);
file->writeQuotedLine("Next Avail. Message Number", indent);
file->writeNumberLine(_nextMessageNumber, indent);
file->writeQuotedLine("", indent);
_files.save(file, indent);
file->writeQuotedLine("Next Avail. Room Number", indent);
file->writeNumberLine(_nextRoomNumber, indent);
CTreeItem::save(file, indent);
}
void CProjectItem::buildFilesList() {
_files.destroyContents();
CTreeItem *treeItem = getFirstChild();
while (treeItem) {
if (treeItem->isFileItem()) {
CString name = static_cast<CFileItem *>(treeItem)->getFilename();
_files.add()->_name = name;
}
treeItem = getNextSibling();
}
}
void CProjectItem::load(SimpleFile *file) {
int val = file->readNumber();
_files.destroyContents();
int count;
switch (val) {
case 1:
file->readBuffer();
_nextRoomNumber = file->readNumber();
// Intentional fall-through
case 0:
// Load the list of files
count = file->readNumber();
for (int idx = 0; idx < count; ++idx) {
CString name = file->readString();
_files.add()->_name = name;
}
break;
case 6:
file->readBuffer();
_nextObjectNumber = file->readNumber();
// Intentional fall-through
case 5:
file->readBuffer();
_nextMessageNumber = file->readNumber();
// Intentional fall-through
case 4:
file->readBuffer();
// Intentional fall-through
case 2:
case 3:
_files.load(file);
file->readBuffer();
_nextRoomNumber = file->readNumber();
break;
default:
break;
}
CTreeItem::load(file);
}
CGameManager *CProjectItem::getGameManager() const {
return _gameManager;
}
void CProjectItem::setGameManager(CGameManager *gameManager) {
if (!_gameManager)
_gameManager = gameManager;
}
void CProjectItem::resetGameManager() {
_gameManager = nullptr;
}
void CProjectItem::loadGame(int slotId) {
CompressedFile file;
// Clear any existing project contents and call preload code
preLoad();
clear();
g_vm->_loadSaveSlot = -1;
// Open either an existing savegame slot or the new game template
if (slotId >= 0) {
Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(
g_vm->getSaveStateName(slotId));
file.open(saveFile);
} else {
Common::File *newFile = new Common::File();
if (!newFile->open("newgame.st"))
error("Could not open newgame.st");
file.open(newFile);
}
// Load the savegame header in
TitanicSavegameHeader header;
if (!readSavegameHeader(&file, header))
error("Failed to read save game header");
g_vm->_events->setTotalPlayTicks(header._totalFrames);
// Load the contents in
CProjectItem *newProject = loadData(&file);
file.isClassStart();
getGameManager()->load(&file);
file.close();
// Clear existing project
clear();
// Detach each item under the loaded project, and re-attach them
// to the existing project instance (this)
CTreeItem *item;
while ((item = newProject->getFirstChild()) != nullptr) {
item->detach();
item->addUnder(this);
}
// Loaded project instance is no longer needed
newProject->destroyAll();
// Post-load processing
postLoad();
}
void CProjectItem::saveGame(int slotId, const CString &desc) {
CompressedFile file;
Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(
g_vm->getSaveStateName(slotId), false);
file.open(saveFile);
// Signal the game is being saved
preSave();
// Write out the savegame header
TitanicSavegameHeader header;
header._saveName = desc;
writeSavegameHeader(&file, header);
// Save the contents out
saveData(&file, this);
// Save the game manager data
_gameManager->save(&file);
// Close the file and signal that the saving has finished
file.close();
postSave();
}
void CProjectItem::clear() {
CTreeItem *item;
while ((item = getFirstChild()) != nullptr)
item->destroyAll();
}
CProjectItem *CProjectItem::loadData(SimpleFile *file) {
if (!file->isClassStart())
return nullptr;
CProjectItem *root = nullptr;
CTreeItem *parent = nullptr;
CTreeItem *item = nullptr;
do {
CString entryString = file->readString();
if (entryString == "ALONG") {
// Move along, nothing needed
} else if (entryString == "UP") {
// Move up
if (parent == nullptr ||
(parent = parent->getParent()) == nullptr)
break;
} else if (entryString == "DOWN") {
// Move down
if (parent == nullptr)
parent = item;
else
parent = parent->getLastChild();
} else {
// Create new class instance
item = dynamic_cast<CTreeItem *>(CSaveableObject::createInstance(entryString));
assert(item);
if (root) {
// Already created root project
item->addUnder(parent);
} else {
root = dynamic_cast<CProjectItem *>(item);
assert(root);
root->_filename = _filename;
}
// Load the data for the item
item->load(file);
}
file->isClassStart();
} while (file->isClassStart());
return root;
}
void CProjectItem::saveData(SimpleFile *file, CTreeItem *item) const {
while (item) {
item->saveHeader(file, 0);
item->save(file, 1);
item->saveFooter(file, 0);
CTreeItem *child = item->getFirstChild();
if (child) {
file->write("\n{\n", 3);
file->writeQuotedString("DOWN");
file->write("\n}\n", 3);
saveData(file, child);
file->write("\n{\n", 3);
file->writeQuotedString("UP");
} else {
file->write("\n{\n", 3);
file->writeQuotedString("ALONG");
}
file->write("\n}\n", 3);
item = item->getNextSibling();
}
}
void CProjectItem::preLoad() {
if (_gameManager)
_gameManager->preLoad();
CScreenManager *scrManager = CScreenManager::_currentScreenManagerPtr;
if (scrManager)
scrManager->preLoad();
}
void CProjectItem::postLoad() {
CGameManager *gameManager = getGameManager();
if (gameManager)
gameManager->postLoad(this);
CPetControl *petControl = getPetControl();
if (petControl)
petControl->postLoad();
}
void CProjectItem::preSave() {
if (_gameManager)
_gameManager->preSave(this);
}
void CProjectItem::postSave() {
if (_gameManager)
_gameManager->postSave();
}
CPetControl *CProjectItem::getPetControl() const {
CDontSaveFileItem *fileItem = getDontSaveFileItem();
CTreeItem *treeItem;
if (!fileItem || (treeItem = fileItem->getLastChild()) == nullptr)
return nullptr;
while (treeItem) {
CPetControl *petControl = dynamic_cast<CPetControl *>(treeItem);
if (petControl)
return petControl;
treeItem = treeItem->getPriorSibling();
}
return nullptr;
}
CRoomItem *CProjectItem::findFirstRoom() const {
return dynamic_cast<CRoomItem *>(findChildInstance(CRoomItem::_type));
}
CTreeItem *CProjectItem::findChildInstance(ClassDef *classDef) const {
CTreeItem *treeItem = getFirstChild();
if (treeItem == nullptr)
return nullptr;
do {
CTreeItem *childItem = treeItem->getFirstChild();
if (childItem) {
do {
if (childItem->isInstanceOf(classDef))
return childItem;
} while ((childItem = childItem->getNextSibling()) != nullptr);
}
} while ((treeItem = treeItem->getNextSibling()) != nullptr);
return nullptr;
}
CRoomItem *CProjectItem::findNextRoom(CRoomItem *priorRoom) const {
return dynamic_cast<CRoomItem *>(findSiblingChildInstanceOf(CRoomItem::_type, priorRoom));
}
CTreeItem *CProjectItem::findSiblingChildInstanceOf(ClassDef *classDef, CTreeItem *startItem) const {
for (CTreeItem *treeItem = startItem->getParent()->getNextSibling();
treeItem; treeItem = treeItem->getNextSibling()) {
for (CTreeItem *childItem = treeItem->getFirstChild();
childItem; childItem = childItem->getNextSibling()) {
if (childItem->isInstanceOf(classDef))
return childItem;
}
}
return nullptr;
}
CDontSaveFileItem *CProjectItem::getDontSaveFileItem() const {
for (CTreeItem *treeItem = getFirstChild(); treeItem; treeItem = treeItem->getNextSibling()) {
if (treeItem->isInstanceOf(CDontSaveFileItem::_type))
return dynamic_cast<CDontSaveFileItem *>(treeItem);
}
return nullptr;
}
CRoomItem *CProjectItem::findHiddenRoom() {
return dynamic_cast<CRoomItem *>(findByName("HiddenRoom"));
}
CViewItem *CProjectItem::findView(int roomNumber, int nodeNumber, int viewNumber) {
CTreeItem *treeItem = getFirstChild();
CRoomItem *roomItem = nullptr;
// Scan for the specified room
if (treeItem) {
do {
CTreeItem *childItem = treeItem->getFirstChild();
CRoomItem *rItem = dynamic_cast<CRoomItem *>(childItem);
if (rItem && rItem->_roomNumber == roomNumber) {
roomItem = rItem;
break;
}
} while ((treeItem = treeItem->getNextSibling()) != nullptr);
}
if (!roomItem)
return nullptr;
// Scan for the specified node within the room
CNodeItem *nodeItem = nullptr;
CNodeItem *nItem = dynamic_cast<CNodeItem *>(
roomItem->findChildInstanceOf(CNodeItem::_type));
for (; nItem && !nodeItem; nItem = dynamic_cast<CNodeItem *>(
findNextInstanceOf(CNodeItem::_type, nItem))) {
if (nItem->_nodeNumber == nodeNumber)
nodeItem = nItem;
}
if (!nodeItem)
return nullptr;
// Scan for the specified view within the node
CViewItem *viewItem = dynamic_cast<CViewItem *>(
nodeItem->findChildInstanceOf(CViewItem::_type));
for (; viewItem; viewItem = dynamic_cast<CViewItem *>(
findNextInstanceOf(CViewItem::_type, viewItem))) {
if (viewItem->_viewNumber == viewNumber)
return viewItem;
}
return nullptr;
}
SaveStateList CProjectItem::getSavegameList(const MetaEngine *metaEngine, const Common::String &target) {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Common::StringArray filenames;
Common::String saveDesc;
Common::String pattern = Common::String::format("%s.0??", target.c_str());
TitanicSavegameHeader header;
filenames = saveFileMan->listSavefiles(pattern);
sort(filenames.begin(), filenames.end()); // Sort to get the files in numerical order
SaveStateList saveList;
for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
const char *ext = strrchr(file->c_str(), '.');
int slot = ext ? atoi(ext + 1) : -1;
if (slot >= 0 && slot <= MAX_SAVES) {
Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(*file);
if (in) {
SimpleFile f;
f.open(in);
if (readSavegameHeader(&f, header))
saveList.push_back(SaveStateDescriptor(metaEngine, slot, header._saveName));
delete in;
}
}
}
return saveList;
}
WARN_UNUSED_RESULT bool CProjectItem::readSavegameHeader(SimpleFile *file, TitanicSavegameHeader &header, bool skipThumbnail) {
char saveIdentBuffer[SAVEGAME_STR_SIZE + 1];
header._thumbnail = nullptr;
header._totalFrames = 0;
// Validate the header Id
file->unsafeRead(saveIdentBuffer, SAVEGAME_STR_SIZE + 1);
if (strncmp(saveIdentBuffer, SAVEGAME_STR, SAVEGAME_STR_SIZE)) {
file->seek(-SAVEGAME_STR_SIZE, SEEK_CUR);
header._saveName = "Unnamed";
return true;
}
header._version = file->readByte();
if (header._version < MINIMUM_SAVEGAME_VERSION || header._version > CURRENT_SAVEGAME_VERSION)
return false;
// Read in the string
header._saveName.clear();
char ch;
while ((ch = (char)file->readByte()) != '\0') header._saveName += ch;
// Get the thumbnail
if (!Graphics::loadThumbnail(*file, header._thumbnail, skipThumbnail))
return false;
// Read in save date/time
header._year = file->readUint16LE();
header._month = file->readUint16LE();
header._day = file->readUint16LE();
header._hour = file->readUint16LE();
header._minute = file->readUint16LE();
header._totalFrames = file->readUint32LE();
return true;
}
void CProjectItem::writeSavegameHeader(SimpleFile *file, TitanicSavegameHeader &header) {
// Write out a savegame header
file->write(SAVEGAME_STR, SAVEGAME_STR_SIZE + 1);
file->writeByte(CURRENT_SAVEGAME_VERSION);
// Write savegame name
file->write(header._saveName.c_str(), header._saveName.size());
file->writeByte('\0');
// Create a thumbnail of the screen and save it out
Graphics::Surface *thumb = createThumbnail();
Graphics::saveThumbnail(*file, *thumb);
thumb->free();
delete thumb;
// Write out the save date/time
TimeDate td;
g_system->getTimeAndDate(td);
file->writeUint16LE(td.tm_year + 1900);
file->writeUint16LE(td.tm_mon + 1);
file->writeUint16LE(td.tm_mday);
file->writeUint16LE(td.tm_hour);
file->writeUint16LE(td.tm_min);
file->writeUint32LE(g_vm->_events->getTotalPlayTicks());
}
Graphics::Surface *CProjectItem::createThumbnail() {
Graphics::Surface *thumb = new Graphics::Surface();
::createThumbnailFromScreen(thumb);
return thumb;
}
CViewItem *CProjectItem::parseView(const CString &viewString) {
int firstIndex = viewString.indexOf('.');
int lastIndex = viewString.lastIndexOf('.');
CString roomName, nodeName, viewName;
if (firstIndex == -1) {
roomName = viewString;
}
else {
roomName = viewString.left(firstIndex);
if (lastIndex > firstIndex) {
nodeName = viewString.mid(firstIndex + 1, lastIndex - firstIndex - 1);
viewName = viewString.mid(lastIndex + 1);
}
else {
nodeName = viewString.mid(firstIndex + 1);
}
}
CGameManager *gameManager = getGameManager();
if (!gameManager)
return nullptr;
CRoomItem *room = gameManager->getRoom();
CProjectItem *project = room->getRoot();
// Ensure we have the specified room
if (project) {
if (room->getName().compareToIgnoreCase(roomName)) {
// Scan for the correct room
for (room = project->findFirstRoom();
room && room->getName().compareToIgnoreCase(roomName);
room = project->findNextRoom(room));
}
}
if (!room)
return nullptr;
// Find the designated node within the room
CNodeItem *node = dynamic_cast<CNodeItem *>(room->findChildInstanceOf(CNodeItem::_type));
while (node && node->getName().compareToIgnoreCase(nodeName))
node = dynamic_cast<CNodeItem *>(room->findNextInstanceOf(CNodeItem::_type, node));
if (!node)
return nullptr;
CViewItem *view = dynamic_cast<CViewItem *>(node->findChildInstanceOf(CViewItem::_type));
while (view && view->getName().compareToIgnoreCase(viewName))
view = dynamic_cast<CViewItem *>(node->findNextInstanceOf(CViewItem::_type, view));
if (!view)
return nullptr;
// Find the view, so return it
return view;
}
bool CProjectItem::changeView(const CString &viewName) {
return changeView(viewName, "");
}
bool CProjectItem::changeView(const CString &viewName, const CString &clipName) {
CViewItem *newView = parseView(viewName);
CGameManager *gameManager = getGameManager();
CViewItem *oldView = gameManager->getView();
if (!oldView || !newView)
return false;
CMovieClip *clip = nullptr;
if (!clipName.empty()) {
clip = oldView->findNode()->findRoom()->findClip(clipName);
} else {
CLinkItem *link = oldView->findLink(newView);
if (link)
clip = link->getClip();
}
gameManager->_gameState.changeView(newView, clip);
return true;
}
} // End of namespace Titanic

View File

@@ -0,0 +1,257 @@
/* 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/>.
*
*/
#ifndef TITANIC_PROJECT_ITEM_H
#define TITANIC_PROJECT_ITEM_H
#include "common/scummsys.h"
#include "common/str.h"
#include "engines/savestate.h"
#include "graphics/surface.h"
#include "titanic/support/simple_file.h"
#include "titanic/core/dont_save_file_item.h"
#include "titanic/core/file_item.h"
#include "titanic/core/list.h"
#include "titanic/core/room_item.h"
namespace Titanic {
struct TitanicSavegameHeader {
uint8 _version;
CString _saveName;
Graphics::Surface *_thumbnail;
int _year, _month, _day;
int _hour, _minute;
int _totalFrames;
TitanicSavegameHeader() { clear(); }
/**
* Clear the header
*/
void clear();
};
class CGameManager;
class CPetControl;
class CViewItem;
/**
* File list item
*/
class CFileListItem : public ListItem {
public:
CString _name;
public:
CLASSDEF;
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
};
/**
* Filename list
*/
class CFileList: public List<CFileListItem> {
};
class CProjectItem : public CFileItem {
DECLARE_MESSAGE_MAP;
private:
CString _filename;
CFileList _files;
int _nextRoomNumber;
int _nextMessageNumber;
int _nextObjectNumber;
CGameManager *_gameManager;
/**
* Called during save, iterates through the children to do some stuff
*/
void buildFilesList();
/**
* Called at the beginning of loading a game
*/
void preLoad();
/**
* Does post-loading processing
*/
void postLoad();
/**
* Called when a game is about to be saved
*/
void preSave();
/**
* Called when a game has finished being saved
*/
void postSave();
/**
* Finds the first child instance of a given class type
*/
CTreeItem *findChildInstance(ClassDef *classDef) const;
/**
* Finds the next sibling occurrence of a given class type
*/
CTreeItem *findSiblingChildInstanceOf(ClassDef *classDef, CTreeItem *startItem) const;
private:
/**
* Load project data from the passed file
*/
CProjectItem *loadData(SimpleFile *file);
/**
* Save project data to the passed file
*/
void saveData(SimpleFile *file, CTreeItem *item) const;
/**
* Creates a thumbnail for the current on-screen contents
*/
static Graphics::Surface *createThumbnail();
public:
/**
* Load a list of savegames
*/
static SaveStateList getSavegameList(const MetaEngine *metaEngine, const Common::String &target);
/**
* Write out the header information for a savegame
*/
static void writeSavegameHeader(SimpleFile *file, TitanicSavegameHeader &header);
/**
* Read in the header information for a savegame
*/
WARN_UNUSED_RESULT static bool readSavegameHeader(SimpleFile *file, TitanicSavegameHeader &header, bool skipThumbnail = true);
public:
CLASSDEF;
CProjectItem();
~CProjectItem() override { destroyChildren(); }
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
/**
* Get the game manager for the project
*/
CGameManager *getGameManager() const override;
/**
* Sets the game manager for the project, if not already set
*/
void setGameManager(CGameManager *gameManager);
/**
* Get a reference to the PET control
*/
CPetControl *getPetControl() const;
/**
* Resets the game manager field
*/
void resetGameManager();
/**
* Load the entire project data for a given slot Id
*/
void loadGame(int slotId);
/**
* Save the entire project data to a given savegame slot
*/
void saveGame(int slotId, const CString &desc);
/**
* Clear any currently loaded project
*/
void clear();
/**
* Set the proejct's name
*/
void setFilename(const CString &name) { _filename = name; }
/**
* Returns a reference to the first room item in the project
*/
CRoomItem *findFirstRoom() const;
/**
* Returns a reference to the next room following the specified room
*/
CRoomItem *findNextRoom(CRoomItem *priorRoom) const;
/**
* Returns the don't save file item, if it exists in the project
*/
CDontSaveFileItem *getDontSaveFileItem() const;
/**
* Finds the hidden room node of the project
*/
CRoomItem *findHiddenRoom();
/**
* Finds a view
*/
CViewItem *findView(int roomNumber, int nodeNumber, int viewNumber);
/**
* Parses a view into it's components of room, node, and view,
* and locates the designated view
*/
CViewItem *parseView(const CString &viewString);
/**
* Change the view
*/
bool changeView(const CString &viewName, const CString &clipName);
/**
* Change the view
*/
bool changeView(const CString &viewName);
};
} // End of namespace Titanic
#endif /* TITANIC_PROJECT_ITEM_H */

View File

@@ -0,0 +1,88 @@
/* 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 "titanic/core/resource_key.h"
#include "titanic/support/files_manager.h"
#include "titanic/support/simple_file.h"
#include "titanic/titanic.h"
#include "common/file.h"
namespace Titanic {
void CResourceKey::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
file->writeQuotedLine("Resource Key...", indent);
file->writeQuotedLine(_key, indent);
CSaveableObject::save(file, indent);
}
void CResourceKey::load(SimpleFile *file) {
int val = file->readNumber();
if (val == 0 || val == 1) {
file->readBuffer();
CString str = file->readString();
setValue(str);
}
CSaveableObject::load(file);
}
void CResourceKey::setValue(const CString &name) {
CString nameStr = name;
nameStr.toLowercase();
_key = nameStr;
_value = nameStr;
int idx = _value.lastIndexOf('\\');
if (idx >= 0)
_value = _value.mid(idx + 1);
}
CString CResourceKey::getFilename() const {
CString name = _key;
// Check for a resource being specified within an ST container
int idx = name.indexOf('#');
if (idx >= 0) {
name = name.left(idx);
name += ".st";
}
// The original did tests for the file in the different asset paths,
// which aren't needed in ScummVM, so just return full name
return name;
}
bool CResourceKey::scanForFile() const {
return g_vm->_filesManager->scanForFile(_value);
}
FileType CResourceKey::fileTypeSuffix() const {
return _value.fileTypeSuffix();
}
ImageType CResourceKey::imageTypeSuffix() const {
return _value.imageTypeSuffix();
}
} // End of namespace Titanic

View File

@@ -0,0 +1,79 @@
/* 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/>.
*
*/
#ifndef TITANIC_RESOURCE_KEY_H
#define TITANIC_RESOURCE_KEY_H
#include "titanic/support/string.h"
#include "titanic/core/saveable_object.h"
namespace Titanic {
class CResourceKey: public CSaveableObject {
private:
CString _key;
CString _value;
void setValue(const CString &name);
public:
CLASSDEF;
CResourceKey() {}
CResourceKey(const CString &name) { setValue(name); }
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
/**
* Return the key
*/
const CString &getString() const { return _key; }
/**
* Extracts a filename from the resource key
*/
CString getFilename() const;
/**
* Scans for a file with a matching name
*/
bool scanForFile() const;
/**
* Returns the type of the resource based on it's extension
*/
FileType fileTypeSuffix() const;
/**
* Returns the type of the resource based on it's extension
*/
ImageType imageTypeSuffix() const;
};
} // End of namespace Titanic
#endif /* TITANIC_RESOURCE_KEY_H */

View File

@@ -0,0 +1,197 @@
/* 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 "titanic/core/room_item.h"
namespace Titanic {
EMPTY_MESSAGE_MAP(CRoomItem, CNamedItem);
CRoomItem::CRoomItem() : CNamedItem(), _roomNumber(0),
_roomDimensionX(0.0), _roomDimensionY(0.0) {
}
void CRoomItem::save(SimpleFile *file, int indent) {
file->writeNumberLine(3, indent);
file->writeQuotedLine("Exit Movies", indent);
_exitMovieKey.save(file, indent);
file->writeQuotedLine("Room dimensions x 1000", indent);
file->writeNumberLine((int)(_roomDimensionX * 1000.0), indent + 1);
file->writeNumberLine((int)(_roomDimensionY * 1000.0), indent + 1);
file->writeQuotedLine("Transition Movie", indent);
_transitionMovieKey.save(file, indent);
file->writeQuotedLine("Movie Clip list", indent);
_clipList.save(file, indent + 1);
file->writeQuotedLine("Room Rect", indent);
file->writeNumberLine(_roomRect.left, indent + 1);
file->writeNumberLine(_roomRect.top, indent + 1);
file->writeNumberLine(_roomRect.right, indent + 1);
file->writeNumberLine(_roomRect.bottom, indent + 1);
file->writeQuotedLine("Room Number", indent);
file->writeNumberLine(_roomNumber, indent);
CNamedItem::save(file, indent);
}
void CRoomItem::load(SimpleFile *file) {
int val = file->readNumber();
switch (val) {
case 3:
// Read exit movie
file->readBuffer();
_exitMovieKey.load(file);
// Intentional fall-through
case 2:
// Read room dimensions
file->readBuffer();
_roomDimensionX = (double)file->readNumber() / 1000.0;
_roomDimensionY = (double)file->readNumber() / 1000.0;
// Intentional fall-through
case 1:
// Read transition movie key and clip list
file->readBuffer();
_transitionMovieKey.load(file);
file->readBuffer();
_clipList.load(file);
postLoad();
// Intentional fall-through
case 0:
// Read room rect
file->readBuffer();
_roomRect.left = file->readNumber();
_roomRect.top = file->readNumber();
_roomRect.right = file->readNumber();
_roomRect.bottom = file->readNumber();
file->readBuffer();
_roomNumber = file->readNumber();
break;
default:
break;
}
CNamedItem::load(file);
}
void CRoomItem::postLoad() {
if (!_exitMovieKey.getFilename().empty())
return;
CString name = _transitionMovieKey.getFilename();
if (name.right(7) == "nav.avi") {
_exitMovieKey = CResourceKey(name.left(name.size() - 7) + "exit.avi");
}
}
void CRoomItem::calcNodePosition(const Point &nodePos, double &xVal, double &yVal) const {
xVal = yVal = 0.0;
if (_roomDimensionX >= 0.0 && _roomDimensionY >= 0.0) {
xVal = _roomRect.width() / _roomDimensionX;
yVal = _roomRect.height() / _roomDimensionY;
xVal = (nodePos.x - _roomRect.left) / xVal;
yVal = (nodePos.y - _roomRect.top) / yVal;
}
}
int CRoomItem::getScriptId() const {
CString name = getName();
if (name == "1stClassLobby")
return 130;
else if (name == "1stClassRestaurant")
return 132;
else if (name == "1stClassState")
return 131;
else if (name == "2ndClassLobby")
return 128;
else if (name == "Bar")
return 112;
else if (name == "BottomOfWell")
return 108;
else if (name == "Bridge")
return 121;
else if (name == "Dome")
return 122;
else if (name == "Home")
return 100;
else if (name == "Lift")
return 103;
else if (name == "MusicRoom")
return 117;
else if (name == "MusicRoomLobby")
return 118;
else if (name == "ParrotLobby")
return 111;
else if (name == "Pellerator")
return 104;
else if (name == "PromenadeDeck")
return 114;
else if (name == "SculptureChamber")
return 116;
else if (name == "secClassState")
return 129;
else if (name == "ServiceElevator")
return 102;
else if (name == "SGTLeisure")
return 125;
else if (name == "SGTLittleLift")
return 105;
else if (name == "SgtLobby")
return 124;
else if (name == "SGTState")
return 126;
else if (name == "Titania")
return 123;
else if (name == "TopOfWell")
return 107;
else if (name == "EmbLobby" || name == "MoonEmbLobby")
return 110;
else if (name == "CreatorsChamber" || name == "CreatorsChamberOn")
return 113;
else if (name == "Arboretum" || name == "FrozenArboretum")
return 115;
else if (name == "BilgeRoom" || name == "BilgeRoomWith")
return 101;
return 0;
}
CResourceKey CRoomItem::getTransitionMovieKey() {
_transitionMovieKey.scanForFile();
return _transitionMovieKey;
}
CResourceKey CRoomItem::getExitMovieKey() {
return _exitMovieKey;
}
} // End of namespace Titanic

View File

@@ -0,0 +1,83 @@
/* 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/>.
*
*/
#ifndef TITANIC_ROOM_ITEM_H
#define TITANIC_ROOM_ITEM_H
#include "titanic/support/rect.h"
#include "titanic/core/list.h"
#include "titanic/support/movie_clip.h"
#include "titanic/core/named_item.h"
#include "titanic/core/resource_key.h"
namespace Titanic {
class CRoomItem : public CNamedItem {
DECLARE_MESSAGE_MAP;
private:
/**
* Handles post-load processing
*/
void postLoad();
public:
Rect _roomRect;
CMovieClipList _clipList;
int _roomNumber;
CResourceKey _transitionMovieKey;
CResourceKey _exitMovieKey;
double _roomDimensionX, _roomDimensionY;
public:
CLASSDEF;
CRoomItem();
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
/**
* Return a movie clip for the room by name
*/
CMovieClip *findClip(const CString &name) { return _clipList.findByName(name); }
/**
* Calculates the positioning of a node within the overall room
*/
void calcNodePosition(const Point &nodePos, double &xVal, double &yVal) const;
/**
* Get the TrueTalk script Id associated with the room
*/
int getScriptId() const;
CResourceKey getTransitionMovieKey();
CResourceKey getExitMovieKey();
};
} // End of namespace Titanic
#endif /* TITANIC_ROOM_ITEM_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,113 @@
/* 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/>.
*
*/
#ifndef TITANIC_SAVEABLE_OBJECT_H
#define TITANIC_SAVEABLE_OBJECT_H
#include "common/scummsys.h"
#include "common/array.h"
#include "common/hash-str.h"
#include "common/list.h"
#include "titanic/support/simple_file.h"
namespace Titanic {
class CSaveableObject;
class ClassDef {
public:
const char *_className;
ClassDef *_parent;
public:
ClassDef(const char *className, ClassDef *parent) :
_className(className), _parent(parent) {}
virtual ~ClassDef() {}
virtual CSaveableObject *create();
};
template<typename T>
class TypeTemplate : public ClassDef {
public:
TypeTemplate(const char *className, ClassDef *parent) :
ClassDef(className, parent) {}
CSaveableObject *create() override { return new T(); }
};
#define CLASSDEF \
static ClassDef *_type; \
ClassDef *getType() const override { return _type; }
class CSaveableObject {
typedef CSaveableObject *(*CreateFunction)();
private:
typedef Common::List<ClassDef *> ClassDefList;
typedef Common::HashMap<Common::String, CreateFunction> ClassListMap;
static ClassDefList *_classDefs;
static ClassListMap *_classList;
public:
/**
* Sets up the list of saveable object classes
*/
static void initClassList();
/**
* Free the list of saveable object classes
*/
static void freeClassList();
/**
* Creates a new instance of a saveable object class
*/
static CSaveableObject *createInstance(const Common::String &name);
public:
static ClassDef *_type; \
virtual ClassDef *getType() const { return _type; }
virtual ~CSaveableObject() {}
bool isInstanceOf(const ClassDef *classDef) const;
/**
* Save the data for the class to file
*/
virtual void save(SimpleFile *file, int indent);
/**
* Load the data for the class from file
*/
virtual void load(SimpleFile *file);
/**
* Write out a header definition for the class to file
* prior to saving the actual data for the class
*/
virtual void saveHeader(SimpleFile *file, int indent);
/**
* Writes out a footer for the class after it's data has
* been written to file
*/
virtual void saveFooter(SimpleFile *file, int indent);
};
} // End of namespace Titanic
#endif /* TITANIC_SAVEABLE_OBJECT_H */

View File

@@ -0,0 +1,38 @@
/* 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 "titanic/core/static_image.h"
namespace Titanic {
EMPTY_MESSAGE_MAP(CStaticImage, CGameObject);
void CStaticImage::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
CGameObject::save(file, indent);
}
void CStaticImage::load(SimpleFile *file) {
file->readNumber();
CGameObject::load(file);
}
} // End of namespace Titanic

View File

@@ -0,0 +1,47 @@
/* 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/>.
*
*/
#ifndef TITANIC_STATIC_IMAGE_H
#define TITANIC_STATIC_IMAGE_H
#include "titanic/core/game_object.h"
namespace Titanic {
class CStaticImage : public CGameObject {
DECLARE_MESSAGE_MAP;
public:
CLASSDEF;
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
};
} // End of namespace Titanic
#endif /* TITANIC_STATIC_IMAGE_H */

View File

@@ -0,0 +1,287 @@
/* 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 "titanic/core/tree_item.h"
#include "titanic/core/dont_save_file_item.h"
#include "titanic/core/file_item.h"
#include "titanic/core/game_object.h"
#include "titanic/core/game_object_desc_item.h"
#include "titanic/core/link_item.h"
#include "titanic/core/mail_man.h"
#include "titanic/core/named_item.h"
#include "titanic/core/node_item.h"
#include "titanic/core/project_item.h"
#include "titanic/core/view_item.h"
#include "titanic/core/room_item.h"
#include "titanic/pet_control/pet_control.h"
#include "titanic/game_manager.h"
#include "titanic/game/placeholder/place_holder.h"
namespace Titanic {
EMPTY_MESSAGE_MAP(CTreeItem, CMessageTarget);
CTreeItem::CTreeItem() : _parent(nullptr), _firstChild(nullptr),
_nextSibling(nullptr), _priorSibling(nullptr), _field14(0) {
}
void CTreeItem::dump(int indent) {
CString line = dumpItem(indent);
debug("%s", line.c_str());
CTreeItem *item = getFirstChild();
while (item) {
item->dump(indent + 1);
item = item->getNextSibling();
}
}
CString CTreeItem::dumpItem(int indent) const {
CString result;
for (int idx = 0; idx < indent; ++idx)
result += '\t';
result += getType()->_className;
return result;
}
void CTreeItem::save(SimpleFile *file, int indent) {
file->writeNumberLine(0, indent);
CMessageTarget::save(file, indent);
}
void CTreeItem::load(SimpleFile *file) {
file->readNumber();
CMessageTarget::load(file);
}
bool CTreeItem::isFileItem() const {
return isInstanceOf(CFileItem::_type);
}
bool CTreeItem::isRoomItem() const {
return isInstanceOf(CRoomItem::_type);
}
bool CTreeItem::isNodeItem() const {
return isInstanceOf(CNodeItem::_type);
}
bool CTreeItem::isViewItem() const {
return isInstanceOf(CViewItem::_type);
}
bool CTreeItem::isLinkItem() const {
return isInstanceOf(CLinkItem::_type);
}
bool CTreeItem::isPlaceHolderItem() const {
return isInstanceOf(CPlaceHolder::_type);
}
bool CTreeItem::isNamedItem() const {
return isInstanceOf(CNamedItem::_type);
}
bool CTreeItem::isGameObject() const {
return isInstanceOf(CGameObject::_type);
}
bool CTreeItem::isGameObjectDescItem() const {
return isInstanceOf(CGameObjectDescItem::_type);
}
CGameManager *CTreeItem::getGameManager() const {
return _parent ? _parent->getGameManager() : nullptr;
}
CProjectItem *CTreeItem::getRoot() const {
CTreeItem *parent = getParent();
if (parent) {
do {
parent = parent->getParent();
} while (parent->getParent());
}
return dynamic_cast<CProjectItem *>(parent);
}
CTreeItem *CTreeItem::getLastSibling() {
CTreeItem *item = this;
while (item->getNextSibling())
item = item->getNextSibling();
return item;
}
CTreeItem *CTreeItem::getLastChild() const {
if (!_firstChild)
return nullptr;
return _firstChild->getLastSibling();
}
CTreeItem *CTreeItem::scan(CTreeItem *item) const {
if (_firstChild)
return _firstChild;
const CTreeItem *treeItem = this;
while (treeItem != item) {
if (treeItem->_nextSibling)
return treeItem->_nextSibling;
treeItem = treeItem->_parent;
if (!treeItem)
break;
}
return nullptr;
}
CTreeItem *CTreeItem::findChildInstanceOf(ClassDef *classDef) const {
for (CTreeItem *treeItem = _firstChild; treeItem; treeItem = treeItem->getNextSibling()) {
if (treeItem->isInstanceOf(classDef))
return treeItem;
}
return nullptr;
}
CTreeItem *CTreeItem::findNextInstanceOf(ClassDef *classDef, CTreeItem *startItem) const {
CTreeItem *treeItem = startItem ? startItem->getNextSibling() : getFirstChild();
for (; treeItem; treeItem = treeItem->getNextSibling()) {
if (treeItem->isInstanceOf(classDef))
return treeItem;
}
return nullptr;
}
void CTreeItem::addUnder(CTreeItem *newParent) {
if (newParent->_firstChild)
addSibling(newParent->_firstChild->getLastSibling());
else
setParent(newParent);
}
void CTreeItem::setParent(CTreeItem *newParent) {
_parent = newParent;
_priorSibling = nullptr;
_nextSibling = newParent->_firstChild;
if (newParent->_firstChild)
newParent->_firstChild->_priorSibling = this;
newParent->_firstChild = this;
}
void CTreeItem::addSibling(CTreeItem *item) {
_priorSibling = item;
_nextSibling = item->_nextSibling;
_parent = item->_parent;
if (item->_nextSibling)
item->_nextSibling->_priorSibling = this;
item->_nextSibling = this;
}
void CTreeItem::moveUnder(CTreeItem *newParent) {
if (newParent) {
detach();
addUnder(newParent);
}
}
void CTreeItem::destroyAll() {
destroyChildren();
detach();
delete this;
}
int CTreeItem::destroyChildren() {
if (!_firstChild)
return 0;
CTreeItem *item = _firstChild, *child, *nextSibling;
int total = 0;
do {
child = item->_firstChild;
nextSibling = item->_nextSibling;
if (child)
total += item->destroyChildren();
item->detach();
delete item;
++total;
} while ((item = nextSibling) != nullptr);
return total;
}
void CTreeItem::detach() {
// Delink this item from any prior and/or next siblings
if (_priorSibling)
_priorSibling->_nextSibling = _nextSibling;
if (_nextSibling)
_nextSibling->_priorSibling = _priorSibling;
if (_parent && _parent->_firstChild == this)
_parent->_firstChild = _nextSibling;
_priorSibling = _nextSibling = _parent = nullptr;
}
void CTreeItem::attach(CTreeItem *item) {
_nextSibling = item;
_priorSibling = item->_priorSibling;
_parent = item->_parent;
if (item->_priorSibling)
item->_priorSibling->_nextSibling = this;
item->_priorSibling = this;
if (item->_parent && !item->_parent->_firstChild)
item->_parent->_firstChild = this;
}
CNamedItem *CTreeItem::findByName(const CString &name, bool subMatch) {
CString nameLower = name;
nameLower.toLowercase();
for (CTreeItem *treeItem = this; treeItem; treeItem = treeItem->scan(this)) {
CString itemName = treeItem->getName();
itemName.toLowercase();
if (subMatch) {
if (!itemName.left(nameLower.size()).compareTo(nameLower))
return dynamic_cast<CNamedItem *>(treeItem);
} else {
if (!itemName.compareTo(nameLower))
return dynamic_cast<CNamedItem *>(treeItem);
}
}
return nullptr;
}
} // End of namespace Titanic

View File

@@ -0,0 +1,264 @@
/* 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/>.
*
*/
#ifndef TITANIC_TREE_ITEM_H
#define TITANIC_TREE_ITEM_H
#include "titanic/core/message_target.h"
#include "titanic/support/simple_file.h"
namespace Titanic {
class CGameManager;
class CMovieClipList;
class CNamedItem;
class CProjectItem;
class CScreenManager;
class CViewItem;
class CTreeItem: public CMessageTarget {
friend class CMessage;
DECLARE_MESSAGE_MAP;
private:
CTreeItem *_parent;
CTreeItem *_nextSibling;
CTreeItem *_priorSibling;
CTreeItem *_firstChild;
int _field14;
public:
CLASSDEF;
CTreeItem();
/**
* Dump the item and any of it's children
*/
void dump(int indent);
/**
* Dump the item
*/
virtual CString dumpItem(int indent) const;
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
/**
* Get the game manager for the project
*/
virtual CGameManager *getGameManager() const;
/**
* Returns true if the item is a file item
*/
virtual bool isFileItem() const;
/**
* Returns true if the item is a room item
*/
virtual bool isRoomItem() const;
/**
* Returns true if the item is a node item
*/
virtual bool isNodeItem() const;
/**
* Returns true if the item is a view item
*/
virtual bool isViewItem() const;
/**
* Returns true if the item is a link item
*/
virtual bool isLinkItem() const;
/**
* Returns true if the item is a placeholder item
*/
virtual bool isPlaceHolderItem() const;
/**
* Returns true if the item is a named item
*/
virtual bool isNamedItem() const;
/**
* Returns true if the item is a game object
*/
virtual bool isGameObject() const;
/**
* Returns true if the item is a game object desc item
*/
virtual bool isGameObjectDescItem() const;
/**
* Gets the name of the item, if any
*/
virtual const CString getName() const { return CString(); }
/**
* Returns true if the item's name matches a passed name
*/
virtual bool isEquals(const CString &name, bool startsWith = false) const{ return false; }
/**
* Compares the name of the item to a passed name
*/
virtual int compareTo(const CString &name, int maxLen = 0) const { return false; }
/**
* Returns the clip list, if any, associated with the item
*/
virtual const CMovieClipList *getMovieClips() const { return nullptr; }
/**
* Returns true if the given item connects to another specified view
*/
virtual bool connectsTo(CViewItem *destView) const { return false; }
/**
* Allows the item to draw itself
*/
virtual void draw(CScreenManager *screenManager) {}
/**
* Gets the bounds occupied by the item
*/
virtual Rect getBounds() const { return Rect(); }
/**
* Free up any surface the object used
*/
virtual void freeSurface() {}
/**
* Get the parent for the given item
*/
CTreeItem *getParent() const { return _parent; }
/**
* Jumps up through the parents to find the root item
*/
CProjectItem *getRoot() const;
/**
* Get the next sibling
*/
CTreeItem *getNextSibling() const { return _nextSibling; }
/**
* Get the prior sibling
*/
CTreeItem *getPriorSibling() const { return _priorSibling; }
/**
* Get the last sibling of this sibling
*/
CTreeItem *getLastSibling();
/**
* Get the first child of the item, if any
*/
CTreeItem *getFirstChild() const { return _firstChild; }
/**
* Get the last child of the item, if any
*/
CTreeItem *getLastChild() const;
/**
* Given all the recursive children of the tree item, gives the next
* item in sequence to the passed starting item
*/
CTreeItem *scan(CTreeItem *item) const;
/**
* Find the first child item that is of a given type
*/
CTreeItem *findChildInstanceOf(ClassDef *classDef) const;
/**
* Find the next sibling item that is of the given type
*/
CTreeItem *findNextInstanceOf(ClassDef *classDef, CTreeItem *startItem) const;
/**
* Adds the item under another tree item
*/
void addUnder(CTreeItem *newParent);
/**
* Sets the parent for the item
*/
void setParent(CTreeItem *newParent);
/**
* Adds the item as a sibling of another item
*/
void addSibling(CTreeItem *item);
/**
* Moves the tree item to be under another parent
*/
void moveUnder(CTreeItem *newParent);
/**
* Destroys both the item as well as any of it's children
*/
void destroyAll();
/**
* Destroys all child tree items under this one.
* @returns Total number of tree items recursively removed
*/
int destroyChildren();
/**
* Detach the tree item from any other associated tree items
*/
void detach();
/**
* Attaches a tree item to a new node
*/
void attach(CTreeItem *item);
/**
* Finds a tree item by name
* @param name Name to find
* @param subMatch If false, does an exact name match.
* If false, matches any item that starts with the given name
*/
CNamedItem *findByName(const CString &name, bool subMatch = false);
};
} // End of namespace Titanic
#endif /* TITANIC_TREE_ITEM_H */

View File

@@ -0,0 +1,58 @@
/* 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 "titanic/core/turn_on_object.h"
namespace Titanic {
BEGIN_MESSAGE_MAP(CTurnOnObject, CBackground)
ON_MESSAGE(MouseButtonDownMsg)
ON_MESSAGE(MouseButtonUpMsg)
END_MESSAGE_MAP()
CTurnOnObject::CTurnOnObject() : CBackground(), _msgName("NULL") {
}
void CTurnOnObject::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
file->writeQuotedLine(_msgName, indent);
CBackground::save(file, indent);
}
void CTurnOnObject::load(SimpleFile *file) {
file->readNumber();
_msgName = file->readString();
CBackground::load(file);
}
bool CTurnOnObject::MouseButtonDownMsg(CMouseButtonDownMsg *msg) {
return true;
}
bool CTurnOnObject::MouseButtonUpMsg(CMouseButtonUpMsg *msg) {
CTurnOn turnOn;
turnOn.execute(_msgName);
return true;
}
} // End of namespace Titanic

View File

@@ -0,0 +1,52 @@
/* 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/>.
*
*/
#ifndef TITANIC_TURN_ON_OBJECT_H
#define TITANIC_TURN_ON_OBJECT_H
#include "titanic/core/background.h"
namespace Titanic {
class CTurnOnObject : public CBackground {
DECLARE_MESSAGE_MAP;
bool MouseButtonDownMsg(CMouseButtonDownMsg *msg);
bool MouseButtonUpMsg(CMouseButtonUpMsg *msg);
protected:
CString _msgName;
public:
CLASSDEF;
CTurnOnObject();
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
};
} // End of namespace Titanic
#endif /* TITANIC_TURN_ON_OBJECT_H */

View File

@@ -0,0 +1,59 @@
/* 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 "titanic/core/turn_on_play_sound.h"
namespace Titanic {
BEGIN_MESSAGE_MAP(CTurnOnPlaySound, CTurnOnObject)
ON_MESSAGE(MouseButtonUpMsg)
END_MESSAGE_MAP()
CTurnOnPlaySound::CTurnOnPlaySound() : CTurnOnObject(),
_soundName("NULL"), _soundVolume(80), _soundVal3(0) {
}
void CTurnOnPlaySound::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
file->writeQuotedLine(_soundName, indent);
file->writeNumberLine(_soundVolume, indent);
file->writeNumberLine(_soundVal3, indent);
CTurnOnObject::save(file, indent);
}
void CTurnOnPlaySound::load(SimpleFile *file) {
file->readNumber();
_soundName = file->readString();
_soundVolume = file->readNumber();
_soundVal3 = file->readNumber();
CTurnOnObject::load(file);
}
bool CTurnOnPlaySound::MouseButtonUpMsg(CMouseButtonUpMsg *msg) {
if (_soundName != "NULL")
playSound(_soundName, _soundVolume, _soundVal3);
return CTurnOnObject::MouseButtonUpMsg(msg);
}
} // End of namespace Titanic

View File

@@ -0,0 +1,53 @@
/* 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/>.
*
*/
#ifndef TITANIC_TURN_ON_PLAY_SOUND_H
#define TITANIC_TURN_ON_PLAY_SOUND_H
#include "titanic/core/turn_on_object.h"
namespace Titanic {
class CTurnOnPlaySound : public CTurnOnObject {
DECLARE_MESSAGE_MAP;
bool MouseButtonUpMsg(CMouseButtonUpMsg *msg);
private:
CString _soundName;
int _soundVolume;
int _soundVal3;
public:
CLASSDEF;
CTurnOnPlaySound();
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
};
} // End of namespace Titanic
#endif /* TITANIC_TURN_ON_PLAY_SOUND_H */

View File

@@ -0,0 +1,81 @@
/* 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 "titanic/core/turn_on_turn_off.h"
namespace Titanic {
BEGIN_MESSAGE_MAP(CTurnOnTurnOff, CBackground)
ON_MESSAGE(TurnOn)
ON_MESSAGE(TurnOff)
END_MESSAGE_MAP()
CTurnOnTurnOff::CTurnOnTurnOff() : CBackground(), _startFrameOn(0),
_endFrameOn(0), _startFrameOff(0), _endFrameOff(0), _isOn(false) {
}
void CTurnOnTurnOff::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
file->writeNumberLine(_startFrameOn, indent);
file->writeNumberLine(_endFrameOn, indent);
file->writeNumberLine(_startFrameOff, indent);
file->writeNumberLine(_endFrameOff, indent);
file->writeNumberLine(_isOn, indent);
CBackground::save(file, indent);
}
void CTurnOnTurnOff::load(SimpleFile *file) {
file->readNumber();
_startFrameOn = file->readNumber();
_endFrameOn = file->readNumber();
_startFrameOff = file->readNumber();
_endFrameOff = file->readNumber();
_isOn = file->readNumber();
CBackground::load(file);
}
bool CTurnOnTurnOff::TurnOn(CTurnOn *msg) {
if (!_isOn) {
if (_isBlocking)
playMovie(_startFrameOn, _endFrameOn, MOVIE_WAIT_FOR_FINISH);
else
playMovie(_startFrameOn, _endFrameOn, MOVIE_NOTIFY_OBJECT);
_isOn = true;
}
return true;
}
bool CTurnOnTurnOff::TurnOff(CTurnOff *msg) {
if (_isOn) {
if (_isBlocking)
playMovie(_startFrameOff, _endFrameOff, MOVIE_WAIT_FOR_FINISH);
else
playMovie(_startFrameOff, _endFrameOff, MOVIE_NOTIFY_OBJECT);
_isOn = false;
}
return true;
}
} // End of namespace Titanic

View File

@@ -0,0 +1,56 @@
/* 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/>.
*
*/
#ifndef TITANIC_TURN_ON_TURN_OFF_H
#define TITANIC_TURN_ON_TURN_OFF_H
#include "titanic/core/background.h"
namespace Titanic {
class CTurnOnTurnOff : public CBackground {
DECLARE_MESSAGE_MAP;
bool TurnOn(CTurnOn *msg);
bool TurnOff(CTurnOff *msg);
private:
int _startFrameOn;
int _endFrameOn;
int _startFrameOff;
int _endFrameOff;
bool _isOn;
public:
CLASSDEF;
CTurnOnTurnOff();
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
};
} // End of namespace Titanic
#endif /* TITANIC_TURN_ON_TURN_OFF_H */

View File

@@ -0,0 +1,437 @@
/* 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 "titanic/core/view_item.h"
#include "titanic/core/project_item.h"
#include "titanic/core/room_item.h"
#include "titanic/events.h"
#include "titanic/game_manager.h"
#include "titanic/messages/messages.h"
#include "titanic/pet_control/pet_control.h"
#include "titanic/support/screen_manager.h"
#include "titanic/titanic.h"
namespace Titanic {
BEGIN_MESSAGE_MAP(CViewItem, CNamedItem)
ON_MESSAGE(MouseButtonDownMsg)
ON_MESSAGE(MouseButtonUpMsg)
ON_MESSAGE(MouseDoubleClickMsg)
ON_MESSAGE(MouseMoveMsg)
ON_MESSAGE(MovementMsg)
END_MESSAGE_MAP()
CViewItem::CViewItem() : CNamedItem() {
Common::fill(&_buttonUpTargets[0], &_buttonUpTargets[4], (CTreeItem *)nullptr);
_field24 = 0;
_angle = 0.0;
_viewNumber = 0;
setAngle(0.0);
}
void CViewItem::setAngle(double angle) {
_angle = angle;
_viewPos.x = (int16)(cos(_angle) * 30.0);
_viewPos.y = (int16)(sin(_angle) * -30.0);
}
void CViewItem::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
_resourceKey.save(file, indent);
file->writeQuotedLine("V", indent);
file->writeFloatLine(_angle, indent + 1);
file->writeNumberLine(_viewNumber, indent + 1);
CNamedItem::save(file, indent);
}
void CViewItem::load(SimpleFile *file) {
int val = file->readNumber();
switch (val) {
case 1:
_resourceKey.load(file);
// Intentional fall-through
default:
file->readBuffer();
setAngle(file->readFloat());
_viewNumber = file->readNumber();
break;
}
CNamedItem::load(file);
}
bool CViewItem::getResourceKey(CResourceKey *key) {
*key = _resourceKey;
CString filename = key->getFilename();
return !filename.empty();
}
void CViewItem::leaveView(CViewItem *newView) {
// Only do the processing if we've been passed a view, and it's not the same
if (newView && newView != this) {
CLeaveViewMsg viewMsg(this, newView);
viewMsg.execute(this, nullptr, MSGFLAG_SCAN);
CNodeItem *oldNode = findNode();
CNodeItem *newNode = newView->findNode();
if (newNode != oldNode) {
CLeaveNodeMsg nodeMsg(oldNode, newNode);
nodeMsg.execute(oldNode, nullptr, MSGFLAG_SCAN);
CRoomItem *oldRoom = oldNode->findRoom();
CRoomItem *newRoom = newNode->findRoom();
if (newRoom != oldRoom) {
CGameManager *gm = getGameManager();
if (gm)
gm->roomChange();
CLeaveRoomMsg roomMsg(oldRoom, newRoom);
roomMsg.execute(oldRoom, nullptr, MSGFLAG_SCAN);
}
}
}
}
void CViewItem::preEnterView(CViewItem *newView) {
// Only do the processing if we've been passed a view, and it's not the same
if (newView && newView != this) {
CPreEnterViewMsg viewMsg(this, newView);
viewMsg.execute(newView, nullptr, MSGFLAG_SCAN);
CNodeItem *oldNode = findNode();
CNodeItem *newNode = newView->findNode();
if (newNode != oldNode) {
CPreEnterNodeMsg nodeMsg(oldNode, newNode);
nodeMsg.execute(newNode, nullptr, MSGFLAG_SCAN);
CRoomItem *oldRoom = oldNode->findRoom();
CRoomItem *newRoom = newNode->findRoom();
if (newRoom != oldRoom) {
CPreEnterRoomMsg roomMsg(oldRoom, newRoom);
roomMsg.execute(newRoom, nullptr, MSGFLAG_SCAN);
}
}
}
}
void CViewItem::enterView(CViewItem *newView) {
// Only do the processing if we've been passed a view, and it's not the same
if (newView && newView != this) {
CEnterViewMsg viewMsg(this, newView);
viewMsg.execute(newView, nullptr, MSGFLAG_SCAN);
CNodeItem *oldNode = findNode();
CNodeItem *newNode = newView->findNode();
if (newNode != oldNode) {
CEnterNodeMsg nodeMsg(oldNode, newNode);
nodeMsg.execute(newNode, nullptr, MSGFLAG_SCAN);
CRoomItem *oldRoom = oldNode->findRoom();
CRoomItem *newRoom = newNode->findRoom();
CPetControl *petControl = nullptr;
if (newRoom != nullptr) {
petControl = newRoom->getRoot()->getPetControl();
if (petControl)
petControl->enterNode(newNode);
}
if (newRoom != oldRoom) {
CEnterRoomMsg roomMsg(oldRoom, newRoom);
roomMsg.execute(newRoom, nullptr, MSGFLAG_SCAN);
if (petControl)
petControl->enterRoom(newRoom);
}
}
// WORKAROUND: Do a dummy mouse movement, to allow for the correct cursor
// to be set for the current position in the new view
CMouseMoveMsg moveMsg(g_vm->_events->getMousePos(), 0);
newView->MouseMoveMsg(&moveMsg);
}
}
CLinkItem *CViewItem::findLink(CViewItem *newView) {
for (CTreeItem *treeItem = getFirstChild(); treeItem;
treeItem = treeItem->scan(this)) {
CLinkItem *link = dynamic_cast<CLinkItem *>(treeItem);
if (link && link->connectsTo(newView))
return link;
}
return nullptr;
}
bool CViewItem::MouseButtonDownMsg(CMouseButtonDownMsg *msg) {
if (msg->_buttons & MB_LEFT) {
if (!handleMouseMsg(msg, true)) {
CGameManager *gm = getGameManager();
if (gm->isntTransitioning()) {
findNode()->findRoom();
CLinkItem *linkItem = dynamic_cast<CLinkItem *>(
findChildInstanceOf(CLinkItem::_type));
while (linkItem) {
if (linkItem->_bounds.contains(msg->_mousePos)) {
gm->_gameState.triggerLink(linkItem);
return true;
}
linkItem = dynamic_cast<CLinkItem *>(
findNextInstanceOf(CLinkItem::_type, linkItem));
}
handleMouseMsg(msg, false);
}
}
}
return true;
}
bool CViewItem::MouseButtonUpMsg(CMouseButtonUpMsg *msg) {
if (msg->_buttons & MB_LEFT)
handleMouseMsg(msg, false);
return true;
}
bool CViewItem::MouseDoubleClickMsg(CMouseDoubleClickMsg *msg) {
if (msg->_buttons & MB_LEFT)
handleMouseMsg(msg, false);
return true;
}
bool CViewItem::MouseMoveMsg(CMouseMoveMsg *msg) {
CScreenManager *screenManager = CScreenManager::_screenManagerPtr;
uint changeCount = screenManager->_mouseCursor->getChangeCount();
if (handleMouseMsg(msg, true)) {
// If the cursor hasn't been set in the call to handleMouseMsg,
// then reset it back to the default arrow cursor
if (screenManager->_mouseCursor->getChangeCount() == changeCount)
screenManager->_mouseCursor->setCursor(CURSOR_ARROW);
} else {
// Iterate through each link item, and if any is highlighted,
// change the mouse cursor to the designated cursor for the item
CTreeItem *treeItem = getFirstChild();
while (treeItem) {
CLinkItem *linkItem = dynamic_cast<CLinkItem *>(treeItem);
if (linkItem && linkItem->_bounds.contains(msg->_mousePos)) {
screenManager->_mouseCursor->setCursor(linkItem->_cursorId);
return true;
}
treeItem = treeItem->getNextSibling();
}
if (!handleMouseMsg(msg, false) || (screenManager->_mouseCursor->getChangeCount() == changeCount))
screenManager->_mouseCursor->setCursor(CURSOR_ARROW);
}
return true;
}
bool CViewItem::handleMouseMsg(CMouseMsg *msg, bool flag) {
CMouseButtonUpMsg *upMsg = dynamic_cast<CMouseButtonUpMsg *>(msg);
if (upMsg) {
handleButtonUpMsg(upMsg);
return true;
}
Common::Array<CGameObject *> gameObjects;
for (CTreeItem *treeItem = scan(this); treeItem; treeItem = treeItem->scan(this)) {
CGameObject *gameObject = dynamic_cast<CGameObject *>(treeItem);
if (gameObject) {
if (gameObject->checkPoint(msg->_mousePos, false, true) &&
(!flag || !gameObject->_handleMouseFlag)) {
if (gameObjects.size() < 256)
gameObjects.push_back(gameObject);
}
}
}
const CMouseMoveMsg *moveMsg = dynamic_cast<const CMouseMoveMsg *>(msg);
if (moveMsg) {
if (gameObjects.size() == 0)
return false;
for (int idx = (int)gameObjects.size() - 1; idx >= 0; --idx) {
if (gameObjects[idx]->_cursorId != CURSOR_IGNORE) {
CScreenManager::_screenManagerPtr->_mouseCursor->setCursor(gameObjects[idx]->_cursorId);
break;
}
}
}
if (gameObjects.size() == 0)
return false;
bool result = false;
for (int idx = (int)gameObjects.size() - 1; idx >= 0; --idx) {
if (msg->execute(gameObjects[idx])) {
if (msg->isButtonDownMsg())
_buttonUpTargets[msg->_buttons >> 1] = gameObjects[idx];
return true;
}
if (CMouseMsg::isSupportedBy(gameObjects[idx]))
result = true;
}
return result;
}
void CViewItem::handleButtonUpMsg(CMouseButtonUpMsg *msg) {
CTreeItem *&target = _buttonUpTargets[msg->_buttons >> 1];
if (target) {
msg->execute(target);
target = nullptr;
}
}
void CViewItem::getPosition(double &xp, double &yp, double &zp) {
// Get the position of the owning node within the room
CNodeItem *node = findNode();
node->getPosition(xp, yp, zp);
// Adjust the position slightly to compensate for view's angle,
// ensuring different direction views don't all have the same position
xp += cos(_angle) * 0.5;
yp -= sin(_angle) * 0.5;
}
CString CViewItem::getFullViewName() const {
CNodeItem *node = findNode();
CRoomItem *room = node->findRoom();
return CString::format("%s.%s.%s", room->getName().c_str(),
node->getName().c_str(), getName().c_str());
}
CString CViewItem::getNodeViewName() const {
CNodeItem *node = findNode();
return CString::format("%s.%s", node->getName().c_str(), getName().c_str());
}
bool CViewItem::MovementMsg(CMovementMsg *msg) {
Point pt;
bool foundPt = false;
int quadrant;
// First allow any child objects to handle it
for (CTreeItem *treeItem = getFirstChild(); treeItem;
treeItem = treeItem->scan(this)) {
if (msg->execute(treeItem, nullptr, 0))
return true;
}
if (msg->_posToUse.x != 0 || msg->_posToUse.y != 0) {
pt = msg->_posToUse;
foundPt = true;
} else {
// Iterate through the view's contents to find a link or item
// with the appropriate movement action
for (CTreeItem *treeItem = getFirstChild(); treeItem;
treeItem = treeItem->scan(this)) {
CLinkItem *link = dynamic_cast<CLinkItem *>(treeItem);
CGameObject *gameObj = dynamic_cast<CGameObject *>(treeItem);
if (link) {
// Skip links that aren't for the desired direction
if (link->getMovement() != msg->_movement)
continue;
for (quadrant = Q_CENTER; quadrant <= Q_BOTTOM; ++quadrant) {
if (link->findPoint((Quadrant)quadrant, pt))
if (link == getItemAtPoint(pt))
break;
}
if (quadrant > Q_BOTTOM)
continue;
} else if (gameObj) {
if (!gameObj->_visible || gameObj->getMovement() != msg->_movement)
continue;
for (quadrant = Q_CENTER; quadrant <= Q_BOTTOM; ++quadrant) {
if (gameObj->findPoint((Quadrant)quadrant, pt))
if (gameObj == getItemAtPoint(pt))
break;
}
if (quadrant > Q_BOTTOM)
continue;
} else {
// Not a link or object, so ignore
continue;
}
foundPt = true;
break;
}
}
if (foundPt) {
// We've found a point on the object or link that has a
// cursor for the given direction. So simulate a mouse
// press and release on the desired point
CMouseButtonDownMsg downMsg(pt, MB_LEFT);
CMouseButtonUpMsg upMsg(pt, MB_LEFT);
MouseButtonDownMsg(&downMsg);
MouseButtonUpMsg(&upMsg);
return true;
}
return false;
}
CTreeItem *CViewItem::getItemAtPoint(const Point &pt) {
CTreeItem *result = nullptr;
// First scan for objects
for (CTreeItem *treeItem = scan(this); treeItem; treeItem = treeItem->scan(this)) {
CGameObject *gameObject = dynamic_cast<CGameObject *>(treeItem);
if (gameObject && gameObject->checkPoint(pt, false, true))
result = treeItem;
}
if (result == nullptr) {
// Scan for links coverign that position
for (CTreeItem *treeItem = scan(this); treeItem; treeItem = treeItem->scan(this)) {
CLinkItem *link = dynamic_cast<CLinkItem *>(treeItem);
if (link && link->_bounds.contains(pt)) {
result = treeItem;
break;
}
}
}
return result;
}
} // End of namespace Titanic

View File

@@ -0,0 +1,128 @@
/* 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/>.
*
*/
#ifndef TITANIC_VIEW_ITEM_H
#define TITANIC_VIEW_ITEM_H
#include "titanic/core/link_item.h"
#include "titanic/core/named_item.h"
#include "titanic/core/resource_key.h"
#include "titanic/messages/mouse_messages.h"
namespace Titanic {
class CViewItem : public CNamedItem {
DECLARE_MESSAGE_MAP;
bool MouseButtonDownMsg(CMouseButtonDownMsg *msg);
bool MouseButtonUpMsg(CMouseButtonUpMsg *msg);
bool MouseMoveMsg(CMouseMoveMsg *msg);
bool MouseDoubleClickMsg(CMouseDoubleClickMsg *msg);
bool MovementMsg(CMovementMsg *msg);
private:
CTreeItem *_buttonUpTargets[4];
private:
/**
* Sets the angle of the view relative to the node it belongs to
*/
void setAngle(double angle);
/**
* Called to handle mouse messagaes on the view
*/
bool handleMouseMsg(CMouseMsg *msg, bool flag);
/**
* Handles mouse button up messages
*/
void handleButtonUpMsg(CMouseButtonUpMsg *msg);
/**
* Returns the item in the view at a given point that will
* receive any mouse click
*/
CTreeItem *getItemAtPoint(const Point &pt);
protected:
int _field24;
CResourceKey _resourceKey;
Point _viewPos;
public:
int _viewNumber;
double _angle;
public:
CLASSDEF;
CViewItem();
/**
* Save the data for the class to file
*/
void save(SimpleFile *file, int indent) override;
/**
* Load the data for the class from file
*/
void load(SimpleFile *file) override;
/**
* Get the resource key for the view
*/
bool getResourceKey(CResourceKey *key);
/**
* Called when leaving the view
*/
void leaveView(CViewItem *newView);
/**
* Called on an old view just left, and about to enter a new view
*/
void preEnterView(CViewItem *newView);
/**
* Called when a new view is being entered
*/
void enterView(CViewItem *newView);
/**
* Finds a link which connects to another designated view
*/
CLinkItem *findLink(CViewItem *newView);
/**
* Return the full Id of the current view in a
* room.node.view tuplet form
*/
CString getFullViewName() const;
/**
* Return the Id of the current view in a
* room.node.view tuplet form
*/
CString getNodeViewName() const;
/**
* Gets the relative position of the view within the owning room
*/
void getPosition(double &xp, double &yp, double &zp);
};
} // End of namespace Titanic
#endif /* TITANIC_NAMED_ITEM_H */