Move isRouteVehicle, isSquadEquipment from workflow to Items module

develop
lethosor 2018-05-12 14:49:30 -04:00
parent abb903d28f
commit c15571caa0
6 changed files with 40 additions and 18 deletions

@ -1306,6 +1306,14 @@ Items module
Checks whether the item and all items it contains, if any, can be traded.
* ``dfhack.items.isRouteVehicle(item)``
Checks whether the item is an assigned hauling vehicle.
* ``dfhack.items.isSquadEquipment(item)``
Checks whether the item is assigned to a squad.
Maps module
-----------

@ -42,6 +42,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- ``Items::checkMandates()``
- ``Items::canTrade()``
- ``Items::canTradeWithContents()``
- ``Items::isRouteVehicle()``
- ``Items::isSquadEquipment()``
# 0.44.10-beta1

@ -1758,6 +1758,8 @@ static const LuaWrapper::FunctionReg dfhack_items_module[] = {
WRAPM(Items, checkMandates),
WRAPM(Items, canTrade),
WRAPM(Items, canTradeWithContents),
WRAPM(Items, isRouteVehicle),
WRAPM(Items, isSquadEquipment),
WRAPN(moveToGround, items_moveToGround),
WRAPN(moveToContainer, items_moveToContainer),
WRAPN(moveToInventory, items_moveToInventory),

@ -190,6 +190,11 @@ DFHACK_EXPORT bool canTrade(df::item *item);
/// Checks whether the item and all items it contains, if any, can be traded
DFHACK_EXPORT bool canTradeWithContents(df::item *item);
/// Checks whether the item is an assigned hauling vehicle
DFHACK_EXPORT bool isRouteVehicle(df::item *item);
/// Checks whether the item is assigned to a squad
DFHACK_EXPORT bool isSquadEquipment(df::item *item);
}
}

@ -85,6 +85,7 @@ using namespace std;
#include "df/ui.h"
#include "df/unit.h"
#include "df/unit_inventory_item.h"
#include "df/vehicle.h"
#include "df/vermin.h"
#include "df/viewscreen_itemst.h"
#include "df/world.h"
@ -1485,3 +1486,23 @@ bool Items::canTradeWithContents(df::item *item)
return true;
}
bool Items::isRouteVehicle(df::item *item)
{
CHECK_NULL_POINTER(item);
int id = item->getVehicleID();
if (id < 0) return false;
auto vehicle = df::vehicle::find(id);
return vehicle && vehicle->route_id >= 0;
}
bool Items::isSquadEquipment(df::item *item)
{
CHECK_NULL_POINTER(item);
if (!ui)
return false;
auto &vec = ui->equipment.items_assigned[item->getType()];
return binsearch_index(vec, &df::item::id, item->id) >= 0;
}

@ -40,7 +40,6 @@
#include "df/plant_raw.h"
#include "df/inorganic_raw.h"
#include "df/builtin_mats.h"
#include "df/vehicle.h"
using std::vector;
using std::string;
@ -1159,21 +1158,6 @@ static bool itemInRealJob(df::item *item)
!= job_type_class::Hauling;
}
static bool isRouteVehicle(df::item *item)
{
int id = item->getVehicleID();
if (id < 0) return false;
auto vehicle = df::vehicle::find(id);
return vehicle && vehicle->route_id >= 0;
}
static bool isAssignedSquad(df::item *item)
{
auto &vec = ui->equipment.items_assigned[item->getType()];
return binsearch_index(vec, &df::item::id, item->id) >= 0;
}
static void map_job_items(color_ostream &out)
{
for (size_t i = 0; i < constraints.size(); i++)
@ -1288,10 +1272,10 @@ static void map_job_items(color_ostream &out)
item->flags.bits.owned ||
item->flags.bits.in_chest ||
item->isAssignedToStockpile() ||
isRouteVehicle(item) ||
Items::isRouteVehicle(item) ||
itemInRealJob(item) ||
itemBusy(item) ||
isAssignedSquad(item))
Items::isSquadEquipment(item))
{
is_invalid = true;
cv->item_inuse_count++;