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 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. 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 diff --git a/plugins/spectate.cpp b/plugins/spectate.cpp index 54bd4944a0..ae287f6000 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; @@ -436,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) { @@ -452,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 (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); } else { @@ -510,9 +516,10 @@ 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); + 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()); @@ -523,6 +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, NICKNAMED_CITIZEN_PREFERRED_WEIGHT); add_bucket(job_units, units, intervals, weights, JOB_WEIGHT); add_bucket(other_units, units, intervals, weights, OTHER_WEIGHT); @@ -538,6 +546,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 +584,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");