2012-03-06 03:34:46 +00: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.
|
2012-05-11 14:03:59 +00:00
|
|
|
|
2012-03-06 03:34:46 +00:00
|
|
|
* 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.
|
2012-05-11 14:03:59 +00:00
|
|
|
|
2012-03-06 03:34:46 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is based on WME Lite.
|
|
|
|
* http://dead-code.org/redir.php?target=wmelite
|
|
|
|
* Copyright (c) 2011 Jan Nedoma
|
|
|
|
*/
|
|
|
|
|
2012-07-21 16:19:07 +00:00
|
|
|
#include "engines/wintermute/ad/ad_scene.h"
|
|
|
|
#include "engines/wintermute/ad/ad_actor.h"
|
|
|
|
#include "engines/wintermute/ad/ad_entity.h"
|
|
|
|
#include "engines/wintermute/ad/ad_game.h"
|
|
|
|
#include "engines/wintermute/ad/ad_layer.h"
|
|
|
|
#include "engines/wintermute/ad/ad_node_state.h"
|
|
|
|
#include "engines/wintermute/ad/ad_object.h"
|
|
|
|
#include "engines/wintermute/ad/ad_path.h"
|
|
|
|
#include "engines/wintermute/ad/ad_path_point.h"
|
|
|
|
#include "engines/wintermute/ad/ad_rot_level.h"
|
|
|
|
#include "engines/wintermute/ad/ad_scale_level.h"
|
|
|
|
#include "engines/wintermute/ad/ad_scene_node.h"
|
|
|
|
#include "engines/wintermute/ad/ad_scene_state.h"
|
|
|
|
#include "engines/wintermute/ad/ad_sentence.h"
|
|
|
|
#include "engines/wintermute/ad/ad_waypoint_group.h"
|
|
|
|
#include "engines/wintermute/base/base_dynamic_buffer.h"
|
|
|
|
#include "engines/wintermute/base/base_file_manager.h"
|
|
|
|
#include "engines/wintermute/base/font/base_font.h"
|
|
|
|
#include "engines/wintermute/base/base_game.h"
|
|
|
|
#include "engines/wintermute/base/base_object.h"
|
|
|
|
#include "engines/wintermute/base/base_parser.h"
|
|
|
|
#include "engines/wintermute/base/base_point.h"
|
|
|
|
#include "engines/wintermute/base/base_region.h"
|
|
|
|
#include "engines/wintermute/base/base_scriptable.h"
|
|
|
|
#include "engines/wintermute/base/base_sprite.h"
|
|
|
|
#include "engines/wintermute/base/base_viewport.h"
|
|
|
|
#include "engines/wintermute/base/scriptables/script_stack.h"
|
|
|
|
#include "engines/wintermute/base/scriptables/script_value.h"
|
|
|
|
#include "engines/wintermute/base/scriptables/script.h"
|
|
|
|
#include "engines/wintermute/ui/ui_window.h"
|
2012-06-02 00:31:59 +00:00
|
|
|
#include "engines/wintermute/utils/utils.h"
|
2012-03-06 03:34:46 +00:00
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
namespace WinterMute {
|
|
|
|
|
2012-07-21 19:01:47 +00:00
|
|
|
IMPLEMENT_PERSISTENT(AdScene, false)
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-27 17:37:00 +00:00
|
|
|
AdScene::AdScene(BaseGame *inGame) : BaseObject(inGame) {
|
2012-07-21 19:01:47 +00:00
|
|
|
_pfTarget = new BasePoint;
|
2012-06-26 11:23:32 +00:00
|
|
|
setDefaults();
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
AdScene::~AdScene() {
|
2012-06-25 22:41:05 +00:00
|
|
|
cleanup();
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->unregisterObject(_fader);
|
2012-06-26 11:23:32 +00:00
|
|
|
delete _pfTarget;
|
|
|
|
_pfTarget = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
void AdScene::setDefaults() {
|
2012-04-27 22:00:14 +00:00
|
|
|
_initialized = false;
|
2012-06-26 11:23:32 +00:00
|
|
|
_pfReady = true;
|
|
|
|
_pfTargetPath = NULL;
|
|
|
|
_pfRequester = NULL;
|
2012-04-27 22:00:14 +00:00
|
|
|
_mainLayer = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-06-26 11:23:32 +00:00
|
|
|
_pfPointsNum = 0;
|
2012-04-27 22:00:14 +00:00
|
|
|
_persistentState = false;
|
|
|
|
_persistentStateSprites = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
_autoScroll = true;
|
|
|
|
_offsetLeft = _offsetTop = 0;
|
|
|
|
_targetOffsetLeft = _targetOffsetTop = 0;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
_lastTimeH = _lastTimeV = 0;
|
|
|
|
_scrollTimeH = _scrollTimeV = 10;
|
|
|
|
_scrollPixelsH = _scrollPixelsV = 1;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-06-26 11:23:32 +00:00
|
|
|
_pfMaxTime = 15;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
_paralaxScrolling = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// editor settings
|
2012-04-27 22:00:14 +00:00
|
|
|
_editorMarginH = _editorMarginV = 100;
|
|
|
|
|
|
|
|
_editorColFrame = 0xE0888888;
|
|
|
|
_editorColEntity = 0xFF008000;
|
|
|
|
_editorColRegion = 0xFF0000FF;
|
|
|
|
_editorColBlocked = 0xFF800080;
|
|
|
|
_editorColWaypoints = 0xFF0000FF;
|
|
|
|
_editorColEntitySel = 0xFFFF0000;
|
|
|
|
_editorColRegionSel = 0xFFFF0000;
|
|
|
|
_editorColBlockedSel = 0xFFFF0000;
|
|
|
|
_editorColWaypointsSel = 0xFFFF0000;
|
|
|
|
_editorColScale = 0xFF00FF00;
|
|
|
|
_editorColDecor = 0xFF00FFFF;
|
|
|
|
_editorColDecorSel = 0xFFFF0000;
|
|
|
|
|
|
|
|
_editorShowRegions = true;
|
|
|
|
_editorShowBlocked = true;
|
|
|
|
_editorShowDecor = true;
|
|
|
|
_editorShowEntities = true;
|
|
|
|
_editorShowScale = true;
|
|
|
|
|
|
|
|
_shieldWindow = NULL;
|
|
|
|
|
2012-07-21 19:01:47 +00:00
|
|
|
_fader = new BaseFader(_gameRef);
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->registerObject(_fader);
|
2012-04-27 22:00:14 +00:00
|
|
|
|
|
|
|
_viewport = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
void AdScene::cleanup() {
|
|
|
|
BaseObject::cleanup();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
_mainLayer = NULL; // reference only
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
delete _shieldWindow;
|
|
|
|
_shieldWindow = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->unregisterObject(_fader);
|
2012-04-27 22:00:14 +00:00
|
|
|
_fader = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
for (i = 0; i < _layers.getSize(); i++) {
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->unregisterObject(_layers[i]);
|
2012-07-26 13:59:26 +00:00
|
|
|
}
|
2012-07-26 17:41:18 +00:00
|
|
|
_layers.clear();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
for (i = 0; i < _waypointGroups.getSize(); i++) {
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->unregisterObject(_waypointGroups[i]);
|
2012-07-26 13:59:26 +00:00
|
|
|
}
|
2012-07-26 17:41:18 +00:00
|
|
|
_waypointGroups.clear();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
for (i = 0; i < _scaleLevels.getSize(); i++) {
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->unregisterObject(_scaleLevels[i]);
|
2012-07-26 13:59:26 +00:00
|
|
|
}
|
2012-07-26 17:41:18 +00:00
|
|
|
_scaleLevels.clear();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
for (i = 0; i < _rotLevels.getSize(); i++) {
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->unregisterObject(_rotLevels[i]);
|
2012-07-26 13:59:26 +00:00
|
|
|
}
|
2012-07-26 17:41:18 +00:00
|
|
|
_rotLevels.clear();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
for (i = 0; i < _pfPath.getSize(); i++) {
|
2012-06-26 11:23:32 +00:00
|
|
|
delete _pfPath[i];
|
2012-07-26 13:59:26 +00:00
|
|
|
}
|
2012-07-26 17:41:18 +00:00
|
|
|
_pfPath.clear();
|
2012-06-26 11:23:32 +00:00
|
|
|
_pfPointsNum = 0;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
for (i = 0; i < _objects.getSize(); i++) {
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->unregisterObject(_objects[i]);
|
2012-07-26 13:59:26 +00:00
|
|
|
}
|
2012-07-26 17:41:18 +00:00
|
|
|
_objects.clear();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
delete _viewport;
|
|
|
|
_viewport = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-06-26 11:23:32 +00:00
|
|
|
setDefaults();
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::getPath(BasePoint source, BasePoint target, AdPath *path, BaseObject *requester) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!_pfReady) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2012-06-26 11:23:32 +00:00
|
|
|
_pfReady = false;
|
|
|
|
*_pfTarget = target;
|
|
|
|
_pfTargetPath = path;
|
|
|
|
_pfRequester = requester;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 17:23:41 +00:00
|
|
|
_pfTargetPath->reset();
|
|
|
|
_pfTargetPath->setReady(false);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// prepare working path
|
|
|
|
int i;
|
2012-06-26 11:23:32 +00:00
|
|
|
pfPointsStart();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// first point
|
2012-07-21 19:01:47 +00:00
|
|
|
//_pfPath.add(new AdPathPoint(source.x, source.y, 0));
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// if we're one pixel stuck, get unstuck
|
2012-07-04 19:32:29 +00:00
|
|
|
int startX = source.x;
|
|
|
|
int startY = source.y;
|
|
|
|
int bestDistance = 1000;
|
|
|
|
if (isBlockedAt(startX, startY, true, requester)) {
|
|
|
|
int tolerance = 2;
|
|
|
|
for (int xxx = startX - tolerance; xxx <= startX + tolerance; xxx++) {
|
|
|
|
for (int yyy = startY - tolerance; yyy <= startY + tolerance; yyy++) {
|
2012-06-26 11:23:32 +00:00
|
|
|
if (isWalkableAt(xxx, yyy, true, requester)) {
|
2012-07-04 19:32:29 +00:00
|
|
|
int distance = abs(xxx - source.x) + abs(yyy - source.y);
|
|
|
|
if (distance < bestDistance) {
|
|
|
|
startX = xxx;
|
|
|
|
startY = yyy;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
bestDistance = distance;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
pfPointsAdd(startX, startY, 0);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
//CorrectTargetPoint(&target.x, &target.y);
|
|
|
|
|
|
|
|
// last point
|
2012-07-21 19:01:47 +00:00
|
|
|
//_pfPath.add(new AdPathPoint(target.x, target.y, INT_MAX));
|
2012-06-26 11:23:32 +00:00
|
|
|
pfPointsAdd(target.x, target.y, INT_MAX);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// active waypoints
|
2012-07-09 02:50:38 +00:00
|
|
|
for (i = 0; i < _waypointGroups.getSize(); i++) {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_waypointGroups[i]->_active) {
|
2012-06-26 11:23:32 +00:00
|
|
|
pfAddWaypointGroup(_waypointGroups[i], requester);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// free waypoints
|
2012-07-09 02:50:38 +00:00
|
|
|
for (i = 0; i < _objects.getSize(); i++) {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentWptGroup) {
|
2012-06-26 11:23:32 +00:00
|
|
|
pfAddWaypointGroup(_objects[i]->_currentWptGroup, requester);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-21 19:01:47 +00:00
|
|
|
AdGame *adGame = (AdGame *)_gameRef;
|
2012-07-09 02:50:38 +00:00
|
|
|
for (i = 0; i < adGame->_objects.getSize(); i++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentWptGroup) {
|
|
|
|
pfAddWaypointGroup(adGame->_objects[i]->_currentWptGroup, requester);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
void AdScene::pfAddWaypointGroup(AdWaypointGroup *wpt, BaseObject *requester) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!wpt->_active) {
|
|
|
|
return;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < wpt->_points.getSize(); i++) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (isBlockedAt(wpt->_points[i]->x, wpt->_points[i]->y, true, requester)) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-21 19:01:47 +00:00
|
|
|
//_pfPath.add(new AdPathPoint(Wpt->_points[i]->x, Wpt->_points[i]->y, INT_MAX));
|
2012-07-04 19:32:29 +00:00
|
|
|
pfPointsAdd(wpt->_points[i]->x, wpt->_points[i]->y, INT_MAX);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
float AdScene::getZoomAt(int x, int y) {
|
2012-03-06 03:34:46 +00:00
|
|
|
float ret = 100;
|
|
|
|
|
|
|
|
bool found = false;
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_mainLayer) {
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdSceneNode *node = _mainLayer->_nodes[i];
|
2012-07-07 15:52:08 +00:00
|
|
|
if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_blocked && node->_region->pointInRegion(x, y)) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (node->_region->_zoom != 0) {
|
|
|
|
ret = node->_region->_zoom;
|
2012-03-06 03:34:46 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!found) {
|
|
|
|
ret = getScaleAt(y);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
uint32 AdScene::getAlphaAt(int x, int y, bool colorCheck) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!_gameRef->_debugDebugMode) {
|
|
|
|
colorCheck = false;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
uint32 ret;
|
2012-07-26 13:59:26 +00:00
|
|
|
if (colorCheck) {
|
|
|
|
ret = 0xFFFF0000;
|
|
|
|
} else {
|
|
|
|
ret = 0xFFFFFFFF;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_mainLayer) {
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdSceneNode *node = _mainLayer->_nodes[i];
|
2012-07-07 15:52:08 +00:00
|
|
|
if (node->_type == OBJECT_REGION && node->_region->_active && (colorCheck || !node->_region->_blocked) && node->_region->pointInRegion(x, y)) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!node->_region->_blocked) {
|
|
|
|
ret = node->_region->_alpha;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::isBlockedAt(int x, int y, bool checkFreeObjects, BaseObject *requester) {
|
2012-03-06 03:34:46 +00:00
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
if (checkFreeObjects) {
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _objects.getSize(); i++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-21 19:01:47 +00:00
|
|
|
AdGame *adGame = (AdGame *)_gameRef;
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < adGame->_objects.getSize(); i++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_mainLayer) {
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _mainLayer->_nodes.getSize(); i++) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdSceneNode *node = _mainLayer->_nodes[i];
|
2012-03-06 03:34:46 +00:00
|
|
|
/*
|
2012-06-12 12:41:29 +00:00
|
|
|
if (Node->_type == OBJECT_REGION && Node->_region->_active && Node->_region->_blocked && Node->_region->PointInRegion(X, Y))
|
2012-03-06 03:34:46 +00:00
|
|
|
{
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*/
|
2012-07-07 15:52:08 +00:00
|
|
|
if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_decoration && node->_region->pointInRegion(x, y)) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (node->_region->_blocked) {
|
2012-03-06 03:34:46 +00:00
|
|
|
ret = true;
|
|
|
|
break;
|
2012-07-26 13:59:26 +00:00
|
|
|
} else {
|
|
|
|
ret = false;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::isWalkableAt(int x, int y, bool checkFreeObjects, BaseObject *requester) {
|
2012-03-06 03:34:46 +00:00
|
|
|
bool ret = false;
|
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
if (checkFreeObjects) {
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _objects.getSize(); i++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-21 19:01:47 +00:00
|
|
|
AdGame *adGame = (AdGame *)_gameRef;
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < adGame->_objects.getSize(); i++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_mainLayer) {
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _mainLayer->_nodes.getSize(); i++) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdSceneNode *node = _mainLayer->_nodes[i];
|
2012-07-07 15:52:08 +00:00
|
|
|
if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_decoration && node->_region->pointInRegion(x, y)) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (node->_region->_blocked) {
|
2012-03-06 03:34:46 +00:00
|
|
|
ret = false;
|
|
|
|
break;
|
2012-07-26 13:59:26 +00:00
|
|
|
} else {
|
|
|
|
ret = true;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
int AdScene::getPointsDist(BasePoint p1, BasePoint p2, BaseObject *requester) {
|
2012-07-04 19:32:29 +00:00
|
|
|
double xStep, yStep, x, y;
|
2012-03-06 03:34:46 +00:00
|
|
|
int xLength, yLength, xCount, yCount;
|
2012-07-04 19:32:29 +00:00
|
|
|
int x1, y1, x2, y2;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
x1 = p1.x;
|
|
|
|
y1 = p1.y;
|
|
|
|
x2 = p2.x;
|
|
|
|
y2 = p2.y;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
xLength = abs(x2 - x1);
|
|
|
|
yLength = abs(y2 - y1);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
if (xLength > yLength) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (x1 > x2) {
|
2012-07-21 19:01:47 +00:00
|
|
|
BaseUtils::swap(&x1, &x2);
|
|
|
|
BaseUtils::swap(&y1, &y2);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
yStep = (double)(y2 - y1) / (double)(x2 - x1);
|
|
|
|
y = y1;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
for (xCount = x1; xCount < x2; xCount++) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (isBlockedAt(xCount, (int)y, true, requester)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2012-07-04 19:32:29 +00:00
|
|
|
y += yStep;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (y1 > y2) {
|
2012-07-21 19:01:47 +00:00
|
|
|
BaseUtils::swap(&x1, &x2);
|
|
|
|
BaseUtils::swap(&y1, &y2);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
xStep = (double)(x2 - x1) / (double)(y2 - y1);
|
|
|
|
x = x1;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
for (yCount = y1; yCount < y2; yCount++) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (isBlockedAt((int)x, yCount, true, requester)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2012-07-04 19:32:29 +00:00
|
|
|
x += xStep;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-11 15:30:43 +00:00
|
|
|
return MAX(xLength, yLength);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
void AdScene::pathFinderStep() {
|
2012-03-06 03:34:46 +00:00
|
|
|
int i;
|
|
|
|
// get lowest unmarked
|
2012-07-04 19:32:29 +00:00
|
|
|
int lowestDist = INT_MAX;
|
2012-07-21 19:01:47 +00:00
|
|
|
AdPathPoint *lowestPt = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-06-26 11:23:32 +00:00
|
|
|
for (i = 0; i < _pfPointsNum; i++)
|
2012-07-04 19:32:29 +00:00
|
|
|
if (!_pfPath[i]->_marked && _pfPath[i]->_distance < lowestDist) {
|
|
|
|
lowestDist = _pfPath[i]->_distance;
|
|
|
|
lowestPt = _pfPath[i];
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
if (lowestPt == NULL) { // no path -> terminate PathFinder
|
2012-06-26 11:23:32 +00:00
|
|
|
_pfReady = true;
|
2012-07-04 17:23:41 +00:00
|
|
|
_pfTargetPath->setReady(true);
|
2012-03-06 03:34:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
lowestPt->_marked = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// target point marked, generate path and terminate
|
2012-07-04 19:32:29 +00:00
|
|
|
if (lowestPt->x == _pfTarget->x && lowestPt->y == _pfTarget->y) {
|
|
|
|
while (lowestPt != NULL) {
|
2012-07-26 17:41:18 +00:00
|
|
|
_pfTargetPath->_points.insert_at(0, new BasePoint(lowestPt->x, lowestPt->y));
|
2012-07-04 19:32:29 +00:00
|
|
|
lowestPt = lowestPt->_origin;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 11:23:32 +00:00
|
|
|
_pfReady = true;
|
2012-07-04 17:23:41 +00:00
|
|
|
_pfTargetPath->setReady(true);
|
2012-03-06 03:34:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise keep on searching
|
2012-06-26 11:23:32 +00:00
|
|
|
for (i = 0; i < _pfPointsNum; i++)
|
|
|
|
if (!_pfPath[i]->_marked) {
|
2012-07-04 19:32:29 +00:00
|
|
|
int j = getPointsDist(*lowestPt, *_pfPath[i], _pfRequester);
|
|
|
|
if (j != -1 && lowestPt->_distance + j < _pfPath[i]->_distance) {
|
|
|
|
_pfPath[i]->_distance = lowestPt->_distance + j;
|
|
|
|
_pfPath[i]->_origin = lowestPt;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::initLoop() {
|
2012-03-06 03:34:46 +00:00
|
|
|
#ifdef _DEBUGxxxx
|
2012-04-27 22:00:14 +00:00
|
|
|
int nu_steps = 0;
|
2012-07-18 16:25:09 +00:00
|
|
|
uint32 start = _gameRef->_currentTime;
|
2012-07-23 01:01:05 +00:00
|
|
|
while (!_pfReady && g_system->getMillis() - start <= _pfMaxTime) {
|
2012-03-06 03:34:46 +00:00
|
|
|
PathFinderStep();
|
2012-04-27 22:00:14 +00:00
|
|
|
nu_steps++;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-26 13:59:26 +00:00
|
|
|
if (nu_steps > 0) {
|
|
|
|
_gameRef->LOG(0, "STAT: PathFinder iterations in one loop: %d (%s) _pfMaxTime=%d", nu_steps, _pfReady ? "finished" : "not yet done", _pfMaxTime);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
#else
|
2012-07-18 16:25:09 +00:00
|
|
|
uint32 start = _gameRef->_currentTime;
|
2012-07-26 13:59:26 +00:00
|
|
|
while (!_pfReady && g_system->getMillis() - start <= _pfMaxTime) {
|
|
|
|
pathFinderStep();
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
#endif
|
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::loadFile(const char *filename) {
|
2012-07-29 00:30:26 +00:00
|
|
|
byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename);
|
2012-07-04 17:23:41 +00:00
|
|
|
if (buffer == NULL) {
|
2012-07-21 19:01:47 +00:00
|
|
|
_gameRef->LOG(0, "AdScene::LoadFile failed for file '%s'", filename);
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_FAILED;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-18 16:31:56 +00:00
|
|
|
bool ret;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-22 20:55:54 +00:00
|
|
|
setFilename(filename);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (DID_FAIL(ret = loadBuffer(buffer, true))) {
|
|
|
|
_gameRef->LOG(0, "Error parsing SCENE file '%s'", filename);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-22 20:55:54 +00:00
|
|
|
setFilename(filename);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-25 19:05:03 +00:00
|
|
|
delete[] buffer;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TOKEN_DEF_START
|
|
|
|
TOKEN_DEF(SCENE)
|
|
|
|
TOKEN_DEF(TEMPLATE)
|
|
|
|
TOKEN_DEF(NAME)
|
|
|
|
TOKEN_DEF(LAYER)
|
|
|
|
TOKEN_DEF(WAYPOINTS)
|
|
|
|
TOKEN_DEF(EVENTS)
|
|
|
|
TOKEN_DEF(CURSOR)
|
|
|
|
TOKEN_DEF(CAMERA)
|
|
|
|
TOKEN_DEF(ENTITY)
|
|
|
|
TOKEN_DEF(SCALE_LEVEL)
|
|
|
|
TOKEN_DEF(ROTATION_LEVEL)
|
|
|
|
TOKEN_DEF(EDITOR_MARGIN_H)
|
|
|
|
TOKEN_DEF(EDITOR_MARGIN_V)
|
|
|
|
TOKEN_DEF(EDITOR_COLOR_FRAME)
|
|
|
|
TOKEN_DEF(EDITOR_COLOR_ENTITY_SEL)
|
|
|
|
TOKEN_DEF(EDITOR_COLOR_REGION_SEL)
|
|
|
|
TOKEN_DEF(EDITOR_COLOR_DECORATION_SEL)
|
|
|
|
TOKEN_DEF(EDITOR_COLOR_BLOCKED_SEL)
|
|
|
|
TOKEN_DEF(EDITOR_COLOR_WAYPOINTS_SEL)
|
|
|
|
TOKEN_DEF(EDITOR_COLOR_REGION)
|
|
|
|
TOKEN_DEF(EDITOR_COLOR_DECORATION)
|
|
|
|
TOKEN_DEF(EDITOR_COLOR_BLOCKED)
|
|
|
|
TOKEN_DEF(EDITOR_COLOR_ENTITY)
|
|
|
|
TOKEN_DEF(EDITOR_COLOR_WAYPOINTS)
|
|
|
|
TOKEN_DEF(EDITOR_COLOR_SCALE)
|
|
|
|
TOKEN_DEF(EDITOR_SHOW_REGIONS)
|
|
|
|
TOKEN_DEF(EDITOR_SHOW_BLOCKED)
|
|
|
|
TOKEN_DEF(EDITOR_SHOW_DECORATION)
|
|
|
|
TOKEN_DEF(EDITOR_SHOW_ENTITIES)
|
|
|
|
TOKEN_DEF(EDITOR_SHOW_SCALE)
|
|
|
|
TOKEN_DEF(SCRIPT)
|
|
|
|
TOKEN_DEF(CAPTION)
|
|
|
|
TOKEN_DEF(PROPERTY)
|
|
|
|
TOKEN_DEF(VIEWPORT)
|
|
|
|
TOKEN_DEF(PERSISTENT_STATE_SPRITES)
|
|
|
|
TOKEN_DEF(PERSISTENT_STATE)
|
|
|
|
TOKEN_DEF(EDITOR_PROPERTY)
|
|
|
|
TOKEN_DEF_END
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::loadBuffer(byte *buffer, bool complete) {
|
2012-03-06 03:34:46 +00:00
|
|
|
TOKEN_TABLE_START(commands)
|
|
|
|
TOKEN_TABLE(SCENE)
|
|
|
|
TOKEN_TABLE(TEMPLATE)
|
|
|
|
TOKEN_TABLE(NAME)
|
|
|
|
TOKEN_TABLE(LAYER)
|
|
|
|
TOKEN_TABLE(WAYPOINTS)
|
|
|
|
TOKEN_TABLE(EVENTS)
|
|
|
|
TOKEN_TABLE(CURSOR)
|
|
|
|
TOKEN_TABLE(CAMERA)
|
|
|
|
TOKEN_TABLE(ENTITY)
|
|
|
|
TOKEN_TABLE(SCALE_LEVEL)
|
|
|
|
TOKEN_TABLE(ROTATION_LEVEL)
|
|
|
|
TOKEN_TABLE(EDITOR_MARGIN_H)
|
|
|
|
TOKEN_TABLE(EDITOR_MARGIN_V)
|
|
|
|
TOKEN_TABLE(EDITOR_COLOR_FRAME)
|
|
|
|
TOKEN_TABLE(EDITOR_COLOR_ENTITY_SEL)
|
|
|
|
TOKEN_TABLE(EDITOR_COLOR_REGION_SEL)
|
|
|
|
TOKEN_TABLE(EDITOR_COLOR_DECORATION_SEL)
|
|
|
|
TOKEN_TABLE(EDITOR_COLOR_BLOCKED_SEL)
|
|
|
|
TOKEN_TABLE(EDITOR_COLOR_WAYPOINTS_SEL)
|
|
|
|
TOKEN_TABLE(EDITOR_COLOR_REGION)
|
|
|
|
TOKEN_TABLE(EDITOR_COLOR_DECORATION)
|
|
|
|
TOKEN_TABLE(EDITOR_COLOR_BLOCKED)
|
|
|
|
TOKEN_TABLE(EDITOR_COLOR_ENTITY)
|
|
|
|
TOKEN_TABLE(EDITOR_COLOR_WAYPOINTS)
|
|
|
|
TOKEN_TABLE(EDITOR_COLOR_SCALE)
|
|
|
|
TOKEN_TABLE(EDITOR_SHOW_REGIONS)
|
|
|
|
TOKEN_TABLE(EDITOR_SHOW_DECORATION)
|
|
|
|
TOKEN_TABLE(EDITOR_SHOW_BLOCKED)
|
|
|
|
TOKEN_TABLE(EDITOR_SHOW_ENTITIES)
|
|
|
|
TOKEN_TABLE(EDITOR_SHOW_SCALE)
|
|
|
|
TOKEN_TABLE(SCRIPT)
|
|
|
|
TOKEN_TABLE(CAPTION)
|
|
|
|
TOKEN_TABLE(PROPERTY)
|
|
|
|
TOKEN_TABLE(VIEWPORT)
|
|
|
|
TOKEN_TABLE(PERSISTENT_STATE_SPRITES)
|
|
|
|
TOKEN_TABLE(PERSISTENT_STATE)
|
|
|
|
TOKEN_TABLE(EDITOR_PROPERTY)
|
|
|
|
TOKEN_TABLE_END
|
|
|
|
|
2012-06-25 22:41:05 +00:00
|
|
|
cleanup();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
byte *params;
|
|
|
|
int cmd;
|
2012-07-29 00:30:26 +00:00
|
|
|
BaseParser parser;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 17:23:41 +00:00
|
|
|
if (complete) {
|
2012-07-08 17:55:35 +00:00
|
|
|
if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCENE) {
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->LOG(0, "'SCENE' keyword expected.");
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_FAILED;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer = params;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ar, ag, ab, aa;
|
2012-07-09 02:09:15 +00:00
|
|
|
char camera[MAX_PATH_LENGTH] = "";
|
2012-07-26 20:20:55 +00:00
|
|
|
/* float waypointHeight = -1.0f; */
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-08 17:55:35 +00:00
|
|
|
while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) {
|
2012-03-06 03:34:46 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case TOKEN_TEMPLATE:
|
2012-07-26 13:59:26 +00:00
|
|
|
if (DID_FAIL(loadFile((char *)params))) {
|
|
|
|
cmd = PARSERR_GENERIC;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_NAME:
|
2012-06-25 22:41:05 +00:00
|
|
|
setName((char *)params);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_CAPTION:
|
2012-06-25 23:11:52 +00:00
|
|
|
setCaption((char *)params);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_LAYER: {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdLayer *layer = new AdLayer(_gameRef);
|
2012-07-09 01:27:21 +00:00
|
|
|
if (!layer || DID_FAIL(layer->loadBuffer(params, false))) {
|
2012-03-06 03:34:46 +00:00
|
|
|
cmd = PARSERR_GENERIC;
|
|
|
|
delete layer;
|
|
|
|
layer = NULL;
|
|
|
|
} else {
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->registerObject(layer);
|
2012-07-09 02:50:38 +00:00
|
|
|
_layers.add(layer);
|
2012-04-27 22:00:14 +00:00
|
|
|
if (layer->_main) {
|
|
|
|
_mainLayer = layer;
|
|
|
|
_width = layer->_width;
|
|
|
|
_height = layer->_height;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_WAYPOINTS: {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdWaypointGroup *wpt = new AdWaypointGroup(_gameRef);
|
2012-07-09 01:27:21 +00:00
|
|
|
if (!wpt || DID_FAIL(wpt->loadBuffer(params, false))) {
|
2012-03-06 03:34:46 +00:00
|
|
|
cmd = PARSERR_GENERIC;
|
|
|
|
delete wpt;
|
|
|
|
wpt = NULL;
|
|
|
|
} else {
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->registerObject(wpt);
|
2012-07-09 02:50:38 +00:00
|
|
|
_waypointGroups.add(wpt);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_SCALE_LEVEL: {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdScaleLevel *sl = new AdScaleLevel(_gameRef);
|
2012-07-09 01:27:21 +00:00
|
|
|
if (!sl || DID_FAIL(sl->loadBuffer(params, false))) {
|
2012-03-06 03:34:46 +00:00
|
|
|
cmd = PARSERR_GENERIC;
|
|
|
|
delete sl;
|
|
|
|
sl = NULL;
|
|
|
|
} else {
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->registerObject(sl);
|
2012-07-09 02:50:38 +00:00
|
|
|
_scaleLevels.add(sl);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_ROTATION_LEVEL: {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdRotLevel *rl = new AdRotLevel(_gameRef);
|
2012-07-09 01:27:21 +00:00
|
|
|
if (!rl || DID_FAIL(rl->loadBuffer(params, false))) {
|
2012-03-06 03:34:46 +00:00
|
|
|
cmd = PARSERR_GENERIC;
|
|
|
|
delete rl;
|
|
|
|
rl = NULL;
|
|
|
|
} else {
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->registerObject(rl);
|
2012-07-09 02:50:38 +00:00
|
|
|
_rotLevels.add(rl);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_ENTITY: {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdEntity *entity = new AdEntity(_gameRef);
|
2012-07-09 01:27:21 +00:00
|
|
|
if (!entity || DID_FAIL(entity->loadBuffer(params, false))) {
|
2012-03-06 03:34:46 +00:00
|
|
|
cmd = PARSERR_GENERIC;
|
|
|
|
delete entity;
|
|
|
|
entity = NULL;
|
|
|
|
} else {
|
2012-06-26 11:23:32 +00:00
|
|
|
addObject(entity);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_CURSOR:
|
2012-04-27 22:00:14 +00:00
|
|
|
delete _cursor;
|
2012-07-21 19:01:47 +00:00
|
|
|
_cursor = new BaseSprite(_gameRef);
|
2012-07-09 01:27:21 +00:00
|
|
|
if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) {
|
2012-04-27 22:00:14 +00:00
|
|
|
delete _cursor;
|
|
|
|
_cursor = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
cmd = PARSERR_GENERIC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_CAMERA:
|
|
|
|
strcpy(camera, (char *)params);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_MARGIN_H:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%d", &_editorMarginH);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_MARGIN_V:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%d", &_editorMarginV);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_COLOR_FRAME:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa);
|
2012-07-09 01:27:21 +00:00
|
|
|
_editorColFrame = BYTETORGBA(ar, ag, ab, aa);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_COLOR_ENTITY:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa);
|
2012-07-09 01:27:21 +00:00
|
|
|
_editorColEntity = BYTETORGBA(ar, ag, ab, aa);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_COLOR_ENTITY_SEL:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa);
|
2012-07-09 01:27:21 +00:00
|
|
|
_editorColEntitySel = BYTETORGBA(ar, ag, ab, aa);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_COLOR_REGION_SEL:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa);
|
2012-07-09 01:27:21 +00:00
|
|
|
_editorColRegionSel = BYTETORGBA(ar, ag, ab, aa);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_COLOR_DECORATION_SEL:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa);
|
2012-07-09 01:27:21 +00:00
|
|
|
_editorColDecorSel = BYTETORGBA(ar, ag, ab, aa);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_COLOR_BLOCKED_SEL:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa);
|
2012-07-09 01:27:21 +00:00
|
|
|
_editorColBlockedSel = BYTETORGBA(ar, ag, ab, aa);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_COLOR_WAYPOINTS_SEL:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa);
|
2012-07-09 01:27:21 +00:00
|
|
|
_editorColWaypointsSel = BYTETORGBA(ar, ag, ab, aa);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_COLOR_REGION:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa);
|
2012-07-09 01:27:21 +00:00
|
|
|
_editorColRegion = BYTETORGBA(ar, ag, ab, aa);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_COLOR_DECORATION:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa);
|
2012-07-09 01:27:21 +00:00
|
|
|
_editorColDecor = BYTETORGBA(ar, ag, ab, aa);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_COLOR_BLOCKED:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa);
|
2012-07-09 01:27:21 +00:00
|
|
|
_editorColBlocked = BYTETORGBA(ar, ag, ab, aa);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_COLOR_WAYPOINTS:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa);
|
2012-07-09 01:27:21 +00:00
|
|
|
_editorColWaypoints = BYTETORGBA(ar, ag, ab, aa);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_COLOR_SCALE:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa);
|
2012-07-09 01:27:21 +00:00
|
|
|
_editorColScale = BYTETORGBA(ar, ag, ab, aa);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_SHOW_REGIONS:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%b", &_editorShowRegions);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_SHOW_BLOCKED:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%b", &_editorShowBlocked);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_SHOW_DECORATION:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%b", &_editorShowDecor);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_SHOW_ENTITIES:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%b", &_editorShowEntities);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_SHOW_SCALE:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%b", &_editorShowScale);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_SCRIPT:
|
2012-06-25 22:41:05 +00:00
|
|
|
addScript((char *)params);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_PROPERTY:
|
2012-06-25 22:41:05 +00:00
|
|
|
parseProperty(params, false);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_VIEWPORT: {
|
2012-07-09 10:27:06 +00:00
|
|
|
Rect32 rc;
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom);
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!_viewport) {
|
|
|
|
_viewport = new BaseViewport(_gameRef);
|
|
|
|
}
|
|
|
|
if (_viewport) {
|
|
|
|
_viewport->setRect(rc.left, rc.top, rc.right, rc.bottom, true);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case TOKEN_PERSISTENT_STATE:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%b", &_persistentState);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_PERSISTENT_STATE_SPRITES:
|
2012-07-08 17:55:35 +00:00
|
|
|
parser.scanStr((char *)params, "%b", &_persistentStateSprites);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_PROPERTY:
|
2012-06-25 22:13:57 +00:00
|
|
|
parseEditorProperty(params, false);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cmd == PARSERR_TOKENNOTFOUND) {
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->LOG(0, "Syntax error in SCENE definition");
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_FAILED;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (_mainLayer == NULL) {
|
|
|
|
_gameRef->LOG(0, "Warning: scene '%s' has no main layer.", getFilename());
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
|
2012-06-26 11:23:32 +00:00
|
|
|
sortScaleLevels();
|
|
|
|
sortRotLevels();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
_initialized = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::traverseNodes(bool doUpdate) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!_initialized) {
|
|
|
|
return STATUS_OK;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
int j, k;
|
2012-07-21 19:01:47 +00:00
|
|
|
AdGame *adGame = (AdGame *)_gameRef;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// prepare viewport
|
2012-07-26 13:59:26 +00:00
|
|
|
bool popViewport = false;
|
2012-07-18 16:25:09 +00:00
|
|
|
if (_viewport && !_gameRef->_editorMode) {
|
|
|
|
_gameRef->pushViewport(_viewport);
|
2012-07-26 13:59:26 +00:00
|
|
|
popViewport = true;
|
2012-07-18 16:25:09 +00:00
|
|
|
} else if (adGame->_sceneViewport && !_gameRef->_editorMode) {
|
|
|
|
_gameRef->pushViewport(adGame->_sceneViewport);
|
2012-07-26 13:59:26 +00:00
|
|
|
popViewport = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// *** adjust scroll offset
|
2012-07-09 00:50:15 +00:00
|
|
|
if (doUpdate) {
|
2012-03-06 03:34:46 +00:00
|
|
|
/*
|
2012-07-18 16:25:09 +00:00
|
|
|
if (_autoScroll && _gameRef->_mainObject != NULL)
|
2012-03-06 03:34:46 +00:00
|
|
|
{
|
2012-07-18 16:25:09 +00:00
|
|
|
ScrollToObject(_gameRef->_mainObject);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_autoScroll) {
|
2012-03-06 03:34:46 +00:00
|
|
|
// adjust horizontal scroll
|
2012-07-18 16:25:09 +00:00
|
|
|
if (_gameRef->_timer - _lastTimeH >= _scrollTimeH) {
|
|
|
|
_lastTimeH = _gameRef->_timer;
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_offsetLeft < _targetOffsetLeft) {
|
|
|
|
_offsetLeft += _scrollPixelsH;
|
2012-05-11 15:30:43 +00:00
|
|
|
_offsetLeft = MIN(_offsetLeft, _targetOffsetLeft);
|
2012-04-27 22:00:14 +00:00
|
|
|
} else if (_offsetLeft > _targetOffsetLeft) {
|
|
|
|
_offsetLeft -= _scrollPixelsH;
|
2012-05-11 15:30:43 +00:00
|
|
|
_offsetLeft = MAX(_offsetLeft, _targetOffsetLeft);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// adjust vertical scroll
|
2012-07-18 16:25:09 +00:00
|
|
|
if (_gameRef->_timer - _lastTimeV >= _scrollTimeV) {
|
|
|
|
_lastTimeV = _gameRef->_timer;
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_offsetTop < _targetOffsetTop) {
|
|
|
|
_offsetTop += _scrollPixelsV;
|
2012-05-11 15:30:43 +00:00
|
|
|
_offsetTop = MIN(_offsetTop, _targetOffsetTop);
|
2012-04-27 22:00:14 +00:00
|
|
|
} else if (_offsetTop > _targetOffsetTop) {
|
|
|
|
_offsetTop -= _scrollPixelsV;
|
2012-05-11 15:30:43 +00:00
|
|
|
_offsetTop = MAX(_offsetTop, _targetOffsetTop);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (_offsetTop == _targetOffsetTop && _offsetLeft == _targetOffsetLeft) {
|
|
|
|
_ready = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_ready = true; // not scrolling, i.e. always ready
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-04 19:32:29 +00:00
|
|
|
int viewportWidth, viewportHeight;
|
|
|
|
getViewportSize(&viewportWidth, &viewportHeight);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
int viewportX, viewportY;
|
|
|
|
getViewportOffset(&viewportX, &viewportY);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
int scrollableX = _width - viewportWidth;
|
|
|
|
int scrollableY = _height - viewportHeight;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
double widthRatio = scrollableX <= 0 ? 0 : ((double)(_offsetLeft) / (double)scrollableX);
|
|
|
|
double heightRatio = scrollableY <= 0 ? 0 : ((double)(_offsetTop) / (double)scrollableY);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
int origX, origY;
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->getOffset(&origX, &origY);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// *** display/update everything
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->_renderer->setup2D();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// for each layer
|
2012-07-26 20:20:55 +00:00
|
|
|
/* int mainOffsetX = 0; */
|
|
|
|
/* int mainOffsetY = 0; */
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 02:50:38 +00:00
|
|
|
for (j = 0; j < _layers.getSize(); j++) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!_layers[j]->_active) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// make layer exclusive
|
2012-07-09 00:50:15 +00:00
|
|
|
if (!doUpdate) {
|
2012-07-18 16:25:09 +00:00
|
|
|
if (_layers[j]->_closeUp && !_gameRef->_editorMode) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!_shieldWindow) {
|
|
|
|
_shieldWindow = new UIWindow(_gameRef);
|
|
|
|
}
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_shieldWindow) {
|
|
|
|
_shieldWindow->_posX = _shieldWindow->_posY = 0;
|
2012-07-18 16:25:09 +00:00
|
|
|
_shieldWindow->_width = _gameRef->_renderer->_width;
|
|
|
|
_shieldWindow->_height = _gameRef->_renderer->_height;
|
2012-06-25 23:11:52 +00:00
|
|
|
_shieldWindow->display();
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_paralaxScrolling) {
|
2012-07-04 19:32:29 +00:00
|
|
|
int offsetX = (int)(widthRatio * (_layers[j]->_width - viewportWidth) - viewportX);
|
|
|
|
int offsetY = (int)(heightRatio * (_layers[j]->_height - viewportHeight) - viewportY);
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->setOffset(offsetX, offsetY);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->_offsetPercentX = (float)offsetX / ((float)_layers[j]->_width - viewportWidth) * 100.0f;
|
|
|
|
_gameRef->_offsetPercentY = (float)offsetY / ((float)_layers[j]->_height - viewportHeight) * 100.0f;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-18 16:25:09 +00:00
|
|
|
//_gameRef->QuickMessageForm("%d %f", OffsetX+ViewportX, _gameRef->_offsetPercentX);
|
2012-03-06 03:34:46 +00:00
|
|
|
} else {
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->setOffset(_offsetLeft - viewportX, _offsetTop - viewportY);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->_offsetPercentX = (float)(_offsetLeft - viewportX) / ((float)_layers[j]->_width - viewportWidth) * 100.0f;
|
|
|
|
_gameRef->_offsetPercentY = (float)(_offsetTop - viewportY) / ((float)_layers[j]->_height - viewportHeight) * 100.0f;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// for each node
|
2012-07-09 02:50:38 +00:00
|
|
|
for (k = 0; k < _layers[j]->_nodes.getSize(); k++) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdSceneNode *node = _layers[j]->_nodes[k];
|
2012-07-04 19:32:29 +00:00
|
|
|
switch (node->_type) {
|
2012-03-06 03:34:46 +00:00
|
|
|
case OBJECT_ENTITY:
|
2012-07-18 16:25:09 +00:00
|
|
|
if (node->_entity->_active && (_gameRef->_editorMode || !node->_entity->_editorOnly)) {
|
|
|
|
_gameRef->_renderer->setup2D();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (doUpdate) {
|
|
|
|
node->_entity->update();
|
|
|
|
} else {
|
|
|
|
node->_entity->display();
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OBJECT_REGION: {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (node->_region->_blocked) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (node->_region->_decoration) {
|
|
|
|
break;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!doUpdate) {
|
|
|
|
displayRegionContent(node->_region);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-05-12 05:47:09 +00:00
|
|
|
default:
|
|
|
|
error("AdScene::TraverseNodes - Unhandled enum");
|
|
|
|
break;
|
2012-03-06 03:34:46 +00:00
|
|
|
} // switch
|
|
|
|
} // each node
|
|
|
|
|
|
|
|
// display/update all objects which are off-regions
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_layers[j]->_main) {
|
2012-07-09 00:50:15 +00:00
|
|
|
if (doUpdate) {
|
2012-06-26 11:23:32 +00:00
|
|
|
updateFreeObjects();
|
2012-03-06 03:34:46 +00:00
|
|
|
} else {
|
2012-06-26 11:23:32 +00:00
|
|
|
displayRegionContent(NULL);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // each layer
|
|
|
|
|
|
|
|
|
|
|
|
// restore state
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->setOffset(origX, origY);
|
|
|
|
_gameRef->_renderer->setup2D();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// display/update fader
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_fader) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (doUpdate) {
|
|
|
|
_fader->update();
|
|
|
|
} else {
|
|
|
|
_fader->display();
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (popViewport) {
|
|
|
|
_gameRef->popViewport();
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::display() {
|
2012-06-26 11:23:32 +00:00
|
|
|
return traverseNodes(false);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::updateFreeObjects() {
|
|
|
|
AdGame *adGame = (AdGame *)_gameRef;
|
2012-07-28 21:10:33 +00:00
|
|
|
// 3D-code removed
|
|
|
|
// bool is3DSet;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// *** update all active objects
|
2012-07-28 21:10:33 +00:00
|
|
|
// is3DSet = false;
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < adGame->_objects.getSize(); i++) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!adGame->_objects[i]->_active) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-07-28 21:10:33 +00:00
|
|
|
// 3D-code removed
|
2012-07-04 17:23:41 +00:00
|
|
|
adGame->_objects[i]->update();
|
|
|
|
adGame->_objects[i]->_drawn = false;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _objects.getSize(); i++) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!_objects[i]->_active) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-06-25 23:11:52 +00:00
|
|
|
_objects[i]->update();
|
2012-04-27 22:00:14 +00:00
|
|
|
_objects[i]->_drawn = false;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-18 16:25:09 +00:00
|
|
|
if (_autoScroll && _gameRef->_mainObject != NULL) {
|
|
|
|
scrollToObject(_gameRef->_mainObject);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::displayRegionContent(AdRegion *region, bool display3DOnly) {
|
|
|
|
AdGame *adGame = (AdGame *)_gameRef;
|
2012-07-26 17:41:18 +00:00
|
|
|
BaseArray<AdObject *> objects;
|
2012-07-21 19:01:47 +00:00
|
|
|
AdObject *obj;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// global objects
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < adGame->_objects.getSize(); i++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
obj = adGame->_objects[i];
|
2012-07-07 15:52:08 +00:00
|
|
|
if (obj->_active && !obj->_drawn && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) {
|
2012-07-09 02:50:38 +00:00
|
|
|
objects.add(obj);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// scene objects
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _objects.getSize(); i++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
obj = _objects[i];
|
2012-07-07 15:52:08 +00:00
|
|
|
if (obj->_active && !obj->_editorOnly && !obj->_drawn && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) {
|
2012-07-09 02:50:38 +00:00
|
|
|
objects.add(obj);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
// sort by _posY
|
2012-07-21 19:01:47 +00:00
|
|
|
qsort(objects.getData(), objects.getSize(), sizeof(AdObject *), AdScene::compareObjs);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// display them
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < objects.getSize(); i++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
obj = objects[i];
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (display3DOnly && !obj->_is3D) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->_renderer->setup2D();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (_gameRef->_editorMode || !obj->_editorOnly) {
|
|
|
|
obj->display();
|
|
|
|
}
|
2012-07-04 19:32:29 +00:00
|
|
|
obj->_drawn = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// display design only objects
|
2012-07-04 19:32:29 +00:00
|
|
|
if (!display3DOnly) {
|
2012-07-18 16:25:09 +00:00
|
|
|
if (_gameRef->_editorMode && region == NULL) {
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _objects.getSize(); i++) {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_objects[i]->_active && _objects[i]->_editorOnly) {
|
2012-06-25 23:11:52 +00:00
|
|
|
_objects[i]->display();
|
2012-04-27 22:00:14 +00:00
|
|
|
_objects[i]->_drawn = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
int AdScene::compareObjs(const void *obj1, const void *obj2) {
|
|
|
|
AdObject *object1 = *(AdObject **)obj1;
|
|
|
|
AdObject *object2 = *(AdObject **)obj2;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (object1->_posY < object2->_posY) {
|
|
|
|
return -1;
|
|
|
|
} else if (object1->_posY > object2->_posY) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::displayRegionContentOld(AdRegion *region) {
|
|
|
|
AdGame *adGame = (AdGame *)_gameRef;
|
|
|
|
AdObject *obj;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
// display all objects in region sorted by _posY
|
2012-03-06 03:34:46 +00:00
|
|
|
do {
|
|
|
|
obj = NULL;
|
|
|
|
int minY = INT_MAX;
|
|
|
|
|
|
|
|
// global objects
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < adGame->_objects.getSize(); i++) {
|
2012-07-07 15:52:08 +00:00
|
|
|
if (adGame->_objects[i]->_active && !adGame->_objects[i]->_drawn && adGame->_objects[i]->_posY < minY && (adGame->_objects[i]->_stickRegion == region || region == NULL || (adGame->_objects[i]->_stickRegion == NULL && region->pointInRegion(adGame->_objects[i]->_posX, adGame->_objects[i]->_posY)))) {
|
2012-07-04 17:23:41 +00:00
|
|
|
obj = adGame->_objects[i];
|
|
|
|
minY = adGame->_objects[i]->_posY;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// scene objects
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _objects.getSize(); i++) {
|
2012-07-07 15:52:08 +00:00
|
|
|
if (_objects[i]->_active && !_objects[i]->_editorOnly && !_objects[i]->_drawn && _objects[i]->_posY < minY && (_objects[i]->_stickRegion == region || region == NULL || (_objects[i]->_stickRegion == NULL && region->pointInRegion(_objects[i]->_posX, _objects[i]->_posY)))) {
|
2012-04-27 22:00:14 +00:00
|
|
|
obj = _objects[i];
|
|
|
|
minY = _objects[i]->_posY;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (obj != NULL) {
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->_renderer->setup2D();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (_gameRef->_editorMode || !obj->_editorOnly) {
|
|
|
|
obj->display();
|
|
|
|
}
|
2012-04-27 22:00:14 +00:00
|
|
|
obj->_drawn = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
} while (obj != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
// design only objects
|
2012-07-18 16:25:09 +00:00
|
|
|
if (_gameRef->_editorMode && region == NULL) {
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _objects.getSize(); i++) {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_objects[i]->_active && _objects[i]->_editorOnly) {
|
2012-06-25 23:11:52 +00:00
|
|
|
_objects[i]->display();
|
2012-04-27 22:00:14 +00:00
|
|
|
_objects[i]->_drawn = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::update() {
|
2012-06-26 11:23:32 +00:00
|
|
|
return traverseNodes(true);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
void AdScene::scrollTo(int offsetX, int offsetY) {
|
2012-07-04 19:32:29 +00:00
|
|
|
int viewportWidth, viewportHeight;
|
|
|
|
getViewportSize(&viewportWidth, &viewportHeight);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
int origOffsetLeft = _targetOffsetLeft;
|
|
|
|
int origOffsetTop = _targetOffsetTop;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
_targetOffsetLeft = MAX(0, offsetX - viewportWidth / 2);
|
|
|
|
_targetOffsetLeft = MIN(_targetOffsetLeft, _width - viewportWidth);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
_targetOffsetTop = MAX(0, offsetY - viewportHeight / 2);
|
|
|
|
_targetOffsetTop = MIN(_targetOffsetTop, _height - viewportHeight);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
|
2012-07-18 16:25:09 +00:00
|
|
|
if (_gameRef->_mainObject && _gameRef->_mainObject->_is3D) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (abs(origOffsetLeft - _targetOffsetLeft) < 5) {
|
|
|
|
_targetOffsetLeft = origOffsetLeft;
|
|
|
|
}
|
|
|
|
if (abs(origOffsetTop - _targetOffsetTop) < 5) {
|
|
|
|
_targetOffsetTop = origOffsetTop;
|
|
|
|
}
|
2012-04-27 22:00:14 +00:00
|
|
|
//_targetOffsetTop = 0;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
_ready = false;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
void AdScene::scrollToObject(BaseObject *object) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (object) {
|
|
|
|
scrollTo(object->_posX, object->_posY - object->getHeight() / 2);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
void AdScene::skipToObject(BaseObject *object) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (object) {
|
|
|
|
skipTo(object->_posX, object->_posY - object->getHeight() / 2);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
void AdScene::skipTo(int offsetX, int offsetY) {
|
2012-07-04 19:32:29 +00:00
|
|
|
int viewportWidth, viewportHeight;
|
|
|
|
getViewportSize(&viewportWidth, &viewportHeight);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
_offsetLeft = MAX(0, offsetX - viewportWidth / 2);
|
|
|
|
_offsetLeft = MIN(_offsetLeft, _width - viewportWidth);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
_offsetTop = MAX(0, offsetY - viewportHeight / 2);
|
|
|
|
_offsetTop = MIN(_offsetTop, _height - viewportHeight);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
_targetOffsetLeft = _offsetLeft;
|
|
|
|
_targetOffsetTop = _offsetTop;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// high level scripting interface
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) {
|
2012-03-06 03:34:46 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// LoadActor
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
if (strcmp(name, "LoadActor") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(1);
|
2012-07-21 19:01:47 +00:00
|
|
|
AdActor *act = new AdActor(_gameRef);
|
2012-07-09 01:27:21 +00:00
|
|
|
if (act && DID_SUCCEED(act->loadFile(stack->pop()->getString()))) {
|
2012-06-26 11:23:32 +00:00
|
|
|
addObject(act);
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->pushNative(act, true);
|
2012-03-06 03:34:46 +00:00
|
|
|
} else {
|
|
|
|
delete act;
|
|
|
|
act = NULL;
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->pushNULL();
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// LoadEntity
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "LoadEntity") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(1);
|
2012-07-21 19:01:47 +00:00
|
|
|
AdEntity *ent = new AdEntity(_gameRef);
|
2012-07-09 01:27:21 +00:00
|
|
|
if (ent && DID_SUCCEED(ent->loadFile(stack->pop()->getString()))) {
|
2012-06-26 11:23:32 +00:00
|
|
|
addObject(ent);
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->pushNative(ent, true);
|
2012-03-06 03:34:46 +00:00
|
|
|
} else {
|
|
|
|
delete ent;
|
|
|
|
ent = NULL;
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->pushNULL();
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// CreateEntity
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "CreateEntity") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(1);
|
2012-07-21 19:01:47 +00:00
|
|
|
ScValue *val = stack->pop();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-21 19:01:47 +00:00
|
|
|
AdEntity *ent = new AdEntity(_gameRef);
|
2012-07-04 19:32:29 +00:00
|
|
|
addObject(ent);
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!val->isNULL()) {
|
|
|
|
ent->setName(val->getString());
|
|
|
|
}
|
2012-07-04 19:32:29 +00:00
|
|
|
stack->pushNative(ent, true);
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// UnloadObject / UnloadActor / UnloadEntity / UnloadActor3D / DeleteEntity
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "UnloadObject") == 0 || strcmp(name, "UnloadActor") == 0 || strcmp(name, "UnloadEntity") == 0 || strcmp(name, "UnloadActor3D") == 0 || strcmp(name, "DeleteEntity") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(1);
|
2012-07-21 19:01:47 +00:00
|
|
|
ScValue *val = stack->pop();
|
|
|
|
AdObject *obj = (AdObject *)val->getNative();
|
2012-06-26 11:23:32 +00:00
|
|
|
removeObject(obj);
|
2012-07-26 13:59:26 +00:00
|
|
|
if (val->getType() == VAL_VARIABLE_REF) {
|
|
|
|
val->setNULL();
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->pushNULL();
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// SkipTo
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "SkipTo") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(2);
|
2012-07-21 19:01:47 +00:00
|
|
|
ScValue *val1 = stack->pop();
|
|
|
|
ScValue *val2 = stack->pop();
|
2012-07-03 03:37:08 +00:00
|
|
|
if (val1->isNative()) {
|
2012-07-21 19:01:47 +00:00
|
|
|
skipToObject((BaseObject *)val1->getNative());
|
2012-03-06 03:34:46 +00:00
|
|
|
} else {
|
2012-07-03 03:37:08 +00:00
|
|
|
skipTo(val1->getInt(), val2->getInt());
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->pushNULL();
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// ScrollTo / ScrollToAsync
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "ScrollTo") == 0 || strcmp(name, "ScrollToAsync") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(2);
|
2012-07-21 19:01:47 +00:00
|
|
|
ScValue *val1 = stack->pop();
|
|
|
|
ScValue *val2 = stack->pop();
|
2012-07-03 03:37:08 +00:00
|
|
|
if (val1->isNative()) {
|
2012-07-21 19:01:47 +00:00
|
|
|
scrollToObject((BaseObject *)val1->getNative());
|
2012-03-06 03:34:46 +00:00
|
|
|
} else {
|
2012-07-03 03:37:08 +00:00
|
|
|
scrollTo(val1->getInt(), val2->getInt());
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-26 13:59:26 +00:00
|
|
|
if (strcmp(name, "ScrollTo") == 0) {
|
|
|
|
script->waitForExclusive(this);
|
|
|
|
}
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->pushNULL();
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// GetLayer
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "GetLayer") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(1);
|
2012-07-21 19:01:47 +00:00
|
|
|
ScValue *val = stack->pop();
|
2012-07-03 03:37:08 +00:00
|
|
|
if (val->isInt()) {
|
|
|
|
int layer = val->getInt();
|
2012-07-26 13:59:26 +00:00
|
|
|
if (layer < 0 || layer >= _layers.getSize()) {
|
|
|
|
stack->pushNULL();
|
|
|
|
} else {
|
|
|
|
stack->pushNative(_layers[layer], true);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
} else {
|
2012-07-26 13:59:26 +00:00
|
|
|
const char *layerName = val->getString();
|
|
|
|
bool layerFound = false;
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _layers.getSize(); i++) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (scumm_stricmp(layerName, _layers[i]->getName()) == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->pushNative(_layers[i], true);
|
2012-07-26 13:59:26 +00:00
|
|
|
layerFound = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!layerFound) {
|
|
|
|
stack->pushNULL();
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// GetWaypointGroup
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "GetWaypointGroup") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(1);
|
2012-07-03 03:37:08 +00:00
|
|
|
int group = stack->pop()->getInt();
|
2012-07-26 13:59:26 +00:00
|
|
|
if (group < 0 || group >= _waypointGroups.getSize()) {
|
|
|
|
stack->pushNULL();
|
|
|
|
} else {
|
|
|
|
stack->pushNative(_waypointGroups[group], true);
|
|
|
|
}
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// GetNode
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "GetNode") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(1);
|
2012-07-03 03:37:08 +00:00
|
|
|
const char *nodeName = stack->pop()->getString();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-21 19:01:47 +00:00
|
|
|
BaseObject *node = getNodeByName(nodeName);
|
2012-07-26 13:59:26 +00:00
|
|
|
if (node) {
|
|
|
|
stack->pushNative((BaseScriptable *)node, true);
|
|
|
|
} else {
|
|
|
|
stack->pushNULL();
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// GetFreeNode
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "GetFreeNode") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(1);
|
2012-07-21 19:01:47 +00:00
|
|
|
ScValue *val = stack->pop();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-21 19:01:47 +00:00
|
|
|
AdObject *ret = NULL;
|
2012-07-04 19:32:29 +00:00
|
|
|
if (val->isInt()) {
|
|
|
|
int index = val->getInt();
|
2012-07-26 13:59:26 +00:00
|
|
|
if (index >= 0 && index < _objects.getSize()) {
|
|
|
|
ret = _objects[index];
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
} else {
|
2012-07-04 19:32:29 +00:00
|
|
|
const char *nodeName = val->getString();
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _objects.getSize(); i++) {
|
2012-07-22 21:17:32 +00:00
|
|
|
if (_objects[i] && _objects[i]->getName() && scumm_stricmp(_objects[i]->getName(), nodeName) == 0) {
|
2012-07-04 19:32:29 +00:00
|
|
|
ret = _objects[i];
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-26 13:59:26 +00:00
|
|
|
if (ret) {
|
|
|
|
stack->pushNative(ret, true);
|
|
|
|
} else {
|
|
|
|
stack->pushNULL();
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// GetRegionAt
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "GetRegionAt") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(3);
|
2012-07-04 19:32:29 +00:00
|
|
|
int x = stack->pop()->getInt();
|
|
|
|
int y = stack->pop()->getInt();
|
2012-07-21 19:01:47 +00:00
|
|
|
ScValue *val = stack->pop();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
bool includeDecors = false;
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!val->isNULL()) {
|
|
|
|
includeDecors = val->getBool();
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_mainLayer) {
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdSceneNode *node = _mainLayer->_nodes[i];
|
2012-07-07 15:52:08 +00:00
|
|
|
if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (node->_region->_decoration && !includeDecors) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
stack->pushNative(node->_region, true);
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->pushNULL();
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsBlockedAt
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "IsBlockedAt") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(2);
|
2012-07-04 19:32:29 +00:00
|
|
|
int x = stack->pop()->getInt();
|
|
|
|
int y = stack->pop()->getInt();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
stack->pushBool(isBlockedAt(x, y));
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsWalkableAt
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "IsWalkableAt") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(2);
|
2012-07-04 19:32:29 +00:00
|
|
|
int x = stack->pop()->getInt();
|
|
|
|
int y = stack->pop()->getInt();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
stack->pushBool(isWalkableAt(x, y));
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// GetScaleAt
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "GetScaleAt") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(2);
|
2012-07-04 19:32:29 +00:00
|
|
|
int x = stack->pop()->getInt();
|
|
|
|
int y = stack->pop()->getInt();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
stack->pushFloat(getZoomAt(x, y));
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// GetRotationAt
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "GetRotationAt") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(2);
|
2012-07-04 19:32:29 +00:00
|
|
|
int x = stack->pop()->getInt();
|
|
|
|
int y = stack->pop()->getInt();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
stack->pushFloat(getRotationAt(x, y));
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsScrolling
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "IsScrolling") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(0);
|
2012-07-04 19:32:29 +00:00
|
|
|
bool ret = false;
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_autoScroll) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (_targetOffsetLeft != _offsetLeft || _targetOffsetTop != _offsetTop) {
|
|
|
|
ret = true;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
stack->pushBool(ret);
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// FadeOut / FadeOutAsync
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "FadeOut") == 0 || strcmp(name, "FadeOutAsync") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(5);
|
2012-07-04 19:32:29 +00:00
|
|
|
uint32 duration = stack->pop()->getInt(500);
|
|
|
|
byte red = stack->pop()->getInt(0);
|
|
|
|
byte green = stack->pop()->getInt(0);
|
|
|
|
byte blue = stack->pop()->getInt(0);
|
|
|
|
byte alpha = stack->pop()->getInt(0xFF);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
_fader->fadeOut(BYTETORGBA(red, green, blue, alpha), duration);
|
2012-07-26 13:59:26 +00:00
|
|
|
if (strcmp(name, "FadeOutAsync") != 0) {
|
|
|
|
script->waitFor(_fader);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->pushNULL();
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// FadeIn / FadeInAsync
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "FadeIn") == 0 || strcmp(name, "FadeInAsync") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(5);
|
2012-07-04 19:32:29 +00:00
|
|
|
uint32 duration = stack->pop()->getInt(500);
|
|
|
|
byte red = stack->pop()->getInt(0);
|
|
|
|
byte green = stack->pop()->getInt(0);
|
|
|
|
byte blue = stack->pop()->getInt(0);
|
|
|
|
byte alpha = stack->pop()->getInt(0xFF);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
_fader->fadeIn(BYTETORGBA(red, green, blue, alpha), duration);
|
2012-07-26 13:59:26 +00:00
|
|
|
if (strcmp(name, "FadeInAsync") != 0) {
|
|
|
|
script->waitFor(_fader);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->pushNULL();
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// GetFadeColor
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "GetFadeColor") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(0);
|
|
|
|
stack->pushInt(_fader->getCurrentColor());
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsPointInViewport
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "IsPointInViewport") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(2);
|
2012-07-04 19:32:29 +00:00
|
|
|
int x = stack->pop()->getInt();
|
|
|
|
int y = stack->pop()->getInt();
|
|
|
|
stack->pushBool(pointInViewport(x, y));
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// SetViewport
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "SetViewport") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(4);
|
2012-07-04 19:32:29 +00:00
|
|
|
int x = stack->pop()->getInt();
|
|
|
|
int y = stack->pop()->getInt();
|
|
|
|
int width = stack->pop()->getInt();
|
|
|
|
int height = stack->pop()->getInt();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (width <= 0) {
|
|
|
|
width = _gameRef->_renderer->_width;
|
|
|
|
}
|
|
|
|
if (height <= 0) {
|
|
|
|
height = _gameRef->_renderer->_height;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!_viewport) {
|
|
|
|
_viewport = new BaseViewport(_gameRef);
|
|
|
|
}
|
|
|
|
if (_viewport) {
|
|
|
|
_viewport->setRect(x, y, x + width, y + height);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->pushBool(true);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// AddLayer
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "AddLayer") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(1);
|
2012-07-21 19:01:47 +00:00
|
|
|
ScValue *val = stack->pop();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-21 19:01:47 +00:00
|
|
|
AdLayer *layer = new AdLayer(_gameRef);
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!val->isNULL()) {
|
|
|
|
layer->setName(val->getString());
|
|
|
|
}
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_mainLayer) {
|
2012-07-04 19:32:29 +00:00
|
|
|
layer->_width = _mainLayer->_width;
|
|
|
|
layer->_height = _mainLayer->_height;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-09 02:50:38 +00:00
|
|
|
_layers.add(layer);
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->registerObject(layer);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
stack->pushNative(layer, true);
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// InsertLayer
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "InsertLayer") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(2);
|
2012-07-04 19:32:29 +00:00
|
|
|
int index = stack->pop()->getInt();
|
2012-07-21 19:01:47 +00:00
|
|
|
ScValue *val = stack->pop();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-21 19:01:47 +00:00
|
|
|
AdLayer *layer = new AdLayer(_gameRef);
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!val->isNULL()) {
|
|
|
|
layer->setName(val->getString());
|
|
|
|
}
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_mainLayer) {
|
2012-07-04 19:32:29 +00:00
|
|
|
layer->_width = _mainLayer->_width;
|
|
|
|
layer->_height = _mainLayer->_height;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-26 13:59:26 +00:00
|
|
|
if (index < 0) {
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
if (index <= _layers.getSize() - 1) {
|
2012-07-26 17:41:18 +00:00
|
|
|
_layers.insert_at(index, layer);
|
2012-07-26 13:59:26 +00:00
|
|
|
} else {
|
|
|
|
_layers.add(layer);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->registerObject(layer);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
stack->pushNative(layer, true);
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// DeleteLayer
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "DeleteLayer") == 0) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->correctParams(1);
|
2012-07-21 19:01:47 +00:00
|
|
|
ScValue *val = stack->pop();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-21 19:01:47 +00:00
|
|
|
AdLayer *toDelete = NULL;
|
2012-07-04 19:32:29 +00:00
|
|
|
if (val->isNative()) {
|
2012-07-21 19:01:47 +00:00
|
|
|
BaseScriptable *temp = val->getNative();
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _layers.getSize(); i++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (_layers[i] == temp) {
|
|
|
|
toDelete = _layers[i];
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2012-07-04 19:32:29 +00:00
|
|
|
int index = val->getInt();
|
2012-07-09 02:50:38 +00:00
|
|
|
if (index >= 0 && index < _layers.getSize()) {
|
2012-07-04 19:32:29 +00:00
|
|
|
toDelete = _layers[index];
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-04 19:32:29 +00:00
|
|
|
if (toDelete == NULL) {
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->pushBool(false);
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
if (toDelete->_main) {
|
2012-07-08 22:11:20 +00:00
|
|
|
script->runtimeError("Scene.DeleteLayer - cannot delete main scene layer");
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->pushBool(false);
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _layers.getSize(); i++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (_layers[i] == toDelete) {
|
2012-07-26 17:41:18 +00:00
|
|
|
_layers.remove_at(i);
|
2012-07-18 16:25:09 +00:00
|
|
|
_gameRef->unregisterObject(toDelete);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-07-03 03:08:59 +00:00
|
|
|
stack->pushBool(true);
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-07-26 13:59:26 +00:00
|
|
|
} else {
|
|
|
|
return BaseObject::scCallMethod(script, stack, thisStack, name);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
ScValue *AdScene::scGetProperty(const char *name) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_scValue->setNULL();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Type
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
if (strcmp(name, "Type") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_scValue->setString("scene");
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// NumLayers (RO)
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "NumLayers") == 0) {
|
2012-07-09 02:50:38 +00:00
|
|
|
_scValue->setInt(_layers.getSize());
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// NumWaypointGroups (RO)
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "NumWaypointGroups") == 0) {
|
2012-07-09 02:50:38 +00:00
|
|
|
_scValue->setInt(_waypointGroups.getSize());
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// MainLayer (RO)
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "MainLayer") == 0) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (_mainLayer) {
|
|
|
|
_scValue->setNative(_mainLayer, true);
|
|
|
|
} else {
|
|
|
|
_scValue->setNULL();
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// NumFreeNodes (RO)
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "NumFreeNodes") == 0) {
|
2012-07-09 02:50:38 +00:00
|
|
|
_scValue->setInt(_objects.getSize());
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// MouseX (RO)
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "MouseX") == 0) {
|
2012-07-04 19:32:29 +00:00
|
|
|
int viewportX;
|
|
|
|
getViewportOffset(&viewportX);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-18 16:25:09 +00:00
|
|
|
_scValue->setInt(_gameRef->_mousePos.x + _offsetLeft - viewportX);
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// MouseY (RO)
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "MouseY") == 0) {
|
2012-07-04 19:32:29 +00:00
|
|
|
int viewportY;
|
|
|
|
getViewportOffset(NULL, &viewportY);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-18 16:25:09 +00:00
|
|
|
_scValue->setInt(_gameRef->_mousePos.y + _offsetTop - viewportY);
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// AutoScroll
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "AutoScroll") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_scValue->setBool(_autoScroll);
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// PersistentState
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "PersistentState") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_scValue->setBool(_persistentState);
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// PersistentStateSprites
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "PersistentStateSprites") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_scValue->setBool(_persistentStateSprites);
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// ScrollPixelsX
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "ScrollPixelsX") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_scValue->setInt(_scrollPixelsH);
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// ScrollPixelsY
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "ScrollPixelsY") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_scValue->setInt(_scrollPixelsV);
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// ScrollSpeedX
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "ScrollSpeedX") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_scValue->setInt(_scrollTimeH);
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// ScrollSpeedY
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "ScrollSpeedY") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_scValue->setInt(_scrollTimeV);
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// OffsetX
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "OffsetX") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_scValue->setInt(_offsetLeft);
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// OffsetY
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "OffsetY") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_scValue->setInt(_offsetTop);
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Width (RO)
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "Width") == 0) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (_mainLayer) {
|
|
|
|
_scValue->setInt(_mainLayer->_width);
|
|
|
|
} else {
|
|
|
|
_scValue->setInt(0);
|
|
|
|
}
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Height (RO)
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "Height") == 0) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (_mainLayer) {
|
|
|
|
_scValue->setInt(_mainLayer->_height);
|
|
|
|
} else {
|
|
|
|
_scValue->setInt(0);
|
|
|
|
}
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-07-26 13:59:26 +00:00
|
|
|
} else {
|
|
|
|
return BaseObject::scGetProperty(name);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::scSetProperty(const char *name, ScValue *value) {
|
2012-03-06 03:34:46 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
if (strcmp(name, "Name") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
setName(value->getString());
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// AutoScroll
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "AutoScroll") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_autoScroll = value->getBool();
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// PersistentState
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "PersistentState") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_persistentState = value->getBool();
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// PersistentStateSprites
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "PersistentStateSprites") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_persistentStateSprites = value->getBool();
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// ScrollPixelsX
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "ScrollPixelsX") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_scrollPixelsH = value->getInt();
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// ScrollPixelsY
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "ScrollPixelsY") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_scrollPixelsV = value->getInt();
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// ScrollSpeedX
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "ScrollSpeedX") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_scrollTimeH = value->getInt();
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// ScrollSpeedY
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "ScrollSpeedY") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_scrollTimeV = value->getInt();
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// OffsetX
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "OffsetX") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_offsetLeft = value->getInt();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
int viewportWidth, viewportHeight;
|
|
|
|
getViewportSize(&viewportWidth, &viewportHeight);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
_offsetLeft = MAX(0, _offsetLeft - viewportWidth / 2);
|
|
|
|
_offsetLeft = MIN(_offsetLeft, _width - viewportWidth);
|
2012-04-27 22:00:14 +00:00
|
|
|
_targetOffsetLeft = _offsetLeft;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// OffsetY
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-03 02:31:32 +00:00
|
|
|
else if (strcmp(name, "OffsetY") == 0) {
|
2012-07-03 03:37:08 +00:00
|
|
|
_offsetTop = value->getInt();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
int viewportWidth, viewportHeight;
|
|
|
|
getViewportSize(&viewportWidth, &viewportHeight);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
_offsetTop = MAX(0, _offsetTop - viewportHeight / 2);
|
|
|
|
_offsetTop = MIN(_offsetTop, _height - viewportHeight);
|
2012-04-27 22:00:14 +00:00
|
|
|
_targetOffsetTop = _offsetTop;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-07-26 13:59:26 +00:00
|
|
|
} else {
|
|
|
|
return BaseObject::scSetProperty(name, value);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
const char *AdScene::scToString() {
|
2012-03-06 03:34:46 +00:00
|
|
|
return "[scene object]";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::addObject(AdObject *object) {
|
2012-07-09 02:50:38 +00:00
|
|
|
_objects.add(object);
|
2012-07-18 16:25:09 +00:00
|
|
|
return _gameRef->registerObject(object);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::removeObject(AdObject *object) {
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _objects.getSize(); i++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (_objects[i] == object) {
|
2012-07-26 17:41:18 +00:00
|
|
|
_objects.remove_at(i);
|
2012-07-18 16:25:09 +00:00
|
|
|
return _gameRef->unregisterObject(object);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_FAILED;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) {
|
2012-03-06 03:34:46 +00:00
|
|
|
int i;
|
|
|
|
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent, "SCENE {\n");
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-22 21:17:32 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName());
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption());
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (_persistentState) {
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "PERSISTENT_STATE=%s\n", _persistentState ? "TRUE" : "FALSE");
|
2012-07-26 13:59:26 +00:00
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!_persistentStateSprites) {
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "PERSISTENT_STATE_SPRITES=%s\n", _persistentStateSprites ? "TRUE" : "FALSE");
|
2012-07-26 13:59:26 +00:00
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
// scripts
|
2012-07-09 02:50:38 +00:00
|
|
|
for (i = 0; i < _scripts.getSize(); i++) {
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "\n");
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// properties
|
2012-07-26 13:59:26 +00:00
|
|
|
if (_scProp) {
|
|
|
|
_scProp->saveAsText(buffer, indent + 2);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// viewport
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_viewport) {
|
2012-07-09 10:27:06 +00:00
|
|
|
Rect32 *rc = _viewport->getRect();
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "VIEWPORT { %d, %d, %d, %d }\n", rc->left, rc->top, rc->right, rc->bottom);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// editor settings
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "; ----- editor settings\n");
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_MARGIN_H=%d\n", _editorMarginH);
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_MARGIN_V=%d\n", _editorMarginV);
|
2012-07-09 01:27:21 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_COLOR_FRAME { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColFrame), RGBCOLGetG(_editorColFrame), RGBCOLGetB(_editorColFrame), RGBCOLGetA(_editorColFrame));
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_COLOR_ENTITY_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColEntitySel), RGBCOLGetG(_editorColEntitySel), RGBCOLGetB(_editorColEntitySel), RGBCOLGetA(_editorColEntitySel));
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_COLOR_REGION_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColRegionSel), RGBCOLGetG(_editorColRegionSel), RGBCOLGetB(_editorColRegionSel), RGBCOLGetA(_editorColRegionSel));
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_COLOR_BLOCKED_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColBlockedSel), RGBCOLGetG(_editorColBlockedSel), RGBCOLGetB(_editorColBlockedSel), RGBCOLGetA(_editorColBlockedSel));
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_COLOR_DECORATION_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColDecorSel), RGBCOLGetG(_editorColDecorSel), RGBCOLGetB(_editorColDecorSel), RGBCOLGetA(_editorColDecorSel));
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_COLOR_WAYPOINTS_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColWaypointsSel), RGBCOLGetG(_editorColWaypointsSel), RGBCOLGetB(_editorColWaypointsSel), RGBCOLGetA(_editorColWaypointsSel));
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_COLOR_ENTITY { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColEntity), RGBCOLGetG(_editorColEntity), RGBCOLGetB(_editorColEntity), RGBCOLGetA(_editorColEntity));
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_COLOR_REGION { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColRegion), RGBCOLGetG(_editorColRegion), RGBCOLGetB(_editorColRegion), RGBCOLGetA(_editorColRegion));
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_COLOR_DECORATION { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColDecor), RGBCOLGetG(_editorColDecor), RGBCOLGetB(_editorColDecor), RGBCOLGetA(_editorColDecor));
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_COLOR_BLOCKED { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColBlocked), RGBCOLGetG(_editorColBlocked), RGBCOLGetB(_editorColBlocked), RGBCOLGetA(_editorColBlocked));
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_COLOR_WAYPOINTS { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColWaypoints), RGBCOLGetG(_editorColWaypoints), RGBCOLGetB(_editorColWaypoints), RGBCOLGetA(_editorColWaypoints));
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_COLOR_SCALE { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColScale), RGBCOLGetG(_editorColScale), RGBCOLGetB(_editorColScale), RGBCOLGetA(_editorColScale));
|
2012-07-04 17:23:41 +00:00
|
|
|
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_SHOW_REGIONS=%s\n", _editorShowRegions ? "TRUE" : "FALSE");
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_SHOW_BLOCKED=%s\n", _editorShowBlocked ? "TRUE" : "FALSE");
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_SHOW_DECORATION=%s\n", _editorShowDecor ? "TRUE" : "FALSE");
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_SHOW_ENTITIES=%s\n", _editorShowEntities ? "TRUE" : "FALSE");
|
|
|
|
buffer->putTextIndent(indent + 2, "EDITOR_SHOW_SCALE=%s\n", _editorShowScale ? "TRUE" : "FALSE");
|
|
|
|
|
|
|
|
buffer->putTextIndent(indent + 2, "\n");
|
|
|
|
|
2012-07-21 19:01:47 +00:00
|
|
|
BaseClass::saveAsText(buffer, indent + 2);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// waypoints
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "; ----- waypoints\n");
|
2012-07-26 13:59:26 +00:00
|
|
|
for (i = 0; i < _waypointGroups.getSize(); i++) {
|
|
|
|
_waypointGroups[i]->saveAsText(buffer, indent + 2);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "\n");
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// layers
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "; ----- layers\n");
|
2012-07-26 13:59:26 +00:00
|
|
|
for (i = 0; i < _layers.getSize(); i++) {
|
|
|
|
_layers[i]->saveAsText(buffer, indent + 2);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// scale levels
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "; ----- scale levels\n");
|
2012-07-26 13:59:26 +00:00
|
|
|
for (i = 0; i < _scaleLevels.getSize(); i++) {
|
|
|
|
_scaleLevels[i]->saveAsText(buffer, indent + 2);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// rotation levels
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "; ----- rotation levels\n");
|
2012-07-26 13:59:26 +00:00
|
|
|
for (i = 0; i < _rotLevels.getSize(); i++) {
|
|
|
|
_rotLevels[i]->saveAsText(buffer, indent + 2);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "\n");
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// free entities
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent + 2, "; ----- free entities\n");
|
2012-07-09 02:50:38 +00:00
|
|
|
for (i = 0; i < _objects.getSize(); i++) {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_objects[i]->_type == OBJECT_ENTITY) {
|
2012-07-04 17:23:41 +00:00
|
|
|
_objects[i]->saveAsText(buffer, indent + 2);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-04 17:23:41 +00:00
|
|
|
buffer->putTextIndent(indent, "}\n");
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::sortScaleLevels() {
|
2012-03-06 03:34:46 +00:00
|
|
|
bool changed;
|
|
|
|
do {
|
|
|
|
changed = false;
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _scaleLevels.getSize() - 1; i++) {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_scaleLevels[i]->_posY > _scaleLevels[i + 1]->_posY) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdScaleLevel *sl = _scaleLevels[i];
|
2012-04-27 22:00:14 +00:00
|
|
|
_scaleLevels[i] = _scaleLevels[i + 1];
|
|
|
|
_scaleLevels[i + 1] = sl;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (changed);
|
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::sortRotLevels() {
|
2012-03-06 03:34:46 +00:00
|
|
|
bool changed;
|
|
|
|
do {
|
|
|
|
changed = false;
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _rotLevels.getSize() - 1; i++) {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_rotLevels[i]->_posX > _rotLevels[i + 1]->_posX) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdRotLevel *rl = _rotLevels[i];
|
2012-04-27 22:00:14 +00:00
|
|
|
_rotLevels[i] = _rotLevels[i + 1];
|
|
|
|
_rotLevels[i + 1] = rl;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (changed);
|
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
float AdScene::getScaleAt(int Y) {
|
|
|
|
AdScaleLevel *prev = NULL;
|
|
|
|
AdScaleLevel *next = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _scaleLevels.getSize(); i++) {
|
2012-07-21 19:01:47 +00:00
|
|
|
/* AdScaleLevel *xxx = _scaleLevels[i];*/
|
2012-07-09 02:50:38 +00:00
|
|
|
/* int j = _scaleLevels.getSize(); */
|
2012-07-26 13:59:26 +00:00
|
|
|
if (_scaleLevels[i]->_posY < Y) {
|
|
|
|
prev = _scaleLevels[i];
|
|
|
|
} else {
|
2012-04-27 22:00:14 +00:00
|
|
|
next = _scaleLevels[i];
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (prev == NULL || next == NULL) {
|
|
|
|
return 100;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
int delta_y = next->_posY - prev->_posY;
|
|
|
|
float delta_scale = next->_scale - prev->_scale;
|
|
|
|
Y -= prev->_posY;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
float percent = (float)Y / ((float)delta_y / 100.0f);
|
2012-04-27 22:00:14 +00:00
|
|
|
return prev->_scale + delta_scale / 100 * percent;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::persist(BasePersistenceManager *persistMgr) {
|
|
|
|
BaseObject::persist(persistMgr);
|
2012-06-22 11:56:51 +00:00
|
|
|
|
|
|
|
persistMgr->transfer(TMEMBER(_autoScroll));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorColBlocked));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorColBlockedSel));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorColDecor));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorColDecorSel));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorColEntity));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorColEntitySel));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorColFrame));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorColRegion));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorColRegionSel));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorColScale));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorColWaypoints));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorColWaypointsSel));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorMarginH));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorMarginV));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorShowBlocked));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorShowDecor));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorShowEntities));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorShowRegions));
|
|
|
|
persistMgr->transfer(TMEMBER(_editorShowScale));
|
|
|
|
persistMgr->transfer(TMEMBER(_fader));
|
|
|
|
persistMgr->transfer(TMEMBER(_height));
|
|
|
|
persistMgr->transfer(TMEMBER(_initialized));
|
|
|
|
persistMgr->transfer(TMEMBER(_lastTimeH));
|
|
|
|
persistMgr->transfer(TMEMBER(_lastTimeV));
|
2012-06-22 18:06:12 +00:00
|
|
|
_layers.persist(persistMgr);
|
2012-06-22 11:56:51 +00:00
|
|
|
persistMgr->transfer(TMEMBER(_mainLayer));
|
2012-06-22 18:06:12 +00:00
|
|
|
_objects.persist(persistMgr);
|
2012-06-22 11:56:51 +00:00
|
|
|
persistMgr->transfer(TMEMBER(_offsetLeft));
|
|
|
|
persistMgr->transfer(TMEMBER(_offsetTop));
|
|
|
|
persistMgr->transfer(TMEMBER(_paralaxScrolling));
|
|
|
|
persistMgr->transfer(TMEMBER(_persistentState));
|
|
|
|
persistMgr->transfer(TMEMBER(_persistentStateSprites));
|
2012-06-26 11:23:32 +00:00
|
|
|
persistMgr->transfer(TMEMBER(_pfMaxTime));
|
|
|
|
_pfPath.persist(persistMgr);
|
|
|
|
persistMgr->transfer(TMEMBER(_pfPointsNum));
|
|
|
|
persistMgr->transfer(TMEMBER(_pfReady));
|
|
|
|
persistMgr->transfer(TMEMBER(_pfRequester));
|
|
|
|
persistMgr->transfer(TMEMBER(_pfTarget));
|
|
|
|
persistMgr->transfer(TMEMBER(_pfTargetPath));
|
2012-06-22 18:06:12 +00:00
|
|
|
_rotLevels.persist(persistMgr);
|
|
|
|
_scaleLevels.persist(persistMgr);
|
2012-06-22 11:56:51 +00:00
|
|
|
persistMgr->transfer(TMEMBER(_scrollPixelsH));
|
|
|
|
persistMgr->transfer(TMEMBER(_scrollPixelsV));
|
|
|
|
persistMgr->transfer(TMEMBER(_scrollTimeH));
|
|
|
|
persistMgr->transfer(TMEMBER(_scrollTimeV));
|
|
|
|
persistMgr->transfer(TMEMBER(_shieldWindow));
|
|
|
|
persistMgr->transfer(TMEMBER(_targetOffsetLeft));
|
|
|
|
persistMgr->transfer(TMEMBER(_targetOffsetTop));
|
2012-06-22 18:06:12 +00:00
|
|
|
_waypointGroups.persist(persistMgr);
|
2012-06-22 11:56:51 +00:00
|
|
|
persistMgr->transfer(TMEMBER(_viewport));
|
|
|
|
persistMgr->transfer(TMEMBER(_width));
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::afterLoad() {
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::correctTargetPoint2(int startX, int startY, int *targetX, int *targetY, bool checkFreeObjects, BaseObject *requester) {
|
2012-07-04 19:32:29 +00:00
|
|
|
double xStep, yStep, x, y;
|
2012-03-06 03:34:46 +00:00
|
|
|
int xLength, yLength, xCount, yCount;
|
2012-07-04 19:32:29 +00:00
|
|
|
int x1, y1, x2, y2;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
x1 = *targetX;
|
|
|
|
y1 = *targetY;
|
|
|
|
x2 = startX;
|
|
|
|
y2 = startY;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
xLength = abs(x2 - x1);
|
|
|
|
yLength = abs(y2 - y1);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
if (xLength > yLength) {
|
|
|
|
/*
|
2012-06-12 12:41:29 +00:00
|
|
|
if (X1 > X2)
|
2012-03-06 03:34:46 +00:00
|
|
|
{
|
|
|
|
Swap(&X1, &X2);
|
|
|
|
Swap(&Y1, &Y2);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
yStep = fabs((double)(y2 - y1) / (double)(x2 - x1));
|
|
|
|
y = y1;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
for (xCount = x1; xCount < x2; xCount++) {
|
|
|
|
if (isWalkableAt(xCount, (int)y, checkFreeObjects, requester)) {
|
|
|
|
*targetX = xCount;
|
|
|
|
*targetY = (int)y;
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-04 19:32:29 +00:00
|
|
|
y += yStep;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
2012-06-12 12:41:29 +00:00
|
|
|
if (Y1 > Y2) {
|
2012-03-06 03:34:46 +00:00
|
|
|
Swap(&X1, &X2);
|
|
|
|
Swap(&Y1, &Y2);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
xStep = fabs((double)(x2 - x1) / (double)(y2 - y1));
|
|
|
|
x = x1;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
for (yCount = y1; yCount < y2; yCount++) {
|
|
|
|
if (isWalkableAt((int)x, yCount, checkFreeObjects, requester)) {
|
|
|
|
*targetX = (int)x;
|
|
|
|
*targetY = yCount;
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-04 19:32:29 +00:00
|
|
|
x += xStep;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::correctTargetPoint(int startX, int startY, int *argX, int *argY, bool checkFreeObjects, BaseObject *requester) {
|
2012-07-04 19:32:29 +00:00
|
|
|
int x = *argX;
|
|
|
|
int y = *argY;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
if (isWalkableAt(x, y, checkFreeObjects, requester) || !_mainLayer) {
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// right
|
2012-07-26 13:59:26 +00:00
|
|
|
int lengthRight = 0;
|
|
|
|
bool foundRight = false;
|
|
|
|
for (x = *argX, y = *argY; x < _mainLayer->_width; x++, lengthRight++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x - 5, y, checkFreeObjects, requester)) {
|
2012-07-26 13:59:26 +00:00
|
|
|
foundRight = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// left
|
2012-07-26 13:59:26 +00:00
|
|
|
int lengthLeft = 0;
|
|
|
|
bool foundLeft = false;
|
|
|
|
for (x = *argX, y = *argY; x >= 0; x--, lengthLeft--) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x + 5, y, checkFreeObjects, requester)) {
|
2012-07-26 13:59:26 +00:00
|
|
|
foundLeft = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// up
|
2012-07-26 13:59:26 +00:00
|
|
|
int lengthUp = 0;
|
|
|
|
bool foundUp = false;
|
|
|
|
for (x = *argX, y = *argY; y >= 0; y--, lengthUp--) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y + 5, checkFreeObjects, requester)) {
|
2012-07-26 13:59:26 +00:00
|
|
|
foundUp = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// down
|
2012-07-26 13:59:26 +00:00
|
|
|
int lengthDown = 0;
|
|
|
|
bool foundDown = false;
|
|
|
|
for (x = *argX, y = *argY; y < _mainLayer->_height; y++, lengthDown++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y - 5, checkFreeObjects, requester)) {
|
2012-07-26 13:59:26 +00:00
|
|
|
foundDown = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!foundLeft && !foundRight && !foundUp && !foundDown) {
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
int offsetX = INT_MAX, offsetY = INT_MAX;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (foundLeft && foundRight) {
|
|
|
|
if (abs(lengthLeft) < abs(lengthRight)) {
|
|
|
|
offsetX = lengthLeft;
|
|
|
|
} else {
|
|
|
|
offsetX = lengthRight;
|
|
|
|
}
|
|
|
|
} else if (foundLeft) {
|
|
|
|
offsetX = lengthLeft;
|
|
|
|
} else if (foundRight) {
|
|
|
|
offsetX = lengthRight;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (foundUp && foundDown) {
|
|
|
|
if (abs(lengthUp) < abs(lengthDown)) {
|
|
|
|
offsetY = lengthUp;
|
|
|
|
} else {
|
|
|
|
offsetY = lengthDown;
|
|
|
|
}
|
|
|
|
} else if (foundUp) {
|
|
|
|
offsetY = lengthUp;
|
|
|
|
} else if (foundDown) {
|
|
|
|
offsetY = lengthDown;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (abs(offsetX) < abs(offsetY)) {
|
|
|
|
*argX = *argX + offsetX;
|
|
|
|
} else {
|
|
|
|
*argY = *argY + offsetY;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!isWalkableAt(*argX, *argY)) {
|
|
|
|
return correctTargetPoint2(startX, startY, argX, argY, checkFreeObjects, requester);
|
|
|
|
} else {
|
|
|
|
return STATUS_OK;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
void AdScene::pfPointsStart() {
|
2012-06-26 11:23:32 +00:00
|
|
|
_pfPointsNum = 0;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
void AdScene::pfPointsAdd(int x, int y, int distance) {
|
2012-07-09 02:50:38 +00:00
|
|
|
if (_pfPointsNum >= _pfPath.getSize()) {
|
2012-07-21 19:01:47 +00:00
|
|
|
_pfPath.add(new AdPathPoint(x, y, distance));
|
2012-03-06 03:34:46 +00:00
|
|
|
} else {
|
2012-07-04 19:32:29 +00:00
|
|
|
_pfPath[_pfPointsNum]->x = x;
|
|
|
|
_pfPath[_pfPointsNum]->y = y;
|
|
|
|
_pfPath[_pfPointsNum]->_distance = distance;
|
2012-06-26 11:23:32 +00:00
|
|
|
_pfPath[_pfPointsNum]->_marked = false;
|
|
|
|
_pfPath[_pfPointsNum]->_origin = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 11:23:32 +00:00
|
|
|
_pfPointsNum++;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::getViewportOffset(int *offsetX, int *offsetY) {
|
|
|
|
AdGame *adGame = (AdGame *)_gameRef;
|
2012-07-18 16:25:09 +00:00
|
|
|
if (_viewport && !_gameRef->_editorMode) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (offsetX) {
|
|
|
|
*offsetX = _viewport->_offsetX;
|
|
|
|
}
|
|
|
|
if (offsetY) {
|
|
|
|
*offsetY = _viewport->_offsetY;
|
|
|
|
}
|
2012-07-18 16:25:09 +00:00
|
|
|
} else if (adGame->_sceneViewport && !_gameRef->_editorMode) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (offsetX) {
|
|
|
|
*offsetX = adGame->_sceneViewport->_offsetX;
|
|
|
|
}
|
|
|
|
if (offsetY) {
|
|
|
|
*offsetY = adGame->_sceneViewport->_offsetY;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
} else {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (offsetX) {
|
|
|
|
*offsetX = 0;
|
|
|
|
}
|
|
|
|
if (offsetY) {
|
|
|
|
*offsetY = 0;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::getViewportSize(int *width, int *height) {
|
|
|
|
AdGame *adGame = (AdGame *)_gameRef;
|
2012-07-18 16:25:09 +00:00
|
|
|
if (_viewport && !_gameRef->_editorMode) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (width) {
|
|
|
|
*width = _viewport->getWidth();
|
|
|
|
}
|
|
|
|
if (height) {
|
|
|
|
*height = _viewport->getHeight();
|
|
|
|
}
|
2012-07-18 16:25:09 +00:00
|
|
|
} else if (adGame->_sceneViewport && !_gameRef->_editorMode) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (width) {
|
|
|
|
*width = adGame->_sceneViewport->getWidth();
|
|
|
|
}
|
|
|
|
if (height) {
|
|
|
|
*height = adGame->_sceneViewport->getHeight();
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
} else {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (width) {
|
|
|
|
*width = _gameRef->_renderer->_width;
|
|
|
|
}
|
|
|
|
if (height) {
|
|
|
|
*height = _gameRef->_renderer->_height;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
int AdScene::getOffsetLeft() {
|
2012-07-04 19:32:29 +00:00
|
|
|
int viewportX;
|
|
|
|
getViewportOffset(&viewportX);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
return _offsetLeft - viewportX;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
int AdScene::getOffsetTop() {
|
2012-07-04 19:32:29 +00:00
|
|
|
int viewportY;
|
|
|
|
getViewportOffset(NULL, &viewportY);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
return _offsetTop - viewportY;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::pointInViewport(int x, int y) {
|
2012-07-04 19:32:29 +00:00
|
|
|
int left, top, width, height;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
getViewportOffset(&left, &top);
|
|
|
|
getViewportSize(&width, &height);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 19:32:29 +00:00
|
|
|
return x >= left && x <= left + width && y >= top && y <= top + height;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
void AdScene::setOffset(int offsetLeft, int offsetTop) {
|
2012-07-04 19:32:29 +00:00
|
|
|
_offsetLeft = offsetLeft;
|
|
|
|
_offsetTop = offsetTop;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
BaseObject *AdScene::getNodeByName(const char *name) {
|
|
|
|
BaseObject *ret = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// dependent objects
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _layers.getSize(); i++) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdLayer *layer = _layers[i];
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int j = 0; j < layer->_nodes.getSize(); j++) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdSceneNode *node = layer->_nodes[j];
|
2012-07-22 21:17:32 +00:00
|
|
|
if ((node->_type == OBJECT_ENTITY && !scumm_stricmp(name, node->_entity->getName())) ||
|
|
|
|
(node->_type == OBJECT_REGION && !scumm_stricmp(name, node->_region->getName()))) {
|
2012-04-27 22:00:14 +00:00
|
|
|
switch (node->_type) {
|
2012-03-06 03:34:46 +00:00
|
|
|
case OBJECT_ENTITY:
|
2012-04-27 22:00:14 +00:00
|
|
|
ret = node->_entity;
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
case OBJECT_REGION:
|
2012-04-27 22:00:14 +00:00
|
|
|
ret = node->_region;
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = NULL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// free entities
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _objects.getSize(); i++) {
|
2012-07-22 21:17:32 +00:00
|
|
|
if (_objects[i]->_type == OBJECT_ENTITY && !scumm_stricmp(name, _objects[i]->getName())) {
|
2012-04-27 22:00:14 +00:00
|
|
|
return _objects[i];
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// waypoint groups
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _waypointGroups.getSize(); i++) {
|
2012-07-22 21:17:32 +00:00
|
|
|
if (!scumm_stricmp(name, _waypointGroups[i]->getName())) {
|
2012-04-27 22:00:14 +00:00
|
|
|
return _waypointGroups[i];
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::saveState() {
|
2012-06-26 11:23:32 +00:00
|
|
|
return persistState(true);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::loadState() {
|
2012-06-26 11:23:32 +00:00
|
|
|
return persistState(false);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::persistState(bool saving) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!_persistentState) {
|
|
|
|
return STATUS_OK;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-21 19:01:47 +00:00
|
|
|
AdGame *adGame = (AdGame *)_gameRef;
|
2012-07-22 20:55:54 +00:00
|
|
|
AdSceneState *state = adGame->getSceneState(getFilename(), saving);
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!state) {
|
|
|
|
return STATUS_OK;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-21 19:01:47 +00:00
|
|
|
AdNodeState *nodeState;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// dependent objects
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _layers.getSize(); i++) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdLayer *layer = _layers[i];
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int j = 0; j < layer->_nodes.getSize(); j++) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdSceneNode *node = layer->_nodes[j];
|
2012-04-27 22:00:14 +00:00
|
|
|
switch (node->_type) {
|
2012-03-06 03:34:46 +00:00
|
|
|
case OBJECT_ENTITY:
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!node->_entity->_saveState) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-07-22 21:17:32 +00:00
|
|
|
nodeState = state->getNodeState(node->_entity->getName(), saving);
|
2012-07-04 17:23:41 +00:00
|
|
|
if (nodeState) {
|
|
|
|
nodeState->transferEntity(node->_entity, _persistentStateSprites, saving);
|
2012-07-25 19:21:55 +00:00
|
|
|
//if (Saving) NodeState->_active = node->_entity->_active;
|
2012-04-27 22:00:14 +00:00
|
|
|
//else node->_entity->_active = NodeState->_active;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OBJECT_REGION:
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!node->_region->_saveState) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-07-22 21:17:32 +00:00
|
|
|
nodeState = state->getNodeState(node->_region->getName(), saving);
|
2012-07-04 17:23:41 +00:00
|
|
|
if (nodeState) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (saving) {
|
|
|
|
nodeState->_active = node->_region->_active;
|
|
|
|
} else {
|
|
|
|
node->_region->_active = nodeState->_active;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-06-25 13:48:00 +00:00
|
|
|
default:
|
2012-07-21 19:01:47 +00:00
|
|
|
warning("AdScene::PersistState - unhandled enum");
|
2012-06-25 13:48:00 +00:00
|
|
|
break;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// free entities
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _objects.getSize(); i++) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!_objects[i]->_saveState) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_objects[i]->_type == OBJECT_ENTITY) {
|
2012-07-22 21:17:32 +00:00
|
|
|
nodeState = state->getNodeState(_objects[i]->getName(), saving);
|
2012-07-04 17:23:41 +00:00
|
|
|
if (nodeState) {
|
2012-07-21 19:01:47 +00:00
|
|
|
nodeState->transferEntity((AdEntity *)_objects[i], _persistentStateSprites, saving);
|
2012-07-25 19:21:55 +00:00
|
|
|
//if (Saving) NodeState->_active = _objects[i]->_active;
|
2012-04-27 22:00:14 +00:00
|
|
|
//else _objects[i]->_active = NodeState->_active;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// waypoint groups
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _waypointGroups.getSize(); i++) {
|
2012-07-22 21:17:32 +00:00
|
|
|
nodeState = state->getNodeState(_waypointGroups[i]->getName(), saving);
|
2012-07-04 17:23:41 +00:00
|
|
|
if (nodeState) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (saving) {
|
|
|
|
nodeState->_active = _waypointGroups[i]->_active;
|
|
|
|
} else {
|
|
|
|
_waypointGroups[i]->_active = nodeState->_active;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
float AdScene::getRotationAt(int x, int y) {
|
|
|
|
AdRotLevel *prev = NULL;
|
|
|
|
AdRotLevel *next = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _rotLevels.getSize(); i++) {
|
2012-07-21 19:01:47 +00:00
|
|
|
/* AdRotLevel *xxx = _rotLevels[i];
|
2012-07-09 02:50:38 +00:00
|
|
|
int j = _rotLevels.getSize();*/
|
2012-07-26 13:59:26 +00:00
|
|
|
if (_rotLevels[i]->_posX < x) {
|
|
|
|
prev = _rotLevels[i];
|
|
|
|
} else {
|
2012-04-27 22:00:14 +00:00
|
|
|
next = _rotLevels[i];
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (prev == NULL || next == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
int delta_x = next->_posX - prev->_posX;
|
|
|
|
float delta_rot = next->_rotation - prev->_rotation;
|
2012-07-04 17:23:41 +00:00
|
|
|
x -= prev->_posX;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-04 17:23:41 +00:00
|
|
|
float percent = (float)x / ((float)delta_x / 100.0f);
|
2012-04-27 22:00:14 +00:00
|
|
|
return prev->_rotation + delta_rot / 100 * percent;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::handleItemAssociations(const char *itemName, bool show) {
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _layers.getSize(); i++) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdLayer *layer = _layers[i];
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int j = 0; j < layer->_nodes.getSize(); j++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (layer->_nodes[j]->_type == OBJECT_ENTITY) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdEntity *ent = layer->_nodes[j]->_entity;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (ent->_item && strcmp(ent->_item, itemName) == 0) {
|
|
|
|
ent->_active = show;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _objects.getSize(); i++) {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_objects[i]->_type == OBJECT_ENTITY) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdEntity *ent = (AdEntity *)_objects[i];
|
2012-07-26 13:59:26 +00:00
|
|
|
if (ent->_item && strcmp(ent->_item, itemName) == 0) {
|
|
|
|
ent->_active = show;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::getRegionsAt(int x, int y, AdRegion **regionList, int numRegions) {
|
2012-07-04 19:32:29 +00:00
|
|
|
int numUsed = 0;
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_mainLayer) {
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdSceneNode *node = _mainLayer->_nodes[i];
|
2012-07-07 15:52:08 +00:00
|
|
|
if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (numUsed < numRegions - 1) {
|
|
|
|
regionList[numUsed] = node->_region;
|
|
|
|
numUsed++;
|
2012-07-26 13:59:26 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-04 19:32:29 +00:00
|
|
|
for (int i = numUsed; i < numRegions; i++) {
|
|
|
|
regionList[i] = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
bool AdScene::restoreDeviceObjects() {
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
BaseObject *AdScene::getNextAccessObject(BaseObject *currObject) {
|
2012-07-26 17:41:18 +00:00
|
|
|
BaseArray<AdObject *> objects;
|
2012-07-04 17:23:41 +00:00
|
|
|
getSceneObjects(objects, true);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (objects.getSize() == 0) {
|
|
|
|
return NULL;
|
|
|
|
} else {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (currObject != NULL) {
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < objects.getSize(); i++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (objects[i] == currObject) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (i < objects.getSize() - 1) {
|
|
|
|
return objects[i + 1];
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-04 17:23:41 +00:00
|
|
|
return objects[0];
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-21 19:01:47 +00:00
|
|
|
BaseObject *AdScene::getPrevAccessObject(BaseObject *currObject) {
|
2012-07-26 17:41:18 +00:00
|
|
|
BaseArray<AdObject *> objects;
|
2012-07-04 19:32:29 +00:00
|
|
|
getSceneObjects(objects, true);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-26 13:59:26 +00:00
|
|
|
if (objects.getSize() == 0) {
|
|
|
|
return NULL;
|
|
|
|
} else {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (currObject != NULL) {
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = objects.getSize() - 1; i >= 0; i--) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (objects[i] == currObject) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (i > 0) {
|
|
|
|
return objects[i - 1];
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-09 02:50:38 +00:00
|
|
|
return objects[objects.getSize() - 1];
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-26 17:41:18 +00:00
|
|
|
bool AdScene::getSceneObjects(BaseArray<AdObject *> &objects, bool interactiveOnly) {
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _layers.getSize(); i++) {
|
2012-03-06 03:34:46 +00:00
|
|
|
// close-up layer -> remove everything below it
|
2012-07-26 13:59:26 +00:00
|
|
|
if (interactiveOnly && _layers[i]->_closeUp) {
|
2012-07-26 17:41:18 +00:00
|
|
|
objects.clear();
|
2012-07-26 13:59:26 +00:00
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int j = 0; j < _layers[i]->_nodes.getSize(); j++) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdSceneNode *node = _layers[i]->_nodes[j];
|
2012-07-04 19:32:29 +00:00
|
|
|
switch (node->_type) {
|
2012-03-06 03:34:46 +00:00
|
|
|
case OBJECT_ENTITY: {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdEntity *ent = node->_entity;
|
2012-07-26 13:59:26 +00:00
|
|
|
if (ent->_active && (ent->_registrable || !interactiveOnly)) {
|
2012-07-09 02:50:38 +00:00
|
|
|
objects.add(ent);
|
2012-07-26 13:59:26 +00:00
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OBJECT_REGION: {
|
2012-07-26 17:41:18 +00:00
|
|
|
BaseArray<AdObject *> regionObj;
|
2012-07-04 19:32:29 +00:00
|
|
|
getRegionObjects(node->_region, regionObj, interactiveOnly);
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int newIndex = 0; newIndex < regionObj.getSize(); newIndex++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
bool found = false;
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int old = 0; old < objects.getSize(); old++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (objects[old] == regionObj[newIndex]) {
|
|
|
|
found = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!found) {
|
|
|
|
objects.add(regionObj[newIndex]);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-07-25 19:21:55 +00:00
|
|
|
//if (RegionObj.getSize() > 0) Objects.Append(RegionObj);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-06-25 13:48:00 +00:00
|
|
|
default:
|
2012-07-21 19:01:47 +00:00
|
|
|
warning("AdScene::GetSceneObjects - Unhandled enum");
|
2012-06-25 13:48:00 +00:00
|
|
|
break;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// objects outside any region
|
2012-07-26 17:41:18 +00:00
|
|
|
BaseArray<AdObject *> regionObj;
|
2012-07-04 19:32:29 +00:00
|
|
|
getRegionObjects(NULL, regionObj, interactiveOnly);
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int newIndex = 0; newIndex < regionObj.getSize(); newIndex++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
bool found = false;
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int old = 0; old < objects.getSize(); old++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
if (objects[old] == regionObj[newIndex]) {
|
|
|
|
found = true;
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-07-26 13:59:26 +00:00
|
|
|
if (!found) {
|
|
|
|
objects.add(regionObj[newIndex]);
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-07-26 17:41:18 +00:00
|
|
|
bool AdScene::getRegionObjects(AdRegion *region, BaseArray<AdObject *> &objects, bool interactiveOnly) {
|
2012-07-21 19:01:47 +00:00
|
|
|
AdGame *adGame = (AdGame *)_gameRef;
|
|
|
|
AdObject *obj;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// global objects
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < adGame->_objects.getSize(); i++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
obj = adGame->_objects[i];
|
2012-07-07 15:52:08 +00:00
|
|
|
if (obj->_active && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (interactiveOnly && !obj->_registrable) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 02:50:38 +00:00
|
|
|
objects.add(obj);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// scene objects
|
2012-07-09 02:50:38 +00:00
|
|
|
for (int i = 0; i < _objects.getSize(); i++) {
|
2012-07-04 19:32:29 +00:00
|
|
|
obj = _objects[i];
|
2012-07-07 15:52:08 +00:00
|
|
|
if (obj->_active && !obj->_editorOnly && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) {
|
2012-07-26 13:59:26 +00:00
|
|
|
if (interactiveOnly && !obj->_registrable) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 02:50:38 +00:00
|
|
|
objects.add(obj);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
// sort by _posY
|
2012-07-21 19:01:47 +00:00
|
|
|
qsort(objects.getData(), objects.getSize(), sizeof(AdObject *), AdScene::compareObjs);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-07-09 01:27:21 +00:00
|
|
|
return STATUS_OK;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end of namespace WinterMute
|