00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00059 int moneyPerAssist =
00060 context_->getOptionsGame().getMoneyWonPerAssistPoint() *
00061 5;
00062 int scorePerAssist = context_->getOptionsGame().getScorePerAssist();
00063
00064
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
00078 if (hurtByTank == tank) continue;
00079
00080
00081 if ((context_->getOptionsGame().getTeams() > 1) &&
00082 (hurtByTank->getTeam() == tank->getTeam())) continue;
00083
00084
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
00100 tank->getState().setState(TankState::sDead);
00101
00102
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 }