Merge branch 'remote_control' of https://github.com/JapaMala/dfhack into remote_control

develop
Japa 2018-01-24 10:24:23 +05:30
commit 42bbe124b7
8 changed files with 162 additions and 37 deletions

@ -55,6 +55,9 @@ keybinding add Alt-S@dwarfmode/Default gui/settings-manager
# change quantity of manager orders # change quantity of manager orders
keybinding add Alt-Q@jobmanagement/Main gui/manager-quantity keybinding add Alt-Q@jobmanagement/Main gui/manager-quantity
# view combat reports for the selected unit/corpse/spatter
keybinding add Ctrl-Shift-R view-unit-reports
############################## ##############################
# Generic adv mode bindings # # Generic adv mode bindings #
############################## ##############################

@ -28,6 +28,7 @@ Carter Bray Qartar
Chris Dombroski cdombroski Chris Dombroski cdombroski
Clayton Hughes Clayton Hughes
Clément Vuchener cvuchener Clément Vuchener cvuchener
Dan Amlund danamlund
David Corbett dscorbett David Corbett dscorbett
David Seguin dseguin David Seguin dseguin
Deon Deon

@ -276,6 +276,9 @@ public:
return true; return true;
} }
int32_t priorityAt(df::coord2d p);
bool setPriorityAt(df::coord2d p, int32_t priority);
df::tile_occupancy OccupancyAt(df::coord2d p) df::tile_occupancy OccupancyAt(df::coord2d p)
{ {
return index_tile<df::tile_occupancy>(occupancy,p); return index_tile<df::tile_occupancy>(occupancy,p);
@ -544,11 +547,29 @@ class DFHACK_EXPORT MapCache
Block * b= BlockAtTile(tilecoord); Block * b= BlockAtTile(tilecoord);
return b ? b->DesignationAt(tilecoord) : df::tile_designation(); return b ? b->DesignationAt(tilecoord) : df::tile_designation();
} }
bool setDesignationAt (DFCoord tilecoord, df::tile_designation des) // priority is optional, only set if >= 0
bool setDesignationAt (DFCoord tilecoord, df::tile_designation des, int32_t priority = -1)
{
if (Block *b = BlockAtTile(tilecoord))
{ {
if(Block * b= BlockAtTile(tilecoord)) if (!b->setDesignationAt(tilecoord, des))
return b->setDesignationAt(tilecoord, des);
return false; return false;
if (priority >= 0 && b->setPriorityAt(tilecoord, priority))
return false;
return true;
}
return false;
}
int32_t priorityAt (DFCoord tilecoord)
{
Block *b = BlockAtTile(tilecoord);
return b ? b->priorityAt(tilecoord) : -1;
}
bool setPriorityAt (DFCoord tilecoord, int32_t priority)
{
Block *b = BlockAtTile(tilecoord);
return b ? b->setPriorityAt(tilecoord, priority) : false;
} }
df::tile_occupancy occupancyAt (DFCoord tilecoord) df::tile_occupancy occupancyAt (DFCoord tilecoord)

@ -46,6 +46,7 @@ distribution.
namespace df { namespace df {
struct block_square_event; struct block_square_event;
struct block_square_event_designation_priorityst;
struct block_square_event_frozen_liquidst; struct block_square_event_frozen_liquidst;
struct block_square_event_grassst; struct block_square_event_grassst;
struct block_square_event_item_spatterst; struct block_square_event_item_spatterst;
@ -321,7 +322,8 @@ extern DFHACK_EXPORT bool SortBlockEvents(df::map_block *block,
std::vector<df::block_square_event_grassst *>* grass = 0, std::vector<df::block_square_event_grassst *>* grass = 0,
std::vector<df::block_square_event_world_constructionst *>* constructions = 0, std::vector<df::block_square_event_world_constructionst *>* constructions = 0,
std::vector<df::block_square_event_spoorst *>* spoors = 0, std::vector<df::block_square_event_spoorst *>* spoors = 0,
std::vector<df::block_square_event_item_spatterst *>* items = 0 std::vector<df::block_square_event_item_spatterst *>* items = 0,
std::vector<df::block_square_event_designation_priorityst *>* priorities = 0
); );
/// remove a block event from the block by address /// remove a block event from the block by address

@ -49,8 +49,9 @@ using namespace std;
#include "df/block_burrow.h" #include "df/block_burrow.h"
#include "df/block_burrow_link.h" #include "df/block_burrow_link.h"
#include "df/block_square_event_grassst.h" #include "df/block_square_event_designation_priorityst.h"
#include "df/block_square_event_frozen_liquidst.h" #include "df/block_square_event_frozen_liquidst.h"
#include "df/block_square_event_grassst.h"
#include "df/building_type.h" #include "df/building_type.h"
#include "df/builtin_mats.h" #include "df/builtin_mats.h"
#include "df/burrow.h" #include "df/burrow.h"
@ -271,6 +272,43 @@ bool MapExtras::Block::setTiletypeAt(df::coord2d pos, df::tiletype tt, bool forc
return true; return true;
} }
static df::block_square_event_designation_priorityst *getPriorityEvent(df::map_block *block, bool write)
{
vector<df::block_square_event_designation_priorityst*> events;
Maps::SortBlockEvents(block, 0, 0, 0, 0, 0, 0, 0, &events);
if (events.empty())
{
if (!write)
return NULL;
auto event = df::allocate<df::block_square_event_designation_priorityst>();
block->block_events.push_back((df::block_square_event*)event);
return event;
}
return events[0];
}
int32_t MapExtras::Block::priorityAt(df::coord2d pos)
{
if (!block)
return false;
if (auto event = getPriorityEvent(block, false))
return event->priority[pos.x % 16][pos.y % 16];
return 0;
}
bool MapExtras::Block::setPriorityAt(df::coord2d pos, int32_t priority)
{
if (!block || priority < 0)
return false;
auto event = getPriorityEvent(block, true);
event->priority[pos.x % 16][pos.y % 16] = priority;
return true;
}
bool MapExtras::Block::setVeinMaterialAt(df::coord2d pos, int16_t mat, df::inclusion_type type) bool MapExtras::Block::setVeinMaterialAt(df::coord2d pos, int16_t mat, df::inclusion_type type)
{ {
using namespace df::enums::tiletype_material; using namespace df::enums::tiletype_material;

@ -402,7 +402,8 @@ bool Maps::SortBlockEvents(df::map_block *block,
vector <df::block_square_event_grassst *> *grasses, vector <df::block_square_event_grassst *> *grasses,
vector <df::block_square_event_world_constructionst *> *constructions, vector <df::block_square_event_world_constructionst *> *constructions,
vector <df::block_square_event_spoorst *> *spoors, vector <df::block_square_event_spoorst *> *spoors,
vector <df::block_square_event_item_spatterst *> *items) vector <df::block_square_event_item_spatterst *> *items,
vector <df::block_square_event_designation_priorityst *> *priorities)
{ {
if (veins) if (veins)
veins->clear(); veins->clear();
@ -456,6 +457,10 @@ bool Maps::SortBlockEvents(df::map_block *block,
if (items) if (items)
items->push_back((df::block_square_event_item_spatterst *)evt); items->push_back((df::block_square_event_item_spatterst *)evt);
break; break;
case block_square_event_type::designation_priority:
if (priorities)
priorities->push_back((df::block_square_event_designation_priorityst *)evt);
break;
} }
} }
return true; return true;

@ -1 +1 @@
Subproject commit 6b6dda838fc1b9c4e1c47fbdfbf19838749bad14 Subproject commit f0c609211fbfd354b576cae75e9e64f8c6c80b06

@ -1,16 +1,23 @@
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <string>
#include <cmath>
#include "Core.h" #include "Core.h"
#include "Console.h" #include "Console.h"
#include "Export.h" #include "Export.h"
#include "PluginManager.h" #include "PluginManager.h"
#include "modules/Maps.h" #include "uicommon.h"
#include "modules/Gui.h" #include "modules/Gui.h"
#include "modules/MapCache.h" #include "modules/MapCache.h"
#include "modules/Maps.h"
#include "modules/Materials.h" #include "modules/Materials.h"
#include <vector>
#include <cstdio> #include "df/ui_sidebar_menus.h"
#include <stack>
#include <string>
#include <cmath>
using std::vector; using std::vector;
using std::string; using std::string;
using std::stack; using std::stack;
@ -27,6 +34,7 @@ command_result digcircle (color_ostream &out, vector <string> & parameters);
command_result digtype (color_ostream &out, vector <string> & parameters); command_result digtype (color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("dig"); DFHACK_PLUGIN("dig");
REQUIRE_GLOBAL(ui_sidebar_menus);
REQUIRE_GLOBAL(world); REQUIRE_GLOBAL(world);
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
@ -97,6 +105,7 @@ enum circle_what
bool dig (MapExtras::MapCache & MCache, bool dig (MapExtras::MapCache & MCache,
circle_what what, circle_what what,
df::tile_dig_designation type, df::tile_dig_designation type,
int32_t priority,
int32_t x, int32_t y, int32_t z, int32_t x, int32_t y, int32_t z,
int x_max, int y_max int x_max, int y_max
) )
@ -175,20 +184,21 @@ bool dig (MapExtras::MapCache & MCache,
break; break;
} }
std::cerr << "allowing tt" << (int)tt << "\n"; std::cerr << "allowing tt" << (int)tt << "\n";
MCache.setDesignationAt(at,des); MCache.setDesignationAt(at,des,priority);
return true; return true;
}; };
bool lineX (MapExtras::MapCache & MCache, bool lineX (MapExtras::MapCache & MCache,
circle_what what, circle_what what,
df::tile_dig_designation type, df::tile_dig_designation type,
int32_t priority,
int32_t y1, int32_t y2, int32_t x, int32_t z, int32_t y1, int32_t y2, int32_t x, int32_t z,
int x_max, int y_max int x_max, int y_max
) )
{ {
for(int32_t y = y1; y <= y2; y++) for(int32_t y = y1; y <= y2; y++)
{ {
dig(MCache, what, type,x,y,z, x_max, y_max); dig(MCache, what, type, priority, x,y,z, x_max, y_max);
} }
return true; return true;
}; };
@ -196,17 +206,51 @@ bool lineX (MapExtras::MapCache & MCache,
bool lineY (MapExtras::MapCache & MCache, bool lineY (MapExtras::MapCache & MCache,
circle_what what, circle_what what,
df::tile_dig_designation type, df::tile_dig_designation type,
int32_t priority,
int32_t x1, int32_t x2, int32_t y, int32_t z, int32_t x1, int32_t x2, int32_t y, int32_t z,
int x_max, int y_max int x_max, int y_max
) )
{ {
for(int32_t x = x1; x <= x2; x++) for(int32_t x = x1; x <= x2; x++)
{ {
dig(MCache, what, type,x,y,z, x_max, y_max); dig(MCache, what, type, priority, x,y,z, x_max, y_max);
} }
return true; return true;
}; };
int32_t parse_priority(color_ostream &out, vector<string> &parameters)
{
int32_t default_priority = ui_sidebar_menus->designation.priority;
for (auto it = parameters.begin(); it != parameters.end(); ++it)
{
const string &s = *it;
if (s.substr(0, 2) == "p=" || s.substr(0, 2) == "-p")
{
if (s.size() >= 3)
{
auto priority = int32_t(1000 * atof(s.c_str() + 2));
parameters.erase(it);
return priority;
}
else if (it + 1 != parameters.end())
{
auto priority = int32_t(1000 * atof((*(it + 1)).c_str()));
parameters.erase(it);
parameters.erase(it + 1);
return priority;
}
else
{
out.printerr("invalid priority specified; reverting to %i\n", default_priority);
break;
}
}
}
return default_priority;
}
command_result digcircle (color_ostream &out, vector <string> & parameters) command_result digcircle (color_ostream &out, vector <string> & parameters)
{ {
static bool filled = false; static bool filled = false;
@ -215,6 +259,8 @@ command_result digcircle (color_ostream &out, vector <string> & parameters)
static int diameter = 0; static int diameter = 0;
auto saved_d = diameter; auto saved_d = diameter;
bool force_help = false; bool force_help = false;
int32_t priority = parse_priority(out, parameters);
for(size_t i = 0; i < parameters.size();i++) for(size_t i = 0; i < parameters.size();i++)
{ {
if(parameters[i] == "help" || parameters[i] == "?") if(parameters[i] == "help" || parameters[i] == "?")
@ -326,12 +372,12 @@ command_result digcircle (color_ostream &out, vector <string> & parameters)
// paint center // paint center
if(filled) if(filled)
{ {
lineY(MCache,what,type, cx - r, cx + r, cy, cz,x_max,y_max); lineY(MCache, what, type, priority, cx - r, cx + r, cy, cz, x_max, y_max);
} }
else else
{ {
dig(MCache, what, type,cx - r, cy, cz,x_max,y_max); dig(MCache, what, type, priority, cx - r, cy, cz, x_max, y_max);
dig(MCache, what, type,cx + r, cy, cz,x_max,y_max); dig(MCache, what, type, priority, cx + r, cy, cz, x_max, y_max);
} }
adjust = false; adjust = false;
iter = 2; iter = 2;
@ -363,24 +409,24 @@ command_result digcircle (color_ostream &out, vector <string> & parameters)
// paint // paint
if(filled || iter == diameter - 1) if(filled || iter == diameter - 1)
{ {
lineY(MCache,what,type, left, right, top , cz,x_max,y_max); lineY(MCache, what, type, priority, left, right, top, cz, x_max, y_max);
lineY(MCache,what,type, left, right, bottom , cz,x_max,y_max); lineY(MCache, what, type, priority, left, right, bottom, cz, x_max, y_max);
} }
else else
{ {
dig(MCache, what, type,left, top, cz,x_max,y_max); dig(MCache, what, type, priority, left, top, cz, x_max, y_max);
dig(MCache, what, type,left, bottom, cz,x_max,y_max); dig(MCache, what, type, priority, left, bottom, cz, x_max, y_max);
dig(MCache, what, type,right, top, cz,x_max,y_max); dig(MCache, what, type, priority, right, top, cz, x_max, y_max);
dig(MCache, what, type,right, bottom, cz,x_max,y_max); dig(MCache, what, type, priority, right, bottom, cz, x_max, y_max);
} }
if(!filled && diff > 1) if(!filled && diff > 1)
{ {
int lright = cx + lastwhole; int lright = cx + lastwhole;
int lleft = cx - lastwhole + adjust; int lleft = cx - lastwhole + adjust;
lineY(MCache,what,type, lleft + 1, left - 1, top + 1 , cz,x_max,y_max); lineY(MCache, what, type, priority, lleft + 1, left - 1, top + 1 , cz, x_max, y_max);
lineY(MCache,what,type, right + 1, lright - 1, top + 1 , cz,x_max,y_max); lineY(MCache, what, type, priority, right + 1, lright - 1, top + 1 , cz, x_max, y_max);
lineY(MCache,what,type, lleft + 1, left - 1, bottom - 1 , cz,x_max,y_max); lineY(MCache, what, type, priority, lleft + 1, left - 1, bottom - 1 , cz, x_max, y_max);
lineY(MCache,what,type, right + 1, lright - 1, bottom - 1 , cz,x_max,y_max); lineY(MCache, what, type, priority, right + 1, lright - 1, bottom - 1 , cz, x_max, y_max);
} }
lastwhole = whole; lastwhole = whole;
} }
@ -808,6 +854,8 @@ command_result digexp (color_ostream &out, vector <string> & parameters)
bool force_help = false; bool force_help = false;
static explo_how how = EXPLO_NOTHING; static explo_how how = EXPLO_NOTHING;
static explo_what what = EXPLO_HIDDEN; static explo_what what = EXPLO_HIDDEN;
int32_t priority = parse_priority(out, parameters);
for(size_t i = 0; i < parameters.size();i++) for(size_t i = 0; i < parameters.size();i++)
{ {
if(parameters[i] == "help" || parameters[i] == "?") if(parameters[i] == "help" || parameters[i] == "?")
@ -963,7 +1011,7 @@ command_result digexp (color_ostream &out, vector <string> & parameters)
if(cross[y][x]) if(cross[y][x])
{ {
des.bits.dig = tile_dig_designation::Default; des.bits.dig = tile_dig_designation::Default;
mx.setDesignationAt(pos,des); mx.setDesignationAt(pos,des,priority);
} }
} }
mx.WriteAll(); mx.WriteAll();
@ -984,6 +1032,7 @@ command_result digvx (color_ostream &out, vector <string> & parameters)
// HOTKEY COMMAND: CORE ALREADY SUSPENDED // HOTKEY COMMAND: CORE ALREADY SUSPENDED
vector <string> lol; vector <string> lol;
lol.push_back("x"); lol.push_back("x");
lol.push_back(string("-p") + int_to_string(parse_priority(out, parameters)));
return digv(out,lol); return digv(out,lol);
} }
@ -992,6 +1041,8 @@ command_result digv (color_ostream &out, vector <string> & parameters)
// HOTKEY COMMAND: CORE ALREADY SUSPENDED // HOTKEY COMMAND: CORE ALREADY SUSPENDED
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
bool updown = false; bool updown = false;
int32_t priority = parse_priority(out, parameters);
for(size_t i = 0; i < parameters.size();i++) for(size_t i = 0; i < parameters.size();i++)
{ {
if(parameters.size() && parameters[0]=="x") if(parameters.size() && parameters[0]=="x")
@ -1118,7 +1169,7 @@ command_result digv (color_ostream &out, vector <string> & parameters)
des_minus.bits.dig = tile_dig_designation::UpDownStair; des_minus.bits.dig = tile_dig_designation::UpDownStair;
else else
des_minus.bits.dig = tile_dig_designation::UpStair; des_minus.bits.dig = tile_dig_designation::UpStair;
MCache->setDesignationAt(current-1,des_minus); MCache->setDesignationAt(current-1,des_minus,priority);
des.bits.dig = tile_dig_designation::DownStair; des.bits.dig = tile_dig_designation::DownStair;
} }
@ -1130,7 +1181,7 @@ command_result digv (color_ostream &out, vector <string> & parameters)
des_plus.bits.dig = tile_dig_designation::UpDownStair; des_plus.bits.dig = tile_dig_designation::UpDownStair;
else else
des_plus.bits.dig = tile_dig_designation::DownStair; des_plus.bits.dig = tile_dig_designation::DownStair;
MCache->setDesignationAt(current+1,des_plus); MCache->setDesignationAt(current+1,des_plus,priority);
if(des.bits.dig == tile_dig_designation::DownStair) if(des.bits.dig == tile_dig_designation::DownStair)
des.bits.dig = tile_dig_designation::UpDownStair; des.bits.dig = tile_dig_designation::UpDownStair;
@ -1140,7 +1191,7 @@ command_result digv (color_ostream &out, vector <string> & parameters)
} }
if(des.bits.dig == tile_dig_designation::No) if(des.bits.dig == tile_dig_designation::No)
des.bits.dig = tile_dig_designation::Default; des.bits.dig = tile_dig_designation::Default;
MCache->setDesignationAt(current,des); MCache->setDesignationAt(current,des,priority);
} }
} }
MCache->WriteAll(); MCache->WriteAll();
@ -1153,6 +1204,7 @@ command_result diglx (color_ostream &out, vector <string> & parameters)
// HOTKEY COMMAND: CORE ALREADY SUSPENDED // HOTKEY COMMAND: CORE ALREADY SUSPENDED
vector <string> lol; vector <string> lol;
lol.push_back("x"); lol.push_back("x");
lol.push_back(string("-p") + int_to_string(parse_priority(out, parameters)));
return digl(out,lol); return digl(out,lol);
} }
@ -1168,6 +1220,8 @@ command_result digl (color_ostream &out, vector <string> & parameters)
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
bool updown = false; bool updown = false;
bool undo = false; bool undo = false;
int32_t priority = parse_priority(out, parameters);
for(size_t i = 0; i < parameters.size();i++) for(size_t i = 0; i < parameters.size();i++)
{ {
if(parameters[i]=="x") if(parameters[i]=="x")
@ -1326,7 +1380,7 @@ command_result digl (color_ostream &out, vector <string> & parameters)
// undo mode: clear designation // undo mode: clear designation
if(undo) if(undo)
des_minus.bits.dig = tile_dig_designation::No; des_minus.bits.dig = tile_dig_designation::No;
MCache->setDesignationAt(current-1,des_minus); MCache->setDesignationAt(current-1,des_minus,priority);
des.bits.dig = tile_dig_designation::DownStair; des.bits.dig = tile_dig_designation::DownStair;
} }
@ -1341,7 +1395,7 @@ command_result digl (color_ostream &out, vector <string> & parameters)
// undo mode: clear designation // undo mode: clear designation
if(undo) if(undo)
des_plus.bits.dig = tile_dig_designation::No; des_plus.bits.dig = tile_dig_designation::No;
MCache->setDesignationAt(current+1,des_plus); MCache->setDesignationAt(current+1,des_plus,priority);
if(des.bits.dig == tile_dig_designation::DownStair) if(des.bits.dig == tile_dig_designation::DownStair)
des.bits.dig = tile_dig_designation::UpDownStair; des.bits.dig = tile_dig_designation::UpDownStair;
@ -1354,7 +1408,7 @@ command_result digl (color_ostream &out, vector <string> & parameters)
// undo mode: clear designation // undo mode: clear designation
if(undo) if(undo)
des.bits.dig = tile_dig_designation::No; des.bits.dig = tile_dig_designation::No;
MCache->setDesignationAt(current,des); MCache->setDesignationAt(current,des,priority);
} }
} }
MCache->WriteAll(); MCache->WriteAll();
@ -1371,6 +1425,7 @@ command_result digauto (color_ostream &out, vector <string> & parameters)
command_result digtype (color_ostream &out, vector <string> & parameters) command_result digtype (color_ostream &out, vector <string> & parameters)
{ {
//mostly copy-pasted from digv //mostly copy-pasted from digv
int32_t priority = parse_priority(out, parameters);
CoreSuspender suspend; CoreSuspender suspend;
if ( parameters.size() > 1 ) if ( parameters.size() > 1 )
{ {
@ -1474,7 +1529,7 @@ command_result digtype (color_ostream &out, vector <string> & parameters)
df::tile_designation designation = mCache->designationAt(current); df::tile_designation designation = mCache->designationAt(current);
designation.bits.dig = baseDes.bits.dig; designation.bits.dig = baseDes.bits.dig;
mCache->setDesignationAt(current, designation); mCache->setDesignationAt(current, designation,priority);
} }
} }
} }