diff --git a/library/Core.cpp b/library/Core.cpp index 8e8b37cec..0d02861a0 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -1,4 +1,4 @@ -/* +/* https://github.com/peterix/dfhack Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) diff --git a/library/include/Core.h b/library/include/Core.h index c1d9f8217..586340c3f 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -1,4 +1,4 @@ -/* +/* https://github.com/peterix/dfhack Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) diff --git a/library/include/ModuleFactory.h b/library/include/ModuleFactory.h index 4a2f3870d..276ccabb3 100644 --- a/library/include/ModuleFactory.h +++ b/library/include/ModuleFactory.h @@ -1,4 +1,4 @@ -/* +/* https://github.com/peterix/dfhack Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) diff --git a/library/include/modules/Buildings.h b/library/include/modules/Buildings.h index 7da2ad9dc..39fbe8de6 100644 --- a/library/include/modules/Buildings.h +++ b/library/include/modules/Buildings.h @@ -24,6 +24,8 @@ distribution. #pragma once #include "Export.h" +#include "DataDefs.h" +#include "df/building.h" namespace DFHack { @@ -45,7 +47,7 @@ struct t_building t_matglossPair material; uint32_t type; int32_t custom_type; - void * origin; + df::building * origin; }; /** diff --git a/library/include/modules/Constructions.h b/library/include/modules/Constructions.h index 2e771b301..9e2150dd6 100644 --- a/library/include/modules/Constructions.h +++ b/library/include/modules/Constructions.h @@ -1,4 +1,4 @@ -/* +/* https://github.com/peterix/dfhack Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) diff --git a/library/include/modules/Maps.h b/library/include/modules/Maps.h index 57c84248d..f9c8d328b 100644 --- a/library/include/modules/Maps.h +++ b/library/include/modules/Maps.h @@ -39,7 +39,7 @@ distribution. #include "modules/Materials.h" #include "df/world.h" -#include "df/feature_type.h" +#include "df/feature_init.h" #include "df/map_block.h" #include "df/block_square_event.h" #include "df/block_square_event_mineralst.h" @@ -84,7 +84,7 @@ struct t_feature /// placeholder bool discovered; /// this is NOT part of the DF feature, but an address of the feature as seen by DFhack. - void * origin; + df::feature_init * origin; }; /** @@ -144,14 +144,14 @@ typedef int16_t t_blockmaterials [16][16]; * 16x16 array of designation flags * \ingroup grp_maps */ -typedef df::tile_designation designations40d [16][16]; typedef df::tile_designation t_designation; +typedef t_designation designations40d [16][16]; /** * 16x16 array of occupancy flags * \ingroup grp_maps */ -typedef df::tile_occupancy occupancies40d [16][16]; typedef df::tile_occupancy t_occupancy; +typedef t_occupancy occupancies40d [16][16]; /** * array of 16 biome indexes valid for the block * \ingroup grp_maps @@ -178,7 +178,7 @@ typedef struct /// values used for geology/biome assignment biome_indices40d biome_indices; /// the address where the block came from - void * origin; + df::map_block * origin; t_blockflags blockflags; /// index into the global feature vector int32_t global_feature; @@ -251,7 +251,7 @@ extern DFHACK_EXPORT bool ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_fea /** * Get pointers to features of an already read block */ -extern DFHACK_EXPORT bool ReadFeatures(mapblock40d * block, t_feature * local, t_feature * global); +extern DFHACK_EXPORT bool ReadFeatures(mapblock40d * block,t_feature * local, t_feature * global); /** * Read a specific global or local feature directly @@ -306,8 +306,7 @@ extern DFHACK_EXPORT bool SetBlockLocalFeature(uint32_t blockx, uint32_t blocky, extern DFHACK_EXPORT bool SetBlockGlobalFeature(uint32_t blockx, uint32_t blocky, uint32_t blockz, int32_t global = -1); /// copy region offsets of a block - used for determining layer stone matgloss -extern DFHACK_EXPORT bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, - biome_indices40d *buffer); +extern DFHACK_EXPORT bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, biome_indices40d *buffer); /// sorts the block event vector into multiple vectors by type /// mineral veins, what's under ice, blood smears and mud diff --git a/library/include/modules/Vermin.h b/library/include/modules/Vermin.h index 9ca2730d8..bc04111a5 100644 --- a/library/include/modules/Vermin.h +++ b/library/include/modules/Vermin.h @@ -3,6 +3,9 @@ * \defgroup grp_vermin Wild vermin (ants, bees, etc) */ #include "Export.h" +#include "DataDefs.h" +#include "df/vermin.h" + namespace DFHack { namespace Simple { namespace Vermin { /** @@ -11,7 +14,7 @@ namespace DFHack { namespace Simple { namespace Vermin */ struct t_vermin { - void * origin; + df::vermin * origin; int16_t race; int16_t caste; uint16_t x; diff --git a/library/modules/Buildings.cpp b/library/modules/Buildings.cpp index 2213abd35..1673cfc5c 100644 --- a/library/modules/Buildings.cpp +++ b/library/modules/Buildings.cpp @@ -43,7 +43,6 @@ using namespace DFHack::Simple; #include "DataDefs.h" #include "df/world.h" #include "df/building_def.h" -#include "df/building.h" #include "df/building_workshopst.h" using namespace df::enums; @@ -72,7 +71,7 @@ bool Buildings::Read (const uint32_t index, t_building & building) building.material.type = bld_40d->mat_type; building.type = type; building.custom_type = bld_40d->getCustomType(); - building.origin = (void *) &bld_40d; + building.origin = bld_40d; return true; } diff --git a/library/modules/Constructions.cpp b/library/modules/Constructions.cpp index 12658bb12..0f371b56a 100644 --- a/library/modules/Constructions.cpp +++ b/library/modules/Constructions.cpp @@ -1,4 +1,4 @@ -/* +/* https://github.com/peterix/dfhack Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index 28a7a81a3..d0ab9e022 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -1,4 +1,4 @@ -/* +/* https://github.com/peterix/dfhack Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) diff --git a/library/modules/Job.cpp b/library/modules/Job.cpp index be9560890..547a1b71c 100644 --- a/library/modules/Job.cpp +++ b/library/modules/Job.cpp @@ -1,4 +1,4 @@ -/* +/* https://github.com/peterix/dfhack Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 3fdc04622..928565b97 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -1,4 +1,4 @@ -/* +/* https://github.com/peterix/dfhack Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index 7967fe386..48195aac2 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -769,10 +769,10 @@ bool Materials::ReadCreatureTypesEx (void) // body parts caste.bodypart.empty(); - uint32_t sizebp = ca->unknown1.body_parts.size(); + uint32_t sizebp = ca->body_info.body_parts.size(); for (uint32_t k = 0; k < sizebp; k++) { - df::body_part_raw *bp = ca->unknown1.body_parts[k]; + df::body_part_raw *bp = ca->body_info.body_parts[k]; t_bodypart part; part.id = bp->part_code; part.category = bp->part_name; diff --git a/library/modules/Translation.cpp b/library/modules/Translation.cpp index 74de70bd3..2d44e2144 100644 --- a/library/modules/Translation.cpp +++ b/library/modules/Translation.cpp @@ -38,15 +38,18 @@ using namespace std; using namespace DFHack; using namespace DFHack::Simple; +using namespace df::enums; #include "DataDefs.h" #include "df/world.h" +#include "df/d_init.h" using df::global::world; +using df::global::d_init; bool Translation::IsValid () { - return (world->raws.language.words.size() > 0) && (world->raws.language.translations.size() > 0); + return (world && (world->raws.language.words.size() > 0) && (world->raws.language.translations.size() > 0)); } bool Translation::readName(t_name & name, df::language_name * source) @@ -78,50 +81,78 @@ bool Translation::copyName(df::language_name * source, df::language_name * targe return true; } +void addNameWord (string &out, const string &word) +{ + if (word.empty()) + return; + string upper = word; + upper[0] = toupper(upper[0]); + if (out.length() > 0) + out.append(" "); + out.append(upper); +} + string Translation::TranslateName(const df::language_name * name, bool inEnglish) { string out; + string word; + + if (!name->first_name.empty()) + addNameWord(out, name->first_name); + + if (!name->nickname.empty()) + { + word = "`" + name->nickname + "'"; + switch (d_init ? d_init->nickname_dwarf : d_init_nickname::CENTRALIZE) + { + case d_init_nickname::REPLACE_ALL: + out = word; + return out; + case d_init_nickname::REPLACE_FIRST: + out = ""; + break; + case d_init_nickname::CENTRALIZE: + break; + } + addNameWord(out, word); + } - if(!inEnglish) + if (!inEnglish) { if (name->words[0] >= 0 || name->words[1] >= 0) { + word.clear(); if (name->words[0] >= 0) - out.append(*world->raws.language.translations[name->language]->words[name->words[0]]); + word.append(*world->raws.language.translations[name->language]->words[name->words[0]]); if (name->words[1] >= 0) - out.append(*world->raws.language.translations[name->language]->words[name->words[1]]); - out[0] = toupper(out[0]); + word.append(*world->raws.language.translations[name->language]->words[name->words[1]]); + addNameWord(out, word); } if (name->words[5] >= 0) { - string word; + word.clear(); for (int i = 2; i <= 5; i++) if (name->words[i] >= 0) word.append(*world->raws.language.translations[name->language]->words[name->words[i]]); - word[0] = toupper(word[0]); - if (out.length() > 0) - out.append(" "); - out.append(word); + addNameWord(out, word); } if (name->words[6] >= 0) { - string word = *world->raws.language.translations[name->language]->words[name->words[6]]; - - word[0] = toupper(word[0]); - if (out.length() > 0) - out.append(" "); - out.append(word); + word.clear(); + word.append(*world->raws.language.translations[name->language]->words[name->words[6]]); + addNameWord(out, word); } } else { if (name->words[0] >= 0 || name->words[1] >= 0) { + word.clear(); if (name->words[0] >= 0) - out.append(world->raws.language.words[name->words[0]]->forms[name->parts_of_speech[0].value]); + word.append(world->raws.language.words[name->words[0]]->forms[name->parts_of_speech[0].value]); if (name->words[1] >= 0) - out.append(world->raws.language.words[name->words[1]]->forms[name->parts_of_speech[1].value]); - out[0] = toupper(out[0]); + word.append(world->raws.language.words[name->words[1]]->forms[name->parts_of_speech[1].value]); + addNameWord(out, word); } if (name->words[5] >= 0) { @@ -129,14 +160,11 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish out.append(" the"); else out.append("The"); + for (int i = 2; i <= 5; i++) { if (name->words[i] >= 0) - { - string word = world->raws.language.words[name->words[i]]->forms[name->parts_of_speech[i].value]; - word[0] = toupper(word[0]); - out.append(" " + word); - } + addNameWord(out, world->raws.language.words[name->words[i]]->forms[name->parts_of_speech[i].value]); } } if (name->words[6] >= 0) @@ -146,10 +174,9 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish else out.append("Of"); - string word = world->raws.language.words[name->words[6]]->forms[name->parts_of_speech[6].value]; - word[0] = toupper(word[0]); - out.append(" " + word); + addNameWord(out, world->raws.language.words[name->words[6]]->forms[name->parts_of_speech[6].value]); } } + return out; } diff --git a/plugins/cleanowned.cpp b/plugins/cleanowned.cpp index 911f23c94..dec591639 100644 --- a/plugins/cleanowned.cpp +++ b/plugins/cleanowned.cpp @@ -16,7 +16,6 @@ using namespace std; #include #include "modules/Items.h" #include "modules/Units.h" -#include "modules/Materials.h" #include "modules/Translation.h" #include "DataDefs.h" #include "df/world.h" @@ -96,9 +95,11 @@ DFhackCExport command_result df_cleanowned (Core * c, vector & paramete CoreSuspender suspend(c); - DFHack::Materials *Materials = c->getMaterials(); - - bool ok = Materials->ReadAllMaterials(); + if (!Translation::IsValid()) + { + c->con.printerr("Translation data unavailable!\n"); + return CR_FAILURE; + } c->con.print("Found total %d items.\n", world->items.all.size()); @@ -181,17 +182,9 @@ DFhackCExport command_result df_cleanowned (Core * c, vector & paramete ); df::unit *owner = Items::getItemOwner(item); - std::string info; if (owner) - { - info = owner->name.first_name; - if (!owner->name.nickname.empty()) - info += std::string(" '") + owner->name.nickname + "'"; - info += " "; - info += Translation::TranslateName(&owner->name,false); - c->con.print(", owner %s", info.c_str()); - } + c->con.print(", owner %s", Translation::TranslateName(&owner->name,false).c_str()); if (!dry_run) { diff --git a/plugins/fixveins.cpp b/plugins/fixveins.cpp index 092630f3e..29215c7be 100644 --- a/plugins/fixveins.cpp +++ b/plugins/fixveins.cpp @@ -22,6 +22,19 @@ using namespace df::enums; using df::global::world; +bool setTileMaterial(int16_t &tile, const TileMaterial mat) +{ + int16_t newTile = findTileType(tileShape(tile), mat, tileVariant(tile), tileSpecial(tile), tileDirection(tile)); + if (newTile == -1) + return false; + if (newTile != tile) + { + tile = newTile; + return true; + } + return false; +} + DFhackCExport command_result df_fixveins (Core * c, vector & parameters) { if (parameters.size()) @@ -35,8 +48,8 @@ DFhackCExport command_result df_fixveins (Core * c, vector & parameters return CR_FAILURE; } - int removed = 0; - int added = 0; + int mineral_removed = 0, feature_removed = 0; + int mineral_added = 0, feature_added = 0; int num_blocks = 0, blocks_total = world->map.map_blocks.size(); for (int i = 0; i < blocks_total; i++) @@ -57,33 +70,22 @@ DFhackCExport command_result df_fixveins (Core * c, vector & parameters for (int y = 0; y < 16; y++) { int16_t oldT = block->tiletype[x][y]; - int16_t newT = oldT; TileMaterial mat = tileMaterial(oldT); if ((mat == VEIN) && !(has_mineral[y] & (1 << x))) - { - newT = findTileType(tileShape(oldT), STONE, tileVariant(oldT), tileSpecial(oldT), tileDirection(oldT)); - if ((newT != -1) && (newT != oldT)) - { - block->tiletype[x][y] = newT; - removed++; - } - } + mineral_removed += setTileMaterial(block->tiletype[x][y], STONE); if ((mat == STONE) && (has_mineral[y] & (1 << x))) - { - newT = findTileType(tileShape(oldT), VEIN, tileVariant(oldT), tileSpecial(oldT), tileDirection(oldT)); - if ((newT != -1) && (newT != oldT)) - { - block->tiletype[x][y] = newT; - added++; - } - } + mineral_added += setTileMaterial(block->tiletype[x][y], VEIN); + if ((mat == FEATSTONE) && !(block->designation[x][y].bits.feature_local || block->designation[x][y].bits.feature_global)) + feature_removed += setTileMaterial(block->tiletype[x][y], STONE); + if ((mat == STONE) && (block->designation[x][y].bits.feature_local || block->designation[x][y].bits.feature_global)) + feature_added += setTileMaterial(block->tiletype[x][y], FEATSTONE); } } } - if (removed) - c->con.print("Removed %i invalid references to mineral inclusions.\n", removed); - if (added) - c->con.print("Restored %i missing references to mineral inclusions.\n", added); + if (mineral_removed || feature_removed) + c->con.print("Removed invalid references from %i mineral inclusion and %i map feature tiles.\n", mineral_removed, feature_removed); + if (mineral_added || feature_added) + c->con.print("Restored missing references to %i mineral inclusion and %i map feature tiles.\n", mineral_added, feature_added); return CR_OK; } diff --git a/plugins/showmood.cpp b/plugins/showmood.cpp index dad10efa4..834d9ded7 100644 --- a/plugins/showmood.cpp +++ b/plugins/showmood.cpp @@ -32,6 +32,12 @@ DFhackCExport command_result df_showmood (Core * c, vector & parameters if (!parameters.empty()) return CR_WRONG_USAGE; + if (!Translation::IsValid()) + { + c->con.printerr("Translation data unavailable!\n"); + return CR_FAILURE; + } + CoreSuspender suspend(c); bool found = false; @@ -61,7 +67,7 @@ DFhackCExport command_result df_showmood (Core * c, vector & parameters c->con.printerr("Dwarf with strange mood does not have a mood type!\n"); continue; } - c->con.print("%s %s is currently ", unit->name.first_name.c_str(), Translation::TranslateName(&unit->name, false).c_str()); + c->con.print("%s is currently ", Translation::TranslateName(&unit->name, false).c_str()); switch (unit->mood) { case mood_type::Macabre: