diff options
author | Marisa-Chan | 2014-06-13 21:43:04 +0700 |
---|---|---|
committer | Marisa-Chan | 2014-06-13 21:43:04 +0700 |
commit | 45589950c0fb1a449351e6a00ef10d42290d8bae (patch) | |
tree | 44e4eedcb7e69d5fc386155b000ed038af07251d /engines/cruise | |
parent | 48360645dcd5f8fddb135b6e31ae5cae4be8d77f (diff) | |
parent | 5c005ad3a3f1df0bc968c85c1cf0fc48e36ab0b2 (diff) | |
download | scummvm-rg350-45589950c0fb1a449351e6a00ef10d42290d8bae.tar.gz scummvm-rg350-45589950c0fb1a449351e6a00ef10d42290d8bae.tar.bz2 scummvm-rg350-45589950c0fb1a449351e6a00ef10d42290d8bae.zip |
Merge remote-tracking branch 'upstream/master' into zvision
Conflicts:
engines/zvision/animation/rlf_animation.cpp
engines/zvision/animation_control.h
engines/zvision/core/console.cpp
engines/zvision/core/events.cpp
engines/zvision/cursors/cursor.cpp
engines/zvision/cursors/cursor_manager.cpp
engines/zvision/cursors/cursor_manager.h
engines/zvision/fonts/truetype_font.cpp
engines/zvision/graphics/render_manager.cpp
engines/zvision/graphics/render_manager.h
engines/zvision/inventory/inventory_manager.h
engines/zvision/inventory_manager.h
engines/zvision/meta_animation.h
engines/zvision/module.mk
engines/zvision/scripting/actions.cpp
engines/zvision/scripting/control.h
engines/zvision/scripting/controls/animation_control.cpp
engines/zvision/scripting/controls/animation_control.h
engines/zvision/scripting/controls/input_control.cpp
engines/zvision/scripting/controls/lever_control.cpp
engines/zvision/scripting/controls/timer_node.cpp
engines/zvision/scripting/controls/timer_node.h
engines/zvision/scripting/puzzle.h
engines/zvision/scripting/scr_file_handling.cpp
engines/zvision/scripting/script_manager.cpp
engines/zvision/scripting/script_manager.h
engines/zvision/sidefx.cpp
engines/zvision/sound/zork_raw.cpp
engines/zvision/sound/zork_raw.h
engines/zvision/video/video.cpp
engines/zvision/video/zork_avi_decoder.h
engines/zvision/zvision.cpp
engines/zvision/zvision.h
Diffstat (limited to 'engines/cruise')
60 files changed, 857 insertions, 1143 deletions
diff --git a/engines/cruise/actor.cpp b/engines/cruise/actor.cpp index 94f620ed7b..331b1c1edd 100644 --- a/engines/cruise/actor.cpp +++ b/engines/cruise/actor.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -289,16 +289,15 @@ void poly2(int x1, int y1, int x2, int y2) { } int point_proche(int16 table[][2]) { - int x1, y1, i, x, y, p; int d1 = 1000; _vm->_polyStructs = &_vm->_polyStructNorm; if (nclick_noeud == 1) { - x = x_mouse; - y = y_mouse; - x1 = table_ptselect[0][0]; - y1 = table_ptselect[0][1]; + int x = x_mouse; + int y = y_mouse; + int x1 = table_ptselect[0][0]; + int y1 = table_ptselect[0][1]; _vm->_polyStructs = &_vm->_polyStructExp; @@ -326,10 +325,10 @@ int point_proche(int16 table[][2]) { } _vm->_polyStructs = &_vm->_polyStructNorm; - p = -1; - for (i = 0; i < ctp_routeCoordCount; i++) { - x = table[i][0]; - y = table[i][1]; + int p = -1; + for (int i = 0; i < ctp_routeCoordCount; i++) { + int x = table[i][0]; + int y = table[i][1]; int pointDistance = computeDistance(x_mouse, y_mouse, x, y); if (pointDistance < d1) { @@ -363,9 +362,7 @@ int8 Fsol[NBNOEUD + 1]; int D; void explore(int depart, int arrivee) { - int id1, id2, i; - - id1 = depart; + int id1 = depart; fl[id1]++; sol[idsol++] = (char)id1; @@ -377,8 +374,9 @@ void explore(int depart, int arrivee) { return; } + int i; while ((i = fl[id1]) < 20) { - id2 = ctp_routes[id1][i + 1]; + int id2 = ctp_routes[id1][i + 1]; if (id2 == arrivee) { if (idsol < solmax) { @@ -426,16 +424,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; @@ -444,9 +439,6 @@ void chemin0(int depart, int arrivee) { } void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2]) { - int a, b, d, i, p1, x1, x2, y1, y2; - //int y=30; - table[*nclick] = p; table[(*nclick) + 1] = -1; table_ptselect[*nclick][0] = x_mouse; @@ -455,10 +447,10 @@ void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2 _vm->_polyStructs = &_vm->_polyStructNorm; if (*nclick == 2) { // second point - x1 = table_ptselect[0][0]; - y1 = table_ptselect[0][1]; - x2 = table_ptselect[1][0]; - y2 = table_ptselect[1][1]; + int x1 = table_ptselect[0][0]; + int y1 = table_ptselect[0][1]; + int x2 = table_ptselect[1][0]; + int y2 = table_ptselect[1][1]; if ((x1 == x2) && (y1 == y2)) { return; } @@ -507,13 +499,11 @@ void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2 } else { solution0[0][0] = x1; solution0[0][1] = y1; - i = 0; + int i = 0; while (solution[i] != -1) { - p1 = solution[i]; - solution0[i + 1][0] = - ctp_routeCoords[p1][0]; - solution0[++i][1] = - ctp_routeCoords[p1][1]; + int p1 = solution[i]; + solution0[i + 1][0] = ctp_routeCoords[p1][0]; + solution0[++i][1] = ctp_routeCoords[p1][1]; } _vm->_polyStructs = &_vm->_polyStructExp; poly2(x2, y2, @@ -530,8 +520,8 @@ void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2 /****** Trim down any un-necessary walk points ******/ i++; - d = 0; - a = i; + int d = 0; + int a = i; flag_obstacle = 1; while (d != a) { x1 = solution0[d][0]; @@ -547,7 +537,7 @@ void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2 flag_obstacle = 1; if (d != i) { i++; - for (b = d + 1; b < i; b++) { + for (int b = d + 1; b < i; b++) { solution0[b][0] = -2; } } else @@ -582,10 +572,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/actor.h b/engines/cruise/actor.h index b409bf7b7f..5d8cce1f99 100644 --- a/engines/cruise/actor.h +++ b/engines/cruise/actor.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/background.cpp b/engines/cruise/background.cpp index 9da5413013..4cf52f62e1 100644 --- a/engines/cruise/background.cpp +++ b/engines/cruise/background.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -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; @@ -180,7 +178,7 @@ int loadBackground(const char *name, int idx) { break; default: - ASSERT(0); + assert(0); } gfxModuleData_setPal256(palScreen[idx]); diff --git a/engines/cruise/background.h b/engines/cruise/background.h index 7a8f2d5494..ea9e7bba87 100644 --- a/engines/cruise/background.h +++ b/engines/cruise/background.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/backgroundIncrust.cpp b/engines/cruise/backgroundIncrust.cpp index ddda8dee45..77e15ccf4c 100644 --- a/engines/cruise/backgroundIncrust.cpp +++ b/engines/cruise/backgroundIncrust.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -59,6 +59,8 @@ void backupBackground(backgroundIncrustStruct *pIncrust, int X, int Y, int width } void restoreBackground(backgroundIncrustStruct *pIncrust) { + if (!pIncrust) + return; if (pIncrust->type != 1) return; if (pIncrust->ptr == NULL) @@ -87,39 +89,32 @@ void restoreBackground(backgroundIncrustStruct *pIncrust) { } backgroundIncrustStruct *addBackgroundIncrust(int16 overlayIdx, int16 objectIdx, backgroundIncrustStruct *pHead, int16 scriptNumber, int16 scriptOverlay, int16 backgroundIdx, int16 saveBuffer) { - uint8 *backgroundPtr; - uint8 *ptr; objectParamsQuery params; - backgroundIncrustStruct *newElement; - backgroundIncrustStruct *currentHead; - backgroundIncrustStruct *currentHead2; - getMultipleObjectParam(overlayIdx, objectIdx, ¶ms); - ptr = filesDatabase[params.fileIdx].subData.ptr; + uint8 *ptr = filesDatabase[params.fileIdx].subData.ptr; // Don't process any further if not a sprite or polygon - if (!ptr) return NULL; - if ((filesDatabase[params.fileIdx].subData.resourceType != OBJ_TYPE_SPRITE) && - (filesDatabase[params.fileIdx].subData.resourceType != OBJ_TYPE_POLY)) { + if (!ptr) return NULL; - } - - backgroundPtr = backgroundScreens[backgroundIdx]; - backgroundChanged[backgroundIdx] = true; + if ((filesDatabase[params.fileIdx].subData.resourceType != OBJ_TYPE_SPRITE) && + (filesDatabase[params.fileIdx].subData.resourceType != OBJ_TYPE_POLY)) + return NULL; + uint8 *backgroundPtr = backgroundScreens[backgroundIdx]; assert(backgroundPtr != NULL); - currentHead = pHead; - currentHead2 = currentHead->next; + backgroundChanged[backgroundIdx] = true; + backgroundIncrustStruct *currentHead = pHead; + backgroundIncrustStruct *currentHead2 = currentHead->next; while (currentHead2) { currentHead = currentHead2; currentHead2 = currentHead->next; } - newElement = (backgroundIncrustStruct *)mallocAndZero(sizeof(backgroundIncrustStruct)); + backgroundIncrustStruct *newElement = (backgroundIncrustStruct *)mallocAndZero(sizeof(backgroundIncrustStruct)); if (!newElement) return NULL; @@ -127,13 +122,11 @@ backgroundIncrustStruct *addBackgroundIncrust(int16 overlayIdx, int16 objectIdx, newElement->next = currentHead->next; currentHead->next = newElement; - if (!currentHead2) { + if (!currentHead2) currentHead2 = pHead; - } newElement->prev = currentHead2->prev; currentHead2->prev = newElement; - newElement->objectIdx = objectIdx; newElement->type = saveBuffer; newElement->backgroundIdx = backgroundIdx; @@ -152,9 +145,8 @@ backgroundIncrustStruct *addBackgroundIncrust(int16 overlayIdx, int16 objectIdx, // sprite int width = filesDatabase[params.fileIdx].width; int height = filesDatabase[params.fileIdx].height; - if (saveBuffer == 1) { + if (saveBuffer == 1) backupBackground(newElement, newElement->X, newElement->Y, width, height, backgroundPtr); - } drawSprite(width, height, NULL, filesDatabase[params.fileIdx].subData.ptr, newElement->Y, newElement->X, backgroundPtr, filesDatabase[params.fileIdx].subData.ptrMask); @@ -168,7 +160,7 @@ backgroundIncrustStruct *addBackgroundIncrust(int16 overlayIdx, int16 objectIdx, int sizeTable[4]; // 0 = left, 1 = right, 2 = bottom, 3 = top - // this function checks if the dataPtr is not 0, else it retrives the data for X, Y, scale and DataPtr again (OLD: mainDrawSub1Sub1) + // this function checks if the dataPtr is not 0, else it retrieves the data for X, Y, scale and DataPtr again (OLD: mainDrawSub1Sub1) flipPoly(params.fileIdx, (int16 *)filesDatabase[params.fileIdx].subData.ptr, params.scale, &newFrame, newElement->X, newElement->Y, &newX, &newY, &newScale); // this function fills the sizeTable for the poly (OLD: mainDrawSub1Sub2) @@ -187,16 +179,15 @@ backgroundIncrustStruct *addBackgroundIncrust(int16 overlayIdx, int16 objectIdx, } void regenerateBackgroundIncrust(backgroundIncrustStruct *pHead) { - lastAni[0] = 0; - - backgroundIncrustStruct* pl = pHead->next; + backgroundIncrustStruct *pl = pHead->next; while (pl) { backgroundIncrustStruct* pl2 = pl->next; int frame = pl->frame; - //int screen = pl->backgroundIdx; + if (frame < 0) + error("regenerateBackgroundIncrust() : Unexpected use of negative frame index"); if ((filesDatabase[frame].subData.ptr == NULL) || (strcmp(pl->name, filesDatabase[frame].subData.name))) { frame = NUM_FILE_ENTRIES - 1; @@ -235,7 +226,6 @@ void freeBackgroundIncrustList(backgroundIncrustStruct *pHead) { MemFree(pCurrent->ptr); MemFree(pCurrent); - pCurrent = pNext; } @@ -244,52 +234,41 @@ void freeBackgroundIncrustList(backgroundIncrustStruct *pHead) { void removeBackgroundIncrust(int overlay, int idx, backgroundIncrustStruct * pHead) { objectParamsQuery params; - int var_4; - int var_6; - - backgroundIncrustStruct *pCurrent; - backgroundIncrustStruct *pCurrentHead; getMultipleObjectParam(overlay, idx, ¶ms); - var_4 = params.X; - var_6 = params.Y; - - pCurrent = pHead->next; + int x = params.X; + int y = params.Y; + backgroundIncrustStruct *pCurrent = pHead->next; while (pCurrent) { - if ((pCurrent->overlayIdx == overlay || overlay == -1) && (pCurrent->objectIdx == idx || idx == -1) && (pCurrent->X == var_4) && (pCurrent->Y == var_6)) { - pCurrent->type = - 1; - } + if ((pCurrent->overlayIdx == overlay || overlay == -1) && (pCurrent->objectIdx == idx || idx == -1) && (pCurrent->X == x) && (pCurrent->Y == y)) + pCurrent->type = -1; pCurrent = pCurrent->next; } - pCurrentHead = pHead; + backgroundIncrustStruct *pCurrentHead = pHead; pCurrent = pHead->next; while (pCurrent) { - if (pCurrent->type == - 1) { + if (pCurrent->type == -1) { backgroundIncrustStruct *pNext = pCurrent->next; backgroundIncrustStruct *bx = pCurrentHead; - backgroundIncrustStruct *cx; bx->next = pNext; - cx = pNext; + backgroundIncrustStruct *cx = pNext; - if (!pNext) { + if (!pNext) cx = pHead; - } bx = cx; bx->prev = pCurrent->next; - if (pCurrent->ptr) { + if (pCurrent->ptr) MemFree(pCurrent->ptr); - } MemFree(pCurrent); - pCurrent = pNext; } else { pCurrentHead = pCurrent; @@ -299,25 +278,24 @@ void removeBackgroundIncrust(int overlay, int idx, backgroundIncrustStruct * pHe } void unmergeBackgroundIncrust(backgroundIncrustStruct * pHead, int ovl, int idx) { - backgroundIncrustStruct *pl; - backgroundIncrustStruct *pl2; - objectParamsQuery params; getMultipleObjectParam(ovl, idx, ¶ms); int x = params.X; int y = params.Y; - pl = pHead; - pl2 = pl; + backgroundIncrustStruct *pl = pHead; + backgroundIncrustStruct *pl2 = pl; pl = pl2->next; while (pl) { pl2 = pl; - if ((pl->overlayIdx == ovl) || (ovl == -1)) - if ((pl->objectIdx == idx) || (idx == -1)) + if ((pl->overlayIdx == ovl) || (ovl == -1)) { + if ((pl->objectIdx == idx) || (idx == -1)) { if ((pl->X == x) && (pl->Y == y)) restoreBackground(pl); + } + } pl = pl2->next; } diff --git a/engines/cruise/backgroundIncrust.h b/engines/cruise/backgroundIncrust.h index 567df0a51e..f29e38edcf 100644 --- a/engines/cruise/backgroundIncrust.h +++ b/engines/cruise/backgroundIncrust.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/cell.cpp b/engines/cruise/cell.cpp index f0fb580ec1..b7cef41764 100644 --- a/engines/cruise/cell.cpp +++ b/engines/cruise/cell.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/cell.h b/engines/cruise/cell.h index 3620a0c945..7865f02fe1 100644 --- a/engines/cruise/cell.h +++ b/engines/cruise/cell.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/configure.engine b/engines/cruise/configure.engine new file mode 100644 index 0000000000..925da25370 --- /dev/null +++ b/engines/cruise/configure.engine @@ -0,0 +1,3 @@ +# This file is included from the main "configure" script +# add_engine [name] [desc] [build-by-default] [subengines] [base games] [deps] +add_engine cruise "Cinematique evo 2" yes diff --git a/engines/cruise/cruise.cpp b/engines/cruise/cruise.cpp index 2147419886..eebd8fdc15 100644 --- a/engines/cruise/cruise.cpp +++ b/engines/cruise/cruise.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -50,6 +50,15 @@ CruiseEngine::CruiseEngine(OSystem * syst, const CRUISEGameDescription *gameDesc _debugger = new Debugger(); _sound = new PCSound(_mixer, this); + PCFadeFlag = false; + _preLoad = false; + _savedCursor = CURSOR_NOMOUSE; + _lastTick = 0; + _gameSpeed = GAME_FRAME_DELAY_1; + _speedFlag = false; + _polyStructs = nullptr; + _polyStruct = nullptr; + // Setup mixer syncSoundSettings(); } @@ -87,9 +96,6 @@ Common::Error CruiseEngine::run() { Cruise::changeCursor(Cruise::CURSOR_NORMAL); CursorMan.showMouse(true); - lastTick = 0; - lastTickDebug = 0; - mainLoop(); deinitialize(); @@ -98,24 +104,12 @@ Common::Error CruiseEngine::run() { } void CruiseEngine::initialize() { - PCFadeFlag = 0; - _gameSpeed = GAME_FRAME_DELAY_1; - _speedFlag = false; - - /*volVar1 = 0; - * fileData1 = 0; */ - - /*PAL_fileHandle = -1; */ - // video init stuff - initSystem(); gfxModuleData_Init(); // another bit of video init - readVolCnf(); - _vm->_polyStruct = NULL; } void CruiseEngine::deinitialize() { diff --git a/engines/cruise/cruise.h b/engines/cruise/cruise.h index 3e49e77770..8624ba693e 100644 --- a/engines/cruise/cruise.h +++ b/engines/cruise/cruise.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -60,7 +60,7 @@ private: PCSound *_sound; Common::StringArray _langStrings; CursorType _savedCursor; - uint32 lastTick, lastTickDebug; + uint32 _lastTick; int _gameSpeed; bool _speedFlag; diff --git a/engines/cruise/cruise_main.cpp b/engines/cruise/cruise_main.cpp index 911041c1a4..2de8d273f7 100644 --- a/engines/cruise/cruise_main.cpp +++ b/engines/cruise/cruise_main.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -35,10 +35,10 @@ namespace Cruise { enum RelationType {RT_REL = 30, RT_MSG = 50}; -static int playerDontAskQuit; +static bool _playerDontAskQuit; unsigned int timer = 0; -gfxEntryStruct* linkedMsgList = NULL; +gfxEntryStruct *linkedMsgList = nullptr; typedef CruiseEngine::MemInfo MemInfo; @@ -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,9 +157,9 @@ 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) { - strcpy(exportName, arraySymbGlob[i].offsetToName + exportNamePtr); + Common::strlcpy(exportName, arraySymbGlob[i].offsetToName + exportNamePtr, sizeof(exportName)); if (!strcmp(exportName, name)) { return (arraySymbGlob[i].idx); @@ -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"); @@ -371,7 +364,7 @@ int loadFileSub1(uint8 **ptr, const char *name, uint8 *ptr2) { * strcatuint8(buffer,".HP"); * } */ } else { - strcpy(buffer, name); + Common::strlcpy(buffer, name, sizeof(buffer)); } fileIdx = findFileInDisks(buffer); @@ -434,14 +427,12 @@ void resetFileEntry(int32 entryNumber) { } uint8 *mainProc14(uint16 overlay, uint16 idx) { - ASSERT(0); + assert(0); return NULL; } 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; } @@ -653,8 +642,7 @@ int findObject(int mouseX, int mouseY, int *outObjOvl, int *outObjIdx) { (currentObject->type == OBJ_TYPE_SPRITE || currentObject->type == OBJ_TYPE_MASK || currentObject->type == OBJ_TYPE_EXIT || currentObject->type == OBJ_TYPE_VIRTUAL)) { const char* pObjectName = getObjectName(currentObject->idx, overlayTable[currentObject->overlay].ovlData->arrayNameObj); - - strcpy(objectName, pObjectName); + Common::strlcpy(objectName, pObjectName, sizeof(objectName)); if (strlen(objectName) && (currentObject->freeze == 0)) { int objIdx = currentObject->idx; @@ -863,7 +851,6 @@ bool createDialog(int objOvl, int objIdx, int x, int y) { bool found = false; int testState1 = -1; int testState2 = -1; - int j; int16 objectState; int16 objectState2; @@ -871,7 +858,7 @@ bool createDialog(int objOvl, int objIdx, int x, int y) { menuTable[0] = createMenu(x, y, _vm->langString(ID_SPEAK_ABOUT)); - for (j = 1; j < numOfLoadedOverlay; j++) { + for (int j = 1; j < numOfLoadedOverlay; j++) { if (overlayTable[j].alreadyLoaded) { int idHeader = overlayTable[j].ovlData->numMsgRelHeader; @@ -895,24 +882,26 @@ bool createDialog(int objOvl, int objIdx, int x, int y) { } if ((thisOvl == objOvl) && (ptrHead->obj2Number == objIdx)) { - int verbeOvl = ptrHead->verbOverlay; + int verbOvl = ptrHead->verbOverlay; int obj1Ovl = ptrHead->obj1Overlay; int obj2Ovl = ptrHead->obj2Overlay; - if (!verbeOvl) verbeOvl = j; - if (!obj1Ovl) obj1Ovl = j; - if (!obj2Ovl) obj2Ovl = j; + if (!verbOvl) + verbOvl = j; + if (!obj1Ovl) + obj1Ovl = j; + if (!obj2Ovl) + obj2Ovl = j; - char verbe_name[80]; - - verbe_name[0] = 0; + char verbName[80]; + verbName[0] = 0; ovlDataStruct *ovl2 = NULL; ovlDataStruct *ovl3 = NULL; ovlDataStruct *ovl4 = NULL; - if (verbeOvl > 0) - ovl2 = overlayTable[verbeOvl].ovlData; + if (verbOvl > 0) + ovl2 = overlayTable[verbOvl].ovlData; if (obj1Ovl > 0) ovl3 = overlayTable[obj1Ovl].ovlData; @@ -920,21 +909,21 @@ bool createDialog(int objOvl, int objIdx, int x, int y) { if (obj2Ovl > 0) ovl4 = overlayTable[obj2Ovl].ovlData; - if ((ovl3) && (ptrHead->obj1Number >= 0)) { + if (ovl3 && (ptrHead->obj1Number >= 0)) { testState1 = ptrHead->obj1OldState; } - if ((ovl4) && (ptrHead->obj2Number >= 0)) { + if (ovl4 && (ptrHead->obj2Number >= 0)) { testState2 = ptrHead->obj2OldState; } - if ((ovl4) && (ptrHead->verbNumber >= 0) && + if (ovl4 && ovl2 && (ptrHead->verbNumber >= 0) && ((testState1 == -1) || (testState1 == objectState2)) && ((testState2 == -1) || (testState2 == objectState))) { if (ovl2->nameVerbGlob) { const char *ptr = getObjectName(ptrHead->verbNumber, ovl2->nameVerbGlob); - strcpy(verbe_name, ptr); + Common::strlcpy(verbName, ptr, sizeof(verbName)); - if (!strlen(verbe_name)) + if (!strlen(verbName)) attacheNewScriptToTail(&relHead, j, ptrHead->id, 30, currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, scriptType_REL); else if (ovl2->nameVerbGlob) { found = true; @@ -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; @@ -985,23 +973,27 @@ bool findRelation(int objOvl, int objIdx, int x, int y) { objDataStruct* pObject = getObjectDataFromOverlay(thisOvl, ptrHead->obj1Number); if ((thisOvl == objOvl) && (objIdx == ptrHead->obj1Number) && pObject && (pObject->_class != THEME)) { - int verbeOvl = ptrHead->verbOverlay; + int verbOvl = ptrHead->verbOverlay; int obj1Ovl = ptrHead->obj1Overlay; - int obj2Ovl = ptrHead->obj2Overlay; + // Unused variable + // int obj2Ovl = ptrHead->obj2Overlay; - if (!verbeOvl) verbeOvl = j; - if (!obj1Ovl) obj1Ovl = j; - if (!obj2Ovl) obj2Ovl = j; + if (!verbOvl) + verbOvl = j; + if (!obj1Ovl) + obj1Ovl = j; + // Unused variable + // if (!obj2Ovl) + // obj2Ovl = j; - char verbe_name[80]; - verbe_name[0] = 0; + char verbName[80]; + verbName[0] = 0; ovlDataStruct *ovl2 = NULL; ovlDataStruct *ovl3 = NULL; - //ovlDataStruct *ovl4 = NULL; - if (verbeOvl > 0) - ovl2 = overlayTable[verbeOvl].ovlData; + if (verbOvl > 0) + ovl2 = overlayTable[verbOvl].ovlData; if (obj1Ovl > 0) ovl3 = overlayTable[obj1Ovl].ovlData; @@ -1022,10 +1014,10 @@ bool findRelation(int objOvl, int objIdx, int x, int y) { if ((ovl2) && (ptrHead->verbNumber >= 0)) { if (ovl2->nameVerbGlob) { const char *ptr = getObjectName(ptrHead->verbNumber, ovl2->nameVerbGlob); - strcpy(verbe_name, ptr); + Common::strlcpy(verbName, ptr, sizeof(verbName)); if ((!first) && ((testState == -1) || (testState == objectState))) { - if (!strlen(verbe_name)) { + if (!strlen(verbName)) { if (currentScriptPtr) { attacheNewScriptToTail(&relHead, j, ptrHead->id, 30, currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, scriptType_REL); } else { @@ -1088,9 +1080,6 @@ void callSubRelation(menuElementSubStruct *pMenuElement, int nOvl, int nObj) { } if ((obj2Ovl == nOvl) && (pHeader->obj2Number != -1) && (pHeader->obj2Number == nObj)) { - int x = 60; - int y = 60; - objectParamsQuery params; memset(¶ms, 0, sizeof(objectParamsQuery)); // to remove warning @@ -1138,6 +1127,8 @@ void callSubRelation(menuElementSubStruct *pMenuElement, int nOvl, int nObj) { } } } else if (pHeader->type == RT_MSG) { + int x = 60; + int y = 60; if (pHeader->obj2Number >= 0) { if ((pHeader->trackX !=-1) && (pHeader->trackY !=-1) && @@ -1166,7 +1157,7 @@ void callSubRelation(menuElementSubStruct *pMenuElement, int nOvl, int nObj) { createTextObject(&cellHead, ovlIdx, pHeader->id, x, y, 200, findHighColor(), masterScreen, 0, 0); } - userWait = 1; + userWait = true; autoOvl = ovlIdx; autoMsg = pHeader->id; @@ -1195,7 +1186,7 @@ void callSubRelation(menuElementSubStruct *pMenuElement, int nOvl, int nObj) { pTrack->flag = 1; autoTrack = true; - userWait = 0; + userWait = false; userEnabled = 0; freezeCell(&cellHead, ovlIdx, pHeader->id, 5, -1, 0, 9998); } @@ -1312,7 +1303,7 @@ void callRelation(menuElementSubStruct *pMenuElement, int nObj2) { createTextObject(&cellHead, ovlIdx, pHeader->id, x, y, 200, findHighColor(), masterScreen, 0, 0); } - userWait = 1; + userWait = true; autoOvl = ovlIdx; autoMsg = pHeader->id; @@ -1343,7 +1334,7 @@ void callRelation(menuElementSubStruct *pMenuElement, int nObj2) { pTrack->flag = 1; autoTrack = true; - userWait = 0; + userWait = false; userEnabled = 0; freezeCell(&cellHead, ovlIdx, pHeader->id, 5, -1, 0, 9998); } @@ -1368,7 +1359,7 @@ void closeAllMenu() { menuTable[1] = NULL; } if (linkedMsgList) { - ASSERT(0); + assert(0); // freeMsgList(linkedMsgList); } @@ -1464,7 +1455,7 @@ int CruiseEngine::processInput() { if (userWait) { // Check for left mouse button click or Space to end user waiting if ((keyboardCode == Common::KEYCODE_SPACE) || (button == CRS_MB_LEFT)) - userWait = 0; + userWait = false; keyboardCode = Common::KEYCODE_INVALID; return 0; @@ -1523,7 +1514,7 @@ int CruiseEngine::processInput() { menuTable[0] = NULL; if (linkedMsgList) { - ASSERT(0); + assert(0); // freeMsgList(linkedMsgList); } @@ -1715,7 +1706,7 @@ bool manageEvents() { break; case Common::EVENT_QUIT: case Common::EVENT_RTL: - playerDontAskQuit = 1; + _playerDontAskQuit = true; break; case Common::EVENT_KEYUP: switch (event.kbd.keycode) { @@ -1781,16 +1772,12 @@ void CruiseEngine::mainLoop() { currentActiveMenu = -1; autoMsg = -1; linkedRelation = 0; - main21 = 0; - main22 = 0; - userWait = 0; + userWait = false; autoTrack = false; initAllData(); - playerDontAskQuit = 0; - int quitValue2 = 1; - int quitValue = 0; + _playerDontAskQuit = false; if (ConfMan.hasKey("save_slot")) loadGameState(ConfMan.getInt("save_slot")); @@ -1840,23 +1827,20 @@ void CruiseEngine::mainLoop() { if (!skipEvents || bFastMode) skipEvents = manageEvents(); - if (bFastMode) { - if (currentTick >= (lastTickDebug + 10)) - lastTickDebug = currentTick; - } else { + if (!bFastMode) { g_system->delayMillis(10); currentTick = g_system->getMillis(); } - if (playerDontAskQuit) + if (_playerDontAskQuit) break; _vm->getDebugger()->onFrame(); - } while (currentTick < lastTick + _gameSpeed && !bFastMode); - if (playerDontAskQuit) + } while (currentTick < _lastTick + _gameSpeed && !bFastMode); + if (_playerDontAskQuit) break; - lastTick = g_system->getMillis(); + _lastTick = g_system->getMillis(); // Handle switchover in game speed after intro if (!_speedFlag && canLoadGameStateCurrently()) { @@ -1871,7 +1855,7 @@ void CruiseEngine::mainLoop() { // readKeyboard(); - bool isUserWait = userWait != 0; + bool isUserWait = userWait; // WORKAROUND: This prevents hotspots responding during // delays i.e. Menu opening if you click fast on another // hotspot after trying to open a locked door, which @@ -1880,8 +1864,8 @@ void CruiseEngine::mainLoop() { currentMouseButton = 0; } - playerDontAskQuit = processInput(); - if (playerDontAskQuit) + _playerDontAskQuit = processInput(); + if (_playerDontAskQuit) break; if (enableUser) { @@ -1906,11 +1890,10 @@ void CruiseEngine::mainLoop() { // Raoul appearing when looking at the book is being there are 3 script iterations separation between the // scene being changed to the book, and the Raoul actor being frozen/disabled. This loop is a hack to ensure // that does a few extra script executions for that scene - bool bgChanged; int numIterations = 1; while (numIterations-- > 0) { - bgChanged = backgroundChanged[masterScreen]; + bool bgChanged = backgroundChanged[masterScreen]; manageScripts(&relHead); manageScripts(&procHead); @@ -1928,7 +1911,7 @@ void CruiseEngine::mainLoop() { processAnimation(); if (remdo) { - // ASSERT(0); + // assert(0); /* main3 = 0; * var24 = 0; * var23 = 0; @@ -1937,7 +1920,7 @@ void CruiseEngine::mainLoop() { } if (cmdLine[0]) { - ASSERT(0); + assert(0); /* redrawStrings(0,&cmdLine,8); waitForPlayerInput(); @@ -1947,13 +1930,13 @@ void CruiseEngine::mainLoop() { if (displayOn) { if (doFade) - PCFadeFlag = 0; + PCFadeFlag = false; /*if (!PCFadeFlag)*/ mainDraw(userWait); flipScreen(); - if (userWait == 1) { + if (userWait) { // Waiting for press - original wait loop has been integrated into the // main event loop continue; @@ -1968,7 +1951,7 @@ void CruiseEngine::mainLoop() { char* pText = getText(autoMsg, autoOvl); if (strlen(pText)) - userWait = 1; + userWait = true; } changeScriptParamInList(-1, -1, &relHead, 9998, 0); @@ -1986,7 +1969,7 @@ void CruiseEngine::mainLoop() { g_system->updateScreen(); } - } while (!playerDontAskQuit && quitValue2 && quitValue != 7); + } while (!_playerDontAskQuit); // Free data removeAllScripts(&relHead); diff --git a/engines/cruise/cruise_main.h b/engines/cruise/cruise_main.h index 9afae4336b..f9d0e2fc78 100644 --- a/engines/cruise/cruise_main.h +++ b/engines/cruise/cruise_main.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -62,9 +62,6 @@ enum MouseButton { /*#define DUMP_SCRIPT #define DUMP_OBJECT*/ -#define ASSERT_PTR assert -#define ASSERT assert - enum ResType { OBJ_TYPE_LINE = 0, OBJ_TYPE_MASK = 1, diff --git a/engines/cruise/ctp.cpp b/engines/cruise/ctp.cpp index a7b6faec1c..9515b552e1 100644 --- a/engines/cruise/ctp.cpp +++ b/engines/cruise/ctp.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -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; } @@ -245,7 +244,7 @@ int initCt(const char *ctpName) { } // get the path-finding coordinates - ASSERT((segementSizeTable[0] % 4) == 0); + assert((segementSizeTable[0] % 4) == 0); for (int i = 0; i < segementSizeTable[0] / 4; i++) { ctp_routeCoords[i][0] = (int16)READ_BE_UINT16(dataPointer); dataPointer += 2; @@ -254,7 +253,7 @@ int initCt(const char *ctpName) { } // get the path-finding line informations (indexing the routeCoords array) - ASSERT((segementSizeTable[1] % 20) == 0); + assert((segementSizeTable[1] % 20) == 0); for (int i = 0; i < segementSizeTable[1] / 20; i++) { for (int j = 0; j < 10; j++) { ctp_routes[i][j] = (int16)READ_BE_UINT16(dataPointer); @@ -263,7 +262,7 @@ int initCt(const char *ctpName) { } // read polygons - ASSERT((segementSizeTable[2] % 80) == 0); + assert((segementSizeTable[2] % 80) == 0); for (int i = 0; i < segementSizeTable[2] / 80; i++) { for (int j = 0; j < 40; j++) { ctp_walkboxTable[i][j] = (int16)READ_BE_UINT16(dataPointer); @@ -278,14 +277,14 @@ int initCt(const char *ctpName) { } else { // get the walkbox type // Type: 0x00 - non walkable, 0x01 - walkable, 0x02 - exit zone - ASSERT((segementSizeTable[3] % 2) == 0); + assert((segementSizeTable[3] % 2) == 0); for (int i = 0; i < segementSizeTable[3] / 2; i++) { walkboxColor[i] = (int16)READ_BE_UINT16(dataPointer); dataPointer += 2; } // change indicator, walkbox type can change, i.e. blocked by object (values are either 0x00 or 0x01) - ASSERT((segementSizeTable[4] % 2) == 0); + assert((segementSizeTable[4] % 2) == 0); for (int i = 0; i < segementSizeTable[4] / 2; i++) { walkboxState[i] = (int16)READ_BE_UINT16(dataPointer); dataPointer += 2; @@ -293,14 +292,14 @@ int initCt(const char *ctpName) { } // - ASSERT((segementSizeTable[5] % 2) == 0); + assert((segementSizeTable[5] % 2) == 0); for (int i = 0; i < segementSizeTable[5] / 2; i++) { walkboxColorIndex[i] = (int16)READ_BE_UINT16(dataPointer); dataPointer += 2; } // - ASSERT((segementSizeTable[6] % 2) == 0); + assert((segementSizeTable[6] % 2) == 0); for (int i = 0; i < segementSizeTable[6] / 2; i++) { walkboxZoom[i] = (int16)READ_BE_UINT16(dataPointer); dataPointer += 2; diff --git a/engines/cruise/ctp.h b/engines/cruise/ctp.h index 340832e6fb..93f7466c52 100644 --- a/engines/cruise/ctp.h +++ b/engines/cruise/ctp.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/dataLoader.cpp b/engines/cruise/dataLoader.cpp index b2a319bb85..7a1258dbde 100644 --- a/engines/cruise/dataLoader.cpp +++ b/engines/cruise/dataLoader.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -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; } @@ -225,7 +225,7 @@ fileTypeEnum getFileType(const char *name) { newFileType = type_FNT; } - ASSERT(newFileType != type_UNK); + assert(newFileType != type_UNK); return newFileType; } @@ -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; - - numMaxEntriesInSet = getNumMaxEntiresInSet(ptr); // get maximum number of sprites/animations in SET file + int 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); } @@ -356,39 +352,32 @@ int loadFullBundle(const char *name, int startIdx) { } int loadFNTSub(uint8 *ptr, int destIdx) { - uint8 *ptr2 = ptr; - uint8 *destPtr; - int fileIndex; - //uint32 fontSize; - - ptr2 += 4; + uint8 *ptr2 = ptr + 4; loadFileVar1 = READ_BE_UINT32(ptr2); - if (destIdx == -1) { + int fileIndex; + if (destIdx == -1) fileIndex = createResFileEntry(loadFileVar1, 1, loadFileVar1, 1); - } else { + else fileIndex = updateResFileEntry(loadFileVar1, 1, loadFileVar1, destIdx, 1); - } - destPtr = filesDatabase[fileIndex].subData.ptr; + if (fileIndex < 0) + error("Unable to load FNT resource"); - if (destPtr != NULL) { - int32 i; - uint8 *currentPtr; + uint8 *destPtr = filesDatabase[fileIndex].subData.ptr; + if (destPtr != NULL) { memcpy(destPtr, ptr2, loadFileVar1); - //fontSize = READ_BE_UINT32(ptr2); - destPtr = filesDatabase[fileIndex].subData.ptr; bigEndianLongToNative((int32 *) destPtr); bigEndianLongToNative((int32 *)(destPtr + 4)); flipGen(destPtr + 8, 6); - currentPtr = destPtr + 14; + uint8 *currentPtr = destPtr + 14; - for (i = 0; i < (int16)READ_UINT16(destPtr + 8); i++) { + for (int i = 0; i < (int16)READ_UINT16(destPtr + 8); i++) { bigEndianLongToNative((int32 *) currentPtr); currentPtr += 4; @@ -401,16 +390,17 @@ int loadFNTSub(uint8 *ptr, int destIdx) { } int loadSPLSub(uint8 *ptr, int destIdx) { - uint8 *destPtr; int fileIndex; - if (destIdx == -1) { + if (destIdx == -1) fileIndex = createResFileEntry(loadFileVar1, 1, loadFileVar1, 1); - } else { + else fileIndex = updateResFileEntry(loadFileVar1, 1, loadFileVar1, destIdx, 1); - } - destPtr = filesDatabase[fileIndex].subData.ptr; + if (fileIndex < 0) + error("Unable to load SPL resource"); + + uint8* destPtr = filesDatabase[fileIndex].subData.ptr; memcpy(destPtr, ptr, loadFileVar1); return 1; @@ -423,135 +413,119 @@ int loadSetEntry(const char *name, uint8 *ptr, int currentEntryIdx, int currentD int sec = 0; uint16 numIdx; - if (!strcmp((char *)ptr, "SEC")) { + if (!strcmp((char *)ptr, "SEC")) sec = 1; - } numIdx = READ_BE_UINT16(ptr + 4); - ptr3 = ptr + 6; - offset = currentEntryIdx * 16; - { - int resourceSize; - int fileIndex; - setHeaderEntry localBuffer; - uint8 *ptr5; - - Common::MemoryReadStream s4(ptr + offset + 6, 16); + int resourceSize; + int fileIndex; + setHeaderEntry localBuffer; - localBuffer.offset = s4.readUint32BE(); - localBuffer.width = s4.readUint16BE(); - localBuffer.height = s4.readUint16BE(); - localBuffer.type = s4.readUint16BE(); - localBuffer.transparency = s4.readUint16BE() & 0x1F; - localBuffer.hotspotY = s4.readUint16BE(); - localBuffer.hotspotX = s4.readUint16BE(); + Common::MemoryReadStream s4(ptr + offset + 6, 16); - if (sec == 1) - // Type 1: Width - (1*2) , Type 5: Width - (5*2) - localBuffer.width -= localBuffer.type * 2; + localBuffer.offset = s4.readUint32BE(); + localBuffer.width = s4.readUint16BE(); + localBuffer.height = s4.readUint16BE(); + localBuffer.type = s4.readUint16BE(); + localBuffer.transparency = s4.readUint16BE() & 0x1F; + localBuffer.hotspotY = s4.readUint16BE(); + localBuffer.hotspotX = s4.readUint16BE(); - resourceSize = localBuffer.width * localBuffer.height; + if (sec == 1) + // Type 1: Width - (1*2) , Type 5: Width - (5*2) + localBuffer.width -= localBuffer.type * 2; - if (!sec && (localBuffer.type == 5)) - // Type 5: Width - (2*5) - localBuffer.width -= 10; + resourceSize = localBuffer.width * localBuffer.height; - if (currentDestEntry == -1) { - fileIndex = createResFileEntry(localBuffer.width, localBuffer.height, resourceSize, localBuffer.type); - } else { - fileIndex = updateResFileEntry(localBuffer.height, localBuffer.width, resourceSize, currentDestEntry, localBuffer.type); - } + if (!sec && (localBuffer.type == 5)) + // Type 5: Width - (2*5) + localBuffer.width -= 10; - if (fileIndex < 0) { - return -1; // TODO: buffer is not freed - } - - if (!sec && (localBuffer.type == 5)) { - // There are sometimes sprites with a reduced width than what their pixels provide. - // The original handled this here by copy parts of each line - for ScummVM, we're - // simply setting the width in bytes and letting the decoder do the rest - filesDatabase[fileIndex].width += 2; - } + if (currentDestEntry == -1) + fileIndex = createResFileEntry(localBuffer.width, localBuffer.height, resourceSize, localBuffer.type); + else + fileIndex = updateResFileEntry(localBuffer.height, localBuffer.width, resourceSize, currentDestEntry, localBuffer.type); - ptr5 = ptr3 + localBuffer.offset + numIdx * 16; + if (fileIndex < 0) + return -1; // TODO: buffer is not freed - memcpy(filesDatabase[fileIndex].subData.ptr, ptr5, resourceSize); + if (!sec && (localBuffer.type == 5)) { + // There are sometimes sprites with a reduced width than what their pixels provide. + // The original handled this here by copy parts of each line - for ScummVM, we're + // simply setting the width in bytes and letting the decoder do the rest + filesDatabase[fileIndex].width += 2; + } - ptr5 += resourceSize; + uint8 *ptr5 = ptr3 + localBuffer.offset + numIdx * 16; + memcpy(filesDatabase[fileIndex].subData.ptr, ptr5, resourceSize); - switch (localBuffer.type) { - case 0: { // polygon + switch (localBuffer.type) { + case 0: // polygon filesDatabase[fileIndex].subData.resourceType = OBJ_TYPE_POLY; filesDatabase[fileIndex].subData.index = currentEntryIdx; break; - } - case 1: { + + case 1: filesDatabase[fileIndex].width = filesDatabase[fileIndex].widthInColumn * 8; filesDatabase[fileIndex].subData.resourceType = OBJ_TYPE_BGMASK; decodeGfxUnified(&filesDatabase[fileIndex], localBuffer.type); filesDatabase[fileIndex].subData.index = currentEntryIdx; filesDatabase[fileIndex].subData.transparency = 0; break; - } - case 4: { + + case 4: filesDatabase[fileIndex].width = filesDatabase[fileIndex].widthInColumn * 2; filesDatabase[fileIndex].subData.resourceType = OBJ_TYPE_SPRITE; decodeGfxUnified(&filesDatabase[fileIndex], localBuffer.type); filesDatabase[fileIndex].subData.index = currentEntryIdx; filesDatabase[fileIndex].subData.transparency = localBuffer.transparency % 0x10; break; - } - case 5: { + + case 5: filesDatabase[fileIndex].subData.resourceType = OBJ_TYPE_SPRITE; decodeGfxUnified(&filesDatabase[fileIndex], localBuffer.type); filesDatabase[fileIndex].width = filesDatabase[fileIndex].widthInColumn; filesDatabase[fileIndex].subData.index = currentEntryIdx; filesDatabase[fileIndex].subData.transparency = localBuffer.transparency; break; - } - case 8: { + + case 8: filesDatabase[fileIndex].subData.resourceType = OBJ_TYPE_SPRITE; filesDatabase[fileIndex].width = filesDatabase[fileIndex].widthInColumn; filesDatabase[fileIndex].subData.index = currentEntryIdx; filesDatabase[fileIndex].subData.transparency = localBuffer.transparency; break; - } - default: { - warning("Unsuported gfx loading type: %d", localBuffer.type); + + default: + warning("Unsupported gfx loading type: %d", localBuffer.type); break; - } - } + } - if (name != filesDatabase[fileIndex].subData.name) - strcpy(filesDatabase[fileIndex].subData.name, name); + if (name != filesDatabase[fileIndex].subData.name) + Common::strlcpy(filesDatabase[fileIndex].subData.name, name, sizeof(filesDatabase[fileIndex].subData.name)); - // create the mask - switch (localBuffer.type) { + // create the mask + switch (localBuffer.type) { case 1: case 4: case 5: - case 8: { - int maskX; - int maskY; - + case 8: memset(filesDatabase[fileIndex].subData.ptrMask, 0, filesDatabase[fileIndex].width / 8 * filesDatabase[fileIndex].height); - for (maskY = 0; maskY < filesDatabase[fileIndex].height; maskY++) { - for (maskX = 0; maskX < filesDatabase[fileIndex].width; maskX++) { + for (int maskY = 0; maskY < filesDatabase[fileIndex].height; maskY++) { + for (int maskX = 0; maskX < filesDatabase[fileIndex].width; maskX++) { if (*(filesDatabase[fileIndex].subData.ptr + filesDatabase[fileIndex].width * maskY + maskX) != filesDatabase[fileIndex].subData.transparency) { *(filesDatabase[fileIndex].subData.ptrMask + filesDatabase[fileIndex].width / 8 * maskY + maskX / 8) |= 0x80 >> (maskX & 7); } } } + break; + default: break; - } - default: { - } - } } // TODO: free diff --git a/engines/cruise/dataLoader.h b/engines/cruise/dataLoader.h index 96188c7982..cf19145beb 100644 --- a/engines/cruise/dataLoader.h +++ b/engines/cruise/dataLoader.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/debugger.cpp b/engines/cruise/debugger.cpp index a74f600ddd..d4e706a094 100644 --- a/engines/cruise/debugger.cpp +++ b/engines/cruise/debugger.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -29,9 +29,9 @@ namespace Cruise { Debugger::Debugger(): GUI::Debugger() { - DCmd_Register("continue", WRAP_METHOD(Debugger, Cmd_Exit)); - DCmd_Register("hotspots", WRAP_METHOD(Debugger, cmd_hotspots)); - DCmd_Register("items", WRAP_METHOD(Debugger, cmd_items)); + registerCmd("continue", WRAP_METHOD(Debugger, cmdExit)); + registerCmd("hotspots", WRAP_METHOD(Debugger, cmd_hotspots)); + registerCmd("items", WRAP_METHOD(Debugger, cmd_items)); } /** @@ -70,7 +70,7 @@ bool Debugger::cmd_hotspots(int argc, const char **argv) { if (*pObjectName) { getMultipleObjectParam(currentObject->overlay, currentObject->idx, ¶ms); - DebugPrintf("%s %s - %d,%d\n", pObjectName, pObjType, params.X, params.Y); + debugPrintf("%s %s - %d,%d\n", pObjectName, pObjType, params.X, params.Y); } } @@ -96,7 +96,7 @@ bool Debugger::cmd_items(int argc, const char **argv) { getSingleObjectParam(i, j, 5, &returnVar); if (returnVar < -1) - DebugPrintf("%s\n", getObjectName(j, pOvlData->arrayNameObj)); + debugPrintf("%s\n", getObjectName(j, pOvlData->arrayNameObj)); } } } diff --git a/engines/cruise/debugger.h b/engines/cruise/debugger.h index 3cef6b371d..a79773f37e 100644 --- a/engines/cruise/debugger.h +++ b/engines/cruise/debugger.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/decompiler.cpp b/engines/cruise/decompiler.cpp index 74a78201bc..7691a1bba7 100644 --- a/engines/cruise/decompiler.cpp +++ b/engines/cruise/decompiler.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -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, @@ -495,7 +491,7 @@ int decompOpcodeType2() { char buffer3[256]; char varName[256]; int byte1 = getByteFromDecompScriptReal(); - int byte2 = getByteFromDecompScriptReal(); + getByteFromDecompScriptReal(); getShortFromDecompScript(buffer3); resolveVarName("0", byte1 & 7, buffer3, varName); @@ -506,7 +502,7 @@ int decompOpcodeType2() { } case 5: { int byte1 = getByteFromDecompScriptReal(); - int byte2 = getByteFromDecompScriptReal(); + getByteFromDecompScriptReal(); short int short1 = getShortFromDecompScriptReal(); int8 *ptr = scriptDataPtrTable[byte1 & 7] + short1; @@ -559,7 +555,7 @@ int decompMath() { break; } case 4: { - sprintf(tempbuffer, "%s\%%s", param1, param2); + sprintf(tempbuffer, "%s % %s", param1, param2); pushDecomp(tempbuffer); break; } @@ -701,49 +697,41 @@ int decompSwapStack() { int decompFunction() { currentScriptOpcodeType = getByteFromDecompScriptReal(); -// addDecomp("OP_%X", currentScriptOpcodeType); switch (currentScriptOpcodeType) { - case 0x1: { - pushDecomp("_setdoFade()"); + case 0x1: + pushDecomp("Op_FadeIn()"); break; - } - case 0x2: { - pushDecomp("_prepareFade()"); + + case 0x2: + pushDecomp("Op_FadeOut()"); break; - } - case 0x3: { - sprintf(tempbuffer, "_loadBackground(%s,%s)", - popDecomp(), popDecomp()); + + case 0x3: + sprintf(tempbuffer, "Op_loadBackground(%s,%s)", popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x4: { - sprintf(tempbuffer, "_loadFullBundle(%s,%s)", - popDecomp(), popDecomp()); + + case 0x4: + sprintf(tempbuffer, "Op_LoadAbs(%s,%s)", popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x5: { - sprintf(tempbuffer, "_addCell(%s,%s,%s)", popDecomp(), - popDecomp(), popDecomp()); + + case 0x5: + sprintf(tempbuffer, "Op_AddCell(%s,%s,%s)", popDecomp(), popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } + case 0x6: { unsigned long int numArg = atoi(popDecomp()); - char *ovlStr; - char *idxStr; - int i; char functionName[100]; - idxStr = popDecomp(); - ovlStr = popDecomp(); + char *idxStr = popDecomp(); + char *ovlStr = popDecomp(); resolveVarName(ovlStr, 0x20, idxStr, functionName); + sprintf(tempbuffer, "Op_AddProc(%s", functionName); - sprintf(tempbuffer, "_startASync(%s", functionName); - - for (i = 0; i < numArg; i++) { + for (int i = 0; i < numArg; i++) { strcatuint8(tempbuffer, ","); strcatuint8(tempbuffer, popDecomp()); } @@ -752,196 +740,165 @@ int decompFunction() { pushDecomp(tempbuffer); break; - } - case 0x7: { - char *var1; - char *objIdxStr; - char *ovlStr; + } - var1 = popDecomp(); - objIdxStr = popDecomp(); - ovlStr = popDecomp(); + case 0x7: { + char *var1 = popDecomp(); + char *objIdxStr = popDecomp(); + char *ovlStr = popDecomp(); - sprintf(tempbuffer, - "_createObjectFromOvlData(ovl:%s,dataIdx:%s,%s)", - ovlStr, objIdxStr, var1); + sprintf(tempbuffer, "Op_InitializeState(ovl:%s,dataIdx:%s,%s)", ovlStr, objIdxStr, var1); pushDecomp(tempbuffer); break; - } - case 0x8: { - sprintf(tempbuffer, "_removeCell(%s,%s,%s)", - popDecomp(), popDecomp(), popDecomp()); + } + + case 0x8: + sprintf(tempbuffer, "Op_RemoveCell(%s,%s,%s)", popDecomp(), popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x9: { - pushDecomp("_freeobjectList()"); + + case 0x9: + pushDecomp("Op_FreeCell()"); break; - } - case 0xA: { - sprintf(tempbuffer, "_removeScript(ovl(%s),%s)", - popDecomp(), popDecomp()); + + case 0xA: + sprintf(tempbuffer, "Op_RemoveProc(ovl(%s),%s)", popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0xB: { - sprintf(tempbuffer, "_resetFilesEntries(%s,%s)", - popDecomp(), popDecomp()); + + case 0xB: + sprintf(tempbuffer, "Op_RemoveFrame(%s,%s)", popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0xC: { - sprintf(tempbuffer, "_loadOverlay(%s)", popDecomp()); + + case 0xC: + sprintf(tempbuffer, "Op_LoadOverlay(%s)", popDecomp()); pushDecomp(tempbuffer); break; - } - case 0xD: { - sprintf(tempbuffer, "_palManipulation(%s,%s,%s,%s,%s)", - popDecomp(), popDecomp(), popDecomp(), popDecomp(), - popDecomp()); + + case 0xD: + sprintf(tempbuffer, "Op_SetColor(%s,%s,%s,%s,%s)", popDecomp(), popDecomp(), popDecomp(), popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0xE: { - sprintf(tempbuffer, "_playSample(%s,%s,%s,%s)", - popDecomp(), popDecomp(), popDecomp(), - popDecomp()); + + case 0xE: + sprintf(tempbuffer, "Op_PlayFX(%s,%s,%s,%s)", popDecomp(), popDecomp(), popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x10: { - sprintf(tempbuffer, "_releaseScript2(%s)", - popDecomp()); + + case 0x10: + sprintf(tempbuffer, "Op_FreeOverlay(%s)", popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x11: { - sprintf(tempbuffer, "_getOverlayIdx(%s)", popDecomp()); + + case 0x11: + sprintf(tempbuffer, "Op_FindOverlay(%s)", popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x13: { - sprintf(tempbuffer, - "_displayMessage(%s,\"%s\",%s,%s,%s,%s)", - popDecomp(), resolveMessage(popDecomp()), - popDecomp(), popDecomp(), popDecomp(), - popDecomp()); + + case 0x13: + sprintf(tempbuffer, "Op_AddMessage(%s,\"%s\",%s,%s,%s,%s)", popDecomp(), + resolveMessage(popDecomp()), popDecomp(), popDecomp(), popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x14: { - sprintf(tempbuffer, "_removeObject(ovl(%s),%s)", - popDecomp(), popDecomp()); + + case 0x14: + sprintf(tempbuffer, "Op_RemoveMessage(ovl(%s),%s)", popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x15: { - pushDecomp("_pauseScript()"); + + case 0x15: + pushDecomp("Op_UserWait()"); break; - } - case 0x16: { - sprintf(tempbuffer, - "_Op_FreezeCell(%s,%s,%s,%s,%s,%s)", popDecomp(), - popDecomp(), popDecomp(), popDecomp(), popDecomp(), - popDecomp()); + + case 0x16: + sprintf(tempbuffer, "Op_FreezeCell(%s,%s,%s,%s,%s,%s)", popDecomp(), popDecomp(), + popDecomp(), popDecomp(), popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x17: { - sprintf(tempbuffer, "_loadCtp(%s)", popDecomp()); + + case 0x17: + sprintf(tempbuffer, "Op_LoadCt(%s)", popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x18: { - sprintf(tempbuffer, - "_Op_AddAnimation(%s,%s,%s,%s,%s,%s,%s)", - popDecomp(), popDecomp(), popDecomp(), popDecomp(), - popDecomp(), popDecomp(), popDecomp()); + + case 0x18: + sprintf(tempbuffer, "Op_AddAnimation(%s,%s,%s,%s,%s,%s,%s)", popDecomp(), popDecomp(), + popDecomp(), popDecomp(), popDecomp(), popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x19: { - sprintf(tempbuffer, "_Op_RemoveAnimation(%s,%s,%s)", - popDecomp(), popDecomp(), popDecomp()); + + case 0x19: + sprintf(tempbuffer, "Op_RemoveAnimation(%s,%s,%s)", popDecomp(), popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x1A: { - sprintf(tempbuffer, "_setupScaleFormula(%s,%s,%s,%s)", - popDecomp(), popDecomp(), popDecomp(), - popDecomp()); + + case 0x1A: + sprintf(tempbuffer, "Op_SetZoom(%s,%s,%s,%s)", popDecomp(), popDecomp(), popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x1E: { - sprintf(tempbuffer, "_Op_TrackAnim(%s,%s,%s,%s,%s,%s)", - popDecomp(), popDecomp(), popDecomp(), popDecomp(), - popDecomp(), popDecomp()); + + case 0x1E: + sprintf(tempbuffer, "Op_TrackAnim(%s,%s,%s,%s,%s,%s)", popDecomp(), popDecomp(), + popDecomp(), popDecomp(), popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x21: { - sprintf(tempbuffer, "_isActorLoaded(%s,%s,%s)", - popDecomp(), popDecomp(), popDecomp()); + + case 0x21: + sprintf(tempbuffer, "Op_EndAnim(%s,%s,%s)", popDecomp(), popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x22: { - sprintf(tempbuffer, "_computeScale(%s)", popDecomp()); + + case 0x22: + sprintf(tempbuffer, "Op_GetZoom(%s)", popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x23: { - sprintf(tempbuffer, "_convertToScale(%s,%s)", - popDecomp(), popDecomp()); + + case 0x23: + sprintf(tempbuffer, "Op_GetStep(%s,%s)", popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x24: { - sprintf(tempbuffer, "_op_24(%s,%s,%s,%s)", popDecomp(), - popDecomp(), popDecomp(), popDecomp()); + + case 0x24: + sprintf(tempbuffer, "Op_SetStringColors(%s,%s,%s,%s)", popDecomp(), popDecomp(), + popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x27: { - sprintf(tempbuffer, "_getWalkBoxCollision(%s,%s)", - popDecomp(), popDecomp()); + + case 0x27: + sprintf(tempbuffer, "Op_getPixel(%s,%s)", popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x28: { - sprintf(tempbuffer, "_changeSaveAllowedState(%s)", - popDecomp()); + + case 0x28: + sprintf(tempbuffer, "Op_UserOn(%s)", popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x29: { - pushDecomp("_freeAllPerso()"); + + case 0x29: + pushDecomp("Op_FreeCT()"); break; - } - case 0x2B: { - sprintf(tempbuffer, "_getProcIdx(%s,%s)", popDecomp(), - popDecomp()); + + case 0x2B: + sprintf(tempbuffer, "Op_FindProc(%s,%s)", popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x2C: { - sprintf(tempbuffer, "_setObjectPosition(%s,%s,%s)", - popDecomp(), popDecomp(), popDecomp()); + + case 0x2C: + sprintf(tempbuffer, "Op_WriteObject(%s,%s,%s)", popDecomp(), popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x2E: { - sprintf(tempbuffer, "_releaseScript(%s)", popDecomp()); + + case 0x2E: + sprintf(tempbuffer, "Op_RemoveOverlay(%s)", popDecomp()); pushDecomp(tempbuffer); break; - } - case 0x2F: { - sprintf(tempbuffer, "_addBackgroundIncrust(%s,%s,%s)", - popDecomp(), popDecomp(), popDecomp()); + + case 0x2F: + sprintf(tempbuffer, "Op_AddBackgroundIncrust(%s,%s,%s)", popDecomp(), popDecomp(), popDecomp()); pushDecomp(tempbuffer); break; - } + case 0x30: { sprintf(tempbuffer, "_removeBackgroundIncrust(%s,%s)", popDecomp(), popDecomp()); @@ -1094,7 +1051,6 @@ int decompFunction() { unsigned long int numArg = atoi(popDecomp()); char *ovlStr; char *idxStr; - int i; char functionName[256]; idxStr = popDecomp(); @@ -1104,7 +1060,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 +1130,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 +1241,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 +1255,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 +1265,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 +1281,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 +1319,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,22 +1363,18 @@ 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); - fprintf(fHandle, "else", decompileLineTable[i].line); - fprintf(fHandle, "\n"); + fprintf(fHandle, "else %s\n", decompileLineTable[i].line); } 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"); + + fprintf(fHandle, "%s\n", decompileLineTable[i].line); } fclose(fHandle); diff --git a/engines/cruise/delphine-unpack.cpp b/engines/cruise/delphine-unpack.cpp index ee7dbd3c5e..84140fb896 100644 --- a/engines/cruise/delphine-unpack.cpp +++ b/engines/cruise/delphine-unpack.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/detection.cpp b/engines/cruise/detection.cpp index bce3f184db..4ca88a08d6 100644 --- a/engines/cruise/detection.cpp +++ b/engines/cruise/detection.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -286,7 +286,7 @@ bool CruiseMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGa #if PLUGIN_ENABLED_DYNAMIC(CRUISE) -REGISTER_PLUGIN_DYNAMIC(CRUISE, PLUGIN_TYPE_ENGINE, CruiseMetaEngine); + REGISTER_PLUGIN_DYNAMIC(CRUISE, PLUGIN_TYPE_ENGINE, CruiseMetaEngine); #else -REGISTER_PLUGIN_STATIC(CRUISE, PLUGIN_TYPE_ENGINE, CruiseMetaEngine); + REGISTER_PLUGIN_STATIC(CRUISE, PLUGIN_TYPE_ENGINE, CruiseMetaEngine); #endif diff --git a/engines/cruise/font.cpp b/engines/cruise/font.cpp index 2fd86a11b7..43fbf8c79b 100644 --- a/engines/cruise/font.cpp +++ b/engines/cruise/font.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -50,7 +50,7 @@ int32 getLineHeight(int16 charCount, const FontEntry *fontPtr) { } /** - * This function determins how many lines the text will have + * This function determines how many lines the text will have */ int32 getTextLineCount(int32 rightBorder_X, int16 wordSpacingWidth, const FontEntry *fontData, const char *textString) { @@ -59,6 +59,9 @@ int32 getTextLineCount(int32 rightBorder_X, int16 wordSpacingWidth, uint8 ch; int32 total = 0, lineLength = 0; + if (rightBorder_X == 0) + error("getTextLineCount() - invalid parameter"); + if (!*textString) return (0); @@ -89,6 +92,7 @@ int32 getTextLineCount(int32 rightBorder_X, int16 wordSpacingWidth, if (lineLength > 0) total += rightBorder_X; + return (total / rightBorder_X); } @@ -148,8 +152,6 @@ void initSystem() { preloadData[i].nofree = 0; } - lowMemory = 0; - doFade = 0; fadeFlag = 0; scroll = 0; @@ -178,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/font.h b/engines/cruise/font.h index 679faf194d..12745c5b59 100644 --- a/engines/cruise/font.h +++ b/engines/cruise/font.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/function.cpp b/engines/cruise/function.cpp index 610465e962..3f794c4e70 100644 --- a/engines/cruise/function.cpp +++ b/engines/cruise/function.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -87,9 +87,7 @@ int16 Op_Exec() { int numOfArgToPop = popVar(); - int i = 0; - - for (i = 0; i < numOfArgToPop; i++) { + for (int i = 0; i < numOfArgToPop; i++) { popTable[numOfArgToPop - i - 1] = popVar(); } @@ -111,7 +109,7 @@ int16 Op_Exec() { ptr2 = ptr; - for (i = 0; i < numOfArgToPop; i++) { + for (int i = 0; i < numOfArgToPop; i++) { WRITE_BE_UINT16(ptr2, popTable[i]); ptr2 += 2; } @@ -198,13 +196,22 @@ int16 Op_Random() { int16 Op_PlayFX() { int volume = popVar(); + +#if 0 int speed = popVar(); - /*int channelNum = */popVar(); + int channelNum = popVar(); +#else + popVar(); + popVar(); +#endif + int sampleNum = popVar(); if ((sampleNum >= 0) && (sampleNum < NUM_FILE_ENTRIES) && (filesDatabase[sampleNum].subData.ptr)) { +#if 0 if (speed == -1) speed = filesDatabase[sampleNum].subData.transparency; +#endif _vm->sound().playSound(filesDatabase[sampleNum].subData.ptr, filesDatabase[sampleNum].width, volume); @@ -215,13 +222,23 @@ int16 Op_PlayFX() { int16 Op_LoopFX() { int volume = popVar(); + +#if 0 int speed = popVar(); - /*int channelNum = */popVar(); + int channelNum = popVar(); +#else + popVar(); + popVar(); +#endif + int sampleNum = popVar(); if ((sampleNum >= 0) && (sampleNum < NUM_FILE_ENTRIES) && (filesDatabase[sampleNum].subData.ptr)) { + +#if 0 if (speed == -1) speed = filesDatabase[sampleNum].subData.transparency; +#endif _vm->sound().playSound(filesDatabase[sampleNum].subData.ptr, filesDatabase[sampleNum].width, volume); @@ -335,20 +352,15 @@ int16 Op_RemoveMessage() { } int16 Op_FindSet() { - int16 i; - char name[36] = ""; - char *ptr; - - ptr = (char *) popPtr(); - - if (!ptr) { + char *ptr = (char *) popPtr(); + if (!ptr) return -1; - } - strcpy(name, ptr); + char name[36] = ""; + Common::strlcpy(name, ptr, sizeof(name)); strToUpper(name); - for (i = 0; i < NUM_FILE_ENTRIES; i++) { + for (int i = 0; i < NUM_FILE_ENTRIES; i++) { if (!strcmp(name, filesDatabase[i].subData.name)) { return (i); } @@ -397,8 +409,7 @@ int16 Op_FreeOverlay() { char *namePtr; namePtr = (char *) popPtr(); - - strcpy(localName, namePtr); + Common::strlcpy(localName, namePtr, sizeof(localName)); if (localName[0]) { strToUpper(localName); @@ -410,14 +421,10 @@ int16 Op_FreeOverlay() { int16 Op_FindProc() { char name[36] = ""; - char *ptr; - int param; - - ptr = (char *)popPtr(); - strcpy(name, ptr); - - param = getProcParam(popVar(), 20, name); + char *ptr = (char *)popPtr(); + Common::strlcpy(name, ptr, sizeof(name)); + int param = getProcParam(popVar(), 20, name); return param; } @@ -497,7 +504,7 @@ int16 Op_LoadBackground() { ptr = (char *) popPtr(); - strcpy(bgName, ptr); + Common::strlcpy(bgName, ptr, sizeof(bgName)); bgIdx = popVar(); @@ -537,12 +544,10 @@ int16 Op_LoadFrame() { int param1; int param2; int param3; - char name[36] = ""; - char *ptr; - - ptr = (char *) popPtr(); - strcpy(name, ptr); + char name[36] = ""; + char *ptr = (char *) popPtr(); + Common::strlcpy(name, ptr, sizeof(name)); param1 = popVar(); param2 = popVar(); @@ -566,16 +571,14 @@ int16 Op_LoadFrame() { } int16 Op_LoadAbs() { - int slot; - char name[36] = ""; - char *ptr; int result = 0; - ptr = (char *) popPtr(); - slot = popVar(); + char *ptr = (char *) popPtr(); + int slot = popVar(); if ((slot >= 0) && (slot < NUM_FILE_ENTRIES)) { - strcpy(name, ptr); + char name[36] = ""; + Common::strlcpy(name, ptr, sizeof(name)); strToUpper(name); gfxModuleData_gfxWaitVSync(); @@ -606,7 +609,7 @@ int16 Op_InitializeState() { } int16 Op_GetlowMemory() { - return lowMemory; + return 0; } int16 Op_AniDir() { @@ -641,7 +644,7 @@ int16 Op_FadeOut() { flip(); fadeFlag = 1; - PCFadeFlag = 1; + PCFadeFlag = true; return 0; } @@ -663,8 +666,7 @@ int16 Op_FindOverlay() { char *ptr; ptr = (char *) popPtr(); - - strcpy(name, ptr); + Common::strlcpy(name, ptr, sizeof(name)); strToUpper(name); return (isOverlayLoaded(name)); @@ -996,11 +998,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); @@ -1099,11 +1099,6 @@ actorStruct *addAnimation(actorStruct * pHead, int overlay, int objIdx, int para pCurrent = pPrevious->next; } - if (pCurrent && (pCurrent->overlayNumber == overlay) - && (pCurrent->idx == objIdx) && (pCurrent->type == param2)) { - return NULL; - } - actorStruct *pNewElement = (actorStruct *) MemAlloc(sizeof(actorStruct)); if (!pNewElement) return NULL; @@ -1353,7 +1348,7 @@ int16 Op_LoadSong() { const char *ptr = (const char *)popPtr(); char buffer[33]; - strcpy(buffer, ptr); + Common::strlcpy(buffer, ptr, sizeof(buffer)); strToUpper(buffer); _vm->sound().loadMusic(buffer); @@ -1382,12 +1377,11 @@ int16 Op_RestoreSong() { } int16 Op_SongSize() { - int size, oldSize; - + int oldSize; if (_vm->sound().songLoaded()) { oldSize = _vm->sound().numOrders(); - size = popVar(); + int size = popVar(); if ((size >= 1) && (size < 128)) _vm->sound().setNumOrders(size); } else @@ -1517,8 +1511,9 @@ int16 Op_Itoa() { int nbp = popVar(); int param[160]; char txt[40]; - char format[30]; - char nbf[20]; + + for (int i = 0; i < 160; ++i) + param[i] = 0; for (int i = nbp - 1; i >= 0; i--) param[i] = popVar(); @@ -1529,6 +1524,8 @@ int16 Op_Itoa() { if (!nbp) sprintf(txt, "%d", val); else { + char format[30]; + char nbf[20]; strcpy(format, "%"); sprintf(nbf, "%d", param[0]); strcat(format, nbf); @@ -1576,7 +1573,7 @@ int16 Op_FindObject() { var_26[0] = 0; if (ptr) { - strcpy(var_26, ptr); + Common::strlcpy(var_26, ptr, sizeof(var_26)); } overlayIdx = popVar(); @@ -1614,7 +1611,7 @@ int16 Op_GetNodeX() { int result = getNode(nodeInfo, node); - ASSERT(result == 0); + assert(result == 0); return nodeInfo[0]; } @@ -1626,7 +1623,7 @@ int16 Op_GetNodeY() { int result = getNode(nodeInfo, node); - ASSERT(result == 0); + assert(result == 0); return nodeInfo[1]; } @@ -1649,7 +1646,7 @@ int16 Op_SongExist() { if (songName) { char name[33]; - strcpy(name, songName); + Common::strlcpy(name, songName, sizeof(name)); strToUpper(name); if (!strcmp(_vm->sound().musicName(), name)) @@ -1835,7 +1832,7 @@ int16 Op_ThemeReset() { } int16 Op_UserWait() { - userWait = 1; + userWait = true; if (currentScriptPtr->type == scriptType_PROC) { changeScriptParamInList(currentScriptPtr->overlayNumber, currentScriptPtr->scriptNumber, &procHead, -1, 9999); } else if (currentScriptPtr->type == scriptType_REL) { diff --git a/engines/cruise/function.h b/engines/cruise/function.h index 4fba8d3c63..39e7e22506 100644 --- a/engines/cruise/function.h +++ b/engines/cruise/function.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/gfxModule.cpp b/engines/cruise/gfxModule.cpp index aa2dbc5370..9fd94d7ea6 100644 --- a/engines/cruise/gfxModule.cpp +++ b/engines/cruise/gfxModule.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -121,12 +121,10 @@ void gfxModuleData_setPalColor(int idx, int r, int g, int b) { } void gfxModuleData_setPalEntries(const byte *ptr, int start, int num) { - int R, G, B, i; - - for (i = start; i < start + num; i++) { - R = *(ptr++); - G = *(ptr++); - B = *(ptr++); + for (int i = start; i < start + num; i++) { + int R = *(ptr++); + int G = *(ptr++); + int B = *(ptr++); lpalette[i].R = R; lpalette[i].G = G; @@ -142,12 +140,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); @@ -340,7 +337,6 @@ void resetBitmap(uint8 *dataPtr, int32 dataSize) { */ void switchBackground(const byte *newBg) { const byte *bg = gfxModuleData.pPage00; - int sliceXStart, sliceXEnd; // If both the upper corners are different, presume it's a full screen change if ((*newBg != *bg) && (*(newBg + 319) != *(bg + 319))) { @@ -353,7 +349,8 @@ void switchBackground(const byte *newBg) { */ for (int yp = 0; yp < 200; ++yp) { - sliceXStart = -1; sliceXEnd = -1; + int sliceXStart = -1; + int sliceXEnd = -1; for (int xp = 0; xp < 320; ++xp, ++bg, ++newBg) { if (*bg != *newBg) { if (sliceXStart == -1) { diff --git a/engines/cruise/gfxModule.h b/engines/cruise/gfxModule.h index ce58c65d34..a394ccfe97 100644 --- a/engines/cruise/gfxModule.h +++ b/engines/cruise/gfxModule.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/linker.cpp b/engines/cruise/linker.cpp index e8ef415fe7..9786de775f 100644 --- a/engines/cruise/linker.cpp +++ b/engines/cruise/linker.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -35,23 +35,22 @@ exportEntryStruct *parseExport(int *out1, int *pExportedFuncionIdx, char *buffer int numSymbGlob; exportEntryStruct *currentExportEntry; char *entity1Name; - int i; *out1 = 0; *pExportedFuncionIdx = 0; - strcpy(localBuffer, buffer); + Common::strlcpy(localBuffer, buffer, sizeof(localBuffer)); dotPtr = strchr(localBuffer, '.'); if (dotPtr) { - strcpy(functionName, dotPtr + 1); + Common::strlcpy(functionName, dotPtr + 1, sizeof(functionName)); *dotPtr = 0; strcpy(overlayName, localBuffer); } else { overlayName[0] = 0; - strcpy(functionName, buffer); + Common::strlcpy(functionName, buffer, sizeof(functionName)); } ptr2 = strchr((char *)functionName, ':'); @@ -85,11 +84,11 @@ 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; - strcpy(exportedName, name); + Common::strlcpy(exportedName, name, sizeof(exportedName)); strToUpper(exportedName); if (!strcmp(functionName, exportedName)) { @@ -130,8 +129,6 @@ int updateScriptImport(int ovlIdx) { // do it for the 2 first string types do { - int i = 0; - if (param == 0) { var_32 = numData3; } else { @@ -139,16 +136,16 @@ int updateScriptImport(int ovlIdx) { } if (var_32) { + int i = 0; do { importScriptStruct *ptrImportData; const char *ptrImportName; uint8 *ptrData; - if (param == 0) { + if (param == 0) pScript = getOvlData3Entry(ovlIdx, i); - } else { + else pScript = scriptFunc1Sub2(ovlIdx, i); - } ptrImportData = (importScriptStruct *)(pScript->dataPtr + pScript->offsetToImportData); // import data ptrImportName = (const char*)(pScript->dataPtr + pScript->offsetToImportName); // import name @@ -165,7 +162,7 @@ int updateScriptImport(int ovlIdx) { int out1; int out2; - strcpy(buffer, ptrImportName + ptrImportData->offsetToName); + Common::strlcpy(buffer, ptrImportName + ptrImportData->offsetToName, sizeof(buffer)); ptrDest2 = parseExport(&out1, &out2, buffer); if (ptrDest2 && out2) { @@ -221,16 +218,14 @@ 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; int linkType; int linkEntryIdx; - strcpy(buffer, ovlData->arrayNameRelocGlob + ovlData->arrayRelocGlob[i].nameOffset); + Common::strlcpy(buffer, ovlData->arrayNameRelocGlob + ovlData->arrayRelocGlob[i].nameOffset, sizeof(buffer)); pFoundExport = parseExport(&out1, &foundExportIdx, buffer); @@ -264,12 +259,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/linker.h b/engines/cruise/linker.h index 25f4a5cc2a..85f65348f4 100644 --- a/engines/cruise/linker.h +++ b/engines/cruise/linker.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/mainDraw.cpp b/engines/cruise/mainDraw.cpp index 24f65500db..5777b846b4 100644 --- a/engines/cruise/mainDraw.cpp +++ b/engines/cruise/mainDraw.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -120,7 +120,7 @@ void fadeIn() { gfxModuleData_setPal256(workpal); fadeFlag = 0; - PCFadeFlag = 0; + PCFadeFlag = false; } void flipScreen() { @@ -479,10 +479,7 @@ void buildSegment() { // swap again ? SWAP(X1, X2); - int patchAdd = 2; - int dy = Y2 - Y1; - if (dy == 0) { // hline int16* ptr = (Y1 - ydep) * 2 + XMIN_XMAX + 1; @@ -503,6 +500,8 @@ void buildSegment() { ptr[1] = SI; } } else { + int patchAdd = 2; + if (dy < 0) { dy = -dy; patchAdd = -2; @@ -721,7 +720,6 @@ void buildPolyModel(int positionX, int positionY, int scale, char *pMask, char * int startX = 0; // first X in model int startY = 0; // first Y in model int x = 0; // current X - int y = 0; // current Y int offsetXinModel = 0; // offset of the X value in the model int offsetYinModel = 0; // offset of the Y value in the model unsigned char *dataPointer = (unsigned char *)dataPtr; @@ -761,9 +759,8 @@ void buildPolyModel(int positionX, int positionY, int scale, char *pMask, char * startY >>= 1; } - if (m_flipLeftRight) { + if (m_flipLeftRight) startX = -startX; - } /* * NOTE: @@ -796,7 +793,7 @@ void buildPolyModel(int positionX, int positionY, int scale, char *pMask, char * ptrPoly_1_Buf++; offsetXinModel = x; - y = *(dataPointer) - m_first_Y; + int y = *(dataPointer) - m_first_Y; dataPointer++; if (m_useSmallScale) { y >>= 1; @@ -881,7 +878,6 @@ bool findPoly(char* dataPtr, int positionX, int positionY, int scale, int mouseX int startX = 0; // first X in model int startY = 0; // first Y in model int x = 0; // current X - int y = 0; // current Y int offsetXinModel = 0; // offset of the X value in the model int offsetYinModel = 0; // offset of the Y value in the model unsigned char *dataPointer = (unsigned char *)dataPtr; @@ -955,11 +951,11 @@ bool findPoly(char* dataPtr, int positionX, int positionY, int scale, int mouseX ptrPoly_1_Buf++; offsetXinModel = x; - y = *(dataPointer) - m_first_Y; + int y = *(dataPointer) - m_first_Y; dataPointer++; - if (m_useSmallScale) { + if (m_useSmallScale) y >>= 1; - } + ptrPoly_1_Buf[0] = -(offsetYinModel - y); ptrPoly_1_Buf++; offsetYinModel = y; @@ -1150,10 +1146,6 @@ void drawMessage(const gfxEntryStruct *pGfxPtr, int globalX, int globalY, int wi // this is used for font only if (pGfxPtr) { - uint8 *initialOuput; - uint8 *output; - int xp, yp; - int x, y; const uint8 *ptr = pGfxPtr->imagePtr; int height = pGfxPtr->height; @@ -1172,14 +1164,14 @@ void drawMessage(const gfxEntryStruct *pGfxPtr, int globalX, int globalY, int wi gfxModuleData_addDirtyRect(Common::Rect(globalX, globalY, globalX + width, globalY + height)); - initialOuput = ouputPtr + (globalY * 320) + globalX; + uint8 *initialOuput = ouputPtr + (globalY * 320) + globalX; - for (yp = 0; yp < height; yp++) { - output = initialOuput + 320 * yp; - y = globalY + yp; + for (int yp = 0; yp < height; yp++) { + uint8 *output = initialOuput + 320 * yp; + int y = globalY + yp; - for (xp = 0; xp < pGfxPtr->width; xp++) { - x = globalX + xp; + for (int xp = 0; xp < pGfxPtr->width; xp++) { + int x = globalX + xp; uint8 color = *(ptr++); if (color) { @@ -1255,18 +1247,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], @@ -1388,7 +1377,7 @@ int getValueFromObjectQuerry(objectParamsQuery *params, int idx) { return 0; } -void mainDraw(int16 param) { +void mainDraw(bool waitFl) { uint8 *bgPtr; cellStruct *currentObjPtr; int16 currentObjIdx; @@ -1472,7 +1461,7 @@ void mainDraw(int16 param) { } // automatic animation process - if (currentObjPtr->animStep && !param) { + if (currentObjPtr->animStep && !waitFl) { if (currentObjPtr->animCounter <= 0) { bool change = true; diff --git a/engines/cruise/mainDraw.h b/engines/cruise/mainDraw.h index bb21f515af..1af403fca5 100644 --- a/engines/cruise/mainDraw.h +++ b/engines/cruise/mainDraw.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -33,7 +33,7 @@ extern int m_color; int upscaleValue(int value, int scale); void pixel(int x, int y, char color); -void mainDraw(int16 param); +void mainDraw(bool waitFl); void flipScreen(); void buildPolyModel(int X, int Y, int scale, char *ptr2, char *destBuffer, char *dataPtr); void drawSprite(int width, int height, cellStruct *currentObjPtr, const uint8 *dataIn, int ys, int xs, uint8 *output, const uint8 *dataBuf); diff --git a/engines/cruise/menu.cpp b/engines/cruise/menu.cpp index 512259f7d7..cf0b872646 100644 --- a/engines/cruise/menu.cpp +++ b/engines/cruise/menu.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -39,7 +39,7 @@ menuStruct *createMenu(int X, int Y, const char *menuName) { menuStruct *entry; entry = (menuStruct *) MemAlloc(sizeof(menuStruct)); - ASSERT(entry); + assert(entry); entry->x = X - 160 / 2; entry->y = Y; @@ -69,7 +69,7 @@ void addSelectableMenuEntry(int ovlIdx, int headerIdx, menuStruct *pMenu, int pa if (!strcmp(var_6->string, menuText)) { pNewElement = var_6; pSubStruct = (menuElementSubStruct *)allocAndZero(sizeof(menuElementSubStruct)); - ASSERT(pSubStruct); + assert(pSubStruct); pSubStruct->pNext = NULL; pSubStruct->ovlIdx = ovlIdx; @@ -99,9 +99,9 @@ void addSelectableMenuEntry(int ovlIdx, int headerIdx, menuStruct *pMenu, int pa } pNewElement = (menuElementStruct *)allocAndZero(sizeof(menuElementStruct)); - ASSERT(pNewElement); + assert(pNewElement); pSubStruct = (menuElementSubStruct *)allocAndZero(sizeof(menuElementSubStruct)); - ASSERT(pSubStruct); + assert(pSubStruct); pNewElement->string = menuText; pNewElement->next = NULL; @@ -160,7 +160,7 @@ int processMenu(menuStruct *pMenu) { int si; currentActiveMenu = 0; - mainDraw(1); + mainDraw(true); flipScreen(); di = 0; @@ -179,7 +179,7 @@ int processMenu(menuStruct *pMenu) { di = 1; } - mainDraw(1); + mainDraw(true); flipScreen(); manageEvents(); @@ -190,7 +190,7 @@ int processMenu(menuStruct *pMenu) { currentActiveMenu = -1; - mainDraw(1); + mainDraw(true); flipScreen(); if (mouseButton & 1) { @@ -233,7 +233,6 @@ static void handleSaveLoad(bool saveFlag) { } int playerMenu(int menuX, int menuY) { - int retourMenu; //int restartGame = 0; if (playerMenuEnabled && displayOn) { @@ -267,7 +266,7 @@ int playerMenu(int menuX, int menuY) { freeDisk(); menuTable[0] = createMenu(menuX, menuY, _vm->langString(ID_PLAYER_MENU)); - ASSERT(menuTable[0]); + assert(menuTable[0]); //addSelectableMenuEntry(0, 3, menuTable[0], 1, -1, "Save game disk"); if (userEnabled) { @@ -277,7 +276,7 @@ int playerMenu(int menuX, int menuY) { addSelectableMenuEntry(0, 6, menuTable[0], 1, -1, _vm->langString(ID_RESTART)); addSelectableMenuEntry(0, 7, menuTable[0], 1, -1, _vm->langString(ID_QUIT)); - retourMenu = processMenu(menuTable[0]); + int retourMenu = processMenu(menuTable[0]); freeMenu(menuTable[0]); menuTable[0] = NULL; diff --git a/engines/cruise/menu.h b/engines/cruise/menu.h index d605903cdc..c6f607506e 100644 --- a/engines/cruise/menu.h +++ b/engines/cruise/menu.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/mouse.cpp b/engines/cruise/mouse.cpp index 6248bd01d3..9e01044bb0 100644 --- a/engines/cruise/mouse.cpp +++ b/engines/cruise/mouse.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/mouse.h b/engines/cruise/mouse.h index a5f5c19073..4407718168 100644 --- a/engines/cruise/mouse.h +++ b/engines/cruise/mouse.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/object.cpp b/engines/cruise/object.cpp index b4a3489c1d..845fc34d1f 100644 --- a/engines/cruise/object.cpp +++ b/engines/cruise/object.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -116,14 +116,10 @@ int16 getMultipleObjectParam(int16 overlayIdx, int16 objectIdx, objectParamsQuer } void setObjectPosition(int16 ovlIdx, int16 objIdx, int16 param3, int16 param4) { - objDataStruct *ptr; - objectParams *ptr2; - - ptr = getObjectDataFromOverlay(ovlIdx, objIdx); - - if (!ptr) { + objDataStruct *ptr = getObjectDataFromOverlay(ovlIdx, objIdx); + if (!ptr) return; - } + //overlayTable[param1].ovlData switch (ptr->_class) { @@ -138,7 +134,7 @@ void setObjectPosition(int16 ovlIdx, int16 objIdx, int16 param3, int16 param4) { case UNIQUE: return; case VARIABLE: { - ptr2 = &overlayTable[ovlIdx].ovlData->arrayObjVar[ptr->_varTableIdx]; + objectParams *ptr2 = &overlayTable[ovlIdx].ovlData->arrayObjVar[ptr->_varTableIdx]; switch (param3) { case 0: { // x @@ -167,14 +163,14 @@ void setObjectPosition(int16 ovlIdx, int16 objIdx, int16 param3, int16 param4) { break; } default: { - ASSERT(0); + assert(0); } } break; } default: { - ASSERT(0); + assert(0); } } } diff --git a/engines/cruise/object.h b/engines/cruise/object.h index cbe5872a9d..954bed0687 100644 --- a/engines/cruise/object.h +++ b/engines/cruise/object.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/overlay.cpp b/engines/cruise/overlay.cpp index d618ab5599..f7df741892 100644 --- a/engines/cruise/overlay.cpp +++ b/engines/cruise/overlay.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -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); } @@ -159,7 +155,7 @@ int loadOverlay(const char *scriptName) { return (-2); if (scriptName != overlayTable[scriptIdx].overlayName) - strcpy(overlayTable[scriptIdx].overlayName, scriptName); + Common::strlcpy(overlayTable[scriptIdx].overlayName, scriptName, sizeof(overlayTable[scriptIdx].overlayName)); overlayTable[scriptIdx].alreadyLoaded = 1; @@ -167,9 +163,8 @@ int loadOverlay(const char *scriptName) { overlayTable[scriptIdx].ovlData->scriptNumber = scriptIdx; - strcpy(fileName, scriptName); - - strcat(fileName, ".OVL"); + Common::strlcpy(fileName, scriptName, sizeof(fileName)); + Common::strlcat(fileName, ".OVL", sizeof(fileName)); debug(1, "Attempting to load overlay file %s...", fileName); @@ -247,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(); @@ -275,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(); @@ -305,16 +295,14 @@ int loadOverlay(const char *scriptName) { } if (ovlData->numMsgRelHeader) { // link data - int i; - ASSERT(sizeof(linkDataStruct) == 0x22); + 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(); @@ -342,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(); @@ -370,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) { @@ -395,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(); @@ -423,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); @@ -463,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(); @@ -501,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(); @@ -521,38 +494,28 @@ 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]; //char* unpackedBuffer; - strcpy(fileName, scriptName); - - strcat(fileName, ".FR"); + Common::strlcpy(fileName, scriptName, sizeof(fileName)); + Common::strlcat(fileName, ".FR", sizeof(fileName)); fileIdx = findFileInDisks(fileName); @@ -625,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) { @@ -650,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); } } @@ -659,15 +621,14 @@ 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); fHandle = fopen(nameBundle, "w+"); - ASSERT(fHandle); + 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]; @@ -700,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); } @@ -711,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/overlay.h b/engines/cruise/overlay.h index 3b69f2acef..cfba75dd7a 100644 --- a/engines/cruise/overlay.h +++ b/engines/cruise/overlay.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/perso.cpp b/engines/cruise/perso.cpp index 85c9b1614f..ff33eca14b 100644 --- a/engines/cruise/perso.cpp +++ b/engines/cruise/perso.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -172,23 +172,20 @@ void processActorWalk(MovementEntry &resx_y, int16 *inc_droite, int16 *inc_droit int16 *inc_chemin, point* cor_joueur, int16 solution0[NUM_NODES + 3][2], int16 *inc_jo1, int16 *inc_jo2, int16 *dir_perso, int16 *inc_jo0, int16 num) { - int x1, x2, y1, y2; - int i, u; - - u = 0; + int u = 0; inc_jo = *inc_jo0; - i = *inc_chemin; + int i = *inc_chemin; if (!*inc_droite) { - x1 = solution0[i][0]; - y1 = solution0[i][1]; + int x1 = solution0[i][0]; + int y1 = solution0[i][1]; i++; if (solution0[i][0] != -1) { do { if (solution0[i][0] != -2) { - x2 = solution0[i][0]; - y2 = solution0[i][1]; + int x2 = solution0[i][0]; + int y2 = solution0[i][1]; if ((x1 == x2) && (y1 == y2)) { resx_y.x = -1; resx_y.y = -1; @@ -240,7 +237,7 @@ void processActorWalk(MovementEntry &resx_y, int16 *inc_droite, int16 *inc_droit void affiche_chemin(int16 persoIdx, MovementEntry &data) { persoStruct *pPerso = persoTable[persoIdx]; - ASSERT(pPerso); + assert(pPerso); processActorWalk(data, &pPerso->inc_droite, &pPerso->inc_droite0, &pPerso->inc_chemin, pPerso->coordinates, pPerso->solution, diff --git a/engines/cruise/perso.h b/engines/cruise/perso.h index e0ca479dff..6d8120793e 100644 --- a/engines/cruise/perso.h +++ b/engines/cruise/perso.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/polys.cpp b/engines/cruise/polys.cpp index 964540f802..f6d0691c69 100644 --- a/engines/cruise/polys.cpp +++ b/engines/cruise/polys.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -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++; @@ -212,20 +211,15 @@ void fillpoly(int16 *point_data, int lineCount, ColorP color) { } // Reinit array counters - - int x1, y1, x2, y2; - int y, i; - - for (i = 0; i < SCREENHEIGHT; i++) { + for (int i = 0; i < SCREENHEIGHT; i++) { num_intersect[i] = 0; } // Find the top/bottom of the polygon. - int top = point_data[1]; int bottom = point_data[1]; - for (i = 1; i < lineCount; i++) { + for (int i = 1; i < lineCount; i++) { if (point_data[2 * i + 1] < top) top = point_data[2 * i + 1]; else if (point_data[2 * i + 1] > bottom) @@ -238,14 +232,13 @@ void fillpoly(int16 *point_data, int lineCount, ColorP color) { bottom = SCREENHEIGHT - 1; // Calculate intersections for each scan line + for (int y = top; y <= bottom; y++) { + int x2 = point_data[2 * lineCount - 2]; + int y2 = point_data[2 * lineCount - 1]; - for (y = top; y <= bottom; y++) { - x2 = point_data[2 * lineCount - 2]; - y2 = point_data[2 * lineCount - 1]; - - for (i = 0; i < lineCount; i++) { - x1 = x2; - y1 = y2; + for (int i = 0; i < lineCount; i++) { + int x1 = x2; + int y1 = y2; x2 = point_data[2 * i]; y2 = point_data[2 * i + 1]; @@ -265,9 +258,8 @@ void fillpoly(int16 *point_data, int lineCount, ColorP color) { } // Drawing. - - for (y = top; y <= bottom; y++) { - for (i = 0; i < num_intersect[y]; i += 2) { + for (int y = top; y <= bottom; y++) { + for (int i = 0; i < num_intersect[y]; i += 2) { hline(intersect[y][i], intersect[y][i + 1], y, color); } } diff --git a/engines/cruise/polys.h b/engines/cruise/polys.h index 8505f791a6..6add9c6ded 100644 --- a/engines/cruise/polys.h +++ b/engines/cruise/polys.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/saveload.cpp b/engines/cruise/saveload.cpp index 26bea0441c..a62648df08 100644 --- a/engines/cruise/saveload.cpp +++ b/engines/cruise/saveload.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -182,11 +182,13 @@ static void syncFilesDatabase(Common::Serializer &s) { s.syncAsUint16LE(fe.resType); s.syncAsUint16LE(fe.height); - // TODO: Have a look at the saving/loading of this pointer + // Remember whether this file database was open or not. + // Upon loading, loadSavegameData uses this information + // in order to re-open the file databases accordingly. tmp = (fe.subData.ptr) ? 1 : 0; s.syncAsUint32LE(tmp); if (s.isLoading()) { - fe.subData.ptr = (uint8 *)tmp; + fe.subData.ptr = tmp ? (uint8 *)1 : 0; } s.syncAsSint16LE(fe.subData.index); @@ -195,11 +197,11 @@ static void syncFilesDatabase(Common::Serializer &s) { s.syncAsSint16LE(fe.subData.transparency); - // TODO: Have a look at the saving/loading of this pointer + // Treat fe.subData.ptrMask the same as fe.subData.ptr. tmp = (fe.subData.ptrMask) ? 1 : 0; s.syncAsUint32LE(tmp); if (s.isLoading()) { - fe.subData.ptrMask = (uint8 *)tmp; + fe.subData.ptrMask = tmp ? (uint8 *)1 : 0; } s.syncAsUint16LE(fe.subData.resourceType); @@ -282,7 +284,7 @@ static void syncOverlays2(Common::Serializer &s) { if (ovlRestoreData[i]._sBssSize) { ovlRestoreData[i]._pBss = (uint8 *) mallocAndZero(ovlRestoreData[i]._sBssSize); - ASSERT(ovlRestoreData[i]._pBss); + assert(ovlRestoreData[i]._pBss); s.syncBytes(ovlRestoreData[i]._pBss, ovlRestoreData[i]._sBssSize); } @@ -291,7 +293,7 @@ static void syncOverlays2(Common::Serializer &s) { if (ovlRestoreData[i]._sNumObj) { ovlRestoreData[i]._pObj = (objectParams *) mallocAndZero(ovlRestoreData[i]._sNumObj * sizeof(objectParams)); - ASSERT(ovlRestoreData[i]._pObj); + assert(ovlRestoreData[i]._pObj); for (int j = 0; j < ovlRestoreData[i]._sNumObj; j++) { s.syncAsSint16LE(ovlRestoreData[i]._pObj[j].X); @@ -733,7 +735,7 @@ void initVars() { resetBackgroundIncrustList(&backgroundIncrustHead); vblLimit = 0; - remdo = 0; + remdo = false; songLoaded = 0; songPlayed = 0; songLoop = 1; @@ -775,7 +777,7 @@ void initVars() { buttonDown = 0; var41 = 0; playerMenuEnabled = 0; - PCFadeFlag = 0; + PCFadeFlag = false; } Common::Error saveSavegameData(int saveGameIdx, const Common::String &saveName) { @@ -806,7 +808,6 @@ Common::Error saveSavegameData(int saveGameIdx, const Common::String &saveName) } Common::Error loadSavegameData(int saveGameIdx) { - int lowMemorySave; Common::String saveName; cellStruct *currentcellHead; @@ -878,20 +879,17 @@ Common::Error loadSavegameData(int saveGameIdx) { lastAni[0] = 0; - lowMemorySave = lowMemory; - 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 && filesDatabase[j].subData.ptr && !strcmp(filesDatabase[i].subData.name, filesDatabase[j].subData.name) && (filesDatabase[j].subData.index == (j - i)); j++) + 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++) { - if (filesDatabase[k].subData.ptrMask) - lowMemory = 0; - + for (int k = i; k < j; k++) { filesDatabase[k].subData.ptr = NULL; filesDatabase[k].subData.ptrMask = NULL; } @@ -908,7 +906,6 @@ Common::Error loadSavegameData(int saveGameIdx) { } i = j - 1; - lowMemory = lowMemorySave; } } @@ -918,17 +915,14 @@ Common::Error loadSavegameData(int saveGameIdx) { while (currentcellHead) { if (currentcellHead->type == 5) { + assert(0); +#if 0 uint8 *ptr = mainProc14(currentcellHead->overlay, currentcellHead->idx); - - ASSERT(0); - - if (ptr) { - ASSERT(0); - //*(int16 *)(currentcellHead->datas+0x2E) = getSprite(ptr,*(int16 *)(currentcellHead->datas+0xE)); - } else { - ASSERT(0); - //*(int16 *)(currentcellHead->datas+0x2E) = 0; - } + if (ptr) + *(int16 *)(currentcellHead->datas+0x2E) = getSprite(ptr,*(int16 *)(currentcellHead->datas+0xE)); + else + *(int16 *)(currentcellHead->datas+0x2E) = 0; +#endif } currentcellHead = currentcellHead->next; @@ -953,7 +947,7 @@ Common::Error loadSavegameData(int saveGameIdx) { // to finish changeCursor(CURSOR_NORMAL); - mainDraw(1); + mainDraw(true); flipScreen(); return Common::kNoError; diff --git a/engines/cruise/saveload.h b/engines/cruise/saveload.h index 695913f46f..6fb1f4b545 100644 --- a/engines/cruise/saveload.h +++ b/engines/cruise/saveload.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/script.cpp b/engines/cruise/script.cpp index d753d938bd..1f308714f7 100644 --- a/engines/cruise/script.cpp +++ b/engines/cruise/script.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -51,12 +51,13 @@ int32 opcodeType0() { int index = 0; switch (currentScriptOpcodeType) { - case 0: { + case 0: pushVar(getShortFromScript()); return (0); - } + case 5: index = saveOpcodeVar; + // No break on purpose case 1: { uint8 *address = 0; int type = getByteFromScript(); @@ -131,12 +132,12 @@ int32 opcodeType1() { int offset = 0; switch (currentScriptOpcodeType) { - case 0: { + case 0: return (0); // strange, but happens also in original interpreter - } - case 5: { + + case 5: offset = saveOpcodeVar; - } + //no break on purpose case 1: { int var_A = 0; @@ -169,7 +170,7 @@ int32 opcodeType1() { if (var_6 == 5) { ptr = overlayTable[byte2].ovlData->data4Ptr + var_C; } else { - ASSERT(0); + assert(0); } } else { ptr = scriptDataPtrTable[var_6] + var_C; @@ -226,6 +227,7 @@ int32 opcodeType2() { switch (currentScriptOpcodeType) { case 5: index = saveOpcodeVar; + // No break on purpose case 1: { uint8* adresse = NULL; int type = getByteFromScript(); @@ -247,7 +249,7 @@ int32 opcodeType2() { if (!overlayTable[overlay].ovlData) { return (-4); } - ASSERT(0); + assert(0); } adresse += offset; @@ -261,6 +263,7 @@ int32 opcodeType2() { } } + break; } return 0; @@ -281,39 +284,37 @@ int32 opcodeType4() { // test int var2 = popVar(); switch (currentScriptOpcodeType) { - case 0: { + case 0: if (var2 != var1) boolVar = 1; break; - } - case 1: { + + case 1: if (var2 == var1) boolVar = 1; break; - } - case 2: { + + case 2: if (var2 < var1) boolVar = 1; break; - } - case 3: { + + case 3: if (var2 <= var1) boolVar = 1; break; - } - case 4: { + + case 4: if (var2 > var1) boolVar = 1; break; - } - case 5: { + + case 5: if (var2 >= var1) boolVar = 1; break; } - } - pushVar(boolVar); return (0); @@ -327,13 +328,11 @@ int32 opcodeType6() { if (!pop) si = 1; - if (pop < 0) { + if (pop < 0) si |= 4; - } - if (pop > 0) { + if (pop > 0) si |= 2; - } currentScriptPtr->ccr = si; @@ -357,50 +356,49 @@ int32 opcodeType5() { int bitMask = currentScriptPtr->ccr; switch (currentScriptOpcodeType) { - case 0: { - if (!(bitMask & 1)) { + case 0: + if (!(bitMask & 1)) currentScriptPtr->scriptOffset = newSi; - } + break; - } - case 1: { - if (bitMask & 1) { + + case 1: + if (bitMask & 1) currentScriptPtr->scriptOffset = newSi; - } + break; - } - case 2: { - if (bitMask & 2) { + + case 2: + if (bitMask & 2) currentScriptPtr->scriptOffset = newSi; - } + break; - } - case 3: { - if (bitMask & 3) { + + case 3: + if (bitMask & 3) currentScriptPtr->scriptOffset = newSi; - } + break; - } - case 4: { - if (bitMask & 4) { + + case 4: + if (bitMask & 4) currentScriptPtr->scriptOffset = newSi; - } + break; - } - case 5: { - if (bitMask & 5) { + + case 5: + if (bitMask & 5) currentScriptPtr->scriptOffset = newSi; - } + break; - } - case 6: { + + case 6: break; // never - } - case 7: { + + case 7: currentScriptPtr->scriptOffset = newSi; //always break; } - } return (0); } @@ -410,35 +408,39 @@ int32 opcodeType3() { // math int pop2 = popVar(); switch (currentScriptOpcodeType) { - case 0: { + case 0: pushVar(pop1 + pop2); return (0); - } - case 1: { + + case 1: + if (pop2 == 0) + error("opcodeType3 - Invalid value for pop2"); pushVar(pop1 / pop2); return (0); - } - case 2: { + + case 2: pushVar(pop1 - pop2); return (0); - } - case 3: { + + case 3: pushVar(pop1 * pop2); return (0); - } - case 4: { + + case 4: + if (pop2 == 0) + error("opcodeType3 - Invalid value for pop2"); pushVar(pop1 % pop2); return (0); - } + case 7: - case 5: { + case 5: pushVar(pop2 | pop1); return (0); - } - case 6: { + + case 6: pushVar(pop2 & pop1); return (0); - } + } return 0; @@ -451,11 +453,8 @@ int32 opcodeType9() { // stop script } void setupFuncArray() { - int i; - - for (i = 0; i < 64; i++) { + for (int i = 0; i < 64; i++) opcodeTypeTable[i] = NULL; - } opcodeTypeTable[1] = opcodeType0; opcodeTypeTable[2] = opcodeType1; @@ -472,19 +471,13 @@ void setupFuncArray() { } int removeScript(int overlay, int idx, scriptInstanceStruct *headPtr) { - scriptInstanceStruct *scriptPtr; + scriptInstanceStruct *scriptPtr = headPtr->nextScriptPtr; - scriptPtr = headPtr->nextScriptPtr; + while (scriptPtr) { + if (scriptPtr->overlayNumber == overlay && (scriptPtr->scriptNumber == idx || idx == -1)) + scriptPtr->scriptNumber = -1; - if (scriptPtr) { - do { - if (scriptPtr->overlayNumber == overlay - && (scriptPtr->scriptNumber == idx || idx == -1)) { - scriptPtr->scriptNumber = -1; - } - - scriptPtr = scriptPtr->nextScriptPtr; - } while (scriptPtr); + scriptPtr = scriptPtr->nextScriptPtr; } return (0); @@ -493,77 +486,61 @@ int removeScript(int overlay, int idx, scriptInstanceStruct *headPtr) { uint8 *attacheNewScriptToTail(scriptInstanceStruct *scriptHandlePtr, int16 overlayNumber, int16 param, int16 arg0, int16 arg1, int16 arg2, scriptTypeEnum scriptType) { int useArg3Neg = 0; ovlData3Struct *data3Ptr; - scriptInstanceStruct *tempPtr; int var_C; scriptInstanceStruct *oldTail; - //debug("Starting script %d of overlay %s", param,overlayTable[overlayNumber].overlayName); - if (scriptType < 0) { useArg3Neg = 1; - scriptType = (scriptTypeEnum) - scriptType; + scriptType = (scriptTypeEnum) -scriptType; } - if (scriptType == 20) { + if (scriptType == 20) data3Ptr = getOvlData3Entry(overlayNumber, param); - } else { - if (scriptType == 30) { - data3Ptr = scriptFunc1Sub2(overlayNumber, param); - } else { - return (NULL); - } - } + else if (scriptType == 30) + data3Ptr = scriptFunc1Sub2(overlayNumber, param); + else + return (NULL); - if (!data3Ptr) { + if (!data3Ptr) return (NULL); - } - if (!data3Ptr->dataPtr) { + if (!data3Ptr->dataPtr) return (NULL); - } var_C = data3Ptr->sysKey; - oldTail = scriptHandlePtr; - while (oldTail->nextScriptPtr) { // go to the end of the list + while (oldTail->nextScriptPtr) // go to the end of the list oldTail = oldTail->nextScriptPtr; - } - tempPtr = - (scriptInstanceStruct *) - mallocAndZero(sizeof(scriptInstanceStruct)); + scriptInstanceStruct *tempPtr = (scriptInstanceStruct *)mallocAndZero(sizeof(scriptInstanceStruct)); if (!tempPtr) return (NULL); tempPtr->data = NULL; - if (var_C) { + if (var_C) tempPtr->data = (uint8 *) mallocAndZero(var_C); - } tempPtr->dataSize = var_C; tempPtr->nextScriptPtr = NULL; tempPtr->scriptOffset = 0; - tempPtr->scriptNumber = param; tempPtr->overlayNumber = overlayNumber; - if (scriptType == 20) { // Obj or not ? + if (scriptType == 20) // Obj or not ? tempPtr->sysKey = useArg3Neg; - } else { + else tempPtr->sysKey = 1; - } tempPtr->freeze = 0; tempPtr->type = scriptType; tempPtr->var18 = arg2; tempPtr->var16 = arg1; tempPtr->var1A = arg0; - tempPtr->nextScriptPtr = oldTail->nextScriptPtr; // should always be NULL as it's the tail - - oldTail->nextScriptPtr = tempPtr; // attache the new node to the list + tempPtr->nextScriptPtr = oldTail->nextScriptPtr; // should always be NULL as it's the tail + oldTail->nextScriptPtr = tempPtr; // attach the new node to the list return (tempPtr->data); } @@ -576,27 +553,18 @@ int executeScripts(scriptInstanceStruct *ptr) { numScript2 = ptr->scriptNumber; - if (ptr->type == 20) { + if (ptr->type == 20) ptr2 = getOvlData3Entry(ptr->overlayNumber, numScript2); + else if (ptr->type == 30) + ptr2 = scriptFunc1Sub2(ptr->overlayNumber, numScript2); + else + return (-6); - if (!ptr2) { - return (-4); - } - } else { - if (ptr->type == 30) { - ptr2 = scriptFunc1Sub2(ptr->overlayNumber, numScript2); - - if (!ptr2) { - return (-4); - } - } else { - return (-6); - } - } + if (!ptr2) + return (-4); - if (!overlayTable[ptr->overlayNumber].alreadyLoaded) { + if (!overlayTable[ptr->overlayNumber].alreadyLoaded) return (-7); - } ovlData = overlayTable[ptr->overlayNumber].ovlData; @@ -604,14 +572,11 @@ int executeScripts(scriptInstanceStruct *ptr) { return (-4); currentData3DataPtr = ptr2->dataPtr; - scriptDataPtrTable[1] = (uint8 *) ptr->data; scriptDataPtrTable[2] = getDataFromData3(ptr2, 1); scriptDataPtrTable[5] = ovlData->data4Ptr; // free strings scriptDataPtrTable[6] = ovlData->ptr8; - currentScriptPtr = ptr; - positionInStack = 0; do { @@ -645,21 +610,15 @@ int executeScripts(scriptInstanceStruct *ptr) { void manageScripts(scriptInstanceStruct *scriptHandle) { scriptInstanceStruct *ptr = scriptHandle; - if (ptr) { - do { - if (!overlayTable[ptr->overlayNumber].executeScripts) { - if ((ptr->scriptNumber != -1) && (ptr->freeze == 0) && (ptr->sysKey != 0)) { - executeScripts(ptr); - } + while (ptr) { + if (!overlayTable[ptr->overlayNumber].executeScripts) { + if ((ptr->scriptNumber != -1) && (ptr->freeze == 0) && (ptr->sysKey != 0)) + executeScripts(ptr); - if (ptr->sysKey == 0) { - ptr->sysKey = 1; - } - } - - ptr = ptr->nextScriptPtr; - - } while (ptr); + if (ptr->sysKey == 0) + ptr->sysKey = 1; + } + ptr = ptr->nextScriptPtr; } } diff --git a/engines/cruise/script.h b/engines/cruise/script.h index cba4f580f8..15f29e8921 100644 --- a/engines/cruise/script.h +++ b/engines/cruise/script.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/sound.cpp b/engines/cruise/sound.cpp index 21d9a75297..0b0fab8c4a 100644 --- a/engines/cruise/sound.cpp +++ b/engines/cruise/sound.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -342,9 +342,7 @@ void AdLibSoundDriver::adjustVolume(int channel, int volume) { volume = 0; } volume += volume / 4; - if (volume > 127) { - volume = 127; - } + // The higher possible value for volume is 100 int volAdjust = (channel == 4) ? _sfxVolume : _musicVolume; volume = (volume * volAdjust) / 128; @@ -379,13 +377,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); } @@ -610,6 +607,13 @@ PCSoundFxPlayer::PCSoundFxPlayer(PCSoundDriver *driver) _sfxData = NULL; _fadeOutCounter = 0; _driver->setUpdateCallback(updateCallback, this); + + _currentPos = 0; + _currentOrder = 0; + _numOrders = 0; + _eventsDelay = 0; + _looping = false; + _updateTicksCounter = 0; } PCSoundFxPlayer::~PCSoundFxPlayer() { @@ -630,7 +634,7 @@ bool PCSoundFxPlayer::load(const char *song) { stop(); } - strcpy(_musicName, song); + Common::strlcpy(_musicName, song, sizeof(_musicName)); _songPlayed = false; _looping = false; _sfxData = readBundleSoundFile(song); @@ -652,7 +656,7 @@ bool PCSoundFxPlayer::load(const char *song) { if (dot) { *dot = '\0'; } - strcat(instrument, _driver->getInstrumentExtension()); + Common::strlcat(instrument, _driver->getInstrumentExtension(), sizeof(instrument)); _instrumentsData[i] = readBundleSoundFile(instrument); if (!_instrumentsData[i]) { warning("Unable to load soundfx instrument '%s'", instrument); @@ -795,6 +799,7 @@ PCSound::PCSound(Audio::Mixer *mixer, CruiseEngine *vm) { _mixer = mixer; _soundDriver = new AdLibSoundDriverADL(_mixer); _player = new PCSoundFxPlayer(_soundDriver); + _genVolume = 0; } PCSound::~PCSound() { diff --git a/engines/cruise/sound.h b/engines/cruise/sound.h index c1975dc579..57035e2b11 100644 --- a/engines/cruise/sound.h +++ b/engines/cruise/sound.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/stack.cpp b/engines/cruise/stack.cpp index 985fe8d7fd..52a7a84814 100644 --- a/engines/cruise/stack.cpp +++ b/engines/cruise/stack.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -44,7 +44,7 @@ int16 popVar() { positionInStack--; - ASSERT(scriptStack[positionInStack].type == STACK_SHORT); + assert(scriptStack[positionInStack].type == STACK_SHORT); return (scriptStack[positionInStack].data.shortVar); } @@ -66,7 +66,7 @@ void *popPtr() { positionInStack--; - ASSERT(scriptStack[positionInStack].type == STACK_PTR); + assert(scriptStack[positionInStack].type == STACK_PTR); return (scriptStack[positionInStack].data.ptrVar); } diff --git a/engines/cruise/stack.h b/engines/cruise/stack.h index fe2d594c9e..1c96f430d9 100644 --- a/engines/cruise/stack.h +++ b/engines/cruise/stack.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/staticres.cpp b/engines/cruise/staticres.cpp index 08ff4d7548..e9ba941ae0 100644 --- a/engines/cruise/staticres.cpp +++ b/engines/cruise/staticres.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/staticres.h b/engines/cruise/staticres.h index acf0b640be..3691260078 100644 --- a/engines/cruise/staticres.h +++ b/engines/cruise/staticres.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/engines/cruise/various.cpp b/engines/cruise/various.cpp index 90b072b478..df09ac92c8 100644 --- a/engines/cruise/various.cpp +++ b/engines/cruise/various.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -24,8 +24,8 @@ namespace Cruise { -uint16 remdo = 0; -uint16 PCFadeFlag; +bool remdo = false; +bool PCFadeFlag; char *getText(int textIndex, int overlayIndex) { if (!overlayTable[overlayIndex].ovlData) { diff --git a/engines/cruise/various.h b/engines/cruise/various.h index b59593961d..94fc29173a 100644 --- a/engines/cruise/various.h +++ b/engines/cruise/various.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -27,8 +27,8 @@ namespace Cruise { -extern uint16 remdo; -extern uint16 PCFadeFlag; +extern bool remdo; +extern bool PCFadeFlag; int16 objInit(int ovlIdx, int param1, int param2); char *getText(int textIndex, int overlayIndex); diff --git a/engines/cruise/vars.cpp b/engines/cruise/vars.cpp index f381358356..e9b68968ef 100644 --- a/engines/cruise/vars.cpp +++ b/engines/cruise/vars.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -31,7 +31,6 @@ uint8 selectColor = 3; uint8 titleColor = 2; uint8 subColor = 5; -int16 lowMemory; int16 scroll; int16 switchPal; char cmdLine[90]; @@ -54,9 +53,7 @@ char nextOverlay[38]; int16 currentActiveMenu; int16 autoMsg; menuElementSubStruct* linkedRelation; -int16 main21; -int16 main22; -int16 userWait; +bool userWait; int16 autoTrack; int16 currentDiskNumber = 1; diff --git a/engines/cruise/vars.h b/engines/cruise/vars.h index ccbf149610..e7c687d5fb 100644 --- a/engines/cruise/vars.h +++ b/engines/cruise/vars.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -59,7 +59,6 @@ extern uint8 selectColor; extern uint8 titleColor; extern uint8 subColor; -extern int16 lowMemory; extern int16 scroll; extern int16 switchPal; extern char cmdLine[90]; @@ -157,9 +156,7 @@ extern char nextOverlay[38]; extern int16 currentActiveMenu; extern int16 autoMsg; extern menuElementSubStruct* linkedRelation; -extern int16 main21; -extern int16 main22; -extern int16 userWait; +extern bool userWait; extern int16 autoTrack; extern int16 currentDiskNumber; diff --git a/engines/cruise/volume.cpp b/engines/cruise/volume.cpp index 9fb6842882..99d86e48bb 100644 --- a/engines/cruise/volume.cpp +++ b/engines/cruise/volume.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -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); } @@ -213,24 +202,25 @@ int16 findFileInList(char *fileName) { void askDisk(int16 discNumber) { char fileName[256]; char string[256]; - char messageDrawn = 0; if (discNumber != -1) { currentDiskNumber = discNumber; } - // skip drive selection stuff sprintf(fileName, "VOL.%d", currentDiskNumber); - sprintf(string, "INSERER LE DISQUE %d EN ", currentDiskNumber); - //while (Common::File::exists((const char*)fileName)) - { +#if 0 // skip drive selection stuff + bool messageDrawn = false; + while (Common::File::exists((const char*)fileName)) { if (!messageDrawn) { drawMsgString(string); - messageDrawn = 1; + messageDrawn = true; } } +#else + drawMsgString(string); +#endif changeCursor(currentCursor); } @@ -240,7 +230,7 @@ int16 findFileInDisks(const char *name) { int disk; int fileIdx; - strcpy(fileName, name); + Common::strlcpy(fileName, name, sizeof(fileName)); strToUpper(fileName); if (!volumeDataLoaded) { @@ -324,13 +314,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 +328,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 +344,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 +369,6 @@ int16 readVolCnf() { #ifdef dumpResources for (i = 0; i < numOfDisks; i++) { - int j; char nameBuffer[256]; fileEntry *buffer; @@ -397,7 +384,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(); diff --git a/engines/cruise/volume.h b/engines/cruise/volume.h index 80e1f10db2..0caa894744 100644 --- a/engines/cruise/volume.h +++ b/engines/cruise/volume.h @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |