diff options
| -rw-r--r-- | saga/actor.cpp | 35 | ||||
| -rw-r--r-- | saga/actor.h | 12 | ||||
| -rw-r--r-- | saga/events.cpp | 2 | ||||
| -rw-r--r-- | saga/game.cpp | 4 | ||||
| -rw-r--r-- | saga/isomap.cpp | 5 | ||||
| -rw-r--r-- | saga/itedata.h | 2 | ||||
| -rw-r--r-- | saga/objectmap.cpp | 17 | ||||
| -rw-r--r-- | saga/saga.cpp | 93 | ||||
| -rw-r--r-- | saga/saga.h | 2 | ||||
| -rw-r--r-- | saga/scene.cpp | 5 | ||||
| -rw-r--r-- | saga/scene.h | 2 | ||||
| -rw-r--r-- | saga/script.cpp | 17 | ||||
| -rw-r--r-- | saga/sfuncs.cpp | 14 | 
13 files changed, 143 insertions, 67 deletions
| diff --git a/saga/actor.cpp b/saga/actor.cpp index ce5db9f7cb..ea0073bbd6 100644 --- a/saga/actor.cpp +++ b/saga/actor.cpp @@ -62,6 +62,9 @@ static int commonObjectCompare(const CommonObjectDataPointer& obj1, const Common  static int tileCommonObjectCompare(const CommonObjectDataPointer& obj1, const CommonObjectDataPointer& obj2) {  	int p1 = -obj1->location.u() - obj1->location.v() - obj1->location.z;  	int p2 = -obj2->location.u() - obj2->location.v() - obj2->location.z; +	//TODO:  for kObjNotFlat obj Height*3 of sprite should be adde to p1 and p2 +	//if (validObjId(obj1->id)) { +  	if (p1 == p2) {  		return 0;  	} else { @@ -248,15 +251,15 @@ Actor::Actor(SagaEngine *vm) : _vm(vm) {  			debug(9, "init obj id=%d index=%d", obj->id, obj->index);  			obj->nameIndex = ITE_ObjectTable[i].nameIndex;  			obj->scriptEntrypointNumber = ITE_ObjectTable[i].scriptEntrypointNumber; -			obj->spriteListResourceId = ITE_ObjectTable[i].spriteListResourceId; +			obj->frameNumber = ITE_ObjectTable[i].frameNumber;  			obj->sceneNumber = ITE_ObjectTable[i].sceneIndex;  			obj->interactBits = ITE_ObjectTable[i].interactBits;  			obj->flags = 0; -			obj->frameNumber = 0;  			obj->location.x = ITE_ObjectTable[i].x;  			obj->location.y = ITE_ObjectTable[i].y;  			obj->location.z = ITE_ObjectTable[i].z; +			obj->disabled = false;  		}  	} else { @@ -352,7 +355,7 @@ bool Actor::loadActorResources(ActorData *actor) {  	resourceId = actor->spriteListResourceId;  	debug(9, "Loading sprite resource id %d", resourceId);  	if (_vm->_sprite->loadList(resourceId, actor->spriteList) != SUCCESS) { -		warning("Unable to load sprite list"); +		warning("loadActorResources: Unable to load sprite list");  		return false;  	} @@ -439,7 +442,7 @@ void Actor::realLocation(Location &location, uint16 objectId, uint16 walkFlags)  			angle = location.x & 15;  			distance = location.y; -			location.x = (angleLUT[angle][0] * distance) >> 6; //fixme - call real angle calc +			location.x = (angleLUT[angle][0] * distance) >> 6;  			location.y = (angleLUT[angle][1] * distance) >> 6;  		}  	} @@ -506,6 +509,9 @@ ObjectData *Actor::getObj(uint16 objId) {  	obj = _objs[objIdToIndex(objId)]; +	if (obj->disabled) +		error("Actor::getObj disabled objId 0x%X", objId); +  	return obj;  } @@ -525,7 +531,7 @@ ActorData *Actor::getActor(uint16 actorId) {  	actor = _actors[actorIdToIndex(actorId)];  	if (actor->disabled) -		warning("Actor::getActor disabled actorId 0x%X", actorId); +		error("Actor::getActor disabled actorId 0x%X", actorId);  	return actor;  } @@ -841,7 +847,6 @@ void Actor::handleActions(int msec, bool setup) {  		case kActionWalkToPoint:  		case kActionWalkToLink: -			// tiled stuff  			if (_vm->_scene->getFlags() & kSceneFlagISO) {  				actor->partialTarget.delta(actor->location, delta); @@ -979,7 +984,6 @@ void Actor::handleActions(int msec, bool setup) {  			break;  		case kActionWalkDir: -			// tiled stuff  			if (_vm->_scene->getFlags() & kSceneFlagISO) {  				actor->location.u() += tileDirectionLUT[actor->actionDirection][0];  				actor->location.v() += tileDirectionLUT[actor->actionDirection][1]; @@ -1092,7 +1096,7 @@ void Actor::handleActions(int msec, bool setup) {  		if ((actor->currentAction >= kActionWalkToPoint) && (actor->currentAction <= kActionWalkDir)) {  			hitZone = NULL; -			// tiled stuff +  			if (_vm->_scene->getFlags() & kSceneFlagISO) {  				actor->location.toScreenPointUV(hitPoint);  			} else { @@ -1198,13 +1202,14 @@ void Actor::createDrawOrderList() {  		if (actor->disabled) continue;  		if (actor->sceneNumber != _vm->_scene->currentSceneNumber()) continue; -			_drawOrderList.pushBack(actor, compareFunction); +		_drawOrderList.pushBack(actor, compareFunction);  		calcScreenPosition(actor);  	}  	for (i = 0; i < _objsCount; i++) {  		obj = _objs[i]; +		if (obj->disabled) continue;  		if (obj->sceneNumber != _vm->_scene->currentSceneNumber()) continue;  		_drawOrderList.pushBack(obj, compareFunction); @@ -1223,13 +1228,17 @@ bool Actor::getSpriteParams(CommonObjectData *commonObjectData, int &frameNumber  		spriteList = &_vm->_sprite->_mainSprites;  	} else {  		frameNumber = commonObjectData->frameNumber;			 -		spriteList = &commonObjectData->spriteList;	 +		if (validActorId(commonObjectData->id)) { +			spriteList = &((ActorData*)commonObjectData)->spriteList;	 +		} else { +			spriteList = &_vm->_sprite->_mainSprites; +		} +		  	} + +  	if ((frameNumber < 0) || (spriteList->spriteCount <= frameNumber)) { -		if (_vm->_scene->getFlags() & kSceneFlagISO) { // TODO: remove it -			return false; -		}  		warning("Actor::getSpriteParams frameNumber invalid for object id 0x%X", commonObjectData->id);  		return false;  	} diff --git a/saga/actor.h b/saga/actor.h index 0d87b6a4cd..7696bdaf2a 100644 --- a/saga/actor.h +++ b/saga/actor.h @@ -186,6 +186,7 @@ struct Location {  class CommonObjectData {  public: +	bool disabled;				// disabled in init section   	int index;					// index in local array  	uint16 id;					// object id  	uint16 flags;				// initial flags @@ -198,9 +199,6 @@ public:  	int screenDepth;			//  	int screenScale;			// -	SpriteList spriteList;		// sprite list data -	int spriteListResourceId;	// sprite list resource id -  	int frameNumber;			// current frame number  	CommonObjectData() { @@ -208,6 +206,7 @@ public:  		flags = 0;  		frameNumber = 0;  	} +  };  typedef CommonObjectData *CommonObjectDataPointer; @@ -221,7 +220,7 @@ public:  class ActorData: public CommonObjectData {  public: -	bool disabled;				// Actor disabled in init section +  	byte speechColor;			// Actor dialogue color  	uint16 actorFlags;			// dynamic flags @@ -237,12 +236,13 @@ public:  	uint8 cycleTimeCount;  	uint8 cycleFlags; +	SpriteList spriteList;		// sprite list data +	int spriteListResourceId;	// sprite list resource id +  	ActorFrameSequence *frames;	// Actor's frames  	int framesCount;			// Actor's frames count  	int frameListResourceId;	// Actor's frame list resource id -	//int walkPath[ACTOR_STEPS_MAX]; //todo: will gone -  	int tileDirectionsAlloced;  	byte *tileDirections; diff --git a/saga/events.cpp b/saga/events.cpp index 6b40aad606..1483bbc3a1 100644 --- a/saga/events.cpp +++ b/saga/events.cpp @@ -408,8 +408,6 @@ int Events::handleOneShot(EVENT *event) {  			sthread->_threadVars[kThreadVarWithObject] = TO_LE_16(event->param5);  			sthread->_threadVars[kThreadVarActor] = TO_LE_16(event->param6); -//			_vm->_script->executeThread(sthread, event->param); -  			if (event->op == EVENT_EXEC_BLOCKING)  				_vm->_script->completeThread(); diff --git a/saga/game.cpp b/saga/game.cpp index e1ed1b2792..9322d4000e 100644 --- a/saga/game.cpp +++ b/saga/game.cpp @@ -108,8 +108,8 @@ static GameSoundInfo ITEDEMO_GameSound = {  };  static GameFontDescription ITEMACDEMO_GameFonts[] = { -	{0}, -	{2} +	{2}, +	{0}  };   // Inherit the Earth - Wyrmkeep Win32 Demo version diff --git a/saga/isomap.cpp b/saga/isomap.cpp index a1af26ecac..439cce965d 100644 --- a/saga/isomap.cpp +++ b/saga/isomap.cpp @@ -257,14 +257,19 @@ void IsoMap::loadMulti(const byte * resourcePointer, size_t resourceLength) {  void IsoMap::freeMem() {  	free(_tileData); +	_tileData = NULL;  	_tilesCount = 0;  	free(_tilePlatformList); +	_tilePlatformList = NULL;  	_tilePlatformsCount = 0;  	free(_metaTileList); +	_metaTileList = NULL;  	_metaTilesCount = 0;  	free(_multiTable); +	_multiTable = NULL;  	_multiCount = 0;  	free(_multiTableData); +	_multiTableData = NULL;  	_multiDataCount = 0;  } diff --git a/saga/itedata.h b/saga/itedata.h index 299cc365db..d604dfc4fd 100644 --- a/saga/itedata.h +++ b/saga/itedata.h @@ -71,7 +71,7 @@ struct ObjectTableData {  	int16 x;  	int16 y;  	int16 z; -	int32 spriteListResourceId; +	int32 frameNumber;  	byte scriptEntrypointNumber;  	uint16 interactBits;  }; diff --git a/saga/objectmap.cpp b/saga/objectmap.cpp index 6b592fff67..4a037e98c0 100644 --- a/saga/objectmap.cpp +++ b/saga/objectmap.cpp @@ -34,6 +34,9 @@  #include "saga/interface.h"  #include "saga/objectmap.h"  #include "saga/stream.h" +#include "saga/actor.h" +#include "saga/scene.h" +#include "saga/isomap.h"  namespace Saga { @@ -57,7 +60,7 @@ HitZone::HitZone(MemoryReadStreamEndian *readStream, int index): _index(index) {  	for (i = 0; i < _clickAreasCount; i++) {  		clickArea = &_clickAreas[i]; -		clickArea->pointsCount = readStream->readUint16(); +		clickArea->pointsCount = readStream->readUint16LE();  		assert(clickArea->pointsCount); @@ -189,6 +192,7 @@ void ObjectMap::freeMem() {  		free(_hitZoneList);  		_hitZoneList = NULL;  	} +	_hitZoneListCount = 0;  } @@ -197,8 +201,17 @@ void ObjectMap::draw(SURFACE *ds, const Point& testPoint, int color, int color2)  	int i;  	int hitZoneIndex;  	char txtBuf[32]; +	Point pickPoint; +	Location pickLocation; +	pickPoint = testPoint; +	if (_vm->_scene->getFlags() & kSceneFlagISO) { +		assert(_vm->_actor->_protagonist); +		pickPoint.y -= _vm->_actor->_protagonist->location.z; +		_vm->_isoMap->screenPointToTileCoords(pickPoint, pickLocation); +		pickLocation.toScreenPointUV(pickPoint); +	} -	hitZoneIndex = hitTest(testPoint); +	hitZoneIndex = hitTest(pickPoint);  	for (i = 0; i < _hitZoneListCount; i++) {		  		_hitZoneList[i]->draw(ds, (hitZoneIndex == i) ? color2 : color); diff --git a/saga/saga.cpp b/saga/saga.cpp index c1d3d1a0cf..7042f38b51 100644 --- a/saga/saga.cpp +++ b/saga/saga.cpp @@ -120,6 +120,24 @@ SagaEngine::SagaEngine(GameDetector *detector, OSystem *syst)  	_gameFileContexts = NULL;  	_quit = false; +	_sndRes = NULL; +	_events = NULL; +	_font = NULL; +	_sprite = NULL; +	_anim = NULL; +	_script = NULL; +	_interface = NULL; +	_actor = NULL; +	_palanim = NULL; +	_scene = NULL; +	_isoMap = NULL; +	_gfx = NULL; +	_console = NULL; +	_render = NULL; +	_music = NULL; +	_sound = NULL; + +  	// The Linux version of Inherit the Earth puts all data files in an  	// 'itedata' sub-directory, except for voices.rsc  	File::addDefaultDirectory(_gameDataPath + "itedata/"); @@ -147,23 +165,54 @@ SagaEngine::SagaEngine(GameDetector *detector, OSystem *syst)  SagaEngine::~SagaEngine() {  	int i; -	delete _scene; -	delete _actor; -	delete _script; -	delete _sprite; -	delete _font; -	delete _console; -	delete _events; -	delete _palanim; - -	delete _interface; -	delete _render; -	delete _isoMap; -	delete _sndRes; -	// Shutdown system modules */ -	delete _music; -	delete _sound; -	delete _anim; +	if (_sndRes != NULL) { +		delete _sndRes; +	} +	if (_events != NULL) { +		delete _events; +	} +	if (_font != NULL) { +		delete _font; +	} +	if (_sprite != NULL) { +		delete _sprite; +	} +	if (_anim != NULL) { +		delete _anim; +	} +	if (_script != NULL) { +		delete _script; +	} +	if (_interface != NULL) { +		delete _interface; +	} +	if (_actor != NULL) { +		delete _actor; +	} +	if (_palanim != NULL) { +		delete _palanim; +	} +	if (_scene != NULL) { +		delete _scene; +	} +	if (_isoMap != NULL) { +		delete _isoMap; +	} +	if (_render != NULL) { +		delete _render; +	} +	if (_music != NULL) { +		delete _music; +	} +	if (_sound != NULL) { +		delete _sound; +	} +	if (_gfx != NULL) { +		delete _gfx; +	} +	if (_console != NULL) { +		delete _console; +	}  	if (_gameFileContexts != NULL) {  		for (i = 0; i < _gameDescription->filesCount; i++) { @@ -197,7 +246,7 @@ int SagaEngine::init(GameDetector &detector) {  	// Detect game and open resource files  	if (initGame() != SUCCESS) { -		return -1; +		return FAILURE;  	}  	// Initialize engine modules @@ -215,8 +264,7 @@ int SagaEngine::init(GameDetector &detector) {  	if (!_scene->initialized()) {  		warning("Couldn't initialize scene module"); -		// TODO/FIXME: We are leaking here -		return -1; +		return FAILURE;  	}  	// System initialization @@ -253,8 +301,7 @@ int SagaEngine::init(GameDetector &detector) {  	_render = new Render(this, _system);  	if (!_render->initialized()) { -		// TODO/FIXME: We are leaking here -		return -1; +		return FAILURE;  	}  	// Initialize system specific sound @@ -266,7 +313,7 @@ int SagaEngine::init(GameDetector &detector) {  	_interface->converseInit();  	_script->setVerb(kVerbWalkTo); -	return 0; +	return SUCCESS;  }  int SagaEngine::go() { diff --git a/saga/saga.h b/saga/saga.h index 4e365dec58..c5d2db4287 100644 --- a/saga/saga.h +++ b/saga/saga.h @@ -81,7 +81,7 @@ struct RSCFILE_CONTEXT;  struct StringList;  enum ERRORCODE { -	MEM = -2, +	MEM = -2,//todo: remove  	FAILURE = -1,  	SUCCESS = 0  }; diff --git a/saga/scene.cpp b/saga/scene.cpp index 7c2162d46b..1033d5c80b 100644 --- a/saga/scene.cpp +++ b/saga/scene.cpp @@ -283,7 +283,7 @@ int Scene::skipScene() {  	return SUCCESS;  } -int Scene::changeScene(int sceneNumber, int actorsEntrance) { +int Scene::changeScene(int sceneNumber, int actorsEntrance, int fadeIn) {  	assert(_initialized);  	if (!_sceneLoaded) { @@ -302,7 +302,7 @@ int Scene::changeScene(int sceneNumber, int actorsEntrance) {  	}  	endScene(); -	loadScene(sceneNumber, BY_SCENE, SC_defaultScene, NULL, SCENE_NOFADE, actorsEntrance); +	loadScene(sceneNumber, BY_SCENE, SC_defaultScene, NULL, fadeIn, actorsEntrance);  	return SUCCESS;  } @@ -965,6 +965,7 @@ int Scene::endScene() {  	_actionMap->freeMem();  	_entryList.freeMem();  	_sceneStrings.freeMem(); +	_vm->_isoMap->freeMem();  	_animList.clear(); diff --git a/saga/scene.h b/saga/scene.h index 5acffbf074..437f98302b 100644 --- a/saga/scene.h +++ b/saga/scene.h @@ -254,7 +254,7 @@ class Scene {  	void getSlopes(int &beginSlope, int &endSlope);  	int clearSceneQueue(void); -	int changeScene(int sceneNumber, int actorsEntrance); +	int changeScene(int sceneNumber, int actorsEntrance, int fadeIn = SCENE_NOFADE);  	bool initialized() { return _initialized; } diff --git a/saga/script.cpp b/saga/script.cpp index a3f841cdc1..7f65c8c696 100644 --- a/saga/script.cpp +++ b/saga/script.cpp @@ -677,10 +677,10 @@ void Script::whichObject(const Point& mousePoint) {  	int newRightButtonVerb;  	uint16 newObjectId;  	ActorData *actor; +	Point pickPoint;  	Location pickLocation;  	int hitZoneIndex;  	const HitZone * hitZone; -	Point tempPoint;  	objectId = ID_NOTHING;  	objectFlags = 0; @@ -719,17 +719,16 @@ void Script::whichObject(const Point& mousePoint) {  		}  		if (newObjectId == ID_NOTHING) {		 + +			pickPoint = mousePoint; +  			if (_vm->_scene->getFlags() & kSceneFlagISO) { -				tempPoint = mousePoint; -				tempPoint.y -= _vm->_actor->_protagonist->location.z; -				_vm->_isoMap->screenPointToTileCoords(tempPoint, pickLocation); -			} else { -				pickLocation.x = mousePoint.x; -				pickLocation.y = mousePoint.y; -				pickLocation.z = 0; +				pickPoint.y -= _vm->_actor->_protagonist->location.z; +				_vm->_isoMap->screenPointToTileCoords(pickPoint, pickLocation); +				pickLocation.toScreenPointUV(pickPoint);  			} -			hitZoneIndex = _vm->_scene->_objectMap->hitTest(mousePoint); +			hitZoneIndex = _vm->_scene->_objectMap->hitTest(pickPoint);  			if ((hitZoneIndex != -1)) {  				hitZone = _vm->_scene->_objectMap->getHitZone(hitZoneIndex); diff --git a/saga/sfuncs.cpp b/saga/sfuncs.cpp index 20e92cbd70..cd97643057 100644 --- a/saga/sfuncs.cpp +++ b/saga/sfuncs.cpp @@ -504,11 +504,14 @@ void Script::sfScriptGotoScene(SCRIPTFUNC_PARAMS) {  	// This is used for latter demos where all places on world map except  	// Tent Faire are substituted with LBM picture and short description  	// TODO: implement -	for (int i = 0; i < ARRAYSIZE(sceneSubstitutes); i++) -		if (sceneSubstitutes[i].sceneId == sceneNumber) +	for (int i = 0; i < ARRAYSIZE(sceneSubstitutes); i++) { +	 +		if (sceneSubstitutes[i].sceneId == sceneNumber) {  			debug(0, "Scene %d substitute exists", sceneNumber); +		} +	} -//	_vm->_scene->loadScene(sceneNumber, BY_SCENE, _vm->_scene->SC_defaultScene, NULL, (sceneNumber = RID_ITE_ENDCREDIT_SCENE_1) ? SCENE_FADE : SCENE_NOFADE, entrance); +	_vm->_scene->changeScene(sceneNumber, entrance, (sceneNumber == RID_ITE_ENDCREDIT_SCENE_1) ? SCENE_FADE : SCENE_NOFADE);  	//TODO: placard stuff  	_pendingVerb = kVerbNone; @@ -913,7 +916,7 @@ void Script::sfSetFrame(SCRIPTFUNC_PARAMS) {  	frameRange = _vm->_actor->getActorFrameRange(actorId, frameType);  	if (frameRange->frameCount <= frameOffset) { -	//	frameRange = _vm->_actor->getActorFrameRange(actorId, frameType); +		frameRange = _vm->_actor->getActorFrameRange(actorId, frameType);  		error("Wrong frameOffset 0x%X", frameOffset);  	} @@ -1012,8 +1015,9 @@ void Script::sfPlaceActor(SCRIPTFUNC_PARAMS) {  	if (frameType >= 0) {  		frameRange = _vm->_actor->getActorFrameRange(actorId, frameType); -		if (frameRange->frameCount <= frameOffset) +		if (frameRange->frameCount <= frameOffset) {  			error("Wrong frameOffset 0x%X", frameOffset); +		}  		actor->frameNumber = frameRange->frameIndex + frameOffset;  		actor->currentAction = kActionFreeze; | 
