Add infos into target window
[ryzomcore.git] / ryzom / server / src / entities_game_service / weather / weather.cpp
blob605978f355c3eac4b56a491e98f947887ba077d6
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
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/>.
19 #include "stdpch.h"
21 #include "weather.h"
23 // #include "game_share/property_manager_template.h"
24 // #include "game_share/property_manager_container_template.h"
25 #include "game_share/cdb.h"
26 #include "game_share/cdb_leaf.h"
27 #include "game_share/cdb_branch.h"
28 #include "game_share/cdb_synchronised.h"
30 using namespace NLMISC;
31 using namespace std;
33 CMirrorPropValue< float > CWeather::_RyzomTime;
34 CMirrorPropValue< uint8 > CWeather::_DayCycle;
36 //-----------------------------------------------
37 // constructor
38 //-----------------------------------------------
39 void CWeather::init()
41 NL_ALLOC_CONTEXT(WTHR_INIT);
42 WeatherCfg.load( WeatherFileName );
44 ztrhetjyuety
47 CPropertyManager * manager = CContainerPropertyEmiter::getPropertyManager( string("RyzomTime") );
48 if( manager == 0 )
50 manager = new CSpecializedPropertyManager<float>( "RyzomTime", 0);
51 CContainerPropertyEmiter::addPropertyManager( manager );
53 static_cast<CSpecializedPropertyManager<float> *>(manager)->addProperty( RYZOMID::World, &_RyzomTime );
55 manager = CContainerPropertyEmiter::getPropertyManager( string("DayCycle") );
56 if( manager == 0 )
58 manager = new CSpecializedPropertyManager<uint8>( "DayCycle", 0);
59 CContainerPropertyEmiter::addPropertyManager( manager );
61 static_cast<CSpecializedPropertyManager<uint8> *>(manager)->addProperty( RYZOMID::World, &_DayCycle );
64 //-----------------------------------------------
65 // Update Ryzom time
66 //-----------------------------------------------
67 void CWeather::updateRyzomTime()
69 uint32 Time = (uint32) ( CTickEventHandler::getGameTime() + 500) % ( (uint32) ( WeatherCfg.RealDayLength ) );
70 float RyzomTime = Time * WeatherCfg.NumHours / WeatherCfg.RealDayLength;
71 _RyzomTime = RyzomTime;
73 if( ( RyzomTime < WeatherCfg.DawnTransitionStartHour ) || ( RyzomTime > WeatherCfg.NightTransitionEndHour ) )
75 _DayCycle = night;
77 else if( RyzomTime < WeatherCfg.DawnTransitionEndHour )
79 _DayCycle = dawn;
81 else if( RyzomTime < WeatherCfg.NightTransitionStartHour )
83 _DayCycle = day;
85 else
87 _DayCycle = twilight;
91 static string DawnString("dawn");
92 static string DayString("day");
93 static string TwilightString("twilight");
94 static string NightString("night");
95 static string UnknownString("Unknown");
97 //-----------------------------------------------
98 // get string of day cycle
99 //-----------------------------------------------
100 const std::string& CWeather::toString( uint8 c )
102 switch( c )
104 case dawn:
105 return DawnString;
106 case day:
107 return DayString;
108 case twilight:
109 return TwilightString;
110 case night:
111 return NightString;
112 default:
113 return UnknownString;