Skip to content

Commit

Permalink
Merge pull request OpenApoc#1495 from kgd192/turning_velocity
Browse files Browse the repository at this point in the history
Fix OpenApoc#1310 Turning Slow Down Mechanic
  • Loading branch information
FilmBoy84 authored Sep 3, 2024
2 parents 00e93d0 + 8792314 commit b733a71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions game/state/city/vehicle.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#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"
#include "framework/framework.h"
#include "framework/logger.h"
Expand All @@ -11,6 +12,7 @@
#include "game/state/city/building.h"
#include "game/state/city/city.h"
#include "game/state/city/scenery.h"
#include "game/state/city/vehicle.h"
#include "game/state/city/vehiclemission.h"
#include "game/state/city/vequipment.h"
#include "game/state/gameevent.h"
Expand All @@ -31,8 +33,10 @@
#include "game/state/tilemap/tileobject_vehicle.h"
#include "game/ui/general/messagebox.h"
#include "library/sp.h"
#include <fstream>
#include <glm/glm.hpp>
#include <glm/gtx/vector_angle.hpp>
#include <iostream>
#include <limits>
#include <queue>
#include <random>
Expand Down Expand Up @@ -558,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 @@ -571,7 +574,8 @@ 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;
}
}
}
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, purely found by data analysis, could not
// establish any logical conclusion
static const float TURNING_SLOW_DOWN_CORRECTION = 38.893f;

class Image;
class TileObjectVehicle;
Expand Down

0 comments on commit b733a71

Please sign in to comment.