1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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/>.
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"
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
)
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");
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");
61 matchGroup
.Pairs
.resize (matchGroup
.Pairs
.size()+1);
62 std::pair
<std::string
, std::string
> &pair
= matchGroup
.Pairs
.back();
66 if (config
.getPropertyString (name
, filename
, match
, "NAME"))
72 config
.syntaxError (filename
, match
, "Missing match name in configuration (%s)", name
.c_str());
76 // Get the match value
77 if (config
.getPropertyString (name
, filename
, match
, "VALUE"))
82 match
= CIXml::getNextChildNode (match
, "MATCH");
87 matchGroups
= CIXml::getNextChildNode (matchGroups
, "MATCH_GROUP");
94 // ***************************************************************************
96 bool CPrimitiveConfigurations::belong (const IPrimitive
&primitive
) const
98 // For each match group
100 const uint numGroup
= (uint
)MatchPairs
.size();
101 for (group
=0; group
<numGroup
; group
++)
103 const CMatchGroup
&matchGroup
= MatchPairs
[group
];
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
);
115 if (primitive
.getPropertyByName (pairs
.first
.c_str(), value
))
117 if (toLowerAscii(value
) == key
)
122 const std::vector
<string
> *array
= NULL
;
123 if (primitive
.getPropertyByName (pairs
.first
.c_str(), array
) && array
)
126 for (i
=0; i
<array
->size(); i
++)
128 if (toLowerAscii((*array
)[i
]) == key
)
131 if (i
!=array
->size())
140 if (rules
== numRules
)
146 // ***************************************************************************