Merge from development branch heightmap to main.
[scorched3d.git] / src / common / weapons / WeaponGiveWin.cpp
blob842e7db494f3702afe4b963d562f350b3cfa3d9a
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2003
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <weapons/WeaponGiveWin.h>
22 #include <weapons/AccessoryStore.h>
23 #include <engine/ActionController.h>
24 #include <tank/TankContainer.h>
25 #include <tank/TankTeamScore.h>
26 #include <tank/TankColorGenerator.h>
27 #include <tank/TankScore.h>
28 #include <common/Defines.h>
29 #include <common/ChannelManager.h>
30 #include <common/OptionsScorched.h>
31 #include <lang/LangResource.h>
33 REGISTER_ACCESSORY_SOURCE(WeaponGiveWin);
35 WeaponGiveWin::WeaponGiveWin() :
36 winningTeam_(0)
41 WeaponGiveWin::~WeaponGiveWin()
46 bool WeaponGiveWin::parseXML(AccessoryCreateContext &context, XMLNode *accessoryNode)
48 if (!Weapon::parseXML(context, accessoryNode)) return false;
50 if (!accessoryNode->getNamedChild("objective", objective_)) return false;
52 accessoryNode->getNamedChild("winningteam", winningTeam_);
54 return true;
57 void WeaponGiveWin::fireWeapon(ScorchedContext &context,
58 WeaponFireContext &weaponContext, FixedVector &position, FixedVector &velocity)
60 context.getActionController().addAction(
61 new CallbackWeapon("WeaponGiveWin", this, 0, 0,
62 weaponContext, position, velocity));
65 void WeaponGiveWin::weaponCallback(
66 ScorchedContext &context,
67 WeaponFireContext &weaponContext, FixedVector &position, FixedVector &velocity,
68 unsigned int data)
70 if (context.getOptionsGame().getTeams() > 1)
72 int team = winningTeam_;
73 if (team == 0)
75 Tank *tank = context.getTankContainer().getTankById(weaponContext.getPlayerId());
76 if (!tank) return;
78 team = tank->getTeam();
80 context.getTankTeamScore().setWonGame(team);
83 ChannelText text("combat",
84 LANG_RESOURCE_2("TANK_TEAM_WIN",
85 "{0} team {1} and won the game",
86 TankColorGenerator::getTeamName(team),
87 objective_));
88 ChannelManager::showText(context, text);
91 else
93 Tank *tank = context.getTankContainer().getTankById(weaponContext.getPlayerId());
94 if (!tank) return;
96 tank->getScore().setWonGame();
99 ChannelText text("combat",
100 LANG_RESOURCE_2("TANK_SINGLE_WIN",
101 "[p:{0}] {1} and won the game",
102 tank->getTargetName(),
103 objective_));
104 ChannelManager::showText(context, text);