@ -87,6 +87,58 @@ static uint8_t *getExtentTile(df::building_extents &extent, df::coord2d tile)
 
			
		
	
		
		
			
				
					
					    return  & extent . extents [ dx  +  dy * extent . width ] ; 
    return  & extent . extents [ dx  +  dy * extent . width ] ; 
 
			
		
	
		
		
			
				
					
					} }  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					/*
  
			
		
	
		
		
			
				
					
					 *  A  monitor  to  work  around  this  bug ,  in  its  application  to  buildings : 
 
			
		
	
		
		
			
				
					
					 * 
 
			
		
	
		
		
			
				
					
					 *  http : //www.bay12games.com/dwarves/mantisbt/view.php?id=1416
 
 
			
		
	
		
		
			
				
					
					 */ 
 
			
		
	
		
		
			
				
					
					bool  buildings_do_onupdate  =  false ;  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					void  buildings_onStateChange ( color_ostream  & out ,  state_change_event  event )  
			
		
	
		
		
			
				
					
					{  
			
		
	
		
		
			
				
					
					    switch  ( event )  { 
 
			
		
	
		
		
			
				
					
					    case  SC_MAP_LOADED : 
 
			
		
	
		
		
			
				
					
					        buildings_do_onupdate  =  true ; 
 
			
		
	
		
		
			
				
					
					        break ; 
 
			
		
	
		
		
			
				
					
					    case  SC_MAP_UNLOADED : 
 
			
		
	
		
		
			
				
					
					        buildings_do_onupdate  =  false ; 
 
			
		
	
		
		
			
				
					
					        break ; 
 
			
		
	
		
		
			
				
					
					    default : 
 
			
		
	
		
		
			
				
					
					        break ; 
 
			
		
	
		
		
			
				
					
					    } 
 
			
		
	
		
		
			
				
					
					}  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					void  buildings_onUpdate ( color_ostream  & out )  
			
		
	
		
		
			
				
					
					{  
			
		
	
		
		
			
				
					
					    buildings_do_onupdate  =  false ; 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    df : : job_list_link  * link  =  world - > job_list . next ; 
 
			
		
	
		
		
			
				
					
					    for  ( ;  link ;  link  =  link - > next )  { 
 
			
		
	
		
		
			
				
					
					        df : : job  * job  =  link - > item ; 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        if  ( job - > job_type  ! =  job_type : : ConstructBuilding ) 
 
			
		
	
		
		
			
				
					
					            continue ; 
 
			
		
	
		
		
			
				
					
					        if  ( job - > job_items . empty ( ) ) 
 
			
		
	
		
		
			
				
					
					            continue ; 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        buildings_do_onupdate  =  true ; 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        for  ( size_t  i  =  0 ;  i  <  job - > items . size ( ) ;  i + + ) 
 
			
		
	
		
		
			
				
					
					        { 
 
			
		
	
		
		
			
				
					
					            df : : job_item_ref  * iref  =  job - > items [ i ] ; 
 
			
		
	
		
		
			
				
					
					            if  ( iref - > role  ! =  df : : job_item_ref : : Reagent ) 
 
			
		
	
		
		
			
				
					
					                continue ; 
 
			
		
	
		
		
			
				
					
					            df : : job_item  * item  =  vector_get ( job - > job_items ,  iref - > job_item_idx ) ; 
 
			
		
	
		
		
			
				
					
					            if  ( ! item ) 
 
			
		
	
		
		
			
				
					
					                continue ; 
 
			
		
	
		
		
			
				
					
					            // Convert Reagent to Hauled, while decrementing quantity
 
 
			
		
	
		
		
			
				
					
					            item - > quantity  =  std : : max ( 0 ,  item - > quantity - 1 ) ; 
 
			
		
	
		
		
			
				
					
					            iref - > role  =  df : : job_item_ref : : Hauled ; 
 
			
		
	
		
		
			
				
					
					            iref - > job_item_idx  =  - 1 ; 
 
			
		
	
		
		
			
				
					
					        } 
 
			
		
	
		
		
			
				
					
					    } 
 
			
		
	
		
		
			
				
					
					}  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					uint32_t  Buildings : : getNumBuildings ( ) uint32_t  Buildings : : getNumBuildings ( )  
			
		
	
		
		
			
				
					
					{ {  
			
		
	
		
		
			
				
					
					    return  world - > buildings . all . size ( ) ; 
    return  world - > buildings . all . size ( ) ; 
 
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -906,6 +958,8 @@ bool Buildings::constructWithFilters(df::building *bld, std::vector<df::job_item
 
			
		
	
		
		
			
				
					
					            bld - > mat_index  =  items [ i ] - > mat_index ; 
            bld - > mat_index  =  items [ i ] - > mat_index ; 
 
			
		
	
		
		
			
				
					
					    } 
    } 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    buildings_do_onupdate  =  true ; 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    createDesign ( bld ,  rough ) ; 
    createDesign ( bld ,  rough ) ; 
 
			
		
	
		
		
			
				
					
					    return  true ; 
    return  true ; 
 
			
		
	
		
		
			
				
					
					} }  
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -969,3 +1023,4 @@ bool Buildings::deconstruct(df::building *bld)
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    return  true ; 
    return  true ; 
 
			
		
	
		
		
			
				
					
					} }