Add class code used by scripts in Elvira 1

svn-id: r24491
This commit is contained in:
Travis Howell 2006-10-25 05:32:15 +00:00
parent 8b0f34e193
commit 869243142a
5 changed files with 81 additions and 18 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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)

View File

@ -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;