diff options
| -rw-r--r-- | engines/prince/prince.cpp | 63 | ||||
| -rw-r--r-- | engines/prince/prince.h | 2 | ||||
| -rw-r--r-- | engines/prince/script.cpp | 47 | ||||
| -rw-r--r-- | engines/prince/script.h | 3 | 
4 files changed, 81 insertions, 34 deletions
| diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp index 3140f2298f..62b5197cac 100644 --- a/engines/prince/prince.cpp +++ b/engines/prince/prince.cpp @@ -132,6 +132,8 @@ PrinceEngine::~PrinceEngine() {  	}  	_objList.clear(); +	delete[] _objSlot; +  	for (uint32 i = 0; i < _pscrList.size(); i++) {  		delete _pscrList[i];  	} @@ -300,6 +302,11 @@ void PrinceEngine::init() {  	for (int i = 0; i < kMaxNormAnims; i++) {  		_normAnimList.push_back(tempAnim);  	} + +	_objSlot = new int[kMaxObjects]; +	for (int i = 0; i < kMaxObjects; i++) { +		_objSlot[i] = -1; +	}  }  void PrinceEngine::showLogo() { @@ -436,6 +443,8 @@ bool PrinceEngine::loadLocation(uint16 locationNr) {  	freeDrawNodes(); +	_script->installObjects(_room->_obj); +  	clearBackAnimList();  	_script->installBackAnims(_backAnimList, _room->_backAnim); @@ -857,14 +866,17 @@ int PrinceEngine::checkMob(Graphics::Surface *screen, Common::Array<Mob> &mobLis  			break;  		case 3:  			//mob_obj -			if (mob._mask < _objList.size()) { -				Object &obj = *_objList[mob._mask]; -				Common::Rect objectRect(obj._x, obj._y, obj._x + obj._width, obj._y + obj._height); -				if (objectRect.contains(mousePosCamera)) { -					Graphics::Surface *objSurface = obj.getSurface(); -					byte *pixel = (byte *)objSurface->getBasePtr(mousePosCamera.x - obj._x, mousePosCamera.y - obj._y); -					if (*pixel != 255) { -						break; +			if (mob._mask < kMaxObjects) { +				int nr = _objSlot[mob._mask]; +				if (nr != -1) { +					Object &obj = *_objList[nr]; +					Common::Rect objectRect(obj._x, obj._y, obj._x + obj._width, obj._y + obj._height); +					if (objectRect.contains(mousePosCamera)) { +						Graphics::Surface *objSurface = obj.getSurface(); +						byte *pixel = (byte *)objSurface->getBasePtr(mousePosCamera.x - obj._x, mousePosCamera.y - obj._y); +						if (*pixel != 255) { +							break; +						}  					}  				}  			} @@ -1412,35 +1424,36 @@ void PrinceEngine::initZoomOut(int slot) {  }  void PrinceEngine::showObjects() { -	if (!_objList.empty()) { -		for (uint i = 0; i < _objList.size(); i++) { -			if ((_objList[i]->_mask & 0x8000) != 0) { -				_objList[i]->_zoomInTime--; -				if (_objList[i]->_zoomInTime == 0) { -					_objList[i]->_mask &= 0x7FFF; +	for (int i = 0; i < kMaxObjects; i++) { +		int nr = _objSlot[i]; +		if (nr != -1) { +			if ((_objList[nr]->_mask & 0x8000) != 0) { +				_objList[nr]->_zoomInTime--; +				if (_objList[nr]->_zoomInTime == 0) { +					_objList[nr]->_mask &= 0x7FFF;  				} else {  					// doZoomIn();  					// mov edx, d [esi.Obj_ZoomInAddr]  				}  			} -			if ((_objList[i]->_mask & 0x4000) != 0) { -				_objList[i]->_zoomInTime--; -				if (_objList[i]->_zoomInTime == 0) { -					_objList[i]->_mask &= 0xBFFF; +			if ((_objList[nr]->_mask & 0x4000) != 0) { +				_objList[nr]->_zoomInTime--; +				if (_objList[nr]->_zoomInTime == 0) { +					_objList[nr]->_mask &= 0xBFFF;  				} else {  					// doZoomOut();  					// mov edx, d [esi.Obj_ZoomInAddr]  				}  			} -			Graphics::Surface *objSurface = _objList[i]->getSurface(); -			if (spriteCheck(objSurface->w, objSurface->h, _objList[i]->_x, _objList[i]->_y)) { +			Graphics::Surface *objSurface = _objList[nr]->getSurface(); +			if (spriteCheck(objSurface->w, objSurface->h, _objList[nr]->_x, _objList[nr]->_y)) {  				if ((_objList[i]->_mask & 0x0200) == 0) { -					int destX = _objList[i]->_x - _picWindowX; -					int destY = _objList[i]->_y - _picWindowY; +					int destX = _objList[nr]->_x - _picWindowX; +					int destY = _objList[nr]->_y - _picWindowY;  					DrawNode newDrawNode;  					newDrawNode.posX = destX;  					newDrawNode.posY = destY; -					newDrawNode.posZ = _objList[i]->_z; +					newDrawNode.posZ = _objList[nr]->_z;  					newDrawNode.width = 0;  					newDrawNode.height = 0;  					newDrawNode.s = objSurface; @@ -1453,8 +1466,8 @@ void PrinceEngine::showObjects() {  					// showBackSprite();  				}  			} -			if ((_objList[i]->_mask & 1) != 0) { -				checkMasks(_objList[i]->_x, _objList[i]->_y, objSurface->w, objSurface->h, _objList[i]->_z); +			if ((_objList[nr]->_mask & 1) != 0) { +				checkMasks(_objList[nr]->_x, _objList[nr]->_y, objSurface->w, objSurface->h, _objList[nr]->_z);  			}  		}  	} diff --git a/engines/prince/prince.h b/engines/prince/prince.h index a96aba56c1..6ad5dd35e5 100644 --- a/engines/prince/prince.h +++ b/engines/prince/prince.h @@ -301,12 +301,14 @@ public:  	static const int kMaxNormAnims = 64;  	static const int kMaxBackAnims = 64; +	static const int kMaxObjects = 64;  	Common::Array<AnimListItem> _animList;  	Common::Array<BackgroundAnim> _backAnimList;  	Common::Array<Anim> _normAnimList;  	Common::Array<Mob> _mobList;  	Common::Array<Object *> _objList; +	int *_objSlot;  	void freeNormAnim(int slot);  	void freeAllNormAnims(); diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp index 7322752e6d..84dfd7754a 100644 --- a/engines/prince/script.cpp +++ b/engines/prince/script.cpp @@ -261,6 +261,10 @@ void Script::setBackAnimId(int offset, int animId) {  	WRITE_UINT32(&_data[offset], animId);  } +void Script::setObjId(int offset, int objId) { +	_data[offset] = objId; +} +  int Script::scanMobEvents(int mobMask, int dataEventOffset) {  	debug("mobMask: %d", mobMask);  	int i = 0; @@ -380,12 +384,23 @@ void Script::installSingleBackAnim(Common::Array<BackgroundAnim> &backAnimList,  }  void Script::installBackAnims(Common::Array<BackgroundAnim> &backAnimList, int offset) { -	for (uint i = 0; i < _vm->kMaxBackAnims; i++) { +	for (int i = 0; i < _vm->kMaxBackAnims; i++) {  		installSingleBackAnim(backAnimList, i, offset);  		offset += 4;  	}  } +void Script::installObjects(int offset) { +	for (int i = 0; i < _vm->kMaxObjects; i++) { +		if (_data[offset] != 0xFF) { +			_vm->_objSlot[i] = i; +		} else { +			_vm->_objSlot[i] = -1; +		} +		offset++; +	} +} +  bool Script::loadAllMasks(Common::Array<Mask> &maskList, int offset) {  	Mask tempMask;  	while (1) { @@ -565,9 +580,10 @@ Flags::Id Interpreter::readScriptFlagId() {  }  void Interpreter::O_WAITFOREVER() { -	//debugInterpreter("O_WAITFOREVER"); +	_vm->changeCursor(_vm->_currentPointerNumber);  	_opcodeNF = 1;  	_currentInstruction -= 2; +	//debugInterpreter("O_WAITFOREVER");  }  void Interpreter::O_BLACKPALETTE() { @@ -609,13 +625,29 @@ void Interpreter::O_PUTOBJECT() {  	uint16 roomId = readScriptFlagValue();  	uint16 slot = readScriptFlagValue();  	uint16 objectId = readScriptFlagValue(); +	Room *room = new Room(); +	room->loadRoom(_script->getRoomOffset(roomId)); +	int offset = room->_obj + slot; +	_vm->_script->setObjId(offset, objectId); +	if (_vm->_locationNr == roomId) { +		_vm->_objSlot[slot] = objectId; +	} +	delete room;  	debugInterpreter("O_PUTOBJECT roomId %d, slot %d, objectId %d", roomId, slot, objectId);  }  void Interpreter::O_REMOBJECT() {  	uint16 roomId = readScriptFlagValue(); -	uint16 objectId = readScriptFlagValue(); -	debugInterpreter("O_REMOBJECT roomId %d objectId %d", roomId, objectId); +	uint16 slot = readScriptFlagValue(); +	Room *room = new Room(); +	room->loadRoom(_script->getRoomOffset(roomId)); +	int offset = room->_obj + slot; +	_vm->_script->setObjId(offset, 0xFF); +	if (_vm->_locationNr == roomId) { +		_vm->_objSlot[slot] = -1; +	} +	delete room; +	debugInterpreter("O_REMOBJECT roomId %d slot %d", roomId, slot);  }  void Interpreter::O_SHOWANIM() { @@ -1252,15 +1284,12 @@ void Interpreter::O_SETBACKFRAME() {  	debugInterpreter("O_SETBACKFRAME anim %d, frame %d", anim, frame);  } -// TODO - check if proper max for getRandomNumber  void Interpreter::O_GETRND() {  	Flags::Id flag = readScriptFlagId();  	uint16 rndSeed = readScript<uint16>(); -	debugInterpreter("O_GETRND flag %d, rndSeed %d", flag, rndSeed); -	// puts and random value as flag value -	// fairly random value ;) -	int value = _vm->_randomSource.getRandomNumber(rndSeed); +	int value = _vm->_randomSource.getRandomNumber(rndSeed - 1);  	_flags->setFlagValue(flag, value); +	debugInterpreter("O_GETRND flag %d, rndSeed %d, value %d", flag, rndSeed, value);  }  void Interpreter::O_TALKBACKANIM() { diff --git a/engines/prince/script.h b/engines/prince/script.h index 278a8c858e..17ae0dc917 100644 --- a/engines/prince/script.h +++ b/engines/prince/script.h @@ -37,6 +37,7 @@ namespace Prince {  class PrinceEngine;  class Animation; +class Object;  struct Anim;  struct BackgroundAnim;  struct Mask; @@ -138,8 +139,10 @@ public:  	uint8 *getRoomOffset(int locationNr);  	int32 getOptionStandardOffset(int option);  	void setBackAnimId(int offset, int animId); +	void setObjId(int offset, int objId);  	void installBackAnims(Common::Array<BackgroundAnim> &backAnimList, int offset);  	void installSingleBackAnim(Common::Array<BackgroundAnim> &backAnimList, int slot, int offset); +	void installObjects(int offset);  	bool loadAllMasks(Common::Array<Mask> &maskList, int offset);  	int scanMobEvents(int mobMask, int dataEventOffset); | 
