00001 /*------------------------------------ Includes ---------------------------------------------*/ 00002 #pragma warning(disable: 4786) 00003 00004 #include <iostream> 00005 00006 #include "bsp.h" 00007 #include "game_graph.h" 00008 00009 using namespace std; 00010 00011 00012 /****************************************************************************************************/ 00013 // class cPortal 00014 /****************************************************************************************************/ 00015 /*--------------------------------------------------------------------------------------------------*/ 00016 ostream & operator<<(ostream &os, const cPortal &ex) 00017 { 00018 os << "[" << ex.Get_Id() << "] between ["; 00019 if( ex.Area1 != NULL ) 00020 os << ex.Area1->Get_Id(); 00021 else 00022 os << "NULL"; 00023 00024 cout << "] and ["; 00025 00026 if( ex.Area2 != NULL ) 00027 os << ex.Area2->Get_Id(); 00028 else 00029 os << "NULL"; 00030 00031 cout << "] "; 00032 00033 return os << ex.Segment; 00034 00035 }; 00036 00037 /*--------------------------------------------------------------------------------------------------*/ 00038 cPortal::cPortal(int id) 00039 { 00040 Area1=NULL; 00041 Area2=NULL; 00042 Id=id; 00043 } 00044 00045 /*--------------------------------------------------------------------------------------------------*/ 00046 cPortal::cPortal(cHV_Seg & seg , cSquare_Area * area , int id) 00047 { 00048 assert( area != NULL); 00049 Area1=area; 00050 Area2=NULL; 00051 Segment=seg; 00052 Id=id; 00053 seg.Get_Middle(Position); 00054 } 00055 00056 00057 /*--------------------------------------------------------------------------------------------------*/ 00058 float cPortal::Get_Cost( cA_Star_Node * destination) 00059 { 00060 assert( destination != NULL); 00061 assert( Voisinage.Contain(destination )); 00062 00063 return Get_Distance(Position , destination->Position); 00064 }; 00065 00066 /*--------------------------------------------------------------------------------------------------*/ 00067 float cPortal::Get_Estimated_Cost( cA_Star_Node * destination) 00068 { 00069 // on prendre pour cout estime la longeeur de la ligne droite 00070 assert( destination != NULL); 00071 return Get_Distance(Position , destination->Position); 00072 }; 00073 00074 00075 /*--------------------------------------------------------------------------------------------------*/ 00076 void cPortal::Add_Area( cSquare_Area * new_area) 00077 { 00078 assert( Area1 != NULL || Area2!=NULL); 00079 assert( new_area != NULL); 00080 00081 if(Area1==NULL) 00082 { 00083 assert( Area1 != new_area); 00084 Area1 = new_area; 00085 } 00086 else 00087 { 00088 assert( Area2 != new_area); 00089 Area2 = new_area; 00090 } 00091 } 00092 00093 00094 /*--------------------------------------------------------------------------------------------------*/ 00095 // met ds voisins la liste des noeuds voisins 00096 void cPortal::Get_List_Neighbors( cList_A_Star_Nodes & voisins ) 00097 { 00098 assert( Area1 != NULL); 00099 assert( Area2 != NULL); 00100 00101 cList_A_Star_Nodes::iterator nodes_itr; 00102 voisins.clear(); 00103 for( nodes_itr = Voisinage.begin() ; nodes_itr != Voisinage.end() ; nodes_itr++) 00104 voisins.push_front( (*nodes_itr) ); 00105 00106 }; 00107 00108 /*--------------------------------------------------------------------------------------------------*/ 00109 bool cPortal::Is_Similar( cPortal & portal) 00110 { 00111 return (( Area1 == portal.Area1 && Area2 == portal.Area2 ) || 00112 ( Area1 == portal.Area2 && Area2 == portal.Area1 ) ); 00113 } 00114 00115 /*--------------------------------------------------------------------------------------------------*/ 00116 void cPortal::Add_Voisin( cA_Star_Node * node) 00117 { 00118 assert( node != NULL); 00119 Voisinage.push_front( node); 00120 } 00121 00122 /*--------------------------------------------------------------------------------------------------*/ 00123 void cPortal::Remove_Voisin( cA_Star_Node * node) 00124 { 00125 Voisinage.remove(node); 00126 } 00127 00128 /****************************************************************************************************/ 00129 // class cA_Star_Point 00130 /****************************************************************************************************/ 00131 /*--------------------------------------------------------------------------------------------------*/ 00132 cA_Star_Point::cA_Star_Point( cSquare_Area * area , cPoint2D& p) 00133 { 00134 Area=area; 00135 Position=p; 00136 }; 00137 00138 /*--------------------------------------------------------------------------------------------------*/ 00139 void cA_Star_Point::Get_List_Neighbors( cList_A_Star_Nodes & voisinage ) 00140 { 00141 std::vector<cPortal*>::iterator portals_itr; 00142 assert( Area != NULL); 00143 for( portals_itr = Area->List_Portals.begin() ; portals_itr != Area->List_Portals.end() ; portals_itr++) 00144 voisinage.push_front( (*portals_itr) ); 00145 } 00146 00147 /*--------------------------------------------------------------------------------------------------*/ 00148 float cA_Star_Point::Get_Cost( cA_Star_Node * destination) 00149 { 00150 assert( destination != NULL); 00151 return Get_Distance(Position , destination->Position); 00152 }; 00153 00154 /*--------------------------------------------------------------------------------------------------*/ 00155 float cA_Star_Point::Get_Estimated_Cost( cA_Star_Node * destination) 00156 { 00157 // on prendre pour cout estime la distance directe 00158 assert( destination != NULL); 00159 return Get_Distance(Position , destination->Position); 00160 };