Pol  Revision:4b29d2b
multis.cpp
Go to the documentation of this file.
1 
9 #include <stddef.h>
10 
11 #include "../../bscript/bobject.h"
12 #include "../../bscript/bstruct.h"
13 #include "../../bscript/objmembers.h"
14 #include "../../clib/logfacility.h"
15 #include "../../clib/passert.h"
16 #include "../baseobject.h"
17 #include "../globals/state.h"
18 #include "../item/item.h"
19 #include "../item/itemdesc.h"
20 #include "../uobjcnt.h"
21 #include "multi.h"
22 #include "multidef.h"
23 
24 namespace Pol
25 {
26 namespace Multi
27 {
28 UMulti::UMulti( const Items::ItemDesc& itemdesc ) : Item( itemdesc, Core::UOBJ_CLASS::CLASS_MULTI )
29 {
30  multiid = itemdesc.multiid;
31 
32  if ( !MultiDefByMultiIDExists( itemdesc.multiid ) )
33  {
34  ERROR_PRINT.Format( "Tried to create a Multi type 0x{:X}\n" ) << itemdesc.objtype;
35  throw std::runtime_error( "Unvalid Multi type" );
36  }
38 }
39 
41 {
43 }
44 
46 {
47  ERROR_PRINT << "Ack! You can't double-click a multi!\n";
48  throw std::runtime_error( "double_click() on a multi should not be possible." );
49 }
50 
52 {
53  return nullptr;
54 }
56 {
57  return nullptr;
58 }
59 
60 void UMulti::register_object( UObject* /*obj*/ ) {}
61 
63 
64 const char* UMulti::classname() const
65 {
66  return "MULTI";
67 }
68 
69 const MultiDef& UMulti::multidef() const
70 {
72 
73  return *MultiDefByMultiID( multiid );
74 }
75 
77 {
78  const MultiDef& md = multidef();
79  std::unique_ptr<Bscript::BStruct> ret( new Bscript::BStruct );
80  ret->addMember( "xmin", new Bscript::BLong( x + md.minrx ) );
81  ret->addMember( "xmax", new Bscript::BLong( x + md.maxrx ) );
82  ret->addMember( "ymin", new Bscript::BLong( y + md.minry ) );
83  ret->addMember( "ymax", new Bscript::BLong( y + md.maxry ) );
84  return ret.release();
85 }
86 
88 {
90  if ( imp )
91  return imp;
92 
93  switch ( id )
94  {
96  return footprint();
97  break;
98  default:
99  return nullptr;
100  }
101 }
102 
103 Bscript::BObjectImp* UMulti::get_script_member( const char* membername ) const
104 {
105  Bscript::ObjMember* objmember = Bscript::getKnownObjMember( membername );
106  if ( objmember != nullptr )
107  return this->get_script_member_id( objmember->id );
108  else
109  return nullptr;
110 }
111 
112 size_t UMulti::estimatedSize() const
113 {
114  return base::estimatedSize() + sizeof( u16 ) /*multiid*/
115  ;
116 }
117 }
118 }
virtual Bscript::BObjectImp * get_script_member(const char *membername) const POL_OVERRIDE
Definition: multis.cpp:103
virtual Bscript::BObjectImp * get_script_member_id(const int id) const POL_OVERRIDE
Definition: uoscrobj.cpp:898
UObject(u32 objtype, UOBJ_CLASS uobj_class)
Definition: uobject.cpp:72
UMulti(const Items::ItemDesc &itemdesc)
Definition: multis.cpp:28
ObjMember * getKnownObjMember(const char *token)
Definition: parser.cpp:483
virtual class UBoat * as_boat()
Definition: multis.cpp:51
virtual void double_click(Network::Client *client) POL_OVERRIDE
Definition: multis.cpp:45
Bscript::BStruct * footprint() const
Definition: multis.cpp:76
virtual void register_object(UObject *obj)
Definition: multis.cpp:60
unsigned short multiid
Definition: itemdesc.h:128
unsigned short u16
Definition: rawtypes.h:26
virtual class UHouse * as_house()
Definition: multis.cpp:55
#define passert(exp)
Definition: passert.h:62
StateManager stateManager
Definition: state.cpp:8
virtual size_t estimatedSize() const POL_OVERRIDE
Definition: item00.cpp:58
virtual Bscript::BObjectImp * get_script_member_id(const int id) const POL_OVERRIDE
id test
Definition: multis.cpp:87
bool MultiDefByMultiIDExists(u16 multiid)
Definition: multidef.cpp:293
virtual ~UMulti()
Definition: multis.cpp:40
virtual size_t estimatedSize() const POL_OVERRIDE
Definition: multis.cpp:112
#define ERROR_PRINT
Definition: logfacility.h:230
const MultiDef & multidef() const
Definition: multis.cpp:69
virtual const char * classname() const POL_OVERRIDE
Definition: multis.cpp:64
virtual void unregister_object(UObject *obj)
Definition: multis.cpp:62
Definition: berror.cpp:12
const MultiDef * MultiDefByMultiID(u16 multiid)
Definition: multidef.cpp:297
UObjCount uobjcount
Definition: state.h:49