00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <weapons/WeaponNapalm.h>
00022 #include <actions/Napalm.h>
00023 #include <common/Defines.h>
00024 #ifndef S3D_SERVER
00025 #include <sound/SoundUtils.h>
00026 #endif
00027 #include <engine/ActionController.h>
00028 #include <landscapemap/LandscapeMaps.h>
00029
00030 REGISTER_ACCESSORY_SOURCE(WeaponNapalm);
00031
00032 WeaponNapalm::WeaponNapalm()
00033 {
00034
00035 }
00036
00037 WeaponNapalm::~WeaponNapalm()
00038 {
00039
00040 }
00041
00042 bool WeaponNapalm::parseXML(AccessoryCreateContext &context, XMLNode *accessoryNode)
00043 {
00044 if (!Weapon::parseXML(context, accessoryNode)) return false;
00045
00046 if (!accessoryNode->getNamedChild("napalmtime", napalmTime_)) return false;
00047 if (!accessoryNode->getNamedChild("napalmheight", napalmHeight_)) return false;
00048 if (!accessoryNode->getNamedChild("steptime", stepTime_)) return false;
00049 if (!accessoryNode->getNamedChild("hurtsteptime", hurtStepTime_)) return false;
00050 if (!accessoryNode->getNamedChild("hurtpersecond", hurtPerSecond_)) return false;
00051 if (!accessoryNode->getNamedChild("numberstreams", numberStreams_)) return false;
00052 if (!accessoryNode->getNamedChild("napalmsound", napalmSound_)) return false;
00053 if (!S3D::checkDataFile(S3D::formatStringBuffer("data/wav/%s", napalmSound_.c_str()))) return false;
00054
00055 if (!params_.parseXML(accessoryNode)) return false;
00056
00057 return true;
00058 }
00059
00060 void WeaponNapalm::fireWeapon(ScorchedContext &context,
00061 WeaponFireContext &weaponContext, FixedVector &position, FixedVector &velocity)
00062 {
00063 fixed minHeight = context.getLandscapeMaps().getGroundMaps().getInterpHeight(
00064 position[0], position[1]);
00065
00066
00067 if (position[2] < minHeight)
00068 {
00069 if (minHeight - position[2] > 10)
00070 {
00071 return;
00072 }
00073 }
00074
00075 RandomGenerator &random = context.getActionController().getRandom();
00076 for (int i=0; i<numberStreams_; i++)
00077 {
00078 int x = (position[0] + random.getRandFixed() * 4 - 2).asInt();
00079 int y = (position[1] + random.getRandFixed() * 4 - 2).asInt();
00080 addNapalm(context, weaponContext, x, y);
00081 }
00082
00083 #ifndef S3D_SERVER
00084 if (!context.getServerMode())
00085 {
00086 if (napalmSound_.c_str()[0] &&
00087 0 != strcmp(napalmSound_.c_str(), "none"))
00088 {
00089 SoundBuffer *expSound =
00090 Sound::instance()->fetchOrCreateBuffer(
00091 S3D::getDataFile(S3D::formatStringBuffer("data/wav/%s", napalmSound_.c_str())));
00092 SoundUtils::playAbsoluteSound(VirtualSoundPriority::eAction,
00093 expSound, position.asVector());
00094 }
00095 }
00096 #endif
00097 }
00098
00099 void WeaponNapalm::addNapalm(ScorchedContext &context,
00100 WeaponFireContext &weaponContext, int x, int y)
00101 {
00102 NapalmParams *params = new NapalmParams(params_);
00103 params->setNapalmTime(napalmTime_.getValue(context));
00104 params->setNapalmHeight(napalmHeight_.getValue(context));
00105 params->setStepTime(stepTime_.getValue(context));
00106 params->setHurtStepTime(hurtStepTime_.getValue(context));
00107 params->setHurtPerSecond(hurtPerSecond_.getValue(context));
00108
00109
00110
00111 context.getActionController().addAction(
00112 new Napalm(x, y, this, params, weaponContext));
00113 }