Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Template for new versions:

## Misc Improvements
- `spectate`: show dwarves' activities (like prayer)
- `spectate`: added prefer nicknamed units

## Documentation

Expand Down
3 changes: 3 additions & 0 deletions docs/plugins/spectate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions plugins/lua/spectate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions plugins/spectate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -82,6 +84,7 @@ static struct Configuration {
include_wildlife = false;
prefer_conflict = true;
prefer_new_arrivals = true;
prefer_nicknamed = true;
follow_ms = 10000;
}
} config;
Expand Down Expand Up @@ -436,6 +439,7 @@ static bool is_in_combat(df::unit *unit) {
static void get_dwarf_buckets(color_ostream &out,
vector<df::unit*> &citizen_combat_units,
vector<df::unit*> &other_combat_units,
vector<df::unit*> &nicknamed_units,
vector<df::unit*> &job_units,
vector<df::unit*> &other_units)
{
Expand All @@ -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 {
Expand Down Expand Up @@ -510,9 +516,10 @@ static void follow_a_dwarf(color_ostream &out) {

vector<df::unit*> citizen_combat_units;
vector<df::unit*> other_combat_units;
vector<df::unit*> nicknamed_units;
vector<df::unit*> job_units;
vector<df::unit*> 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());

Expand All @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
Loading