00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <actions/TankFired.h>
00022 #include <actions/Explosion.h>
00023 #include <actions/TankSay.h>
00024 #include <weapons/AccessoryStore.h>
00025 #include <engine/ScorchedContext.h>
00026 #include <engine/ActionController.h>
00027 #ifndef S3D_SERVER
00028 #include <sound/SoundUtils.h>
00029 #endif
00030 #include <common/Defines.h>
00031 #include <tank/TankContainer.h>
00032 #include <tank/TankPosition.h>
00033 #include <tankai/TankAIStrings.h>
00034 #include <target/TargetRenderer.h>
00035
00036 TankFired::TankFired(unsigned int playerId,
00037 Weapon *weapon,
00038 fixed rotXY, fixed rotXZ) :
00039 ActionReferenced("TankFired"),
00040 playerId_(playerId), weapon_(weapon),
00041 rotXY_(rotXY), rotXZ_(rotXZ), firstTime_(true)
00042 {
00043
00044 }
00045
00046 TankFired::~TankFired()
00047 {
00048 }
00049
00050 void TankFired::init()
00051 {
00052
00053 }
00054
00055 std::string TankFired::getActionDetails()
00056 {
00057 return S3D::formatStringBuffer("%u %s",
00058 playerId_, weapon_->getParent()->getName());
00059 }
00060
00061 void TankFired::simulate(fixed frameTime, bool &remove)
00062 {
00063 if (firstTime_)
00064 {
00065 firstTime_ = false;
00066 Tank *tank =
00067 context_->getTankContainer().getTankById(playerId_);
00068 if (tank)
00069 {
00070 tank->getPosition().rotateGunXY(rotXY_, false);
00071 tank->getPosition().rotateGunYZ(rotXZ_, false);
00072 tank->getPosition().madeShot();
00073
00074 if (tank->getDestinationId() == 0)
00075 {
00076 const char *line = TankAIStrings::instance()->getAttackLine(*context_);
00077 if (line)
00078 {
00079 context_->getActionController().addAction(
00080 new TankSay(tank->getPlayerId(),
00081 LANG_STRING(line)));
00082 }
00083 }
00084
00085 #ifndef S3D_SERVER
00086 if (!context_->getServerMode())
00087 {
00088 TargetRenderer *renderer = tank->getRenderer();
00089 if (renderer)
00090 {
00091 renderer->fired();
00092 }
00093
00094
00095 if (weapon_->getParent()->getActivationSound() &&
00096 0 != strcmp("none", weapon_->getParent()->getActivationSound()))
00097 {
00098 SoundBuffer *firedSound =
00099 Sound::instance()->fetchOrCreateBuffer(
00100 S3D::getDataFile(S3D::formatStringBuffer("data/wav/%s",
00101 weapon_->getParent()->getActivationSound())));
00102 SoundUtils::playAbsoluteSound(VirtualSoundPriority::eAction,
00103 firedSound, tank->getPosition().getTankPosition().asVector());
00104 }
00105 }
00106 #endif // #ifndef S3D_SERVER
00107
00108 if (weapon_->getParent()->getMuzzleFlash())
00109 {
00110 WeaponFireContext weaponContext(playerId_, 0);
00111 Weapon *muzzleFlash = context_->getAccessoryStore().getMuzzelFlash();
00112 if (muzzleFlash) muzzleFlash->fireWeapon(*context_, weaponContext,
00113 tank->getPosition().getTankGunPosition(), FixedVector::getNullVector());
00114 }
00115 }
00116 }
00117
00118 remove = true;
00119 Action::simulate(frameTime, remove);
00120 }