Skip to content
Merged
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
3 changes: 2 additions & 1 deletion docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ Template for new versions:
## API

- ``Screen``: new functions ``paintMapPortTile`` and ``readMapPortTile`` to write and read world and region map tiles.
- ``Materials``: ``MaterialInfo`` constants ``NUM_BUILTIN``, ``GROUP_SIZE``, ``CREATURE_BASE``, ``FIGURE_BASE``, ``PLANT_BASE``, and ``END_BASE`` removed. New plugins should use appropriate members of the ``df::builtin_mats`` enum.

## Lua

- Added ``Screen::paintMapPortTile`` as ``dfhack.screen.paintMapPortTile``
- Added ``Screen::readMapPortTile`` as ``dfhack.screen.readMapPortTile``

- Deprecated ``gui.materials.CREATURE_BASE`` and ``gui.materials.PLANT_BASE`` - scripts should instead use ``df.builtin_mats.CREATURE_1`` and ``df.builtin_mats.PLANT_1``, respectively.

## Removed

Expand Down
3 changes: 2 additions & 1 deletion library/LuaApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ distribution.
#include "df/building_stockpilest.h"
#include "df/building_tradedepotst.h"
#include "df/building_workshopst.h"
#include "df/builtin_mats.h"
#include "df/burrow.h"
#include "df/caravan_state.h"
#include "df/construction.h"
Expand Down Expand Up @@ -491,7 +492,7 @@ static bool decode_matinfo(lua_State *state, MaterialInfo *info, bool numpair =
if (auto item = Lua::GetDFObject<df::item>(state, 1))
return info->decode(item);
if (auto plant = Lua::GetDFObject<df::plant>(state, 1))
return info->decode(MaterialInfo::PLANT_BASE, plant->material);
return info->decode(df::builtin_mats::PLANT_1, plant->material);
if (auto mvec = Lua::GetDFObject<df::material_vec_ref>(state, 1))
return info->decode(*mvec, luaL_checkint(state, 2));
}
Expand Down
6 changes: 3 additions & 3 deletions library/RemoteTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ static command_result ListMaterials(color_ostream &stream,

if (in->builtin())
{
for (int i = 0; i < MaterialInfo::NUM_BUILTIN; i++)
for (int i = 0; i < df::builtin_mats::CREATURE_1; i++)
listMaterial(out, i, -1, mask);
}

Expand All @@ -549,7 +549,7 @@ static command_result ListMaterials(color_ostream &stream,
auto praw = vec[i];

for (size_t j = 0; j < praw->material.size(); j++)
listMaterial(out, MaterialInfo::CREATURE_BASE+j, i, mask);
listMaterial(out, df::builtin_mats::CREATURE_1+j, i, mask);
}
}

Expand All @@ -561,7 +561,7 @@ static command_result ListMaterials(color_ostream &stream,
auto praw = vec[i];

for (size_t j = 0; j < praw->material.size(); j++)
listMaterial(out, MaterialInfo::PLANT_BASE+j, i, mask);
listMaterial(out, df::builtin_mats::PLANT_1+j, i, mask);
}
}

Expand Down
7 changes: 0 additions & 7 deletions library/include/modules/Materials.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ namespace DFHack

struct DFHACK_EXPORT MaterialInfo
{
static const int NUM_BUILTIN = 19;
static const int GROUP_SIZE = 200;
static const int CREATURE_BASE = NUM_BUILTIN;
static const int FIGURE_BASE = NUM_BUILTIN + GROUP_SIZE;
static const int PLANT_BASE = NUM_BUILTIN + GROUP_SIZE * 2;
static const int END_BASE = NUM_BUILTIN + GROUP_SIZE * 3;

int16_t type;
int32_t index;

Expand Down
9 changes: 5 additions & 4 deletions library/lua/gui/materials.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ local dlg = require('gui.dialogs')

ARROW = string.char(26)

CREATURE_BASE = 19
PLANT_BASE = 419
-- For backwards compatibility with older scripts
CREATURE_BASE = df.builtin_mats.CREATURE_1
PLANT_BASE = df.builtin_mats.PLANT_1

MaterialDialog = defclass(MaterialDialog, gui.FramedScreen)

Expand Down Expand Up @@ -127,7 +128,7 @@ function MaterialDialog:initCreatureMode()
local choices = {}

for i,v in ipairs(df.global.world.raws.creatures.all) do
self:addObjectChoice(choices, v, v.name[0], CREATURE_BASE, i)
self:addObjectChoice(choices, v, v.name[0], df.builtin_mats.CREATURE_1, i)
end

self:pushContext('Creature materials', choices)
Expand All @@ -137,7 +138,7 @@ function MaterialDialog:initPlantMode()
local choices = {}

for i,v in ipairs(df.global.world.raws.plants.all) do
self:addObjectChoice(choices, v, v.name, PLANT_BASE, i)
self:addObjectChoice(choices, v, v.name, df.builtin_mats.PLANT_1, i)
end

self:pushContext('Plant materials', choices)
Expand Down
4 changes: 2 additions & 2 deletions library/lua/tile-material.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function GetTreeMat(x, y, z)
for _, tree in ipairs(df.global.world.plants.all) do
if tree.tree_info ~= nil then
if coordInTree(pos, tree) then
return dfhack.matinfo.decode(419, tree.material)
return dfhack.matinfo.decode(df.builtin_mats.PLANT_1, tree.material)
end
end
end
Expand All @@ -209,7 +209,7 @@ function GetShrubMat(x, y, z)
for _, shrub in ipairs(df.global.world.plants.all) do
if shrub.tree_info == nil then
if shrub.pos.x == pos.x and shrub.pos.y == pos.y and shrub.pos.z == pos.z then
return dfhack.matinfo.decode(419, shrub.material)
return dfhack.matinfo.decode(df.builtin_mats.PLANT_1, shrub.material)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion library/modules/Items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ int32_t Items::pickGrowthPrint(int16_t subtype, int16_t mat, int32_t matg)
{
int growth_print = -1;
// Make sure it's made of a valid plant material, then grab its definition
if (mat >= 419 && mat <= 618 && matg >= 0 && (unsigned)matg < world->raws.plants.all.size())
if (mat >= df::builtin_mats::PLANT_1 && mat <= df::builtin_mats::PLANT_200 && matg >= 0 && (unsigned)matg < world->raws.plants.all.size())
{
auto plant_def = world->raws.plants.all[matg];
// Make sure it subtype is also valid
Expand Down
2 changes: 1 addition & 1 deletion library/modules/Kitchen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void Kitchen::debug_print(color_ostream &out)
plotinfo->kitchen.mat_types[i],
plotinfo->kitchen.mat_indices[i],
plotinfo->kitchen.exc_types[i].whole,
(plotinfo->kitchen.mat_types[i] >= 419 && plotinfo->kitchen.mat_types[i] <= 618) ? world->raws.plants.all[plotinfo->kitchen.mat_indices[i]]->id : "n/a"
(plotinfo->kitchen.mat_types[i] >= df::builtin_mats::PLANT_1 && plotinfo->kitchen.mat_types[i] <= df::builtin_mats::PLANT_200) ? world->raws.plants.all[plotinfo->kitchen.mat_indices[i]]->id : "n/a"
);
}
out.print("\n");
Expand Down
4 changes: 2 additions & 2 deletions library/modules/MapCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ t_matpair MapExtras::BlockInfo::getBaseMaterial(df::tiletype tt, df::coord2d pos
case ROOT:
case TREE:
case PLANT:
rv.mat_type = MaterialInfo::PLANT_BASE;
rv.mat_type = df::builtin_mats::PLANT_1;
if (auto plant = plants[block->map_pos + df::coord(x,y,0)])
{
if (auto raw = df::plant_raw::find(plant->material))
Expand All @@ -958,7 +958,7 @@ t_matpair MapExtras::BlockInfo::getBaseMaterial(df::tiletype tt, df::coord2d pos
case GRASS_DARK:
case GRASS_DRY:
case GRASS_DEAD:
rv.mat_type = MaterialInfo::PLANT_BASE;
rv.mat_type = df::builtin_mats::PLANT_1;
if (auto raw = df::plant_raw::find(grass[x][y]))
{
rv.mat_type = raw->material_defs.type[plant_material_def::basic_mat];
Expand Down
22 changes: 11 additions & 11 deletions library/modules/Materials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,31 @@ bool MaterialInfo::decode(int16_t type, int32_t index)
{
material = raws.mat_table.builtin[type];
}
else if (type == 0)
else if (type == df::builtin_mats::INORGANIC)
{
mode = Inorganic;
inorganic = df::inorganic_raw::find(index);
if (!inorganic)
return false;
material = &inorganic->material;
}
else if (type < CREATURE_BASE)
else if (type < df::builtin_mats::CREATURE_1)
{
material = raws.mat_table.builtin[type];
}
else if (type < FIGURE_BASE)
else if (type <= df::builtin_mats::CREATURE_200)
{
mode = Creature;
subtype = type - CREATURE_BASE;
subtype = type - df::builtin_mats::CREATURE_1;
creature = df::creature_raw::find(index);
if (!creature || size_t(subtype) >= creature->material.size())
return false;
material = creature->material[subtype];
}
else if (type < PLANT_BASE)
else if (type <= df::builtin_mats::HIST_FIG_200)
{
mode = Creature;
subtype = type - FIGURE_BASE;
subtype = type - df::builtin_mats::HIST_FIG_1;
figure = df::historical_figure::find(index);
if (!figure)
return false;
Expand All @@ -141,10 +141,10 @@ bool MaterialInfo::decode(int16_t type, int32_t index)
return false;
material = creature->material[subtype];
}
else if (type < END_BASE)
else if (type <= df::builtin_mats::PLANT_200)
{
mode = Plant;
subtype = type - PLANT_BASE;
subtype = type - df::builtin_mats::PLANT_1;
plant = df::plant_raw::find(index);
if (!plant || size_t(subtype) >= plant->material.size())
return false;
Expand Down Expand Up @@ -219,7 +219,7 @@ bool MaterialInfo::findBuiltin(const std::string& token)
}

auto& raws = world->raws;
for (int i = 0; i < NUM_BUILTIN; i++)
for (int i = 0; i < df::builtin_mats::CREATURE_1; i++)
{
auto obj = raws.mat_table.builtin[i];
if (obj && obj->id == token)
Expand Down Expand Up @@ -266,7 +266,7 @@ bool MaterialInfo::findPlant(const std::string& token, const std::string& subtok

for (size_t j = 0; j < p->material.size(); j++)
if (p->material[j]->id == subtoken)
return decode(PLANT_BASE + j, i);
return decode(df::builtin_mats::PLANT_1 + j, i);

break;
}
Expand All @@ -286,7 +286,7 @@ bool MaterialInfo::findCreature(const std::string& token, const std::string& sub

for (size_t j = 0; j < p->material.size(); j++)
if (p->material[j]->id == subtoken)
return decode(CREATURE_BASE + j, i);
return decode(df::builtin_mats::CREATURE_1 + j, i);

break;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/autochop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ static int32_t estimate_logs(const df::plant *plant) {
return 0;

MaterialInfo mi;
mi.decode(MaterialInfo::PLANT_BASE, plant->material);
mi.decode(df::builtin_mats::PLANT_1, plant->material);
bool is_shroom = mi.plant->flags.is_set(df::plant_raw_flags::TREE_HAS_MUSHROOM_CAP);

int32_t trunks = 0, parent_dir = 0;
Expand Down
2 changes: 1 addition & 1 deletion plugins/buildingplan/buildingplan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static void load_organic_material_cache(df::organic_mat_category cat) {

static void load_material_cache() {
auto &raws = world->raws;
for (int i = 1; i < DFHack::MaterialInfo::NUM_BUILTIN; ++i)
for (int i = 1; i < df::builtin_mats::CREATURE_1; ++i)
if (raws.mat_table.builtin[i])
cache_matched(i, -1);

Expand Down
26 changes: 13 additions & 13 deletions plugins/remotefortressreader/remotefortressreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,12 +634,12 @@ static command_result CheckHashes(color_ostream &stream, const EmptyMessage *in)

void CopyMat(RemoteFortressReader::MatPair * mat, int type, int index)
{
if (type >= MaterialInfo::FIGURE_BASE && type < MaterialInfo::PLANT_BASE)
if (type >= df::builtin_mats::HIST_FIG_1 && type <= df::builtin_mats::HIST_FIG_200)
{
df::historical_figure * figure = df::historical_figure::find(index);
if (figure)
{
type -= MaterialInfo::GROUP_SIZE;
type = (type - df::builtin_mats::HIST_FIG_1) + df::builtin_mats::CREATURE_1;
index = figure->race;
}
}
Expand Down Expand Up @@ -817,9 +817,9 @@ static command_result GetMaterialList(color_ostream &stream, const EmptyMessage
MaterialInfo mat;
for (size_t i = 0; i < raws->inorganics.all.size(); i++)
{
mat.decode(0, i);
mat.decode(df::builtin_mats::INORGANIC, i);
MaterialDefinition *mat_def = out->add_material_list();
mat_def->mutable_mat_pair()->set_mat_type(0);
mat_def->mutable_mat_pair()->set_mat_type(df::builtin_mats::INORGANIC);
mat_def->mutable_mat_pair()->set_mat_index(i);
mat_def->set_id(mat.getToken());
mat_def->set_name(DF2UTF(mat.toString())); //find the name at cave temperature;
Expand All @@ -828,11 +828,11 @@ static command_result GetMaterialList(color_ostream &stream, const EmptyMessage
ConvertDFColorDescriptor(raws->inorganics.all[i]->material.state_color[GetState(&raws->inorganics.all[i]->material)], mat_def->mutable_state_color());
}
}
for (int i = 0; i < 19; i++)
for (int i = 0; i < df::builtin_mats::CREATURE_1; i++)
{
int k = -1;
if (i == 7)
k = 1;// for coal.
if (i == df::builtin_mats::COAL)
k = 1;// for coke and charcoal
for (int j = -1; j <= k; j++)
{
mat.decode(i, j);
Expand All @@ -852,9 +852,9 @@ static command_result GetMaterialList(color_ostream &stream, const EmptyMessage
df::creature_raw * creature = raws->creatures.all[i];
for (size_t j = 0; j < creature->material.size(); j++)
{
mat.decode(j + MaterialInfo::CREATURE_BASE, i);
mat.decode(j + df::builtin_mats::CREATURE_1, i);
MaterialDefinition *mat_def = out->add_material_list();
mat_def->mutable_mat_pair()->set_mat_type(j + 19);
mat_def->mutable_mat_pair()->set_mat_type(j + df::builtin_mats::CREATURE_1);
mat_def->mutable_mat_pair()->set_mat_index(i);
mat_def->set_id(mat.getToken());
mat_def->set_name(DF2UTF(mat.toString())); //find the name at cave temperature;
Expand All @@ -869,9 +869,9 @@ static command_result GetMaterialList(color_ostream &stream, const EmptyMessage
df::plant_raw * plant = raws->plants.all[i];
for (size_t j = 0; j < plant->material.size(); j++)
{
mat.decode(j + 419, i);
mat.decode(j + df::builtin_mats::PLANT_1, i);
MaterialDefinition *mat_def = out->add_material_list();
mat_def->mutable_mat_pair()->set_mat_type(j + 419);
mat_def->mutable_mat_pair()->set_mat_type(j + df::builtin_mats::PLANT_1);
mat_def->mutable_mat_pair()->set_mat_index(i);
mat_def->set_id(mat.getToken());
mat_def->set_name(DF2UTF(mat.toString())); //find the name at cave temperature;
Expand Down Expand Up @@ -2096,14 +2096,14 @@ static void SetRegionTile(RegionTile * out, df::region_map_entry * e1)
auto plantMat = out->add_plant_materials();

plantMat->set_mat_index(pop->plant);
plantMat->set_mat_type(419);
plantMat->set_mat_type(df::builtin_mats::PLANT_1);
}
else if (pop->type == world_population_type::Tree)
{
auto plantMat = out->add_tree_materials();

plantMat->set_mat_index(pop->plant);
plantMat->set_mat_type(419);
plantMat->set_mat_type(df::builtin_mats::PLANT_1);
}
}
#if DF_VERSION_INT >= 43005
Expand Down
Loading