weather: re-add val_override, minor cleanup

develop
lethosor 2016-01-01 11:46:40 -05:00
parent 81b055ee93
commit 51690b4ba2
1 changed files with 20 additions and 9 deletions

@ -9,26 +9,37 @@ Prints a map of the local weather, or with arguments ``clear``,
=end]] =end]]
local args = {...} local args = {...}
if args[1] == "help" or args[1] == "?" then local cmd
local val_override = tonumber(args[1])
if args[1] then
cmd = args[1]:sub(1, 1)
end
if cmd == "h" or cmd == "?" then
print("The current weather is "..df.weather_type[dfhack.world.ReadCurrentWeather()]) print("The current weather is "..df.weather_type[dfhack.world.ReadCurrentWeather()])
print((helpstr:gsub('=[a-z]+', ''))) print((helpstr:gsub('=[a-z]+', '')))
elseif args[1] == "clear" then elseif cmd == "c" then
dfhack.world.SetCurrentWeather(df.weather_type["None"]) dfhack.world.SetCurrentWeather(df.weather_type.None)
print("The weather has cleared.") print("The weather has cleared.")
elseif args[1] == "rain" then elseif cmd == "r" then
dfhack.world.SetCurrentWeather(df.weather_type["Rain"]) dfhack.world.SetCurrentWeather(df.weather_type.Rain)
print("It is now raining.") print("It is now raining.")
elseif args[1] == "snow" then elseif cmd == "s" then
dfhack.world.SetCurrentWeather(df.weather_type["Snow"]) dfhack.world.SetCurrentWeather(df.weather_type.Snow)
print("It is now snowing.") print("It is now snowing.")
elseif val_override then
dfhack.world.SetCurrentWeather(val_override)
print("Set weather to " .. val_override)
elseif args[1] then
qerror("Unrecognized argument: " .. args[1])
else else
-- df.global.current_weather is arranged in columns, not rows -- df.global.current_weather is arranged in columns, not rows
kind = {[0]="C ", "R ", "S "} kind = {[0]="C", "R", "S"}
print("Weather map (C = clear, R = rain, S = snow):") print("Weather map (C = clear, R = rain, S = snow):")
for y=0, 4 do for y=0, 4 do
s = "" s = ""
for x=0, 4 do for x=0, 4 do
s = s..kind[df.global.current_weather[x][y]] local cur = df.global.current_weather[x][y]
s = s .. (kind[cur] or cur) .. ' '
end end
print(s) print(s)
end end