mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-06 17:23:03 +02:00
merloj: Communication p2
- can now find Soldiers in viewRange
This commit is contained in:
parent
e627369767
commit
f24523da7c
@ -16,10 +16,14 @@ public class Communication : MonoBehaviour
|
|||||||
|
|
||||||
// ---------- public methods
|
// ---------- public methods
|
||||||
|
|
||||||
public void Initialize(float _viewRange, Soldier _mySoldier, Entity.Team _myTeam)
|
private void Awake()
|
||||||
|
{
|
||||||
|
mySoldier = GetComponent<Soldier>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialize(float _viewRange, Entity.Team _myTeam)
|
||||||
{
|
{
|
||||||
viewRange = _viewRange;
|
viewRange = _viewRange;
|
||||||
mySoldier = _mySoldier;
|
|
||||||
myTeam = _myTeam;
|
myTeam = _myTeam;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,10 +34,24 @@ public class Communication : MonoBehaviour
|
|||||||
result.enemiesSpotted = new List<Soldier>();
|
result.enemiesSpotted = new List<Soldier>();
|
||||||
|
|
||||||
// look for soldiers in vincinity
|
// look for soldiers in vincinity
|
||||||
|
Soldier[] soldiersFound = GetSoldiersInVincinity();
|
||||||
|
|
||||||
// send Keep Alive (myTeam) - reset TTL (myTTL)
|
// send Keep Alive (myTeam) - reset TTL (myTTL)
|
||||||
|
foreach (Soldier sold in soldiersFound)
|
||||||
|
{
|
||||||
|
if (sold.GetOwnTeam() == myTeam)
|
||||||
|
{
|
||||||
|
result.resetTTL = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Debug.Log(result.resetTTL);
|
||||||
|
|
||||||
// look fo enemies (enemyTeam) - add Enemies to enemiesSpotted (send List<Enemies>)
|
// look fo enemies (enemyTeam) - add Enemies to enemiesSpotted (send List<Enemies>)
|
||||||
|
if (result.resetTTL)//only check for enemies if you can see your squad
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -42,9 +60,27 @@ public class Communication : MonoBehaviour
|
|||||||
|
|
||||||
private Soldier[] GetSoldiersInVincinity()
|
private Soldier[] GetSoldiersInVincinity()
|
||||||
{
|
{
|
||||||
//TO DO - implement
|
List<Soldier> soldiersFound = new List<Soldier>();
|
||||||
Physics.SphereCastAll()
|
|
||||||
|
|
||||||
return null;
|
Vector2Int curPos = mySoldier.tileCoord;
|
||||||
|
int range = mySoldier.rangeView;
|
||||||
|
int rangeSQR = range * range;
|
||||||
|
|
||||||
|
for (int i=curPos.x - range; i <= curPos.x + range; i++)
|
||||||
|
{
|
||||||
|
for (int j = curPos.y - range; j <= curPos.y + range; j++)
|
||||||
|
{
|
||||||
|
Vector2Int curTile = new Vector2Int(i, j);
|
||||||
|
if ( (curTile - curPos).sqrMagnitude <= rangeSQR && curTile != curPos)//is current Tile in a circular range (and not our tile)
|
||||||
|
{
|
||||||
|
Soldier newSoldier = (Soldier)TilemapManager.GetSoldierS(i, j);
|
||||||
|
|
||||||
|
if (newSoldier != null)
|
||||||
|
soldiersFound.Add(newSoldier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return soldiersFound.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@ public class Entity : MonoBehaviour
|
|||||||
|
|
||||||
[HideInInspector] public UnityEvent<Entity> OnDeath = new UnityEvent<Entity>();
|
[HideInInspector] public UnityEvent<Entity> OnDeath = new UnityEvent<Entity>();
|
||||||
|
|
||||||
[SerializeField] protected Vector2Int tileCoord;
|
public Vector2Int tileCoord;
|
||||||
|
|
||||||
[SerializeField] protected Vector3 WORLD_SPACE_OFFSET = new Vector3(0.5f, 0.5f, 0.5f);
|
[SerializeField] protected Vector3 WORLD_SPACE_OFFSET = new Vector3(0.5f, 0.5f, 0.5f);
|
||||||
|
|
||||||
|
|||||||
@ -59,7 +59,7 @@ public class Soldier : Entity
|
|||||||
|
|
||||||
[Header("Soldier Values")]
|
[Header("Soldier Values")]
|
||||||
[SerializeField] private float rangeAttack = 100;
|
[SerializeField] private float rangeAttack = 100;
|
||||||
[SerializeField] private float rangeView = 1;
|
public int rangeView = 1;
|
||||||
[SerializeField] private float damageAttack = 1;
|
[SerializeField] private float damageAttack = 1;
|
||||||
[SerializeField] private int speedAttack = 1; // ticks between attacks
|
[SerializeField] private int speedAttack = 1; // ticks between attacks
|
||||||
[SerializeField] private int lastAttackTick = -1;
|
[SerializeField] private int lastAttackTick = -1;
|
||||||
@ -69,11 +69,21 @@ public class Soldier : Entity
|
|||||||
[SerializeField] private Team enemyType;
|
[SerializeField] private Team enemyType;
|
||||||
|
|
||||||
[SerializeField] private Vector2Int movementDestination = Vector2Int.zero;
|
[SerializeField] private Vector2Int movementDestination = Vector2Int.zero;
|
||||||
[SerializeField] private bool hasReachedDestination = true;
|
[SerializeField] private bool hasReachedDestination = true;
|
||||||
// Start is called before the first frame update
|
|
||||||
|
private Communication ourCommunication = null;
|
||||||
|
|
||||||
|
protected override void Awake()
|
||||||
|
{
|
||||||
|
base.Awake();
|
||||||
|
ourCommunication = GetComponent<Communication>();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Start(){
|
protected override void Start(){
|
||||||
base.Start();
|
base.Start();
|
||||||
SetEnemyTag();
|
SetEnemyTag();
|
||||||
|
|
||||||
|
ourCommunication.Initialize(rangeView, myTeam);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetEnemyTag()
|
public void SetEnemyTag()
|
||||||
@ -84,7 +94,14 @@ public class Soldier : Entity
|
|||||||
|
|
||||||
protected override void HandleTick(TickSystem.OnTickEventArgs tickEventArgs)
|
protected override void HandleTick(TickSystem.OnTickEventArgs tickEventArgs)
|
||||||
{
|
{
|
||||||
// base.HandleTick(tickEventArgs);
|
// base.HandleTick(tickEventArgs);
|
||||||
|
|
||||||
|
Communication.CommunicationResult cResult = ourCommunication.HandleCommuncation();
|
||||||
|
|
||||||
|
if (cResult.resetTTL)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
ref Queue<Action> queueToHandle = ref interrupts;
|
ref Queue<Action> queueToHandle = ref interrupts;
|
||||||
if (interrupts.Count < 1) // if no interrupt actions to do, handle regular queue
|
if (interrupts.Count < 1) // if no interrupt actions to do, handle regular queue
|
||||||
|
|||||||
@ -172,6 +172,11 @@ public class TilemapManager : MonoBehaviour
|
|||||||
return ins.MoveEntity(x1, y1, x2, y2);
|
return ins.MoveEntity(x1, y1, x2, y2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Entity GetSoldierS(int x, int y)
|
||||||
|
{
|
||||||
|
return ins.GetSoldier(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
// ---------- private methods
|
// ---------- private methods
|
||||||
|
|
||||||
private TileState GetTileState(int x, int y)
|
private TileState GetTileState(int x, int y)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user