Implement "weather" as a script

develop
PeridexisErrant 2015-12-04 15:48:15 +09:30 committed by lethosor
parent d923633689
commit 81b055ee93
5 changed files with 39 additions and 153 deletions

@ -65,6 +65,10 @@ Fixes
- `exportlegends`: Handles entities without specific races, and a few other fixes for things new to v0.42
- `showmood`: Fixed name display on OS X/Linux
Misc Improvements
-----------------
- `weather`: now implemented by a script
DFHack 0.40.24-r5
=================

@ -2105,11 +2105,6 @@ Options:
Beware that filling in hollow veins will trigger a demon invasion on top of
your miner when you dig into the region that used to be hollow.
weather
=======
Prints the current weather, and lets you change the weather to 'clear', 'rain'
or 'snow', with those words as commands (eg ``weather rain``).
=================

@ -167,7 +167,6 @@ if (BUILD_SUPPORTED)
# DFHACK_PLUGIN(treefarm treefarm.cpp)
DFHACK_PLUGIN(tubefill tubefill.cpp)
add_subdirectory(tweak)
DFHACK_PLUGIN(weather weather.cpp)
DFHACK_PLUGIN(workflow workflow.cpp LINK_LIBRARIES lua)
DFHACK_PLUGIN(workNow workNow.cpp)
DFHACK_PLUGIN(zone zone.cpp LINK_LIBRARIES lua)

@ -1,147 +0,0 @@
#include "Core.h"
#include "Console.h"
#include "Export.h"
#include "PluginManager.h"
#include <vector>
#include <string>
#include "modules/World.h"
#include "DataDefs.h"
#include "df/weather_type.h"
using std::vector;
using std::string;
using namespace DFHack;
using namespace df::enums;
DFHACK_PLUGIN("weather");
REQUIRE_GLOBAL(current_weather);
bool locked = false;
unsigned char locked_data[25];
command_result weather (color_ostream &out, vector <string> & parameters);
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{
commands.push_back(PluginCommand(
"weather", "Print the weather map or change weather.",
weather, false,
" Prints the current weather map by default.\n"
"Options:\n"
" snow - make it snow everywhere.\n"
" rain - make it rain.\n"
" clear - clear the sky.\n"
));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{
return CR_OK;
}
command_result weather (color_ostream &con, vector <string> & parameters)
{
int val_override = -1;
bool lock = false;
bool unlock = false;
bool snow = false;
bool rain = false;
bool clear = false;
for(size_t i = 0; i < parameters.size();i++)
{
if(parameters[i] == "rain")
rain = true;
else if(parameters[i] == "snow")
snow = true;
else if(parameters[i] == "clear")
clear = true;
else if(parameters[i] == "lock")
lock = true;
else if(parameters[i] == "unlock")
unlock = true;
else
{
val_override = atoi(parameters[i].c_str());
if(val_override == 0)
return CR_WRONG_USAGE;
}
}
if(lock && unlock)
{
con << "Lock or unlock? DECIDE!" << std::endl;
return CR_FAILURE;
}
int cnt = 0;
cnt += rain;
cnt += snow;
cnt += clear;
if(cnt > 1)
{
con << "Rain, snow or clear sky? DECIDE!" << std::endl;
return CR_FAILURE;
}
bool something = lock || unlock || rain || snow || clear || val_override != -1;
CoreSuspender suspend;
if(!current_weather)
{
con << "Weather support seems broken :(" << std::endl;
return CR_FAILURE;
}
if(!something)
{
// paint weather map
con << "Weather map (C = clear, R = rain, S = snow):" << std::endl;
for(int y = 0; y<5;y++)
{
for(int x = 0; x<5;x++)
{
switch((*current_weather)[x][y])
{
case weather_type::None:
con << "C ";
break;
case weather_type::Rain:
con << "R ";
break;
case weather_type::Snow:
con << "S ";
break;
default:
con << (int) (*current_weather)[x][y] << " ";
break;
}
}
con << std::endl;
}
}
else
{
// weather changing action!
if(rain)
{
con << "Here comes the rain." << std::endl;
World::SetCurrentWeather(weather_type::Rain);
}
if(snow)
{
con << "Snow everywhere!" << std::endl;
World::SetCurrentWeather(weather_type::Snow);
}
if(clear)
{
con << "Suddenly, sunny weather!" << std::endl;
World::SetCurrentWeather(weather_type::None);
}
if(val_override != -1)
{
con << "I have no damn idea what this is... " << val_override << std::endl;
World::SetCurrentWeather(val_override);
}
// FIXME: weather lock needs map ID to work reliably... needs to be implemented.
}
return CR_OK;
}

@ -0,0 +1,35 @@
-- Print the weather map or change weather.
local helpstr = [[=begin
weather
=======
Prints a map of the local weather, or with arguments ``clear``,
``rain``, and ``snow`` changes the weather.
=end]]
local args = {...}
if args[1] == "help" or args[1] == "?" then
print("The current weather is "..df.weather_type[dfhack.world.ReadCurrentWeather()])
print((helpstr:gsub('=[a-z]+', '')))
elseif args[1] == "clear" then
dfhack.world.SetCurrentWeather(df.weather_type["None"])
print("The weather has cleared.")
elseif args[1] == "rain" then
dfhack.world.SetCurrentWeather(df.weather_type["Rain"])
print("It is now raining.")
elseif args[1] == "snow" then
dfhack.world.SetCurrentWeather(df.weather_type["Snow"])
print("It is now snowing.")
else
-- df.global.current_weather is arranged in columns, not rows
kind = {[0]="C ", "R ", "S "}
print("Weather map (C = clear, R = rain, S = snow):")
for y=0, 4 do
s = ""
for x=0, 4 do
s = s..kind[df.global.current_weather[x][y]]
end
print(s)
end
end