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/WeaponReference.h>
22 #include <weapons/AccessoryStore.h>
23 #include <common/DefinesString.h>
25 REGISTER_ACCESSORY_SOURCE(WeaponReference
);
27 WeaponReference::WeaponReference()
32 WeaponReference::~WeaponReference()
37 bool WeaponReference::parseXML(AccessoryCreateContext
&context
, XMLNode
*accessoryNode
)
39 if (!Weapon::parseXML(context
, accessoryNode
)) return false;
41 // Get the next weapon
43 if (!accessoryNode
->getNamedChild("weapon", subNode
)) return false;
45 // Find the accessory name
46 std::map
<std::string
, XMLNode
*> &nodes
= context
.getAccessoryStore().getParsingNodes();
47 std::map
<std::string
, XMLNode
*>::iterator finditor
=
48 nodes
.find(subNode
.c_str());
49 if (finditor
== nodes
.end())
51 S3D::dialogMessage("WeaponReference", S3D::formatStringBuffer(
52 "Failed to find weapon \"%s\"",
56 XMLNode
*weaponNode
= (*finditor
).second
;
57 weaponNode
->resurrectRemovedChildren();
60 XMLNode
*actionNode
= 0;
61 if (!weaponNode
->getNamedChild("accessoryaction", actionNode
)) return false;
63 // Create the new weapon
64 AccessoryPart
*accessory
= context
.getAccessoryStore().
65 createAccessoryPart(context
, parent_
, actionNode
);
66 if (!accessory
|| accessory
->getType() != AccessoryPart::AccessoryWeapon
)
68 S3D::dialogMessage("Accessory", S3D::formatStringBuffer(
69 "Failed to find create weapon/wrong type \"%s\"",
73 refWeapon_
= (Weapon
*) accessory
;
78 void WeaponReference::fireWeapon(ScorchedContext
&context
,
79 WeaponFireContext
&weaponContext
, FixedVector
&position
, FixedVector
&velocity
)
81 refWeapon_
->fireWeapon(context
, weaponContext
, position
, velocity
);