2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
|
|
|
#include <Console.h>
|
|
|
|
#include <Export.h>
|
|
|
|
#include <PluginManager.h>
|
2011-07-13 00:17:51 -06:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2011-12-31 04:48:42 -07:00
|
|
|
#include <modules/Vermin.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
|
|
|
#include <DFHack.h>
|
|
|
|
|
|
|
|
DFhackCExport command_result colonies (Core * c, vector <string> & parameters);
|
|
|
|
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
{
|
|
|
|
return "colonies";
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
commands.clear();
|
|
|
|
commands.push_back(PluginCommand("colonies",
|
2011-08-08 17:50:22 -06:00
|
|
|
"List or change wild colonies (ants hills and such)",
|
2011-07-13 00:17:51 -06:00
|
|
|
colonies));
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-07 22:59:52 -07:00
|
|
|
void destroyColonies();
|
|
|
|
void convertColonies(DFHack::Materials *Materials);
|
|
|
|
void showColonies(Core *c, DFHack::Materials *Materials);
|
2011-07-13 00:17:51 -06:00
|
|
|
|
|
|
|
DFhackCExport command_result colonies (Core * c, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
bool destroy = false;
|
|
|
|
bool convert = false;
|
2011-08-08 17:50:22 -06:00
|
|
|
bool help = false;
|
2011-07-13 00:17:51 -06:00
|
|
|
|
|
|
|
for(int i = 0; i < parameters.size();i++)
|
|
|
|
{
|
|
|
|
if(parameters[i] == "kill")
|
|
|
|
destroy = true;
|
|
|
|
else if(parameters[i] == "bees")
|
|
|
|
convert = true;
|
2011-08-08 17:50:22 -06:00
|
|
|
else if(parameters[i] == "help" || parameters[i] == "?")
|
|
|
|
{
|
|
|
|
help = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(help)
|
|
|
|
{
|
|
|
|
c->con.print("Without any options, this command lists all the vermin colonies present.\n"
|
|
|
|
"Options:\n"
|
|
|
|
"kill - destroy colonies\n"
|
|
|
|
"bees - turn colonies into honey bees\n"
|
|
|
|
);
|
|
|
|
return CR_OK;
|
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");
|
|
|
|
c->Resume();
|
2011-07-13 00:17:51 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
c->Suspend();
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
c->Resume();
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
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-07 22:59:52 -07:00
|
|
|
if (sp.in_use && Vermin::isWildColony(sp))
|
2011-07-13 00:17:51 -06:00
|
|
|
{
|
|
|
|
sp.in_use = 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-07 22:59:52 -07:00
|
|
|
void convertColonies(DFHack::Materials *Materials)
|
2011-07-13 00:17:51 -06:00
|
|
|
{
|
|
|
|
int bee_idx = -1;
|
|
|
|
for (size_t i = 0; i < Materials->raceEx.size(); i++)
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07 22:59:52 -07:00
|
|
|
if (sp.in_use && Vermin::isWildColony(sp))
|
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-07 22:59:52 -07:00
|
|
|
void showColonies(Core *c, DFHack::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-07 22:59:52 -07:00
|
|
|
if (sp.in_use && Vermin::isWildColony(sp))
|
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
|
|
|
|
2011-07-13 18:36:39 -06:00
|
|
|
c->con.print("Spawn point %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
|
|
|
}
|