TankResign.cpp

Go to the documentation of this file.
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 <actions/TankResign.h>
00022 #include <engine/ScorchedContext.h>
00023 #include <tank/TankContainer.h>
00024 #include <tank/TankState.h>
00025 #include <tank/TankScore.h>
00026 #include <tank/TankTeamScore.h>
00027 #include <common/Defines.h>
00028 #include <common/ChannelManager.h>
00029 #include <common/OptionsScorched.h>
00030 #include <common/StatsLogger.h>
00031 #include <lang/LangResource.h>
00032 
00033 TankResign::TankResign(unsigned int playerId) :
00034         ActionReferenced("TankResign"),
00035         firstTime_(true),
00036         playerId_(playerId)
00037 {
00038 
00039 }
00040 
00041 TankResign::~TankResign()
00042 {
00043 }
00044 
00045 void TankResign::init()
00046 {
00047 }
00048 
00049 void TankResign::simulate(fixed frameTime, bool &remove)
00050 {
00051         if (firstTime_)
00052         {
00053                 firstTime_ = false;
00054                 Tank *tank = 
00055                         context_->getTankContainer().getTankById(playerId_);
00056                 if (tank && tank->getState().getState() == TankState::sNormal)
00057                 {
00058                         // update player assists when this player resigns
00059                         int moneyPerAssist = 
00060                                 context_->getOptionsGame().getMoneyWonPerAssistPoint() *
00061                                         5;
00062                         int scorePerAssist = context_->getOptionsGame().getScorePerAssist();
00063 
00064                         // Update assists
00065                         std::set<unsigned int> &hurtBy = 
00066                                 tank->getScore().getHurtBy();
00067                         std::set<unsigned int>::iterator itor;
00068                         for (itor = hurtBy.begin();
00069                                 itor != hurtBy.end();
00070                                 itor++)
00071                         {
00072                                 unsigned int hurtByPlayer = (*itor);
00073                                 Tank *hurtByTank = 
00074                                         context_->getTankContainer().getTankById(hurtByPlayer);
00075                                 if (!hurtByTank) continue;
00076 
00077                                 // Only score when the tank does not hurt itself
00078                                 if (hurtByTank == tank) continue;
00079 
00080                                 // or a team member
00081                                 if ((context_->getOptionsGame().getTeams() > 1) &&
00082                                         (hurtByTank->getTeam() == tank->getTeam())) continue;
00083 
00084                                 // Update assist score
00085                                 hurtByTank->getScore().setAssists(
00086                                         hurtByTank->getScore().getAssists() + 1);
00087                                 hurtByTank->getScore().setMoney(
00088                                         hurtByTank->getScore().getMoney() + moneyPerAssist);
00089                                 hurtByTank->getScore().setScore(
00090                                         hurtByTank->getScore().getScore() + scorePerAssist);
00091 
00092                                 if (hurtByTank->getTeam() > 0)
00093                                 {
00094                                         context_->getTankTeamScore().addScore(
00095                                                 scorePerAssist, hurtByTank->getTeam());
00096                                 }
00097                         }
00098 
00099                         // tank is dead
00100                         tank->getState().setState(TankState::sDead);
00101 
00102                         // This tank has lost a life
00103                         if (tank->getState().getMaxLives() > 0)
00104                         {
00105                                 tank->getState().setLives(
00106                                         tank->getState().getLives() - 1);
00107                         }
00108 
00109                         StatsLogger::instance()->tankResigned(tank);
00110 
00111 #ifndef S3D_SERVER
00112                         {
00113                                 ChannelText text("combat",
00114                                         LANG_RESOURCE_1(
00115                                                 "TANK_RESIGNED",
00116                                                 "[p:{0}] resigned from round", 
00117                                                 tank->getTargetName()));
00118                                 ChannelManager::showText(*context_, text);
00119                         }
00120 #endif // #ifndef S3D_SERVER
00121                 }
00122         }
00123 
00124         remove = true;
00125         Action::simulate(frameTime, remove);
00126 }
00127 
00128 std::string TankResign::getActionDetails()
00129 {
00130         return S3D::formatStringBuffer("%u", playerId_);
00131 }

Generated on Mon Feb 16 15:14:48 2009 for Scorched3D by  doxygen 1.5.3