NLS Engine  v0.1
The Next Logical Step in game engine design.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines
ASTARMap.h
Go to the documentation of this file.
00001 
00010 #pragma once
00011 
00012 // Standard Includes
00013 #include <map>
00014 #include <string>
00015 #include <vector>
00016 
00017 // Library Includes
00018 
00019 // Local Includes
00020 #include "../../sharedbase/PointList.h"
00021 #include "../../sharedbase/ComponentInterface.h"
00022 #include "../../sharedbase/Envelope_fwd.h"
00023 
00024 // Forward Declarations
00025 class MessageRouter;
00026 
00027 // Typedefs
00028 
00029 // Constants
00030 
00031 // Classes
00032 namespace Physics {
00033 
00034   enum STATE {SOLID, PICKUP, FREE};
00035 
00036   struct navPoint {
00037     int f, g;
00038     float h;
00039     Point pos;
00040     navPoint* parent;
00041   };
00042 
00043   typedef std::map< Point, STATE > STATEGrid;
00044   typedef std::map< Point, navPoint > NavGrid;
00045 
00046   class ASTARMap : public ComponentInterface {
00047   public:
00048     ASTARMap(EntitySPTR owner, ModuleInterface* module, MessageRouter* msgrtr);
00049 
00050     ~ASTARMap();
00051 
00052     // Load the map from a TMX file.
00053     bool LoadMapData(EnvelopeSPTR data);
00054     bool LoadObjectData(EnvelopeSPTR data);
00055 
00056     // Obstacle placement attempt.
00057     EnvelopeSPTR MouseClickonPoint(EnvelopeSPTR env);
00058 
00059     // Retrieves the node at x,y
00060     STATE GetState(Point c);
00061 
00062     // Sets the specified node at x,y to n
00063     void SetState(Point c, STATE n);
00064 
00065     // Shortcut to set the node at x,y to an empty,free node
00066     void RemoveState(Point c);
00067 
00068     // Retrieves the begin iterator
00069     STATEGrid::iterator begin();
00070 
00071     // Retrieves the end iterator
00072     STATEGrid::iterator end();
00073 
00074     // Finds the path to the target node starting at x,y
00075     void FindPath(Point player);
00076 
00077     // Updates the path if anything has changed.
00078     // It will use the currentPoint in points for the starting location.
00079     void UpdatePath();
00080     EnvelopeSPTR UpdateIfPathBlocked(EnvelopeSPTR env); // Checks if the next point in the list is blocked and calls UpdatePath if it is
00081 
00082     void SetGoal(int x, int y);
00083 
00084     // Retrieves the PointList for use by other components or scripting
00085     PointList* GetPoints();
00086 
00087     Point start;
00088   private:
00089     STATEGrid grid;
00090     PointList points;
00091     Point goal;
00092     NavGrid openList;
00093     NavGrid closedList;
00094     MessageRouter* msgrouter;
00095   };
00096 }