Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base: master
...
compare: killai
  • 4 commits
  • 10 files changed
  • 0 commit comments
  • 2 contributors
Commits on Dec 12, 2013
killsto killsto bomb not moving 5cfd501
killsto killsto Merge remote-tracking branch 'origin/master' into killai
Conflicts:
	Game/Units/Types/Ai/Killem/KillemKamakazi.cs
	Game/Units/Types/Ai/Killem/KillemMelee.cs
	Game/Units/Types/Ai/Killem/KillemRanged.cs
	Game/Units/Types/Ai/Seven/ZackKamakazi.cs
	Game/Units/Types/Ai/Seven/ZackMelee.cs
	Game/Units/Types/Ai/Seven/ZackRanged.cs
5c5df56
Commits on Dec 13, 2013
killsto killsto Some changes bc4796c
killsto killsto Stack overflow in octtree && Merge remote-tracking branch 'origin/mas…
…ter' into killai

Conflicts:
	Game/Units/Types/Ai/Killem/KillemKamakazi.cs
	Game/Units/Types/Ai/Killem/KillemMelee.cs
	Game/Units/Types/Ai/Killem/KillemRanged.cs
57d8d14
97 Game/Units/Types/Ai/Killem/KillemKamakazi.cs
View
@@ -12,51 +12,78 @@ public class KillemKamakazi : Kamakazi
EnemyState _enemyState;
AllyState _allyState;
- public KillemKamakazi(string id, StaticModel staticModel) : base(id, staticModel) { }
+ KillemMelee _leader;
+ public AllyState State { get { return _allyState; } set { _allyState = value; } }
+ public Unit Target { get { return _target; } }
+
+ public KillemKamakazi(string id, StaticModel staticModel) : base(id, staticModel)
+ {
+ _allyState = AllyState.Waiting;
+ }
public override void AI(float elapsedTime, OctreeLinked<Unit, string> octree)
{
- if (IsDead == false)
+ if (_allyState == AllyState.MovingToSquad)
{
- // Targeting
- if (_target == null || _target.IsDead)
+ MoveTowards(_leader.Position);
+ }
+
+ Unit closeBomb = null;
+ Unit closeRange = null;
+ Unit closeMelee = null;
+ octree.Traverse((Unit unit) =>
+ {
+ if (closeBomb == null || (unit is ZackKamakazi && this.DistanceTo(unit) < this.DistanceTo(closeBomb)))
{
- float longest = float.MinValue;
- octree.Traverse
- (
- (Unit current) =>
- {
- if ((current is ZackKamakazi || current is ZackMelee || current is ZackRanged) && !current.IsDead)
- {
- float length = (current.Position - Position).Length;
- if (_target == null || _target.IsDead)
- {
- _target = current;
- longest = length;
- }
- else if (length > longest)
- {
- _target = current;
- longest = length;
- }
- }
- }
- );
+ closeBomb = unit;
}
- // Attacking
- else if (Foundations.Abs((Position - _target.Position).Length) < _attackRange / 2)
+ else if (closeRange == null || (unit is ZackRanged && this.DistanceTo(unit) < this.DistanceTo(closeRange)))
{
- Attack(octree);
+ closeRange = unit;
}
- // Moving
- else
+ else if (closeMelee == null || (unit is ZackMelee && this.DistanceTo(unit) < this.DistanceTo(closeMelee)))
{
- Vector direction = _target.Position - Position;
- Position.X += (direction.X / direction.Length) * MoveSpeed;
- Position.Y += (direction.Y / direction.Length) * MoveSpeed;
- Position.Z += (direction.Z / direction.Length) * MoveSpeed;
+ closeMelee = unit;
}
- }
+ });
+
+ }
+ public void RegisterLeader(KillemMelee leader)
+ {
+ _allyState = AllyState.Matched;
+ _leader = leader;
+ }
+
+ public void UnregisterLeader()
+ {
+ _allyState = AllyState.Waiting;
+ _leader = null;
}
+
+ public void FindCloseUnits(OctreeLinked<Unit, string> octree)
+ {
+ Unit closeBomb = null;
+ Unit closeRange = null;
+ Unit closeMelee = null;
+ octree.Traverse((Unit unit) =>
+ {
+ if (closeBomb == null || (unit is ZackKamakazi && this.DistanceTo(unit) < this.DistanceTo(closeBomb)))
+ {
+ closeBomb = unit;
+ }
+ else if (closeRange == null || (unit is ZackRanged && this.DistanceTo(unit) < this.DistanceTo(closeRange)))
+ {
+ closeRange = unit;
+ }
+ else if (closeMelee == null || (unit is ZackMelee && this.DistanceTo(unit) < this.DistanceTo(closeMelee)))
+ {
+ closeMelee = unit;
+ }
+ });
+
+ _leader.RegisterClosest(closeBomb, closeRange, closeBomb);
+ }
+
+
}
}
177 Game/Units/Types/Ai/Killem/KillemMelee.cs
View
@@ -8,83 +8,124 @@
namespace Game.Units
{
+ public delegate Vector VectorV();
public class KillemMelee : Melee
{
Unit _target;
- float _time = 0;
- const float _delay = 4000;
-
- public KillemMelee(string id, StaticModel staticModel) : base(id, staticModel) { }
-
+ AllyState _rangeAllyState;
+ AllyState _bombAllyState;
+ KillemKamakazi _bombAlly;
+ KillemRanged _rangeAlly;
+ private int _minAllyRange = 5000;
+ static List<Unit> _targeted = new ListArray<Unit>(90);
+ public Unit Target { get { return _target; } }
+ public KillemMelee(string id, StaticModel staticModel)
+ : base(id, staticModel)
+ {
+ _rangeAllyState = AllyState.Finding;
+ _bombAllyState = AllyState.Finding;
+ }
public override void AI(float elapsedTime, OctreeLinked<Unit, string> octree)
{
- if (_time < _delay)
- _time += elapsedTime;
- if (IsDead == false)
+ octree.Traverse((Unit unit) =>
{
- if (_target == null || _target.IsDead)
- {
- float shortest = float.MaxValue;
- octree.Traverse
- (
- (Unit current) =>
- {
- if ((current is ZackMelee || current is ZackRanged) && !current.IsDead)
- {
- if (_target == null || _target.IsDead || _target is ZackKamakazi)
- {
- _target = current;
- shortest = (current.Position - Position).Length;
- }
- else
- {
- float length = (current.Position - Position).Length;
- if (length < shortest)
- {
- _target = current;
- shortest = length;
- }
- }
- }
- else if (current is ZackKamakazi && !current.IsDead)
- {
- if (_target == null || _target.IsDead)
- {
- _target = current;
- shortest = (current.Position - Position).Length;
- }
- else
- {
- float length = (current.Position - Position).Length;
- if (length < shortest)
- {
- _target = current;
- shortest = length;
- }
- }
- }
- }
- );
- }
- // Attacking
- else if (Foundations.Abs((Position - _target.Position).Length) < _attackRange)
- {
- AiBattle.lines.Add(new Link3<Vector, Vector, Color>(
- new Vector(Position.X, Position.Y, Position.Z),
- new Vector(_target.Position.X, _target.Position.Y, _target.Position.Z),
- Color.Blue));
- if (Attack(_target))
- _target = null;
- }
- // Moving
- else if (_time > _delay)
+ if (unit is KillemRanged)
+ FindRanged((KillemRanged)unit);
+ if (unit is KillemKamakazi)
+ FindBombed((KillemKamakazi)unit);
+ });
+ if (_bombAlly != null && !AllyInRange(_bombAlly))
+ _bombAlly.State = AllyState.MovingToSquad;
+ if (_rangeAlly != null && !AllyInRange(_rangeAlly))
+ _rangeAlly.State = AllyState.MovingToSquad;
+
+ closeUnits.Traverse((Unit unit) => {
+ if(!_targeted.Contains(unit))
{
- Vector direction = _target.Position - Position;
- Position.X += (direction.X / direction.Length) * MoveSpeed;
- Position.Y += (direction.Y / direction.Length) * MoveSpeed;
- Position.Z += (direction.Z / direction.Length) * MoveSpeed;
+ if (_rangeAlly != null && _rangeAlly.Target == null)
+ {
+ _rangeAlly.SetTarget(unit);
+ }
+ else if (_rangeAlly != null && _rangeAlly.Target != null &&
+ unit.DistanceTo(_rangeAlly) < _rangeAlly.DistanceTo(_rangeAlly.Target))
+ {
+ _rangeAlly.SetTarget(unit);
+ }
+ else if (_rangeAlly != null && _rangeAlly.Target == null)
+ {
+ _rangeAlly.SetTarget(unit);
+ }
+ else if (_rangeAlly != null)
+ {
+
+ }
+
}
+ });
+ }
+
+ List<Unit> closeUnits = new ListArray<Unit>(10);
+ public void RegisterClosest(Unit unit1, Unit unit2, Unit unit3)
+ {
+ if(!closeUnits.Contains(unit1))
+ closeUnits.Add(unit1);
+ if(!closeUnits.Contains(unit2))
+ closeUnits.Add(unit2);
+ if(!closeUnits.Contains(unit3))
+ closeUnits.Add(unit3);
+ }
+
+
+ public void FindRanged(KillemRanged unit)
+ {
+ if (_rangeAlly == null && unit.State == AllyState.Waiting)
+ {
+ _rangeAllyState = AllyState.Matched;
+ _rangeAlly = unit;
+ unit.RegisterLeader(this);
}
+ else if (unit.State == AllyState.Waiting && CloserMoveSpeed((Unit)unit, (Unit)_rangeAlly))
+ {
+ _rangeAlly.UnregisterLeader();
+ unit.RegisterLeader(this);
+ _rangeAlly = unit;
+ unit.RegisterLeader(this);
+ }
+ }
+
+ public void FindBombed(KillemKamakazi unit)
+ {
+ if (_bombAlly == null && unit.State == AllyState.Waiting)
+ {
+ _bombAllyState = AllyState.Matched;
+ _bombAlly = unit;
+ unit.RegisterLeader(this);
+ }
+ else if (unit.State == AllyState.Waiting && CloserMoveSpeed((Unit)unit, (Unit)_bombAlly))
+ {
+ Console.WriteLine(unit.MoveSpeed + " Is closer to " + _moveSpeed + "than " + _bombAlly.MoveSpeed);
+ _bombAlly.UnregisterLeader();
+ unit.RegisterLeader(this);
+ _bombAlly = unit;
+ unit.RegisterLeader(this);
+ }
+ }
+
+ public void ReportDeath(Unit unit)
+ {
+ if(closeUnits.Contains(unit))
+ closeUnits.RemoveFirst(unit);
+ }
+ private bool CloserMoveSpeed(Unit newUnit, Unit currentUnit)
+ {
+ return Math.Abs(newUnit.MoveSpeed - _moveSpeed) < Math.Abs(currentUnit.MoveSpeed - _moveSpeed);
+
}
+
+ private bool AllyInRange(Unit unit)
+ {
+ return DistanceTo(unit) < _minAllyRange;
+ }
+
}
}
140 Game/Units/Types/Ai/Killem/KillemRanged.cs
View
@@ -11,81 +11,91 @@ namespace Game.Units
public class KillemRanged : Ranged
{
Unit _target;
- float _time = 0;
- const float _delay = 4000;
-
- public KillemRanged(string id, StaticModel staticModel) : base(id, staticModel) { }
+ AllyState _allyState = AllyState.Waiting;
+ EnemyState _enemyState = EnemyState.Normal;
+ VectorV _towards;
+ KillemMelee _leader;
+ public AllyState State { get { return _allyState; } set { _allyState = value; } }
+ public Unit Target { get { return _target; } }
+ public KillemRanged(string id, StaticModel staticModel) : base(id, staticModel)
+ {
+ _allyState = AllyState.Waiting;
+ }
public override void AI(float elapsedTime, OctreeLinked<Unit, string> octree)
{
- if (_time < _delay)
- _time += elapsedTime;
- if (IsDead == false)
+ if (_allyState == AllyState.MovingToSquad /*&& _enemyState != EnemyState.Attacking*/)
{
- // Targeting
- if (_target == null || _target.IsDead)
+ MoveTowards(_leader.Position);
+ }
+ else if (_enemyState == EnemyState.Attacking)
+ {
+ MoveTowards(_target.Position);
+ if ((Position - _target.Position).Length < _attackRange)
{
- float shortest = float.MaxValue;
- octree.Traverse
- (
- (Unit current) =>
- {
- if (current is ZackKamakazi && !current.IsDead)
- {
- if (_target == null || _target.IsDead || !(_target is ZackKamakazi))
- {
- _target = current;
- shortest = (current.Position - Position).Length;
- }
- else
- {
- float length = (current.Position - Position).Length;
- if (length < shortest)
- {
- _target = current;
- shortest = length;
- }
- }
- }
- else if ((current is ZackMelee || current is ZackRanged) && !current.IsDead)
- {
- if (_target == null || _target.IsDead)
- {
- _target = current;
- shortest = (current.Position - Position).Length;
- }
- else
- {
- float length = (current.Position - Position).Length;
- if (length < shortest)
- {
- _target = current;
- shortest = length;
- }
- }
- }
- }
- );
+ Attack(_target);
}
- // Attacking
- else if (Foundations.Abs((Position - _target.Position).Length) < _attackRange)
+
+ if (_target.IsDead)
{
- AiBattle.lines.Add(new Link3<Vector, Vector, Color>(
- new Vector(Position.X, Position.Y, Position.Z),
- new Vector(_target.Position.X, _target.Position.Y, _target.Position.Z),
- Color.Violet));
- if (Attack(_target))
- _target = null;
+ _enemyState = EnemyState.Normal;
+ if (_leader != null)
+ _leader.ReportDeath(_target);
+ _target = null;
}
- // Moving
- else if (_time > _delay)
+ }
+ if(_leader != null)
+ {
+ FindCloseUnits(octree);
+ }
+ }
+
+
+
+ public void FindCloseUnits(OctreeLinked<Unit, string> octree)
+ {
+ Unit closeBomb = null;
+ Unit closeRange = null;
+ Unit closeMelee = null;
+ octree.Traverse((Unit unit) =>
+ {
+ if (unit != null)
{
- Vector direction = _target.Position - Position;
- Position.X += (direction.X / direction.Length) * MoveSpeed;
- Position.Y += (direction.Y / direction.Length) * MoveSpeed;
- Position.Z += (direction.Z / direction.Length) * MoveSpeed;
+ if (closeBomb == null || (!unit.IsDead && unit is ZackKamakazi && this.DistanceTo(unit) < this.DistanceTo(closeBomb)))
+ {
+ closeBomb = unit;
+ }
+ else if (closeRange == null || (!unit.IsDead && unit is ZackRanged && this.DistanceTo(unit) < this.DistanceTo(closeRange)))
+ {
+ closeRange = unit;
+ }
+ else if (closeMelee == null || (!unit.IsDead && unit is ZackMelee && this.DistanceTo(unit) < this.DistanceTo(closeMelee)))
+ {
+ closeMelee = unit;
+ }
}
- }
+ });
+
+ _leader.RegisterClosest(closeBomb, closeRange, closeBomb);
+ }
+
+
+ public void RegisterLeader(KillemMelee leader)
+ {
+ _allyState = AllyState.Matched;
+ _leader = leader;
+ }
+
+ public void SetTarget(Unit target)
+ {
+ _enemyState = EnemyState.Attacking;
+ _target = target;
+ }
+
+ public void UnregisterLeader()
+ {
+ _allyState = AllyState.Waiting;
+ _leader = null;
}
}
}
4 Game/Units/Types/Ai/Killem/State.cs
View
@@ -15,7 +15,9 @@ public enum AllyState
Aligned,
Finding,
Matched,
- Moving
+ Moving,
+ Waiting,
+ MovingToSquad
}
}
1  Game/Units/Types/Ai/Seven/ZackKamakazi.cs
View
@@ -54,7 +54,6 @@ public override void AI(float elapsedTime, OctreeLinked<Unit, string> octree)
Position.Y += (direction.Y / direction.Length) * MoveSpeed;
Position.Z += (direction.Z / direction.Length) * MoveSpeed;
}
- StaticModel.Orientation.W += .1f;
}
}
}
7 Game/Units/Types/Ai/Seven/ZackMelee.cs
View
@@ -18,12 +18,10 @@ public class ZackMelee : Melee
public override void AI(float elapsedTime, OctreeLinked<Unit, string> octree)
{
- if (_time < _delay)
- _time += elapsedTime;
if (IsDead == false)
{
// Targeting
- /*if (_target == null || _target.IsDead)
+ if (_target == null || _target.IsDead)
{
float shortest = float.MaxValue;
octree.Traverse
@@ -66,7 +64,7 @@ public override void AI(float elapsedTime, OctreeLinked<Unit, string> octree)
}
}
);
- }*/
+ }
if (_target == null || _target.IsDead)
{
float shortest = float.MaxValue;
@@ -129,7 +127,6 @@ public override void AI(float elapsedTime, OctreeLinked<Unit, string> octree)
Position.Y += (direction.Y / direction.Length) * MoveSpeed;
Position.Z += (direction.Z / direction.Length) * MoveSpeed;
}
- this.StaticModel.Orientation.W+=.1f;
}
}
}
1  Game/Units/Types/Ai/Seven/ZackRanged.cs
View
@@ -85,7 +85,6 @@ public override void AI(float elapsedTime, OctreeLinked<Unit, string> octree)
Position.Y += (direction.Y / direction.Length) * MoveSpeed;
Position.Z += (direction.Z / direction.Length) * MoveSpeed;
}
- this.StaticModel.Orientation.W+=.1f;
}
}
}
4 Game/Units/Types/Kamakazi.cs
View
@@ -23,8 +23,8 @@ public Explosion()
public abstract class Kamakazi : Unit
{
- private const int _healthMin = 500;
- private const int _healthMax = 1000;
+ private const int _healthMin = 5;
+ private const int _healthMax = 10;
private const int _damageMin = 500;
private const int _damageMax = 700;
private const int _viewDistanceMin = 1;
11 Game/Units/Unit.cs
View
@@ -25,6 +25,7 @@ public abstract class Unit : InterfacePositionVector, InterfaceStringId
public StaticModel StaticModel { get { return _staticModel; } set { _staticModel = value; } }
public Vector Position { get { return _staticModel.Position; } set { _staticModel.Position = value; } }
public virtual bool IsDead { get { return _isDead; } set { _isDead = value; } }
+ public float Attack { get { return _attackRange; } }
public Unit(string id, StaticModel staticModel)
{
@@ -36,9 +37,7 @@ public Unit(string id, StaticModel staticModel)
public void MoveTowards(Vector vector)
{
- //Vector v1 = new Vector(0, 0, -1);
- //Vector moveV = _staticModel.Position - vector;
- //Vector v2 = moveV.RotateBy(_staticModel.Orientation.W, 0, 1, 0);
+ vector = vector - _staticModel.Position;
_staticModel.Position.X += (vector.X / vector.Length) * _moveSpeed;
_staticModel.Position.Y += (vector.Y / vector.Length) * _moveSpeed;
_staticModel.Position.Z += (vector.Z / vector.Length) * _moveSpeed;
@@ -48,5 +47,11 @@ public void MoveTowards(Vector vector)
public static int CompareTo(Unit left, Unit right) { return left.Id.CompareTo(right.Id); }
public static int CompareTo(Unit left, string right) { return left.Id.CompareTo(right); }
+
+ public float DistanceTo(Unit other)
+ {
+ return (Position - other.Position).Length;
+ }
+
}
}
2  SevenEngine/DataStructures/List.cs
View
@@ -491,7 +491,7 @@ public void RemoveFirst(Type removal)
newList[i] = _list[i];
_list = newList;
}
- for (int i = index; i < _count; i++)
+ for (int i = index; i < _count-1; i++)
_list[i] = _list[i + 1];
_count--;
WriterUnlock();

No commit comments for this range

Something went wrong with that request. Please try again.