aboutsummaryrefslogtreecommitdiff
path: root/engines/dm/movesens.cpp
diff options
context:
space:
mode:
authorStrangerke2016-09-05 21:06:06 +0200
committerStrangerke2016-09-05 21:08:06 +0200
commit17bf26821b5d800dc7bd9d2fd0e382b6a777e4a6 (patch)
treeff1155848ffaf36d4e86a174523237b99bb2e8c5 /engines/dm/movesens.cpp
parent4befd3a23214953632d1cdc5ba32d2bd1bb7293d (diff)
downloadscummvm-rg350-17bf26821b5d800dc7bd9d2fd0e382b6a777e4a6.tar.gz
scummvm-rg350-17bf26821b5d800dc7bd9d2fd0e382b6a777e4a6.tar.bz2
scummvm-rg350-17bf26821b5d800dc7bd9d2fd0e382b6a777e4a6.zip
DM: Better refactoring of processThingAdditionOrRemoval
Diffstat (limited to 'engines/dm/movesens.cpp')
-rw-r--r--engines/dm/movesens.cpp195
1 files changed, 92 insertions, 103 deletions
diff --git a/engines/dm/movesens.cpp b/engines/dm/movesens.cpp
index 07909c8b2f..fc0f4b2c3c 100644
--- a/engines/dm/movesens.cpp
+++ b/engines/dm/movesens.cpp
@@ -761,119 +761,108 @@ void MovesensMan::processThingAdditionOrRemoval(uint16 mapX, uint16 mapY, Thing
if (addThing && (thingType != kM1_PartyThingType))
_vm->_dungeonMan->linkThingToList(thing, Thing(0), mapX, mapY);
- curThing = _vm->_dungeonMan->getSquareFirstThing(mapX, mapY);
- while (curThing != Thing::_endOfList) {
- bool skipToNextThing = false;
+ for (curThing = _vm->_dungeonMan->getSquareFirstThing(mapX, mapY); curThing != Thing::_endOfList; curThing = _vm->_dungeonMan->getNextThing(curThing)) {
uint16 curThingType = curThing.getType();
if (curThingType == k3_SensorThingType) {
Sensor *curSensor = (Sensor *)_vm->_dungeonMan->getThingData(curThing);
if (curSensor->getType() == k0_SensorDisabled)
- skipToNextThing = true;
+ continue;
+
+ int16 curSensorData = curSensor->getData();
+ bool triggerSensor = addThing;
+ if (sensorTriggeredCell == kM1_CellAny) {
+ switch (curSensor->getType()) {
+ case k1_SensorFloorTheronPartyCreatureObj:
+ if (partySquare || squareContainsObject || squareContainsGroup) /* BUG0_30 A floor sensor is not triggered when you put an object on the floor if a levitating creature is present on the same square. The condition to determine if the sensor should be triggered checks if there is a creature on the square but does not check whether the creature is levitating. While it is normal not to trigger the sensor if there is a non levitating creature on the square (because it was already triggered by the creature itself), a levitating creature should not prevent triggering the sensor with an object. */
+ continue;
+ break;
+ case k2_SensorFloorTheronPartyCreature:
+ if ((thingType > k4_GroupThingType) || partySquare || squareContainsGroup)
+ continue;
+ break;
+ case k3_SensorFloorParty:
+ if ((thingType != kM1_PartyThingType) || (_vm->_championMan->_partyChampionCount == 0))
+ continue;
+
+ if (curSensorData == 0) {
+ if (partySquare)
+ continue;
+ } else if (!addThing)
+ triggerSensor = false;
+ else
+ triggerSensor = (curSensorData == _vm->indexToOrdinal(_vm->_dungeonMan->_partyDir));
+ break;
+ case k4_SensorFloorObj:
+ if ((curSensorData != _vm->_objectMan->getObjectType(thing)) || squareContainsThingOfSameType)
+ continue;
+ break;
+ case k5_SensorFloorPartyOnStairs:
+ if ((thingType != kM1_PartyThingType) || (curSquare.getType() != k3_StairsElemType))
+ continue;
+ break;
+ case k6_SensorFloorGroupGenerator:
+ continue;
+ break;
+ case k7_SensorFloorCreature:
+ if ((thingType > k4_GroupThingType) || (thingType == kM1_PartyThingType) || squareContainsGroup)
+ continue;
+ break;
+ case k8_SensorFloorPartyPossession:
+ if (thingType != kM1_PartyThingType)
+ continue;
- if (!skipToNextThing) {
- int16 curSensorData = curSensor->getData();
- bool triggerSensor = addThing;
- if (sensorTriggeredCell == kM1_CellAny) {
- switch (curSensor->getType()) {
- case k1_SensorFloorTheronPartyCreatureObj:
- if (partySquare || squareContainsObject || squareContainsGroup) /* BUG0_30 A floor sensor is not triggered when you put an object on the floor if a levitating creature is present on the same square. The condition to determine if the sensor should be triggered checks if there is a creature on the square but does not check whether the creature is levitating. While it is normal not to trigger the sensor if there is a non levitating creature on the square (because it was already triggered by the creature itself), a levitating creature should not prevent triggering the sensor with an object. */
- skipToNextThing = true;
- break;
- case k2_SensorFloorTheronPartyCreature:
- if ((thingType > k4_GroupThingType) || partySquare || squareContainsGroup)
- skipToNextThing = true;
- break;
- case k3_SensorFloorParty:
- if ((thingType != kM1_PartyThingType) || (_vm->_championMan->_partyChampionCount == 0)) {
- skipToNextThing = true;
- break;
- }
-
- if (curSensorData == 0) {
- if (partySquare)
- skipToNextThing = true;
- } else if (!addThing)
- triggerSensor = false;
- else
- triggerSensor = (curSensorData == _vm->indexToOrdinal(_vm->_dungeonMan->_partyDir));
- break;
- case k4_SensorFloorObj:
- if ((curSensorData != _vm->_objectMan->getObjectType(thing)) || squareContainsThingOfSameType)
- skipToNextThing = true;
- break;
- case k5_SensorFloorPartyOnStairs:
- if ((thingType != kM1_PartyThingType) || (curSquare.getType() != k3_StairsElemType))
- skipToNextThing = true;
- break;
- case k6_SensorFloorGroupGenerator:
- skipToNextThing = true;
- break;
- case k7_SensorFloorCreature:
- if ((thingType > k4_GroupThingType) || (thingType == kM1_PartyThingType) || squareContainsGroup)
- skipToNextThing = true;
- break;
- case k8_SensorFloorPartyPossession:
- if (thingType != kM1_PartyThingType)
- skipToNextThing = true;
- else
- triggerSensor = isObjectInPartyPossession(curSensorData);
- break;
- case k9_SensorFloorVersionChecker:
- if ((thingType != kM1_PartyThingType) || !addThing || partySquare)
- skipToNextThing = true;
- else
- // Strangerke: 20 is a hardcoded version of the game. later version uses 21. Not present in the original dungeons anyway.
- triggerSensor = (curSensorData <= 20);
- break;
- default:
- skipToNextThing = true;
- break;
- }
- } else {
- if (sensorTriggeredCell != curThing.getCell())
- skipToNextThing = true;
- else {
- switch (curSensor->getType()) {
- case k1_SensorWallOrnClick:
- if (squareContainsObject)
- skipToNextThing = true;
- break;
- case k2_SensorWallOrnClickWithAnyObj:
- if (squareContainsThingOfSameType || (curSensor->getData() != _vm->_objectMan->getObjectType(thing)))
- skipToNextThing = true;
- break;
- case k3_SensorWallOrnClickWithSpecObj:
- if (squareContainsThingOfDifferentType || (curSensor->getData() == _vm->_objectMan->getObjectType(thing)))
- skipToNextThing = true;
- break;
- default:
- skipToNextThing = true;
- break;
- }
- }
+ triggerSensor = isObjectInPartyPossession(curSensorData);
+ break;
+ case k9_SensorFloorVersionChecker:
+ if ((thingType != kM1_PartyThingType) || !addThing || partySquare)
+ continue;
+
+ // Strangerke: 20 is a hardcoded version of the game. later version uses 21. Not present in the original dungeons anyway.
+ triggerSensor = (curSensorData <= 20);
+ break;
+ default:
+ continue;
+ break;
}
- if (!skipToNextThing) {
- triggerSensor ^= curSensor->getAttrRevertEffectA();
- int16 curSensorEffect = curSensor->getAttrEffectA();
- if (curSensorEffect == k3_SensorEffHold)
- curSensorEffect = triggerSensor ? k0_SensorEffSet : k1_SensorEffClear;
- else if (!triggerSensor)
- skipToNextThing = true;
-
- if (!skipToNextThing) {
- if (curSensor->getAttrAudibleA())
- _vm->_sound->requestPlay(k01_soundSWITCH, mapX, mapY, k1_soundModePlayIfPrioritized);
-
- triggerEffect(curSensor, curSensorEffect, mapX, mapY, (uint16)kM1_CellAny); // this will wrap around
- skipToNextThing = true;
- }
+ } else {
+ if (sensorTriggeredCell != curThing.getCell())
+ continue;
+
+ switch (curSensor->getType()) {
+ case k1_SensorWallOrnClick:
+ if (squareContainsObject)
+ continue;
+ break;
+ case k2_SensorWallOrnClickWithAnyObj:
+ if (squareContainsThingOfSameType || (curSensor->getData() != _vm->_objectMan->getObjectType(thing)))
+ continue;
+ break;
+ case k3_SensorWallOrnClickWithSpecObj:
+ if (squareContainsThingOfDifferentType || (curSensor->getData() == _vm->_objectMan->getObjectType(thing)))
+ continue;
+ break;
+ default:
+ continue;
+ break;
}
}
+
+ triggerSensor ^= curSensor->getAttrRevertEffectA();
+ int16 curSensorEffect = curSensor->getAttrEffectA();
+ if (curSensorEffect == k3_SensorEffHold)
+ curSensorEffect = triggerSensor ? k0_SensorEffSet : k1_SensorEffClear;
+ else if (!triggerSensor)
+ continue;
+
+ if (curSensor->getAttrAudibleA())
+ _vm->_sound->requestPlay(k01_soundSWITCH, mapX, mapY, k1_soundModePlayIfPrioritized);
+
+ triggerEffect(curSensor, curSensorEffect, mapX, mapY, (uint16)kM1_CellAny); // this will wrap around
+ continue;
}
- if (!skipToNextThing && (curThingType >= k4_GroupThingType))
- break;
- curThing = _vm->_dungeonMan->getNextThing(curThing);
+ if (curThingType >= k4_GroupThingType)
+ break;
}
processRotationEffect();
}