Pol  Revision:4b29d2b
npc.h
Go to the documentation of this file.
1 
13 #ifndef H_NPC_H
14 #define H_NPC_H
15 
16 #ifndef __CHARACTR_H
17 #include "charactr.h"
18 #endif
19 
20 #ifndef ARMOR_H
21 #include "../item/armor.h"
22 #endif
23 
24 #include <iosfwd>
25 #include <map>
26 #include <stddef.h>
27 #include <string>
28 
29 #include "../../bscript/bobject.h"
30 #include "../../clib/boostutils.h"
31 #include "../../clib/compilerspecifics.h"
32 #include "../../clib/rawtypes.h"
33 #include "../dynproperties.h"
34 #include "../eventid.h"
35 #include "../item/weapon.h"
36 #include "../npctmpl.h"
37 #include "../reftypes.h"
38 #include "../uconst.h"
39 
40 namespace Pol
41 {
42 namespace Bscript
43 {
44 class Executor;
45 } // namespace Bscript
46 namespace Clib
47 {
48 class StreamWriter;
49 } // namespace Clib
50 namespace Items
51 {
52 class Item;
53 } // namespace Items
54 } // namespace Pol
55 template <class T>
56 class ref_ptr;
57 
58 namespace Pol
59 {
60 namespace Clib
61 {
62 class ConfigElem;
63 }
64 namespace Module
65 {
66 class NPCExecutorModule;
67 }
68 namespace Core
69 {
70 class RepSystem;
71 class UOExecutor;
72 }
73 namespace Mobile
74 {
75 struct Anchor
76 {
77  Anchor() : enabled( false ), x( 0 ), y( 0 ), dstart( 0 ), psub( 0 ){};
78  bool enabled;
79  unsigned short x;
80  unsigned short y;
81  unsigned short dstart;
82  unsigned short psub;
83 };
84 
85 class NPC : public Character
86 {
87  typedef Character base;
88 
89 public:
90  explicit NPC( u32 objtype, const Clib::ConfigElem& elem );
91  virtual ~NPC();
92 
93 private: // not implemented
94  NPC( const NPC& npc );
95  NPC& operator=( const NPC& npc );
96 
97  // UOBJECT INTERFACE
98 public:
99  virtual size_t estimatedSize() const POL_OVERRIDE;
100 
101  virtual void destroy() POL_OVERRIDE;
102 
103  virtual void readProperties( Clib::ConfigElem& elem ) POL_OVERRIDE;
104 
105  virtual Bscript::BObjectImp* get_script_member( const char* membername ) const POL_OVERRIDE;
106  virtual Bscript::BObjectImp* get_script_member_id( const int id ) const POL_OVERRIDE;
107  virtual Bscript::BObjectImp* set_script_member( const char* membername, int value ) POL_OVERRIDE;
108  virtual Bscript::BObjectImp* set_script_member( const char* membername,
109  const std::string& ) POL_OVERRIDE;
110  virtual Bscript::BObjectImp* set_script_member_id( const int id,
111  int value ) POL_OVERRIDE; // id test
112  virtual Bscript::BObjectImp* set_script_member_id( const int id,
113  const std::string& ) POL_OVERRIDE; // id test
114  virtual Bscript::BObjectImp* script_method( const char* methodname,
115  Bscript::Executor& ex ) POL_OVERRIDE;
116  virtual Bscript::BObjectImp* script_method_id( const int id, Bscript::Executor& ex ) POL_OVERRIDE;
117  virtual Bscript::BObjectImp* custom_script_method( const char* methodname,
118  Bscript::Executor& ex ) POL_OVERRIDE;
119  virtual bool script_isa( unsigned isatype ) const POL_OVERRIDE;
120 
121 protected:
122  virtual const char* classname() const POL_OVERRIDE;
123  virtual void printOn( Clib::StreamWriter& sw ) const POL_OVERRIDE;
124  virtual void printSelfOn( Clib::StreamWriter& sw ) const POL_OVERRIDE;
125  virtual void printProperties( Clib::StreamWriter& sw ) const POL_OVERRIDE;
126  virtual void printDebugProperties( Clib::StreamWriter& sw ) const POL_OVERRIDE;
127 
128  // NPC INTERFACE
129 public:
130  virtual Items::UWeapon* intrinsic_weapon() POL_OVERRIDE;
131 
132  virtual void inform_disengaged( Character* disengaged ) POL_OVERRIDE;
133  virtual void inform_engaged( Character* engaged ) POL_OVERRIDE;
134  virtual void inform_criminal( Character* thecriminal ) POL_OVERRIDE;
135  virtual void inform_leftarea( Character* wholeft ) POL_OVERRIDE;
136  virtual void inform_enteredarea( Character* whoentered ) POL_OVERRIDE;
137  virtual void inform_moved( Character* moved ) POL_OVERRIDE;
138  virtual void inform_imoved( Character* chr ) POL_OVERRIDE;
139  virtual double armor_absorb_damage( double damage ) POL_OVERRIDE;
140  virtual void get_hitscript_params( double damage, Items::UArmor** parmor,
141  unsigned short* rawdamage ) POL_OVERRIDE;
142  virtual unsigned short ar() const POL_OVERRIDE;
143  virtual void refresh_ar() POL_OVERRIDE;
144 
145  virtual void apply_raw_damage_hundredths( unsigned int damage, Character* source,
146  bool userepsys = true,
147  bool send_damage_packet = false ) POL_OVERRIDE;
148  virtual void on_death( Items::Item* corpse ) POL_OVERRIDE;
149 
150  virtual bool can_be_renamed_by( const Character* chr ) const POL_OVERRIDE;
151 
152  virtual void repsys_on_attack( Character* defender ) POL_OVERRIDE;
153  virtual void repsys_on_damage( Character* defender ) POL_OVERRIDE;
154  virtual void repsys_on_help( Character* recipient ) POL_OVERRIDE;
155  virtual unsigned char hilite_color_idx( const Character* seen_by ) const POL_OVERRIDE;
156  virtual unsigned short name_color( const Character* seen_by ) const POL_OVERRIDE;
157 
158 protected:
159  virtual u16 get_damaged_sound() const POL_OVERRIDE;
160  // MOVEMENT
161 public:
162  bool use_adjustments() const;
163  void use_adjustments( bool newvalue );
164  bool could_move( Core::UFACING dir ) const;
165  bool anchor_allows_move( Core::UFACING dir ) const;
166  bool npc_path_blocked( Core::UFACING dir ) const;
167 
168  // EVENTS
169 public:
170  // Speech: ASCII versions
171  void on_pc_spoke( Character* src_chr, const char* speech, u8 texttype );
172  void on_ghost_pc_spoke( Character* src_chr, const char* speech, u8 texttype );
173  // Speech: Unicode (and ASCII) versions
174  void on_pc_spoke( Character* src_chr, const char* speech, u8 texttype, const u16* wspeech,
175  const char lang[4], Bscript::ObjArray* speechtokens = nullptr );
176  void on_ghost_pc_spoke( Character* src_chr, const char* speech, u8 texttype, const u16* wspeech,
177  const char lang[4], Bscript::ObjArray* speechtokens = nullptr );
178  bool can_accept_event( Core::EVENTID eventid );
179  Bscript::BObjectImp* send_event_script( Bscript::BObjectImp* event );
180  bool send_event( Bscript::BObjectImp* event );
181 
182  // SCRIPT
183 public:
184  void restart_script();
185  void start_script();
186 
187 protected:
188  void stop_scripts();
189 
190  // SERIALIZATION
191 public:
192  void readPropertiesForNewNPC( Clib::ConfigElem& elem );
193 
194 private:
195  void readNpcProperties( Clib::ConfigElem& elem );
196  void loadEquipablePropertiesNPC( Clib::ConfigElem& elem );
197  void readNewNpcAttributes( Clib::ConfigElem& elem );
198 
199  // ATTRIBUTES / VITALS
200 private:
201  DYN_PROPERTY( orig_fire_resist, s16, Core::PROP_ORIG_RESIST_FIRE, 0 );
202  DYN_PROPERTY( orig_cold_resist, s16, Core::PROP_ORIG_RESIST_COLD, 0 );
203  DYN_PROPERTY( orig_energy_resist, s16, Core::PROP_ORIG_RESIST_ENERGY, 0 );
204  DYN_PROPERTY( orig_poison_resist, s16, Core::PROP_ORIG_RESIST_POISON, 0 );
205  DYN_PROPERTY( orig_physical_resist, s16, Core::PROP_ORIG_RESIST_PHYSICAL, 0 );
206 
207  DYN_PROPERTY( orig_fire_damage, s16, Core::PROP_ORIG_DAMAGE_FIRE, 0 );
208  DYN_PROPERTY( orig_cold_damage, s16, Core::PROP_ORIG_DAMAGE_COLD, 0 );
209  DYN_PROPERTY( orig_energy_damage, s16, Core::PROP_ORIG_DAMAGE_ENERGY, 0 );
210  DYN_PROPERTY( orig_poison_damage, s16, Core::PROP_ORIG_DAMAGE_POISON, 0 );
211  DYN_PROPERTY( orig_physical_damage, s16, Core::PROP_ORIG_DAMAGE_PHYSICAL, 0 );
212 
213  void resetEquipablePropertiesNPC();
214 
215  // MISC
216 public:
217  Character* master() const;
218  Core::NpcTemplate::ALIGNMENT alignment() const;
219 
220  bool no_drop_exception() const;
221  void no_drop_exception( bool newvalue );
222 
223  std::string templatename() const;
224  // ==========================================================
225  // DATA:
226  // ==========================================================
227  friend class Core::RepSystem;
228  friend class Module::NPCExecutorModule;
229  friend class ref_ptr<NPC>;
230 
231  // UOBJECT INTERFACE
232  // NPC INTERFACE
233 private:
234  unsigned short npc_ar_;
235  // MOVEMENT
236 public:
237  unsigned short run_speed;
238 
239 private:
240  Anchor anchor;
241  // EVENTS
242 private:
243  DYN_PROPERTY( speech_color, u16, Core::PROP_SPEECH_COLOR, Core::DEFAULT_TEXT_COLOR );
244  DYN_PROPERTY( speech_font, u16, Core::PROP_SPEECH_FONT, Core::DEFAULT_TEXT_FONT );
245  // SCRIPT
246 private:
247  boost_utils::script_name_flystring script;
248 
249 protected:
250  Core::UOExecutor* ex;
251  // SERIALIZATION
252  // ATTRIBUTES / VITALS
253  // MISC
254 public:
255  unsigned short damaged_sound;
256 
257 protected:
258  boost_utils::npctemplate_name_flystring template_name;
259 
260 private:
261  Core::CharacterRef master_;
262  const Core::NpcTemplate& template_;
263 };
264 
265 inline Character* NPC::master() const
266 {
267  return master_.get();
268 }
269 
271 {
272  return template_.alignment;
273 }
274 
275 inline unsigned short NPC::ar() const
276 {
277  if ( ar_ == 0 )
278  {
279  if ( shield != nullptr && shield->is_intrinsic() )
280  return npc_ar_ + shield->ar();
281  return npc_ar_;
282  }
283  else
284  return ar_;
285 }
286 }
287 }
288 #endif
unsigned char u8
Definition: rawtypes.h:25
#define POL_OVERRIDE
Character base
Definition: npc.h:87
STL namespace.
const unsigned short DEFAULT_TEXT_COLOR
Definition: uconst.h:97
const unsigned short DEFAULT_TEXT_FONT
Definition: uconst.h:96
unsigned short u16
Definition: rawtypes.h:26
unsigned int u32
Definition: rawtypes.h:27
signed short s16
Definition: rawtypes.h:30
Definition: refptr.h:65
bool enabled
Definition: npc.h:77
ref_ptr< Mobile::Character > CharacterRef
Definition: reftypes.h:42
unsigned short y
Definition: npc.h:80
virtual unsigned short ar() const POL_OVERRIDE
Definition: npc.h:275
boost::flyweight< std::string, boost::flyweights::tag< script_name_tag >, FLYWEIGHT_HASH_FACTORY > script_name_flystring
Definition: boostutils.h:148
unsigned short dstart
Definition: npc.h:81
#define DYN_PROPERTY(name, type, id, defaultvalue)
Definition: dynproperties.h:62
unsigned short psub
Definition: npc.h:82
void start_script(const char *filename, Bscript::BObjectImp *param0, Bscript::BObjectImp *param1)
Definition: scrsched.cpp:150
Core::NpcTemplate::ALIGNMENT alignment() const
Definition: npc.h:270
Definition: berror.cpp:12
boost::flyweight< std::string, boost::flyweights::tag< npctemplate_name_tag >, FLYWEIGHT_HASH_FACTORY > npctemplate_name_flystring
Definition: boostutils.h:154
unsigned short x
Definition: npc.h:79