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