Skip to content

Commit

Permalink
update role calc, role prefs, custom role bug
Browse files Browse the repository at this point in the history
- re-wrote role calculations to use new checks and transformations based
on thistleknot's latest role work
- added highlighting of which preferences are matched in roles, and
additionally listed the exact matches
- updated role preference names, and added a check to update general
material names on load
- updated roles to have proper member variables
- split the crop role preference category into crops (gather/grow) and
crops (grow)
- removed the 'wagon' creature from roles
- fixed a bug with role attributes rounding due to passing int instead
of double
- fixed a bug with roles where having invalid/bad weights resulted in
invalid ratings which caused drawing anomalies
  • Loading branch information
splintermind committed Oct 4, 2014
1 parent 480ad9d commit ec6a34f
Show file tree
Hide file tree
Showing 35 changed files with 608 additions and 622 deletions.
10 changes: 6 additions & 4 deletions dwarftherapist.pro
Expand Up @@ -237,7 +237,6 @@ HEADERS += inc/viewmanager.h \
inc/itemweaponsubtype.h \
inc/cp437codec.h \
inc/rolestats.h \
inc/ecdf.h \
inc/contextmenuhelper.h \
inc/belief.h \
inc/unitbelief.h \
Expand All @@ -251,7 +250,10 @@ HEADERS += inc/viewmanager.h \
inc/grid_view/unitkillscolumn.h \
inc/dtstandarditem.h \
inc/docks/informationdock.h \
inc/docks/equipmentoverviewdock.h
inc/docks/equipmentoverviewdock.h \
inc/rolecalcminmax.h \
inc/rolecalcrecenter.h \
inc/rolecalcbase.h
SOURCES += src/viewmanager.cpp \
src/uberdelegate.cpp \
src/truncatingfilelogger.cpp \
Expand Down Expand Up @@ -331,7 +333,6 @@ SOURCES += src/viewmanager.cpp \
src/item.cpp \
src/uniform.cpp \
src/itemweaponsubtype.cpp \
src/ecdf.cpp \
src/rolestats.cpp \
src/belief.cpp \
src/grid_view/superlaborcolumn.cpp \
Expand All @@ -345,7 +346,8 @@ SOURCES += src/viewmanager.cpp \
src/grid_view/unitkillscolumn.cpp \
src/dtstandarditem.cpp \
src/docks/informationdock.cpp \
src/docks/equipmentoverviewdock.cpp
src/docks/equipmentoverviewdock.cpp \
src/rolecalcbase.cpp
FORMS += ui/scriptdialog.ui \
ui/scannerdialog.ui \
ui/pendingchanges.ui \
Expand Down
14 changes: 7 additions & 7 deletions inc/attribute.h
Expand Up @@ -44,16 +44,16 @@ class Attribute {
QString get_descriptor(){return m_descriptor;}
int get_descriptor_rank(){return m_descriptor_index;}
int get_value() {return m_value;}
float get_potential_value();
float get_balanced_value();
double get_potential_value();
double get_balanced_value();
void calculate_balanced_value();
int display_value(){return m_display_value;}
float rating(bool potential = false);
double rating(bool potential = false);
QStringList syndrome_names(){return m_syn_names;}
float max() {return m_max;}
float cti() {return m_cti;}

void set_rating(float rating, bool potential=false);
void set_rating(double rating, bool potential=false);
void set_syn_names(QStringList names);

static void load_attribute_descriptors(QSettings &s);
Expand All @@ -65,11 +65,11 @@ class Attribute {
private:
ATTRIBUTES_TYPE m_id;
int m_value; //raw value including permanent syndrome effects
float m_value_potential;
float m_value_balanced;
double m_value_potential;
double m_value_balanced;
int m_display_value; //raw value including permanent and temporary syndrome effects
int m_max;
float m_rating_potential;
double m_rating_potential;
float m_rating;
int m_cti; //cost to improve (caste specific)
QString m_descriptor; //caste specific depending on the bins
Expand Down
6 changes: 4 additions & 2 deletions inc/dwarf.h
Expand Up @@ -258,8 +258,8 @@ class Dwarf : public QObject
void load_trait_values(QVector<double> &list);
QMultiMap<int,Preference*> *get_preferences(){return &m_preferences;}

double get_role_pref_match_counts(Role *r);
double get_role_pref_match_counts(Preference *role_pref);
double get_role_pref_match_counts(Role *r, bool load_map = false);
double get_role_pref_match_counts(Preference *role_pref, Role *r = 0);

//! return a skill object by skill_id
Skill get_skill(int skill_id);
Expand Down Expand Up @@ -373,6 +373,7 @@ class Dwarf : public QObject
double calc_role_rating(Role *);
Q_INVOKABLE float get_role_rating(QString role_name);
Q_INVOKABLE float get_raw_role_rating(QString role_name);
QList<QPair<QString,QString> > get_role_pref_matches(QString role_name){return m_role_pref_map.value(role_name);}
void refresh_role_display_ratings();

void calc_attribute_ratings();
Expand Down Expand Up @@ -584,6 +585,7 @@ class Dwarf : public QObject
QHash<QString, double> m_raw_role_ratings;
QList<Role::simple_rating> m_sorted_role_ratings;
QList<QPair<QString,float> > m_sorted_custom_role_ratings;
QHash<QString,QList<QPair<QString,QString> > > m_role_pref_map;
QHash<short, int> m_states;
bool m_born_in_fortress;
quint32 m_birth_year;
Expand Down
4 changes: 2 additions & 2 deletions inc/dwarfjob.h
Expand Up @@ -225,11 +225,11 @@ class DwarfJob : public QObject {
case 256:
return tr("tooth");
case 512:
return tr("horn");
return tr("horn/hoof");
case 1024:
return tr("pearl");
case 2048:
return tr("yarn");
return tr("yarn/wool/fur");
}

return "unknown";
Expand Down
5 changes: 2 additions & 3 deletions inc/dwarfstats.h
Expand Up @@ -28,7 +28,6 @@ THE SOFTWARE.
#include "attribute.h"

#include "truncatingfilelogger.h"
#include "ecdf.h"
#include "rolestats.h"

class Dwarf;
Expand All @@ -45,10 +44,10 @@ class DwarfStats
static float get_att_potential_weight(){return m_att_pot_weight;}
static float get_skill_rate_weight(){return m_skill_rate_weight;}
static int get_max_unit_kills(){return m_max_unit_kills;}
static float calc_att_potential_value(int value, float max, float cti);
static double calc_att_potential_value(int value, float max, float cti);

static void init_attributes(QVector<double> attribute_values, QVector<double> attribute_raw_values);
static double get_attribute_rating(int val,bool raw = false);
static double get_attribute_rating(double val, bool raw = false);

static void init_traits(QVector<double> trait_values);
static double get_trait_rating(int val);
Expand Down
42 changes: 0 additions & 42 deletions inc/ecdf.h

This file was deleted.

2 changes: 2 additions & 0 deletions inc/global_enums.h
Expand Up @@ -288,6 +288,7 @@ typedef enum{
} MATERIAL_CLASS;

typedef enum{
WAGON=1,
VERMIN_FISH=9,
CAN_LEARN=71,
HATEABLE=72,
Expand Down Expand Up @@ -337,6 +338,7 @@ typedef enum {
P_SUMMER = 1,
P_AUTUMN = 2,
P_WINTER = 3,
P_SEED = 5,
P_DRINK = 7,
P_EXTRACT_BARREL = 8,
P_EXTRACT_VIAL = 9,
Expand Down
13 changes: 6 additions & 7 deletions inc/material.h
Expand Up @@ -46,17 +46,17 @@ class Material : public QObject {
QString get_material_name(MATERIAL_STATES state);
int id() {return m_index;}

void load_data();
void load_data();
bool is_inorganic() {return m_inorganic;}
bool is_generated() {return m_is_generated;}

FlagArray flags() {return m_flags;}
FlagArray flags() {return m_flags;}

static const QString get_material_flag_desc(const MATERIAL_FLAGS &flag) {
QMap<MATERIAL_FLAGS, QString> m;
m[BONE]=tr("Bone");
m[TOOTH]=tr("Tooth");
m[HORN]=tr("Horn");
m[HORN]=tr("Horn/Hoof");
m[PEARL]=tr("Pearl");
m[SHELL]=tr("Shell");
m[LEATHER]=tr("Leather");
Expand All @@ -66,7 +66,6 @@ class Material : public QObject {
m[IS_WOOD]=tr("Wood");
m[IS_STONE]=tr("Stone");
m[IS_METAL]=tr("Metal");
m[ALCOHOL_PLANT]=tr("Plants (Alcohol)");
m[THREAD_PLANT]=tr("Cloth");
m[YARN]=tr("Yarn/Wool/Fur");
return m.value(flag, "Missing Description");
Expand All @@ -86,7 +85,7 @@ class Material : public QObject {
m[MC_SHELL]=tr("Shell");
m[MC_PEARL]=tr("Pearl");
m[MC_TOOTH]=tr("Tooth");
m[MC_HORN]=tr("Horn");
m[MC_HORN]=tr("Horn/Hoof");
m[MC_PLANT_FIBER]=tr("Plant Fiber");
m[MC_SILK]=tr("Silk");
m[MC_YARN]=tr("Yarn/Wool/Fur");
Expand All @@ -98,11 +97,11 @@ class Material : public QObject {
VIRTADDR m_address;
VIRTADDR m_flag_address;
DFInstance * m_df;
MemoryLayout * m_mem;
MemoryLayout * m_mem;
FlagArray m_flags;
bool m_inorganic;
bool m_is_generated;
QHash<MATERIAL_STATES, QString> m_state_names;
QHash<MATERIAL_STATES, QString> m_state_names;

void read_material();
};
Expand Down
1 change: 1 addition & 0 deletions inc/preference.h
Expand Up @@ -69,6 +69,7 @@ class Preference : public QObject {
ITEM_TYPE get_item_type() {return m_iType;}
QVector<int> special_flags() {return m_special_flags;}
bool exact_match() {return m_exact_match;}
FlagArray material_flags() {return m_material_flags;}

RoleAspect *pref_aspect;

Expand Down
27 changes: 19 additions & 8 deletions inc/role.h
Expand Up @@ -31,6 +31,7 @@ THE SOFTWARE.

class Preference;
class RoleAspect;
class Dwarf;

class Role : public QObject {
Q_OBJECT
Expand All @@ -40,10 +41,6 @@ class Role : public QObject {
Role(const Role &r);
virtual ~Role();

QString name;
QString script;
bool is_custom;

struct global_weight{
bool is_default;
float weight;
Expand All @@ -55,6 +52,13 @@ class Role : public QObject {
QString name;
};

QString name(){return m_name;}
void name(QString name){m_name = name;}
QString script(){return m_script;}
void script(QString script){m_script = script;}
bool is_custom(){return m_is_custom;}
void is_custom(bool val){m_is_custom = val;}

//unfortunately we need to keep all the keys as a string and cast them so we can use the same functions
//ie can't pass in a hash with <string, aspect> and <int, aspect>
QHash<QString, RoleAspect*> attributes;
Expand All @@ -68,12 +72,12 @@ class Role : public QObject {
global_weight traits_weight;
global_weight prefs_weight;

QString get_role_details();
QString get_role_details(Dwarf *d = 0);

void set_labors(QList<int> list){m_labors = list;}
QList<int> get_labors() {return m_labors;}

void create_role_details(QSettings &s);
void create_role_details(QSettings &s, Dwarf *d=0);

void write_to_ini(QSettings &s, float default_attributes_weight, float default_traits_weight, float default_skills_weight, float default_prefs_weight);

Expand All @@ -85,11 +89,18 @@ class Role : public QObject {
void write_pref_group(QSettings &s, float default_prefs_weight);

QString get_aspect_details(QString title, global_weight aspect_group_weight, float aspect_default_weight, QHash<QString, RoleAspect *> &list);
QString get_preference_details(float aspect_default_weight);

QString get_preference_details(float aspect_default_weight, Dwarf *d=0);
void refresh_preferences(Dwarf *d);
void highlight_pref_matches(Dwarf *d, QString &pref_desc);
QString generate_details(QString title, global_weight aspect_group_weight,float aspect_default_weight, QMap<QString,global_weight> list);

QString m_name;
QString m_script;
bool m_is_custom;

QString role_details;
QList<int> m_labors; //labors associated via the skills in the role
QString m_pref_desc;
int m_cur_pref_len;
};
#endif // ROLE_H
29 changes: 29 additions & 0 deletions inc/rolecalcbase.h
@@ -0,0 +1,29 @@
#ifndef ROLECALCBASE_H
#define ROLECALCBASE_H

#include <QVector>

class RoleCalcBase{
public:
RoleCalcBase(const QVector<double> &sorted);
virtual ~RoleCalcBase();

virtual double rating(const double val);
double base_rating(const double val);

double operator()(double val, bool leq = true)const{
return leq ? pos_upper(val) : pos_lower(val);}

static double find_median(QVector<double> v);
static double range_transform(double val, double min, double mid, double max);

protected:
QVector<double> m_sorted;
QVector<double>::const_iterator m_begin, m_end;
void init_list();
double m_count;
double m_div;
double pos_upper(double val)const;
double pos_lower(double val)const;
};
#endif // ROLECALCBASE_H
31 changes: 31 additions & 0 deletions inc/rolecalcminmax.h
@@ -0,0 +1,31 @@
#ifndef ROLECALCMINMAX_H
#define ROLECALCMINMAX_H

#include <QVector>
#include "rolecalcbase.h"

class RoleCalcMinMax: public RoleCalcBase{
public:
RoleCalcMinMax(const QVector<double> &sorted)
: RoleCalcBase(sorted)
, m_min(sorted.first())
, m_max(sorted.last())
{
m_diff = m_max - m_min;
if(m_diff == 0)
m_diff = 1;
}

double rating(const double val){
return (base_rating(val) + calc_min_max(val)) * 0.25 + 0.5f;
}

private:
double m_min;
double m_max;
double m_diff;
double calc_min_max(double val){
return (val - m_min) / m_diff;
}
};
#endif // ROLECALCMINMAX_H

0 comments on commit ec6a34f

Please sign in to comment.