00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <weapons/AccessoryStore.h>
00022 #include <weapons/WeaponMoveTank.h>
00023 #include <tank/TankWeapon.h>
00024 #include <tank/TankContainer.h>
00025 #include <tank/TankAccessories.h>
00026 #include <target/TargetLife.h>
00027 #include <engine/ScorchedContext.h>
00028 #include <common/Defines.h>
00029 #include <common/ChannelManager.h>
00030 #ifndef S3D_SERVER
00031 #include <client/ScorchedClient.h>
00032 #include <client/ClientState.h>
00033 #include <landscape/Landscape.h>
00034 #endif
00035 #include <landscapemap/LandscapeMaps.h>
00036 #include <landscapemap/MovementMap.h>
00037 #include <lang/LangResource.h>
00038
00039 TankWeapon::TankWeapon(ScorchedContext &context) :
00040 currentWeapon_(0), context_(context),
00041 tank_(0)
00042 {
00043 }
00044
00045 TankWeapon::~TankWeapon()
00046 {
00047 }
00048
00049 void TankWeapon::newMatch()
00050 {
00051 setCurrentWeapon(0);
00052 }
00053
00054 void TankWeapon::changed()
00055 {
00056 if (!tank_->getAccessories().canUse(currentWeapon_) ||
00057 currentWeapon_ == 0)
00058 {
00059 setCurrentWeapon(0);
00060 std::list<Accessory *> &result =
00061 tank_->getAccessories().getAllAccessoriesByGroup("weapon");
00062 std::list<Accessory *>::iterator itor;
00063 for (itor = result.begin();
00064 itor != result.end();
00065 itor++)
00066 {
00067 if (tank_->getAccessories().canUse(*itor))
00068 {
00069 setWeapon(*itor);
00070 break;
00071 }
00072 }
00073 }
00074 }
00075
00076 bool TankWeapon::setWeapon(Accessory *wp)
00077 {
00078 if (tank_->getAccessories().canUse(wp))
00079 {
00080 setCurrentWeapon(wp);
00081 return true;
00082 }
00083 return false;
00084 }
00085
00086 Accessory *TankWeapon::getCurrent()
00087 {
00088 return currentWeapon_;
00089 }
00090
00091 void TankWeapon::setCurrentWeapon(Accessory *wp)
00092 {
00093 #ifndef S3D_SERVER
00094 if (!context_.getServerMode())
00095 {
00096
00097 if (ScorchedClient::instance()->getTankContainer().getCurrentDestinationId() ==
00098 tank_->getDestinationId() &&
00099 ScorchedClient::instance()->getGameState().getState() == ClientState::StatePlaying)
00100 {
00101
00102
00103 if (currentWeapon_ &&
00104 currentWeapon_->getPositionSelect() != Accessory::ePositionSelectNone)
00105 {
00106 Landscape::instance()->restoreLandscapeTexture();
00107 }
00108
00109 if (wp &&
00110 wp->getPositionSelect() != Accessory::ePositionSelectNone)
00111 {
00112 if (wp->getPositionSelect() == Accessory::ePositionSelectFuel)
00113 {
00114 WeaponMoveTank *moveWeapon = (WeaponMoveTank *)
00115 context_.getAccessoryStore().findAccessoryPartByAccessoryId(
00116 wp->getAccessoryId(), "WeaponMoveTank");
00117 if (moveWeapon)
00118 {
00119 MovementMap mmap(
00120 tank_,
00121 context_);
00122 mmap.calculateAllPositions(mmap.getFuel(moveWeapon));
00123 mmap.movementTexture();
00124 }
00125 }
00126 else if (wp->getPositionSelect() == Accessory::ePositionSelectFuelLimit)
00127 {
00128 MovementMap mmap(
00129 tank_,
00130 context_);
00131 mmap.calculateAllPositions(fixed(wp->getPositionSelectLimit()));
00132 mmap.movementTexture();
00133 }
00134 else if (wp->getPositionSelect() == Accessory::ePositionSelectLimit)
00135 {
00136 MovementMap::limitTexture(tank_->getLife().getTargetPosition(),
00137 wp->getPositionSelectLimit());
00138 }
00139
00140 ChannelText text("banner",
00141 LANG_RESOURCE_1(
00142 "GROUND_WEAPON_ACTIVATE",
00143 "Click ground to activate {0}",
00144 wp->getName()));
00145 ChannelManager::showText(ScorchedClient::instance()->getContext(),
00146 text);
00147 }
00148
00149 }
00150 }
00151 #endif
00152
00153 currentWeapon_ = wp;
00154 }
00155
00156 const char *TankWeapon::getWeaponString()
00157 {
00158 if (!getCurrent()) return "";
00159
00160 static char buffer[256];
00161 int count = tank_->getAccessories().getAccessoryCount(getCurrent());
00162 snprintf(buffer, 256, ((count>0)?"%s (%i)":"%s (In)"),
00163 getCurrent()->getName(), count);
00164 return buffer;
00165 }