Skip to content

Commit

Permalink
DM: Move some globals to DMEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerke committed Sep 11, 2016
1 parent 8eaf094 commit f90bf31
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 195 deletions.
36 changes: 18 additions & 18 deletions engines/dm/champion.cpp
Expand Up @@ -237,7 +237,7 @@ bool ChampionMan::isObjectThrown(uint16 champIndex, int16 slotIndex, int16 side)
int16 attack = getBoundedValue((uint16)40, (uint16)((skillLevel << 3) + _vm->getRandomNumber(32)), (uint16)200);
int16 stepEnergy = MAX(5, 11 - skillLevel);
_vm->_projexpl->createProjectile(curThing, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY,
normalizeModulo4(_vm->_dungeonMan->_partyDir + side),
_vm->normalizeModulo4(_vm->_dungeonMan->_partyDir + side),
_vm->_dungeonMan->_partyDir, kineticEnergy, attack, stepEnergy);
_vm->_projectileDisableMovementTicks = 4;
_vm->_lastProjectileDisabledMovementDirection = _vm->_dungeonMan->_partyDir;
Expand Down Expand Up @@ -931,7 +931,7 @@ void ChampionMan::disableAction(uint16 champIndex, uint16 ticks) {

int16 eventIndex = curChampion->_enableActionEventIndex;
if (eventIndex >= 0) {
int32 currentEnableActionEventTime = filterTime(_vm->_timeline->_events[eventIndex]._mapTime);
int32 currentEnableActionEventTime = _vm->filterTime(_vm->_timeline->_events[eventIndex]._mapTime);
if (updatedEnableActionEventTime >= currentEnableActionEventTime) {
updatedEnableActionEventTime += (currentEnableActionEventTime - _vm->_gameTime) >> 1;
} else {
Expand All @@ -942,7 +942,7 @@ void ChampionMan::disableAction(uint16 champIndex, uint16 ticks) {
setFlag(curChampion->_attributes, kDMAttributeActionHand | kDMAttributeDisableAction);
drawChampionState((ChampionIndex)champIndex);
}
setMapAndTime(curEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, updatedEnableActionEventTime);
_vm->setMapAndTime(curEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, updatedEnableActionEventTime);
curChampion->_enableActionEventIndex = _vm->_timeline->addEventGetEventIndex(&curEvent);
}

Expand Down Expand Up @@ -1070,7 +1070,7 @@ int16 ChampionMan::getDamagedChampionCount(uint16 attack, int16 wounds, int16 at
}

int16 ChampionMan::getTargetChampionIndex(int16 mapX, int16 mapY, uint16 cell) {
if (_partyChampionCount && (getDistance(mapX, mapY, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY) <= 1)) {
if (_partyChampionCount && (_vm->getDistance(mapX, mapY, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY) <= 1)) {
signed char orderedCellsToAttack[4];
_vm->_groupMan->setOrderedCellsToAttack(orderedCellsToAttack, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, mapX, mapY, cell);
for (uint16 i = 0; i < 4; i++) {
Expand Down Expand Up @@ -1117,7 +1117,7 @@ void ChampionMan::championPoison(int16 champIndex, uint16 attack) {
TimelineEvent newEvent;
newEvent._type = k75_TMEventTypePoisonChampion;
newEvent._priority = champIndex;
setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 36);
_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 36);
newEvent._Bu._attack = attack;
_vm->_timeline->addEventGetEventIndex(&newEvent);
}
Expand All @@ -1129,14 +1129,14 @@ void ChampionMan::setPartyDirection(int16 dir) {
if (dir == _vm->_dungeonMan->_partyDir)
return;

int16 L0834_i_Delta = dir - _vm->_dungeonMan->_partyDir;
if (L0834_i_Delta < 0)
L0834_i_Delta += 4;
int16 dirDiff = dir - _vm->_dungeonMan->_partyDir;
if (dirDiff < 0)
dirDiff += 4;

Champion *curChampion = _champions;
for (int16 i = kDMChampionFirst; i < _partyChampionCount; i++) {
curChampion->_cell = (ViewCell)normalizeModulo4(curChampion->_cell + L0834_i_Delta);
curChampion->_dir = (Direction)normalizeModulo4(curChampion->_dir + L0834_i_Delta);
curChampion->_cell = (ViewCell)_vm->normalizeModulo4(curChampion->_cell + dirDiff);
curChampion->_dir = (Direction)_vm->normalizeModulo4(curChampion->_dir + dirDiff);
curChampion++;
}

Expand Down Expand Up @@ -1357,7 +1357,7 @@ bool ChampionMan::isProjectileSpellCast(uint16 champIndex, Thing thing, int16 ki

void ChampionMan::championShootProjectile(Champion *champ, Thing thing, int16 kineticEnergy, int16 attack, int16 stepEnergy) {
Direction newDirection = champ->_dir;
_vm->_projexpl->createProjectile(thing, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, normalizeModulo4((((champ->_cell - newDirection + 1) & 0x0002) >> 1) + newDirection), newDirection, kineticEnergy, attack, stepEnergy);
_vm->_projexpl->createProjectile(thing, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY, _vm->normalizeModulo4((((champ->_cell - newDirection + 1) & 0x0002) >> 1) + newDirection), newDirection, kineticEnergy, attack, stepEnergy);
_vm->_projectileDisableMovementTicks = 4;
_vm->_lastProjectileDisabledMovementDirection = newDirection;
}
Expand Down Expand Up @@ -1432,12 +1432,12 @@ void ChampionMan::applyAndDrawPendingDamageAndWounds() {
if (eventIndex == -1) {
TimelineEvent newEvent;
newEvent._type = k12_TMEventTypeHideDamageReceived;
setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 5);
_vm->setMapAndTime(newEvent._mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 5);
newEvent._priority = championIndex;
championPtr->_hideDamageReceivedIndex = _vm->_timeline->addEventGetEventIndex(&newEvent);
} else {
TimelineEvent *curEvent = &_vm->_timeline->_events[eventIndex];
setMapAndTime(curEvent->_mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 5);
_vm->setMapAndTime(curEvent->_mapTime, _vm->_dungeonMan->_partyMapIndex, _vm->_gameTime + 5);
_vm->_timeline->fixChronology(_vm->_timeline->getIndex(eventIndex));
}
drawChampionState((ChampionIndex)championIndex);
Expand Down Expand Up @@ -1476,7 +1476,7 @@ void ChampionMan::championKill(uint16 champIndex) {
L0966_ps_Junk->setDoNotDiscard(true);
L0966_ps_Junk->setChargeCount(champIndex);
curCell = curChampion->_cell;
_vm->_moveSens->getMoveResult(thingWithNewCell(unusedThing, curCell), kM1_MapXNotOnASquare, 0, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY);
_vm->_moveSens->getMoveResult(_vm->thingWithNewCell(unusedThing, curCell), kM1_MapXNotOnASquare, 0, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY);
}
curChampion->_symbolStep = 0;
curChampion->_symbols[0] = '\0';
Expand Down Expand Up @@ -1553,7 +1553,7 @@ void ChampionMan::dropAllObjects(uint16 champIndex) {
for (uint16 slotIndex = kDMSlotReadyHand; slotIndex < kDMSlotChest1; slotIndex++) {
Thing curThing = getObjectRemovedFromSlot(champIndex, slotDropOrder[slotIndex]);
if (curThing != Thing::_none)
_vm->_moveSens->getMoveResult(thingWithNewCell(curThing, curCell), kM1_MapXNotOnASquare, 0, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY);
_vm->_moveSens->getMoveResult(_vm->thingWithNewCell(curThing, curCell), kM1_MapXNotOnASquare, 0, _vm->_dungeonMan->_partyMapX, _vm->_dungeonMan->_partyMapY);
}
}

Expand Down Expand Up @@ -1881,10 +1881,10 @@ void ChampionMan::addCandidateChampionToParty(uint16 championPortraitIndex) {
championPtr->_hideDamageReceivedIndex = -1;
championPtr->_dir = _vm->_dungeonMan->_partyDir;
uint16 viewCell = k0_ViewCellFronLeft;
while (getIndexInCell(normalizeModulo4(viewCell + _vm->_dungeonMan->_partyDir)) != kDMChampionNone)
while (getIndexInCell(_vm->normalizeModulo4(viewCell + _vm->_dungeonMan->_partyDir)) != kDMChampionNone)
viewCell++;

championPtr->_cell = (ViewCell)normalizeModulo4(viewCell + _vm->_dungeonMan->_partyDir);
championPtr->_cell = (ViewCell)_vm->normalizeModulo4(viewCell + _vm->_dungeonMan->_partyDir);
championPtr->_attributes = kDMAttributeIcon;
championPtr->_directionMaximumDamageReceived = _vm->_dungeonMan->_partyDir;
championPtr->_food = 1500 + _vm->getRandomNumber(256);
Expand Down Expand Up @@ -1960,7 +1960,7 @@ void ChampionMan::addCandidateChampionToParty(uint16 championPortraitIndex) {

int16 curMapX = _vm->_dungeonMan->_partyMapX;
int16 curMapY = _vm->_dungeonMan->_partyMapY;
uint16 championObjectsCell = returnOppositeDir(_vm->_dungeonMan->_partyDir);
uint16 championObjectsCell = _vm->returnOppositeDir(_vm->_dungeonMan->_partyDir);
curMapX += _vm->_dirIntoStepCountEast[_vm->_dungeonMan->_partyDir], curMapY += _vm->_dirIntoStepCountNorth[_vm->_dungeonMan->_partyDir];
curThing = _vm->_dungeonMan->getSquareFirstThing(curMapX, curMapY);
int16 slotIdx = kDMSlotBackpackLine1_1;
Expand Down
28 changes: 14 additions & 14 deletions engines/dm/dm.cpp
Expand Up @@ -75,59 +75,59 @@ const char *debugGetDirectionName(Direction dir) {
return directionNames[dir];
}

void turnDirRight(Direction &dir) {
void DMEngine::turnDirRight(Direction &dir) {
dir = (Direction)((dir + 1) & 3);
}

void turnDirLeft(Direction &dir) {
void DMEngine::turnDirLeft(Direction &dir) {
dir = (Direction)((dir - 1) & 3);
}

Direction returnOppositeDir(Direction dir) {
Direction DMEngine::returnOppositeDir(Direction dir) {
return (Direction)((dir + 2) & 3);
}

uint16 returnPrevVal(uint16 val) {
uint16 DMEngine::returnPrevVal(uint16 val) {
return (Direction)((val + 3) & 3);
}

uint16 returnNextVal(uint16 val) {
uint16 DMEngine::returnNextVal(uint16 val) {
return (val + 1) & 0x3;
}

bool isOrientedWestEast(Direction dir) {
bool DMEngine::isOrientedWestEast(Direction dir) {
return dir & 1;
}

uint16 toggleFlag(uint16& val, uint16 mask) {
uint16 DMEngine::toggleFlag(uint16& val, uint16 mask) {
return val ^= mask;
}

uint16 bitmapByteCount(uint16 pixelWidth, uint16 height) {
uint16 DMEngine::bitmapByteCount(uint16 pixelWidth, uint16 height) {
return pixelWidth / 2 * height;
}

uint16 normalizeModulo4(uint16 val) {
uint16 DMEngine::normalizeModulo4(uint16 val) {
return val & 3;
}

int32 filterTime(int32 mapTime) {
int32 DMEngine::filterTime(int32 mapTime) {
return mapTime & 0x00FFFFFF;
}

int32 setMapAndTime(int32 &mapTime, uint32 map, uint32 time) {
int32 DMEngine::setMapAndTime(int32 &mapTime, uint32 map, uint32 time) {
return (mapTime) = ((time) | (((long)(map)) << 24));
}

uint16 getMap(int32 mapTime) {
uint16 DMEngine::getMap(int32 mapTime) {
return ((uint16)((mapTime) >> 24));
}

Thing thingWithNewCell(Thing thing, int16 cell) {
Thing DMEngine::thingWithNewCell(Thing thing, int16 cell) {
return Thing(((thing.toUint16()) & 0x3FFF) | ((cell) << 14));
}

int16 getDistance(int16 mapx1, int16 mapy1, int16 mapx2, int16 mapy2) {
int16 DMEngine::getDistance(int16 mapx1, int16 mapy1, int16 mapx2, int16 mapy2) {
return ABS(mapx1 - mapx2) + ABS(mapy1 - mapy2);
}

Expand Down
31 changes: 15 additions & 16 deletions engines/dm/dm.h
Expand Up @@ -200,26 +200,10 @@ class Thing {
bool operator!=(const Thing &rhs) const { return _data != rhs._data; }
}; // @ THING

void turnDirRight(Direction &dir);
void turnDirLeft(Direction &dir);
Direction returnOppositeDir(Direction dir); // @ M18_OPPOSITE
uint16 returnPrevVal(uint16 val); // @ M19_PREVIOUS
uint16 returnNextVal(uint16 val); // @ M17_NEXT
bool isOrientedWestEast(Direction dir); // @ M16_IS_ORIENTED_WEST_EAST

#define setFlag(val, mask) ((val) |= (mask))
#define getFlag(val, mask) ((val) & (mask))
#define clearFlag(val, mask) ((val) &= (~(mask))) // @ M09_CLEAR

uint16 toggleFlag(uint16 &val, uint16 mask); // @ M10_TOGGLE
uint16 bitmapByteCount(uint16 pixelWidth, uint16 height); // @ M75_BITMAP_BYTE_COUNT
uint16 normalizeModulo4(uint16 val); // @ M21_NORMALIZE
int32 filterTime(int32 map_time); // @ M30_TIME
int32 setMapAndTime(int32 &map_time, uint32 map, uint32 time); // @ M33_SET_MAP_AND_TIME
uint16 getMap(int32 map_time); // @ M29_MAP
Thing thingWithNewCell(Thing thing, int16 cell); // @ M15_THING_WITH_NEW_CELL
int16 getDistance(int16 mapx1, int16 mapy1, int16 mapx2, int16 mapy2);// @ M38_DISTANCE

//TODO: Directly use CLIP
template<typename T>
inline T getBoundedValue(T min, T val, T max) {
Expand Down Expand Up @@ -272,6 +256,21 @@ class DMEngine : public Engine {
void fuseSequenceUpdate(); // @ F0445_STARTEND_FuseSequenceUpdate
Common::Language getGameLanguage();

void turnDirRight(Direction &dir);
void turnDirLeft(Direction &dir);
Direction returnOppositeDir(Direction dir); // @ M18_OPPOSITE
uint16 returnPrevVal(uint16 val); // @ M19_PREVIOUS
uint16 returnNextVal(uint16 val); // @ M17_NEXT
bool isOrientedWestEast(Direction dir); // @ M16_IS_ORIENTED_WEST_EAST
uint16 toggleFlag(uint16 &val, uint16 mask); // @ M10_TOGGLE
uint16 bitmapByteCount(uint16 pixelWidth, uint16 height); // @ M75_BITMAP_BYTE_COUNT
uint16 normalizeModulo4(uint16 val); // @ M21_NORMALIZE
int32 filterTime(int32 map_time); // @ M30_TIME
int32 setMapAndTime(int32 &map_time, uint32 map, uint32 time); // @ M33_SET_MAP_AND_TIME
uint16 getMap(int32 map_time); // @ M29_MAP
Thing thingWithNewCell(Thing thing, int16 cell); // @ M15_THING_WITH_NEW_CELL
int16 getDistance(int16 mapx1, int16 mapy1, int16 mapx2, int16 mapy2);// @ M38_DISTANCE

private:
uint16 _dungeonId; // @ G0526_ui_DungeonID
byte *_entranceDoorAnimSteps[10]; // @ G0562_apuc_Bitmap_EntranceDoorAnimationSteps
Expand Down
16 changes: 8 additions & 8 deletions engines/dm/dungeonman.cpp
Expand Up @@ -40,7 +40,7 @@ namespace DM {
void DungeonMan::mapCoordsAfterRelMovement(Direction dir, int16 stepsForward, int16 stepsRight, int16 &posX, int16 &posY) {
posX += _vm->_dirIntoStepCountEast[dir] * stepsForward;
posY += _vm->_dirIntoStepCountNorth[dir] * stepsForward;
turnDirRight(dir);
_vm->turnDirRight(dir);
posX += _vm->_dirIntoStepCountEast[dir] * stepsRight;
posY += _vm->_dirIntoStepCountNorth[dir] * stepsRight;
}
Expand Down Expand Up @@ -895,7 +895,7 @@ void DungeonMan::setSquareAspect(uint16 *aspectArray, Direction dir, int16 mapX,
setSquareAspectOrnOrdinals(aspectArray, leftRandomWallOrnamentAllowed, frontRandomWallOrnamentAllowed, rightRandomWallOrnamentAllowed, dir, mapX, mapY, squareIsFakeWall);
while ((curThing != Thing::_endOfList) && (curThing.getType() <= kDMThingTypeSensor)) {
ThingType curThingType = curThing.getType();
int16 AL0310_i_SideIndex = normalizeModulo4(curThing.getCell() - dir);
int16 AL0310_i_SideIndex = _vm->normalizeModulo4(curThing.getCell() - dir);
if (AL0310_i_SideIndex) { /* Invisible on the back wall if 0 */
Sensor *curSensor = (Sensor *)getThingData(curThing);
if (curThingType == kDMstringTypeText) {
Expand Down Expand Up @@ -960,14 +960,14 @@ void DungeonMan::setSquareAspect(uint16 *aspectArray, Direction dir, int16 mapX,

break;
case k3_ElementTypeStairs:
aspectArray[k0_ElementAspect] = (bool((getFlag(AL0307_uc_Square, k0x0008_StairsNorthSouthOrient) >> 3)) == isOrientedWestEast(dir)) ? k18_ElementTypeStairsSide : k19_ElementTypeStaisFront;
aspectArray[k0_ElementAspect] = (bool((getFlag(AL0307_uc_Square, k0x0008_StairsNorthSouthOrient) >> 3)) == _vm->isOrientedWestEast(dir)) ? k18_ElementTypeStairsSide : k19_ElementTypeStaisFront;
aspectArray[k2_StairsUpAspect] = getFlag(AL0307_uc_Square, k0x0004_StairsUp);
AL0307_uc_FootprintsAllowed = false;
while ((curThing != Thing::_endOfList) && (curThing.getType() <= kDMThingTypeSensor))
curThing = getNextThing(curThing);
break;
case k4_DoorElemType:
if (bool((getFlag(AL0307_uc_Square, k0x0008_DoorNorthSouthOrient) >> 3)) == isOrientedWestEast(dir)) {
if (bool((getFlag(AL0307_uc_Square, (byte) k0x0008_DoorNorthSouthOrient) >> 3)) == _vm->isOrientedWestEast(dir)) {
aspectArray[k0_ElementAspect] = k16_DoorSideElemType;
} else {
aspectArray[k0_ElementAspect] = k17_DoorFrontElemType;
Expand All @@ -991,9 +991,9 @@ void DungeonMan::setSquareAspectOrnOrdinals(uint16 *aspectArray, bool leftAllowe
int16 mapX, int16 mapY, bool isFakeWall) {

int16 randomWallOrnamentCount = _currMap->_randWallOrnCount;
aspectArray[k2_RightWallOrnOrdAspect] = getRandomOrnOrdinal(leftAllowed, randomWallOrnamentCount, mapX, ++mapY * (normalizeModulo4(++dir) + 1), 30);
aspectArray[k3_FrontWallOrnOrdAspect] = getRandomOrnOrdinal(frontAllowed, randomWallOrnamentCount, mapX, mapY * (normalizeModulo4(++dir) + 1), 30);
aspectArray[k4_LeftWallOrnOrdAspect] = getRandomOrnOrdinal(rightAllowed, randomWallOrnamentCount, mapX, mapY-- * (normalizeModulo4(++dir) + 1), 30);
aspectArray[k2_RightWallOrnOrdAspect] = getRandomOrnOrdinal(leftAllowed, randomWallOrnamentCount, mapX, ++mapY * (_vm->normalizeModulo4(++dir) + 1), 30);
aspectArray[k3_FrontWallOrnOrdAspect] = getRandomOrnOrdinal(frontAllowed, randomWallOrnamentCount, mapX, mapY * (_vm->normalizeModulo4(++dir) + 1), 30);
aspectArray[k4_LeftWallOrnOrdAspect] = getRandomOrnOrdinal(rightAllowed, randomWallOrnamentCount, mapX, mapY-- * (_vm->normalizeModulo4(++dir) + 1), 30);
if (isFakeWall || (mapX < 0) || (mapX >= _currMapWidth) || (mapY < 0) || (mapY >= _currMapHeight)) { /* If square is a fake wall or is out of map bounds */
for (int16 sideIndex = k2_RightWallOrnOrdAspect; sideIndex <= k4_LeftWallOrnOrdAspect; sideIndex++) { /* Loop to remove any random ornament that is an alcove */
if (isWallOrnAnAlcove(_vm->ordinalToIndex(aspectArray[sideIndex])))
Expand Down Expand Up @@ -1531,7 +1531,7 @@ void DungeonMan::setGroupDirections(Group *group, int16 dir, uint16 mapIndex) {
if (mapIndex == _partyMapIndex)
_vm->_groupMan->_activeGroups[group->getActiveGroupIndex()]._directions = (Direction)dir;
else
group->setDir(normalizeModulo4(dir));
group->setDir(_vm->normalizeModulo4(dir));
}

bool DungeonMan::isCreatureAllowedOnMap(Thing thing, uint16 mapIndex) {
Expand Down

0 comments on commit f90bf31

Please sign in to comment.