MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / GoalReached

Method GoalReached

Source/Utils/micropather.cpp:508–569  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

506
507
508void MicroPather::GoalReached( PathNode* node, cPosition* start, cPosition* end, MP_VECTOR< cPosition > *_path )
509{
510 MP_VECTOR< cPosition >& path = *_path;
511 path.clear();
512
513 // We have reached the goal.
514 // How long is the path? Used to allocate the vector which is returned.
515 int count = 1;
516 PathNode* it = node;
517 while( it->parent )
518 {
519 ++count;
520 it = it->parent;
521 }
522
523 // Now that the path has a known length, allocate
524 // and fill the vector that will be returned.
525 if ( count < 3 )
526 {
527 // Handle the short, special case.
528 path.resize(2);
529 path[0] = *start;
530 path[1] = *end;
531 }
532 else
533 {
534 path.resize(count);
535
536 path[0] = *start;
537 path[count-1] = *end;
538 count-=2;
539 it = node->parent;
540
541 while ( it->parent )
542 {
543 path[count] = it->state;
544 it = it->parent;
545 --count;
546 }
547 }
548
549 #ifdef DEBUG_PATH
550 printf( "Path: " );
551 int counter=0;
552 #endif
553 for ( unsigned k=0; k<path.size(); ++k )
554 {
555 #ifdef DEBUG_PATH
556 graph->PrintStateInfo( path[k] );
557 printf( " " );
558 ++counter;
559 if ( counter == 8 )
560 {
561 printf( "\n" );
562 counter = 0;
563 }
564 #endif
565 }

Callers

nothing calls this directly

Calls 4

resizeMethod · 0.80
PrintStateInfoMethod · 0.80
clearMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected