2011-08-01 18:21:25 -06:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <map>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
|
|
|
#include "modules/Maps.h"
|
|
|
|
#include "modules/Gui.h"
|
|
|
|
#include "TileTypes.h"
|
|
|
|
#include "modules/MapCache.h"
|
2013-01-02 09:26:30 -07:00
|
|
|
#include "df/plant.h"
|
2011-08-01 18:21:25 -06:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using namespace DFHack;
|
2012-01-21 16:54:57 -07:00
|
|
|
using df::global::world;
|
|
|
|
|
2013-01-02 09:26:30 -07:00
|
|
|
const uint32_t sapling_to_tree_threshold = 120 * 28 * 12 * 3; // 3 years
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result df_grow (color_ostream &out, vector <string> & parameters);
|
|
|
|
command_result df_immolate (color_ostream &out, vector <string> & parameters);
|
|
|
|
command_result df_extirpate (color_ostream &out, vector <string> & parameters);
|
2011-08-01 18:21:25 -06:00
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
DFHACK_PLUGIN("plants");
|
2011-08-01 18:21:25 -06:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
|
|
|
commands.push_back(PluginCommand("grow", "Grows saplings into trees (with active cursor, only the targetted one).", df_grow));
|
|
|
|
commands.push_back(PluginCommand("immolate", "Set plants on fire (under cursor, 'shrubs', 'trees' or 'all').", df_immolate));
|
|
|
|
commands.push_back(PluginCommand("extirpate", "Kill plants (same mechanics as immolate).", df_extirpate));
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum do_what
|
|
|
|
{
|
|
|
|
do_immolate,
|
|
|
|
do_extirpate
|
|
|
|
};
|
|
|
|
|
2011-08-08 17:50:22 -06:00
|
|
|
static bool getoptions( vector <string> & parameters, bool & shrubs, bool & trees, bool & help)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2012-01-31 09:55:38 -07:00
|
|
|
for(size_t i = 0;i < parameters.size();i++)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
|
|
|
if(parameters[i] == "shrubs")
|
|
|
|
{
|
|
|
|
shrubs = true;
|
|
|
|
}
|
|
|
|
else if(parameters[i] == "trees")
|
|
|
|
{
|
|
|
|
trees = true;
|
|
|
|
}
|
|
|
|
else if(parameters[i] == "all")
|
|
|
|
{
|
|
|
|
trees = true;
|
|
|
|
shrubs = true;
|
|
|
|
}
|
2011-08-08 17:50:22 -06:00
|
|
|
else if(parameters[i] == "help" || parameters[i] == "?")
|
|
|
|
{
|
|
|
|
help = true;
|
|
|
|
}
|
2011-08-01 18:21:25 -06:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Book of Immolations, chapter 1, verse 35:
|
|
|
|
* Armok emerged from the hellish depths and beheld the sunny realms for the first time.
|
|
|
|
* And he cursed the plants and trees for their bloodless wood, turning them into ash and smoldering ruin.
|
|
|
|
* Armok was pleased and great temples were built by the dwarves, for they shared his hatred for trees and plants.
|
|
|
|
*/
|
2012-03-10 04:55:42 -07:00
|
|
|
static command_result immolations (color_ostream &out, do_what what, bool shrubs, bool trees, bool help)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2011-08-08 17:50:22 -06:00
|
|
|
static const char * what1 = "destroys";
|
|
|
|
static const char * what2 = "burns";
|
|
|
|
if(help)
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Without any options, this command %s a plant under the cursor.\n"
|
2011-08-08 17:50:22 -06:00
|
|
|
"Options:\n"
|
|
|
|
"shrubs - affect all shrubs\n"
|
|
|
|
"trees - affect all trees\n"
|
|
|
|
"all - affect all plants\n",
|
|
|
|
what == do_immolate? what2 : what1
|
|
|
|
);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-03-10 04:55:42 -07:00
|
|
|
CoreSuspender suspend;
|
2012-01-19 20:44:17 -07:00
|
|
|
if (!Maps::IsValid())
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Map is not available!\n");
|
2011-08-01 18:21:25 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
uint32_t x_max, y_max, z_max;
|
2012-01-19 20:44:17 -07:00
|
|
|
Maps::getSize(x_max, y_max, z_max);
|
|
|
|
MapExtras::MapCache map;
|
2011-08-01 18:21:25 -06:00
|
|
|
if(shrubs || trees)
|
|
|
|
{
|
|
|
|
int destroyed = 0;
|
2012-01-21 16:54:57 -07:00
|
|
|
for(size_t i = 0 ; i < world->plants.all.size(); i++)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2012-01-21 16:54:57 -07:00
|
|
|
df::plant *p = world->plants.all[i];
|
|
|
|
if(shrubs && p->flags.bits.is_shrub || trees && !p->flags.bits.is_shrub)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
|
|
|
if (what == do_immolate)
|
2013-01-02 09:26:30 -07:00
|
|
|
p->damage_flags.bits.is_burning = true;
|
2011-08-01 18:21:25 -06:00
|
|
|
p->hitpoints = 0;
|
|
|
|
destroyed ++;
|
|
|
|
}
|
|
|
|
}
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Praise Armok!\n");
|
2011-08-01 18:21:25 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int32_t x,y,z;
|
2012-03-03 06:38:24 -07:00
|
|
|
if(Gui::getCursorCoords(x,y,z))
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2012-04-11 02:01:27 -06:00
|
|
|
auto block = Maps::getTileBlock(x,y,z);
|
|
|
|
vector<df::plant *> *alltrees = block ? &block->plants : NULL;
|
|
|
|
if(alltrees)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
|
|
|
bool didit = false;
|
|
|
|
for(size_t i = 0 ; i < alltrees->size(); i++)
|
|
|
|
{
|
2012-01-21 16:54:57 -07:00
|
|
|
df::plant * tree = alltrees->at(i);
|
|
|
|
if(tree->pos.x == x && tree->pos.y == y && tree->pos.z == z)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
|
|
|
if(what == do_immolate)
|
2013-01-02 09:26:30 -07:00
|
|
|
tree->damage_flags.bits.is_burning = true;
|
2011-08-01 18:21:25 -06:00
|
|
|
tree->hitpoints = 0;
|
|
|
|
didit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
if(!didit)
|
|
|
|
{
|
|
|
|
cout << "----==== There's NOTHING there! ====----" << endl;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("No mass destruction and no cursor...\n" );
|
2011-08-01 18:21:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result df_immolate (color_ostream &out, vector <string> & parameters)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2011-08-08 17:50:22 -06:00
|
|
|
bool shrubs = false, trees = false, help = false;
|
|
|
|
if(getoptions(parameters,shrubs,trees,help))
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
return immolations(out,do_immolate,shrubs,trees, help);
|
2011-08-01 18:21:25 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Invalid parameter!\n");
|
2011-08-01 18:21:25 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result df_extirpate (color_ostream &out, vector <string> & parameters)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2011-08-08 17:50:22 -06:00
|
|
|
bool shrubs = false, trees = false, help = false;
|
|
|
|
if(getoptions(parameters,shrubs,trees, help))
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
return immolations(out,do_extirpate,shrubs,trees, help);
|
2011-08-01 18:21:25 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Invalid parameter!\n");
|
2011-08-01 18:21:25 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result df_grow (color_ostream &out, vector <string> & parameters)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2012-01-31 09:55:38 -07:00
|
|
|
for(size_t i = 0; i < parameters.size();i++)
|
2011-08-08 17:50:22 -06:00
|
|
|
{
|
|
|
|
if(parameters[i] == "help" || parameters[i] == "?")
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("This command turns all living saplings into full-grown trees.\n");
|
2011-08-08 17:50:22 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
2012-03-10 04:55:42 -07:00
|
|
|
CoreSuspender suspend;
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
if (!Maps::IsValid())
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Map is not available!\n");
|
2011-08-01 18:21:25 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2012-01-19 20:44:17 -07:00
|
|
|
MapExtras::MapCache map;
|
2011-08-01 18:21:25 -06:00
|
|
|
int32_t x,y,z;
|
2012-03-03 06:38:24 -07:00
|
|
|
if(Gui::getCursorCoords(x,y,z))
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2012-04-11 02:01:27 -06:00
|
|
|
auto block = Maps::getTileBlock(x,y,z);
|
|
|
|
vector<df::plant *> *alltrees = block ? &block->plants : NULL;
|
|
|
|
if(alltrees)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
|
|
|
for(size_t i = 0 ; i < alltrees->size(); i++)
|
|
|
|
{
|
2012-01-21 16:54:57 -07:00
|
|
|
df::plant * tree = alltrees->at(i);
|
|
|
|
if(tree->pos.x == x && tree->pos.y == y && tree->pos.z == z)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2012-02-13 15:56:33 -07:00
|
|
|
if(tileShape(map.tiletypeAt(DFCoord(x,y,z))) == tiletype_shape::SAPLING &&
|
|
|
|
tileSpecial(map.tiletypeAt(DFCoord(x,y,z))) != tiletype_special::DEAD)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2013-01-02 09:26:30 -07:00
|
|
|
tree->grow_counter = sapling_to_tree_threshold;
|
2011-08-01 18:21:25 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int grown = 0;
|
2012-01-21 16:54:57 -07:00
|
|
|
for(size_t i = 0 ; i < world->plants.all.size(); i++)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2012-01-21 16:54:57 -07:00
|
|
|
df::plant *p = world->plants.all[i];
|
2012-02-13 15:56:33 -07:00
|
|
|
df::tiletype ttype = map.tiletypeAt(df::coord(p->pos.x,p->pos.y,p->pos.z));
|
|
|
|
if(!p->flags.bits.is_shrub && tileShape(ttype) == tiletype_shape::SAPLING && tileSpecial(ttype) != tiletype_special::DEAD)
|
2011-08-01 18:21:25 -06:00
|
|
|
{
|
2013-01-02 09:26:30 -07:00
|
|
|
p->grow_counter = sapling_to_tree_threshold;
|
2011-08-01 18:21:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|