OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
gamescript.h
Go to the documentation of this file.
1#pragma once
2
3#include <zenkit/DaedalusVm.hh>
4#include <zenkit/addon/daedalus.hh>
5#include <zenkit/CutsceneLibrary.hh>
6
7#include <memory>
8#include <set>
9#include <random>
10
11#include <Tempest/Matrix4x4>
12#include <Tempest/Painter>
13
16#include "game/aiouputpipe.h"
17#include "game/constants.h"
18#include "game/aistate.h"
19#include "game/questlog.h"
20
21class GameSession;
22class World;
23class DirectMemory;
24class Npc;
25class Item;
26class VisualFx;
27class ParticleFx;
28class Serialize;
29class Gothic;
30
31class ScriptFn final {
32 public:
33 ScriptFn()=default;
34 ScriptFn(size_t v):ptr(v){}
35
36 size_t ptr=size_t(-1);
37
38 bool isValid() const { return ptr!=size_t(-1); }
39
40 friend bool operator == (const ScriptFn& a,const ScriptFn& b) {
41 return a.ptr==b.ptr;
42 }
43 };
44
45class GameScript final {
46 public:
47 GameScript(GameSession &owner);
49
50 struct DlgChoice final {
51 std::string title;
52 int32_t sort = 0;
53 uint32_t scriptFn = 0;
54 bool isTrade = false;
55 zenkit::IInfo* handle = nullptr;
56 };
57
58 struct PerDist {
59 PerDist();
60 int32_t range[PERC_Count] = {};
61 int at(PercType perc, int r) const;
62 };
63
64 bool hasSymbolName(std::string_view fn);
65
66 void initializeInstanceNpc(const std::shared_ptr<zenkit::INpc>& npc, size_t instance);
67 void initializeInstanceItem(const std::shared_ptr<zenkit::IItem>& item, size_t instance);
68 void resetVarPointers();
69
70 void initDialogs();
71 void saveQuests(Serialize& fout);
72 void loadQuests(Serialize& fin);
73 void saveVar(Serialize& fout);
74 void loadVar(Serialize& fin);
75 void savePerc(Serialize& fout);
76 void loadPerc(Serialize& fin);
77
78 inline auto& getVm() { return vm; }
79 auto questLog() const -> const QuestLog&;
80
81 const World& world() const;
82 World& world();
83 uint64_t tickCount() const;
84 void tick(uint64_t dt);
85
86 uint32_t rand(uint32_t max);
87 void removeItem(Item& it);
88
89 void setInstanceNPC (std::string_view name, Npc& npc);
90 void setInstanceItem(Npc& holder, size_t itemId);
91
93 AiOuputPipe* openDlgOuput(Npc &player, Npc &npc);
94
95 auto* goldId() const { return itMi_Gold; }
97 std::string_view currencyName() const { return goldTxt; }
98 int npcDamDiveTime();
99 int32_t criticalDamageMultiplyer() const;
100 auto* lockPickSymbol() const { return ItKE_lockpick; }
101 uint32_t lockPickId() const;
102
103 const zenkit::IFocus& focusNorm() const { return cFocusNorm; }
104 const zenkit::IFocus& focusMelee() const { return cFocusMelee; }
105 const zenkit::IFocus& focusRange() const { return cFocusRange; }
106 const zenkit::IFocus& focusMage() const { return cFocusMage; }
107 const zenkit::IGuildValues& guildVal() const { return *cGuildVal; }
108
109 std::string_view menuMain() const;
110
111 zenkit::DaedalusSymbol* findSymbol(std::string_view s);
112 zenkit::DaedalusSymbol* findSymbol(const size_t s);
113 size_t findSymbolIndex(std::string_view s);
114 size_t symbolsCount() const;
115
116 const AiState& aiState (ScriptFn id);
117 const zenkit::ISpell& spellDesc(int32_t splId);
118 const VisualFx* spellVfx (int32_t splId);
119
120 auto dialogChoices(std::shared_ptr<zenkit::INpc> self, std::shared_ptr<zenkit::INpc> npc, const std::vector<uint32_t> &except, bool includeImp) -> std::vector<DlgChoice>;
121 auto updateDialog (const GameScript::DlgChoice &dlg, Npc &player, Npc &npc) -> std::vector<GameScript::DlgChoice>;
122 void exec(const DlgChoice &dlg, Npc &player, Npc &npc);
123
124 void printCannotUseError (Npc &npc, int32_t atr, int32_t nValue);
125 void printCannotCastError (Npc &npc, int32_t plM, int32_t itM);
126 void printCannotBuyError (Npc &npc);
127 void printMobMissingItem (Npc &npc);
128 void printMobAnotherIsUsing (Npc &npc);
129 void printMobMissingKey (Npc &npc);
131 void printMobMissingLockpick (Npc &npc);
132 void printMobTooFar (Npc &npc);
133
134 void invokeState(const std::shared_ptr<zenkit::INpc>& hnpc, const std::shared_ptr<zenkit::INpc>& hother, const char* name);
135 int invokeState(Npc* npc, Npc* other, Npc *victim, ScriptFn fn);
136 void invokeItem (Npc* npc, ScriptFn fn);
137 int invokeMana (Npc& npc, Npc* target, int mana);
138 int invokeManaRelease (Npc& npc, Npc* target, int mana);
139 void invokeSpell(Npc& npc, Npc *target, Item& fn);
140 int invokeCond (Npc& npc, std::string_view func);
141 void invokePickLock(Npc& npc, int bSuccess, int bBrokenOpen);
142 void invokeRefreshAtInsert(Npc& npc);
143 auto canNpcCollideWithSpell(Npc& npc, Npc* shooter, int32_t spellId) -> CollideMask;
144
146 int playerHotKeyScreenMap(Npc& pl);
147 void playerHotLamePotion(Npc& pl);
148 void playerHotLameHeal(Npc& pl);
149
150 const PerDist& percRanges() const { return perceptionRanges; }
151
152 bool isDead (const Npc &pl);
153 bool isUnconscious(const Npc &pl);
154 bool isTalk (const Npc &pl);
155 bool isAttack (const Npc &pl) const;
156
157 std::string_view spellCastAnim(Npc& npc, Item& fn);
158 std::string_view messageFromSvm(std::string_view id,int voice) const;
159 std::string_view messageByName (std::string_view id) const;
160 uint32_t messageTime (std::string_view id) const;
161
162 void printNothingToGet();
163 float tradeValueMultiplier() const { return tradeValMult; }
164 void useInteractive(const std::shared_ptr<zenkit::INpc>& hnpc, std::string_view func);
165 Attitude guildAttitude(const Npc& p0,const Npc& p1) const;
166 Attitude personAttitude(const Npc& p0,const Npc& p1) const;
167 bool isFriendlyFire(const Npc& src, const Npc& dst) const;
168
169 BodyState schemeToBodystate(std::string_view sc);
170
171 void onWldItemRemoved(const Item& itm);
172 void fixNpcPosition(Npc& npc, float angle0, float distBias);
173
174 void eventPlayAni(Npc& npc, std::string_view ani);
175
176 private:
177 template<typename T>
178 struct DetermineSignature {
179 using signature = void();
180 };
181
182 template <typename C, typename R, typename ... P>
183 struct DetermineSignature<R(C::*)(P...)> {
184 using signature = R(P...);
185 };
186
187 struct GlobalOutput : AiOuputPipe {
188 explicit GlobalOutput(GameScript& owner):owner(owner){}
189
190 bool output (Npc &npc, std::string_view text) override;
191 bool outputSvm(Npc& npc, std::string_view text) override;
192 bool outputOv (Npc& npc, std::string_view text) override;
193 bool printScr (Npc& npc, int time, std::string_view msg, int x,int y, std::string_view font) override;
194 bool isFinished() override;
195
196 bool close() override { return true; }
197
198 GameScript& owner;
199 };
200
201 template <class F>
202 void bindExternal(const std::string& name, F function) {
203 vm.register_external(name, std::function<typename DetermineSignature<F>::signature> (
204 [this, function](auto ... v) { return (this->*function)(v...); }));
205 }
206
207 void initCommon();
208 void initSettings();
209 void loadDialogOU();
210
211 Item* findItem(zenkit::IItem* handle);
212 Item* findItemById(size_t id);
213 Item* findItemById(const std::shared_ptr<zenkit::DaedalusInstance>& handle);
214 Npc* findNpc(zenkit::DaedalusSymbol* s);
215 Npc* findNpc(zenkit::INpc* handle);
216 Npc* findNpc(const std::shared_ptr<zenkit::INpc>& handle);
217 Npc* findNpcById (const std::shared_ptr<zenkit::DaedalusInstance>& handle);
218 Npc* findNpcById (size_t id);
219 auto findInfo (size_t id) -> zenkit::IInfo*;
220 auto findFocus(std::string_view name) -> zenkit::IFocus;
221
222 void storeItem(Item* it);
223
224 bool aiOutput (Npc &from, std::string_view name, bool overlay);
225 bool aiOutputSvm(Npc &from, std::string_view name, bool overlay);
226
227 bool searchScheme(std::string_view sc, std::string_view listName);
228
229 static zenkit::DaedalusVm createVm(Gothic& gothic);
230
231 bool game_initgerman ();
232 bool game_initenglish ();
233
234 int hlp_random (int bound);
235 bool hlp_isvalidnpc (std::shared_ptr<zenkit::INpc> npcRef);
236 bool hlp_isitem (std::shared_ptr<zenkit::IItem> itemRef, int instanceSymbol);
237 bool hlp_isvaliditem (std::shared_ptr<zenkit::IItem> itemRef);
238 int hlp_getinstanceid (std::shared_ptr<zenkit::DaedalusInstance> instance);
239 auto hlp_getnpc (int instanceSymbol) -> std::shared_ptr<zenkit::INpc>;
240
241 void wld_insertitem (int itemInstance, std::string_view spawnpoint);
242 void wld_insertnpc (int npcInstance, std::string_view spawnpoint);
243 void wld_removenpc (int npcInstance);
244 void wld_settime (int hour, int minute);
245 int wld_getday ();
246 void wld_playeffect (std::string_view visual, std::shared_ptr<zenkit::DaedalusInstance> sourceId, std::shared_ptr<zenkit::DaedalusInstance> targetId, int effectLevel, int damage, int damageType, int isProjectile);
247 void wld_stopeffect (std::string_view visual);
248 int wld_getplayerportalguild();
249 int wld_getformerplayerportalguild();
250 void wld_setguildattitude (int gil1, int att, int gil2);
251 int wld_getguildattitude (int g1, int g0);
252 void wld_exchangeguildattitudes (std::string_view name);
253 bool wld_istime (int hour0, int min0, int hour1, int min1);
254 bool wld_isfpavailable (std::shared_ptr<zenkit::INpc> self, std::string_view name);
255 bool wld_isnextfpavailable(std::shared_ptr<zenkit::INpc> self, std::string_view name);
256 bool wld_ismobavailable (std::shared_ptr<zenkit::INpc> self, std::string_view name);
257 void wld_setmobroutine (int h, int m, std::string_view name, int st);
258 int wld_getmobstate (std::shared_ptr<zenkit::INpc> npc, std::string_view scheme);
259 void wld_assignroomtoguild(std::string_view name, int g);
260 bool wld_detectnpc (std::shared_ptr<zenkit::INpc> npcRef, int inst, int state, int guild);
261 bool wld_detectnpcex (std::shared_ptr<zenkit::INpc> npcRef, int inst, int state, int guild, int player);
262 bool wld_detectitem (std::shared_ptr<zenkit::INpc> npcRef, int flags);
263 void wld_spawnnpcrange (std::shared_ptr<zenkit::INpc> npcRef, int clsId, int count, float lifeTime);
264 void wld_sendtrigger (std::string_view triggerTarget);
265 void wld_senduntrigger (std::string_view triggerTarget);
266 bool wld_israining ();
267
268 void mdl_setvisual (std::shared_ptr<zenkit::INpc> npcRef, std::string_view visual);
269 void mdl_setvisualbody (std::shared_ptr<zenkit::INpc> npcRef, std::string_view body, int bodyTexNr, int bodyTexColor, std::string_view head, int headTexNr, int teethTexNr, int armor);
270 void mdl_setmodelfatness (std::shared_ptr<zenkit::INpc> npcRef, float fat);
271 void mdl_applyoverlaymds (std::shared_ptr<zenkit::INpc> npcRef, std::string_view overlayname);
272 void mdl_applyoverlaymdstimed(std::shared_ptr<zenkit::INpc> npcRef, std::string_view overlayname, int ticks);
273 void mdl_removeoverlaymds(std::shared_ptr<zenkit::INpc> npcRef, std::string_view overlayname);
274 void mdl_setmodelscale (std::shared_ptr<zenkit::INpc> npcRef, float x, float y, float z);
275 void mdl_startfaceani (std::shared_ptr<zenkit::INpc> npcRef, std::string_view ani, float intensity, float time);
276 void mdl_applyrandomani (std::shared_ptr<zenkit::INpc> npcRef, std::string_view s1, std::string_view s0);
277 void mdl_applyrandomanifreq(std::shared_ptr<zenkit::INpc> npcRef, std::string_view s1, float f0);
278 void mdl_applyrandomfaceani(std::shared_ptr<zenkit::INpc> npcRef, std::string_view name, float timeMin, float timeMinVar, float timeMax, float timeMaxVar, float probMin);
279
280 void npc_settofightmode (std::shared_ptr<zenkit::INpc> npcRef, int weaponSymbol);
281 void npc_settofistmode (std::shared_ptr<zenkit::INpc> npcRef);
282 bool npc_isinstate (std::shared_ptr<zenkit::INpc> npcRef, int stateFn);
283 bool npc_isinroutine (std::shared_ptr<zenkit::INpc> npcRef, int stateFn);
284 bool npc_wasinstate (std::shared_ptr<zenkit::INpc> npcRef, int stateFn);
285 int npc_getdisttowp (std::shared_ptr<zenkit::INpc> npcRef, std::string_view wpname);
286 void npc_exchangeroutine (std::shared_ptr<zenkit::INpc> npcRef, std::string_view rname);
287 bool npc_isdead (std::shared_ptr<zenkit::INpc> npcRef);
288 bool npc_knowsinfo (std::shared_ptr<zenkit::INpc> npcRef, int infoinstance);
289 void npc_settalentskill (std::shared_ptr<zenkit::INpc> npcRef, int t, int lvl);
290 int npc_gettalentskill (std::shared_ptr<zenkit::INpc> npcRef, int skillId);
291 void npc_settalentvalue (std::shared_ptr<zenkit::INpc> npcRef, int t, int lvl);
292 int npc_gettalentvalue (std::shared_ptr<zenkit::INpc> npcRef, int skillId);
293 void npc_setrefusetalk (std::shared_ptr<zenkit::INpc> npcRef, int timeSec);
294 bool npc_refusetalk (std::shared_ptr<zenkit::INpc> npcRef);
295 int npc_hasitems (std::shared_ptr<zenkit::INpc> npcRef, int itemId);
296 bool npc_hasspell (std::shared_ptr<zenkit::INpc> npcRef, int splId);
297 int npc_getinvitem (std::shared_ptr<zenkit::INpc> npcRef, int itemId);
298 int npc_getinvitembyslot(std::shared_ptr<zenkit::INpc> npcRef, int cat, int slotnr);
299 int npc_removeinvitem (std::shared_ptr<zenkit::INpc> npcRef, int itemId);
300 int npc_removeinvitems (std::shared_ptr<zenkit::INpc> npcRef, int itemId, int amount);
301 int npc_getbodystate (std::shared_ptr<zenkit::INpc> npcRef);
302 std::shared_ptr<zenkit::INpc> npc_getlookattarget (std::shared_ptr<zenkit::INpc> npcRef);
303 int npc_getdisttonpc (std::shared_ptr<zenkit::INpc> aRef, std::shared_ptr<zenkit::INpc> bRef);
304 bool npc_hasequippedarmor(std::shared_ptr<zenkit::INpc> npcRef);
305 void npc_setperctime (std::shared_ptr<zenkit::INpc> npcRef, float sec);
306 void npc_percenable (std::shared_ptr<zenkit::INpc> npcRef, int pr, int fn);
307 void npc_percdisable (std::shared_ptr<zenkit::INpc> npcRef, int pr);
308 std::string npc_getnearestwp (std::shared_ptr<zenkit::INpc> npcRef);
309 std::string npc_getnextwp(std::shared_ptr<zenkit::INpc> npcRef);
310 void npc_clearaiqueue (std::shared_ptr<zenkit::INpc> npcRef);
311 bool npc_isplayer (std::shared_ptr<zenkit::INpc> npcRef);
312 int npc_getstatetime (std::shared_ptr<zenkit::INpc> npcRef);
313 void npc_setstatetime (std::shared_ptr<zenkit::INpc> npcRef, int val);
314 void npc_changeattribute (std::shared_ptr<zenkit::INpc> npcRef, int atr, int val);
315 bool npc_isonfp (std::shared_ptr<zenkit::INpc> npcRef, std::string_view val);
316 int npc_getheighttonpc (std::shared_ptr<zenkit::INpc> aRef, std::shared_ptr<zenkit::INpc> bRef);
317 std::shared_ptr<zenkit::IItem> npc_getequippedmeleeweapon (std::shared_ptr<zenkit::INpc> npcRef);
318 std::shared_ptr<zenkit::IItem> npc_getequippedrangedweapon(std::shared_ptr<zenkit::INpc> npcRef);
319 std::shared_ptr<zenkit::IItem> npc_getequippedarmor(std::shared_ptr<zenkit::INpc> npcRef);
320 bool npc_canseenpc (std::shared_ptr<zenkit::INpc> npcRef, std::shared_ptr<zenkit::INpc> otherRef);
321 bool npc_canseenpcfreelos(std::shared_ptr<zenkit::INpc> npcRef, std::shared_ptr<zenkit::INpc> otherRef);
322 bool npc_canseeitem (std::shared_ptr<zenkit::INpc> npcRef, std::shared_ptr<zenkit::IItem> itemRef);
323 bool npc_hasequippedweapon(std::shared_ptr<zenkit::INpc> npcRef);
324 bool npc_hasequippedmeleeweapon(std::shared_ptr<zenkit::INpc> npcRef);
325 bool npc_hasequippedrangedweapon(std::shared_ptr<zenkit::INpc> npcRef);
326 int npc_getactivespell (std::shared_ptr<zenkit::INpc> npcRef);
327 bool npc_getactivespellisscroll(std::shared_ptr<zenkit::INpc> npcRef);
328 bool npc_isinfightmode (std::shared_ptr<zenkit::INpc> npcRef, int modeI);
329 int npc_getactivespellcat(std::shared_ptr<zenkit::INpc> npcRef);
330 int npc_setactivespellinfo(std::shared_ptr<zenkit::INpc> npcRef, int v);
331 int npc_getactivespelllevel(std::shared_ptr<zenkit::INpc> npcRef);
332 void npc_settarget (std::shared_ptr<zenkit::INpc> npcRef, std::shared_ptr<zenkit::INpc> otherRef);
333 bool npc_gettarget (std::shared_ptr<zenkit::INpc> npcRef);
334 bool npc_getnexttarget (std::shared_ptr<zenkit::INpc> npcRef);
335 void npc_sendpassiveperc (std::shared_ptr<zenkit::INpc> npcRef, int id, std::shared_ptr<zenkit::INpc> victimRef, std::shared_ptr<zenkit::INpc> otherRef);
336 void npc_sendsingleperc (std::shared_ptr<zenkit::INpc> npcRef, std::shared_ptr<zenkit::INpc> otherRef, int id);
337 bool npc_checkinfo (std::shared_ptr<zenkit::INpc> npcRef, int imp);
338 int npc_getportalguild (std::shared_ptr<zenkit::INpc> npcRef);
339 bool npc_isinplayersroom (std::shared_ptr<zenkit::INpc> npcRef);
340 std::shared_ptr<zenkit::IItem> npc_getreadiedweapon(std::shared_ptr<zenkit::INpc> npcRef);
341 bool npc_hasreadiedweapon(std::shared_ptr<zenkit::INpc> npcRef);
342 bool npc_hasreadiedmeleeweapon(std::shared_ptr<zenkit::INpc> npcRef);
343 bool npc_hasreadiedrangedweapon(std::shared_ptr<zenkit::INpc> npcRef);
344 bool npc_hasrangedweaponwithammo(std::shared_ptr<zenkit::INpc> npcRef);
345 int npc_isdrawingspell (std::shared_ptr<zenkit::INpc> npcRef);
346 int npc_isdrawingweapon (std::shared_ptr<zenkit::INpc> npcRef);
347 void npc_perceiveall (std::shared_ptr<zenkit::INpc> npcRef);
348 void npc_stopani (std::shared_ptr<zenkit::INpc> npcRef, std::string_view name);
349 int npc_settrueguild (std::shared_ptr<zenkit::INpc> npcRef, int gil);
350 int npc_gettrueguild (std::shared_ptr<zenkit::INpc> npcRef);
351 void npc_clearinventory (std::shared_ptr<zenkit::INpc> npcRef);
352 int npc_getattitude (std::shared_ptr<zenkit::INpc> aRef, std::shared_ptr<zenkit::INpc> bRef);
353 int npc_getpermattitude (std::shared_ptr<zenkit::INpc> aRef, std::shared_ptr<zenkit::INpc> bRef);
354 void npc_setattitude (std::shared_ptr<zenkit::INpc> npcRef, int att);
355 void npc_settempattitude (std::shared_ptr<zenkit::INpc> npcRef, int att);
356 bool npc_hasbodyflag (std::shared_ptr<zenkit::INpc> npcRef, int bodyflag);
357 int npc_getlasthitspellid(std::shared_ptr<zenkit::INpc> npcRef);
358 int npc_getlasthitspellcat(std::shared_ptr<zenkit::INpc> npcRef);
359 void npc_playani (std::shared_ptr<zenkit::INpc> npcRef, std::string_view name);
360 bool npc_isdetectedmobownedbynpc(std::shared_ptr<zenkit::INpc> usrRef, std::shared_ptr<zenkit::INpc> npcRef);
361 std::string npc_getdetectedmob (std::shared_ptr<zenkit::INpc> npcRef);
362 bool npc_ownedbynpc (std::shared_ptr<zenkit::IItem> itmRef, std::shared_ptr<zenkit::INpc> npcRef);
363 bool npc_canseesource (std::shared_ptr<zenkit::INpc> npcRef);
364 bool npc_isincutscene (std::shared_ptr<zenkit::INpc> npcRef);
365 int npc_getdisttoitem (std::shared_ptr<zenkit::INpc> npcRef, std::shared_ptr<zenkit::IItem> itmRef);
366 int npc_getheighttoitem (std::shared_ptr<zenkit::INpc> npcRef, std::shared_ptr<zenkit::IItem> itmRef);
367 int npc_getdisttoplayer (std::shared_ptr<zenkit::INpc> npcRef);
368 bool npc_isdetectedmobownedbyguild(std::shared_ptr<zenkit::INpc> npcRef, int guild);
369
370 void ai_output (std::shared_ptr<zenkit::INpc> selfRef, std::shared_ptr<zenkit::INpc> targetRef, std::string_view outputname);
371 void ai_stopprocessinfos (std::shared_ptr<zenkit::INpc> selfRef);
372 void ai_processinfos (std::shared_ptr<zenkit::INpc> npcRef);
373 void ai_standup (std::shared_ptr<zenkit::INpc> selfRef);
374 void ai_standupquick (std::shared_ptr<zenkit::INpc> selfRef);
375 void ai_continueroutine (std::shared_ptr<zenkit::INpc> selfRef);
376 void ai_stoplookat (std::shared_ptr<zenkit::INpc> selfRef);
377 void ai_lookat (std::shared_ptr<zenkit::INpc> selfRef, std::string_view waypoint);
378 void ai_lookatnpc (std::shared_ptr<zenkit::INpc> selfRef, std::shared_ptr<zenkit::INpc> npcRef);
379 void ai_removeweapon (std::shared_ptr<zenkit::INpc> npcRef);
380 void ai_unreadyspell (std::shared_ptr<zenkit::INpc> npcRef);
381 void ai_turnaway (std::shared_ptr<zenkit::INpc> selfRef, std::shared_ptr<zenkit::INpc> npcRef);
382 void ai_turntonpc (std::shared_ptr<zenkit::INpc> selfRef, std::shared_ptr<zenkit::INpc> npcRef);
383 void ai_whirlaround (std::shared_ptr<zenkit::INpc> selfRef, std::shared_ptr<zenkit::INpc> npcRef);
384 void ai_outputsvm (std::shared_ptr<zenkit::INpc> selfRef, std::shared_ptr<zenkit::INpc> targetRef, std::string_view name);
385 void ai_outputsvm_overlay(std::shared_ptr<zenkit::INpc> selfRef, std::shared_ptr<zenkit::INpc> targetRef, std::string_view name);
386 void ai_startstate (std::shared_ptr<zenkit::INpc> selfRef, int func, int state, std::string_view wp);
387 void ai_playani (std::shared_ptr<zenkit::INpc> npcRef, std::string_view name);
388 void ai_setwalkmode (std::shared_ptr<zenkit::INpc> npcRef, int modeBits);
389 void ai_wait (std::shared_ptr<zenkit::INpc> npcRef, float ms);
390 void ai_waitms (std::shared_ptr<zenkit::INpc> npcRef, int ms);
391 void ai_aligntowp (std::shared_ptr<zenkit::INpc> npcRef);
392 void ai_gotowp (std::shared_ptr<zenkit::INpc> npcRef, std::string_view waypoint);
393 void ai_gotofp (std::shared_ptr<zenkit::INpc> npcRef, std::string_view waypoint);
394 void ai_playanibs (std::shared_ptr<zenkit::INpc> npcRef, std::string_view ani, int bs);
395 void ai_equiparmor (std::shared_ptr<zenkit::INpc> npcRef, int id);
396 void ai_equipbestarmor (std::shared_ptr<zenkit::INpc> npcRef);
397 int ai_equipbestmeleeweapon (std::shared_ptr<zenkit::INpc> npcRef);
398 int ai_equipbestrangedweapon(std::shared_ptr<zenkit::INpc> npcRef);
399 bool ai_usemob (std::shared_ptr<zenkit::INpc> npcRef, std::string_view tg, int state);
400 void ai_teleport (std::shared_ptr<zenkit::INpc> npcRef, std::string_view tg);
401 void ai_stoppointat (std::shared_ptr<zenkit::INpc> npcRef);
402 void ai_drawweapon (std::shared_ptr<zenkit::INpc> npcRef);
403 void ai_readymeleeweapon (std::shared_ptr<zenkit::INpc> npcRef);
404 void ai_readyrangedweapon(std::shared_ptr<zenkit::INpc> npcRef);
405 void ai_readyspell (std::shared_ptr<zenkit::INpc> npcRef, int spell, int mana);
406 void ai_attack (std::shared_ptr<zenkit::INpc> npcRef);
407 void ai_flee (std::shared_ptr<zenkit::INpc> npcRef);
408 void ai_dodge (std::shared_ptr<zenkit::INpc> npcRef);
409 void ai_unequipweapons (std::shared_ptr<zenkit::INpc> npcRef);
410 void ai_unequiparmor (std::shared_ptr<zenkit::INpc> npcRef);
411 void ai_gotonpc (std::shared_ptr<zenkit::INpc> npcRef, std::shared_ptr<zenkit::INpc> toRef);
412 void ai_gotonextfp (std::shared_ptr<zenkit::INpc> npcRef, std::string_view to);
413 void ai_aligntofp (std::shared_ptr<zenkit::INpc> npcRef);
414 void ai_useitem (std::shared_ptr<zenkit::INpc> npcRef, int item);
415 void ai_useitemtostate (std::shared_ptr<zenkit::INpc> npcRef, int item, int state);
416 void ai_setnpcstostate (std::shared_ptr<zenkit::INpc> npcRef, int state, int radius);
417 void ai_finishingmove (std::shared_ptr<zenkit::INpc> npcRef, std::shared_ptr<zenkit::INpc> othRef);
418 void ai_takeitem (std::shared_ptr<zenkit::INpc> npcRef, std::shared_ptr<zenkit::IItem> itmRef);
419 void ai_gotoitem (std::shared_ptr<zenkit::INpc> npcRef, std::shared_ptr<zenkit::IItem> itmRef);
420 void ai_pointat (std::shared_ptr<zenkit::INpc> npcRef, std::string_view waypoint);
421 void ai_pointatnpc (std::shared_ptr<zenkit::INpc> npcRef, std::shared_ptr<zenkit::INpc> otherRef);
422 int ai_printscreen (std::string_view msg, int posx, int posy, std::string_view font, int timesec);
423
424 int mob_hasitems (std::string_view tag, int item);
425
426 void ta_min (std::shared_ptr<zenkit::INpc> npcRef, int start_h, int start_m, int stop_h, int stop_m, int action, std::string_view waypoint);
427
428 void log_createtopic (std::string_view topicName, int section);
429 void log_settopicstatus (std::string_view topicName, int status);
430 void log_addentry (std::string_view topicName, std::string_view entry);
431
432 void equipitem (std::shared_ptr<zenkit::INpc> npcRef, int cls);
433 void createinvitem (std::shared_ptr<zenkit::INpc> npcRef, int itemInstance);
434 void createinvitems (std::shared_ptr<zenkit::INpc> npcRef, int itemInstance, int amount);
435
436 void perc_setrange (int perc, int dist);
437
438 void info_addchoice (int infoInstance, std::string_view text, int func);
439 void info_clearchoices (int infoInstance);
440 bool infomanager_hasfinished();
441
442 void snd_play (std::string_view fileS);
443 void snd_play3d (std::shared_ptr<zenkit::INpc> npcRef, std::string_view fileS);
444
445 void exitsession ();
446
447 void sort(std::vector<DlgChoice>& dlg);
448 void setNpcInfoKnown(const zenkit::INpc& npc, const zenkit::IInfo& info);
449 bool doesNpcKnowInfo(const zenkit::INpc& npc, size_t infoInstance) const;
450
451 void saveSym(Serialize& fout, zenkit::DaedalusSymbol& s);
452
453 void onWldInstanceRemoved(const zenkit::DaedalusInstance* obj);
454 void makeCurrent(Item* w);
455
456 GameSession& owner;
457 zenkit::DaedalusVm vm;
458 int32_t vmLang = -1;
459 std::mt19937 randGen;
461
462 std::unique_ptr<DirectMemory> dma;
463
464 std::unique_ptr<SpellDefinitions> spells;
465 std::unique_ptr<SvmDefinitions> svm;
466 uint64_t svmBarrier=0;
467
468 std::set<std::pair<size_t,size_t>> dlgKnownInfos;
469 std::vector<std::shared_ptr<zenkit::IInfo>> dialogsInfo;
470 zenkit::CutsceneLibrary dialogs;
471 std::unordered_map<size_t,AiState> aiStates;
472 std::unique_ptr<AiOuputPipe> aiDefaultPipe;
473
474 QuestLog quests;
475 zenkit::DaedalusSymbol* itMi_Gold = nullptr;
476 zenkit::DaedalusSymbol* ItKE_lockpick = nullptr;
477 zenkit::DaedalusSymbol* B_RefreshAtInsert = nullptr;
478 float tradeValMult = 0.3f;
479 zenkit::DaedalusSymbol* spellFxInstanceNames = nullptr;
480 zenkit::DaedalusSymbol* spellFxAniLetters = nullptr;
481 std::string goldTxt;
482 float viewTimePerChar = 0.5;
483 int32_t damCriticalMultiplier = 2;
484 mutable std::unordered_map<std::string,uint32_t> msgTimings;
485 size_t gilTblSize=0;
486 size_t gilCount=0;
487 std::vector<int32_t> gilAttitudes;
488 int aiOutOrderId=0;
489
490 PerDist perceptionRanges;
491
492 size_t ZS_Dead=0;
493 size_t ZS_Unconscious=0;
494 size_t ZS_Talk=0;
495 size_t ZS_Attack=0;
496 size_t ZS_MM_Attack=0;
497
498 zenkit::IFocus cFocusNorm,cFocusMelee,cFocusRange,cFocusMage;
499 std::shared_ptr<zenkit::IGuildValues> cGuildVal;
500
501 friend struct ScopeCtx;
502 };
void printMobMissingKeyOrLockpick(Npc &npc)
void invokeRefreshAtInsert(Npc &npc)
size_t findSymbolIndex(std::string_view s)
Attitude guildAttitude(const Npc &p0, const Npc &p1) const
void printCannotCastError(Npc &npc, int32_t plM, int32_t itM)
void initDialogs()
uint32_t lockPickId() const
void printNothingToGet()
int invokeMana(Npc &npc, Npc *target, int mana)
bool hasSymbolName(std::string_view fn)
bool isTalk(const Npc &pl)
size_t symbolsCount() const
void printCannotUseError(Npc &npc, int32_t atr, int32_t nValue)
std::string_view spellCastAnim(Npc &npc, Item &fn)
std::string_view menuMain() const
uint32_t messageTime(std::string_view id) const
void playerHotLameHeal(Npc &pl)
int playerHotKeyScreenMap(Npc &pl)
void loadPerc(Serialize &fin)
void loadQuests(Serialize &fin)
int invokeCond(Npc &npc, std::string_view func)
void exec(const DlgChoice &dlg, Npc &player, Npc &npc)
bool isFriendlyFire(const Npc &src, const Npc &dst) const
const zenkit::IFocus & focusRange() const
Definition gamescript.h:105
std::string_view messageByName(std::string_view id) const
void printMobAnotherIsUsing(Npc &npc)
const AiState & aiState(ScriptFn id)
void initializeInstanceItem(const std::shared_ptr< zenkit::IItem > &item, size_t instance)
void fixNpcPosition(Npc &npc, float angle0, float distBias)
void useInteractive(const std::shared_ptr< zenkit::INpc > &hnpc, std::string_view func)
void loadVar(Serialize &fin)
const PerDist & percRanges() const
Definition gamescript.h:150
int npcDamDiveTime()
void onWldItemRemoved(const Item &itm)
void invokeState(const std::shared_ptr< zenkit::INpc > &hnpc, const std::shared_ptr< zenkit::INpc > &hother, const char *name)
const zenkit::IFocus & focusMage() const
Definition gamescript.h:106
const zenkit::IFocus & focusMelee() const
Definition gamescript.h:104
void removeItem(Item &it)
void printMobMissingItem(Npc &npc)
auto questLog() const -> const QuestLog &
zenkit::DaedalusSymbol * findSymbol(std::string_view s)
const zenkit::ISpell & spellDesc(int32_t splId)
std::string_view messageFromSvm(std::string_view id, int voice) const
AiOuputPipe * openAiOuput()
void tick(uint64_t dt)
void resetVarPointers()
auto * lockPickSymbol() const
Definition gamescript.h:100
uint64_t tickCount() const
void printMobMissingKey(Npc &npc)
int playerHotKeyScreenMap_G1(Npc &pl)
AiOuputPipe * openDlgOuput(Npc &player, Npc &npc)
void printMobTooFar(Npc &npc)
bool isUnconscious(const Npc &pl)
void setInstanceItem(Npc &holder, size_t itemId)
void saveQuests(Serialize &fout)
int32_t criticalDamageMultiplyer() const
auto updateDialog(const GameScript::DlgChoice &dlg, Npc &player, Npc &npc) -> std::vector< GameScript::DlgChoice >
float tradeValueMultiplier() const
Definition gamescript.h:163
ScriptFn playerPercAssessMagic()
void invokeSpell(Npc &npc, Npc *target, Item &fn)
const zenkit::IGuildValues & guildVal() const
Definition gamescript.h:107
void playerHotLamePotion(Npc &pl)
uint32_t rand(uint32_t max)
Attitude personAttitude(const Npc &p0, const Npc &p1) const
int invokeManaRelease(Npc &npc, Npc *target, int mana)
void printCannotBuyError(Npc &npc)
auto * goldId() const
Definition gamescript.h:95
auto dialogChoices(std::shared_ptr< zenkit::INpc > self, std::shared_ptr< zenkit::INpc > npc, const std::vector< uint32_t > &except, bool includeImp) -> std::vector< DlgChoice >
std::string_view currencyName() const
Definition gamescript.h:97
const VisualFx * spellVfx(int32_t splId)
bool isAttack(const Npc &pl) const
const World & world() const
auto canNpcCollideWithSpell(Npc &npc, Npc *shooter, int32_t spellId) -> CollideMask
void initializeInstanceNpc(const std::shared_ptr< zenkit::INpc > &npc, size_t instance)
void savePerc(Serialize &fout)
void printMobMissingLockpick(Npc &npc)
auto & getVm()
Definition gamescript.h:78
void invokeItem(Npc *npc, ScriptFn fn)
bool isDead(const Npc &pl)
void invokePickLock(Npc &npc, int bSuccess, int bBrokenOpen)
void saveVar(Serialize &fout)
void setInstanceNPC(std::string_view name, Npc &npc)
const zenkit::IFocus & focusNorm() const
Definition gamescript.h:103
void eventPlayAni(Npc &npc, std::string_view ani)
BodyState schemeToBodystate(std::string_view sc)
Definition item.h:14
Definition npc.h:25
bool isValid() const
Definition gamescript.h:38
size_t ptr
Definition gamescript.h:36
friend bool operator==(const ScriptFn &a, const ScriptFn &b)
Definition gamescript.h:40
ScriptFn()=default
ScriptFn(size_t v)
Definition gamescript.h:34
Definition world.h:31
static CommandLine * instance
CollideMask
Definition constants.h:252
NpcProcessPolicy
Definition constants.h:506
Attitude
Definition constants.h:234
BodyState
Definition constants.h:140
PercType
Definition constants.h:396
@ PERC_Count
Definition constants.h:432
zenkit::IInfo * handle
Definition gamescript.h:55
int32_t range[PERC_Count]
Definition gamescript.h:60
int at(PercType perc, int r) const