2011-05-14 17:53:43 -06:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <map>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
2011-07-26 03:01:16 -06:00
|
|
|
#include <string>
|
2011-05-14 17:53:43 -06:00
|
|
|
|
2011-07-26 03:01:16 -06:00
|
|
|
#include <dfhack/Core.h>
|
|
|
|
#include <dfhack/Console.h>
|
|
|
|
#include <dfhack/Export.h>
|
|
|
|
#include <dfhack/PluginManager.h>
|
|
|
|
#include <dfhack/modules/Vegetation.h>
|
|
|
|
#include <dfhack/modules/Maps.h>
|
|
|
|
#include <dfhack/modules/Gui.h>
|
|
|
|
#include <dfhack/TileTypes.h>
|
2011-05-14 17:53:43 -06:00
|
|
|
#include <dfhack/extra/MapExtras.h>
|
|
|
|
|
2011-07-26 03:01:16 -06:00
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
DFhackCExport command_result df_grow (Core * c, vector <string> & parameters);
|
|
|
|
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
2011-05-14 17:53:43 -06:00
|
|
|
{
|
2011-07-26 03:01:16 -06:00
|
|
|
return "grow";
|
|
|
|
}
|
2011-05-14 17:53:43 -06:00
|
|
|
|
2011-07-26 03:01:16 -06:00
|
|
|
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
commands.clear();
|
|
|
|
commands.push_back(PluginCommand("grow", "Grows saplings into trees (with active cursor, only the targetted one).", df_grow));
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2011-05-14 17:53:43 -06:00
|
|
|
|
2011-07-26 03:01:16 -06:00
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2011-05-14 17:53:43 -06:00
|
|
|
|
2011-07-26 03:01:16 -06:00
|
|
|
DFhackCExport command_result df_grow (Core * c, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
//uint32_t x_max = 0, y_max = 0, z_max = 0;
|
|
|
|
c->Suspend();
|
|
|
|
DFHack::Maps *maps = c->getMaps();
|
|
|
|
Console & con = c->con;
|
2011-05-14 17:53:43 -06:00
|
|
|
if (!maps->Start())
|
|
|
|
{
|
2011-07-26 03:01:16 -06:00
|
|
|
con.printerr("Cannot get map info!\n");
|
|
|
|
c->Resume();
|
|
|
|
return CR_FAILURE;
|
2011-05-14 17:53:43 -06:00
|
|
|
}
|
2011-07-26 03:01:16 -06:00
|
|
|
//maps->getSize(x_max, y_max, z_max);
|
2011-05-14 17:53:43 -06:00
|
|
|
MapExtras::MapCache map(maps);
|
2011-07-26 03:01:16 -06:00
|
|
|
DFHack::Vegetation *veg = c->getVegetation();
|
|
|
|
if (!veg->all_plants)
|
2011-05-14 17:53:43 -06:00
|
|
|
{
|
2011-07-26 03:01:16 -06:00
|
|
|
con.printerr("Unable to read vegetation!\n");
|
|
|
|
c->Resume();
|
|
|
|
return CR_FAILURE;
|
2011-05-14 17:53:43 -06:00
|
|
|
}
|
2011-07-26 03:01:16 -06:00
|
|
|
DFHack::Gui *Gui = c->getGui();
|
2011-05-14 17:53:43 -06:00
|
|
|
int32_t x,y,z;
|
|
|
|
if(Gui->getCursorCoords(x,y,z))
|
|
|
|
{
|
2011-07-26 03:01:16 -06:00
|
|
|
vector<DFHack::df_plant *> * alltrees;
|
|
|
|
if(maps->ReadVegetation(x/16,y/16,z,alltrees))
|
2011-05-14 17:53:43 -06:00
|
|
|
{
|
2011-07-26 03:01:16 -06:00
|
|
|
for(size_t i = 0 ; i < alltrees->size(); i++)
|
2011-05-14 17:53:43 -06:00
|
|
|
{
|
2011-07-26 03:01:16 -06:00
|
|
|
DFHack::df_plant * tree = alltrees->at(i);
|
|
|
|
if(tree->x == x && tree->y == y && tree->z == z)
|
2011-05-14 17:53:43 -06:00
|
|
|
{
|
|
|
|
if(DFHack::tileShape(map.tiletypeAt(DFHack::DFCoord(x,y,z))) == DFHack::SAPLING_OK)
|
|
|
|
{
|
2011-07-26 03:01:16 -06:00
|
|
|
tree->grow_counter = DFHack::sapling_to_tree_threshold;
|
2011-05-14 17:53:43 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int grown = 0;
|
2011-07-26 03:01:16 -06:00
|
|
|
for(size_t i = 0 ; i < veg->all_plants->size(); i++)
|
2011-05-14 17:53:43 -06:00
|
|
|
{
|
2011-07-26 03:01:16 -06:00
|
|
|
DFHack::df_plant *p = veg->all_plants->at(i);
|
|
|
|
uint16_t ttype = map.tiletypeAt(DFHack::DFCoord(p->x,p->y,p->z));
|
|
|
|
if(!p->is_shrub && DFHack::tileShape(ttype) == DFHack::SAPLING_OK)
|
2011-05-14 17:53:43 -06:00
|
|
|
{
|
2011-07-26 03:01:16 -06:00
|
|
|
p->grow_counter = DFHack::sapling_to_tree_threshold;
|
2011-05-14 17:53:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
veg->Finish();
|
|
|
|
maps->Finish();
|
2011-07-26 03:01:16 -06:00
|
|
|
c->Resume();
|
|
|
|
return CR_OK;
|
2011-05-14 17:53:43 -06:00
|
|
|
}
|
2011-07-26 03:01:16 -06:00
|
|
|
|