Okay, theoretically-working script:
-- Makes all werebeasts that are loaded insane
for _,unit in ipairs(df.global.world.units.all) do
-- Get the historical figure
for _,generalRef in ipairs(unit.general_refs) do
if getmetatable(generalRef)=="general_ref_is_nemesisst" then
local nemesis = df.global.world.nemesis.all[generalRef.nemesis_id]
if nemesis.figure.info.curse then
for _,active_interaction in ipairs(nemesis.figure.info.curse.active_interactions) do
if string.find(active_interaction.name,"WEREBEAST") then
-- This is a werecreature
-- Select one of the three proper "insane" moods
unit.mood = math.random(3) + 4 -- 5, 6, or 7
end
end
end
end
end
end
When saved to a .lua file in the hack/scripts directory, then invoked, it will make all cursed creatures on the map insane.
Goatmaan: The central question is if turning cures insanity. This can be tested by cursing an insane dwarf (hard to do safely), or by insanifying a cursed dwarf (which the script above does).
Like I said earlier, I highly doubt that the werebeast turning will actually fix insanity. The reason is simple: the insanity is stored somewhere away from the curse and the body.
All loaded units are in memory, and listed through vector<unit*> global.world.units.all. Each unit contains a few fields, like unit.T_body unit::body (which is the actual body the unit is using, containing things like injuries), mood_type unit::mood (which determines the current strange mood, insanity form, or if the unit is a baby), and, somewhere in vector<general_ref*> unit::general_refs, a general_ref_is_nemesisst with a int32_t ::nemesis_id, referring to the actual historical figure. That is used as an index into vector<nemesis_record*> global.world.nemesis.all, and then the curse details are stored at historical_figure_info.T_curse nemesis_record::figure.info.curse.
In other words, all units (being entries in the Units list) store a body, insanity value, and reference to their historical figure (if applicable). The historical figure holds curse details, and the body holds stuff like the creature's actual body. I believe the werecreature turning creates a new body for the unit, which would only affect the body; the insanity isn't part of the body, so it wouldn't be affected.