Respect export mandates

develop
Anuradha Dissanayake 2013-03-31 23:25:57 +13:00
parent 2027416997
commit c020c0271c
1 changed files with 44 additions and 1 deletions

@ -15,6 +15,7 @@
#include "modules/Job.h" #include "modules/Job.h"
#include "df/ui.h" #include "df/ui.h"
#include "df/caravan_state.h" #include "df/caravan_state.h"
#include "df/mandate.h"
#include "modules/Maps.h" #include "modules/Maps.h"
#include "modules/World.h" #include "modules/World.h"
@ -251,6 +252,31 @@ static TradeDepotInfo depot_info;
* Item Manipulation * Item Manipulation
*/ */
static bool check_mandates(df::item *item)
{
for (auto it = world->mandates.begin(); it != world->mandates.end(); it++)
{
auto mandate = *it;
if (mandate->mode != 0)
continue;
if (item->getType() != mandate->item_type ||
(mandate->item_subtype != -1 && item->getSubtype() != mandate->item_subtype))
continue;
if (mandate->mat_type != -1 && item->getMaterial() != mandate->mat_type)
continue;
if (mandate->mat_index != -1 && item->getMaterialIndex() != mandate->mat_index)
continue;
return false;
}
return true;
}
static bool is_valid_item(df::item *item) static bool is_valid_item(df::item *item)
{ {
for (size_t i = 0; i < item->general_refs.size(); i++) for (size_t i = 0; i < item->general_refs.size(); i++)
@ -284,6 +310,8 @@ static bool is_valid_item(df::item *item)
} }
} }
if (!check_mandates(item))
return false;
return true; return true;
} }
@ -300,7 +328,6 @@ static void mark_all_in_stockpiles(vector<StockpileInfo> &stockpiles, bool annou
std::vector<df::item*> &items = world->items.other[items_other_id::IN_PLAY]; std::vector<df::item*> &items = world->items.other[items_other_id::IN_PLAY];
//FIXME filter out mandates
// Precompute a bitmask with the bad flags // Precompute a bitmask with the bad flags
df::item_flags bad_flags; df::item_flags bad_flags;
@ -329,6 +356,22 @@ static void mark_all_in_stockpiles(vector<StockpileInfo> &stockpiles, bool annou
if (!it->inStockpile(item)) if (!it->inStockpile(item))
continue; continue;
// In case of container, check contained items for mandates
bool mandates_ok = true;
vector<df::item*> contained_items;
Items::getContainedItems(item, &contained_items);
for (auto cit = contained_items.begin(); cit != contained_items.end(); cit++)
{
if (!check_mandates(*cit))
{
mandates_ok = false;
break;
}
}
if (!mandates_ok)
continue;
if (depot_info.assignItem(item)) if (depot_info.assignItem(item))
{ {
++marked_count; ++marked_count;