1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
18 #include "nel/ligo/transition.h"
21 #include "nel/ligo/zone_template.h"
22 #include "nel/ligo/ligo_error.h"
23 #include "nel/ligo/ligo_material.h"
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]=
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
)
68 if ((arrayTemplate
.size() != TransitionZoneCount
))
71 mainErrors
.MainError
= CLigoError::UnknownError
;
78 // Check zone template edge count
80 for (i
=0; i
<TransitionZoneCount
; i
++)
83 if (arrayTemplate
[i
]&&(arrayTemplate
[i
]->getEdges ().size()!=4))
86 mainErrors
.MainError
= CLigoError::MustHave4Edges
;
87 errors
[i
].MainError
= CLigoError::MustHave4Edges
;
95 _EdgeZone
[0]=mat0
.getEdge ();
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
])
113 sint32 edge
= TransitionZoneEdges
[i
][j
];
116 if (((edge
==k
+1)||(edge
==-(k
+1))))
119 _EdgeZone
[k
]=arrayTemplate
[i
]->getEdges ()[j
];
121 // Invert it if negative
125 _EdgeZone
[k
].invert (config
);
138 // Get the inverted edges
139 CZoneEdge invertedEdges
[4];
143 invertedEdges
[i
]=_EdgeZone
[i
];
146 invertedEdges
[i
].invert(config
);
149 // false if can't build because some template are missing
152 // Now check each zones against the edges
153 for (i
=0; i
<TransitionZoneCount
; i
++)
155 // Template present ?
156 if (arrayTemplate
[i
])
159 for (uint j
=0; j
<4; j
++)
161 // Get the edge number
162 sint32 edge
=TransitionZoneEdges
[i
][j
];
168 if (!invertedEdges
[-edge
-1].isTheSame (arrayTemplate
[i
]->getEdges()[j
], config
, errors
[i
]))
176 if (!_EdgeZone
[edge
-1].isTheSame (arrayTemplate
[i
]->getEdges()[j
], config
, errors
[i
]))
198 // ***************************************************************************
200 void CTransition::serial (NLMISC::IStream
&s
)
202 // Serial the main node
203 s
.xmlPush ("LIGO_TRANSITION");
206 s
.serialCheck (NELID("STGL"));
208 // Serial the version
209 /*sint ver =*/ s
.serialVersion (0);
211 // Serial the edgezones
213 s
.xmlPush ("EDGE_ZONES");
214 for (i
=0; i
<ZoneEdgeCount
; i
++)
215 s
.xmlSerial (_EdgeZone
[i
], "ELM");
218 // Close the main node
222 // ***************************************************************************
224 bool CTransition::check (const CZoneTemplate
&zoneTemplate
, uint transitionNumber
, const CLigoConfig
&config
, CLigoError
&errors
) const
230 for (uint j
=0; j
<4; j
++)
232 // Get the edge number
233 sint32 edge
=TransitionZoneEdges
[transitionNumber
][j
];
239 CZoneEdge invertedEdges
= _EdgeZone
[-edge
-1];
240 invertedEdges
.invert(config
);
243 if (!invertedEdges
.isTheSame (zoneTemplate
.getEdges()[j
], config
, errors
))
251 if (!_EdgeZone
[edge
-1].isTheSame (zoneTemplate
.getEdges()[j
], config
, errors
))
262 // ***************************************************************************