00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <server/ServerShotState.h>
00022 #include <server/ScorchedServer.h>
00023 #include <server/ServerShotHolder.h>
00024 #include <server/ServerCommon.h>
00025 #include <server/ServerChannelManager.h>
00026 #include <coms/ComsMessageSender.h>
00027 #include <common/OptionsScorched.h>
00028 #include <common/OptionsTransient.h>
00029 #include <tank/TankState.h>
00030 #include <engine/ActionController.h>
00031
00032 ServerShotState::ServerShotState() :
00033 GameStateI("ServerShotState"),
00034 shotState_(ScorchedServer::instance()->getContext(), *ServerShotHolder::instance())
00035 {
00036 }
00037
00038 ServerShotState::~ServerShotState()
00039 {
00040 }
00041
00042 void ServerShotState::enterState(const unsigned state)
00043 {
00044
00045 playing_.clear();
00046 std::map<unsigned int, Tank *>::iterator itor;
00047 std::map<unsigned int, Tank *> tanks =
00048 ScorchedServer::instance()->getTankContainer().getPlayingTanks();
00049 std::set<unsigned int>::iterator findItor;
00050 for (itor = tanks.begin();
00051 itor != tanks.end();
00052 itor++)
00053 {
00054 Tank *tank = (*itor).second;
00055 if (tank->getState().getState() != TankState::sPending &&
00056 tank->getState().getState() != TankState::sLoading &&
00057 tank->getState().getState() != TankState::sInitializing &&
00058 tank->getDestinationId() != 0)
00059 {
00060 unsigned int destination = tank->getDestinationId();
00061 playing_.insert(destination);
00062 }
00063 }
00064
00065
00066
00067 if (ServerShotHolder::instance()->allSkipped() &&
00068 ScorchedServer::instance()->getOptionsGame().getTurnType().getValue() == OptionsGame::TurnSimultaneous)
00069 {
00070 bool allAis = true;
00071 bool someAlive = false;
00072 std::map<unsigned int, Tank *> &tanks =
00073 ScorchedServer::instance()->getTankContainer().getPlayingTanks();
00074 std::map<unsigned int, Tank *>::iterator itor;
00075 for (itor = tanks.begin();
00076 itor != tanks.end();
00077 itor++)
00078 {
00079 Tank *tank = (*itor).second;
00080 if (tank->getState().getState() == TankState::sNormal)
00081 {
00082 someAlive = true;
00083 if (tank->getDestinationId() != 0)
00084 {
00085 allAis = false;
00086 }
00087 }
00088 }
00089
00090 if (allAis && someAlive)
00091 {
00092 ServerChannelManager::instance()->sendText(
00093 ChannelText("info",
00094 "TURN_SKIPPING_STALEMATE",
00095 "Skipping all turns due to stalemate..."),
00096 true);
00097 ScorchedServer::instance()->getOptionsTransient().startNewRound();
00098 }
00099 }
00100
00101
00102
00103
00104
00105
00106 unsigned int seed = rand();
00107 ComsPlayMovesMessage playMovesMessage;
00108 playMovesMessage.getSeed() = seed;
00109 ServerShotHolder::instance()->createMessage(playMovesMessage);
00110 ComsMessageSender::sendToAllPlayingClients(playMovesMessage);
00111
00112
00113 ScorchedServer::instance()->getTankContainer().setAllNotReady();
00114 ScorchedServer::instance()->getActionController().getRandom().seed(seed);
00115 shotState_.setup();
00116 }
00117
00118 bool ServerShotState::acceptStateChange(const unsigned state,
00119 const unsigned nextState,
00120 float frameTime)
00121 {
00122 return shotState_.run(frameTime);
00123 }