Skip to content

Instantly share code, notes, and snippets.

@warmist
Last active June 10, 2022 13:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save warmist/4198190 to your computer and use it in GitHub Desktop.
Save warmist/4198190 to your computer and use it in GitHub Desktop.
Switch to fort mode
-- changes from advmode to fort safely (hopefully)
if df.global.gamemode==df.game_mode.ADVENTURE then
local adv=df.global.world.units.active[0]
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
local site=inSite()
if site==nil then
qerror("No site you are in found.")
end
local h_ent
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 then --maybe match race too?
h_ent=v
break
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 addToEntity(entity,unit,addtoLead)
local nem=dfhack.units.getNemesis(unit)
local hfig=nem.figure
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)
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
ui.site_id=site.id
ui.group_id=h_ent.id
ui.game_state=2
addToEntity(h_ent,adv,true)
if #ui.alerts.list==0 then
ui.alerts.list:insert("#",{new=true,name="Dummy alert"})
ui.alerts.next_id=1
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
local screen=df.viewscreen_dwarfmodest:new()
dfhack.screen.show(screen,dfhack.gui.getCurViewscreen())
dfhack.screen.dismiss(dfhack.gui.getCurViewscreen())
print("Mode change complete. Now save and load")
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
local screen=df.viewscreen_dungeonmodest:new()
dfhack.screen.show(screen,dfhack.gui.getCurViewscreen())
dfhack.screen.dismiss(dfhack.gui.getCurViewscreen())
print("Mode change complete. Now save and load")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment