Planeshift
|
00001 /* 00002 * modehandler.h Keith Fulton <[email protected]> 00003 * 00004 * Copyright (C) 2001-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 MODEHANDLER_H 00020 #define MODEHANDLER_H 00021 //============================================================================= 00022 // Crystal Space Includes 00023 //============================================================================= 00024 #include <csutil/parray.h> 00025 #include <csutil/ref.h> 00026 #include <csutil/cscolor.h> 00027 #include <csutil/weakref.h> 00028 #include <iengine/portal.h> 00029 00030 //============================================================================= 00031 // Project Includes 00032 //============================================================================= 00033 #include "net/cmdbase.h" 00034 00035 //============================================================================= 00036 // Local Includes 00037 //============================================================================= 00038 00039 struct iEngine; 00040 struct iBase; 00041 struct iSoundManager; 00042 struct iLoaderContext; 00043 struct LightingList; 00044 struct LightingSetting; 00045 struct WeatherInfo; 00046 00047 class pawsChatWindow; 00048 class GEMClientActor; 00049 class psCelClient; 00050 class MsgHandler; 00051 class WeatherObject; 00052 00053 /* Defines for the various times of day. Some things may need to trigger on a 00054 'general' time of day. */ 00055 enum TimeOfDay 00056 { 00057 TIME_ANY, 00058 TIME_NIGHT, 00059 TIME_MORNING, 00060 TIME_AFTERNOON, 00061 TIME_EVENING 00062 }; 00063 00064 00066 00067 /* This class is used as callback when a portal is shown. 00068 This is needed to have correct weather */ 00069 class psPortalCallback : public scfImplementation1<psPortalCallback,iPortalCallback> 00070 { 00071 public: 00072 psPortalCallback(); 00073 virtual ~psPortalCallback(); 00074 00080 virtual bool Traverse (iPortal* portal,iBase* context); 00081 00082 const char* GetSector() { return sector; } 00083 00084 private: 00085 csString sector; 00086 csRef<iLoaderContext> loaderContext; 00087 }; 00088 00090 struct WeatherPortal 00091 { 00092 WeatherInfo* wi; 00093 WeatherObject* downfall; 00094 00095 iPortal* portal; 00096 csBox3 bbox; 00097 csVector3 pos; 00098 }; 00099 00107 class ModeHandler : public psClientNetSubscriber 00108 { 00109 public: 00110 ModeHandler(psCelClient *cc,MsgHandler* mh,iObjectRegistry* object_reg); 00111 virtual ~ModeHandler(); 00112 virtual void HandleMessage(MsgEntry* me); 00113 00114 bool Initialize(); 00115 00116 void ClearLightFadeSettings(); 00117 void FinishLightFade(); 00118 00119 void PreProcess(); 00120 00121 void SetEntity(GEMClientActor *ent); 00122 00123 // Get the general time of day it is ( from enum ) 00124 TimeOfDay GetGeneralTime() { return timeOfDay; } 00125 00126 // Get the hour of the day. 00127 size_t GetTime() { return clockHour; } 00128 00129 void DoneLoading(const char* sectorname); // Called when every connected sector is loaded 00130 00132 void CreatePortalWeather(iSector* sector, csTicks delta); 00133 bool CreatePortalWeather(iPortal* portal, csTicks delta); 00135 void RemovePortalWeather(); 00137 void RemoveWeather(); 00138 00139 void AddDownfallObject(WeatherObject* weatherobject); 00140 void RemoveDownfallObject(WeatherObject* weatherobject); 00141 00142 void SetModeSounds(uint8_t mode); 00143 void UpdateLights(); 00144 00145 protected: 00146 GEMClientObject* actorEntity; 00147 00149 TimeOfDay timeOfDay; 00150 00152 uint clockHour; 00153 00154 iObjectRegistry* object_reg; 00155 csRef<psCelClient> celclient; 00156 csRef<MsgHandler> msghandler; 00157 csRef<iEngine> engine; 00158 csRef<iVFS> vfs; 00159 00160 // Each element represents an hour of the day. 00161 csPDelArray<LightingList> lights; 00162 // Track the stage of the current step. 00163 uint stepStage; 00164 csTicks interpolation_time; 00165 uint interpolation_step; 00166 csTicks last_interpolation_reset; 00167 bool interpolation_complete; 00168 csRandomGen *randomgen; 00169 bool sound_queued; 00170 csString sound_name; 00171 csTicks sound_when; 00172 00173 // Lighting variable. 00174 csRef<iSharedVariable> lightningreset; 00175 CS::ShaderVarStringID ambientId; 00176 CS::ShaderVarStringID combinedAmbientId; 00177 00178 // Weather intepolation stuff 00179 csTicks last_weather_update; 00180 csTicks weather_update_time; 00181 00182 csHash<WeatherInfo*, csString> weatherlist; 00183 00184 // Weather gfx object for current sector 00185 WeatherObject* downfall; // Weather object following the player around 00186 WeatherObject* fog; // Weather object that is always in effect 00187 csPDelArray<WeatherPortal> portals; // Weather for portals out of the sector. 00188 bool processWeather; // determine whether to show weather effects or not 00189 00190 void HandleModeMessage(MsgEntry* me); 00191 void HandleWeatherMessage(MsgEntry* me); 00192 void HandleNewSectorMessage(MsgEntry* me); 00193 void HandleCombatEvent(MsgEntry* me); 00194 void HandleSpecialCombatEvent(MsgEntry* me); 00195 void HandleCachedFile(MsgEntry* me); 00196 00197 bool ProcessLighting(LightingSetting *color, float pct); 00198 LightingSetting *FindLight(LightingSetting *light,int which); 00199 00200 bool CheckCurrentSector(GEMClientObject *entity, 00201 const char *sectorname, 00202 csVector3& pos, 00203 iSector*& sector); 00204 00205 void SetSectorMusic(const char *sectorname); 00206 void PublishTime( int newTime ); 00207 00208 void UpdateLights(csTicks when, bool force = false); 00209 00210 /* WEATHER FUNCTIONS */ 00211 // Controls the weather. 00212 void ProcessLighting(const psWeatherMessage::NetWeatherInfo& info); 00213 void ProcessDownfall(const psWeatherMessage::NetWeatherInfo& info); 00214 public: 00215 void ProcessFog(const psWeatherMessage::NetWeatherInfo& info); 00216 protected: 00217 bool CreateWeather(WeatherInfo* ri, csTicks delta); 00218 00219 void StartFollowWeather(); 00220 void StopFollowWeather(); 00221 00222 WeatherObject* CreateDownfallWeatherObject(WeatherInfo* ri); 00223 WeatherObject* CreateStaticWeatherObject(WeatherInfo* ri); 00224 00225 WeatherPortal* GetPortal(iPortal* portal); 00226 WeatherInfo* GetWeatherInfo(const char* sector); 00227 WeatherInfo* CreateWeatherInfo(const char* sector); 00228 float GetDensity(WeatherInfo* wi); 00229 00230 void UpdateWeather(csTicks when); 00231 void UpdateWeatherSounds(); 00232 00233 /* END OF WEATHER FUNCTIONS */ 00234 00235 bool LoadLightingLevels(); // Called from Initialize 00236 00237 00238 private: 00239 pawsChatWindow* chatWindow; 00240 00241 csString MungeName(GEMClientActor* obj, bool startOfPhrase = false); 00242 00243 void SetCombatAnim( GEMClientActor* atObject, csStringID anim ); 00244 00245 void Other( int type, float damage, GEMClientActor* atObject, GEMClientActor* tarObject, csString& location ); 00246 void OtherOutOfRange( GEMClientActor* atObject, GEMClientActor* tarObject ); 00247 void OtherMiss( GEMClientActor* atObject, GEMClientActor* tarObject ); 00248 void OtherDodge( GEMClientActor* atObject, GEMClientActor* tarObject ); 00249 void OtherDeath( GEMClientActor* atObject, GEMClientActor* tarObject ); 00250 void OtherDamage( float damage, GEMClientActor* atObject, GEMClientActor* tarObject ); 00251 void OtherBlock( GEMClientActor* atObject, GEMClientActor* tarObject ); 00252 void OtherNearlyDead(GEMClientActor *tarObject); 00253 00254 void Defend( int type, float damage, GEMClientActor* atObject, GEMClientActor* tarObject, csString& location ); 00255 void DefendOutOfRange( GEMClientActor* atObject, GEMClientActor* tarObject ); 00256 void DefendMiss( GEMClientActor* atObject, GEMClientActor* tarObject ); 00257 void DefendDodge( GEMClientActor* atObject, GEMClientActor* tarObject ); 00258 void DefendDeath( GEMClientActor* atObject ); 00259 void DefendDamage( float damage, GEMClientActor* atObject, GEMClientActor* tarObject, csString& location ); 00260 void DefendBlock( GEMClientActor* atObject, GEMClientActor* tarObject, csString& location ); 00261 void DefendNearlyDead(); 00262 00263 void Attack( int type, float damage, GEMClientActor* atObject, GEMClientActor* tarObject, csString& location ); 00264 void AttackOutOfRange( GEMClientActor* atObject, GEMClientActor* tarObject ); 00265 void AttackMiss(GEMClientActor* atObject, GEMClientActor* tarObject, csString& location ); 00266 void AttackDodge( GEMClientActor* atObject, GEMClientActor* tarObject ); 00267 void AttackDeath( GEMClientActor* atObject, GEMClientActor* tarObject ); 00268 void AttackDamage(float damage, GEMClientActor* atObject, GEMClientActor* tarObject, csString& location ); 00269 void AttackBlock( GEMClientActor* atObject, GEMClientActor* tarObject, csString& location ); 00270 00271 }; 00272 00278 struct LightingList 00279 { 00280 csPDelArray<LightingSetting> colors; 00281 }; 00282 00283 00284 struct LightingSetting 00285 { 00286 bool error; 00287 size_t value; 00288 double density; 00289 csString type; 00290 csString object; 00291 csColor color; 00292 csColor raincolor; 00293 csColor start_color; 00294 csColor base_color; 00295 csColor diff; 00296 csString sector; 00297 // The two cache values below use csWeakRef to make sure that the cache is cleared automatically 00298 // as soon as the light or sector is removed (this can happen in case the region is unloaded). 00299 csWeakRef<iLight> light_cache; // Optimization: pointer to light so we don't have to search it again. 00300 csWeakRef<iSector> sector_cache; // Optimization: pointer to sector so we don't have to search it again. 00301 csRef<csShaderVariable> ambient_cache; // Optimization: pointer to ambient so we don't have to search it again. 00302 csRef<csShaderVariable> combined_ambient_cache; // Optimization: pointer to combined ambient so we don't have to search it again. 00303 }; 00304 00305 #endif