Skip to content

Commit 2cc6bcf

Browse files
committed
Use CoreSuspender and namespace df::enums
1 parent ccf22be commit 2cc6bcf

21 files changed

Lines changed: 582 additions & 621 deletions

plugins/autodump.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ using namespace std;
2626
#include "df/general_ref.h"
2727

2828
using namespace DFHack;
29+
using namespace df::enums;
30+
2931
using MapExtras::Block;
3032
using MapExtras::MapCache;
3133
using df::global::world;
@@ -291,9 +293,9 @@ DFhackCExport command_result df_autodump_destroy_item(Core * c, vector <string>
291293
return CR_FAILURE;
292294

293295
// Allow undoing the destroy
294-
if (df::global::world->frame_counter != last_frame)
296+
if (world->frame_counter != last_frame)
295297
{
296-
last_frame = df::global::world->frame_counter;
298+
last_frame = world->frame_counter;
297299
pending_destroy.clear();
298300
}
299301

@@ -327,7 +329,7 @@ DFhackCExport command_result df_autodump_destroy_item(Core * c, vector <string>
327329
for (unsigned i = 0; i < item->itemrefs.size(); i++)
328330
{
329331
df::general_ref *ref = item->itemrefs[i];
330-
if (ref->getType() == df::general_ref_type::UNIT_HOLDER)
332+
if (ref->getType() == general_ref_type::UNIT_HOLDER)
331333
{
332334
c->con.printerr("Choosing not to destroy items in unit inventory.\n");
333335
return CR_FAILURE;

plugins/cleaners.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ using std::vector;
1717
using std::string;
1818
using namespace DFHack;
1919
using namespace DFHack::Simple;
20+
using namespace df::enums;
2021

2122
using df::global::world;
2223
using df::global::cursor;
@@ -40,20 +41,20 @@ command_result cleanmap (Core * c, bool snow, bool mud)
4041
for (int j = 0; j < block->block_events.size(); j++)
4142
{
4243
df::block_square_event *evt = block->block_events[j];
43-
if (evt->getType() != df::block_square_event_type::material_spatter)
44+
if (evt->getType() != block_square_event_type::material_spatter)
4445
continue;
4546
// type verified - recast to subclass
4647
df::block_square_event_material_spatterst *spatter = (df::block_square_event_material_spatterst *)evt;
4748

4849
// filter snow
4950
if(!snow
50-
&& spatter->mat_type == df::builtin_mats::WATER
51-
&& spatter->mat_state == df::matter_state::Powder)
51+
&& spatter->mat_type == builtin_mats::WATER
52+
&& spatter->mat_state == matter_state::Powder)
5253
continue;
5354
// filter mud
5455
if(!mud
55-
&& spatter->mat_type == df::builtin_mats::MUD
56-
&& spatter->mat_state == df::matter_state::Solid)
56+
&& spatter->mat_type == builtin_mats::MUD
57+
&& spatter->mat_state == matter_state::Solid)
5758
continue;
5859

5960
delete evt;
@@ -119,7 +120,7 @@ DFhackCExport command_result spotclean (Core * c, vector <string> & parameters)
119120
if (cursor->x == -30000)
120121
{
121122
c->con.printerr("The cursor is not active.\n");
122-
return CR_FAILURE;
123+
return CR_WRONG_USAGE;
123124
}
124125
df::map_block *block = Maps::getBlockAbs(cursor->x, cursor->y, cursor->z);
125126
if (block == NULL)
@@ -131,7 +132,7 @@ DFhackCExport command_result spotclean (Core * c, vector <string> & parameters)
131132
for (int i = 0; i < block->block_events.size(); i++)
132133
{
133134
df::block_square_event *evt = block->block_events[i];
134-
if (evt->getType() != df::block_square_event_type::material_spatter)
135+
if (evt->getType() != block_square_event_type::material_spatter)
135136
continue;
136137
// type verified - recast to subclass
137138
df::block_square_event_material_spatterst *spatter = (df::block_square_event_material_spatterst *)evt;
@@ -189,14 +190,13 @@ DFhackCExport command_result clean (Core * c, vector <string> & parameters)
189190
);
190191
return CR_OK;
191192
}
192-
c->Suspend();
193+
CoreSuspender suspend(c);
193194
if(map)
194195
cleanmap(c,snow,mud);
195196
if(units)
196197
cleanunits(c);
197198
if(items)
198199
cleanitems(c);
199-
c->Resume();
200200
return CR_OK;
201201
}
202202

plugins/cleanowned.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ using namespace std;
1818
#include "modules/Units.h"
1919
#include "modules/Materials.h"
2020
#include "modules/Translation.h"
21-
using namespace DFHack;
22-
using namespace DFHack::Simple;
2321
#include "DataDefs.h"
2422
#include "df/world.h"
2523

24+
using namespace DFHack;
25+
using namespace DFHack::Simple;
26+
using namespace df::enums;
27+
2628
using df::global::world;
2729

2830
DFhackCExport command_result df_cleanowned (Core * c, vector <string> & parameters);
@@ -91,7 +93,9 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
9193
return CR_FAILURE;
9294
}
9395
}
94-
c->Suspend();
96+
97+
CoreSuspender suspend(c);
98+
9599
DFHack::Materials *Materials = c->getMaterials();
96100
DFHack::Units *Creatures = c->getUnits();
97101
DFHack::Translation *Tran = c->getTranslation();
@@ -132,13 +136,13 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
132136
else if (item->flags.bits.on_ground)
133137
{
134138
int32_t type = item->getType();
135-
if(type == df::item_type::MEAT ||
136-
type == df::item_type::FISH ||
137-
type == df::item_type::VERMIN ||
138-
type == df::item_type::PET ||
139-
type == df::item_type::PLANT ||
140-
type == df::item_type::CHEESE ||
141-
type == df::item_type::FOOD
139+
if(type == item_type::MEAT ||
140+
type == item_type::FISH ||
141+
type == item_type::VERMIN ||
142+
type == item_type::PET ||
143+
type == item_type::PLANT ||
144+
type == item_type::CHEESE ||
145+
type == item_type::FOOD
142146
)
143147
{
144148
confiscate = true;
@@ -207,6 +211,5 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
207211
c->con.print("\n");
208212
}
209213
}
210-
c->Resume();
211214
return CR_OK;
212215
}

plugins/colonies.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
2323
{
2424
commands.clear();
2525
commands.push_back(PluginCommand("colonies",
26-
"List or change wild colonies (ants hills and such)",
27-
colonies));
26+
"List or change wild colonies (ants hills and such)",
27+
colonies));
2828
return CR_OK;
2929
}
3030

@@ -57,19 +57,18 @@ DFhackCExport command_result colonies (Core * c, vector <string> & parameters)
5757
if(help)
5858
{
5959
c->con.print("Without any options, this command lists all the vermin colonies present.\n"
60-
"Options:\n"
61-
"kill - destroy colonies\n"
62-
"bees - turn colonies into honey bees\n"
63-
);
60+
"Options:\n"
61+
"kill - destroy colonies\n"
62+
"bees - turn colonies into honey bees\n"
63+
);
6464
return CR_OK;
6565
}
6666
if (destroy && convert)
6767
{
6868
c->con.printerr("Kill or make bees? DECIDE!\n");
69-
c->Resume();
7069
return CR_FAILURE;
7170
}
72-
c->Suspend();
71+
CoreSuspender suspend(c);
7372

7473
Materials * materials = c->getMaterials();
7574

@@ -84,7 +83,6 @@ DFhackCExport command_result colonies (Core * c, vector <string> & parameters)
8483

8584
materials->Finish();
8685

87-
c->Resume();
8886
return CR_OK;
8987
}
9088

@@ -110,11 +108,13 @@ void convertColonies(Materials *Materials)
110108
{
111109
int bee_idx = -1;
112110
for (size_t i = 0; i < Materials->raceEx.size(); i++)
111+
{
113112
if (Materials->raceEx[i].id == "HONEY_BEE")
114113
{
115114
bee_idx = i;
116115
break;
117116
}
117+
}
118118

119119
if (bee_idx == -1)
120120
{
@@ -153,8 +153,8 @@ void showColonies(Core *c, Materials *Materials)
153153
if(sp.race != -1)
154154
race = Materials->raceEx[sp.race].id;
155155

156-
c->con.print("Colony %u: %s at %d:%d:%d\n", i,
157-
race.c_str(), sp.x, sp.y, sp.z);
156+
c->con.print("Colony %u: %s at %d:%d:%d\n", i,
157+
race.c_str(), sp.x, sp.y, sp.z);
158158
}
159159
}
160160

plugins/deramp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
using std::vector;
1313
using std::string;
1414
using namespace DFHack;
15+
using namespace DFHack::Simple;
16+
using namespace df::enums;
1517

1618
using df::global::world;
17-
using namespace DFHack;
18-
using namespace DFHack::Simple;
1919

2020
DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters)
2121
{
@@ -48,7 +48,7 @@ DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters)
4848
{
4949
int16_t oldT = block->tiletype[x][y];
5050
if ((tileShape(oldT) == RAMP) &&
51-
(block->designation[x][y].bits.dig == df::tile_dig_designation::Default))
51+
(block->designation[x][y].bits.dig == tile_dig_designation::Default))
5252
{
5353
// Current tile is a ramp.
5454
// Set current tile, as accurately as can be expected
@@ -59,7 +59,7 @@ DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters)
5959
continue;
6060
// Set new tile type, clear designation
6161
block->tiletype[x][y] = newT;
62-
block->designation[x][y].bits.dig = df::tile_dig_designation::No;
62+
block->designation[x][y].bits.dig = tile_dig_designation::No;
6363

6464
// Check the tile above this one, in case a downward slope needs to be removed.
6565
if ((above) && (tileShape(above->tiletype[x][y]) == RAMP_TOP))

plugins/drybuckets.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,45 @@
1313
using std::string;
1414
using std::vector;
1515
using namespace DFHack;
16+
using namespace df::enums;
1617

1718
using df::global::world;
1819

1920
DFhackCExport command_result df_drybuckets (Core * c, vector <string> & parameters)
2021
{
21-
if (!parameters.empty())
22-
return CR_WRONG_USAGE;
23-
24-
CoreSuspender suspend(c);
25-
26-
int dried_total = 0;
27-
for (int i = 0; i < world->items.all.size(); i++)
28-
{
29-
df::item *item = world->items.all[i];
30-
if ((item->getType() == df::item_type::LIQUID_MISC) && (item->getMaterial() == df::builtin_mats::WATER))
31-
{
32-
item->flags.bits.garbage_colect = 1;
33-
dried_total++;
34-
}
35-
}
36-
if (dried_total)
37-
c->con.print("Done. %d buckets of water marked for emptying.\n", dried_total);
38-
return CR_OK;
22+
if (!parameters.empty())
23+
return CR_WRONG_USAGE;
24+
25+
CoreSuspender suspend(c);
26+
27+
int dried_total = 0;
28+
for (int i = 0; i < world->items.all.size(); i++)
29+
{
30+
df::item *item = world->items.all[i];
31+
if ((item->getType() == item_type::LIQUID_MISC) && (item->getMaterial() == builtin_mats::WATER))
32+
{
33+
item->flags.bits.garbage_colect = 1;
34+
dried_total++;
35+
}
36+
}
37+
if (dried_total)
38+
c->con.print("Done. %d buckets of water marked for emptying.\n", dried_total);
39+
return CR_OK;
3940
}
4041

4142
DFhackCExport const char * plugin_name ( void )
4243
{
43-
return "drybuckets";
44+
return "drybuckets";
4445
}
4546

4647
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
4748
{
48-
commands.clear();
49-
commands.push_back(PluginCommand("drybuckets", "Removes water from buckets.", df_drybuckets));
50-
return CR_OK;
49+
commands.clear();
50+
commands.push_back(PluginCommand("drybuckets", "Removes water from buckets.", df_drybuckets));
51+
return CR_OK;
5152
}
5253

5354
DFhackCExport command_result plugin_shutdown ( Core * c )
5455
{
55-
return CR_OK;
56+
return CR_OK;
5657
}

0 commit comments

Comments
 (0)