コード例 #1
0
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);
}
コード例 #2
0
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]]);
}
コード例 #3
0
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);
            gwg->AddFigure(worker, pos);
            inventory.visual.Remove(ConvertShields(ware->type));
            worker->WalkToGoal();
            ware->Carry(GetFlag());
            waiting_wares.pop_front();
        } else
        {
            // Kein Platz mehr für Waren --> keiner brauch mehr rauszukommen, und Figuren gibts ja auch keine mehr
            go_out = false;
        }
    }

    // Wenn keine Figuren und Waren mehr da sind (bzw die Flagge vorm Haus voll ist), brauch auch keiner mehr rauszukommen
    if(leave_house.empty() && waiting_wares.empty())
        go_out = false;

    if(go_out)
        leaving_event = em->AddEvent(this, LEAVE_INTERVAL + RANDOM.Rand(__FILE__, __LINE__, GetObjId(), LEAVE_INTERVAL_RAND));
}
コード例 #4
0
ファイル: Inventory.cpp プロジェクト: 4ian/GD
 * @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);