ScummVM API documentation
interaction.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef HARVESTER_INTERACTION_H
23 #define HARVESTER_INTERACTION_H
24 
25 #include "common/error.h"
26 #include "harvester/bitmap.h"
27 #include "harvester/scene/room_support.h"
28 #include "harvester/saveload.h"
29 
30 namespace Harvester {
31 
32 class Flow;
33 class HarvesterEngine;
34 class InventorySystem;
35 class Interaction;
36 class SceneEntities;
37 class Player;
38 struct IndexedBitmap;
39 struct RoomPlayerState;
40 
41 extern const char *const kExitCloseupPendingRoomChange;
42 
44 public:
45  virtual ~InteractionCallbacks() {}
46 
47  virtual bool refreshCurrentScene(bool preservePlayerPlacement) = 0;
48  virtual bool applyCurrentRoomRuntimeMutationsInPlace(bool preservePaletteState) = 0;
49  virtual void syncGlobalTimerEntities(const Common::Array<TimerRecord> &previousTimerRecords) = 0;
50  virtual bool captureDialogueBackdrop(IndexedBitmap &dialogueBackdrop) = 0;
51  virtual Common::Error showCdChangePrompt(int discNumber) = 0;
52  virtual Common::Error runRoomExitCommands() = 0;
53  virtual Common::Error applyLightingCommand(StartupLightingCommand lightingCommand) = 0;
54  virtual void applyPlayerGotoXZ(int x, int z) = 0;
55  virtual Common::Error runModalShowText(const ResolvedText &modalText) = 0;
56  virtual void resetIdleState() = 0;
57  virtual void notePlayerActivity() = 0;
58  virtual void stopPlayerRegionInteraction() = 0;
59  virtual void startPlayerDefeatSequence(const char *reason, const Common::String &sourceName,
60  int damageType) = 0;
61 };
62 
64 public:
66  SceneEntities &sceneRuntime, InventorySystem &inventory, const Common::String &pendingRoomChange);
67 
68  const Common::String &getCarriedRoomItemLabel() const { return _carriedRoomItemLabel; }
69  const IndexedBitmap &getCarriedRoomItemBitmap() const { return _carriedRoomItemBitmap; }
70  bool hasCarriedRoomItem() const;
71  bool hasSelectedItem() const;
72  Common::String getSelectedItemName() const;
73  void clearSelectedItem();
74  void hideCarriedRoomItem();
75  bool stowCarriedRoomItemToInventory();
76  Common::Error handleSelectedItemTargetInteraction(const ObjectRecord &target,
77  Interaction &interactionProcessor, bool &needsRedraw);
78  const Entity *findSelectedItemTarget(const Common::Point &point, bool opaquePixels = true);
79  Common::Error handleSelectedItemMiss(Interaction &interactionProcessor, bool &needsRedraw);
80  Common::Error handleRoomItemPickup(const ObjectRecord &object, bool playerPresent,
81  Interaction &interactionProcessor, InteractionCallbacks &callbacks, bool &needsRedraw);
82 
83 private:
84  void clearCarriedRoomItem();
85  void hideSceneObject(const Common::String &objectName, const Common::String *ownerOrRoom);
86  bool shouldCancelDeniedPickup(const InteractionResult &interaction, bool didTransition) const;
87  Common::Error restoreDeniedPickup(Script &script, const ObjectRecord &savedObject, bool clearCarryState,
88  InteractionCallbacks &callbacks, bool &needsRedraw);
89  Common::Error moveRoomItemDirectlyToInventory(const ObjectRecord &object,
90  Interaction &interactionProcessor, InteractionCallbacks &callbacks, bool &needsRedraw);
91  Common::Error beginRoomItemCarry(const ObjectRecord &object,
92  Interaction &interactionProcessor, InteractionCallbacks &callbacks, bool &needsRedraw);
93 
94  HarvesterEngine &_engine;
95  SceneState &_scene;
96  SceneEntities &_sceneRuntime;
97  InventorySystem &_inventory;
98  const Common::String &_pendingRoomChange;
99  Common::String _carriedRoomItemName;
100  Common::String _carriedRoomItemLabel;
101  IndexedBitmap _carriedRoomItemBitmap;
102 };
103 
104 class Interaction {
105 public:
106  Interaction(HarvesterEngine &engine, Flow &flow, SceneState &scene,
107  Player &player, Common::String &pendingRegionName,
108  Common::String &pendingRoomChange, bool &pendingRoomChangeIsRoomName,
109  bool &pendingRoomChangeUsesSavedRoomState, SaveRoomState &pendingRoomChangeSavedRoomState,
110  bool canExitCloseupToParent, InteractionCallbacks &callbacks);
111 
112  void queueRegionInteraction(const RegionRecord &region, const Common::Point &mousePos);
113  Common::Error runRegionInteraction(const RegionRecord &region,
114  InventorySystem &inventory, bool &needsRedraw);
115  Common::Error tryActivatePendingRegion(InventorySystem &inventory, bool &needsRedraw);
116  Common::Error tryActivatePassiveRegion(InventorySystem &inventory, bool &needsRedraw);
117  int getPendingRegionFacing() const;
118 
119  bool hasPendingMainMenuReturn() const;
120  Common::Error handleCombatInteraction(const InteractionResult &interaction, bool &needsRedraw);
121  Common::Error handleInteractionResult(const InteractionResult &interaction,
122  bool &didTransition, const Common::String &usedItemName, bool interruptPlayerMovement = true);
123  Common::Error runScriptedDialogue(const Common::String &npcName, const Common::String &usedItemName,
124  const Common::String &continuationTag, bool &didTransition);
125 
126 private:
127  void preparePlayerForInteraction(const RoomPlayerState &playerState, bool interruptPlayerMovement);
128  Common::Error handleDemoEnding(bool &didTransition);
129  Common::Error handleMainMenuReturn(const Common::String &deathFlicPath);
130  void applyPlayerDeathRequest(const InteractionResult &interaction);
131  Common::Error queueImplicitRoomRestart(const InteractionResult &interaction,
132  bool discChanged, bool &didTransition);
133  Common::Error queueSavedRoomRestart(const SaveRoomState &savedState, bool &didTransition);
134  Common::Error queueRoomChange(const Common::String &nextRoomName, bool &didTransition);
135  Common::Error runCloseupInteraction(const InteractionResult &interaction, bool discChanged,
136  const Common::String &restoreMusicPath, bool &didTransition);
137  Common::Error queueCloseupExit(bool &didTransition);
138  Common::Error applySameSceneEffects(const InteractionResult &interaction,
139  const RoomPlayerState &playerState, bool &didTransition, const Common::String &usedItemName,
140  bool interruptPlayerMovement);
141 
142  HarvesterEngine &_engine;
143  Flow &_flow;
144  SceneState &_scene;
145  Player &_player;
146  Common::String &_pendingRegionName;
147  Common::String &_pendingRoomChange;
148  bool &_pendingRoomChangeIsRoomName;
149  bool &_pendingRoomChangeUsesSavedRoomState;
150  SaveRoomState &_pendingRoomChangeSavedRoomState;
151  bool _canExitCloseupToParent;
152  InteractionCallbacks &_callbacks;
153 };
154 
155 bool hasRoomEntryInteraction(const InteractionResult &interaction);
156 
157 } // End of namespace Harvester
158 
159 #endif // HARVESTER_INTERACTION_H
Definition: flow.h:45
Definition: str.h:59
Definition: art.h:31
Definition: saveload.h:29
Definition: error.h:81
Definition: bitmap.h:33
Definition: array.h:52
Definition: script.h:342
Definition: player.h:36
Definition: room_support.h:46
Definition: interaction.h:43
Definition: script.h:86
Definition: entity.h:66
Definition: inventory.h:54
Definition: scene_entities.h:31
Definition: interaction.h:104
Definition: interaction.h:63
Definition: script.h:306
Definition: rect.h:144
Definition: player.h:105
Definition: harvester.h:47
Definition: script.h:164
Definition: script.h:311