Skip to content

Commit 0e8e858

Browse files
authored
Merge pull request #5564 from ab9rf/tailor-dye-3
tailor: logging tweaks, configuration
2 parents 0f389d1 + 2aa6ab0 commit 0e8e858

1 file changed

Lines changed: 44 additions & 25 deletions

File tree

plugins/tailor.cpp

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ class Tailor {
546546
return count;
547547
}
548548

549+
using oqt = decltype(df::manager_order::amount_total);
550+
549551
using color_type = decltype(MaterialInfo::material->powder_dye);
550552

551553
static auto product_is_dye (df::reaction_product* r) -> bool
@@ -559,7 +561,7 @@ class Tailor {
559561
return false;
560562
};
561563

562-
void order_dye_from_reaction(df::reaction* r, int c = 1)
564+
oqt order_dye_from_reaction(df::reaction* r, int c = 1)
563565
{
564566
std::string descr;
565567
auto dye = std::ranges::find_if(r->products, product_is_dye);
@@ -569,13 +571,18 @@ class Tailor {
569571

570572
pp->getDescription(&descr);
571573

572-
get_or_create_order(c, df::job_type::CustomReaction, -1, -1, 0, r->code);
573-
INFO(cycle).print("tailor: ordered %d %s\n", c, DF2CONSOLE(descr).c_str());
574+
auto [_, n] = get_or_create_order(c, df::job_type::CustomReaction, -1, -1, 0, r->code);
575+
if (n > 0)
576+
{
577+
INFO(cycle).print("tailor: ordered %d %s\n", c, DF2CONSOLE(descr).c_str());
578+
}
579+
return n;
574580
}
575581

576-
void order_dye_cloth(int c = 1)
582+
oqt order_dye_cloth(int c = 1)
577583
{
578-
get_or_create_order(c, df::job_type::DyeCloth, -1, -1, 0);
584+
auto [_, n] = get_or_create_order(c, df::job_type::DyeCloth, -1, -1, 0);
585+
return n;
579586
}
580587

581588
void make_dyes(int count)
@@ -590,7 +597,7 @@ class Tailor {
590597

591598
if (max > 0)
592599
{
593-
order_dye_from_reaction(r, max);
600+
max = order_dye_from_reaction(r, max);
594601
}
595602

596603
count = std::max(0, count - max);
@@ -613,9 +620,7 @@ class Tailor {
613620
return sum;
614621
}
615622

616-
using oqt = decltype(df::manager_order::amount_total);
617-
618-
static df::manager_order* get_or_create_order(oqt c, df::job_type ty, int16_t sub, int32_t hfid, df::job_material_category mcat, std::string custom_reaction = "")
623+
static std::pair<df::manager_order*,oqt> get_or_create_order(oqt c, df::job_type ty, int16_t sub, int32_t hfid, df::job_material_category mcat, std::string custom_reaction = "")
619624
{
620625
auto f = [&] (df::manager_order* order) {
621626
return order->job_type == ty &&
@@ -634,12 +639,15 @@ class Tailor {
634639
if (orderIt != world->manager_orders.all.end())
635640
{
636641
auto o = *orderIt;
642+
int chg = 0;
637643
if (o->amount_left > 0)
638644
{
645+
int prev = o->amount_left;
639646
o->amount_left = std::max(c, o->amount_left);
640647
o->amount_total = std::max(c, o->amount_total);
648+
chg = o->amount_left - prev;
641649
}
642-
return o;
650+
return {o, chg};
643651
}
644652

645653
auto order = new df::manager_order;
@@ -659,7 +667,7 @@ class Tailor {
659667

660668
world->manager_orders.all.push_back(order);
661669

662-
return order;
670+
return {order, c};
663671
}
664672

665673
int place_orders()
@@ -755,18 +763,21 @@ class Tailor {
755763
}
756764
supply[m] -= c;
757765

758-
auto order = get_or_create_order(c, ty, sub, sizes[size], m.job_material);
759-
760-
INFO(cycle).print("tailor: added order #%d for %d %s %s, sized for %s\n",
761-
order->id,
762-
c,
763-
bitfield_to_string(order->material_category).c_str(),
764-
DF2CONSOLE((c > 1) ? name_p : name_s).c_str(),
765-
DF2CONSOLE(world->raws.creatures.all[order->specdata.hist_figure_id]->name[1]).c_str()
766-
);
766+
auto [order,n] = get_or_create_order(c, ty, sub, sizes[size], m.job_material);
767767

768-
count -= c;
769-
ordered += c;
768+
if (n > 0)
769+
{
770+
INFO(cycle).print("tailor: added order #%d for %d %s %s, sized for %s\n",
771+
order->id,
772+
n,
773+
bitfield_to_string(order->material_category).c_str(),
774+
DF2CONSOLE((c > 1) ? name_p : name_s).c_str(),
775+
DF2CONSOLE(world->raws.creatures.all[order->specdata.hist_figure_id]->name[1]).c_str()
776+
);
777+
778+
count -= n;
779+
ordered += n;
780+
}
770781
}
771782
else
772783
{
@@ -794,8 +805,11 @@ class Tailor {
794805
DEBUG(cycle).print("tailor: to dye = %d\n", to_dye);
795806
if (to_dye > 0)
796807
{
797-
INFO(cycle).print("tailor: dyeing %d cloth\n", to_dye);
798-
order_dye_cloth(to_dye);
808+
int dyed = order_dye_cloth(to_dye);
809+
if (dyed > 0)
810+
{
811+
INFO(cycle).print("tailor: dyeing %d cloth\n", to_dye);
812+
}
799813
}
800814

801815
int dyes_to_make = available_dyes - to_dye;
@@ -883,7 +897,12 @@ DFhackCExport command_result plugin_load_site_data (color_ostream &out) {
883897
config = World::AddPersistentSiteData(CONFIG_KEY);
884898
config.set_bool(CONFIG_IS_ENABLED, is_enabled);
885899
config.set_bool(CONFIG_CONFISCATE, true);
886-
config.set_bool(CONFIG_AUTOMATE_DYE, false);
900+
}
901+
if (!config2.isValid())
902+
{
903+
DEBUG(control, out).print("no extended config found in this save; initializing\n");
904+
config2 = World::AddPersistentSiteData(CONFIG_KEY_2);
905+
config2.set_bool(CONFIG_AUTOMATE_DYE, false);
887906
}
888907
// transition existing saves to CONFIG_CONFISCATE=true
889908
if (config.get_int(CONFIG_CONFISCATE) < 0) {

0 commit comments

Comments
 (0)