2016-01-28 14:52:40 +01:00
|
|
|
/** @file
|
|
|
|
|
*
|
|
|
|
|
* @par History
|
|
|
|
|
* - 2005/11/26 Shinigami: changed "strcmp" into "stricmp" to suppress Script Errors
|
|
|
|
|
* - 2009/09/03 MuadDib: Relocation of multi related cpp/h
|
|
|
|
|
*/
|
2016-02-11 22:54:43 +01:00
|
|
|
|
|
|
|
|
|
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/bobject.h"
|
2016-02-11 22:54:43 +01:00
|
|
|
#include "../../bscript/bstruct.h"
|
2018-10-13 00:03:40 +02:00
|
|
|
#include "../../bscript/executor.h"
|
2016-02-11 22:54:43 +01:00
|
|
|
#include "../../bscript/objmembers.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../../clib/logfacility.h"
|
|
|
|
|
#include "../../clib/passert.h"
|
|
|
|
|
#include "../baseobject.h"
|
2016-02-11 22:54:43 +01:00
|
|
|
#include "../globals/state.h"
|
2018-10-13 00:03:40 +02:00
|
|
|
#include "../globals/uvars.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../item/item.h"
|
|
|
|
|
#include "../item/itemdesc.h"
|
2018-10-13 00:03:40 +02:00
|
|
|
#include "../syshookscript.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../uobjcnt.h"
|
|
|
|
|
#include "multi.h"
|
|
|
|
|
#include "multidef.h"
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
namespace Pol
|
|
|
|
|
{
|
|
|
|
|
namespace Multi
|
|
|
|
|
{
|
2016-12-12 22:21:59 +01:00
|
|
|
UMulti::UMulti( const Items::ItemDesc& itemdesc ) : Item( itemdesc, Core::UOBJ_CLASS::CLASS_MULTI )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
|
|
|
|
multiid = itemdesc.multiid;
|
|
|
|
|
|
|
|
|
|
if ( !MultiDefByMultiIDExists( itemdesc.multiid ) )
|
|
|
|
|
{
|
|
|
|
|
ERROR_PRINT.Format( "Tried to create a Multi type 0x{:X}\n" ) << itemdesc.objtype;
|
|
|
|
|
throw std::runtime_error( "Unvalid Multi type" );
|
2016-02-11 22:54:43 +01:00
|
|
|
}
|
2016-02-19 19:26:35 +01:00
|
|
|
++Core::stateManager.uobjcount.umulti_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UMulti::~UMulti()
|
|
|
|
|
{
|
|
|
|
|
--Core::stateManager.uobjcount.umulti_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UMulti::double_click( Network::Client* /*client*/ )
|
|
|
|
|
{
|
|
|
|
|
ERROR_PRINT << "Ack! You can't double-click a multi!\n";
|
|
|
|
|
throw std::runtime_error( "double_click() on a multi should not be possible." );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UBoat* UMulti::as_boat()
|
|
|
|
|
{
|
2018-07-31 14:30:29 +02:00
|
|
|
return nullptr;
|
2016-02-19 19:26:35 +01:00
|
|
|
}
|
|
|
|
|
UHouse* UMulti::as_house()
|
|
|
|
|
{
|
2018-07-31 14:30:29 +02:00
|
|
|
return nullptr;
|
2016-02-19 19:26:35 +01:00
|
|
|
}
|
|
|
|
|
|
2018-01-29 21:55:48 +01:00
|
|
|
void UMulti::register_object( UObject* /*obj*/ ) {}
|
2016-02-19 19:26:35 +01:00
|
|
|
|
2018-01-29 21:55:48 +01:00
|
|
|
void UMulti::unregister_object( UObject* /*obj*/ ) {}
|
2016-02-19 19:26:35 +01:00
|
|
|
|
|
|
|
|
const char* UMulti::classname() const
|
|
|
|
|
{
|
|
|
|
|
return "MULTI";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const MultiDef& UMulti::multidef() const
|
|
|
|
|
{
|
|
|
|
|
passert( MultiDefByMultiIDExists( multiid ) );
|
|
|
|
|
|
|
|
|
|
return *MultiDefByMultiID( multiid );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Bscript::BStruct* UMulti::footprint() const
|
|
|
|
|
{
|
|
|
|
|
const MultiDef& md = multidef();
|
|
|
|
|
std::unique_ptr<Bscript::BStruct> ret( new Bscript::BStruct );
|
2020-05-31 19:11:42 +02:00
|
|
|
Core::Pos4d minp( pos() + md.min_relp );
|
|
|
|
|
Core::Pos4d maxp( pos() + md.max_relp );
|
2020-04-18 11:57:19 +02:00
|
|
|
ret->addMember( "xmin", new Bscript::BLong( minp.x() ) );
|
|
|
|
|
ret->addMember( "xmax", new Bscript::BLong( maxp.x() ) );
|
|
|
|
|
ret->addMember( "ymin", new Bscript::BLong( minp.y() ) );
|
|
|
|
|
ret->addMember( "ymax", new Bscript::BLong( maxp.y() ) );
|
2016-02-19 19:26:35 +01:00
|
|
|
return ret.release();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Bscript::BObjectImp* UMulti::get_script_member_id( const int id ) const /// id test
|
|
|
|
|
{
|
|
|
|
|
Bscript::BObjectImp* imp = base::get_script_member_id( id );
|
|
|
|
|
if ( imp )
|
|
|
|
|
return imp;
|
|
|
|
|
|
|
|
|
|
switch ( id )
|
|
|
|
|
{
|
|
|
|
|
case Bscript::MBR_FOOTPRINT:
|
|
|
|
|
return footprint();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2018-07-31 14:30:29 +02:00
|
|
|
return nullptr;
|
2016-02-19 19:26:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Bscript::BObjectImp* UMulti::get_script_member( const char* membername ) const
|
|
|
|
|
{
|
|
|
|
|
Bscript::ObjMember* objmember = Bscript::getKnownObjMember( membername );
|
2018-07-31 14:30:29 +02:00
|
|
|
if ( objmember != nullptr )
|
2016-02-19 19:26:35 +01:00
|
|
|
return this->get_script_member_id( objmember->id );
|
|
|
|
|
else
|
2018-07-31 14:30:29 +02:00
|
|
|
return nullptr;
|
2016-02-19 19:26:35 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-13 00:03:40 +02:00
|
|
|
bool UMulti::get_method_hook( const char* methodname, Bscript::Executor* ex,
|
|
|
|
|
Core::ExportScript** hook, unsigned int* PC ) const
|
|
|
|
|
{
|
|
|
|
|
if ( Core::gamestate.system_hooks.get_method_hook(
|
|
|
|
|
Core::gamestate.system_hooks.multi_method_script.get(), methodname, ex, hook, PC ) )
|
|
|
|
|
return true;
|
|
|
|
|
return base::get_method_hook( methodname, ex, hook, PC );
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
size_t UMulti::estimatedSize() const
|
|
|
|
|
{
|
|
|
|
|
return base::estimatedSize() + sizeof( u16 ) /*multiid*/
|
|
|
|
|
;
|
|
|
|
|
}
|
2020-04-18 11:57:19 +02:00
|
|
|
} // namespace Multi
|
|
|
|
|
} // namespace Pol
|