Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Template for new versions:

## Fixes

- Fix broken weather lookup in ``World::ReadCurrentWeather``

## Misc Improvements

## Documentation
Expand All @@ -70,6 +72,8 @@ Template for new versions:
- Added ``Maps::getSiteTypeName`` to print the sites classification as a string (e.g. "mountain halls")
- Added ``Maps::addRegionBiomeOffset`` to shift world region coordinate by region_details biome reference
- Added ``Maps::describeSurroundings`` to get surroundings classification from savagery and evilness
- Added ``Maps::getCurrentWeather`` to determine the current weather on the map.
- Deprecated ``World::ReadCurrentWeather`` in favor of ``Maps::getCurrentWeather``

## Lua

Expand Down
10 changes: 9 additions & 1 deletion docs/dev/Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2342,7 +2342,8 @@ World module

* ``dfhack.world.ReadCurrentWeather()``

Returns the current game weather (``df.weather_type``).
Returns the current game weather (``df.weather_type``). Deprecated: use
``dfhack.maps.getCurrentWeather()`` instead.

* ``dfhack.world.SetCurrentWeather(weather)``

Expand Down Expand Up @@ -2441,6 +2442,13 @@ Maps module

Returns *x, y* for use with ``getRegionBiome`` and ``getBiomeType``.

* ``dfhack.maps.getCurrentWeather(coords)``
``dfhack.maps.getCurrentWeather(x,y,z)``
``dfhack.maps.getCurrentWeather()``

Returns the current game weather (``df.weather_type``) at the specified tile
or at the center of the map if no argument is provided.

* ``dfhack.maps.getPlantAtTile(pos)``, or ``getPlantAtTile(x,y,z)``

Returns the plant struct that owns the tile at the specified position.
Expand Down
13 changes: 13 additions & 0 deletions library/LuaApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2724,6 +2724,18 @@ static int maps_getTileBiomeRgn(lua_State *L)
return Lua::PushPosXY(L, Maps::getTileBiomeRgn(pos));
}

static int maps_getCurrentWeather(lua_State *L)
{
if (lua_gettop(L) == 0)
{
lua_pushinteger(L, Maps::getCurrentWeather());
} else {
auto pos = CheckCoordXYZ(L, 1, true);
lua_pushinteger(L, Maps::getCurrentWeather(pos));
}
return 1;
}

static int maps_getPlantAtTile(lua_State *L)
{
auto pos = CheckCoordXYZ(L, 1, true);
Expand Down Expand Up @@ -2830,6 +2842,7 @@ static const luaL_Reg dfhack_maps_funcs[] = {
{ "getTileFlags", maps_getTileFlags },
{ "getRegionBiome", maps_getRegionBiome },
{ "getTileBiomeRgn", maps_getTileBiomeRgn },
{ "getCurrentWeather", maps_getCurrentWeather },
{ "getPlantAtTile", maps_getPlantAtTile },
{ "getBiomeType", maps_getBiomeType },
{ "isTileAquifer", maps_isTileAquifer },
Expand Down
4 changes: 4 additions & 0 deletions library/include/modules/Maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ distribution.
#include "df/matter_state.h"
#include "df/tile_dig_designation.h"
#include "df/tiletype.h"
#include "df/weather_type.h"
#include "df/world_site.h"

namespace df {
Expand Down Expand Up @@ -365,6 +366,9 @@ DFHACK_EXPORT df::coord2d getBlockTileBiomeRgn(df::map_block *block, df::coord2d

inline df::coord2d getTileBiomeRgn(df::coord pos) { return getBlockTileBiomeRgn(getTileBlock(pos), pos); }

DFHACK_EXPORT df::weather_type getCurrentWeather(df::coord pos);
DFHACK_EXPORT df::weather_type getCurrentWeather();

// Enables per-frame updates for liquid flow and/or temperature.
DFHACK_EXPORT void enableBlockUpdates(df::map_block *blk, bool flow = false, bool temperature = false);

Expand Down
3 changes: 2 additions & 1 deletion library/include/modules/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ distribution.
#include "df/game_mode.h"
#include "df/game_type.h"
#include "df/unit.h"
#include "df/weather_type.h"


namespace df
Expand Down Expand Up @@ -80,7 +81,7 @@ namespace DFHack
DFHACK_EXPORT uint32_t ReadCurrentYear();
DFHACK_EXPORT uint32_t ReadCurrentMonth();
DFHACK_EXPORT uint32_t ReadCurrentDay();
DFHACK_EXPORT uint8_t ReadCurrentWeather();
DFHACK_EXPORT df::weather_type ReadCurrentWeather(); // deprecated
DFHACK_EXPORT void SetCurrentWeather(uint8_t weather);
DFHACK_EXPORT bool ReadGameMode(t_gamemodes& rd);
DFHACK_EXPORT bool WriteGameMode(const t_gamemodes & wr); // this is very dangerous
Expand Down
23 changes: 23 additions & 0 deletions library/modules/Maps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ distribution.
#include "df/plotinfost.h"
#include "df/region_map_entry.h"
#include "df/site_map_infost.h"
#include "df/weather_type.h"
#include "df/world_data.h"
#include "df/world_geo_biome.h"
#include "df/world_geo_layer.h"
Expand Down Expand Up @@ -989,6 +990,28 @@ df::coord2d Maps::getBlockTileBiomeRgn(df::map_block *block, df::coord2d pos)
return df::coord2d();
}

df::weather_type Maps::getCurrentWeather(df::coord pos)
{
if (df::global::current_weather){
auto &map = world->map;
auto [biome_x, biome_y] = Maps::getTileBiomeRgn(pos);
const int weather_x = biome_x - map.region_x / 16 + 1;
const int weather_y = biome_y - map.region_y / 16 + 1;
return (*df::global::current_weather)[weather_x][weather_y];
}
return df::weather_type::None;
}

df::weather_type Maps::getCurrentWeather()
{
auto &map = world->map;
if (map.x_count > 0 && map.y_count > 0 && map.z_count > 0) {
return Maps::getCurrentWeather(df::coord( map.x_count / 2, map.y_count / 2, map.z_count / 2 ));
} else {
return df::weather_type::None;
}
}

/*
* Layer geology
*/
Expand Down
8 changes: 4 additions & 4 deletions library/modules/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ distribution.
#include "modules/Gui.h"
#include "modules/Translation.h"
#include "modules/Units.h"
#include "modules/Maps.h"
#include "modules/World.h"
#include "modules/Translation.h"

Expand All @@ -37,6 +38,7 @@ distribution.
#include "df/map_block.h"
#include "df/plotinfost.h"
#include "df/viewscreen_dwarfmodest.h"
#include "df/weather_type.h"
#include "df/world.h"
#include "df/world_data.h"
#include "df/world_site.h"
Expand Down Expand Up @@ -153,11 +155,9 @@ uint32_t World::ReadCurrentDay()
return ((ReadCurrentTick() / 1200) % 28) + 1;
}

uint8_t World::ReadCurrentWeather()
df::weather_type World::ReadCurrentWeather()
{
if (df::global::current_weather)
return (*df::global::current_weather)[2][2];
return 0;
return Maps::getCurrentWeather();
}

void World::SetCurrentWeather(uint8_t weather)
Expand Down
Loading