2016-02-11 22:54:43 +01:00
|
|
|
/** @file
|
|
|
|
|
*
|
|
|
|
|
* @par History
|
|
|
|
|
* - 2006/09/26 Shinigami: GCC 3.4.x fix - added "template<>" to TmplExecutorModule
|
|
|
|
|
* - 2009/09/03 MuadDib: Changes for account related source file relocation
|
|
|
|
|
* Changes for multi related source file relocation
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "boatmod.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include <stddef.h>
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../../bscript/berror.h"
|
2016-02-11 22:54:43 +01:00
|
|
|
#include "../../clib/rawtypes.h"
|
2018-12-21 20:27:05 +01:00
|
|
|
#include "../../plib/uconst.h"
|
2016-12-20 23:53:32 +01:00
|
|
|
#include "../multi/boat.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../multi/multi.h"
|
2016-12-20 23:53:32 +01:00
|
|
|
#include "../realms/realm.h"
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2019-11-10 22:04:08 +01:00
|
|
|
#include <module_defs/boat.h>
|
|
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
namespace Pol
|
|
|
|
|
{
|
|
|
|
|
namespace Module
|
|
|
|
|
{
|
2016-12-14 21:50:23 +01:00
|
|
|
UBoatExecutorModule::UBoatExecutorModule( Bscript::Executor& exec )
|
2020-02-08 09:21:35 +01:00
|
|
|
: Bscript::TmplExecutorModule<UBoatExecutorModule, Core::PolModule>( exec )
|
2016-12-14 21:50:23 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
Bscript::BObjectImp* UBoatExecutorModule::mf_MoveBoat()
|
|
|
|
|
{
|
2018-07-31 14:30:29 +02:00
|
|
|
Multi::UBoat* boat = nullptr;
|
2016-02-19 19:26:35 +01:00
|
|
|
int direction, speed;
|
2021-09-10 20:17:25 +02:00
|
|
|
if ( getUBoatParam( 0, boat ) && getParam( 1, direction, 0, 7 ) && getParam( 2, speed, 1, 4 ) )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
2021-09-11 22:38:43 +02:00
|
|
|
Core::UFACING move_dir = static_cast<Core::UFACING>( direction & 7 );
|
2024-01-10 18:34:40 +08:00
|
|
|
return new Bscript::BLong( boat->move( move_dir, static_cast<u8>( speed ), false ) );
|
2016-02-11 22:54:43 +01:00
|
|
|
}
|
2018-07-31 14:30:29 +02:00
|
|
|
return nullptr;
|
2016-02-19 19:26:35 +01:00
|
|
|
}
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
Bscript::BObjectImp* UBoatExecutorModule::mf_MoveBoatXY()
|
|
|
|
|
{
|
2018-07-31 14:30:29 +02:00
|
|
|
Multi::UBoat* boat = nullptr;
|
2024-07-07 15:32:29 +02:00
|
|
|
Core::Pos2d pos;
|
|
|
|
|
if ( getUBoatParam( 0, boat ) && getPos2dParam( 1, 2, &pos, boat->realm() ) )
|
2024-07-10 19:54:31 +02:00
|
|
|
return new Bscript::BLong( boat->move_to( Core::Pos4d( pos, boat->z(), boat->realm() ), 0 ) );
|
2024-07-07 15:32:29 +02:00
|
|
|
return new Bscript::BError( "Invalid Parameter type" );
|
2016-02-19 19:26:35 +01:00
|
|
|
}
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
Bscript::BObjectImp* UBoatExecutorModule::mf_TurnBoat()
|
|
|
|
|
{
|
2018-07-31 14:30:29 +02:00
|
|
|
Multi::UBoat* boat = nullptr;
|
2016-02-19 19:26:35 +01:00
|
|
|
int relative_dir;
|
2020-02-08 09:21:35 +01:00
|
|
|
if ( getUBoatParam( 0, boat ) && getParam( 1, relative_dir ) )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
|
|
|
|
relative_dir &= 3;
|
|
|
|
|
return new Bscript::BLong(
|
|
|
|
|
boat->turn( static_cast<Multi::UBoat::RELATIVE_DIR>( relative_dir ) ) );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new Bscript::BError( "Invalid Parameter type" );
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
Bscript::BObjectImp* UBoatExecutorModule::mf_MoveBoatRelative()
|
|
|
|
|
{
|
2018-07-31 14:30:29 +02:00
|
|
|
Multi::UBoat* boat = nullptr;
|
2016-02-19 19:26:35 +01:00
|
|
|
int direction, speed;
|
2021-09-10 20:17:25 +02:00
|
|
|
if ( getUBoatParam( 0, boat ) && getParam( 1, direction, 0, 7 ) && getParam( 2, speed, 1, 4 ) )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
2021-09-11 22:38:43 +02:00
|
|
|
Core::UFACING move_dir = static_cast<Core::UFACING>( direction & 7 );
|
2024-01-10 18:34:40 +08:00
|
|
|
return new Bscript::BLong( boat->move( move_dir, static_cast<u8>( speed ), true ) );
|
2016-02-19 19:26:35 +01:00
|
|
|
}
|
2018-07-31 14:30:29 +02:00
|
|
|
return nullptr;
|
2016-02-19 19:26:35 +01:00
|
|
|
}
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
Bscript::BObjectImp* UBoatExecutorModule::mf_RegisterItemWithBoat()
|
|
|
|
|
{
|
2018-07-31 14:30:29 +02:00
|
|
|
Multi::UBoat* boat = nullptr;
|
|
|
|
|
Core::UObject* obj = nullptr;
|
2020-02-08 09:21:35 +01:00
|
|
|
if ( getUBoatParam( 0, boat ) && getUObjectParam( 1, obj ) )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
|
|
|
|
boat->register_object( obj );
|
|
|
|
|
return new Bscript::BLong( 1 );
|
|
|
|
|
}
|
2018-07-31 14:30:29 +02:00
|
|
|
return nullptr;
|
2016-02-19 19:26:35 +01:00
|
|
|
}
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
Bscript::BObjectImp* UBoatExecutorModule::mf_SystemFindBoatBySerial()
|
|
|
|
|
{
|
2018-07-31 14:30:29 +02:00
|
|
|
Multi::UBoat* boat = nullptr;
|
2020-02-08 09:21:35 +01:00
|
|
|
if ( getUBoatParam( 0, boat ) )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
|
|
|
|
return boat->make_ref();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new Bscript::BError( "Boat not found." );
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
Bscript::BObjectImp* UBoatExecutorModule::mf_BoatFromItem()
|
|
|
|
|
{
|
2018-07-31 14:30:29 +02:00
|
|
|
Items::Item* item = nullptr;
|
2020-02-08 09:21:35 +01:00
|
|
|
if ( getItemParam( 0, item ) )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
|
|
|
|
if ( item->ismulti() )
|
|
|
|
|
{
|
|
|
|
|
Multi::UMulti* multi = static_cast<Multi::UMulti*>( item );
|
|
|
|
|
Multi::UBoat* boat = multi->as_boat();
|
2018-07-31 14:30:29 +02:00
|
|
|
if ( boat != nullptr )
|
2016-02-19 19:26:35 +01:00
|
|
|
return boat->make_ref();
|
|
|
|
|
else
|
|
|
|
|
return new Bscript::BError( "Multi wasn't a boat" );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new Bscript::BError( "Item wasn't a multi" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new Bscript::BError( "Invalid parameter type." );
|
2016-02-11 22:54:43 +01:00
|
|
|
}
|
2016-02-19 19:26:35 +01:00
|
|
|
}
|
2018-12-21 20:27:05 +01:00
|
|
|
} // namespace Module
|
|
|
|
|
} // namespace Pol
|