2012-08-31 14:22:55 -06:00
|
|
|
#include "Core.h"
|
|
|
|
#include <Console.h>
|
|
|
|
#include <Export.h>
|
|
|
|
#include <PluginManager.h>
|
|
|
|
#include <modules/Gui.h>
|
|
|
|
#include <modules/Screen.h>
|
2012-09-01 07:52:51 -06:00
|
|
|
#include <modules/Maps.h>
|
|
|
|
#include <TileTypes.h>
|
2012-08-31 14:22:55 -06:00
|
|
|
#include <vector>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <stack>
|
|
|
|
#include <string>
|
|
|
|
#include <cmath>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <VTableInterpose.h>
|
|
|
|
#include "df/graphic.h"
|
|
|
|
#include "df/building_workshopst.h"
|
|
|
|
#include "df/building_def_workshopst.h"
|
|
|
|
#include "df/item_liquid_miscst.h"
|
|
|
|
#include "df/power_info.h"
|
|
|
|
#include "df/workshop_type.h"
|
|
|
|
#include "df/builtin_mats.h"
|
|
|
|
#include "df/world.h"
|
|
|
|
#include "df/buildings_other_id.h"
|
|
|
|
#include "df/machine.h"
|
2012-09-01 01:29:05 -06:00
|
|
|
#include "df/job.h"
|
|
|
|
#include "df/building_drawbuffer.h"
|
2012-09-01 07:52:51 -06:00
|
|
|
#include "df/ui.h"
|
|
|
|
#include "df/viewscreen_dwarfmodest.h"
|
|
|
|
#include "df/ui_build_selector.h"
|
2012-09-01 10:46:34 -06:00
|
|
|
#include "df/flow_info.h"
|
|
|
|
#include "df/report.h"
|
2012-08-31 14:22:55 -06:00
|
|
|
|
|
|
|
#include "MiscUtils.h"
|
|
|
|
|
2012-09-05 01:23:00 -06:00
|
|
|
/*
|
|
|
|
* This plugin implements a steam engine workshop. It activates
|
|
|
|
* if there are any workshops in the raws with STEAM_ENGINE in
|
|
|
|
* their token, and provides the necessary behavior.
|
|
|
|
*
|
|
|
|
* Construction:
|
|
|
|
*
|
|
|
|
* The workshop needs water as its input, which it takes via a
|
|
|
|
* passable floor tile below it, like usual magma workshops do.
|
|
|
|
* The magma version also needs magma.
|
|
|
|
*
|
|
|
|
* ISSUE: Since this building is a machine, and machine collapse
|
|
|
|
* code cannot be modified, it would collapse over true open space.
|
|
|
|
* As a loophole, down stair provides support to machines, while
|
|
|
|
* being passable, so use them.
|
|
|
|
*
|
|
|
|
* After constructing the building itself, machines can be connected
|
|
|
|
* to the edge tiles that look like gear boxes. Their exact position
|
|
|
|
* is extracted from the workshop raws.
|
|
|
|
*
|
|
|
|
* ISSUE: Like with collapse above, part of the code involved in
|
|
|
|
* machine connection cannot be modified. As a result, the workshop
|
|
|
|
* can only immediately connect to machine components built AFTER it.
|
|
|
|
* This also means that engines cannot be chained without intermediate
|
|
|
|
* short axles that can be built later.
|
|
|
|
*
|
|
|
|
* Operation:
|
|
|
|
*
|
|
|
|
* In order to operate the engine, queue the Stoke Boiler job.
|
|
|
|
* A furnace operator will come, possibly bringing a bar of fuel,
|
|
|
|
* and perform it. As a result, a "boiling water" item will appear
|
|
|
|
* in the 't' view of the workshop.
|
|
|
|
*
|
|
|
|
* Note: The completion of the job will actually consume one unit
|
|
|
|
* of appropriate liquids from below the workshop.
|
|
|
|
*
|
|
|
|
* Every such item gives 100 power, up to a limit of 300 for coal,
|
|
|
|
* and 500 for a magma engine. The building can host twice that
|
|
|
|
* amount of items to provide longer autonomous running. When the
|
|
|
|
* boiler gets filled to capacity, all queued jobs are suspended;
|
|
|
|
* once it drops back to 3+1 or 5+1 items, they are re-enabled.
|
|
|
|
*
|
|
|
|
* While the engine is providing power, steam is being consumed.
|
|
|
|
* The consumption speed includes a fixed 10% waste rate, and
|
|
|
|
* the remaining 90% are applied proportionally to the actual
|
|
|
|
* load in the machine. With the engine at nominal 300 power with
|
|
|
|
* 150 load in the system, it will consume steam for actual
|
|
|
|
* 300*(10% + 90%*150/300) = 165 power.
|
|
|
|
*
|
|
|
|
* Masterpiece mechanism and chain will decrease the mechanical
|
|
|
|
* power drawn by the engine itself from 10 to 5. Masterpiece
|
|
|
|
* barrel decreases waste rate by 4%. Masterpiece piston and pipe
|
|
|
|
* decrease it by further 4%, and also decrease the whole steam
|
|
|
|
* use rate by 10%.
|
|
|
|
*
|
|
|
|
* Explosions:
|
|
|
|
*
|
|
|
|
* The engine must be constructed using barrel, pipe and piston
|
|
|
|
* from fire-safe, or in the magma version magma-safe metals.
|
|
|
|
*
|
|
|
|
* During operation weak parts get gradually worn out, and
|
|
|
|
* eventually the engine explodes. It should also explode if
|
|
|
|
* toppled during operation by a building destroyer, or a
|
|
|
|
* tantruming dwarf.
|
|
|
|
*
|
|
|
|
* Save files:
|
|
|
|
*
|
|
|
|
* It should be safe to load and view fortresses using engines
|
|
|
|
* from a DF version without DFHack installed, except that in such
|
|
|
|
* case the engines won't work. However actually making modifications
|
|
|
|
* to them, or machines they connect to (including by pulling levers),
|
|
|
|
* can easily result in inconsistent state once this plugin is
|
|
|
|
* available again. The effects may be as weird as negative power
|
|
|
|
* being generated.
|
|
|
|
*/
|
|
|
|
|
2012-08-31 14:22:55 -06:00
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using std::stack;
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
|
|
|
|
|
|
|
using df::global::gps;
|
|
|
|
using df::global::world;
|
2012-09-01 07:52:51 -06:00
|
|
|
using df::global::ui;
|
2012-08-31 14:22:55 -06:00
|
|
|
using df::global::ui_build_selector;
|
|
|
|
|
|
|
|
DFHACK_PLUGIN("steam-engine");
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
/*
|
|
|
|
* List of known steam engine workshop raws.
|
|
|
|
*/
|
|
|
|
|
2012-08-31 14:22:55 -06:00
|
|
|
struct steam_engine_workshop {
|
|
|
|
int id;
|
|
|
|
df::building_def_workshopst *def;
|
2012-09-02 04:59:13 -06:00
|
|
|
// Cached properties
|
2012-09-01 01:29:05 -06:00
|
|
|
bool is_magma;
|
|
|
|
int max_power, max_capacity;
|
2012-09-01 10:46:34 -06:00
|
|
|
int wear_temp;
|
2012-09-02 04:59:13 -06:00
|
|
|
// Special tiles (relative position)
|
2012-08-31 14:22:55 -06:00
|
|
|
std::vector<df::coord2d> gear_tiles;
|
|
|
|
df::coord2d hearth_tile;
|
|
|
|
df::coord2d water_tile;
|
|
|
|
df::coord2d magma_tile;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<steam_engine_workshop> engines;
|
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
steam_engine_workshop *find_steam_engine(int id)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < engines.size(); i++)
|
|
|
|
if (engines[i].id == id)
|
|
|
|
return &engines[i];
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
/*
|
|
|
|
* Misc utilities.
|
|
|
|
*/
|
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
static const int hearth_colors[6][2] = {
|
|
|
|
{ COLOR_BLACK, 1 },
|
|
|
|
{ COLOR_BROWN, 0 },
|
|
|
|
{ COLOR_RED, 0 },
|
|
|
|
{ COLOR_RED, 1 },
|
|
|
|
{ COLOR_BROWN, 1 },
|
|
|
|
{ COLOR_GREY, 1 }
|
|
|
|
};
|
|
|
|
|
2012-09-01 07:52:51 -06:00
|
|
|
void enable_updates_at(df::coord pos, bool flow, bool temp)
|
|
|
|
{
|
|
|
|
static const int delta[4][2] = { { -1, -1 }, { 1, -1 }, { -1, 1 }, { 1, 1 } };
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
auto blk = Maps::getTileBlock(pos.x+delta[i][0], pos.y+delta[i][1], pos.z);
|
|
|
|
Maps::enableBlockUpdates(blk, flow, temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void decrement_flow(df::coord pos, int amount)
|
|
|
|
{
|
|
|
|
auto pldes = Maps::getTileDesignation(pos);
|
|
|
|
if (!pldes) return;
|
|
|
|
|
2012-09-03 00:28:17 -06:00
|
|
|
int nsize = std::max(0, int(pldes->bits.flow_size - amount));
|
2012-09-01 07:52:51 -06:00
|
|
|
pldes->bits.flow_size = nsize;
|
|
|
|
pldes->bits.flow_forbid = (nsize > 3 || pldes->bits.liquid_type == tile_liquid::Magma);
|
|
|
|
|
|
|
|
enable_updates_at(pos, true, false);
|
|
|
|
}
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
void make_explosion(df::coord center, int power)
|
2012-09-01 10:46:34 -06:00
|
|
|
{
|
2012-09-02 04:59:13 -06:00
|
|
|
static const int bias[9] = {
|
|
|
|
60, 30, 60,
|
|
|
|
30, 0, 30,
|
|
|
|
60, 30, 60
|
|
|
|
};
|
2012-09-01 10:46:34 -06:00
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
int mat_type = builtin_mats::WATER, mat_index = -1;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (int dx = -1; dx <= 1; dx++)
|
|
|
|
{
|
|
|
|
for (int dy = -1; dy <= 1; dy++)
|
|
|
|
{
|
|
|
|
int size = power - bias[i++];
|
|
|
|
auto pos = center + df::coord(dx,dy,0);
|
|
|
|
|
|
|
|
if (size > 0)
|
|
|
|
Maps::spawnFlow(pos, flow_type::MaterialDust, mat_type, mat_index, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Gui::showAutoAnnouncement(
|
|
|
|
announcement_type::CAVE_COLLAPSE, center,
|
|
|
|
"A boiler has exploded!", COLOR_RED, true
|
|
|
|
);
|
|
|
|
}
|
2012-09-01 10:46:34 -06:00
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
static const int WEAR_TICKS = 806400;
|
2012-09-01 10:46:34 -06:00
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
bool add_wear_nodestroy(df::item_actual *item, int rate)
|
|
|
|
{
|
|
|
|
if (item->incWearTimer(rate))
|
|
|
|
{
|
|
|
|
while (item->wear_timer >= WEAR_TICKS)
|
|
|
|
{
|
|
|
|
item->wear_timer -= WEAR_TICKS;
|
|
|
|
item->wear++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return item->wear > 3;
|
2012-09-01 10:46:34 -06:00
|
|
|
}
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
/*
|
|
|
|
* Hook for the liquid item. Implements a special 'boiling'
|
|
|
|
* matter state with a modified description and temperature
|
|
|
|
* locked at boiling-1.
|
|
|
|
*/
|
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
struct liquid_hook : df::item_liquid_miscst {
|
|
|
|
typedef df::item_liquid_miscst interpose_base;
|
|
|
|
|
|
|
|
static const uint32_t BOILING_FLAG = 0x80000000U;
|
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, getItemDescription, (std::string *buf, int8_t mode))
|
|
|
|
{
|
|
|
|
if (mat_state.whole & BOILING_FLAG)
|
|
|
|
buf->append("boiling ");
|
|
|
|
|
|
|
|
INTERPOSE_NEXT(getItemDescription)(buf, mode);
|
|
|
|
}
|
2012-09-01 04:42:19 -06:00
|
|
|
|
|
|
|
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)();
|
|
|
|
}
|
2012-09-01 01:29:05 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(liquid_hook, getItemDescription);
|
2012-09-01 04:42:19 -06:00
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(liquid_hook, adjustTemperature);
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(liquid_hook, checkTemperatureDamage);
|
2012-09-01 01:29:05 -06:00
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
/*
|
|
|
|
* Hook for the workshop itself. Implements core logic.
|
|
|
|
*/
|
|
|
|
|
2012-08-31 14:22:55 -06:00
|
|
|
struct workshop_hook : df::building_workshopst {
|
|
|
|
typedef df::building_workshopst interpose_base;
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
// Engine detection
|
|
|
|
|
2012-08-31 14:22:55 -06:00
|
|
|
steam_engine_workshop *get_steam_engine()
|
|
|
|
{
|
|
|
|
if (type == workshop_type::Custom)
|
2012-09-01 01:29:05 -06:00
|
|
|
return find_steam_engine(custom_type);
|
2012-08-31 14:22:55 -06:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
inline bool is_fully_built()
|
|
|
|
{
|
|
|
|
return getBuildStage() >= getMaxBuildStage();
|
|
|
|
}
|
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
// Use high bits of flags to store current steam amount.
|
|
|
|
// This is necessary for consistency if items disappear unexpectedly.
|
|
|
|
|
2012-08-31 14:22:55 -06:00
|
|
|
int get_steam_amount()
|
|
|
|
{
|
2012-09-01 01:29:05 -06:00
|
|
|
return (flags.whole >> 28) & 15;
|
|
|
|
}
|
2012-08-31 14:22:55 -06:00
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
void set_steam_amount(int count)
|
|
|
|
{
|
|
|
|
flags.whole = (flags.whole & 0x0FFFFFFFU) | uint32_t((count & 15) << 28);
|
|
|
|
}
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
// Find liquids to consume below the engine.
|
|
|
|
|
2012-09-02 08:57:10 -06:00
|
|
|
bool find_liquids(df::coord *pwater, df::coord *pmagma, bool is_magma, int min_level)
|
2012-09-01 07:52:51 -06:00
|
|
|
{
|
|
|
|
if (!is_magma)
|
|
|
|
pmagma = NULL;
|
|
|
|
|
|
|
|
for (int x = x1; x <= x2; x++)
|
|
|
|
{
|
|
|
|
for (int y = y1; y <= y2; y++)
|
|
|
|
{
|
|
|
|
auto ptile = Maps::getTileType(x,y,z);
|
|
|
|
if (!ptile || !LowPassable(*ptile))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto pltile = Maps::getTileType(x,y,z-1);
|
|
|
|
if (!pltile || !FlowPassable(*pltile))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto pldes = Maps::getTileDesignation(x,y,z-1);
|
2012-09-02 08:57:10 -06:00
|
|
|
if (!pldes || pldes->bits.flow_size < min_level)
|
2012-09-01 07:52:51 -06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (pldes->bits.liquid_type == tile_liquid::Magma)
|
|
|
|
{
|
2012-09-02 08:57:10 -06:00
|
|
|
if (pmagma)
|
|
|
|
*pmagma = df::coord(x,y,z-1);
|
2012-09-01 07:52:51 -06:00
|
|
|
if (pwater->isValid())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pwater = df::coord(x,y,z-1);
|
|
|
|
if (!pmagma || pmagma->isValid())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
// Absorbs a water item produced by stoke reaction into the engine.
|
|
|
|
|
2012-09-01 07:52:51 -06:00
|
|
|
bool absorb_unit(steam_engine_workshop *engine, df::item_liquid_miscst *liquid)
|
2012-09-01 01:29:05 -06:00
|
|
|
{
|
2012-09-02 04:59:13 -06:00
|
|
|
// Consume liquid inputs
|
2012-09-01 07:52:51 -06:00
|
|
|
df::coord water, magma;
|
|
|
|
|
2012-09-02 08:57:10 -06:00
|
|
|
if (!find_liquids(&water, &magma, engine->is_magma, 1))
|
2012-09-01 07:52:51 -06:00
|
|
|
{
|
2012-09-02 04:59:13 -06:00
|
|
|
// Destroy the item with enormous wear amount.
|
|
|
|
liquid->addWear(WEAR_TICKS*5, true, false);
|
2012-09-01 07:52:51 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
decrement_flow(water, 1);
|
|
|
|
if (engine->is_magma)
|
|
|
|
decrement_flow(magma, 1);
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
// Update flags
|
2012-09-01 01:29:05 -06:00
|
|
|
liquid->flags.bits.in_building = true;
|
|
|
|
liquid->mat_state.whole |= liquid_hook::BOILING_FLAG;
|
2012-09-01 04:42:19 -06:00
|
|
|
liquid->temperature = liquid->getBoilingPoint()-1;
|
|
|
|
liquid->temperature_fraction = 0;
|
2012-08-31 14:22:55 -06:00
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
// This affects where the steam appears to come from
|
|
|
|
if (engine->hearth_tile.isValid())
|
|
|
|
liquid->pos = df::coord(x1+engine->hearth_tile.x, y1+engine->hearth_tile.y, z);
|
2012-09-01 07:52:51 -06:00
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
// Enable block temperature updates
|
2012-09-01 07:52:51 -06:00
|
|
|
enable_updates_at(liquid->pos, false, true);
|
|
|
|
return true;
|
2012-08-31 14:22:55 -06:00
|
|
|
}
|
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
bool boil_unit(df::item_liquid_miscst *liquid)
|
2012-08-31 14:22:55 -06:00
|
|
|
{
|
2012-09-01 01:29:05 -06:00
|
|
|
liquid->wear = 4;
|
|
|
|
liquid->flags.bits.in_building = false;
|
|
|
|
liquid->temperature = liquid->getBoilingPoint() + 10;
|
|
|
|
|
|
|
|
return liquid->checkMeltBoil();
|
|
|
|
}
|
|
|
|
|
|
|
|
void suspend_jobs(bool suspend)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < jobs.size(); i++)
|
|
|
|
if (jobs[i]->job_type == job_type::CustomReaction)
|
|
|
|
jobs[i]->flags.bits.suspend = suspend;
|
2012-08-31 14:22:55 -06:00
|
|
|
}
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
// Scan contained items for boiled steam to absorb.
|
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
df::item_liquid_miscst *collect_steam(steam_engine_workshop *engine, int *count)
|
2012-08-31 14:22:55 -06:00
|
|
|
{
|
|
|
|
df::item_liquid_miscst *first = NULL;
|
2012-09-01 01:29:05 -06:00
|
|
|
*count = 0;
|
2012-08-31 14:22:55 -06:00
|
|
|
|
|
|
|
for (int i = contained_items.size()-1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
auto item = contained_items[i];
|
|
|
|
if (item->use_mode != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto liquid = strict_virtual_cast<df::item_liquid_miscst>(item->item);
|
|
|
|
if (!liquid)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!liquid->flags.bits.in_building)
|
|
|
|
{
|
|
|
|
if (liquid->mat_type != builtin_mats::WATER ||
|
2012-09-01 01:29:05 -06:00
|
|
|
liquid->age > 1 ||
|
2012-08-31 14:22:55 -06:00
|
|
|
liquid->wear != 0)
|
|
|
|
continue;
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
// This may destroy the item
|
2012-09-01 07:52:51 -06:00
|
|
|
if (!absorb_unit(engine, liquid))
|
|
|
|
continue;
|
2012-08-31 14:22:55 -06:00
|
|
|
}
|
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
if (*count < engine->max_capacity)
|
|
|
|
{
|
|
|
|
first = liquid;
|
|
|
|
++*count;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Overpressure valve
|
|
|
|
boil_unit(liquid);
|
2012-09-02 04:59:13 -06:00
|
|
|
suspend_jobs(true);
|
2012-09-01 01:29:05 -06:00
|
|
|
}
|
2012-08-31 14:22:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return first;
|
|
|
|
}
|
|
|
|
|
2012-09-01 04:42:19 -06:00
|
|
|
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;
|
|
|
|
|
2012-09-03 00:28:17 -06:00
|
|
|
if (cnt == 0 || rand() < RAND_MAX/2)
|
2012-09-01 04:42:19 -06:00
|
|
|
{
|
|
|
|
cnt++;
|
|
|
|
boil_unit(liquid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
int classify_component(df::building_actual::T_contained_items *item)
|
2012-09-01 10:46:34 -06:00
|
|
|
{
|
2012-09-02 04:59:13 -06:00
|
|
|
if (item->use_mode != 2 || item->item->isBuildMat())
|
|
|
|
return -1;
|
2012-09-01 10:46:34 -06:00
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
switch (item->item->getType())
|
|
|
|
{
|
|
|
|
case item_type::TRAPPARTS:
|
|
|
|
case item_type::CHAIN:
|
|
|
|
return 0;
|
|
|
|
case item_type::BARREL:
|
|
|
|
return 2;
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-01 10:46:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool check_component_wear(steam_engine_workshop *engine, int count, int power)
|
|
|
|
{
|
2012-09-02 04:59:13 -06:00
|
|
|
int coeffs[3] = { 0, power, count };
|
|
|
|
|
2012-09-01 10:46:34 -06:00
|
|
|
for (int i = contained_items.size()-1; i >= 0; i--)
|
|
|
|
{
|
2012-09-02 04:59:13 -06:00
|
|
|
int type = classify_component(contained_items[i]);
|
|
|
|
if (type < 0)
|
2012-09-01 10:46:34 -06:00
|
|
|
continue;
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
df::item *item = contained_items[i]->item;
|
|
|
|
int melt_temp = item->getMeltingPoint();
|
|
|
|
if (coeffs[type] == 0 || melt_temp >= engine->wear_temp)
|
2012-09-01 10:46:34 -06:00
|
|
|
continue;
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
// let 500 degree delta at 4 pressure work 1 season
|
|
|
|
float ticks = coeffs[type]*(engine->wear_temp - melt_temp)*3.0f/500.0f/4.0f;
|
|
|
|
if (item->addWear(int(8*(1 + ticks)), true, true))
|
2012-09-01 10:46:34 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-02 07:32:44 -06:00
|
|
|
float get_component_quality(int use_type)
|
|
|
|
{
|
|
|
|
float sum = 0, cnt = 0;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < contained_items.size(); i++)
|
|
|
|
{
|
|
|
|
int type = classify_component(contained_items[i]);
|
|
|
|
if (type != use_type)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sum += contained_items[i]->item->getQuality();
|
|
|
|
cnt += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (cnt > 0 ? sum/cnt : 0);
|
|
|
|
}
|
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
int get_steam_use_rate(steam_engine_workshop *engine, int dimension, int power_level)
|
|
|
|
{
|
|
|
|
// total ticks to wear off completely
|
|
|
|
float ticks = WEAR_TICKS * 4.0f;
|
|
|
|
// dimension == days it lasts * 100
|
|
|
|
ticks /= 1200.0f * dimension / 100.0f;
|
|
|
|
// true power use
|
|
|
|
float power_rate = 1.0f;
|
|
|
|
// check the actual load
|
|
|
|
if (auto mptr = df::machine::find(machine.machine_id))
|
|
|
|
{
|
|
|
|
if (mptr->cur_power >= mptr->min_power)
|
|
|
|
power_rate = float(mptr->min_power) / mptr->cur_power;
|
|
|
|
else
|
|
|
|
power_rate = 0.0f;
|
|
|
|
}
|
2012-09-02 07:32:44 -06:00
|
|
|
// waste rate: 1-10% depending on piston assembly quality
|
2012-09-05 01:23:00 -06:00
|
|
|
float piston_qual = get_component_quality(1);
|
|
|
|
float waste = 0.1f - 0.016f * 0.5f * (piston_qual + get_component_quality(2));
|
|
|
|
float efficiency_coeff = 1.0f - 0.02f * piston_qual;
|
2012-09-02 07:32:44 -06:00
|
|
|
// apply rate and waste factor
|
2012-09-05 01:23:00 -06:00
|
|
|
ticks *= (waste + 0.9f*power_rate)*power_level*efficiency_coeff;
|
2012-09-01 01:29:05 -06:00
|
|
|
// end result
|
|
|
|
return std::max(1, int(ticks));
|
|
|
|
}
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
void update_under_construction(steam_engine_workshop *engine)
|
|
|
|
{
|
|
|
|
if (machine.machine_id != -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int cur_count = 0;
|
|
|
|
|
|
|
|
if (auto first = collect_steam(engine, &cur_count))
|
|
|
|
{
|
|
|
|
if (add_wear_nodestroy(first, WEAR_TICKS*4/10))
|
|
|
|
{
|
|
|
|
boil_unit(first);
|
|
|
|
cur_count--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set_steam_amount(cur_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_working(steam_engine_workshop *engine)
|
|
|
|
{
|
|
|
|
int old_count = get_steam_amount();
|
|
|
|
int old_power = std::min(engine->max_power, old_count);
|
|
|
|
int cur_count = 0;
|
|
|
|
|
|
|
|
if (auto first = collect_steam(engine, &cur_count))
|
|
|
|
{
|
|
|
|
int rate = get_steam_use_rate(engine, first->dimension, old_power);
|
|
|
|
|
|
|
|
if (add_wear_nodestroy(first, rate))
|
|
|
|
{
|
|
|
|
boil_unit(first);
|
|
|
|
cur_count--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_component_wear(engine, old_count, old_power))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_count < engine->max_capacity && cur_count == engine->max_capacity)
|
|
|
|
suspend_jobs(true);
|
|
|
|
else if (cur_count <= engine->max_power+1 && old_count > engine->max_power+1)
|
|
|
|
suspend_jobs(false);
|
|
|
|
|
|
|
|
set_steam_amount(cur_count);
|
|
|
|
|
|
|
|
int cur_power = std::min(engine->max_power, cur_count);
|
|
|
|
if (cur_power != old_power)
|
|
|
|
{
|
|
|
|
auto mptr = df::machine::find(machine.machine_id);
|
|
|
|
if (mptr)
|
|
|
|
mptr->cur_power += (cur_power - old_power)*100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
// Furnaces need architecture, and this is a workshop
|
|
|
|
// only because furnaces cannot connect to machines.
|
2012-08-31 14:22:55 -06:00
|
|
|
DEFINE_VMETHOD_INTERPOSE(bool, needsDesign, ())
|
|
|
|
{
|
|
|
|
if (get_steam_engine())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return INTERPOSE_NEXT(needsDesign)();
|
|
|
|
}
|
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
// Machine interface
|
2012-08-31 14:22:55 -06:00
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, getPowerInfo, (df::power_info *info))
|
|
|
|
{
|
|
|
|
if (auto engine = get_steam_engine())
|
|
|
|
{
|
2012-09-01 01:29:05 -06:00
|
|
|
info->produced = std::min(engine->max_power, get_steam_amount())*100;
|
2012-09-02 07:32:44 -06:00
|
|
|
info->consumed = 10 - int(get_component_quality(0));
|
2012-08-31 14:22:55 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERPOSE_NEXT(getPowerInfo)(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(df::machine_info*, getMachineInfo, ())
|
|
|
|
{
|
|
|
|
if (get_steam_engine())
|
|
|
|
return &machine;
|
|
|
|
|
|
|
|
return INTERPOSE_NEXT(getMachineInfo)();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(bool, isPowerSource, ())
|
|
|
|
{
|
|
|
|
if (get_steam_engine())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return INTERPOSE_NEXT(isPowerSource)();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, categorize, (bool free))
|
|
|
|
{
|
|
|
|
if (get_steam_engine())
|
|
|
|
{
|
|
|
|
auto &vec = world->buildings.other[buildings_other_id::ANY_MACHINE];
|
|
|
|
insert_into_vector(vec, &df::building::id, (df::building*)this);
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERPOSE_NEXT(categorize)(free);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, uncategorize, ())
|
|
|
|
{
|
|
|
|
if (get_steam_engine())
|
|
|
|
{
|
|
|
|
auto &vec = world->buildings.other[buildings_other_id::ANY_MACHINE];
|
|
|
|
erase_from_vector(vec, &df::building::id, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERPOSE_NEXT(uncategorize)();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(bool, canConnectToMachine, (df::machine_tile_set *info))
|
|
|
|
{
|
|
|
|
if (auto engine = get_steam_engine())
|
|
|
|
{
|
|
|
|
int real_cx = centerx, real_cy = centery;
|
|
|
|
bool ok = false;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < engine->gear_tiles.size(); i++)
|
|
|
|
{
|
2012-09-01 01:29:05 -06:00
|
|
|
// the original function connects to the center tile
|
2012-08-31 14:22:55 -06:00
|
|
|
centerx = x1 + engine->gear_tiles[i].x;
|
|
|
|
centery = y1 + engine->gear_tiles[i].y;
|
|
|
|
|
|
|
|
if (!INTERPOSE_NEXT(canConnectToMachine)(info))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ok = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
centerx = real_cx; centery = real_cy;
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return INTERPOSE_NEXT(canConnectToMachine)(info);
|
|
|
|
}
|
|
|
|
|
2012-09-01 07:52:51 -06:00
|
|
|
// Operation logic
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(bool, isUnpowered, ())
|
|
|
|
{
|
|
|
|
if (auto engine = get_steam_engine())
|
|
|
|
{
|
|
|
|
df::coord water, magma;
|
2012-09-02 08:57:10 -06:00
|
|
|
return !find_liquids(&water, &magma, engine->is_magma, 3);
|
2012-09-01 07:52:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return INTERPOSE_NEXT(isUnpowered)();
|
|
|
|
}
|
|
|
|
|
2012-08-31 14:22:55 -06:00
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, updateAction, ())
|
|
|
|
{
|
|
|
|
if (auto engine = get_steam_engine())
|
|
|
|
{
|
2012-09-02 04:59:13 -06:00
|
|
|
if (is_fully_built())
|
|
|
|
update_working(engine);
|
|
|
|
else
|
|
|
|
update_under_construction(engine);
|
2012-09-01 01:29:05 -06:00
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
if (flags.bits.almost_deleted)
|
|
|
|
return;
|
2012-08-31 14:22:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
INTERPOSE_NEXT(updateAction)();
|
|
|
|
}
|
2012-09-01 01:29:05 -06:00
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, drawBuilding, (df::building_drawbuffer *db, void *unk))
|
|
|
|
{
|
|
|
|
INTERPOSE_NEXT(drawBuilding)(db, unk);
|
|
|
|
|
|
|
|
if (auto engine = get_steam_engine())
|
|
|
|
{
|
2012-09-02 04:59:13 -06:00
|
|
|
if (!is_fully_built())
|
|
|
|
return;
|
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
// If machine is running, tweak gear assemblies
|
|
|
|
auto mptr = df::machine::find(machine.machine_id);
|
|
|
|
if (mptr && (mptr->visual_phase & 1) != 0)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < engine->gear_tiles.size(); i++)
|
|
|
|
{
|
|
|
|
auto pos = engine->gear_tiles[i];
|
|
|
|
db->tile[pos.x][pos.y] = 42;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use the hearth color to display power level
|
|
|
|
if (engine->hearth_tile.isValid())
|
|
|
|
{
|
|
|
|
auto pos = engine->hearth_tile;
|
|
|
|
int power = std::min(engine->max_power, get_steam_amount());
|
|
|
|
db->fore[pos.x][pos.y] = hearth_colors[power][0];
|
|
|
|
db->bright[pos.x][pos.y] = hearth_colors[power][1];
|
|
|
|
}
|
2012-09-01 07:52:51 -06:00
|
|
|
|
|
|
|
// Set liquid indicator state
|
|
|
|
if (engine->water_tile.isValid() || engine->magma_tile.isValid())
|
|
|
|
{
|
|
|
|
df::coord water, magma;
|
2012-09-02 08:57:10 -06:00
|
|
|
find_liquids(&water, &magma, engine->is_magma, 3);
|
|
|
|
df::coord dwater, dmagma;
|
|
|
|
find_liquids(&dwater, &dmagma, engine->is_magma, 5);
|
2012-09-01 07:52:51 -06:00
|
|
|
|
2012-09-02 08:57:10 -06:00
|
|
|
if (engine->water_tile.isValid())
|
|
|
|
{
|
|
|
|
if (!water.isValid())
|
|
|
|
db->fore[engine->water_tile.x][engine->water_tile.y] = 0;
|
|
|
|
else if (!dwater.isValid())
|
|
|
|
db->bright[engine->water_tile.x][engine->water_tile.y] = 0;
|
|
|
|
}
|
|
|
|
if (engine->magma_tile.isValid() && engine->is_magma)
|
|
|
|
{
|
|
|
|
if (!magma.isValid())
|
|
|
|
db->fore[engine->magma_tile.x][engine->magma_tile.y] = 0;
|
|
|
|
else if (!dmagma.isValid())
|
|
|
|
db->bright[engine->magma_tile.x][engine->magma_tile.y] = 0;
|
|
|
|
}
|
2012-09-01 07:52:51 -06:00
|
|
|
}
|
2012-09-01 01:29:05 -06:00
|
|
|
}
|
|
|
|
}
|
2012-09-01 04:42:19 -06:00
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, deconstructItems, (bool noscatter, bool lost))
|
|
|
|
{
|
|
|
|
if (get_steam_engine())
|
2012-09-02 04:59:13 -06:00
|
|
|
{
|
|
|
|
// Explode if any steam left
|
|
|
|
if (int amount = get_steam_amount())
|
|
|
|
{
|
|
|
|
make_explosion(
|
|
|
|
df::coord((x1+x2)/2, (y1+y2)/2, z),
|
|
|
|
40 + amount * 20
|
|
|
|
);
|
2012-09-01 04:42:19 -06:00
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
random_boil();
|
|
|
|
}
|
|
|
|
}
|
2012-09-01 10:46:34 -06:00
|
|
|
|
2012-09-01 04:42:19 -06:00
|
|
|
INTERPOSE_NEXT(deconstructItems)(noscatter, lost);
|
|
|
|
}
|
2012-08-31 14:22:55 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, needsDesign);
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, getPowerInfo);
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, getMachineInfo);
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, isPowerSource);
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, categorize);
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, uncategorize);
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, canConnectToMachine);
|
2012-09-01 07:52:51 -06:00
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, isUnpowered);
|
2012-08-31 14:22:55 -06:00
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, updateAction);
|
2012-09-01 01:29:05 -06:00
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, drawBuilding);
|
2012-09-01 04:42:19 -06:00
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(workshop_hook, deconstructItems);
|
2012-08-31 14:22:55 -06:00
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
/*
|
|
|
|
* Hook for the dwarfmode screen. Tweaks the build menu
|
|
|
|
* behavior to suit the steam engine building more.
|
|
|
|
*/
|
|
|
|
|
2012-09-01 07:52:51 -06:00
|
|
|
struct dwarfmode_hook : df::viewscreen_dwarfmodest
|
|
|
|
{
|
|
|
|
typedef df::viewscreen_dwarfmodest interpose_base;
|
|
|
|
|
|
|
|
steam_engine_workshop *get_steam_engine()
|
|
|
|
{
|
|
|
|
if (ui->main.mode == ui_sidebar_mode::Build &&
|
|
|
|
ui_build_selector->stage == 1 &&
|
|
|
|
ui_build_selector->building_type == building_type::Workshop &&
|
|
|
|
ui_build_selector->building_subtype == workshop_type::Custom)
|
|
|
|
{
|
|
|
|
return find_steam_engine(ui_build_selector->custom_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_hanging_tiles(steam_engine_workshop *engine)
|
|
|
|
{
|
|
|
|
using df::global::cursor;
|
|
|
|
|
|
|
|
if (!engine) return;
|
|
|
|
|
|
|
|
bool error = false;
|
|
|
|
|
|
|
|
int x1 = cursor->x - engine->def->workloc_x;
|
|
|
|
int y1 = cursor->y - engine->def->workloc_y;
|
|
|
|
|
|
|
|
for (int x = 0; x < engine->def->dim_x; x++)
|
|
|
|
{
|
|
|
|
for (int y = 0; y < engine->def->dim_y; y++)
|
|
|
|
{
|
|
|
|
if (ui_build_selector->tiles[x][y] >= 5)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto ptile = Maps::getTileType(x1+x,y1+y,cursor->z);
|
|
|
|
if (ptile && !isOpenTerrain(*ptile))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ui_build_selector->tiles[x][y] = 6;
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
2012-09-02 04:59:13 -06:00
|
|
|
const char *msg = "Hanging - cover channels with down stairs.";
|
2012-09-01 07:52:51 -06:00
|
|
|
ui_build_selector->errors.push_back(new std::string(msg));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, feed, (set<df::interface_key> *input))
|
|
|
|
{
|
|
|
|
steam_engine_workshop *engine = get_steam_engine();
|
|
|
|
|
|
|
|
// Selector insists that workshops cannot be placed hanging
|
|
|
|
// unless they require magma, so pretend we always do.
|
|
|
|
if (engine)
|
|
|
|
engine->def->needs_magma = true;
|
|
|
|
|
|
|
|
INTERPOSE_NEXT(feed)(input);
|
|
|
|
|
|
|
|
// Restore the flag
|
|
|
|
if (engine)
|
|
|
|
engine->def->needs_magma = engine->is_magma;
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
// And now, check for open space. Since these workshops
|
|
|
|
// are machines, they will collapse over true open space.
|
2012-09-01 07:52:51 -06:00
|
|
|
check_hanging_tiles(get_steam_engine());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(dwarfmode_hook, feed);
|
|
|
|
|
2012-09-02 04:59:13 -06:00
|
|
|
/*
|
|
|
|
* Scan raws for matching workshop buildings.
|
|
|
|
*/
|
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
static bool find_engines()
|
2012-08-31 14:22:55 -06:00
|
|
|
{
|
|
|
|
engines.clear();
|
|
|
|
|
|
|
|
auto &wslist = world->raws.buildings.workshops;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < wslist.size(); i++)
|
|
|
|
{
|
|
|
|
if (strstr(wslist[i]->code.c_str(), "STEAM_ENGINE") == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
steam_engine_workshop ws;
|
|
|
|
ws.def = wslist[i];
|
|
|
|
ws.id = ws.def->id;
|
|
|
|
|
|
|
|
int bs = ws.def->build_stages;
|
|
|
|
for (int x = 0; x < ws.def->dim_x; x++)
|
|
|
|
{
|
|
|
|
for (int y = 0; y < ws.def->dim_y; y++)
|
|
|
|
{
|
2012-09-02 07:17:18 -06:00
|
|
|
switch (ws.def->tile[bs][x][y])
|
|
|
|
{
|
|
|
|
case 15:
|
2012-08-31 14:22:55 -06:00
|
|
|
ws.gear_tiles.push_back(df::coord2d(x,y));
|
2012-09-02 07:17:18 -06:00
|
|
|
break;
|
|
|
|
case 19:
|
|
|
|
ws.hearth_tile = df::coord2d(x,y);
|
|
|
|
break;
|
|
|
|
}
|
2012-08-31 14:22:55 -06:00
|
|
|
|
|
|
|
if (ws.def->tile_color[2][bs][x][y])
|
|
|
|
{
|
|
|
|
switch (ws.def->tile_color[0][bs][x][y])
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
ws.water_tile = df::coord2d(x,y);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
ws.magma_tile = df::coord2d(x,y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
ws.is_magma = ws.def->needs_magma;
|
|
|
|
ws.max_power = ws.is_magma ? 5 : 3;
|
|
|
|
ws.max_capacity = ws.is_magma ? 10 : 6;
|
2012-09-01 10:46:34 -06:00
|
|
|
ws.wear_temp = ws.is_magma ? 12000 : 11000;
|
2012-09-01 01:29:05 -06:00
|
|
|
|
|
|
|
if (!ws.gear_tiles.empty())
|
|
|
|
engines.push_back(ws);
|
2012-08-31 14:22:55 -06:00
|
|
|
}
|
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
return !engines.empty();
|
2012-08-31 14:22:55 -06:00
|
|
|
}
|
|
|
|
|
2012-09-01 01:29:05 -06:00
|
|
|
static void enable_hooks(bool enable)
|
2012-08-31 14:22:55 -06:00
|
|
|
{
|
2012-09-01 01:29:05 -06:00
|
|
|
INTERPOSE_HOOK(liquid_hook, getItemDescription).apply(enable);
|
2012-09-01 04:42:19 -06:00
|
|
|
INTERPOSE_HOOK(liquid_hook, adjustTemperature).apply(enable);
|
|
|
|
INTERPOSE_HOOK(liquid_hook, checkTemperatureDamage).apply(enable);
|
2012-09-01 01:29:05 -06:00
|
|
|
|
|
|
|
INTERPOSE_HOOK(workshop_hook, needsDesign).apply(enable);
|
|
|
|
INTERPOSE_HOOK(workshop_hook, getPowerInfo).apply(enable);
|
|
|
|
INTERPOSE_HOOK(workshop_hook, getMachineInfo).apply(enable);
|
|
|
|
INTERPOSE_HOOK(workshop_hook, isPowerSource).apply(enable);
|
|
|
|
INTERPOSE_HOOK(workshop_hook, categorize).apply(enable);
|
|
|
|
INTERPOSE_HOOK(workshop_hook, uncategorize).apply(enable);
|
|
|
|
INTERPOSE_HOOK(workshop_hook, canConnectToMachine).apply(enable);
|
2012-09-01 07:52:51 -06:00
|
|
|
INTERPOSE_HOOK(workshop_hook, isUnpowered).apply(enable);
|
2012-09-01 01:29:05 -06:00
|
|
|
INTERPOSE_HOOK(workshop_hook, updateAction).apply(enable);
|
|
|
|
INTERPOSE_HOOK(workshop_hook, drawBuilding).apply(enable);
|
2012-09-01 04:42:19 -06:00
|
|
|
INTERPOSE_HOOK(workshop_hook, deconstructItems).apply(enable);
|
2012-09-01 07:52:51 -06:00
|
|
|
|
|
|
|
INTERPOSE_HOOK(dwarfmode_hook, feed).apply(enable);
|
2012-08-31 14:22:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
|
|
|
|
{
|
|
|
|
switch (event) {
|
|
|
|
case SC_MAP_LOADED:
|
2012-09-01 01:29:05 -06:00
|
|
|
if (find_engines())
|
2012-08-31 14:22:55 -06:00
|
|
|
{
|
|
|
|
out.print("Detected steam engine workshops - enabling plugin.\n");
|
2012-09-01 01:29:05 -06:00
|
|
|
enable_hooks(true);
|
2012-08-31 14:22:55 -06:00
|
|
|
}
|
2012-09-01 01:29:05 -06:00
|
|
|
else
|
|
|
|
enable_hooks(false);
|
2012-08-31 14:22:55 -06:00
|
|
|
break;
|
|
|
|
case SC_MAP_UNLOADED:
|
2012-09-01 01:29:05 -06:00
|
|
|
enable_hooks(false);
|
2012-08-31 14:22:55 -06:00
|
|
|
engines.clear();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
if (Core::getInstance().isMapLoaded())
|
|
|
|
plugin_onstatechange(out, SC_MAP_LOADED);
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
|
|
|
{
|
2012-09-01 01:29:05 -06:00
|
|
|
enable_hooks(false);
|
2012-08-31 14:22:55 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|