2022-05-23 17:36:25 +02:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-05-23 17:55:37 +02:00
|
|
|
|
2022-05-23 17:36:25 +02:00
|
|
|
public class Formation : MonoBehaviour
|
|
|
|
|
{
|
2022-05-30 13:13:39 +02:00
|
|
|
[SerializeField] Squad squad;
|
2022-05-23 17:36:25 +02:00
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
{
|
2022-05-23 19:07:14 +02:00
|
|
|
squad = GetComponent<Squad>();
|
2022-05-23 17:36:25 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-23 19:07:14 +02:00
|
|
|
public Dictionary<Entity, Vector2Int> CalculatePositions(Vector2Int coordinates)
|
2022-05-23 17:36:25 +02:00
|
|
|
{
|
2022-05-23 19:07:14 +02:00
|
|
|
|
|
|
|
|
List<Entity> soldiers = squad.GetSoldiers();
|
|
|
|
|
Dictionary<Entity, Vector2Int> soldiersNewCoordinates = new Dictionary<Entity, Vector2Int>();
|
2022-05-23 17:36:25 +02:00
|
|
|
int soldierNumber = 0;
|
2022-05-30 13:48:37 +02:00
|
|
|
int add = 1;
|
2022-05-23 17:55:37 +02:00
|
|
|
foreach (Entity Entity in soldiers)
|
2022-05-23 17:36:25 +02:00
|
|
|
{
|
2022-05-30 13:48:37 +02:00
|
|
|
soldiersNewCoordinates.Add(Entity, CalculateSoldierCoordinates(soldierNumber, coordinates, add));
|
2022-05-23 19:07:14 +02:00
|
|
|
soldierNumber++;
|
2022-05-30 13:48:37 +02:00
|
|
|
add *= -1;
|
2022-05-23 17:36:25 +02:00
|
|
|
}
|
2022-05-23 19:07:14 +02:00
|
|
|
return soldiersNewCoordinates;
|
2022-05-23 17:36:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/in-parameter-modifier
|
2022-05-30 13:48:37 +02:00
|
|
|
private Vector2Int CalculateSoldierCoordinates(int soldierNumber, in Vector2Int coordinates,in int add)
|
2022-05-23 17:36:25 +02:00
|
|
|
{
|
2022-05-30 13:13:39 +02:00
|
|
|
// Horizontal line we change x
|
2022-05-30 13:48:37 +02:00
|
|
|
soldierNumber = add * soldierNumber;
|
2022-05-30 13:13:39 +02:00
|
|
|
TilemapManager.TileState tileState = TilemapManager.GetTileState(coordinates.x + soldierNumber, coordinates.y);
|
|
|
|
|
if ( tileState == TilemapManager.TileState.free)
|
|
|
|
|
{
|
|
|
|
|
Vector2Int soldierCoordinates = new Vector2Int(coordinates.x + soldierNumber, coordinates.y);
|
|
|
|
|
return soldierCoordinates;
|
|
|
|
|
} else if (tileState == TilemapManager.TileState.taken)
|
|
|
|
|
{
|
|
|
|
|
Vector2Int soldierCoordinates = new Vector2Int(coordinates.x, coordinates.y);
|
|
|
|
|
return soldierCoordinates;
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
Vector2Int soldierCoordinates = new Vector2Int(coordinates.x, coordinates.y);
|
|
|
|
|
return soldierCoordinates;
|
|
|
|
|
}
|
2022-05-23 17:36:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-05-30 13:48:37 +02:00
|
|
|
|
2022-05-23 17:36:25 +02:00
|
|
|
}
|