00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <weapons/WeaponGiveWin.h>
00022 #include <weapons/AccessoryStore.h>
00023 #include <engine/ActionController.h>
00024 #include <tank/TankContainer.h>
00025 #include <tank/TankTeamScore.h>
00026 #include <tank/TankColorGenerator.h>
00027 #include <tank/TankScore.h>
00028 #include <common/Defines.h>
00029 #include <common/ChannelManager.h>
00030 #include <common/OptionsScorched.h>
00031 #include <lang/LangResource.h>
00032
00033 REGISTER_ACCESSORY_SOURCE(WeaponGiveWin);
00034
00035 WeaponGiveWin::WeaponGiveWin() :
00036 winningTeam_(0)
00037 {
00038
00039 }
00040
00041 WeaponGiveWin::~WeaponGiveWin()
00042 {
00043
00044 }
00045
00046 bool WeaponGiveWin::parseXML(AccessoryCreateContext &context, XMLNode *accessoryNode)
00047 {
00048 if (!Weapon::parseXML(context, accessoryNode)) return false;
00049
00050 if (!accessoryNode->getNamedChild("objective", objective_)) return false;
00051
00052 accessoryNode->getNamedChild("winningteam", winningTeam_);
00053
00054 return true;
00055 }
00056
00057 void WeaponGiveWin::fireWeapon(ScorchedContext &context,
00058 WeaponFireContext &weaponContext, FixedVector &position, FixedVector &velocity)
00059 {
00060 context.getActionController().addAction(
00061 new CallbackWeapon("WeaponGiveWin", this, 0, 0,
00062 weaponContext, position, velocity));
00063 }
00064
00065 void WeaponGiveWin::weaponCallback(
00066 ScorchedContext &context,
00067 WeaponFireContext &weaponContext, FixedVector &position, FixedVector &velocity,
00068 unsigned int data)
00069 {
00070 if (context.getOptionsGame().getTeams() > 1)
00071 {
00072 int team = winningTeam_;
00073 if (team == 0)
00074 {
00075 Tank *tank = context.getTankContainer().getTankById(weaponContext.getPlayerId());
00076 if (!tank) return;
00077
00078 team = tank->getTeam();
00079 }
00080 context.getTankTeamScore().setWonGame(team);
00081
00082 {
00083 ChannelText text("combat",
00084 LANG_RESOURCE_2("TANK_TEAM_WIN",
00085 "{0} team {1} and won the game",
00086 TankColorGenerator::getTeamName(team),
00087 objective_));
00088 ChannelManager::showText(context, text);
00089 }
00090 }
00091 else
00092 {
00093 Tank *tank = context.getTankContainer().getTankById(weaponContext.getPlayerId());
00094 if (!tank) return;
00095
00096 tank->getScore().setWonGame();
00097
00098 {
00099 ChannelText text("combat",
00100 LANG_RESOURCE_2("TANK_SINGLE_WIN",
00101 "[p:{0}] {1} and won the game",
00102 tank->getTargetName(),
00103 objective_));
00104 ChannelManager::showText(context, text);
00105 }
00106 }
00107 }
00108