00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <actions/Teleport.h>
00022 #include <actions/CameraPositionAction.h>
00023 #include <common/Defines.h>
00024 #include <common/OptionsScorched.h>
00025 #include <tank/TankContainer.h>
00026 #include <tank/TankState.h>
00027 #include <tank/TankPosition.h>
00028 #include <target/TargetDamageCalc.h>
00029 #include <target/TargetLife.h>
00030 #include <engine/ActionController.h>
00031 #include <engine/ScorchedContext.h>
00032 #include <weapons/AccessoryStore.h>
00033 #include <landscapemap/DeformLandscape.h>
00034 #include <landscapemap/LandscapeMaps.h>
00035 #ifndef S3D_SERVER
00036 #include <sound/SoundUtils.h>
00037 #include <sprites/TeleportRenderer.h>
00038 #include <land/VisibilityPatchGrid.h>
00039 #endif
00040
00041 Teleport::Teleport(FixedVector position,
00042 WeaponFireContext &weaponContext,
00043 WeaponTeleport *weapon) :
00044 ActionReferenced("Teleport"),
00045 position_(position),
00046 weaponContext_(weaponContext),
00047 weapon_(weapon),
00048 totalTime_(0),
00049 firstTime_(true),
00050 vPoint_(0)
00051 {
00052
00053 }
00054
00055 Teleport::~Teleport()
00056 {
00057 if (vPoint_) context_->getViewPoints().releaseViewPoint(vPoint_);
00058 }
00059
00060 void Teleport::init()
00061 {
00062 vPoint_ = context_->getViewPoints().getNewViewPoint(weaponContext_.getPlayerId());
00063
00064 #ifndef S3D_SERVER
00065 if (!context_->getServerMode())
00066 {
00067 Tank *tank = context_->getTankContainer().getTankById(weaponContext_.getPlayerId());
00068 if (tank && tank->getState().getState() == TankState::sNormal)
00069 {
00070 Vector white(1.0f, 1.0f, 1.0f);
00071 TeleportRenderer *teleport = new TeleportRenderer(
00072 tank->getPosition().getTankTurretPosition().asVector(),
00073 white);
00074 context_->getActionController().addAction(new SpriteAction(teleport));
00075 }
00076 }
00077 #endif
00078
00079 CameraPositionAction *pos = new CameraPositionAction(
00080 position_, 5, 5);
00081 context_->getActionController().addAction(pos);
00082 }
00083
00084 void Teleport::simulate(fixed frameTime, bool &remove)
00085 {
00086 if (vPoint_) vPoint_->setPosition(position_);
00087
00088 if (firstTime_)
00089 {
00090 firstTime_ = false;
00091
00092 #ifndef S3D_SERVER
00093 if (!context_->getServerMode())
00094 {
00095 Tank *tank = context_->getTankContainer().getTankById(weaponContext_.getPlayerId());
00096 if (tank && tank->getState().getState() == TankState::sNormal)
00097 {
00098 SoundBuffer *activateSound =
00099 Sound::instance()->fetchOrCreateBuffer(
00100 S3D::getDataFile(weapon_->getSound()));
00101 SoundUtils::playAbsoluteSound(VirtualSoundPriority::eAction,
00102 activateSound, tank->getPosition().getTankPosition().asVector());
00103 }
00104 }
00105 #endif // #ifndef S3D_SERVER
00106 }
00107
00108 totalTime_ += frameTime;
00109 if (totalTime_ > weapon_->getDelay(*context_))
00110 {
00111 Tank *tank = context_->getTankContainer().getTankById(weaponContext_.getPlayerId());
00112 if (tank && tank->getState().getState() == TankState::sNormal)
00113 {
00114 fixed height = context_->getLandscapeMaps().getGroundMaps().getInterpHeight(
00115 position_[0], position_[1]);
00116 if (weapon_->getGroundOnly() || height >= position_[2])
00117 {
00118
00119 position_[2] = height;
00120
00121 if (context_->getOptionsGame().getActionSyncCheck())
00122 {
00123 context_->getActionController().addSyncCheck(
00124 S3D::formatStringBuffer("Telport: %u %i, %i, %i",
00125 tank->getPlayerId(),
00126 position_[0].getInternal(),
00127 position_[1].getInternal(),
00128 position_[2].getInternal()));
00129 }
00130
00131
00132 tank->getLife().setTargetPosition(position_);
00133 DeformLandscape::flattenArea(*context_, position_);
00134 #ifndef S3D_SERVER
00135 if (!context_->getServerMode())
00136 {
00137 VisibilityPatchGrid::instance()->recalculateErrors(position_, 2);
00138 }
00139 #endif
00140 }
00141 else
00142 {
00143 if (context_->getOptionsGame().getActionSyncCheck())
00144 {
00145 context_->getActionController().addSyncCheck(
00146 S3D::formatStringBuffer("Telport: %u %i, %i, %i",
00147 tank->getPlayerId(),
00148 position_[0].getInternal(),
00149 position_[1].getInternal(),
00150 position_[2].getInternal()));
00151 }
00152
00153
00154 tank->getLife().setTargetPosition(position_);
00155
00156
00157 TargetDamageCalc::damageTarget(*context_, tank, weapon_,
00158 weaponContext_, 0, false, true, false);
00159 }
00160 }
00161
00162 remove = true;
00163 }
00164
00165 Action::simulate(frameTime, remove);
00166 }
00167
00168 std::string Teleport::getActionDetails()
00169 {
00170 return S3D::formatStringBuffer("%u %i,%i,%i %s",
00171 weaponContext_.getPlayerId(),
00172 position_[0].getInternal(),
00173 position_[1].getInternal(),
00174 position_[2].getInternal(),
00175 weapon_->getParent()->getName());
00176 }