Merge remote-tracking branch 'PatrikLundell/Units' into develop

develop
lethosor 2020-04-22 22:05:09 -04:00
commit 7fa3f176bd
2 changed files with 22 additions and 25 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::HidingCurse:
case df::identity_type::Identity:
case df::identity_type::FalseIdentity:
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::TrueName:
case df::identity_type::Unk_4: // Pure guess, as this is a new case, still unseen
id_hfig = df::historical_figure::find(identity->histfig_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::HidingCurse)
return true; return true;
} }
@ -722,12 +733,11 @@ 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) {
{ birth_time = identity->birth_year + identity->birth_second / year_ticks;
if (identity->histfig_id < 0) }
birth_time = identity->birth_year + identity->birth_second/year_ticks;
} }
} }

@ -1693,20 +1693,7 @@ static command_result GetUnitListInside(color_ostream &stream, const BlockReques
using df::global::cur_year; using df::global::cur_year;
using df::global::cur_year_tick; using df::global::cur_year_tick;
int year_ticks = 403200; send_unit->set_age(Units::getAge(unit, false));
int birth_time = unit->birth_year * year_ticks + unit->birth_time;
int cur_time = *cur_year * year_ticks + *cur_year_tick;
if (unit->curse_year >= 0)
{
if (auto identity = Units::getIdentity(unit))
{
if (identity->histfig_id < 0)
birth_time = identity->birth_year * year_ticks + identity->birth_second;
}
}
send_unit->set_age(cur_time - birth_time);
ConvertDfColor(Units::getProfessionColor(unit), send_unit->mutable_profession_color()); ConvertDfColor(Units::getProfessionColor(unit), send_unit->mutable_profession_color());
send_unit->set_flags1(unit->flags1.whole); send_unit->set_flags1(unit->flags1.whole);