当前位置: 首页>>代码示例>>C++>>正文


C++ Inventory::Add方法代码示例

本文整理汇总了C++中Inventory::Add方法的典型用法代码示例。如果您正苦于以下问题:C++ Inventory::Add方法的具体用法?C++ Inventory::Add怎么用?C++ Inventory::Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Inventory的用法示例。


在下文中一共展示了Inventory::Add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: housePos

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);
}
开发者ID:Return-To-The-Roots,项目名称:s25client,代码行数:28,代码来源:testProduction.cpp

示例2: MapPoint

BOOST_FIXTURE_TEST_CASE(MetalWorkerStopped, WorldWithGCExecution1P)
{
    rttr::test::LogAccessor logAcc;
    ggs.setSelection(AddonId::TOOL_ORDERING, 1);
    ggs.setSelection(AddonId::METALWORKSBEHAVIORONZERO, 1);
    Inventory goods;
    goods.goods[GD_IRON] = 10;
    world.GetSpecObj<nobBaseWarehouse>(hqPos)->AddGoods(goods, true);
    MapPoint bldPos = hqPos + MapPoint(2, 0);
    BuildingFactory::CreateBuilding(world, BLD_METALWORKS, bldPos, curPlayer, NAT_AFRICANS);
    this->BuildRoad(world.GetNeighbour(bldPos, Direction::SOUTHEAST), false, std::vector<Direction>(2, Direction::WEST));
    MapPoint bldPos2 = hqPos - MapPoint(2, 0);
    BuildingFactory::CreateBuilding(world, BLD_METALWORKS, bldPos2, curPlayer, NAT_AFRICANS);
    this->BuildRoad(world.GetNeighbour(bldPos2, Direction::SOUTHEAST), false, std::vector<Direction>(2, Direction::EAST));

    std::array<signed char, NUM_TOOLS> toolOrder;
    ToolSettings toolSettings;
    std::fill(toolOrder.begin(), toolOrder.end(), 0);
    std::fill(toolSettings.begin(), toolSettings.end(), 0);
    this->ChangeTools(toolSettings, toolOrder.data());
    // Get wares and workers in
    RTTR_SKIP_GFS(1000);

    toolOrder[0] = 1;
    toolOrder[1] = 1;
    toolOrder[2] = 1;
    PostBox* postbox = world.GetPostMgr().AddPostBox(0);
    postbox->Clear();
    const Inventory& curInventory = world.GetPlayer(curPlayer).GetInventory();
    Inventory expectedInventory = curInventory;
    expectedInventory.Add(TOOLS[0], toolOrder[0]);
    expectedInventory.Add(TOOLS[1], toolOrder[1]);
    expectedInventory.Add(TOOLS[2], toolOrder[2]);
    // Place order
    this->ChangeTools(toolSettings, toolOrder.data());
    RTTR_REQUIRE_LOG_CONTAINS("Committing an order", true);
    // Wait for completion message
    RTTR_EXEC_TILL(3000, postbox->GetNumMsgs() == 1u);
    BOOST_REQUIRE_EQUAL(postbox->GetMsg(0)->GetCategory(), PostCategory::Economy);
    // Stop it and wait till goods are produced
    this->SetProductionEnabled(bldPos, false);
    this->SetProductionEnabled(bldPos2, false);
    RTTR_EXEC_TILL(2000, curInventory[TOOLS[0]] == expectedInventory[TOOLS[0]] && curInventory[TOOLS[1]] == expectedInventory[TOOLS[1]]
                           && curInventory[TOOLS[2]] == expectedInventory[TOOLS[2]]);
}
开发者ID:Return-To-The-Roots,项目名称:s25client,代码行数:45,代码来源:testProduction.cpp

示例3: HandleLeaveEvent

void nobBaseWarehouse::HandleLeaveEvent()
{
#if RTTR_ENABLE_ASSERTS
    // Harbors have more queues. Ignore for now
    if(GetGOT() != GOT_NOB_HARBORBUILDING)
    {
        Inventory should = inventory.real;
        for(std::list<noFigure*>::iterator it = leave_house.begin(); it != leave_house.end(); ++it)
        {
            // Don't count warehouse workers
            if(!(*it)->MemberOfWarehouse()){
                if((*it)->GetJobType() == JOB_BOATCARRIER)
                    should.Add(JOB_HELPER);
                else
                    should.Add((*it)->GetJobType());
            }
        }
        for(unsigned i = 0; i < JOB_TYPES_COUNT; i++)
            RTTR_Assert(should.people[i] == inventory.visual.people[i]);
    }
#endif

    // Falls eine Bestellung storniert wurde
    if(leave_house.empty() && waiting_wares.empty())
    {
        go_out = false;
        return;
    }

    // Fight or something in front of the house and we are not defending?
    if(!gwg->IsRoadNodeForFigures(gwg->GetNeighbour(pos, 4), 4))
    {
        // there's a fight
        bool found = false;

        // try to find a defender and make him leave the house first
        for(std::list<noFigure*>::iterator it = leave_house.begin(); it != leave_house.end(); ++it)
        {
            if(((*it)->GetGOT() == GOT_NOF_AGGRESSIVEDEFENDER) || ((*it)->GetGOT() == GOT_NOF_DEFENDER))
            {
                // remove defender from list, insert him again in front of all others
                leave_house.push_front(*it);
                leave_house.erase(it);

                found = true;
                break;
            }
        }

        // no defender found? trigger next leaving event :)
        if(!found)
        {
            go_out = false;
            AddLeavingEvent();
            return;
        }
    }

    // Figuren kommen zuerst raus
    if(!leave_house.empty())
    {
        noFigure* fig = leave_house.front();

        gwg->AddFigure(fig, pos);

        // Init road walking for figures walking on roads
        if(fig->IsWalkingOnRoad())
            fig->InitializeRoadWalking(routes[4], 0, true);

        fig->ActAtFirst();
        // Bei Lagerhausarbeitern das nicht abziehen!
        if(!fig->MemberOfWarehouse())
        {
            // War das ein Boot-Träger?
            if(fig->GetJobType() == JOB_BOATCARRIER)
            {
                // Remove helper and boat separately
                inventory.visual.Remove(JOB_HELPER);
                inventory.visual.Remove(GD_BOAT);
            } else
                inventory.visual.Remove(fig->GetJobType());

            if(fig->GetGOT() == GOT_NOF_TRADEDONKEY)
            {
                // Trade donkey carrying wares?
                GoodType carriedWare = static_cast<nofTradeDonkey*>(fig)->GetCarriedWare();
                if(carriedWare != GD_NOTHING)
                    inventory.visual.Remove(carriedWare);
            }
        }

        leave_house.pop_front();
    } else
    {
        // Ist noch Platz an der Flagge?
        if(GetFlag()->GetWareCount() < 8)
        {
            // Dann Ware raustragen lassen
            Ware* ware = waiting_wares.front();
            nofWarehouseWorker* worker = new nofWarehouseWorker(pos, player, ware, 0);
//.........这里部分代码省略.........
开发者ID:jonathan-reisdorf,项目名称:s25client,代码行数:101,代码来源:nobBaseWarehouse.cpp

示例4:

 * @file Tests for the Inventory extension.
 */
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "../Inventory.h"

TEST_CASE( "Inventory", "[game-engine][inventory]" ) {
	SECTION("Inventory") {
		Inventory inventory;

		// Is empty when constructed") {
		REQUIRE(inventory.Has("sword") == false);
		REQUIRE(inventory.Has("soul reaver") == false);

		// Can receive one or more items") {
		REQUIRE(inventory.Add("sword") == true);
		REQUIRE(inventory.Has("sword") == true);
		REQUIRE(inventory.Has("soul reaver") == false);

		REQUIRE(inventory.Add("soul reaver") == true);
		REQUIRE(inventory.Add("sword") == true);
		REQUIRE(inventory.Has("sword") == true);
		REQUIRE(inventory.Has("soul reaver") == true);

		// Can return the number of items") {
		REQUIRE(inventory.Count("sword") == 2);
		REQUIRE(inventory.Count("soul reaver") == 1);

		// Can equip items") {
		REQUIRE(inventory.Equip("soul reaver", true) == true);
		REQUIRE(inventory.IsEquipped("soul reaver") == true);
开发者ID:4ian,项目名称:GD,代码行数:31,代码来源:Inventory.cpp


注:本文中的Inventory::Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。