#include #include #include #include #include #include #include using std::vector; using std::string; using namespace DFHack; bool locked = false; unsigned char locked_data[25]; DFhackCExport command_result weather (Core * c, vector & parameters); DFhackCExport const char * plugin_name ( void ) { return "weather"; } DFhackCExport command_result plugin_init ( Core * c, std::vector &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 & 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) { c->con << "Lock or unlock? DECIDE!" << std::endl; return CR_FAILURE; } int cnt = 0; cnt += rain; cnt += snow; cnt += clear; if(cnt > 1) { c->con << "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) { c->con << "Weather support seems broken :(" << std::endl; c->Resume(); return CR_FAILURE; } if(!something) { // paint weather map c->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((*w->wmap)[x][y]) { case DFHack::CLEAR: c->con << "C "; break; case DFHack::RAINING: c->con << "R "; break; case DFHack::SNOWING: c->con << "S "; break; default: c->con << (int) (*w->wmap)[x][y] << " "; break; } } c->con << std::endl; } } else { // weather changing action! if(rain) { c->con << "Here comes the rain." << std::endl; w->SetCurrentWeather(RAINING); } if(snow) { c->con << "Snow everywhere!" << std::endl; w->SetCurrentWeather(SNOWING); } if(clear) { c->con << "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; }