void SaveLastPlaylist(HWND hwnd) { char str[40]; WritePrivateProfileString("Playlist","LastPlaylist",list_filename,szINIFileName); wsprintf(str,"%d",GetNodePos(curNode)); WritePrivateProfileString("Playlist","LastNode",str,szINIFileName); }
bool CAI_TacticalServices::FindCoverPos( const Vector &vNearPos, const Vector &vThreatPos, const Vector &vThreatEyePos, float flMinDist, float flMaxDist, Vector *pResult ) { AI_PROFILE_SCOPE( CAI_TacticalServices_FindCoverPos ); MARK_TASK_EXPENSIVE(); int node = FindCoverNode( vNearPos, vThreatPos, vThreatEyePos, flMinDist, flMaxDist ); if (node == NO_NODE) return false; *pResult = GetNodePos( node ); return true; }
bool CAI_TacticalServices::FindLos(const Vector &threatPos, const Vector &threatEyePos, float minThreatDist, float maxThreatDist, float blockTime, FlankType_t eFlankType, const Vector &vecFlankRefPos, float flFlankParam, Vector *pResult) { AI_PROFILE_SCOPE( CAI_TacticalServices_FindLos ); MARK_TASK_EXPENSIVE(); int node = FindLosNode( threatPos, threatEyePos, minThreatDist, maxThreatDist, blockTime, eFlankType, vecFlankRefPos, flFlankParam ); if (node == NO_NODE) return false; *pResult = GetNodePos( node ); return true; }
void CPlanarGraph::PickClosestNode(float px, float py) { float distSqrMin = std::numeric_limits<float>::max(); v2f p; p[0] = px; p[1] = py; for ( int i=0; i<int(m_nodes.size()); i++ ) { v2f pi = m_nodes[i].GetPos(); float distSqrTmp = mag2(pi - p); if ( distSqrTmp < distSqrMin ) { distSqrMin = distSqrTmp; m_pickedNodeIndex = i; } } std::cout << "Have picked the " << m_pickedNodeIndex << "th node centered at " << GetNodePos(m_pickedNodeIndex) << "!\n"; }
bool CAI_TacticalServices::FindBackAwayPos( const Vector &vecThreat, Vector *pResult ) { MARK_TASK_EXPENSIVE(); Vector vMoveAway = GetAbsOrigin() - vecThreat; vMoveAway.NormalizeInPlace(); if ( GetOuter()->GetNavigator()->FindVectorGoal( pResult, vMoveAway, 10*12, 10*12, true ) ) return true; int node = FindBackAwayNode( vecThreat ); if (node != NO_NODE) { *pResult = GetNodePos( node ); return true; } if ( GetOuter()->GetNavigator()->FindVectorGoal( pResult, vMoveAway, GetHullWidth() * 4, GetHullWidth() * 2, true ) ) return true; return false; }
Position GetNodePos(MapPoint pt) { return GetNodePos(Position(pt)); }
Position GetNodePos(MapPoint pt, uint8_t height) { Position result = GetNodePos(pt); result.y -= HEIGHT_FACTOR * height; return result; }
/************************************************************************************************ * CRMPathManager::PathVisit * This method is called recursively to create a network of nodes connected with paths. * * inputs: * c_x, c_y - cell to visit * * return: * none * ************************************************************************************************/ void CRMPathManager::PathVisit(const int c_x, const int c_y) { // does this cell have any neighbors with all walls intact? int i,off; // look at neighbors in random order off = TheRandomMissionManager->GetLandScape()->irand(DIR_FIRST, DIR_MAX-1); ++mDepth; // track our depth of recursion for (i = DIR_FIRST; i<DIR_MAX && mDepth <= mMaxDepth; i++) { int d = (i + off) % DIR_MAX; if ( !Cell(c_x, c_y).Border(d) ) { // we can move this way, since no border int new_c_x = c_x + neighbor_x[d]; int new_c_y = c_y + neighbor_y[d]; if (Cell(new_c_x,new_c_y).Wall() == DIR_ALL) { // we have a new cell that has not been visited! int new_dir; // d is the direction relative to the current cell // new_dir is the direction relative to the next cell (N becomes S, NE becomes SW, etc...) if( d < HALF_DIR_MAX ) { new_dir = d + HALF_DIR_MAX; } else { new_dir = d - HALF_DIR_MAX; } // knock down walls Cell(c_x,c_y).RemoveWall(d); Cell(new_c_x,new_c_y).RemoveWall(new_dir); //DIR_MAX - d); // set path id Node(c_x, c_y)->SetPath(d, mPathCount); Node(new_c_x, new_c_y)->SetPath(new_dir, mPathCount); //DIR_MAX - d, mPathCount); // create path between cells mTerrain->CreatePath( mPathCount++, -1, 0, mPathPoints, GetNodePos(c_x,c_y)[0], GetNodePos(c_x,c_y)[1], GetNodePos(new_c_x,new_c_y)[0], GetNodePos(new_c_x,new_c_y)[1], mPathMinWidth, mPathMaxWidth, mPathDepth, mPathDeviation, mPathBreadth ); // flatten a small spot CArea area; float flat_radius = mPathMaxWidth * fabs(TheRandomMissionManager->GetLandScape()->GetBounds()[1][0] - TheRandomMissionManager->GetLandScape()->GetBounds()[0][0]); area.Init( GetNodePos(c_x,c_y), flat_radius, 0.0f, AT_NONE, 0, 0 ); TheRandomMissionManager->GetLandScape()->FlattenArea(&area, 255 * mPathDepth, false, true, true ); // recurse PathVisit(new_c_x, new_c_y); } } } --mDepth; // NOTE: *whoop* hack alert, the first time this is reached, it should be the very last placed node. if( !mCrossed && TheRandomMissionManager->GetMission()->GetSymmetric() && TheRandomMissionManager->GetMission()->GetBackUpPath() ) { mCrossed = true; int directionSet[3][3] = {DIR_NW,DIR_W,DIR_SW,DIR_N,-1,DIR_S,DIR_NE,DIR_E,DIR_SE}; int ncx = (mXNodes-1)-c_x; int ncy = (mYNodes-1)-c_y; int x_delta = ncx - c_x; int y_delta = ncy - c_y; if( x_delta < -1 ) { x_delta = -1; } else if( x_delta > 1 ) { x_delta = 1; } if( y_delta < -1 ) { y_delta = -1; } else if( y_delta > 1 ) { y_delta = 1; } // make sure the mirror is actually in a different position than then un-mirrored node if( x_delta || y_delta ) { int d = directionSet[x_delta][y_delta]; int new_dir; // d is the direction relative to the current cell // new_dir is the direction relative to the next cell (N becomes S, NE becomes SW, etc...) if( d < HALF_DIR_MAX ) { new_dir = d + HALF_DIR_MAX; } else { new_dir = d - HALF_DIR_MAX; } //NOTE: Knocking down these walls will cause instances to be created on this new artificial path // Since this path could span more than just the normal 1 cell, these walls being knocked down are not exactly correct... but get the job done // knock down walls Cell(c_x,c_y).RemoveWall(d); Cell(ncx,ncy).RemoveWall(new_dir); //DIR_MAX - d); // set path id Node(c_x, c_y)->SetPath(d, mPathCount); Node(ncx, ncy)->SetPath(new_dir, mPathCount); //DIR_MAX - d, mPathCount); // create an artificial path that crosses over to connect the symmetric and non-symmetric map parts mTerrain->CreatePath( mPathCount++, -1, 0, mPathPoints, GetNodePos(c_x,c_y)[0], GetNodePos(c_x,c_y)[1], GetNodePos(ncx,ncy)[0], GetNodePos(ncx,ncy)[1], mPathMinWidth, mPathMaxWidth, mPathDepth, mPathDeviation, mPathBreadth ); } } PlaceLocation(c_x, c_y); }