29 #include "../clib/cfgelem.h" 30 #include "../clib/logfacility.h" 31 #include "../clib/passert.h" 32 #include "../clib/random.h" 33 #include "../clib/streamsaver.h" 70 +
sizeof(
unsigned int )
80 Contents::value_type item =
contents_.back();
83 item->container =
nullptr;
114 if ( item !=
nullptr )
116 if ( item->itemdesc().save_on_exit && item->saveonexit() )
141 if (
weight() + weight_diff > USHRT_MAX )
202 contents_.push_back( Contents::value_type( item ) );
212 add_bulk( -static_cast<int>( 1 ), -static_cast<int>( item->
weight() ) );
222 held_weight_ +=
static_cast<unsigned short>( weight_delta );
247 if ( item ==
nullptr )
249 if ( item->slot_index() == slotIndex )
263 bool slot_check =
false;
265 for (
u8 slot_location = 1; slot_location <=
max_items(); ++slot_location )
269 if ( item ==
nullptr )
271 if ( item->slot_index() == slot_location )
280 slotIndex = slot_location;
333 int weight_diff1 = -weight_diff0;
334 int item_count_diff1 = -item_count_diff0;
336 return (
can_add_bulk( 0, item_count_diff0, weight_diff0 ) &&
337 cont.
can_add_bulk( 0, item_count_diff1, weight_diff1 ) );
347 add_bulk( item_count_diff, weight_diff );
348 cont.
add_bulk( -item_count_diff, -weight_diff );
357 if ( item && ( item->script_isa( polclass ) ) )
367 if ( item && ( item->objtype_ == objtype ) )
376 if ( item && ( item->objtype_ == objtype ) && !item->inuse() )
386 if ( item && ( item->objtype_ == objtype ) && ( item->getamount() <= maxamount ) )
392 unsigned short maxamount )
const 396 if ( item && ( item->objtype_ == objtype ) && ( item->getamount() <= maxamount ) &&
414 if ( item && item->can_add_to_self( *adding_item,
false ) )
427 if ( _item !=
nullptr )
439 if ( child_item !=
nullptr )
452 if ( _item !=
nullptr )
463 if ( child_item !=
nullptr )
473 unsigned int amt = 0;
477 if ( item && !item->inuse() )
479 if ( item->objtype_ == objtype )
480 amt += item->getamount();
497 while ( amount != 0 )
502 unsigned short thisamt = item->
getamount();
503 if ( thisamt > amount )
504 thisamt =
static_cast<unsigned short>( amount );
515 item =
find( objserial, itr );
516 if ( item !=
nullptr )
518 if ( found_in !=
nullptr )
530 POLLOG.Format(
"UContainer::remove(Item*), serial=0x{:X}, item=0x{:X}, item->cont=0x{:X}\n" )
543 if ( chr_owner !=
nullptr && chr_owner->client !=
nullptr )
549 if ( chr_owner !=
nullptr && chr_owner->client !=
nullptr )
582 if ( cont->
serial == objserial )
585 if ( cont !=
nullptr )
598 if ( item !=
nullptr )
600 if ( item->
serial == objserial )
602 where_in_container = itr;
610 item = cont->
find( objserial, where_in_container );
611 if ( item !=
nullptr )
625 if ( item !=
nullptr )
627 if ( item->serial == objserial )
635 auto child_item = cont->
find( objserial );
636 if ( child_item !=
nullptr )
650 if ( item !=
nullptr )
652 if ( item->serial == objserial )
788 Items::Item* existing_item,
unsigned short amt_to_add,
806 Items::Item* existing_item,
unsigned short amt_to_add )
853 if ( chr !=
nullptr )
870 if ( has_max_items_mod() )
871 sw() <<
"\tMax_Items_mod\t" << max_items_mod() <<
pf_endl;
872 if ( has_max_weight_mod() )
873 sw() <<
"\tMax_Weight_mod\t" << max_weight_mod() <<
pf_endl;
874 if ( has_max_slots_mod() )
875 sw() <<
"\tMax_Slots_mod\t" << max_slots_mod() <<
pf_endl;
883 max_items_mod( static_cast<s16>( elem.
remove_int(
"MAX_ITEMS_MOD", 0 ) ) );
884 max_weight_mod( static_cast<s16>( elem.
remove_int(
"MAX_WEIGHT_MOD", 0 ) ) );
885 max_slots_mod( static_cast<s8>( elem.
remove_int(
"MAX_SLOTS_MOD", 0 ) ) );
890 Contents& saveItemsTo,
int flags )
const 892 unsigned int amt = 0;
896 if ( item && !item->inuse() )
898 if ( item->objtype_ == objtype )
900 saveItemsTo.push_back( item );
901 amt += item->getamount();
914 if ( amt >= amtToGet )
925 item->max_items_mod( this->max_items_mod() );
926 item->max_weight_mod( this->max_weight_mod() );
927 item->max_slots_mod( this->max_slots_mod() );
944 if ( max_weight < 1 )
946 else if ( max_weight <= USHRT_MAX )
virtual void printProperties(Clib::StreamWriter &sw) const POL_OVERRIDE
virtual void on_insert_add_item(Mobile::Character *mob, MoveType move, Items::Item *new_item)
Contents::const_iterator const_iterator
void on_remove(Mobile::Character *chr, Items::Item *item, MoveType move=MT_PLAYER)
std::vector< Items::Item * > Contents
void enumerate_contents(Bscript::ObjArray *arr, int flags)
const Items::ContainerDesc & desc
unsigned short stack_limit
virtual Items::Item * clone() const POL_OVERRIDE
UContainer * find_container(u32 serial) const
bool can_add_to_slot(u8 &slotIndex)
bool is_legal_posn(const Items::Item *item, u16 x, u16 y) const
unsigned int find_sumof_objtype_noninuse(u32 objtype) const
const int FINDSUBSTANCE_IGNORE_LOCKED
virtual Bscript::BObjectImp * make_ref() POL_OVERRIDE
virtual bool can_add(const Items::Item &item) const
virtual void printProperties(Clib::StreamWriter &sw) const POL_OVERRIDE
void add_item_to_world(Items::Item *item)
virtual void add_bulk(int item_count_delta, int weight_delta)
const int INSERT_ADD_ITEM
void extract(Contents &cnt)
const int INSERT_INCREASE_STACK
Core::ScriptDef on_remove_script
bool is_slot_empty(u8 &slotIndex)
virtual void readProperties(Clib::ConfigElem &elem) POL_OVERRIDE
bool can_add_bulk(int tli_diff, int item_count_diff, int weight_diff) const
Items::Item * find(u32 serial) const
bool get(ENUM flag) const
int remove_int(const char *propname)
virtual void builtin_on_use(Network::Client *client) POL_OVERRIDE
void send_open_gump(Network::Client *client, const UContainer &cont)
virtual void register_object(UObject *obj)
Contents::iterator iterator
virtual void readProperties(Clib::ConfigElem &elem) POL_OVERRIDE
Core::ScriptDef on_insert_script
virtual void add(Items::Item *item)
bool can_swap(const UContainer &cont) const
void swap(UContainer &cont)
void remove_bulk(const Items::Item *item)
virtual Items::Item * remove(u32 serial, UContainer **found_in=nullptr)
#define ITEM_ELEM_PTR(elem)
Items::Item * find_addable_stack(const Items::Item *adding_item) const
void get_random_location(u16 *px, u16 *py) const
bool call_script(const ScriptDef &script, Bscript::BObjectImp *param0)
void destroy_item(Item *item)
AttributeFlags< OBJ_FLAGS > flags_
virtual unsigned int weight() const POL_OVERRIDE
Items::Item * find_toplevel(u32 serial) const
#define MAX_CONTAINER_ITEMS
Core::ScriptDef can_insert_script
const int FINDOBJTYPE_ROOT_ONLY
static UninitObject * create()
unsigned short max_weight() const
virtual void destroy() POL_OVERRIDE
void on_insert_increase_stack(Mobile::Character *mob, MoveType move, Items::Item *existing_item, unsigned short amt_added)
Items::Item * find_toplevel_objtype(u32 objtype) const
virtual Bscript::BObjectImp * make_ref() POL_OVERRIDE
const int FINDSUBSTANCE_FIND_ALL
void add_at_random_location(Items::Item *item)
virtual unsigned int item_count() const
Core::UContainer * container
#define GET_ITEM_PTR(itr)
virtual void printOn(Clib::StreamWriter &sw) const POL_OVERRIDE
void send_remove_object_to_inrange(const UObject *centerObject)
void send_full_statmsg(Network::Client *client, Mobile::Character *chr)
void move_item(Item *item, UFACING facing)
void consume_sumof_objtype_noninuse(u32 objtype, unsigned int amount)
SettingsManager settingsManager
virtual void spill_contents(Multi::UMulti *supporting_multi) POL_OVERRIDE
virtual void printSelfOn(Clib::StreamWriter &sw) const POL_OVERRIDE
StateManager stateManager
virtual unsigned int item_count() const POL_OVERRIDE
unsigned int held_item_count_
Items::Item * find_objtype_noninuse(u32 objtype) const
Items::Item * find_toplevel_objtype_noninuse(u32 objtype) const
void addElement(BObjectImp *imp)
void subtract_amount_from_item(Item *item, unsigned short amount)
bool no_drop_exception() const
UContainer(const Items::ContainerDesc &descriptor)
void send_container_contents(Network::Client *client, const UContainer &cont)
Core::ScriptDef can_remove_script
bool check_can_remove_script(Mobile::Character *chr, Items::Item *item, MoveType move=MT_PLAYER)
virtual void printOn(Clib::StreamWriter &) const
bool can_insert_increase_stack(Mobile::Character *mob, MoveType move, Items::Item *existing_item, unsigned short amt_to_add, Items::Item *adding_item)
bool gflag_enforce_container_limits
bool default_no_drop_exception() const
bool isa(UOBJ_CLASS uobj_class) const
void change(ENUM flag, bool value)
const int FINDOBJTYPE_IGNORE_LOCKED
Items::Item * find_toplevel_polclass(unsigned int polclass) const
Items::Item * find_objtype(u32 objtype, int flags) const
unsigned short max_items() const
const ItemDesc & itemdesc() const
virtual size_t estimatedSize() const POL_OVERRIDE
const ContainerDesc & find_container_desc(u32 objtype)
virtual unsigned int weight() const POL_OVERRIDE
#define passert_always(exp)
const int ENUMERATE_IGNORE_LOCKED
virtual Items::Item * clone() const POL_OVERRIDE
Mobile::Character * GetCharacterOwner()
const int ENUMERATE_ROOT_ONLY
const int FINDSUBSTANCE_ROOT_ONLY
bool find_empty_slot(u8 &slotIndex)
virtual size_t estimatedSize() const POL_OVERRIDE
bool remove_bool(const char *propname)
void send_sysmessage(Network::Client *client, const char *text, unsigned short font, unsigned short color)
virtual void for_each_item(void(*f)(Item *item, void *a), void *arg)
bool can_insert_add_item(Mobile::Character *mob, MoveType move, Items::Item *new_item)
void printContents(Clib::StreamWriter &sw) const
#define INC_PROFILEVAR(counter)