00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <server/ServerPlayingState.h>
00022 #include <server/ServerShotHolder.h>
00023 #include <server/ServerState.h>
00024 #include <server/ScorchedServer.h>
00025 #include <server/ServerChannelManager.h>
00026 #include <server/TurnController.h>
00027 #include <server/ServerCommon.h>
00028 #include <tank/TankContainer.h>
00029 #include <tank/TankState.h>
00030 #include <tank/TankScore.h>
00031 #include <lua/LUAScriptHook.h>
00032 #include <common/OptionsScorched.h>
00033 #include <common/Logger.h>
00034
00035 ServerPlayingState::ServerPlayingState() :
00036 GameStateI("ServerPlayingState"),
00037 time_(0.0f)
00038 {
00039 ScorchedServer::instance()->getLUAScriptHook().addHookProvider("server_playing");
00040 }
00041
00042 ServerPlayingState::~ServerPlayingState()
00043 {
00044 }
00045
00046 void ServerPlayingState::enterState(const unsigned state)
00047 {
00048
00049 time_ = 0.0f;
00050
00051
00052 ScorchedServer::instance()->getLUAScriptHook().callHook("server_playing");
00053 }
00054
00055 bool ServerPlayingState::acceptStateChange(const unsigned state,
00056 const unsigned nextState,
00057 float frameTime)
00058 {
00059
00060 time_ += frameTime;
00061 int shotTime = 0;
00062 if (state == ServerState::ServerStateBuying)
00063 {
00064 shotTime = ScorchedServer::instance()->getOptionsGame().getBuyingTime();
00065 }
00066 else
00067 {
00068 shotTime = ScorchedServer::instance()->getOptionsGame().getShotTime();
00069 }
00070
00071
00072 if (shotTime > 0)
00073 {
00074 if (time_ > shotTime + 5)
00075 {
00076
00077
00078
00079
00080 std::list<unsigned int> &tanks =
00081 TurnController::instance()->getPlayersThisTurn();
00082 std::list<unsigned int>::iterator itor;
00083 for (itor = tanks.begin();
00084 itor != tanks.end();
00085 itor++)
00086 {
00087 Tank *tank = ScorchedServer::instance()->getTankContainer().getTankById(*itor);
00088 if (tank && tank->getState().getState() == TankState::sNormal)
00089 {
00090 if (!ServerShotHolder::instance()->haveShot(
00091 tank->getPlayerId()))
00092 {
00093 int movesMissed = tank->getScore().getMissedMoves() + 1;
00094 tank->getScore().setMissedMoves(movesMissed);
00095
00096 #ifdef S3D_SERVER
00097
00098 if (ScorchedServer::instance()->getOptionsGame().getAllowedMissedMoves() > 0)
00099 {
00100 if (state == ServerState::ServerStateBuying)
00101 {
00102 ServerChannelManager::instance()->sendText(
00103 ChannelText("info",
00104 "PLAYER_MISSED_BUY",
00105 "Player \"{0}\" failed to buy, allowed {1} more missed move(s)",
00106 tank->getTargetName(),
00107 ScorchedServer::instance()->getOptionsGame().getAllowedMissedMoves() - movesMissed),
00108 true);
00109 }
00110 else
00111 {
00112 ServerChannelManager::instance()->sendText(
00113 ChannelText("info",
00114 "PLAYER_MISSED_SHOOT",
00115 "Player \"{0}\" failed to shoot, allowed {1} more missed move(s)",
00116 tank->getTargetName(),
00117 ScorchedServer::instance()->getOptionsGame().getAllowedMissedMoves() - movesMissed),
00118 true);
00119 }
00120
00121
00122 if (movesMissed >= ScorchedServer::instance()->getOptionsGame().getAllowedMissedMoves())
00123 {
00124
00125 ServerCommon::kickDestination(tank->getDestinationId());
00126 }
00127 }
00128 #endif
00129 }
00130 }
00131 }
00132
00133 return true;
00134 }
00135 }
00136
00137
00138 if (ServerShotHolder::instance()->haveAllTurnShots())
00139 {
00140 return true;
00141 }
00142
00143 return false;
00144 }