unit_type::alignment to use MAKE_ENUM macro
This commit is contained in:
parent
7b876194bd
commit
684d1c35c6
4 changed files with 39 additions and 29 deletions
|
@ -280,7 +280,7 @@ variant unit_type_callable::get_value(const std::string& key) const
|
|||
} else if(key == "type") {
|
||||
return variant(u_.type_name());
|
||||
} else if(key == "alignment") {
|
||||
return variant(u_.alignment_id(u_.alignment()));
|
||||
return variant(lexical_cast<std::string>(u_.alignment()));
|
||||
} else if(key == "abilities") {
|
||||
std::vector<std::string> abilities = u_.get_ability_list();
|
||||
std::vector<variant> res;
|
||||
|
|
|
@ -348,7 +348,7 @@ static config unit_alignment(const unit* u)
|
|||
if (!u) return report();
|
||||
std::ostringstream str, tooltip;
|
||||
char const *align = unit_type::alignment_description(u->alignment(), u->gender());
|
||||
std::string align_id = unit_type::alignment_id(u->alignment());
|
||||
std::string align_id = lexical_cast<std::string>(u->alignment());
|
||||
int cm = combat_modifier(resources::screen->displayed_unit_hex(), u->alignment(),
|
||||
u->is_fearless());
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "unit_types.hpp"
|
||||
|
||||
#include "game_config.hpp"
|
||||
#include "gettext.hpp"
|
||||
//#include "gettext.hpp"
|
||||
#include "loadscreen.hpp"
|
||||
#include "log.hpp"
|
||||
#include "portrait.hpp"
|
||||
|
@ -486,21 +486,7 @@ void unit_type::build_full(const movement_type_map &mv_types,
|
|||
gender_types_[i]->build_full(mv_types, races, traits);
|
||||
}
|
||||
|
||||
const std::string& align = cfg_["alignment"];
|
||||
if(align == "lawful")
|
||||
alignment_ = LAWFUL;
|
||||
else if(align == "chaotic")
|
||||
alignment_ = CHAOTIC;
|
||||
else if(align == "neutral")
|
||||
alignment_ = NEUTRAL;
|
||||
else if(align == "liminal")
|
||||
alignment_ = LIMINAL;
|
||||
else {
|
||||
if ( !align.empty() ) {
|
||||
ERR_CF << "Invalid alignment found for " << log_id() << ": '" << align << "'" << std::endl;
|
||||
}
|
||||
alignment_ = NEUTRAL;
|
||||
}
|
||||
alignment_ = lexical_cast_default<unit_type::ALIGNMENT>(cfg_["alignment"], unit_type::NEUTRAL);
|
||||
|
||||
if ( race_ != &unit_race::null_race )
|
||||
{
|
||||
|
@ -835,7 +821,7 @@ int unit_type::experience_needed(bool with_acceleration) const
|
|||
}
|
||||
return experience_needed_;
|
||||
}
|
||||
|
||||
/*
|
||||
const char* unit_type::alignment_description(unit_type::ALIGNMENT align, unit_race::GENDER gender)
|
||||
{
|
||||
static const char* aligns[] = { N_("lawful"), N_("neutral"), N_("chaotic"), N_("liminal") };
|
||||
|
@ -843,13 +829,7 @@ const char* unit_type::alignment_description(unit_type::ALIGNMENT align, unit_ra
|
|||
const char** tlist = (gender == unit_race::MALE ? aligns : aligns_female);
|
||||
|
||||
return (sgettext(tlist[align]));
|
||||
}
|
||||
|
||||
const char* unit_type::alignment_id(unit_type::ALIGNMENT align)
|
||||
{
|
||||
static const char* aligns[] = { "lawful", "neutral", "chaotic", "liminal" };
|
||||
return (aligns[align]);
|
||||
}
|
||||
}*/
|
||||
|
||||
bool unit_type::has_ability_by_id(const std::string& ability) const
|
||||
{
|
||||
|
|
|
@ -14,12 +14,18 @@
|
|||
#ifndef UNIT_TYPES_H_INCLUDED
|
||||
#define UNIT_TYPES_H_INCLUDED
|
||||
|
||||
#include "gettext.hpp"
|
||||
#include "make_enum.hpp"
|
||||
#include "map_location.hpp"
|
||||
#include "movetype.hpp"
|
||||
#include "race.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct tportrait;
|
||||
class unit_ability_list;
|
||||
|
@ -222,11 +228,32 @@ public:
|
|||
int old_value_;
|
||||
};
|
||||
|
||||
enum ALIGNMENT { LAWFUL, NEUTRAL, CHAOTIC, LIMINAL };
|
||||
//enum ALIGNMENT { LAWFUL, NEUTRAL, CHAOTIC, LIMINAL };
|
||||
MAKE_ENUM (ALIGNMENT,
|
||||
(LAWFUL, N_("lawful"))
|
||||
(NEUTRAL, N_("neutral"))
|
||||
(CHAOTIC, N_("chaotic"))
|
||||
(LIMINAL, N_("liminal"))
|
||||
)
|
||||
MAKE_ENUM (ALIGNMENT_FEMALE_VARIATION,
|
||||
(FEMALE_LAWFUL, N_("female^lawful"))
|
||||
(FEMALE_NEUTRAL, N_("female^neutral"))
|
||||
(FEMALE_CHAOTIC, N_("female^chaotic"))
|
||||
(FEMALE_LIMINAL, N_("female^liminal"))
|
||||
)
|
||||
|
||||
ALIGNMENT alignment() const { return alignment_; }
|
||||
static const char* alignment_description(ALIGNMENT align, unit_race::GENDER gender = unit_race::MALE);
|
||||
static const char* alignment_id(ALIGNMENT align);
|
||||
inline static const char* alignment_description(ALIGNMENT align, unit_race::GENDER gender = unit_race::MALE)
|
||||
{
|
||||
std::string str = std::string();
|
||||
if (gender == unit_race::FEMALE) {
|
||||
ALIGNMENT_FEMALE_VARIATION fem = static_cast<ALIGNMENT_FEMALE_VARIATION> (align);
|
||||
str = lexical_cast<std::string>(fem);
|
||||
} else {
|
||||
str = lexical_cast<std::string>(align);
|
||||
}
|
||||
return sgettext(str.c_str());
|
||||
}
|
||||
|
||||
fixed_t alpha() const { return alpha_; }
|
||||
|
||||
|
@ -357,6 +384,9 @@ private:
|
|||
std::vector<tportrait> portraits_;
|
||||
};
|
||||
|
||||
MAKE_ENUM_STREAM_OPS2(unit_type, ALIGNMENT)
|
||||
MAKE_ENUM_STREAM_OPS2(unit_type, ALIGNMENT_FEMALE_VARIATION)
|
||||
|
||||
class unit_type_data
|
||||
: private boost::noncopyable
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue