Made modtools/force use standard argument processing.

develop
expwnent 2014-06-30 04:06:25 -04:00
parent 5811f07a1f
commit cd9abacf34
1 changed files with 25 additions and 59 deletions

@ -3,6 +3,8 @@
-- edited by expwnent
-- Forces an event.
local utils = require 'utils'
local function findCiv(arg)
local entities = df.global.world.entities.all
if tonumber(arg) then return arg end
@ -14,71 +16,35 @@ local function findCiv(arg)
return nil
end
local args = {...}
if not args or not args[1] then
qerror('Needs an argument. Valid arguments are caravan, migrants, diplomat, megabeast, curiousbeast, mischievousbeast, flier, siege and nightcreature. Second argument is civ, either raw entity ID or "player" for player\'s civ.')
local args = utils.processArgs(...)
if next(args) == nil or args.help then
print('force: -eventType [Megabeast, Migrants, Caravan, Diplomat, WildlifeCurious, WildlifeMischievous, WildlifeFlier, CivAttack, NightCreature] -civ [player,ENTITY_ID]')
return
end
local eventType = string.lower(args[1])
forceEntity = args[2]=="player" and df.historical_entity.find(df.global.ui.civ_id) or findCiv(args[2])
if (eventType == "caravan" or eventType == "diplomat" or eventType == "siege") and not forceEntity then
qerror('caravan, diplomat and siege require a civilization ID to be included.')
if not args.eventType then
error 'Specify an eventType.'
elseif not df.timed_event_type[args.eventType] then
error('Invalid eventType: ' .. args.eventType)
end
local function eventTypeIsNotValid()
local eventTypes = {
"caravan",
"migrants",
"diplomat",
"megabeast",
"curiousbeast",
"mischevousbeast",
"mischeviousbeast",
"flier",
"siege",
"nightcreature"
}
for _,v in ipairs(eventTypes) do
if args[1] == v then return false end
end
return true
if args.civ == 'player' then
args.civ = df.historical_entity.find(df.global.ui.civ_id)
elseif args.civ then
args.civ = findCiv(args.civ)
end
--code may be kind of bad below :V Putnam ain't experienced in lua... --Putnam's comment, not mine ~expwnent
if eventTypeIsNotValid() then
qerror('Invalid argument. Valid arguments are caravan, migrants, diplomat, megabeast, curiousbeast, mischievousbeast, flier, siege and nightcreature.')
if args.eventType == 'Migrants' then
args.civ = df.historical_entity.find(df.global.ui.civ_id)
end
allEventTypes={}
allEventTypes["megabeast"]=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.Megabeast, season = df.global.cur_season, season_ticks = df.global.cur_season_tick } )
end
allEventTypes["migrants"]=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.Migrants, season = df.global.cur_season, season_ticks = df.global.cur_season_tick, entity = df.global.world.entities.all[df.global.ui.civ_id] } )
end
allEventTypes["caravan"]=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.Caravan, season = df.global.cur_season, season_ticks = df.global.cur_season_tick, entity = forceEntity } )
end
allEventTypes["diplomat"]=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.Diplomat, season = df.global.cur_season, season_ticks = df.global.cur_season_tick, entity = forceEntity } )
end
allEventTypes["curious"]=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.WildlifeCurious, season = df.global.cur_season, season_ticks = df.global.cur_season_tick } )
end
allEventTypes["mischevousbeast"]=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.WildlifeMichievous, season = df.global.cur_season, season_ticks = df.global.cur_season_tick } )
end
allEventTypes["flier"]=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.WildlifeFlier, season = df.global.cur_season, season_ticks = df.global.cur_season_tick } )
end
allEventTypes["siege"]=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.CivAttack, season = df.global.cur_season, season_ticks = df.global.cur_season_tick, entity = forceEntity } )
end
allEventTypes["nightcreature"]=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.NightCreature, season = df.global.cur_season, season_ticks = df.global.cur_season_tick } )
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
end
allEventTypes[eventType]()
df.global.timed_events:insert('#', timedEvent)