summaryrefslogtreecommitdiff
path: root/plugins/devel
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-09-01 14:42:19 +0400
committerAlexander Gavrilov2012-09-01 14:42:19 +0400
commit74501d3197d23c657524204b8f99253f7102f6f3 (patch)
tree5af0a4712495ffe73c544f4fd5463e963c2ad23c /plugins/devel
parentf158e1894d15c2d835f8ee8b65ce3b094b71e5f6 (diff)
downloaddfhack-74501d3197d23c657524204b8f99253f7102f6f3.tar.gz
dfhack-74501d3197d23c657524204b8f99253f7102f6f3.tar.bz2
dfhack-74501d3197d23c657524204b8f99253f7102f6f3.tar.xz
Try preventing "boiling water" from freezing, and dump steam on destroy.
Diffstat (limited to 'plugins/devel')
-rw-r--r--plugins/devel/steam-engine.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/plugins/devel/steam-engine.cpp b/plugins/devel/steam-engine.cpp
index 5a26fb24..6f83c41d 100644
--- a/plugins/devel/steam-engine.cpp
+++ b/plugins/devel/steam-engine.cpp
@@ -82,9 +82,27 @@ struct liquid_hook : df::item_liquid_miscst {
INTERPOSE_NEXT(getItemDescription)(buf, mode);
}
+
+ DEFINE_VMETHOD_INTERPOSE(bool, adjustTemperature, (uint16_t temp, int32_t unk))
+ {
+ if (mat_state.whole & BOILING_FLAG)
+ temp = std::max(int(temp), getBoilingPoint()-1);
+
+ return INTERPOSE_NEXT(adjustTemperature)(temp, unk);
+ }
+
+ DEFINE_VMETHOD_INTERPOSE(bool, checkTemperatureDamage, ())
+ {
+ if (mat_state.whole & BOILING_FLAG)
+ temperature = std::max(int(temperature), getBoilingPoint()-1);
+
+ return INTERPOSE_NEXT(checkTemperatureDamage)();
+ }
};
IMPLEMENT_VMETHOD_INTERPOSE(liquid_hook, getItemDescription);
+IMPLEMENT_VMETHOD_INTERPOSE(liquid_hook, adjustTemperature);
+IMPLEMENT_VMETHOD_INTERPOSE(liquid_hook, checkTemperatureDamage);
struct workshop_hook : df::building_workshopst {
typedef df::building_workshopst interpose_base;
@@ -114,6 +132,8 @@ struct workshop_hook : df::building_workshopst {
{
liquid->flags.bits.in_building = true;
liquid->mat_state.whole |= liquid_hook::BOILING_FLAG;
+ liquid->temperature = liquid->getBoilingPoint()-1;
+ liquid->temperature_fraction = 0;
// This affects where the steam appears to come from
if (engine->hearth_tile.isValid())
@@ -176,6 +196,28 @@ struct workshop_hook : df::building_workshopst {
return first;
}
+ void random_boil()
+ {
+ int cnt = 0;
+
+ for (int i = contained_items.size()-1; i >= 0; i--)
+ {
+ auto item = contained_items[i];
+ if (item->use_mode != 0 || !item->item->flags.bits.in_building)
+ continue;
+
+ auto liquid = strict_virtual_cast<df::item_liquid_miscst>(item->item);
+ if (!liquid)
+ continue;
+
+ if (cnt == 0 || random() < RAND_MAX/2)
+ {
+ cnt++;
+ boil_unit(liquid);
+ }
+ }
+ }
+
static const int WEAR_TICKS = 806400;
int get_steam_use_rate(steam_engine_workshop *engine, int dimension, int power_level)
@@ -362,6 +404,14 @@ struct workshop_hook : df::building_workshopst {
}
}
}
+
+ DEFINE_VMETHOD_INTERPOSE(void, deconstructItems, (bool noscatter, bool lost))
+ {
+ if (get_steam_engine())
+ random_boil();
+
+ INTERPOSE_NEXT(deconstructItems)(noscatter, lost);
+ }
};
IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, needsDesign);
@@ -373,6 +423,7 @@ IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, uncategorize);
IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, canConnectToMachine);
IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, updateAction);
IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, drawBuilding);
+IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, deconstructItems);
static bool find_engines()
{
@@ -431,6 +482,8 @@ static bool find_engines()
static void enable_hooks(bool enable)
{
INTERPOSE_HOOK(liquid_hook, getItemDescription).apply(enable);
+ INTERPOSE_HOOK(liquid_hook, adjustTemperature).apply(enable);
+ INTERPOSE_HOOK(liquid_hook, checkTemperatureDamage).apply(enable);
INTERPOSE_HOOK(workshop_hook, needsDesign).apply(enable);
INTERPOSE_HOOK(workshop_hook, getPowerInfo).apply(enable);
@@ -441,6 +494,7 @@ static void enable_hooks(bool enable)
INTERPOSE_HOOK(workshop_hook, canConnectToMachine).apply(enable);
INTERPOSE_HOOK(workshop_hook, updateAction).apply(enable);
INTERPOSE_HOOK(workshop_hook, drawBuilding).apply(enable);
+ INTERPOSE_HOOK(workshop_hook, deconstructItems).apply(enable);
}
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)