Planeshift

weathermanager.h

Go to the documentation of this file.
00001 /*
00002  * weathermanager.h
00003  *
00004  * Copyright (C) 2002 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 #ifndef __WEATHERMANAGER_H__
00020 #define __WEATHERMANAGER_H__
00021 
00022 //=============================================================================
00023 // Crystal Space Includes
00024 //=============================================================================
00025 #include <iengine/sector.h>
00026 #include <csutil/randomgen.h>
00027 #include <csutil/sysfunc.h>
00028 
00029 //=============================================================================
00030 // Project Includes
00031 //=============================================================================
00032 #include "util/gameevent.h"
00033 
00034 //=============================================================================
00035 // Local Includes
00036 //=============================================================================
00037 
00038 
00039 
00040 class psWeatherGameEvent;
00041 class psSectorInfo;
00042 class CacheManager;
00043 
00048 class WeatherManager
00049 {
00050 public:
00051     WeatherManager(CacheManager* cachemanager);
00052     ~WeatherManager();
00053 
00054     void Initialize();
00055 
00056     void QueueNextEvent(int delayticks,
00057                         int eventtype,
00058                         int eventvalue,
00059                         int duration,
00060                         int fade,
00061                         const char* sector,
00062                         psSectorInfo* si,
00063                         uint clientnum = 0,
00064                         int r = 0,
00065                         int g = 0,
00066                         int b = 0);
00067 
00068 
00074     void StartWeather(psSectorInfo* si, unsigned int type = 0);
00075 
00083     void StopWeather(psSectorInfo* si, unsigned int type = 0);
00084     void HandleWeatherEvent(psWeatherGameEvent* event);
00085     void SendClientGameTime(int cnum);
00086     void BroadcastGameTime();
00087     void BroadcastGameTimeSuperclients();
00088     void UpdateClient(uint32_t cnum);
00089     int GetGameTODMinute()
00090     {
00091         return gameTimeMinute;
00092     }
00093     int GetGameTODHour()
00094     {
00095         return gameTimeHour;
00096     }
00097     int GetGameTODDay()
00098     {
00099         return gameTimeDay;
00100     }
00101     int GetGameTODMonth()
00102     {
00103         return gameTimeMonth;
00104     }
00105     int GetGameTODYear()
00106     {
00107         return gameTimeYear;
00108     }
00109 
00113     void StartGameTime();
00114     void SaveGameTime();
00115     void SetGameTime(int hour,int minute);
00116 
00117 
00118 protected:
00119     csRandomGen* randomgen;
00120     int gameTimeMinute;
00121     int gameTimeHour;
00122     int gameTimeDay;
00123     int gameTimeMonth;
00124     int gameTimeYear;
00125 
00126     csArray<psWeatherGameEvent*> ignored; 
00127 
00128     CS::Threading::Mutex eventsMutex;
00129     csArray<psWeatherGameEvent*> events; // Ugly, but we need a copy of our events
00130 
00131     CacheManager* cacheManager;
00132 };
00133 
00137 class psWeatherGameEvent : public psGameEvent
00138 {
00139 public:
00140     psWeatherGameEvent(WeatherManager* mgr,
00141                        int delayticks,
00142                        int eventtype,
00143                        int eventvalue,
00144                        int duration,
00145                        int fade,
00146                        const char* sector,
00147                        psSectorInfo* si,
00148                        uint client,
00149                        int r = 0,
00150                        int g = 0,
00151                        int b = 0);
00152 
00153     virtual void Trigger();  
00154 
00155     const char* GetType();
00156 
00157     int cr,cg,cb;
00158     int type, value, duration,fade;
00159     csString sector;
00160     psSectorInfo* si;
00161     uint clientnum;
00162 
00163 
00164 protected:
00165     WeatherManager* weathermanager;
00166 
00167 
00168 };
00169 
00170 #endif
00171