@ -1,4 +1,4 @@
# include "buildingplan-lib.h"
# include <unordered_map>
# include "df/entity_position.h"
# include "df/entity_position.h"
# include "df/interface_key.h"
# include "df/interface_key.h"
@ -14,6 +14,7 @@
# include "uicommon.h"
# include "uicommon.h"
# include "listcolumn.h"
# include "listcolumn.h"
# include "buildingplan-lib.h"
DFHACK_PLUGIN ( " buildingplan " ) ;
DFHACK_PLUGIN ( " buildingplan " ) ;
# define PLUGIN_VERSION 0.15
# define PLUGIN_VERSION 0.15
@ -27,15 +28,14 @@ REQUIRE_GLOBAL(world);
using namespace DFHack ;
using namespace DFHack ;
using namespace df : : enums ;
using namespace df : : enums ;
bool show_help = false ;
bool quickfort_mode = false ;
bool quickfort_mode = false ;
bool in_dummy_screen = false ;
bool in_dummy_screen = false ;
std : : map< df : : building_type , bool > planmode_enabled ;
std : : unordered_map< BuildingTypeKey , bool , BuildingTypeKeyHash > planmode_enabled ;
class ViewscreenChooseMaterial : public dfhack_viewscreen
class ViewscreenChooseMaterial : public dfhack_viewscreen
{
{
public :
public :
ViewscreenChooseMaterial ( ItemFilter * filter ) ;
ViewscreenChooseMaterial ( ItemFilter & filter ) ;
void feed ( set < df : : interface_key > * input ) ;
void feed ( set < df : : interface_key > * input ) ;
@ -47,14 +47,12 @@ private:
ListColumn < df : : dfhack_material_category > masks_column ;
ListColumn < df : : dfhack_material_category > masks_column ;
ListColumn < MaterialInfo > materials_column ;
ListColumn < MaterialInfo > materials_column ;
int selected_column ;
int selected_column ;
ItemFilter * filter ;
ItemFilter & filter ;
df : : building_type btype ;
void addMaskEntry ( df : : dfhack_material_category & mask , const std : : string & text )
void addMaskEntry ( df : : dfhack_material_category & mask , const std : : string & text )
{
{
auto entry = ListEntry < df : : dfhack_material_category > ( pad_string ( text , MAX_MASK , false ) , mask ) ;
auto entry = ListEntry < df : : dfhack_material_category > ( pad_string ( text , MAX_MASK , false ) , mask ) ;
if ( filter - > matches ( mask ) )
if ( filter . matches ( mask ) )
entry . selected = true ;
entry . selected = true ;
masks_column . add ( entry ) ;
masks_column . add ( entry ) ;
@ -131,7 +129,7 @@ private:
material . decode ( DFHack : : MaterialInfo : : PLANT_BASE + j , i ) ;
material . decode ( DFHack : : MaterialInfo : : PLANT_BASE + j , i ) ;
auto name = material . toString ( ) ;
auto name = material . toString ( ) ;
ListEntry < MaterialInfo > entry ( pad_string ( name , MAX_MATERIAL , false ) , material ) ;
ListEntry < MaterialInfo > entry ( pad_string ( name , MAX_MATERIAL , false ) , material ) ;
if ( filter - > matches ( material ) )
if ( filter . matches ( material ) )
entry . selected = true ;
entry . selected = true ;
materials_column . add ( entry ) ;
materials_column . add ( entry ) ;
@ -147,7 +145,7 @@ private:
if ( ! selected_category . whole | | material . matches ( selected_category ) )
if ( ! selected_category . whole | | material . matches ( selected_category ) )
{
{
ListEntry < MaterialInfo > entry ( pad_string ( name , MAX_MATERIAL , false ) , material ) ;
ListEntry < MaterialInfo > entry ( pad_string ( name , MAX_MATERIAL , false ) , material ) ;
if ( filter - > matches ( material ) )
if ( filter . matches ( material ) )
entry . selected = true ;
entry . selected = true ;
materials_column . add ( entry ) ;
materials_column . add ( entry ) ;
@ -167,9 +165,10 @@ private:
}
}
} ;
} ;
DFHack : : MaterialInfo & material_info_identity_fn ( DFHack : : MaterialInfo & m ) { return m ; }
const DFHack : : MaterialInfo & material_info_identity_fn ( const DFHack : : MaterialInfo & m ) { return m ; }
ViewscreenChooseMaterial : : ViewscreenChooseMaterial ( ItemFilter * filter )
ViewscreenChooseMaterial : : ViewscreenChooseMaterial ( ItemFilter & filter )
: filter ( filter )
{
{
selected_column = 0 ;
selected_column = 0 ;
masks_column . setTitle ( " Type " ) ;
masks_column . setTitle ( " Type " ) ;
@ -179,7 +178,6 @@ ViewscreenChooseMaterial::ViewscreenChooseMaterial(ItemFilter *filter)
materials_column . left_margin = MAX_MASK + 3 ;
materials_column . left_margin = MAX_MASK + 3 ;
materials_column . setTitle ( " Material " ) ;
materials_column . setTitle ( " Material " ) ;
materials_column . multiselect = true ;
materials_column . multiselect = true ;
this - > filter = filter ;
masks_column . changeHighlight ( 0 ) ;
masks_column . changeHighlight ( 0 ) ;
@ -217,7 +215,7 @@ void ViewscreenChooseMaterial::feed(set<df::interface_key> *input)
}
}
if ( input - > count ( interface_key : : CUSTOM_SHIFT_C ) )
if ( input - > count ( interface_key : : CUSTOM_SHIFT_C ) )
{
{
filter - > clear ( ) ;
filter . clear ( ) ;
masks_column . clearSelection ( ) ;
masks_column . clearSelection ( ) ;
materials_column . clearSelection ( ) ;
materials_column . clearSelection ( ) ;
populateMaterials ( ) ;
populateMaterials ( ) ;
@ -225,17 +223,18 @@ void ViewscreenChooseMaterial::feed(set<df::interface_key> *input)
else if ( input - > count ( interface_key : : SEC_SELECT ) )
else if ( input - > count ( interface_key : : SEC_SELECT ) )
{
{
// Convert list selections to material filters
// Convert list selections to material filters
filter - > mat_mask . whole = 0 ;
filter . clearMaterialMask ( ) ;
filter - > materials . clear ( ) ;
// Category masks
// Category masks
auto masks = masks_column . getSelectedElems ( ) ;
auto masks = masks_column . getSelectedElems ( ) ;
for ( auto it = masks . begin ( ) ; it ! = masks . end ( ) ; + + it )
for ( auto it = masks . begin ( ) ; it ! = masks . end ( ) ; + + it )
filter - > mat_mask . whole | = it - > whole ;
filter . addMaterialMask ( it - > whole ) ;
// Specific materials
// Specific materials
auto materials = materials_column . getSelectedElems ( ) ;
auto materials = materials_column . getSelectedElems ( ) ;
transform_ ( materials , filter - > materials , material_info_identity_fn ) ;
std : : vector < DFHack : : MaterialInfo > materialInfos ;
transform_ ( materials , materialInfos , material_info_identity_fn ) ;
filter . setMaterials ( materialInfos ) ;
Screen : : dismiss ( this ) ;
Screen : : dismiss ( this ) ;
}
}
@ -285,180 +284,158 @@ void ViewscreenChooseMaterial::render()
}
}
//START Viewscreen Hook
//START Viewscreen Hook
static bool is_planmode_enabled ( df: : building_type type )
static bool is_planmode_enabled ( BuildingTypeKey key )
{
{
return planmode_enabled [ type ] | | quickfort_mode ;
return planmode_enabled [ key ] | | quickfort_mode ;
}
}
struct buildingplan_ hook : public df : : viewscreen_dwarfmodest
struct buildingplan_ query_ hook : public df : : viewscreen_dwarfmodest
{
{
//START UI Methods
typedef df : : viewscreen_dwarfmodest interpose_base ;
typedef df : : viewscreen_dwarfmodest interpose_base ;
void send_key ( const df : : interface_key & key )
{
set < df : : interface_key > keys ;
keys . insert ( key ) ;
this - > feed ( & keys ) ;
}
bool isInPlannedBuildingQueryMode ( )
bool isInPlannedBuildingQueryMode ( )
{
{
return ( ui - > main . mode = = df : : ui_sidebar_mode : : QueryBuilding | |
return ( ui - > main . mode = = df : : ui_sidebar_mode : : QueryBuilding | |
ui - > main . mode = = df : : ui_sidebar_mode : : BuildingItems ) & &
ui - > main . mode = = df : : ui_sidebar_mode : : BuildingItems ) & &
planner . get Selected PlannedBuilding( ) ;
planner . getPlannedBuilding ( world - > selected_building ) ;
}
}
bool isInPlannedBuildingPlacementMode( )
bool handleInput( set < df : : interface_key > * input )
{
{
return ui - > main . mode = = ui_sidebar_mode : : Build & &
if ( ! isInPlannedBuildingQueryMode ( ) )
df : : global : : ui_build_selector & &
return false ;
df : : global : : ui_build_selector - > stage < 2 & &
planner . isPlannableBuilding ( ui_build_selector - > building_type ) ;
}
std : : vector < Units : : NoblePosition > getNoblePositionOfSelectedBuildingOwner ( )
if ( input - > count ( interface_key : : SUSPENDBUILDING ) )
{
return true ; // Don't unsuspend planned buildings
std : : vector < Units : : NoblePosition > np ;
if ( input - > count ( interface_key : : DESTROYBUILDING ) )
if ( ui - > main . mode ! = df : : ui_sidebar_mode : : QueryBuilding | |
! world - > selected_building | |
! world - > selected_building - > owner )
{
{
return np ;
// remove persistent data
planner . getPlannedBuilding ( world - > selected_building ) - > remove ( ) ;
// still allow the building to be removed
return false ;
}
}
switch ( world - > selected_building - > getType ( ) )
return true ;
}
DEFINE_VMETHOD_INTERPOSE ( void , feed , ( set < df : : interface_key > * input ) )
{
{
case building_type : : Bed :
if ( ! handleInput ( input ) )
case building_type : : Chair :
INTERPOSE_NEXT ( feed ) ( input ) ;
case building_type : : Table :
break ;
default :
return np ;
}
}
return getUniqueNoblePositions ( world - > selected_building - > owner ) ;
DEFINE_VMETHOD_INTERPOSE ( void , render , ( ) )
{
INTERPOSE_NEXT ( render ) ( ) ;
if ( ! isInPlannedBuildingQueryMode ( ) )
return ;
// Hide suspend toggle option
auto dims = Gui : : getDwarfmodeViewDims ( ) ;
int left_margin = dims . menu_x1 + 1 ;
int x = left_margin ;
int y = 20 ;
Screen : : Pen pen ( ' ' , COLOR_BLACK ) ;
Screen : : fillRect ( pen , x , y , dims . menu_x2 , y ) ;
// all current buildings only have one filter
auto & filter = planner . getPlannedBuilding ( world - > selected_building ) - > getFilters ( ) [ 0 ] ;
y = 24 ;
OutputString ( COLOR_WHITE , x , y , " Planned Building Filter " , true , left_margin ) ;
+ + y ;
OutputString ( COLOR_BROWN , x , y , " Min Quality: " , false , left_margin ) ;
OutputString ( COLOR_BLUE , x , y , filter . getMinQuality ( ) , true , left_margin ) ;
OutputString ( COLOR_BROWN , x , y , " Max Quality: " , false , left_margin ) ;
OutputString ( COLOR_BLUE , x , y , filter . getMaxQuality ( ) , true , left_margin ) ;
if ( filter . getDecoratedOnly ( ) )
OutputString ( COLOR_BLUE , x , y , " Decorated Only " , true , left_margin ) ;
OutputString ( COLOR_BROWN , x , y , " Materials: " , true , left_margin ) ;
auto filters = filter . getMaterials ( ) ;
for ( auto it = filters . begin ( ) ; it ! = filters . end ( ) ; + + it )
OutputString ( COLOR_BLUE , x , y , " * " + * it , true , left_margin ) ;
}
}
} ;
bool isInNobleRoomQueryMode ( )
struct buildingplan_place_hook : public df : : viewscreen_dwarfmodest
{
typedef df : : viewscreen_dwarfmodest interpose_base ;
bool isInPlannedBuildingPlacementMode ( )
{
{
if ( getNoblePositionOfSelectedBuildingOwner ( ) . size ( ) > 0 )
return ui - > main . mode = = ui_sidebar_mode : : Build & &
return canReserveRoom ( world - > selected_building ) ;
df : : global : : ui_build_selector & &
else
df : : global : : ui_build_selector - > stage < 2 & &
return false ;
planner . isPlannableBuilding ( toBuildingTypeKey ( ui_build_selector ) ) ;
}
}
bool handleInput ( set < df : : interface_key > * input )
bool handleInput ( set < df : : interface_key > * input )
{
{
if ( isInPlannedBuildingPlacementMode ( ) )
if ( ! isInPlannedBuildingPlacementMode ( ) )
{
return false ;
auto type = ui_build_selector - > building_type ;
if ( input - > count ( interface_key : : CUSTOM_SHIFT_P ) )
if ( in_dummy_screen )
{
{
planmode_enabled [ type ] = ! planmode_enabled [ type ] ;
if ( input - > count ( interface_key : : SELECT ) | | input - > count ( interface_key : : SEC_SELECT )
if ( ! is_planmode_enabled ( type ) )
| | input - > count ( interface_key : : LEAVESCREEN ) )
{
{
Gui : : refreshSidebar ( ) ;
in_dummy_screen = false ;
in_dummy_screen = false ;
// pass LEAVESCREEN up to parent view
input - > clear ( ) ;
input - > insert ( interface_key : : LEAVESCREEN ) ;
return false ;
}
}
return true ;
return true ;
}
}
else if ( input - > count ( interface_key : : CUSTOM_P ) | |
input - > count ( interface_key : : CUSTOM_F ) | |
input - > count ( interface_key : : CUSTOM_D ) | |
input - > count ( interface_key : : CUSTOM_N ) )
{
show_help = true ;
}
if ( is_planmode_enabled ( type ) )
BuildingTypeKey key = toBuildingTypeKey ( ui_build_selector ) ;
{
if ( input - > count ( interface_key : : CUSTOM_SHIFT_P ) )
if ( quickfort_mode & & in_dummy_screen )
{
if ( input - > count ( interface_key : : SELECT ) | | input - > count ( interface_key : : SEC_SELECT )
| | input - > count ( interface_key : : LEAVESCREEN ) )
{
{
in_dummy_screen = false ;
planmode_enabled [ key ] = ! planmode_enabled [ key ] ;
send_key ( interface_key : : LEAVESCREEN ) ;
if ( ! is_planmode_enabled ( key ) )
Gui : : refreshSidebar ( ) ;
return true ;
}
}
if ( input - > count ( interface_key : : CUSTOM_SHIFT_F ) )
{
quickfort_mode = ! quickfort_mode ;
return true ;
return true ;
}
}
if ( ! is_planmode_enabled ( key ) )
return false ;
if ( input - > count ( interface_key : : SELECT ) )
if ( input - > count ( interface_key : : SELECT ) )
{
{
if ( ui_build_selector - > errors . size ( ) = = 0 & & planner . allocatePlannedBuilding ( type ) )
if ( ui_build_selector - > errors . size ( ) = = 0 & & planner . allocatePlannedBuilding ( key ) )
{
{
Gui : : refreshSidebar ( ) ;
Gui : : refreshSidebar ( ) ;
if ( quickfort_mode )
if ( quickfort_mode )
{
in_dummy_screen = true ;
in_dummy_screen = true ;
}
}
}
return true ;
return true ;
}
}
else if ( input - > count ( interface_key : : CUSTOM_SHIFT_F ) )
{
// all current buildings only have one filter
quickfort_mode = ! quickfort_mode ;
auto filter = planner . getItemFilters ( key ) . rbegin ( ) ;
}
if ( input - > count ( interface_key : : CUSTOM_SHIFT_M ) )
else if ( input - > count ( interface_key : : CUSTOM_SHIFT_M ) )
Screen : : show ( dts : : make_unique < ViewscreenChooseMaterial > ( * filter ) , plugin_self ) ;
{
Screen : : show ( dts : : make_unique < ViewscreenChooseMaterial > ( planner . getDefaultItemFilterForType ( type ) ) , plugin_self ) ;
}
else if ( input - > count ( interface_key : : CUSTOM_Q ) )
else if ( input - > count ( interface_key : : CUSTOM_Q ) )
{
filter - > decMinQuality ( ) ;
planner . adjustMinQuality ( type , - 1 ) ;
}
else if ( input - > count ( interface_key : : CUSTOM_W ) )
else if ( input - > count ( interface_key : : CUSTOM_W ) )
{
filter - > incMinQuality ( ) ;
planner . adjustMinQuality ( type , 1 ) ;
}
else if ( input - > count ( interface_key : : CUSTOM_SHIFT_Q ) )
else if ( input - > count ( interface_key : : CUSTOM_SHIFT_Q ) )
{
filter - > decMaxQuality ( ) ;
planner . adjustMaxQuality ( type , - 1 ) ;
}
else if ( input - > count ( interface_key : : CUSTOM_SHIFT_W ) )
else if ( input - > count ( interface_key : : CUSTOM_SHIFT_W ) )
{
filter - > incMaxQuality ( ) ;
planner . adjustMaxQuality ( type , 1 ) ;
}
else if ( input - > count ( interface_key : : CUSTOM_SHIFT_D ) )
else if ( input - > count ( interface_key : : CUSTOM_SHIFT_D ) )
{
filter - > toggleDecoratedOnly ( ) ;
planner . getDefaultItemFilterForType ( type ) - > decorated_only =
else
! planner . getDefaultItemFilterForType ( type ) - > decorated_only ;
}
}
}
else if ( isInPlannedBuildingQueryMode ( ) )
{
if ( input - > count ( interface_key : : SUSPENDBUILDING ) )
{
return true ; // Don't unsuspend planned buildings
}
else if ( input - > count ( interface_key : : DESTROYBUILDING ) )
{
planner . removeSelectedPlannedBuilding ( ) ; // Remove persistent data
}
}
else if ( isInNobleRoomQueryMode ( ) )
{
if ( Gui : : inRenameBuilding ( ) )
return false ;
auto np = getNoblePositionOfSelectedBuildingOwner ( ) ;
df : : interface_key last_token = get_string_key ( input ) ;
if ( last_token > = interface_key : : STRING_A048 & & last_token < = interface_key : : STRING_A058 )
{
size_t selection = last_token - interface_key : : STRING_A048 ;
if ( np . size ( ) < selection )
return false ;
return false ;
roomMonitor . toggleRoomForPosition ( world - > selected_building - > id , np . at ( selection - 1 ) . position - > code ) ;
return true ;
return true ;
}
}
}
return false ;
}
DEFINE_VMETHOD_INTERPOSE ( void , feed , ( set < df : : interface_key > * input ) )
DEFINE_VMETHOD_INTERPOSE ( void , feed , ( set < df : : interface_key > * input ) )
{
{
@ -469,38 +446,36 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
DEFINE_VMETHOD_INTERPOSE ( void , render , ( ) )
DEFINE_VMETHOD_INTERPOSE ( void , render , ( ) )
{
{
bool plannable = isInPlannedBuildingPlacementMode ( ) ;
bool plannable = isInPlannedBuildingPlacementMode ( ) ;
if ( plannable & & is_planmode_enabled ( ui_build_selector - > building_type ) )
BuildingTypeKey key = toBuildingTypeKey ( ui_build_selector ) ;
if ( plannable & & is_planmode_enabled ( key ) )
{
{
if ( ui_build_selector - > stage < 1 )
if ( ui_build_selector - > stage < 1 )
{
// No materials but turn on cursor
// No materials but turn on cursor
ui_build_selector - > stage = 1 ;
ui_build_selector - > stage = 1 ;
}
for ( auto iter = ui_build_selector - > errors . begin ( ) ; iter ! = ui_build_selector - > errors . end ( ) ; )
for ( auto iter = ui_build_selector - > errors . begin ( ) ;
{
iter ! = ui_build_selector - > errors . end ( ) ; )
//FIXME Hide bags
if ( ( ( * iter ) - > find ( " Needs " ) ! = string : : npos & & * * iter ! = " Needs adjacent wall " ) | |
( * iter ) - > find ( " No access " ) ! = string : : npos )
{
{
// FIXME Hide bags
if ( ( ( * iter ) - > find ( " Needs " ) ! = string : : npos
& & * * iter ! = " Needs adjacent wall " )
| | ( * iter ) - > find ( " No access " ) ! = string : : npos )
iter = ui_build_selector - > errors . erase ( iter ) ;
iter = ui_build_selector - > errors . erase ( iter ) ;
}
else
else
{
+ + iter ;
+ + iter ;
}
}
}
}
}
INTERPOSE_NEXT ( render ) ( ) ;
INTERPOSE_NEXT ( render ) ( ) ;
if ( ! plannable )
return ;
auto dims = Gui : : getDwarfmodeViewDims ( ) ;
auto dims = Gui : : getDwarfmodeViewDims ( ) ;
int left_margin = dims . menu_x1 + 1 ;
int left_margin = dims . menu_x1 + 1 ;
int x = left_margin ;
int x = left_margin ;
auto type = ui_build_selector - > building_type ;
if ( plannable )
if ( in_dummy_screen )
{
if ( quickfort_mode & & in_dummy_screen )
{
{
Screen : : Pen pen ( ' ' , COLOR_BLACK ) ;
Screen : : Pen pen ( ' ' , COLOR_BLACK ) ;
int y = dims . y1 + 1 ;
int y = dims . y1 + 1 ;
@ -508,94 +483,133 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
+ + y ;
+ + y ;
OutputString ( COLOR_BROWN , x , y , " Quickfort Placeholder " , true , left_margin ) ;
OutputString ( COLOR_BROWN , x , y ,
" Placeholder for legacy Quickfort. This screen is not required for DFHack native quickfort. " ,
true , left_margin ) ;
OutputString ( COLOR_WHITE , x , y , " Enter, Shift-Enter or Esc " , true , left_margin ) ;
OutputString ( COLOR_WHITE , x , y , " Enter, Shift-Enter or Esc " , true , left_margin ) ;
return ;
}
}
else
{
int y = 23 ;
if ( show_help )
int y = 23 ;
{
OutputString ( COLOR_BROWN , x , y , " Note: " ) ;
OutputString ( COLOR_WHITE , x , y , " Use Shift-Keys here " , true , left_margin ) ;
}
OutputToggleString ( x , y , " Planning Mode " , " P " , is_planmode_enabled ( type ) , true , left_margin ) ;
if ( is_planmode_enabled ( type ) )
OutputToggleString ( x , y , " Planning Mode " , " P " , planmode_enabled [ key ] , true , left_margin ) ;
{
OutputToggleString ( x , y , " Quickfort Mode " , " F " , quickfort_mode , true , left_margin ) ;
OutputToggleString ( x , y , " Quickfort Mode " , " F " , quickfort_mode , true , left_margin ) ;
auto filter = planner . getDefaultItemFilterForType ( type ) ;
if ( ! is_planmode_enabled ( key ) )
return ;
auto filter = planner . getItemFilters ( key ) . rbegin ( ) ;
y + = 2 ;
OutputHotkeyString ( x , y , " Min Quality: " , " qw " ) ;
OutputHotkeyString ( x , y , " Min Quality: " , " qw " ) ;
OutputString ( COLOR_BROWN , x , y , filter - > getMinQuality ( ) , true , left_margin ) ;
OutputString ( COLOR_BROWN , x , y , filter - > getMinQuality ( ) , true , left_margin ) ;
OutputHotkeyString ( x , y , " Max Quality: " , " QW " ) ;
OutputHotkeyString ( x , y , " Max Quality: " , " QW " ) ;
OutputString ( COLOR_BROWN , x , y , filter - > getMaxQuality ( ) , true , left_margin ) ;
OutputString ( COLOR_BROWN , x , y , filter - > getMaxQuality ( ) , true , left_margin ) ;
OutputToggleString ( x , y , " Decorated Only : " , " D " , filter - > decorated_only , true , left_margin ) ;
OutputToggleString ( x , y , " Decorated Only " , " D " , filter - > getDecoratedOnly( ) , true , left_margin ) ;
OutputHotkeyString ( x , y , " Material Filter: " , " M " , true , left_margin ) ;
OutputHotkeyString ( x , y , " Material Filter: " , " M " , true , left_margin ) ;
auto filter_descriptions = filter - > getMaterialFilterAsVector ( ) ;
auto filter_descriptions = filter - > getMaterials ( ) ;
for ( auto it = filter_descriptions . begin ( ) ; it ! = filter_descriptions . end ( ) ; + + it )
for ( auto it = filter_descriptions . begin ( ) ;
it ! = filter_descriptions . end ( ) ; + + it )
OutputString ( COLOR_BROWN , x , y , " * " + * it , true , left_margin ) ;
OutputString ( COLOR_BROWN , x , y , " * " + * it , true , left_margin ) ;
}
}
else
} ;
struct buildingplan_room_hook : public df : : viewscreen_dwarfmodest
{
typedef df : : viewscreen_dwarfmodest interpose_base ;
std : : vector < Units : : NoblePosition > getNoblePositionOfSelectedBuildingOwner ( )
{
{
in_dummy_screen = false ;
std : : vector < Units : : NoblePosition > np ;
if ( ui - > main . mode ! = df : : ui_sidebar_mode : : QueryBuilding | |
! world - > selected_building | |
! world - > selected_building - > owner )
{
return np ;
}
}
switch ( world - > selected_building - > getType ( ) )
{
case building_type : : Bed :
case building_type : : Chair :
case building_type : : Table :
break ;
default :
return np ;
}
}
return getUniqueNoblePositions ( world - > selected_building - > owner ) ;
}
}
else if ( isInPlannedBuildingQueryMode ( ) )
bool isInNobleRoomQueryMode ( )
{
{
in_dummy_screen = false ;
if ( getNoblePositionOfSelectedBuildingOwner ( ) . size ( ) > 0 )
return canReserveRoom ( world - > selected_building ) ;
else
return false ;
}
// Hide suspend toggle option
bool handleInput ( set < df : : interface_key > * input )
int y = 20 ;
{
Screen : : Pen pen ( ' ' , COLOR_BLACK ) ;
if ( ! isInNobleRoomQueryMode ( ) )
Screen : : fillRect ( pen , x , y , dims . menu_x2 , y ) ;
return false ;
auto filter = planner . getSelectedPlannedBuilding ( ) - > getFilter ( ) ;
if ( Gui : : inRenameBuilding ( ) )
y = 24 ;
return false ;
OutputString ( COLOR_BROWN , x , y , " Planned Building Filter: " , true , left_margin ) ;
auto np = getNoblePositionOfSelectedBuildingOwner ( ) ;
OutputString ( COLOR_BROWN , x , y , " Min Quality: " , false , left_margin ) ;
df : : interface_key last_token = get_string_key ( input ) ;
OutputString ( COLOR_BLUE , x , y , filter - > getMinQuality ( ) , true , left_margin ) ;
if ( last_token > = interface_key : : STRING_A048
OutputString ( COLOR_BROWN , x , y , " Max Quality: " , false , left_margin ) ;
& & last_token < = interface_key : : STRING_A058 )
OutputString ( COLOR_BLUE , x , y , filter - > getMaxQuality ( ) , true , left_margin ) ;
{
size_t selection = last_token - interface_key : : STRING_A048 ;
if ( np . size ( ) < selection )
return false ;
roomMonitor . toggleRoomForPosition ( world - > selected_building - > id , np . at ( selection - 1 ) . position - > code ) ;
return true ;
}
if ( filter - > decorated_only )
return false ;
OutputString ( COLOR_BLUE , x , y , " Decorated Only " , true , left_margin ) ;
}
OutputString ( COLOR_BROWN , x , y , " Materials: " , true , left_margin ) ;
DEFINE_VMETHOD_INTERPOSE ( void , feed , ( set < df : : interface_key > * input ) )
auto filters = filter - > getMaterialFilterAsVector ( ) ;
{
for ( auto it = filters . begin ( ) ; it ! = filters . end ( ) ; + + it )
if ( ! handleInput ( input ) )
OutputString ( COLOR_BLUE , x , y , " * " + * it , true , left_margin ) ;
INTERPOSE_NEXT ( feed ) ( input ) ;
}
}
else if ( isInNobleRoomQueryMode ( ) )
DEFINE_VMETHOD_INTERPOSE ( void , render , ( ) )
{
{
INTERPOSE_NEXT ( render ) ( ) ;
if ( ! isInNobleRoomQueryMode ( ) )
return ;
auto np = getNoblePositionOfSelectedBuildingOwner ( ) ;
auto np = getNoblePositionOfSelectedBuildingOwner ( ) ;
auto dims = Gui : : getDwarfmodeViewDims ( ) ;
int left_margin = dims . menu_x1 + 1 ;
int x = left_margin ;
int y = 24 ;
int y = 24 ;
OutputString ( COLOR_BROWN , x , y , " DFHack " , true , left_margin ) ;
OutputString ( COLOR_BROWN , x , y , " DFHack " , true , left_margin ) ;
OutputString ( COLOR_WHITE , x , y , " Auto-allocate to: " , true , left_margin ) ;
OutputString ( COLOR_WHITE , x , y , " Auto-allocate to: " , true , left_margin ) ;
for ( size_t i = 0 ; i < np . size ( ) & & i < 9 ; i + + )
for ( size_t i = 0 ; i < np . size ( ) & & i < 9 ; i + + )
{
{
bool enabled = ( roomMonitor . getReservedNobleCode ( world - > selected_building - > id )
bool enabled =
= = np [ i ] . position - > code ) ;
roomMonitor . getReservedNobleCode ( world - > selected_building - > id )
= = np [ i ] . position - > code ;
OutputToggleString ( x , y , np [ i ] . position - > name [ 0 ] . c_str ( ) ,
OutputToggleString ( x , y , np [ i ] . position - > name [ 0 ] . c_str ( ) ,
int_to_string ( i + 1 ) . c_str ( ) , enabled , true , left_margin ) ;
int_to_string ( i + 1 ) . c_str ( ) , enabled , true , left_margin ) ;
}
}
}
}
else
{
in_dummy_screen = false ;
show_help = false ;
}
}
} ;
} ;
IMPLEMENT_VMETHOD_INTERPOSE ( buildingplan_hook , feed ) ;
IMPLEMENT_VMETHOD_INTERPOSE ( buildingplan_query_hook , feed ) ;
IMPLEMENT_VMETHOD_INTERPOSE ( buildingplan_hook , render ) ;
IMPLEMENT_VMETHOD_INTERPOSE ( buildingplan_place_hook , feed ) ;
IMPLEMENT_VMETHOD_INTERPOSE ( buildingplan_room_hook , feed ) ;
IMPLEMENT_VMETHOD_INTERPOSE ( buildingplan_query_hook , render ) ;
IMPLEMENT_VMETHOD_INTERPOSE ( buildingplan_place_hook , render ) ;
IMPLEMENT_VMETHOD_INTERPOSE ( buildingplan_room_hook , render ) ;
static command_result buildingplan_cmd ( color_ostream & out , vector < string > & parameters )
static command_result buildingplan_cmd ( color_ostream & out , vector < string > & parameters )
{
{
@ -624,10 +638,14 @@ DFhackCExport command_result plugin_enable(color_ostream &out, bool enable)
if ( enable ! = is_enabled )
if ( enable ! = is_enabled )
{
{
planner . reset ( out ) ;
planner . reset ( ) ;
if ( ! INTERPOSE_HOOK ( buildingplan_hook , feed ) . apply ( enable ) | |
if ( ! INTERPOSE_HOOK ( buildingplan_query_hook , feed ) . apply ( enable ) | |
! INTERPOSE_HOOK ( buildingplan_hook , render ) . apply ( enable ) )
! INTERPOSE_HOOK ( buildingplan_place_hook , feed ) . apply ( enable ) | |
! INTERPOSE_HOOK ( buildingplan_room_hook , feed ) . apply ( enable ) | |
! INTERPOSE_HOOK ( buildingplan_query_hook , render ) . apply ( enable ) | |
! INTERPOSE_HOOK ( buildingplan_place_hook , render ) . apply ( enable ) | |
! INTERPOSE_HOOK ( buildingplan_room_hook , render ) . apply ( enable ) )
return CR_FAILURE ;
return CR_FAILURE ;
is_enabled = enable ;
is_enabled = enable ;
@ -640,7 +658,7 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <Plug
{
{
commands . push_back (
commands . push_back (
PluginCommand (
PluginCommand (
" buildingplan " , " Pla ce furniture before it's built " ,
" buildingplan " , " Pla n building construction before you have materials " ,
buildingplan_cmd , false , " Run 'buildingplan debug [on|off]' to toggle debugging, or 'buildingplan version' to query the plugin version. " ) ) ;
buildingplan_cmd , false , " Run 'buildingplan debug [on|off]' to toggle debugging, or 'buildingplan version' to query the plugin version. " ) ) ;
planner . initialize ( ) ;
planner . initialize ( ) ;
@ -651,7 +669,7 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
{
{
switch ( event ) {
switch ( event ) {
case SC_MAP_LOADED :
case SC_MAP_LOADED :
planner . reset ( out ) ;
planner . reset ( ) ;
roomMonitor . reset ( out ) ;
roomMonitor . reset ( out ) ;
break ;
break ;
default :
default :
@ -661,13 +679,17 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
return CR_OK ;
return CR_OK ;
}
}
static bool cycle_requested = false ;
# define DAY_TICKS 1200
# define DAY_TICKS 1200
DFhackCExport command_result plugin_onupdate ( color_ostream & )
DFhackCExport command_result plugin_onupdate ( color_ostream & )
{
{
if ( Maps : : IsValid ( ) & & ! World : : ReadPauseState ( ) & & world - > frame_counter % ( DAY_TICKS / 2 ) = = 0 )
if ( Maps : : IsValid ( ) & & ! World : : ReadPauseState ( )
& & ( cycle_requested | | world - > frame_counter % ( DAY_TICKS / 2 ) = = 0 ) )
{
{
planner . doCycle ( ) ;
planner . doCycle ( ) ;
roomMonitor . doCycle ( ) ;
roomMonitor . doCycle ( ) ;
cycle_requested = false ;
}
}
return CR_OK ;
return CR_OK ;
@ -680,8 +702,11 @@ DFhackCExport command_result plugin_shutdown(color_ostream &)
// Lua API section
// Lua API section
static bool isPlannableBuilding ( df : : building_type type ) {
static bool isPlannableBuilding ( df : : building_type type ,
return planner . isPlannableBuilding ( type ) ;
int16_t subtype ,
int32_t custom ) {
return planner . isPlannableBuilding (
toBuildingTypeKey ( type , subtype , custom ) ) ;
}
}
static void addPlannedBuilding ( df : : building * bld ) {
static void addPlannedBuilding ( df : : building * bld ) {
@ -692,9 +717,14 @@ static void doCycle() {
planner . doCycle ( ) ;
planner . doCycle ( ) ;
}
}
static void scheduleCycle ( ) {
cycle_requested = true ;
}
DFHACK_PLUGIN_LUA_FUNCTIONS {
DFHACK_PLUGIN_LUA_FUNCTIONS {
DFHACK_LUA_FUNCTION ( isPlannableBuilding ) ,
DFHACK_LUA_FUNCTION ( isPlannableBuilding ) ,
DFHACK_LUA_FUNCTION ( addPlannedBuilding ) ,
DFHACK_LUA_FUNCTION ( addPlannedBuilding ) ,
DFHACK_LUA_FUNCTION ( doCycle ) ,
DFHACK_LUA_FUNCTION ( doCycle ) ,
DFHACK_LUA_FUNCTION ( scheduleCycle ) ,
DFHACK_LUA_END
DFHACK_LUA_END
} ;
} ;