NANCY: Implement SetValue

Added support for the simplest of the data access action
records. This simply sets or adds to a value inside the
TableData struct.
This commit is contained in:
Kaloyan Chehlarski 2024-02-07 20:45:08 +01:00
parent af2ff22907
commit 1369449374
5 changed files with 54 additions and 4 deletions

View File

@ -185,6 +185,8 @@ ActionRecord *ActionManager::createActionRecord(uint16 type, Common::SeekableRea
return new TextBoxWrite();
case 76:
return new TextboxClear();
case 77:
return new SetValue();
case 97:
return new EventFlags(true);
case 98:

View File

@ -70,7 +70,7 @@ void TableIndexSetValueHS::execute() {
break;
case kIncrementTableValue:
++playerTable->singleValues[_tableIndex - 1];
if (playerTable->singleValues[_tableIndex - 1] >= playerTable->singleValues.size() + 1) {
if (playerTable->singleValues[_tableIndex - 1] >= (int)playerTable->singleValues.size() + 1) {
playerTable->singleValues[_tableIndex - 1] = 1;
}
break;
@ -113,6 +113,40 @@ void TableIndexSetValueHS::execute() {
}
}
void SetValue::readData(Common::SeekableReadStream &stream) {
_index = stream.readByte();
_shouldSet = stream.readByte();
_value = stream.readSint16LE();
}
void SetValue::execute() {
TableData *playerTable = (TableData *)NancySceneState.getPuzzleData(TableData::getTag());
assert(playerTable);
// nancy8 has 20 single & 20 combo values, later games have 30/10
uint numSingleValues = g_nancy->getGameType() <= kGameTypeNancy8 ? 20 : 30;
if (_index < numSingleValues) {
// Single values
int16 curValue = playerTable->getSingleValue(_index);
if (_shouldSet || curValue == kNoTableValue) {
playerTable->setSingleValue(_index, _value);
} else {
playerTable->setSingleValue(_index, curValue + _value);
}
} else {
// Combo values
float curValue = playerTable->getComboValue(_index - numSingleValues);
if (_shouldSet || curValue == (float)kNoTableValue) {
playerTable->setComboValue(_index - numSingleValues, _value);
} else {
playerTable->setComboValue(_index - numSingleValues, curValue + _value);
}
}
finishExecution();
}
void EventFlags::readData(Common::SeekableReadStream &stream) {
if (!_isTerse) {
_flags.readData(stream);

View File

@ -52,6 +52,20 @@ protected:
Common::Array<HotspotDescription> _hotspots;
};
// Sets (or adds to) a value inside the TableData struct
class SetValue : public ActionRecord {
public:
void readData(Common::SeekableReadStream &stream) override;
void execute() override;
protected:
Common::String getRecordTypeName() const override { return "SetValue"; }
byte _index = 0;
bool _shouldSet = false;
int16 _value = kNoTableValue;
};
// Sets up to 10 flags at once.
class EventFlags : public ActionRecord {
public:

View File

@ -117,7 +117,7 @@ static const byte kPlayOverlayNoHotspot = 2;
static const byte kNoChangeTableValue = 0;
static const byte kIncrementTableValue = 1;
static const byte kDecrementTableValue = 2;
static const int16 kNoChangeTableValue = 9999;
static const int16 kNoTableValue = 9999;
// 3D sound rotation
static const byte kRotateAroundX = 0;

View File

@ -182,7 +182,7 @@ void TableData::synchronize(Common::Serializer &ser) {
void TableData::setSingleValue(uint16 index, int16 value) {
if (singleValues.size() <= index) {
singleValues.resize(index, kNoTableValue);
singleValues.resize(index + 1, kNoTableValue);
}
singleValues[index] = value;
@ -194,7 +194,7 @@ int16 TableData::getSingleValue(uint16 index) const {
void TableData::setComboValue(uint16 index, float value) {
if (comboValues.size() < index) {
comboValues.resize(index, kNoTableValue);
comboValues.resize(index + 1, kNoTableValue);
}
comboValues[index] = value;