diff --git a/engines/saga2/actor.cpp b/engines/saga2/actor.cpp index 927ca73b690..d02e1029d4f 100644 --- a/engines/saga2/actor.cpp +++ b/engines/saga2/actor.cpp @@ -1330,7 +1330,7 @@ void *Actor::archive(void *buf) { a->currentRecoveryPoints = currentRecoveryPoints; a->leaderID = leader != NULL ? leader->thisID() : Nothing; a->followersID = followers != NULL ? getBandID(followers) : NoBand; - for (i = 0; i < elementsof(a->armorObjects); i++) + for (i = 0; i < ARRAYSIZE(a->armorObjects); i++) a->armorObjects[i] = armorObjects[i]; a->currentTargetID = currentTarget != NULL ? currentTarget->thisID() : Nothing; for (i = 0; i < actorScriptVars; i++) @@ -3076,7 +3076,7 @@ bool Actor::pathFindState(void) { // Add knowledge package to actor bool Actor::addKnowledge(uint16 kID) { - for (int i = 0; i < elementsof(knowledge); i++) { + for (int i = 0; i < ARRAYSIZE(knowledge); i++) { if (knowledge[i] == 0) { knowledge[i] = kID; return true; @@ -3089,7 +3089,7 @@ bool Actor::addKnowledge(uint16 kID) { // Remove knowledge package from actor bool Actor::removeKnowledge(uint16 kID) { - for (int i = 0; i < elementsof(knowledge); i++) { + for (int i = 0; i < ARRAYSIZE(knowledge); i++) { if (knowledge[i] == kID) { knowledge[i] = 0; return true; @@ -3102,7 +3102,7 @@ bool Actor::removeKnowledge(uint16 kID) { // Remove all knowledge package from actor void Actor::clearKnowledge(void) { - for (int i = 0; i < elementsof(knowledge); i++) { + for (int i = 0; i < ARRAYSIZE(knowledge); i++) { knowledge[i] = 0; } } @@ -3117,7 +3117,7 @@ void Actor::useKnowledge(scriptCallFrame &scf) { // First, search for the class with the best response - for (int i = 0; i < elementsof(knowledge); i++) { + for (int i = 0; i < ARRAYSIZE(knowledge); i++) { if (knowledge[i]) { scriptResult res; diff --git a/engines/saga2/automap.cpp b/engines/saga2/automap.cpp index 1e11dc8a209..c05678da03e 100644 --- a/engines/saga2/automap.cpp +++ b/engines/saga2/automap.cpp @@ -551,7 +551,7 @@ int16 openAutoMap() { scrollBtn = new gCompButton(*pAutoMap, scrollBtnRect, scrollBtnImage, numBtnImages, 0, cmdAutoMapScroll); pAutoMap->setDecorations(autoMapDecorations, - elementsof(autoMapDecorations), + ARRAYSIZE(autoMapDecorations), decRes, 'M', 'A', 'P'); // attach the structure to the book diff --git a/engines/saga2/band.cpp b/engines/saga2/band.cpp index 1ea0aacd8a1..a1c0ee1d8d5 100644 --- a/engines/saga2/band.cpp +++ b/engines/saga2/band.cpp @@ -105,7 +105,7 @@ public: BandList::BandList(void) { int i; - for (i = 0; i < elementsof(array); i++) + for (i = 0; i < ARRAYSIZE(array); i++) free.addTail(array[i]); } @@ -222,7 +222,7 @@ void *BandList::newBand(void) { // Place a specific Band into the active list and return its address void *BandList::newBand(BandID id) { - assert(id >= 0 && id < elementsof(array)); + assert(id >= 0 && id < ARRAYSIZE(array)); BandPlaceHolder *bp; @@ -395,7 +395,7 @@ Band::Band(void **buf) { bufferPtr = (ObjectID *)bufferPtr + 1; // Restore the member count - assert(*((int16 *)bufferPtr) < elementsof(members)); + assert(*((int16 *)bufferPtr) < ARRAYSIZE(members)); memberCount = *((int16 *)bufferPtr); bufferPtr = (int16 *)bufferPtr + 1; diff --git a/engines/saga2/band.h b/engines/saga2/band.h index 14b7f40f1e2..4137b386e8d 100644 --- a/engines/saga2/band.h +++ b/engines/saga2/band.h @@ -98,7 +98,7 @@ public: } bool add(Actor *newMember) { - if (memberCount < elementsof(members)) { + if (memberCount < ARRAYSIZE(members)) { members[memberCount++] = newMember; return true; } else diff --git a/engines/saga2/contain.cpp b/engines/saga2/contain.cpp index c5b918fcdd0..30174c0a1a3 100644 --- a/engines/saga2/contain.cpp +++ b/engines/saga2/contain.cpp @@ -1241,7 +1241,7 @@ TangibleContainerWindow::TangibleContainerWindow( if (deathFlag) { // set the decorations for this window setDecorations(deathDecorations, - elementsof(deathDecorations), + ARRAYSIZE(deathDecorations), containerRes, 'F', 'R', 'M'); massWeightIndicator = NULL; } else { @@ -1258,7 +1258,7 @@ TangibleContainerWindow::TangibleContainerWindow( // set the decorations for this window setDecorations(winDecs[bgndType], - elementsof(brassDecorations), // brass was arb, all should have same + ARRAYSIZE(brassDecorations), // brass was arb, all should have same containerRes, 'F', 'R', 'M'); // set the userdata such that we can extract the container object later @@ -1343,7 +1343,7 @@ IntangibleContainerWindow::IntangibleContainerWindow( // set the decorations for this window setDecorations(mentalDecorations, - elementsof(mentalDecorations), + ARRAYSIZE(mentalDecorations), containerRes, 'F', 'R', 'M'); setMindContainer(nd.mindType, *this); @@ -1928,7 +1928,7 @@ void setMindContainer(int index, IntangibleContainerWindow &cw) { ObjectID id; assert(index >= 0); - assert(index < elementsof(classTable)); + assert(index < ARRAYSIZE(classTable)); int containerClass = classTable[index]; diff --git a/engines/saga2/dispnode.cpp b/engines/saga2/dispnode.cpp index 97ac7f34946..bba75c729ad 100644 --- a/engines/saga2/dispnode.cpp +++ b/engines/saga2/dispnode.cpp @@ -501,7 +501,7 @@ void DisplayNode::drawObject(void) { buildColorTable( mainColors, bubbleColorTable, - elementsof(bubbleColorTable)); + ARRAYSIZE(bubbleColorTable)); if (a->kludgeCount < 0 || ++a->kludgeCount >= bubbleSpriteCount) a->kludgeCount = 0; diff --git a/engines/saga2/document.cpp b/engines/saga2/document.cpp index 018efdda594..db011e695cf 100644 --- a/engines/saga2/document.cpp +++ b/engines/saga2/document.cpp @@ -74,7 +74,7 @@ CDocumentAppearance scrollAppearance( Rect16(0, 0, 0, 0), // (No page 2) Rect16(184, 206, 44, 42), // Close button rect scrollDecorations, - elementsof(scrollDecorations), + ARRAYSIZE(scrollDecorations), MKTAG('S', 'C', 'R', 'L'), MKTAG('S', 'R', 'L', 0) ); @@ -101,7 +101,7 @@ CDocumentAppearance bookAppearance( Rect16(218, 26, 135, 205), // Page 2 Rect16(231, 217, 34, 27), // Close button rect bookDecorations, - elementsof(bookDecorations), + ARRAYSIZE(bookDecorations), MKTAG('B', 'O', 'O', 'K'), MKTAG('B', 'K', 'D', 0) ); @@ -123,7 +123,7 @@ CDocumentAppearance parchAppearance( Rect16(0, 0, 0, 0), // (No page 2) Rect16(164, 229, 20, 20), // Close button rect parchDecorations, - elementsof(parchDecorations), + ARRAYSIZE(parchDecorations), MKTAG('P', 'A', 'R', 'C'), MKTAG('P', 'C', 'H', 0) ); diff --git a/engines/saga2/intrface.cpp b/engines/saga2/intrface.cpp index 597a7b33a40..c7bdcfd9e99 100644 --- a/engines/saga2/intrface.cpp +++ b/engines/saga2/intrface.cpp @@ -594,31 +594,31 @@ void CPortrait::getStateString(char buf[], int8 size, uint16 brotherID) { length += appendToStr( &buf[length], asleepStr, - elementsof(asleepStr) - 1, + ARRAYSIZE(asleepStr) - 1, size - length - 1); } else if (a->enchantmentFlags & (1 << actorParalyzed)) { length += appendToStr( &buf[length], paralysedStr, - elementsof(paralysedStr) - 1, + ARRAYSIZE(paralysedStr) - 1, size - length - 1); } else if (a->enchantmentFlags & (1 << actorBlind)) { length += appendToStr( &buf[length], blindStr, - elementsof(blindStr) - 1, + ARRAYSIZE(blindStr) - 1, size - length - 1); } else if (a->enchantmentFlags & (1 << actorFear)) { length += appendToStr( &buf[length], afraidStr, - elementsof(afraidStr) - 1, + ARRAYSIZE(afraidStr) - 1, size - length - 1); } else if (pa->isAggressive()) { length += appendToStr( &buf[length], angryStr, - elementsof(angryStr) - 1, + ARRAYSIZE(angryStr) - 1, size - length - 1); } @@ -627,24 +627,24 @@ void CPortrait::getStateString(char buf[], int8 size, uint16 brotherID) { length += appendToStr( &buf[length], commaStr, - elementsof(commaStr) - 1, + ARRAYSIZE(commaStr) - 1, size - length - 1); length += appendToStr( &buf[length], badlyWoundedStr, - elementsof(badlyWoundedStr) - 1, + ARRAYSIZE(badlyWoundedStr) - 1, size - length - 1); } else if (stats.vitality * 2 > a->effectiveStats.vitality * 3) { if (length != 0) length += appendToStr( &buf[length], commaStr, - elementsof(commaStr) - 1, + ARRAYSIZE(commaStr) - 1, size - length - 1); length += appendToStr( &buf[length], hurtStr, - elementsof(hurtStr) - 1, + ARRAYSIZE(hurtStr) - 1, size - length - 1); } @@ -653,24 +653,24 @@ void CPortrait::getStateString(char buf[], int8 size, uint16 brotherID) { length += appendToStr( &buf[length], commaStr, - elementsof(commaStr) - 1, + ARRAYSIZE(commaStr) - 1, size - length - 1); length += appendToStr( &buf[length], poisonedStr, - elementsof(poisonedStr) - 1, + ARRAYSIZE(poisonedStr) - 1, size - length - 1); } else if (a->enchantmentFlags & (1 << actorDiseased)) { if (length != 0) length += appendToStr( &buf[length], commaStr, - elementsof(commaStr) - 1, + ARRAYSIZE(commaStr) - 1, size - length - 1); length += appendToStr( &buf[length], diseasedStr, - elementsof(diseasedStr) - 1, + ARRAYSIZE(diseasedStr) - 1, size - length - 1); } @@ -678,7 +678,7 @@ void CPortrait::getStateString(char buf[], int8 size, uint16 brotherID) { length += appendToStr( &buf[length], normalStr, - elementsof(normalStr) - 1, + ARRAYSIZE(normalStr) - 1, size - length - 1); } } @@ -705,7 +705,7 @@ CStatusLine::CStatusLine(gPanelList &list, lineDisplayed = false; queueHead = queueTail = 0; - for (i = 0; i < elementsof(lineQueue); i++) + for (i = 0; i < ARRAYSIZE(lineQueue); i++) lineQueue[i].text = nullptr; } diff --git a/engines/saga2/mission.cpp b/engines/saga2/mission.cpp index 6332b27d1ef..423d85cf80a 100644 --- a/engines/saga2/mission.cpp +++ b/engines/saga2/mission.cpp @@ -42,7 +42,7 @@ ActiveMission *ActiveMission::newMission(ObjectID genID, uint16 script) { int i; ActiveMission *ms = NULL; - for (i = 0; i < elementsof(activeMissions); i++) { + for (i = 0; i < ARRAYSIZE(activeMissions); i++) { if (!(activeMissions[i]._data.missionFlags & inUse)) { ms = &activeMissions[i]; break; @@ -58,7 +58,7 @@ ActiveMission *ActiveMission::newMission(ObjectID genID, uint16 script) { ms->_data.numKnowledgeIDs = ms->_data.numObjectIDs = 0; - memset(ms->_data.missionVars, 0, elementsof(ms->_data.missionVars)); + memset(ms->_data.missionVars, 0, ARRAYSIZE(ms->_data.missionVars)); return ms; } @@ -69,7 +69,7 @@ ActiveMission *ActiveMission::newMission(ObjectID genID, uint16 script) { int ActiveMission::findMission(ObjectID genID) { int i; - for (i = 0; i < elementsof(activeMissions); i++) { + for (i = 0; i < ARRAYSIZE(activeMissions); i++) { if (activeMissions[i]._data.missionFlags & inUse && activeMissions[i]._data.generatorID == genID) { return i; @@ -81,7 +81,7 @@ int ActiveMission::findMission(ObjectID genID) { ActiveMission *ActiveMission::missionAddress(int index) { assert(index >= 0); - assert(index < elementsof(activeMissions)); + assert(index < ARRAYSIZE(activeMissions)); return &activeMissions[index]; } @@ -90,7 +90,7 @@ ActiveMission *ActiveMission::missionAddress(int index) { // Add record of object creation to mission bool ActiveMission::addObjectID(ObjectID objID) { - if (_data.numObjectIDs < elementsof(_data.missionObjectList)) { + if (_data.numObjectIDs < ARRAYSIZE(_data.missionObjectList)) { _data.missionObjectList[_data.numObjectIDs++] = objID; return true; } @@ -124,7 +124,7 @@ bool ActiveMission::removeObjectID(ObjectID objID) { bool ActiveMission::addKnowledgeID(ObjectID actor, uint16 knowledgeID) { if (!isActor(actor)) return false; - if (_data.numKnowledgeIDs < elementsof(_data.missionKnowledgeList)) { + if (_data.numKnowledgeIDs < ARRAYSIZE(_data.missionKnowledgeList)) { Actor *a = (Actor *)GameObject::objectAddress(actor); if (!a->addKnowledge(knowledgeID)) return false; @@ -191,7 +191,7 @@ void ActiveMission::cleanup(void) { void initMissions(void) { int i; - for (i = 0; i < elementsof(activeMissions); i++) + for (i = 0; i < ARRAYSIZE(activeMissions); i++) activeMissions[i]._data.missionFlags &= ~inUse; } diff --git a/engines/saga2/mission.h b/engines/saga2/mission.h index 51ea1fb58a8..a9f2a47bb61 100644 --- a/engines/saga2/mission.h +++ b/engines/saga2/mission.h @@ -86,7 +86,7 @@ public: void cleanup(void); bool spaceForObject(void) { - return _data.numObjectIDs < elementsof(_data.missionObjectList); + return _data.numObjectIDs < ARRAYSIZE(_data.missionObjectList); } // Add record of object creation to mission diff --git a/engines/saga2/motion.cpp b/engines/saga2/motion.cpp index 4bb1dff55c8..b188b20c299 100644 --- a/engines/saga2/motion.cpp +++ b/engines/saga2/motion.cpp @@ -361,7 +361,7 @@ static MotionTaskList &mTaskList = *((MotionTaskList *)mTaskListBuffer); // Initialize the MotionTaskList MotionTaskList::MotionTaskList(void) { - for (int i = 0; i < elementsof(array); i++) { + for (int i = 0; i < ARRAYSIZE(array); i++) { free.addTail(array[i]); } } @@ -375,7 +375,7 @@ MotionTaskList::MotionTaskList(void **buf) { int16 i, motionTaskCount; - for (i = 0; i < elementsof(array); i++) { + for (i = 0; i < ARRAYSIZE(array); i++) { free.addTail(array[i]); } @@ -3283,7 +3283,7 @@ const uint8 twoHandedSwingArray[] = { const CombatMotionSet twoHandedSwingSet = CombatMotionSet( twoHandedSwingArray, - elementsof(twoHandedSwingArray)); + ARRAYSIZE(twoHandedSwingArray)); // Construct a subset of all high two handed swing types const uint8 twoHandedHighSwingArray[] = { @@ -3295,7 +3295,7 @@ const uint8 twoHandedHighSwingArray[] = { const CombatMotionSet twoHandedHighSwingSet = CombatMotionSet( twoHandedHighSwingArray, - elementsof(twoHandedHighSwingArray)); + ARRAYSIZE(twoHandedHighSwingArray)); // Construct a subset of all low two handed swing types const uint8 twoHandedLowSwingArray[] = { @@ -3307,7 +3307,7 @@ const uint8 twoHandedLowSwingArray[] = { const CombatMotionSet twoHandedLowSwingSet = CombatMotionSet( twoHandedLowSwingArray, - elementsof(twoHandedLowSwingArray)); + ARRAYSIZE(twoHandedLowSwingArray)); //----------------------------------------------------------------------- // Handle all two handed swing motions @@ -3402,7 +3402,7 @@ const uint8 oneHandedSwingArray[] = { const CombatMotionSet oneHandedSwingSet = CombatMotionSet( oneHandedSwingArray, - elementsof(oneHandedSwingArray)); + ARRAYSIZE(oneHandedSwingArray)); // Construct a subset of all high one handed swing types const uint8 oneHandedHighSwingArray[] = { @@ -3412,7 +3412,7 @@ const uint8 oneHandedHighSwingArray[] = { const CombatMotionSet oneHandedHighSwingSet = CombatMotionSet( oneHandedHighSwingArray, - elementsof(oneHandedHighSwingArray)); + ARRAYSIZE(oneHandedHighSwingArray)); // Construct a subset of all low one handed swing types const uint8 oneHandedLowSwingArray[] = { @@ -3422,7 +3422,7 @@ const uint8 oneHandedLowSwingArray[] = { const CombatMotionSet oneHandedLowSwingSet = CombatMotionSet( oneHandedLowSwingArray, - elementsof(oneHandedLowSwingArray)); + ARRAYSIZE(oneHandedLowSwingArray)); //----------------------------------------------------------------------- // Handle all one handed swing motions diff --git a/engines/saga2/objects.cpp b/engines/saga2/objects.cpp index a3c74afaf05..d15b0868662 100644 --- a/engines/saga2/objects.cpp +++ b/engines/saga2/objects.cpp @@ -1250,7 +1250,7 @@ void GameObject::deleteObject(void) { if (a->leftHandObject == id) a->leftHandObject = Nothing; if (a->rightHandObject == id) a->rightHandObject = Nothing; - for (i = 0; i < elementsof(a->armorObjects); i++) + for (i = 0; i < ARRAYSIZE(a->armorObjects); i++) if (a->armorObjects[i] == id) a->wear(Nothing, i); } @@ -3246,7 +3246,7 @@ static ActiveRegion activeRegionList[playerActors]; void updateActiveRegions(void) { int16 i; - for (i = 0; i < elementsof(activeRegionList); i++) + for (i = 0; i < ARRAYSIZE(activeRegionList); i++) activeRegionList[i].update(); } @@ -3761,7 +3761,7 @@ bool ActiveRegionObjectIterator::nextActiveRegion(void) { TilePoint currentRegionSize; do { - if (++activeRegionIndex >= elementsof(activeRegionList)) + if (++activeRegionIndex >= ARRAYSIZE(activeRegionList)) return false; int16 prevRegionIndex; @@ -3941,7 +3941,7 @@ ObjectID ActiveRegionObjectIterator::first(GameObject **obj) { ObjectID ActiveRegionObjectIterator::next(GameObject **obj) { assert(activeRegionIndex >= 0); - assert(activeRegionIndex < elementsof(activeRegionList)); + assert(activeRegionIndex < ARRAYSIZE(activeRegionList)); ObjectID currentObjectID; diff --git a/engines/saga2/objproto.cpp b/engines/saga2/objproto.cpp index 2ebec42a415..1674a81aaec 100644 --- a/engines/saga2/objproto.cpp +++ b/engines/saga2/objproto.cpp @@ -786,7 +786,7 @@ bool ProtoObj::acceptInsertionAtAction( // Creates a color translation table for this object void ProtoObj::getColorTranslation(ColorTable map) { - buildColorTable(map, colorMap, elementsof(colorMap)); + buildColorTable(map, colorMap, ARRAYSIZE(colorMap)); } uint16 ProtoObj::containmentSet(void) { @@ -1106,7 +1106,7 @@ bool InventoryProto::dropAction( static const int8 dirOffsetTable[] = { 0, 1, -1, 2, -2, 3, -3 }; - for (i = 0; i < elementsof(dirOffsetTable); i++) { + for (i = 0; i < ARRAYSIZE(dirOffsetTable); i++) { TilePoint testPt; Direction testDir; @@ -2852,7 +2852,7 @@ ContainerWindow *EnchantmentProto::makeWindow( GameObject *Obj ) // set the decorations for this window window->setDecorations( enchantDecorations, - elementsof( enchantDecorations ), + ARRAYSIZE( enchantDecorations ), decRes, 'E', 'F', 'R' ); diff --git a/engines/saga2/path.cpp b/engines/saga2/path.cpp index cdf57758309..7f62f9c9cac 100644 --- a/engines/saga2/path.cpp +++ b/engines/saga2/path.cpp @@ -867,13 +867,13 @@ DirMaskGroup *MaskComputer::computeMask(uint8 crossSection) { } } - if (arraySize < elementsof(array)) { + if (arraySize < ARRAYSIZE(array)) { // Allocate a new place for this mask group maskGroup = ptrArray[arraySize] = &array[arraySize]; arraySize++; } else // Discard last referenced mask group in array - maskGroup = ptrArray[elementsof(array) - 1]; + maskGroup = ptrArray[ARRAYSIZE(array) - 1]; // Compute the new group of masks maskGroup->computeMask(crossSection); @@ -1525,12 +1525,12 @@ void PathRequest::initialize(void) { *tablePtrPtr = node; if (nextAvailableLookupNode - >= elementsof(volumeLookupNodePool)) + >= ARRAYSIZE(volumeLookupNodePool)) goto big_break; } } - if (++objectVolumes >= elementsof(objectVolumeArray)) break; + if (++objectVolumes >= ARRAYSIZE(objectVolumeArray)) break; } big_break: @@ -1607,7 +1607,7 @@ void PathRequest::finish(void) { assert(cell != nullptr); if (cell->direction != dirInvalid) { - res = &tempResult[elementsof(tempResult)]; + res = &tempResult[ARRAYSIZE(tempResult)]; prevDir = dirInvalid; @@ -1648,8 +1648,8 @@ void PathRequest::finish(void) { } if (resultSteps) { - while (stepCount < elementsof(path) - && res < &tempResult[elementsof(tempResult)]) { + while (stepCount < ARRAYSIZE(path) + && res < &tempResult[ARRAYSIZE(tempResult)]) { *resultSteps++ = *res++; stepCount++; } diff --git a/engines/saga2/player.cpp b/engines/saga2/player.cpp index b8955928989..19136940f55 100644 --- a/engines/saga2/player.cpp +++ b/engines/saga2/player.cpp @@ -510,7 +510,7 @@ void PlayerActor::handleAttacked(void) { // Return a pointer to a PlayerActor given it's ID PlayerActor *getPlayerActorAddress(PlayerActorID id) { - assert(id >= 0 && id < elementsof(playerList)); + assert(id >= 0 && id < ARRAYSIZE(playerList)); return &playerList[id]; } diff --git a/engines/saga2/sagafunc.cpp b/engines/saga2/sagafunc.cpp index 47d49f8be68..ae1121fc8af 100644 --- a/engines/saga2/sagafunc.cpp +++ b/engines/saga2/sagafunc.cpp @@ -2342,7 +2342,7 @@ C_Call *actorCFuncList[] = { scriptActorImNotQuiteDead, }; -CallTable actorCFuncs = { actorCFuncList, elementsof(actorCFuncList), 0 }; +CallTable actorCFuncs = { actorCFuncList, ARRAYSIZE(actorCFuncList), 0 }; //----------------------------------------------------------------------- // Return the id of this TAI @@ -2615,7 +2615,7 @@ C_Call *tagCFuncList[] = { scriptTagReleaseLock, }; -CallTable tagCFuncs = { tagCFuncList, elementsof(tagCFuncList), 0 }; +CallTable tagCFuncs = { tagCFuncList, ARRAYSIZE(tagCFuncList), 0 }; //----------------------------------------------------------------------- // Find a mission by generator id @@ -2696,7 +2696,7 @@ C_Call *missionCFuncList[] = { scriptMissionMakeActor, }; -CallTable missionCFuncs = { missionCFuncList, elementsof(missionCFuncList), 0 }; +CallTable missionCFuncs = { missionCFuncList, ARRAYSIZE(missionCFuncList), 0 }; //----------------------------------------------------------------------- // Global functions @@ -4014,6 +4014,6 @@ C_Call *globalCFuncList[] = { scriptBigMul, }; -CallTable globalCFuncs = { globalCFuncList, elementsof(globalCFuncList), 0 }; +CallTable globalCFuncs = { globalCFuncList, ARRAYSIZE(globalCFuncList), 0 }; } // end of namespace Saga2 diff --git a/engines/saga2/sensor.cpp b/engines/saga2/sensor.cpp index 4a91c56c095..6189b23b845 100644 --- a/engines/saga2/sensor.cpp +++ b/engines/saga2/sensor.cpp @@ -482,7 +482,7 @@ bool ProtaganistSensor::check(SenseInfo &info, uint32 senseFlags) { int16 i; bool objIsActor = isActor(getObject()); - for (i = 0; i < (long)elementsof(playerActorIDs); i++) { + for (i = 0; i < (long)ARRAYSIZE(playerActorIDs); i++) { Actor *protag = getPlayerActorAddress(playerActorIDs[i])->getActor(); diff --git a/engines/saga2/speech.cpp b/engines/saga2/speech.cpp index ffb13633f00..0e3a45b9caa 100644 --- a/engines/saga2/speech.cpp +++ b/engines/saga2/speech.cpp @@ -680,18 +680,18 @@ void abortAllSpeeches(void) { void sentenceGenerator(char *sentence) { int16 index; - index = rand() % elementsof(names); + index = rand() % ARRAYSIZE(names); strcat(sentence, names[index]); - index = rand() % elementsof(verbs); + index = rand() % ARRAYSIZE(verbs); strcat(sentence, verbs[index]); - index = rand() % elementsof(adjectives); + index = rand() % ARRAYSIZE(adjectives); strcat(sentence, adjectives[index]); - index = rand() % elementsof(nouns); + index = rand() % ARRAYSIZE(nouns); strcat(sentence, nouns[index]); -// for(int i=0; ispriteBanks); bank++) { + for (bank = 0; bank < (long)ARRAYSIZE(aa->spriteBanks); bank++) { if (aa->spriteBanks[bank]) delete aa->spriteBanks[bank]; aa->spriteBanks[bank] = nullptr; @@ -845,7 +845,7 @@ void initSprites(void) { initQuickMem(0x10000); // Initialize actor appearance table - for (i = 0; i < elementsof(appearanceTable); i++) { + for (i = 0; i < ARRAYSIZE(appearanceTable); i++) { ActorAppearance *aa = &appearanceTable[i]; aa->useCount = 0; diff --git a/engines/saga2/std.h b/engines/saga2/std.h index 5b3d763cd33..510f67b6c6b 100644 --- a/engines/saga2/std.h +++ b/engines/saga2/std.h @@ -38,13 +38,8 @@ typedef uint32 ChunkID; #define FTA -// #define LEAVE goto exitit // bail out of function #define unless(x) if((x)==NULL) // an inverted if statement -#ifndef elementsof -#define elementsof(x) (sizeof(x)/sizeof(x[0])) -#endif - #ifndef offsetof #define offsetof(type,field) (uint32)&(((type *)0)->field) #endif diff --git a/engines/saga2/task.cpp b/engines/saga2/task.cpp index 5d82588190d..684085cc30a 100644 --- a/engines/saga2/task.cpp +++ b/engines/saga2/task.cpp @@ -2170,11 +2170,11 @@ TilePoint GoAwayFromActorTask::getRepulsionVector(void) { repulsionVector; int16 i; TilePoint locArray[6]; - int16 strengthArray[elementsof(locArray)] = + int16 strengthArray[ARRAYSIZE(locArray)] = { 1, 1, 1, 1, 1, 1 }; - int16 distArray[elementsof(locArray)]; + int16 distArray[ARRAYSIZE(locArray)]; TargetLocationArray tla( - elementsof(locArray), + ARRAYSIZE(locArray), locArray, distArray); @@ -2728,9 +2728,9 @@ void HuntToBeNearObjectTask::evaluateTarget(void) { Actor *a = stack->getActor(); int16 i; GameObject *objArray[16]; - int16 distArray[elementsof(objArray)]; + int16 distArray[ARRAYSIZE(objArray)]; TargetObjectArray toa( - elementsof(objArray), + ARRAYSIZE(objArray), objArray, distArray); SenseInfo info; @@ -2867,9 +2867,9 @@ void HuntToPossessTask::evaluateTarget(void) { Actor *a = stack->getActor(); int16 i; GameObject *objArray[16]; - int16 distArray[elementsof(objArray)]; + int16 distArray[ARRAYSIZE(objArray)]; TargetObjectArray toa( - elementsof(objArray), + ARRAYSIZE(objArray), objArray, distArray); SenseInfo info; @@ -3166,9 +3166,9 @@ void HuntToBeNearActorTask::evaluateTarget(void) { Actor *a = stack->getActor(); int16 i; Actor *actorArray[16]; - int16 distArray[elementsof(actorArray)]; + int16 distArray[ARRAYSIZE(actorArray)]; TargetActorArray taa( - elementsof(actorArray), + ARRAYSIZE(actorArray), actorArray, distArray); SenseInfo info; @@ -3411,9 +3411,9 @@ void HuntToKillTask::evaluateTarget(void) { ActorProto *proto = (ActorProto *)a->proto(); int16 i; Actor *actorArray[16]; - int16 distArray[elementsof(actorArray)]; + int16 distArray[ARRAYSIZE(actorArray)]; TargetActorArray taa( - elementsof(actorArray), + ARRAYSIZE(actorArray), actorArray, distArray); SenseInfo info; @@ -3921,8 +3921,8 @@ void BandTask::evaluateTarget(void) { TilePoint repulsorVector; int16 repulsorStrength; TilePoint repulsorVectorArray[6]; - int16 repulsorStrengthArray[elementsof(repulsorVectorArray)]; - int16 repulsorDistArray[elementsof(repulsorVectorArray)]; + int16 repulsorStrengthArray[ARRAYSIZE(repulsorVectorArray)]; + int16 repulsorDistArray[ARRAYSIZE(repulsorVectorArray)]; int16 repulsorCount; bool repulsorFlag; @@ -3950,7 +3950,7 @@ void BandTask::evaluateTarget(void) { int16 j = repulsorCount; if (repulsorDist < repulsorDistArray[j - 1]) { - if (repulsorCount < (long)elementsof(repulsorVectorArray)) { + if (repulsorCount < (long)ARRAYSIZE(repulsorVectorArray)) { repulsorDistArray[j] = repulsorDistArray[j - 1]; repulsorVectorArray[j] = repulsorVectorArray[j - 1]; repulsorStrengthArray[j] = repulsorStrengthArray[j - 1]; @@ -3965,8 +3965,8 @@ void BandTask::evaluateTarget(void) { j--; } - if (j < (long)elementsof(repulsorVectorArray)) { - if (repulsorCount < (long)elementsof(repulsorVectorArray)) + if (j < (long)ARRAYSIZE(repulsorVectorArray)) { + if (repulsorCount < (long)ARRAYSIZE(repulsorVectorArray)) repulsorCount++; repulsorDistArray[j] = repulsorDist; repulsorVectorArray[j] = repulsorVector; @@ -4099,8 +4099,8 @@ bool BandTask::BandAndAvoidEnemiesRepulsorIterator::firstEnemyRepulsor( int16 &repulsorStrength) { assert(iteratingThruEnemies); - int16 actorDistArray[elementsof(actorArray)]; - TargetActorArray taa(elementsof(actorArray), actorArray, actorDistArray); + int16 actorDistArray[ARRAYSIZE(actorArray)]; + TargetActorArray taa(ARRAYSIZE(actorArray), actorArray, actorDistArray); ActorPropertyTarget target(actorPropIDEnemy); numActors = target.actor(a->world(), a->getLocation(), taa); diff --git a/engines/saga2/tile.cpp b/engines/saga2/tile.cpp index 6eadd5b4348..d889a460d8a 100644 --- a/engines/saga2/tile.cpp +++ b/engines/saga2/tile.cpp @@ -984,7 +984,7 @@ static TileActivityTaskList &aTaskList = // Constructor TileActivityTaskList::TileActivityTaskList(void) { - for (uint i = 0; i < elementsof(array); i++) { + for (uint i = 0; i < ARRAYSIZE(array); i++) { free.addTail(array[i]); } } @@ -997,7 +997,7 @@ TileActivityTaskList::TileActivityTaskList(void **buf) { int16 taskCount; - for (uint i = 0; i < elementsof(array); i++) { + for (uint i = 0; i < ARRAYSIZE(array); i++) { free.addTail(array[i]); } @@ -2481,7 +2481,7 @@ void WorldMapData::buildInstanceHash(void) { 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); + % ARRAYSIZE(instHash); itemHash.setVal(hashVal, ai); } @@ -2496,7 +2496,7 @@ ActiveItem *WorldMapData::findHashedInstance( TilePoint &tp, int16 group) { int16 hashVal = (((tp.u + tp.z) << 4) + tp.v + (group << 2)) - % elementsof(instHash); + % ARRAYSIZE(instHash); if (itemHash.contains(hashVal)) return itemHash.getVal(hashVal); @@ -2865,7 +2865,7 @@ void buildRipTables(void) { int16 tableIndex; // bit array of available rip tables - uint8 tableAvail[(elementsof(ripTableList) + 7) >> 3]; + uint8 tableAvail[(ARRAYSIZE(ripTableList) + 7) >> 3]; memset(tableAvail, 0xFF, sizeof(tableAvail)); @@ -2899,7 +2899,7 @@ void buildRipTables(void) { uint j; // Find available table - for (j = 0; j < elementsof(ripTableList); j++) { + for (j = 0; j < ARRAYSIZE(ripTableList); j++) { if (tableAvail[j >> 3] & (1 << (j & 0x7))) break; } diff --git a/engines/saga2/tilemode.cpp b/engines/saga2/tilemode.cpp index ddb3e076611..b73a235c499 100644 --- a/engines/saga2/tilemode.cpp +++ b/engines/saga2/tilemode.cpp @@ -668,7 +668,7 @@ void loadTileModeState(SaveFileReader &saveGame) { void TileModeSetup(void) { // Load in decorative panels for the main window (for this mode) - mainWindow->setDecorations(mainWindowDecorations, elementsof(mainWindowDecorations), imageRes); + mainWindow->setDecorations(mainWindowDecorations, ARRAYSIZE(mainWindowDecorations), imageRes); // Test to draw borders. // REM: We should actually have a routine to refresh the window... diff --git a/engines/saga2/uidialog.cpp b/engines/saga2/uidialog.cpp index d6ab0f3fcba..b57d8aab64d 100644 --- a/engines/saga2/uidialog.cpp +++ b/engines/saga2/uidialog.cpp @@ -737,7 +737,7 @@ int16 FileDialog(int16 fileProcess) { win->setDecorations(saveWindowDecorations, - elementsof(saveWindowDecorations), + ARRAYSIZE(saveWindowDecorations), decRes, 'S', 'L', 'D'); win->userData = &rInfo; @@ -922,7 +922,7 @@ int16 OptionsDialog(bool disableSaveResume) { } win->setDecorations(optionsDecorations, - elementsof(optionsDecorations), + ARRAYSIZE(optionsDecorations), decRes, 'O', 'P', 'T'); @@ -1035,7 +1035,7 @@ bool initUserDialog(void) { udWin = new ModalWindow(messageWindowRect, 0 nullptr); udWin->setDecorations(messageDecorations, - elementsof(messageDecorations), + ARRAYSIZE(messageDecorations), udDecRes, 'M', 'E', 'S'); udWin->userData = &udrInfo; @@ -1237,7 +1237,7 @@ int16 userDialog(const char *title, const char *msg, const char *bMsg1, new CPlacardPanel(*win, messageTextRects[1], msg, &Onyx10Font, 0, pal, 0, nullptr); win->setDecorations(messageDecorations, - elementsof(messageDecorations), + ARRAYSIZE(messageDecorations), decRes, 'M', 'E', 'S'); @@ -1539,7 +1539,7 @@ void placardWindow(int8 type, char *text) { // setup the background imagery win->setDecorations(plaqDecWood, - elementsof(plaqDecWood), + ARRAYSIZE(plaqDecWood), resContext, 'P', 'L', 'Q'); break; @@ -1554,7 +1554,7 @@ void placardWindow(int8 type, char *text) { // setup the background imagery win->setDecorations(plaqDecStone, - elementsof(plaqDecStone), + ARRAYSIZE(plaqDecStone), resContext, 'P', 'L', 'Q'); break; @@ -1569,7 +1569,7 @@ void placardWindow(int8 type, char *text) { // setup the background imagery win->setDecorations(plaqDecBrass, - elementsof(plaqDecBrass), + ARRAYSIZE(plaqDecBrass), resContext, 'P', 'L', 'Q'); break; diff --git a/engines/saga2/videobox.cpp b/engines/saga2/videobox.cpp index 168d4272b2c..e82253dec18 100644 --- a/engines/saga2/videobox.cpp +++ b/engines/saga2/videobox.cpp @@ -137,7 +137,7 @@ void CVideoBox::init(void) { // get the decorations for this window setDecorations(vidDec, - elementsof(vidDec), + ARRAYSIZE(vidDec), decRes, 'V', 'B', 'D'); diff --git a/engines/saga2/vpal.cpp b/engines/saga2/vpal.cpp index 35d2b35daab..e3c69886bec 100644 --- a/engines/saga2/vpal.cpp +++ b/engines/saga2/vpal.cpp @@ -247,7 +247,7 @@ void createPalette( int i; uint32 fadeProgress = (elapsedTime << 8) / totalTime_; - for (i = 0; i < (long)elementsof(newP->entry); i++) { + for (i = 0; i < (long)ARRAYSIZE(newP->entry); i++) { gPaletteEntry *srcPal = &srcP->entry[i]; gPaletteEntry *dstPal = &dstP->entry[i]; gPaletteEntry *curPal = &newP->entry[i];