Skip to content

Instantly share code, notes, and snippets.

@warmist
Created November 25, 2012 00:08
Show Gist options
  • Save warmist/4141894 to your computer and use it in GitHub Desktop.
Save warmist/4141894 to your computer and use it in GitHub Desktop.
Make site
function addSiteAtPos(x,y,rgn_x,rgn_y)
rgn_x=rgn_x or math.random(1,15)
rgn_y=rgn_y or math.random(1,15)
--[=[
<angavrilov> global = pos*16 + rgn
<angavrilov> BUT
<angavrilov> for cities global is usually 17x17, i.e. max size
<angavrilov> while rgn designates a small bit in the middle
<angavrilov> for stuff like forts that formula holds exactly
]=]--
local wd=df.global.world.world_data
local nsite=df.world_site:new()
nsite.name.first_name="Warmist's site"
nsite.name.has_name=true
nsite.pos:assign{x=x,y=y}
nsite.rgn_max_x=rgn_x
nsite.rgn_min_x=rgn_x
nsite.rgn_min_y=rgn_y
nsite.rgn_max_y=rgn_y
nsite.global_max_x=nsite.pos.x*16+nsite.rgn_max_x
nsite.global_min_x=nsite.pos.x*16+nsite.rgn_min_x
nsite.global_max_y=nsite.pos.y*16+nsite.rgn_max_y
nsite.global_min_y=nsite.pos.y*16+nsite.rgn_min_y
nsite.id=wd.next_site_id
nsite.type=7 --lair
nsite.flags:resize(23)
--nsite.flags[4]=true
--nsite.flags[5]=true
--nsite.flags[6]=true
nsite.index=#wd.sites+1
wd.sites:insert("#",nsite)
wd.next_site_id=wd.next_site_id+1
--might not be needed...
--[[local unk130=df.world_site_unk130:new()
unk130.index=#wd.site_unk130+1
wd.site_unk130:insert("#",unk130)
--wd.next_site_unk136_id=wd.next_site_unk136_id+1--]]
end
local rg_x,rg_y
rg_x=df.global.world.map.region_x
rg_y=df.global.world.map.region_y
addSiteAtPos(rg_x/16,rg_y/16,rg_x%16,rg_y%16)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment