Skip to content

Instantly share code, notes, and snippets.

@warmist
Created September 19, 2012 20:50
Show Gist options
  • Save warmist/3752176 to your computer and use it in GitHub Desktop.
Save warmist/3752176 to your computer and use it in GitHub Desktop.
Add raws to entity
function getMyEntity()
return df.historical_entity.find(df.global.ui.group_id)
end
function getWorkshopId(token)
for k,v in pairs(df.global.world.raws.buildings.all) do
if token==v.code then
return v.id
end
end
end
function getReactionId(token)
for k,v in pairs(df.global.world.raws.reactions) do
if token==v.code then
return v.index
end
end
end
function addPermittedBuilding(entity,token)
entity.entity_raw.workshops.permitted_building_id:insert("#",getWorkshopId(token))
end
function addPermittedReaction(entity,token)
entity.entity_raw.workshops.permitted_reaction_id:insert("#",getReactionId(token))
end
function addPermits(entity,buildings,reactions)
entity=entity or getMyEntity()
for _,v in ipairs(buildings or {}) do
addPermittedBuilding(entity,v)
end
for _,v in ipairs(reactions or {}) do
addPermittedReaction(entity,v)
end
end
addPermits(nil,{"STEAM_ENGINE","MAGMA_STEAM_ENGINE"},{"STOKE_BOILER"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment