Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 48 additions & 11 deletions Assets/Scripts/UnitBrains/Player/SecondUnitBrain.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using System.Collections.Generic;
using Model;
using Model.Runtime.Projectiles;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Utilities;

namespace UnitBrains.Player
{
public class SecondUnitBrain : DefaultPlayerUnitBrain
{
public override string TargetUnitName => "Cobra Commando";
private List<Vector2Int> moveTarget = new List<Vector2Int>();
private const float OverheatTemperature = 3f;
private const float OverheatCooldown = 2f;
private float _temperature = 0f;
Expand All @@ -26,21 +30,54 @@ protected override void GenerateProjectiles(Vector2Int forTarget, List<BaseProje

public override Vector2Int GetNextStep()
{
return base.GetNextStep();
if (moveTarget.Count == 0 || IsTargetInRange(moveTarget[0]))
{
return unit.Pos;
}

return unit.Pos.CalcNextStepTowards(moveTarget[0]);
}

protected override List<Vector2Int> SelectTargets()
public List<Vector2Int> SelectEnemyBaseAsTarget() {
RuntimeModel runtimeModel = new RuntimeModel();
Vector2Int enemyBase = runtimeModel.RoMap.Bases[IsPlayerUnitBrain ? RuntimeModel.BotPlayerId : RuntimeModel.PlayerId];
moveTarget.Add(enemyBase);
return new List<Vector2Int> { enemyBase };
}

public Vector2Int FindNearestTobaseTarget(List<Vector2Int> attackTargets)
{
///////////////////////////////////////
// Homework 1.4 (1st block, 4rd module)
///////////////////////////////////////
List<Vector2Int> result = GetReachableTargets();
while (result.Count > 1)
Vector2Int nearestToBaseTarget = attackTargets.FirstOrDefault();

foreach (Vector2Int target in attackTargets)
{
result.RemoveAt(result.Count - 1);
if (DistanceToOwnBase(target) < DistanceToOwnBase(nearestToBaseTarget))
{
nearestToBaseTarget = target;
}
}
return result;
///////////////////////////////////////

return nearestToBaseTarget;
}

protected override List<Vector2Int> SelectTargets()
{
moveTarget.Clear();
List<Vector2Int> attackTargets = GetAllTargets().ToList();
if (attackTargets.Count() == 0) {
return SelectEnemyBaseAsTarget();
}

Vector2Int nearestToBaseTarget = FindNearestTobaseTarget(attackTargets);

attackTargets.Clear();

if (IsTargetInRange(nearestToBaseTarget)) {
attackTargets.Add(nearestToBaseTarget);
}
moveTarget.Add(nearestToBaseTarget);

return attackTargets;
}

public override void Update(float deltaTime, float time)
Expand Down