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