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];
|
|
|
|
|
|
|
|
DFhackCExport command_result weather (Core * c, vector <string> & parameters);
|
|
|
|
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
{
|
|
|
|
return "weather";
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
commands.clear();
|
2011-08-13 06:42:09 -06:00
|
|
|
commands.push_back(PluginCommand("weather", "Print the weather map or change weather.",weather));
|
2011-07-07 02:57:57 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result weather (Core * c, vector <string> & parameters)
|
|
|
|
{
|
2011-07-13 20:05:27 -06:00
|
|
|
Console & con = c->con;
|
2011-07-07 02:57:57 -06:00
|
|
|
bool lock = false;
|
|
|
|
bool unlock = false;
|
|
|
|
bool snow = false;
|
|
|
|
bool rain = false;
|
|
|
|
bool clear = false;
|
2011-08-08 17:50:22 -06:00
|
|
|
bool help = false;
|
2011-07-07 02:57:57 -06:00
|
|
|
for(int 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;
|
2011-08-08 17:50:22 -06:00
|
|
|
else if(parameters[i] == "help" || parameters[i] == "?")
|
|
|
|
help = true;
|
|
|
|
}
|
|
|
|
if(help)
|
|
|
|
{
|
2011-08-13 06:42:09 -06:00
|
|
|
c->con.print("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;
|
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;
|
|
|
|
}
|
|
|
|
bool something = lock || unlock || rain || snow || clear;
|
|
|
|
c->Suspend();
|
|
|
|
DFHack::World * w = c->getWorld();
|
|
|
|
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
|
|
|
c->Resume();
|
|
|
|
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])
|
|
|
|
{
|
|
|
|
case DFHack::CLEAR:
|
2011-07-13 20:05:27 -06:00
|
|
|
con << "C ";
|
2011-07-07 02:57:57 -06:00
|
|
|
break;
|
|
|
|
case DFHack::RAINING:
|
2011-07-13 20:05:27 -06:00
|
|
|
con << "R ";
|
2011-07-07 02:57:57 -06:00
|
|
|
break;
|
|
|
|
case DFHack::SNOWING:
|
2011-07-13 20:05:27 -06:00
|
|
|
con << "S ";
|
2011-07-07 02:57:57 -06:00
|
|
|
break;
|
|
|
|
default:
|
2011-07-13 20:05:27 -06:00
|
|
|
con << (int) (*w->wmap)[x][y] << " ";
|
2011-07-07 02:57:57 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
// FIXME: weather lock needs map ID to work reliably... needs to be implemented.
|
|
|
|
}
|
|
|
|
c->Resume();
|
|
|
|
return CR_OK;
|
|
|
|
}
|