-
Notifications
You must be signed in to change notification settings - Fork 498
Expand file tree
/
Copy pathbuildprobe.cpp
More file actions
122 lines (101 loc) · 3 KB
/
Copy pathbuildprobe.cpp
File metadata and controls
122 lines (101 loc) · 3 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
//Quick building occupancy flag test.
//Individual bits had no apparent meaning. Assume it's an enum, set by number.
#include <Console.h>
#include <Export.h>
#include <PluginManager.h>
#include <modules/Maps.h>
#include <modules/Gui.h>
#include <modules/MapCache.h>
#include <vector>
#include <cstdio>
#include <stack>
#include <string>
#include <cmath>
using std::vector;
using std::string;
using std::stack;
using namespace DFHack;
command_result readFlag (color_ostream &out, vector <string> & parameters);
command_result writeFlag (color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("buildprobe");
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{
commands.push_back(PluginCommand("bshow","Output building occupancy value",readFlag));
commands.push_back(PluginCommand("bset","Set building occupancy value",writeFlag));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{
return CR_OK;
}
command_result readFlag (color_ostream &out, vector <string> & parameters)
{
// init the map
if(!Maps::IsValid())
{
out.printerr("Can't init map. Make sure you have a map loaded in DF.\n");
return CR_FAILURE;
}
int32_t cx, cy, cz;
if(!Gui::getCursorCoords(cx,cy,cz))
{
out.printerr("Cursor is not active.\n");
return CR_FAILURE;
}
DFCoord cursor = DFCoord(cx,cy,cz);
MapExtras::MapCache * MCache = new MapExtras::MapCache();
t_occupancy oc = MCache->occupancyAt(cursor);
out.print("Current Value: {}\n", ENUM_AS_STR(oc.bits.building));
return CR_OK;
}
command_result writeFlag (color_ostream &out, vector <string> & parameters)
{
if (parameters.size() == 0)
{
out.print("No value specified\n");
return CR_FAILURE;
}
if (parameters[0] == "help" || parameters[0] == "?")
{
out.print("Set the building occupancy flag.\n"
"Value must be between 0 and 7, inclusive.\n");
return CR_OK;
}
char value;
switch (parameters[0][0])
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
value = parameters[0][0] - '0';
break;
default:
out.print("Invalid value specified\n");
return CR_FAILURE;
break; //Redundant.
}
// init the map
if(!Maps::IsValid())
{
out.printerr("Can't init map. Make sure you have a map loaded in DF.\n");
return CR_FAILURE;
}
int32_t cx, cy, cz;
if(!Gui::getCursorCoords(cx,cy,cz))
{
out.printerr("Cursor is not active.\n");
return CR_FAILURE;
}
DFCoord cursor = DFCoord(cx,cy,cz);
MapExtras::MapCache * MCache = new MapExtras::MapCache();
t_occupancy oc = MCache->occupancyAt(cursor);
oc.bits.building = df::tile_building_occ(value);
MCache->setOccupancyAt(cursor, oc);
MCache->WriteAll();
return CR_OK;
}