forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather.cpp
More file actions
132 lines (125 loc) · 3.49 KB
/
Copy pathweather.cpp
File metadata and controls
132 lines (125 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#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)
{
Console & con = c->con;
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)
{
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;
c->Suspend();
DFHack::World * w = c->getWorld();
if(!w->wmap)
{
con << "Weather support seems broken :(" << std::endl;
c->Resume();
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((*w->wmap)[x][y])
{
case DFHack::CLEAR:
con << "C ";
break;
case DFHack::RAINING:
con << "R ";
break;
case DFHack::SNOWING:
con << "S ";
break;
default:
con << (int) (*w->wmap)[x][y] << " ";
break;
}
}
con << std::endl;
}
}
else
{
// weather changing action!
if(rain)
{
con << "Here comes the rain." << std::endl;
w->SetCurrentWeather(RAINING);
}
if(snow)
{
con << "Snow everywhere!" << std::endl;
w->SetCurrentWeather(SNOWING);
}
if(clear)
{
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;
}