STUFF!
parent
5d54bfca96
commit
b09ff94b24
@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
rst2html README.rst > Readme.html
|
||||
rst2html COMPILE.rst > Compile.html
|
||||
rst2html DEVEL.rst > Devel.html
|
||||
|
@ -0,0 +1,84 @@
|
||||
// foo
|
||||
// vi:expandtab:sw=4
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
using namespace std;
|
||||
#include <dfhack/Core.h>
|
||||
#include <dfhack/Console.h>
|
||||
#include <dfhack/Export.h>
|
||||
#include <dfhack/PluginManager.h>
|
||||
#include <dfhack/VersionInfo.h>
|
||||
#include <dfhack/modules/Creatures.h>
|
||||
using namespace DFHack;
|
||||
|
||||
// dfhack interface
|
||||
DFhackCExport const char * plugin_name ( void )
|
||||
{
|
||||
return "fastdwarf";
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_shutdown ( Core * c )
|
||||
{
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
static int enable_fastdwarf;
|
||||
|
||||
// remove that if struct df_creature is updated
|
||||
#define job_counter unk_540
|
||||
|
||||
DFhackCExport command_result plugin_onupdate ( Core * c )
|
||||
{
|
||||
if (!enable_fastdwarf)
|
||||
return CR_OK;
|
||||
|
||||
static vector <df_creature*> *v;
|
||||
df_creature *cre;
|
||||
|
||||
if (!v) {
|
||||
OffsetGroup *ogc = c->vinfo->getGroup("Creatures");
|
||||
v = (vector<df_creature*>*)ogc->getAddress("vector");
|
||||
}
|
||||
|
||||
//c->Suspend(); // will deadlock in onupdate
|
||||
for (unsigned i=0 ; i<v->size() ; ++i) {
|
||||
cre = v->at(i);
|
||||
if (cre->race == 241 && cre->job_counter > 0)
|
||||
cre->job_counter = 0;
|
||||
// could also patch the cre->current_job->counter
|
||||
}
|
||||
//c->Resume();
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
static command_result fastdwarf (Core * c, vector <string> & parameters)
|
||||
{
|
||||
if (parameters.size() == 1 && (parameters[0] == "0" || parameters[0] == "1")) {
|
||||
if (parameters[0] == "0")
|
||||
enable_fastdwarf = 0;
|
||||
else
|
||||
enable_fastdwarf = 1;
|
||||
c->con.print("fastdwarf %sactivated.\n", (enable_fastdwarf ? "" : "de"));
|
||||
} else {
|
||||
c->con.print("Activate fastdwarf with 'fastdwarf 1', deactivate with 'fastdwarf 0'.\nCurrent state: %d.\n", enable_fastdwarf);
|
||||
}
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
||||
{
|
||||
commands.clear();
|
||||
|
||||
commands.push_back(PluginCommand("fastdwarf",
|
||||
"enable/disable fastdwarf (parameter=0/1)",
|
||||
fastdwarf));
|
||||
|
||||
return CR_OK;
|
||||
}
|
@ -0,0 +1,191 @@
|
||||
// Designate all matching plants for gathering/cutting
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <dfhack/Core.h>
|
||||
#include <dfhack/Console.h>
|
||||
#include <dfhack/Export.h>
|
||||
#include <dfhack/PluginManager.h>
|
||||
#include <dfhack/modules/Maps.h>
|
||||
#include <dfhack/modules/Materials.h>
|
||||
#include <dfhack/modules/Vegetation.h>
|
||||
#include <dfhack/TileTypes.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace DFHack;
|
||||
|
||||
DFhackCExport command_result df_getplants (Core * c, vector <string> & parameters);
|
||||
|
||||
DFhackCExport const char * plugin_name ( void )
|
||||
{
|
||||
return "getplants";
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_init ( Core * c, vector <PluginCommand> &commands)
|
||||
{
|
||||
commands.clear();
|
||||
commands.push_back(PluginCommand("getplants", "Cut down all of the specified trees or gather all of the specified shrubs", df_getplants));
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_shutdown ( Core * c )
|
||||
{
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
DFhackCExport command_result df_getplants (Core * c, vector <string> & parameters)
|
||||
{
|
||||
uint32_t x_max,y_max,z_max;
|
||||
designations40d designations;
|
||||
tiletypes40d tiles;
|
||||
t_blockflags blockflags;
|
||||
string plantMatStr = "";
|
||||
set<int> plantIDs;
|
||||
set<string> plantNames;
|
||||
bool deselect = false, exclude = false, treesonly = false, shrubsonly = false;
|
||||
|
||||
bool dirty = false;
|
||||
int count = 0;
|
||||
for (size_t i = 0; i < parameters.size(); i++)
|
||||
{
|
||||
if(parameters[i] == "help" || parameters[i] == "?")
|
||||
{
|
||||
c->con.print("Specify the types of trees to cut down and/or shrubs to gather by their plant names, separated by spaces.\n"
|
||||
"Options:\n"
|
||||
"\t-t - Select trees only (exclude shrubs)\n"
|
||||
"\t-s - Select shrubs only (exclude trees)\n"
|
||||
"\t-c - Clear designations instead of setting them\n"
|
||||
"\t-x - Apply selected action to all plants except those specified\n"
|
||||
"Specifying both -t and -s will have no effect.\n"
|
||||
"If no plant IDs are specified, all valid plant IDs will be listed.\n"
|
||||
);
|
||||
return CR_OK;
|
||||
}
|
||||
else if(parameters[i] == "-t")
|
||||
treesonly = true;
|
||||
else if(parameters[i] == "-s")
|
||||
shrubsonly = true;
|
||||
else if(parameters[i] == "-c")
|
||||
deselect = true;
|
||||
else if(parameters[i] == "-x")
|
||||
exclude = true;
|
||||
else plantNames.insert(parameters[i]);
|
||||
}
|
||||
c->Suspend();
|
||||
|
||||
Materials *mats = c->getMaterials();
|
||||
mats->ReadOrganicMaterials();
|
||||
for (vector<t_matgloss>::const_iterator it = mats->organic.begin(); it != mats->organic.end(); it++)
|
||||
{
|
||||
if (plantNames.find((*it).id) != plantNames.end())
|
||||
{
|
||||
plantNames.erase((*it).id);
|
||||
plantIDs.insert(it - mats->organic.begin());
|
||||
}
|
||||
}
|
||||
if (plantNames.size() > 0)
|
||||
{
|
||||
c->con.printerr("Invalid plant ID(s):");
|
||||
for (set<string>::const_iterator it = plantNames.begin(); it != plantNames.end(); it++)
|
||||
c->con.printerr(" %s", (*it).c_str());
|
||||
c->Resume();
|
||||
return CR_FAILURE;
|
||||
}
|
||||
|
||||
if (plantIDs.size() == 0)
|
||||
{
|
||||
c->con.print("Valid plant IDs:\n");
|
||||
for (vector<t_matgloss>::const_iterator it = mats->organic.begin(); it != mats->organic.end(); it++)
|
||||
c->con.print("* %s\n", (*it).id.c_str());
|
||||
c->Resume();
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
Maps *maps = c->getMaps();
|
||||
|
||||
// init the map
|
||||
if (!maps->Start())
|
||||
{
|
||||
c->con.printerr("Can't init map.\n");
|
||||
c->Resume();
|
||||
return CR_FAILURE;
|
||||
}
|
||||
|
||||
maps->getSize(x_max,y_max,z_max);
|
||||
// walk the map
|
||||
for (uint32_t x = 0; x < x_max; x++)
|
||||
{
|
||||
for (uint32_t y = 0; y < y_max; y++)
|
||||
{
|
||||
for (uint32_t z = 0; z < z_max; z++)
|
||||
{
|
||||
if (maps->getBlock(x,y,z))
|
||||
{
|
||||
dirty = false;
|
||||
maps->ReadDesignations(x,y,z, &designations);
|
||||
maps->ReadTileTypes(x,y,z, &tiles);
|
||||
maps->ReadBlockFlags(x,y,z, blockflags);
|
||||
|
||||
vector<df_plant *> *plants;
|
||||
if (maps->ReadVegetation(x, y, z, plants))
|
||||
{
|
||||
for (vector<df_plant *>::const_iterator it = plants->begin(); it != plants->end(); it++)
|
||||
{
|
||||
const df_plant &plant = *(*it);
|
||||
uint32_t tx = plant.x % 16;
|
||||
uint32_t ty = plant.y % 16;
|
||||
if (plantIDs.find(plant.material) != plantIDs.end())
|
||||
{
|
||||
if (exclude)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!exclude)
|
||||
continue;
|
||||
}
|
||||
|
||||
TileShape shape = tileShape(tiles[tx][ty]);
|
||||
if (plant.is_shrub && (treesonly || shape != SHRUB_OK))
|
||||
continue;
|
||||
if (!plant.is_shrub && (shrubsonly || (shape != TREE_OK && shape != TREE_DEAD)))
|
||||
continue;
|
||||
if (designations[tx][ty].bits.hidden)
|
||||
continue;
|
||||
if (deselect && designations[tx][ty].bits.dig != designation_no)
|
||||
{
|
||||
designations[tx][ty].bits.dig = designation_no;
|
||||
dirty = true;
|
||||
++count;
|
||||
}
|
||||
if (!deselect && designations[tx][ty].bits.dig != designation_default)
|
||||
{
|
||||
designations[tx][ty].bits.dig = designation_default;
|
||||
dirty = true;
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
// If anything was changed, write it all.
|
||||
if (dirty)
|
||||
{
|
||||
blockflags.bits.designated = 1;
|
||||
maps->WriteDesignations(x,y,z, &designations);
|
||||
maps->WriteBlockFlags(x,y,z, blockflags);
|
||||
dirty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
c->Resume();
|
||||
if (count)
|
||||
c->con.print("Updated %d plant designations.\n", count);
|
||||
return CR_OK;
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
PROJECT (skeleton)
|
||||
# A list of source files
|
||||
SET(PROJECT_SRCS
|
||||
skeleton.cpp
|
||||
)
|
||||
# A list of headers
|
||||
SET(PROJECT_HDRS
|
||||
skeleton.h
|
||||
)
|
||||
SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE)
|
||||
|
||||
# mash them together (headers are marked as headers and nothing will try to compile them)
|
||||
LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS})
|
||||
|
||||
# option to use a thread for no particular reason
|
||||
OPTION(SKELETON_THREAD "Use threads in the skeleton plugin." ON)
|
||||
#linux
|
||||
IF(UNIX)
|
||||
add_definitions(-DLINUX_BUILD)
|
||||
SET(PROJECT_LIBS
|
||||
# add any extra linux libs here
|
||||
${PROJECT_LIBS}
|
||||
)
|
||||
# windows
|
||||
ELSE(UNIX)
|
||||
SET(PROJECT_LIBS
|
||||
# add any extra linux libs here
|
||||
${PROJECT_LIBS}
|
||||
$(NOINHERIT)
|
||||
)
|
||||
ENDIF(UNIX)
|
||||
# this makes sure all the stuff is put in proper places and linked to dfhack
|
||||
DFHACK_PLUGIN(skeleton ${PROJECT_SRCS} LINK_LIBRARIES ${PROJECT_LIBS})
|
@ -0,0 +1,78 @@
|
||||
// This is a generic plugin that does nothing useful apart from acting as an example... of a plugin that does nothing :D
|
||||
|
||||
// some headers required for a plugin. Nothing special, just the basics.
|
||||
#include <dfhack/Core.h>
|
||||
#include <dfhack/Console.h>
|
||||
#include <dfhack/Export.h>
|
||||
#include <dfhack/PluginManager.h>
|
||||
using namespace DFHack;
|
||||
|
||||
// our own, empty header.
|
||||
#include "skeleton.h"
|
||||
|
||||
|
||||
// Here go all the command declarations...
|
||||
// mostly to allow having the mandatory stuff on top of the file and commands on the bottom
|
||||
DFhackCExport command_result skeleton (Core * c, std::vector <std::string> & parameters);
|
||||
|
||||
// A plugins must be able to return its name. This must correspond to the filename - skeleton.plug.so or skeleton.plug.dll
|
||||
DFhackCExport const char * plugin_name ( void )
|
||||
{
|
||||
return "skeleton";
|
||||
}
|
||||
|
||||
// Mandatory init function. If you have some global state, create it here.
|
||||
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
||||
{
|
||||
// Fill the command list with your commands.
|
||||
commands.clear();
|
||||
commands.push_back(PluginCommand("skeleton",
|
||||
"Do nothing, look pretty.",
|
||||
skeleton /*,
|
||||
true or false - true means that the command can't be used from non-interactive user interface'*/));
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
// This is called right before the plugin library is removed from memory.
|
||||
DFhackCExport command_result plugin_shutdown ( Core * c )
|
||||
{
|
||||
// You *MUST* kill all threads you created before this returns.
|
||||
// If everythin fails, just return CR_FAILURE. Your plugin will be
|
||||
// in a zombie state, but things won't crash.
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
// Whatever you put here will be done in each game step. Don't abuse it.
|
||||
// It's optional, so you can just comment it out like this if you don't need it.
|
||||
/*
|
||||
DFhackCExport command_result plugin_onupdate ( Core * c )
|
||||
{
|
||||
// whetever. You don't need to suspend DF execution here.
|
||||
return CR_OK;
|
||||
}
|
||||
*/
|
||||
|
||||
// A command! It sits around and looks pretty. And it's nice and friendly.
|
||||
DFhackCExport command_result skeleton (Core * c, std::vector <std::string> & parameters)
|
||||
{
|
||||
// It's nice to provide a 'help' option for your command.
|
||||
// It's also nice to print the same help if you get invalid options from the user instead of just acting strange
|
||||
for(int i = 0; i < parameters.size();i++)
|
||||
{
|
||||
if(parameters[i] == "help" || parameters[i] == "?")
|
||||
{
|
||||
// Core has a handle to the console. The console is thread-safe.
|
||||
// Only one thing can read from it at a time though...
|
||||
c->con.print("This command does nothing!\n");
|
||||
return CR_OK;
|
||||
}
|
||||
}
|
||||
// Commands are called from threads other than the DF one.
|
||||
// Suspend this thread until DF has time for us.
|
||||
c->Suspend();
|
||||
// Actually do something here. Yay.
|
||||
c->con.print("Hello! I do nothing, remember?\n");
|
||||
// Give control back to DF.
|
||||
c->Resume();
|
||||
return CR_OK;
|
||||
}
|
@ -0,0 +1 @@
|
||||
#pragma once
|
Loading…
Reference in New Issue