Renamed Maps::canWalkBetween to Maps::canPathBetween and added Maps::canWalkBetween, which does what it says.

develop
expwnent 2012-12-16 23:26:50 -05:00
parent 0c70a448d0
commit 01e5e93825
6 changed files with 136 additions and 3 deletions

@ -1309,7 +1309,7 @@ static const LuaWrapper::FunctionReg dfhack_maps_module[] = {
WRAPM(Maps, enableBlockUpdates), WRAPM(Maps, enableBlockUpdates),
WRAPM(Maps, getGlobalInitFeature), WRAPM(Maps, getGlobalInitFeature),
WRAPM(Maps, getLocalInitFeature), WRAPM(Maps, getLocalInitFeature),
WRAPM(Maps, canWalkBetween), WRAPM(Maps, canPathBetween),
WRAPM(Maps, spawnFlow), WRAPM(Maps, spawnFlow),
WRAPN(hasTileAssignment, hasTileAssignment), WRAPN(hasTileAssignment, hasTileAssignment),
WRAPN(getTileAssignment, getTileAssignment), WRAPN(getTileAssignment, getTileAssignment),

@ -308,6 +308,7 @@ extern DFHACK_EXPORT bool SortBlockEvents(df::map_block *block,
/// remove a block event from the block by address /// remove a block event from the block by address
extern DFHACK_EXPORT bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * which ); extern DFHACK_EXPORT bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * which );
DFHACK_EXPORT bool canPathBetween(df::coord pos1, df::coord pos2);
DFHACK_EXPORT bool canWalkBetween(df::coord pos1, df::coord pos2); DFHACK_EXPORT bool canWalkBetween(df::coord pos1, df::coord pos2);
} }
} }

@ -521,7 +521,7 @@ bool Maps::ReadGeology(vector<vector<int16_t> > *layer_mats, vector<df::coord2d>
return true; return true;
} }
bool Maps::canWalkBetween(df::coord pos1, df::coord pos2) bool Maps::canPathBetween(df::coord pos1, df::coord pos2)
{ {
auto block1 = getTileBlock(pos1); auto block1 = getTileBlock(pos1);
auto block2 = getTileBlock(pos2); auto block2 = getTileBlock(pos2);
@ -535,6 +535,50 @@ bool Maps::canWalkBetween(df::coord pos1, df::coord pos2)
return tile1 && tile1 == tile2; return tile1 && tile1 == tile2;
} }
bool Maps::canWalkBetween(df::coord pos1, df::coord pos2)
{
bool b = canPathBetween(pos1, pos2);
if ( !b )
return false;
int32_t dx = pos1.x-pos2.x;
int32_t dy = pos1.y-pos2.y;
int32_t dz = pos1.z-pos2.z;
if ( dx*dx > 1 || dy*dy > 1 || dz*dz > 1 )
return false;
if ( dz == 0 )
return true;
df::tiletype* type1 = Maps::getTileType(pos1);
df::tiletype* type2 = Maps::getTileType(pos2);
df::tiletype_shape shape1 = ENUM_ATTR(tiletype,shape,*type1);
df::tiletype_shape shape2 = ENUM_ATTR(tiletype,shape,*type2);
if ( pos2.z < pos1.z ) {
df::tiletype_shape temp = shape1;
shape1 = shape2;
shape2 = temp;
}
if ( dx == 0 && dy == 0 ) {
if ( shape1 == tiletype_shape::STAIR_UPDOWN && shape2 == shape1 )
return true;
if ( shape1 == tiletype_shape::STAIR_UPDOWN && shape2 == tiletype_shape::STAIR_DOWN )
return true;
if ( shape1 == tiletype_shape::STAIR_UP && shape2 == tiletype_shape::STAIR_UPDOWN )
return true;
return false;
}
//diagonal up: has to be a ramp
if ( shape1 == tiletype_shape::RAMP && shape2 == tiletype_shape::RAMP )
return true;
return false;
}
#define COPY(a,b) memcpy(&a,&b,sizeof(a)) #define COPY(a,b) memcpy(&a,&b,sizeof(a))
MapExtras::Block::Block(MapCache *parent, DFCoord _bcoord) : parent(parent) MapExtras::Block::Block(MapCache *parent, DFCoord _bcoord) : parent(parent)

@ -21,3 +21,4 @@ DFHACK_PLUGIN(vshook vshook.cpp)
IF(UNIX) IF(UNIX)
DFHACK_PLUGIN(ref-index ref-index.cpp) DFHACK_PLUGIN(ref-index ref-index.cpp)
ENDIF() ENDIF()
DFHACK_PLUGIN(walkBetween walkBetween.cpp)

@ -0,0 +1,87 @@
#include "Core.h"
#include <Console.h>
#include <Export.h>
#include <PluginManager.h>
// DF data structure definition headers
#include "DataDefs.h"
#include "df/world.h"
#include "modules/Gui.h"
#include "modules/Maps.h"
using namespace DFHack;
using namespace df::enums;
command_result walkBetween (color_ostream &out, std::vector <std::string> & parameters);
// A plugin must be able to return its name and version.
// The name string provided must correspond to the filename - skeleton.plug.so or skeleton.plug.dll in this case
DFHACK_PLUGIN("walkBetween");
// Mandatory init function. If you have some global state, create it here.
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{
// Fill the command list with your commands.
commands.push_back(PluginCommand(
"walkBetween", "Do nothing, look pretty.",
walkBetween, false, /* true means that the command can't be used from non-interactive user interface */
// Extended help string. Used by CR_WRONG_USAGE and the help command:
" This command does nothing at all.\n"
));
return CR_OK;
}
// This is called right before the plugin library is removed from memory.
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{
// You *MUST* kill all threads you created before this returns.
// If everything fails, just return CR_FAILURE. Your plugin will be
// in a zombie state, but things won't crash.
return CR_OK;
}
// Called to notify the plugin about important state changes.
// Invoked with DF suspended, and always before the matching plugin_onupdate.
// More event codes may be added in the future.
/*
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
{
switch (event) {
case SC_GAME_LOADED:
// initialize from the world just loaded
break;
case SC_GAME_UNLOADED:
// cleanup
break;
default:
break;
}
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 ( color_ostream &out )
{
// whetever. You don't need to suspend DF execution here.
return CR_OK;
}
*/
df::coord prev;
// A command! It sits around and looks pretty. And it's nice and friendly.
command_result walkBetween (color_ostream &out, std::vector <std::string> & parameters)
{
df::coord bob = Gui::getCursorPos();
out.print("(%d,%d,%d), (%d,%d,%d): canWalkBetween = %d, canPathBetween = %d\n", prev.x, prev.y, prev.z, bob.x, bob.y, bob.z, Maps::canWalkBetween(prev, bob), Maps::canPathBetween(prev,bob));
prev = bob;
return CR_OK;
}

@ -475,7 +475,7 @@ static bool try_store_item(df::building *target, df::item *item)
df::coord tpos(target->centerx, target->centery, target->z); df::coord tpos(target->centerx, target->centery, target->z);
df::coord ipos = Items::getPosition(item); df::coord ipos = Items::getPosition(item);
if (!Maps::canWalkBetween(tpos, ipos)) if (!Maps::canPathBetween(tpos, ipos))
return false; return false;
// Check if the target has enough space left // Check if the target has enough space left