1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
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/>.
20 #include "continent_sheet.h"
21 #include "game_share/georges_helper.h"
23 #include "nel/georges/u_form_elm.h"
24 #include "nel/georges/u_form.h"
25 #include "nel/georges/u_form_loader.h"
27 #include "nel/misc/smart_ptr.h"
29 using namespace NLMISC
;
31 using namespace NLGEORGES
;
33 //=========================================================================
34 CContinentParameters::CContinentParameters()
38 EntitySunContributionPower
= 0.0f
;
39 EntitySunContributionMaxThreshold
= 0.0f
;
40 LandscapePointLightMaterial
.set( 0, 0, 0, 255 );
47 for( uint32 i
= 0; i
< EGSPD::CSeason::Invalid
; ++i
)
49 TileColorMono
[i
] = false;
50 TileColorFactor
[i
] = 0.0f
;
51 StaticLightingFactor
[i
] = 0.0f
;
52 ForceDisplayedSeason
[i
] = (EGSPD::CSeason::TSeason
)i
;
56 //=========================================================================
57 CContinentSheet::CContinentSheet()
59 Type
= CEntitySheet::CONTINENT
;
62 //=========================================================================
63 void CContinentParameters::build(const NLGEORGES::UFormElm
&item
)
66 item
.getValueByName (Name
, "Name");
69 item
.getValueByName (WorldMap
, "WorldMap");
72 item
.getValueByName (ZoneMin
, "ZoneMin");
73 item
.getValueByName (ZoneMax
, "ZoneMax");
75 // Load Light Landscape Day.
77 if (item
.getNodeByName (&elm
, "LightLandscapeDay") && elm
)
78 LandscapeLightDay
.build(*elm
);
80 // Load Light Landscape Night.
81 if (item
.getNodeByName (&elm
, "LightLandscapeNight") && elm
)
82 LandscapeLightNight
.build(*elm
);
84 // Load Light Landscape Dusk.
85 if (item
.getNodeByName (&elm
, "LightLandscapeDusk") && elm
)
87 if (!LandscapeLightDusk
.build(*elm
)) LandscapeLightDusk
.blend(LandscapeLightDay
, LandscapeLightNight
, 0.5f
);
89 else LandscapeLightDusk
.blend(LandscapeLightDay
, LandscapeLightNight
, 0.5f
);
92 // Load Landscape PointLightMaterial
93 if (item
.getNodeByName (&elm
, "LandscapePointLightMaterial") && elm
)
94 CGeorgesHelper::convert (LandscapePointLightMaterial
, *elm
);
96 LandscapePointLightMaterial
= CRGBA::White
;
98 // Load Light Entity Day.
99 if (item
.getNodeByName (&elm
, "LightEntityDay") && elm
)
100 EntityLightDay
.build(*elm
);
103 // Load Light Entity Night.
104 if (item
.getNodeByName (&elm
, "LightEntityNight") && elm
)
105 EntityLightNight
.build(*elm
);
107 // Load Light Entity Dusk
108 if (item
.getNodeByName (&elm
, "LightEntityDusk") && elm
)
110 if (!EntityLightDusk
.build(*elm
)) EntityLightDusk
.blend(EntityLightDay
, EntityLightNight
, 0.5f
);
112 else EntityLightDusk
.blend(EntityLightDay
, EntityLightNight
, 0.5f
);
114 // Load Light Root Day.
115 if (item
.getNodeByName (&elm
, "LightRootDay") && elm
)
116 RootLightDay
.build(*elm
);
118 // Load Light Root Night.
119 if (item
.getNodeByName (&elm
, "LightRootNight") && elm
)
120 RootLightNight
.build(*elm
);
122 // Load Light Root Dusk
123 if (item
.getNodeByName (&elm
, "LightRootDusk") && elm
)
125 if (!RootLightDusk
.build(*elm
)) RootLightDusk
.blend(RootLightDay
, RootLightNight
, 0.5f
);
127 else RootLightDusk
.blend(RootLightDay
, RootLightNight
, 0.5f
);
130 // Load Entity sun contribution power.
131 item
.getValueByName (EntitySunContributionPower
, "EntitySunPower");
133 // Load Entity sun contribution max threshold.
134 item
.getValueByName (EntitySunContributionMaxThreshold
, "EntitySunMaxThreshold");
137 item
.getValueByName (PacsRBank
, "PacsRBank");
140 item
.getValueByName (PacsGR
, "PacsGR");
142 // Load IG list filename.
143 item
.getValueByName (LandscapeIG
, "LandscapeIG");
145 // Load Sky day filename.
146 item
.getValueByName (SkyDay
, "SkyDay");
148 // Load Sky night filename.
149 item
.getValueByName (SkyNight
, "SkyNight");
151 // Load Sky fog part filename.
152 item
.getValueByName (SkyFogPartName
, "SkyFogPart");
154 // Load Sky ig filename.
155 item
.getValueByName (BackgroundIGName
, "SkyIg");
157 // Load IG for canopy for each season
158 for (uint season
= 0; season
< EGSPD::CSeason::Invalid
; ++season
)
160 item
.getValueByName(CanopyIGfileName
[season
], (EGSPD::CSeason::toString( (EGSPD::CSeason::TSeason
)season
) + "CanopyIG").c_str());
165 if (item
.getValueByName (filename
, "Ecosystem"))
167 UFormLoader
*loader
= UFormLoader::createLoader();
171 CSmartPtr
<UForm
> form
= loader
->loadForm (filename
.c_str ());
177 elm
= &form
->getRootNode ();
180 elm
->getValueByName (MicroVeget
, "MicroVeget");
183 elm
->getValueByName (SmallBank
, "SmallBank");
186 elm
->getValueByName (FarBank
, "FarBank");
188 // Coarse mesh texture.
189 elm
->getValueByName (CoarseMeshMap
, "CoarseMeshMap");
193 nlwarning("CContinent::build : Can't load form %s.", filename
.c_str());
195 UFormLoader::releaseLoader(loader
);
199 // Load all "Zone Constructible".
200 if(item
.getNodeByName(&elm
, "ZCs") && elm
)
204 if(elm
->getArraySize(nbZC
))
207 for(uint i
= 0; i
< nbZC
; ++i
)
211 if(elm
->getArrayNode(&zc
, i
) && zc
)
213 // Get the zone associated.
215 zone
.EnableRuins
= true;
216 if(!zc
->getValueByName(zone
.Name
, "Zone"))
217 nlwarning("CContinent::build : key 'Zone' not found.");
218 if(!zc
->getValueByName(zone
.ForceLoadDist
, "ForceLoadDist"))
219 nlwarning("CContinent::build : key 'ForceLoadDist' not found.");
220 if(!zc
->getValueByName(zone
.LoadDist
, "LoadDist"))
221 nlwarning("CContinent::build : key 'LoadDist' not found.");
222 if(!zc
->getValueByName(zone
.UnloadDist
, "UnloadDist"))
223 nlwarning("CContinent::build : key 'UnloadDist' not found.");
224 if(!zc
->getValueByName(zone
.EnableRuins
, "EnableRuins"))
225 nlwarning("CContinent::build : key 'EnableRuins' not found.");
227 ZCList
.push_back(zone
);
232 nlwarning("CContinent::build : it seems 'ZCs' is not an array.");
235 // build fog map descriptor
236 buildFogMapBuild(item
);
238 // Load Sky ig filename.
239 item
.getValueByName (Indoor
, "Indoor");
242 // Load the landmark list
244 if(item.getNodeByName (&elm, "LandMarks") && elm)
246 // Get number of village
248 nlverify (elm->getArraySize (numLandMarks));
249 LandMarks.resize(numLandMarks);
252 for(uint k = 0; k < numLandMarks; ++k)
255 const UFormElm *landMarkForm;
256 if (elm->getArrayNode (&landMarkForm, k) && landMarkForm)
258 LandMarks[k].build(*landMarkForm);
264 item
.getValueByName (LocalizedName
, "LocalizedName");
266 // Micro-life primitives
267 if(item
.getNodeByName(&elm
, "MicroLifePrimitives") && elm
)
269 // Get number of prims
271 if(elm
->getArraySize(numPrims
))
274 for(uint i
= 0; i
< numPrims
; ++i
)
276 std::string primFilename
;
277 if (elm
->getArrayValue(primFilename
, i
))
279 MicroLifeZones
.push_back(primFilename
);
284 nlwarning("CContinent::build : it seems 'ZCs' is not an array.");
287 // Read Season related parameters
288 for (uint season
= 0; season
< EGSPD::CSeason::Invalid
; ++season
)
290 item
.getValueByName(TileColorMono
[season
], (EGSPD::CSeason::toString( (EGSPD::CSeason::TSeason
)season
) + "TileColorMono").c_str());
291 item
.getValueByName(TileColorFactor
[season
], (EGSPD::CSeason::toString( (EGSPD::CSeason::TSeason
)season
) + "TileColorFactor").c_str());
292 item
.getValueByName(StaticLightingFactor
[season
], (EGSPD::CSeason::toString( (EGSPD::CSeason::TSeason
)season
) + "StaticLightingFactor").c_str());
293 item
.getValueByName(SkySheet
[season
], ("SkySheet" + EGSPD::CSeason::toString( (EGSPD::CSeason::TSeason
)season
)).c_str());
295 // A continent may want to force some season instead another. read it
296 ForceDisplayedSeason
[season
]= (EGSPD::CSeason::TSeason
)season
;
298 item
.getValueByName(strSeason
, ("DisplayedSeasonFor" + EGSPD::CSeason::toString( (EGSPD::CSeason::TSeason
)season
)).c_str());
299 EGSPD::CSeason::TSeason readSeason
= ForceDisplayedSeason
[season
]= EGSPD::CSeason::fromString(strSeason
);
300 if(readSeason
<EGSPD::CSeason::Invalid
)
301 ForceDisplayedSeason
[season
]= readSeason
;
306 void CContinentParameters::buildFogMapBuild(const NLGEORGES::UFormElm
&item
)
308 item
.getValueByName (FogMapBuild
.Map
[CFogMapBuild::Day
], "FogDayMap");
309 item
.getValueByName (FogMapBuild
.Map
[CFogMapBuild::Night
], "FogNightMap");
310 item
.getValueByName (FogMapBuild
.Map
[CFogMapBuild::Distance
], "FogDistMap");
311 item
.getValueByName (FogMapBuild
.Map
[CFogMapBuild::Depth
], "FogDepthMap");
312 item
.getValueByName (FogMapBuild
.Map
[CFogMapBuild::NoPrecipitation
], "NoRainMap");
313 item
.getValueByName (FogStart
, "FogStart");
314 item
.getValueByName (FogEnd
, "FogEnd");
315 item
.getValueByName (FogMapBuild
.ZoneMin
, "ZoneMin");
316 item
.getValueByName (FogMapBuild
.ZoneMax
, "ZoneMax");
317 if (FogStart
> FogEnd
)
319 std::swap(FogStart
, FogEnd
);
321 if (!item
.getValueByName (RootFogStart
, "RootFogStart"))
323 RootFogStart
= FogStart
;
325 if (!item
.getValueByName (RootFogEnd
, "RootFogEnd"))
329 if (RootFogStart
> RootFogEnd
)
331 std::swap(RootFogStart
, RootFogEnd
);
336 //=========================================================================
337 void CContinentParameters::serial(NLMISC::IStream
&f
)
342 f
.serial(LandscapeIG
);
345 f
.serial(SkyFogPartName
);
346 f
.serial(BackgroundIGName
);
348 for(uint k
= 0; k
< EGSPD::CSeason::Invalid
; ++k
)
350 f
.serial(CanopyIGfileName
[k
]);
353 f
.serial(MicroVeget
);
356 f
.serial(CoarseMeshMap
);
357 f
.serial(EntitySunContributionPower
);
358 f
.serial(EntitySunContributionMaxThreshold
);
359 f
.serial(LandscapeLightDay
);
360 f
.serial(LandscapeLightDusk
);
361 f
.serial(LandscapeLightNight
);
362 f
.serial(LandscapePointLightMaterial
);
363 f
.serial(EntityLightDay
);
364 f
.serial(EntityLightDusk
);
365 f
.serial(EntityLightNight
);
366 f
.serial(RootLightDay
);
367 f
.serial(RootLightDusk
);
368 f
.serial(RootLightNight
);
370 f
.serialCont(ZCList
);
372 f
.serial(FogMapBuild
);
375 f
.serial(RootFogStart
);
376 f
.serial(RootFogEnd
);
380 //f.serialCont(LandMarks);
381 f
.serial(LocalizedName
);
383 f
.serialCont(MicroLifeZones
);
388 for (uint i
= 0; i
< EGSPD::CSeason::Invalid
; ++i
)
390 f
.serial(TileColorMono
[i
]);
391 f
.serial(TileColorFactor
[i
]);
392 f
.serial(StaticLightingFactor
[i
]);
393 f
.serial(SkySheet
[i
]);
394 f
.serialEnum(ForceDisplayedSeason
[i
]);
398 //=========================================================================
400 void CContinentParameters::CZC::serial(NLMISC::IStream
&f
)
403 f
.serial (ForceLoadDist
);
405 f
.serial (UnloadDist
);
406 f
.serial (EnableRuins
);
409 //=========================================================================
410 void CContinentSheet::build(const NLGEORGES::UFormElm
&item
)
412 Continent
.build(item
);
414 // Load the village list
415 if(item
.getNodeByName (&elm
, "Villages") && elm
)
417 // Get number of village
419 nlverify (elm
->getArraySize (numVillage
));
420 Villages
.resize(numVillage
);
423 for(uint k
= 0; k
< numVillage
; ++k
)
426 const UFormElm
*villageForm
;
427 if (elm
->getArrayNode (&villageForm
, k
) && villageForm
)
429 Villages
[k
].build(*villageForm
);
430 elm
->getArrayNodeName(Villages
[k
].Name
, k
);
434 // load the weather functions
435 // Build season descriptor
436 static const char *seasonFuncName
[] =
438 "SpringWeatherFunction",
439 "SummerWeatherFunction",
440 "AutumnWeatherFunction",
441 "WinterWeatherFunction"
443 // added - 1 because there is an invalid season
444 nlctassert(sizeof(seasonFuncName
) / sizeof(seasonFuncName
[0]) == EGSPD::CSeason::Invalid
);
446 // Load weather functions & sky sheets
447 for(uint k
= 0; k
< EGSPD::CSeason::Invalid
; ++k
)
449 const NLGEORGES::UFormElm
*elm
;
450 if (item
.getNodeByName(&elm
, seasonFuncName
[k
]) && elm
)
452 WeatherFunction
[k
].build(*elm
);
458 //=========================================================================
459 void CContinentSheet::serial(NLMISC::IStream
&f
)
462 f
.serialCont(Villages
);
463 for(uint k
= 0; k
< EGSPD::CSeason::Invalid
; ++k
)
465 f
.serial(WeatherFunction
[k
]);
469 //=========================================================================
470 /*void CLandMark::build(const NLGEORGES::UFormElm &item)
472 item.getValueByName(Pos.x, "X");
473 item.getValueByName(Pos.y, "Y");
474 item.getValueByName(TitleTextID, "Name");
477 //=========================================================================
478 void CLandMark::serial(NLMISC::IStream &f)
480 f.serial(Pos, TitleTextID);