OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
interactive.h
Go to the documentation of this file.
1#pragma once
2
3#include <Tempest/Matrix4x4>
4#include <zenkit/vobs/MovableObject.hh>
5
10#include "game/inventory.h"
11#include "utils/keycodec.h"
12#include "vob.h"
13
14class Npc;
15class World;
16class Trigger;
17
18class Interactive : public Vob {
19 public:
20 enum Anim : int8_t {
21 In = 1,
22 Active = 0,
23 Out = -1,
24
25 ToStand = 10,
27 };
28
29 Interactive(Vob* parent, World& world, const zenkit::VMovableObject& vob, Flags flags);
30
31 void load(Serialize& fin) override;
32 void save(Serialize& fout) const override;
33 void postValidate();
34
35 void resetPositionToTA(int32_t state);
36 void updateAnimation(uint64_t dt);
37 void tick(uint64_t dt);
39
40 std::string_view tag() const;
41 std::string_view focusName() const;
42 bool checkMobName(std::string_view dest) const;
43 std::string_view ownerName() const;
44
45 bool overrideFocus() const;
46
47 Tempest::Vec3 displayPosition() const;
48 std::string_view displayName() const;
49
50 auto bBox() const -> const Tempest::Vec3*;
51
52 int32_t stateId() const { return state; }
53 int32_t stateCount() const { return stateNum; }
54 bool setMobState(std::string_view scheme,int32_t st) override;
55 void emitTriggerEvent(TriggerEvent::Type type) const;
56 void emitSoundEffect(std::string_view sound, float range, bool freeSlot);
57 std::string_view schemeName() const;
58 std::string_view posSchemeName() const;
59
60 bool isContainer() const;
61 bool isDoor() const;
62 bool isTrueDoor(const Npc& npc) const;
63 bool isLadder() const;
64 std::string_view pickLockCode() const { return pickLockStr; }
65 void setAsCracked(bool c) { isLockCracked = c; }
66 bool isCracked() const { return isLockCracked; }
67 bool needToLockpick(const Npc& pl) const;
68
70 void setSlotItem(MeshObjects::Mesh&& itm, std::string_view slot);
71
72 uint32_t stateMask() const;
73
74 bool canSeeNpc(const Npc &npc, bool freeLos) const;
75 Tempest::Vec3 nearestPoint(const Npc& to) const;
76
77 bool isAvailable() const;
78 bool isStaticState() const;
79 bool isDetachState(const Npc& npc) const;
80 bool canQuitAtState(const Npc& npc, int32_t state) const;
81 bool attach (Npc& npc);
82 bool detach(Npc& npc,bool quick);
83 bool isAttached(const Npc& to);
84
85 auto animNpc(const AnimationSolver &solver, Anim t) const -> const Animation::Sequence*;
86 void marchInteractives(DbgPainter& p) const;
87
88 protected:
89 Tempest::Matrix4x4 nodeTranform(std::string_view nodeName) const;
90 void moveEvent() override;
91 float extendedSearchRadius() const override;
92 virtual void onStateChanged(){}
93
94 private:
95 enum Phase : uint8_t {
96 NotStarted = 0,
97 Started = 1,
98 Quit = 2,
99 };
100
101 struct Pos final {
102 std::string name;
103 Npc* user = nullptr;
104 Phase started = NotStarted;
105 bool attachMode = false;
106
107 size_t node=0;
108 Tempest::Matrix4x4 pos;
109
110 std::string_view posTag() const;
111 bool isAttachPoint() const;
112 bool isDistPos() const;
113 };
114
115 void setVisual(const zenkit::VirtualObject& vob);
116 void invokeStateFunc(Npc &npc);
117 void implTick(Pos &p);
118 void implQuitInteract(Pos &p);
119 bool setPos(Npc& npc, const Tempest::Vec3& pos);
120 void setDir(Npc& npc,const Tempest::Matrix4x4& mt);
121 bool attach(Npc& npc,Pos& to);
122 void implAddItem(std::string_view name);
123 void autoDetachNpc();
124 void implChState(bool next);
125 bool checkUseConditions(Npc& npc);
126
127 auto setAnim(Anim t) -> const Animation::Sequence*;
128 bool setAnim(Npc* npc, Anim dir);
129 void setState(int st);
130
131 template<class P, class Inter>
132 static P* findNearest(Inter& in, const Npc& to);
133
134 const Pos* findNearest(const Npc& to) const;
135 Pos* findNearest(const Npc& to);
136 const Pos* findFreePos() const;
137 Pos* findFreePos();
138 auto worldPos(const Pos &to) const -> Tempest::Vec3;
139 float qDistTo(const Npc &npc, const Pos &to) const;
140 Tempest::Matrix4x4 nodeTranform(const Npc &npc, const Pos &p) const;
141 auto nodePosition(const Npc &npc, const Pos &p) const -> Tempest::Vec3;
142
143 std::string vobName;
144 std::string focName;
145 std::string mdlVisual;
146 Tempest::Vec3 bbox[2]={};
147 std::string owner;
148 bool focOver=false;
149 bool showVisual=true;
150 Tempest::Vec3 displayOffset;
151 // oCMobInter
152 int stateNum=0;
153 std::string triggerTarget;
154 std::string useWithItem;
155 std::string conditionFunc;
156 std::string onStateFunc;
157 bool rewind = false;
158 // oCMobContainer
159 bool locked=false;
160 std::string keyInstance;
161 std::string pickLockStr;
162 Inventory invent;
163 // oCMobLadder
164 int stepsCount = 0;
165
166 int32_t state = -1;
167 bool reverseState = false;
168 bool loopState = false;
169 bool isLockCracked = false;
170
171 uint64_t waitAnim = 0;
172 bool animChanged = false;
173
174 std::vector<Pos> attPos;
175 PhysicMesh physic;
176
177 ObjVisual visual;
178 };
void postValidate()
bool setMobState(std::string_view scheme, int32_t st) override
bool isDoor() const
bool canSeeNpc(const Npc &npc, bool freeLos) const
float extendedSearchRadius() const override
int32_t stateCount() const
Definition interactive.h:53
std::string_view pickLockCode() const
Definition interactive.h:64
bool isAvailable() const
bool attach(Npc &npc)
std::string_view tag() const
bool checkMobName(std::string_view dest) const
std::string_view ownerName() const
Tempest::Vec3 nearestPoint(const Npc &to) const
std::string_view posSchemeName() const
bool isContainer() const
Tempest::Matrix4x4 nodeTranform(std::string_view nodeName) const
bool canQuitAtState(const Npc &npc, int32_t state) const
bool isLadder() const
bool isDetachState(const Npc &npc) const
virtual void onStateChanged()
Definition interactive.h:92
void tick(uint64_t dt)
void resetPositionToTA(int32_t state)
bool overrideFocus() const
void setSlotItem(MeshObjects::Mesh &&itm, std::string_view slot)
bool isTrueDoor(const Npc &npc) const
void emitSoundEffect(std::string_view sound, float range, bool freeSlot)
void onKeyInput(KeyCodec::Action act)
void emitTriggerEvent(TriggerEvent::Type type) const
bool detach(Npc &npc, bool quick)
uint32_t stateMask() const
bool isCracked() const
Definition interactive.h:66
std::string_view schemeName() const
auto animNpc(const AnimationSolver &solver, Anim t) const -> const Animation::Sequence *
bool isStaticState() const
std::string_view focusName() const
int32_t stateId() const
Definition interactive.h:52
void setAsCracked(bool c)
Definition interactive.h:65
Inventory & inventory()
Tempest::Vec3 displayPosition() const
void load(Serialize &fin) override
bool isAttached(const Npc &to)
void save(Serialize &fout) const override
void updateAnimation(uint64_t dt)
std::string_view displayName() const
void moveEvent() override
bool needToLockpick(const Npc &pl) const
auto bBox() const -> const Tempest::Vec3 *
void marchInteractives(DbgPainter &p) const
Definition npc.h:25
Definition vob.h:11
Flags
Definition vob.h:13
World & world
Definition vob.h:45
Definition world.h:31