@@ -131,15 +131,24 @@ local function zoomed_searcher(startn, end_or_sz)
131131end
132132
133133local finder_searches = {}
134- local function exec_finder (finder , names )
134+ local function exec_finder (finder , names , validators )
135135 if type (names ) ~= ' table' then
136136 names = { names }
137137 end
138+ if type (validators ) ~= ' table' then
139+ validators = { validators }
140+ end
138141 local search = force_scan [' all' ]
139- for _ ,v in ipairs (names ) do
142+ for k ,v in ipairs (names ) do
140143 if force_scan [v ] or not is_known (v ) then
141144 table.insert (finder_searches , v )
142145 search = true
146+ elseif validators [k ] then
147+ if not validators [k ](df .global [v ]) then
148+ dfhack .printerr (' Validation failed for ' .. v .. ' , will try to find again' )
149+ table.insert (finder_searches , v )
150+ search = true
151+ end
143152 end
144153 end
145154 if search then
505514
506515local function is_valid_world (world )
507516 if not ms .is_valid_vector (world .units .all , 4 )
517+ or not ms .is_valid_vector (world .units .active , 4 )
508518 or not ms .is_valid_vector (world .units .bad , 4 )
509519 or not ms .is_valid_vector (world .history .figures , 4 )
510520 or not ms .is_valid_vector (world .features .map_features , 4 )
776786--
777787
778788local function find_current_weather ()
779- print (' \n Please load the save previously processed with prepare-save.' )
780- if not utils .prompt_yes_no (' Proceed?' , true ) then
781- return
782- end
783-
784789 local zone
785790 if os_type == ' windows' then
786791 zone = zoomed_searcher (' crime_next_id' , 512 )
@@ -839,7 +844,14 @@ local function find_ui_selected_unit()
839844 end
840845
841846 for i ,unit in ipairs (df .global .world .units .active ) do
842- dfhack .units .setNickname (unit , i )
847+ -- This function does a lot of things and accesses histfigs, souls and so on:
848+ -- dfhack.units.setNickname(unit, i)
849+
850+ -- Instead use just a simple bit of code that only requires the start of the
851+ -- unit to be valid. It may not work properly with vampires or reset later
852+ -- if unpaused, but is sufficient for this script and won't crash:
853+ unit .name .nickname = tostring (i )
854+ unit .name .has_name = true
843855 end
844856
845857 local addr = searcher :find_menu_cursor ([[
@@ -1506,17 +1518,23 @@ print('\nInitial globals (need title screen):\n')
15061518exec_finder (find_gview , ' gview' )
15071519exec_finder (find_cursor , { ' cursor' , ' selection_rect' , ' gamemode' , ' gametype' })
15081520exec_finder (find_announcements , ' announcements' )
1509- exec_finder (find_d_init , ' d_init' )
1510- exec_finder (find_enabler , ' enabler' )
1511- exec_finder (find_gps , ' gps' )
1521+ exec_finder (find_d_init , ' d_init' , is_valid_d_init )
1522+ exec_finder (find_enabler , ' enabler' , is_valid_enabler )
1523+ exec_finder (find_gps , ' gps' , is_valid_gps )
15121524
15131525print (' \n Compound globals (need loaded world):\n ' )
15141526
1515- exec_finder (find_world , ' world' )
1516- exec_finder (find_ui , ' ui' )
1527+ print (' \n Please load the save previously processed with prepare-save.' )
1528+ if not utils .prompt_yes_no (' Proceed?' , true ) then
1529+ searcher :reset ()
1530+ return
1531+ end
1532+
1533+ exec_finder (find_world , ' world' , is_valid_world )
1534+ exec_finder (find_ui , ' ui' , is_valid_ui )
15171535exec_finder (find_ui_sidebar_menus , ' ui_sidebar_menus' )
15181536exec_finder (find_ui_build_selector , ' ui_build_selector' )
1519- exec_finder (find_init , ' init' )
1537+ exec_finder (find_init , ' init' , is_valid_init )
15201538
15211539print (' \n Primitive globals:\n ' )
15221540
0 commit comments