Merge branch 'main/rendor-staging' into fixes
[ryzomcore.git] / nel / src / ligo / primitive_configuration.cpp
blobf73e5acb6ee86d2acb37e659062d8511b025a995
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program 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 Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdligo.h"
21 #include "nel/ligo/primitive_configuration.h"
22 #include "nel/ligo/ligo_config.h"
23 #include "nel/ligo/primitive.h"
24 #include "nel/misc/i_xml.h"
26 using namespace std;
27 using namespace NLMISC;
28 using namespace NLLIGO;
30 extern bool ReadColor (CRGBA &color, xmlNodePtr node);
32 // ***************************************************************************
34 bool CPrimitiveConfigurations::read (xmlNodePtr configurationNode, const char *filename, const char *name, NLLIGO::CLigoConfig &config)
36 // The name
37 Name = name;
39 // Read the color
40 ReadColor (Color, configurationNode);
42 // Get the first matching pair
43 MatchPairs.reserve (CIXml::countChildren (configurationNode, "MATCH_GROUP"));
44 xmlNodePtr matchGroups = CIXml::getFirstChildNode (configurationNode, "MATCH_GROUP");
45 if (matchGroups)
49 // Add a pair
50 MatchPairs.push_back(CMatchGroup());
51 CMatchGroup &matchGroup = MatchPairs.back();
53 // Get the first matching pair
54 matchGroup.Pairs.reserve (CIXml::countChildren (matchGroups, "MATCH"));
55 xmlNodePtr match = CIXml::getFirstChildNode (matchGroups, "MATCH");
56 if (match)
60 // Add the match
61 matchGroup.Pairs.resize (matchGroup.Pairs.size()+1);
62 std::pair<std::string, std::string> &pair = matchGroup.Pairs.back();
64 // Get the match name
65 std::string name;
66 if (config.getPropertyString (name, filename, match, "NAME"))
68 pair.first = name;
70 else
72 config.syntaxError (filename, match, "Missing match name in configuration (%s)", name.c_str());
73 return false;
76 // Get the match value
77 if (config.getPropertyString (name, filename, match, "VALUE"))
79 pair.second = name;
82 match = CIXml::getNextChildNode (match, "MATCH");
84 while (match);
87 matchGroups = CIXml::getNextChildNode (matchGroups, "MATCH_GROUP");
89 while (matchGroups);
91 return true;
94 // ***************************************************************************
96 bool CPrimitiveConfigurations::belong (const IPrimitive &primitive) const
98 // For each match group
99 uint group;
100 const uint numGroup = (uint)MatchPairs.size();
101 for (group=0; group<numGroup; group++)
103 const CMatchGroup &matchGroup = MatchPairs[group];
105 // For each rules
106 uint rules;
107 const uint numRules = (uint)matchGroup.Pairs.size();
108 for (rules=0; rules<numRules; rules++)
110 const std::pair<std::string, std::string> &pairs = matchGroup.Pairs[rules];
111 string key = toLowerAscii(pairs.second);
113 // Get the property
114 string value;
115 if (primitive.getPropertyByName (pairs.first.c_str(), value))
117 if (toLowerAscii(value) == key)
118 continue;
121 // Get the property
122 const std::vector<string> *array = NULL;
123 if (primitive.getPropertyByName (pairs.first.c_str(), array) && array)
125 uint i;
126 for (i=0; i<array->size(); i++)
128 if (toLowerAscii((*array)[i]) == key)
129 break;
131 if (i!=array->size())
132 continue;
135 // Don't match
136 break;
139 // Match ?
140 if (rules == numRules)
141 return true;
143 return false;
146 // ***************************************************************************