From a0e2abe20a1906f5449be6d931e7b53f1b4f7e21 Mon Sep 17 00:00:00 2001 From: PatrikLundell Date: Sat, 4 Apr 2020 14:00:26 +0200 Subject: [PATCH 1/5] Units update need coordination with structure identity --- library/modules/Units.cpp | 32 ++++++++++++------- .../remotefortressreader.cpp | 2 +- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index 3ac235203..07c3a7acf 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -58,6 +58,7 @@ using namespace std; #include "df/entity_position_assignment.h" #include "df/entity_raw.h" #include "df/entity_raw_flags.h" +#include "df/identity_type.h" #include "df/game_mode.h" #include "df/histfig_entity_link_positionst.h" #include "df/historical_entity.h" @@ -200,13 +201,23 @@ void Units::setNickname(df::unit *unit, std::string nick) 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) { - // 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); } else @@ -247,7 +258,7 @@ bool Units::isHidingCurse(df::unit *unit) if (!unit->job.hunt_target) { auto identity = Units::getIdentity(unit); - if (identity && identity->unk_4c == 0) + if (identity && identity->type == df::identity_type::Hiding_Curse) 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 cur_time = *cur_year + *cur_year_tick / year_ticks; - if (!true_age && unit->curse_year >= 0) - { - if (auto identity = getIdentity(unit)) - { - if (identity->histfig_id < 0) - birth_time = identity->birth_year + identity->birth_second/year_ticks; + if (!true_age) { + if (auto identity = getIdentity(unit)) { + if (identity->birth_year != -1) { + birth_time = identity->birth_year + identity->birth_second / year_ticks; + } } } diff --git a/plugins/remotefortressreader/remotefortressreader.cpp b/plugins/remotefortressreader/remotefortressreader.cpp index f63ae5b2c..6ab401027 100644 --- a/plugins/remotefortressreader/remotefortressreader.cpp +++ b/plugins/remotefortressreader/remotefortressreader.cpp @@ -1701,7 +1701,7 @@ static command_result GetUnitListInside(color_ostream &stream, const BlockReques { 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; } } From 55988e3fc4042af34408f362772c09d9a88b21f9 Mon Sep 17 00:00:00 2001 From: PatrikLundell Date: Wed, 8 Apr 2020 08:45:40 +0200 Subject: [PATCH 2/5] adapted to updated structures, remote Using units for age --- library/modules/Units.cpp | 2 +- .../remotefortressreader/remotefortressreader.cpp | 15 +-------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index 07c3a7acf..fa7007574 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -210,7 +210,7 @@ void Units::setNickname(df::unit *unit, std::string nick) 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::True_Name: 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; diff --git a/plugins/remotefortressreader/remotefortressreader.cpp b/plugins/remotefortressreader/remotefortressreader.cpp index 6ab401027..686c32211 100644 --- a/plugins/remotefortressreader/remotefortressreader.cpp +++ b/plugins/remotefortressreader/remotefortressreader.cpp @@ -1693,20 +1693,7 @@ static command_result GetUnitListInside(color_ostream &stream, const BlockReques using df::global::cur_year; using df::global::cur_year_tick; - int year_ticks = 403200; - 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_nemesis_id < 0) - birth_time = identity->birth_year * year_ticks + identity->birth_second; - } - } - - send_unit->set_age(cur_time - birth_time); + send_unit->set_age(Units::getAge(unit, false)); ConvertDfColor(Units::getProfessionColor(unit), send_unit->mutable_profession_color()); send_unit->set_flags1(unit->flags1.whole); From f4f2aa0d5ef0814adce64af3f8339207e9c97aef Mon Sep 17 00:00:00 2001 From: PatrikLundell Date: Wed, 15 Apr 2020 10:18:37 +0200 Subject: [PATCH 3/5] removed underscores, adapted to structure (re)naming --- library/modules/Items.cpp | 2 +- library/modules/Job.cpp | 4 ++-- library/modules/Units.cpp | 8 ++++---- plugins/orders.cpp | 6 +++--- plugins/stocks.cpp | 10 +++++----- plugins/workflow.cpp | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index 4939aa9dd..4b6010718 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -658,7 +658,7 @@ df::coord Items::getPosition(df::item *item) switch (ref->type) { case specific_ref_type::VERMIN_ESCAPED_PET: - return ref->data.VERMIN_ESCAPED_PET->pos; + return ref->data.vermin->pos; default: break; diff --git a/library/modules/Job.cpp b/library/modules/Job.cpp index d0487941f..0aa01af95 100644 --- a/library/modules/Job.cpp +++ b/library/modules/Job.cpp @@ -311,7 +311,7 @@ void DFHack::Job::disconnectJobItem(df::job *job, df::job_item_ref *ref) { auto ref = item->specific_refs[refIndex]; if (ref->type == df::specific_ref_type::JOB) { - if (ref->data.JOB == job) { + if (ref->data.job == job) { vector_erase_at(item->specific_refs, refIndex); delete ref; } else { @@ -579,7 +579,7 @@ bool DFHack::Job::attachJobItem(df::job *job, df::item *item, auto item_link = new df::specific_ref(); item_link->type = specific_ref_type::JOB; - item_link->data.JOB = job; + item_link->data.job = job; item->specific_refs.push_back(item_link); auto job_link = new df::job_item_ref(); diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index fa7007574..313d6ee9f 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -204,13 +204,13 @@ void Units::setNickname(df::unit *unit, std::string nick) df::historical_figure *id_hfig = NULL; switch (identity->type) { - case df::identity_type::Hiding_Curse: + case df::identity_type::HidingCurse: case df::identity_type::Identity: - case df::identity_type::False_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::True_Name: + 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_nemesis_id); break; @@ -258,7 +258,7 @@ bool Units::isHidingCurse(df::unit *unit) if (!unit->job.hunt_target) { auto identity = Units::getIdentity(unit); - if (identity && identity->type == df::identity_type::Hiding_Curse) + if (identity && identity->type == df::identity_type::HidingCurse) return true; } diff --git a/plugins/orders.cpp b/plugins/orders.cpp index f600b0cd0..045c07a1f 100644 --- a/plugins/orders.cpp +++ b/plugins/orders.cpp @@ -798,13 +798,13 @@ static command_result orders_clear_command(color_ostream & out) { delete condition; } - if (order->anon_1) + if (order->items) { - for (auto anon_1 : *order->anon_1) + for (auto anon_1 : *order->items) { delete anon_1; } - delete order->anon_1; + delete order->items; } delete order; diff --git a/plugins/stocks.cpp b/plugins/stocks.cpp index d9ec97c0d..af49dcb2a 100644 --- a/plugins/stocks.cpp +++ b/plugins/stocks.cpp @@ -179,8 +179,8 @@ static map items_in_cages; static df::job *get_item_job(df::item *item) { auto ref = Items::getSpecificRef(item, specific_ref_type::JOB); - if (ref && ref->data.JOB) - return ref->data.JOB; + if (ref && ref->data.job) + return ref->data.job; return nullptr; } @@ -1008,12 +1008,12 @@ private: if (item->flags.bits.in_job) { auto ref = Items::getSpecificRef(item, specific_ref_type::JOB); - if (ref && ref->data.JOB) + if (ref && ref->data.job) { - if (ref->data.JOB->job_type == job_type::Eat || ref->data.JOB->job_type == job_type::Drink) + if (ref->data.job->job_type == job_type::Eat || ref->data.job->job_type == job_type::Drink) return pos; - auto unit = Job::getWorker(ref->data.JOB); + auto unit = Job::getWorker(ref->data.job); if (unit) return unit->pos; } diff --git a/plugins/workflow.cpp b/plugins/workflow.cpp index 3e31d14ab..600a8bef1 100644 --- a/plugins/workflow.cpp +++ b/plugins/workflow.cpp @@ -1151,10 +1151,10 @@ static bool itemInRealJob(df::item *item) return false; auto ref = Items::getSpecificRef(item, specific_ref_type::JOB); - if (!ref || !ref->data.JOB) + if (!ref || !ref->data.job) return true; - return ENUM_ATTR(job_type, type, ref->data.JOB->job_type) + return ENUM_ATTR(job_type, type, ref->data.job->job_type) != job_type_class::Hauling; } From f371ae6da86e3bf770b2a2412f10e12eccf99c63 Mon Sep 17 00:00:00 2001 From: PatrikLundell Date: Wed, 22 Apr 2020 12:38:37 +0200 Subject: [PATCH 4/5] adapted to histfig_nemesis_id->union --- library/modules/Units.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index 313d6ee9f..dc76c6802 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -212,7 +212,7 @@ void Units::setNickname(df::unit *unit, std::string nick) 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_nemesis_id); + id_hfig = df::historical_figure::find(identity->figure.historical); break; } From 21be5cf061c65ef9d0ec7e9e8c1ab99adc97fa77 Mon Sep 17 00:00:00 2001 From: PatrikLundell Date: Wed, 22 Apr 2020 15:32:49 +0200 Subject: [PATCH 5/5] adapted to structures --- library/modules/Units.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index dc76c6802..c4b9e60fa 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -212,7 +212,7 @@ void Units::setNickname(df::unit *unit, std::string nick) 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->figure.historical); + id_hfig = df::historical_figure::find(identity->histfig_id); break; }