| 634 | |
| 635 | |
| 636 | void MapLoader::LoadLevelScripts( const Vfs::FileContent& process_file, MapData& map_data ) |
| 637 | { |
| 638 | const char* const start= reinterpret_cast<const char*>( process_file.data() ); |
| 639 | const char* const end= start + process_file.size(); |
| 640 | |
| 641 | std::istringstream stream( std::string( start, end ) ); |
| 642 | |
| 643 | char line[ 512 ]; |
| 644 | |
| 645 | while( !stream.eof() ) |
| 646 | { |
| 647 | stream.getline( line, sizeof(line), '\n' ); |
| 648 | if( stream.eof() || stream.fail() ) |
| 649 | break; |
| 650 | |
| 651 | std::istringstream line_stream{ std::string( line ) }; |
| 652 | |
| 653 | char thing_type[ sizeof(line) ]; |
| 654 | line_stream >> thing_type; |
| 655 | |
| 656 | if( line_stream.fail() || thing_type[0] != '#' ) |
| 657 | continue; |
| 658 | else if( StringEquals( thing_type, "#mess" ) ) |
| 659 | { |
| 660 | unsigned int message_number= 0; |
| 661 | line_stream >> message_number; |
| 662 | if( !line_stream.fail() && message_number != 0 ) |
| 663 | LoadMessage( message_number, stream, map_data ); |
| 664 | } |
| 665 | else if( std::strncmp( thing_type, "#proc", std::strlen("#proc" ) ) == 0 ) |
| 666 | { |
| 667 | const unsigned int c_max_procedure_number= 1000; |
| 668 | |
| 669 | // catch something, like #proc42 |
| 670 | if( std::strlen( thing_type ) > std::strlen( "#proc" ) ) |
| 671 | { |
| 672 | const char* const num_str= thing_type + std::strlen( "#proc" ); |
| 673 | const unsigned int procedure_number= std::atoi( num_str ); |
| 674 | if( std::isdigit(*num_str) && procedure_number < c_max_procedure_number ) |
| 675 | LoadProcedure( procedure_number, stream, map_data ); |
| 676 | } |
| 677 | else |
| 678 | { |
| 679 | unsigned int procedure_number; |
| 680 | line_stream >> procedure_number; |
| 681 | if( !line_stream.fail() && procedure_number < c_max_procedure_number ) |
| 682 | LoadProcedure( procedure_number, stream, map_data ); |
| 683 | } |
| 684 | } |
| 685 | else if( StringEquals( thing_type, "#links" ) ) |
| 686 | LoadLinks( stream, map_data ); |
| 687 | else if( StringEquals( thing_type, "#teleports" ) ) |
| 688 | LoadTeleports( stream, map_data ); |
| 689 | else if( StringEquals( thing_type, "#stopani" ) ) |
| 690 | { |
| 691 | map_data.stopani_commands.emplace_back(); |
| 692 | line_stream >> map_data.stopani_commands.back(); |
| 693 | } |
nothing calls this directly
no test coverage detected