Added support to mark certain drivelines so that they are ignored
by the AI. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7720 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -80,7 +80,8 @@ void AIBaseController::computePath()
|
||||
for(unsigned int i=0; i<m_quad_graph->getNumNodes(); i++)
|
||||
{
|
||||
next.clear();
|
||||
m_quad_graph->getSuccessors(i, next);
|
||||
// Get all successors the AI is allowed to take.
|
||||
m_quad_graph->getSuccessors(i, next, /*for_ai*/true);
|
||||
// For now pick one part on random, which is not adjusted during the
|
||||
// race. Long term statistics might be gathered to determine the
|
||||
// best way, potentially depending on race position etc.
|
||||
|
||||
@@ -132,3 +132,5 @@ float GraphNode::getDistance2FromPoint(const Vec3 &xyz)
|
||||
core::vector2df closest = m_line.getClosestPoint(xyz2d);
|
||||
return (closest-xyz2d).getLengthSQ();
|
||||
} // getDistance2FromPoint
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -134,6 +134,14 @@ public:
|
||||
/** Returns the length of the quad of this node. */
|
||||
float getNodeLength() const
|
||||
{return (m_lower_center-m_upper_center).length();}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true if the index-successor of this node is one that the AI
|
||||
* is allowed to use.
|
||||
* \param index Index of the successor. */
|
||||
bool ignoreSuccessorForAI(unsigned int i) const
|
||||
{
|
||||
return m_all_quads->getQuad(m_vertices[i]).letAIIgnore();
|
||||
};
|
||||
}; // GraphNode
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
/** Constructor, takes 4 points. */
|
||||
Quad::Quad(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2, const Vec3 &p3,
|
||||
bool invisible)
|
||||
bool invisible, bool ai_ignore)
|
||||
{
|
||||
if(sideOfLine2D(p0, p2, p1)>0 ||
|
||||
sideOfLine2D(p0, p2, p3)<0)
|
||||
@@ -44,6 +44,7 @@ Quad::Quad(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2, const Vec3 &p3,
|
||||
m_min_height = std::min ( std::min(p0.getY(), p1.getY()),
|
||||
std::min(p2.getY(), p3.getY()) );
|
||||
m_invisible = invisible;
|
||||
m_ai_ignore = ai_ignore;
|
||||
|
||||
} // Quad
|
||||
|
||||
|
||||
@@ -48,10 +48,13 @@ private:
|
||||
/** Set to true if this quad should not be shown in the minimap. */
|
||||
bool m_invisible;
|
||||
|
||||
/** Set if this quad should not be used by the AI. */
|
||||
bool m_ai_ignore;
|
||||
|
||||
float sideOfLine2D(const Vec3& l1, const Vec3& l2, const Vec3& p) const;
|
||||
public:
|
||||
Quad(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2, const Vec3 &p3,
|
||||
bool invis=false);
|
||||
bool invis=false, bool ai_ignore=false);
|
||||
void getVertices(video::S3DVertex *v, const video::SColor &color) const;
|
||||
bool pointInQuad(const Vec3& p) const;
|
||||
void transform(const btTransform &t, Quad *result) const;
|
||||
@@ -68,5 +71,8 @@ public:
|
||||
/** Returns true of this quad is invisible, i.e. not to be shown in
|
||||
* the minimap. */
|
||||
bool isInvisible() const { return m_invisible; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** True if this quad should be ignored by the AI. */
|
||||
bool letAIIgnore() const { return m_ai_ignore; }
|
||||
}; // class Quad
|
||||
#endif
|
||||
|
||||
@@ -425,13 +425,19 @@ void QuadGraph::cleanupDebugMesh()
|
||||
/** Returns the list of successors or a node.
|
||||
* \param node_number The number of the node.
|
||||
* \param succ A vector of ints to which the successors are added.
|
||||
* \param for_ai true if only quads accessible by the AI should be returned.
|
||||
*/
|
||||
void QuadGraph::getSuccessors(int node_number,
|
||||
std::vector<unsigned int>& succ) const
|
||||
std::vector<unsigned int>& succ,
|
||||
bool for_ai) const
|
||||
{
|
||||
const GraphNode *gn=m_all_nodes[node_number];
|
||||
for(unsigned int i=0; i<gn->getNumberOfSuccessors(); i++) {
|
||||
succ.push_back(gn->getSuccessor(i));
|
||||
for(unsigned int i=0; i<gn->getNumberOfSuccessors(); i++)
|
||||
{
|
||||
// If getSuccessor is called for the AI, only add
|
||||
// quads that are meant for the AI to be used.
|
||||
if(!for_ai || !gn->ignoreSuccessorForAI(i))
|
||||
succ.push_back(gn->getSuccessor(i));
|
||||
}
|
||||
} // getSuccessors
|
||||
|
||||
|
||||
@@ -75,7 +75,8 @@ public:
|
||||
void createDebugMesh();
|
||||
void cleanupDebugMesh();
|
||||
void getSuccessors(int node_number,
|
||||
std::vector<unsigned int>& succ) const;
|
||||
std::vector<unsigned int>& succ,
|
||||
bool for_ai=false) const;
|
||||
void spatialToTrack(Vec3 *dst, const Vec3& xyz,
|
||||
const int sector) const;
|
||||
void findRoadSector(const Vec3& XYZ, int *sector,
|
||||
|
||||
@@ -90,6 +90,11 @@ void QuadSet::load(const std::string &filename)
|
||||
xml_node->getName().c_str(), filename.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Note that it's not easy to do the reading of the parameters here
|
||||
// in quad, since the specification in the xml can contain references
|
||||
// to previous points. E.g.:
|
||||
// <quad p0="40:3" p1="40:2" p2="25.396030 0.770338 64.796539" ...
|
||||
Vec3 p0, p1, p2, p3;
|
||||
getPoint(xml_node, "p0", &p0);
|
||||
getPoint(xml_node, "p1", &p1);
|
||||
@@ -97,7 +102,9 @@ void QuadSet::load(const std::string &filename)
|
||||
getPoint(xml_node, "p3", &p3);
|
||||
bool invisible=false;
|
||||
xml_node->get("invisible", &invisible);
|
||||
Quad* q=new Quad(p0,p1,p2,p3, invisible);
|
||||
bool ai_ignore=false;
|
||||
xml_node->get("ai-ignore", &ai_ignore);
|
||||
Quad* q=new Quad(p0,p1,p2,p3, invisible, ai_ignore);
|
||||
m_all_quads.push_back(q);
|
||||
m_max.max(p0);m_max.max(p1);m_max.max(p2);m_max.max(p3);
|
||||
m_min.min(p0);m_min.min(p1);m_min.min(p2);m_min.min(p3);
|
||||
|
||||
Reference in New Issue
Block a user