From 6d123687241f76775156faed5ebb48c4242236a0 Mon Sep 17 00:00:00 2001 From: expwnent Date: Sun, 19 Aug 2012 22:45:47 -0400 Subject: Added digtype to dig.cpp. Digtype allows designation of all veins of a given type. --- plugins/dig.cpp | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 130 insertions(+), 1 deletion(-) diff --git a/plugins/dig.cpp b/plugins/dig.cpp index 21c19910..c1b6f633 100644 --- a/plugins/dig.cpp +++ b/plugins/dig.cpp @@ -24,7 +24,7 @@ command_result diglx (color_ostream &out, vector & parameters); command_result digauto (color_ostream &out, vector & parameters); command_result digexp (color_ostream &out, vector & parameters); command_result digcircle (color_ostream &out, vector & parameters); - +command_result digtype (color_ostream &out, vector & parameters); DFHACK_PLUGIN("dig"); @@ -57,6 +57,18 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector & parameters) { return CR_NOT_IMPLEMENTED; } + +command_result digtype (color_ostream &out, vector & parameters) +{ + //mostly copy-pasted from digv + CoreSuspender suspend; + if ( parameters.size() > 1 ) + { + out.printerr("Too many parameters.\n"); + return CR_FAILURE; + } + + uint32_t targetDigType; + if ( parameters.size() == 1 ) + { + string parameter = parameters[0]; + if ( parameter == "clear" ) + targetDigType = tile_dig_designation::No; + else if ( parameter == "dig" ) + targetDigType = tile_dig_designation::Default; + else if ( parameter == "updown" ) + targetDigType = tile_dig_designation::UpDownStair; + else if ( parameter == "channel" ) + targetDigType = tile_dig_designation::Channel; + else if ( parameter == "ramp" ) + targetDigType = tile_dig_designation::Ramp; + else if ( parameter == "down" ) + targetDigType = tile_dig_designation::DownStair; + else if ( parameter == "up" ) + targetDigType = tile_dig_designation::UpStair; + else + { + out.printerr("Invalid parameter.\n"); + return CR_FAILURE; + } + } + else + { + targetDigType = -1; + } + + if (!Maps::IsValid()) + { + out.printerr("Map is not available!\n"); + return CR_FAILURE; + } + + int32_t cx, cy, cz; + uint32_t xMax,yMax,zMax; + Maps::getSize(xMax,yMax,zMax); + uint32_t tileXMax = xMax * 16; + uint32_t tileYMax = yMax * 16; + Gui::getCursorCoords(cx,cy,cz); + if (cx == -30000) + { + out.printerr("Cursor is not active. Point the cursor at a vein.\n"); + return CR_FAILURE; + } + DFHack::DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz); + MapExtras::MapCache * mCache = new MapExtras::MapCache; + df::tile_designation baseDes = mCache->designationAt(xy); + df::tiletype tt = mCache->tiletypeAt(xy); + int16_t veinmat = mCache->veinMaterialAt(xy); + if( veinmat == -1 ) + { + out.printerr("This tile is not a vein.\n"); + delete mCache; + return CR_FAILURE; + } + out.print("(%d,%d,%d) tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, baseDes.whole); + + if ( targetDigType != -1 ) + { + baseDes.bits.dig = (tile_dig_designation::tile_dig_designation)targetDigType; + } + else + { + if ( baseDes.bits.dig == tile_dig_designation::No ) + { + baseDes.bits.dig = tile_dig_designation::Default; + } + } + + for( uint32_t z = 0; z < zMax; z++ ) + { + for( uint32_t x = 1; x < tileXMax-1; x++ ) + { + for( uint32_t y = 1; y < tileYMax-1; y++ ) + { + DFHack::DFCoord current(x,y,z); + int16_t vmat2 = mCache->veinMaterialAt(current); + if ( vmat2 != veinmat ) + continue; + tt = mCache->tiletypeAt(current); + if (!DFHack::isWallTerrain(tt)) + continue; + + //designate it for digging + df::tile_designation des = mCache->designationAt(current); + if ( !mCache->testCoord(current) ) + { + out.printerr("testCoord failed at (%d,%d,%d)\n", x, y, z); + delete mCache; + return CR_FAILURE; + } + + df::tile_designation designation = mCache->designationAt(current); + designation.bits.dig = baseDes.bits.dig; + mCache->setDesignationAt(current, designation); + } + } + } + + mCache->WriteAll(); + delete mCache; + return CR_OK; +} + -- cgit v1.2.1 From eac2f3f5d1fb93fb47b8a060892d1eb38af33ac5 Mon Sep 17 00:00:00 2001 From: expwnent Date: Tue, 21 Aug 2012 01:33:04 -0400 Subject: Added misery plugin: multiply effects of negative thoughts. --- plugins/CMakeLists.txt | 1 + plugins/misery.cpp | 174 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 plugins/misery.cpp diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 2c54aeba..670c9ce7 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -115,6 +115,7 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(sort sort.cpp LINK_LIBRARIES lua) # not yet. busy with other crud again... #DFHACK_PLUGIN(versionosd versionosd.cpp) + DFHACK_PLUGIN(misery misery.cpp) endif() diff --git a/plugins/misery.cpp b/plugins/misery.cpp new file mode 100644 index 00000000..f17a4559 --- /dev/null +++ b/plugins/misery.cpp @@ -0,0 +1,174 @@ +#include "PluginManager.h" +#include "Export.h" + +#include "DataDefs.h" +#include "df/world.h" +#include "df/ui.h" +#include "df/unit.h" +#include "df/unit_thought.h" +#include "df/unit_thought_type.h" + +#include +#include +#include +using namespace std; + +using namespace DFHack; + +static int factor = 1; +static map processedThoughtCountTable; + +//keep track of fake thoughts so you can remove them if requested +static vector > fakeThoughts; + +DFHACK_PLUGIN("misery"); + +command_result misery(color_ostream& out, vector& parameters); + +DFhackCExport command_result plugin_shutdown(color_ostream& out) { + factor = 1; + return CR_OK; +} + +DFhackCExport command_result plugin_onupdate(color_ostream& out) { + static bool wasLoaded = false; + if ( factor == 1 || !df::global::world || !df::global::world->map.block_index ) { + if ( wasLoaded ) { + //we just unloaded the game: clear all data + factor = 1; + processedThoughtCountTable.clear(); + fakeThoughts.clear(); + wasLoaded = false; + } + return CR_OK; + } + + if ( !wasLoaded ) { + wasLoaded = true; + } + + int32_t race_id = df::global::ui->race_id; + int32_t civ_id = df::global::ui->civ_id; + for ( size_t a = 0; a < df::global::world->units.all.size(); a++ ) { + df::unit* unit = df::global::world->units.all[a]; //TODO: consider units.active + //living, native units only + if ( unit->race != race_id || unit->civ_id != civ_id ) + continue; + if ( unit->flags1.bits.dead ) + continue; + + int processedThoughtCount; + map::iterator i = processedThoughtCountTable.find(unit->id); + if ( i == processedThoughtCountTable.end() ) { + processedThoughtCount = unit->status.recent_events.size(); + processedThoughtCountTable[unit->id] = processedThoughtCount; + } else { + processedThoughtCount = (*i).second; + } + + if ( processedThoughtCount == unit->status.recent_events.size() ) { + continue; + } else if ( processedThoughtCount > unit->status.recent_events.size() ) { + processedThoughtCount = unit->status.recent_events.size(); + } + + //don't reprocess any old thoughts + vector newThoughts; + for ( size_t b = processedThoughtCount; b < unit->status.recent_events.size(); b++ ) { + df::unit_thought* oldThought = unit->status.recent_events[b]; + const char* bob = ENUM_ATTR(unit_thought_type, value, oldThought->type); + if ( bob[0] != '-' ) { + //out.print("unit %4d: old thought value = %s\n", unit->id, bob); + continue; + } + /*out.print("unit %4d: Duplicating thought type %d (%s), value %s, age %d, subtype %d, severity %d\n", + unit->id, + oldThought->type.value, + ENUM_ATTR(unit_thought_type, caption, (oldThought->type)), + //df::enum_traits::attr_table[oldThought->type].caption + bob, + oldThought->age, + oldThought->subtype, + oldThought->severity + );*/ + //add duplicate thoughts to the temp list + for ( size_t c = 0; c < factor; c++ ) { + df::unit_thought* thought = new df::unit_thought; + thought->type = unit->status.recent_events[b]->type; + thought->age = unit->status.recent_events[b]->age; + thought->subtype = unit->status.recent_events[b]->subtype; + thought->severity = unit->status.recent_events[b]->severity; + newThoughts.push_back(thought); + } + } + for ( size_t b = 0; b < newThoughts.size(); b++ ) { + fakeThoughts.push_back(std::pair(a, unit->status.recent_events.size())); + unit->status.recent_events.push_back(newThoughts[b]); + } + processedThoughtCountTable[unit->id] = unit->status.recent_events.size(); + } + + return CR_OK; +} + +DFhackCExport command_result plugin_init(color_ostream& out, vector &commands) { + commands.push_back(PluginCommand("misery", "increase the intensity of negative dwarven thoughts", + &misery, false, + "misery: When enabled, every new negative dwarven thought will be multiplied by a factor (2 by default).\n" + "Usage:\n" + " misery enable n\n" + " enable misery with optional magnitude n. If specified, n must be positive.\n" + " misery n\n" + " same as \"misery enable n\"\n" + " misery enable\n" + " same as \"misery enable 2\"\n" + " misery disable\n" + " stop adding new negative thoughts. This will not remove existing duplicated thoughts. Equivalent to \"misery 1\"\n" + " misery clear\n" + " remove fake thoughts added in this session of DF. Saving makes them permanent! Does not change factor.\n\n" + )); + return CR_OK; +} + +command_result misery(color_ostream &out, vector& parameters) { + if ( !df::global::world || !df::global::world->map.block_index ) { + out.printerr("misery can only be enabled in fortress mode with a fully-loaded game.\n"); + return CR_FAILURE; + } + + if ( parameters.size() < 1 || parameters.size() > 2 ) { + return CR_WRONG_USAGE; + } + + if ( parameters[0] == "disable" ) { + if ( parameters.size() > 1 ) { + return CR_WRONG_USAGE; + } + factor = 1; + return CR_OK; + } else if ( parameters[0] == "enable" ) { + factor = 2; + if ( parameters.size() == 2 ) { + factor = atoi(parameters[1].c_str()); + if ( factor < 1 ) { + out.printerr("Second argument must be a positive integer.\n"); + return CR_WRONG_USAGE; + } + } + } else if ( parameters[0] == "clear" ) { + for ( size_t a = 0; a < fakeThoughts.size(); a++ ) { + int dorfIndex = fakeThoughts[a].first; + int thoughtIndex = fakeThoughts[a].second; + df::global::world->units.all[dorfIndex]->status.recent_events[thoughtIndex]->age = 1000000; + } + fakeThoughts.clear(); + } else { + int a = atoi(parameters[0].c_str()); + if ( a < 1 ) { + return CR_WRONG_USAGE; + } + factor = a; + } + + return CR_OK; +} -- cgit v1.2.1 From 76cd941084f952a226a0a7777fe72b085f790707 Mon Sep 17 00:00:00 2001 From: expwnent Date: Mon, 20 Aug 2012 22:18:39 -0400 Subject: Added teledwarf: teleports dwarves to their destination instantly. --- plugins/fastdwarf.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 16 deletions(-) diff --git a/plugins/fastdwarf.cpp b/plugins/fastdwarf.cpp index 5a2e2f20..c51684ae 100644 --- a/plugins/fastdwarf.cpp +++ b/plugins/fastdwarf.cpp @@ -23,33 +23,88 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out ) return CR_OK; } -static int enable_fastdwarf = false; +static bool enable_fastdwarf = false; +static bool enable_teledwarf = false; DFhackCExport command_result plugin_onupdate ( color_ostream &out ) { // check run conditions - if(!world || !world->map.block_index || !enable_fastdwarf) + if(!world || !world->map.block_index) { - // give up if we shouldn't be running' + enable_fastdwarf = enable_teledwarf = false; return CR_OK; } int32_t race = ui->race_id; int32_t civ = ui->civ_id; - - for (size_t i = 0; i < world->units.all.size(); i++) - { - df::unit *unit = world->units.all[i]; - - if (unit->race == race && unit->civ_id == civ && unit->counters.job_counter > 0) - unit->counters.job_counter = 0; - // could also patch the unit->job.current_job->completion_timer + + if ( enable_fastdwarf ) { + for (size_t i = 0; i < world->units.all.size(); i++) + { + df::unit *unit = world->units.all[i]; + + if (unit->race == race && unit->civ_id == civ && unit->counters.job_counter > 0) + unit->counters.job_counter = 0; + // could also patch the unit->job.current_job->completion_timer + } + } + if ( enable_teledwarf ) { + for (size_t i = 0; i < world->units.all.size(); i++) + { + df::unit *unit = world->units.all[i]; + + if (unit->race != race || unit->civ_id != civ || unit->path.dest.x == -30000) + continue; + if (unit->relations.draggee_id != -1 || unit->relations.dragger_id != -1) + continue; + if (unit->relations.following != 0) + continue; + + //move immediately to destination + unit->pos.x = unit->path.dest.x; + unit->pos.y = unit->path.dest.y; + unit->pos.z = unit->path.dest.z; + } } return CR_OK; } static command_result fastdwarf (color_ostream &out, vector & parameters) { - if (parameters.size() == 1 && (parameters[0] == "0" || parameters[0] == "1")) + if (parameters.size() == 1) { + if ( parameters[0] == "0" ) { + enable_fastdwarf = true; + enable_teledwarf = false; + } else if ( parameters[0] == "1" ) { + enable_fastdwarf = false; + enable_teledwarf = false; + } else { + out.print("Incorrect usage.\n"); + return CR_OK; + } + } else if (parameters.size() == 2) { + if ( parameters[0] == "0" ) { + enable_fastdwarf = false; + } else if ( parameters[0] == "1" ) { + enable_fastdwarf = true; + } else { + out.print("Incorrect usage.\n"); + return CR_OK; + } + if ( parameters[1] == "0" ) { + enable_teledwarf = false; + } else if ( parameters[1] == "1" ) { + enable_teledwarf = true; + } else { + out.print("Incorrect usage.\n"); + return CR_OK; + } + } else if (parameters.size() == 0) { + //print status + } else { + out.print("Incorrect usage.\n"); + return CR_OK; + } + /*if (parameters.size() == 1 && (parameters[0] == "0" || parameters[0] == "1")) { if (parameters[0] == "0") enable_fastdwarf = 0; @@ -62,7 +117,7 @@ static command_result fastdwarf (color_ostream &out, vector & parameter out.print("Makes your minions move at ludicrous speeds.\n" "Activate with 'fastdwarf 1', deactivate with 'fastdwarf 0'.\n" "Current state: %d.\n", enable_fastdwarf); - } + }*/ return CR_OK; } @@ -70,8 +125,17 @@ static command_result fastdwarf (color_ostream &out, vector & parameter DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand("fastdwarf", - "enable/disable fastdwarf (parameter=0/1)", - fastdwarf)); - + "enable/disable fastdwarf and teledwarf (parameters=0/1)", + fastdwarf, false, + "fastdwarf: controls speedydwarf and teledwarf. Speedydwarf makes dwarves move quickly and perform tasks quickly. Teledwarf makes dwarves move instantaneously, but do jobs at the same speed.\n" + "Usage:\n" + " fastdwarf 0 0: disable both speedydwarf and teledwarf\n" + " fastdwarf 0 1: disable speedydwarf, enable teledwarf\n" + " fastdwarf 1 0: enable speedydwarf, disable teledwarf\n" + " fastdwarf 1 1: enable speedydwarf, enable teledwarf\n" + " fastdwarf 0: disable speedydwarf, disable teledwarf\n" + " fastdwarf 1: enable speedydwarf, disable teledwarf\n" + )); + return CR_OK; } -- cgit v1.2.1 From 15adb17559992fd6feb87d26235c1280bf8c009c Mon Sep 17 00:00:00 2001 From: expwnent Date: Thu, 23 Aug 2012 22:21:09 -0400 Subject: Converted tabs to spaces. --- plugins/CMakeLists.txt | 2 +- plugins/misery.cpp | 272 ++++++++++++++++++++++++------------------------- 2 files changed, 137 insertions(+), 137 deletions(-) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 670c9ce7..55a7c250 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -115,7 +115,7 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(sort sort.cpp LINK_LIBRARIES lua) # not yet. busy with other crud again... #DFHACK_PLUGIN(versionosd versionosd.cpp) - DFHACK_PLUGIN(misery misery.cpp) + DFHACK_PLUGIN(misery misery.cpp) endif() diff --git a/plugins/misery.cpp b/plugins/misery.cpp index f17a4559..260eedd8 100644 --- a/plugins/misery.cpp +++ b/plugins/misery.cpp @@ -26,149 +26,149 @@ DFHACK_PLUGIN("misery"); command_result misery(color_ostream& out, vector& parameters); DFhackCExport command_result plugin_shutdown(color_ostream& out) { - factor = 1; - return CR_OK; + factor = 1; + return CR_OK; } DFhackCExport command_result plugin_onupdate(color_ostream& out) { - static bool wasLoaded = false; - if ( factor == 1 || !df::global::world || !df::global::world->map.block_index ) { - if ( wasLoaded ) { - //we just unloaded the game: clear all data - factor = 1; - processedThoughtCountTable.clear(); - fakeThoughts.clear(); - wasLoaded = false; - } - return CR_OK; - } - - if ( !wasLoaded ) { - wasLoaded = true; - } - - int32_t race_id = df::global::ui->race_id; - int32_t civ_id = df::global::ui->civ_id; - for ( size_t a = 0; a < df::global::world->units.all.size(); a++ ) { - df::unit* unit = df::global::world->units.all[a]; //TODO: consider units.active - //living, native units only - if ( unit->race != race_id || unit->civ_id != civ_id ) - continue; - if ( unit->flags1.bits.dead ) - continue; - - int processedThoughtCount; - map::iterator i = processedThoughtCountTable.find(unit->id); - if ( i == processedThoughtCountTable.end() ) { - processedThoughtCount = unit->status.recent_events.size(); - processedThoughtCountTable[unit->id] = processedThoughtCount; - } else { - processedThoughtCount = (*i).second; - } - - if ( processedThoughtCount == unit->status.recent_events.size() ) { - continue; - } else if ( processedThoughtCount > unit->status.recent_events.size() ) { - processedThoughtCount = unit->status.recent_events.size(); - } - - //don't reprocess any old thoughts - vector newThoughts; - for ( size_t b = processedThoughtCount; b < unit->status.recent_events.size(); b++ ) { - df::unit_thought* oldThought = unit->status.recent_events[b]; - const char* bob = ENUM_ATTR(unit_thought_type, value, oldThought->type); - if ( bob[0] != '-' ) { - //out.print("unit %4d: old thought value = %s\n", unit->id, bob); - continue; - } - /*out.print("unit %4d: Duplicating thought type %d (%s), value %s, age %d, subtype %d, severity %d\n", - unit->id, - oldThought->type.value, - ENUM_ATTR(unit_thought_type, caption, (oldThought->type)), - //df::enum_traits::attr_table[oldThought->type].caption - bob, - oldThought->age, - oldThought->subtype, - oldThought->severity - );*/ - //add duplicate thoughts to the temp list - for ( size_t c = 0; c < factor; c++ ) { - df::unit_thought* thought = new df::unit_thought; - thought->type = unit->status.recent_events[b]->type; - thought->age = unit->status.recent_events[b]->age; - thought->subtype = unit->status.recent_events[b]->subtype; - thought->severity = unit->status.recent_events[b]->severity; - newThoughts.push_back(thought); - } - } - for ( size_t b = 0; b < newThoughts.size(); b++ ) { - fakeThoughts.push_back(std::pair(a, unit->status.recent_events.size())); - unit->status.recent_events.push_back(newThoughts[b]); - } - processedThoughtCountTable[unit->id] = unit->status.recent_events.size(); - } - - return CR_OK; + static bool wasLoaded = false; + if ( factor == 1 || !df::global::world || !df::global::world->map.block_index ) { + if ( wasLoaded ) { + //we just unloaded the game: clear all data + factor = 1; + processedThoughtCountTable.clear(); + fakeThoughts.clear(); + wasLoaded = false; + } + return CR_OK; + } + + if ( !wasLoaded ) { + wasLoaded = true; + } + + int32_t race_id = df::global::ui->race_id; + int32_t civ_id = df::global::ui->civ_id; + for ( size_t a = 0; a < df::global::world->units.all.size(); a++ ) { + df::unit* unit = df::global::world->units.all[a]; //TODO: consider units.active + //living, native units only + if ( unit->race != race_id || unit->civ_id != civ_id ) + continue; + if ( unit->flags1.bits.dead ) + continue; + + int processedThoughtCount; + map::iterator i = processedThoughtCountTable.find(unit->id); + if ( i == processedThoughtCountTable.end() ) { + processedThoughtCount = unit->status.recent_events.size(); + processedThoughtCountTable[unit->id] = processedThoughtCount; + } else { + processedThoughtCount = (*i).second; + } + + if ( processedThoughtCount == unit->status.recent_events.size() ) { + continue; + } else if ( processedThoughtCount > unit->status.recent_events.size() ) { + processedThoughtCount = unit->status.recent_events.size(); + } + + //don't reprocess any old thoughts + vector newThoughts; + for ( size_t b = processedThoughtCount; b < unit->status.recent_events.size(); b++ ) { + df::unit_thought* oldThought = unit->status.recent_events[b]; + const char* bob = ENUM_ATTR(unit_thought_type, value, oldThought->type); + if ( bob[0] != '-' ) { + //out.print("unit %4d: old thought value = %s\n", unit->id, bob); + continue; + } + /*out.print("unit %4d: Duplicating thought type %d (%s), value %s, age %d, subtype %d, severity %d\n", + unit->id, + oldThought->type.value, + ENUM_ATTR(unit_thought_type, caption, (oldThought->type)), + //df::enum_traits::attr_table[oldThought->type].caption + bob, + oldThought->age, + oldThought->subtype, + oldThought->severity + );*/ + //add duplicate thoughts to the temp list + for ( size_t c = 0; c < factor; c++ ) { + df::unit_thought* thought = new df::unit_thought; + thought->type = unit->status.recent_events[b]->type; + thought->age = unit->status.recent_events[b]->age; + thought->subtype = unit->status.recent_events[b]->subtype; + thought->severity = unit->status.recent_events[b]->severity; + newThoughts.push_back(thought); + } + } + for ( size_t b = 0; b < newThoughts.size(); b++ ) { + fakeThoughts.push_back(std::pair(a, unit->status.recent_events.size())); + unit->status.recent_events.push_back(newThoughts[b]); + } + processedThoughtCountTable[unit->id] = unit->status.recent_events.size(); + } + + return CR_OK; } DFhackCExport command_result plugin_init(color_ostream& out, vector &commands) { - commands.push_back(PluginCommand("misery", "increase the intensity of negative dwarven thoughts", - &misery, false, - "misery: When enabled, every new negative dwarven thought will be multiplied by a factor (2 by default).\n" - "Usage:\n" - " misery enable n\n" - " enable misery with optional magnitude n. If specified, n must be positive.\n" - " misery n\n" - " same as \"misery enable n\"\n" - " misery enable\n" - " same as \"misery enable 2\"\n" - " misery disable\n" - " stop adding new negative thoughts. This will not remove existing duplicated thoughts. Equivalent to \"misery 1\"\n" - " misery clear\n" - " remove fake thoughts added in this session of DF. Saving makes them permanent! Does not change factor.\n\n" - )); - return CR_OK; + commands.push_back(PluginCommand("misery", "increase the intensity of negative dwarven thoughts", + &misery, false, + "misery: When enabled, every new negative dwarven thought will be multiplied by a factor (2 by default).\n" + "Usage:\n" + " misery enable n\n" + " enable misery with optional magnitude n. If specified, n must be positive.\n" + " misery n\n" + " same as \"misery enable n\"\n" + " misery enable\n" + " same as \"misery enable 2\"\n" + " misery disable\n" + " stop adding new negative thoughts. This will not remove existing duplicated thoughts. Equivalent to \"misery 1\"\n" + " misery clear\n" + " remove fake thoughts added in this session of DF. Saving makes them permanent! Does not change factor.\n\n" + )); + return CR_OK; } command_result misery(color_ostream &out, vector& parameters) { - if ( !df::global::world || !df::global::world->map.block_index ) { - out.printerr("misery can only be enabled in fortress mode with a fully-loaded game.\n"); - return CR_FAILURE; - } - - if ( parameters.size() < 1 || parameters.size() > 2 ) { - return CR_WRONG_USAGE; - } - - if ( parameters[0] == "disable" ) { - if ( parameters.size() > 1 ) { - return CR_WRONG_USAGE; - } - factor = 1; - return CR_OK; - } else if ( parameters[0] == "enable" ) { - factor = 2; - if ( parameters.size() == 2 ) { - factor = atoi(parameters[1].c_str()); - if ( factor < 1 ) { - out.printerr("Second argument must be a positive integer.\n"); - return CR_WRONG_USAGE; - } - } - } else if ( parameters[0] == "clear" ) { - for ( size_t a = 0; a < fakeThoughts.size(); a++ ) { - int dorfIndex = fakeThoughts[a].first; - int thoughtIndex = fakeThoughts[a].second; - df::global::world->units.all[dorfIndex]->status.recent_events[thoughtIndex]->age = 1000000; - } - fakeThoughts.clear(); - } else { - int a = atoi(parameters[0].c_str()); - if ( a < 1 ) { - return CR_WRONG_USAGE; - } - factor = a; - } - - return CR_OK; + if ( !df::global::world || !df::global::world->map.block_index ) { + out.printerr("misery can only be enabled in fortress mode with a fully-loaded game.\n"); + return CR_FAILURE; + } + + if ( parameters.size() < 1 || parameters.size() > 2 ) { + return CR_WRONG_USAGE; + } + + if ( parameters[0] == "disable" ) { + if ( parameters.size() > 1 ) { + return CR_WRONG_USAGE; + } + factor = 1; + return CR_OK; + } else if ( parameters[0] == "enable" ) { + factor = 2; + if ( parameters.size() == 2 ) { + factor = atoi(parameters[1].c_str()); + if ( factor < 1 ) { + out.printerr("Second argument must be a positive integer.\n"); + return CR_WRONG_USAGE; + } + } + } else if ( parameters[0] == "clear" ) { + for ( size_t a = 0; a < fakeThoughts.size(); a++ ) { + int dorfIndex = fakeThoughts[a].first; + int thoughtIndex = fakeThoughts[a].second; + df::global::world->units.all[dorfIndex]->status.recent_events[thoughtIndex]->age = 1000000; + } + fakeThoughts.clear(); + } else { + int a = atoi(parameters[0].c_str()); + if ( a < 1 ) { + return CR_WRONG_USAGE; + } + factor = a; + } + + return CR_OK; } -- cgit v1.2.1 From e12e7ddd40677f6048993bbbe12886f3982c0b43 Mon Sep 17 00:00:00 2001 From: expwnent Date: Mon, 27 Aug 2012 14:42:00 -0400 Subject: Fixed some memory leaks. --- plugins/dig.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/dig.cpp b/plugins/dig.cpp index c1b6f633..5e2bb9f8 100644 --- a/plugins/dig.cpp +++ b/plugins/dig.cpp @@ -963,7 +963,7 @@ command_result digexp (color_ostream &out, vector & parameters) mx.setDesignationAt(pos,des); } } - mx.WriteAll(); + mx.WriteAll(); } else for(uint32_t x = 0; x < x_max; x++) { @@ -1141,6 +1141,7 @@ command_result digv (color_ostream &out, vector & parameters) } } MCache->WriteAll(); + delete MCache; return CR_OK; } @@ -1354,6 +1355,7 @@ command_result digl (color_ostream &out, vector & parameters) } } MCache->WriteAll(); + delete MCache; return CR_OK; } -- cgit v1.2.1 From 1a5f05768f9abee0b932f712794045eef526cb2a Mon Sep 17 00:00:00 2001 From: expwnent Date: Mon, 27 Aug 2012 15:06:41 -0400 Subject: Made it not run every tick. --- plugins/misery.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/misery.cpp b/plugins/misery.cpp index 260eedd8..9e0535d5 100644 --- a/plugins/misery.cpp +++ b/plugins/misery.cpp @@ -20,6 +20,8 @@ static map processedThoughtCountTable; //keep track of fake thoughts so you can remove them if requested static vector > fakeThoughts; +static int count; +const int maxCount = 1000; DFHACK_PLUGIN("misery"); @@ -46,6 +48,12 @@ DFhackCExport command_result plugin_onupdate(color_ostream& out) { if ( !wasLoaded ) { wasLoaded = true; } + + if ( count < maxCount ) { + count++; + return CR_OK; + } + count = 0; int32_t race_id = df::global::ui->race_id; int32_t civ_id = df::global::ui->civ_id; @@ -172,3 +180,4 @@ command_result misery(color_ostream &out, vector& parameters) { return CR_OK; } + -- cgit v1.2.1 From d69a7c63e3fae75a9acb0de3e1038c9507dc4ed3 Mon Sep 17 00:00:00 2001 From: expwnent Date: Mon, 27 Aug 2012 16:05:23 -0400 Subject: Tabs to spaces. --- plugins/misery.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/misery.cpp b/plugins/misery.cpp index 9e0535d5..a0c0a239 100644 --- a/plugins/misery.cpp +++ b/plugins/misery.cpp @@ -50,8 +50,8 @@ DFhackCExport command_result plugin_onupdate(color_ostream& out) { } if ( count < maxCount ) { - count++; - return CR_OK; + count++; + return CR_OK; } count = 0; -- cgit v1.2.1 From 79ac1a81b9c2751c162fc413c91ef0ee84766d01 Mon Sep 17 00:00:00 2001 From: expwnent Date: Fri, 28 Sep 2012 16:36:37 -0400 Subject: It was backwards when calling fastdwarf with just one argument. Also made it print the current status of fastdwarf when no arguments are given. --- plugins/fastdwarf.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/fastdwarf.cpp b/plugins/fastdwarf.cpp index c51684ae..400bff23 100644 --- a/plugins/fastdwarf.cpp +++ b/plugins/fastdwarf.cpp @@ -72,10 +72,10 @@ static command_result fastdwarf (color_ostream &out, vector & parameter { if (parameters.size() == 1) { if ( parameters[0] == "0" ) { - enable_fastdwarf = true; + enable_fastdwarf = false; enable_teledwarf = false; } else if ( parameters[0] == "1" ) { - enable_fastdwarf = false; + enable_fastdwarf = true; enable_teledwarf = false; } else { out.print("Incorrect usage.\n"); @@ -100,6 +100,7 @@ static command_result fastdwarf (color_ostream &out, vector & parameter } } else if (parameters.size() == 0) { //print status + out.print("Current state: fast = %d, teleport = %d.\n", enable_fastdwarf, enable_teledwarf); } else { out.print("Incorrect usage.\n"); return CR_OK; -- cgit v1.2.1 From 1bde32fa5b72a070a81c142b4044f8fd355e2145 Mon Sep 17 00:00:00 2001 From: expwnent Date: Fri, 28 Sep 2012 19:06:22 -0400 Subject: Fixed a tile occupancy problem with teleporting dwarves. --- plugins/fastdwarf.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/fastdwarf.cpp b/plugins/fastdwarf.cpp index 400bff23..4c235394 100644 --- a/plugins/fastdwarf.cpp +++ b/plugins/fastdwarf.cpp @@ -2,6 +2,7 @@ #include "Console.h" #include "Export.h" #include "PluginManager.h" +#include "modules/MapCache.h" #include "DataDefs.h" #include "df/ui.h" @@ -48,6 +49,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) } } if ( enable_teledwarf ) { + MapExtras::MapCache *MCache = new MapExtras::MapCache(); for (size_t i = 0; i < world->units.all.size(); i++) { df::unit *unit = world->units.all[i]; @@ -59,11 +61,19 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) if (unit->relations.following != 0) continue; + MapExtras::Block* block = MCache->BlockAtTile(unit->pos); + df::coord2d pos(unit->pos.x % 16, unit->pos.y % 16); + df::tile_occupancy occ = block->OccupancyAt(pos); + occ.bits.unit = 0; + block->setOccupancyAt(pos, occ); + //move immediately to destination unit->pos.x = unit->path.dest.x; unit->pos.y = unit->path.dest.y; unit->pos.z = unit->path.dest.z; } + MCache->WriteAll(); + delete MCache; } return CR_OK; } -- cgit v1.2.1 From d41c4849f96eef155b41eac29d887ce926bd1781 Mon Sep 17 00:00:00 2001 From: expwnent Date: Fri, 28 Sep 2012 19:17:12 -0400 Subject: Fixed unit_grounded in teleporting dwarf tile. --- plugins/fastdwarf.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/fastdwarf.cpp b/plugins/fastdwarf.cpp index 4c235394..aea14e7f 100644 --- a/plugins/fastdwarf.cpp +++ b/plugins/fastdwarf.cpp @@ -65,6 +65,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) df::coord2d pos(unit->pos.x % 16, unit->pos.y % 16); df::tile_occupancy occ = block->OccupancyAt(pos); occ.bits.unit = 0; + occ.bits.unit_grounded = 0; block->setOccupancyAt(pos, occ); //move immediately to destination -- cgit v1.2.1