From e9438065d6db242387aa62670484b30e9e8036ba Mon Sep 17 00:00:00 2001 From: Squid Coder Date: Mon, 7 Apr 2025 10:30:59 -0500 Subject: [PATCH 1/8] Add prefer nicknamed --- plugins/spectate.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/spectate.cpp b/plugins/spectate.cpp index 54bd4944a0..7c7e0f3e57 100644 --- a/plugins/spectate.cpp +++ b/plugins/spectate.cpp @@ -43,6 +43,7 @@ static uint32_t next_cycle_unpaused_ms = 0; // threshold for the next cycle static const size_t MAX_HISTORY = 200; static const float CITIZEN_COMBAT_PREFERRED_WEIGHT = 25.0f; +static const float NICKNAMED_CITIZEN_PREFERRED_WEIGHT = 15.0f; static const float OTHER_COMBAT_PREFERRED_WEIGHT = 10.0f; static const float JOB_WEIGHT = 5.0f; static const float OTHER_WEIGHT = 1.0f; @@ -71,6 +72,7 @@ static struct Configuration { bool include_wildlife; bool prefer_conflict; bool prefer_new_arrivals; + bool prefer_nicknamed; int32_t follow_ms; void reset() { @@ -82,6 +84,7 @@ static struct Configuration { include_wildlife = false; prefer_conflict = true; prefer_new_arrivals = true; + prefer_nicknamed = true; follow_ms = 10000; } } config; @@ -510,6 +513,7 @@ static void follow_a_dwarf(color_ostream &out) { vector citizen_combat_units; vector other_combat_units; + vector nicknamed_units; vector job_units; vector other_units; get_dwarf_buckets(out, citizen_combat_units, other_combat_units, job_units, other_units); @@ -523,6 +527,7 @@ static void follow_a_dwarf(color_ostream &out) { intervals.push_back(0); add_bucket(citizen_combat_units, units, intervals, weights, config.prefer_conflict ? CITIZEN_COMBAT_PREFERRED_WEIGHT : JOB_WEIGHT); add_bucket(other_combat_units, units, intervals, weights, config.prefer_conflict ? OTHER_COMBAT_PREFERRED_WEIGHT : JOB_WEIGHT); + add_bucket(nicknamed_units, units, intervals, weights, config.prefer_nicknamed ? NICKNAMED_CITIZEN_PREFERRED_WEIGHT : JOB_WEIGHT); add_bucket(job_units, units, intervals, weights, JOB_WEIGHT); add_bucket(other_units, units, intervals, weights, OTHER_WEIGHT); @@ -538,6 +543,7 @@ static void follow_a_dwarf(color_ostream &out) { if (debug_cycle.isEnabled(DebugCategory::LDEBUG)) { DUMP_BUCKET(citizen_combat_units); DUMP_BUCKET(other_combat_units); + DUMP_BUCKET(nicknamed_units); DUMP_BUCKET(job_units); DUMP_BUCKET(other_units); DUMP_FLOAT_VECTOR(intervals); @@ -575,6 +581,8 @@ static void spectate_setSetting(color_ostream &out, string name, int val) { config.prefer_conflict = val; } else if (name == "prefer-new-arrivals") { config.prefer_new_arrivals = val; + } else if (name == "prefer-nicknamed") { + config.prefer_nicknamed = val; } else if (name == "follow-seconds") { if (val <= 0) { WARN(control,out).print("follow-seconds must be a positive integer\n"); From 6edf48f673e2ba2b572aa0512b80938ece59e9d8 Mon Sep 17 00:00:00 2001 From: Squid Coder Date: Tue, 8 Apr 2025 11:44:17 -0500 Subject: [PATCH 2/8] Actually add to the nicknamed bucket --- plugins/spectate.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/spectate.cpp b/plugins/spectate.cpp index 7c7e0f3e57..4ae21b7d44 100644 --- a/plugins/spectate.cpp +++ b/plugins/spectate.cpp @@ -439,6 +439,7 @@ static bool is_in_combat(df::unit *unit) { static void get_dwarf_buckets(color_ostream &out, vector &citizen_combat_units, vector &other_combat_units, + vector &nicknamed_units, vector &job_units, vector &other_units) { @@ -455,11 +456,13 @@ static void get_dwarf_buckets(color_ostream &out, continue; if (is_in_combat(unit)) { - TRACE(cycle,out).print("unit %d is in combat: %s\n", unit->id, DF2CONSOLE(Units::getReadableName(unit)).c_str()); + TRACE(cycle, out).print("unit %d is in combat: %s\n", unit->id, DF2CONSOLE(Units::getReadableName(unit)).c_str()); if (Units::isCitizen(unit, true) || Units::isResident(unit, true)) citizen_combat_units.push_back(unit); else other_combat_units.push_back(unit); + } else if (!unit->name.nickname.empty()) { + nicknamed_units.push_back(unit); } else if (unit->job.current_job && !boring_jobs.contains(unit->job.current_job->job_type)) { job_units.push_back(unit); } else { @@ -516,7 +519,7 @@ static void follow_a_dwarf(color_ostream &out) { vector nicknamed_units; vector job_units; vector other_units; - get_dwarf_buckets(out, citizen_combat_units, other_combat_units, job_units, other_units); + get_dwarf_buckets(out, citizen_combat_units, other_combat_units, nicknamed_units, job_units, other_units); set_next_cycle_unpaused_ms(out, !citizen_combat_units.empty()); From 05e952f281485be2a72679e14093b0f8e305dfa0 Mon Sep 17 00:00:00 2001 From: Squid Coder Date: Tue, 8 Apr 2025 12:14:40 -0500 Subject: [PATCH 3/8] Use other not job weight --- plugins/spectate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/spectate.cpp b/plugins/spectate.cpp index 4ae21b7d44..1e3042c360 100644 --- a/plugins/spectate.cpp +++ b/plugins/spectate.cpp @@ -530,7 +530,7 @@ static void follow_a_dwarf(color_ostream &out) { intervals.push_back(0); add_bucket(citizen_combat_units, units, intervals, weights, config.prefer_conflict ? CITIZEN_COMBAT_PREFERRED_WEIGHT : JOB_WEIGHT); add_bucket(other_combat_units, units, intervals, weights, config.prefer_conflict ? OTHER_COMBAT_PREFERRED_WEIGHT : JOB_WEIGHT); - add_bucket(nicknamed_units, units, intervals, weights, config.prefer_nicknamed ? NICKNAMED_CITIZEN_PREFERRED_WEIGHT : JOB_WEIGHT); + add_bucket(nicknamed_units, units, intervals, weights, config.prefer_nicknamed ? NICKNAMED_CITIZEN_PREFERRED_WEIGHT : OTHER_WEIGHT); add_bucket(job_units, units, intervals, weights, JOB_WEIGHT); add_bucket(other_units, units, intervals, weights, OTHER_WEIGHT); From d7a9054281bbbf0c9353cec8585198c114dff101 Mon Sep 17 00:00:00 2001 From: Squid Coder Date: Wed, 9 Apr 2025 12:35:43 -0500 Subject: [PATCH 4/8] Update changelog.txt --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index d65aeace62..3f6fbfb2ab 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -64,6 +64,7 @@ Template for new versions: ## Misc Improvements - `spectate`: show dwarves' activities (like prayer) +- `spectate`: added prefer nicknamed units ## Documentation From 976f9e67b9a5535def880d44d78f9d21cc6d54ce Mon Sep 17 00:00:00 2001 From: Squid Coder Date: Fri, 18 Apr 2025 13:34:02 -0500 Subject: [PATCH 5/8] weight change --- plugins/spectate.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/spectate.cpp b/plugins/spectate.cpp index 1e3042c360..a9df3fa0a0 100644 --- a/plugins/spectate.cpp +++ b/plugins/spectate.cpp @@ -530,7 +530,9 @@ static void follow_a_dwarf(color_ostream &out) { intervals.push_back(0); add_bucket(citizen_combat_units, units, intervals, weights, config.prefer_conflict ? CITIZEN_COMBAT_PREFERRED_WEIGHT : JOB_WEIGHT); add_bucket(other_combat_units, units, intervals, weights, config.prefer_conflict ? OTHER_COMBAT_PREFERRED_WEIGHT : JOB_WEIGHT); - add_bucket(nicknamed_units, units, intervals, weights, config.prefer_nicknamed ? NICKNAMED_CITIZEN_PREFERRED_WEIGHT : OTHER_WEIGHT); + if (config.prefer_nicknamed) { + add_bucket(nicknamed_units, units, intervals, weights, NICKNAMED_CITIZEN_PREFERRED_WEIGHT); + } add_bucket(job_units, units, intervals, weights, JOB_WEIGHT); add_bucket(other_units, units, intervals, weights, OTHER_WEIGHT); From 9f88745f2cfc251c0703e50f92f15b60298352b8 Mon Sep 17 00:00:00 2001 From: Squid Coder Date: Fri, 18 Apr 2025 13:35:54 -0500 Subject: [PATCH 6/8] add prefer nicknamed default --- plugins/lua/spectate.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/lua/spectate.lua b/plugins/lua/spectate.lua index 8c7e653a7b..521f24fbfe 100644 --- a/plugins/lua/spectate.lua +++ b/plugins/lua/spectate.lua @@ -25,6 +25,7 @@ local function get_default_state() ['include-wildlife']=false, ['prefer-conflict']=true, ['prefer-new-arrivals']=true, + ['prefer-nicknamed']=true, ['tooltip-follow']=true, ['tooltip-follow-blink-milliseconds']=3000, ['tooltip-follow-hold-to-show']='none', -- one of none, ctrl, alt, or shift From aba5fcca8fea45fa2ba53f30084d2c05a51cb7db Mon Sep 17 00:00:00 2001 From: Squid Coder Date: Sat, 26 Apr 2025 12:02:28 -0500 Subject: [PATCH 7/8] fix my misunderstanding of the code in my testing turning off the prefer nicknamed used the jobs to categorize them . (i went from 16 nicknamed to 2 job units and 14 other units) so I'm pretty sure this works as i meant it to now --- plugins/spectate.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/spectate.cpp b/plugins/spectate.cpp index a9df3fa0a0..ae287f6000 100644 --- a/plugins/spectate.cpp +++ b/plugins/spectate.cpp @@ -461,7 +461,7 @@ static void get_dwarf_buckets(color_ostream &out, citizen_combat_units.push_back(unit); else other_combat_units.push_back(unit); - } else if (!unit->name.nickname.empty()) { + } else if (config.prefer_nicknamed && !unit->name.nickname.empty()) { nicknamed_units.push_back(unit); } else if (unit->job.current_job && !boring_jobs.contains(unit->job.current_job->job_type)) { job_units.push_back(unit); @@ -530,9 +530,7 @@ static void follow_a_dwarf(color_ostream &out) { intervals.push_back(0); add_bucket(citizen_combat_units, units, intervals, weights, config.prefer_conflict ? CITIZEN_COMBAT_PREFERRED_WEIGHT : JOB_WEIGHT); add_bucket(other_combat_units, units, intervals, weights, config.prefer_conflict ? OTHER_COMBAT_PREFERRED_WEIGHT : JOB_WEIGHT); - if (config.prefer_nicknamed) { - add_bucket(nicknamed_units, units, intervals, weights, NICKNAMED_CITIZEN_PREFERRED_WEIGHT); - } + add_bucket(nicknamed_units, units, intervals, weights, NICKNAMED_CITIZEN_PREFERRED_WEIGHT); add_bucket(job_units, units, intervals, weights, JOB_WEIGHT); add_bucket(other_units, units, intervals, weights, OTHER_WEIGHT); From 993fdb20b7444f390ab6ffe21c6337e4a6a84fc3 Mon Sep 17 00:00:00 2001 From: Squid Coder Date: Sat, 3 May 2025 15:32:18 -0500 Subject: [PATCH 8/8] Update spectate.rst --- docs/plugins/spectate.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/plugins/spectate.rst b/docs/plugins/spectate.rst index 68d1013f64..dd0174f320 100644 --- a/docs/plugins/spectate.rst +++ b/docs/plugins/spectate.rst @@ -105,6 +105,9 @@ Settings Toggle whether to prefer following (non-siege) units that have newly arrived on the map. +``prefer-nicknamed`` (default: enabled) + Toggle whether to prefer following nicknamed units. + ``tooltip-follow`` (default: enabled) If the ``spectate.tooltip`` overlay is enabled, toggle whether to show the tooltips that follow onscreen dwarves around the map.