Skip to content

Commit

Permalink
DM: reduce some more redirections
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerke committed Sep 26, 2016
1 parent 53790e7 commit dc19419
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 203 deletions.
53 changes: 30 additions & 23 deletions engines/dm/champion.cpp
Expand Up @@ -666,11 +666,13 @@ uint16 ChampionMan::getStrength(int16 champIndex, int16 slotIndex) {
Thing ChampionMan::getObjectRemovedFromSlot(uint16 champIndex, uint16 slotIndex) {
Champion *curChampion = &_champions[champIndex];
DungeonMan &dungeon = *_vm->_dungeonMan;
InventoryMan &inventory = *_vm->_inventoryMan;

Thing curThing;

if (slotIndex >= kDMSlotChest1) {
curThing = _vm->_inventoryMan->_chestSlots[slotIndex - kDMSlotChest1];
_vm->_inventoryMan->_chestSlots[slotIndex - kDMSlotChest1] = Thing::_none;
curThing = inventory._chestSlots[slotIndex - kDMSlotChest1];
inventory._chestSlots[slotIndex - kDMSlotChest1] = Thing::_none;
} else {
curThing = curChampion->_slots[slotIndex];
curChampion->_slots[slotIndex] = Thing::_none;
Expand All @@ -679,7 +681,7 @@ Thing ChampionMan::getObjectRemovedFromSlot(uint16 champIndex, uint16 slotIndex)
if (curThing == Thing::_none)
return Thing::_none;

bool isInventoryChampion = (_vm->indexToOrdinal(champIndex) == _vm->_inventoryMan->_inventoryChampionOrdinal);
bool isInventoryChampion = (_vm->indexToOrdinal(champIndex) == inventory._inventoryChampionOrdinal);
int16 curIconIndex = _vm->_objectMan->getIconIndex(curThing);
// Remove object modifiers
applyModifiersToStatistics(curChampion, slotIndex, curIconIndex, -1, curThing);
Expand All @@ -689,7 +691,7 @@ Thing ChampionMan::getObjectRemovedFromSlot(uint16 champIndex, uint16 slotIndex)
if ((curIconIndex >= kDMIconIndiceJunkIllumuletUnequipped) && (curIconIndex <= kDMIconIndiceJunkIllumuletEquipped)) {
((Junk *)curWeapon)->setChargeCount(0);
_party._magicalLightAmount -= _lightPowerToLightAmount[2];
_vm->_inventoryMan->setDungeonViewPalette();
inventory.setDungeonViewPalette();
} else if ((curIconIndex >= kDMIconIndiceJunkJewelSymalUnequipped) && (curIconIndex <= kDMIconIndiceJunkJewelSymalEquipped)) {
((Junk *)curWeapon)->setChargeCount(0);
}
Expand All @@ -713,14 +715,14 @@ Thing ChampionMan::getObjectRemovedFromSlot(uint16 champIndex, uint16 slotIndex)

if ((curIconIndex >= kDMIconIndiceWeaponTorchUnlit) && (curIconIndex <= kDMIconIndiceWeaponTorchLit)) {
curWeapon->setLit(false);
_vm->_inventoryMan->setDungeonViewPalette();
inventory.setDungeonViewPalette();
drawChangedObjectIcons();
}

if (isInventoryChampion && (slotIndex == kDMSlotActionHand)) {
switch (curIconIndex) {
case kDMIconIndiceContainerChestClosed:
_vm->_inventoryMan->closeChest();
inventory.closeChest();
// No break on purpose
case kDMIconIndiceScrollOpen:
case kDMIconIndiceScrollClosed:
Expand Down Expand Up @@ -1126,12 +1128,12 @@ void ChampionMan::championPoison(int16 champIndex, uint16 attack) {
if ((champIndex == kDMChampionNone) || (_vm->indexToOrdinal(champIndex) == _candidateChampionOrdinal))
return;

InventoryMan &inventory = *_vm->_inventoryMan;
Champion *curChampion = &_champions[champIndex];
addPendingDamageAndWounds_getDamage(champIndex, MAX(1, attack >> 6), kDMWoundNone, kDMAttackTypeNormal);
setFlag(curChampion->_attributes, kDMAttributeStatistics);
if ((_vm->indexToOrdinal(champIndex) == _vm->_inventoryMan->_inventoryChampionOrdinal) && (_vm->_inventoryMan->_panelContent == kDMPanelContentFoodWaterPoisoned)) {
if ((_vm->indexToOrdinal(champIndex) == inventory._inventoryChampionOrdinal) && (inventory._panelContent == kDMPanelContentFoodWaterPoisoned))
setFlag(curChampion->_attributes, kDMAttributePanel);
}

if (--attack) {
curChampion->_poisonEventCount++;
Expand Down Expand Up @@ -1321,25 +1323,26 @@ void ChampionMan::clickOnSlotBox(uint16 slotBoxIndex) {
uint16 champIndex;
uint16 slotIndex;

InventoryMan &inventory = *_vm->_inventoryMan;
if (slotBoxIndex < kDMSlotBoxInventoryFirstSlot) {
if (_candidateChampionOrdinal)
return;

champIndex = slotBoxIndex >> 1;
if ((champIndex >= _partyChampionCount) || (_vm->indexToOrdinal(champIndex) == _vm->_inventoryMan->_inventoryChampionOrdinal) || !_champions[champIndex]._currHealth)
if ((champIndex >= _partyChampionCount) || (_vm->indexToOrdinal(champIndex) == inventory._inventoryChampionOrdinal) || !_champions[champIndex]._currHealth)
return;

slotIndex = getHandSlotIndex(slotBoxIndex);
} else {
champIndex = _vm->ordinalToIndex(_vm->_inventoryMan->_inventoryChampionOrdinal);
champIndex = _vm->ordinalToIndex(inventory._inventoryChampionOrdinal);
slotIndex = slotBoxIndex - kDMSlotBoxInventoryFirstSlot;
}

DungeonMan &dungeon = *_vm->_dungeonMan;
Thing leaderHandObject = _leaderHandObject;
Thing slotThing;
if (slotIndex >= kDMSlotChest1)
slotThing = _vm->_inventoryMan->_chestSlots[slotIndex - kDMSlotChest1];
slotThing = inventory._chestSlots[slotIndex - kDMSlotChest1];
else
slotThing = _champions[champIndex]._slots[slotIndex];

Expand Down Expand Up @@ -1483,10 +1486,10 @@ void ChampionMan::championKill(uint16 champIndex) {
Champion *curChampion = &_champions[champIndex];
EventManager &evtMan = *_vm->_eventMan;
DisplayMan &display = *_vm->_displayMan;

InventoryMan &inventory = *_vm->_inventoryMan;
curChampion->_currHealth = 0;
setFlag(curChampion->_attributes, kDMAttributeStatusBox);
if (_vm->indexToOrdinal(champIndex) == _vm->_inventoryMan->_inventoryChampionOrdinal) {
if (_vm->indexToOrdinal(champIndex) == inventory._inventoryChampionOrdinal) {
if (_vm->_pressingEye) {
_vm->_pressingEye = false;
evtMan._ignoreMouseMovements = false;
Expand All @@ -1501,7 +1504,7 @@ void ChampionMan::championKill(uint16 champIndex) {
evtMan._hideMousePointerRequestCount = 1;
evtMan.hideMouse();
}
_vm->_inventoryMan->toggleInventory(kDMChampionCloseInventory);
inventory.toggleInventory(kDMChampionCloseInventory);
}
dropAllObjects(champIndex);
Thing unusedThing = dungeon.getUnusedThing(kDMMaskChampionBones | kDMThingTypeJunk);
Expand Down Expand Up @@ -1611,6 +1614,8 @@ void ChampionMan::applyTimeEffects() {
return;

DungeonMan &dungeon = *_vm->_dungeonMan;
InventoryMan &inventory = *_vm->_inventoryMan;

Scent checkScent;
checkScent.setMapX(dungeon._partyMapX);
checkScent.setMapY(dungeon._partyMapY);
Expand Down Expand Up @@ -1722,8 +1727,8 @@ void ChampionMan::applyTimeEffects() {
setFlag(championPtr->_attributes, kDMAttributeIcon);
}
setFlag(championPtr->_attributes, kDMAttributeStatistics);
if (_vm->indexToOrdinal(championIndex) == _vm->_inventoryMan->_inventoryChampionOrdinal) {
if (_vm->_pressingMouth || _vm->_pressingEye || (_vm->_inventoryMan->_panelContent == kDMPanelContentFoodWaterPoisoned)) {
if (_vm->indexToOrdinal(championIndex) == inventory._inventoryChampionOrdinal) {
if (_vm->_pressingMouth || _vm->_pressingEye || (inventory._panelContent == kDMPanelContentFoodWaterPoisoned)) {
setFlag(championPtr->_attributes, kDMAttributePanel);
}
}
Expand Down Expand Up @@ -2167,12 +2172,13 @@ void ChampionMan::drawChampionState(ChampionIndex champIndex) {
EventManager &evtMan = *_vm->_eventMan;
TextMan &txtMan = *_vm->_textMan;
DisplayMan &display = *_vm->_displayMan;
InventoryMan &inventory = *_vm->_inventoryMan;

uint16 championAttributes = curChampion->_attributes;
if (!getFlag(championAttributes, kDMAttributeNameTitle | kDMAttributeStatistics | kDMAttributeLoad | kDMAttributeIcon | kDMAttributePanel | kDMAttributeStatusBox | kDMAttributeWounds | kDMAttributeViewport | kDMAttributeActionHand))
return;

bool isInventoryChampion = (_vm->indexToOrdinal(champIndex) == _vm->_inventoryMan->_inventoryChampionOrdinal);
bool isInventoryChampion = (_vm->indexToOrdinal(champIndex) == inventory._inventoryChampionOrdinal);
display._useByteBoxCoordinates = false;
evtMan.showMouse();
if (getFlag(championAttributes, kDMAttributeStatusBox)) {
Expand Down Expand Up @@ -2201,7 +2207,7 @@ void ChampionMan::drawChampionState(ChampionIndex champIndex) {
display.blitToScreen(display.getNativeBitmapOrGraphic(nativeBitmapIndices[borderCount]), &box, k40_byteWidth, kDMColorFlesh, 29);

if (isInventoryChampion) {
_vm->_inventoryMan->drawStatusBoxPortrait(champIndex);
inventory.drawStatusBoxPortrait(champIndex);
setFlag(championAttributes, kDMAttributeStatistics);
} else
setFlag(championAttributes, kDMAttributeNameTitle | kDMAttributeStatistics | kDMAttributeWounds | kDMAttributeActionHand);
Expand Down Expand Up @@ -2322,12 +2328,12 @@ void ChampionMan::drawChampionState(ChampionIndex champIndex) {
}
if (getFlag(championAttributes, kDMAttributePanel) && isInventoryChampion) {
if (_vm->_pressingMouth)
_vm->_inventoryMan->drawPanelFoodWaterPoisoned();
inventory.drawPanelFoodWaterPoisoned();
else if (_vm->_pressingEye) {
if (_leaderEmptyHanded)
_vm->_inventoryMan->drawChampionSkillsAndStatistics();
inventory.drawChampionSkillsAndStatistics();
} else
_vm->_inventoryMan->drawPanel();
inventory.drawPanel();

setFlag(championAttributes, kDMAttributeViewport);
}
Expand Down Expand Up @@ -2358,9 +2364,10 @@ void ChampionMan::drawSlot(uint16 champIndex, int16 slotIndex) {
Champion *champ = &_champions[champIndex];
EventManager &evtMan = *_vm->_eventMan;
DisplayMan &display = *_vm->_displayMan;
InventoryMan &inventory = *_vm->_inventoryMan;

int16 nativeBitmapIndex = -1;
bool isInventoryChamp = (_vm->_inventoryMan->_inventoryChampionOrdinal == _vm->indexToOrdinal(champIndex));
bool isInventoryChamp = (inventory._inventoryChampionOrdinal == _vm->indexToOrdinal(champIndex));

uint16 slotBoxIndex;
if (!isInventoryChamp) {
Expand All @@ -2373,7 +2380,7 @@ void ChampionMan::drawSlot(uint16 champIndex, int16 slotIndex) {

Thing thing;
if (slotIndex >= kDMSlotChest1)
thing = _vm->_inventoryMan->_chestSlots[slotIndex - kDMSlotChest1];
thing = inventory._chestSlots[slotIndex - kDMSlotChest1];
else
thing = champ->getSlot((ChampionSlot)slotIndex);

Expand Down
9 changes: 5 additions & 4 deletions engines/dm/dungeonman.cpp
Expand Up @@ -867,6 +867,7 @@ void DungeonMan::setSquareAspect(uint16 *aspectArray, Direction dir, int16 mapX,
#define AL0307_uc_ScentOrdinal L0307_uc_Multiple

DisplayMan &displMan = *_vm->_displayMan;
ChampionMan &championMan = *_vm->_championMan;

for (uint16 i = 0; i < 5; ++i)
aspectArray[i] = 0;
Expand Down Expand Up @@ -970,8 +971,8 @@ void DungeonMan::setSquareAspect(uint16 *aspectArray, Direction dir, int16 mapX,
curThing = getNextThing(curThing);
}

AL0307_uc_ScentOrdinal = _vm->_championMan->getScentOrdinal(mapX, mapY);
if (AL0307_uc_FootprintsAllowed && (AL0307_uc_ScentOrdinal) && (--AL0307_uc_ScentOrdinal >= _vm->_championMan->_party._firstScentIndex) && (AL0307_uc_ScentOrdinal < _vm->_championMan->_party._lastScentIndex))
AL0307_uc_ScentOrdinal = championMan.getScentOrdinal(mapX, mapY);
if (AL0307_uc_FootprintsAllowed && (AL0307_uc_ScentOrdinal) && (--AL0307_uc_ScentOrdinal >= championMan._party._firstScentIndex) && (AL0307_uc_ScentOrdinal < championMan._party._lastScentIndex))
setFlag(aspectArray[kDMSquareAspectFloorOrn], kDMMaskFootprints);

break;
Expand All @@ -995,8 +996,8 @@ void DungeonMan::setSquareAspect(uint16 *aspectArray, Direction dir, int16 mapX,
while ((curThing != Thing::_endOfList) && (curThing.getType() <= kDMThingTypeSensor))
curThing = getNextThing(curThing);

AL0307_uc_ScentOrdinal = _vm->_championMan->getScentOrdinal(mapX, mapY);
if (AL0307_uc_FootprintsAllowed && (AL0307_uc_ScentOrdinal) && (--AL0307_uc_ScentOrdinal >= _vm->_championMan->_party._firstScentIndex) && (AL0307_uc_ScentOrdinal < _vm->_championMan->_party._lastScentIndex))
AL0307_uc_ScentOrdinal = championMan.getScentOrdinal(mapX, mapY);
if (AL0307_uc_FootprintsAllowed && (AL0307_uc_ScentOrdinal) && (--AL0307_uc_ScentOrdinal >= championMan._party._firstScentIndex) && (AL0307_uc_ScentOrdinal < championMan._party._lastScentIndex))
setFlag(aspectArray[kDMSquareAspectFloorOrn], kDMMaskFootprints);
break;
}
Expand Down
13 changes: 7 additions & 6 deletions engines/dm/eventman.cpp
Expand Up @@ -725,6 +725,7 @@ void EventManager::processCommandQueue() {

DisplayMan &displMan = *_vm->_displayMan;
TextMan &txtMan = *_vm->_textMan;
InventoryMan &inventory = *_vm->_inventoryMan;

_isCommandQueueLocked = true;
if (_commandQueue.empty()) { /* If the command queue is empty */
Expand Down Expand Up @@ -787,14 +788,14 @@ void EventManager::processCommandQueue() {

int16 championIndex = cmdType - kDMCommandToggleInventoryChampion0;
if (((championIndex == kDMChampionCloseInventory) || (championIndex < _vm->_championMan->_partyChampionCount)) && !_vm->_championMan->_candidateChampionOrdinal)
_vm->_inventoryMan->toggleInventory((ChampionIndex)championIndex);
inventory.toggleInventory((ChampionIndex)championIndex);

return;
}

if (cmdType == kDMCommandToggleInventoryLeader) {
if (_vm->_championMan->_leaderIndex != kDMChampionNone)
_vm->_inventoryMan->toggleInventory(_vm->_championMan->_leaderIndex);
inventory.toggleInventory(_vm->_championMan->_leaderIndex);

return;
}
Expand All @@ -814,12 +815,12 @@ void EventManager::processCommandQueue() {
}

if (cmdType == kDMCommandClickOnMouth) {
_vm->_inventoryMan->clickOnMouth();
inventory.clickOnMouth();
return;
}

if (cmdType == kDMCommandClickOnEye) {
_vm->_inventoryMan->clickOnEye();
inventory.clickOnEye();
return;
}

Expand All @@ -837,8 +838,8 @@ void EventManager::processCommandQueue() {

if (cmdType == kDMCommandSleep) {
if (!_vm->_championMan->_candidateChampionOrdinal) {
if (_vm->_inventoryMan->_inventoryChampionOrdinal)
_vm->_inventoryMan->toggleInventory(kDMChampionCloseInventory);
if (inventory._inventoryChampionOrdinal)
inventory.toggleInventory(kDMChampionCloseInventory);

_vm->_menuMan->drawDisabledMenu();
_vm->_championMan->_partyIsSleeping = true;
Expand Down
13 changes: 9 additions & 4 deletions engines/dm/gfx.cpp
Expand Up @@ -1108,6 +1108,7 @@ void DisplayMan::drawDoor(uint16 doorThingIndex, DoorState doorState, int16 *doo
if (doorState == kDMDoorStateOpen)
return;

ChampionMan &championMan = *_vm->_championMan;
DoorFrames *doorFramesTemp = doorFrames;
Door *door = (Door *)(_vm->_dungeonMan->_thingData[kDMThingTypeDoor]) + doorThingIndex;
uint16 doorType = door->getType();
Expand All @@ -1121,7 +1122,7 @@ void DisplayMan::drawDoor(uint16 doorThingIndex, DoorState doorState, int16 *doo
flipBitmapVertical(_tmpBitmap, doorFramesTemp->_closedOrDestroyed._srcByteWidth, doorFramesTemp->_closedOrDestroyed._srcHeight);
}

if ((doorFramesTemp == _doorFrameD1C) && _vm->_championMan->_party._event73Count_ThievesEye)
if ((doorFramesTemp == _doorFrameD1C) && championMan._party._event73Count_ThievesEye)
drawDoorOrnament(_vm->indexToOrdinal(k16_DoorOrnThivesEyeMask), kDMDoorOrnamentD1LCR);

if (doorState == kDMDoorStateClosed)
Expand Down Expand Up @@ -1914,6 +1915,8 @@ void DisplayMan::drawSquareD1C(Direction dir, int16 posX, int16 posY) {
static Frame frameCeilingPitD1C = Frame(32, 191, 8, 16, 80, 9, 0, 0); // @ G0156_s_Graphic558_Frame_CeilingPit_D1C
static Box boxThievesEyeVisibleArea(0, 95, 0, 94); // @ G0107_s_Graphic558_Box_ThievesEye_VisibleArea

ChampionMan &championMan = *_vm->_championMan;

CellOrder order;
uint16 squareAspect[5];
bool skip = false;
Expand All @@ -1935,7 +1938,7 @@ void DisplayMan::drawSquareD1C(Direction dir, int16 posX, int16 posY) {
_vm->_dungeonMan->_isFacingAlcove = false;
_vm->_dungeonMan->_isFacingViAltar = false;
_vm->_dungeonMan->_isFacingFountain = false;
if (_vm->_championMan->_party._event73Count_ThievesEye) {
if (championMan._party._event73Count_ThievesEye) {
isDerivedBitmapInCache(kDMDerivedBitmapThievesEyeVisibleArea);
blitToBitmap(_bitmapViewport, getDerivedBitmap(kDMDerivedBitmapThievesEyeVisibleArea),
boxThievesEyeVisibleArea, _boxThievesEyeViewPortVisibleArea._rect.left, _boxThievesEyeViewPortVisibleArea._rect.top,
Expand All @@ -1948,7 +1951,7 @@ void DisplayMan::drawSquareD1C(Direction dir, int16 posX, int16 posY) {
if (isDrawnWallOrnAnAlcove(squareAspect[kDMSquareFrontWallOrnOrd], kDMViewWallD1CFront))
drawObjectsCreaturesProjectilesExplosions(Thing(squareAspect[kDMSquareAspectFirstGroupOrObject]), dir, posX, posY, kDMViewSquareD1C, kDMCellOrderAlcove);

if (_vm->_championMan->_party._event73Count_ThievesEye) {
if (championMan._party._event73Count_ThievesEye) {
blitToBitmap(getDerivedBitmap(kDMDerivedBitmapThievesEyeVisibleArea),
_bitmapViewport, _boxThievesEyeViewPortVisibleArea, 0, 0,
48, k112_byteWidthViewport, kDMColorGold, 95, k136_heightViewport); /* BUG0_74 */
Expand Down Expand Up @@ -2061,12 +2064,14 @@ void DisplayMan::drawSquareD0C(Direction dir, int16 posX, int16 posY) {
static Frame frameCeilingPitD0C = Frame(16, 207, 0, 3, 96, 4, 0, 0); // @ G0159_s_Graphic558_Frame_CeilingPit_D0C
static Box boxThievesEyeHoleInDoorFrame(0, 31, 19, 113); // @ G0108_s_Graphic558_Box_ThievesEye_HoleInDoorFrame

ChampionMan &championMan = *_vm->_championMan;

uint16 squareAspect[5];

_vm->_dungeonMan->setSquareAspect(squareAspect, dir, posX, posY);
switch (squareAspect[kDMSquareAspectElement]) {
case kDMElementTypeDoorSide:
if (_vm->_championMan->_party._event73Count_ThievesEye) {
if (championMan._party._event73Count_ThievesEye) {
memmove(_tmpBitmap, _bitmapWallSetDoorFrameFront, 32 * 123);
blitToBitmap(getNativeBitmapOrGraphic(kDMGraphicIdxHoleInWall),
_tmpBitmap, boxThievesEyeHoleInDoorFrame, doorFrameD0C._box._rect.left - _boxThievesEyeViewPortVisibleArea._rect.left,
Expand Down

0 comments on commit dc19419

Please sign in to comment.