2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
2011-07-07 02:57:57 -06:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "modules/World.h"
|
2011-07-07 02:57:57 -06:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
bool locked = false;
|
|
|
|
unsigned char locked_data[25];
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result weather (color_ostream &out, vector <string> & parameters);
|
2011-07-07 02:57:57 -06:00
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
DFHACK_PLUGIN("weather");
|
2011-07-07 02:57:57 -06:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
2011-07-07 02:57:57 -06:00
|
|
|
{
|
|
|
|
commands.clear();
|
2012-01-28 05:03:56 -07:00
|
|
|
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"
|
|
|
|
));
|
2011-07-07 02:57:57 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2011-07-07 02:57:57 -06:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result weather (color_ostream &con, vector <string> & parameters)
|
2011-07-07 02:57:57 -06:00
|
|
|
{
|
2012-02-22 07:21:29 -07:00
|
|
|
int val_override = -1;
|
2011-07-07 02:57:57 -06:00
|
|
|
bool lock = false;
|
|
|
|
bool unlock = false;
|
|
|
|
bool snow = false;
|
|
|
|
bool rain = false;
|
|
|
|
bool clear = false;
|
2012-01-31 09:55:38 -07:00
|
|
|
for(size_t i = 0; i < parameters.size();i++)
|
2011-07-07 02:57:57 -06:00
|
|
|
{
|
|
|
|
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;
|
2012-01-28 05:03:56 -07:00
|
|
|
else
|
2012-02-22 07:21:29 -07:00
|
|
|
{
|
|
|
|
val_override = atoi(parameters[i].c_str());
|
|
|
|
if(val_override == 0)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
2011-07-07 02:57:57 -06:00
|
|
|
}
|
|
|
|
if(lock && unlock)
|
|
|
|
{
|
2011-07-13 20:05:27 -06:00
|
|
|
con << "Lock or unlock? DECIDE!" << std::endl;
|
2011-07-07 02:57:57 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
int cnt = 0;
|
|
|
|
cnt += rain;
|
|
|
|
cnt += snow;
|
|
|
|
cnt += clear;
|
|
|
|
if(cnt > 1)
|
|
|
|
{
|
2011-07-13 20:05:27 -06:00
|
|
|
con << "Rain, snow or clear sky? DECIDE!" << std::endl;
|
2011-07-07 02:57:57 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2012-02-22 07:21:29 -07:00
|
|
|
bool something = lock || unlock || rain || snow || clear || val_override != -1;
|
2012-01-21 17:31:15 -07:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
CoreSuspender suspend;
|
|
|
|
|
|
|
|
DFHack::World * w = Core::getInstance().getWorld();
|
2011-07-07 02:57:57 -06:00
|
|
|
if(!w->wmap)
|
|
|
|
{
|
2011-07-13 20:05:27 -06:00
|
|
|
con << "Weather support seems broken :(" << std::endl;
|
2011-07-07 02:57:57 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
if(!something)
|
|
|
|
{
|
|
|
|
// paint weather map
|
2011-07-13 20:05:27 -06:00
|
|
|
con << "Weather map (C = clear, R = rain, S = snow):" << std::endl;
|
2011-07-07 02:57:57 -06:00
|
|
|
for(int y = 0; y<5;y++)
|
|
|
|
{
|
|
|
|
for(int x = 0; x<5;x++)
|
|
|
|
{
|
|
|
|
switch((*w->wmap)[x][y])
|
|
|
|
{
|
2012-01-21 17:31:15 -07:00
|
|
|
case CLEAR:
|
|
|
|
con << "C ";
|
|
|
|
break;
|
|
|
|
case RAINING:
|
|
|
|
con << "R ";
|
|
|
|
break;
|
|
|
|
case SNOWING:
|
|
|
|
con << "S ";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
con << (int) (*w->wmap)[x][y] << " ";
|
|
|
|
break;
|
2011-07-07 02:57:57 -06:00
|
|
|
}
|
|
|
|
}
|
2011-07-13 20:05:27 -06:00
|
|
|
con << std::endl;
|
2011-07-07 02:57:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// weather changing action!
|
|
|
|
if(rain)
|
|
|
|
{
|
2011-07-13 20:05:27 -06:00
|
|
|
con << "Here comes the rain." << std::endl;
|
2011-07-07 02:57:57 -06:00
|
|
|
w->SetCurrentWeather(RAINING);
|
|
|
|
}
|
|
|
|
if(snow)
|
|
|
|
{
|
2011-07-13 20:05:27 -06:00
|
|
|
con << "Snow everywhere!" << std::endl;
|
2011-07-07 02:57:57 -06:00
|
|
|
w->SetCurrentWeather(SNOWING);
|
|
|
|
}
|
|
|
|
if(clear)
|
|
|
|
{
|
2011-07-13 20:05:27 -06:00
|
|
|
con << "Suddenly, sunny weather!" << std::endl;
|
2011-07-07 02:57:57 -06:00
|
|
|
w->SetCurrentWeather(CLEAR);
|
|
|
|
}
|
2012-02-22 07:21:29 -07:00
|
|
|
if(val_override != -1)
|
|
|
|
{
|
|
|
|
con << "I have no damn idea what this is... " << val_override << std::endl;
|
|
|
|
w->SetCurrentWeather(val_override);
|
|
|
|
}
|
2011-07-07 02:57:57 -06:00
|
|
|
// FIXME: weather lock needs map ID to work reliably... needs to be implemented.
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|