/* ========================================================================== * ÀÛ ¼º ÀÚ : À̼ø±Ô * ÀÛ ¼º ÀÏ : 2007.10.08 * ³» ¿ë : * ÁÖÀÇ»çÇ× : *===========================================================================*/ #pragma once /// ±æÃ£±â ³ëµå class cPathNode { friend class cPathFinder; friend class cPathNodeCompare; public: cPathNode(); private: /// ÁÂÇ¥ unsigned short mXIndex; unsigned short mYIndex; /// ºÎ¸ð cPathNode* mParent; /// ÀÚ½Ä cPathNode* mChild[8]; /// ´ÙÀ½ (±æÃ£±â ¼º°øÈÄ¿¡ °æ·Î°¡ µÇ´Â ÀÚ½Ä) cPathNode* mNext; /// ÃѺñ¿ë (f = g + h) unsigned short mTotalCost; /// ½ÃÀÛÁ¡¿¡¼­ ÇöÀç ³ëµå±îÁöÀÇ ºñ¿ë (g) unsigned short mCostFromStart; /// ÇöÀç ³ëµå¿¡¼­ ¸ñÇ¥Á¡±îÁöÀÇ ºñ¿ë (h) unsigned short mCostToGoal; /// ´ÝÈû ¿©ºÎ bool mClosed; }; class cNaviField; class cPathNodeCompare { public: bool operator () ( void* x, void* y ) const { return ((cPathNode*)x)->mTotalCost < ((cPathNode*)y)->mTotalCost; } }; /// ±æÃ£±â class cPathFinder { static const unsigned int MAX_PATH_COUNT = 2048; public: cPathFinder( unsigned int capacity ); ~cPathFinder(); /// Áö¿ò void Clear(); /// ÃʱâÈ­ void Init( const cNaviField* naviField ); /// ±æÃ£±â bool FindPath( NiPoint2* pathArray, unsigned int* pathCount, unsigned int maxCount, const NiPoint2& start, const NiPoint2& goal ); bool FindPath( NiPoint2* pathArray, unsigned int* pathCount, unsigned int maxCount, const NiPoint2& start, const NiPoint2& goal, unsigned short sx, unsigned short sy, unsigned short gx, unsigned short gy ); bool GetPossibleGoal( NiPoint2 start, NiPoint2 &goal ); bool IsPossible( NiPoint2 start, NiPoint2 goal ); bool EnableGoto( float x, float y ); protected: /// ±×¸®µå Å©±â¸¦ °Ë»ç bool CheckCellCount( unsigned int cellCount ); /// ¹ß°ßÀû ºñ¿ëÀ» °è»ê unsigned short CalcHeuristic( unsigned short x, unsigned short y ); protected: /// ±×¸®µå Å©±â ¹× ´ÜÀ§ unsigned int mCellCount; unsigned int mLineCount; /// ³ëµå ¹è¿­ cPathNode** mNodes; cPathNode*** mCells; cPathNode mTempNode; /// ¿­¸° Å¥ typedef tPriorityQueue cOpenQueue; cOpenQueue mOpenQueue; /// ¸ñÇ¥Á¡ unsigned short mGoalX; unsigned short mGoalY; }; inline bool cPathFinder::EnableGoto( float x, float y ) { if( x < 0 ) return false; if( y < 0 ) return false; unsigned short xi = (unsigned short)((x + 50.0f) / 100.0f); unsigned short yi = (unsigned short)((y + 50.0f) / 100.0f); if( xi >= mCellCount ) return false; if( yi >= mCellCount ) return false; assert( mCells ); return mCells[yi][xi] != 0; }