Export unit curse, squad, death and burrow info.

develop
Alexander Gavrilov 2012-03-18 13:52:39 +04:00
parent 415ae35dff
commit e33414fa69
4 changed files with 98 additions and 7 deletions

@ -73,6 +73,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "df/historical_entity.h"
#include "df/squad.h"
#include "df/squad_position.h"
#include "df/death_info.h"
#include "BasicApi.pb.h"
@ -100,11 +101,13 @@ void DFHack::describeEnum(RepeatedPtrField<EnumItemName> *pf, int base,
{
for (int i = 0; i < size; i++)
{
const char *key = names[i];
if (!key)
continue;
auto item = pf->Add();
item->set_value(base+i);
const char *key = names[i];
if (key)
item->set_name(key);
item->set_name(key);
}
}
@ -113,11 +116,16 @@ void DFHack::describeBitfield(RepeatedPtrField<EnumItemName> *pf,
{
for (int i = 0; i < size; i++)
{
const char *key = items[i].name;
if (!key && items[i].size <= 1)
continue;
auto item = pf->Add();
item->set_value(i);
const char *key = items[i].name;
if (key)
item->set_name(key);
if (items[i].size > 1)
{
item->set_bit_size(items[i].size);
@ -229,6 +237,16 @@ void DFHack::describeName(NameInfo *info, df::language_name *name)
info->set_english_name(lname);
}
void DFHack::describeNameTriple(NameTriple *info, const std::string &name,
const std::string &plural, const std::string &adj)
{
info->set_normal(name);
if (!plural.empty() && plural != name)
info->set_plural(plural);
if (!adj.empty() && adj != name)
info->set_adjective(adj);
}
void DFHack::describeUnit(BasicUnitInfo *info, df::unit *unit,
const BasicUnitInfoMask *mask)
{
@ -255,6 +273,18 @@ void DFHack::describeUnit(BasicUnitInfo *info, df::unit *unit,
info->set_civ_id(unit->civ_id);
if (unit->hist_figure_id >= 0)
info->set_histfig_id(unit->hist_figure_id);
if (unit->counters.death_id >= 0)
{
info->set_death_id(unit->counters.death_id);
if (auto death = df::death_info::find(unit->counters.death_id))
info->set_death_flags(death->flags.whole);
}
if (unit->military.squad_index >= 0)
{
info->set_squad_id(unit->military.squad_index);
info->set_squad_position(unit->military.squad_position);
}
if (mask && mask->labors())
{
@ -276,6 +306,27 @@ void DFHack::describeUnit(BasicUnitInfo *info, df::unit *unit,
item->set_experience(skill->experience);
}
}
if (unit->curse.add_tags1.whole ||
unit->curse.add_tags2.whole ||
unit->curse.rem_tags1.whole ||
unit->curse.rem_tags2.whole ||
unit->curse.name_visible)
{
auto curse = info->mutable_curse();
curse->set_add_tags1(unit->curse.add_tags1.whole);
curse->set_rem_tags1(unit->curse.rem_tags1.whole);
curse->set_add_tags2(unit->curse.add_tags2.whole);
curse->set_rem_tags2(unit->curse.rem_tags2.whole);
if (unit->curse.name_visible)
describeNameTriple(curse->mutable_name(), unit->curse.name,
unit->curse.name_plural, unit->curse.name_adjective);
}
for (size_t i = 0; i < unit->burrows.size(); i++)
info->add_burrows(unit->burrows[i]);
}
static command_result GetVersion(color_ostream &stream,
@ -373,6 +424,11 @@ static command_result ListEnums(color_ostream &stream,
ENUM(unit_labor);
ENUM(job_skill);
BITFIELD(cie_add_tag_mask1);
BITFIELD(cie_add_tag_mask2);
describe_bitfield<df::death_info::T_flags>(out->mutable_death_info_flags());
#undef ENUM
#undef BITFIELD
}

@ -116,6 +116,11 @@ namespace DFHack
DFHACK_EXPORT void describeName(NameInfo *info, df::language_name *name);
using dfproto::NameTriple;
DFHACK_EXPORT void describeNameTriple(NameTriple *info, const std::string &name,
const std::string &plural, const std::string &adj);
using dfproto::BasicUnitInfo;
using dfproto::BasicUnitInfoMask;

@ -79,6 +79,21 @@ message NameInfo {
optional string english_name = 5;
};
message NameTriple {
required string normal = 1;
optional string plural = 2;
optional string adjective = 3;
};
message UnitCurseInfo {
required fixed32 add_tags1 = 1;
required fixed32 rem_tags1 = 2;
required fixed32 add_tags2 = 3;
required fixed32 rem_tags2 = 4;
optional NameTriple name = 5;
};
message SkillInfo {
required int32 id = 1;
required int32 level = 2;
@ -88,6 +103,10 @@ message SkillInfo {
message BasicUnitInfo {
required int32 unit_id = 1;
required int32 pos_x = 13;
required int32 pos_y = 14;
required int32 pos_z = 15;
optional NameInfo name = 2;
required fixed32 flags1 = 3;
@ -101,15 +120,21 @@ message BasicUnitInfo {
optional int32 civ_id = 9 [default = -1];
optional int32 histfig_id = 10 [default = -1];
optional int32 death_id = 17 [default = -1];
optional uint32 death_flags = 18;
optional int32 squad_id = 19 [default = -1];
optional int32 squad_position = 20 [default = -1];
// IF mask.labors:
repeated int32 labors = 11;
// IF mask.skills:
repeated SkillInfo skills = 12;
required int32 pos_x = 13;
required int32 pos_y = 14;
required int32 pos_z = 15;
optional UnitCurseInfo curse = 16;
repeated int32 burrows = 21;
};
message BasicUnitInfoMask {

@ -37,6 +37,11 @@ message ListEnumsOut {
repeated EnumItemName unit_labor = 6;
repeated EnumItemName job_skill = 7;
repeated EnumItemName cie_add_tag_mask1 = 8;
repeated EnumItemName cie_add_tag_mask2 = 9;
repeated EnumItemName death_info_flags = 10;
};
message ListMaterialsIn {