Show bonus/malus timer text if available
[ryzomcore.git] / nel / src / ligo / primitive_configuration.cpp
blobd85d626ebba6fb15a00b213e8341b2c522eba4ac
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdligo.h"
18 #include "nel/ligo/primitive_configuration.h"
19 #include "nel/ligo/ligo_config.h"
20 #include "nel/ligo/primitive.h"
21 #include "nel/misc/i_xml.h"
23 using namespace std;
24 using namespace NLMISC;
25 using namespace NLLIGO;
27 extern bool ReadColor (CRGBA &color, xmlNodePtr node);
29 // ***************************************************************************
31 bool CPrimitiveConfigurations::read (xmlNodePtr configurationNode, const char *filename, const char *name, NLLIGO::CLigoConfig &config)
33 // The name
34 Name = name;
36 // Read the color
37 ReadColor (Color, configurationNode);
39 // Get the first matching pair
40 MatchPairs.reserve (CIXml::countChildren (configurationNode, "MATCH_GROUP"));
41 xmlNodePtr matchGroups = CIXml::getFirstChildNode (configurationNode, "MATCH_GROUP");
42 if (matchGroups)
46 // Add a pair
47 MatchPairs.push_back(CMatchGroup());
48 CMatchGroup &matchGroup = MatchPairs.back();
50 // Get the first matching pair
51 matchGroup.Pairs.reserve (CIXml::countChildren (matchGroups, "MATCH"));
52 xmlNodePtr match = CIXml::getFirstChildNode (matchGroups, "MATCH");
53 if (match)
57 // Add the match
58 matchGroup.Pairs.resize (matchGroup.Pairs.size()+1);
59 std::pair<std::string, std::string> &pair = matchGroup.Pairs.back();
61 // Get the match name
62 std::string name;
63 if (config.getPropertyString (name, filename, match, "NAME"))
65 pair.first = name;
67 else
69 config.syntaxError (filename, match, "Missing match name in configuration (%s)", name.c_str());
70 return false;
73 // Get the match value
74 if (config.getPropertyString (name, filename, match, "VALUE"))
76 pair.second = name;
79 match = CIXml::getNextChildNode (match, "MATCH");
81 while (match);
84 matchGroups = CIXml::getNextChildNode (matchGroups, "MATCH_GROUP");
86 while (matchGroups);
88 return true;
91 // ***************************************************************************
93 bool CPrimitiveConfigurations::belong (const IPrimitive &primitive) const
95 // For each match group
96 uint group;
97 const uint numGroup = (uint)MatchPairs.size();
98 for (group=0; group<numGroup; group++)
100 const CMatchGroup &matchGroup = MatchPairs[group];
102 // For each rules
103 uint rules;
104 const uint numRules = (uint)matchGroup.Pairs.size();
105 for (rules=0; rules<numRules; rules++)
107 const std::pair<std::string, std::string> &pairs = matchGroup.Pairs[rules];
108 string key = toLowerAscii(pairs.second);
110 // Get the property
111 string value;
112 if (primitive.getPropertyByName (pairs.first.c_str(), value))
114 if (toLowerAscii(value) == key)
115 continue;
118 // Get the property
119 const std::vector<string> *array = NULL;
120 if (primitive.getPropertyByName (pairs.first.c_str(), array) && array)
122 uint i;
123 for (i=0; i<array->size(); i++)
125 if (toLowerAscii((*array)[i]) == key)
126 break;
128 if (i!=array->size())
129 continue;
132 // Don't match
133 break;
136 // Match ?
137 if (rules == numRules)
138 return true;
140 return false;
143 // ***************************************************************************