aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStrangerke2014-06-01 01:21:32 +0200
committerStrangerke2014-06-01 01:21:32 +0200
commit1dbcd7498804f4b59280e3599e2d1c7f864a5228 (patch)
tree0ace66f0cc1b65026e4ae0c9b9779168293ecaf4
parent7d24e1471c445fbf49b3efbb8d046eb26db849cd (diff)
downloadscummvm-rg350-1dbcd7498804f4b59280e3599e2d1c7f864a5228.tar.gz
scummvm-rg350-1dbcd7498804f4b59280e3599e2d1c7f864a5228.tar.bz2
scummvm-rg350-1dbcd7498804f4b59280e3599e2d1c7f864a5228.zip
CRUISE: Reduce the scope of variables used in the for loops
-rw-r--r--engines/cruise/actor.cpp10
-rw-r--r--engines/cruise/background.cpp4
-rw-r--r--engines/cruise/cruise_main.cpp30
-rw-r--r--engines/cruise/ctp.cpp5
-rw-r--r--engines/cruise/dataLoader.cpp14
-rw-r--r--engines/cruise/decompiler.cpp39
-rw-r--r--engines/cruise/font.cpp10
-rw-r--r--engines/cruise/function.cpp4
-rw-r--r--engines/cruise/gfxModule.cpp3
-rw-r--r--engines/cruise/linker.cpp14
-rw-r--r--engines/cruise/mainDraw.cpp9
-rw-r--r--engines/cruise/overlay.cpp114
-rw-r--r--engines/cruise/polys.cpp5
-rw-r--r--engines/cruise/saveload.cpp8
-rw-r--r--engines/cruise/script.cpp4
-rw-r--r--engines/cruise/sound.cpp9
-rw-r--r--engines/cruise/volume.cpp46
17 files changed, 107 insertions, 221 deletions
diff --git a/engines/cruise/actor.cpp b/engines/cruise/actor.cpp
index ab3b581825..0a7bbfe86a 100644
--- a/engines/cruise/actor.cpp
+++ b/engines/cruise/actor.cpp
@@ -426,16 +426,13 @@ void explore(int depart, int arrivee) {
}
void chemin0(int depart, int arrivee) {
- int i;
- //int y=30;
-
prem = 0;
prem2 = 0;
dist_chemin = 0;
idsol = 0;
solmax = 999;
- for (i = 0; i < 20 + 1; i++)
+ for (int i = 0; i < 20 + 1; i++)
fl[i] = -1;
X = 0, Y = 30;
@@ -582,10 +579,9 @@ int16 computePathfinding(MovementEntry &moveInfo, int16 x, int16 y, int16 destX,
}
if (!flagCt) {
- int i;
int16 *ptr;
-
- for (i = 0; i < NUM_PERSONS; i++) { // 10 = num perso
+ int i = 0;
+ for (; i < NUM_PERSONS; i++) { // 10 = num perso
if (!persoTable[i]) {
break;
}
diff --git a/engines/cruise/background.cpp b/engines/cruise/background.cpp
index a59db8ef95..921c621eba 100644
--- a/engines/cruise/background.cpp
+++ b/engines/cruise/background.cpp
@@ -65,12 +65,10 @@ int loadCVT(uint8 **ptr) {
char *localPtr = (char *) * ptr;
if (!strcmp(localPtr, "CVT")) {
- int i;
localPtr += 4;
- for (i = 0; i < 0x20; i++) {
+ for (int i = 0; i < 0x20; i++)
cvtPalette[i] = *(localPtr++);
- }
*ptr = (uint8 *) localPtr;
diff --git a/engines/cruise/cruise_main.cpp b/engines/cruise/cruise_main.cpp
index 35cfc13bdb..b3f9308d17 100644
--- a/engines/cruise/cruise_main.cpp
+++ b/engines/cruise/cruise_main.cpp
@@ -110,7 +110,6 @@ void loadPackedFileToMem(int fileIdx, uint8 *buffer) {
int getNumObjectsByClass(int scriptIdx, int param) {
objDataStruct *ptr2;
int counter;
- int i;
if (!overlayTable[scriptIdx].ovlData)
return (0);
@@ -125,7 +124,7 @@ int getNumObjectsByClass(int scriptIdx, int param) {
counter = 0;
- for (i = 0; i < overlayTable[scriptIdx].ovlData->numObj; i++) {
+ for (int i = 0; i < overlayTable[scriptIdx].ovlData->numObj; i++) {
if (ptr2[i]._class == param) {
counter++;
}
@@ -135,15 +134,12 @@ int getNumObjectsByClass(int scriptIdx, int param) {
}
void resetFileEntryRange(int start, int count) {
- int i;
-
- for (i = 0; i < count; ++i)
+ for (int i = 0; i < count; ++i)
resetFileEntry(start + i);
}
int getProcParam(int overlayIdx, int param2, const char *name) {
int numSymbGlob;
- int i;
exportEntryStruct *arraySymbGlob;
char *exportNamePtr;
char exportName[80];
@@ -161,7 +157,7 @@ int getProcParam(int overlayIdx, int param2, const char *name) {
if (!exportNamePtr)
return 0;
- for (i = 0; i < numSymbGlob; i++) {
+ for (int i = 0; i < numSymbGlob; i++) {
if (arraySymbGlob[i].var4 == param2) {
Common::strlcpy(exportName, arraySymbGlob[i].offsetToName + exportNamePtr, sizeof(exportName));
@@ -188,9 +184,7 @@ void changeScriptParamInList(int param1, int param2, scriptInstanceStruct *pScri
}
void initBigVar3() {
- int i;
-
- for (i = 0; i < NUM_FILE_ENTRIES; i++) {
+ for (int i = 0; i < NUM_FILE_ENTRIES; i++) {
if (filesDatabase[i].subData.ptr) {
MemFree(filesDatabase[i].subData.ptr);
}
@@ -338,13 +332,12 @@ void removeExtention(const char *name, char *buffer) { // not like in original
int lastFileSize;
int loadFileSub1(uint8 **ptr, const char *name, uint8 *ptr2) {
- int i;
char buffer[256];
int fileIdx;
int unpackedSize;
uint8 *unpackedBuffer;
- for (i = 0; i < 64; i++) {
+ for (int i = 0; i < 64; i++) {
if (preloadData[i].ptr) {
if (!strcmp(preloadData[i].name, name)) {
error("Unsupported code in loadFIleSub1");
@@ -440,8 +433,6 @@ uint8 *mainProc14(uint16 overlay, uint16 idx) {
}
void CruiseEngine::initAllData() {
- int i;
-
setupFuncArray();
initOverlayTable();
@@ -457,15 +448,13 @@ void CruiseEngine::initAllData() {
menuTable[0] = NULL;
- for (i = 0; i < 2000; i++) {
+ for (int i = 0; i < 2000; i++)
globalVars[i] = 0;
- }
- for (i = 0; i < 8; i++) {
+ for (int i = 0; i < 8; i++)
backgroundTable[i].name[0] = 0;
- }
- for (i = 0; i < NUM_FILE_ENTRIES; i++) {
+ for (int i = 0; i < NUM_FILE_ENTRIES; i++) {
filesDatabase[i].subData.ptr = NULL;
filesDatabase[i].subData.ptrMask = NULL;
}
@@ -963,12 +952,11 @@ bool findRelation(int objOvl, int objIdx, int x, int y) {
bool found = false;
bool first = true;
int testState = -1;
- int j;
int16 objectState;
getSingleObjectParam(objOvl, objIdx, 5, &objectState);
- for (j = 1; j < numOfLoadedOverlay; j++) {
+ for (int j = 1; j < numOfLoadedOverlay; j++) {
if (overlayTable[j].alreadyLoaded) {
int idHeader = overlayTable[j].ovlData->numMsgRelHeader;
diff --git a/engines/cruise/ctp.cpp b/engines/cruise/ctp.cpp
index b5151f3f7a..074132d9a2 100644
--- a/engines/cruise/ctp.cpp
+++ b/engines/cruise/ctp.cpp
@@ -95,7 +95,6 @@ void getWalkBoxCenter(int n, int16 table[][40]) {
// ax dx bx
void renderCTPWalkBox(int16 *walkboxData, int hotPointX, int hotPointY, int X, int Y, int scale) {
int numPoints;
- int i;
int16 *destination;
int startX = X - ((upscaleValue(hotPointX, scale) + 0x8000) >> 16);
@@ -105,7 +104,7 @@ void renderCTPWalkBox(int16 *walkboxData, int hotPointX, int hotPointY, int X, i
destination = polyBuffer2;
- for (i = 0; i < numPoints; i++) {
+ for (int i = 0; i < numPoints; i++) {
int pointX = *(walkboxData++);
int pointY = *(walkboxData++);
@@ -119,7 +118,7 @@ void renderCTPWalkBox(int16 *walkboxData, int hotPointX, int hotPointY, int X, i
m_color = 0;
ctpVarUnk = 0;
- for (i = 0; i < numPoints; i++) {
+ for (int i = 0; i < numPoints; i++) {
walkboxTable[i] = i;
}
diff --git a/engines/cruise/dataLoader.cpp b/engines/cruise/dataLoader.cpp
index 55ed2c4e68..8532d3074e 100644
--- a/engines/cruise/dataLoader.cpp
+++ b/engines/cruise/dataLoader.cpp
@@ -170,11 +170,11 @@ int createResFileEntry(int width, int height, int size, int resType) {
return 0; // for compilers that don't support NORETURN
#if 0
- int i;
int entryNumber;
int div = 0;
- for (i = 0; i < NUM_FILE_ENTRIES; i++) {
+ int i = 0;
+ for (; i < NUM_FILE_ENTRIES; i++) {
if (!filesDatabase[i].subData.ptr)
break;
}
@@ -280,10 +280,9 @@ int loadFileRange(const char *name, int startIdx, int currentEntryIdx, int numId
switch (fileType) {
case type_SET: {
- int i;
int numMaxEntriesInSet = getNumMaxEntiresInSet(ptr);
- for (i = 0; i < numIdx; i++) {
+ for (int i = 0; i < numIdx; i++) {
if ((startIdx + i) > numMaxEntriesInSet) {
MemFree(ptr);
return 0; // exit if limit is reached
@@ -325,12 +324,9 @@ int loadFullBundle(const char *name, int startIdx) {
switch (fileType) {
case type_SET: {
// Sprite set
- int i;
- int numMaxEntriesInSet;
+ int numMaxEntriesInSet = getNumMaxEntiresInSet(ptr); // get maximum number of sprites/animations in SET file
- numMaxEntriesInSet = getNumMaxEntiresInSet(ptr); // get maximum number of sprites/animations in SET file
-
- for (i = 0; i < numMaxEntriesInSet; i++) {
+ for (int i = 0; i < numMaxEntriesInSet; i++) {
loadSetEntry(name, ptr, i, startIdx + i);
}
diff --git a/engines/cruise/decompiler.cpp b/engines/cruise/decompiler.cpp
index 0c83bd6968..043946ae1a 100644
--- a/engines/cruise/decompiler.cpp
+++ b/engines/cruise/decompiler.cpp
@@ -130,13 +130,12 @@ void pushDecomp(char *string, ...) {
void resolveDecompShort(char *buffer) {
ovlData3Struct *data3Ptr = currentScript;
- int i;
importScriptStruct *importEntry =
(importScriptStruct *)(data3Ptr->dataPtr +
data3Ptr->offsetToImportData);
- for (i = 0; i < data3Ptr->numRelocGlob; i++) {
+ for (int i = 0; i < data3Ptr->numRelocGlob; i++) {
switch (importEntry->type) {
case 20: // script
case 30:
@@ -177,13 +176,12 @@ void resolveDecompShort(char *buffer) {
void resolveDecompChar(char *buffer) {
ovlData3Struct *data3Ptr = currentScript;
- int i;
importScriptStruct *importEntry =
(importScriptStruct *)(data3Ptr->dataPtr +
data3Ptr->offsetToImportData);
- for (i = 0; i < data3Ptr->numRelocGlob; i++) {
+ for (int i = 0; i < data3Ptr->numRelocGlob; i++) {
switch (importEntry->type) {
default: {
if (importEntry->offset ==
@@ -315,9 +313,7 @@ void resolveVarName(char *ovlIdxString, int varType, char *varIdxString,
}
if (!strcmp(ovlIdxString, "0")) {
- int i;
-
- for (i = 0; i < currentDecompOvl->numSymbGlob; i++) {
+ for (int i = 0; i < currentDecompOvl->numSymbGlob; i++) {
if (varIdx == currentDecompOvl->arraySymbGlob[i].idx) {
if (((currentDecompOvl->arraySymbGlob[i].var4 & 0xF0) == 0) && varType != 0x20) { // var
strcpy(outputName,
@@ -733,7 +729,6 @@ int decompFunction() {
unsigned long int numArg = atoi(popDecomp());
char *ovlStr;
char *idxStr;
- int i;
char functionName[100];
idxStr = popDecomp();
@@ -743,7 +738,7 @@ int decompFunction() {
sprintf(tempbuffer, "_startASync(%s", functionName);
- for (i = 0; i < numArg; i++) {
+ for (int i = 0; i < numArg; i++) {
strcatuint8(tempbuffer, ",");
strcatuint8(tempbuffer, popDecomp());
}
@@ -1094,7 +1089,6 @@ int decompFunction() {
unsigned long int numArg = atoi(popDecomp());
char *ovlStr;
char *idxStr;
- int i;
char functionName[256];
idxStr = popDecomp();
@@ -1104,7 +1098,7 @@ int decompFunction() {
sprintf(tempbuffer, "%s(", functionName);
- for (i = 0; i < numArg; i++) {
+ for (int i = 0; i < numArg; i++) {
if (i)
strcatuint8(tempbuffer, ",");
strcatuint8(tempbuffer, popDecomp());
@@ -1174,14 +1168,13 @@ int decompFunction() {
unsigned long int numArg = atoi(popDecomp());
char *ovlStr;
char *idxStr;
- int i;
idxStr = popDecomp();
ovlStr = popDecomp();
sprintf(tempbuffer, "_op_6F(%s,%s", idxStr, ovlStr);
- for (i = 0; i < numArg; i++) {
+ for (int i = 0; i < numArg; i++) {
strcatuint8(tempbuffer, ",");
strcatuint8(tempbuffer, popDecomp());
}
@@ -1286,9 +1279,7 @@ int decompBreak() {
}
void generateIndentation() {
- int i, j;
-
- for (i = 0; i < positionInDecompileLineTable; i++) {
+ for (int i = 0; i < positionInDecompileLineTable; i++) {
if (decompileLineTable[i].type != 0) {
char *gotoStatement;
int destLine;
@@ -1302,7 +1293,7 @@ void generateIndentation() {
destLine = atoi(gotoStatement);
destLineIdx = -1;
- for (j = 0; j < positionInDecompileLineTable; j++) {
+ for (int j = 0; j < positionInDecompileLineTable; j++) {
if (decompileLineTable[j].lineOffset == destLine) {
destLineIdx = j;
break;
@@ -1312,7 +1303,7 @@ void generateIndentation() {
assert(destLineIdx != -1);
if (destLineIdx > i) {
- for (j = i + 1; j < destLineIdx; j++) {
+ for (int j = i + 1; j < destLineIdx; j++) {
decompileLineTable[j].indent++;
}
@@ -1328,7 +1319,6 @@ void generateIndentation() {
void dumpScript(uint8 *ovlName, ovlDataStruct *ovlData, int idx) {
uint8 opcodeType;
char buffer[256];
- int i;
char temp[256];
char scriptName[256];
@@ -1367,9 +1357,8 @@ void dumpScript(uint8 *ovlName, ovlDataStruct *ovlData, int idx) {
decompileStackPosition = 0;
- for (i = 0; i < 64; i++) {
+ for (int i = 0; i < 64; i++)
decompOpcodeTypeTable[i] = NULL;
- }
decompOpcodeTypeTable[1] = decompLoadVar;
decompOpcodeTypeTable[2] = decompSaveVar;
@@ -1412,9 +1401,7 @@ void dumpScript(uint8 *ovlName, ovlDataStruct *ovlData, int idx) {
generateIndentation();
- for (i = 0; i < positionInDecompileLineTable; i++) {
- int j;
-
+ for (int i = 0; i < positionInDecompileLineTable; i++) {
if (decompileLineTable[i].pendingElse) {
fprintf(fHandle, "%05d:\t",
decompileLineTable[i].lineOffset);
@@ -1423,9 +1410,9 @@ void dumpScript(uint8 *ovlName, ovlDataStruct *ovlData, int idx) {
}
fprintf(fHandle, "%05d:\t", decompileLineTable[i].lineOffset);
- for (j = 0; j < decompileLineTable[i].indent; j++) {
+ for (int j = 0; j < decompileLineTable[i].indent; j++)
fprintf(fHandle, "\t");
- }
+
fprintf(fHandle, "%s", decompileLineTable[i].line);
fprintf(fHandle, "\n");
}
diff --git a/engines/cruise/font.cpp b/engines/cruise/font.cpp
index 2ef43c952a..43fbf8c79b 100644
--- a/engines/cruise/font.cpp
+++ b/engines/cruise/font.cpp
@@ -180,30 +180,26 @@ void bigEndianLongToNative(void *var) {
}
void flipGen(void *var, int32 length) {
- int i;
short int *varPtr = (int16 *) var;
- for (i = 0; i < (length / 2); i++) {
+ for (int i = 0; i < (length / 2); i++) {
bigEndianShortToNative(&varPtr[i]);
}
}
void renderWord(const uint8 *fontPtr_Data, uint8 *outBufferPtr, int xOffset, int yOffset,
int32 height, int32 param4, int32 stringRenderBufferSize, int32 width, int32 charWidth) {
- int i;
- int j;
const uint8 *fontPtr_Data2 = fontPtr_Data + height * 2;
-
outBufferPtr += yOffset * width + xOffset;
- for (i = 0; i < height; i++) { // y++
+ for (int i = 0; i < height; i++) { // y++
uint16 bitSet1 = READ_BE_UINT16(fontPtr_Data);
uint16 bitSet2 = READ_BE_UINT16(fontPtr_Data2);
fontPtr_Data += sizeof(uint16);
fontPtr_Data2 += sizeof(uint16);
- for (j = 0; j < charWidth; j++) {
+ for (int j = 0; j < charWidth; j++) {
*outBufferPtr = ((bitSet1 >> 15) & 1) | ((bitSet2 >> 14) & 2);
outBufferPtr++;
diff --git a/engines/cruise/function.cpp b/engines/cruise/function.cpp
index e0053ec017..dc4303c286 100644
--- a/engines/cruise/function.cpp
+++ b/engines/cruise/function.cpp
@@ -981,11 +981,9 @@ int16 Op_SetColor() {
int endIdx = popVar();
int startIdx = popVar();
- int i;
-
#define convertRatio 36.571428571428571428571428571429
- for (i = startIdx; i <= endIdx; i++) {
+ for (int i = startIdx; i <= endIdx; i++) {
int offsetTable[3];
offsetTable[0] = (int)(colorR * convertRatio);
diff --git a/engines/cruise/gfxModule.cpp b/engines/cruise/gfxModule.cpp
index 39385459d9..e3e7a2d510 100644
--- a/engines/cruise/gfxModule.cpp
+++ b/engines/cruise/gfxModule.cpp
@@ -142,12 +142,11 @@ void gfxModuleData_setPal256(const byte *ptr) {
}
/*void gfxModuleData_setPal(uint8 *ptr) {
- int i;
int R;
int G;
int B;
- for (i = 0; i < 256; i++) {
+ for (int i = 0; i < 256; i++) {
#define convertRatio 36.571428571428571428571428571429
uint16 atariColor = *ptr;
//bigEndianShortToNative(&atariColor);
diff --git a/engines/cruise/linker.cpp b/engines/cruise/linker.cpp
index 883bad97d3..7768e05585 100644
--- a/engines/cruise/linker.cpp
+++ b/engines/cruise/linker.cpp
@@ -35,7 +35,6 @@ exportEntryStruct *parseExport(int *out1, int *pExportedFuncionIdx, char *buffer
int numSymbGlob;
exportEntryStruct *currentExportEntry;
char *entity1Name;
- int i;
*out1 = 0;
*pExportedFuncionIdx = 0;
@@ -85,7 +84,7 @@ exportEntryStruct *parseExport(int *out1, int *pExportedFuncionIdx, char *buffer
if (!entity1Name)
return (0);
- for (i = 0; i < numSymbGlob; i++) {
+ for (int i = 0; i < numSymbGlob; i++) {
char exportedName[256];
char *name = entity1Name + currentExportEntry->offsetToName;
@@ -221,9 +220,7 @@ int updateScriptImport(int ovlIdx) {
if (ovlData->arrayRelocGlob && ovlData->arrayNameRelocGlob && numRelocGlob) {
int numImport2 = numRelocGlob;
- int i;
-
- for (i = 0; i < numImport2; i++) {
+ for (int i = 0; i < numImport2; i++) {
int out1;
int foundExportIdx;
exportEntryStruct *pFoundExport;
@@ -264,12 +261,9 @@ int updateScriptImport(int ovlIdx) {
// check that the newly loaded isn't used by the already loaded overlays
void updateAllScriptsImports() {
- int i;
-
- for (i = 0; i < 90; i++) {
- if (overlayTable[i].ovlData && overlayTable[i].alreadyLoaded) {
+ for (int i = 0; i < 90; i++) {
+ if (overlayTable[i].ovlData && overlayTable[i].alreadyLoaded)
updateScriptImport(i);
- }
}
}
diff --git a/engines/cruise/mainDraw.cpp b/engines/cruise/mainDraw.cpp
index 0863a2a84e..0e39740822 100644
--- a/engines/cruise/mainDraw.cpp
+++ b/engines/cruise/mainDraw.cpp
@@ -1255,18 +1255,15 @@ void drawSprite(int width, int height, cellStruct *currentObjPtr, const uint8 *d
#ifdef _DEBUG
void drawCtp() {
- /* int i;
-
- if (ctp_walkboxTable) {
- for (i = 0; i < 15; i++) {
+ /* if (ctp_walkboxTable) {
+ for (int i = 0; i < 15; i++) {
uint16 *dataPtr = &ctp_walkboxTable[i * 40];
int type = walkboxColor[i]; // show different types in different colors
if (*dataPtr) {
- int j;
fillpoly((short *)dataPtr + 1, *dataPtr, type);
- for (j = 0; j < (*dataPtr - 1); j++) {
+ for (int j = 0; j < (*dataPtr - 1); j++) {
line(dataPtr[1 + j * 2],
dataPtr[1 + j * 2 + 1],
dataPtr[1 + (j + 1) * 2],
diff --git a/engines/cruise/overlay.cpp b/engines/cruise/overlay.cpp
index d2cc0f671b..386a11f7ef 100644
--- a/engines/cruise/overlay.cpp
+++ b/engines/cruise/overlay.cpp
@@ -32,9 +32,7 @@ overlayStruct overlayTable[90];
int numOfLoadedOverlay;
void initOverlayTable() {
- int i;
-
- for (i = 0; i < 90; i++) {
+ for (int i = 0; i < 90; i++) {
overlayTable[i].overlayName[0] = 0;
overlayTable[i].ovlData = NULL;
overlayTable[i].alreadyLoaded = 0;
@@ -53,7 +51,6 @@ void freeOverlayTable() {
int freeOverlay(int overlayIdx) {
ovlDataStruct *ovlDataPtr;
- int i;
if (overlayTable[overlayIdx].alreadyLoaded == 0)
return -4;
@@ -65,7 +62,6 @@ int freeOverlay(int overlayIdx) {
if (!ovlDataPtr)
return -4;
-
/*
if (overlayTable[overlayIdx].var1E) {
MemFree(overlayTable[overlayIdx].var1E);
@@ -84,19 +80,19 @@ int freeOverlay(int overlayIdx) {
removeScript(overlayIdx, -1, &relHead);
if (ovlDataPtr->stringTable) {
- for (i = 0; i < ovlDataPtr->numStrings; ++i)
+ for (int i = 0; i < ovlDataPtr->numStrings; ++i)
MemFree(ovlDataPtr->stringTable[i].string);
MemFree(ovlDataPtr->stringTable);
}
if (ovlDataPtr->arrayProc) {
ovlData3Struct *tempPtr = ovlDataPtr->arrayProc;
- for (i = 0; i < ovlDataPtr->numProc; ++i, ++tempPtr)
+ for (int i = 0; i < ovlDataPtr->numProc; ++i, ++tempPtr)
MemFree(tempPtr->dataPtr);
MemFree(ovlDataPtr->arrayProc);
}
if (ovlDataPtr->ptr1) {
ovlData3Struct *tempPtr = (ovlData3Struct *)ovlDataPtr->ptr1;
- for (i = 0; i < ovlDataPtr->numRel; ++i, ++tempPtr)
+ for (int i = 0; i < ovlDataPtr->numRel; ++i, ++tempPtr)
MemFree(tempPtr->dataPtr);
MemFree(ovlDataPtr->ptr1);
}
@@ -246,15 +242,13 @@ int loadOverlay(const char *scriptName) {
ovlData->scriptNumber = s.readUint16BE();
if (ovlData->numSymbGlob) { // export data
- int i;
ovlData->arraySymbGlob =
(exportEntryStruct *) mallocAndZero(ovlData->numSymbGlob * sizeof(exportEntryStruct));
- if (!ovlData->arraySymbGlob) {
+ if (!ovlData->arraySymbGlob)
return (-2);
- }
- for (i = 0; i < ovlData->numSymbGlob; i++) {
+ for (int i = 0; i < ovlData->numSymbGlob; i++) {
ovlData->arraySymbGlob[i].var0 = s.readUint16BE();
ovlData->arraySymbGlob[i].var2 = s.readUint16BE();
ovlData->arraySymbGlob[i].var4 = s.readUint16BE();
@@ -274,17 +268,14 @@ int loadOverlay(const char *scriptName) {
}
if (ovlData->numRelocGlob) { // import data
- int i;
-
ovlData->arrayRelocGlob =
(importDataStruct *) mallocAndZero(ovlData->numRelocGlob *
sizeof(importDataStruct));
- if (!ovlData->arrayRelocGlob) {
+ if (!ovlData->arrayRelocGlob)
return (-2);
- }
- for (i = 0; i < ovlData->numRelocGlob; i++) {
+ for (int i = 0; i < ovlData->numRelocGlob; i++) {
ovlData->arrayRelocGlob[i].var0 = s.readUint16BE();
ovlData->arrayRelocGlob[i].var1 = s.readUint16BE();
ovlData->arrayRelocGlob[i].linkType = s.readUint16BE();
@@ -304,16 +295,14 @@ int loadOverlay(const char *scriptName) {
}
if (ovlData->numMsgRelHeader) { // link data
- int i;
ASSERT(sizeof(linkDataStruct) == 0x22);
ovlData->arrayMsgRelHeader = (linkDataStruct *) mallocAndZero(ovlData->numMsgRelHeader * sizeof(linkDataStruct));
- if (!ovlData->arrayMsgRelHeader) {
+ if (!ovlData->arrayMsgRelHeader)
return (-2);
- }
- for (i = 0; i < ovlData->numMsgRelHeader; i++) {
+ for (int i = 0; i < ovlData->numMsgRelHeader; i++) {
ovlData->arrayMsgRelHeader[i].type = s.readUint16BE();
ovlData->arrayMsgRelHeader[i].id = s.readUint16BE();
ovlData->arrayMsgRelHeader[i].offsetVerbeName = s.readUint16BE();
@@ -341,16 +330,13 @@ int loadOverlay(const char *scriptName) {
if (ovlData->numProc) { // script
ovlData3Struct *tempPtr;
- int i;
- ovlData->arrayProc =
- (ovlData3Struct *) mallocAndZero(ovlData->numProc * sizeof(ovlData3Struct));
+ ovlData->arrayProc = (ovlData3Struct *) mallocAndZero(ovlData->numProc * sizeof(ovlData3Struct));
- if (!ovlData->arrayProc) {
+ if (!ovlData->arrayProc)
return (-2);
- }
- for (i = 0; i < ovlData->numProc; i++) {
+ for (int i = 0; i < ovlData->numProc; i++) {
s.skip(4);
ovlData->arrayProc[i].dataPtr = NULL;
ovlData->arrayProc[i].sizeOfData = s.readUint16BE();
@@ -369,7 +355,7 @@ int loadOverlay(const char *scriptName) {
tempPtr = ovlData->arrayProc;
- for (i = 0; i < ovlData->numProc; i++) {
+ for (int i = 0; i < ovlData->numProc; i++) {
tempPtr->dataPtr = (uint8 *) mallocAndZero(tempPtr->sizeOfData);
if (!tempPtr->dataPtr) {
@@ -394,16 +380,13 @@ int loadOverlay(const char *scriptName) {
if (ovlData->numRel) {
ovlData3Struct *tempPtr;
- int i;
- ovlData->ptr1 =
- (ovlData3Struct *) mallocAndZero(ovlData->numRel * sizeof(ovlData3Struct));
+ ovlData->ptr1 = (ovlData3Struct *) mallocAndZero(ovlData->numRel * sizeof(ovlData3Struct));
- if (!ovlData->ptr1) {
+ if (!ovlData->ptr1)
return (-2);
- }
- for (i = 0; i < ovlData->numRel; i++) {
+ for (int i = 0; i < ovlData->numRel; i++) {
s.skip(4);
ovlData->ptr1[i].dataPtr = NULL;
ovlData->ptr1[i].sizeOfData = s.readUint16BE();
@@ -422,12 +405,11 @@ int loadOverlay(const char *scriptName) {
tempPtr = (ovlData3Struct *) ovlData->ptr1;
- for (i = 0; i < ovlData->numRel; i++) {
+ for (int i = 0; i < ovlData->numRel; i++) {
tempPtr->dataPtr = (uint8 *) mallocAndZero(tempPtr->sizeOfData);
- if (!tempPtr->dataPtr) {
+ if (!tempPtr->dataPtr)
return (-2);
- }
s.read(tempPtr->dataPtr, tempPtr->sizeOfData);
@@ -462,16 +444,12 @@ int loadOverlay(const char *scriptName) {
}
if (ovlData->numObj) {
- int i;
- ovlData->arrayObject =
- (objDataStruct *) mallocAndZero(ovlData->numObj *
- sizeof(objDataStruct));
+ ovlData->arrayObject = (objDataStruct *) mallocAndZero(ovlData->numObj * sizeof(objDataStruct));
- if (!ovlData->arrayObject) {
+ if (!ovlData->arrayObject)
return (-2);
- }
- for (i = 0; i < ovlData->numObj; i++) {
+ for (int i = 0; i < ovlData->numObj; i++) {
ovlData->arrayObject[i]._type = s.readUint16BE();
ovlData->arrayObject[i]._class = (eClass) s.readUint16BE();
ovlData->arrayObject[i]._nameOffset = s.readUint16BE();
@@ -500,16 +478,12 @@ int loadOverlay(const char *scriptName) {
}
if (ovlData->size8) {
- int i;
- ovlData->arrayStates =
- (objectParams *) mallocAndZero(ovlData->size8 *
- sizeof(objectParams));
+ ovlData->arrayStates = (objectParams *) mallocAndZero(ovlData->size8 * sizeof(objectParams));
- if (!ovlData->arrayStates) {
+ if (!ovlData->arrayStates)
return (-2);
- }
- for (i = 0; i < ovlData->size8; i++) {
+ for (int i = 0; i < ovlData->size8; i++) {
ovlData->arrayStates[i].X = s.readUint16BE();
ovlData->arrayStates[i].Y = s.readUint16BE();
ovlData->arrayStates[i].Z = s.readUint16BE();
@@ -520,30 +494,21 @@ int loadOverlay(const char *scriptName) {
}
if (ovlData->numStrings) {
- int i;
-
- ovlData->stringTable =
- (stringEntryStruct *) mallocAndZero(ovlData->numStrings *
- sizeof(stringEntryStruct));
+ ovlData->stringTable = (stringEntryStruct *) mallocAndZero(ovlData->numStrings * sizeof(stringEntryStruct));
- for (i = 0; i < ovlData->numStrings; i++) {
+ for (int i = 0; i < ovlData->numStrings; i++)
ovlData->stringTable[i].idx = s.readUint16BE();
- }
}
if (ovlData->sizeOfData4) {
- ovlData->data4Ptr =
- (uint8 *) mallocAndZero(ovlData->sizeOfData4);
+ ovlData->data4Ptr = (uint8 *) mallocAndZero(ovlData->sizeOfData4);
- if (!ovlData->data4Ptr) {
+ if (!ovlData->data4Ptr)
return (-2);
- }
}
- if (ovlData->
- specialString1Length /*|| ovlData->specialString2Length */
+ if (ovlData->specialString1Length /*|| ovlData->specialString2Length */
|| ovlData->stringTable) {
- int i;
//int unpackedSize;
//int fileIdx;
//uint8 fileName[50];
@@ -623,7 +588,7 @@ int loadOverlay(const char *scriptName) {
s2.read(ovlData->arrayNameObj, ovlData->specialString2Length);
}
- for (i = 0; i < ovlData->numStrings; i++) {
+ for (int i = 0; i < ovlData->numStrings; i++) {
ovlData->stringTable[i].length = s2.readUint16BE();
if (ovlData->stringTable[i].length) {
@@ -648,8 +613,7 @@ int loadOverlay(const char *scriptName) {
}
#ifdef DUMP_SCRIPT
{
- int i;
- for (i = 0; i < ovlData->numProc; i++) {
+ for (int i = 0; i < ovlData->numProc; i++) {
dumpScript(scriptName, ovlData, i);
}
}
@@ -657,7 +621,6 @@ int loadOverlay(const char *scriptName) {
#ifdef DUMP_OBJECT
{
// TODO: Rewrite this to use Common::DumpFile
- int i;
FILE *fHandle;
char nameBundle[100];
sprintf(nameBundle, "%s-objs.txt", scriptName);
@@ -665,7 +628,7 @@ int loadOverlay(const char *scriptName) {
fHandle = fopen(nameBundle, "w+");
ASSERT(fHandle);
- for (i = 0; i < ovlData->numMsgRelHeader; i++) {
+ for (int i = 0; i < ovlData->numMsgRelHeader; i++) {
linkDataStruct *var_34;
var_34 = &ovlData->arrayMsgRelHeader[i];
@@ -698,9 +661,7 @@ int releaseOverlay(const char *name) {
}
int32 findOverlayByName2(const char *name) {
- int i;
-
- for (i = 1; i < numOfLoadedOverlay; i++) {
+ for (int i = 1; i < numOfLoadedOverlay; i++) {
if (!strcmp(overlayTable[i].overlayName, name))
return (i);
}
@@ -709,12 +670,9 @@ int32 findOverlayByName2(const char *name) {
}
int findOverlayByName(const char *overlayName) {
- int i;
-
- for (i = 1; i < numOfLoadedOverlay; i++) {
- if (!strcmp(overlayTable[i].overlayName, overlayName)) {
+ for (int i = 1; i < numOfLoadedOverlay; i++) {
+ if (!strcmp(overlayTable[i].overlayName, overlayName))
return (i);
- }
}
return (-4);
diff --git a/engines/cruise/polys.cpp b/engines/cruise/polys.cpp
index bec03a06a6..415f0520a6 100644
--- a/engines/cruise/polys.cpp
+++ b/engines/cruise/polys.cpp
@@ -183,11 +183,10 @@ void line(int x1, int y1, int x2, int y2, char c) {
static void add_intersect(int *intersect, int x, byte &num) {
if (num < MAXPTS) {
- int i;
- for (i = num; i > 0 && intersect[i - 1] > x; i--) {
+ int i = 0;
+ for (i = num; i > 0 && intersect[i - 1] > x; i--)
intersect[i] = intersect[i - 1];
- }
intersect[i] = x;
num++;
diff --git a/engines/cruise/saveload.cpp b/engines/cruise/saveload.cpp
index a734db4b3b..0f496465e9 100644
--- a/engines/cruise/saveload.cpp
+++ b/engines/cruise/saveload.cpp
@@ -881,17 +881,15 @@ Common::Error loadSavegameData(int saveGameIdx) {
for (int i = 0; i < NUM_FILE_ENTRIES; i++) {
if (filesDatabase[i].subData.ptr) {
- int j;
- int k;
-
- for (j = i + 1; j < NUM_FILE_ENTRIES &&
+ int j = i + 1;
+ for (; j < NUM_FILE_ENTRIES &&
filesDatabase[j].subData.ptr &&
!strcmp(filesDatabase[i].subData.name, filesDatabase[j].subData.name) &&
(filesDatabase[j].subData.index == (j - i));
j++)
;
- for (k = i; k < j; k++) {
+ for (int k = i; k < j; k++) {
filesDatabase[k].subData.ptr = NULL;
filesDatabase[k].subData.ptrMask = NULL;
}
diff --git a/engines/cruise/script.cpp b/engines/cruise/script.cpp
index 764a458b8f..5403c5da59 100644
--- a/engines/cruise/script.cpp
+++ b/engines/cruise/script.cpp
@@ -455,9 +455,7 @@ int32 opcodeType9() { // stop script
}
void setupFuncArray() {
- int i;
-
- for (i = 0; i < 64; i++) {
+ for (int i = 0; i < 64; i++) {
opcodeTypeTable[i] = NULL;
}
diff --git a/engines/cruise/sound.cpp b/engines/cruise/sound.cpp
index 1441ae9661..cef67385f9 100644
--- a/engines/cruise/sound.cpp
+++ b/engines/cruise/sound.cpp
@@ -379,13 +379,12 @@ void AdLibSoundDriver::stopChannel(int channel) {
}
void AdLibSoundDriver::stopAll() {
- int i;
- for (i = 0; i < 18; ++i) {
+ for (int i = 0; i < 18; ++i)
OPLWriteReg(_opl, 0x40 | _operatorsTable[i], 63);
- }
- for (i = 0; i < 9; ++i) {
+
+ for (int i = 0; i < 9; ++i)
OPLWriteReg(_opl, 0xB0 | i, 0);
- }
+
OPLWriteReg(_opl, 0xBD, 0);
}
diff --git a/engines/cruise/volume.cpp b/engines/cruise/volume.cpp
index 54bc6f6d80..3f7a133d9e 100644
--- a/engines/cruise/volume.cpp
+++ b/engines/cruise/volume.cpp
@@ -83,14 +83,12 @@ int closeBase() {
int getVolumeDataEntry(volumeDataStruct *entry) {
char buffer[256];
- int i;
volumeNumEntry = 0;
volumeNumberOfEntry = 0;
- if (_vm->_currentVolumeFile.isOpen()) {
+ if (_vm->_currentVolumeFile.isOpen())
freeDisk();
- }
askDisk(-1);
@@ -98,9 +96,8 @@ int getVolumeDataEntry(volumeDataStruct *entry) {
_vm->_currentVolumeFile.open(buffer);
- if (!_vm->_currentVolumeFile.isOpen()) {
+ if (!_vm->_currentVolumeFile.isOpen())
return (-14);
- }
changeCursor(CURSOR_DISK);
@@ -113,7 +110,7 @@ int getVolumeDataEntry(volumeDataStruct *entry) {
volumePtrToFileDescriptor = (fileEntry *) mallocAndZero(sizeof(fileEntry) * volumeNumEntry);
- for (i = 0; i < volumeNumEntry; i++) {
+ for (int i = 0; i < volumeNumEntry; i++) {
volumePtrToFileDescriptor[i].name[0] = 0;
volumePtrToFileDescriptor[i].offset = 0;
volumePtrToFileDescriptor[i].size = 0;
@@ -121,7 +118,7 @@ int getVolumeDataEntry(volumeDataStruct *entry) {
volumePtrToFileDescriptor[i].unk3 = 0;
}
- for (i = 0; i < volumeNumEntry; i++) {
+ for (int i = 0; i < volumeNumEntry; i++) {
_vm->_currentVolumeFile.read(&volumePtrToFileDescriptor[i].name, 14);
volumePtrToFileDescriptor[i].offset = _vm->_currentVolumeFile.readSint32BE();
volumePtrToFileDescriptor[i].size = _vm->_currentVolumeFile.readSint32BE();
@@ -138,14 +135,12 @@ int getVolumeDataEntry(volumeDataStruct *entry) {
int searchFileInVolCnf(const char *fileName, int32 diskNumber) {
int foundDisk = -1;
- int i;
- for (i = 0; i < numOfDisks; i++) {
+ for (int i = 0; i < numOfDisks; i++) {
if (volumeData[i].diskNumber == diskNumber) {
- int j;
int numOfEntry = volumeData[i].size / 13;
- for (j = 0; j < numOfEntry; j++) {
+ for (int j = 0; j < numOfEntry; j++) {
if (!strcmp(volumeData[i].ptr[j].name, fileName)) {
return (i);
}
@@ -158,13 +153,11 @@ int searchFileInVolCnf(const char *fileName, int32 diskNumber) {
int32 findFileInDisksSub1(const char *fileName) {
int foundDisk = -1;
- int i;
- for (i = 0; i < numOfDisks; i++) {
- int j;
+ for (int i = 0; i < numOfDisks; i++) {
int numOfEntry = volumeData[i].size / 13;
- for (j = 0; j < numOfEntry; j++) {
+ for (int j = 0; j < numOfEntry; j++) {
if (!strcmp(volumeData[i].ptr[j].name, fileName)) {
return (i);
}
@@ -189,19 +182,15 @@ void freeDisk() {
}
int16 findFileInList(char *fileName) {
- int i;
-
- if (!_vm->_currentVolumeFile.isOpen()) {
+ if (!_vm->_currentVolumeFile.isOpen())
return (-1);
- }
strToUpper(fileName);
- if (volumeNumEntry <= 0) {
+ if (volumeNumEntry <= 0)
return (-1);
- }
- for (i = 0; i < volumeNumEntry; i++) {
+ for (int i = 0; i < volumeNumEntry; i++) {
if (!strcmp(volumePtrToFileDescriptor[i].name, fileName)) {
return (i);
}
@@ -324,13 +313,12 @@ int closeCnf() {
}
int16 readVolCnf() {
- int i;
Common::File fileHandle;
//short int sizeHEntry;
volumeDataLoaded = 0;
- for (i = 0; i < 20; i++) {
+ for (int i = 0; i < 20; i++) {
volumeData[i].ident[0] = 0;
volumeData[i].ptr = NULL;
volumeData[i].diskNumber = i + 1;
@@ -339,14 +327,13 @@ int16 readVolCnf() {
fileHandle.open("VOL.CNF");
- if (!fileHandle.isOpen()) {
+ if (!fileHandle.isOpen())
return (0);
- }
numOfDisks = fileHandle.readSint16BE();
/*sizeHEntry =*/ fileHandle.readSint16BE(); // size of one header entry - 20 bytes
- for (i = 0; i < numOfDisks; i++) {
+ for (int i = 0; i < numOfDisks; i++) {
// fread(&volumeData[i],20,1,fileHandle);
fileHandle.read(&volumeData[i].ident, 10);
fileHandle.read(&volumeData[i].ptr, 4);
@@ -356,7 +343,7 @@ int16 readVolCnf() {
debug(1, "Disk number: %d", volumeData[i].diskNumber);
}
- for (i = 0; i < numOfDisks; i++) {
+ for (int i = 0; i < numOfDisks; i++) {
dataFileName *ptr;
volumeData[i].size = fileHandle.readSint32BE();
@@ -381,7 +368,6 @@ int16 readVolCnf() {
#ifdef dumpResources
for (i = 0; i < numOfDisks; i++) {
- int j;
char nameBuffer[256];
fileEntry *buffer;
@@ -397,7 +383,7 @@ int16 readVolCnf() {
buffer = (fileEntry *) mallocAndZero(numEntry * sizeEntry);
- for (j = 0; j < numEntry; j++) {
+ for (int j = 0; j < numEntry; j++) {
fileHandle.seek(4 + j*0x1E);
fileHandle.read(buffer[j].name, 14);
buffer[j].offset = fileHandle.readSint32BE();