Pol  Revision:3cfda13
boat.h
Go to the documentation of this file.
1 
10 #ifndef BOAT_H
11 #define BOAT_H
12 
13 #include <climits>
14 #include <stddef.h>
15 #include <string>
16 #include <vector>
17 
18 #include "../../bscript/bobject.h"
19 #include "../../clib/compilerspecifics.h"
20 #include "../../clib/rawtypes.h"
21 #include "../poltype.h"
22 #include "../reftypes.h"
23 #include "../uconst.h"
24 #include "multi.h"
25 
26 namespace Pol
27 {
28 namespace Bscript
29 {
30 class Executor;
31 } // namespace Bscript
32 namespace Clib
33 {
34 class ConfigElem;
35 class StreamWriter;
36 } // namespace Clib
37 namespace Core
38 {
39 class UObject;
40 } // namespace Core
41 namespace Items
42 {
43 class Item;
44 class ItemDesc;
45 } // namespace Items
46 namespace Mobile
47 {
48 class Character;
49 } // namespace Mobile
50 namespace Network
51 {
52 class Client;
53 } // namespace Network
54 } // namespace Pol
55 
56 namespace Pol
57 {
58 namespace Bscript
59 {
60 class BObjectImp;
61 }
62 namespace Realms
63 {
64 class Realm;
65 }
66 namespace Module
67 {
68 class EUBoatRefObjImp;
69 }
70 namespace Multi
71 {
72 class MultiDef;
73 
74 struct BoatShape
75 {
77  {
78  unsigned int objtype;
79  unsigned short graphic;
80  unsigned short altgraphic;
81  unsigned short xdelta;
82  unsigned short ydelta;
83  signed short zdelta;
84  ComponentShape( const std::string& str, const std::string& altstr, unsigned char type );
85  ComponentShape( const std::string& str, unsigned char type );
86  };
87  std::vector<ComponentShape> Componentshapes;
88 
89  static bool objtype_is_component( unsigned int objtype );
90  BoatShape( Clib::ConfigElem& elem );
91  BoatShape();
92  size_t estimateSize() const;
93 };
94 
95 
96 class UBoat : public UMulti
97 {
98  typedef UMulti base;
99 
101  {
102  const MultiDef& mdef;
103  unsigned short x;
104  unsigned short y;
105 
106  explicit BoatContext( const UBoat& ub ) : mdef( ub.multidef() ), x( ub.x ), y( ub.y ){};
107  friend class UBoat;
108  BoatContext& operator=( const BoatContext& ) { return *this; }
109  };
110 
111 public:
113  {
115  BoatMoveGuard( UBoat* boat ) : _boat( boat )
116  {
117  if ( boat != nullptr )
118  boat->unregself();
119  };
121  {
122  if ( _boat != nullptr )
123  _boat->regself();
124  };
125  };
126 
127  virtual UBoat* as_boat() POL_OVERRIDE;
128  virtual ~UBoat(){};
129  virtual size_t estimatedSize() const POL_OVERRIDE;
130 
131  bool move( Core::UFACING dir, u8 speed, bool relative );
132  bool move_xy( unsigned short x, unsigned short y, int flags, Realms::Realm* oldrealm );
133 
135  {
139  LEFT
140  };
141  bool turn( RELATIVE_DIR dir );
142 
143  virtual void register_object( Core::UObject* obj ) POL_OVERRIDE;
144  virtual void unregister_object( Core::UObject* obj ) POL_OVERRIDE;
145  Core::UFACING boat_facing() const;
146 
147  void send_smooth_move( Network::Client* client, Core::UFACING move_dir, u8 speed, u16 newx,
148  u16 newy, bool relative );
149  void send_smooth_move_to_inrange( Core::UFACING move_dir, u8 speed, u16 newx, u16 newy,
150  bool relative );
151  void send_display_boat( Network::Client* client );
152  void send_display_boat_to_inrange( u16 oldx = USHRT_MAX, u16 oldy = USHRT_MAX );
153  void send_boat( Network::Client* client );
154  void send_boat_old( Network::Client* client );
155  void send_boat_newly_inrange( Network::Client* client );
156  void send_remove_boat( Network::Client* client );
157 
158  void cleanup_deck();
159  bool hold_empty() const;
160  bool deck_empty() const;
161  bool has_offline_mobiles() const;
162  void remove_orphans();
163  void destroy_components();
164  void regself();
165  void unregself();
166 
167  static Bscript::BObjectImp* scripted_create( const Items::ItemDesc& descriptor, u16 x, u16 y,
168  s8 z, Realms::Realm* realm, int flags );
169 
170  virtual Bscript::BObjectImp* make_ref() POL_OVERRIDE;
171  static bool navigable( const MultiDef&, unsigned short x, unsigned short y, short z,
172  Realms::Realm* realm );
173  void realm_changed();
174  void adjust_traveller_z( s8 delta_z );
175 
176  virtual void on_color_changed() POL_OVERRIDE;
177 
178 
179  // Should these be arrays instead to support customizable boats with certain component choises ?
180  Items::Item* tillerman;
181  Items::Item* portplank;
182  Items::Item* starboardplank;
183  Items::Item* hold;
184 
185 protected:
186  void move_travellers( enum Core::UFACING move_dir, const BoatContext& oldlocation,
187  unsigned short x = USHRT_MAX, unsigned short y = USHRT_MAX,
188  Realms::Realm* oldrealm = NULL );
189  void turn_travellers( RELATIVE_DIR dir, const BoatContext& oldlocation );
190  void turn_traveller_coords( Mobile::Character* chr, RELATIVE_DIR dir );
191  static bool on_ship( const BoatContext& bc, const Core::UObject* obj );
192  void move_offline_mobiles( Core::xcoord new_x, Core::ycoord new_y, Core::zcoord new_z,
193  Realms::Realm* new_realm );
194  const MultiDef& multi_ifturn( RELATIVE_DIR dir );
195  unsigned short multiid_ifturn( RELATIVE_DIR dir );
196 
197 
198  void do_tellmoves();
199  const BoatShape& boatshape() const;
200  void rescan_components();
201  void reread_components();
202  void transform_components( const BoatShape& old_boatshape, Realms::Realm* oldrealm );
203  void move_components( Realms::Realm* oldrealm );
204 
205  explicit UBoat( const Items::ItemDesc& descriptor );
206  virtual void fixInvalidGraphic() POL_OVERRIDE;
207  virtual void readProperties( Clib::ConfigElem& elem ) POL_OVERRIDE;
208  virtual void printProperties( Clib::StreamWriter& sw ) const POL_OVERRIDE;
209  friend class UMulti;
210 
211  virtual Bscript::BObjectImp* get_script_member( const char* membername ) const POL_OVERRIDE;
212  virtual Bscript::BObjectImp* get_script_member_id( const int id ) const POL_OVERRIDE;
213  virtual Bscript::BObjectImp* script_method( const char* methodname,
214  Bscript::Executor& ex ) POL_OVERRIDE;
215  virtual Bscript::BObjectImp* script_method_id( const int id, Bscript::Executor& ex ) POL_OVERRIDE;
216  virtual bool script_isa( unsigned isatype ) const POL_OVERRIDE;
217  Bscript::BObjectImp* items_list() const;
218  Bscript::BObjectImp* mobiles_list() const;
219  Bscript::BObjectImp* component_list( unsigned char type ) const;
220 
221  friend class Module::EUBoatRefObjImp;
222  friend struct BoatMoveGuard;
223 
224 private:
225  void create_components();
226  typedef Core::UObjectRef Traveller;
227  typedef std::vector<Traveller> Travellers;
228  Travellers travellers_;
229 
230  // Components are not removed from the list when destroyed by the core,
231  // so you should always check if the component is an orphan.
232  typedef Core::ItemRef Component;
233  std::vector<Component> Components;
234 };
235 
237 {
251 };
252 
254 unsigned int get_component_objtype( unsigned char type );
255 bool BoatShapeExists( u16 multiid );
256 void clean_boatshapes();
257 }
258 }
259 #endif
unsigned char u8
Definition: rawtypes.h:25
UMulti base
Definition: boat.h:98
#define POL_OVERRIDE
std::vector< Traveller > Travellers
Definition: boat.h:227
BoatContext & operator=(const BoatContext &)
Definition: boat.h:108
short zcoord
Definition: poltype.h:21
unsigned short ycoord
Definition: poltype.h:20
bool BoatShapeExists(u16 multiid)
Definition: boat.cpp:276
std::vector< ComponentShape > Componentshapes
Definition: boat.h:87
STL namespace.
void unregself()
Definition: boat.cpp:624
void clean_boatshapes()
Definition: boat.cpp:264
void regself()
Definition: boat.cpp:610
const MultiDef & mdef
Definition: boat.h:102
unsigned short u16
Definition: rawtypes.h:26
unsigned int get_component_objtype(unsigned char type)
Definition: boat.cpp:211
BoatMoveGuard(UBoat *boat)
Definition: boat.h:115
signed char s8
Definition: rawtypes.h:29
Core::ItemRef Component
Definition: boat.h:232
ref_ptr< Items::Item > ItemRef
Definition: reftypes.h:43
virtual ~UBoat()
Definition: boat.h:128
BOAT_COMPONENT
Definition: boat.h:236
Definition: berror.cpp:12
Bscript::BObjectImp * destroy_boat(UBoat *boat)
Definition: boat.cpp:1807
unsigned short xcoord
Definition: poltype.h:19