Merge remote-tracking branch 'Bumber64/patch-1' into develop

develop
lethosor 2021-06-25 00:59:39 -04:00
commit 64f0efd7b2
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
6 changed files with 67 additions and 2 deletions

@ -30,7 +30,6 @@ Benjamin Seiller bseiller RedDwarfStepper
billw2012 billw2012 billw2012 billw2012
BrickViking brickviking BrickViking brickviking
brndd brndd burneddi brndd brndd burneddi
Bumber Bumber64
Caldfir caldfir Caldfir caldfir
Carter Bray Qartar Carter Bray Qartar
Chris Dombroski cdombroski Chris Dombroski cdombroski
@ -152,6 +151,7 @@ rubybrowncoat rubybrowncoat
Rumrusher rumrusher Rumrusher rumrusher
RusAnon RusAnon RusAnon RusAnon
Ryan Bennitt ryanbennitt Ryan Bennitt ryanbennitt
Ryan Williams Bumber64 Bumber
sami sami
scamtank scamtank scamtank scamtank
Sebastian Wolfertz Enkrod Sebastian Wolfertz Enkrod

@ -1558,6 +1558,10 @@ Maps module
Returns *x, y* for use with ``getRegionBiome``. Returns *x, y* for use with ``getRegionBiome``.
* ``dfhack.maps.getPlantAtTile(pos)``, or ``getPlantAtTile(x,y,z)``
Returns the plant struct that owns the tile at the specified position.
* ``dfhack.maps.canWalkBetween(pos1, pos2)`` * ``dfhack.maps.canWalkBetween(pos1, pos2)``
Checks if a dwarf may be able to walk between the two tiles, Checks if a dwarf may be able to walk between the two tiles,

@ -61,6 +61,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## API ## API
- Added ``dfhack.units.teleport(unit, pos)`` - Added ``dfhack.units.teleport(unit, pos)``
- Added ``dfhack.maps.getPlantAtTile(x, y, z)`` and ``dfhack.maps.getPlantAtTile(pos)``
## Documentation ## Documentation
- Added more client library implementations to the `remote interface docs <remote-client-libs>` - Added more client library implementations to the `remote interface docs <remote-client-libs>`

@ -1923,6 +1923,13 @@ static int maps_getTileBiomeRgn(lua_State *L)
return Lua::PushPosXY(L, Maps::getTileBiomeRgn(pos)); return Lua::PushPosXY(L, Maps::getTileBiomeRgn(pos));
} }
static int maps_getPlantAtTile(lua_State *L)
{
auto pos = CheckCoordXYZ(L, 1, true);
Lua::PushDFObject(L, Maps::getPlantAtTile(pos));
return 1;
}
static const luaL_Reg dfhack_maps_funcs[] = { static const luaL_Reg dfhack_maps_funcs[] = {
{ "isValidTilePos", maps_isValidTilePos }, { "isValidTilePos", maps_isValidTilePos },
{ "isTileVisible", maps_isTileVisible }, { "isTileVisible", maps_isTileVisible },
@ -1932,6 +1939,7 @@ static const luaL_Reg dfhack_maps_funcs[] = {
{ "getTileFlags", maps_getTileFlags }, { "getTileFlags", maps_getTileFlags },
{ "getRegionBiome", maps_getRegionBiome }, { "getRegionBiome", maps_getRegionBiome },
{ "getTileBiomeRgn", maps_getTileBiomeRgn }, { "getTileBiomeRgn", maps_getTileBiomeRgn },
{ "getPlantAtTile", maps_getPlantAtTile },
{ NULL, NULL } { NULL, NULL }
}; };

@ -40,6 +40,7 @@ distribution.
#include "df/block_flags.h" #include "df/block_flags.h"
#include "df/feature_type.h" #include "df/feature_type.h"
#include "df/flow_type.h" #include "df/flow_type.h"
#include "df/plant.h"
#include "df/tile_dig_designation.h" #include "df/tile_dig_designation.h"
#include "df/tile_liquid.h" #include "df/tile_liquid.h"
#include "df/tile_traffic.h" #include "df/tile_traffic.h"
@ -335,6 +336,13 @@ extern DFHACK_EXPORT bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, d
DFHACK_EXPORT bool canWalkBetween(df::coord pos1, df::coord pos2); DFHACK_EXPORT bool canWalkBetween(df::coord pos1, df::coord pos2);
DFHACK_EXPORT bool canStepBetween(df::coord pos1, df::coord pos2); DFHACK_EXPORT bool canStepBetween(df::coord pos1, df::coord pos2);
/**
* Get the plant that owns the tile at the specified position
*/
extern DFHACK_EXPORT df::plant *getPlantAtTile(int32_t x, int32_t y, int32_t z);
inline df::plant *getPlantAtTile(df::coord pos) { return getPlantAtTile(pos.x, pos.y, pos.z); }
DFHACK_EXPORT df::enums::biome_type::biome_type GetBiomeType(int world_coord_x, int world_coord_y); DFHACK_EXPORT df::enums::biome_type::biome_type GetBiomeType(int world_coord_x, int world_coord_y);
DFHACK_EXPORT df::enums::biome_type::biome_type GetBiomeTypeWithRef(int world_coord_x, int world_coord_y, int world_ref_y_coord); DFHACK_EXPORT df::enums::biome_type::biome_type GetBiomeTypeWithRef(int world_coord_x, int world_coord_y, int world_ref_y_coord);

@ -55,11 +55,13 @@ using namespace std;
#include "df/burrow.h" #include "df/burrow.h"
#include "df/feature_init.h" #include "df/feature_init.h"
#include "df/flow_info.h" #include "df/flow_info.h"
#include "df/map_block_column.h"
#include "df/plant.h" #include "df/plant.h"
#include "df/plant_tree_info.h"
#include "df/plant_tree_tile.h"
#include "df/region_map_entry.h" #include "df/region_map_entry.h"
#include "df/world.h" #include "df/world.h"
#include "df/world_data.h" #include "df/world_data.h"
#include "df/world_data.h"
#include "df/world_geo_biome.h" #include "df/world_geo_biome.h"
#include "df/world_geo_layer.h" #include "df/world_geo_layer.h"
#include "df/world_region_details.h" #include "df/world_region_details.h"
@ -713,6 +715,48 @@ bool Maps::canStepBetween(df::coord pos1, df::coord pos2)
return false; return false;
} }
/*
* Plants
*/
df::plant *Maps::getPlantAtTile(int32_t x, int32_t y, int32_t z)
{
if (x < 0 || x >= world->map.x_count || y < 0 || y >= world->map.y_count || !world->map.column_index)
return NULL;
df::map_block_column *mbc = world->map.column_index[(x / 48) * 3][(y / 48) * 3];
if (!mbc)
return NULL;
for (size_t i = 0; i < mbc->plants.size(); i++)
{
df::plant *p = mbc->plants[i];
if (p->pos.x == x && p->pos.y == y && p->pos.z == z)
return p;
df::plant_tree_info *t = p->tree_info;
if (!t)
continue;
int32_t x_index = (t->dim_x / 2) - (p->pos.x % 48) + (x % 48);
int32_t y_index = (t->dim_y / 2) - (p->pos.y % 48) + (y % 48);
int32_t z_dis = z - p->pos.z;
if (x_index < 0 || x_index >= t->dim_x || y_index < 0 || y_index >= t->dim_y || z_dis >= t->body_height)
continue;
if (z_dis < 0)
{
if (z_dis < -(t->roots_depth))
continue;
else if ((t->roots[-1 - z_dis][x_index + y_index * t->dim_x].whole & 0x7F) != 0) //any non-blocked tree_tile
return p;
}
else if ((t->body[z_dis][x_index + y_index * t->dim_x].whole & 0x7F) != 0)
return p;
}
return NULL;
}
/* The code below is a heavily refactored version of code found at /* The code below is a heavily refactored version of code found at
https://github.com/ragundo/exportmaps/blob/master/cpp/df_utils/biome_type.cpp. https://github.com/ragundo/exportmaps/blob/master/cpp/df_utils/biome_type.cpp.
*/ */