MCPcopy Create free account
hub / github.com/DFHack/dfhack / autobutcher_modify_watchlist

Function autobutcher_modify_watchlist

plugins/autobutcher.cpp:552–608  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

550}
551
552static void autobutcher_modify_watchlist(color_ostream &out, const autobutcher_options &opts) {
553 std::unordered_set<int> ids;
554
555 if (opts.races_all) {
556 for (auto w : watched_races)
557 ids.emplace(w.first);
558 }
559
560 for (auto race : opts.races) {
561 if (!race_to_id.count(*race)) {
562 out.printerr("race not found: '{}'", race->c_str());
563 continue;
564 }
565 ids.emplace(race_to_id[*race]);
566 }
567
568 for (int id : ids) {
569 if (opts.command == "watch") {
570 if (!watched_races.count(id)) {
571 watched_races.emplace(id,
572 new WatchedRace(out, id, true,
573 config.get_int(CONFIG_DEFAULT_FK),
574 config.get_int(CONFIG_DEFAULT_MK),
575 config.get_int(CONFIG_DEFAULT_FA),
576 config.get_int(CONFIG_DEFAULT_MA)));
577 }
578 else if (!watched_races[id]->isWatched) {
579 DEBUG(control,out).print("watching: {}\n", opts.command);
580 watched_races[id]->isWatched = true;
581 }
582 }
583 else if (opts.command == "unwatch") {
584 if (!watched_races.count(id)) {
585 watched_races.emplace(id,
586 new WatchedRace(out, id, false,
587 config.get_int(CONFIG_DEFAULT_FK),
588 config.get_int(CONFIG_DEFAULT_MK),
589 config.get_int(CONFIG_DEFAULT_FA),
590 config.get_int(CONFIG_DEFAULT_MA)));
591 }
592 else if (watched_races[id]->isWatched) {
593 DEBUG(control,out).print("unwatching: {}\n", opts.command);
594 watched_races[id]->isWatched = false;
595 }
596 }
597 else if (opts.command == "forget") {
598 if (watched_races.count(id)) {
599 DEBUG(control,out).print("forgetting: {}\n", opts.command);
600 watched_races[id]->RemoveConfig(out);
601 delete watched_races[id];
602 watched_races.erase(id);
603 }
604 continue;
605 }
606 watched_races[id]->UpdateConfig(out);
607 }
608}
609

Callers 1

df_autobutcherFunction · 0.85

Calls 6

c_strMethod · 0.80
RemoveConfigMethod · 0.80
UpdateConfigMethod · 0.80
countMethod · 0.45
printMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected