本文整理汇总了C++中Inventory类的典型用法代码示例。如果您正苦于以下问题:C++ Inventory类的具体用法?C++ Inventory怎么用?C++ Inventory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Inventory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
int itemNum, quantity;
double cost;
// Create an Inventory object
Inventory item;
cout << "Please enter the following values:" << endl;
cout << "Item Number > ";
cin >> itemNum;
item.setItemNumber(itemNum);
cout << "Quantity > ";
cin >> quantity;
item.setQuantity(quantity);
cout << "Item cost > $";
cin >> cost;
item.setCost(cost);
item.setTotalCost();
system("CLS");
displayInventory(item);
system("PAUSE");
return 0;
}
示例2: execute
// ---------------------------------------------------------
bool LocationCommand::execute()
{
map<Name, const Item *> itemTable = myMap->getItemLocations();
map<Name, const Item *>::iterator iter;
for ( iter = itemTable.begin(); iter != itemTable.end(); ++iter )
{
cout << iter->first << '\t';
if ( iter->second == 0 )
{
Inventory * inv = myAdventurer->getInventory();
if ( inv->hasItem( iter->first ) )
{
cout << "(inventory)" << '\n';
}
else
{
cout << "(unknown)" << '\n';
}
}
else
{
cout << iter->second->getID() << '\n';
}
}
cout << endl;
return true;
}
示例3: sendDetachedInventory
void Server::sendDetachedInventory(const std::string &name, u16 peer_id)
{
if(m_detached_inventories.count(name) == 0){
errorstream<<FUNCTION_NAME<<": \""<<name<<"\" not found"<<std::endl;
return;
}
Inventory *inv = m_detached_inventories[name];
std::ostringstream os(std::ios_base::binary);
inv->serialize(os);
MSGPACK_PACKET_INIT(TOCLIENT_DETACHED_INVENTORY, 2);
PACK(TOCLIENT_DETACHED_INVENTORY_NAME, name);
PACK(TOCLIENT_DETACHED_INVENTORY_DATA, os.str());
if (peer_id != PEER_ID_INEXISTENT)
{
// Send as reliable
m_clients.send(peer_id, 0, buffer, true);
}
else
{
m_clients.sendToAll(0,buffer,true);
}
}
示例4: punch
int punch(v3f dir,
const ToolCapabilities *toolcap,
ServerActiveObject *puncher,
float time_from_last_punch)
{
// Take item into inventory
ItemStack item = createItemStack();
Inventory *inv = puncher->getInventory();
if(inv != NULL)
{
std::string wieldlist = puncher->getWieldList();
ItemStack leftover = inv->addItem(wieldlist, item);
puncher->setInventoryModified();
if(leftover.empty())
{
m_removed = true;
}
else
{
m_itemstring = leftover.getItemString();
m_itemstring_changed = true;
}
}
return 0;
}
示例5: while
bool Inventory::operator==(const Inventory& other) const
{
if (isEmpty() and other.isEmpty())
{ //both are empty, so they are the same
return true;
}
if (isEmpty() or other.isEmpty())
{ //only one is empty, so they are not the same
return false;
}
ConstInventoryIterator other_one = other.getFirst();
const ConstInventoryIterator other_end = other.getEnd();
ConstInventoryIterator self_one = m_Items.begin();
const ConstInventoryIterator self_end = m_Items.end();
while (self_one!=self_end and other_one!=other_end)
{
if (self_one->first!=other_one->first or self_one->second!=other_one->second)
{
return false;
}
++self_one;
++other_one;
}//while
if ((self_one!=self_end) xor (other_one!=other_end))
{
return false;
}
return true;
}
示例6: InventoryL_RemoveItem
static int InventoryL_RemoveItem(lua_State* luaVM)
{
bool success = false;
const int nargs = lua_gettop(luaVM);
Inventory* inv;
if(nargs > 1)
{
inv = luaW_to<Inventory>(luaVM, 1);
switch(nargs)
{
case 2:
{
success = inv->removeItem(lua_tonumber(luaVM, 2));
break;
}
case 3:
{
success = inv->removeItem(lua_tonumber(luaVM, 2), lua_tonumber(luaVM, 3));
break;
}
}
}
lua_pushboolean(luaVM, success);
return 1;
}
示例7: applyMoney
//=============================================================================
//handles the financial side
//
void EntertainerManager::applyMoney(PlayerObject* customer,PlayerObject* designer,int32 amount)
{
int32 amountcash;
int32 amountbank;
int8 sql[1024];
amountcash = amount;
amountbank = 0;
Inventory* inventory = dynamic_cast<Inventory*>(customer->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory));
if(inventory && inventory->getCredits() < amount)
{
// cash alone isnt sufficient
amountcash = inventory->getCredits();
amountbank = (amount - amountcash);
}
EntertainerManagerAsyncContainer* asyncContainer = new EntertainerManagerAsyncContainer(EMQuery_IDFinances,0);
Transaction* mTransaction = mDatabase->startTransaction(this,asyncContainer);
asyncContainer->customer = customer;
asyncContainer->performer = designer;
asyncContainer->amountcash = amountcash;
asyncContainer->amountbank = amountbank;
sprintf(sql,"UPDATE inventories SET credits=credits-%i WHERE id=%"PRIu64"",amountcash, customer->getId()+1);
mTransaction->addQuery(sql);
sprintf(sql,"UPDATE banks SET credits=credits-%i WHERE id=%"PRIu64"",amountbank, customer->getId()+4);
mTransaction->addQuery(sql);
sprintf(sql,"UPDATE banks SET credits=credits+%i WHERE id=%"PRIu64"",amount, designer->getId()+4);
mTransaction->addQuery(sql);
mTransaction->execute();
}
示例8: bagComponents
//=============================================================================
//
// filled components get returned to the inventory
//
//
void CraftingSession::bagComponents(ManufactureSlot* manSlot,uint64 containerId)
{
//add the components back to the inventory (!!!)
manSlot->setFilledType(DST_Empty);
//put them into the inventory no matter what - only alternative might be a crafting stations hopper at one point ??
Inventory* inventory = dynamic_cast<Inventory*>(mOwner->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory));
FilledComponent::iterator compIt = manSlot->mUsedComponentStacks.begin();
while(compIt != manSlot->mUsedComponentStacks.end())
{
Item* filledComponent = dynamic_cast<Item*>((*compIt).first);
if(!filledComponent)
{
return;
}
inventory->addObject(filledComponent);
gMessageLib->sendContainmentMessage(filledComponent->getId(),inventory->getId(),0xffffffff,mOwner);
filledComponent->setParentIdIncDB(inventory->getId());
compIt = manSlot->mUsedComponentStacks.erase(compIt);
continue;
}
manSlot->mUsedComponentStacks.clear();
manSlot->mFilledResources.clear();
}
示例9: SEISCOMP_DEBUG
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool ResponsePolynomial::detachFrom(PublicObject* object) {
if ( object == NULL ) return false;
// check all possible parents
Inventory* inventory = Inventory::Cast(object);
if ( inventory != NULL ) {
// If the object has been added already to the parent locally
// just remove it by pointer
if ( object == parent() )
return inventory->remove(this);
// The object has not been added locally so it must be looked up
else {
ResponsePolynomial* child = inventory->findResponsePolynomial(publicID());
if ( child != NULL )
return inventory->remove(child);
else {
SEISCOMP_DEBUG("ResponsePolynomial::detachFrom(Inventory): responsePolynomial has not been found");
return false;
}
}
}
SEISCOMP_ERROR("ResponsePolynomial::detachFrom(%s) -> wrong class type", object->className());
return false;
}
示例10: DuskLog
bool ContainerRecord::loadFromStream(std::ifstream& inStream)
{
if (!inStream.good())
{
DuskLog() << "ContainerRecord::loadFromStream: ERROR: stream contains errors!\n";
return false;
}
uint32_t len = 0;
inStream.read((char*) &len, sizeof(uint32_t));
if (len != cHeaderCont)
{
DuskLog() << "ContainerRecord::loadFromStream: ERROR: stream contains unexpected header!\n";
return false;
}
char ID_Buffer[256];
memset(ID_Buffer, 0, 256);
//read ID
len = 0;
inStream.read((char*) &len, sizeof(uint32_t));
if (len>255)
{
DuskLog() << "ContainerRecord::loadFromStream: ERROR: ID is "
<< "longer than 255 characters!\n";
return false;
}
inStream.read(ID_Buffer, len);
if (!inStream.good())
{
DuskLog() << "ContainerRecord::loadFromStream: ERROR while "
<< "reading ID from stream!\n";
return false;
}
//read Mesh
char Mesh_Buffer[256];
memset(Mesh_Buffer, 0, 256);
len = 0;
inStream.read((char*) &len, sizeof(uint32_t));
if (len>255)
{
DuskLog() << "ContainerRecord::loadFromStream: ERROR: mesh path "
<< "is longer than 255 characters!\n";
return false;
}
inStream.read(Mesh_Buffer, len);
if (!inStream.good())
{
DuskLog() << "ContainerRecord::loadFromStream: ERROR while "
<< "reading mesh path from stream!\n";
return false;
}
Inventory temp;
if (!temp.loadFromStream(inStream))
{
DuskLog() << "ContainerRecord::loadFromStream: ERROR while "
<< "reading inventory contens from stream!\n";
return false;
}
//all right so far
return inStream.good();
}
示例11: draw_player_inventory
static void draw_player_inventory(GameState* gs, Inventory& inv,
const BBox& bbox, int min_slot, int max_slot, int slot_selected = -1) {
int mx = gs->mouse_x(), my = gs->mouse_y();
int slot = min_slot;
for (int y = bbox.y1; y < bbox.y2; y += TILE_SIZE) {
for (int x = bbox.x1; x < bbox.x2; x += TILE_SIZE) {
if (slot >= max_slot)
break;
ItemSlot& itemslot = inv.get(slot);
BBox slotbox(x, y, x + TILE_SIZE, y + TILE_SIZE);
Colour outline(COL_UNFILLED_OUTLINE);
if (itemslot.amount > 0 && slot != slot_selected) {
outline = COL_FILLED_OUTLINE;
if (slotbox.contains(mx, my)) {
outline = COL_PALE_YELLOW;
draw_console_item_description(gs, itemslot.item);
}
}
if (slot != slot_selected)
draw_player_inventory_slot(gs, itemslot, x, y);
//draw rectangle over item edges
gl_draw_rectangle_outline(slotbox, outline);
slot++;
}
}
if (slot_selected != -1) {
draw_player_inventory_slot(gs, inv.get(slot_selected),
gs->mouse_x() - TILE_SIZE / 2, gs->mouse_y() - TILE_SIZE / 2);
}
}
示例12: swap_callback
bool UiBarter::SwapFunctor(InventoryObject* object, Inventory& from, Inventory& to)
{
if (from.IncludesObject(object))
{
string object_name = object->GetName();
function<void (unsigned short)> swap_callback([this, &from, &to, object_name](unsigned short quantity)
{
while (quantity--)
{
InventoryObject* swapping = from.GetObject(object_name);
to.AddObject(swapping);
from.DelObject(swapping);
}
Update();
if (_quantity_picker)
_quantity_picker->SetModal(false);
});
if (from.ContainsHowMany(object->GetName()) > 1)
{
if (_quantity_picker) delete _quantity_picker;
_quantity_picker = new UiObjectQuantityPicker(window, context, from, object);
_quantity_picker->SetModal(true);
_quantity_picker->QuantityPicked.Connect(swap_callback);
_quantity_picker->Observer.Connect(VisibilityToggledOff, *_quantity_picker, &UiBase::Hide);
}
else
swap_callback(1);
return (true);
}
return (false);
}
示例13: ItemInHandRenderer_render_hook
static void ItemInHandRenderer_render_hook(ItemInHandRenderer* renderer, float partialTicks) {
// call the actual Minecraft method first to render the right hand
ItemInHandRenderer_render_real(renderer, partialTicks);
// store the current camera position
MatrixStack::Ref matref = MatrixStack::World.push();
// move the camera 1 units to the left
Vec3 oneleft {-1.0f, 0.0f, 0.0f};
matref.matrix->translate(oneleft);
uintptr_t playerPtr = *((uintptr_t*) ((uintptr_t) renderer->minecraft + MINECRAFT_LOCAL_PLAYER_OFFSET));
Inventory* inventory = *((Inventory**) (playerPtr + PLAYER_INVENTORY_OFFSET));
// save the current active slot
ItemInstance backup(renderer->currentItem);
// change the active slot to the item held in slot 1
renderer->currentItem.cloneSafe(inventory->getLinked(1));
// and call the actual ItemInHandRenderer method in MCPE again
ItemInHandRenderer_render_real(renderer, partialTicks);
// restore active slot
renderer->currentItem.cloneSafe(&backup);
// restore
// MatrixStack::View.pop();
// the MatrixStack::Ref auto pops
}
示例14: BOOST_FIXTURE_TEST_CASE
BOOST_FIXTURE_TEST_CASE(MetalWorkerOrders, WorldWithGCExecution1P)
{
Inventory inv;
inv.Add(GD_BOARDS, 10);
inv.Add(GD_IRON, 10);
world.GetSpecObj<nobBaseWarehouse>(hqPos)->AddGoods(inv, true);
ggs.setSelection(AddonId::METALWORKSBEHAVIORONZERO, 1);
ggs.setSelection(AddonId::TOOL_ORDERING, 1);
ToolSettings settings;
std::fill(settings.begin(), settings.end(), 0);
this->ChangeTools(settings);
MapPoint housePos(hqPos.x + 3, hqPos.y);
const nobUsual* mw = static_cast<nobUsual*>(BuildingFactory::CreateBuilding(world, BLD_METALWORKS, housePos, curPlayer, NAT_ROMANS));
MapPoint flagPos = world.GetNeighbour(hqPos, Direction::SOUTHEAST);
this->BuildRoad(flagPos, false, std::vector<Direction>(3, Direction::EAST));
RTTR_EXEC_TILL(200, mw->HasWorker());
BOOST_REQUIRE(!mw->is_working);
// Wait till he has all the wares
RTTR_EXEC_TILL(3000, mw->GetNumWares(0) == 6);
RTTR_EXEC_TILL(3000, mw->GetNumWares(1) == 6);
// No order -> not working
BOOST_REQUIRE(!mw->is_working);
std::array<int8_t, NUM_TOOLS> orders;
std::fill(orders.begin(), orders.end(), 0);
orders[0] = 1;
this->ChangeTools(settings, &orders.front());
RTTR_EXEC_TILL(1300, mw->is_working);
}
示例15: main
int main(int argc, const char *argv[])
{
Inventory inventory;
GuitarSpec whatErinLikes = GuitarSpec(GBuilder::FENDER, "Stratocastor",
GType::ELECTRIC, GWood::ALDER, GWood::ALDER);
//add a guitar
GuitarSpec newspec = GuitarSpec(GBuilder::FENDER, "Stratocastor",
GType::ELECTRIC, GWood::ALDER, GWood::ALDER);
inventory.addGuitar("V95693", 1499.95, newspec) ;
inventory.addGuitar("V9512", 1549.95, newspec) ;
try{
list<Guitar> guitars = inventory.search(whatErinLikes);
cout << "Erin, you might like these guitars:" << endl;
for ( list<Guitar >::const_iterator i = guitars.begin(); i != guitars.end(); i++){
GuitarSpec spec = i->getSpec();
cout <<" We have a " << spec.getBuilder()
<<" " << spec.getModel()
<<" " << spec.getType() << " guitar:" << endl
<<" " << spec.getBackWood() << " back and sides," << endl
<<" " << spec.getTopWood() << " top.\n You can have it for only $"
<< i->getPrice() << "!\n ----" << endl;
}
}
catch(InventoryException &ie) {
cout << "Sorry, Erin, we have nothing for you." << endl;
}
return 0;
}