ok so after intense testing and rage, and stress I finally got around to a mostly some what stable version of warmist's tofort with viewscreen switching implementation.
ok so mapedge-z is used for when you're exploring the world and to prevent shifting to a site and noticing all the visitors are now underground due to being in a higher location than the last time you used the tofort(as tofort only fills in the map edge once and stops once it checks to see it's filled)
-- changes from advmode to fort safely and back (hopefully)
--[[Now to warn you about saving and loading in either game mode might lead
to some side issues, for saving in fort mode switching to adv mode needs the adv to be `bodyswap`
back in again. for Saving in Adv to switch to Fort mode you probably be safe-ish if the site.
isn't a nano fort or a site that isn't 3x3 small. otherwise the game will try to resize the map.
oh and switching to fort mode on any pre-gen site larger than 4x4 might implode one pc if
you don't have like 20 gigs of memory for the 16x16 embark size.]]--
if df.global.gamemode==df.game_mode.ADVENTURE then
local adv=df.global.world.units.active[0]
local comp={}
local ui=df.global.ui
function advGlobalPos()
local wd=df.global.world.world_data
return wd.adv_region_x*16+wd.adv_emb_x,wd.adv_region_y*16+wd.adv_emb_y
end
--[[function inSite()
local tx,ty=advGlobalPos()
for k,v in pairs(df.global.world.world_data.sites) do
local tp={v.pos.x,v.pos.y}
if tx>=tp[1]*16+v.rgn_min_x and tx<=tp[1]*16+v.rgn_max_x and
ty>=tp[2]*16+v.rgn_min_y and ty<=tp[2]*16+v.rgn_max_y then
return v
end
end
end]]--
function inSite()
local tx,ty=advGlobalPos()
for k,v in pairs(df.global.world.world_data.sites) do
local tp2={v.global_min_x, v.global_min_y, v.global_max_x, v.global_max_y}
if tx>=tp2[1] and tx<=tp2[3] and
ty>=tp2[2] and ty<=tp2[4] then
return v
end
end
end
local site=inSite()
if site==nil then
qerror("No site you are in found.")
end
local nomad={}
local h_ent
if ui.main.fortress_entity~=nil or ui.main.fortress_site~=nil then
ui.main.fortress_entity=nil
ui.main.fortress_site=nil
end
--[[for k,v in pairs(df.global.world.history.figures[adv.hist_figures_id].entity_links) do
if v==df.histfig_entity_link_positionst then
nomad=v.entity_id
break
end
end]]--
for k,v in pairs(df.global.world.history.figures[adv.hist_figure_id].entity_links) do
if v~=histfig_entity_link_memberst and not v==nil then
nomad=df.global.world.entities.all[v.entity_id]
print(v.entity_id)
else if v==histfig_entity_link_memberst then
nomad=df.global.world.history.figures[adv.hist_figure_id].entity_links[0]
end
end
end
if ui.main.fortress_entity==nil then
for k,v in pairs(df.global.world.entities.all) do
--if v.type==df.historical_entity_type.SiteGovernment and v.id==nomad.id then --maybe match race too?
if v.id==nomad.id then --maybe match race too?
if nomad.positions.own==nil then
break else
h_ent=v
break
end
end
if v.id~=nomad.id then
if v.type==df.historical_entity_type.SiteGovernment then
h_ent=v
end
end
end
if h_ent==nil then
qerror("Valid historical entity not found. sorry...")
end
ui.main.fortress_entity=h_ent
else
h_ent=ui.main.fortress_entity
end
function cleardesignate(adv)
local adv=df.global.world.units.active[0]
df.global.ui.main.mode=10
df.global.selection_rect.start_x=0
df.global.selection_rect.start_y=0
df.global.selection_rect.start_z=610
df.global.selection_rect.end_x=-14300
df.global.selection_rect.end_y=9000
df.global.selection_rect.end_z=0
df.global.cursor.x=400
df.global.cursor.y=400
df.global.cursor.z=0
dfhack.gui.getCurViewscreen():feed_key(1)
df.global.cursor.x=adv.pos.x
df.global.cursor.y=adv.pos.y
df.global.cursor.z=adv.pos.z
dfhack.gui.getCurViewscreen():feed_key(1)
dfhack.run_command('revflood')
end
local carter={}
function addToEntity(entity,unit,addtoLead)
local nem=dfhack.units.getNemesis(unit)
local hfig=nem.figure
for k,v in pairs(hfig.entity_links) do
--print(v.entity_id,entity.id)
if v.entity_id==entity.id then break else
carter=true
end
end
if carter==true then
hfig.entity_links:insert("#",{new=df.histfig_entity_link_memberst,entity_id=entity.id,link_strength=100})
entity.nemesis_ids:insert("#",nem.id)
entity.nemesis:insert("#",nem)
entity.histfig_ids:insert("#",hfig.id)
entity.hist_figures:insert("#",hfig)
end
if addtoLead then
local lead_id
for k,v in pairs(entity.positions.own) do
if v.flags.IS_LEADER==true then
lead_id=v.id
break
end
end
if lead_id~=nil then
for k,v in pairs(entity.positions.assignments) do
if v.position_id==lead_id then
v.histfig=hfig.id
break
end
end
end
end
end
ui.civ_id=adv.civ_id
ui.race_id=adv.race
--[[for kui,vra in pairs(ui.unk_races) do
if vra~=nil then
print=("hey does this work")
vra:insert("#", ui.race_id)
--df.global.ui.unk_races:insert("#",adv.race)
else
break
end
end]]--
df.global.pause_state=true
ui.unk_races:insert("#",adv.race)
--if ui.unk_races==0 then ui.unk_races:insert("#",adv.race) end
ui.site_id=site.id
if ui.main.fortress_site==nil then ui.main.fortress_site=site end
--if site.entity_links==nil then site.entity_links:insert("#", {new=true, df.entity_site_link, target=site.id, entity_id=ui.fortress_entity.id, flags[0]=true, flags[5]=true }) end end
if site.entity_links==nil then site.entity_links:insert("#", {new=true, df.entity_site_link, target=site.id, entity_id=ui.fortress_entity.id,entity_site_link_flags.residence, entity_site_link_flags.trade_partner }) end
--if site.entity_links==nil then site.entity_links:insert("#", {new=true, df.entity_site_link, target=site.id, entity_id=ui.fortress_entity.id}) end
ui.group_id=h_ent.id
ui.game_state=2
if #ui.tasks.discovered_plants==0 then
df.global.ui.tasks.discovered_plants:insert("#",0)
df.global.ui.tasks.discovered_plant_foods:insert("#",0)
end
if #ui.alerts.list==0 then
ui.alerts.list:insert("#",{new=true,name="Dummy alert"})
ui.alerts.next_id=1
end
local nem2=dfhack.units.getNemesis(adv)
local hfig2=nem2.figure
local nomad2=hfig2.entity_links[0]
local nomad3=hfig2.entity_links
local Test={}
for co2,mp2 in pairs(nomad3) do
--print(mp2.entity_id,h_ent.id)
if mp2.entity_id~=h_ent.id then Test=true else
Test=false
end
end
if Test==true then
addToEntity(h_ent,adv,true)
end
for co,mp in pairs(df.global.world.units.active) do
if mp.relationship_ids.GroupLeader==adv.id then
local comp=mp
if test==true then
addToEntity(h_ent,comp,false)
end
end
end
function sigh()
mapcheck()
for k,v in pairs(df.global.ui.unk_mapedge_x) do
df.global.ui.unk_mapedge_x[k]=adv.pos.x
df.global.ui.unk_mapedge_y[k]=adv.pos.y
df.global.ui.unk_mapedge_z[k]=adv.pos.z
end
for k,v in pairs(df.global.ui.map_edge.surface_z) do
df.global.ui.map_edge.surface_z[k]=adv.pos.z
--v=152
end
end
function mapcheck()
for k,v in pairs(df.global.ui.unk2a8c[0]) do
if v.unk1==0 then
v.unk1=12
v.unk2=12
end
if df.global.ui.unk_mapedge_x~=nil then
df.global.ui.unk_mapedge_x:insert("#","0")
df.global.ui.unk_mapedge_y:insert("#","0")
df.global.ui.unk_mapedge_z:insert("#","0")
df.global.ui.map_edge.surface_x:insert("#","0")
df.global.ui.map_edge.surface_y:insert("#","0")
df.global.ui.map_edge.surface_z:insert("#","0")
for _,Lay in pairs(df.global.ui.map_edge.layer_x) do
Lay:insert("#","0")
end
for _,Lay in pairs(df.global.ui.map_edge.layer_y) do
Lay:insert("#","0")
end
for _,Lay in pairs(df.global.ui.map_edge.layer_z) do
Lay:insert("#","0")
end
end
end
end
Tab={}
Tab2={}
for k,Lay2 in pairs(df.global.ui.map_edge.layer_z) do
for k2,Lay3 in pairs(df.global.ui.unk2a8c[0]) do
if k then break else
Tab:insert("#",k)
end
Tab2:insert("#",k2)
return Tab,Tab2
end
end
if #df.global.ui.map_edge.layer_z[0] == 0 then
print("map edge empty proceed to fill")
sigh()
else
print("welp map edge currently full")
end
if #ui.kitchen.item_types==0 then
ui.kitchen.item_types:insert("#",0)
ui.kitchen.item_subtypes:insert("#",0)
ui.kitchen.mat_types:insert("#",0)
ui.kitchen.mat_indices:insert("#",0)
ui.kitchen.exc_types:insert("#",0)
end
--fix training info
if h_ent.training_knowledge == nil then
h_ent.training_knowledge={new=true}
end
df.global.gamemode=df.game_mode.DWARF
df.global.gametype=df.game_type.DWARF_MAIN
if df.global.gview.view.child.child==nil then df.global.gview.view.child=df.viewscreen_dwarfmodest:new()
df.global.gview.view.child.parent=df.global.gview.view
end
cleardesignate()
print("Mode change complete.")
else
local adv=dfhack.gui.getSelectedUnit(true)
if adv then
--swap units...
end
df.global.gamemode=df.game_mode.ADVENTURE
df.global.gametype=df.game_type.ADVENTURE_MAIN
df.global.gview.view.child=df.viewscreen_dungeonmodest:new()
df.global.gview.view.child.parent=df.global.gview.view
print("Mode change complete.")
end
ok so with this modified script of warmist's old tofort script you can probably safely* switch between adv mode and fort mode.
*so far from what I tested be advise to back up any saves when using any of my scripts. if I remember you probably shouldn't have advfort active while running this or it will throw a monkey wrench into the script and you need to re-run it again to get it to work properly.
hope folks have fun with this more than the tireless testing I had to go through.
edit 2: ok so went back and edited the script after figuring out a way to do mapedges so the latest version has migrant and visitor support... kinda but it also kinda bloaty and set to camp size for the map edge so I don't know how well this would work on different map sizes.
oh probably best to set up a fort and or camp at a location that is flat and even as I haven't sanity check for all zlevel surfaces