Skip to content

Instantly share code, notes, and snippets.

@warmist
Created January 26, 2015 20:28
Show Gist options
  • Save warmist/5ad711fd1e2e75743bd4 to your computer and use it in GitHub Desktop.
Save warmist/5ad711fd1e2e75743bd4 to your computer and use it in GitHub Desktop.
--thrown cages now capture units.
local eventful=require "plugins.eventful"
function remove_unit_from_map(unit)
local pos=copyall(unit.pos)
local d,occupancy=dfhack.maps.getTileFlags(pos)
if not unit.flags1.on_ground then occupancy.unit = false else occupancy.unit_grounded = false end
end
function cage_unit(cage,unit)
unit.flags1.caged=true
unit.general_refs:insert("#",{new=df.general_ref_contained_in_itemst,item_id=cage.id})
cage.general_refs:insert("#",{new=df.general_ref_contains_unitst,unit_id=unit.id})
remove_unit_from_map(unit)
unit.flags1.on_ground=false
end
function same_pos(p1,p2 )
return p1.z==p2.z and p1.x==p2.x and p1.y==p2.y
end
function find_unit(pos)
for i,v in ipairs(df.global.world.units.active) do
if same_pos(pos,v.pos) then --v.flags1.on_ground for some reason does not work...
return v
end
end
end
eventful.onProjItemCheckImpact.pokeball=function(projectile)
local item=projectile.item
local pos=copyall(projectile.cur_pos)
if item:getType()==df.item_type.CAGE then
if dfhack.items.getGeneralRef(item,df.general_ref_type.CONTAINS_UNIT) then --only empty cage pls
return
end
local u=find_unit(pos)
if u then
cage_unit(item,u)
return
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment