-- Create gods from the command-line
--based on moddableGods by Putnam
--edited by expwnent
local usage = [====[

modtools/moddable-gods
======================
This is a standardized version of Putnam's moddableGods script. It allows you
to create gods on the command-line.

Arguments::

    -name godName
        sets the name of the god to godName
        if there's already a god of that name, the script halts
    -spheres [ sphereList ]
        define a space-separated list of spheres of influence of the god
    -depictedAs str
        often depicted as a str
    -domain str
        set the domain of the god
    -description str
        set the description of the god

]====]
local utils = require 'utils'

local validArgs = utils.invert({
 'help',
 'name',
 'spheres',
 'gender',
 'depictedAs',
 'domain',
 'description',
-- 'entities',
})
local args = utils.processArgs({...}, validArgs)

if args.help then
 print(usage)
 return
end

if not args.name or not args.depictedAs or not args.domain or not args.description or not args.spheres or not args.gender then
 error('All arguments must be specified.')
end

local templateGod
for _,fig in ipairs(df.global.world.history.figures) do
 if fig.flags.deity then
  templateGod = fig
  break
 end
end
if not templateGod then
 error 'Could not find template god.'
end

local gender
if args.gender == 'male' then
 gender = 1
elseif args.gender == 'female' then
 gender = 0
else
 error 'invalid gender'
end

for _,fig in ipairs(df.global.world.history.figures) do
 if fig.name.first_name == args.name then
  print('god ' .. args.name .. ' already exists. Skipping')
  return
 end
end

local godFig = df.historical_figure:new()
godFig.appeared_year = -1
godFig.born_year = -1
godFig.born_seconds = -1
godFig.curse_year = -1
godFig.curse_seconds = -1
godFig.old_year = -1
godFig.old_seconds = -1
godFig.died_year = -1
godFig.died_seconds = -1
godFig.name.has_name = true
godFig.breed_id = -1
godFig.flags:assign(templateGod.flags)
godFig.id = df.global.hist_figure_next_id
df.global.hist_figure_next_id = 1+df.global.hist_figure_next_id
godFig.info = df.historical_figure_info:new()
godFig.info.spheres = {new=true}
godFig.info.secret = df.historical_figure_info.T_secret:new()

godFig.sex = gender
godFig.name.first_name = args.name
for _,sphere in ipairs(args.spheres) do
 godFig.info.spheres:insert('#',df.sphere_type[sphere])
end
df.global.world.history.figures:insert('#',godFig)


