Advertisement
Guest User

Goap Framework Outline

a guest
Jan 6th, 2017
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.16 KB | None | 0 0
  1. /*************************
  2.  *  WorldState Classes
  3.  *************************/
  4.  
  5. public class WorldState
  6. {
  7.     public Dictionary<int, LocationData> LocationData { get; private set; }
  8.     public HashSet<TraversalData> TraversalData { get; private set; }
  9.     public Dictionary<string, bool> FlagData { get; private set; }
  10. }
  11.  
  12. public class LocationData
  13. {
  14.     public EntityTypeEnum EntityType { get; set; }
  15.     public Vector3 Position { get; set; }
  16.     public float LastSeen { get; set; }
  17. }
  18.  
  19. public class EnemyLocationData : LocationData
  20. {
  21.     public Vector3 Direction { get; set; }
  22.     public bool IsEliminated { get; set; }
  23. }
  24.  
  25. public class TraversalData
  26. {
  27.     public Vector3 FromPosition { get; set; }
  28.     public Vector3 ToPosition { get; set; }
  29.     public float LastSeen { get; set; }
  30. }
  31.  
  32. /*************************
  33.  *  Goap Core
  34.  *************************/
  35.  
  36. public interface IGoapCondition
  37. {
  38.     string Name { get; }
  39.     bool Validate(WorldState worldstate);
  40. }
  41.  
  42. public interface IGoapAction
  43. {
  44.     float Cost { get; }
  45.     IGoapCondition[] Preconditions{ get; }
  46.     IGoapCondition[] Postconditions{ get; }
  47.  
  48.     void Update(WorldState worldstate);
  49. }
  50.  
  51. public interface IGoapPlanner
  52. {
  53.     Stack<IGoapAction> Plan(WorldState worldstate);
  54. }
  55.  
  56. public class GoapPlanner :IGoapPlanner
  57. {
  58.     public static Stack<IGoapAction> Plan(IGoapAgent agent)
  59.     {
  60.         // Needs goals access
  61.         // Needs worldstate access
  62.         // Needs Action // access
  63.     }  
  64. }
  65.  
  66. public interface IGoapAgent
  67. {
  68.     SortedList<float, IGoapCondition> Goals { get; }
  69.     IGoapAction[] Actions { get; }
  70.     WorldState WorldState { get; }
  71. }
  72.  
  73. public class GoapAgent : Monobehaviour, IGoapAgent
  74. {
  75.     public SortedList<float, IGoapCondition> Goals { get{ return _goals.Clone(??); } }
  76.     public IGoapAction[] Actions { get{ return _actions.ToArray(); } }
  77.     public WorldState WorldState { get{ return _worldState.Clone(); } }
  78.    
  79.     private SortedList<float, IGoapCondition> _goals;
  80.     private List<IGoapAction> _actions;
  81.     private WorldState _worldState;
  82.    
  83.     private Stack<IGoapAction> _acitonPlan;
  84.    
  85.     public void Update()
  86.     {
  87.     }
  88.    
  89.     private void Replan()
  90.     {
  91.         if(Time.time > _lastReplan + _replanInterval)
  92.         {
  93.             _actionPlan = GoapPlanner.Plan(this);
  94.         }
  95.        
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement