<commit_before>#include "vehicle.h"
#include "game/resources/vehiclefactory.h"
#include <cfloat>
#include <random>

namespace OpenApoc {

Vehicle::Vehicle(VehicleDefinition &def)
	: def(def)
{

}

Vehicle::~Vehicle()
{

}

class VehicleRandomWalk : public VehicleMission
{
public:
	std::default_random_engine generator;
	std::uniform_int_distribution<int> distribution;
	VehicleRandomWalk(Vehicle &vehicle)
		: VehicleMission(vehicle), distribution(-1,1)
			{};
	virtual Vec3<float> getNextDestination()
	{
		FlyingVehicle &v = dynamic_cast<FlyingVehicle&>(*this->vehicle.tileObject);
		TileMap &map = v.owningTile->map;
		Vec3<int> nextPosition;
		int tries = 0;
		do {
			nextPosition = {v.position.x, v.position.y, v.position.z};
			Vec3<int> diff {distribution(generator), distribution(generator), distribution(generator)};
			nextPosition += diff;
			//FIXME HACK - abort after some attempts (e.g. if we're completely trapped)
			//and just phase through whatever obstruction is there
			tries++;
			//Keep looping until we find an empty tile within the map
		} while (nextPosition.x >= map.size.x || nextPosition.x < 0 ||
			nextPosition.y >= map.size.y || nextPosition.y < 0 ||
			nextPosition.z >= map.size.z || nextPosition.z < 0
			//FIXME: Proper routing/obstruction handling
			//(This below could cause an infinite loop if a vehicle gets 'trapped'
			|| (tries < 50 && !map.tiles[nextPosition.z][nextPosition.y][nextPosition.z].objects.empty()));
		return Vec3<float>{nextPosition.x, nextPosition.y, nextPosition.z};
	}
};

class FlyingVehicleMover : public VehicleMover
{
public:
	Vec3<float> goalPosition;
	float speed;
	FlyingVehicleMover(Vehicle &v)
		: VehicleMover(v)
	{
		goalPosition.x = -1.0f;
		speed = 0.1f;
	}
	virtual void update(unsigned int ticks)
	{
		FlyingVehicle &v = dynamic_cast<FlyingVehicle&>(*this->vehicle.tileObject);
		if (goalPosition.x == -1.0f)
			goalPosition = v.mission->getNextDestination();
		float distanceLeft = speed * ticks;
		while (distanceLeft > 0)
		{
			Vec3<float> vectorToGoal = goalPosition -
				v.position;<commit_msg>Add a little randomness to the test vehicle speeds<commit_after>#include "vehicle.h"
#include "game/resources/vehiclefactory.h"
#include <cfloat>
#include <random>

std::default_random_engine rng;

namespace OpenApoc {

Vehicle::Vehicle(VehicleDefinition &def)
	: def(def)
{

}

Vehicle::~Vehicle()
{

}

class VehicleRandomWalk : public VehicleMission
{
public:
	std::uniform_int_distribution<int> distribution;
	VehicleRandomWalk(Vehicle &vehicle)
		: VehicleMission(vehicle), distribution(-1,1)
			{};
	virtual Vec3<float> getNextDestination()
	{
		FlyingVehicle &v = dynamic_cast<FlyingVehicle&>(*this->vehicle.tileObject);
		TileMap &map = v.owningTile->map;
		Vec3<int> nextPosition;
		int tries = 0;
		do {
			nextPosition = {v.position.x, v.position.y, v.position.z};
			Vec3<int> diff {distribution(rng), distribution(rng), distribution(rng)};
			nextPosition += diff;
			//FIXME HACK - abort after some attempts (e.g. if we're completely trapped)
			//and just phase through whatever obstruction is there
			tries++;
			//Keep looping until we find an empty tile within the map
		} while (nextPosition.x >= map.size.x || nextPosition.x < 0 ||
			nextPosition.y >= map.size.y || nextPosition.y < 0 ||
			nextPosition.z >= map.size.z || nextPosition.z < 0
			//FIXME: Proper routing/obstruction handling
			//(This below could cause an infinite loop if a vehicle gets 'trapped'
			|| (tries < 50 && !map.tiles[nextPosition.z][nextPosition.y][nextPosition.z].objects.empty()));
		return Vec3<float>{nextPosition.x, nextPosition.y, nextPosition.z};
	}
};


class FlyingVehicleMover : public VehicleMover
{
public:
	Vec3<float> goalPosition;
	float speed;
	FlyingVehicleMover(Vehicle &v)
		: VehicleMover(v)
	{
		std::uniform_real_distribution<float> distribution(-0.02, 0.02);
		goalPosition.x = -1.0f;
		//Tweak the speed slightly, makes everything a little less synchronised
		speed = 0.05 + distribution(rng);
	}
	virtual void update(unsigned int ticks)
	{
		FlyingVehicle &v = dynamic_cast<FlyingVehicle&>(*this->vehicle.tileObject);
		if (goalPosition.x == -1.0f)
			goalPosition = v.mission->getNextDestination();
		float distanceLeft = speed * ticks;
		while (distanceLeft > 0)
		{
			Vec3<float> vectorToGoal = goalPosition -
				v.position;
{'fraction_non_alphanumeric': 0.13217993079584775, 'fraction_numerical': 0.011303344867358709, 'mean_word_length': 4.516539440203562, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6499994', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1478, 'n_words': 341}