OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
StatString.h
1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_STATSTRING_H
20 #define OPENXCOM_STATSTRING_H
21 
22 #include <yaml-cpp/yaml.h>
23 #include "Unit.h"
24 #include "StatStringCondition.h"
25 
26 namespace OpenXcom
27 {
28 
34 /*
35 NameStats in XCOMUTIL.CFG:
36 
37 StatStrings, which were added in version 7.2, are used for automatically
38 renaming soldiers. They are case sensitive and they are processed in the
39 order in which they are specified. The format of these StatStrings is:
40 
41  string statid:[lower]-[upper] [statid:[lower]-[upper] [...] ]
42 
43  where string = string to add to name. If length == 1, then the strings
44  accumulate. Otherwise, success ends the search. All
45  single character strings SHOULD come last, but that is
46  not required. / and ; are not a valid strings. The maximum
47  string length is 19.
48  statid = a = armor (front)
49  b = bravery
50  d = time units (dexterity)
51  e = stamina (endurance)
52  f = firing accuracy
53  h = health
54  k = psi/mc skill
55  p = psi/mc strength (if skill > 0)
56  q = psi/mc strength (regardless of skill)
57  r = reactions
58  s = strength
59  t = throwing accuracy
60  lower = lower limit of stat (inclusive), defaults to 0
61  upper = upper limit of stat (inclusive), defaults to 255
62 
63 Stat ranges are ANDed together when testing for success. To achieve a logical
64 OR, list the same string more than once. For example, Wimp b:0-10 and
65 Wimp s:0-20 would designate a Wimp as either someone who is not brave or
66 someone who is very weak. By arranging the string properly, you can put all
67 of your strengths before your weaknesses or list the stats in order, which is
68 the default.
69 
70 You may specify as many ranges for one StatString as you like, up to the limit
71 of the memory I have allocated. There is enough space for a total of more
72 than 600 ranges to be defined. Let me know if you need more.
73 
74 The # character is a special string that will be replaced by numbers
75 corresponding to the values of the statistics listed, divided by 10. For
76 example, # fr will generate the string 74 if the firing accuracy value is 72
77 and the reactions value is 48. This is a cumulative string, so that you could
78 prefix your strings with letters by using statid:0-255 before it. For
79 example P p:0-255 followed by # p would generate P6 for a Psi Strength of 64,
80 assuming that Psi Skill is non-zero. Psi/MC Strength is always reported as
81 zero unless Psi/MC Skill is greater than 0. To test Psi/MC Strength without
82 checking the Psi/MC Skill, use the q statid.
83 
84 Since strings longer than one character will terminate the checking, these
85 strings are normally listed first. More stats accumulating after Snpr would
86 ruin the usefulness of Snpr as an equipment type. However, if you wanted to
87 place an indicator in front of Snpr as a warning of some critical weakness,
88 you could place a single character string at the start of the list. For
89 example, if you wanted to know that your Snpr had a very low Psi/MC Strength
90 and had little resistance to alien control, you could put x p:0-30 or x q:0-30
91 at the start of the list to produce Snpr or xSnpr as your final code. This is
92 what I did in the default case. See the XCOMUTIL.CFG file for examples.
93 
94 If the resulting string exceeds the maximum length for a name, the first
95 name will be replaced by an initial. If the string is still too long, the
96 first name will be removed entirely. If this string is still too long, no
97 change will be made.
98 
99 If / is used as a statid, it indicates that this is the last required name
100 stat. That is, if the name stats make the name too long, the total string
101 will be reduced to the size at the moment that the / statid was
102 encountered. XcomUtil will again check the length of the name, reducing
103 or eliminating the first name as needed. If this string is still too
104 long, nothing will be changed.
105 */
106 
108 {
109 private:
110  std::string _stringToBeAddedIfAllConditionsAreMet;
111  std::vector< StatStringCondition* > _conditions;
112  StatStringCondition *getCondition(const std::string &conditionName, const YAML::Node &node);
113 public:
115  StatString();
117  virtual ~StatString();
119  void load(const YAML::Node& node);
121  const std::vector< StatStringCondition* > getConditions();
123  const std::string getString();
125  static const std::wstring calcStatString(UnitStats &currentStats, const std::vector<StatString *> &statStrings, bool psiStrengthEval);
127  static std::map<std::string, int> getCurrentStats(UnitStats &currentStats);
128 };
129 
130 }
131 #endif
Definition: StatStringCondition.h:27
const std::string getString()
Get the StatString string.
Definition: StatString.cpp:92
static const std::wstring calcStatString(UnitStats &currentStats, const std::vector< StatString * > &statStrings, bool psiStrengthEval)
Calculate a StatString.
Definition: StatString.cpp:104
static std::map< std::string, int > getCurrentStats(UnitStats &currentStats)
Get the CurrentStats.
Definition: StatString.cpp:150
For adding statStrings to the game.
Definition: StatString.h:107
virtual ~StatString()
Cleans up the StatString ruleset.
Definition: StatString.cpp:36
const std::vector< StatStringCondition * > getConditions()
Get the conditions for this StatString.
Definition: StatString.cpp:83
StatString()
Creates a blank StatString ruleset.
Definition: StatString.cpp:29
This struct holds some plain unit attribute data together.
Definition: Unit.h:32
void load(const YAML::Node &node)
Loads the StatString from YAML.
Definition: StatString.cpp:44