Skip to content

Commit

Permalink
AI now attacks*
Browse files Browse the repository at this point in the history
*Prioritizes melee, but will use ranged if no moves will yield a melee
attack this turn.  If neither attack may be used this turn it will move
towards the nearest calculated attack position.  Uses predictive
pathfinding & attacking from other units which reflects planned game
changes before the actual commands are issued to the engine.
  • Loading branch information
nthexwn committed May 14, 2013
1 parent 95799a0 commit b2e3b43
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 108 deletions.
15 changes: 4 additions & 11 deletions Haxxit.MonoGame/AI/AINodeData.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartboyDevelopments.Haxxit;

namespace SmartboyDevelopments.Haxxit.MonoGame
{
Expand Down Expand Up @@ -30,8 +31,8 @@ class AINodeData
public bool IsSpawn { get { return isSpawn; } set { isSpawn = value; } }

// Link to the program currently occupying this node
private Programs.Program occupiedBy;
public Programs.Program OccupiedBy { get { return occupiedBy; } set { occupiedBy = value; } }
private Maps.ProgramHeadNode occupiedBy;
public Maps.ProgramHeadNode OccupiedBy { get { return occupiedBy; } set { occupiedBy = value; } }

// This is used on a node by node basis during
// calls fromthe AStar shortest path algorithm
Expand Down Expand Up @@ -62,10 +63,6 @@ public enum AStarStatus
private int h;
public int H { get { return h; } set { h = value; } }

// Planned for future implementation
//public List<Maps.Point> endangeredBy;
//public List<Maps.Point> canFireUpon;

// Constructor
public AINodeData(int column, int row)
{
Expand All @@ -80,10 +77,6 @@ public AINodeData(int column, int row)
f = int.MaxValue;
g = int.MaxValue;
h = int.MaxValue;

// Planned for future implementation
//endangeredBy = new List<Maps.Point>();
//canFireUpon = new List<Maps.Point>();
}

// Checks to see if this node is either available or
Expand All @@ -94,7 +87,7 @@ public bool canHoldCurrentProgram(Maps.ProgramHeadNode program)
{
return true;
}
else if (occupiedBy == program.Program)
else if (occupiedBy == program)
{
return true;
}
Expand Down
55 changes: 55 additions & 0 deletions Haxxit.MonoGame/AI/CommandInfo.cs
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartboyDevelopments.Haxxit;

namespace SmartboyDevelopments.Haxxit.MonoGame
{
// This class stores the actual parameters used in the targetOptions list of the PrioritizedCommand class.
// these parameters include a source point from which to issue the program's command, a destination point
// for that command, the program to be targeted by that command, and a path to get to the source point.
// These CommandInfo objects will be sorted within the targetOptions list of the PrioritizedCommand class
// by the length of their paths (shorter is preferable to AI).
class CommandInfo : IComparable
{
private Maps.Point source;
public Maps.Point Source { get { return source; } set { source = value; } }

private Maps.Point target;
public Maps.Point Target { get { return target; } set { target = value; } }

private Maps.ProgramHeadNode targetProgram;
public Maps.ProgramHeadNode TargetProgram { get { return targetProgram; } set { targetProgram = value; } }

private Stack<Maps.Point> path;
public Stack<Maps.Point> Path { get { return path; } set { path = value; } }

// Constructor
public CommandInfo(Maps.Point newSource, Maps.Point newTarget, Maps.ProgramHeadNode newTargetProgram, Stack<Maps.Point> newPath)
{
source = newSource;
target = newTarget;
targetProgram = newTargetProgram;
path = newPath;
}

// Required for IComparable inheritance
public int CompareTo(object obj)
{
CommandInfo otherCommandInfo = obj as CommandInfo;
if (otherCommandInfo.Path.Count < path.Count)
{
return 1;
}
else if (otherCommandInfo.Path.Count == path.Count)
{
return 0;
}
else
{
return -1;
}
}
}
}
1 change: 1 addition & 0 deletions Haxxit.MonoGame/AI/NotifyArgs.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartboyDevelopments.Haxxit;

namespace SmartboyDevelopments.Haxxit.MonoGame
{
Expand Down

0 comments on commit b2e3b43

Please sign in to comment.