Merge branch 'main/rendor-staging' into fixes
[ryzomcore.git] / nel / src / ligo / transition.cpp
blob2a2e7b8134c8cd97ea3b08bffa0667c8a45c3883
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/transition.h"
20 // Ligo include
21 #include "nel/ligo/zone_template.h"
22 #include "nel/ligo/ligo_error.h"
23 #include "nel/ligo/ligo_material.h"
25 #ifdef DEBUG_NEW
26 #define new DEBUG_NEW
27 #endif
29 namespace NLLIGO
32 // ***************************************************************************
34 sint32 CTransition::TransitionZoneEdges[TransitionZoneCount][4]=
36 {+2, +2, -4, +4}, // 0
37 {+4, +2, +2, -3}, // 1
38 {+1, +3, +2, -3}, // 2
39 {-3, +3, +2, +2}, // 3
40 {+1, +1, +3, -4}, // 4
41 {+1, +4, -4, +1}, // 5
42 {+4, +2, -4, +1}, // 6
43 {+4, +2, -3, +1}, // 7
44 {+3, -3, +1, +1}, // 8
47 // ***************************************************************************
49 sint32 CTransition::TransitionZoneOffset[TransitionZoneCount][2]=
51 {0, 1}, // 0
52 {1, 1}, // 1
53 {1, 2}, // 2
54 {1, 3}, // 3
55 {0, 3}, // 4
56 {0, 4}, // 5
57 {1, 4}, // 6
58 {2, 4}, // 7
59 {3, 4}, // 8
62 // ***************************************************************************
64 bool CTransition::build (const CMaterial &mat0, const CMaterial &mat1, const std::vector<const CZoneTemplate*> &arrayTemplate,
65 const CLigoConfig &config, CLigoError *errors, CLigoError &mainErrors)
67 // Check size
68 if ((arrayTemplate.size() != TransitionZoneCount))
70 // Error message
71 mainErrors.MainError = CLigoError::UnknownError;
72 return false;
75 // Ok ?
76 bool ok=true;
78 // Check zone template edge count
79 uint i;
80 for (i=0; i<TransitionZoneCount; i++)
82 // Must have 4 edges
83 if (arrayTemplate[i]&&(arrayTemplate[i]->getEdges ().size()!=4))
85 // Error code
86 mainErrors.MainError = CLigoError::MustHave4Edges;
87 errors[i].MainError = CLigoError::MustHave4Edges;
91 // continue ?
92 if (ok)
94 // Get first edge
95 _EdgeZone[0]=mat0.getEdge ();
97 // Get second edge
98 _EdgeZone[1]=mat1.getEdge ();
100 // For the two others edges
101 for (sint32 k=2; k<(sint32)ZoneEdgeCount; k++)
103 // Get the first third edge found
104 for (i=0; i<TransitionZoneCount; i++)
106 // This template exist ?
107 if (arrayTemplate[i])
109 uint j;
110 for (j=0; j<4; j++)
112 // Get edge
113 sint32 edge = TransitionZoneEdges[i][j];
115 // The good edge ?
116 if (((edge==k+1)||(edge==-(k+1))))
118 // Back the ege
119 _EdgeZone[k]=arrayTemplate[i]->getEdges ()[j];
121 // Invert it if negative
122 if (edge<0)
124 // Invert
125 _EdgeZone[k].invert (config);
128 // Break
129 break;
132 if (j<4)
133 break;
138 // Get the inverted edges
139 CZoneEdge invertedEdges[4];
140 for (i=0; i<4; i++)
142 // Copy the edge
143 invertedEdges[i]=_EdgeZone[i];
145 // Invert it
146 invertedEdges[i].invert(config);
149 // false if can't build because some template are missing
150 bool build=true;
152 // Now check each zones against the edges
153 for (i=0; i<TransitionZoneCount; i++)
155 // Template present ?
156 if (arrayTemplate[i])
158 // For each edge
159 for (uint j=0; j<4; j++)
161 // Get the edge number
162 sint32 edge=TransitionZoneEdges[i][j];
164 // Compare the edge
165 if (edge<0)
167 // The same edge ?
168 if (!invertedEdges[-edge-1].isTheSame (arrayTemplate[i]->getEdges()[j], config, errors[i]))
170 ok=false;
173 else
175 // The same edge ?
176 if (!_EdgeZone[edge-1].isTheSame (arrayTemplate[i]->getEdges()[j], config, errors[i]))
178 ok=false;
183 else
184 // Can't build
185 build=false;
188 // Ok to build ?
189 if (ok && build)
194 // Return error code
195 return ok;
198 // ***************************************************************************
200 void CTransition::serial (NLMISC::IStream &s)
202 // Serial the main node
203 s.xmlPush ("LIGO_TRANSITION");
205 // Serial the header
206 s.serialCheck (NELID("STGL"));
208 // Serial the version
209 /*sint ver =*/ s.serialVersion (0);
211 // Serial the edgezones
212 uint i;
213 s.xmlPush ("EDGE_ZONES");
214 for (i=0; i<ZoneEdgeCount; i++)
215 s.xmlSerial (_EdgeZone[i], "ELM");
216 s.xmlPop ();
218 // Close the main node
219 s.xmlPop ();
222 // ***************************************************************************
224 bool CTransition::check (const CZoneTemplate &zoneTemplate, uint transitionNumber, const CLigoConfig &config, CLigoError &errors) const
226 // Return value
227 bool ok = true;
229 // For each edge
230 for (uint j=0; j<4; j++)
232 // Get the edge number
233 sint32 edge=TransitionZoneEdges[transitionNumber][j];
235 // Compare the edge
236 if (edge<0)
238 // Invert the edge
239 CZoneEdge invertedEdges = _EdgeZone[-edge-1];
240 invertedEdges.invert(config);
242 // The same edge ?
243 if (!invertedEdges.isTheSame (zoneTemplate.getEdges()[j], config, errors))
245 ok=false;
248 else
250 // The same edge ?
251 if (!_EdgeZone[edge-1].isTheSame (zoneTemplate.getEdges()[j], config, errors))
253 ok=false;
258 // Return status
259 return ok;
262 // ***************************************************************************