Skip to content

Commit 56f9a23

Browse files
committed
tailor: logging tweaks, configuration
1 parent 0f389d1 commit 56f9a23

1 file changed

Lines changed: 40 additions & 25 deletions

File tree

plugins/tailor.cpp

Lines changed: 40 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,16 @@ 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+
INFO(cycle).print("tailor: ordered %d %s\n", c, DF2CONSOLE(descr).c_str());
577+
return n;
574578
}
575579

576-
void order_dye_cloth(int c = 1)
580+
oqt order_dye_cloth(int c = 1)
577581
{
578-
get_or_create_order(c, df::job_type::DyeCloth, -1, -1, 0);
582+
auto [_, n] = get_or_create_order(c, df::job_type::DyeCloth, -1, -1, 0);
583+
return n;
579584
}
580585

581586
void make_dyes(int count)
@@ -590,7 +595,7 @@ class Tailor {
590595

591596
if (max > 0)
592597
{
593-
order_dye_from_reaction(r, max);
598+
max = order_dye_from_reaction(r, max);
594599
}
595600

596601
count = std::max(0, count - max);
@@ -613,9 +618,7 @@ class Tailor {
613618
return sum;
614619
}
615620

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 = "")
621+
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 = "")
619622
{
620623
auto f = [&] (df::manager_order* order) {
621624
return order->job_type == ty &&
@@ -634,12 +637,15 @@ class Tailor {
634637
if (orderIt != world->manager_orders.all.end())
635638
{
636639
auto o = *orderIt;
640+
int chg = 0;
637641
if (o->amount_left > 0)
638642
{
643+
int prev = o->amount_left;
639644
o->amount_left = std::max(c, o->amount_left);
640645
o->amount_total = std::max(c, o->amount_total);
646+
chg = o->amount_left - prev;
641647
}
642-
return o;
648+
return {o, chg};
643649
}
644650

645651
auto order = new df::manager_order;
@@ -659,7 +665,7 @@ class Tailor {
659665

660666
world->manager_orders.all.push_back(order);
661667

662-
return order;
668+
return {order, c};
663669
}
664670

665671
int place_orders()
@@ -755,18 +761,21 @@ class Tailor {
755761
}
756762
supply[m] -= c;
757763

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-
);
764+
auto [order,n] = get_or_create_order(c, ty, sub, sizes[size], m.job_material);
767765

768-
count -= c;
769-
ordered += c;
766+
if (n > 0)
767+
{
768+
INFO(cycle).print("tailor: added order #%d for %d %s %s, sized for %s\n",
769+
order->id,
770+
n,
771+
bitfield_to_string(order->material_category).c_str(),
772+
DF2CONSOLE((c > 1) ? name_p : name_s).c_str(),
773+
DF2CONSOLE(world->raws.creatures.all[order->specdata.hist_figure_id]->name[1]).c_str()
774+
);
775+
776+
count -= n;
777+
ordered += n;
778+
}
770779
}
771780
else
772781
{
@@ -794,8 +803,9 @@ class Tailor {
794803
DEBUG(cycle).print("tailor: to dye = %d\n", to_dye);
795804
if (to_dye > 0)
796805
{
797-
INFO(cycle).print("tailor: dyeing %d cloth\n", to_dye);
798-
order_dye_cloth(to_dye);
806+
int dyed = order_dye_cloth(to_dye);
807+
if (dyed > 0)
808+
INFO(cycle).print("tailor: dyeing %d cloth\n", to_dye);
799809
}
800810

801811
int dyes_to_make = available_dyes - to_dye;
@@ -883,7 +893,12 @@ DFhackCExport command_result plugin_load_site_data (color_ostream &out) {
883893
config = World::AddPersistentSiteData(CONFIG_KEY);
884894
config.set_bool(CONFIG_IS_ENABLED, is_enabled);
885895
config.set_bool(CONFIG_CONFISCATE, true);
886-
config.set_bool(CONFIG_AUTOMATE_DYE, false);
896+
}
897+
if (!config2.isValid())
898+
{
899+
DEBUG(control, out).print("no extended config found in this save; initializing\n");
900+
config2 = World::AddPersistentSiteData(CONFIG_KEY_2);
901+
config2.set_bool(CONFIG_AUTOMATE_DYE, false);
887902
}
888903
// transition existing saves to CONFIG_CONFISCATE=true
889904
if (config.get_int(CONFIG_CONFISCATE) < 0) {

0 commit comments

Comments
 (0)