00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <engine/ShotState.h>
00022 #include <engine/ActionController.h>
00023 #include <actions/CheckResurrection.h>
00024 #include <coms/ComsMessageSender.h>
00025 #include <common/Logger.h>
00026 #include <common/RandomGenerator.h>
00027 #include <common/OptionsScorched.h>
00028 #include <common/OptionsTransient.h>
00029 #include <tank/TankState.h>
00030 #include <tank/TankScore.h>
00031 #include <tank/TankAccessories.h>
00032 #include <tank/TankPosition.h>
00033 #include <target/TargetLife.h>
00034 #include <target/TargetState.h>
00035
00036 ShotState::ShotState(ScorchedContext &context,
00037 PlayShots &playShots) :
00038 context_(context), playShots_(playShots),
00039 firstTime_(true)
00040 {
00041 }
00042
00043 ShotState::~ShotState()
00044 {
00045 }
00046
00047 void ShotState::setup()
00048 {
00049
00050 {
00051 std::map<unsigned int, Tank *> &tanks =
00052 context_.getTankContainer().getPlayingTanks();
00053 std::map<unsigned int, Tank *>::iterator itor;
00054 for (itor = tanks.begin();
00055 itor != tanks.end();
00056 itor++)
00057 {
00058 Tank *tank = (*itor).second;
00059 tank->getScore().setTurnKills(0);
00060 }
00061 }
00062
00063
00064 context_.getActionController().setStopImmediately(true);
00065 context_.getActionController().resetTime();
00066 context_.getActionController().clear();
00067
00068 if (context_.getOptionsGame().getActionSyncCheck())
00069 {
00070 std::map<unsigned int, Target *> &targets =
00071 context_.getTargetContainer().getTargets();
00072 std::map<unsigned int, Target *>::iterator itor;
00073 for (itor = targets.begin();
00074 itor != targets.end();
00075 itor++)
00076 {
00077 Target *target = itor->second;
00078 if (target->getPlayerId() >= TargetID::MIN_TARGET_TRANSIENT_ID ||
00079 target->getTargetState().getMovement() ||
00080 !target->isTarget())
00081 {
00082 context_.getActionController().addSyncCheck(
00083 S3D::formatStringBuffer("TargetDef : %u %s %i %i,%i,%i %i,%i,%i %s",
00084 target->getPlayerId(),
00085 target->getCStrName().c_str(),
00086 target->getLife().getLife().getInternal(),
00087 target->getLife().getTargetPosition()[0].getInternal(),
00088 target->getLife().getTargetPosition()[1].getInternal(),
00089 target->getLife().getTargetPosition()[2].getInternal(),
00090 target->getLife().getVelocity()[0].getInternal(),
00091 target->getLife().getVelocity()[1].getInternal(),
00092 target->getLife().getVelocity()[2].getInternal(),
00093 target->getAlive()?"Alive":"Dead"));
00094 }
00095 }
00096 }
00097
00098
00099
00100 playShots_.playShots(context_);
00101 context_.getActionController().addLastAction(new CheckResurrection());
00102
00103
00104 firstTime_ = true;
00105
00106
00107 context_.getActionController().getEvents().initialize(context_);
00108 }
00109
00110 bool ShotState::run(float frameTime)
00111 {
00112 if (!context_.getActionController().noReferencedActions() ||
00113 firstTime_)
00114 {
00115
00116
00117
00118 firstTime_ = false;
00119 }
00120 else
00121 {
00122
00123 Logger::log(S3D::formatStringBuffer(
00124 "Finished playing Shots %.2f seconds",
00125 context_.getActionController().getActionTime().asFloat()));
00126 context_.getActionController().getEvents().clear();
00127 context_.getActionController().logProfiledActions();
00128 context_.getActionController().setStopImmediately(false);
00129
00130 return true;
00131 }
00132 return false;
00133 }