-
Notifications
You must be signed in to change notification settings - Fork 194
/
force.lua
58 lines (50 loc) · 1.53 KB
/
force.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
local wildlife = reqscript('fix/wildlife')
local function findCiv(civ)
if civ == 'player' then return df.historical_entity.find(df.global.plotinfo.civ_id) end
if tonumber(civ) then return df.historical_entity.find(tonumber(civ)) end
civ = string.lower(tostring(civ))
for _,entity in ipairs(df.global.world.entities.all) do
if string.lower(entity.entity_raw.code) == civ then return entity end
end
end
local args = { ... }
if #args < 1 then qerror('missing event type') end
if args[1]:find('help') then
print(dfhack.script_help())
return
end
local eventType = args[1]:upper()
-- handle synthetic events
if eventType == 'WILDLIFE' then
wildlife.free_all_wildlife(args[2] == 'all')
return
end
-- handle native events
for _, type in ipairs(df.timed_event_type) do
if type:lower() == args[1]:lower() then
eventType = type
end
end
if not df.timed_event_type[eventType] then
qerror('unknown event type: ' .. args[1])
end
if eventType == 'FeatureAttack' then
qerror('Event type: FeatureAttack is not currently supported')
end
local civ
if eventType == 'Caravan' or eventType == 'Diplomat' then
civ = findCiv(args[2] or 'player')
if not civ then
qerror('unable to find civilization: '..tostring(civ))
end
elseif eventType == 'Migrants' then
civ = findCiv('player')
end
df.global.timed_events:insert('#', {
new=true,
type=df.timed_event_type[eventType],
season=df.global.cur_season,
season_ticks=df.global.cur_season_tick,
entity=civ,
feature_ind=-1,
})