2016-02-23 20:59:57 -05:00
|
|
|
/* 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 2
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-04-03 16:16:35 -04:00
|
|
|
#include "titanic/support/files_manager.h"
|
2016-03-22 07:44:45 -04:00
|
|
|
#include "titanic/game_manager.h"
|
2016-04-03 16:16:35 -04:00
|
|
|
#include "titanic/support/screen_manager.h"
|
2016-03-22 07:44:45 -04:00
|
|
|
#include "titanic/titanic.h"
|
2016-04-03 16:16:35 -04:00
|
|
|
#include "titanic/support/video_surface.h"
|
2016-02-25 08:48:21 -05:00
|
|
|
#include "titanic/core/game_object.h"
|
|
|
|
#include "titanic/core/resource_key.h"
|
2016-03-24 22:09:49 -04:00
|
|
|
#include "titanic/pet_control/pet_control.h"
|
2016-02-23 20:59:57 -05:00
|
|
|
|
|
|
|
namespace Titanic {
|
|
|
|
|
2016-03-22 07:44:45 -04:00
|
|
|
void *CGameObject::_v1 = nullptr;
|
|
|
|
|
2016-02-24 23:14:49 -05:00
|
|
|
CGameObject::CGameObject(): CNamedItem() {
|
2016-03-21 20:53:49 -04:00
|
|
|
_bounds = Rect(0, 0, 15, 15);
|
2016-02-24 23:14:49 -05:00
|
|
|
_field34 = 0;
|
|
|
|
_field38 = 0;
|
|
|
|
_field3C = 0;
|
|
|
|
_field40 = 0;
|
|
|
|
_field44 = 0xF0;
|
|
|
|
_field48 = 0xF0;
|
|
|
|
_field4C = 0xFF;
|
|
|
|
_field50 = 0;
|
|
|
|
_field54 = 0;
|
|
|
|
_field58 = 0;
|
2016-03-28 22:25:15 -04:00
|
|
|
_visible = true;
|
2016-02-24 23:14:49 -05:00
|
|
|
_field60 = 0;
|
2016-03-23 20:51:42 -04:00
|
|
|
_cursorId = CURSOR_1;
|
2016-02-24 23:14:49 -05:00
|
|
|
_field78 = 0;
|
2016-03-22 07:44:45 -04:00
|
|
|
_frameNumber = -1;
|
2016-02-24 23:14:49 -05:00
|
|
|
_field90 = 0;
|
|
|
|
_field94 = 0;
|
|
|
|
_field98 = 0;
|
|
|
|
_field9C = 0;
|
2016-03-22 07:44:45 -04:00
|
|
|
_surface = nullptr;
|
2016-02-24 23:14:49 -05:00
|
|
|
_fieldB8 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameObject::save(SimpleFile *file, int indent) const {
|
|
|
|
file->writeNumberLine(7, indent);
|
|
|
|
error("TODO: CGameObject::save");
|
|
|
|
|
|
|
|
CNamedItem::save(file, indent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameObject::load(SimpleFile *file) {
|
|
|
|
int val = file->readNumber();
|
|
|
|
CResourceKey resourceKey;
|
|
|
|
|
|
|
|
switch (val) {
|
|
|
|
case 7:
|
|
|
|
_clipList2.load(file);
|
2016-03-22 07:44:45 -04:00
|
|
|
_frameNumber = file->readNumber();
|
2016-02-24 23:14:49 -05:00
|
|
|
// Deliberate fall-through
|
|
|
|
|
|
|
|
case 6:
|
2016-03-23 20:51:42 -04:00
|
|
|
_cursorId = (CursorId)file->readNumber();
|
2016-02-24 23:14:49 -05:00
|
|
|
// Deliberate fall-through
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
_clipList1.load(file);
|
|
|
|
// Deliberate fall-through
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
_field60 = file->readNumber();
|
|
|
|
// Deliberate fall-through
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
_field40 = file->readNumber();
|
|
|
|
// Deliberate fall-through
|
|
|
|
|
|
|
|
case 2:
|
2016-03-22 07:44:45 -04:00
|
|
|
_resource = file->readString();
|
2016-02-24 23:14:49 -05:00
|
|
|
// Deliberate fall-through
|
|
|
|
|
|
|
|
case 1:
|
2016-04-05 20:15:14 -04:00
|
|
|
_bounds = file->readBounds();
|
2016-02-24 23:14:49 -05:00
|
|
|
_field34 = file->readFloat();
|
|
|
|
_field38 = file->readFloat();
|
|
|
|
_field3C = file->readFloat();
|
|
|
|
_field44 = file->readNumber();
|
|
|
|
_field48 = file->readNumber();
|
|
|
|
_field4C = file->readNumber();
|
|
|
|
_fieldB8 = file->readNumber();
|
2016-03-28 22:25:15 -04:00
|
|
|
_visible = file->readNumber() != 0;
|
2016-02-24 23:14:49 -05:00
|
|
|
_field50 = file->readNumber();
|
|
|
|
_field54 = file->readNumber();
|
|
|
|
_field58 = file->readNumber();
|
|
|
|
|
|
|
|
resourceKey.load(file);
|
2016-03-22 07:44:45 -04:00
|
|
|
_surface = nullptr;
|
2016-02-24 23:14:49 -05:00
|
|
|
val = file->readNumber();
|
|
|
|
if (val) {
|
2016-03-22 07:44:45 -04:00
|
|
|
_resource = resourceKey.getString();
|
2016-02-24 23:14:49 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CNamedItem::load(file);
|
|
|
|
}
|
|
|
|
|
2016-03-24 13:16:21 -04:00
|
|
|
void CGameObject::stopMovie() {
|
|
|
|
if (_surface)
|
|
|
|
_surface->stopMovie();
|
2016-03-14 20:03:32 -04:00
|
|
|
}
|
|
|
|
|
2016-03-28 22:48:44 -04:00
|
|
|
bool CGameObject::checkPoint(const Point &pt, bool ignore40, bool visibleOnly) {
|
|
|
|
if ((!_visible && visibleOnly) || !_bounds.contains(pt))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (ignore40 || _field40)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!_surface) {
|
|
|
|
if (_frameNumber == -1)
|
|
|
|
return true;
|
|
|
|
loadFrame(_frameNumber);
|
|
|
|
if (!_surface)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Point pixelPos = pt - _bounds;
|
|
|
|
if (_surface->_blitStyleFlag) {
|
|
|
|
pixelPos.y = ((_bounds.height() - _bounds.top) / 2) * 2 - pixelPos.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint transColor = _surface->getTransparencyColor();
|
|
|
|
uint pixel = _surface->getPixel(pixelPos);
|
|
|
|
return pixel != transColor;
|
2016-03-19 18:19:45 -04:00
|
|
|
}
|
|
|
|
|
2016-03-21 22:44:55 -04:00
|
|
|
void CGameObject::draw(CScreenManager *screenManager) {
|
2016-03-28 22:25:15 -04:00
|
|
|
if (!_visible)
|
2016-03-22 07:44:45 -04:00
|
|
|
return;
|
|
|
|
if (_v1) {
|
|
|
|
error("TODO: Block in CGameObject::draw");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_field40) {
|
|
|
|
if (_field90) {
|
|
|
|
if (_bounds.intersects(getGameManager()->_bounds))
|
|
|
|
warning("TODO: _field90(screenManager);");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!_surface) {
|
|
|
|
if (!_resource.empty()) {
|
|
|
|
loadResource(_resource);
|
|
|
|
_resource = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_surface) {
|
|
|
|
_bounds.right = _surface->getWidth();
|
|
|
|
_bounds.bottom = _surface->getHeight();
|
|
|
|
|
|
|
|
if (!_bounds.right || !_bounds.bottom)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (_frameNumber >= 0) {
|
|
|
|
loadFrame(_frameNumber);
|
|
|
|
_frameNumber = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_clipList2.empty())
|
|
|
|
processClipList2();
|
|
|
|
|
|
|
|
if (_bounds.intersects(getGameManager()->_bounds)) {
|
|
|
|
if (_surface) {
|
|
|
|
Point destPos(_bounds.left, _bounds.top);
|
2016-03-22 21:54:26 -04:00
|
|
|
screenManager->blitFrom(SURFACE_BACKBUFFER, _surface, &destPos);
|
2016-03-22 07:44:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_field90)
|
|
|
|
warning("TODO: sub_415f80(screenManager);");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-30 21:43:07 -04:00
|
|
|
void CGameObject::draw(CScreenManager *screenManager, const Common::Point &destPos) {
|
|
|
|
if (!_surface && !_resource.empty()) {
|
|
|
|
loadResource(_resource);
|
|
|
|
_resource.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_surface) {
|
|
|
|
int xSize = _surface->getWidth();
|
|
|
|
int ySize = _surface->getHeight();
|
|
|
|
|
|
|
|
if (xSize > 0 && ySize > 0) {
|
|
|
|
screenManager->blitFrom(SURFACE_BACKBUFFER, _surface, &destPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-22 07:44:45 -04:00
|
|
|
void CGameObject::loadResource(const CString &name) {
|
|
|
|
switch (name.imageTypeSuffix()) {
|
|
|
|
case FILETYPE_IMAGE:
|
|
|
|
loadImage(name);
|
|
|
|
break;
|
|
|
|
case FILETYPE_MOVIE:
|
|
|
|
loadMovie(name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameObject::loadMovie(const CString &name, bool pendingFlag) {
|
|
|
|
warning("TODO: CGameObject::loadMovie");
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameObject::loadImage(const CString &name, bool pendingFlag) {
|
|
|
|
// Get a refernce to the game and screen managers
|
|
|
|
CGameManager *gameManager = getGameManager();
|
|
|
|
CScreenManager *screenManager;
|
|
|
|
|
|
|
|
if (gameManager && (screenManager = CScreenManager::setCurrent()) != nullptr) {
|
|
|
|
// Destroy the object's surface if it already had one
|
|
|
|
if (_surface) {
|
|
|
|
delete _surface;
|
|
|
|
_surface = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_vm->_filesManager.fn5(name);
|
|
|
|
|
|
|
|
if (!name.empty()) {
|
|
|
|
_surface = new OSVideoSurface(screenManager, CResourceKey(name), pendingFlag);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_surface && !pendingFlag) {
|
|
|
|
_bounds.right = _surface->getWidth();
|
|
|
|
_bounds.bottom = _surface->getHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark the object's area as dirty, so that on the next frame rendering
|
|
|
|
// this object will be redrawn
|
|
|
|
makeDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
_field78 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameObject::loadFrame(int frameNumber) {
|
2016-03-24 21:02:25 -04:00
|
|
|
if (frameNumber != -1 && !_resource.empty())
|
|
|
|
loadResource(_resource);
|
|
|
|
|
|
|
|
if (_surface)
|
|
|
|
_surface->setMovieFrame(frameNumber);
|
|
|
|
|
|
|
|
makeDirty();
|
2016-03-22 07:44:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGameObject::processClipList2() {
|
|
|
|
warning("CGameObject::processClipList2");
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameObject::makeDirty(const Rect &r) {
|
|
|
|
CGameManager *gameManager = getGameManager();
|
|
|
|
if (gameManager)
|
|
|
|
gameManager->extendBounds(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameObject::makeDirty() {
|
|
|
|
makeDirty(_bounds);
|
2016-03-21 22:44:55 -04:00
|
|
|
}
|
|
|
|
|
2016-03-24 21:02:25 -04:00
|
|
|
bool CGameObject::soundFn1(int val) {
|
|
|
|
if (val != 0 && val != -1) {
|
|
|
|
CGameManager *gameManager = getGameManager();
|
|
|
|
if (gameManager)
|
|
|
|
return gameManager->_sound.fn1(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameObject::soundFn2(int val, int val2) {
|
|
|
|
if (val != 0 && val != -1) {
|
|
|
|
CGameManager *gameManager = getGameManager();
|
|
|
|
if (gameManager) {
|
|
|
|
if (val2)
|
|
|
|
gameManager->_sound.fn3(val, 0, val2);
|
|
|
|
else
|
|
|
|
gameManager->_sound.fn2(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-28 22:25:15 -04:00
|
|
|
void CGameObject::setVisible(bool val) {
|
|
|
|
if (val != _visible) {
|
|
|
|
_visible = val;
|
2016-03-24 21:02:25 -04:00
|
|
|
makeDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-24 22:09:49 -04:00
|
|
|
void CGameObject::petFn2(int val) {
|
|
|
|
CPetControl *pet = getPetControl();
|
|
|
|
if (pet)
|
|
|
|
pet->fn2(val);
|
|
|
|
}
|
|
|
|
|
2016-03-29 22:57:22 -04:00
|
|
|
void CGameObject::petFn3(CTreeItem *item) {
|
2016-03-24 22:09:49 -04:00
|
|
|
CPetControl *pet = getPetControl();
|
|
|
|
if (pet)
|
2016-03-29 22:57:22 -04:00
|
|
|
pet->fn3(item);
|
2016-03-24 22:09:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGameObject::fn1(int val1, int val2, int val3) {
|
|
|
|
warning("TODO: CGameObject::fn1");
|
|
|
|
}
|
|
|
|
|
2016-03-25 00:01:15 -04:00
|
|
|
void CGameObject::changeStatus(int newStatus) {
|
|
|
|
if (_frameNumber == -1 && !_resource.empty()) {
|
|
|
|
loadResource(_resource);
|
|
|
|
_resource.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
CVideoSurface *surface = (newStatus & 4) ? _surface : nullptr;
|
|
|
|
if (_surface) {
|
|
|
|
_surface->proc32(newStatus, surface);
|
|
|
|
|
|
|
|
if (newStatus & 0x10) {
|
|
|
|
getGameManager()->_gameState.addMovie(_surface->_movie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-28 22:25:15 -04:00
|
|
|
void CGameObject::savePosition() {
|
|
|
|
_savedPos = _bounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameObject::resetPosition() {
|
|
|
|
setPosition(_savedPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameObject::setPosition(const Common::Point &newPos) {
|
|
|
|
makeDirty();
|
|
|
|
_bounds.moveTo(newPos);
|
|
|
|
makeDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGameObject::checkStartDragging(CMouseDragStartMsg *msg) {
|
|
|
|
if (_visible && checkPoint(msg->_mousePos, msg->_field14, 1)) {
|
|
|
|
savePosition();
|
|
|
|
msg->_dragItem = this;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 22:57:22 -04:00
|
|
|
void CGameObject::setPetArea(PetArea newArea) const {
|
|
|
|
CPetControl *pet = getPetControl();
|
|
|
|
if (pet)
|
|
|
|
pet->setArea(newArea);
|
|
|
|
}
|
|
|
|
|
2016-03-30 20:11:02 -04:00
|
|
|
bool CGameObject::hasActiveMovie() const {
|
|
|
|
if (_surface && _surface->_movie)
|
|
|
|
return _surface->_movie->isActive();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CGameObject::getMovie19() const {
|
|
|
|
if (_surface && _surface->_movie)
|
|
|
|
return _surface->_movie->proc19();
|
|
|
|
return _field78;
|
|
|
|
}
|
|
|
|
|
2016-03-30 21:01:51 -04:00
|
|
|
int CGameObject::getSurface45() const {
|
|
|
|
return _surface ? _surface->proc45() : 0;
|
|
|
|
}
|
|
|
|
|
2016-02-23 20:59:57 -05:00
|
|
|
} // End of namespace Titanic
|