Units update need coordination with structure identity

develop
PatrikLundell 2020-04-04 14:00:26 +02:00
parent c8a0ac146c
commit a0e2abe20a
2 changed files with 22 additions and 12 deletions

@ -58,6 +58,7 @@ using namespace std;
#include "df/entity_position_assignment.h" #include "df/entity_position_assignment.h"
#include "df/entity_raw.h" #include "df/entity_raw.h"
#include "df/entity_raw_flags.h" #include "df/entity_raw_flags.h"
#include "df/identity_type.h"
#include "df/game_mode.h" #include "df/game_mode.h"
#include "df/histfig_entity_link_positionst.h" #include "df/histfig_entity_link_positionst.h"
#include "df/historical_entity.h" #include "df/historical_entity.h"
@ -200,13 +201,23 @@ void Units::setNickname(df::unit *unit, std::string nick)
if (auto identity = getFigureIdentity(figure)) if (auto identity = getFigureIdentity(figure))
{ {
auto id_hfig = df::historical_figure::find(identity->histfig_id); df::historical_figure *id_hfig = NULL;
switch (identity->type) {
case df::identity_type::Hiding_Curse:
case df::identity_type::Identity:
case df::identity_type::False_Identity:
break; // We want the nickname to end up in the identity
case df::identity_type::Unk_1: // Guess, but that's how it worked in the past
case df::identity_type::Demon_Alias:
case df::identity_type::Unk_4: // Pure guess, as this is a new case, still unseen
id_hfig = df::historical_figure::find(identity->histfig_nemesis_id);
break;
}
if (id_hfig) if (id_hfig)
{ {
// Even DF doesn't do this bit, because it's apparently
// only used for demons masquerading as gods, so you
// can't ever change their nickname in-game.
Translation::setNickname(&id_hfig->name, nick); Translation::setNickname(&id_hfig->name, nick);
} }
else else
@ -247,7 +258,7 @@ bool Units::isHidingCurse(df::unit *unit)
if (!unit->job.hunt_target) if (!unit->job.hunt_target)
{ {
auto identity = Units::getIdentity(unit); auto identity = Units::getIdentity(unit);
if (identity && identity->unk_4c == 0) if (identity && identity->type == df::identity_type::Hiding_Curse)
return true; return true;
} }
@ -722,14 +733,13 @@ double Units::getAge(df::unit *unit, bool true_age)
double birth_time = unit->birth_year + unit->birth_time/year_ticks; double birth_time = unit->birth_year + unit->birth_time/year_ticks;
double cur_time = *cur_year + *cur_year_tick / year_ticks; double cur_time = *cur_year + *cur_year_tick / year_ticks;
if (!true_age && unit->curse_year >= 0) if (!true_age) {
{ if (auto identity = getIdentity(unit)) {
if (auto identity = getIdentity(unit)) if (identity->birth_year != -1) {
{
if (identity->histfig_id < 0)
birth_time = identity->birth_year + identity->birth_second / year_ticks; birth_time = identity->birth_year + identity->birth_second / year_ticks;
} }
} }
}
return cur_time - birth_time; return cur_time - birth_time;
} }

@ -1701,7 +1701,7 @@ static command_result GetUnitListInside(color_ostream &stream, const BlockReques
{ {
if (auto identity = Units::getIdentity(unit)) if (auto identity = Units::getIdentity(unit))
{ {
if (identity->histfig_id < 0) if (identity->histfig_nemesis_id < 0)
birth_time = identity->birth_year * year_ticks + identity->birth_second; birth_time = identity->birth_year * year_ticks + identity->birth_second;
} }
} }