1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
4 // This file is part of Scorched3D.
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/WeaponGiveScore.h>
22 #include <weapons/AccessoryStore.h>
23 #include <engine/ActionController.h>
24 #include <tank/TankContainer.h>
25 #include <tank/TankTeamScore.h>
26 #include <tank/TankScore.h>
27 #include <common/Defines.h>
28 #include <common/ChannelManager.h>
29 #include <lang/LangResource.h>
31 REGISTER_ACCESSORY_SOURCE(WeaponGiveScore
);
33 WeaponGiveScore::WeaponGiveScore()
38 WeaponGiveScore::~WeaponGiveScore()
43 bool WeaponGiveScore::parseXML(AccessoryCreateContext
&context
, XMLNode
*accessoryNode
)
45 if (!Weapon::parseXML(context
, accessoryNode
)) return false;
47 if (!accessoryNode
->getNamedChild("score", score_
)) return false;
52 void WeaponGiveScore::fireWeapon(ScorchedContext
&context
,
53 WeaponFireContext
&weaponContext
, FixedVector
&position
, FixedVector
&velocity
)
55 context
.getActionController().addAction(
56 new CallbackWeapon("WeaponGiveScore", this, 0, 0,
57 weaponContext
, position
, velocity
));
60 void WeaponGiveScore::weaponCallback(
61 ScorchedContext
&context
,
62 WeaponFireContext
&weaponContext
, FixedVector
&position
, FixedVector
&velocity
,
63 unsigned int userData
)
65 Tank
*tank
= context
.getTankContainer().getTankById(weaponContext
.getPlayerId());
68 tank
->getScore().setScore(tank
->getScore().getScore() + score_
);
69 if (tank
->getTeam() > 0)
71 context
.getTankTeamScore().addScore(score_
, tank
->getTeam());
77 ChannelText
text("combat",
78 LANG_RESOURCE_2("TANK_GET_SCORE",
79 "[p:{0}] received {1} bonus score",
80 tank
->getTargetName(),
81 S3D::formatStringBuffer("%i", score_
)));
82 ChannelManager::showText(context
, text
);
86 ChannelText
text("combat",
87 LANG_RESOURCE_2("TANK_LOST_SCORE",
88 "[p:{0}] lost {1} bonus score",
89 tank
->getTargetName(),
90 S3D::formatStringBuffer("%i", -score_
)));
91 ChannelManager::showText(context
, text
);