TargetDamageCalc.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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                 // Check if the explosion causes damage
00046                 fixed dist = current->getLife().collisionDistance(position);
00047                 if (dist < radius)
00048                 {
00049                         // Direct hit by explosion
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 &currentPosition = 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                                 // explosion under tank
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         // Remove the correct damage from the tanks
00083         TankDamage *tankDamage = new TankDamage(
00084                 weapon, target->getPlayerId(), weaponContext, 
00085                 damage, useShieldDamage, checkFall, shieldOnlyDamage);
00086         context.getActionController().addAction(tankDamage);
00087 }

Generated on Mon Feb 16 15:14:52 2009 for Scorched3D by  doxygen 1.5.3