<commit_before>#include "ControlSystem.hpp"
#include <DeferredTaskSystem.hpp>
#include <TimeWorldComponent.hpp>
#include <InputWorldComponent.hpp>

#include "MovementComponent.hpp"
#include "CollisionComponent.hpp"
#include "TankComponent.hpp"

using namespace Poly;

void ControlSystem::ControlSystemPhase(World* world)
{

	GameManagerComponent* gameManager = nullptr;
	double time = world->GetWorldComponent<TimeWorldComponent>()->GetGameplayTime();
	double deltaTime = TimeSystem::GetTimerDeltaTime(world, Poly::eEngineTimer::GAMEPLAY);
	for (auto componentTuple : world->IterateComponents<GameManagerComponent>())
	{
		gameManager = std::get<GameManagerComponent*>(componentTuple);
	}
	for (auto componentTuple : world->IterateComponents<PlayerControllerComponent>())
	{
		PlayerControllerComponent* player = std::get<PlayerControllerComponent*>(componentTuple);
		Vector move(0, 0, 0);
		if (world->GetWorldComponent<InputWorldComponent>()->IsPressed(player->GetLeftKey()))
			move -= Vector::UNIT_X;
		else if (world->GetWorldComponent<InputWorldComponent>()->IsPressed(player->GetRightKey()))
			move += Vector::UNIT_X;


		if (move.Length() > 0)
		{
			move.Normalize();
			move *= player->GetMovementSpeed();
			move *= deltaTime;
			TransformComponent* player_transform = player->GetSibling<TransformComponent>();
			Vector prev_location = player_transform->GetLocalTranslation();
			if (Abs(prev_location.X + move.X) <= player->GetMaxAbsXPosition())
				player_transform->SetLocalTranslation(prev_location + move);
		}
		if (world->GetWorldComponent<InputWorldComponent>()->IsPressed(player->GetShootKey()) && (world->GetWorldComponent<TimeWorldComponent>()->GetGameplayTime() - player->GetLastShoot() >= player->GetShootInterval()))
		{
			Vector pos = player->GetSibling<TransformComponent>()->GetLocalTranslation();

			SpawnBullet(gameManager, world, pos, Vector(0.0f, 0.0f, -1.0f), player->GetBulletSpeed());
			player->SetLastShoot(world->GetWorldComponent<TimeWorldComponent>()->GetGameplayTime());
		}
	}

	for (auto tuple : world->IterateComponents<Invaders::MovementSystem::MovementComponent, Invaders::TankComponent>())
	{
		Invaders::MovementSystem::MovementComponent* transform = std::get<Invaders::MovementSystem::MovementComponent*>(tuple);
		Invaders::TankComponent* tank = std::get<Invaders::TankComponent*>(tuple);

		if (tank->MovedDistance > 100)
		{
			Invaders::MovementSystem::SetLinearVelocity(world, transform->GetOwnerID(), -Invaders::MovementSystem::GetLinearVelocity(world, transform->GetOwnerID()));
			tank->MovedDistance = 0;
		}

		tank->MovedDistance += std::fabs(Invaders::MovementSystem::GetLinearVelocity(world, transform->GetOwnerID()).X * deltaTime);
		
	}
	
	for (auto componentTuple : world->IterateComponents<Invaders::TankComponent, TransformComponent>())
	{
		TransformComponent* transform = std::get<TransformComponent*>(componentTuple);
		Invaders::TankComponent* tank = std::get<Invaders::TankComponent*>(componentTuple);
		TransformComponent* transformTurret = world->GetComponent<TransformComponent>(tank->Turret);
 
		if (tank->NextRotTime < time)
		{
			tank->NextRotTime = time + 5.0f;
			tank->Degree *= -1;
		}
		Quaternion rotaton(Vector::UNIT_Y, tank->Degree * deltaTime);
		rotaton *= transformTurret->GetLocalRotation();
		transformTurret->SetLocalRotation(rotaton);

	}

	for (auto componentTuple : world->IterateComponents<BulletComponent, TransformComponent>())
	{
		BulletComponent* bullet = std::get<BulletComponent*>(componentTuple);
		TransformComponent* transform = std::get<TransformComponent*>(componentTuple);
		if (time < bullet->GetSpawnTme() + bullet->GetLifeTme())
		{
			Vector move = bullet->GetDirection();
			move *= bullet->GetMovementSpeed();
			move *= TimeSystem::GetTimerDeltaTime(world, Poly::eEngineTimer::GAMEPLAY);
			transform->SetLocalTranslation(transform->GetLocalTranslation() + move);
			bullet->GetCollisionBox().SetPosition(transform->GetLocalTranslation() + move);
		}
		else
		{
			if (!gameManager->GetDeadGameEntities()->Contains(bullet->GetOwnerID()))
				gameManager->GetDeadGameEntities()->PushBack(bullet->GetOwnerID());
		}
	}

	Invaders::CollisionSystem::CollisionComponent* collider;
	
	for (auto tuple : world->IterateComponents<Invaders::CollisionSystem::CollisionComponent>())
	{
		collider = std::get<Invaders::CollisionSystem::CollisionComponent*>(tuple);
		if (collider->IsColliding())
		{
			gameManager->SetKillCount(gameManager->GetKillCount() + 1);
			DeferredTaskSystem::DestroyEntity(world, collider->GetOwnerID());<commit_msg>Doubled kill count fixed.<commit_after>#include "ControlSystem.hpp"
#include <DeferredTaskSystem.hpp>
#include <TimeWorldComponent.hpp>
#include <InputWorldComponent.hpp>

#include "MovementComponent.hpp"
#include "CollisionComponent.hpp"
#include "TankComponent.hpp"

using namespace Poly;

void ControlSystem::ControlSystemPhase(World* world)
{

	GameManagerComponent* gameManager = nullptr;
	double time = world->GetWorldComponent<TimeWorldComponent>()->GetGameplayTime();
	double deltaTime = TimeSystem::GetTimerDeltaTime(world, Poly::eEngineTimer::GAMEPLAY);
	for (auto componentTuple : world->IterateComponents<GameManagerComponent>())
	{
		gameManager = std::get<GameManagerComponent*>(componentTuple);
	}
	for (auto componentTuple : world->IterateComponents<PlayerControllerComponent>())
	{
		PlayerControllerComponent* player = std::get<PlayerControllerComponent*>(componentTuple);
		Vector move(0, 0, 0);
		if (world->GetWorldComponent<InputWorldComponent>()->IsPressed(player->GetLeftKey()))
			move -= Vector::UNIT_X;
		else if (world->GetWorldComponent<InputWorldComponent>()->IsPressed(player->GetRightKey()))
			move += Vector::UNIT_X;


		if (move.Length() > 0)
		{
			move.Normalize();
			move *= player->GetMovementSpeed();
			move *= deltaTime;
			TransformComponent* player_transform = player->GetSibling<TransformComponent>();
			Vector prev_location = player_transform->GetLocalTranslation();
			if (Abs(prev_location.X + move.X) <= player->GetMaxAbsXPosition())
				player_transform->SetLocalTranslation(prev_location + move);
		}
		if (world->GetWorldComponent<InputWorldComponent>()->IsPressed(player->GetShootKey()) && (world->GetWorldComponent<TimeWorldComponent>()->GetGameplayTime() - player->GetLastShoot() >= player->GetShootInterval()))
		{
			Vector pos = player->GetSibling<TransformComponent>()->GetLocalTranslation();

			SpawnBullet(gameManager, world, pos, Vector(0.0f, 0.0f, -1.0f), player->GetBulletSpeed());
			player->SetLastShoot(world->GetWorldComponent<TimeWorldComponent>()->GetGameplayTime());
		}
	}

	for (auto tuple : world->IterateComponents<Invaders::MovementSystem::MovementComponent, Invaders::TankComponent>())
	{
		Invaders::MovementSystem::MovementComponent* transform = std::get<Invaders::MovementSystem::MovementComponent*>(tuple);
		Invaders::TankComponent* tank = std::get<Invaders::TankComponent*>(tuple);

		if (tank->MovedDistance > 100)
		{
			Invaders::MovementSystem::SetLinearVelocity(world, transform->GetOwnerID(), -Invaders::MovementSystem::GetLinearVelocity(world, transform->GetOwnerID()));
			tank->MovedDistance = 0;
		}

		tank->MovedDistance += std::fabs(Invaders::MovementSystem::GetLinearVelocity(world, transform->GetOwnerID()).X * deltaTime);
		
	}
	
	for (auto componentTuple : world->IterateComponents<Invaders::TankComponent, TransformComponent>())
	{
		TransformComponent* transform = std::get<TransformComponent*>(componentTuple);
		Invaders::TankComponent* tank = std::get<Invaders::TankComponent*>(componentTuple);
		TransformComponent* transformTurret = world->GetComponent<TransformComponent>(tank->Turret);
 
		if (tank->NextRotTime < time)
		{
			tank->NextRotTime = time + 5.0f;
			tank->Degree *= -1;
		}
		Quaternion rotaton(Vector::UNIT_Y, tank->Degree * deltaTime);
		rotaton *= transformTurret->GetLocalRotation();
		transformTurret->SetLocalRotation(rotaton);

	}

	for (auto componentTuple : world->IterateComponents<BulletComponent, TransformComponent>())
	{
		BulletComponent* bullet = std::get<BulletComponent*>(componentTuple);
		TransformComponent* transform = std::get<TransformComponent*>(componentTuple);
		if (time < bullet->GetSpawnTme() + bullet->GetLifeTme())
		{
			Vector move = bullet->GetDirection();
			move *= bullet->GetMovementSpeed();
			move *= TimeSystem::GetTimerDeltaTime(world, Poly::eEngineTimer::GAMEPLAY);
			transform->SetLocalTranslation(transform->GetLocalTranslation() + move);
			bullet->GetCollisionBox().SetPosition(transform->GetLocalTranslation() + move);
		}
		else
		{
			if (!gameManager->GetDeadGameEntities()->Contains(bullet->GetOwnerID()))
				gameManager->GetDeadGameEntities()->PushBack(bullet->GetOwnerID());
		}
	}

	Invaders::CollisionSystem::CollisionComponent* collider;
	
	for (auto tuple : world->IterateComponents<Invaders::CollisionSystem::CollisionComponent>())
	{
		collider = std::get<Invaders::CollisionSystem::CollisionComponent*>(tuple);
		if (collider->IsColliding())
		{
			if(collider->GetSibling<Invaders::TankComponent>() != nullptr)
				gameManager->SetKillCount(gameManager->GetKillCount() + 1);
			DeferredTaskSystem::DestroyEntity(world, collider->GetOwnerID());
{'fraction_non_alphanumeric': 0.14901491237618375, 'fraction_numerical': 0.003918580603026015, 'mean_word_length': 7.330009066183137, 'pattern_counts': {'":': 0, '<': 64, '<?xml version=': 0, '>': 193, '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': '5386984', 'n_tokens_mistral': 2932, 'n_tokens_neox': 2699, 'n_words': 384}