Sort layer materials in prospector by depth.

develop
Petr Mrázek 2012-03-03 23:18:12 +01:00
parent 7fe8762852
commit d33e9a9770
3 changed files with 28 additions and 34 deletions

@ -47,6 +47,7 @@ using namespace std;
#include "modules/Gui.h" #include "modules/Gui.h"
#include "modules/World.h" #include "modules/World.h"
#include "modules/Graphic.h" #include "modules/Graphic.h"
//#include "modules/Windows.h"
using namespace DFHack; using namespace DFHack;
#include "SDL_events.h" #include "SDL_events.h"

@ -23,9 +23,6 @@ distribution.
*/ */
#pragma once #pragma once
#ifndef CL_MOD_GUI
#define CL_MOD_GUI
#include "Export.h" #include "Export.h"
#include "Module.h" #include "Module.h"
#include "Virtual.h" #include "Virtual.h"
@ -95,18 +92,6 @@ namespace DFHack
DFHACK_EXPORT void showAnnouncement(std::string message, int color = 7, bool bright = true); DFHACK_EXPORT void showAnnouncement(std::string message, int color = 7, bool bright = true);
DFHACK_EXPORT void showPopupAnnouncement(std::string message, int color = 7, bool bright = true); DFHACK_EXPORT void showPopupAnnouncement(std::string message, int color = 7, bool bright = true);
/**
* One tile of the screen.
* \ingroup grp_gui
*/
struct t_screen
{
uint8_t symbol;
uint8_t foreground;
uint8_t background;
uint8_t bright;
};
/* /*
* Cursor and window coords * Cursor and window coords
*/ */
@ -126,12 +111,10 @@ namespace DFHack
/// Get the current top-level view-screen /// Get the current top-level view-screen
DFHACK_EXPORT df::viewscreen * GetCurrentScreen(); DFHACK_EXPORT df::viewscreen * GetCurrentScreen();
/* /// get the size of the window buffer
* Window size in tiles
*/
DFHACK_EXPORT bool getWindowSize(int32_t & width, int32_t & height); DFHACK_EXPORT bool getWindowSize(int32_t & width, int32_t & height);
/* /**
*Menu width: *Menu width:
*3:3 - menu and area map closed *3:3 - menu and area map closed
*2:3 - menu open single width *2:3 - menu open single width
@ -144,5 +127,3 @@ namespace DFHack
DFHACK_EXPORT bool setMenuWidth(const uint8_t menu_width, const uint8_t area_map_width); DFHACK_EXPORT bool setMenuWidth(const uint8_t menu_width, const uint8_t area_map_width);
} }
} }
#endif

@ -76,6 +76,18 @@ bool operator>(const matdata & q1, const matdata & q2)
return q1.count > q2.count; return q1.count > q2.count;
} }
template<typename _Tp = matdata >
struct shallower : public binary_function<_Tp, _Tp, bool>
{
bool operator()(const _Tp& top, const _Tp& bottom) const
{
float topavg = (top.lower_z + top.upper_z)/2.0f;
float btmavg = (bottom.lower_z + bottom.upper_z)/2.0f;
return topavg > btmavg;
}
};
typedef std::map<int16_t, matdata> MatMap; typedef std::map<int16_t, matdata> MatMap;
typedef std::vector< pair<int16_t, matdata> > MatSorter; typedef std::vector< pair<int16_t, matdata> > MatSorter;
@ -90,10 +102,10 @@ template<template <typename> class P = std::greater >
struct compare_pair_second struct compare_pair_second
{ {
template<class T1, class T2> template<class T1, class T2>
bool operator()(const std::pair<T1, T2>& left, const std::pair<T1, T2>& right) bool operator()(const std::pair<T1, T2>& left, const std::pair<T1, T2>& right)
{ {
return P<T2>()(left.second, right.second); return P<T2>()(left.second, right.second);
} }
}; };
static void printMatdata(DFHack::Console & con, const matdata &data) static void printMatdata(DFHack::Console & con, const matdata &data)
@ -116,7 +128,7 @@ static int getValue(const df::plant_raw &info)
return info.value; return info.value;
} }
template <typename T> template <typename T, template <typename> class P>
void printMats(DFHack::Console & con, MatMap &mat, std::vector<T*> &materials, bool show_value) void printMats(DFHack::Console & con, MatMap &mat, std::vector<T*> &materials, bool show_value)
{ {
unsigned int total = 0; unsigned int total = 0;
@ -126,7 +138,7 @@ void printMats(DFHack::Console & con, MatMap &mat, std::vector<T*> &materials, b
sorting_vector.push_back(*it); sorting_vector.push_back(*it);
} }
std::sort(sorting_vector.begin(), sorting_vector.end(), std::sort(sorting_vector.begin(), sorting_vector.end(),
compare_pair_second<>()); compare_pair_second<P>());
for (MatSorter::const_iterator it = sorting_vector.begin(); for (MatSorter::const_iterator it = sorting_vector.begin();
it != sorting_vector.end(); ++it) it != sorting_vector.end(); ++it)
{ {
@ -168,13 +180,13 @@ void printVeins(DFHack::Console & con, MatMap &mat_map,
} }
con << "Ores:" << std::endl; con << "Ores:" << std::endl;
printMats(con, ores, world->raws.inorganics, show_value); printMats<df::inorganic_raw, std::greater>(con, ores, world->raws.inorganics, show_value);
con << "Gems:" << std::endl; con << "Gems:" << std::endl;
printMats(con, gems, world->raws.inorganics, show_value); printMats<df::inorganic_raw, std::greater>(con, gems, world->raws.inorganics, show_value);
con << "Other vein stone:" << std::endl; con << "Other vein stone:" << std::endl;
printMats(con, rest, world->raws.inorganics, show_value); printMats<df::inorganic_raw, std::greater>(con, rest, world->raws.inorganics, show_value);
} }
command_result prospector (Core * c, vector <string> & parameters); command_result prospector (Core * c, vector <string> & parameters);
@ -329,7 +341,7 @@ static command_result embark_prospector(DFHack::Core *c, df::viewscreen_choose_s
// Print the report // Print the report
c->con << "Layer materials:" << std::endl; c->con << "Layer materials:" << std::endl;
printMats(c->con, layerMats, world->raws.inorganics, showValue); printMats<df::inorganic_raw, shallower>(c->con, layerMats, world->raws.inorganics, showValue);
if (showHidden) { if (showHidden) {
DFHack::Materials *mats = c->getMaterials(); DFHack::Materials *mats = c->getMaterials();
@ -588,16 +600,16 @@ command_result prospector (DFHack::Core * c, vector <string> & parameters)
} }
con << std::endl << "Layer materials:" << std::endl; con << std::endl << "Layer materials:" << std::endl;
printMats(con, layerMats, world->raws.inorganics, showValue); printMats<df::inorganic_raw, shallower>(con, layerMats, world->raws.inorganics, showValue);
printVeins(con, veinMats, mats, showValue); printVeins(con, veinMats, mats, showValue);
if (showPlants) if (showPlants)
{ {
con << "Shrubs:" << std::endl; con << "Shrubs:" << std::endl;
printMats(con, plantMats, world->raws.plants.all, showValue); printMats<df::plant_raw, std::greater>(con, plantMats, world->raws.plants.all, showValue);
con << "Wood in trees:" << std::endl; con << "Wood in trees:" << std::endl;
printMats(con, treeMats, world->raws.plants.all, showValue); printMats<df::plant_raw, std::greater>(con, treeMats, world->raws.plants.all, showValue);
} }
if (hasAquifer) if (hasAquifer)