Skip to content

Commit

Permalink
Fix Velocity Slowdown during turn
Browse files Browse the repository at this point in the history
Slowdown mechanic now uses the angular velocity and not ticks, to prevent issue OpenApoc#1310
  • Loading branch information
kgd192 committed Aug 30, 2024
1 parent 60db974 commit 8590eb8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
21 changes: 5 additions & 16 deletions game/state/city/vehicle.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#include "game/state/gametime.h"
#include <cstdlib>
#endif
#include "game/state/city/vehicle.h"
#include "framework/configfile.h"
Expand Down Expand Up @@ -96,8 +98,8 @@ const UString &StateObject<Vehicle>::getId(const GameState &state, const sp<Vehi

class FlyingVehicleMover : public VehicleMover
{
public:
FlyingVehicleMover(Vehicle &v) : VehicleMover(v) {}
public:
FlyingVehicleMover(Vehicle &v) : VehicleMover(v) {}
// Vehicle is considered idle whenever it's at goal in its tile, even if it has missions to do
void updateIdle(GameState &state)
{
Expand Down Expand Up @@ -560,7 +562,6 @@ class FlyingVehicleMover : public VehicleMover
// d += 0.12f * (float)M_PI;
vehicle.ticksToTurn = floorf(d / vehicle.angularVelocity);

// FIXME: Introduce proper turning speed
// Here we just slow down velocity if we're moving too quickly
if (vehicle.position != vehicle.goalPosition)
{
Expand All @@ -573,21 +574,9 @@ class FlyingVehicleMover : public VehicleMover
2.0f);
if (ticksToMove < vehicle.ticksToTurn)
{
vehicle.velocity *= (float)ticksToMove / (float)vehicle.ticksToTurn;
vehicle.velocity *= std::abs(vehicle.angularVelocity) * TURNING_SLOW_DOWN_CORRECTION;
}

//@kgd192 log velocity data in relation to angular velocity for research
std::ofstream velocityLog("velocitylog.csv", std::ios_base::app);
velocityLog << ("angular, " + std::to_string(vehicle.angularVelocity) + "\n");
velocityLog << ("old velocity," + std::to_string(vehicle.velocity.x) +
"," + std::to_string(vehicle.velocity.y) + "," +
std::to_string(vehicle.velocity.z) + "\n");
// Slow down in relation to angular Velocity
auto turningV = vehicle.velocity;
turningV = vehicle.velocity * std::abs(vehicle.angularVelocity);
velocityLog << ("new velocity," + std::to_string(turningV.x) +
"," + std::to_string(turningV.y) + "," +
std::to_string(turningV.z) + "\n");
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions game/state/city/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ static const int FV_SCRAPPED_COST_PERCENT = 25;
static const int FUEL_TICKS_PER_SECOND = 144;
// How much ticks is required to spend one unit of fuel
static const int FUEL_TICKS_PER_UNIT = 40000;
// Correction factor for turning slowdown mechanic, pure found by data analysis, could not establish any logical conclution
static const float TURNING_SLOW_DOWN_CORRECTION = 38.893f;


class Image;
class TileObjectVehicle;
Expand Down

0 comments on commit 8590eb8

Please sign in to comment.