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 -- edited by expwnent
-- Forces an event. -- Forces an event.
local utils = require 'utils'
local function findCiv(arg) local function findCiv(arg)
local entities = df.global.world.entities.all local entities = df.global.world.entities.all
if tonumber(arg) then return arg end if tonumber(arg) then return arg end
@ -14,71 +16,35 @@ local function findCiv(arg)
return nil return nil
end end
local args = {...} local args = utils.processArgs(...)
if next(args) == nil or args.help then
if not args or not args[1] then print('force: -eventType [Megabeast, Migrants, Caravan, Diplomat, WildlifeCurious, WildlifeMischievous, WildlifeFlier, CivAttack, NightCreature] -civ [player,ENTITY_ID]')
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.') return
end end
local eventType = string.lower(args[1]) if not args.eventType then
error 'Specify an eventType.'
forceEntity = args[2]=="player" and df.historical_entity.find(df.global.ui.civ_id) or findCiv(args[2]) elseif not df.timed_event_type[args.eventType] then
error('Invalid eventType: ' .. args.eventType)
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.')
end end
local function eventTypeIsNotValid() if args.civ == 'player' then
local eventTypes = { args.civ = df.historical_entity.find(df.global.ui.civ_id)
"caravan", elseif args.civ then
"migrants", args.civ = findCiv(args.civ)
"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
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.')
end end
allEventTypes={} if args.eventType == 'Migrants' then
allEventTypes["megabeast"]=function() args.civ = df.historical_entity.find(df.global.ui.civ_id)
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 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 } ) local timedEvent = df.timed_event:new()
end timedEvent['type'] = df.timed_event_type[args.eventType]
allEventTypes["curious"]=function() timedEvent.season = df.global.cur_season
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 } ) timedEvent.season_ticks = df.global.cur_season_tick
end if args.civ then
allEventTypes["mischevousbeast"]=function() timedEvent.entity = args.civ
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 } )
end end
allEventTypes[eventType]() df.global.timed_events:insert('#', timedEvent)