diff options
| -rw-r--r-- | engines/agos/agos.cpp | 7 | ||||
| -rw-r--r-- | engines/agos/agos.h | 6 | ||||
| -rw-r--r-- | engines/agos/items.cpp | 20 | ||||
| -rw-r--r-- | engines/agos/script_e1.cpp | 3 | ||||
| -rw-r--r-- | engines/agos/subroutine.cpp | 63 | 
5 files changed, 81 insertions, 18 deletions
diff --git a/engines/agos/agos.cpp b/engines/agos/agos.cpp index 8ce3b87bee..7db49b9ca6 100644 --- a/engines/agos/agos.cpp +++ b/engines/agos/agos.cpp @@ -330,10 +330,15 @@ AGOSEngine::AGOSEngine(OSystem *syst)  	_nextVgaTimerToProcess = 0; -	_agosMenu = 0; +	_classLine = 0;  	_classMask = 0;  	_classMode1 = 0;  	_classMode2 = 0; +	_currentLine = 0; +	_currentTable = 0; +	_findNextPtr = 0; + +	_agosMenu = 0;  	_superRoomNumber = 0;  	_wallOn = 0; diff --git a/engines/agos/agos.h b/engines/agos/agos.h index 427b60072c..2ad783c98e 100644 --- a/engines/agos/agos.h +++ b/engines/agos/agos.h @@ -314,7 +314,12 @@ protected:  	char *_linePtrs[6];  	int _boxCR; +	SubroutineLine *_classLine;  	uint _classMask, _classMode1, _classMode2; +	Item *_findNextPtr; +	Subroutine *_currentTable; +	SubroutineLine *_currentLine; +  	int _agosMenu;  	byte _textMenu[10];  	uint _superRoomNumber; @@ -628,6 +633,7 @@ protected:  	void delTimeEvent(TimeEvent *te);  	Item *findInByClass(Item *i, int16 m); +	Item *nextInByClass(Item *i, int16 m);  	Item *findMaster(int16 a, int16 n);  	Item *nextMaster(Item *item, int16 a, int16 n);  	int wordMatch(Item *item, int16 a, int16 n); diff --git a/engines/agos/items.cpp b/engines/agos/items.cpp index 64d8f639de..31574e6dbb 100644 --- a/engines/agos/items.cpp +++ b/engines/agos/items.cpp @@ -385,19 +385,33 @@ Item *AGOSEngine::derefItem(uint item) {  Item *AGOSEngine::findInByClass(Item *i, int16 m) {  	i = derefItem(i->child); -  	while (i) {  		if (i->classFlags & m) { -			//_findNextPtr = derefItem(i->next); +			_findNextPtr = derefItem(i->next);  			return i;  		}  		if (m == 0) { -			//_findNextPtr = derefItem(i->next); +			_findNextPtr = derefItem(i->next);  			return i;  		}  		i = derefItem(i->next);  	} +	return NULL; +} +Item *AGOSEngine::nextInByClass(Item *i, int16 m) { +	i = _findNextPtr; +	while(i) { +		if (i->classFlags & m) { +			_findNextPtr = derefItem(i->next); +			return i; +		} +		if (m == 0) { +			_findNextPtr = derefItem(i->next); +			return i; +		} +		i = derefItem(i->next); +	}  	return NULL;  } diff --git a/engines/agos/script_e1.cpp b/engines/agos/script_e1.cpp index 3339ffdbf0..5468e1cb27 100644 --- a/engines/agos/script_e1.cpp +++ b/engines/agos/script_e1.cpp @@ -344,8 +344,7 @@ void AGOSEngine::oe1_doClass() {  	int16 num = getVarOrWord();  	_classMask = (cm != -1) ? 1 << cm : 0; -	//_classLine = (SubroutineLine *)((uint32)_currentLine->next+(uint32)_currentTable); - +	_classLine = (SubroutineLine *)((byte *)_currentTable + _currentLine->next);  	if (num == 1) {  		_subjectItem = findInByClass(i, (1 << cm));  		if (_subjectItem) diff --git a/engines/agos/subroutine.cpp b/engines/agos/subroutine.cpp index 517f33b3fb..6975017664 100644 --- a/engines/agos/subroutine.cpp +++ b/engines/agos/subroutine.cpp @@ -522,14 +522,24 @@ void AGOSEngine::runSubroutine101() {  int AGOSEngine::startSubroutine(Subroutine *sub) {  	int result = -1; -	SubroutineLine *sl; -	const byte *old_code_ptr; +	SubroutineLine *sl = (SubroutineLine *)((byte *)sub + sub->first); + +	const byte *old_code_ptr = _codePtr; +	Subroutine *old_currentTable = _currentTable; +	SubroutineLine *old_currentLine = _currentLine; +	SubroutineLine *old_classLine = _classLine; +	int16 old_classMask = _classMask; +	int16 old_classMode1 = _classMode1; +	int16 old_classMode2 = _classMode2; + +	_classLine = 0; +	_classMask = 0; +	_classMode1 = 0; +	_classMode2 = 0;  	if (_startMainScript)  		dumpSubroutine(sub); -	old_code_ptr = _codePtr; -  	if (++_recursionDepth > 40)  		error("Recursion error"); @@ -543,9 +553,10 @@ int AGOSEngine::startSubroutine(Subroutine *sub) {  			setBitFlag(171, false);  	} -	sl = (SubroutineLine *)((byte *)sub + sub->first); - +	_currentTable = sub; +restart:  	while ((byte *)sl != (byte *)sub) { +		_currentLine = sl;  		if (checkIfToRunSubroutineLine(sl, sub)) {  			result = 0;  			_codePtr = (byte *)sl; @@ -558,19 +569,47 @@ int AGOSEngine::startSubroutine(Subroutine *sub) {  				printf("; %d\n", sub->id);  			result = runScript();  			if (result != 0) { -				/* result -10 means restart subroutine */ -				if (result == -10) { -					delay(0);							/* maybe leave control to the VGA */ -					sl = (SubroutineLine *)((byte *)sub + sub->first); -					continue; -				}  				break;  			}  		}  		sl = (SubroutineLine *)((byte *)sub + sl->next);  	} +	if (_classMode1) { +		debug(0, "_classMode1"); +		_subjectItem = nextInByClass(_subjectItem, _classMask); +		if (!_subjectItem) { +			_classMode1 = 0; +		} else { +			sl = _classLine;	/* Rescanner */ +			goto restart; +		} +	} +	if (_classMode2) { +		debug(0, "_classMode2"); +		_objectItem = nextInByClass(_objectItem, _classMask); +		if (!_objectItem) { +			_classMode2 = 0; +		} else { +			sl = _classLine;	/* Rescanner */ +			goto restart; +		} +	} + +	/* result -10 means restart subroutine */ +	if (result == -10) { +		sl = (SubroutineLine *)((byte *)sub + sub->first); +		goto restart; +	} +  	_codePtr = old_code_ptr; +	_currentLine = old_currentLine; +	_currentTable = old_currentTable; +	_classLine = old_classLine; +	_classMask = old_classMask; +	_classMode1 = old_classMode2; +	_classMode2 = old_classMode1; +	_findNextPtr = 0;  	_recursionDepth--;  	return result;  | 
