· 5 years ago · Feb 21, 2020, 02:48 PM
1-- Create gods from the command-line
2--based on moddableGods by Putnam
3--edited by expwnent
4
5--example: modtools/moddable-gods -name "TEST11" -depictedAs "GECKO_LEOPARD" -domain "TEST1" -description "TEST2" -gender "MALE" -spheres [ ART CRAFTS ]
6
7local usage = [====[
8
9modtools/moddable-gods
10======================
11This is a standardized version of Putnam's moddableGods script. It allows you
12to create gods on the command-line.
13
14Arguments::
15
16 -name godName
17 sets the name of the god to godName
18 if there's already a god of that name, the script halts
19 -spheres [ sphereList ]
20 define a space-separated list of spheres of influence of the god
21 -depictedAs str
22 often depicted as a str
23 -domain str
24 set the domain of the god
25 -description str
26 set the description of the god
27
28]====]
29
30function getRaceCasteIDs(raceStr, casteStr)
31-- Takes a race name and a caste name and returns the appropriate race and caste IDs.
32-- Returns a table of valid caste IDs if casteStr is omitted.
33 if not raceStr then
34 qerror("Race not specified!")
35 end
36 local race
37 local raceIndex
38 for i,c in ipairs(df.global.world.raws.creatures.all) do
39 if c.creature_id == raceStr then
40 race = c
41 raceIndex = i
42 break
43 end
44 end
45 if not race then
46 qerror('Invalid race: ' .. raceStr)
47 end
48
49 local casteIndex
50 local caste_id_choices = {}
51 if casteStr then
52 for i,c in ipairs(race.caste) do
53 if c.caste_id == casteStr then
54 casteIndex = i
55 break
56 end
57 end
58 if not casteIndex then
59 qerror('Invalid caste: ' .. casteStr)
60 end
61 else
62 for i,c in ipairs(race.caste) do
63 table.insert(caste_id_choices, i)
64 end
65 end
66
67 return raceIndex, casteIndex, caste_id_choices
68end
69
70local utils = require 'utils'
71
72local validArgs = utils.invert({
73 'help',
74 'name',
75 'spheres',
76 'gender',
77 'depictedAs',
78 'domain',
79 'description',
80-- 'entities',
81})
82local args = utils.processArgs({...}, validArgs)
83
84if args.help then
85 print(usage)
86 return
87end
88
89if not args.name or not args.depictedAs or not args.spheres or not args.gender then
90 error('All arguments must be specified.')
91end
92
93local templateGod
94for _,fig in ipairs(df.global.world.history.figures) do
95 if fig.flags.deity then
96 templateGod = fig
97 break
98 end
99end
100if not templateGod then
101 error 'Could not find template god.'
102end
103
104local gender
105if args.gender == 'MALE' then
106 gender = 1
107elseif args.gender == 'FEMALE' then
108 gender = 0
109else
110 error 'invalid gender'
111end
112
113for _,fig in ipairs(df.global.world.history.figures) do
114 if fig.name.first_name == args.name then
115 print('god ' .. args.name .. ' already exists. Skipping')
116 return
117 end
118end
119
120local godFig = df.historical_figure:new()
121godFig.appeared_year = -1
122godFig.born_year = -1
123godFig.born_seconds = -1
124godFig.curse_year = -1
125godFig.curse_seconds = -1
126godFig.old_year = -1
127godFig.old_seconds = -1
128godFig.died_year = -1
129godFig.died_seconds = -1
130godFig.name.has_name = true
131godFig.breed_id = -1
132godFig.flags:assign(templateGod.flags)
133godFig.id = df.global.hist_figure_next_id
134df.global.hist_figure_next_id = 1+df.global.hist_figure_next_id
135godFig.info = df.historical_figure_info:new()
136godFig.info.spheres = {new=true}
137godFig.info.secret = df.historical_figure_info.T_secret:new()
138
139godFig.sex = gender
140local race = getRaceCasteIDs(args.depictedAs,args.gender)
141godFig.race = race
142godFig.name.first_name = args.name
143for _,sphere in ipairs(args.spheres) do
144 godFig.info.spheres:insert('#',df.sphere_type[sphere])
145end
146df.global.world.history.figures:insert('#',godFig)