Pol  Revision:cb584c9
boatmod.cpp
Go to the documentation of this file.
1 
10 #include "boatmod.h"
11 
12 #include <stddef.h>
13 
14 #include "../../bscript/berror.h"
15 #include "../../clib/rawtypes.h"
16 #include "../multi/boat.h"
17 #include "../multi/multi.h"
18 #include "../realms/realm.h"
19 #include "../uconst.h"
20 #include "../uoexhelp.h"
21 
22 namespace Pol
23 {
24 namespace Bscript
25 {
26 using namespace Module;
27 template <>
30  {"MoveBoat", &UBoatExecutorModule::mf_MoveBoat},
31  {"MoveBoatRelative", &UBoatExecutorModule::mf_MoveBoatRelative},
32  {"MoveBoatXY", &UBoatExecutorModule::mf_MoveBoatXY},
33  {"TurnBoat", &UBoatExecutorModule::mf_TurnBoat},
34  {"RegisterItemWithBoat", &UBoatExecutorModule::mf_RegisterItemWithBoat},
35  {"BoatFromItem", &UBoatExecutorModule::mf_BoatFromItem},
36  {"SystemFindBoatBySerial", &UBoatExecutorModule::mf_SystemFindBoatBySerial}};
37 }
38 namespace Module
39 {
41  : Bscript::TmplExecutorModule<UBoatExecutorModule>( "boat", exec )
42 {
43 }
44 
46 {
47  Multi::UBoat* boat = nullptr;
48  int direction, speed;
49  if ( getUBoatParam( exec, 0, boat ) && getParam( 1, direction, 0, 7 ) &&
50  getParam( 2, speed, 1, 4 ) )
51  {
52  Core::UFACING move_dir = static_cast<Core::UFACING>( direction & 7 );
53  boat->move( move_dir, static_cast<u8>( speed ), false );
54  return new Bscript::BLong( 1 );
55  }
56  return nullptr;
57 }
58 
60 {
61  Multi::UBoat* boat = nullptr;
62  unsigned short x, y;
63  if ( getUBoatParam( exec, 0, boat ) &&
64  getParam( 1, x, 0, static_cast<u16>( boat->realm->width() ) ) &&
65  getParam( 2, y, 0, static_cast<u16>( boat->realm->height() ) ) )
66  {
67  return new Bscript::BLong( boat->move_xy( x, y, 0, boat->realm ) );
68  }
69  else
70  {
71  return new Bscript::BError( "Invalid Parameter type" );
72  }
73 }
74 
76 {
77  Multi::UBoat* boat = nullptr;
78  int relative_dir;
79  if ( getUBoatParam( exec, 0, boat ) && getParam( 1, relative_dir ) )
80  {
81  relative_dir &= 3;
82  return new Bscript::BLong(
83  boat->turn( static_cast<Multi::UBoat::RELATIVE_DIR>( relative_dir ) ) );
84  }
85  else
86  {
87  return new Bscript::BError( "Invalid Parameter type" );
88  }
89 }
90 
92 {
93  Multi::UBoat* boat = nullptr;
94  int direction, speed;
95  if ( getUBoatParam( exec, 0, boat ) && getParam( 1, direction, 0, 7 ) &&
96  getParam( 2, speed, 1, 4 ) )
97  {
98  Core::UFACING move_dir = static_cast<Core::UFACING>( direction & 7 );
99  boat->move( move_dir, static_cast<u8>( speed ), true );
100  return new Bscript::BLong( 1 );
101  }
102  return nullptr;
103 }
104 
106 {
107  Multi::UBoat* boat = nullptr;
108  Core::UObject* obj = nullptr;
109  if ( getUBoatParam( exec, 0, boat ) && getUObjectParam( exec, 1, obj ) )
110  {
111  boat->register_object( obj );
112  return new Bscript::BLong( 1 );
113  }
114  return nullptr;
115 }
116 
118 {
119  Multi::UBoat* boat = nullptr;
120  if ( getUBoatParam( exec, 0, boat ) )
121  {
122  return boat->make_ref();
123  }
124  else
125  {
126  return new Bscript::BError( "Boat not found." );
127  }
128 }
129 
131 {
132  Items::Item* item = nullptr;
133  if ( getItemParam( exec, 0, item ) )
134  {
135  if ( item->ismulti() )
136  {
137  Multi::UMulti* multi = static_cast<Multi::UMulti*>( item );
138  Multi::UBoat* boat = multi->as_boat();
139  if ( boat != nullptr )
140  return boat->make_ref();
141  else
142  return new Bscript::BError( "Multi wasn't a boat" );
143  }
144  else
145  {
146  return new Bscript::BError( "Item wasn't a multi" );
147  }
148  }
149  else
150  {
151  return new Bscript::BError( "Invalid parameter type." );
152  }
153 }
154 }
155 }
bool move(Core::UFACING dir, u8 speed, bool relative)
Definition: boat.cpp:1223
std::vector< FunctionDef > FunctionTable
Definition: execmodl.h:112
Bscript::BObjectImp * mf_SystemFindBoatBySerial()
Definition: boatmod.cpp:117
UBoatExecutorModule(Bscript::Executor &exec)
Definition: boatmod.cpp:40
Bscript::BObjectImp * mf_BoatFromItem()
Definition: boatmod.cpp:130
bool getParam(unsigned param, int &value)
Definition: execmodl.cpp:62
virtual class UBoat * as_boat()
Definition: multis.cpp:51
virtual void register_object(Core::UObject *obj) POL_OVERRIDE
Definition: boat.cpp:1486
virtual Bscript::BObjectImp * make_ref() POL_OVERRIDE
Definition: uoscrobj.cpp:3516
Bscript::BObjectImp * mf_MoveBoat()
Definition: boatmod.cpp:45
Bscript::BObjectImp * mf_MoveBoatXY()
Definition: boatmod.cpp:59
Bscript::BObjectImp * mf_RegisterItemWithBoat()
Definition: boatmod.cpp:105
bool turn(RELATIVE_DIR dir)
Definition: boat.cpp:1455
unsigned short height() const
Definition: realm.h:245
bool getItemParam(Executor &exec, unsigned param, Items::Item *&itemptr)
Definition: uoexhelp.cpp:219
Bscript::BObjectImp * mf_TurnBoat()
Definition: boatmod.cpp:75
bool getUObjectParam(Executor &exec, unsigned param, UObject *&objptr)
Definition: uoexhelp.cpp:369
Realms::Realm * realm
Definition: baseobject.h:56
unsigned short width() const
Definition: realm.h:241
bool ismulti() const
Definition: baseobject.h:114
bool move_xy(unsigned short x, unsigned short y, int flags, Realms::Realm *oldrealm)
Definition: boat.cpp:1187
Definition: berror.cpp:12
bool getUBoatParam(Executor &exec, unsigned param, Multi::UBoat *&boatptr)
Definition: uoexhelp.cpp:262
Bscript::BObjectImp * mf_MoveBoatRelative()
Definition: boatmod.cpp:91