| 583 | */ |
| 584 | |
| 585 | int CSequencer::ParseLoop( CBlock *block, bstream_t *bstream , CIcarus* icarus) |
| 586 | { |
| 587 | IGameInterface* game = icarus->GetGame(); |
| 588 | CSequence *sequence; |
| 589 | CBlockMember *bm; |
| 590 | float min, max; |
| 591 | int rIter; |
| 592 | int memberNum = 0; |
| 593 | |
| 594 | //Set the parent |
| 595 | sequence = AddSequence( m_curSequence, m_curSequence, ( CSequence::SQ_LOOP | CSequence::SQ_RETAIN ), icarus ); |
| 596 | |
| 597 | assert( sequence ); |
| 598 | if ( sequence == NULL ) |
| 599 | { |
| 600 | game->DebugPrint(IGameInterface::WL_ERROR, "ParseLoop : failed to allocate container sequence" ); |
| 601 | block->Free(icarus); |
| 602 | delete block; |
| 603 | block = NULL; |
| 604 | return SEQ_FAILED; |
| 605 | } |
| 606 | |
| 607 | m_curSequence->AddChild( sequence ); |
| 608 | |
| 609 | //Set the number of iterations of this sequence |
| 610 | |
| 611 | bm = block->GetMember( memberNum++ ); |
| 612 | |
| 613 | if ( bm->GetID() == CIcarus::ID_RANDOM ) |
| 614 | { |
| 615 | //Parse out the random number |
| 616 | min = *(float *) block->GetMemberData( memberNum++ ); |
| 617 | max = *(float *) block->GetMemberData( memberNum++ ); |
| 618 | |
| 619 | rIter = (int) game->Random( min, max ); |
| 620 | sequence->SetIterations( rIter ); |
| 621 | } |
| 622 | else |
| 623 | { |
| 624 | sequence->SetIterations ( (int) (*(float *) bm->GetData()) ); |
| 625 | } |
| 626 | |
| 627 | //Add a unique loop identifier to the block for reference later |
| 628 | block->Write( CIcarus::TK_FLOAT, (float) sequence->GetID(), icarus ); |
| 629 | |
| 630 | //Push this onto the stack to mark the loop entrance |
| 631 | PushCommand( block, CSequence::PUSH_FRONT ); |
| 632 | |
| 633 | //Recursively obtain the loop |
| 634 | Route( sequence, bstream , icarus); |
| 635 | |
| 636 | return SEQ_OK; |
| 637 | } |
| 638 | |
| 639 | /* |
| 640 | ======================== |
nothing calls this directly
no test coverage detected