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>
|
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"
|
|
|
|
#include "PluginManager.h"
|
|
|
|
#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"
|
|
|
|
#include "df/world_geo_biome.h"
|
|
|
|
#include "df/world_geo_layer.h"
|
|
|
|
#include "df/inclusion_type.h"
|
|
|
|
#include "df/viewscreen_choose_start_sitest.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-01-21 09:12:26 -07:00
|
|
|
using df::global::world;
|
2012-02-02 11:14:49 -07:00
|
|
|
using df::coord2d;
|
2011-04-30 15:58:29 -06:00
|
|
|
|
2011-10-24 18:39:15 -06:00
|
|
|
struct matdata
|
|
|
|
{
|
|
|
|
const static int invalid_z = -30000;
|
|
|
|
matdata()
|
|
|
|
{
|
|
|
|
count = 0;
|
|
|
|
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;
|
|
|
|
}
|
2012-02-02 11:14:49 -07:00
|
|
|
unsigned int add( int z_level = invalid_z, int delta = 1 )
|
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
|
|
|
}
|
|
|
|
unsigned int count;
|
|
|
|
int lower_z;
|
|
|
|
int upper_z;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator>(const matdata & q1, const matdata & q2)
|
|
|
|
{
|
|
|
|
return q1.count > q2.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
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>
|
|
|
|
bool operator()(const std::pair<T1, T2>& left, const std::pair<T1, T2>& right)
|
|
|
|
{
|
|
|
|
return P<T2>()(left.second, right.second);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-17 08:56:52 -07:00
|
|
|
static void printMatdata(DFHack::Console & con, const matdata &data)
|
2012-01-17 08:44:48 -07:00
|
|
|
{
|
|
|
|
con << std::setw(9) << data.count;
|
|
|
|
|
|
|
|
if(data.lower_z != data.upper_z)
|
|
|
|
con <<" Z:" << std::setw(4) << data.lower_z << ".." << data.upper_z << std::endl;
|
|
|
|
else
|
|
|
|
con <<" Z:" << std::setw(4) << data.lower_z << std::endl;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-11-02 21:30:59 -06:00
|
|
|
template <typename T>
|
2012-01-17 08:56:52 -07:00
|
|
|
void printMats(DFHack::Console & con, MatMap &mat, std::vector<T*> &materials, bool show_value)
|
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(),
|
|
|
|
compare_pair_second<>());
|
|
|
|
for (MatSorter::const_iterator it = sorting_vector.begin();
|
|
|
|
it != sorting_vector.end(); ++it)
|
2010-06-20 16:31:43 -06:00
|
|
|
{
|
2011-05-24 21:13:24 -06:00
|
|
|
if(it->first >= materials.size())
|
|
|
|
{
|
2011-07-20 07:18:50 -06:00
|
|
|
con << "Bad index: " << it->first << " out of "
|
|
|
|
<< 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 << " : ";
|
2012-01-17 08:56:52 -07:00
|
|
|
if (show_value)
|
|
|
|
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
|
|
|
|
|
|
|
void printVeins(DFHack::Console & con, MatMap &mat_map,
|
2012-01-17 08:56:52 -07:00
|
|
|
DFHack::Materials* mats, bool show_value)
|
2011-07-20 07:18:50 -06:00
|
|
|
{
|
|
|
|
MatMap ores;
|
|
|
|
MatMap gems;
|
|
|
|
MatMap rest;
|
|
|
|
|
|
|
|
for (MatMap::const_iterator it = mat_map.begin(); it != mat_map.end(); ++it)
|
|
|
|
{
|
2012-01-21 09:12:26 -07:00
|
|
|
df::inorganic_raw *gloss = world->raws.inorganics[it->first];
|
2011-07-20 07:18:50 -06:00
|
|
|
|
2012-01-21 09:12:26 -07:00
|
|
|
if (gloss->material.isGem())
|
2011-07-20 07:18:50 -06:00
|
|
|
gems[it->first] = it->second;
|
2011-11-02 21:30:59 -06:00
|
|
|
else if (gloss->isOre())
|
2011-07-21 19:00:56 -06:00
|
|
|
ores[it->first] = it->second;
|
2011-07-20 07:18:50 -06:00
|
|
|
else
|
|
|
|
rest[it->first] = it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
con << "Ores:" << std::endl;
|
2012-01-21 09:12:26 -07:00
|
|
|
printMats(con, ores, world->raws.inorganics, show_value);
|
2011-07-20 07:18:50 -06:00
|
|
|
|
|
|
|
con << "Gems:" << std::endl;
|
2012-01-21 09:12:26 -07:00
|
|
|
printMats(con, gems, world->raws.inorganics, show_value);
|
2011-07-20 07:18:50 -06:00
|
|
|
|
|
|
|
con << "Other vein stone:" << std::endl;
|
2012-01-21 09:12:26 -07:00
|
|
|
printMats(con, rest, world->raws.inorganics, show_value);
|
2011-07-20 07:18:50 -06:00
|
|
|
}
|
|
|
|
|
2012-02-13 21:54:08 -07:00
|
|
|
command_result prospector (Core * c, vector <string> & parameters);
|
2010-06-20 16:31:43 -06:00
|
|
|
|
2011-06-19 21:08:21 -06:00
|
|
|
DFhackCExport const char * plugin_name ( void )
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2011-06-19 21:08:21 -06:00
|
|
|
return "prospector";
|
|
|
|
}
|
|
|
|
|
2011-06-26 20:49:56 -06:00
|
|
|
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
commands.clear();
|
2012-01-28 05:03:56 -07:00
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"prospect", "Show stats of available raw resources.",
|
|
|
|
prospector, false,
|
|
|
|
" Prints a big list of all the present minerals.\n"
|
|
|
|
" By default, only the visible part of the map is scanned.\n"
|
|
|
|
"Options:\n"
|
|
|
|
" all - Scan the whole map, as if it was revealed.\n"
|
|
|
|
" value - Show material value in the output. Most useful for gems.\n"
|
|
|
|
" hell - Show the Z range of HFS tubes. Implies 'all'.\n"
|
2012-02-02 11:14:49 -07:00
|
|
|
"Pre-embark estimate:\n"
|
|
|
|
" If called during the embark selection screen, displays\n"
|
|
|
|
" an estimate of layer stone availability. If the 'all'\n"
|
|
|
|
" option is specified, also estimates veins.\n"
|
|
|
|
" The estimate is computed either for 1 embark tile of the\n"
|
|
|
|
" blinking biome, or for all tiles of the embark rectangle.\n"
|
2012-01-28 05:03:56 -07:00
|
|
|
));
|
2011-06-26 20:49:56 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
};
|
|
|
|
|
|
|
|
static command_result embark_prospector(DFHack::Core *c, df::viewscreen_choose_start_sitest *screen,
|
|
|
|
bool showHidden, bool showValue)
|
|
|
|
{
|
|
|
|
if (!world || !world->world_data)
|
|
|
|
{
|
|
|
|
c->con.printerr("World data is not available.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::world_data *data = world->world_data;
|
|
|
|
coord2d cur_region = screen->region_pos;
|
|
|
|
int d_idx = linear_index(data->region_details, &df::world_region_details::pos, cur_region);
|
|
|
|
auto cur_details = vector_get(data->region_details, d_idx);
|
|
|
|
|
|
|
|
if (!cur_details)
|
|
|
|
{
|
|
|
|
c->con.printerr("Current region details are not available.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute biomes
|
|
|
|
std::map<coord2d, int> biomes;
|
|
|
|
|
|
|
|
if (screen->biome_highlighted)
|
|
|
|
{
|
|
|
|
c->con.print("Processing one embark tile of biome F%d.\n\n", screen->biome_idx+1);
|
|
|
|
biomes[screen->biome_rgn[screen->biome_idx]]++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int x = screen->embark_pos_min.x; x <= screen->embark_pos_max.x; x++)
|
|
|
|
{
|
|
|
|
for (int y = screen->embark_pos_min.y; y <= screen->embark_pos_max.y; y++)
|
|
|
|
{
|
|
|
|
int bv = clip_range(cur_details->biome[x][y], 1, 9);
|
|
|
|
biomes[cur_region + biome_delta[bv-1]]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute material maps
|
|
|
|
MatMap layerMats;
|
|
|
|
MatMap veinMats;
|
|
|
|
|
|
|
|
for (auto biome_it = biomes.begin(); biome_it != biomes.end(); ++biome_it)
|
|
|
|
{
|
|
|
|
int bx = clip_range(biome_it->first.x, 0, data->world_width-1);
|
|
|
|
int by = clip_range(biome_it->first.y, 0, data->world_height-1);
|
|
|
|
auto ®ion = data->region_map[bx][by];
|
|
|
|
df::world_geo_biome *geo_biome = df::world_geo_biome::find(region.geo_index);
|
|
|
|
|
|
|
|
if (!geo_biome)
|
|
|
|
{
|
|
|
|
c->con.printerr("Region geo-biome not found: (%d,%d)\n", bx, by);
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cnt = biome_it->second;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < geo_biome->layers.size(); i++)
|
|
|
|
{
|
|
|
|
auto layer = geo_biome->layers[i];
|
|
|
|
|
2012-02-03 00:43:13 -07:00
|
|
|
layerMats[layer->mat_index].add(layer->bottom_height, 0);
|
|
|
|
|
|
|
|
int level_cnt = layer->top_height - layer->bottom_height + 1;
|
|
|
|
int layer_size = 48*48*cnt*level_cnt;
|
2012-02-02 11:14:49 -07:00
|
|
|
|
2012-02-03 01:48:38 -07:00
|
|
|
int sums[ENUM_LAST_ITEM(inclusion_type)+1] = { 0 };
|
|
|
|
|
|
|
|
for (unsigned j = 0; j < layer->vein_mat.size(); j++)
|
|
|
|
if (inclusion_type::is_valid(layer->vein_type[j]))
|
|
|
|
sums[layer->vein_type[j]] += layer->vein_unk_38[j];
|
|
|
|
|
2012-02-03 00:43:13 -07:00
|
|
|
for (unsigned j = 0; j < layer->vein_mat.size(); j++)
|
|
|
|
{
|
|
|
|
// TODO: find out how to estimate the real density
|
2012-02-03 01:48:38 -07:00
|
|
|
// this code assumes that vein_unk_38 is the weight
|
|
|
|
// used when choosing the vein material
|
|
|
|
int size = layer->vein_unk_38[j]*cnt*level_cnt;
|
|
|
|
df::inclusion_type type = layer->vein_type[j];
|
|
|
|
|
|
|
|
switch (type)
|
2012-02-02 11:14:49 -07:00
|
|
|
{
|
2012-02-03 00:43:13 -07:00
|
|
|
case inclusion_type::VEIN:
|
2012-02-03 01:48:38 -07:00
|
|
|
// 3 veins of 80 tiles avg
|
|
|
|
size = size * 80 * 3 / sums[type];
|
2012-02-03 00:43:13 -07:00
|
|
|
break;
|
|
|
|
case inclusion_type::CLUSTER:
|
2012-02-03 01:48:38 -07:00
|
|
|
// 1 cluster of 700 tiles avg
|
|
|
|
size = size * 700 * 1 / sums[type];
|
2012-02-03 00:43:13 -07:00
|
|
|
break;
|
|
|
|
case inclusion_type::CLUSTER_SMALL:
|
2012-02-03 01:48:38 -07:00
|
|
|
size = size * 6 * 7 / sums[type];
|
2012-02-03 00:43:13 -07:00
|
|
|
break;
|
|
|
|
case inclusion_type::CLUSTER_ONE:
|
2012-02-03 01:48:38 -07:00
|
|
|
size = size * 1 * 5 / sums[type];
|
2012-02-03 00:43:13 -07:00
|
|
|
break;
|
2012-02-03 01:48:38 -07:00
|
|
|
default:
|
|
|
|
// shouldn't actually happen
|
|
|
|
size = cnt*level_cnt;
|
2012-02-02 11:14:49 -07:00
|
|
|
}
|
2012-02-03 00:43:13 -07:00
|
|
|
|
|
|
|
veinMats[layer->vein_mat[j]].add(layer->bottom_height, 0);
|
|
|
|
veinMats[layer->vein_mat[j]].add(layer->top_height, size);
|
|
|
|
|
|
|
|
layer_size -= size;
|
2012-02-02 11:14:49 -07:00
|
|
|
}
|
2012-02-03 00:43:13 -07:00
|
|
|
|
|
|
|
layerMats[layer->mat_index].add(layer->top_height, std::max(0,layer_size));
|
2012-02-02 11:14:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print the report
|
|
|
|
c->con << "Layer materials:" << std::endl;
|
|
|
|
printMats(c->con, layerMats, world->raws.inorganics, showValue);
|
|
|
|
|
|
|
|
if (showHidden) {
|
|
|
|
DFHack::Materials *mats = c->getMaterials();
|
|
|
|
printVeins(c->con, veinMats, mats, showValue);
|
|
|
|
mats->Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
c->con << "Warning: the above data is only a very rough estimate." << std::endl;
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-13 21:54:08 -07:00
|
|
|
command_result prospector (DFHack::Core * c, vector <string> & parameters)
|
2011-06-19 21:08:21 -06:00
|
|
|
{
|
2011-06-26 20:49:56 -06:00
|
|
|
bool showHidden = false;
|
2011-04-30 15:58:29 -06:00
|
|
|
bool showPlants = true;
|
|
|
|
bool showSlade = true;
|
|
|
|
bool showTemple = true;
|
2012-01-17 08:56:52 -07:00
|
|
|
bool showValue = false;
|
2012-01-20 09:29:51 -07:00
|
|
|
bool showTube = false;
|
2011-07-13 20:05:27 -06:00
|
|
|
Console & con = c->con;
|
2012-01-31 09:55:38 -07:00
|
|
|
for(size_t i = 0; i < parameters.size();i++)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2012-01-17 08:56:52 -07:00
|
|
|
if (parameters[i] == "all")
|
2011-08-08 17:50:22 -06:00
|
|
|
{
|
|
|
|
showHidden = true;
|
|
|
|
}
|
2012-01-20 09:29:51 -07:00
|
|
|
else if (parameters[i] == "value")
|
2012-01-17 08:56:52 -07:00
|
|
|
{
|
|
|
|
showValue = true;
|
|
|
|
}
|
2012-01-20 09:29:51 -07:00
|
|
|
else if (parameters[i] == "hell")
|
|
|
|
{
|
|
|
|
showHidden = showTube = true;
|
|
|
|
}
|
2012-01-28 05:03:56 -07:00
|
|
|
else
|
|
|
|
return CR_WRONG_USAGE;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
2012-01-21 17:31:15 -07:00
|
|
|
CoreSuspender suspend(c);
|
2012-02-02 11:14:49 -07:00
|
|
|
|
|
|
|
// Embark screen active: estimate using world geology data
|
|
|
|
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_choose_start_sitest, c->getTopViewscreen()))
|
|
|
|
return embark_prospector(c, screen, showHidden, showValue);
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
if (!Maps::IsValid())
|
2010-03-26 06:01:46 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
c->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
|
|
|
|
2011-06-19 21:08:21 -06:00
|
|
|
DFHack::Materials *mats = c->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 hasAquifer = false;
|
|
|
|
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
|
|
|
uint32_t vegCount = 0;
|
2010-11-10 18:32:33 -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));
|
|
|
|
if (!b || !b->valid)
|
|
|
|
{
|
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
|
|
|
|
2011-04-30 15:58:29 -06:00
|
|
|
{ // Find features
|
2012-01-19 20:44:17 -07:00
|
|
|
uint32_t index = b->raw.global_feature;
|
|
|
|
if (index != -1)
|
|
|
|
Maps::GetGlobalFeature(blockFeatureGlobal, index);
|
2010-11-10 18:32:33 -07:00
|
|
|
|
2011-04-30 15:58:29 -06:00
|
|
|
index = b->raw.local_feature;
|
2012-01-19 20:44:17 -07:00
|
|
|
if (index != -1)
|
|
|
|
Maps::GetLocalFeature(blockFeatureLocal, blockCoord, index);
|
2011-04-17 07:51:52 -06:00
|
|
|
}
|
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
|
|
|
|
if (!showHidden && 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
|
|
|
{
|
2011-04-30 15:58:29 -06:00
|
|
|
hasAquifer = true;
|
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-02-13 15:56:33 -07:00
|
|
|
df::tiletype type = b->TileTypeAt(coord);
|
|
|
|
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-01-17 08:44:48 -07:00
|
|
|
layerMats[b->baseMaterialAt(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
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
else if (showTemple
|
2012-01-21 17:31:15 -07:00
|
|
|
&& 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
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
if (showSlade && blockFeatureGlobal.type != -1 && des.bits.feature_global
|
2012-01-21 17:31:15 -07:00
|
|
|
&& blockFeatureGlobal.type == feature_type::feature_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;
|
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
|
|
|
|
if (showPlants)
|
2010-04-23 17:15:15 -06:00
|
|
|
{
|
2011-06-19 21:08:21 -06:00
|
|
|
PlantList * plants;
|
2012-01-19 20:44:17 -07:00
|
|
|
if (Maps::ReadVegetation(b_x, b_y, z, 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);
|
|
|
|
df::coord2d loc(plant.pos.x, plant.pos.y);
|
2011-04-30 15:58:29 -06:00
|
|
|
loc = loc % 16;
|
|
|
|
if (showHidden || !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
|
|
|
|
2011-07-13 20:05:27 -06:00
|
|
|
con << "Base materials:" << std::endl;
|
2011-04-30 15:58:29 -06:00
|
|
|
for (it = baseMats.begin(); it != baseMats.end(); ++it)
|
2010-03-31 09:31:49 -06:00
|
|
|
{
|
2012-02-13 18:17:38 -07:00
|
|
|
con << std::setw(25) << ENUM_KEY_STR(tiletype_material,(df::tiletype_material)it->first) << " : " << it->second.count << std::endl;
|
2010-03-31 09:31:49 -06:00
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
|
2012-01-17 08:44:48 -07:00
|
|
|
if (liquidWater.count || liquidMagma.count)
|
|
|
|
{
|
|
|
|
con << std::endl << "Liquids:" << std::endl;
|
|
|
|
if (liquidWater.count)
|
|
|
|
{
|
|
|
|
con << std::setw(25) << "WATER" << " : ";
|
|
|
|
printMatdata(con, liquidWater);
|
|
|
|
}
|
|
|
|
if (liquidWater.count)
|
|
|
|
{
|
|
|
|
con << std::setw(25) << "MAGMA" << " : ";
|
|
|
|
printMatdata(con, liquidMagma);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-13 20:05:27 -06:00
|
|
|
con << std::endl << "Layer materials:" << std::endl;
|
2012-01-21 09:12:26 -07:00
|
|
|
printMats(con, layerMats, world->raws.inorganics, showValue);
|
2011-04-30 15:58:29 -06:00
|
|
|
|
2012-01-17 08:56:52 -07:00
|
|
|
printVeins(con, veinMats, mats, showValue);
|
2011-04-30 15:58:29 -06:00
|
|
|
|
|
|
|
if (showPlants)
|
2011-04-17 07:51:52 -06:00
|
|
|
{
|
2011-07-13 20:05:27 -06:00
|
|
|
con << "Shrubs:" << std::endl;
|
2012-01-21 09:12:26 -07:00
|
|
|
printMats(con, plantMats, world->raws.plants.all, showValue);
|
2011-07-13 20:05:27 -06:00
|
|
|
con << "Wood in trees:" << std::endl;
|
2012-01-21 09:12:26 -07:00
|
|
|
printMats(con, treeMats, world->raws.plants.all, showValue);
|
2011-04-17 07:51:52 -06:00
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
|
|
|
|
if (hasAquifer)
|
2011-04-17 07:51:52 -06:00
|
|
|
{
|
2012-01-17 08:44:48 -07:00
|
|
|
con << "Has aquifer";
|
|
|
|
if (aquiferTiles.count)
|
|
|
|
{
|
|
|
|
con << " : ";
|
|
|
|
printMatdata(con, aquiferTiles);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
con << std::endl;
|
2011-04-17 07:51:52 -06:00
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
|
2012-01-20 09:29:51 -07:00
|
|
|
if (showTube && tubeTiles.count)
|
|
|
|
{
|
|
|
|
con << "Has HFS tubes : ";
|
|
|
|
printMatdata(con, tubeTiles);
|
|
|
|
}
|
|
|
|
|
2011-04-30 15:58:29 -06:00
|
|
|
if (hasDemonTemple)
|
2011-04-17 07:51:52 -06:00
|
|
|
{
|
2011-07-13 20:05:27 -06:00
|
|
|
con << "Has demon temple" << std::endl;
|
2011-04-17 07:51:52 -06:00
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
|
|
|
|
if (hasLair)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2011-07-13 20:05:27 -06:00
|
|
|
con << "Has lair" << std::endl;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
2011-04-30 15:58:29 -06:00
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
mats->Finish();
|
2011-07-13 20:05:27 -06:00
|
|
|
con << std::endl;
|
2011-06-26 20:49:56 -06:00
|
|
|
return CR_OK;
|
2009-12-13 14:03:19 -07:00
|
|
|
}
|