Skip to content

Commit

Permalink
LASTEXPRESS: more fixes in NPC logic
Browse files Browse the repository at this point in the history
  • Loading branch information
grechnik committed Sep 23, 2018
1 parent 875ce81 commit f057ac7
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 35 deletions.
10 changes: 5 additions & 5 deletions engines/lastexpress/entities/mahmud.cpp
Expand Up @@ -664,15 +664,15 @@ IMPLEMENT_FUNCTION(14, Mahmud, chaptersHandler)
break;

case 5: {
CursorStyle cursor = kCursorHand;
CursorStyle cursor2 = kCursorHandKnock;
CursorStyle cursor = kCursorHandKnock;
CursorStyle cursor2 = kCursorHand;

if (getProgress().jacket == kJacketBlood
|| getEvent(kEventMahmudWrongDoor)
|| getEvent(kEventMahmudWrongDoorOriginalJacket)
|| getEvent(kEventMahmudWrongDoorDay)) {
cursor = kCursorNormal;
cursor2 = kCursorTalk;
cursor = kCursorTalk;
cursor2 = kCursorNormal;
}

getObjects()->update(kObjectCompartment4, kEntityMahmud, kObjectLocation1, cursor, cursor2);
Expand Down Expand Up @@ -825,7 +825,7 @@ IMPLEMENT_FUNCTION(19, Mahmud, chapter4)
getData()->location = kLocationInsideCompartment;
getData()->car = kCarGreenSleeping;
getData()->clothes = kClothesDefault;
getData()->inventoryItem = kItemNone;
getData()->inventoryItem = kItemNone; // not in the original game, but it does no harm, I suppose?

break;
}
Expand Down
20 changes: 16 additions & 4 deletions engines/lastexpress/entities/mertens.cpp
Expand Up @@ -400,6 +400,10 @@ IMPLEMENT_FUNCTION_II(10, Mertens, updateEntity, CarIndex, EntityPosition)

if (params->param1 != 3 || (params->param2 != kPosition_8200 && params->param2 != kPosition_9510)) {
loadSceneFromPosition();
if (getEntities()->updateEntity(kEntityMertens, (CarIndex)params->param1, (EntityPosition)params->param2)) {
getData()->inventoryItem = kItemNone;
callbackAction();
}
break;
}

Expand Down Expand Up @@ -432,13 +436,21 @@ IMPLEMENT_FUNCTION_II(10, Mertens, updateEntity, CarIndex, EntityPosition)
}

loadSceneFromPosition();
if (getEntities()->updateEntity(kEntityMertens, (CarIndex)params->param1, (EntityPosition)params->param2)) {
getData()->inventoryItem = kItemNone;
callbackAction();
}
break;

case 4:
getAction()->playAnimation(kEventMertensKronosConcertInvitation);
ENTITY_PARAM(2, 4) = 0;

loadSceneFromPosition();
if (getEntities()->updateEntity(kEntityMertens, (CarIndex)params->param1, (EntityPosition)params->param2)) {
getData()->inventoryItem = kItemNone;
callbackAction();
}
break;

case 5:
Expand Down Expand Up @@ -501,7 +513,6 @@ IMPLEMENT_FUNCTION_I(12, Mertens, bonsoir, EntityIndex)
getSound()->playSound(kEntityMertens, "CON1112F");
} else {
switch (rnd(3)) {
default:
case 0:
getSound()->playSound(kEntityMertens, "CON1061");
break;
Expand Down Expand Up @@ -1964,6 +1975,7 @@ IMPLEMENT_FUNCTION_I(27, Mertens, tylerCompartment, MertensActionType)
case 27:
getAction()->playAnimation(kEventMertensBloodJacket);
getLogic()->gameOver(kSavegameTypeIndex, 1, kSceneGameOverBloodJacket, true);
// BUG: for [case 13] the original game continues executing code here
break;

case 14:
Expand Down Expand Up @@ -3040,10 +3052,10 @@ IMPLEMENT_FUNCTION(42, Mertens, function42)
}

if (params->param4 >= getState()->time)
break;
goto label_callback_8;
}

ENTITY_PARAM(0, 4) = kTimeInvalid;
params->param4 = kTimeInvalid;
getData()->inventoryItem = kItemNone;

setCallback(8);
Expand Down Expand Up @@ -3240,7 +3252,7 @@ IMPLEMENT_FUNCTION(42, Mertens, function42)
goto label_callback_2_4;

case 3:
getAction()->playAnimation(getProgress().jacket == kJacketOriginal ? kEventMertensLastCarOriginalJacket : kEventMertensLastCar);
getAction()->playAnimation(getProgress().jacket == kJacketGreen ? kEventMertensLastCar : kEventMertensLastCarOriginalJacket);
getEntities()->drawSequenceRight(kEntityMertens, "601A");
getScenes()->loadSceneFromPosition(kCarGreenSleeping, 6);
getScenes()->loadSceneFromItemPosition(kItem7);
Expand Down
14 changes: 8 additions & 6 deletions engines/lastexpress/entities/milos.cpp
Expand Up @@ -141,7 +141,6 @@ IMPLEMENT_FUNCTION_II(10, Milos, enterCompartmentDialog, CarIndex, EntityPositio
if (getEvent(kEventMilosTylerCompartmentDefeat)) {
// Robert saying: "Milos"
switch(rnd(3)) {
default:
case 0:
getSound()->playSound(kEntityPlayer, "CAT1014");
break;
Expand Down Expand Up @@ -443,7 +442,7 @@ IMPLEMENT_FUNCTION(14, Milos, function14)
++params->param5;
switch (params->param5) {
default:
getObjects()->update(kObjectCompartment1, kEntityMilos, getObjects()->get(kObjectCompartment1).status, params->param3 < 1 ? kCursorTalk : kCursorNormal, kCursorHand);
getObjects()->update(kObjectCompartment1, kEntityMilos, getObjects()->get(kObjectCompartment1).status, params->param3 == 0 ? kCursorTalk : kCursorNormal, kCursorHand);
CURRENT_PARAM(1, 2) = 0;
break;

Expand All @@ -467,7 +466,7 @@ IMPLEMENT_FUNCTION(14, Milos, function14)

if (params->param7 < 3) {
params->param5 = 1;
getObjects()->update(kObjectCompartment1, kEntityMilos, getObjects()->get(kObjectCompartment1).status, params->param3 < 1 ? kCursorTalk : kCursorNormal, kCursorHand);
getObjects()->update(kObjectCompartment1, kEntityMilos, getObjects()->get(kObjectCompartment1).status, params->param3 == 0 ? kCursorTalk : kCursorNormal, kCursorHand);
CURRENT_PARAM(1, 2) = 0;
break;
}
Expand Down Expand Up @@ -645,7 +644,7 @@ IMPLEMENT_FUNCTION(14, Milos, function14)
case 7:
case 9:
case 11:
getObjects()->update(kObjectCompartment1, kEntityMilos, getObjects()->get(kObjectCompartment1).status, params->param3 < 1 ? kCursorTalk : kCursorNormal, kCursorHand);
getObjects()->update(kObjectCompartment1, kEntityMilos, getObjects()->get(kObjectCompartment1).status, params->param3 == 0 ? kCursorTalk : kCursorNormal, kCursorHand);
CURRENT_PARAM(1, 2) = 0;
break;

Expand Down Expand Up @@ -1367,9 +1366,13 @@ IMPLEMENT_FUNCTION(25, Milos, function25)

case 3:
getObjects()->update(kObjectCompartmentG, kEntityMilos, kObjectLocation1, kCursorTalk, kCursorNormal);
getObjects()->update(kObjectCompartmentG, kEntityMilos, kObjectLocation1, kCursorHandKnock, kCursorHand);

params->param1 = 1;
// BUG: the original game executes the last line of [case 4:] here too, resetting cursor once again.
// We get here when Cath knocks or tries to enter the compartment G when Vesna is there,
// after Vesna says VES1015A (in Serbian, supposedly a variant of "Who is it?").
// The action for next knock / attempt to enter is saying CAT1505/CAT1505A,
// so the cursor should be kCursorTalk and not kCursorHandKnock as in the original game.
break;

case 4:
Expand Down Expand Up @@ -1524,7 +1527,6 @@ IMPLEMENT_FUNCTION(29, Milos, chapter4Handler)
getSound()->playSound(kEntityMilos, sound); \
if (getEntities()->isDistanceBetweenEntities(kEntityMilos, kEntityPlayer, 2000)) \
getProgress().field_94 = 1; \
break; \
}

switch (savepoint.action) {
Expand Down
2 changes: 1 addition & 1 deletion engines/lastexpress/entities/mmeboutarel.cpp
Expand Up @@ -887,7 +887,7 @@ IMPLEMENT_FUNCTION(21, MmeBoutarel, chapter3Handler)
if (getState()->time <= kTime2038500) {
if (!getEntities()->isPlayerInCar(kCarRedSleeping)
|| !params->param1
|| getSoundQueue()->isBuffered("FRA2012")
|| getSoundQueue()->isBuffered("FRA2012") // the original game tests this sound twice. Maybe a bug?
|| getSoundQueue()->isBuffered("FRA2010")
||!params->param2)
params->param2 = (uint)getState()->time;
Expand Down
6 changes: 3 additions & 3 deletions engines/lastexpress/entities/rebecca.cpp
Expand Up @@ -309,7 +309,7 @@ IMPLEMENT_FUNCTION_I(17, Rebecca, function17, bool)
break;

case 2:
getEntities()->clearSequences(kEntitySophie);
getEntities()->clearSequences(kEntityRebecca);
break;

case 3:
Expand Down Expand Up @@ -1371,7 +1371,7 @@ IMPLEMENT_FUNCTION(36, Rebecca, function36)
getSound()->playSound(kEntityRebecca, "Reb3007");

setCallback(2);
setup_updatePosition("118E", kCarRedSleeping, 52);
setup_updatePosition("118E", kCarRestaurant, 52);
break;
}
}
Expand Down Expand Up @@ -1726,7 +1726,7 @@ IMPLEMENT_FUNCTION(44, Rebecca, function44)
break;

case kAction123712592:
getEntities()->drawSequenceLeft(kEntityRebecca, "BLANK");
getEntities()->drawSequenceLeft(kEntityWaiter1, "BLANK");
getSound()->playSound(kEntityRebecca, "Reb4003");

setCallback(4);
Expand Down
2 changes: 1 addition & 1 deletion engines/lastexpress/entities/salko.cpp
Expand Up @@ -181,7 +181,7 @@ IMPLEMENT_FUNCTION(10, Salko, chapter1Handler)

case kActionCallback:
if (getCallback() == 1) {
getEntities()->clearSequences(kEntitySalko);
getEntities()->drawSequenceLeft(kEntitySalko, "BLANK");
setup_function8();
}
break;
Expand Down
8 changes: 4 additions & 4 deletions engines/lastexpress/entities/tatiana.cpp
Expand Up @@ -209,7 +209,7 @@ IMPLEMENT_FUNCTION(15, Tatiana, exitCompartment)

case kActionDefault:
setCallback(getProgress().chapter == kChapter1 ? 1 : 2);
setup_enterExitCompartment2(getProgress().chapter == kChapter1 ? "603Bb" : "673Bb", kObjectCompartmentB);
setup_enterExitCompartment(getProgress().chapter == kChapter1 ? "603Bb" : "673Bb", kObjectCompartmentB);
break;

case kActionCallback:
Expand Down Expand Up @@ -615,8 +615,7 @@ IMPLEMENT_FUNCTION(22, Tatiana, getSomeAir)
if (params->param1 == kTimeInvalid || getState()->time <= kTime1179000)
goto label_update;

if (Entity::updateParameterTime(kTime1233000, ((!getEvent(kEventTatianaAskMatchSpeakRussian) && !getEvent(kEventTatianaAskMatch)) || getEntities()->isInGreenCarEntrance(kEntityPlayer)), params->param1, 0)) {
params->param1 = kTimeInvalid;
if (!Entity::updateParameterTime(kTime1233000, ((!getEvent(kEventTatianaAskMatchSpeakRussian) && !getEvent(kEventTatianaAskMatch)) || getEntities()->isInGreenCarEntrance(kEntityPlayer)), params->param1, 0)) {

label_update:
if (!getEvent(kEventTatianaAskMatchSpeakRussian)
Expand Down Expand Up @@ -1036,6 +1035,7 @@ IMPLEMENT_FUNCTION(32, Tatiana, playChess)
break;

case kActionEndSound:
parameters->param2 = 0;
++parameters->param3;

switch (parameters->param3) {
Expand Down Expand Up @@ -1200,7 +1200,7 @@ IMPLEMENT_FUNCTION(35, Tatiana, concert)

label_callback_1:
if (getState()->time > kTime2133000) {
if (getData()->car >= kCarRedSleeping || (getData()->car == kCarGreenSleeping && getData()->entityPosition > kPosition_5790))
if (getEntityData(kEntityAugust)->car >= kCarRedSleeping || (getEntityData(kEntityAugust)->car == kCarGreenSleeping && getEntityData(kEntityAugust)->entityPosition > kPosition_5790))
setup_leaveConcert();
}
break;
Expand Down
14 changes: 7 additions & 7 deletions engines/lastexpress/entities/vassili.cpp
Expand Up @@ -108,7 +108,7 @@ IMPLEMENT_FUNCTION(5, Vassili, chapter1Handler)
if (!Entity::updateParameterCheck(params->param3, getState()->time, 450))
break;

if (!params->param2 && getObjects()->get(kObjectCompartmentA).status == kObjectLocation1) {
if (!params->param2 && getObjects()->get(kObjectCompartmentA).model == kObjectLocation1) {
params->param2 = 1;
getEntities()->drawSequenceLeft(kEntityVassili, "303A");
getObjects()->update(kObjectCompartmentA, kEntityPlayer, kObjectLocationNone, kCursorHandKnock, kCursorHand);
Expand Down Expand Up @@ -313,19 +313,19 @@ IMPLEMENT_FUNCTION(10, Vassili, seizure)
// Check that we have removed the body from the train and changed jacket
if (!getProgress().eventCorpseMovedFromFloor) {
getAction()->playAnimation(kEventMertensCorpseFloor);
getLogic()->gameOver(kSavegameTypeIndex, 0, kSceneNone, false);
getLogic()->gameOver(kSavegameTypeIndex, 0, kSceneNone, true);
break;
}

if (!getProgress().eventCorpseThrown) {
getAction()->playAnimation(kEventMertensCorpseBed);
getLogic()->gameOver(kSavegameTypeIndex, 0, kSceneNone, false);
getLogic()->gameOver(kSavegameTypeIndex, 0, kSceneNone, true);
break;
}

if (getProgress().jacket == kJacketBlood) {
getAction()->playAnimation(kEventMertensBloodJacket);
getLogic()->gameOver(kSavegameTypeIndex, 0, kSceneNone, false);
getLogic()->gameOver(kSavegameTypeIndex, 0, kSceneNone, true);
break;
}

Expand Down Expand Up @@ -410,7 +410,7 @@ IMPLEMENT_FUNCTION(13, Vassili, sleeping)
break;

case kActionDefault:
params->param5 = 5 * (3 * rnd(25) + 15);
params->param1 = 5 * (3 * rnd(25) + 15);
getEntities()->drawSequenceLeft(kEntityVassili, "303A");
break;

Expand Down Expand Up @@ -475,7 +475,7 @@ IMPLEMENT_FUNCTION(15, Vassili, stealEgg)
break;

case kActionDefault:
params->param5 = 5 * (3 * rnd(25) + 15);
params->param1 = 5 * (3 * rnd(25) + 15);
getEntities()->drawSequenceLeft(kEntityVassili, "303A");
break;

Expand Down Expand Up @@ -555,7 +555,7 @@ IMPLEMENT_FUNCTION(17, Vassili, chapter4Handler)
break;

case kActionDefault:
params->param5 = 5 * (3 * rnd(25) + 15);
params->param1 = 5 * (3 * rnd(25) + 15);
getEntities()->drawSequenceLeft(kEntityVassili, "303A");
break;

Expand Down
3 changes: 2 additions & 1 deletion engines/lastexpress/entities/verges.cpp
Expand Up @@ -1083,6 +1083,7 @@ IMPLEMENT_FUNCTION(28, Verges, chapter2Handler)
if (getEntities()->isInBaggageCarEntrance(kEntityPlayer)) {
setCallback(1);
setup_baggageCar(false);
break;
}

label_callback_1:
Expand Down Expand Up @@ -1708,7 +1709,7 @@ IMPLEMENT_FUNCTION(38, Verges, resetState)

getData()->entityPosition = kPosition_6469;
getData()->location = kLocationOutsideCompartment;
getData()->car = kCarGreenSleeping;
getData()->car = kCarRedSleeping;
break;

case kActionCallback:
Expand Down
3 changes: 1 addition & 2 deletions engines/lastexpress/entities/vesna.cpp
Expand Up @@ -1049,8 +1049,6 @@ IMPLEMENT_FUNCTION(29, Vesna, guarding)

case kActionOpenDoor:
setCallback(1);

getData()->currentCall++;
setup_savegame(kSavegameTypeEvent, kEventCathVesnaRestaurantKilled);
break;

Expand Down Expand Up @@ -1118,6 +1116,7 @@ IMPLEMENT_FUNCTION(30, Vesna, climbing)
getLogic()->gameOver(kSavegameTypeIndex, 0, kSceneNone, params->param2 == Fight::kFightEndLost);
} else {
getSound()->playSound(kEntityPlayer, "TUNNEL");
// TODO: fade to black screen

getState()->time = (TimeValue)(getState()->time + 1800);

Expand Down
2 changes: 1 addition & 1 deletion engines/lastexpress/entities/waiter2.cpp
Expand Up @@ -131,7 +131,7 @@ IMPLEMENT_FUNCTION(7, Waiter2, monsieurServeUs)

case 2:
getSavePoints()->push(kEntityWaiter2, kEntityBoutarel, kAction122288808);
setCallback(2);
setCallback(3);
setup_draw("926");
break;

Expand Down

0 comments on commit f057ac7

Please sign in to comment.