2014-07-03 14:33:26 -06:00
|
|
|
-- scripts/modtools/force.lua
|
2014-06-26 06:36:57 -06:00
|
|
|
-- author Putnam
|
|
|
|
-- edited by expwnent
|
|
|
|
-- Forces an event.
|
2015-10-23 17:57:04 -06:00
|
|
|
--[[=begin
|
2014-06-26 06:36:57 -06:00
|
|
|
|
2015-10-23 17:57:04 -06:00
|
|
|
modtools/force
|
|
|
|
==============
|
2016-03-04 11:22:19 -07:00
|
|
|
This tool triggers events like megabeasts, caravans, and migrants.
|
2015-10-23 17:57:04 -06:00
|
|
|
|
|
|
|
=end]]
|
2014-06-30 02:06:25 -06:00
|
|
|
local utils = require 'utils'
|
|
|
|
|
2014-06-26 06:36:57 -06:00
|
|
|
local function findCiv(arg)
|
|
|
|
local entities = df.global.world.entities.all
|
|
|
|
if tonumber(arg) then return arg end
|
2015-02-14 20:53:06 -07:00
|
|
|
if arg then
|
2014-06-26 06:36:57 -06:00
|
|
|
for eid,entity in ipairs(entities) do
|
|
|
|
if entity.entity_raw.code == arg then return entity end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2014-06-30 22:55:52 -06:00
|
|
|
validArgs = validArgs or utils.invert({
|
|
|
|
'eventType',
|
|
|
|
'help',
|
|
|
|
'civ'
|
|
|
|
})
|
|
|
|
|
|
|
|
local args = utils.processArgs({...}, validArgs)
|
2014-06-30 02:06:25 -06:00
|
|
|
if next(args) == nil or args.help then
|
2014-07-03 14:33:26 -06:00
|
|
|
print([[force usage
|
|
|
|
arguments:
|
2014-07-09 04:21:52 -06:00
|
|
|
-help
|
|
|
|
print this help message
|
2014-07-03 14:33:26 -06:00
|
|
|
-eventType event
|
|
|
|
specify the type of the event to trigger
|
|
|
|
examples:
|
|
|
|
MegaBeast
|
|
|
|
Migrants
|
|
|
|
Caravan
|
|
|
|
Diplomat
|
|
|
|
WildlifeCurious
|
|
|
|
WildlifeMischievous
|
|
|
|
WildlifeFlier
|
|
|
|
NightCreature
|
|
|
|
-civ entity
|
|
|
|
specify the civ of the event, if applicable
|
|
|
|
examples:
|
|
|
|
player
|
|
|
|
MOUNTAIN
|
|
|
|
EVIL
|
|
|
|
28
|
|
|
|
]])
|
2016-03-04 11:22:19 -07:00
|
|
|
print('force: -eventType [Megabeast, Migrants, Caravan, Diplomat, WildlifeCurious, WildlifeMischievous, WildlifeFlier, NightCreature] -civ [player,ENTITY_ID]')
|
2014-06-30 02:06:25 -06:00
|
|
|
return
|
2014-06-26 06:36:57 -06:00
|
|
|
end
|
|
|
|
|
2014-06-30 02:06:25 -06:00
|
|
|
if not args.eventType then
|
|
|
|
error 'Specify an eventType.'
|
|
|
|
elseif not df.timed_event_type[args.eventType] then
|
|
|
|
error('Invalid eventType: ' .. args.eventType)
|
2014-06-26 06:36:57 -06:00
|
|
|
end
|
|
|
|
|
2014-06-30 02:06:25 -06:00
|
|
|
if args.civ == 'player' then
|
|
|
|
args.civ = df.historical_entity.find(df.global.ui.civ_id)
|
|
|
|
elseif args.civ then
|
2016-03-04 11:22:19 -07:00
|
|
|
local civ = args.civ
|
2014-06-30 02:06:25 -06:00
|
|
|
args.civ = findCiv(args.civ)
|
2016-03-04 11:22:19 -07:00
|
|
|
if not args.civ then
|
|
|
|
error('Invalid civ: ' .. civ)
|
|
|
|
end
|
|
|
|
elseif args.eventType == 'Caravan' or args.eventType == 'Diplomat' then
|
|
|
|
error('Specify civ for this eventType')
|
2014-06-26 06:36:57 -06:00
|
|
|
end
|
|
|
|
|
2014-06-30 02:06:25 -06:00
|
|
|
if args.eventType == 'Migrants' then
|
|
|
|
args.civ = df.historical_entity.find(df.global.ui.civ_id)
|
2014-06-26 06:36:57 -06:00
|
|
|
end
|
2014-06-30 02:06:25 -06:00
|
|
|
|
|
|
|
local timedEvent = df.timed_event:new()
|
|
|
|
timedEvent['type'] = df.timed_event_type[args.eventType]
|
|
|
|
timedEvent.season = df.global.cur_season
|
|
|
|
timedEvent.season_ticks = df.global.cur_season_tick
|
|
|
|
if args.civ then
|
|
|
|
timedEvent.entity = args.civ
|
2014-06-26 06:36:57 -06:00
|
|
|
end
|
|
|
|
|
2014-06-30 02:06:25 -06:00
|
|
|
df.global.timed_events:insert('#', timedEvent)
|
|
|
|
|