Skip to content

Commit

Permalink
DM: Silent some more CppCheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Bendegúz Nagy committed Aug 26, 2016
1 parent 3447af8 commit dce7465
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 150 deletions.
229 changes: 102 additions & 127 deletions engines/dm/dungeonman.cpp
Expand Up @@ -419,6 +419,8 @@ DungeonMan::~DungeonMan() {
delete[] _g260_dungeonTextData;
delete[] _g279_dungeonMapData;
for (uint16 i = 0; i < 16; ++i) {
if (_g284_thingData[i])
delete[] _g284_thingData[i][0];
delete[] _g284_thingData[i];
}
}
Expand Down Expand Up @@ -651,42 +653,42 @@ void DungeonMan::f434_loadDungeonFile() {
continue;

if (_g284_thingData[thingType]) {
delete[] _g284_thingData[thingType][0];
delete[] _g284_thingData[thingType];
}
_g284_thingData[thingType] = new uint16[_g278_dungeonFileHeader._thingCounts[thingType] * thingStoreWordCount];
_g284_thingData[thingType] = new uint16*[_g278_dungeonFileHeader._thingCounts[thingType]];
_g284_thingData[thingType][0] = new uint16[_g278_dungeonFileHeader._thingCounts[thingType] * thingStoreWordCount];
for (uint16 i = 0; i < _g278_dungeonFileHeader._thingCounts[thingType]; ++i)
_g284_thingData[thingType][i] = _g284_thingData[thingType][0] + i * thingStoreWordCount;

if (thingType == k4_GroupThingType) {
for (uint16 i = 0; i < thingCount; ++i) {
uint16 *nextSlot = _g284_thingData[thingType] + i *thingStoreWordCount;
for (uint16 i = 0; i < thingCount; ++i)
for (uint16 j = 0; j < thingStoreWordCount; ++j) {
if (j == 2 || j == 3)
nextSlot[j] = dunDataStream.readByte();
_g284_thingData[thingType][i][j] = dunDataStream.readByte();
else
nextSlot[j] = dunDataStream.readUint16BE();
_g284_thingData[thingType][i][j] = dunDataStream.readUint16BE();
}
}
} else if (thingType == k14_ProjectileThingType) {
for (uint16 i = 0; i < thingCount; ++i) {
uint16 *nextSlot = _g284_thingData[thingType] + i * thingStoreWordCount;
nextSlot[0] = dunDataStream.readUint16BE();
nextSlot[1] = dunDataStream.readUint16BE();
nextSlot[2] = dunDataStream.readByte();
nextSlot[3] = dunDataStream.readByte();
nextSlot[4] = dunDataStream.readUint16BE();
_g284_thingData[thingType][i][0] = dunDataStream.readUint16BE();
_g284_thingData[thingType][i][1] = dunDataStream.readUint16BE();
_g284_thingData[thingType][i][2] = dunDataStream.readByte();
_g284_thingData[thingType][i][3] = dunDataStream.readByte();
_g284_thingData[thingType][i][4] = dunDataStream.readUint16BE();
}
} else {
for (uint16 i = 0; i < thingCount; ++i) {
uint16 *nextSlot = _g284_thingData[thingType] + i *thingStoreWordCount;
for (uint16 j = 0; j < thingStoreWordCount; ++j)
nextSlot[j] = dunDataStream.readUint16BE();
_g284_thingData[thingType][i][j] = dunDataStream.readUint16BE();
}
}

if (_vm->_g298_newGame) {
if ((thingType == k4_GroupThingType) || thingType >= k14_ProjectileThingType)
_vm->_timeline->_g369_eventMaxCount += _g278_dungeonFileHeader._thingCounts[thingType];
for (uint16 i = 0; i < g236_AdditionalThingCounts[thingType]; ++i) {
(_g284_thingData[thingType] + (thingCount + i) * thingStoreWordCount)[0] = Thing::_none.toUint16();
_g284_thingData[thingType][thingCount + i][0] = Thing::_none.toUint16();
}
}
}
Expand Down Expand Up @@ -755,36 +757,33 @@ void DungeonMan::f174_setCurrentMapAndPartyMap(uint16 mapIndex) {


Square DungeonMan::f151_getSquare(int16 mapX, int16 mapY) {
int16 L0248_i_Multiple;
#define AL0248_B_IsMapXInBounds L0248_i_Multiple
#define AL0248_i_SquareType L0248_i_Multiple
int16 L0249_i_Multiple;
#define AL0249_B_IsMapYInBounds L0249_i_Multiple
#define AL0249_i_SquareType L0249_i_Multiple

AL0249_B_IsMapYInBounds = (mapY >= 0) && (mapY < _vm->_dungeonMan->_g274_currMapHeight);
if ((AL0248_B_IsMapXInBounds = (mapX >= 0) && (mapX < _vm->_dungeonMan->_g273_currMapWidth)) && AL0249_B_IsMapYInBounds) {
return Square(_vm->_dungeonMan->_g271_currMapData[mapX][mapY]);
bool isInXBounds = (mapX >= 0) && (mapX < _g273_currMapWidth);
bool isInYBounds = (mapY >= 0) && (mapY < _g274_currMapHeight);

if (isInXBounds && isInYBounds)
return Square(_g271_currMapData[mapX][mapY]);


Square tmpSquare;
if (isInYBounds) {
tmpSquare.set(_g271_currMapData[0][mapY]);
if (mapX == -1 && (tmpSquare.getType() == k1_CorridorElemType || tmpSquare.getType() == k2_PitElemType))
return Square(k0_WallElemType).set(k0x0004_WallEastRandOrnAllowed);

tmpSquare.set(_g271_currMapData[_g273_currMapWidth - 1][mapY]);
if (mapX == _g273_currMapWidth && (tmpSquare.getType() == k1_CorridorElemType || tmpSquare.getType() == k2_PitElemType))
return Square(k0_WallElemType).set(k0x0001_WallWestRandOrnAllowed);
} else if (isInXBounds) {
tmpSquare.set(_g271_currMapData[mapX][0]);
if (mapY == -1 && (tmpSquare.getType() == k1_CorridorElemType || tmpSquare.getType() == k2_PitElemType))
return Square(k0_WallElemType).set(k0x0002_WallSouthRandOrnAllowed);

tmpSquare.set(_g271_currMapData[mapX][_g274_currMapHeight - 1]);
if (mapY == _g274_currMapHeight && (tmpSquare.getType() == k1_CorridorElemType || tmpSquare.getType() == k2_PitElemType))
return Square((k0_WallElemType << 5) | k0x0008_WallNorthRandOrnAllowed);
}

if (AL0249_B_IsMapYInBounds) {
if (((mapX == -1) && ((AL0249_i_SquareType = Square(_vm->_dungeonMan->_g271_currMapData[0][mapY]).getType()) == k1_CorridorElemType)) || (AL0249_i_SquareType == k2_ElementTypePit)) {
return Square(k0_ElementTypeWall, k0x0004_WallEastRandOrnAllowed);
}
if (((mapX == _vm->_dungeonMan->_g273_currMapWidth) && ((AL0249_i_SquareType = Square(_vm->_dungeonMan->_g271_currMapData[_vm->_dungeonMan->_g273_currMapWidth - 1][mapY]).getType()) == k1_CorridorElemType)) || (AL0249_i_SquareType == k2_ElementTypePit)) {
return Square(k0_ElementTypeWall, k0x0001_WallWestRandOrnAllowed);
}
} else {
if (AL0248_B_IsMapXInBounds) {
if (((mapY == -1) && ((AL0248_i_SquareType = Square(_vm->_dungeonMan->_g271_currMapData[mapX][0]).getType()) == k1_CorridorElemType)) || (AL0248_i_SquareType == k2_ElementTypePit)) {
return Square(k0_ElementTypeWall, k0x0002_WallSouthRandOrnAllowed);
}
if (((mapY == _vm->_dungeonMan->_g274_currMapHeight) && ((AL0248_i_SquareType = Square(_vm->_dungeonMan->_g271_currMapData[mapX][_vm->_dungeonMan->_g274_currMapHeight - 1]).getType()) == k1_CorridorElemType)) || (AL0248_i_SquareType == k2_ElementTypePit)) {
return Square(k0_ElementTypeWall, k0x0008_WallNorthRandOrnAllowed);
}
}
}
return Square(k0_ElementTypeWall, 0);
return Square(k0_WallElemType);
}

Square DungeonMan::f152_getRelSquare(direction dir, int16 stepsForward, int16 stepsRight, int16 posX, int16 posY) {
Expand All @@ -793,23 +792,17 @@ Square DungeonMan::f152_getRelSquare(direction dir, int16 stepsForward, int16 st
}

int16 DungeonMan::f160_getSquareFirstThingIndex(int16 mapX, int16 mapY) {
uint16 L0260_ui_ThingIndex;
int16 L0261_i_MapY;
register unsigned char* L0262_puc_Square;
if (mapX < 0 || mapX >= _g273_currMapWidth || mapY < 0 || mapY >= _g274_currMapHeight || !Square(_g271_currMapData[mapX][mapY]).get(k0x0010_ThingListPresent))
return -1;

int16 y = 0;
uint16 index = _g270_currMapColCumulativeSquareFirstThingCount[mapX];
byte* square = _g271_currMapData[mapX];
while (y++ != mapY)
if (Square(*square++).get(k0x0010_ThingListPresent))
index++;

L0262_puc_Square = _vm->_dungeonMan->_g271_currMapData[mapX];
if ((mapX < 0) || (mapX >= _vm->_dungeonMan->_g273_currMapWidth) || (mapY < 0) || (mapY >= _vm->_dungeonMan->_g274_currMapHeight) || !getFlag(L0262_puc_Square[mapY], k0x0010_ThingListPresent)) {
return -1;
}
L0261_i_MapY = 0;
L0260_ui_ThingIndex = _vm->_dungeonMan->_g270_currMapColCumulativeSquareFirstThingCount[mapX];
while (L0261_i_MapY++ != mapY) {
if (getFlag(*L0262_puc_Square++, k0x0010_ThingListPresent)) {
L0260_ui_ThingIndex++;
}
}
return L0260_ui_ThingIndex;
return index;
}

Thing DungeonMan::f161_getSquareFirstThing(int16 mapX, int16 mapY) {
Expand Down Expand Up @@ -966,33 +959,31 @@ differents sides of the wall, the same text is drawn on each affected side */
aspectArray[k1_FirstGroupOrObjectAspect] = thing.toUint16();
}

void DungeonMan::f171_setSquareAspectOrnOrdinals(uint16 *aspectArray, bool leftAllowed, bool frontAllowed, bool rightAllowed, int16 dir,
void DungeonMan::f171_setSquareAspectOrnOrdinals(uint16 *aspectArray, bool leftAllowed, bool frontAllowed, bool rightAllowed, direction dir,
int16 mapX, int16 mapY, bool isFakeWall) {
int16 L0306_i_Multiple;
#define AL0306_i_RandomWallOrnamentCount L0306_i_Multiple
#define AL0306_i_SideIndex L0306_i_Multiple


AL0306_i_RandomWallOrnamentCount = _vm->_dungeonMan->_g269_currMap->_randWallOrnCount;
aspectArray[k2_RightWallOrnOrdAspect] = _vm->_dungeonMan->f170_getRandomOrnOrdinal(leftAllowed, AL0306_i_RandomWallOrnamentCount, mapX, ++mapY * (M21_normalizeModulo4(++dir) + 1), 30);
aspectArray[k3_FrontWallOrnOrdAspect] = _vm->_dungeonMan->f170_getRandomOrnOrdinal(frontAllowed, AL0306_i_RandomWallOrnamentCount, mapX, mapY * (M21_normalizeModulo4(++dir) + 1), 30);
aspectArray[k4_LeftWallOrnOrdAspect] = _vm->_dungeonMan->f170_getRandomOrnOrdinal(rightAllowed, AL0306_i_RandomWallOrnamentCount, mapX, mapY-- * (M21_normalizeModulo4(++dir) + 1), 30);
if (isFakeWall || (mapX < 0) || (mapX >= _vm->_dungeonMan->_g273_currMapWidth) || (mapY < 0) || (mapY >= _vm->_dungeonMan->_g274_currMapHeight)) { /* If square is a fake wall or is out of map bounds */
for (AL0306_i_SideIndex = k2_RightWallOrnOrdAspect; AL0306_i_SideIndex <= k4_LeftWallOrnOrdAspect; AL0306_i_SideIndex++) { /* Loop to remove any random ornament that is an alcove */
if (_vm->_dungeonMan->f149_isWallOrnAnAlcove(_vm->M1_ordinalToIndex(aspectArray[AL0306_i_SideIndex]))) {
aspectArray[AL0306_i_SideIndex] = 0;
}
int16 ornCount = _g269_currMap->_randWallOrnCount;

turnDirRight(dir);
aspectArray[k2_RightWallOrnOrdAspect] = f170_getRandomOrnOrdinal(leftAllowed, ornCount, mapX, ++mapY * (dir + 1), 30);
turnDirRight(dir);
aspectArray[k3_FrontWallOrnOrdAspect] = f170_getRandomOrnOrdinal(frontAllowed, ornCount, mapX, ++mapY * (dir + 1), 30);
turnDirRight(dir);
aspectArray[k4_LeftWallOrnOrdAspect] = f170_getRandomOrnOrdinal(rightAllowed, ornCount, mapX, ++mapY * (dir + 1), 30);

if (isFakeWall || mapX < 0 || mapX >= _g273_currMapWidth || mapY < 0 || mapY >= _g274_currMapHeight) {
for (uint16 i = k2_RightWallOrnOrdAspect; i <= k4_LeftWallOrnOrdAspect; ++i) {
if (f149_isWallOrnAnAlcove(_vm->M1_ordinalToIndex(aspectArray[i])))
aspectArray[i] = 0;
}
}
}

int16 DungeonMan::f170_getRandomOrnOrdinal(bool allowed, int16 count, int16 mapX, int16 mapY, int16 modulo) {
int16 L0305_i_RandomOrnamentIndex;


if (allowed && ((L0305_i_RandomOrnamentIndex = f169_getRandomOrnamentIndex((int16)2000 + (mapX << 5) + mapY, (int16)3000 + (_vm->_dungeonMan->_g272_currMapIndex << (int16)6) + _vm->_dungeonMan->_g273_currMapWidth + _vm->_dungeonMan->_g274_currMapHeight, modulo)) < count)) {
return _vm->M0_indexToOrdinal(L0305_i_RandomOrnamentIndex);
}
int16 index = (((((2000 + (mapX << 5) + mapY) * 31417) >> 1)
+ (3000 + (_g272_currMapIndex << 6) + _g273_currMapWidth + _g274_currMapHeight) * 11
+ _g278_dungeonFileHeader._ornamentRandomSeed) >> 2) % modulo;
if (allowed && index < count)
return _vm->M0_indexToOrdinal(index);
return 0;
}

Expand All @@ -1006,15 +997,15 @@ bool DungeonMan::f149_isWallOrnAnAlcove(int16 wallOrnIndex) {
}

uint16 *DungeonMan::f156_getThingData(Thing thing) {
return _g284_thingData[thing.getType()] + thing.getIndex() * g235_ThingDataWordCount[thing.getType()];
return _g284_thingData[thing.getType()][thing.getIndex()];
}

uint16* DungeonMan::f157_getSquareFirstThingData(int16 mapX, int16 mapY) {
return f156_getThingData(f161_getSquareFirstThing(mapX, mapY));
}

Thing DungeonMan::f159_getNextThing(Thing thing) {
return Thing(f156_getThingData(thing)[0]);
return Thing(f156_getThingData(thing)[0]); // :)
}

char g255_MessageAndScrollEscReplacementStrings[32][8] = { // @ G0255_aac_Graphic559_MessageAndScrollEscapeReplacementStrings
Expand Down Expand Up @@ -1119,10 +1110,10 @@ char g257_InscriptionEscReplacementStrings[32][8] = { // @ G0257_aac_Graphic559_


void DungeonMan::f168_decodeText(char *destString, Thing thing, TextType type) {
char sepChar;
TextString textString(_g284_thingData[k2_TextstringType] + thing.getIndex() * g235_ThingDataWordCount[k2_TextstringType]);
TextString textString(_g284_thingData[k2_TextstringType][thing.getIndex()]);
if ((textString.isVisible()) || (type & k0x8000_DecodeEvenIfInvisible)) {
type = (TextType)(type & ~k0x8000_DecodeEvenIfInvisible);
char sepChar;
if (type == k1_TextTypeMessage) {
*destString++ = '\n';
sepChar = ' ';
Expand Down Expand Up @@ -1313,56 +1304,46 @@ int16 DungeonMan::f141_getObjectInfoIndex(Thing thing) {
}

void DungeonMan::f163_linkThingToList(Thing thingToLink, Thing thingInList, int16 mapX, int16 mapY) {
Thing L0265_T_Thing;
uint16 L0266_ui_Multiple;
#define AL0266_ui_Column L0266_ui_Multiple
#define AL0266_ui_SquareFirstThingIndex L0266_ui_Multiple
Thing* L0267_pT_Thing;
byte* L0268_puc_Square;
Thing* L0269_ps_Generic;
uint16 L0270_ui_MapY;
if (thingToLink == Thing::_endOfList)
return;

uint16 *rawObjPtr = f156_getThingData(thingToLink);
*rawObjPtr = Thing::_endOfList.toUint16();

if (thingToLink == Thing::_endOfList) {
return;
}
L0269_ps_Generic = (Thing*)f156_getThingData(thingToLink);
*L0269_ps_Generic = Thing::_endOfList;
/* If mapX >= 0 then the thing is linked to the list of things on the specified square else it is linked at the end of the specified thing list */
if (mapX >= 0) {
L0268_puc_Square = &_g271_currMapData[mapX][mapY];
if (getFlag(*L0268_puc_Square, k0x0010_ThingListPresent)) {
Square *squarePtr = (Square*)&_g271_currMapData[mapX][mapY];
if (squarePtr->get(k0x0010_ThingListPresent)) {
thingInList = f161_getSquareFirstThing(mapX, mapY);
} else {
setFlag(*L0268_puc_Square, k0x0010_ThingListPresent);
uint16 * tmp = _g270_currMapColCumulativeSquareFirstThingCount + mapX + 1;
AL0266_ui_Column = _g282_dungeonColumCount - (_g281_dungeonMapsFirstColumnIndex[_g272_currMapIndex] + mapX) - 1;
while (AL0266_ui_Column--) { /* For each column starting from and after the column containing the square where the thing is added */
(*tmp++)++; /* Increment the cumulative first thing count */
squarePtr->set(k0x0010_ThingListPresent);
uint16 *cumulativeCount = &_g270_currMapColCumulativeSquareFirstThingCount[mapX + 1];
uint16 column = _g282_dungeonColumCount - (_g281_dungeonMapsFirstColumnIndex[_g272_currMapIndex] + mapX) - 1;
while (column--) {
(*cumulativeCount++)++;
}
L0270_ui_MapY = 0;
L0268_puc_Square -= mapY;
AL0266_ui_SquareFirstThingIndex = _g270_currMapColCumulativeSquareFirstThingCount[mapX];
while (L0270_ui_MapY++ != mapY) {
if (getFlag(*L0268_puc_Square++, k0x0010_ThingListPresent)) {
AL0266_ui_SquareFirstThingIndex++;
uint16 mapYStep = 0;
squarePtr -= mapY;
uint16 squareFirstThingIndex = _g270_currMapColCumulativeSquareFirstThingCount[mapX];
while (mapYStep++ != mapY) {
if (squarePtr->get(k0x0010_ThingListPresent)) {
squareFirstThingIndex++;
}
squarePtr++;
}
L0267_pT_Thing = &_g283_squareFirstThings[AL0266_ui_SquareFirstThingIndex];
// the second '- 1' is for the loop initialization, > 0 is because we are copying from one behind
for (int16 i = _g278_dungeonFileHeader._squareFirstThingCount - AL0266_ui_SquareFirstThingIndex - 1 - 1; i > 0; --i)
L0267_pT_Thing[i] = L0267_pT_Thing[i - 1];

*L0267_pT_Thing = thingToLink;
Thing* thingPtr = &_g283_squareFirstThings[squareFirstThingIndex];
memmove(thingPtr + 1, thingPtr, sizeof(Thing) * (_g278_dungeonFileHeader._squareFirstThingCount - squareFirstThingIndex - 1));
*thingPtr = thingToLink;
return;
}
}
L0265_T_Thing = f159_getNextThing(thingInList);
while (L0265_T_Thing != Thing::_endOfList) {
L0265_T_Thing = f159_getNextThing(thingInList = L0265_T_Thing);

Thing thing = f159_getNextThing(thingInList);
while (thing != Thing::_endOfList) {
thing = f159_getNextThing(thing);
thingInList = thing;
}
L0269_ps_Generic = (Thing*)f156_getThingData(thingInList);
*L0269_ps_Generic = thingToLink;
rawObjPtr = f156_getThingData(thingInList);
*rawObjPtr = thingToLink.toUint16();
}

WeaponInfo* DungeonMan::f158_getWeaponInfo(Thing thing) {
Expand Down Expand Up @@ -1714,10 +1695,4 @@ Thing DungeonMan::f167_getObjForProjectileLaucherOrObjGen(uint16 iconIndex) {
}
return L0295_T_Thing;
}

int16 DungeonMan::f169_getRandomOrnamentIndex(uint16 val1, uint16 val2, int16 modulo) {
return ((((((val1 * 31417) & 0xFFFF) >> 1) + ((val2 * 11) & 0xFFFF)
+ _vm->_dungeonMan->_g278_dungeonFileHeader._ornamentRandomSeed) & 0xFFFF) >> 2) % modulo; /* Pseudorandom number generator */
}

}
4 changes: 4 additions & 0 deletions engines/dm/eventman.cpp
Expand Up @@ -305,6 +305,10 @@ EventManager::EventManager(DMEngine *vm) : _vm(vm) {
_g326_refreshMousePointerInMainLoop = false;
_g341_highlightBoxEnabled = false;
_g599_useChampionIconOrdinalAsMousePointerBitmap = 0;
_g439_pendingClickButton = k0_NoneMouseButton;
_g600_useObjectAsMousePointerBitmap = false;
_g601_useHandAsMousePointerBitmap = false;
_gK100_preventBuildPointerScreenArea = false;
}

EventManager::~EventManager() {
Expand Down

0 comments on commit dce7465

Please sign in to comment.