ScummVM API documentation
converse.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 NUVIE_CORE_CONVERSE_H
23#define NUVIE_CORE_CONVERSE_H
24
25#include "common/str.h"
26#include "ultima/nuvie/actors/actor.h"
27#include "ultima/nuvie/gui/widgets/msg_scroll.h"
28#include "ultima/nuvie/files/u6_lib_n.h"
29#include "ultima/nuvie/views/view.h"
30
31namespace Ultima {
32namespace Nuvie {
33
34class Actor;
35class ActorManager;
36class Configuration;
37class MsgScroll;
38class GameClock;
39class ObjManager;
40class Player;
41class ViewManager;
42class U6Lib_n;
43class U6Lzw;
44
45class ConverseInterpret;
46class ConverseSpeech;
47class ConvScript;
48
49ConverseGumpType get_converse_gump_type_from_config(const Configuration *config);
50
51typedef uint32 converse_value; // any single value read from a script
52typedef unsigned char *convscript_buffer;
53
54typedef struct {
55 uint8 type;
56 converse_value val;
58
59#define U6TALK_VAR_SEX 0x10 // sex of avatar: male=0 female=1
60#define U6TALK_VAR_KARMA 0x14 // avatar's karma
61#define U6TALK_VAR_GARGF 0x15 // 1=player knows Gargish
62#define U6TALK_VAR_NPC_NAME 0x17
63#define U6TALK_VAR_PARTYLIVE 0x17 // number of people (living) following avatar
64#define U6TALK_VAR_PARTYALL 0x18 // number of people (total) following avatar
65#define U6TALK_VAR_HP 0x19 // avatar's health
66#define U6TALK_VAR_PLAYER_NAME 0x19
67#define U6TALK_VAR_QUESTF 0x1A // 0="Thou art not upon a sacred quest!"
68#define WOUTALK_VAR_ADD_TO_INVENTORY_FAILED 0x1D
69#define U6TALK_VAR_WORKTYPE 0x20 // current activity of npc, from schedule
70#define U6TALK_VAR_YSTRING 0x22 // value of $Y variable.
71#define U6TALK_VAR_INPUT 0x23 // previous input from player ($Z)
72#define U6TALK_VAR__LAST_ 0x25 // (all above 36 appear uninitialized)
73
74/* Conversation engine, apart from the interpreter. Loads converse files,
75 * and reads script into buffer. Also manages input/output and has npc-related
76 * support functions. This class handles all game types.
77 */
78class Converse {
79 friend class ConverseInterpret;
80 friend class SETalkInterpret;
81 friend class MDTalkInterpret;
82 friend class WOUConverseInterpret;
83 friend class U6ConverseInterpret;
84
85 // game system objects from nuvie
86 const Configuration *config;
87 GameClock *_clock;
88 ActorManager *actors;
89 ObjManager *objects;
90 Player *player;
91 ViewManager *views;
92 MsgScroll *scroll; // i/o
93
94 nuvie_game_t gametype; // what game is being played?
95 U6Lib_n *src;
96 uint8 src_num; // identify source file: 0=unset/unused
97 const char *src_name();
98
99 ConverseInterpret *conv_i; // interpreter
100 ConvScript *script;
101 View *last_view;
102 Actor *npc;
103 uint8 npc_num;
104 uint8 script_num; //this could differ from npc_num when talking to guards or wisps etc.
105 Common::String _name, _desc;
106
107 bool active; // running npc script? (either paused or unpaused)
108 bool need_input; // waiting for text input
109 bool party_all_the_time; // force NPCs to join player's party?
110
111 Common::String in_str; // last input from player
112 Common::String out_str; // text that is to be printed
113 char *allowed_input; // characters requested for single-character input
114
115 char aname[16]; // return from npc_name()
116 struct converse_variables_s {
117 converse_value cv;
118 char *sv;
119 } *variables; /* initialized for [U6TALK_VAR__LAST_+1] items */
120
121 ConverseSpeech *speech;
122 bool using_fmtowns;
123
124 void reset();
125
126public:
127 Converse();
128 ~Converse();
129 void init(const Configuration *cfg, nuvie_game_t t, MsgScroll *s, ActorManager *a,
130 GameClock *c, Player *p, ViewManager *v, ObjManager *o);
131
132 uint32 get_script_num(uint8 a);
133 void load_conv(const Common::String &convfilename);
134 uint32 load_conv(uint8 a);
135 void unload_conv() {
136 delete src;
137 src = nullptr;
138 }
139 ConvScript *load_script(uint32 n);
140 ConverseInterpret *new_interpreter();
141
142 bool start(Actor *a) {
143 return start(a->get_actor_num());
144 }
145 bool start(uint8 n);
146 void continue_script();
147 void stop();
148
149 bool running() const {
150 return active;
151 }
152 bool is_waiting_for_scroll() {
153 return scroll->get_page_break();
154 }
155 void unwait();
156 void poll_input(const char *allowed = nullptr, bool nonblock = true);
157 bool override_input();
158 void collect_input();
159
160 bool input();
161 void print(const char *s = nullptr);
162 const Common::String &get_input() const {
163 return in_str;
164 }
165 const Common::String &get_output() const {
166 return out_str;
167 }
168 void set_input(Common::String s) {
169 in_str = s;
170 }
171 void set_output(Common::String s) {
172 out_str = s;
173 }
174
175 void set_party_all_the_time(bool val) {
176 party_all_the_time = val;
177 }
178 const char *npc_name(uint8 num);
179 void show_portrait(uint8 n);
180 converse_value get_var(uint8 varnum) const {
181 return (varnum <= U6TALK_VAR__LAST_ ? variables[varnum].cv : 0x00);
182 }
183 const char *get_svar(uint8 varnum);
184 void set_var(uint8 varnum, uint32 val) {
185 if (varnum <= U6TALK_VAR__LAST_) variables[varnum].cv = val;
186 }
187 void set_svar(uint8 varnum, const char *set);
188 void init_variables();
189 void delete_variables();
190
191 ConverseSpeech *get_speech() {
192 return speech;
193 };
194
195 bool conversations_stop_music;
196private:
197 void print_prompt();
198};
199
200
201/* Conversation script container. Maintains current position in the script. The
202 * object only exists if it has data loaded. Different classes with an identical
203 * interface can be created to handle different games' file formats.
204 */
206 friend class Converse;
207
208 convscript_buffer buf;
209 uint32 buf_len;
210 convscript_buffer buf_pt; // pointer into script (current location)
211
212 U6Lib_n *src;
213 uint32 src_index;
214 bool compressed; // was the original file (LZW) compressed?
215
216 uint8 ref; // Multiple objects can use the same buffer
217 ConvScript *cpy;
218
219public:
220 ConvScript(U6Lib_n *s, uint32 idx);
221 ConvScript(ConvScript *orig);
222 ~ConvScript();
223
224 void read_script();
225 bool loaded() const {
226 return ((buf && buf_len)); // script is loaded?
227 }
228
229 /* Reading */
230 converse_value read(uint32 advance = 1);
231 converse_value read2();
232 converse_value read4();
233 converse_value peek(uint32 displacement = 0) {
234 return ((converse_value) * (buf_pt + displacement));
235 }
236
237 /* Writing */
238 void write2(converse_value val);
239
240 /* Seeking - update script pointer */
241 void rewind() {
242 buf_pt = buf;
243 }
244 void skip(uint32 bytes = 1) {
245 buf_pt += bytes;
246 }
247 void seek(uint32 offset = 0) {
248 rewind();
249 skip(offset);
250 }
251
252 uint32 pos() const {
253 return buf_pt - buf;
254 }
255 bool overflow(uint32 ptadd = 0) const {
256 return (((pos() + ptadd) >= buf_len));
257 }
258 convscript_buffer get_buffer(uint32 ptadd = 0) {
259 return ((!ptadd || (ptadd < buf_len)) ? buf + ptadd : nullptr);
260 }
261};
262
263} // End of namespace Nuvie
264} // End of namespace Ultima
265
266#endif
Definition: str.h:59
Definition: actor.h:174
Definition: actor_manager.h:42
Definition: configuration.h:60
Definition: converse.h:205
Definition: converse.h:78
Definition: converse_interpret.h:115
Definition: converse_speech.h:40
Definition: game_clock.h:45
Definition: converse_interpret.h:328
Definition: msg_scroll.h:90
Definition: obj_manager.h:74
Definition: player.h:41
Definition: converse_interpret.h:322
Definition: converse_interpret.h:308
Definition: u6_lib_n.h:42
Definition: view.h:42
Definition: view_manager.h:55
Definition: converse_interpret.h:314
Definition: converse.h:54