Skip to content

Instantly share code, notes, and snippets.

@Putnam3145
Created April 15, 2022 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Putnam3145/c3183342e7589a20bd59a450ca9074e5 to your computer and use it in GitHub Desktop.
Save Putnam3145/c3183342e7589a20bd59a450ca9074e5 to your computer and use it in GitHub Desktop.
Gives statistics regarding relationships in worldgen (how many people had relationships at all, how many are hetero, how many are homo, and so on)
-- Gives statistical info on the prevalence of homosexual relationships
local help = [====[
gaystats
======
Shows the sexual orientation of all historical figures, as well as whether they took lovers of the same or opposite sex.
Options:
:-allowAllRaces: Checks races with modded orientations, too (by default, it only checks races with default orientation)
]====]
local utils = require('utils')
local validArgs = utils.invert({
'allowAllRaces',
'help'
})
local args = utils.processArgs({...}, validArgs)
if args.help then
print(help)
return
end
local gay = 0
local bi = 0
local straight = 0
local exclusively_hetero = 0
local exclusively_gay = 0
local could_but_not = 0
local could_s_but_not = 0
local never_acted_hetero = 0
local never_acted_homo = 0
local ace = 0
local actually_ace = 0
local mixed = 0
local none = 0
local total = 0
local function has_default_orientation(fig)
local r = df.creature_raw.find(fig.race)
if(not r) then
return false
end
local any_caste_has_sex = false
for _,caste in ipairs(r.caste) do
local same,opposite
local this_caste_has_sex = false
if caste.sex == 0 then
this_caste_has_sex = true
same = caste.orientation_female
opposite = caste.orientation_male
elseif caste.sex == 1 then
this_caste_has_sex = true
same = caste.orientation_male
opposite = caste.orientation_female
end
if this_caste_has_sex then
if same[0] ~= 75 or same[1] ~= 20 or same[2] ~= 5 or opposite[0] ~= 5 or opposite[1] ~= 20 or opposite[2] ~= 75 then
return false
end
end
any_caste_has_sex = any_caste_has_sex or this_caste_has_sex
end
return any_caste_has_sex
end
local function is_any_relationship_type(r)
return r._type == df.histfig_hf_link_spousest or r._type == df.histfig_hf_link_loverst or r._type == df.histfig_hf_link_former_spousest or r._type == df.histfig_hf_link_deceased_spousest
end
local function sexuality(fig)
local o = fig.orientation_flags
local f = 0
if fig.sex == 0 then
if o.romance_male or o.marry_male then
f = f | 1
end
if o.romance_female or o.marry_female then
f = f | 2
end
elseif fig.sex == 1 then
if o.romance_female or o.marry_female then
f = f | 1
end
if o.romance_male or o.marry_male then
f = f | 2
end
end
return f
end
for _,v in ipairs(df.global.world.history.figures) do
if args.allowAllRaces or has_default_orientation(v) then
total = total + 1
local s = sexuality(v)
if s == 0 then
ace = ace + 1
end
if s & 1 == 1 then
straight = straight + 1
end
if s & 2 == 2 then
if s & 1 == 1 then
bi = bi + 1
end
gay = gay + 1
end
local no_hetero = true
local some_homo = false
local any_relationship = false
for _,vv in ipairs(v.histfig_links) do
if is_any_relationship_type(vv) then
local other = df.historical_figure.find(vv.target_hf)
if other then
any_relationship = true
if other.sex == v.sex then
some_homo = true
--print(v.id, other.id, v.sex, other.sex, df.creature_raw.find(v.race).creature_id)
else
no_hetero = false
end
end
end
end
if any_relationship then
if no_hetero then
exclusively_gay = exclusively_gay + 1
if s & 1 == 1 then
could_s_but_not = could_s_but_not + 1
end
elseif not some_homo then
exclusively_hetero = exclusively_hetero + 1
if s & 2 == 2 then
could_but_not = could_but_not + 1
end
else
mixed = mixed + 1
end
else
none = none + 1
if s == 0 then
actually_ace = actually_ace + 1
end
if s & 1 == 1 then
never_acted_hetero = never_acted_hetero + 1
end
if s & 2 == 2 then
never_acted_homo = never_acted_homo + 1
end
end
end
end
print("Hetero figs:", straight-bi)
print("Homo figs:", gay-bi)
print("Bi figs:", bi)
print("Asexual figs:", ace)
print("Figs with only hetero relationships:", exclusively_hetero)
print("Figs with only gay relationships:", exclusively_gay)
print("Figs with both:", mixed)
print("Figs with none:", none)
print("Bi figs who never took a hetero lover, but did take a homo lover:", could_s_but_not)
print("Bi figs who never took a homo lover, but did take a hetero lover:", could_but_not)
print("% of straight/bi who never had a lover:", 100*never_acted_hetero/straight)
print("% of gay/bi who never had a lover:", 100*never_acted_homo/gay)
print("% of ace who never had a lover:", 100*actually_ace/ace)
print("approximate % increase in straight relationships if creatures were exclusively heterosexual:", 100*(((exclusively_hetero+exclusively_gay+mixed+(never_acted_hetero/straight*ace))/(exclusively_hetero+mixed))-1))
print("Total checked:", total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment