WeaponGiveWin.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 <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 

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