ScummVM API documentation
interactions.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 //=============================================================================
23 //
24 // Interaction structs.
25 //
26 //-----------------------------------------------------------------------------
27 //
28 // Most of the interaction types here were used before the script and have
29 // very limited capabilities. They were removed from AGS completely in
30 // generation 3.0. The code is left for backwards compatibility.
31 //
32 //-----------------------------------------------------------------------------
33 //
34 /* THE WAY THIS WORKS:
35 *
36 * Interaction (Hotspot 1)
37 * |
38 * +-- eventTypes [NUM_EVENTS]
39 * +-- InteractionCommandList [NUM_EVENTS] (Look at hotspot)
40 * |
41 * +-- InteractionCommand [NUM_COMMANDS] (Display message)
42 * |
43 * +-- InteractionValue [NUM_ARGUMENTS] (5)
44 */
45 //
46 //=============================================================================
47 
48 #ifndef AGS_SHARED_GAME_INTEREACTIONS_H
49 #define AGS_SHARED_GAME_INTEREACTIONS_H
50 
51 #include "common/std/memory.h"
52 #include "ags/shared/util/string_types.h"
53 
54 namespace AGS3 {
55 
56 #define LOCAL_VARIABLE_OFFSET 10000
57 #define MAX_GLOBAL_VARIABLES 100
58 #define MAX_ACTION_ARGS 5
59 #define MAX_NEWINTERACTION_EVENTS 30
60 #define MAX_COMMANDS_PER_LIST 40
61 
62 namespace AGS {
63 namespace Shared {
64 
65 enum InterValType : int8_t {
66  kInterValInvalid = 0,
67  kInterValLiteralInt = 1,
68  kInterValVariable = 2,
69  kInterValBoolean = 3,
70  kInterValCharnum = 4
71 };
72 
73 enum InteractionVersion {
74  kInteractionVersion_Initial = 1
75 };
76 
77 // InteractionValue represents an argument of interaction command
79  InterValType Type; // value type
80  int Value; // value definition
81  int Extra;
82 
84 
85  void clear();
86 
87  void Read(Stream *in);
88  void Write(Stream *out) const;
89 };
90 
91 
94 
95 // InteractionCommand represents a single command (action), an item of Command List
97  int Type; // type of action
98  InteractionValue Data[MAX_ACTION_ARGS]; // action arguments
99  UInterCmdList Children; // list of sub-actions
100  InteractionCommandList *Parent; // action parent (optional)
101 
104 
105  void Assign(const InteractionCommand &ic, InteractionCommandList *parent);
106  void Reset();
107 
108  void Read_v321(Stream *in, bool &has_children);
109  void Write_v321(Stream *out) const;
110 
111  InteractionCommand &operator = (const InteractionCommand &ic);
112 
113  private:
114  void ReadValues_Aligned(Stream *in);
115  void WriteValues_Aligned(Stream *out) const;
116 };
117 
118 
120 // InteractionCommandList represents a list of commands (actions) that need to be
121 // performed on particular game event
123  InterCmdVector Cmds; // actions to run
124  int TimesRun; // used by engine to track score changes
125 
128 
129  void Reset();
130 
131  void Read_v321(Stream *in);
132  void Write_v321(Stream *out) const;
133 
134 protected:
135  void Read_Aligned(Shared::Stream *in, std::vector<bool> &cmd_children);
136  void Write_Aligned(Shared::Stream *out) const;
137 };
138 
139 
140 // InteractionEvent is a single event with a list of commands to performed
142  int Type; // type of event
143  int TimesRun; // used by engine to track score changes
144  UInterCmdList Response; // list of commands to run
145 
148 
149  InteractionEvent &operator = (const InteractionEvent &ic);
150 };
151 
153 // Interaction is the list of events and responses for a game or game object
154 struct Interaction {
155  // The first few event types depend on the item - ID's of 100+ are
156  // custom events (used for subroutines)
157  InterEvtVector Events;
158 
159  Interaction();
160  Interaction(const Interaction &inter);
161 
162  // Copy information on number of times events of this interaction were fired
163  void CopyTimesRun(const Interaction &inter);
164  void Reset();
165 
166  // Game static data (de)serialization
167  static Interaction *CreateFromStream(Stream *in);
168  void Write(Stream *out) const;
169 
170  // Reading and writing runtime data from/to savedgame;
171  // NOTE: these are backwards-compatible methods, that do not always
172  // have practical sense
173  void ReadFromSavedgame_v321(Stream *in);
174  void WriteToSavedgame_v321(Stream *out) const;
175  void ReadTimesRunFromSave_v321(Stream *in);
176  void WriteTimesRunToSave_v321(Stream *out) const;
177 
178  Interaction &operator =(const Interaction &inter);
179 };
180 
182 
183 
184 // Legacy pre-3.0 kind of global and local room variables
186  String Name{};
187  char Type{ '\0' };
188  int Value{ 0 };
189 
191  InteractionVariable(const String &name, char type, int val);
192 
193  void Read(Stream *in);
194  void Write(Stream *out) const;
195 };
196 
198 
199 
200 // A list of script function names for all supported events
202  StringV ScriptFuncNames;
203 
204  static InteractionScripts *CreateFromStream(Stream *in);
205 };
206 
208 
209 } // namespace Shared
210 } // namespace AGS
211 } // namespace AGS3
212 
213 #endif
Definition: achievements_tables.h:27
Definition: interactions.h:141
Definition: interactions.h:154
Definition: interactions.h:96
Definition: interactions.h:78
Definition: ptr.h:572
Definition: lobject.h:59
Definition: interactions.h:185
Definition: string.h:62
Definition: interactions.h:201
Definition: ptr.h:159
Definition: stream.h:52
Definition: ags.h:40
Definition: interactions.h:122