/// Bestellt die zusätzlichen erforderlichen Waren für eine Expedition
void nobHarborBuilding::OrderExpeditionWares()
{
    RTTR_Assert(!IsBeingDestroyedNow()); // Wares should already be canceled!
    if (this->IsBeingDestroyedNow()) // don't order new stuff if we are about to be destroyed
        return;

    if(!expedition.active) //expedition no longer active?
        return;
    // Waren in der Bestellungsliste mit beachten
    unsigned boards = 0, stones = 0;
    for(std::list<Ware*>::iterator it = dependent_wares.begin(); it!=dependent_wares.end(); ++it)
    {
        RTTR_Assert(*it);
        if((*it)->type == GD_BOARDS)
            ++boards;
        if((*it)->type == GD_STONES)
            ++stones;
    }

    // Prüfen, ob jeweils noch weitere Waren bestellt werden müssen
    unsigned todo_boards = 0;
    if(boards + expedition.boards < BUILDING_COSTS[nation][BLD_HARBORBUILDING].boards)
    {
        todo_boards = BUILDING_COSTS[nation][BLD_HARBORBUILDING].boards - (boards + expedition.boards);
        Ware* ware;
        do
        {
            ware = gwg->GetPlayer(player).OrderWare(GD_BOARDS, this);
            if(ware)
            {
                RTTR_Assert(IsWareDependent(ware));
                --todo_boards;
            }
        }
        while(ware && todo_boards);
    }

    unsigned todo_stones = 0;
    if(stones + expedition.stones < BUILDING_COSTS[nation][BLD_HARBORBUILDING].stones)
    {
        todo_stones = BUILDING_COSTS[nation][BLD_HARBORBUILDING].stones - (stones + expedition.stones);
        Ware* ware;
        do
        {
            ware = gwg->GetPlayer(player).OrderWare(GD_STONES, this);
            if(ware)
            {
                RTTR_Assert(IsWareDependent(ware));
                --todo_stones;
            }
        }
        while(ware && todo_stones);
    }

    // Wenn immer noch nicht alles da ist, später noch einmal bestellen
    if(!orderware_ev)
        orderware_ev = em->AddEvent(this, 210, 10);
}
void nobBaseWarehouse::HandleCollectEvent()
{
    // Storing wares done?
    bool storing_done = false;
    // Is storing still wanted?
    bool storing_wanted = false;

    // Untersuchen, welche Waren und Figuren eingelagert werden sollen
    for(unsigned i = 0; i < WARE_TYPES_COUNT; ++i)
    {
        // Soll Ware eingeliefert werden?
        if(!GetInventorySetting(GoodType(i)).IsSet(EInventorySetting::COLLECT))
            continue;

        storing_wanted = true;

        // Lagerhaus suchen, das diese Ware enthält
        nobBaseWarehouse* wh = gwg->GetPlayer(player).FindWarehouse(*this, FW::HasWareButNoCollect(GoodType(i)), false, false);
        // Gefunden?
        if(wh)
        {
            // Dann bestellen
            Ware* ware = wh->OrderWare(GoodType(i), this);
            if(ware)
            {
                RTTR_Assert(IsWareDependent(ware));
                storing_done = true;
                break;
            }
        }
    }

    // Menschen "bestellen" wenn noch keine Ware bestellt wurde
    if(!storing_done)
    {
        for(unsigned i = 0; i < JOB_TYPES_COUNT; ++i)
        {
            // Soll dieser Typ von Mensch bestellt werden?
            if(!GetInventorySetting(Job(i)).IsSet(EInventorySetting::COLLECT))
                continue;

            storing_wanted = true;

            // Lagerhaus suchen, das diesen Job enthält
            nobBaseWarehouse* wh = gwg->GetPlayer(player).FindWarehouse(*this, FW::HasFigureButNoCollect(Job(i), false), false, false);
            // Gefunden?
            if(wh)
            {
                // Dann bestellen
                if(wh->OrderJob(Job(i), this, false))
                    break;
            }
        }
    }

    // Storing still wanted?
    // Then continue ordering new stuff
    if(storing_wanted)
        store_event = em->AddEvent(this, STORE_INTERVAL, 4);
}
void nobBaseWarehouse::AddWare(Ware*& ware)
{
    // Ware not dependent anymore (only if we had a goal)
    if(ware->GetGoal())
    {
        RTTR_Assert(ware->GetGoal() == this); // The goal should be here
        RemoveDependentWare(ware);
    }
    else
        RTTR_Assert(!IsWareDependent(ware));

    // Die Schilde der verschiedenen Nation in eine "Schild-Sorte" (den der Römer) umwandeln!
    GoodType type = ConvertShields(ware->type);

    gwg->GetPlayer(player).RemoveWare(ware);
    deletePtr(ware);

    inventory.Add(type);

    CheckUsesForNewWare(type);
}