diff options
author | Evgeny Grechnikov | 2018-08-25 15:11:24 +0300 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-26 12:09:43 +0200 |
commit | f771fa40ad474d78d32ce5bff67afc937547e5de (patch) | |
tree | 483ee750c81169142fc58a68e87d5a321a4a96f3 /engines/lastexpress/game | |
parent | f3cb1fcd84d7ca1dd25b7adb4b54f08c535008ac (diff) | |
download | scummvm-rg350-f771fa40ad474d78d32ce5bff67afc937547e5de.tar.gz scummvm-rg350-f771fa40ad474d78d32ce5bff67afc937547e5de.tar.bz2 scummvm-rg350-f771fa40ad474d78d32ce5bff67afc937547e5de.zip |
LASTEXPRESS: multiple fixes in NPC logic
Checked the logic against the original game
(to be precise, DOS English version from GOG, although I think
AI logic has no significant differences with other versions).
Fixed a *lot* of errors with varying visibility for the user.
Also, save+exit+load sometimes resulted in memory corruption like
((EntityParametersSSII*)(new EntityParametersIIII))->param8 = 0;
load operation did not restore the correct type of NPC logic context,
the default one was used (which also has the smallest sizeof).
Should be fixed now. Save+load is still unusable because it locks
everybody waiting for kActionEndSound (the sound state is not restored),
but, at least, it should not corrupt the memory. Hopefully.
Diffstat (limited to 'engines/lastexpress/game')
-rw-r--r-- | engines/lastexpress/game/entities.cpp | 10 | ||||
-rw-r--r-- | engines/lastexpress/game/savegame.cpp | 2 | ||||
-rw-r--r-- | engines/lastexpress/game/savepoint.cpp | 6 | ||||
-rw-r--r-- | engines/lastexpress/game/savepoint.h | 3 | ||||
-rw-r--r-- | engines/lastexpress/game/state.h | 279 |
5 files changed, 156 insertions, 144 deletions
diff --git a/engines/lastexpress/game/entities.cpp b/engines/lastexpress/game/entities.cpp index b881d34ebe..1afebbbfaf 100644 --- a/engines/lastexpress/game/entities.cpp +++ b/engines/lastexpress/game/entities.cpp @@ -241,7 +241,7 @@ int Entities::getCompartments1(int index) const { // Savegame ////////////////////////////////////////////////////////////////////////// void Entities::saveLoadWithSerializer(Common::Serializer &s) { - _header->saveLoadWithSerializer(s); + _header->saveLoadWithSerializer(s, NULL); for (uint i = 1; i < _entities.size(); i++) _entities[i]->saveLoadWithSerializer(s); } @@ -1931,7 +1931,7 @@ void Entities::loadSceneFromEntityPosition(CarIndex car, EntityPosition entityPo // Determine position Position position = (alternate ? 1 : 40); do { - if (entityPosition > entityPositions[position]) { + if (alternate ? entityPosition < entityPositions[position] : entityPosition > entityPositions[position]) { if (alternate) break; @@ -1945,7 +1945,7 @@ void Entities::loadSceneFromEntityPosition(CarIndex car, EntityPosition entityPo } while (alternate ? position <= 18 : position >= 22); // For position outside bounds, use minimal value - if ((alternate && position > 18) || (alternate && position < 22)) { + if ((alternate && position > 18) || (!alternate && position < 22)) { getScenes()->loadSceneFromPosition(car, alternate ? 18 : 22); return; } @@ -2117,7 +2117,7 @@ label_process_entity: if (checkDistanceFromPosition(entity, kPosition_1500, 750) && entity != kEntityFrancois) { - if (data->entity != kEntityPlayer) { + if (data->entity == kEntityPlayer) { if (data->direction != kDirectionUp || (position <= kPosition_2000 && data->car == car)) { if (data->direction == kDirectionDown && (position < kPosition_1500 || data->car != car)) { if (data->entityPosition > kPosition_1500 && (data->car == kCarGreenSleeping || data->car == kCarRedSleeping)) { @@ -2282,8 +2282,8 @@ label_process_entity: } } } - return false; } + return false; } } else if (!flag1) { drawSequences(entity, direction, true); diff --git a/engines/lastexpress/game/savegame.cpp b/engines/lastexpress/game/savegame.cpp index e2682ba0d1..ce53e6eadf 100644 --- a/engines/lastexpress/game/savegame.cpp +++ b/engines/lastexpress/game/savegame.cpp @@ -802,7 +802,7 @@ void SaveLoad::readEntry(SavegameType *type, EntityIndex *entity, uint32 *val, b // Skip padding uint32 offset = (uint32)_savegame->pos() - originalPosition; if (offset & 0xF) { - _savegame->seek((~offset & 0xF) + 1, SEEK_SET); + _savegame->seek((~offset & 0xF) + 1, SEEK_CUR); } } diff --git a/engines/lastexpress/game/savepoint.cpp b/engines/lastexpress/game/savepoint.cpp index a8483e6d5c..bd134c637c 100644 --- a/engines/lastexpress/game/savepoint.cpp +++ b/engines/lastexpress/game/savepoint.cpp @@ -162,8 +162,8 @@ void SavePoints::call(EntityIndex entity2, EntityIndex entity1, ActionIndex acti point.action = action; point.entity2 = entity2; - assert(param.size() <= 5); - strncpy((char *)&point.param.charValue, param.c_str(), 5); + assert(param.size() <= 6); // "MUS%03d" + strncpy((char *)&point.param.charValue, param.c_str(), 6); Callback *callback = getCallback(entity1); if (callback != NULL && callback->isValid()) { @@ -230,6 +230,8 @@ bool SavePoints::updateEntityFromData(const SavePoint &savepoint) { void SavePoints::saveLoadWithSerializer(Common::Serializer &s) { // Serialize savepoint data + if (s.isLoading()) + _data.clear(); uint32 dataSize = (s.isLoading() ? _savePointsMaxSize : _data.size()); for (uint i = 0; i < dataSize; i++) { if (s.isLoading()) { diff --git a/engines/lastexpress/game/savepoint.h b/engines/lastexpress/game/savepoint.h index ab6490796b..ea73e7c25d 100644 --- a/engines/lastexpress/game/savepoint.h +++ b/engines/lastexpress/game/savepoint.h @@ -58,7 +58,7 @@ struct SavePoint { EntityIndex entity2; union { uint32 intValue; - char charValue[5]; + char charValue[7]; // "MUS%03d" with terminating zero } param; SavePoint() { @@ -66,6 +66,7 @@ struct SavePoint { action = kActionNone; entity2 = kEntityPlayer; param.intValue = 0; + param.charValue[6] = 0; } Common::String toString() { diff --git a/engines/lastexpress/game/state.h b/engines/lastexpress/game/state.h index 38cd851aaa..b46807b40e 100644 --- a/engines/lastexpress/game/state.h +++ b/engines/lastexpress/game/state.h @@ -313,13 +313,14 @@ public: * @return true if equal, false if not. */ bool isEqual(uint index, uint val) { - return getValueName(index) == val; + return getOrSetValueName(index) == val; } - uint32 getValueName(uint index, Common::String *name = NULL) { - #define EXPOSE_VALUE(idx, entryName) \ + uint32 getOrSetValueName(uint index, Common::String *name = NULL, const uint32* newValue = NULL) { + #define EXPOSE_VALUE(idx, entryName, fieldType) \ case idx: { \ if (name) (*name) = "" #entryName; \ + if (newValue) {entryName = (fieldType)*newValue;} \ return (uint32)entryName; \ } @@ -328,134 +329,134 @@ public: error("[GameProgress::getValueName] Invalid index value (was: %d, max:127)", index); break; - EXPOSE_VALUE(0, field_0); - EXPOSE_VALUE(1, jacket); - EXPOSE_VALUE(2, eventCorpseMovedFromFloor); - EXPOSE_VALUE(3, field_C); - EXPOSE_VALUE(4, eventCorpseFound); - EXPOSE_VALUE(5, field_14); - EXPOSE_VALUE(6, field_18); - EXPOSE_VALUE(7, portrait); - EXPOSE_VALUE(8, eventCorpseThrown); - EXPOSE_VALUE(9, field_24); - EXPOSE_VALUE(10, field_28); - EXPOSE_VALUE(11, chapter); - EXPOSE_VALUE(12, field_30); - EXPOSE_VALUE(13, eventMetAugust); - EXPOSE_VALUE(14, isNightTime); - EXPOSE_VALUE(15, field_3C); - EXPOSE_VALUE(16, field_40); - EXPOSE_VALUE(17, field_44); - EXPOSE_VALUE(18, field_48); - EXPOSE_VALUE(19, field_4C); - EXPOSE_VALUE(20, isTrainRunning); - EXPOSE_VALUE(21, field_54); - EXPOSE_VALUE(22, field_58); - EXPOSE_VALUE(23, field_5C); - EXPOSE_VALUE(24, field_60); - EXPOSE_VALUE(25, field_64); - EXPOSE_VALUE(26, field_68); - EXPOSE_VALUE(27, eventMertensAugustWaiting); - EXPOSE_VALUE(28, eventMertensKronosInvitation); - EXPOSE_VALUE(29, isEggOpen); - EXPOSE_VALUE(30, field_78); - EXPOSE_VALUE(31, field_7C); - EXPOSE_VALUE(32, field_80); - EXPOSE_VALUE(33, field_84); - EXPOSE_VALUE(34, field_88); - EXPOSE_VALUE(35, field_8C); - EXPOSE_VALUE(36, field_90); - EXPOSE_VALUE(37, field_94); - EXPOSE_VALUE(38, field_98); - EXPOSE_VALUE(39, field_9C); - EXPOSE_VALUE(40, field_A0); - EXPOSE_VALUE(41, field_A4); - EXPOSE_VALUE(42, field_A8); - EXPOSE_VALUE(43, field_AC); - EXPOSE_VALUE(44, field_B0); - EXPOSE_VALUE(45, field_B4); - EXPOSE_VALUE(46, field_B8); - EXPOSE_VALUE(47, field_BC); - EXPOSE_VALUE(48, field_C0); - EXPOSE_VALUE(49, field_C4); - EXPOSE_VALUE(50, field_C8); - EXPOSE_VALUE(51, field_CC); - EXPOSE_VALUE(52, eventMetBoutarel); - EXPOSE_VALUE(53, eventMetHadija); - EXPOSE_VALUE(54, eventMetYasmin); - EXPOSE_VALUE(55, field_DC); - EXPOSE_VALUE(56, field_E0); - EXPOSE_VALUE(57, field_E4); - EXPOSE_VALUE(58, field_E8); - EXPOSE_VALUE(59, field_EC); - EXPOSE_VALUE(60, field_F0); - EXPOSE_VALUE(61, field_F4); - EXPOSE_VALUE(62, field_F8); - EXPOSE_VALUE(63, field_FC); - EXPOSE_VALUE(64, field_100); - EXPOSE_VALUE(65, field_104); - EXPOSE_VALUE(66, field_108); - EXPOSE_VALUE(67, field_10C); - EXPOSE_VALUE(68, field_110); - EXPOSE_VALUE(69, field_114); - EXPOSE_VALUE(70, field_118); - EXPOSE_VALUE(71, field_11C); - EXPOSE_VALUE(72, field_120); - EXPOSE_VALUE(73, field_124); - EXPOSE_VALUE(74, field_128); - EXPOSE_VALUE(75, field_12C); - EXPOSE_VALUE(76, field_130); - EXPOSE_VALUE(77, field_134); - EXPOSE_VALUE(78, field_138); - EXPOSE_VALUE(79, field_13C); - EXPOSE_VALUE(80, field_140); - EXPOSE_VALUE(81, field_144); - EXPOSE_VALUE(82, field_148); - EXPOSE_VALUE(83, field_14C); - EXPOSE_VALUE(84, field_150); - EXPOSE_VALUE(85, field_154); - EXPOSE_VALUE(86, field_158); - EXPOSE_VALUE(87, field_15C); - EXPOSE_VALUE(88, field_160); - EXPOSE_VALUE(89, field_164); - EXPOSE_VALUE(90, field_168); - EXPOSE_VALUE(91, field_16C); - EXPOSE_VALUE(92, field_170); - EXPOSE_VALUE(93, field_174); - EXPOSE_VALUE(94, field_178); - EXPOSE_VALUE(95, field_17C); - EXPOSE_VALUE(96, field_180); - EXPOSE_VALUE(97, field_184); - EXPOSE_VALUE(98, field_188); - EXPOSE_VALUE(99, field_18C); - EXPOSE_VALUE(100, field_190); - EXPOSE_VALUE(101, field_194); - EXPOSE_VALUE(102, field_198); - EXPOSE_VALUE(103, field_19C); - EXPOSE_VALUE(104, field_1A0); - EXPOSE_VALUE(105, field_1A4); - EXPOSE_VALUE(106, field_1A8); - EXPOSE_VALUE(107, field_1AC); - EXPOSE_VALUE(108, field_1B0); - EXPOSE_VALUE(109, field_1B4); - EXPOSE_VALUE(110, field_1B8); - EXPOSE_VALUE(111, field_1BC); - EXPOSE_VALUE(112, field_1C0); - EXPOSE_VALUE(113, field_1C4); - EXPOSE_VALUE(114, field_1C8); - EXPOSE_VALUE(115, field_1CC); - EXPOSE_VALUE(116, field_1D0); - EXPOSE_VALUE(117, field_1D4); - EXPOSE_VALUE(118, field_1D8); - EXPOSE_VALUE(119, field_1DC); - EXPOSE_VALUE(120, field_1E0); - EXPOSE_VALUE(121, field_1E4); - EXPOSE_VALUE(122, field_1E8); - EXPOSE_VALUE(123, field_1EC); - EXPOSE_VALUE(124, field_1F0); - EXPOSE_VALUE(125, field_1F4); - EXPOSE_VALUE(126, field_1F8); - EXPOSE_VALUE(127, field_1FC); + EXPOSE_VALUE(0, field_0, uint32); + EXPOSE_VALUE(1, jacket, JacketType); + EXPOSE_VALUE(2, eventCorpseMovedFromFloor, bool); + EXPOSE_VALUE(3, field_C, uint32); + EXPOSE_VALUE(4, eventCorpseFound, bool); + EXPOSE_VALUE(5, field_14, uint32); + EXPOSE_VALUE(6, field_18, uint32); + EXPOSE_VALUE(7, portrait, uint32); + EXPOSE_VALUE(8, eventCorpseThrown, bool); + EXPOSE_VALUE(9, field_24, uint32); + EXPOSE_VALUE(10, field_28, uint32); + EXPOSE_VALUE(11, chapter, ChapterIndex); + EXPOSE_VALUE(12, field_30, uint32); + EXPOSE_VALUE(13, eventMetAugust, bool); + EXPOSE_VALUE(14, isNightTime, bool); + EXPOSE_VALUE(15, field_3C, uint32); + EXPOSE_VALUE(16, field_40, uint32); + EXPOSE_VALUE(17, field_44, uint32); + EXPOSE_VALUE(18, field_48, uint32); + EXPOSE_VALUE(19, field_4C, uint32); + EXPOSE_VALUE(20, isTrainRunning, bool); + EXPOSE_VALUE(21, field_54, uint32); + EXPOSE_VALUE(22, field_58, uint32); + EXPOSE_VALUE(23, field_5C, uint32); + EXPOSE_VALUE(24, field_60, uint32); + EXPOSE_VALUE(25, field_64, uint32); + EXPOSE_VALUE(26, field_68, uint32); + EXPOSE_VALUE(27, eventMertensAugustWaiting, bool); + EXPOSE_VALUE(28, eventMertensKronosInvitation, bool); + EXPOSE_VALUE(29, isEggOpen, bool); + EXPOSE_VALUE(30, field_78, uint32); + EXPOSE_VALUE(31, field_7C, uint32); + EXPOSE_VALUE(32, field_80, uint32); + EXPOSE_VALUE(33, field_84, uint32); + EXPOSE_VALUE(34, field_88, uint32); + EXPOSE_VALUE(35, field_8C, uint32); + EXPOSE_VALUE(36, field_90, uint32); + EXPOSE_VALUE(37, field_94, uint32); + EXPOSE_VALUE(38, field_98, uint32); + EXPOSE_VALUE(39, field_9C, uint32); + EXPOSE_VALUE(40, field_A0, uint32); + EXPOSE_VALUE(41, field_A4, uint32); + EXPOSE_VALUE(42, field_A8, uint32); + EXPOSE_VALUE(43, field_AC, uint32); + EXPOSE_VALUE(44, field_B0, uint32); + EXPOSE_VALUE(45, field_B4, uint32); + EXPOSE_VALUE(46, field_B8, uint32); + EXPOSE_VALUE(47, field_BC, uint32); + EXPOSE_VALUE(48, field_C0, uint32); + EXPOSE_VALUE(49, field_C4, uint32); + EXPOSE_VALUE(50, field_C8, uint32); + EXPOSE_VALUE(51, field_CC, uint32); + EXPOSE_VALUE(52, eventMetBoutarel, bool); + EXPOSE_VALUE(53, eventMetHadija, bool); + EXPOSE_VALUE(54, eventMetYasmin, bool); + EXPOSE_VALUE(55, field_DC, uint32); + EXPOSE_VALUE(56, field_E0, uint32); + EXPOSE_VALUE(57, field_E4, uint32); + EXPOSE_VALUE(58, field_E8, uint32); + EXPOSE_VALUE(59, field_EC, uint32); + EXPOSE_VALUE(60, field_F0, uint32); + EXPOSE_VALUE(61, field_F4, uint32); + EXPOSE_VALUE(62, field_F8, uint32); + EXPOSE_VALUE(63, field_FC, uint32); + EXPOSE_VALUE(64, field_100, uint32); + EXPOSE_VALUE(65, field_104, uint32); + EXPOSE_VALUE(66, field_108, uint32); + EXPOSE_VALUE(67, field_10C, uint32); + EXPOSE_VALUE(68, field_110, uint32); + EXPOSE_VALUE(69, field_114, uint32); + EXPOSE_VALUE(70, field_118, uint32); + EXPOSE_VALUE(71, field_11C, uint32); + EXPOSE_VALUE(72, field_120, uint32); + EXPOSE_VALUE(73, field_124, uint32); + EXPOSE_VALUE(74, field_128, uint32); + EXPOSE_VALUE(75, field_12C, uint32); + EXPOSE_VALUE(76, field_130, uint32); + EXPOSE_VALUE(77, field_134, uint32); + EXPOSE_VALUE(78, field_138, uint32); + EXPOSE_VALUE(79, field_13C, uint32); + EXPOSE_VALUE(80, field_140, uint32); + EXPOSE_VALUE(81, field_144, uint32); + EXPOSE_VALUE(82, field_148, uint32); + EXPOSE_VALUE(83, field_14C, uint32); + EXPOSE_VALUE(84, field_150, uint32); + EXPOSE_VALUE(85, field_154, uint32); + EXPOSE_VALUE(86, field_158, uint32); + EXPOSE_VALUE(87, field_15C, uint32); + EXPOSE_VALUE(88, field_160, uint32); + EXPOSE_VALUE(89, field_164, uint32); + EXPOSE_VALUE(90, field_168, uint32); + EXPOSE_VALUE(91, field_16C, uint32); + EXPOSE_VALUE(92, field_170, uint32); + EXPOSE_VALUE(93, field_174, uint32); + EXPOSE_VALUE(94, field_178, uint32); + EXPOSE_VALUE(95, field_17C, uint32); + EXPOSE_VALUE(96, field_180, uint32); + EXPOSE_VALUE(97, field_184, uint32); + EXPOSE_VALUE(98, field_188, uint32); + EXPOSE_VALUE(99, field_18C, uint32); + EXPOSE_VALUE(100, field_190, uint32); + EXPOSE_VALUE(101, field_194, uint32); + EXPOSE_VALUE(102, field_198, uint32); + EXPOSE_VALUE(103, field_19C, uint32); + EXPOSE_VALUE(104, field_1A0, uint32); + EXPOSE_VALUE(105, field_1A4, uint32); + EXPOSE_VALUE(106, field_1A8, uint32); + EXPOSE_VALUE(107, field_1AC, uint32); + EXPOSE_VALUE(108, field_1B0, uint32); + EXPOSE_VALUE(109, field_1B4, uint32); + EXPOSE_VALUE(110, field_1B8, uint32); + EXPOSE_VALUE(111, field_1BC, uint32); + EXPOSE_VALUE(112, field_1C0, uint32); + EXPOSE_VALUE(113, field_1C4, uint32); + EXPOSE_VALUE(114, field_1C8, uint32); + EXPOSE_VALUE(115, field_1CC, uint32); + EXPOSE_VALUE(116, field_1D0, uint32); + EXPOSE_VALUE(117, field_1D4, uint32); + EXPOSE_VALUE(118, field_1D8, uint32); + EXPOSE_VALUE(119, field_1DC, uint32); + EXPOSE_VALUE(120, field_1E0, uint32); + EXPOSE_VALUE(121, field_1E4, uint32); + EXPOSE_VALUE(122, field_1E8, uint32); + EXPOSE_VALUE(123, field_1EC, uint32); + EXPOSE_VALUE(124, field_1F0, uint32); + EXPOSE_VALUE(125, field_1F4, uint32); + EXPOSE_VALUE(126, field_1F8, uint32); + EXPOSE_VALUE(127, field_1FC, uint32); } } @@ -464,7 +465,7 @@ public: for (uint i = 0; i < 128; i++) { Common::String name = ""; - uint val = getValueName(i, &name); + uint val = getOrSetValueName(i, &name, NULL); ret += Common::String::format("(%03d) %s = %d\n", i, name.c_str(), val); } @@ -472,9 +473,17 @@ public: } void saveLoadWithSerializer(Common::Serializer &s) { - for (uint i = 0; i < 128; i++) { - uint32 val = getValueName(i); - s.syncAsUint32LE(val); + if (s.isLoading()) { + for (uint i = 0; i < 128; i++) { + uint32 val; + s.syncAsUint32LE(val); + getOrSetValueName(i, NULL, &val); + } + } else { + for (uint i = 0; i < 128; i++) { + uint32 val = getOrSetValueName(i); + s.syncAsUint32LE(val); + } } } }; |