2011-04-30 15:58:29 -06:00
|
|
|
// Produces a list of materials available on the map.
|
|
|
|
// Options:
|
|
|
|
// -a : show unrevealed tiles
|
|
|
|
// -p : don't show plants
|
|
|
|
// -s : don't show slade
|
|
|
|
// -t : don't show demon temple
|
2009-09-13 18:02:46 -06:00
|
|
|
|
2011-05-02 15:32:32 -06:00
|
|
|
//#include <cstdlib>
|
2009-09-13 18:02:46 -06:00
|
|
|
#include <iostream>
|
2011-05-01 21:03:48 -06:00
|
|
|
#include <iomanip>
|
2009-09-13 18:02:46 -06:00
|
|
|
#include <map>
|
2011-05-01 21:03:48 -06:00
|
|
|
#include <algorithm>
|
2014-10-31 16:01:56 -06:00
|
|
|
#include <functional>
|
2011-04-30 15:58:29 -06:00
|
|
|
#include <vector>
|
2009-09-13 18:02:46 -06:00
|
|
|
|
2011-04-30 15:58:29 -06:00
|
|
|
using namespace std;
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
2022-07-06 07:57:13 -06:00
|
|
|
#include "LuaTools.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "PluginManager.h"
|
2015-10-02 19:50:55 -06:00
|
|
|
#include "modules/Gui.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "modules/MapCache.h"
|
2011-06-26 20:49:56 -06:00
|
|
|
|
2012-02-02 11:14:49 -07:00
|
|
|
#include "MiscUtils.h"
|
|
|
|
|
2012-01-17 08:44:48 -07:00
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "df/world.h"
|
2012-02-02 11:14:49 -07:00
|
|
|
#include "df/world_data.h"
|
|
|
|
#include "df/world_region_details.h"
|
2012-08-27 13:03:17 -06:00
|
|
|
#include "df/world_region_feature.h"
|
2012-02-02 11:14:49 -07:00
|
|
|
#include "df/world_geo_biome.h"
|
|
|
|
#include "df/world_geo_layer.h"
|
2012-08-27 13:03:17 -06:00
|
|
|
#include "df/world_underground_region.h"
|
|
|
|
#include "df/feature_init.h"
|
2012-08-27 13:03:02 -06:00
|
|
|
#include "df/region_map_entry.h"
|
2012-02-02 11:14:49 -07:00
|
|
|
#include "df/inclusion_type.h"
|
|
|
|
#include "df/viewscreen_choose_start_sitest.h"
|
2012-12-06 15:46:59 -07:00
|
|
|
#include "df/plant.h"
|
2012-01-17 08:44:48 -07:00
|
|
|
|
2011-06-26 20:49:56 -06:00
|
|
|
using namespace DFHack;
|
2012-01-21 17:31:15 -07:00
|
|
|
using namespace df::enums;
|
2012-02-02 11:14:49 -07:00
|
|
|
using df::coord2d;
|
2011-04-30 15:58:29 -06:00
|
|
|
|
2014-12-06 16:47:35 -07:00
|
|
|
DFHACK_PLUGIN("prospector");
|
|
|
|
REQUIRE_GLOBAL(world);
|
|
|
|
|
2022-07-06 07:57:13 -06:00
|
|
|
struct prospect_options {
|
|
|
|
// whether to display help
|
|
|
|
bool help = false;
|
|
|
|
|
|
|
|
// whether to scan the whole map or just the unhidden tiles
|
|
|
|
bool hidden = false;
|
|
|
|
|
|
|
|
// whether to also show material values
|
|
|
|
bool value = false;
|
|
|
|
|
|
|
|
// whether to show adamantine tube z-levels
|
|
|
|
bool tube = false;
|
|
|
|
|
|
|
|
// which report sections to show
|
|
|
|
bool summary = true;
|
|
|
|
bool liquids = true;
|
|
|
|
bool layers = true;
|
|
|
|
bool features = true;
|
|
|
|
bool ores = true;
|
|
|
|
bool gems = true;
|
|
|
|
bool veins = true;
|
|
|
|
bool shrubs = true;
|
|
|
|
bool trees = true;
|
|
|
|
|
|
|
|
static struct_identity _identity;
|
|
|
|
};
|
|
|
|
static const struct_field_info prospect_options_fields[] = {
|
|
|
|
{ struct_field_info::PRIMITIVE, "help", offsetof(prospect_options, help), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "hidden", offsetof(prospect_options, hidden), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "value", offsetof(prospect_options, value), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "tube", offsetof(prospect_options, tube), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "summary", offsetof(prospect_options, summary), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "liquids", offsetof(prospect_options, liquids), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "layers", offsetof(prospect_options, layers), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "features", offsetof(prospect_options, features), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "ores", offsetof(prospect_options, ores), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "gems", offsetof(prospect_options, gems), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "veins", offsetof(prospect_options, veins), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "shrubs", offsetof(prospect_options, shrubs), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::PRIMITIVE, "trees", offsetof(prospect_options, trees), &df::identity_traits<bool>::identity, 0, 0 },
|
|
|
|
{ struct_field_info::END }
|
|
|
|
};
|
|
|
|
struct_identity prospect_options::_identity(sizeof(prospect_options), &df::allocator_fn<prospect_options>, NULL, "prospect_options", NULL, prospect_options_fields);
|
|
|
|
|
2011-10-24 18:39:15 -06:00
|
|
|
struct matdata
|
|
|
|
{
|
|
|
|
const static int invalid_z = -30000;
|
|
|
|
matdata()
|
|
|
|
{
|
2021-02-08 06:45:49 -07:00
|
|
|
count = 0.0;
|
2011-10-24 18:39:15 -06:00
|
|
|
lower_z = invalid_z;
|
|
|
|
upper_z = invalid_z;
|
|
|
|
}
|
|
|
|
matdata (const matdata & copyme)
|
|
|
|
{
|
|
|
|
count = copyme.count;
|
|
|
|
lower_z = copyme.lower_z;
|
|
|
|
upper_z = copyme.upper_z;
|
|
|
|
}
|
2021-02-08 06:45:49 -07:00
|
|
|
float add(int z_level = invalid_z, float delta = 1.0)
|
2011-10-24 18:39:15 -06:00
|
|
|
{
|
2012-02-02 11:14:49 -07:00
|
|
|
count += delta;
|
2011-10-24 18:39:15 -06:00
|
|
|
if(z_level != invalid_z)
|
|
|
|
{
|
|
|
|
if(lower_z == invalid_z || z_level < lower_z)
|
|
|
|
{
|
|
|
|
lower_z = z_level;
|
|
|
|
}
|
|
|
|
if(upper_z == invalid_z || z_level > upper_z)
|
|
|
|
{
|
|
|
|
upper_z = z_level;
|
|
|
|
}
|
|
|
|
}
|
2011-10-24 21:34:11 -06:00
|
|
|
return count;
|
2011-10-24 18:39:15 -06:00
|
|
|
}
|
2021-02-08 06:45:49 -07:00
|
|
|
float count;
|
2011-10-24 18:39:15 -06:00
|
|
|
int lower_z;
|
|
|
|
int upper_z;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator>(const matdata & q1, const matdata & q2)
|
|
|
|
{
|
|
|
|
return q1.count > q2.count;
|
|
|
|
}
|
|
|
|
|
2022-06-05 14:05:14 -06:00
|
|
|
template<typename Tp = matdata >
|
|
|
|
struct shallower
|
2012-03-03 15:18:12 -07:00
|
|
|
{
|
2022-06-05 14:05:14 -06:00
|
|
|
bool operator()(const Tp& top, const Tp& bottom) const
|
2012-03-03 15:18:12 -07:00
|
|
|
{
|
|
|
|
float topavg = (top.lower_z + top.upper_z)/2.0f;
|
|
|
|
float btmavg = (bottom.lower_z + bottom.upper_z)/2.0f;
|
|
|
|
return topavg > btmavg;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-10-24 18:39:15 -06:00
|
|
|
typedef std::map<int16_t, matdata> MatMap;
|
|
|
|
typedef std::vector< pair<int16_t, matdata> > MatSorter;
|
2011-04-30 15:58:29 -06:00
|
|
|
|
2012-01-21 16:54:57 -07:00
|
|
|
typedef std::vector<df::plant *> PlantList;
|
2011-06-26 20:49:56 -06:00
|
|
|
|
2011-07-20 07:18:50 -06:00
|
|
|
#define TO_PTR_VEC(obj_vec, ptr_vec) \
|
|
|
|
ptr_vec.clear(); \
|
|
|
|
for (size_t i = 0; i < obj_vec.size(); i++) \
|
|
|
|
ptr_vec.push_back(&obj_vec[i])
|
|
|
|
|
2011-05-01 21:03:48 -06:00
|
|
|
template<template <typename> class P = std::greater >
|
|
|
|
struct compare_pair_second
|
|
|
|
{
|
|
|
|
template<class T1, class T2>
|
2012-03-03 15:18:12 -07:00
|
|
|
bool operator()(const std::pair<T1, T2>& left, const std::pair<T1, T2>& right)
|
|
|
|
{
|
|
|
|
return P<T2>()(left.second, right.second);
|
|
|
|
}
|
2011-05-01 21:03:48 -06:00
|
|
|
};
|
|
|
|
|
2012-08-27 13:03:17 -06:00
|
|
|
static void printMatdata(color_ostream &con, const matdata &data, bool only_z = false)
|
2012-01-17 08:44:48 -07:00
|
|
|
{
|
2012-08-27 13:03:17 -06:00
|
|
|
if (!only_z)
|
2021-02-08 06:45:49 -07:00
|
|
|
con << std::setw(9) << int(data.count);
|
2012-01-17 08:44:48 -07:00
|
|
|
|
|
|
|
if(data.lower_z != data.upper_z)
|
2022-07-06 07:57:13 -06:00
|
|
|
con <<" Z:" << std::setw(4) << data.lower_z << ".." << data.upper_z << std::endl;
|
2012-01-17 08:44:48 -07:00
|
|
|
else
|
2022-07-06 07:57:13 -06:00
|
|
|
con <<" Z:" << std::setw(4) << data.lower_z << std::endl;
|
2012-01-17 08:44:48 -07:00
|
|
|
}
|
|
|
|
|
2012-01-21 09:12:26 -07:00
|
|
|
static int getValue(const df::inorganic_raw &info)
|
2012-01-17 08:56:52 -07:00
|
|
|
{
|
2012-01-21 09:12:26 -07:00
|
|
|
return info.material.material_value;
|
2012-01-17 08:56:52 -07:00
|
|
|
}
|
|
|
|
|
2012-01-21 09:12:26 -07:00
|
|
|
static int getValue(const df::plant_raw &info)
|
2012-01-17 08:56:52 -07:00
|
|
|
{
|
|
|
|
return info.value;
|
|
|
|
}
|
|
|
|
|
2012-03-03 15:18:12 -07:00
|
|
|
template <typename T, template <typename> class P>
|
2022-07-06 07:57:13 -06:00
|
|
|
void printMats(color_ostream &con, MatMap &mat, std::vector<T*> &materials, const prospect_options &options)
|
2010-06-20 16:31:43 -06:00
|
|
|
{
|
2011-04-30 15:58:29 -06:00
|
|
|
unsigned int total = 0;
|
2011-05-01 21:03:48 -06:00
|
|
|
MatSorter sorting_vector;
|
2011-04-30 15:58:29 -06:00
|
|
|
for (MatMap::const_iterator it = mat.begin(); it != mat.end(); ++it)
|
2011-05-01 21:03:48 -06:00
|
|
|
{
|
|
|
|
sorting_vector.push_back(*it);
|
|
|
|
}
|
2011-07-20 07:18:50 -06:00
|
|
|
std::sort(sorting_vector.begin(), sorting_vector.end(),
|
2012-03-03 15:18:12 -07:00
|
|
|
compare_pair_second<P>());
|
2011-07-20 07:18:50 -06:00
|
|
|
for (MatSorter::const_iterator it = sorting_vector.begin();
|
|
|
|
it != sorting_vector.end(); ++it)
|
2010-06-20 16:31:43 -06:00
|
|
|
{
|
2018-04-06 00:18:15 -06:00
|
|
|
if(size_t(it->first) >= materials.size())
|
2011-05-24 21:13:24 -06:00
|
|
|
{
|
2015-02-14 20:53:06 -07:00
|
|
|
con << "Bad index: " << it->first << " out of "
|
2011-07-20 07:18:50 -06:00
|
|
|
<< materials.size() << endl;
|
2011-05-24 21:13:24 -06:00
|
|
|
continue;
|
|
|
|
}
|
2011-11-02 21:30:59 -06:00
|
|
|
T* mat = materials[it->first];
|
2012-01-21 09:12:26 -07:00
|
|
|
// Somewhat of a hack, but it works because df::inorganic_raw and df::plant_raw both have a field named "id"
|
|
|
|
con << std::setw(25) << mat->id << " : ";
|
2022-07-06 07:57:13 -06:00
|
|
|
if (options.value)
|
2012-01-17 08:56:52 -07:00
|
|
|
con << std::setw(3) << getValue(*mat) << " : ";
|
2012-01-17 08:44:48 -07:00
|
|
|
printMatdata(con, it->second);
|
2011-10-24 18:39:15 -06:00
|
|
|
total += it->second.count;
|
2010-06-20 16:31:43 -06:00
|
|
|
}
|
2011-05-01 21:03:48 -06:00
|
|
|
|
2011-07-13 03:45:30 -06:00
|
|
|
con << ">>> TOTAL = " << total << std::endl << std::endl;
|
2011-04-30 15:58:29 -06:00
|
|
|
}
|
2011-07-20 07:18:50 -06:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
void printVeins(color_ostream &con, MatMap &mat_map,
|
2022-07-06 07:57:13 -06:00
|
|
|
const prospect_options &options)
|
2011-07-20 07:18:50 -06:00
|
|
|
{
|
|
|
|
MatMap ores;
|
|
|
|
MatMap gems;
|
|
|
|
MatMap rest;
|
|
|
|
|
2018-05-17 17:56:48 -06:00
|
|
|
for (const auto &kv : mat_map)
|
2011-07-20 07:18:50 -06:00
|
|
|
{
|
2018-05-17 17:56:48 -06:00
|
|
|
df::inorganic_raw *gloss = vector_get(world->raws.inorganics, kv.first);
|
|
|
|
if (!gloss)
|
|
|
|
{
|
|
|
|
con.printerr("invalid material gloss: %hi\n", kv.first);
|
|
|
|
continue;
|
|
|
|
}
|
2011-07-20 07:18:50 -06:00
|
|
|
|
2012-01-21 09:12:26 -07:00
|
|
|
if (gloss->material.isGem())
|
2018-05-17 17:56:48 -06:00
|
|
|
gems[kv.first] = kv.second;
|
2011-11-02 21:30:59 -06:00
|
|
|
else if (gloss->isOre())
|
2018-05-17 17:56:48 -06:00
|
|
|
ores[kv.first] = kv.second;
|
2011-07-20 07:18:50 -06:00
|
|
|
else
|
2018-05-17 17:56:48 -06:00
|
|
|
rest[kv.first] = kv.second;
|
2011-07-20 07:18:50 -06:00
|
|
|
}
|
|
|
|
|
2022-07-06 07:57:13 -06:00
|
|
|
if (options.ores) {
|
|
|
|
con << "Ores:" << std::endl;
|
|
|
|
printMats<df::inorganic_raw, std::greater>(con, ores, world->raws.inorganics, options);
|
|
|
|
}
|
2011-07-20 07:18:50 -06:00
|
|
|
|
2022-07-06 07:57:13 -06:00
|
|
|
if (options.gems) {
|
|
|
|
con << "Gems:" << std::endl;
|
|
|
|
printMats<df::inorganic_raw, std::greater>(con, gems, world->raws.inorganics, options);
|
|
|
|
}
|
2011-07-20 07:18:50 -06:00
|
|
|
|
2022-07-06 07:57:13 -06:00
|
|
|
if (options.veins) {
|
|
|
|
con << "Other vein stone:" << std::endl;
|
|
|
|
printMats<df::inorganic_raw, std::greater>(con, rest, world->raws.inorganics, options);
|
|
|
|
}
|
2011-07-20 07:18:50 -06:00
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result prospector (color_ostream &out, vector <string> & parameters);
|
2010-06-20 16:31:43 -06:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
2011-06-26 20:49:56 -06:00
|
|
|
{
|
2012-01-28 05:03:56 -07:00
|
|
|
commands.push_back(PluginCommand(
|
2022-07-29 00:12:11 -06:00
|
|
|
"prospect",
|
|
|
|
"Show raw resources available on the map.",
|
|
|
|
prospector));
|
2011-06-26 20:49:56 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2011-06-26 20:49:56 -06:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-02 11:14:49 -07:00
|
|
|
static coord2d biome_delta[] = {
|
|
|
|
coord2d(-1,1), coord2d(0,1), coord2d(1,1),
|
|
|
|
coord2d(-1,0), coord2d(0,0), coord2d(1,0),
|
|
|
|
coord2d(-1,-1), coord2d(0,-1), coord2d(1,-1)
|
|
|
|
};
|
|
|
|
|
2012-08-27 13:03:17 -06:00
|
|
|
struct EmbarkTileLayout {
|
2012-08-28 01:52:54 -06:00
|
|
|
coord2d biome_off, biome_pos;
|
|
|
|
df::region_map_entry *biome;
|
2013-10-25 04:37:37 -06:00
|
|
|
df::world_geo_biome *geo_biome;
|
2012-08-28 01:52:54 -06:00
|
|
|
int elevation, max_soil_depth;
|
2012-08-27 13:03:17 -06:00
|
|
|
int min_z, base_z;
|
|
|
|
std::map<int, float> penalty;
|
|
|
|
};
|
|
|
|
|
2013-10-25 04:37:37 -06:00
|
|
|
static df::world_region_details *get_details(df::world_data *data, df::coord2d pos)
|
|
|
|
{
|
|
|
|
int d_idx = linear_index(data->region_details, &df::world_region_details::pos, pos);
|
|
|
|
return vector_get(data->region_details, d_idx);
|
|
|
|
}
|
|
|
|
|
2012-08-27 13:03:17 -06:00
|
|
|
bool estimate_underground(color_ostream &out, EmbarkTileLayout &tile, df::world_region_details *details, int x, int y)
|
|
|
|
{
|
2018-07-20 22:27:11 -06:00
|
|
|
if (x < 0 || y < 0 || x > 15 || y > 15) {
|
|
|
|
out.printerr("Invalid embark coordinates: x=%i, y=%i\n", x, y);
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-28 01:52:54 -06:00
|
|
|
// Find actual biome
|
|
|
|
int bv = clip_range(details->biome[x][y] & 15, 1, 9);
|
|
|
|
tile.biome_off = biome_delta[bv-1];
|
|
|
|
|
|
|
|
df::world_data *data = world->world_data;
|
|
|
|
int bx = clip_range(details->pos.x + tile.biome_off.x, 0, data->world_width-1);
|
|
|
|
int by = clip_range(details->pos.y + tile.biome_off.y, 0, data->world_height-1);
|
|
|
|
tile.biome_pos = coord2d(bx, by);
|
|
|
|
tile.biome = &data->region_map[bx][by];
|
|
|
|
|
2013-10-25 04:37:37 -06:00
|
|
|
tile.geo_biome = df::world_geo_biome::find(tile.biome->geo_index);
|
|
|
|
|
2012-08-28 01:52:54 -06:00
|
|
|
// Compute surface elevation
|
2013-10-25 04:37:37 -06:00
|
|
|
tile.elevation = details->elevation[x][y];
|
|
|
|
tile.max_soil_depth = std::max((154-tile.elevation)/5,1);
|
2012-08-27 13:03:17 -06:00
|
|
|
tile.penalty.clear();
|
|
|
|
|
2013-10-25 04:37:37 -06:00
|
|
|
// Special biome adjustments
|
|
|
|
if (!tile.biome->flags.is_set(region_map_entry_flags::is_lake))
|
|
|
|
{
|
|
|
|
// Mountain biome
|
|
|
|
if (tile.biome->elevation >= 150)
|
|
|
|
tile.max_soil_depth = 0;
|
|
|
|
// Ocean biome
|
|
|
|
else if (tile.biome->elevation < 100)
|
|
|
|
{
|
|
|
|
if (tile.elevation == 99)
|
|
|
|
tile.elevation = 98;
|
|
|
|
|
|
|
|
if (tile.geo_biome && (tile.geo_biome->unk1 == 4 || tile.geo_biome->unk1 == 5))
|
|
|
|
{
|
|
|
|
auto b_details = get_details(data, tile.biome_pos);
|
|
|
|
|
|
|
|
if (b_details && b_details->unk12e8 < 500)
|
|
|
|
tile.max_soil_depth = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tile.base_z = tile.elevation-1;
|
|
|
|
|
2012-08-27 13:03:17 -06:00
|
|
|
auto &features = details->features[x][y];
|
|
|
|
|
|
|
|
// Collect global feature layer depths and apply penalties
|
|
|
|
std::map<int, int> layer_bottom, layer_top;
|
|
|
|
bool sea_found = false;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < features.size(); i++)
|
|
|
|
{
|
|
|
|
auto feature = features[i];
|
|
|
|
auto layer = df::world_underground_region::find(feature->layer);
|
|
|
|
if (!layer || feature->min_z == -30000) continue;
|
|
|
|
|
|
|
|
layer_bottom[layer->layer_depth] = feature->min_z;
|
|
|
|
layer_top[layer->layer_depth] = feature->max_z;
|
|
|
|
tile.base_z = std::min(tile.base_z, (int)feature->min_z);
|
|
|
|
|
|
|
|
float penalty = 1.0f;
|
|
|
|
switch (layer->type) {
|
|
|
|
case df::world_underground_region::Cavern:
|
|
|
|
penalty = 0.75f;
|
|
|
|
break;
|
|
|
|
case df::world_underground_region::MagmaSea:
|
|
|
|
sea_found = true;
|
|
|
|
tile.min_z = feature->min_z;
|
|
|
|
for (int i = feature->min_z; i <= feature->max_z; i++)
|
|
|
|
tile.penalty[i] = 0.2 + 0.6f*(i-feature->min_z)/(feature->max_z-feature->min_z+1);
|
|
|
|
break;
|
|
|
|
case df::world_underground_region::Underworld:
|
|
|
|
penalty = 0.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (penalty != 1.0f)
|
|
|
|
{
|
|
|
|
for (int i = feature->min_z; i <= feature->max_z; i++)
|
|
|
|
tile.penalty[i] = penalty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sea_found)
|
|
|
|
{
|
2013-10-25 04:37:37 -06:00
|
|
|
out.printerr("Could not find magma sea; depth may be incorrect.\n");
|
|
|
|
tile.min_z = tile.base_z;
|
2012-08-27 13:03:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Scan for big local features and apply their penalties
|
|
|
|
for (size_t i = 0; i < features.size(); i++)
|
|
|
|
{
|
|
|
|
auto feature = features[i];
|
|
|
|
auto lfeature = Maps::getLocalInitFeature(details->pos, feature->feature_idx);
|
|
|
|
if (!lfeature)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (lfeature->getType())
|
|
|
|
{
|
|
|
|
case feature_type::pit:
|
|
|
|
case feature_type::magma_pool:
|
|
|
|
case feature_type::volcano:
|
|
|
|
for (int i = layer_bottom[lfeature->end_depth];
|
|
|
|
i <= layer_top[lfeature->start_depth]; i++)
|
|
|
|
tile.penalty[i] = std::min(0.4f, map_find(tile.penalty, i, 1.0f));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_materials(EmbarkTileLayout &tile, matdata &data, float amount, int min_z, int max_z)
|
|
|
|
{
|
|
|
|
for (int z = min_z; z <= max_z; z++)
|
2021-02-08 06:45:49 -07:00
|
|
|
data.add(z, map_find(tile.penalty, z, 1) * amount);
|
2012-08-27 13:03:17 -06:00
|
|
|
}
|
|
|
|
|
2012-08-28 01:52:54 -06:00
|
|
|
bool estimate_materials(color_ostream &out, EmbarkTileLayout &tile, MatMap &layerMats, MatMap &veinMats)
|
2012-08-27 13:03:17 -06:00
|
|
|
{
|
|
|
|
using namespace geo_layer_type;
|
|
|
|
|
2013-10-25 04:37:37 -06:00
|
|
|
df::world_geo_biome *geo_biome = tile.geo_biome;
|
2012-08-27 13:03:17 -06:00
|
|
|
|
|
|
|
if (!geo_biome)
|
|
|
|
{
|
2012-08-28 01:52:54 -06:00
|
|
|
out.printerr("Region geo-biome not found: (%d,%d)\n",
|
|
|
|
tile.biome_pos.x, tile.biome_pos.y);
|
2012-08-27 13:03:17 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// soil depth increases by 1 every 5 levels below 150
|
2013-10-25 04:37:37 -06:00
|
|
|
unsigned nlayers = std::min<unsigned>(16, geo_biome->layers.size());
|
|
|
|
int soil_size = 0;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < nlayers; i++)
|
|
|
|
{
|
|
|
|
auto layer = geo_biome->layers[i];
|
|
|
|
if (layer->type == SOIL || layer->type == SOIL_SAND)
|
|
|
|
soil_size += layer->top_height - layer->bottom_height + 1;
|
|
|
|
}
|
2012-08-27 13:03:17 -06:00
|
|
|
|
2013-10-25 04:37:37 -06:00
|
|
|
// Compute shifts for layers in the stack
|
|
|
|
int soil_erosion = soil_size - std::min(soil_size,tile.max_soil_depth);
|
|
|
|
int layer_shift[16];
|
|
|
|
int cur_shift = tile.elevation+soil_erosion-1;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < nlayers; i++)
|
2012-08-27 13:03:17 -06:00
|
|
|
{
|
|
|
|
auto layer = geo_biome->layers[i];
|
2013-10-25 04:37:37 -06:00
|
|
|
layer_shift[i] = cur_shift;
|
|
|
|
|
|
|
|
if (layer->type == SOIL || layer->type == SOIL_SAND)
|
2012-08-27 13:03:17 -06:00
|
|
|
{
|
2013-10-25 04:37:37 -06:00
|
|
|
int size = layer->top_height - layer->bottom_height + 1;
|
|
|
|
|
|
|
|
// This is to replicate the behavior of a probable bug in the
|
|
|
|
// map generation code: if a layer is partially eroded, the
|
|
|
|
// removed levels are in fact transferred to the layer below,
|
|
|
|
// because unlike the case of removing the whole layer, the code
|
|
|
|
// does not execute a loop to shift the lower part of the stack up.
|
|
|
|
if (size > soil_erosion)
|
|
|
|
cur_shift -= soil_erosion;
|
|
|
|
|
|
|
|
soil_erosion -= std::min(soil_erosion, size);
|
2012-08-27 13:03:17 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 04:37:37 -06:00
|
|
|
// Estimate amounts
|
|
|
|
int last_bottom = tile.elevation;
|
2012-08-27 13:03:17 -06:00
|
|
|
|
2013-10-25 04:37:37 -06:00
|
|
|
for (unsigned i = 0; i < nlayers; i++)
|
2012-08-27 13:03:17 -06:00
|
|
|
{
|
|
|
|
auto layer = geo_biome->layers[i];
|
|
|
|
|
2013-10-25 04:37:37 -06:00
|
|
|
int top_z = last_bottom-1;
|
|
|
|
int bottom_z = std::max(layer->bottom_height + layer_shift[i], tile.min_z);
|
|
|
|
if (i+1 == nlayers) // stretch layer if needed
|
2012-08-27 13:03:17 -06:00
|
|
|
bottom_z = tile.min_z;
|
|
|
|
if (top_z < bottom_z)
|
|
|
|
continue;
|
|
|
|
|
2013-10-25 04:37:37 -06:00
|
|
|
last_bottom = bottom_z;
|
|
|
|
|
2012-08-27 13:03:17 -06:00
|
|
|
float layer_size = 48*48;
|
|
|
|
|
|
|
|
int sums[ENUM_LAST_ITEM(inclusion_type)+1] = { 0 };
|
2021-02-08 06:45:49 -07:00
|
|
|
// Small clusters actually belong to different groups depending on whether they are enclosed by layers, clusters, or veins.
|
|
|
|
// Similarly, veins belong to different groups depending on whether they are enclosed by layers or clusters.
|
|
|
|
// However, these fine details probably drown in the uncertainty inherent in estimating amounts based on RNG distributed proportions.
|
2012-08-27 13:03:17 -06:00
|
|
|
|
|
|
|
for (unsigned j = 0; j < layer->vein_mat.size(); j++)
|
|
|
|
if (is_valid_enum_item<df::inclusion_type>(layer->vein_type[j]))
|
|
|
|
sums[layer->vein_type[j]] += layer->vein_unk_38[j];
|
|
|
|
|
|
|
|
for (unsigned j = 0; j < layer->vein_mat.size(); j++)
|
|
|
|
{
|
|
|
|
// TODO: find out how to estimate the real density
|
|
|
|
// this code assumes that vein_unk_38 is the weight
|
|
|
|
// used when choosing the vein material
|
|
|
|
float size = float(layer->vein_unk_38[j]);
|
|
|
|
df::inclusion_type type = layer->vein_type[j];
|
|
|
|
|
2021-02-08 06:45:49 -07:00
|
|
|
// There doesn't seem to be any relation between mineral scarcity and the number or size of clusters and veins,
|
|
|
|
// apart from when it leads to them being completely absent, e.g. either there are 10 small clusters or there are none.
|
2012-08-27 13:03:17 -06:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case inclusion_type::VEIN:
|
2021-02-08 06:45:49 -07:00
|
|
|
if (layer->vein_nested_in[j] == -1) { // Veins directly in the layer, i.e. the normal case
|
|
|
|
// 2-4 veins with a guessed average of 100 tiles each
|
|
|
|
size = size * 300 / sums[type];
|
|
|
|
}
|
|
|
|
else { // Should only be veins in clusters
|
|
|
|
// 1 vein with a very shaky guessed average of 50 tiles
|
|
|
|
// TODO: Veins in clusters do not share the pool with normal veins but are added on top of it, but this will have to do for now
|
|
|
|
size = size * 50 / sums[type];
|
|
|
|
}
|
2012-08-27 13:03:17 -06:00
|
|
|
break;
|
|
|
|
case inclusion_type::CLUSTER:
|
2021-02-08 06:45:49 -07:00
|
|
|
// 1 cluster of 750 tiles avg. The average size can be refined.
|
|
|
|
size = size * 750 / sums[type];
|
2012-08-27 13:03:17 -06:00
|
|
|
break;
|
|
|
|
case inclusion_type::CLUSTER_SMALL:
|
2021-02-08 06:45:49 -07:00
|
|
|
if (layer->vein_nested_in[j] == -1 ||
|
|
|
|
layer->vein_type[layer->vein_nested_in[j]] != inclusion_type::VEIN) {
|
|
|
|
// Small clusters in the layer and in clusters share a common pool of 10 clusters
|
|
|
|
// An estimate is that the average sum of these is 52, but there is room for refinement
|
|
|
|
size = size * 52 / sums[type];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// A very shaky guess of an average of 3 clusters with 15.6->16 tiles
|
|
|
|
// TODO: Small clusters in veins appear in addition to the regular set, but this will have to do for now
|
|
|
|
size = size * 16 / sums[type];
|
|
|
|
}
|
2012-08-27 13:03:17 -06:00
|
|
|
break;
|
|
|
|
case inclusion_type::CLUSTER_ONE:
|
2021-02-08 06:45:49 -07:00
|
|
|
if (layer->vein_nested_in[j] == -1 ||
|
|
|
|
layer->vein_type[layer->vein_nested_in[j]] != inclusion_type::CLUSTER_SMALL) {
|
|
|
|
// Doesn't happen with vanilla raws, so this is just a wild guess that it might happen 5 times
|
|
|
|
size = size * 5 / sums[type];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Vanilla only has single clusters nested in small ones. We weigh the estimate based on the proportion of
|
|
|
|
// the small clusters out of the 10 standard ones. Note that this does not distinguish between enclosing small
|
|
|
|
// clusters that are actually in standard pool of 10 and those in veins (TODO)
|
|
|
|
size = size * layer->vein_unk_38[layer->vein_nested_in[j]] * 10 / sums[inclusion_type::CLUSTER_SMALL] / sums[type];
|
|
|
|
}
|
2012-08-27 13:03:17 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// shouldn't actually happen
|
|
|
|
size = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
layer_size -= size;
|
|
|
|
|
|
|
|
add_materials(tile, veinMats[layer->vein_mat[j]], size, bottom_z, top_z);
|
|
|
|
}
|
|
|
|
|
|
|
|
add_materials(tile, layerMats[layer->mat_index], layer_size, bottom_z, top_z);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-07-06 07:57:13 -06:00
|
|
|
static command_result embark_prospector(color_ostream &out,
|
|
|
|
df::viewscreen_choose_start_sitest *screen,
|
|
|
|
const prospect_options &options)
|
2012-02-02 11:14:49 -07:00
|
|
|
{
|
|
|
|
if (!world || !world->world_data)
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("World data is not available.\n");
|
2012-02-02 11:14:49 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::world_data *data = world->world_data;
|
2014-07-21 12:18:29 -06:00
|
|
|
coord2d cur_region = screen->location.region_pos;
|
2013-10-25 04:37:37 -06:00
|
|
|
auto cur_details = get_details(data, cur_region);
|
2012-02-02 11:14:49 -07:00
|
|
|
|
|
|
|
if (!cur_details)
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Current region details are not available.\n");
|
2012-02-02 11:14:49 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-08-27 13:03:17 -06:00
|
|
|
// Compute material maps
|
|
|
|
MatMap layerMats;
|
|
|
|
MatMap veinMats;
|
|
|
|
matdata world_bottom;
|
|
|
|
|
2012-02-02 11:14:49 -07:00
|
|
|
// Compute biomes
|
|
|
|
std::map<coord2d, int> biomes;
|
|
|
|
|
2018-07-20 22:27:11 -06:00
|
|
|
for (int x = screen->location.embark_pos_min.x; x <= 15 && x <= screen->location.embark_pos_max.x; x++)
|
2012-02-02 11:14:49 -07:00
|
|
|
{
|
2018-07-20 22:27:11 -06:00
|
|
|
for (int y = screen->location.embark_pos_min.y; y <= 15 && y <= screen->location.embark_pos_max.y; y++)
|
2012-02-02 11:14:49 -07:00
|
|
|
{
|
2012-08-27 13:03:17 -06:00
|
|
|
EmbarkTileLayout tile;
|
|
|
|
if (!estimate_underground(out, tile, cur_details, x, y) ||
|
2012-08-28 01:52:54 -06:00
|
|
|
!estimate_materials(out, tile, layerMats, veinMats))
|
2012-08-27 13:03:17 -06:00
|
|
|
return CR_FAILURE;
|
2012-02-03 01:48:38 -07:00
|
|
|
|
2012-08-27 13:03:17 -06:00
|
|
|
world_bottom.add(tile.base_z, 0);
|
|
|
|
world_bottom.add(tile.elevation-1, 0);
|
2012-02-02 11:14:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print the report
|
2022-07-06 07:57:13 -06:00
|
|
|
if (options.layers) {
|
|
|
|
out << "Layer materials:" << std::endl;
|
|
|
|
printMats<df::inorganic_raw, shallower>(out, layerMats, world->raws.inorganics, options);
|
|
|
|
}
|
2012-02-02 11:14:49 -07:00
|
|
|
|
2022-07-06 07:57:13 -06:00
|
|
|
if (options.hidden) {
|
2012-03-10 04:55:42 -07:00
|
|
|
DFHack::Materials *mats = Core::getInstance().getMaterials();
|
2022-07-06 07:57:13 -06:00
|
|
|
printVeins(out, veinMats, options);
|
2012-02-02 11:14:49 -07:00
|
|
|
mats->Finish();
|
|
|
|
}
|
|
|
|
|
2012-08-27 13:03:17 -06:00
|
|
|
out << "Embark depth: " << (world_bottom.upper_z-world_bottom.lower_z+1) << " ";
|
|
|
|
printMatdata(out, world_bottom, true);
|
|
|
|
|
|
|
|
out << std::endl << "Warning: the above data is only a very rough estimate." << std::endl;
|
2012-02-02 11:14:49 -07:00
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2022-07-06 07:57:13 -06:00
|
|
|
static command_result map_prospector(color_ostream &con,
|
|
|
|
const prospect_options &options) {
|
2012-01-19 20:44:17 -07:00
|
|
|
if (!Maps::IsValid())
|
2010-03-26 06:01:46 -06:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
con.printerr("Map is not available!\n");
|
2011-06-26 20:49:56 -06:00
|
|
|
return CR_FAILURE;
|
2010-03-26 06:01:46 -06:00
|
|
|
}
|
2012-02-02 11:14:49 -07:00
|
|
|
|
|
|
|
uint32_t x_max = 0, y_max = 0, z_max = 0;
|
2012-01-19 20:44:17 -07:00
|
|
|
Maps::getSize(x_max, y_max, z_max);
|
|
|
|
MapExtras::MapCache map;
|
2010-11-10 18:32:33 -07:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFHack::Materials *mats = Core::getInstance().getMaterials();
|
2011-04-30 15:58:29 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
DFHack::t_feature blockFeatureGlobal;
|
|
|
|
DFHack::t_feature blockFeatureLocal;
|
2010-04-23 17:15:15 -06:00
|
|
|
|
2011-04-30 15:58:29 -06:00
|
|
|
bool hasDemonTemple = false;
|
|
|
|
bool hasLair = false;
|
|
|
|
MatMap baseMats;
|
|
|
|
MatMap layerMats;
|
|
|
|
MatMap veinMats;
|
|
|
|
MatMap plantMats;
|
2011-05-01 21:03:48 -06:00
|
|
|
MatMap treeMats;
|
2011-04-30 15:58:29 -06:00
|
|
|
|
2012-01-17 08:44:48 -07:00
|
|
|
matdata liquidWater;
|
|
|
|
matdata liquidMagma;
|
|
|
|
matdata aquiferTiles;
|
2012-01-20 09:29:51 -07:00
|
|
|
matdata tubeTiles;
|
2012-01-17 08:44:48 -07:00
|
|
|
|
2011-04-30 15:58:29 -06:00
|
|
|
for(uint32_t z = 0; z < z_max; z++)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2011-04-30 15:58:29 -06:00
|
|
|
for(uint32_t b_y = 0; b_y < y_max; b_y++)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2011-04-30 15:58:29 -06:00
|
|
|
for(uint32_t b_x = 0; b_x < x_max; b_x++)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2011-04-30 15:58:29 -06:00
|
|
|
// Get the map block
|
2012-01-20 03:28:00 -07:00
|
|
|
df::coord2d blockCoord(b_x, b_y);
|
2011-04-30 15:58:29 -06:00
|
|
|
MapExtras::Block *b = map.BlockAt(DFHack::DFCoord(b_x, b_y, z));
|
2012-04-10 08:21:19 -06:00
|
|
|
if (!b || !b->is_valid())
|
2011-04-30 15:58:29 -06:00
|
|
|
{
|
2009-09-13 18:02:46 -06:00
|
|
|
continue;
|
2011-04-30 15:58:29 -06:00
|
|
|
}
|
2010-11-10 18:32:33 -07:00
|
|
|
|
2012-04-10 08:21:19 -06:00
|
|
|
// Find features
|
|
|
|
b->GetGlobalFeature(&blockFeatureGlobal);
|
|
|
|
b->GetLocalFeature(&blockFeatureLocal);
|
2011-04-17 03:37:36 -06:00
|
|
|
|
2012-01-21 17:31:15 -07:00
|
|
|
int global_z = world->map.region_z + z;
|
2012-01-17 08:44:48 -07:00
|
|
|
|
2011-04-30 15:58:29 -06:00
|
|
|
// Iterate over all the tiles in the block
|
|
|
|
for(uint32_t y = 0; y < 16; y++)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2011-04-30 15:58:29 -06:00
|
|
|
for(uint32_t x = 0; x < 16; x++)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2012-01-20 03:28:00 -07:00
|
|
|
df::coord2d coord(x, y);
|
2012-01-19 13:11:52 -07:00
|
|
|
df::tile_designation des = b->DesignationAt(coord);
|
|
|
|
df::tile_occupancy occ = b->OccupancyAt(coord);
|
2011-04-30 15:58:29 -06:00
|
|
|
|
|
|
|
// Skip hidden tiles
|
2022-07-06 07:57:13 -06:00
|
|
|
if (!options.hidden && des.bits.hidden)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2011-04-19 17:28:47 -06:00
|
|
|
continue;
|
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
|
|
|
|
// Check for aquifer
|
|
|
|
if (des.bits.water_table)
|
2011-04-19 17:28:47 -06:00
|
|
|
{
|
2012-01-17 08:44:48 -07:00
|
|
|
aquiferTiles.add(global_z);
|
2011-04-19 17:28:47 -06:00
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
|
|
|
|
// Check for lairs
|
|
|
|
if (occ.bits.monster_lair)
|
2011-04-19 17:28:47 -06:00
|
|
|
{
|
2011-04-30 15:58:29 -06:00
|
|
|
hasLair = true;
|
2011-04-17 07:51:52 -06:00
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
|
2012-01-17 08:44:48 -07:00
|
|
|
// Check for liquid
|
|
|
|
if (des.bits.flow_size)
|
|
|
|
{
|
2012-01-21 17:31:15 -07:00
|
|
|
if (des.bits.liquid_type == tile_liquid::Magma)
|
2012-01-17 08:44:48 -07:00
|
|
|
liquidMagma.add(global_z);
|
|
|
|
else
|
|
|
|
liquidWater.add(global_z);
|
|
|
|
}
|
|
|
|
|
2012-04-19 09:17:07 -06:00
|
|
|
df::tiletype type = b->tiletypeAt(coord);
|
2012-02-13 15:56:33 -07:00
|
|
|
df::tiletype_shape tileshape = tileShape(type);
|
|
|
|
df::tiletype_material tilemat = tileMaterial(type);
|
2011-04-30 15:58:29 -06:00
|
|
|
|
|
|
|
// We only care about these types
|
2012-02-13 15:56:33 -07:00
|
|
|
switch (tileshape)
|
2011-04-30 15:58:29 -06:00
|
|
|
{
|
2012-02-13 15:56:33 -07:00
|
|
|
case tiletype_shape::WALL:
|
|
|
|
case tiletype_shape::FORTIFICATION:
|
2011-04-30 15:58:29 -06:00
|
|
|
break;
|
2012-02-13 15:56:33 -07:00
|
|
|
case tiletype_shape::EMPTY:
|
2012-01-20 09:29:51 -07:00
|
|
|
/* A heuristic: tubes inside adamantine have EMPTY:AIR tiles which
|
|
|
|
still have feature_local set. Also check the unrevealed status,
|
|
|
|
so as to exclude any holes mined by the player. */
|
2012-02-13 15:56:33 -07:00
|
|
|
if (tilemat == tiletype_material::AIR &&
|
2012-01-20 09:29:51 -07:00
|
|
|
des.bits.feature_local && des.bits.hidden &&
|
2012-01-21 17:31:15 -07:00
|
|
|
blockFeatureLocal.type == feature_type::deep_special_tube)
|
2012-01-20 09:29:51 -07:00
|
|
|
{
|
|
|
|
tubeTiles.add(global_z);
|
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
default:
|
2011-04-19 17:28:47 -06:00
|
|
|
continue;
|
2011-04-30 15:58:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Count the material type
|
2012-02-13 15:56:33 -07:00
|
|
|
baseMats[tilemat].add(global_z);
|
2011-04-30 15:58:29 -06:00
|
|
|
|
|
|
|
// Find the type of the tile
|
2012-02-13 15:56:33 -07:00
|
|
|
switch (tilemat)
|
2011-04-17 07:51:52 -06:00
|
|
|
{
|
2012-02-13 15:56:33 -07:00
|
|
|
case tiletype_material::SOIL:
|
|
|
|
case tiletype_material::STONE:
|
2012-04-19 09:17:07 -06:00
|
|
|
layerMats[b->layerMaterialAt(coord)].add(global_z);
|
2011-04-30 15:58:29 -06:00
|
|
|
break;
|
2012-02-13 15:56:33 -07:00
|
|
|
case tiletype_material::MINERAL:
|
2012-01-17 08:44:48 -07:00
|
|
|
veinMats[b->veinMaterialAt(coord)].add(global_z);
|
2011-04-30 15:58:29 -06:00
|
|
|
break;
|
2012-02-13 15:56:33 -07:00
|
|
|
case tiletype_material::FEATURE:
|
2012-01-19 20:44:17 -07:00
|
|
|
if (blockFeatureLocal.type != -1 && des.bits.feature_local)
|
2011-04-17 07:51:52 -06:00
|
|
|
{
|
2012-01-21 17:31:15 -07:00
|
|
|
if (blockFeatureLocal.type == feature_type::deep_special_tube
|
2012-01-19 20:44:17 -07:00
|
|
|
&& blockFeatureLocal.main_material == 0) // stone
|
2011-04-17 07:51:52 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
veinMats[blockFeatureLocal.sub_material].add(global_z);
|
2011-04-17 07:51:52 -06:00
|
|
|
}
|
2022-07-06 07:57:13 -06:00
|
|
|
else if (blockFeatureLocal.type == feature_type::deep_surface_portal)
|
2011-04-17 07:51:52 -06:00
|
|
|
{
|
2011-04-30 15:58:29 -06:00
|
|
|
hasDemonTemple = true;
|
2011-04-17 07:51:52 -06:00
|
|
|
}
|
|
|
|
}
|
2010-11-10 18:32:33 -07:00
|
|
|
|
2022-07-06 07:57:13 -06:00
|
|
|
if (blockFeatureGlobal.type != -1 && des.bits.feature_global
|
2017-11-04 07:50:47 -06:00
|
|
|
&& blockFeatureGlobal.type == feature_type::underworld_from_layer
|
2012-01-19 20:44:17 -07:00
|
|
|
&& blockFeatureGlobal.main_material == 0) // stone
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
layerMats[blockFeatureGlobal.sub_material].add(global_z);
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
break;
|
2012-02-13 15:56:33 -07:00
|
|
|
case tiletype_material::LAVA_STONE:
|
2011-04-30 15:58:29 -06:00
|
|
|
// TODO ?
|
|
|
|
break;
|
2012-08-27 13:03:02 -06:00
|
|
|
default:
|
|
|
|
break;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-10 18:32:33 -07:00
|
|
|
|
2011-04-30 15:58:29 -06:00
|
|
|
// Check plants this way, as the other way wasn't getting them all
|
|
|
|
// and we can check visibility more easily here
|
2022-07-06 07:57:13 -06:00
|
|
|
if (options.shrubs)
|
2010-04-23 17:15:15 -06:00
|
|
|
{
|
2014-08-06 08:31:42 -06:00
|
|
|
auto block = Maps::getBlockColumn(b_x,b_y);
|
2012-04-11 02:01:27 -06:00
|
|
|
vector<df::plant *> *plants = block ? &block->plants : NULL;
|
|
|
|
if(plants)
|
2010-04-23 17:15:15 -06:00
|
|
|
{
|
2011-06-19 21:08:21 -06:00
|
|
|
for (PlantList::const_iterator it = plants->begin(); it != plants->end(); it++)
|
2011-03-10 19:09:45 -07:00
|
|
|
{
|
2012-01-21 16:54:57 -07:00
|
|
|
const df::plant & plant = *(*it);
|
2018-04-06 00:18:15 -06:00
|
|
|
if (uint32_t(plant.pos.z) != z)
|
2014-08-06 08:31:42 -06:00
|
|
|
continue;
|
2012-01-21 16:54:57 -07:00
|
|
|
df::coord2d loc(plant.pos.x, plant.pos.y);
|
2011-04-30 15:58:29 -06:00
|
|
|
loc = loc % 16;
|
2022-07-06 07:57:13 -06:00
|
|
|
if (options.hidden || !b->DesignationAt(loc).bits.hidden)
|
2010-04-23 17:15:15 -06:00
|
|
|
{
|
2012-01-21 16:54:57 -07:00
|
|
|
if(plant.flags.bits.is_shrub)
|
2012-01-17 08:44:48 -07:00
|
|
|
plantMats[plant.material].add(global_z);
|
2011-05-01 21:03:48 -06:00
|
|
|
else
|
2012-01-17 08:44:48 -07:00
|
|
|
treeMats[plant.material].add(global_z);
|
2010-04-23 17:15:15 -06:00
|
|
|
}
|
2011-03-10 19:09:45 -07:00
|
|
|
}
|
2010-04-23 17:15:15 -06:00
|
|
|
}
|
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
// Block end
|
|
|
|
} // block x
|
2010-11-10 18:32:33 -07:00
|
|
|
|
2011-04-30 15:58:29 -06:00
|
|
|
// Clean uneeded memory
|
|
|
|
map.trash();
|
|
|
|
} // block y
|
|
|
|
} // z
|
2010-11-10 18:32:33 -07:00
|
|
|
|
2011-04-30 15:58:29 -06:00
|
|
|
MatMap::const_iterator it;
|
2011-04-17 07:51:52 -06:00
|
|
|
|
2022-07-06 07:57:13 -06:00
|
|
|
if (options.summary) {
|
|
|
|
con << "Base materials:" << std::endl;
|
|
|
|
for (it = baseMats.begin(); it != baseMats.end(); ++it)
|
|
|
|
{
|
|
|
|
con << std::setw(25) << ENUM_KEY_STR(tiletype_material,(df::tiletype_material)it->first) << " : " << it->second.count << std::endl;
|
|
|
|
}
|
|
|
|
con << std::endl;
|
2010-03-31 09:31:49 -06:00
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
|
2022-07-06 07:57:13 -06:00
|
|
|
if (options.liquids && (liquidWater.count || liquidMagma.count))
|
2012-01-17 08:44:48 -07:00
|
|
|
{
|
2022-07-06 07:57:13 -06:00
|
|
|
con << "Liquids:" << std::endl;
|
2012-01-17 08:44:48 -07:00
|
|
|
if (liquidWater.count)
|
|
|
|
{
|
|
|
|
con << std::setw(25) << "WATER" << " : ";
|
|
|
|
printMatdata(con, liquidWater);
|
|
|
|
}
|
|
|
|
if (liquidWater.count)
|
|
|
|
{
|
|
|
|
con << std::setw(25) << "MAGMA" << " : ";
|
|
|
|
printMatdata(con, liquidMagma);
|
|
|
|
}
|
2022-07-06 07:57:13 -06:00
|
|
|
con << std::endl;
|
2012-01-17 08:44:48 -07:00
|
|
|
}
|
|
|
|
|
2022-07-06 07:57:13 -06:00
|
|
|
if (options.layers) {
|
|
|
|
con << "Layer materials:" << std::endl;
|
|
|
|
printMats<df::inorganic_raw, shallower>(con, layerMats, world->raws.inorganics, options);
|
2011-04-17 07:51:52 -06:00
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
|
2022-07-06 07:57:13 -06:00
|
|
|
if (options.features) {
|
|
|
|
con << "Features:" << std::endl;
|
|
|
|
|
|
|
|
bool hasFeature = false;
|
2012-01-17 08:44:48 -07:00
|
|
|
if (aquiferTiles.count)
|
|
|
|
{
|
2022-07-06 07:57:13 -06:00
|
|
|
con << std::setw(25) << "Has aquifer" << " : ";
|
|
|
|
if (options.value)
|
|
|
|
con << " ";
|
2012-01-17 08:44:48 -07:00
|
|
|
printMatdata(con, aquiferTiles);
|
2022-07-06 07:57:13 -06:00
|
|
|
hasFeature = true;
|
2012-01-17 08:44:48 -07:00
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
|
2022-07-06 07:57:13 -06:00
|
|
|
if (options.tube && tubeTiles.count)
|
|
|
|
{
|
|
|
|
con << std::setw(25) << "Has HFS tubes" << " : ";
|
|
|
|
if (options.value)
|
|
|
|
con << " ";
|
|
|
|
printMatdata(con, tubeTiles, true);
|
|
|
|
hasFeature = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasDemonTemple)
|
|
|
|
{
|
|
|
|
con << std::setw(25) << "Has demon temple" << std::endl;
|
|
|
|
hasFeature = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasLair)
|
|
|
|
{
|
|
|
|
con << std::setw(25) << "Has lair" << std::endl;
|
|
|
|
hasFeature = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasFeature)
|
|
|
|
con << std::setw(25) << "None" << std::endl;
|
|
|
|
|
|
|
|
con << std::endl;
|
2012-01-20 09:29:51 -07:00
|
|
|
}
|
|
|
|
|
2022-07-06 07:57:13 -06:00
|
|
|
printVeins(con, veinMats, options);
|
|
|
|
|
|
|
|
if (options.shrubs) {
|
|
|
|
con << "Shrubs:" << std::endl;
|
|
|
|
printMats<df::plant_raw, std::greater>(con, plantMats, world->raws.plants.all, options);
|
2011-04-17 07:51:52 -06:00
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
|
2022-07-06 07:57:13 -06:00
|
|
|
if (options.trees) {
|
|
|
|
con << "Wood in trees:" << std::endl;
|
|
|
|
printMats<df::plant_raw, std::greater>(con, treeMats, world->raws.plants.all, options);
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
mats->Finish();
|
2022-07-06 07:57:13 -06:00
|
|
|
|
2011-06-26 20:49:56 -06:00
|
|
|
return CR_OK;
|
2009-12-13 14:03:19 -07:00
|
|
|
}
|
2022-07-06 07:57:13 -06:00
|
|
|
|
|
|
|
static bool get_options(color_ostream &out,
|
|
|
|
prospect_options &opts,
|
|
|
|
const vector<string> ¶meters)
|
|
|
|
{
|
|
|
|
auto L = Lua::Core::State;
|
|
|
|
Lua::StackUnwinder top(L);
|
|
|
|
|
|
|
|
if (!lua_checkstack(L, parameters.size() + 2) ||
|
|
|
|
!Lua::PushModulePublic(
|
|
|
|
out, L, "plugins.prospector", "parse_commandline")) {
|
|
|
|
out.printerr("Failed to load prospector Lua code\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Lua::Push(L, &opts);
|
|
|
|
|
|
|
|
for (const string ¶m : parameters)
|
|
|
|
Lua::Push(L, param);
|
|
|
|
|
|
|
|
if (!Lua::SafeCall(out, L, parameters.size() + 1, 0))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result prospector(color_ostream &con, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
CoreSuspender suspend;
|
|
|
|
|
|
|
|
prospect_options options;
|
|
|
|
if (!get_options(con, options, parameters) || options.help)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
// Embark screen active: estimate using world geology data
|
|
|
|
auto screen = Gui::getViewscreenByType<df::viewscreen_choose_start_sitest>(0);
|
|
|
|
return screen ?
|
|
|
|
embark_prospector(con, screen, options) :
|
|
|
|
map_prospector(con, options);
|
|
|
|
}
|