Weather plugin to mirror the weather tool.

develop
Petr Mrázek 2011-07-07 10:57:57 +02:00
parent 8b298f8d91
commit 367d79bcfa
5 changed files with 139 additions and 7 deletions

@ -46,7 +46,7 @@ namespace DFHack
RAINING, RAINING,
SNOWING SNOWING
}; };
typedef unsigned char weather_map [5][5];
/** /**
* \ingroup grp_world * \ingroup grp_world
*/ */
@ -88,7 +88,7 @@ namespace DFHack
class DFHACK_EXPORT World : public Module class DFHACK_EXPORT World : public Module
{ {
public: public:
weather_map * wmap;
World(); World();
~World(); ~World();
bool Start(); bool Start();

@ -75,6 +75,7 @@ World::World()
Core & c = Core::getInstance(); Core & c = Core::getInstance();
d = new Private; d = new Private;
d->owner = c.p; d->owner = c.p;
wmap = 0;
OffsetGroup * OG_World = c.vinfo->getGroup("World"); OffsetGroup * OG_World = c.vinfo->getGroup("World");
try try
@ -94,6 +95,7 @@ World::World()
try try
{ {
d->weather_offset = OG_World->getAddress( "current_weather" ); d->weather_offset = OG_World->getAddress( "current_weather" );
wmap = (weather_map *) d->weather_offset;
d->StartedWeather = true; d->StartedWeather = true;
} }
catch(Error::All &){}; catch(Error::All &){};

@ -28,3 +28,4 @@ DFHACK_PLUGIN(reveal reveal.cpp)
DFHACK_PLUGIN(kittens kittens.cpp) DFHACK_PLUGIN(kittens kittens.cpp)
DFHACK_PLUGIN(prospector prospector.cpp) DFHACK_PLUGIN(prospector prospector.cpp)
DFHACK_PLUGIN(cleanmap cleanmap.cpp) DFHACK_PLUGIN(cleanmap cleanmap.cpp)
DFHACK_PLUGIN(weather weather.cpp)

@ -11,9 +11,6 @@ using std::vector;
using std::string; using std::string;
using namespace DFHack; using namespace DFHack;
const uint32_t water_idx = 6;
const uint32_t mud_idx = 12;
DFhackCExport command_result cleanmap (Core * c, vector <string> & parameters); DFhackCExport command_result cleanmap (Core * c, vector <string> & parameters);
DFhackCExport const char * plugin_name ( void ) DFhackCExport const char * plugin_name ( void )
@ -35,6 +32,9 @@ DFhackCExport command_result plugin_shutdown ( Core * c )
DFhackCExport command_result cleanmap (Core * c, vector <string> & parameters) DFhackCExport command_result cleanmap (Core * c, vector <string> & parameters)
{ {
const uint32_t water_idx = 6;
const uint32_t mud_idx = 12;
bool snow = false; bool snow = false;
bool mud = false; bool mud = false;
for(int i = 0; i < parameters.size();i++) for(int i = 0; i < parameters.size();i++)
@ -57,8 +57,6 @@ DFhackCExport command_result cleanmap (Core * c, vector <string> & parameters)
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
Mapz->getSize(x_max,y_max,z_max); Mapz->getSize(x_max,y_max,z_max);
uint8_t zeroes [16][16] = {{0}};
DFHack::occupancies40d occ;
// walk the map // walk the map
for(uint32_t x = 0; x< x_max;x++) for(uint32_t x = 0; x< x_max;x++)
{ {

@ -0,0 +1,131 @@
#include <dfhack/Core.h>
#include <dfhack/Console.h>
#include <dfhack/Export.h>
#include <dfhack/PluginManager.h>
#include <vector>
#include <string>
#include <dfhack/modules/World.h>
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();
commands.push_back(PluginCommand("weather",
"Print the weather map or change weather.\
\n Options: 'lock'/'unlock' = disallow game from changing weather\
\n 'snow' = make it snow, 'rain' = make it rain.\
\n 'clear' = clear the sky",weather));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( Core * c )
{
return CR_OK;
}
DFhackCExport command_result weather (Core * c, vector <string> & parameters)
{
bool lock = false;
bool unlock = false;
bool snow = false;
bool rain = false;
bool clear = false;
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;
}
if(lock && unlock)
{
dfout << "Lock or unlock? DECIDE!" << std::endl;
return CR_FAILURE;
}
int cnt = 0;
cnt += rain;
cnt += snow;
cnt += clear;
if(cnt > 1)
{
dfout << "Rain, snow or clear sky? DECIDE!" << std::endl;
return CR_FAILURE;
}
bool something = lock || unlock || rain || snow || clear;
c->Suspend();
DFHack::World * w = c->getWorld();
if(!w->wmap)
{
dfout << "Weather support seems broken :(" << std::endl;
c->Resume();
return CR_FAILURE;
}
if(!something)
{
// paint weather map
dfout << "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((*w->wmap)[x][y])
{
case DFHack::CLEAR:
dfout << "C ";
break;
case DFHack::RAINING:
dfout << "R ";
break;
case DFHack::SNOWING:
dfout << "S ";
break;
default:
dfout << (int) (*w->wmap)[x][y] << " ";
break;
}
}
dfout << std::endl;
}
}
else
{
// weather changing action!
if(rain)
{
dfout << "Here comes the rain." << std::endl;
w->SetCurrentWeather(RAINING);
}
if(snow)
{
dfout << "Snow everywhere!" << std::endl;
w->SetCurrentWeather(SNOWING);
}
if(clear)
{
dfout << "Suddenly, sunny weather!" << std::endl;
w->SetCurrentWeather(CLEAR);
}
// FIXME: weather lock needs map ID to work reliably... needs to be implemented.
}
c->Resume();
return CR_OK;
}