Skip to content

Commit c0badc5

Browse files
committed
Fixed Pathfinding to use old starting position if current isn't valid.
The Pathfinding problem fixes an issue with getting stuck on the cliff. Units now always remember their last valid position. Additionally, an automatic un-stuck will happen if a unit gets stuck. Attacking Queue now properly ends when the Action is no longer valid. Completed the Unit and Building lifecycle by hooking event on destroy. The Actor will be removed from the Player's model and game can be lost. Getting an Action Queue of a Unit not having any will initialize it. Temporarily removed everything from the escape Menu. Fixed some namespaces. Added a BotRunner.Log optional API to make robot debugging easier.
1 parent b289a26 commit c0badc5

File tree

21 files changed

+122
-40
lines changed

21 files changed

+122
-40
lines changed

API/Sources/BotRunner.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,15 @@ public static int Speed
4141
{
4242
set { throw new NotImplementedException(); }
4343
}
44+
45+
/// <summary>
46+
/// Logs a string message into the Unity console.
47+
/// All C# objects provide method ToString() that can be used to get a string format.
48+
/// </summary>
49+
/// <param name="message">Mesage to be displayed.</param>
50+
public static void Log(string message)
51+
{
52+
throw new NotImplementedException();
53+
}
4454
}
4555
}

Assets/BotScripts/BattleTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using XposeCraft.Game;
33

4-
namespace XposeCraft.Test
4+
namespace XposeCraft.BotScripts
55
{
66
/// <summary>
77
/// Tretia faza hry.

Assets/BotScripts/BuildingTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using XposeCraft.Game;
33

4-
namespace XposeCraft.Test
4+
namespace XposeCraft.BotScripts
55
{
66
/// <summary>
77
/// Druha faza hry.

Assets/BotScripts/EconomyTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using XposeCraft.Game;
33

4-
namespace XposeCraft.Test
4+
namespace XposeCraft.BotScripts
55
{
66
/// <summary>
77
/// Prva faza hry.

Assets/BotScripts/MyBotData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using XposeCraft.Game;
22

3-
namespace XposeCraft.Test
3+
namespace XposeCraft.BotScripts
44
{
55
/// <summary>
66
/// Additional serialized place to store custom data and references.

Assets/Game/Prefabs/Managers/UGrid.prefab

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,4 @@ MonoBehaviour:
6767
m_Bits: 256
6868
generate: 0
6969
index: 0
70-
pathfinding:
71-
start: {x: 0, y: 0, z: 0}
72-
end: {x: 0, y: 0, z: 0}
73-
gridScript: {fileID: 0}
74-
gridI: 0
75-
myPath:
76-
list:
77-
color: {r: 1, g: 1, b: 1, a: 1}
78-
displayPath: 0
79-
index:
80-
generate: 0
8170
selectionTexture: {fileID: 2800000, guid: 349e81cd9cb2b524f87ae272c078acc5, type: 3}

Assets/Game/Scripts/Core/Faction/Buildings/BuildingController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ private void Killed()
192192
building.OpenPoints(grid, gridI, loc);
193193
Destroy(gameObject);
194194
gui.Killed(gameObject);
195+
PlayerOwner.Buildings.Remove(
196+
GameManager.Instance.ActorLookup[gameObject] as Game.Actors.Buildings.Building);
197+
if (PlayerOwner.Buildings.Count == 0)
198+
{
199+
PlayerOwner.Lost(Player.LoseReason.AllBuildingsDestroyed);
200+
}
195201
}
196202

197203
public void DisplayHealth()

Assets/Game/Scripts/Core/Faction/Units/UnitController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ private void Killed()
410410
{
411411
anim.Die(gameObject);
412412
gui.Killed(gameObject);
413+
PlayerOwner.Units.Remove(GameManager.Instance.ActorLookup[gameObject] as Unit);
413414
}
414415

415416
public void Select(bool select)

Assets/Game/Scripts/Core/Faction/Units/UnitMovement.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class UnitMovement : MonoBehaviour
1919
public float checkDist = 1;
2020
public int layer;
2121
Transform myTransform;
22+
public int lastValidLocation { get; set; }
23+
private int _movementStuckCounter;
2224

2325
private void Awake()
2426
{
@@ -43,19 +45,30 @@ void FixedUpdate()
4345
RequestPath(target);
4446
return;
4547
}
46-
var pointLoc = gridScript.grids[gridI].points[myPath.list[curPoint]].loc;
48+
var point = gridScript.grids[gridI].points[myPath.list[curPoint]];
49+
var pointLoc = point.loc;
4750
float distFromPlace = (
4851
new Vector3(pointLoc.x, 0, pointLoc.z) - new Vector3(myTransform.position.x, 0, myTransform.position.z)
4952
).sqrMagnitude;
5053
if (distFromPlace < checkDist)
5154
{
55+
_movementStuckCounter = 0;
56+
if (point.children.Length > 0)
57+
{
58+
lastValidLocation = myPath.list[curPoint];
59+
}
5260
curPoint++;
5361
if (curPoint == myPath.list.Length)
5462
{
5563
pathComplete = true;
5664
return;
5765
}
5866
}
67+
else if (++_movementStuckCounter > 1000)
68+
{
69+
// If stuck under cliff, un-stuck
70+
myTransform.position = point.loc;
71+
}
5972
// Lerp Rotation
6073
Quaternion targetRotation = Quaternion.LookRotation(
6174
new Vector3(pointLoc.x, 0, pointLoc.z)
@@ -75,6 +88,7 @@ public void SetPath(UPath path)
7588
{
7689
myPath = path;
7790
curPoint = 0;
91+
_movementStuckCounter = 0;
7892
}
7993

8094
void OnDrawGizmosSelected()

Assets/Game/Scripts/Core/Grids/UGrid.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using UnityEngine;
4-
using XposeCraft.Core.Required;
54
using XposeCraft.Game;
65
using XposeCraft.GameInternal.Helpers;
76
#if UNITY_EDITOR
@@ -19,7 +18,6 @@ public class UGrid : MonoBehaviour
1918
public Grid[] grids = new Grid[1];
2019
public bool generate;
2120
public int index;
22-
public APath pathfinding;
2321
public Texture selectionTexture;
2422

2523
public int FindPointGridIndex { get; set; }

0 commit comments

Comments
 (0)