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"
|
2011-07-13 00:17:51 -06:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "modules/Vermin.h"
|
|
|
|
#include "modules/Materials.h"
|
2011-07-13 00:17:51 -06:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using namespace DFHack;
|
2012-01-07 22:59:52 -07:00
|
|
|
using namespace DFHack::Simple;
|
2011-07-13 00:17:51 -06:00
|
|
|
|
2012-02-13 21:54:08 -07:00
|
|
|
command_result colonies (Core * c, vector <string> & parameters);
|
2011-07-13 00:17:51 -06:00
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
DFHACK_PLUGIN("colonies");
|
2011-07-13 00:17:51 -06:00
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
2012-01-28 05:03:56 -07:00
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"colonies", "List or change wild colonies (ants hills and such)",
|
|
|
|
colonies, false,
|
|
|
|
" Without any options, this command lists all the vermin colonies present.\n"
|
|
|
|
"Options:\n"
|
2012-02-04 20:28:20 -07:00
|
|
|
//" kill - destroy colonies\n" // unlisted because it's likely broken anyway
|
|
|
|
" bees - turn colonies into honey bee hives\n"
|
2012-01-28 05:03:56 -07:00
|
|
|
));
|
2011-07-13 00:17:51 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-07 22:59:52 -07:00
|
|
|
void destroyColonies();
|
2012-01-15 13:54:14 -07:00
|
|
|
void convertColonies(Materials *Materials);
|
|
|
|
void showColonies(Core *c, Materials *Materials);
|
2011-07-13 00:17:51 -06:00
|
|
|
|
2012-02-13 21:54:08 -07:00
|
|
|
command_result colonies (Core * c, vector <string> & parameters)
|
2011-07-13 00:17:51 -06:00
|
|
|
{
|
|
|
|
bool destroy = false;
|
|
|
|
bool convert = false;
|
|
|
|
|
2012-01-31 09:55:38 -07:00
|
|
|
for(size_t i = 0; i < parameters.size();i++)
|
2011-07-13 00:17:51 -06:00
|
|
|
{
|
|
|
|
if(parameters[i] == "kill")
|
|
|
|
destroy = true;
|
|
|
|
else if(parameters[i] == "bees")
|
|
|
|
convert = true;
|
2012-01-28 05:03:56 -07:00
|
|
|
else
|
|
|
|
return CR_WRONG_USAGE;
|
2011-07-13 00:17:51 -06:00
|
|
|
}
|
|
|
|
if (destroy && convert)
|
|
|
|
{
|
2011-08-03 20:18:38 -06:00
|
|
|
c->con.printerr("Kill or make bees? DECIDE!\n");
|
2011-07-13 00:17:51 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2012-01-21 17:31:15 -07:00
|
|
|
CoreSuspender suspend(c);
|
2011-07-13 00:17:51 -06:00
|
|
|
|
|
|
|
Materials * materials = c->getMaterials();
|
|
|
|
|
|
|
|
materials->ReadCreatureTypesEx();
|
|
|
|
|
|
|
|
if (destroy)
|
2012-01-07 22:59:52 -07:00
|
|
|
destroyColonies();
|
2011-07-13 00:17:51 -06:00
|
|
|
else if (convert)
|
2012-01-07 22:59:52 -07:00
|
|
|
convertColonies(materials);
|
2011-07-13 00:17:51 -06:00
|
|
|
else
|
2012-01-07 22:59:52 -07:00
|
|
|
showColonies(c, materials);
|
2011-07-13 00:17:51 -06:00
|
|
|
|
|
|
|
materials->Finish();
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-09 16:45:43 -07:00
|
|
|
//FIXME: this is probably bullshit
|
2012-01-07 22:59:52 -07:00
|
|
|
void destroyColonies()
|
2011-07-13 00:17:51 -06:00
|
|
|
{
|
2012-01-07 22:59:52 -07:00
|
|
|
uint32_t numSpawnPoints = Vermin::getNumVermin();
|
2011-07-13 00:17:51 -06:00
|
|
|
for (uint32_t i = 0; i < numSpawnPoints; i++)
|
|
|
|
{
|
2012-01-07 22:59:52 -07:00
|
|
|
Vermin::t_vermin sp;
|
|
|
|
Vermin::Read(i, sp);
|
2011-07-13 00:17:51 -06:00
|
|
|
|
2012-01-09 16:45:43 -07:00
|
|
|
if (sp.visible && sp.is_colony)
|
2011-07-13 00:17:51 -06:00
|
|
|
{
|
2012-01-09 16:45:43 -07:00
|
|
|
sp.visible = false;
|
2012-01-07 22:59:52 -07:00
|
|
|
Vermin::Write(i, sp);
|
2011-07-13 00:17:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert all colonies to honey bees.
|
2012-01-15 13:54:14 -07:00
|
|
|
void convertColonies(Materials *Materials)
|
2011-07-13 00:17:51 -06:00
|
|
|
{
|
|
|
|
int bee_idx = -1;
|
|
|
|
for (size_t i = 0; i < Materials->raceEx.size(); i++)
|
2012-01-21 17:31:15 -07:00
|
|
|
{
|
2011-07-21 14:37:02 -06:00
|
|
|
if (Materials->raceEx[i].id == "HONEY_BEE")
|
2011-07-13 00:17:51 -06:00
|
|
|
{
|
|
|
|
bee_idx = i;
|
|
|
|
break;
|
|
|
|
}
|
2012-01-21 17:31:15 -07:00
|
|
|
}
|
2011-07-13 00:17:51 -06:00
|
|
|
|
|
|
|
if (bee_idx == -1)
|
|
|
|
{
|
|
|
|
std::cerr << "Honey bees not present in game." << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-07 22:59:52 -07:00
|
|
|
uint32_t numSpawnPoints = Vermin::getNumVermin();
|
2011-07-13 00:17:51 -06:00
|
|
|
for (uint32_t i = 0; i < numSpawnPoints; i++)
|
|
|
|
{
|
2012-01-07 22:59:52 -07:00
|
|
|
Vermin::t_vermin sp;
|
|
|
|
Vermin::Read(i, sp);
|
2011-07-13 00:17:51 -06:00
|
|
|
|
2012-01-09 16:45:43 -07:00
|
|
|
if (sp.visible && sp.is_colony)
|
2011-07-13 00:17:51 -06:00
|
|
|
{
|
|
|
|
sp.race = bee_idx;
|
2012-01-07 22:59:52 -07:00
|
|
|
Vermin::Write(i, sp);
|
2011-07-13 00:17:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-15 13:54:14 -07:00
|
|
|
void showColonies(Core *c, Materials *Materials)
|
2011-07-13 00:17:51 -06:00
|
|
|
{
|
2012-01-07 22:59:52 -07:00
|
|
|
uint32_t numSpawnPoints = Vermin::getNumVermin();
|
2011-07-13 00:17:51 -06:00
|
|
|
int numColonies = 0;
|
|
|
|
for (uint32_t i = 0; i < numSpawnPoints; i++)
|
|
|
|
{
|
2012-01-07 22:59:52 -07:00
|
|
|
Vermin::t_vermin sp;
|
2011-07-13 00:17:51 -06:00
|
|
|
|
2012-01-07 22:59:52 -07:00
|
|
|
Vermin::Read(i, sp);
|
2011-07-13 00:17:51 -06:00
|
|
|
|
2012-01-09 16:45:43 -07:00
|
|
|
if (sp.visible && sp.is_colony)
|
2011-07-13 00:17:51 -06:00
|
|
|
{
|
|
|
|
numColonies++;
|
|
|
|
string race="(no race)";
|
2011-07-21 14:37:02 -06:00
|
|
|
if(sp.race != -1)
|
|
|
|
race = Materials->raceEx[sp.race].id;
|
2011-07-13 00:17:51 -06:00
|
|
|
|
2012-01-21 17:31:15 -07:00
|
|
|
c->con.print("Colony %u: %s at %d:%d:%d\n", i,
|
|
|
|
race.c_str(), sp.x, sp.y, sp.z);
|
2011-07-13 00:17:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numColonies == 0)
|
2011-07-13 18:36:39 -06:00
|
|
|
c->con << "No colonies present." << std::endl;
|
2011-07-13 00:17:51 -06:00
|
|
|
}
|