Skip to content
Open
Show file tree
Hide file tree
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .vs/CSharpMainProjectMainFork/v17/.suo
Binary file not shown.
279 changes: 279 additions & 0 deletions .vs/CSharpMainProjectMainFork/v17/DocumentLayout.backup.json

Large diffs are not rendered by default.

280 changes: 280 additions & 0 deletions .vs/CSharpMainProjectMainFork/v17/DocumentLayout.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions Assets/Resources/PlayerUnits/PlayerUnit3.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
_healthBar: {fileID: 178258570018206233}
_debugPathOutput: {fileID: 0}
--- !u!114 &3664015912038799981
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -67,10 +68,8 @@ MonoBehaviour:
_maxHealth: 400
_brainUpdateDelay: 0.25
_moveDelay: 0.25
_attackDelay: 0.75
_attackDelay: 0.15
_attackRange: 3.5
_shotsPerTarget: 1
_targetsInVolley: 1
_projectileType: 0
_damage: 15
--- !u!1 &526913648782850647
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ protected override void UpdateImpl(float deltaTime, float time)
///////////////////////////////////////
// Insert you code here
///////////////////////////////////////

float maxHeight = 0.6f * totalDistance;
localHeight = maxHeight * (-(t * 2 - 1) * (t * 2 - 1) + 1);

///////////////////////////////////////
// End of the code to insert
///////////////////////////////////////

Height = localHeight;
if (time > StartTime + _timeToTarget)
Hit(_target);
Expand Down
63 changes: 51 additions & 12 deletions Assets/Scripts/UnitBrains/BaseUnitBrain.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Collections.Generic;
using System.Linq;
using Model;
using Model;
using Model.Runtime.Projectiles;
using Model.Runtime.ReadOnly;
using System.Collections.Generic;
using System.Linq;
using UnitBrains.Pathfinding;
using UnitBrains.Player;
using UnityEngine;
using Utilities;
using static UnityEngine.GraphicsBuffer;
using Unit = Model.Runtime.Unit;

namespace UnitBrains
Expand All @@ -18,7 +20,7 @@ public abstract class BaseUnitBrain

protected Unit unit { get; private set; }
protected IReadOnlyRuntimeModel runtimeModel => ServiceLocator.Get<IReadOnlyRuntimeModel>();
private BaseUnitPath _activePath = null;
protected private BaseUnitPath _activePath = null;

private readonly Vector2[] _projectileShifts = new Vector2[]
{
Expand All @@ -33,13 +35,35 @@ public abstract class BaseUnitBrain

public virtual Vector2Int GetNextStep()
{
if (HasTargetsInRange())
return unit.Pos;
DefaultPlayerUnitTactics tactics = DefaultPlayerUnitTactics.GetInstance();

PositionWithDanger targetPos = tactics.GetPriorityTarget(IsPlayerUnitBrain);

var target = runtimeModel.RoMap.Bases[
IsPlayerUnitBrain ? RuntimeModel.BotPlayerId : RuntimeModel.PlayerId];

_activePath = new DummyUnitPath(runtimeModel, unit.Pos, target);
Vector2Int target;

if (targetPos.Danger == 1)
{
if (IsTargetInRange(targetPos.Position))
{
target = unit.Pos;
}
else
{
target = targetPos.Position;

}
}
else if (HasTargetsInRange())
{
target = unit.Pos;
}
else
{
target = targetPos.Position;
}

_activePath = new UnitPath(runtimeModel, unit.Pos, target);
return _activePath.GetNextStepFrom(unit.Pos);
}

Expand Down Expand Up @@ -76,9 +100,23 @@ protected virtual void GenerateProjectiles(Vector2Int forTarget, List<BaseProjec

protected virtual List<Vector2Int> SelectTargets()
{
var result = GetReachableTargets();
while (result.Count > 1)
result.RemoveAt(result.Count - 1);
PositionWithDanger targetPos = DefaultPlayerUnitTactics.GetInstance().GetPriorityTarget(IsPlayerUnitBrain);
List<Vector2Int> result = new List<Vector2Int>();
if (targetPos.Danger == 1)
{
if (IsTargetInRange(targetPos.Position))
{
result.Add(targetPos.Position);
return result;
}
return result;
}
else if (HasTargetsInRange())
{
result.Add(GetReachableTargets().OrderBy(x => GetUnitAt(x).Health).First());
return result;
}

return result;
}

Expand Down Expand Up @@ -128,6 +166,7 @@ protected bool HasTargetsInRange()
return false;
}


protected IEnumerable<IReadOnlyUnit> GetAllEnemyUnits()
{
return runtimeModel.RoUnits
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/UnitBrains/Pathfinding/BaseUnitPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public Vector2Int GetNextStepFrom(Vector2Int unitPos)

found = cell == unitPos;
}
if (found == true)
{
Debug.LogWarning("Unit is on the last node");
return unitPos;
}

Debug.LogError($"Unit {unitPos} is not on the path");
return unitPos;
Expand Down
18 changes: 17 additions & 1 deletion Assets/Scripts/UnitBrains/Pathfinding/DebugPathOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,24 @@ public void HighlightPath(BaseUnitPath path)

private IEnumerator HighlightCoroutine(BaseUnitPath path)
{
// TODO Implement me
Debug.Log("Start Coroutine!");
foreach (Vector2Int pos in path.GetPath())
{
while (allHighlights.Count > 0)
{
DestroyHighlight(0);
}
Vector2Int myPos = pos;
for (int i = 0; i < maxHighlights; i++)
{
myPos = path.GetNextStepFrom(myPos);
CreateHighlight(myPos);
}
CreateHighlight(pos);
yield return new WaitForSecondsRealtime(0.25f);
}
yield break;
// TODO Implement me
}

private void CreateHighlight(Vector2Int atCell)
Expand Down
51 changes: 51 additions & 0 deletions Assets/Scripts/UnitBrains/Pathfinding/Node.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;

namespace UnitBrains.Pathfinding
{
public class Node
{
public int X { get; set; }
public int Y { get; set; }
public int G { get; set; }
public int H { get; set; }
public int Value { get; set; }
public Node Parent { get; set; }

public Node(int x, int y)
{
X = x;
Y = y;
G = 0;
H = 0;
Value = 0;
Parent = null;
}

public void CalculateEstimate(int targetX, int targetY)
{
H = Math.Abs(targetX - X) + Math.Abs(targetY - Y);
}

public void CalculateValue()
{
Value = G + H;
}

public override bool Equals(object obj)
{
if (obj is Node other)
return X == other.X && Y == other.Y;
return false;
}

public override int GetHashCode()
{
return (X, Y).GetHashCode();
}

public override string ToString()
{
return $"({X}, {Y}) G={G} H={H} F={Value}";
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/UnitBrains/Pathfinding/Node.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading