MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / calcStatString

Method calcStatString

src/Ruleset/StatString.cpp:104–143  ·  view source on GitHub ↗

* Calculates the list of StatStrings that apply to certain unit stats. * @param currentStats Unit stats. * @param statStrings List of statString rules. * @param psiStrengthEval Are psi stats available? * @return Resulting string of all valid StatStrings. */

Source from the content-addressed store, hash-verified

102 * @return Resulting string of all valid StatStrings.
103 */
104const std::wstring StatString::calcStatString(UnitStats &currentStats, const std::vector<StatString *> &statStrings, bool psiStrengthEval)
105{
106 size_t conditionsMet;
107 int minVal, maxVal;
108 std::string conditionName, string;
109 std::wstring wstring, statString;
110 bool continueCalc = true;
111 std::map<std::string, int> currentStatsMap = getCurrentStats(currentStats);
112
113 for (std::vector<StatString *>::const_iterator i1 = statStrings.begin(); i1 != statStrings.end() && continueCalc; ++i1)
114 {
115 string = (*i1)->getString();
116 const std::vector<StatStringCondition* > conditions = (*i1)->getConditions();
117 conditionsMet = 0;
118 for (std::vector<StatStringCondition* >::const_iterator i2 = conditions.begin(); i2 != conditions.end() && continueCalc; ++i2)
119 {
120 conditionName = (*i2)->getConditionName();
121 minVal = (*i2)->getMinVal();
122 maxVal = (*i2)->getMaxVal();
123 if (currentStatsMap.find(conditionName) != currentStatsMap.end())
124 {
125 if (currentStatsMap[conditionName] >= minVal && currentStatsMap[conditionName] <= maxVal
126 && (conditionName != "psiStrength" || (currentStats.psiSkill > 0 || psiStrengthEval)))
127 {
128 conditionsMet++;
129 }
130 if (conditionsMet == conditions.size())
131 {
132 wstring.assign(string.begin(), string.end());
133 statString = statString + wstring;
134 if (wstring.length() > 1)
135 {
136 continueCalc = false;
137 }
138 }
139 }
140 }
141 }
142 return statString;
143}
144
145/**
146 * Get a map associating stat names to unit stats.

Callers 1

genSoldierMethod · 0.45

Calls 5

getConditionsMethod · 0.80
getConditionNameMethod · 0.80
getMinValMethod · 0.80
getMaxValMethod · 0.80
getStringMethod · 0.45

Tested by

no test coverage detected