diff options
Diffstat (limited to 'engines/agos/agos.cpp')
-rw-r--r-- | engines/agos/agos.cpp | 1549 |
1 files changed, 29 insertions, 1520 deletions
diff --git a/engines/agos/agos.cpp b/engines/agos/agos.cpp index e2775c542e..40f099d57d 100644 --- a/engines/agos/agos.cpp +++ b/engines/agos/agos.cpp @@ -791,1416 +791,6 @@ void AGOSEngine::paletteFadeOut(byte *palPtr, uint num, uint size) { } while (--num); } -byte *AGOSEngine::allocateItem(uint size) { - byte *org = _itemHeapPtr; - size = (size + sizeof(void*) - 1) & ~(sizeof(void*) - 1); - - _itemHeapPtr += size; - _itemHeapCurPos += size; - - if (_itemHeapCurPos > _itemHeapSize) - error("allocateItem: Itemheap overflow"); - - return org; -} - -int AGOSEngine::getUserFlag(Item *item, int a) { - SubUserFlag *subUserFlag; - - subUserFlag = (SubUserFlag *) findChildOfType(item, 9); - if (subUserFlag == NULL) - return 0; - - if (a < 0 || a > 7) - return 0; - - return subUserFlag->userFlags[a]; -} - -void AGOSEngine::setUserFlag(Item *item, int a, int b) { - SubUserFlag *subUserFlag; - - subUserFlag = (SubUserFlag *) findChildOfType(item, 9); - if (subUserFlag == NULL) { - subUserFlag = (SubUserFlag *) allocateChildBlock(item, 9, sizeof(SubUserFlag)); - } - - if (a < 0 || a > 7) - return; - - subUserFlag->userFlags[a] = b; -} - -int AGOSEngine::getUserItem(Item *item, int n) { - SubUserFlag *subUserFlag; - - subUserFlag = (SubUserFlag *) findChildOfType(item, 9); - if (subUserFlag == NULL) - return 0; - - if (n < 0 || n > 0) - return 0; - - return subUserFlag->userItems[n]; -} - -void AGOSEngine::setUserItem(Item *item, int n, int m) { - SubUserFlag *subUserFlag; - - subUserFlag = (SubUserFlag *) findChildOfType(item, 9); - if (subUserFlag == NULL) { - subUserFlag = (SubUserFlag *) allocateChildBlock(item, 9, sizeof(SubUserFlag)); - } - - if (n == 0) - subUserFlag->userItems[n] = m; -} - -void AGOSEngine::createPlayer() { - SubPlayer *p; - - _currentPlayer = _itemArrayPtr[1]; - _currentPlayer->adjective = -1; - _currentPlayer->noun = 10000; - - p = (SubPlayer *)allocateChildBlock(_currentPlayer, 3, sizeof(SubPlayer)); - if (p == NULL) - error("createPlayer: player create failure"); - - p->size = 0; - p->weight = 0; - p->strength = 6000; - //p->flag = xxx; - p->level = 1; - p->score = 0; - - setUserFlag(_currentPlayer, 0, 0); -} - -Child *AGOSEngine::findChildOfType(Item *i, uint type) { - Child *child = i->children; - for (; child; child = child->next) - if (child->type == type) - return child; - return NULL; -} - -bool AGOSEngine::isRoom(Item *item) { - return findChildOfType(item, 1) != NULL; -} - -bool AGOSEngine::isObject(Item *item) { - return findChildOfType(item, 2) != NULL; -} - -bool AGOSEngine::isPlayer(Item *item) { - return findChildOfType(item, 3) != NULL; -} - -uint AGOSEngine::getOffsetOfChild2Param(SubObject *child, uint prop) { - uint m = 1; - uint offset = 0; - while (m != prop) { - if (child->objectFlags & m) - offset++; - m *= 2; - } - return offset; -} - -Child *AGOSEngine::allocateChildBlock(Item *i, uint type, uint size) { - Child *child = (Child *)allocateItem(size); - child->next = i->children; - i->children = child; - child->type = type; - return child; -} - -void AGOSEngine::allocItemHeap() { - _itemHeapSize = _itemMemSize; - _itemHeapCurPos = 0; - _itemHeapPtr = (byte *)calloc(_itemMemSize, 1); - if (!_itemHeapPtr) - error("Out Of Memory - Items"); -} - -void AGOSEngine::allocTablesHeap() { - _tablesHeapSize = _tableMemSize; - _tablesHeapCurPos = 0; - _tablesHeapPtr = (byte *)calloc(_tableMemSize, 1); - if (!_tablesHeapPtr) - error("Out Of Memory - Tables"); -} - -void AGOSEngine::setItemState(Item *item, int value) { - item->state = value; -} - -byte AGOSEngine::getByte() { - return *_codePtr++; -} - -int AGOSEngine::getNextWord() { - int16 a = (int16)READ_BE_UINT16(_codePtr); - _codePtr += 2; - return a; -} - -uint AGOSEngine::getNextStringID() { - return (uint16)getNextWord(); -} - -uint AGOSEngine::getVarOrByte() { - if (getGameType() == GType_ELVIRA1) { - return getVarOrWord(); - } else { - uint a = *_codePtr++; - if (a != 255) - return a; - return readVariable(*_codePtr++); - } -} - -uint AGOSEngine::getVarOrWord() { - uint a = READ_BE_UINT16(_codePtr); - _codePtr += 2; - if (getGameType() == GType_PP) { - if (a >= 60000 && a < 62048) { - return readVariable(a - 60000); - } - } else { - if (a >= 30000 && a < 30512) { - return readVariable(a - 30000); - } - } - return a; -} - -uint AGOSEngine::getVarWrapper() { - if (getGameType() == GType_ELVIRA1 || getGameType() == GType_PP) - return getVarOrWord(); - else - return getVarOrByte(); -} - -Item *AGOSEngine::getNextItemPtr() { - int a = getNextWord(); - switch (a) { - case -1: - return _subjectItem; - case -3: - return _objectItem; - case -5: - return me(); - case -7: - return actor(); - case -9: - return derefItem(me()->parent); - default: - return derefItem(a); - } -} - -Item *AGOSEngine::getNextItemPtrStrange() { - int a = getNextWord(); - switch (a) { - case -1: - return _subjectItem; - case -3: - return _objectItem; - case -5: - return _dummyItem2; - case -7: - return NULL; - case -9: - return _dummyItem3; - default: - return derefItem(a); - } -} - -uint AGOSEngine::getNextItemID() { - int a = getNextWord(); - switch (a) { - case -1: - return itemPtrToID(_subjectItem); - case -3: - return itemPtrToID(_objectItem); - case -5: - return getItem1ID(); - case -7: - return 0; - case -9: - return me()->parent; - default: - return a; - } -} - -Item *AGOSEngine::me() { - if (_currentPlayer) - return _currentPlayer; - return _dummyItem1; -} - -Item *AGOSEngine::actor() { - error("actor: is this code ever used?"); - //if (_actorPlayer) - // return _actorPlayer; - return _dummyItem1; -} - -uint AGOSEngine::getNextVarContents() { - return (uint16)readVariable(getVarWrapper()); -} - -uint AGOSEngine::readVariable(uint variable) { - if (variable >= _numVars) - error("readVariable: Variable %d out of range", variable); - - if (getGameType() == GType_PP) { - return (uint16)_variableArray[variable]; - } else if (getGameType() == GType_FF) { - if (getBitFlag(83)) - return (uint16)_variableArray2[variable]; - else - return (uint16)_variableArray[variable]; - } else { - return _variableArray[variable]; - } -} - -void AGOSEngine::writeNextVarContents(uint16 contents) { - writeVariable(getVarWrapper(), contents); -} - -void AGOSEngine::writeVariable(uint variable, uint16 contents) { - if (variable >= _numVars) - error("writeVariable: Variable %d out of range", variable); - - if (getGameType() == GType_FF && getBitFlag(83)) - _variableArray2[variable] = contents; - else - _variableArray[variable] = contents; -} - -void AGOSEngine::setItemParent(Item *item, Item *parent) { - Item *old_parent = derefItem(item->parent); - - if (item == parent) - error("setItemParent: Trying to set item as its own parent"); - - // unlink it if it has a parent - if (old_parent) - unlinkItem(item); - itemChildrenChanged(old_parent); - linkItem(item, parent); - itemChildrenChanged(parent); -} - -void AGOSEngine::itemChildrenChanged(Item *item) { - int i; - WindowBlock *window; - - if (_noParentNotify) - return; - - mouseOff(); - - for (i = 0; i != 8; i++) { - window = _windowArray[i]; - if (window && window->iconPtr && window->iconPtr->itemRef == item) { - if (_fcsData1[i]) { - _fcsData2[i] = true; - } else { - _fcsData2[i] = false; - drawIconArray(i, item, window->iconPtr->line, window->iconPtr->classMask); - } - } - } - - mouseOn(); -} - -void AGOSEngine::unlinkItem(Item *item) { - Item *first, *parent, *next; - - // can't unlink item without parent - if (item->parent == 0) - return; - - // get parent and first child of parent - parent = derefItem(item->parent); - first = derefItem(parent->child); - - // the node to remove is first in the parent's children? - if (first == item) { - parent->child = item->next; - item->parent = 0; - item->next = 0; - return; - } - - for (;;) { - if (!first) - error("unlinkItem: parent empty"); - if (first->next == 0) - error("unlinkItem: parent does not contain child"); - - next = derefItem(first->next); - if (next == item) { - first->next = next->next; - item->parent = 0; - item->next = 0; - return; - } - first = next; - } -} - -void AGOSEngine::linkItem(Item *item, Item *parent) { - uint id; - // Don't allow that an item that is already linked is relinked - if (item->parent) - return; - - id = itemPtrToID(parent); - item->parent = id; - - if (parent != 0) { - item->next = parent->child; - parent->child = itemPtrToID(item); - } else { - item->next = 0; - } -} - -void AGOSEngine::setup_cond_c_helper() { - HitArea *last; - uint id; - - _noRightClick = 1; - - if (getGameType() == GType_WW) - clearMenuStrip(); - - if (getGameType() == GType_FF) { - int cursor = 5; - int animMax = 16; - - if (getBitFlag(200)) { - cursor = 11; - animMax = 5; - } else if (getBitFlag(201)) { - cursor = 12; - animMax = 5; - } else if (getBitFlag(202)) { - cursor = 13; - animMax = 5; - } else if (getBitFlag(203)) { - cursor = 14; - animMax = 9; - } else if (getBitFlag(205)) { - cursor = 17; - animMax = 11; - } else if (getBitFlag(206)) { - cursor = 16; - animMax = 2; - } else if (getBitFlag(208)) { - cursor = 26; - animMax = 2; - } else if (getBitFlag(209)) { - cursor = 27; - animMax = 9; - } else if (getBitFlag(210)) { - cursor = 28; - animMax = 9; - } - - _animatePointer = 0; - _mouseCursor = cursor; - _mouseAnimMax = animMax; - _mouseAnim = 1; - _needHitAreaRecalc++; - } - - if (getGameType() == GType_SIMON2) { - _mouseCursor = 0; - if (_defaultVerb != 999) { - _mouseCursor = 9; - _needHitAreaRecalc++; - _defaultVerb = 0; - } - } - - _lastHitArea = 0; - _hitAreaObjectItem = NULL; - _nameLocked = 0; - - last = _lastNameOn; - clearName(); - _lastNameOn = last; - - for (;;) { - _lastHitArea = NULL; - _lastHitArea3 = 0; - _leftButtonDown = 0; - - do { - if (_exitCutscene && getBitFlag(9)) { - endCutscene(); - goto out_of_here; - } - - if (getGameType() == GType_FF) { - if (_variableArray[254] == 63) { - hitarea_stuff_helper_2(); - } else if (_variableArray[254] == 75) { - hitarea_stuff_helper_2(); - _variableArray[60] = 9999; - goto out_of_here; - } - } - - delay(100); - } while (_lastHitArea3 == (HitArea *) -1 || _lastHitArea3 == 0); - - if (_lastHitArea == NULL) { - } else if (_lastHitArea->id == 0x7FFB) { - inventoryUp(_lastHitArea->window); - } else if (_lastHitArea->id == 0x7FFC) { - inventoryDown(_lastHitArea->window); - } else if (_lastHitArea->item_ptr != NULL) { - _hitAreaObjectItem = _lastHitArea->item_ptr; - id = 0xFFFF; - if (_lastHitArea->flags & kBFTextBox) { - if (getGameType() == GType_PP) - id = _lastHitArea->id; - else if (getGameType() == GType_FF && (_lastHitArea->flags & kBFHyperBox)) - id = _lastHitArea->data; - else - id = _lastHitArea->flags / 256; - } - if (getGameType() == GType_PP) - _variableArray[199] = id; - else if (getGameType() == GType_WW) - _variableArray[10] = id; - else - _variableArray[60] = id; - break; - } - } - -out_of_here: - _lastHitArea3 = 0; - _lastHitArea = 0; - _lastNameOn = NULL; - _mouseCursor = 0; - _noRightClick = 0; -} - -void AGOSEngine::endCutscene() { - Subroutine *sub; - - _sound->stopVoice(); - - sub = getSubroutineByID(170); - if (sub != NULL) - startSubroutineEx(sub); - - _runScriptReturn1 = true; -} - -bool AGOSEngine::has_item_childflag_0x10(Item *item) { - SubObject *child = (SubObject *)findChildOfType(item, 2); - return child && (child->objectFlags & kOFIcon) != 0; -} - -uint AGOSEngine::itemGetIconNumber(Item *item) { - if (getGameType() == GType_ELVIRA1) { - return getUserFlag(item, 7); - } else { - SubObject *child = (SubObject *)findChildOfType(item, 2); - uint offs; - - if (child == NULL || !(child->objectFlags & kOFIcon)) - return 0; - - offs = getOffsetOfChild2Param(child, 0x10); - return child->objectFlagValue[offs]; - } -} - -void AGOSEngine::waitForInput() { - HitArea *ha; - uint id; - - _leftButtonDown = 0; - _lastHitArea = 0; - _verbHitArea = 0; - _hitAreaSubjectItem = NULL; - _hitAreaObjectItem = NULL; - _nameLocked = 0; - - if (getGameType() == GType_WW) { - _mouseCursor = 0; - _needHitAreaRecalc++; - clearMenuStrip(); - } else { - resetVerbs(); - } - -startOver: - for (;;) { - _lastHitArea = NULL; - _lastHitArea3 = NULL; - - for (;;) { - if (getGameType() != GType_FF && getGameType() != GType_PP && _keyPressed == 35) - displayBoxStars(); - if (processSpecialKeys() != 0) { - goto out_of_here; - } - if (_lastHitArea3 == (HitArea *) -1) - goto startOver; - if (_lastHitArea3 != 0) - break; - hitarea_stuff_helper(); - delay(100); - } - - ha = _lastHitArea; - - if (ha == NULL) { - } else if (ha->id == 0x7FFB) { - inventoryUp(ha->window); - } else if (ha->id == 0x7FFC) { - inventoryDown(ha->window); - } else if ((getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) && - (ha->id >= 101 && ha->id < 113)) { - _verbHitArea = ha->verb; - setVerb(ha); - _defaultVerb = 0; - } else { - if (getGameType() == GType_WW) { - if (_mouseCursor == 3) - _verbHitArea = 236; - - if (ha->id == 98) { - loadSprite(2, 0, 110, 0, 0, 0); - waitForSync(34); - } else if (ha->id == 108) { - loadSprite(2, 0, 106, 0, 0, 0); - waitForSync(34); - } else if (ha->id == 109) { - loadSprite(2, 0, 107, 0, 0, 0); - waitForSync(34); - } else if (ha->id == 115) { - loadSprite(2, 0, 109, 0, 0, 0); - waitForSync(34); - } else if (ha->id == 116) { - loadSprite(2, 0, 113, 0, 0, 0); - waitForSync(34); - } else if (ha->id == 117) { - loadSprite(2, 0, 112, 0, 0, 0); - waitForSync(34); - } else if (ha->id == 118) { - loadSprite(2, 0, 108, 0, 0, 0); - waitForSync(34); - } else if (ha->id == 119) { - loadSprite(2, 0, 111, 0, 0, 0); - waitForSync(34); - } - } - if ((_verbHitArea != 0 || _hitAreaSubjectItem != ha->item_ptr && ha->flags & kBFBoxItem) && - ha->item_ptr) { - if_1:; - _hitAreaSubjectItem = ha->item_ptr; - id = 0xFFFF; - if (ha->flags & kBFTextBox) { - if (getGameType() == GType_PP) - id = _lastHitArea->id; - else if (getGameType() == GType_FF && (ha->flags & kBFHyperBox)) - id = ha->data; - else - id = ha->flags / 256; - } - if (getGameType() == GType_PP) - _variableArray[199] = id; - else if (getGameType() == GType_WW) - _variableArray[10] = id; - else - _variableArray[60] = id; - - _nameLocked = 2; - displayName(ha); - _nameLocked = 1; - - if (_verbHitArea != 0) { - break; - } - - if (getGameType() == GType_ELVIRA2) - doMenuStrip(menuFor_e2(ha->item_ptr, id)); - else if (getGameType() == GType_WW) - doMenuStrip(menuFor_ww(ha->item_ptr, id)); - } else { - // else 1 - if (ha->verb == 0) { - if (ha->item_ptr) - goto if_1; - } else { - if (getGameType() == GType_WW && _mouseCursor != 0 && _mouseCursor < 4) { - _hitAreaSubjectItem = ha->item_ptr; - break; - } - - _verbHitArea = ha->verb & 0xBFFF; - if (ha->verb & 0x4000) { - _hitAreaSubjectItem = ha->item_ptr; - break; - } - if (_hitAreaSubjectItem != NULL) - break; - - if (getGameType() == GType_WW) { - if (ha->id == 109) { - _mouseCursor = 2; - _needHitAreaRecalc++; - } else if (ha->id == 117) { - _mouseCursor = 3; - _needHitAreaRecalc++; - } - } - } - } - } - } - -out_of_here: - if (getGameType() == GType_ELVIRA2 || getGameType() == GType_WW) - clearMenuStrip(); - - _nameLocked = 0; - _needHitAreaRecalc++; -} - -void AGOSEngine::hitarea_stuff_helper() { - time_t cur_time; - - if (getGameType() == GType_SIMON2 || getGameType() == GType_FF || - getGameType() == GType_PP) { - if (_variableArray[254] || _variableArray[249]) { - hitarea_stuff_helper_2(); - } - } else if (getGameType() == GType_ELVIRA2 || getGameType() == GType_WW || - getGameType() == GType_SIMON1) { - uint subr_id = (uint16)_variableArray[254]; - if (subr_id != 0) { - Subroutine *sub = getSubroutineByID(subr_id); - if (sub != NULL) { - startSubroutineEx(sub); - permitInput(); - } - _variableArray[254] = 0; - _runScriptReturn1 = false; - } - } - - time(&cur_time); - if ((uint) cur_time != _lastTime) { - _lastTime = cur_time; - if (kickoffTimeEvents()) - permitInput(); - } -} - -void AGOSEngine::hitarea_stuff_helper_2() { - uint subr_id; - Subroutine *sub; - - subr_id = (uint16)_variableArray[249]; - if (subr_id != 0) { - sub = getSubroutineByID(subr_id); - if (sub != NULL) { - _variableArray[249] = 0; - startSubroutineEx(sub); - permitInput(); - } - _variableArray[249] = 0; - } - - subr_id = (uint16)_variableArray[254]; - if (subr_id != 0) { - sub = getSubroutineByID(subr_id); - if (sub != NULL) { - _variableArray[254] = 0; - startSubroutineEx(sub); - permitInput(); - } - _variableArray[254] = 0; - } - - _runScriptReturn1 = false; -} - -void AGOSEngine::permitInput() { - if (!_mortalFlag) { - _mortalFlag = true; - showmessage_print_char(0); - _curWindow = 0; - if (_windowArray[0] != 0) { - _textWindow = _windowArray[0]; - if (getGameType() == GType_FF || getGameType() == GType_PP) - showmessage_helper_3(_textWindow->textColumn, _textWindow->width); - else - showmessage_helper_3(_textWindow->textLength, _textWindow->textMaxLength); - } - _mortalFlag = false; - } -} - -TextLocation *AGOSEngine::getTextLocation(uint a) { - switch (a) { - case 1: - return &_textLocation1; - case 2: - return &_textLocation2; - case 101: - return &_textLocation3; - case 102: - return &_textLocation4; - default: - error("getTextLocation: Invalid text location %d", a); - } - return NULL; -} - -void AGOSEngine::loadZone(uint zoneNum) { - VgaPointersEntry *vpe; - - CHECK_BOUNDS(zoneNum, _vgaBufferPointers); - - vpe = _vgaBufferPointers + zoneNum; - if (vpe->vgaFile1 != NULL) - return; - - // Loading order is important - // due to resource managment - - loadVGAVideoFile(zoneNum, 2); - vpe->vgaFile2 = _block; - vpe->vgaFile2End = _blockEnd; - - loadVGAVideoFile(zoneNum, 1); - vpe->vgaFile1 = _block; - vpe->vgaFile1End = _blockEnd; - - vpe->sfxFile = NULL; - if (!(getFeatures() & GF_ZLIBCOMP)) { - if (loadVGASoundFile(zoneNum, 3)) { - vpe->sfxFile = _block; - vpe->sfxFileEnd = _blockEnd; - } - } -} - -void AGOSEngine::setZoneBuffers() { - _zoneBuffers = (byte *)malloc(_vgaMemSize); - - _vgaMemPtr = _zoneBuffers; - _vgaMemBase = _zoneBuffers; - _vgaFrozenBase = _zoneBuffers; - _vgaRealBase = _zoneBuffers; - _vgaMemEnd = _zoneBuffers + _vgaMemSize; -} - -byte *AGOSEngine::allocBlock(uint32 size) { - for (;;) { - _block = _vgaMemPtr; - _blockEnd = _block + size; - - if (_blockEnd >= _vgaMemEnd) { - _vgaMemPtr = _vgaMemBase; - } else { - _rejectBlock = false; - checkNoOverWrite(); - if (_rejectBlock) - continue; - checkRunningAnims(); - if (_rejectBlock) - continue; - checkZonePtrs(); - _vgaMemPtr = _blockEnd; - return _block; - } - } -} - -void AGOSEngine::checkNoOverWrite() { - VgaPointersEntry *vpe; - - if (_noOverWrite == 0xFFFF) - return; - - vpe = &_vgaBufferPointers[_noOverWrite]; - - if (getGameType() == GType_FF || getGameType() == GType_PP) { - if (vpe->vgaFile1 < _blockEnd && vpe->vgaFile1End > _block) { - _rejectBlock = true; - _vgaMemPtr = vpe->vgaFile1End; - } else if (vpe->vgaFile2 < _blockEnd && vpe->vgaFile2End > _block) { - _rejectBlock = true; - _vgaMemPtr = vpe->vgaFile2End; - } else if (vpe->sfxFile && vpe->sfxFile < _blockEnd && vpe->sfxFileEnd > _block) { - _rejectBlock = true; - _vgaMemPtr = vpe->sfxFileEnd; - } else { - _rejectBlock = false; - } - } else { - if (_block <= vpe->vgaFile1 && _blockEnd >= vpe->vgaFile1 || - _vgaMemPtr <= vpe->vgaFile2 && _blockEnd >= vpe->vgaFile2) { - _rejectBlock = true; - _vgaMemPtr = vpe->vgaFile1 + 0x5000; - } else { - _rejectBlock = false; - } - } -} - -void AGOSEngine::checkRunningAnims() { - VgaSprite *vsp; - if (getGameType() != GType_FF && getGameType() != GType_PP && (_lockWord & 0x20)) { - return; - } - - for (vsp = _vgaSprites; vsp->id; vsp++) { - checkAnims(vsp->zoneNum); - if (_rejectBlock == true) - return; - } -} - -void AGOSEngine::checkAnims(uint a) { - VgaPointersEntry *vpe; - - vpe = &_vgaBufferPointers[a]; - - if (getGameType() == GType_FF || getGameType() == GType_PP) { - if (vpe->vgaFile1 < _blockEnd && vpe->vgaFile1End > _block) { - _rejectBlock = true; - _vgaMemPtr = vpe->vgaFile1End; - } else if (vpe->vgaFile2 < _blockEnd && vpe->vgaFile2End > _block) { - _rejectBlock = true; - _vgaMemPtr = vpe->vgaFile2End; - } else if (vpe->sfxFile && vpe->sfxFile < _blockEnd && vpe->sfxFileEnd > _block) { - _rejectBlock = true; - _vgaMemPtr = vpe->sfxFileEnd; - } else { - _rejectBlock = false; - } - } else { - if (_block <= vpe->vgaFile1 && _blockEnd >= vpe->vgaFile1 || - _block <= vpe->vgaFile2 && _blockEnd >= vpe->vgaFile2) { - _rejectBlock = true; - _vgaMemPtr = vpe->vgaFile1 + 0x5000; - } else { - _rejectBlock = false; - } - } -} - -void AGOSEngine::checkZonePtrs() { - uint count = ARRAYSIZE(_vgaBufferPointers); - VgaPointersEntry *vpe = _vgaBufferPointers; - do { - if (getGameType() == GType_FF || getGameType() == GType_PP) { - if (vpe->vgaFile1 < _blockEnd && vpe->vgaFile1End > _block || - vpe->vgaFile2 < _blockEnd && vpe->vgaFile2End > _block || - vpe->sfxFile < _blockEnd && vpe->sfxFileEnd > _block) { - vpe->vgaFile1 = NULL; - vpe->vgaFile1End = NULL; - vpe->vgaFile2 = NULL; - vpe->vgaFile2End = NULL; - vpe->sfxFile = NULL; - vpe->sfxFileEnd = NULL; - } - } else { - if (_block <= vpe->vgaFile1 && _blockEnd >= vpe->vgaFile1 || - _block <= vpe->vgaFile2 && _blockEnd >= vpe->vgaFile2) { - vpe->vgaFile1 = NULL; - vpe->vgaFile2 = NULL; - } - } - } while (++vpe, --count); -} - -void AGOSEngine::set_video_mode_internal(uint16 mode, uint16 vga_res_id) { - uint num, num_lines; - VgaPointersEntry *vpe; - byte *bb, *b; - uint16 count, updateWindow; - const byte *vc_ptr_org; - - _windowNum = updateWindow = mode; - _lockWord |= 0x20; - - if (getGameType() == GType_FF || getGameType() == GType_PP) { - vc27_resetSprite(); - } - - if (vga_res_id == 0) { - if (getGameType() == GType_SIMON1) { - _unkPalFlag = true; - } else if (getGameType() == GType_SIMON2) { - _useBackGround = true; - _restoreWindow6 = true; - } - } - - _zoneNumber = num = vga_res_id / 100; - - for (;;) { - vpe = &_vgaBufferPointers[num]; - - _curVgaFile1 = vpe->vgaFile1; - _curVgaFile2 = vpe->vgaFile2; - _curSfxFile = vpe->sfxFile; - - if (vpe->vgaFile1 != NULL) - break; - - loadZone(num); - } - - // ensure flipping complete - - bb = _curVgaFile1; - - if (getGameType() == GType_FF || getGameType() == GType_PP) { - b = bb + READ_LE_UINT16(bb + 2); - count = READ_LE_UINT16(&((VgaFileHeader2_Feeble *) b)->imageCount); - b = bb + READ_LE_UINT16(&((VgaFileHeader2_Feeble *) b)->imageTable); - - while (count--) { - if (READ_LE_UINT16(&((ImageHeader_Feeble *) b)->id) == vga_res_id) - break; - b += sizeof(ImageHeader_Feeble); - } - assert(READ_LE_UINT16(&((ImageHeader_Feeble *) b)->id) == vga_res_id); - - } else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) { - b = bb + READ_BE_UINT16(bb + 4); - count = READ_BE_UINT16(&((VgaFileHeader2_Common *) b)->imageCount); - b = bb + READ_BE_UINT16(&((VgaFileHeader2_Common *) b)->imageTable); - - while (count--) { - if (READ_BE_UINT16(&((ImageHeader_Simon *) b)->id) == vga_res_id) - break; - b += sizeof(ImageHeader_Simon); - } - assert(READ_BE_UINT16(&((ImageHeader_Simon *) b)->id) == vga_res_id); - } else { - b = bb + READ_BE_UINT16(bb + 10); - b += 20; - - count = READ_BE_UINT16(&((VgaFileHeader2_Common *) b)->imageCount); - b = bb + READ_BE_UINT16(&((VgaFileHeader2_Common *) b)->imageTable); - - while (count--) { - if (READ_BE_UINT16(&((ImageHeader_WW *) b)->id) == vga_res_id) - break; - b += sizeof(ImageHeader_WW); - } - assert(READ_BE_UINT16(&((ImageHeader_WW *) b)->id) == vga_res_id); - - clearWindow(_windowNum, READ_BE_UINT16(&((ImageHeader_WW *) b)->color)); - } - - if (_startVgaScript) { - if (getGameType() == GType_FF || getGameType() == GType_PP) { - dump_vga_script(_curVgaFile1 + READ_LE_UINT16(&((ImageHeader_Feeble*)b)->scriptOffs), num, vga_res_id); - } else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) { - dump_vga_script(_curVgaFile1 + READ_BE_UINT16(&((ImageHeader_Simon*)b)->scriptOffs), num, vga_res_id); - } else { - dump_vga_script(_curVgaFile1 + READ_BE_UINT16(&((ImageHeader_WW*)b)->scriptOffs), num, vga_res_id); - } - } - - if (getGameType() == GType_SIMON1) { - if (vga_res_id == 16300) { - clearBackFromTop(134); - _usePaletteDelay = true; - } - } else if (getGameType() == GType_SIMON2 || getGameType() == GType_FF) { - _scrollX = 0; - _scrollY = 0; - _scrollXMax = 0; - _scrollYMax = 0; - _scrollCount = 0; - _scrollFlag = 0; - _scrollHeight = 134; - _variableArrayPtr = _variableArray; - if (_variableArray[34] >= 0) { - if (getGameType() == GType_FF) - _variableArray[250] = 0; - _variableArray[251] = 0; - } - } - - vc_ptr_org = _vcPtr; - - if (getGameType() == GType_FF || getGameType() == GType_PP) { - _vcPtr = _curVgaFile1 + READ_LE_UINT16(&((ImageHeader_Feeble *) b)->scriptOffs); - } else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) { - _vcPtr = _curVgaFile1 + READ_BE_UINT16(&((ImageHeader_Simon *) b)->scriptOffs); - } else { - _vcPtr = _curVgaFile1 + READ_BE_UINT16(&((ImageHeader_WW *) b)->scriptOffs); - } - - runVgaScript(); - _vcPtr = vc_ptr_org; - - if (getGameType() == GType_FF || getGameType() == GType_PP) { - fillFrontFromBack(0, 0, _screenWidth, _screenHeight); - fillBackGroundFromBack(_screenHeight); - _syncFlag2 = 1; - } else if (getGameType() == GType_SIMON2) { - if (!_useBackGround) { - num_lines = _windowNum == 4 ? 134 : 200; - _boxStarHeight = num_lines; - fillFrontFromBack(0, 0, _screenWidth, num_lines); - fillBackGroundFromBack(num_lines); - _syncFlag2 = 1; - } - _useBackGround = false; - } else { - // Allow one section of Simon the Sorcerer 1 introduction to be displayed - // in lower half of screen - if (_subroutine == 2923 || _subroutine == 2926) - num_lines = 200; - else - num_lines = _windowNum == 4 ? 134 : 200; - - fillFrontFromBack(0, 0, _screenWidth, num_lines); - fillBackGroundFromBack(num_lines); - - _syncFlag2 = 1; - _timer5 = 0; - } - - if (getGameType() == GType_ELVIRA1 && updateWindow == 3 && _bottomPalette != 0) { - byte *dst = getBackBuf() + 42560; - int size = 21440; - - while (size--) { - *dst += 0x10; - dst++; - } - } - - _lockWord &= ~0x20; - - if (getGameType() == GType_SIMON1) { - if (_unkPalFlag) { - _unkPalFlag = false; - while (_fastFadeInFlag != 0) { - delay(10); - } - } - } -} - -void AGOSEngine::waitForSync(uint a) { - const uint maxCount = (getGameType() == GType_SIMON1) ? 500 : 1000; - - if (getGameType() == GType_SIMON1 && (getFeatures() & GF_TALKIE)) { - if (a != 200) { - uint16 tmp = _lastVgaWaitFor; - _lastVgaWaitFor = 0; - if (tmp == a) - return; - } - } - - _vgaWaitFor = a; - _syncCount = 0; - _exitCutscene = false; - _rightButtonDown = false; - - while (_vgaWaitFor != 0) { - if (_rightButtonDown) { - if (_vgaWaitFor == 200 && (getGameType() == GType_FF || !getBitFlag(14))) { - skipSpeech(); - break; - } - } - if (_exitCutscene) { - if (getGameType() == GType_ELVIRA1) { - if (_variableArray[105] == 0) { - _variableArray[105] = 255; - break; - } - } else if (getGameType() == GType_ELVIRA2 || getGameType() == GType_WW) { - if (_vgaWaitFor == 51) { - setBitFlag(244, 1); - break; - } - } else { - if (getBitFlag(9)) { - endCutscene(); - break; - } - } - } - processSpecialKeys(); - - if (_syncCount >= maxCount) { - warning("waitForSync: wait timed out"); - break; - } - - delay(1); - } -} - -void AGOSEngine::skipSpeech() { - _sound->stopVoice(); - if (!getBitFlag(28)) { - setBitFlag(14, true); - if (getGameType() == GType_FF) { - _variableArray[103] = 5; - loadSprite(4, 2, 13, 0, 0, 0); - waitForSync(213); - stopAnimateSimon2(2, 1); - } else if (getGameType() == GType_SIMON2) { - _variableArray[100] = 5; - loadSprite(4, 1, 30, 0, 0, 0); - waitForSync(130); - stopAnimateSimon2(2, 1); - } else { - _variableArray[100] = 15; - loadSprite(4, 1, 130, 0, 0, 0); - waitForSync(130); - stopAnimateSimon1(1); - } - } -} - -int AGOSEngine::wordMatch(Item *item, int16 a, int16 n) { - if ((a == -1) && (n == item->noun)) - return 1; - if ((a == item->adjective) && (n == item->noun)) - return 1 ; - - return 0; -} - -Item *AGOSEngine::derefItem(uint item) { - if (item >= _itemArraySize) { - debug(1, "derefItem: invalid item %d", item); - return 0; - } - return _itemArrayPtr[item]; -} - -Item *AGOSEngine::findInByClass(Item *i, int16 m) { - i = derefItem(i->child); - - 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; -} - -Item *AGOSEngine::findMaster(int16 a, int16 n) { - uint j; - - for (j = 1; j < _itemArraySize; j++) { - Item *item = derefItem(j); - if (wordMatch(item, a, n)) - return item; - } - - return NULL; -} - -Item *AGOSEngine::nextMaster(Item *i, int16 a, int16 n) { - uint j; - uint first = itemPtrToID(i) + 1; - - for (j = first; j < _itemArraySize; j++) { - Item *item = derefItem(j); - if (wordMatch(item, a, n)) - return item; - } - - return NULL; -} - -uint AGOSEngine::itemPtrToID(Item *id) { - uint i; - for (i = 0; i != _itemArraySize; i++) - if (_itemArrayPtr[i] == id) - return i; - error("itemPtrToID: not found"); - return 0; -} - -bool AGOSEngine::isSpriteLoaded(uint16 id, uint16 zoneNum) { - VgaSprite *vsp = _vgaSprites; - while (vsp->id) { - if (getGameType() == GType_SIMON2 || getGameType() == GType_FF || getGameType() == GType_PP) { - if (vsp->id == id && vsp->zoneNum == zoneNum) - return true; - } else { - if (vsp->id == id) - return true; - } - vsp++; - } - return false; -} - -bool AGOSEngine::processSpecialKeys() { - switch (_keyPressed) { - case 17: // Up - if (getGameType() == GType_PP) - _verbHitArea = 302; - else if (getGameType() == GType_WW) - _verbHitArea = 239; - break; - case 18: // Down - if (getGameType() == GType_PP) - _verbHitArea = 304; - else if (getGameType() == GType_WW) - _verbHitArea = 241; - break; - case 19: // Right - if (getGameType() == GType_PP) - _verbHitArea = 303; - else if (getGameType() == GType_WW) - _verbHitArea = 240; - break; - case 20: // Left - if (getGameType() == GType_PP) - _verbHitArea = 301; - else if (getGameType() == GType_WW) - _verbHitArea = 242; - break; - case 27: // escape - _exitCutscene = true; - break; - case 59: // F1 - if (getGameType() == GType_SIMON1) { - vcWriteVar(5, 40); - } else { - vcWriteVar(5, 50); - } - vcWriteVar(86, 0); - break; - case 60: // F2 - if (getGameType() == GType_SIMON1) { - vcWriteVar(5, 60); - } else { - vcWriteVar(5, 75); - } - vcWriteVar(86, 1); - break; - case 61: // F3 - if (getGameType() == GType_SIMON1) { - vcWriteVar(5, 100); - } else { - vcWriteVar(5, 125); - } - vcWriteVar(86, 2); - break; - case 63: // F5 - if (getGameType() == GType_SIMON2 || getGameType() == GType_FF) - _exitCutscene = true; - break; - case 65: // F7 - if (getGameType() == GType_FF && getBitFlag(76)) - _variableArray[254] = 70; - break; - case 67: // F9 - if (getGameType() == GType_FF) - setBitFlag(73, !getBitFlag(73)); - break; - case 'p': - pause(); - break; - case 't': - if (getGameType() == GType_FF || (getGameType() == GType_SIMON2 && (getFeatures() & GF_TALKIE)) || - ((getFeatures() & GF_TALKIE) && _language != Common::EN_ANY && _language != Common::DE_DEU)) { - if (_speech) - _subtitles ^= 1; - } - break; - case 'v': - if (getGameType() == GType_FF || (getGameType() == GType_SIMON2 && (getFeatures() & GF_TALKIE))) { - if (_subtitles) - _speech ^= 1; - } - case '+': - midi.set_volume(midi.get_volume() + 16); - break; - case '-': - midi.set_volume(midi.get_volume() - 16); - break; - case 'm': - midi.pause(_musicPaused ^= 1); - break; - case 's': - if (getGameId() == GID_SIMON1DOS) - midi._enable_sfx ^= 1; - else - _sound->effectsPause(_effectsPaused ^= 1); - break; - case 'b': - _sound->ambientPause(_ambientPaused ^= 1); - break; - case 'r': - if (_debugMode) - _startMainScript ^= 1; - break; - case 'o': - if (_debugMode) - _continousMainScript ^= 1; - break; - case 'a': - if (_debugMode) - _startVgaScript ^= 1; - break; - case 'g': - if (_debugMode) - _continousVgaScript ^= 1; - break; - case 'i': - if (_debugMode) - _drawImagesDebug ^= 1; - break; - case 'd': - if (_debugMode) - _dumpImages ^=1; - break; - } - - bool result = (_keyPressed != 0); - _keyPressed = 0; - return result; -} - void AGOSEngine::pause() { _keyPressed = 1; _pause = 1; @@ -2219,110 +809,6 @@ void AGOSEngine::pause() { } -void AGOSEngine::loadSprite(uint windowNum, uint zoneNum, uint vgaSpriteId, uint x, uint y, uint palette) { - VgaSprite *vsp; - VgaPointersEntry *vpe; - byte *p, *pp; - uint count; - - if (getGameType() == GType_SIMON1 && (getFeatures() & GF_TALKIE) && vgaSpriteId >= 400) { - _lastVgaWaitFor = 0; - } - - _lockWord |= 0x40; - - if (isSpriteLoaded(vgaSpriteId, zoneNum)) { - _lockWord &= ~0x40; - return; - } - - vsp = _vgaSprites; - while (vsp->id != 0) - vsp++; - - vsp->windowNum = windowNum; - vsp->priority = 0; - vsp->flags = 0; - - vsp->y = y; - vsp->x = x; - vsp->image = 0; - if (getGameType() == GType_ELVIRA1 || getGameType() == GType_ELVIRA2 || getGameType() == GType_WW) - vsp->palette = 0; - else - vsp->palette = palette; - vsp->id = vgaSpriteId; - - if (getGameType() == GType_SIMON2 || getGameType() == GType_FF || getGameType() == GType_PP) - vsp->zoneNum = zoneNum; - else - vsp->zoneNum = zoneNum = vgaSpriteId / 100; - - for (;;) { - vpe = &_vgaBufferPointers[zoneNum]; - _zoneNumber = zoneNum; - _curVgaFile1 = vpe->vgaFile1; - if (vpe->vgaFile1 != NULL) - break; - loadZone(zoneNum); - } - - pp = _curVgaFile1; - if (getGameType() == GType_FF || getGameType() == GType_PP) { - p = pp + READ_LE_UINT16(pp + 2); - count = READ_LE_UINT16(&((VgaFileHeader2_Feeble *) p)->animationCount); - p = pp + READ_LE_UINT16(&((VgaFileHeader2_Feeble *) p)->animationTable); - } else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) { - p = pp + READ_BE_UINT16(pp + 4); - count = READ_BE_UINT16(&((VgaFileHeader2_Common *) p)->animationCount); - p = pp + READ_BE_UINT16(&((VgaFileHeader2_Common *) p)->animationTable); - } else { - p = pp + READ_BE_UINT16(pp + 10); - p += 20; - - count = READ_BE_UINT16(&((VgaFileHeader2_Common *) p)->animationCount); - p = pp + READ_BE_UINT16(&((VgaFileHeader2_Common *) p)->animationTable); - } - - for (;;) { - if (getGameType() == GType_FF || getGameType() == GType_PP) { - if (READ_LE_UINT16(&((AnimationHeader_Feeble *) p)->id) == vgaSpriteId) { - if (_startVgaScript) - dump_vga_script(pp + READ_LE_UINT16(&((AnimationHeader_Feeble*)p)->scriptOffs), zoneNum, vgaSpriteId); - - addVgaEvent(_vgaBaseDelay, pp + READ_LE_UINT16(&((AnimationHeader_Feeble *) p)->scriptOffs), vgaSpriteId, zoneNum); - break; - } - p += sizeof(AnimationHeader_Feeble); - } else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) { - if (READ_BE_UINT16(&((AnimationHeader_Simon *) p)->id) == vgaSpriteId) { - if (_startVgaScript) - dump_vga_script(pp + READ_BE_UINT16(&((AnimationHeader_Simon*)p)->scriptOffs), zoneNum, vgaSpriteId); - - addVgaEvent(_vgaBaseDelay, pp + READ_BE_UINT16(&((AnimationHeader_Simon *) p)->scriptOffs), vgaSpriteId, zoneNum); - break; - } - p += sizeof(AnimationHeader_Simon); - } else { - if (READ_BE_UINT16(&((AnimationHeader_WW *) p)->id) == vgaSpriteId) { - if (_startVgaScript) - dump_vga_script(pp + READ_BE_UINT16(&((AnimationHeader_WW *)p)->scriptOffs), zoneNum, vgaSpriteId); - - addVgaEvent(_vgaBaseDelay, pp + READ_BE_UINT16(&((AnimationHeader_WW *) p)->scriptOffs), vgaSpriteId, zoneNum); - break; - } - p += sizeof(AnimationHeader_WW); - } - - if (!--count) { - vsp->id = 0; - break; - } - } - - _lockWord &= ~0x40; -} - void AGOSEngine::playSpeech(uint speech_id, uint vgaSpriteId) { if (getGameType() == GType_SIMON1) { if (speech_id == 9999) { @@ -2331,19 +817,19 @@ void AGOSEngine::playSpeech(uint speech_id, uint vgaSpriteId) { if (!getBitFlag(14) && !getBitFlag(28)) { setBitFlag(14, true); _variableArray[100] = 15; - loadSprite(4, 1, 130, 0, 0, 0); + animate(4, 1, 130, 0, 0, 0); waitForSync(130); } _skipVgaWait = true; } else { if (_subtitles && _scriptVar2) { - loadSprite(4, 2, 204, 0, 0, 0); + animate(4, 2, 204, 0, 0, 0); waitForSync(204); stopAnimateSimon1(204); } stopAnimateSimon1(vgaSpriteId + 201); loadVoice(speech_id); - loadSprite(4, 2, vgaSpriteId + 201, 0, 0, 0); + animate(4, 2, vgaSpriteId + 201, 0, 0, 0); } } else { if (speech_id == 0xFFFF) { @@ -2352,7 +838,7 @@ void AGOSEngine::playSpeech(uint speech_id, uint vgaSpriteId) { if (!getBitFlag(14) && !getBitFlag(28)) { setBitFlag(14, true); _variableArray[100] = 5; - loadSprite(4, 1, 30, 0, 0, 0); + animate(4, 1, 30, 0, 0, 0); waitForSync(130); } _skipVgaWait = true; @@ -2363,14 +849,37 @@ void AGOSEngine::playSpeech(uint speech_id, uint vgaSpriteId) { } if (_subtitles && _scriptVar2) { - loadSprite(4, 2, 5, 0, 0, 0); + animate(4, 2, 5, 0, 0, 0); waitForSync(205); stopAnimateSimon2(2,5); } stopAnimateSimon2(2, vgaSpriteId + 2); loadVoice(speech_id); - loadSprite(4, 2, vgaSpriteId + 2, 0, 0, 0); + animate(4, 2, vgaSpriteId + 2, 0, 0, 0); + } + } +} + +void AGOSEngine::skipSpeech() { + _sound->stopVoice(); + if (!getBitFlag(28)) { + setBitFlag(14, true); + if (getGameType() == GType_FF) { + _variableArray[103] = 5; + animate(4, 2, 13, 0, 0, 0); + waitForSync(213); + stopAnimateSimon2(2, 1); + } else if (getGameType() == GType_SIMON2) { + _variableArray[100] = 5; + animate(4, 1, 30, 0, 0, 0); + waitForSync(130); + stopAnimateSimon2(2, 1); + } else { + _variableArray[100] = 15; + animate(4, 1, 130, 0, 0, 0); + waitForSync(130); + stopAnimateSimon1(1); } } } |