00001 //////////////////////////////////////////////////////////////////////////////// 00002 // Scorched3D (c) 2000-2009 00003 // 00004 // This file is part of Scorched3D. 00005 // 00006 // Scorched3D is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 2 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // Scorched3D is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with Scorched3D; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 //////////////////////////////////////////////////////////////////////////////// 00020 00021 #include <client/ClientStartGameHandler.h> 00022 #include <client/ClientState.h> 00023 #include <client/ClientNewGameHandler.h> 00024 #include <client/ScorchedClient.h> 00025 #include <landscape/Landscape.h> 00026 #include <landscapemap/LandscapeMaps.h> 00027 #include <engine/ActionController.h> 00028 #include <tank/TankContainer.h> 00029 #include <tank/TankAccessories.h> 00030 #include <tank/TankCamera.h> 00031 #include <graph/MainCamera.h> 00032 #include <graph/OptionsDisplay.h> 00033 #include <common/OptionsTransient.h> 00034 #include <common/OptionsScorched.h> 00035 #include <common/Defines.h> 00036 #include <sound/SoundUtils.h> 00037 #include <coms/ComsStartGameMessage.h> 00038 #include <weapons/Accessory.h> 00039 00040 ClientStartGameHandler *ClientStartGameHandler::instance_ = 0; 00041 00042 ClientStartGameHandler *ClientStartGameHandler::instance() 00043 { 00044 if (!instance_) 00045 { 00046 instance_ = new ClientStartGameHandler(); 00047 } 00048 00049 return instance_; 00050 } 00051 00052 ClientStartGameHandler::ClientStartGameHandler() 00053 { 00054 ScorchedClient::instance()->getComsMessageHandler().addHandler( 00055 "ComsStartGameMessage", 00056 this); 00057 } 00058 00059 ClientStartGameHandler::~ClientStartGameHandler() 00060 { 00061 00062 } 00063 00064 bool ClientStartGameHandler::processMessage( 00065 NetMessage &netMessage, 00066 const char *messageType, 00067 NetBufferReader &reader) 00068 { 00069 ComsStartGameMessage message; 00070 if (!message.readMessage(reader)) return false; 00071 00072 ScorchedClient::instance()->getTankContainer().setCurrentPlayerId( 00073 message.getCurrentPlayerId()); 00074 Tank *current = ScorchedClient::instance()->getTankContainer().getCurrentTank(); 00075 00076 // Set the camera back to this players camera position 00077 if (OptionsDisplay::instance()->getStorePlayerCamera()) 00078 { 00079 if (current) 00080 { 00081 MainCamera::instance()->getTarget().getCamera().setLookAt(current->getCamera().getCameraLookAt()); 00082 Vector rotation = current->getCamera().getCameraRotation(); 00083 MainCamera::instance()->getTarget().getCamera().movePosition(rotation[0], rotation[1], rotation[2]); 00084 MainCamera::instance()->getTarget().setCameraType((TargetCamera::CamType) current->getCamera().getCameraType()); 00085 } 00086 } 00087 00088 // Ensure that the landscape is set to the "proper" texture 00089 Landscape::instance()->restoreLandscapeTexture(); 00090 00091 // make sound to tell client a new game is commencing 00092 if (current->getDestinationId() == 00093 ScorchedClient::instance()->getTankContainer().getCurrentDestinationId()) 00094 { 00095 CACHE_SOUND(playSound, S3D::getDataFile("data/wav/misc/play.wav")); 00096 SoundUtils::playRelativeSound(VirtualSoundPriority::eText, playSound); 00097 } 00098 00099 // Stimulate into the new game state 00100 ScorchedClient::instance()->getGameState().stimulate(ClientState::StimWait); 00101 ScorchedClient::instance()->getGameState().checkStimulate(); 00102 if (message.getBuyWeapons()) 00103 { 00104 ScorchedClient::instance()->getGameState().stimulate( 00105 ClientState::StimBuyWeapons); 00106 } 00107 else 00108 { 00109 ScorchedClient::instance()->getGameState().stimulate( 00110 ClientState::StimPlaying); 00111 00112 // Set the current weapon, so any graphics are updated 00113 Tank *currentTank = 00114 ScorchedClient::instance()->getTankContainer().getCurrentTank(); 00115 if (currentTank) 00116 { 00117 Accessory *currentWeapon = currentTank->getAccessories().getWeapons().getCurrent(); 00118 if (currentWeapon && 00119 currentWeapon->getPositionSelect() != Accessory::ePositionSelectNone) 00120 { 00121 std::list<Accessory *> &entries = 00122 currentTank->getAccessories().getAllAccessoriesByGroup("weapon"); 00123 if (!entries.empty()) currentWeapon = entries.front(); 00124 } 00125 currentTank->getAccessories().getWeapons().setWeapon(currentWeapon); 00126 } 00127 } 00128 return true; 00129 }
1.5.3