|
@@ -14,14 +14,15 @@
|
|
|
#include "../../lib/mapObjects/CGTownInstance.h"
|
|
|
#include "../CGameInfo.h"
|
|
|
#include "../gui/CAnimation.h"
|
|
|
+#include "../gui/CCanvas.h"
|
|
|
#include "CBattleInterface.h"
|
|
|
#include "CBattleSiegeController.h"
|
|
|
#include "CBattleStacksController.h"
|
|
|
#include "CCreatureAnimation.h"
|
|
|
|
|
|
-CatapultProjectileInfo::CatapultProjectileInfo(const Point &from, const Point &dest)
|
|
|
+static double calculateCatapultParabolaY(const Point & from, const Point & dest, int x)
|
|
|
{
|
|
|
- facA = 0.005; // seems to be constant
|
|
|
+ double facA = 0.005; // seems to be constant
|
|
|
|
|
|
// system of 2 linear equations, solutions of which are missing coefficients
|
|
|
// for quadratic equation a*x*x + b*x + c
|
|
@@ -35,163 +36,205 @@ CatapultProjectileInfo::CatapultProjectileInfo(const Point &from, const Point &d
|
|
|
double detB = eq[0][2] *eq[1][1] - eq[1][2] *eq[0][1];
|
|
|
double detC = eq[0][0] *eq[1][2] - eq[1][0] *eq[0][2];
|
|
|
|
|
|
- facB = detB / det;
|
|
|
- facC = detC / det;
|
|
|
+ double facB = detB / det;
|
|
|
+ double facC = detC / det;
|
|
|
|
|
|
- // make sure that parabola is correct e.g. passes through from and dest
|
|
|
- assert(fabs(calculateY(from.x) - from.y) < 1.0);
|
|
|
- assert(fabs(calculateY(dest.x) - dest.y) < 1.0);
|
|
|
+ return facA *pow(x, 2.0) + facB *x + facC;
|
|
|
}
|
|
|
|
|
|
-double CatapultProjectileInfo::calculateY(double x)
|
|
|
+void ProjectileMissile::show(std::shared_ptr<CCanvas> canvas)
|
|
|
{
|
|
|
- return facA *pow(x, 2.0) + facB *x + facC;
|
|
|
+ size_t group = reverse ? 1 : 0;
|
|
|
+ auto image = animation->getImage(frameNum, group, true);
|
|
|
+
|
|
|
+ if(image)
|
|
|
+ {
|
|
|
+ float progress = float(step) / steps;
|
|
|
+
|
|
|
+ Point pos {
|
|
|
+ CSDL_Ext::lerp(from.x, dest.x, progress) - image->width() / 2,
|
|
|
+ CSDL_Ext::lerp(from.y, dest.y, progress) - image->height() / 2,
|
|
|
+ };
|
|
|
+
|
|
|
+ canvas->draw(image, pos);
|
|
|
+ }
|
|
|
+
|
|
|
+ ++step;
|
|
|
}
|
|
|
|
|
|
-CBattleProjectileController::CBattleProjectileController(CBattleInterface * owner):
|
|
|
- owner(owner)
|
|
|
+void ProjectileCatapult::show(std::shared_ptr<CCanvas> canvas)
|
|
|
{
|
|
|
+ size_t group = reverse ? 1 : 0;
|
|
|
+ auto image = animation->getImage(frameNum, group, true);
|
|
|
+
|
|
|
+ if(image)
|
|
|
+ {
|
|
|
+ float progress = float(step) / steps;
|
|
|
+
|
|
|
+ int posX = CSDL_Ext::lerp(from.x, dest.x, progress);
|
|
|
+ int posY = calculateCatapultParabolaY(from, dest, posX);
|
|
|
+ Point pos(posX, posY);
|
|
|
+
|
|
|
+ canvas->draw(image, pos);
|
|
|
|
|
|
+ frameNum = (frameNum + 1) % animation->size(0);
|
|
|
+
|
|
|
+ if (step == steps)
|
|
|
+ {
|
|
|
+ //TODO: re-enable. Move to ShootingAnimation? What about spells?
|
|
|
+ // last step - explosion effect
|
|
|
+ //Point explosion_pos = pos + image->dimensions() / 2 - Point(126, 105);
|
|
|
+
|
|
|
+ //owner->addNewAnim( new CEffectAnimation(owner, catapultDamage ? "SGEXPL.DEF" : "CSGRCK.DEF", animPos.x, animPos.y));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ++step;
|
|
|
}
|
|
|
|
|
|
-void CBattleProjectileController::initStackProjectile(const CStack * stack)
|
|
|
+void ProjectileRay::show(std::shared_ptr<CCanvas> canvas)
|
|
|
{
|
|
|
- const CCreature * creature;//creature whose shots should be loaded
|
|
|
- if(stack->getCreature()->idNumber == CreatureID::ARROW_TOWERS)
|
|
|
- creature = owner->siegeController->getTurretCreature();
|
|
|
- else
|
|
|
- creature = stack->getCreature();
|
|
|
+ float progress = float(step) / steps;
|
|
|
+
|
|
|
+ Point curr {
|
|
|
+ CSDL_Ext::lerp(from.x, dest.x, progress),
|
|
|
+ CSDL_Ext::lerp(from.y, dest.y, progress),
|
|
|
+ };
|
|
|
+
|
|
|
+ Point length = curr - from;
|
|
|
|
|
|
- if (creature->animation.projectileRay.empty())
|
|
|
+ //select axis to draw ray on, we want angle to be less than 45 degrees so individual sub-rays won't overlap each other
|
|
|
+
|
|
|
+ if (std::abs(length.x) > std::abs(length.y)) // draw in horizontal axis
|
|
|
{
|
|
|
- std::shared_ptr<CAnimation> projectile = std::make_shared<CAnimation>(creature->animation.projectileImageName);
|
|
|
- projectile->preload();
|
|
|
+ int y1 = from.y - rayConfig.size() / 2;
|
|
|
+ int y2 = curr.y - rayConfig.size() / 2;
|
|
|
+
|
|
|
+ int x1 = from.x;
|
|
|
+ int x2 = curr.x;
|
|
|
|
|
|
- if(projectile->size(1) != 0)
|
|
|
- logAnim->error("Expected empty group 1 in stack projectile");
|
|
|
- else
|
|
|
- projectile->createFlippedGroup(0, 1);
|
|
|
+ for (size_t i = 0; i < rayConfig.size(); ++i)
|
|
|
+ {
|
|
|
+ auto ray = rayConfig[i];
|
|
|
+ SDL_Color beginColor{ ray.r1, ray.g1, ray.b1, ray.a1};
|
|
|
+ SDL_Color endColor { ray.r2, ray.g2, ray.b2, ray.a2};
|
|
|
|
|
|
- idToProjectile[stack->getCreature()->idNumber] = projectile;
|
|
|
+ canvas->drawLine(Point(x1, y1 + i), Point(x2, y2+i), beginColor, endColor);
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ else // draw in vertical axis
|
|
|
{
|
|
|
- idToRay[stack->getCreature()->idNumber] = creature->animation.projectileRay;
|
|
|
+ int x1 = from.x - rayConfig.size() / 2;
|
|
|
+ int x2 = curr.x - rayConfig.size() / 2;
|
|
|
+
|
|
|
+ int y1 = from.y;
|
|
|
+ int y2 = curr.y;
|
|
|
+
|
|
|
+ for (size_t i = 0; i < rayConfig.size(); ++i)
|
|
|
+ {
|
|
|
+ auto ray = rayConfig[i];
|
|
|
+ SDL_Color beginColor{ ray.r1, ray.g1, ray.b1, ray.a1};
|
|
|
+ SDL_Color endColor { ray.r2, ray.g2, ray.b2, ray.a2};
|
|
|
+
|
|
|
+ canvas->drawLine(Point(x1 + i, y1), Point(x2 + i, y2), beginColor, endColor);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void CBattleProjectileController::fireStackProjectile(const CStack * stack)
|
|
|
+CBattleProjectileController::CBattleProjectileController(CBattleInterface * owner):
|
|
|
+ owner(owner)
|
|
|
+{}
|
|
|
+
|
|
|
+const CCreature * CBattleProjectileController::getShooter(const CStack * stack)
|
|
|
{
|
|
|
- for (auto it = projectiles.begin(); it!=projectiles.end(); ++it)
|
|
|
+ const CCreature * creature = stack->getCreature();
|
|
|
+
|
|
|
+ if(creature->idNumber == CreatureID::ARROW_TOWERS)
|
|
|
+ creature = owner->siegeController->getTurretCreature();
|
|
|
+
|
|
|
+ if(creature->animation.missleFrameAngles.empty())
|
|
|
{
|
|
|
- if ( !it->shotDone && it->stackID == stack->ID)
|
|
|
- {
|
|
|
- it->shotDone = true;
|
|
|
- return;
|
|
|
- }
|
|
|
+ logAnim->error("Mod error: Creature '%s' on the Archer's tower is not a shooter. Mod should be fixed. Trying to use archer's data instead...", creature->nameSing);
|
|
|
+ creature = CGI->creh->objects[CreatureID::ARCHER];
|
|
|
}
|
|
|
+
|
|
|
+ return creature;
|
|
|
}
|
|
|
|
|
|
-void CBattleProjectileController::showProjectiles(SDL_Surface *to)
|
|
|
+bool CBattleProjectileController::stackUsesRayProjectile(const CStack * stack)
|
|
|
{
|
|
|
- assert(to);
|
|
|
+ return !getShooter(stack)->animation.projectileRay.empty();
|
|
|
+}
|
|
|
|
|
|
- std::list< std::list<ProjectileInfo>::iterator > toBeDeleted;
|
|
|
- for (auto it = projectiles.begin(); it!=projectiles.end(); ++it)
|
|
|
- {
|
|
|
- // Check if projectile is already visible (shooter animation did the shot)
|
|
|
- if (!it->shotDone)
|
|
|
- continue;
|
|
|
+bool CBattleProjectileController::stackUsesMissileProjectile(const CStack * stack)
|
|
|
+{
|
|
|
+ return !getShooter(stack)->animation.projectileImageName.empty();
|
|
|
+}
|
|
|
|
|
|
- if (idToProjectile.count(it->creID))
|
|
|
- {
|
|
|
- size_t group = it->reverse ? 1 : 0;
|
|
|
- auto image = idToProjectile[it->creID]->getImage(it->frameNum, group, true);
|
|
|
+void CBattleProjectileController::initStackProjectile(const CStack * stack)
|
|
|
+{
|
|
|
+ if (!stackUsesMissileProjectile(stack))
|
|
|
+ return;
|
|
|
|
|
|
- if(image)
|
|
|
- {
|
|
|
- SDL_Rect dst;
|
|
|
- dst.h = image->height();
|
|
|
- dst.w = image->width();
|
|
|
- dst.x = static_cast<int>(it->x - dst.w / 2);
|
|
|
- dst.y = static_cast<int>(it->y - dst.h / 2);
|
|
|
+ const CCreature * creature = getShooter(stack);
|
|
|
|
|
|
- image->draw(to, &dst, nullptr);
|
|
|
- }
|
|
|
- }
|
|
|
- if (idToRay.count(it->creID))
|
|
|
- {
|
|
|
- auto const & ray = idToRay[it->creID];
|
|
|
+ std::shared_ptr<CAnimation> projectile = std::make_shared<CAnimation>(creature->animation.projectileImageName);
|
|
|
+ projectile->preload();
|
|
|
|
|
|
- if (std::abs(it->dx) > std::abs(it->dy)) // draw in horizontal axis
|
|
|
- {
|
|
|
- int y1 = it->y0 - ray.size() / 2;
|
|
|
- int y2 = it->y - ray.size() / 2;
|
|
|
+ if(projectile->size(1) != 0)
|
|
|
+ logAnim->error("Expected empty group 1 in stack projectile");
|
|
|
+ else
|
|
|
+ projectile->createFlippedGroup(0, 1);
|
|
|
|
|
|
- int x1 = it->x0;
|
|
|
- int x2 = it->x;
|
|
|
+ projectilesCache[creature->animation.projectileImageName] = projectile;
|
|
|
+}
|
|
|
|
|
|
- for (size_t i = 0; i < ray.size(); ++i)
|
|
|
- {
|
|
|
- SDL_Color beginColor{ ray[i].r1, ray[i].g1, ray[i].b1, ray[i].a1};
|
|
|
- SDL_Color endColor { ray[i].r2, ray[i].g2, ray[i].b2, ray[i].a2};
|
|
|
+std::shared_ptr<CAnimation> CBattleProjectileController::getProjectileImage(const CStack * stack)
|
|
|
+{
|
|
|
+ const CCreature * creature = getShooter(stack);
|
|
|
+ std::string imageName = creature->animation.projectileImageName;
|
|
|
|
|
|
- CSDL_Ext::drawLine(to, x1, y1 + i, x2, y2 + i, beginColor, endColor);
|
|
|
- }
|
|
|
- }
|
|
|
- else // draw in vertical axis
|
|
|
- {
|
|
|
- int x1 = it->x0 - ray.size() / 2;
|
|
|
- int x2 = it->x - ray.size() / 2;
|
|
|
+ if (!projectilesCache.count(imageName))
|
|
|
+ initStackProjectile(stack);
|
|
|
|
|
|
- int y1 = it->y0;
|
|
|
- int y2 = it->y;
|
|
|
+ return projectilesCache[imageName];
|
|
|
+}
|
|
|
|
|
|
- for (size_t i = 0; i < ray.size(); ++i)
|
|
|
- {
|
|
|
- SDL_Color beginColor{ ray[i].r1, ray[i].g1, ray[i].b1, ray[i].a1};
|
|
|
- SDL_Color endColor { ray[i].r2, ray[i].g2, ray[i].b2, ray[i].a2};
|
|
|
+//void CBattleProjectileController::fireStackProjectile(const CStack * stack)
|
|
|
+//{
|
|
|
+// for (auto it = projectiles.begin(); it!=projectiles.end(); ++it)
|
|
|
+// {
|
|
|
+// if ( !it->shotDone && it->stackID == stack->ID)
|
|
|
+// {
|
|
|
+// it->shotDone = true;
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|
|
|
|
|
|
- CSDL_Ext::drawLine(to, x1 + i, y1, x2 + i, y2, beginColor, endColor);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- // Update projectile
|
|
|
- ++it->step;
|
|
|
- if (it->step > it->lastStep)
|
|
|
- {
|
|
|
- toBeDeleted.insert(toBeDeleted.end(), it);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (it->catapultInfo)
|
|
|
- {
|
|
|
- // Parabolic shot of the trajectory, as follows: f(x) = ax^2 + bx + c
|
|
|
- it->x += it->dx;
|
|
|
- it->y = it->catapultInfo->calculateY(it->x);
|
|
|
+void CBattleProjectileController::showProjectiles(std::shared_ptr<CCanvas> canvas)
|
|
|
+{
|
|
|
+ for (auto projectile : projectiles)
|
|
|
+ {
|
|
|
+ // Check if projectile is already visible (shooter animation did the shot)
|
|
|
+ //if (!it->shotDone)
|
|
|
+ // continue;
|
|
|
|
|
|
- ++(it->frameNum);
|
|
|
- it->frameNum %= idToProjectile[it->creID]->size(0);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // Normal projectile, just add the calculated "deltas" to the x and y positions.
|
|
|
- it->x += it->dx;
|
|
|
- it->y += it->dy;
|
|
|
- }
|
|
|
- }
|
|
|
+ projectile->show(canvas);
|
|
|
+
|
|
|
+ // finished flying
|
|
|
+ if ( projectile->step > projectile->steps)
|
|
|
+ projectile.reset();
|
|
|
}
|
|
|
|
|
|
- for (auto & elem : toBeDeleted)
|
|
|
- projectiles.erase(elem);
|
|
|
+ boost::range::remove( projectiles, std::shared_ptr<ProjectileBase>());
|
|
|
}
|
|
|
|
|
|
bool CBattleProjectileController::hasActiveProjectile(const CStack * stack)
|
|
|
{
|
|
|
for(auto const & instance : projectiles)
|
|
|
{
|
|
|
- if(instance.creID == stack->getCreature()->idNumber)
|
|
|
+ if(instance->shooterID == stack->getCreature()->idNumber)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
@@ -199,117 +242,87 @@ bool CBattleProjectileController::hasActiveProjectile(const CStack * stack)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
void CBattleProjectileController::createProjectile(const CStack * shooter, const CStack * target, Point from, Point dest)
|
|
|
{
|
|
|
- // Get further info about the shooter e.g. relative pos of projectile to unit.
|
|
|
- // If the creature id is 149 then it's a arrow tower which has no additional info so get the
|
|
|
- // actual arrow tower shooter instead.
|
|
|
const CCreature *shooterInfo = shooter->getCreature();
|
|
|
|
|
|
- if(shooterInfo->idNumber == CreatureID::ARROW_TOWERS)
|
|
|
- shooterInfo = owner->siegeController->getTurretCreature();
|
|
|
-
|
|
|
- if(!shooterInfo->animation.missleFrameAngles.size())
|
|
|
- logAnim->error("Mod error: Creature '%s' on the Archer's tower is not a shooter. Mod should be fixed. Trying to use archer's data instead..."
|
|
|
- , shooterInfo->nameSing);
|
|
|
-
|
|
|
- auto & angles = shooterInfo->animation.missleFrameAngles.size()
|
|
|
- ? shooterInfo->animation.missleFrameAngles
|
|
|
- : CGI->creh->operator[](CreatureID::ARCHER)->animation.missleFrameAngles;
|
|
|
+ std::shared_ptr<ProjectileBase> projectile;
|
|
|
|
|
|
- // recalculate angle taking in account offsets
|
|
|
- //projectileAngle = atan2(fabs(destPos.y - spi.y), fabs(destPos.x - spi.x));
|
|
|
- //if(shooter->position < dest)
|
|
|
- // projectileAngle = -projectileAngle;
|
|
|
-
|
|
|
- ProjectileInfo spi;
|
|
|
- spi.shotDone = false;
|
|
|
- spi.creID = shooter->getCreature()->idNumber;
|
|
|
- spi.stackID = shooter->ID;
|
|
|
- // reverse if creature is facing right OR this is non-existing stack that is not tower (war machines)
|
|
|
- spi.reverse = shooter ? !owner->stacksController->facingRight(shooter) : shooter->getCreature()->idNumber != CreatureID::ARROW_TOWERS;
|
|
|
-
|
|
|
- spi.step = 0;
|
|
|
- spi.frameNum = 0;
|
|
|
-
|
|
|
- spi.x0 = from.x;
|
|
|
- spi.y0 = from.y;
|
|
|
+ if (!target)
|
|
|
+ {
|
|
|
+ auto catapultProjectile= new ProjectileCatapult();
|
|
|
+ projectile.reset(catapultProjectile);
|
|
|
|
|
|
- spi.x = from.x;
|
|
|
- spi.y = from.y;
|
|
|
+ catapultProjectile->animation = getProjectileImage(shooter);
|
|
|
+ catapultProjectile->wallDamageAmount = 0; //FIXME - receive from caller
|
|
|
+ catapultProjectile->frameNum = 0;
|
|
|
+ catapultProjectile->reverse = false;
|
|
|
+ catapultProjectile->step = 0;
|
|
|
+ catapultProjectile->steps = 0;
|
|
|
|
|
|
- if (target)
|
|
|
- {
|
|
|
- double animSpeed = AnimationControls::getProjectileSpeed(); // flight speed of projectile
|
|
|
- double distanceSquared = (dest.x - spi.x) * (dest.x - spi.x) + (dest.y - spi.y) * (dest.y - spi.y);
|
|
|
- double distance = sqrt(distanceSquared);
|
|
|
- spi.lastStep = std::round(distance / animSpeed);
|
|
|
- if(spi.lastStep == 0)
|
|
|
- spi.lastStep = 1;
|
|
|
- spi.dx = (dest.x - spi.x) / spi.lastStep;
|
|
|
- spi.dy = (dest.y - spi.y) / spi.lastStep;
|
|
|
+ double animSpeed = AnimationControls::getProjectileSpeed() / 10;
|
|
|
+ catapultProjectile->steps = std::round(std::abs((dest.x - from.x) / animSpeed));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- // Catapult attack
|
|
|
- spi.catapultInfo.reset(new CatapultProjectileInfo(Point((int)spi.x, (int)spi.y), dest));
|
|
|
+ if (stackUsesRayProjectile(shooter) && stackUsesMissileProjectile(shooter))
|
|
|
+ {
|
|
|
+ logAnim->error("Mod error: Creature '%s' has both missile and ray projectiles configured. Mod should be fixed. Using ray projectile configuration...", shooterInfo->nameSing);
|
|
|
+ }
|
|
|
|
|
|
- double animSpeed = AnimationControls::getProjectileSpeed() / 10;
|
|
|
- spi.lastStep = static_cast<int>(std::abs((dest.x - spi.x) / animSpeed));
|
|
|
- spi.dx = animSpeed;
|
|
|
- spi.dy = 0;
|
|
|
+ if (stackUsesRayProjectile(shooter))
|
|
|
+ {
|
|
|
+ auto rayProjectile = new ProjectileRay();
|
|
|
+ projectile.reset(rayProjectile);
|
|
|
|
|
|
- auto img = idToProjectile[spi.creID]->getImage(0);
|
|
|
+ rayProjectile->rayConfig = shooterInfo->animation.projectileRay;
|
|
|
+ }
|
|
|
+ else if (stackUsesMissileProjectile(shooter))
|
|
|
+ {
|
|
|
+ auto missileProjectile = new ProjectileMissile();
|
|
|
+ projectile.reset(missileProjectile);
|
|
|
|
|
|
- // Add explosion anim
|
|
|
- Point animPos(dest.x - 126 + img->width() / 2,
|
|
|
- dest.y - 105 + img->height() / 2);
|
|
|
+ auto & angles = shooterInfo->animation.missleFrameAngles;
|
|
|
|
|
|
- //owner->addNewAnim( new CEffectAnimation(owner, catapultDamage ? "SGEXPL.DEF" : "CSGRCK.DEF", animPos.x, animPos.y));
|
|
|
- }
|
|
|
- double pi = std::atan(1)*4;
|
|
|
+ missileProjectile->animation = getProjectileImage(shooter);
|
|
|
+ missileProjectile->reverse = owner->stacksController->facingRight(shooter);
|
|
|
|
|
|
- //in some cases (known one: hero grants shooter bonus to unit) the shooter stack's projectile may not be properly initialized
|
|
|
- if (!idToProjectile.count(spi.creID) && !idToRay.count(spi.creID))
|
|
|
- initStackProjectile(shooter);
|
|
|
|
|
|
- if (idToProjectile.count(spi.creID))
|
|
|
- {
|
|
|
- // only frames below maxFrame are usable: anything higher is either no present or we don't know when it should be used
|
|
|
- size_t maxFrame = std::min<size_t>(angles.size(), idToProjectile.at(spi.creID)->size(0));
|
|
|
+ // only frames below maxFrame are usable: anything higher is either no present or we don't know when it should be used
|
|
|
+ size_t maxFrame = std::min<size_t>(angles.size(), missileProjectile->animation->size(0));
|
|
|
|
|
|
- assert(maxFrame > 0);
|
|
|
- double projectileAngle = atan2(fabs((double)dest.y - from.y), fabs((double)dest.x - from.x));
|
|
|
- //if(shooter->getPosition() < dest)
|
|
|
- // projectileAngle = -projectileAngle;
|
|
|
+ assert(maxFrame > 0);
|
|
|
+ double projectileAngle = atan2(dest.y - from.y, std::abs(dest.x - from.x));
|
|
|
|
|
|
- // values in angles array indicate position from which this frame was rendered, in degrees.
|
|
|
- // find frame that has closest angle to one that we need for this shot
|
|
|
- size_t bestID = 0;
|
|
|
- double bestDiff = fabs( angles[0] / 180 * pi - projectileAngle );
|
|
|
+ // values in angles array indicate position from which this frame was rendered, in degrees.
|
|
|
+ // find frame that has closest angle to one that we need for this shot
|
|
|
+ int bestID = 0;
|
|
|
+ double bestDiff = fabs( angles[0] / 180 * M_PI - projectileAngle );
|
|
|
|
|
|
- for (size_t i=1; i<maxFrame; i++)
|
|
|
- {
|
|
|
- double currentDiff = fabs( angles[i] / 180 * pi - projectileAngle );
|
|
|
- if (currentDiff < bestDiff)
|
|
|
+ for (int i=1; i<maxFrame; i++)
|
|
|
{
|
|
|
- bestID = i;
|
|
|
- bestDiff = currentDiff;
|
|
|
+ double currentDiff = fabs( angles[i] / 180 * M_PI - projectileAngle );
|
|
|
+ if (currentDiff < bestDiff)
|
|
|
+ {
|
|
|
+ bestID = i;
|
|
|
+ bestDiff = currentDiff;
|
|
|
+ }
|
|
|
}
|
|
|
+ missileProjectile->frameNum = bestID;
|
|
|
}
|
|
|
|
|
|
- spi.frameNum = static_cast<int>(bestID);
|
|
|
- }
|
|
|
- else if (idToRay.count(spi.creID))
|
|
|
- {
|
|
|
- // no-op
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- logGlobal->error("Unable to find valid projectile for shooter %d", spi.creID);
|
|
|
+ double animSpeed = AnimationControls::getProjectileSpeed(); // flight speed of projectile
|
|
|
+ double distanceSquared = (dest.x - from.x) * (dest.x - from.x) + (dest.y - from.y) * (dest.y - from.y);
|
|
|
+ double distance = sqrt(distanceSquared);
|
|
|
+ projectile->steps = std::round(distance / animSpeed);
|
|
|
+ if(projectile->steps == 0)
|
|
|
+ projectile->steps = 1;
|
|
|
}
|
|
|
|
|
|
- // Set projectile animation start delay which is specified in frames
|
|
|
- projectiles.push_back(spi);
|
|
|
+ projectile->from = from;
|
|
|
+ projectile->dest = dest;
|
|
|
+ projectile->shooterID = shooter->ID;
|
|
|
+ projectile->step = 0;
|
|
|
+
|
|
|
+ projectiles.push_back(projectile);
|
|
|
}
|