00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <target/TargetDamageCalc.h>
00022 #include <tank/TankContainer.h>
00023 #include <target/TargetLife.h>
00024 #include <target/TargetSpace.h>
00025 #include <common/Logger.h>
00026 #include <engine/ActionController.h>
00027 #include <actions/TankDamage.h>
00028
00029 void TargetDamageCalc::explosion(ScorchedContext &context,
00030 Weapon *weapon,WeaponFireContext &weaponContext,
00031 FixedVector &position, fixed radius,
00032 fixed damageAmount, bool checkFall,
00033 bool shieldOnlyDamage)
00034 {
00035 std::map<unsigned int, Target *> collisionTargets;
00036 context.getTargetSpace().getCollisionSet(position, radius, collisionTargets, true);
00037 std::map<unsigned int, Target *>::iterator itor;
00038 for (itor = collisionTargets.begin();
00039 itor != collisionTargets.end();
00040 itor++)
00041 {
00042 Target *current = (*itor).second;
00043 if (!current->getAlive()) continue;
00044
00045
00046 fixed dist = current->getLife().collisionDistance(position);
00047 if (dist < radius)
00048 {
00049
00050 fixed damage = 100;
00051 if (dist > radius / 3)
00052 {
00053 damage = ((dist - (radius / 3)) / (radius * fixed(true, 6600))) * 100;
00054 damage = fixed(100) - damage;
00055 }
00056
00057 damageTarget(context, current, weapon, weaponContext,
00058 damage * damageAmount, true, checkFall, shieldOnlyDamage);
00059 }
00060 else
00061 {
00062 FixedVector ¤tPosition = current->getLife().getCenterPosition();
00063 FixedVector direction = position - currentPosition;
00064 fixed dist2d = (direction[0] * direction[0] +
00065 direction[1] * direction[1]).sqrt();
00066 if (dist2d < radius + 5)
00067 {
00068
00069 damageTarget(context, current, weapon, weaponContext,
00070 0, true, checkFall, shieldOnlyDamage);
00071 }
00072 }
00073 }
00074 }
00075
00076 void TargetDamageCalc::damageTarget(ScorchedContext &context,
00077 Target *target, Weapon *weapon,
00078 WeaponFireContext &weaponContext, fixed damage,
00079 bool useShieldDamage, bool checkFall,
00080 bool shieldOnlyDamage)
00081 {
00082
00083 TankDamage *tankDamage = new TankDamage(
00084 weapon, target->getPlayerId(), weaponContext,
00085 damage, useShieldDamage, checkFall, shieldOnlyDamage);
00086 context.getActionController().addAction(tankDamage);
00087 }