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-12-24 03:51:58 -07:00
|
|
|
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "df/world.h"
|
|
|
|
#include "df/ui.h"
|
|
|
|
#include "df/building_stockpilest.h"
|
2012-02-20 03:42:40 -07:00
|
|
|
#include "df/global_objects.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "df/viewscreen_dwarfmodest.h"
|
2011-12-24 03:51:58 -07:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using std::endl;
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
|
|
|
|
|
|
|
using df::global::world;
|
|
|
|
using df::global::ui;
|
2011-12-29 05:40:26 -07:00
|
|
|
using df::global::selection_rect;
|
2011-12-24 03:51:58 -07:00
|
|
|
|
|
|
|
using df::building_stockpilest;
|
|
|
|
|
2011-12-30 12:25:50 -07:00
|
|
|
static command_result copystock(Core *c, vector <string> & parameters);
|
|
|
|
static bool copystock_guard(Core *c, df::viewscreen *top);
|
2011-12-24 03:51:58 -07:00
|
|
|
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
{
|
|
|
|
return "stockpiles";
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init (Core *c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
commands.clear();
|
|
|
|
if (world && ui) {
|
2011-12-30 12:25:50 -07:00
|
|
|
commands.push_back(
|
|
|
|
PluginCommand(
|
2011-12-31 02:25:46 -07:00
|
|
|
"copystock", "Copy stockpile under cursor.",
|
|
|
|
copystock, copystock_guard,
|
|
|
|
" - In 'q' or 't' mode: select a stockpile and invoke in order\n"
|
|
|
|
" to switch to the 'p' stockpile creation mode, and initialize\n"
|
|
|
|
" the custom settings from the selected stockpile.\n"
|
|
|
|
" - In 'p': invoke in order to switch back to 'q'.\n"
|
2011-12-30 12:25:50 -07:00
|
|
|
)
|
|
|
|
);
|
2011-12-24 03:51:58 -07:00
|
|
|
}
|
|
|
|
std::cerr << "world: " << sizeof(df::world) << " ui: " << sizeof(df::ui)
|
|
|
|
<< " b_stock: " << sizeof(building_stockpilest) << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-31 02:25:46 -07:00
|
|
|
static bool copystock_guard(Core *c, df::viewscreen *top)
|
2011-12-30 12:25:50 -07:00
|
|
|
{
|
2011-12-24 03:51:58 -07:00
|
|
|
using namespace ui_sidebar_mode;
|
|
|
|
|
2011-12-31 02:25:46 -07:00
|
|
|
if (!dwarfmode_hotkey(c,top))
|
|
|
|
return false;
|
|
|
|
|
2011-12-24 03:51:58 -07:00
|
|
|
switch (ui->main.mode) {
|
2011-12-30 12:25:50 -07:00
|
|
|
case Stockpiles:
|
|
|
|
return true;
|
2011-12-24 03:51:58 -07:00
|
|
|
case BuildingItems:
|
|
|
|
case QueryBuilding:
|
2011-12-30 12:25:50 -07:00
|
|
|
return !!virtual_cast<building_stockpilest>(world->selected_building);
|
2011-12-24 03:51:58 -07:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-30 12:25:50 -07:00
|
|
|
static command_result copystock(Core * c, vector <string> & parameters)
|
2011-12-24 03:51:58 -07:00
|
|
|
{
|
2011-12-31 02:25:46 -07:00
|
|
|
// HOTKEY COMMAND: CORE ALREADY SUSPENDED
|
2011-12-24 03:51:58 -07:00
|
|
|
|
|
|
|
// For convenience: when used in the stockpiles mode, switch to 'q'
|
|
|
|
if (ui->main.mode == ui_sidebar_mode::Stockpiles) {
|
|
|
|
world->selected_building = NULL; // just in case it contains some kind of garbage
|
|
|
|
ui->main.mode = ui_sidebar_mode::QueryBuilding;
|
2011-12-29 05:40:26 -07:00
|
|
|
selection_rect->start_x = -30000;
|
2011-12-24 03:51:58 -07:00
|
|
|
|
|
|
|
c->con << "Switched back to query building." << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
building_stockpilest *sp = virtual_cast<building_stockpilest>(world->selected_building);
|
2011-12-31 05:09:12 -07:00
|
|
|
if (!sp)
|
|
|
|
{
|
2011-12-30 12:25:50 -07:00
|
|
|
c->con.printerr("Selected building isn't a stockpile.\n");
|
2011-12-31 02:25:46 -07:00
|
|
|
return CR_WRONG_USAGE;
|
2011-12-24 03:51:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ui->stockpile.custom_settings = sp->settings;
|
|
|
|
ui->main.mode = ui_sidebar_mode::Stockpiles;
|
|
|
|
world->selected_stockpile_type = stockpile_category::Custom;
|
|
|
|
|
|
|
|
c->con << "Stockpile options copied." << endl;
|
|
|
|
return CR_OK;
|
|
|
|
}
|