diff --git a/engines/saga2/interp.cpp b/engines/saga2/interp.cpp index 3f806689648..4fa2e79de24 100644 --- a/engines/saga2/interp.cpp +++ b/engines/saga2/interp.cpp @@ -89,7 +89,7 @@ uint8 *builtinObjectAddress(int16 segment, uint16 index) { return (uint8 *)GameObject::objectAddress(index); case builtinTypeTAG: - return (uint8 *)ActiveItem::activeItemAddress(index); + return (uint8 *)(&ActiveItem::activeItemAddress(index)->_data); case builtinAbstract: assert(index > 0); @@ -138,7 +138,7 @@ uint16 *builtinVTableAddress(int16 btype, uint8 *addr, CallTable **callTab) { case builtinTypeTAG: aItem = (ActiveItem *)addr; - script = aItem->scriptClassID; + script = aItem->_data.scriptClassID; *callTab = &tagCFuncs; if (script <= 0) @@ -486,15 +486,12 @@ void print_script_name(uint8 *codePtr, char *descr = NULL) { char *objectName(int16 segNum, uint16 segOff) { //static nameBuf[64]; - uint8 *objAddr; if (segNum >= 0) return "SagaObject"; - objAddr = builtinObjectAddress(segNum, segOff); - switch (segNum) { case builtinTypeObject: - return ((GameObject *)objAddr)->objName(); + return GameObject::objectAddress(segOff)->objName(); case builtinTypeTAG: return "Tag"; @@ -526,7 +523,7 @@ static void print_stack(int16 *stackBase, int16 *stack) { debugC(2, kDebugScripts, "]"); } -#define D_OP(x) debugC(1, kDebugScripts, "[%04ld 0x%04x]: %s", (pc - codeSeg - 1), (pc - codeSeg - 1), #x) +#define D_OP(x) debugC(1, kDebugScripts, "[%04ld 0x%04lx]: %s", (pc - codeSeg - 1), (pc - codeSeg - 1), #x) bool Thread::interpret(void) { uint8 *pc, @@ -1922,10 +1919,10 @@ scriptResult runTagMethod( ActiveItemPtr aItem; assert(aItem = ActiveItem::activeItemAddress(index)); - if (!aItem->scriptClassID) + if (!aItem->_data.scriptClassID) return scriptResultNoScript; - return runMethod(aItem->scriptClassID, + return runMethod(aItem->_data.scriptClassID, builtinTypeTAG, index, methodNum, diff --git a/engines/saga2/magic.cpp b/engines/saga2/magic.cpp index a4f4d3e75bd..8b414b3c657 100644 --- a/engines/saga2/magic.cpp +++ b/engines/saga2/magic.cpp @@ -318,7 +318,7 @@ bool implementSpell(GameObject *enactor, ActiveItem *target, SkillProto *spell) return implementSpell(enactor, l, spell); } assert(sProto.shouldTarget(spellApplyTAG)); - assert(target->itemType == activeTypeInstance); + assert(target->_data.itemType == activeTypeInstance); ActorManaID ami = (ActorManaID)(sProto.getManaType()); diff --git a/engines/saga2/motion.cpp b/engines/saga2/motion.cpp index be69eefc44a..85f4aa2fe15 100644 --- a/engines/saga2/motion.cpp +++ b/engines/saga2/motion.cpp @@ -1874,14 +1874,14 @@ void MotionTask::castSpell(Actor &a, SkillProto &spell, ActiveItem &target) { if ((mt = mTaskList.newTask(&a)) != NULL) { if (mt->motionType != type) { Location loc; - assert(target.itemType == activeTypeInstance); + assert(target._data.itemType == activeTypeInstance); mt->motionType = type; mt->spellObj = &spell; mt->targetTAG = ⌖ loc = Location( - target.instance.u << kTileUVShift, - target.instance.v << kTileUVShift, - target.instance.h, + target._data.instance.u << kTileUVShift, + target._data.instance.v << kTileUVShift, + target._data.instance.h, a.world()->thisID()); mt->targetLoc = loc; //target; mt->flags = reset | TAGTarg; @@ -3690,7 +3690,7 @@ void MotionTask::castSpellAction(void) { if (actionCounter == 0) { if (spellObj) { if (flags & TAGTarg) { - assert(targetTAG->itemType == activeTypeInstance); + assert(targetTAG->_data.itemType == activeTypeInstance); spellObj->implementAction(spellObj->getSpellID(), a->thisID(), targetTAG->thisID()); } else if (flags & LocTarg) { spellObj->implementAction(spellObj->getSpellID(), a->thisID(), targetLoc); @@ -4428,12 +4428,12 @@ void MotionTask::updatePositions(void) { ActiveItem *TAG = mt->o.TAI->getGroup(); // Compute in points the region of the TAI - TAIReg.min.u = mt->o.TAI->instance.u << kTileUVShift; - TAIReg.min.v = mt->o.TAI->instance.v << kTileUVShift; + TAIReg.min.u = mt->o.TAI->_data.instance.u << kTileUVShift; + TAIReg.min.v = mt->o.TAI->_data.instance.v << kTileUVShift; TAIReg.max.u = TAIReg.min.u - + (TAG->group.uSize << kTileUVShift); + + (TAG->_data.group.uSize << kTileUVShift); TAIReg.max.v = TAIReg.min.v - + (TAG->group.vSize << kTileUVShift); + + (TAG->_data.group.vSize << kTileUVShift); TAIReg.min.z = TAIReg.max.z = 0; // Find the point on the TAI closest to the actor @@ -4488,12 +4488,12 @@ void MotionTask::updatePositions(void) { ActiveItem *TAG = mt->o.TAI->getGroup(); // Compute in points the region of the TAI - TAIReg.min.u = mt->o.TAI->instance.u << kTileUVShift; - TAIReg.min.v = mt->o.TAI->instance.v << kTileUVShift; + TAIReg.min.u = mt->o.TAI->_data.instance.u << kTileUVShift; + TAIReg.min.v = mt->o.TAI->_data.instance.v << kTileUVShift; TAIReg.max.u = TAIReg.min.u - + (TAG->group.uSize << kTileUVShift); + + (TAG->_data.group.uSize << kTileUVShift); TAIReg.max.v = TAIReg.min.v - + (TAG->group.vSize << kTileUVShift); + + (TAG->_data.group.vSize << kTileUVShift); TAIReg.min.z = TAIReg.max.z = 0; // Find the point on the TAI closest to the actor diff --git a/engines/saga2/path.cpp b/engines/saga2/path.cpp index 20aec1ebaf6..5af53ffe5f3 100644 --- a/engines/saga2/path.cpp +++ b/engines/saga2/path.cpp @@ -382,9 +382,9 @@ void PathTileRegion::fetchSubMeta(const TilePoint &subMeta) { tagV = v - ((tr->flags >> 4) & 0x07); subMetaTag.min.u = tagU; - subMetaTag.max.u = tagU + groupItem->group.uSize; + subMetaTag.max.u = tagU + groupItem->_data.group.uSize; subMetaTag.min.v = tagV; - subMetaTag.max.v = tagV + groupItem->group.vSize; + subMetaTag.max.v = tagV + groupItem->_data.group.vSize; if (subMetaTag.min.u < tileReg.min.u) subMetaTag.min.u = tileReg.min.u; @@ -407,11 +407,11 @@ void PathTileRegion::fetchSubMeta(const TilePoint &subMeta) { if (instanceItem) state = instanceItem->getInstanceState(mapNum); stateData = &(map->activeItemData)[ - groupItem->group.grDataOffset - + state * groupItem->group.animArea]; + groupItem->_data.group.grDataOffset + + state * groupItem->_data.group.animArea]; for (tempU = subMetaTag.min.u; tempU < subMetaTag.max.u; tempU++) { - TileRef *rowData = &stateData[(tempU - tagU) * groupItem->group.vSize]; + TileRef *rowData = &stateData[(tempU - tagU) * groupItem->_data.group.vSize]; PathTilePosInfo *tempArrRow = &array[(tempU + offset.u) * area.v]; for (tempV = subMetaTag.min.v; tempV < subMetaTag.max.v; tempV++) { diff --git a/engines/saga2/sagafunc.cpp b/engines/saga2/sagafunc.cpp index 5ac4200fdca..8ab77f1edb7 100644 --- a/engines/saga2/sagafunc.cpp +++ b/engines/saga2/sagafunc.cpp @@ -2390,7 +2390,7 @@ int16 scriptTagNumAssoc(int16 *args) { MONOLOG(TAG::NumAssoc); ActiveItem *ai = (ActiveItem *)thisThread->thisObject; - return ai->numAssociations; + return ai->_data.numAssociations; } //----------------------------------------------------------------------- @@ -2403,11 +2403,11 @@ int16 scriptTagAssoc(int16 *args) { int mapNum = ai->getMapNum(); assert(args[0] >= 0); - assert(args[0] < ai->numAssociations); + assert(args[0] < ai->_data.numAssociations); assert(mapNum >= 0); assert(mapNum < 8); - return (mapList[mapNum].assocList)[ai->associationOffset + args[0]]; + return (mapList[mapNum].assocList)[ai->_data.associationOffset + args[0]]; } //----------------------------------------------------------------------- @@ -2418,7 +2418,7 @@ int16 scriptTagGetTargetU(int16 *args) { MONOLOG(TAG::GetTargetU); ActiveItem *ai = (ActiveItem *)thisThread->thisObject; - return ai->instance.targetU; + return ai->_data.instance.targetU; } //----------------------------------------------------------------------- @@ -2429,7 +2429,7 @@ int16 scriptTagGetTargetV(int16 *) { MONOLOG(TAG::GetTargetV); ActiveItem *ai = (ActiveItem *)thisThread->thisObject; - return ai->instance.targetV; + return ai->_data.instance.targetV; } //----------------------------------------------------------------------- @@ -2440,7 +2440,7 @@ int16 scriptTagGetTargetZ(int16 *) { MONOLOG(TAG::GetTargetZ); ActiveItem *ai = (ActiveItem *)thisThread->thisObject; - return ai->instance.targetZ; + return ai->_data.instance.targetZ; } //----------------------------------------------------------------------- @@ -2451,7 +2451,7 @@ int16 scriptTagGetTargetW(int16 *) { MONOLOG(TAG::GetTargetW); ActiveItem *ai = (ActiveItem *)thisThread->thisObject; - return ai->instance.worldNum; + return ai->_data.instance.worldNum; } //----------------------------------------------------------------------- @@ -2524,7 +2524,7 @@ int16 scriptTagSetAnimation(int16 *args) { #endif // Assert that the state is valid assert(args[1] >= 0); - assert(args[1] < ai->getGroup()->group.numStates); + assert(args[1] < ai->getGroup()->_data.group.numStates); // If soundID is not NULL, then play the sound if (soundID) playSoundAt(soundID, ail); diff --git a/engines/saga2/speldefs.h b/engines/saga2/speldefs.h index 08c64a9cb0f..1e0f0e83989 100644 --- a/engines/saga2/speldefs.h +++ b/engines/saga2/speldefs.h @@ -115,11 +115,11 @@ typedef GameObject SpellCaster; inline TilePoint TAGPos(ActiveItem *ai) { if (ai == NULL) return Nowhere; - assert(ai->itemType == activeTypeInstance); + assert(ai->_data.itemType == activeTypeInstance); return TilePoint( - ai->instance.u << kTileUVShift, - ai->instance.v << kTileUVShift, - ai->instance.h); + ai->_data.instance.u << kTileUVShift, + ai->_data.instance.v << kTileUVShift, + ai->_data.instance.h); } inline TilePoint objPos(GameObject *go) { diff --git a/engines/saga2/tile.cpp b/engines/saga2/tile.cpp index eeab72e020e..f0be3c6b13a 100644 --- a/engines/saga2/tile.cpp +++ b/engines/saga2/tile.cpp @@ -374,9 +374,9 @@ ObjectID ActiveItem::getInstanceContext(void) { // Return the Location for a TAG Location ActiveItem::getInstanceLocation(void) { - return Location(instance.u << kTileUVShift, - instance.v << kTileUVShift, - instance.h << kTileZShift, + return Location(_data.instance.u << kTileUVShift, + _data.instance.v << kTileUVShift, + _data.instance.h << kTileZShift, getInstanceContext()); } @@ -414,7 +414,7 @@ bool ActiveItem::use(ObjectID enactor) { ActiveItem *groupPtr = activeItemAddress( ActiveItemID( getMapNum(), - instance.groupID)); + _data.instance.groupID)); return groupPtr->use(this, enactor); } @@ -427,7 +427,7 @@ bool ActiveItem::trigger(ObjectID enactor, ObjectID objID) { ActiveItem *groupPtr = activeItemAddress( ActiveItemID( getMapNum(), - instance.groupID)); + _data.instance.groupID)); return groupPtr->trigger(this, enactor, objID); } @@ -440,7 +440,7 @@ bool ActiveItem::release(ObjectID enactor, ObjectID objID) { ActiveItem *groupPtr = activeItemAddress( ActiveItemID( getMapNum(), - instance.groupID)); + _data.instance.groupID)); return groupPtr->release(this, enactor, objID); } @@ -453,7 +453,7 @@ bool ActiveItem::acceptLockToggle(ObjectID enactor, uint8 keyCode) { ActiveItem *groupPtr = activeItemAddress( ActiveItemID( getMapNum(), - instance.groupID)); + _data.instance.groupID)); return groupPtr->acceptLockToggle(this, enactor, keyCode); } @@ -466,12 +466,12 @@ bool ActiveItem::inRange(const TilePoint &loc, int16 range) { ActiveItem *groupPtr = activeItemAddress( ActiveItemID( getMapNum(), - instance.groupID)); + _data.instance.groupID)); - return loc.u >= instance.u - range - && loc.v >= instance.v - range - && loc.u < instance.u + groupPtr->group.uSize + range - && loc.v < instance.v + groupPtr->group.vSize + range; + return loc.u >= _data.instance.u - range + && loc.v >= _data.instance.v - range + && loc.u < _data.instance.u + groupPtr->_data.group.uSize + range + && loc.v < _data.instance.v + groupPtr->_data.group.vSize + range; } //----------------------------------------------------------------------- @@ -491,7 +491,7 @@ bool ActiveItem::use(ActiveItem *ins, ObjectID enactor) { uint16 state = ins->getInstanceState(mapNum); scriptCallFrame scf; - if (ins->scriptClassID != 0) { + if (ins->_data.scriptClassID != 0) { // Set up the arguments we want to pass to the script scf.invokedTAI = ins->thisID(); @@ -500,10 +500,10 @@ bool ActiveItem::use(ActiveItem *ins, ObjectID enactor) { scf.indirectObject = Nothing; // Fill in other params with data from TAG struct - scf.value = ins->instance.worldNum; - scf.coords.u = ins->instance.targetU; - scf.coords.v = ins->instance.targetV; - scf.coords.z = ins->instance.targetZ; + scf.value = ins->_data.instance.worldNum; + scf.coords.u = ins->_data.instance.targetU; + scf.coords.v = ins->_data.instance.targetV; + scf.coords.z = ins->_data.instance.targetZ; if (runTagMethod( scf.invokedTAI, @@ -560,7 +560,7 @@ bool ActiveItem::trigger(ActiveItem *ins, ObjectID enactor, ObjectID objID) { && (!isActor(obj) || (Actor *)obj != getCenterActor())) return true; - if (ins->scriptClassID != 0) { + if (ins->_data.scriptClassID != 0) { // Set up the arguments we want to pass to the script scf.invokedTAI = ins->thisID(); @@ -580,12 +580,12 @@ bool ActiveItem::trigger(ActiveItem *ins, ObjectID enactor, ObjectID objID) { // Mark the object as triggering this TAG obj->setTriggeringTAG(true); - instanceRegion.min.u = ins->instance.u << kTileUVShift; - instanceRegion.min.v = ins->instance.v << kTileUVShift; + instanceRegion.min.u = ins->_data.instance.u << kTileUVShift; + instanceRegion.min.v = ins->_data.instance.v << kTileUVShift; instanceRegion.max.u = instanceRegion.min.u - + (group.uSize << kTileUVShift); + + (_data.group.uSize << kTileUVShift); instanceRegion.max.v = instanceRegion.min.v - + (group.vSize << kTileUVShift); + + (_data.group.vSize << kTileUVShift); RegionalObjectIterator iter( world, @@ -604,7 +604,7 @@ bool ActiveItem::trigger(ActiveItem *ins, ObjectID enactor, ObjectID objID) { // if ( proto->mass < group.triggerWeight ) return false; - if (ins->scriptClassID != 0) { + if (ins->_data.scriptClassID != 0) { // Set up the arguments we want to pass to the script scf.invokedTAI = ins->thisID(); @@ -613,10 +613,10 @@ bool ActiveItem::trigger(ActiveItem *ins, ObjectID enactor, ObjectID objID) { scf.indirectObject = objID; // Fill in other params with data from TAG struct - scf.value = ins->instance.worldNum; - scf.coords.u = ins->instance.targetU; - scf.coords.v = ins->instance.targetV; - scf.coords.z = ins->instance.targetZ; + scf.value = ins->_data.instance.worldNum; + scf.coords.u = ins->_data.instance.targetU; + scf.coords.v = ins->_data.instance.targetV; + scf.coords.z = ins->_data.instance.targetZ; if (runTagMethod( scf.invokedTAI, @@ -638,12 +638,12 @@ bool ActiveItem::trigger(ActiveItem *ins, ObjectID enactor, ObjectID objID) { if (isActor(obj) && (a = (Actor *)obj) == getCenterActor()) { transportCenterBand( Location( - (ins->instance.targetU << kTileUVShift) + (ins->_data.instance.targetU << kTileUVShift) + kTileUVSize / 2, - (ins->instance.targetV << kTileUVShift) + (ins->_data.instance.targetV << kTileUVShift) + kTileUVSize / 2, - (int16)ins->instance.targetZ << 3, - ins->instance.worldNum + WorldBaseID)); + (int16)ins->_data.instance.targetZ << 3, + ins->_data.instance.worldNum + WorldBaseID)); } } break; @@ -668,12 +668,12 @@ bool ActiveItem::release(ActiveItem *ins, ObjectID enactor, ObjectID objID) { if (obj->isTriggeringTAG()) obj->setTriggeringTAG(false); - instanceRegion.min.u = ins->instance.u << kTileUVShift; - instanceRegion.min.v = ins->instance.v << kTileUVShift; + instanceRegion.min.u = ins->_data.instance.u << kTileUVShift; + instanceRegion.min.v = ins->_data.instance.v << kTileUVShift; instanceRegion.max.u = instanceRegion.min.u - + (group.uSize << kTileUVShift); + + (_data.group.uSize << kTileUVShift); instanceRegion.max.v = instanceRegion.min.v - + (group.vSize << kTileUVShift); + + (_data.group.vSize << kTileUVShift); RegionalObjectIterator iter( world, @@ -690,7 +690,7 @@ bool ActiveItem::release(ActiveItem *ins, ObjectID enactor, ObjectID objID) { return true; } - if (ins->scriptClassID != 0) { + if (ins->_data.scriptClassID != 0) { // Set up the arguments we want to pass to the script scf.invokedTAI = ins->thisID(); @@ -699,10 +699,10 @@ bool ActiveItem::release(ActiveItem *ins, ObjectID enactor, ObjectID objID) { scf.indirectObject = objID; // Fill in other params with data from TAG struct - scf.value = ins->instance.worldNum; - scf.coords.u = ins->instance.targetU; - scf.coords.v = ins->instance.targetV; - scf.coords.z = ins->instance.targetZ; + scf.value = ins->_data.instance.worldNum; + scf.coords.u = ins->_data.instance.targetU; + scf.coords.v = ins->_data.instance.targetV; + scf.coords.z = ins->_data.instance.targetZ; if (runTagMethod( scf.invokedTAI, @@ -726,7 +726,7 @@ bool ActiveItem::acceptLockToggle(ActiveItem *ins, ObjectID enactor, uint8 keyCo kTileUVShift; scriptCallFrame scf; - if (ins->scriptClassID != 0) { + if (ins->_data.scriptClassID != 0) { // Set up the arguments we want to pass to the script scf.invokedTAI = ins->thisID(); @@ -773,7 +773,7 @@ bool ActiveItem::acceptLockToggle(ActiveItem *ins, ObjectID enactor, uint8 keyCo //----------------------------------------------------------------------- TilePoint getClosestPointOnTAI(ActiveItem *TAI, GameObject *obj) { - assert(TAI->itemType == activeTypeInstance); + assert(TAI->_data.itemType == activeTypeInstance); TilePoint objLoc = obj->getLocation(), TAILoc; @@ -781,18 +781,18 @@ TilePoint getClosestPointOnTAI(ActiveItem *TAI, GameObject *obj) { ActiveItem *TAG = TAI->getGroup(); // Compute in points the region of the TAI - TAIReg.min.u = TAI->instance.u << kTileUVShift; - TAIReg.min.v = TAI->instance.v << kTileUVShift; + TAIReg.min.u = TAI->_data.instance.u << kTileUVShift; + TAIReg.min.v = TAI->_data.instance.v << kTileUVShift; TAIReg.max.u = TAIReg.min.u - + (TAG->group.uSize << kTileUVShift); + + (TAG->_data.group.uSize << kTileUVShift); TAIReg.max.v = TAIReg.min.v - + (TAG->group.vSize << kTileUVShift); + + (TAG->_data.group.vSize << kTileUVShift); TAIReg.min.z = TAIReg.max.z = 0; // Find the point on the TAI closest to the object TAILoc.u = clamp(TAIReg.min.u - 1, objLoc.u, TAIReg.max.u); TAILoc.v = clamp(TAIReg.min.v - 1, objLoc.v, TAIReg.max.v); - TAILoc.z = TAI->instance.h + obj->proto()->height / 2; + TAILoc.z = TAI->_data.instance.h + obj->proto()->height / 2; return TAILoc; } @@ -867,13 +867,13 @@ void saveActiveItemStates(SaveFileConstructor &saveGame) { ActiveItem *activeItem = activeItemList->_items[j]; uint8 *statePtr; - if (activeItem->itemType != activeTypeInstance) + if (activeItem->_data.itemType != activeTypeInstance) continue; // Get a pointer to the current active item's state // data in the archive buffer statePtr = - &bufferedStateArray[activeItem->instance.stateIndex]; + &bufferedStateArray[activeItem->_data.instance.stateIndex]; // Set the high bit of the state value based upon the // active item's locked state @@ -936,13 +936,13 @@ void loadActiveItemStates(SaveFileReader &saveGame) { ActiveItem *activeItem = activeItemList->_items[j]; uint8 *statePtr; - if (activeItem->itemType != activeTypeInstance) + if (activeItem->_data.itemType != activeTypeInstance) continue; // Get a pointer to the current active item's state // data in the archive buffer statePtr = - &bufferedStateArray[activeItem->instance.stateIndex]; + &bufferedStateArray[activeItem->_data.instance.stateIndex]; // Reset the locked state of the active item based // upon the high bit of the buffered state value @@ -1478,22 +1478,23 @@ MetaTileList::~MetaTileList() { ActiveItem::ActiveItem(ActiveItemList *parent, int ind, Common::SeekableReadStream *stream) { _parent = parent; _index = ind; - nextHash = nullptr; + _nextHash = nullptr; stream->readUint32LE(); - scriptClassID = stream->readUint16LE(); - associationOffset = stream->readUint16LE(); - numAssociations = stream->readByte(); - itemType = stream->readByte(); - instance.groupID = stream->readUint16LE(); - instance.u = stream->readSint16LE(); - instance.v = stream->readSint16LE(); - instance.v = stream->readSint16LE(); - instance.stateIndex = stream->readUint16LE(); - instance.scriptFlags = stream->readUint16LE(); - instance.targetU = stream->readUint16LE(); - instance.targetV = stream->readUint16LE(); - instance.targetZ = stream->readByte(); - instance.worldNum = stream->readByte(); + _data.nextHashDummy = 0; + _data.scriptClassID = stream->readUint16LE(); + _data.associationOffset = stream->readUint16LE(); + _data.numAssociations = stream->readByte(); + _data.itemType = stream->readByte(); + _data.instance.groupID = stream->readUint16LE(); + _data.instance.u = stream->readSint16LE(); + _data.instance.v = stream->readSint16LE(); + _data.instance.v = stream->readSint16LE(); + _data.instance.stateIndex = stream->readUint16LE(); + _data.instance.scriptFlags = stream->readUint16LE(); + _data.instance.targetU = stream->readUint16LE(); + _data.instance.targetV = stream->readUint16LE(); + _data.instance.targetZ = stream->readByte(); + _data.instance.worldNum = stream->readByte(); } ActiveItemList::ActiveItemList(WorldMapData *parent, int count, Common::SeekableReadStream *stream) { @@ -1996,9 +1997,9 @@ TileInfo *Platform::fetchTile( // Get the tile to be drawn from the tile group tr = &(mapList[mapNum].activeItemData)[ - groupItem->group.grDataOffset - + state * groupItem->group.animArea - + relPos.u * groupItem->group.vSize + groupItem->_data.group.grDataOffset + + state * groupItem->_data.group.animArea + + relPos.u * groupItem->_data.group.vSize + relPos.v]; h += tr->tileHeight * 8; @@ -2078,9 +2079,9 @@ TileInfo *Platform::fetchTAGInstance( // Get the tile to be drawn from the tile group tr = &(mapList[mapNum].activeItemData)[ - groupItem->group.grDataOffset - + state * groupItem->group.animArea - + relPos.u * groupItem->group.vSize + groupItem->_data.group.grDataOffset + + state * groupItem->_data.group.animArea + + relPos.u * groupItem->_data.group.vSize + relPos.v]; h += tr->tileHeight * 8; @@ -2153,9 +2154,9 @@ TileInfo *Platform::fetchTile( // Get the tile to be drawn from the tile group tr = &(mapList[mapNum].activeItemData)[ - groupItem->group.grDataOffset - + state * groupItem->group.animArea - + relPos.u * groupItem->group.vSize + groupItem->_data.group.grDataOffset + + state * groupItem->_data.group.animArea + + relPos.u * groupItem->_data.group.vSize + relPos.v]; h += tr->tileHeight * 8; @@ -2236,9 +2237,9 @@ TileInfo *Platform::fetchTAGInstance( // Get the tile to be drawn from the tile group tr = &(mapList[mapNum].activeItemData)[ - groupItem->group.grDataOffset - + state * groupItem->group.animArea - + relPos.u * groupItem->group.vSize + groupItem->_data.group.grDataOffset + + state * groupItem->_data.group.animArea + + relPos.u * groupItem->_data.group.vSize + relPos.v]; h += tr->tileHeight * 8; @@ -2475,9 +2476,9 @@ void WorldMapData::buildInstanceHash(void) { for (i = 0, ail = activeItemList->_items; i < activeCount; i++, ail++) { ActiveItem *ai = *ail; - if (ai->itemType == activeTypeInstance) { - hashVal = (((ai->instance.u + ai->instance.h) << 4) - + ai->instance.v + (ai->instance.groupID << 2)) + if (ai->_data.itemType == activeTypeInstance) { + hashVal = (((ai->_data.instance.u + ai->_data.instance.h) << 4) + + ai->_data.instance.v + (ai->_data.instance.groupID << 2)) % elementsof(instHash); itemHash.setVal(hashVal, ai); diff --git a/engines/saga2/tile.h b/engines/saga2/tile.h index f704f7f378f..07482c96d7c 100644 --- a/engines/saga2/tile.h +++ b/engines/saga2/tile.h @@ -339,20 +339,13 @@ extern byte **stateArray; class ActiveItemList; -class ActiveItem { -public: - ActiveItem *nextHash; // next item in hash chain - -// char name[32]; // name of this group -// uint16 flags; // various flags -// TileGroupID itemID; // unique # of this item - - uint16 scriptClassID; // associated script object - uint16 associationOffset; // offset into association table - uint8 numAssociations; // number of associated items - uint8 itemType; // item type code. - int _index; - ActiveItemList *_parent; +#include "common/pack-start.h" +struct ActiveItemData { + uint32 nextHashDummy; // next item in hash chain + uint16 scriptClassID; // associated script object + uint16 associationOffset; // offset into association table + uint8 numAssociations; // number of associated items + uint8 itemType; // item type code. union { struct { @@ -378,6 +371,15 @@ public: worldNum; // Add 0xf000 to get world Object ID } instance; }; +}; + +#include "common/pack-end.h" +class ActiveItem { +public: + ActiveItem *_nextHash; // next item in hash chain + int _index; + ActiveItemList *_parent; + ActiveItemData _data; enum { activeItemLocked = (1 << 8), // The door is locked @@ -401,9 +403,8 @@ public: // Return a pointer to this TAI's group ActiveItem *getGroup(void) { - assert(itemType == activeTypeInstance); - return activeItemAddress( - ActiveItemID(getMapNum(), instance.groupID)); + assert(_data.itemType == activeTypeInstance); + return activeItemAddress(ActiveItemID(getMapNum(), _data.instance.groupID)); } enum BuiltInBehaviorType { @@ -415,38 +416,42 @@ public: // Return the state number of this active item instance uint8 getInstanceState(int16 mapNum) { - return stateArray[mapNum][instance.stateIndex]; + return stateArray[mapNum][_data.instance.stateIndex]; } // Set the state number of this active item instance void setInstanceState(int16 mapNum, uint8 state) { - stateArray[mapNum][instance.stateIndex] = state; + stateArray[mapNum][_data.instance.stateIndex] = state; } uint8 builtInBehavior(void) { - return (uint8)(instance.scriptFlags >> 13); + return (uint8)(_data.instance.scriptFlags >> 13); } // Access to the locked bit bool isLocked(void) { - return (bool)(instance.scriptFlags & activeItemLocked); + return (bool)(_data.instance.scriptFlags & activeItemLocked); } void setLocked(bool val) { - if (val) instance.scriptFlags |= activeItemLocked; - else instance.scriptFlags &= ~activeItemLocked; + if (val) + _data.instance.scriptFlags |= activeItemLocked; + else + _data.instance.scriptFlags &= ~activeItemLocked; } // Access to the exclusion semaphore bool isExclusive(void) { - return (bool)(instance.scriptFlags & activeItemExclusive); + return (bool)(_data.instance.scriptFlags & activeItemExclusive); } void setExclusive(bool val) { - if (val) instance.scriptFlags |= activeItemExclusive; - else instance.scriptFlags &= ~activeItemExclusive; + if (val) + _data.instance.scriptFlags |= activeItemExclusive; + else + _data.instance.scriptFlags &= ~activeItemExclusive; } uint8 lockType(void) { - return (uint8)instance.scriptFlags; + return (uint8)_data.instance.scriptFlags; } // ActiveItem instance methods @@ -464,10 +469,10 @@ public: bool acceptLockToggle(ActiveItem *ins, ObjectID enactor, uint8 keyCode); bool inRange(ActiveItem *ins, const TilePoint &loc, int16 range) { - return loc.u >= ins->instance.u - range - && loc.v >= ins->instance.v - range - && loc.u < ins->instance.u + group.uSize + range - && loc.v < ins->instance.v + group.vSize + range; + return loc.u >= ins->_data.instance.u - range + && loc.v >= ins->_data.instance.v - range + && loc.u < ins->_data.instance.u + _data.group.uSize + range + && loc.v < ins->_data.instance.v + _data.group.vSize + range; } ObjectID getInstanceContext(void);