@ -1154,7 +1154,7 @@ public:
job_to_labor_table [ df : : job_type : : GatherPlants ] = jlf_const ( df : : unit_labor : : HERBALIST ) ;
job_to_labor_table [ df : : job_type : : GatherPlants ] = jlf_const ( df : : unit_labor : : HERBALIST ) ;
job_to_labor_table [ df : : job_type : : RemoveConstruction ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : RemoveConstruction ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : CollectWebs ] = jlf_const ( df : : unit_labor : : WEAVER ) ;
job_to_labor_table [ df : : job_type : : CollectWebs ] = jlf_const ( df : : unit_labor : : WEAVER ) ;
job_to_labor_table [ df : : job_type : : BringItemToDepot ] = jlf_ no_labor ;
job_to_labor_table [ df : : job_type : : BringItemToDepot ] = jlf_ const( df : : unit_labor : : HAUL_TRADE ) ;
job_to_labor_table [ df : : job_type : : BringItemToShop ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : BringItemToShop ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : Eat ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : Eat ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : GetProvisions ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : GetProvisions ] = jlf_no_labor ;
@ -1178,13 +1178,13 @@ public:
job_to_labor_table [ df : : job_type : : CheckChest ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : CheckChest ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : StoreOwnedItem ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : StoreOwnedItem ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : PlaceItemInTomb ] = jlf_const ( df : : unit_labor : : HAUL_BODY ) ;
job_to_labor_table [ df : : job_type : : PlaceItemInTomb ] = jlf_const ( df : : unit_labor : : HAUL_BODY ) ;
job_to_labor_table [ df : : job_type : : StoreItemInStockpile ] = jlf_ hauling;
job_to_labor_table [ df : : job_type : : StoreItemInStockpile ] = jlf_ no_labor; // Can arise from many different labors, but will never appear in a pending job list
job_to_labor_table [ df : : job_type : : StoreItemInBag ] = jlf_ hauling;
job_to_labor_table [ df : : job_type : : StoreItemInBag ] = jlf_ no_labor; // Can arise from many different labors, but will never appear in a pending job list
job_to_labor_table [ df : : job_type : : StoreItemInHospital ] = jlf_hauling ;
job_to_labor_table [ df : : job_type : : StoreItemInHospital ] = jlf_hauling ;
job_to_labor_table [ df : : job_type : : StoreWeapon ] = jlf_hauling ;
job_to_labor_table [ df : : job_type : : StoreWeapon ] = jlf_hauling ;
job_to_labor_table [ df : : job_type : : StoreArmor ] = jlf_hauling ;
job_to_labor_table [ df : : job_type : : StoreArmor ] = jlf_hauling ;
job_to_labor_table [ df : : job_type : : StoreItemInBarrel ] = jlf_ hauling;
job_to_labor_table [ df : : job_type : : StoreItemInBarrel ] = jlf_ no_labor; // Can arise from many different labors, but will never appear in a pending job list
job_to_labor_table [ df : : job_type : : StoreItemInBin ] = jlf_ const( df : : unit_labor : : HAUL_ITEM ) ;
job_to_labor_table [ df : : job_type : : StoreItemInBin ] = jlf_ no_labor; // Can arise from many different labors, but will never appear in a pending job list
job_to_labor_table [ df : : job_type : : SeekArtifact ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : SeekArtifact ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : SeekInfant ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : SeekInfant ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : AttendParty ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : AttendParty ] = jlf_no_labor ;
@ -1293,14 +1293,14 @@ public:
job_to_labor_table [ df : : job_type : : TameVermin ] = jlf_const ( df : : unit_labor : : ANIMALTRAIN ) ;
job_to_labor_table [ df : : job_type : : TameVermin ] = jlf_const ( df : : unit_labor : : ANIMALTRAIN ) ;
job_to_labor_table [ df : : job_type : : TameAnimal ] = jlf_const ( df : : unit_labor : : ANIMALTRAIN ) ;
job_to_labor_table [ df : : job_type : : TameAnimal ] = jlf_const ( df : : unit_labor : : ANIMALTRAIN ) ;
job_to_labor_table [ df : : job_type : : ChainAnimal ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : ChainAnimal ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : UnchainAnimal ] = jlf_ no_labor ;
job_to_labor_table [ df : : job_type : : UnchainAnimal ] = jlf_ const( df : : unit_labor : : HAUL_ANIMALS ) ;
job_to_labor_table [ df : : job_type : : UnchainPet ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : UnchainPet ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : ReleaseLargeCreature ] = jlf_ no_labor ;
job_to_labor_table [ df : : job_type : : ReleaseLargeCreature ] = jlf_ const( df : : unit_labor : : HAUL_ANIMALS ) ;
job_to_labor_table [ df : : job_type : : ReleasePet ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : ReleasePet ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : ReleaseSmallCreature ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : ReleaseSmallCreature ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : HandleSmallCreature ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : HandleSmallCreature ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : HandleLargeCreature ] = jlf_ no_labor ;
job_to_labor_table [ df : : job_type : : HandleLargeCreature ] = jlf_ const( df : : unit_labor : : HAUL_ANIMALS ) ;
job_to_labor_table [ df : : job_type : : CageLargeCreature ] = jlf_ no_labor ;
job_to_labor_table [ df : : job_type : : CageLargeCreature ] = jlf_ const( df : : unit_labor : : HAUL_ANIMALS ) ;
job_to_labor_table [ df : : job_type : : CageSmallCreature ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : CageSmallCreature ] = jlf_no_labor ;
job_to_labor_table [ df : : job_type : : RecoverWounded ] = jlf_const ( df : : unit_labor : : RECOVER_WOUNDED ) ;
job_to_labor_table [ df : : job_type : : RecoverWounded ] = jlf_const ( df : : unit_labor : : RECOVER_WOUNDED ) ;
job_to_labor_table [ df : : job_type : : DiagnosePatient ] = jlf_const ( df : : unit_labor : : DIAGNOSE ) ;
job_to_labor_table [ df : : job_type : : DiagnosePatient ] = jlf_const ( df : : unit_labor : : DIAGNOSE ) ;
@ -1640,6 +1640,7 @@ private:
int priority_food ;
int priority_food ;
std : : map < df : : unit_labor , int > labor_needed ;
std : : map < df : : unit_labor , int > labor_needed ;
std : : map < df : : unit_labor , int > labor_in_use ;
std : : map < df : : unit_labor , bool > labor_outside ;
std : : map < df : : unit_labor , bool > labor_outside ;
std : : vector < dwarf_info_t * > dwarf_info ;
std : : vector < dwarf_info_t * > dwarf_info ;
std : : list < dwarf_info_t * > available_dwarfs ;
std : : list < dwarf_info_t * > available_dwarfs ;
@ -1668,6 +1669,7 @@ private:
{
{
df : : building_tradedepotst * depot = ( df : : building_tradedepotst * ) build ;
df : : building_tradedepotst * depot = ( df : : building_tradedepotst * ) build ;
trader_requested = depot - > trade_flags . bits . trader_requested ;
trader_requested = depot - > trade_flags . bits . trader_requested ;
if ( print_debug )
if ( print_debug )
{
{
if ( trader_requested )
if ( trader_requested )
@ -1819,20 +1821,23 @@ private:
}
}
df : : unit_labor labor = labor_mapper - > find_job_labor ( j ) ;
df : : unit_labor labor = labor_mapper - > find_job_labor ( j ) ;
labor_needed [ labor ] + + ;
if ( labor ! = df : : unit_labor : : NONE )
if ( labor ! = df : : unit_labor : : NONE )
{
{
labor_needed [ labor ] + + ;
if ( worker = = - 1 )
{
if ( worker ! = - 1 )
labor_infos [ labor ] . mark_assigned ( ) ;
if ( j - > pos . isValid ( ) )
if ( j - > pos . isValid ( ) )
{
{
df : : tile_designation * d = Maps : : getTileDesignation ( j - > pos ) ;
df : : tile_designation * d = Maps : : getTileDesignation ( j - > pos ) ;
if ( d - > bits . outside )
if ( d - > bits . outside )
labor_outside [ labor ] = true ;
labor_outside [ labor ] = true ;
}
}
} else {
labor_infos [ labor ] . mark_assigned ( ) ;
labor_in_use [ labor ] + + ;
}
}
}
}
}
@ -1979,8 +1984,6 @@ private:
}
}
}
}
}
}
if ( state = = OTHER )
dwarf - > clear_all = true ;
}
}
dwarf - > state = state ;
dwarf - > state = state ;
@ -2260,42 +2263,13 @@ public:
// note: this doesn't test to see if the trainer is actually needed, and thus will overallocate trainers. bleah.
// note: this doesn't test to see if the trainer is actually needed, and thus will overallocate trainers. bleah.
}
}
/* move idle dwarfs ready to be assigned to busy list */
/* set requirements to zero for labors with currently idle dwarfs, and remove from requirement dwarfs actually working */
for ( auto d = available_dwarfs . begin ( ) ; d ! = available_dwarfs . end ( ) ; )
{
bool busy = false ;
FOR_ENUM_ITEMS ( unit_labor , l )
FOR_ENUM_ITEMS ( unit_labor , l ) {
{
if ( l = = df : : unit_labor : : NONE )
continue ;
if ( labor_needed [ l ] > 0 & & ( * d ) - > dwarf - > status . labors [ l ] )
{
busy = true ;
labor_needed [ l ] = max ( labor_needed [ l ] - 1 , 0 ) ;
}
}
if ( busy )
{
busy_dwarfs . push_back ( * d ) ;
d = available_dwarfs . erase ( d ) ;
} else {
d + + ;
}
}
/* adjust for over/under */
FOR_ENUM_ITEMS ( unit_labor , l )
{
if ( l = = df : : unit_labor : : NONE )
continue ;
if ( labor_infos [ l ] . idle_dwarfs > 0 )
if ( labor_infos [ l ] . idle_dwarfs > 0 )
labor_needed [ l ] = 0 ;
labor_needed [ l ] = 0 ;
else
else
labor_needed [ l ] = std: : max( labor_needed [ l ] - labor_in fos[ l ] . busy_dwarfs , 0 ) ;
labor_needed [ l ] = max ( 0 , labor_needed [ l ] - labor_in_use [ l ] ) ;
}
}
/* assign food haulers for rotting food items */
/* assign food haulers for rotting food items */
@ -2401,7 +2375,6 @@ public:
priority / = 2 ;
priority / = 2 ;
pq . push ( make_pair ( priority , labor ) ) ;
pq . push ( make_pair ( priority , labor ) ) ;
}
}
}
}
int canary = ( 1 < < df : : unit_labor : : HAUL_STONE ) |
int canary = ( 1 < < df : : unit_labor : : HAUL_STONE ) |
@ -2476,6 +2449,7 @@ public:
to_assign [ best_labor ] - - ;
to_assign [ best_labor ] - - ;
}
}
busy_dwarfs . push_back ( * bestdwarf ) ;
available_dwarfs . erase ( bestdwarf ) ;
available_dwarfs . erase ( bestdwarf ) ;
}
}
@ -2510,40 +2484,55 @@ public:
ENUM_KEY_STR ( unit_labor , ( * d ) - > using_labor ) . c_str ( ) , current_score ) ;
ENUM_KEY_STR ( unit_labor , ( * d ) - > using_labor ) . c_str ( ) , current_score ) ;
}
}
}
}
else
( * d ) - > clear_labor ( l ) ;
}
}
}
}
if ( canary ! = 0 )
dwarf_info_t * canary_dwarf = 0 ;
{
dwarf_info_t * d = 0 ;
for ( auto di = busy_dwarfs . begin ( ) ; di ! = busy_dwarfs . end ( ) ; di + + )
for ( auto di = busy_dwarfs . begin ( ) ; di ! = busy_dwarfs . end ( ) ; di + + )
if ( ! ( * di ) - > clear_all )
if ( ! ( * di ) - > clear_all )
{
{
d = * di ;
canary_ dwarf = * di ;
break ;
break ;
}
}
if ( d)
if ( canary_ dwarf )
{
{
FOR_ENUM_ITEMS ( unit_labor , l )
FOR_ENUM_ITEMS ( unit_labor , l )
{
{
if ( l > = df : : unit_labor : : HAUL_STONE & & l < = df : : unit_labor : : HAUL_ANIMALS & &
if ( l > = df : : unit_labor : : HAUL_STONE & & l < = df : : unit_labor : : HAUL_ANIMALS & &
canary & ( 1 < < l ) )
canary & ( 1 < < l ) )
d- > set_labor ( l ) ;
canary_ dwarf - > set_labor ( l ) ;
}
}
/* Also set the canary to remove constructions, because we have no way yet to tell if there are constructions needing removal */
canary_dwarf - > set_labor ( df : : unit_labor : : REMOVE_CONSTRUCTION ) ;
if ( print_debug )
if ( print_debug )
out . print ( " Setting %s as the hauling canary \n " , d - > dwarf - > name . first_name . c_str ( ) ) ;
out . print ( " Setting %s as the hauling canary \n " , canary_ dwarf - > dwarf - > name . first_name . c_str ( ) ) ;
}
}
else
else
{
{
if ( print_debug )
if ( print_debug )
out . print ( " No dwarf available to set as the hauling canary! \n " ) ;
out . print ( " No dwarf available to set as the hauling canary! \n " ) ;
}
}
/* Assign any leftover dwarfs to "standard" labors */
for ( auto d = available_dwarfs . begin ( ) ; d ! = available_dwarfs . end ( ) ; d + + )
{
FOR_ENUM_ITEMS ( unit_labor , l )
{
if ( l > = df : : unit_labor : : HAUL_STONE & & l < = df : : unit_labor : : HAUL_ANIMALS & &
canary & ( 1 < < l ) )
( * d ) - > set_labor ( l ) ;
}
( * d ) - > set_labor ( df : : unit_labor : : CLEAN ) ;
( * d ) - > set_labor ( df : : unit_labor : : REMOVE_CONSTRUCTION ) ;
}
}
/* set reequip on any dwarfs who are carrying tools needed by others */
/* set reequip on any dwarfs who are carrying tools needed by others */