This is a fork of Zandronum Beta for Mac Os (Silicon and Intel)
Revision | 9266146f34411ac926b4bbeeac0fab07d4b8f18e (tree) |
---|---|
Time | 2022-02-04 23:32:48 |
Author | Adam Kaminski <kaminskiadam9@gmai...> |
Commiter | Adam Kaminski |
BOTCMD_DoChatStringSubstitutions now uses FString instead of C-style char arrays.
@@ -623,42 +623,37 @@ | ||
623 | 623 | |
624 | 624 | //***************************************************************************** |
625 | 625 | // |
626 | -void BOTCMD_DoChatStringSubstitutions( CSkullBot *pBot, const char *pszInString, char *pszOutString ) | |
626 | +void BOTCMD_DoChatStringSubstitutions( CSkullBot *pBot, FString &Input ) | |
627 | 627 | { |
628 | - do | |
628 | + FString Output; | |
629 | + const char *pszInString = Input.GetChars(); | |
630 | + | |
631 | + for ( ; pszInString != 0; pszInString++ ) | |
629 | 632 | { |
630 | 633 | // Continue to copy the instring to the outstring until we hit a '$'. |
631 | 634 | if ( *pszInString != '$' ) |
632 | - *pszOutString++ = *pszInString; | |
635 | + Output.AppendCStrPart( pszInString, 1 ); | |
633 | 636 | else |
634 | 637 | { |
635 | 638 | |
636 | 639 | if (( strnicmp( pszInString + 1, "player_damagedby", strlen( "player_damagedby" )) == 0 ) && ( pBot->m_ulLastPlayerDamagedBy != MAXPLAYERS )) |
637 | 640 | { |
638 | - sprintf( pszOutString, "%s", players[pBot->m_ulLastPlayerDamagedBy].userinfo.GetName() ); | |
639 | - pszOutString += strlen ( players[pBot->m_ulLastPlayerDamagedBy].userinfo.GetName() ); | |
640 | - | |
641 | + Output.AppendFormat( "%s", players[pBot->m_ulLastPlayerDamagedBy].userinfo.GetName() ); | |
641 | 642 | pszInString += strlen( "player_damagedby" ); |
642 | 643 | } |
643 | 644 | else if (( strnicmp( pszInString + 1, "player_enemy", strlen( "player_enemy" )) == 0 ) && ( pBot->m_ulPlayerEnemy != MAXPLAYERS )) |
644 | 645 | { |
645 | - sprintf( pszOutString, "%s", players[pBot->m_ulPlayerEnemy].userinfo.GetName() ); | |
646 | - pszOutString += strlen( players[pBot->m_ulPlayerEnemy].userinfo.GetName() ); | |
647 | - | |
646 | + Output.AppendFormat( "%s", players[pBot->m_ulPlayerEnemy].userinfo.GetName() ); | |
648 | 647 | pszInString += strlen( "player_enemy" ); |
649 | 648 | } |
650 | 649 | else if (( strnicmp( pszInString + 1, "player_killedby", strlen( "player_killedby" )) == 0 ) && ( pBot->m_ulPlayerKilledBy != MAXPLAYERS )) |
651 | 650 | { |
652 | - sprintf( pszOutString, "%s", players[pBot->m_ulPlayerKilledBy].userinfo.GetName() ); | |
653 | - pszOutString += strlen( players[pBot->m_ulPlayerKilledBy].userinfo.GetName() ); | |
654 | - | |
651 | + Output.AppendFormat( "%s", players[pBot->m_ulPlayerKilledBy].userinfo.GetName() ); | |
655 | 652 | pszInString += strlen( "player_killedby" ); |
656 | 653 | } |
657 | 654 | else if (( strnicmp( pszInString + 1, "player_killed", strlen( "player_killed" )) == 0 ) && ( pBot->m_ulPlayerKilled != MAXPLAYERS )) |
658 | 655 | { |
659 | - sprintf( pszOutString, "%s", players[pBot->m_ulPlayerKilled].userinfo.GetName() ); | |
660 | - pszOutString += strlen( players[pBot->m_ulPlayerKilled].userinfo.GetName() ); | |
661 | - | |
656 | + Output.AppendFormat( "%s", players[pBot->m_ulPlayerKilled].userinfo.GetName() ); | |
662 | 657 | pszInString += strlen( "player_killed" ); |
663 | 658 | } |
664 | 659 | else if ( strnicmp( pszInString + 1, "player_inlead", strlen( "player_inlead" )) == 0 ) |
@@ -675,9 +670,7 @@ | ||
675 | 670 | ulBestPlayer = ulIdx; |
676 | 671 | } |
677 | 672 | |
678 | - sprintf( pszOutString, "%s", players[ulBestPlayer].userinfo.GetName() ); | |
679 | - pszOutString += strlen( players[ulBestPlayer].userinfo.GetName() ); | |
680 | - | |
673 | + Output.AppendFormat( "%s", players[ulBestPlayer].userinfo.GetName() ); | |
681 | 674 | pszInString += strlen( "player_inlead" ); |
682 | 675 | } |
683 | 676 | else if ( strnicmp( pszInString + 1, "player_lastplace", strlen( "player_lastplace" )) == 0 ) |
@@ -694,9 +687,7 @@ | ||
694 | 687 | ulBestPlayer = ulIdx; |
695 | 688 | } |
696 | 689 | |
697 | - sprintf( pszOutString, "%s", players[ulBestPlayer].userinfo.GetName() ); | |
698 | - pszOutString += strlen( players[ulBestPlayer].userinfo.GetName() ); | |
699 | - | |
690 | + Output.AppendFormat( "%s", players[ulBestPlayer].userinfo.GetName() ); | |
700 | 691 | pszInString += strlen( "player_lastplace" ); |
701 | 692 | } |
702 | 693 | else if ( strnicmp( pszInString + 1, "player_random_notself", strlen( "player_random_notself" )) == 0 ) |
@@ -723,9 +714,7 @@ | ||
723 | 714 | while (( ulPlayer == static_cast<unsigned> ( pBot->GetPlayer( ) - players )) || ( playeringame[ulPlayer] == false )); |
724 | 715 | } |
725 | 716 | |
726 | - sprintf( pszOutString, "%s", players[ulPlayer].userinfo.GetName() ); | |
727 | - pszOutString += strlen( players[ulPlayer].userinfo.GetName() ); | |
728 | - | |
717 | + Output.AppendFormat( "%s", players[ulPlayer].userinfo.GetName() ); | |
729 | 718 | pszInString += strlen( "player_random_notself" ); |
730 | 719 | } |
731 | 720 | else if ( strnicmp( pszInString + 1, "player_random", strlen( "player_random" )) == 0 ) |
@@ -738,37 +727,30 @@ | ||
738 | 727 | } |
739 | 728 | while ( playeringame[ulPlayer] == false ); |
740 | 729 | |
741 | - sprintf( pszOutString, "%s", players[ulPlayer].userinfo.GetName() ); | |
742 | - pszOutString += strlen( players[ulPlayer].userinfo.GetName() ); | |
743 | - | |
730 | + Output.AppendFormat( "%s", players[ulPlayer].userinfo.GetName() ); | |
744 | 731 | pszInString += strlen( "player_random" ); |
745 | 732 | } |
746 | 733 | else if (( strnicmp( pszInString + 1, "player_lastchat", strlen( "player_lastchat" )) == 0 ) && ( g_LastChatPlayer.Len( ) > 0 )) |
747 | 734 | { |
748 | - sprintf( pszOutString, "%s", g_LastChatPlayer.GetChars( )); | |
749 | - pszOutString += g_LastChatPlayer.Len( ); | |
750 | - | |
735 | + Output.AppendFormat( "%s", g_LastChatPlayer.GetChars() ); | |
751 | 736 | pszInString += strlen( "player_lastchat" ); |
752 | 737 | } |
753 | 738 | else if ( strnicmp( pszInString + 1, "level_name", strlen( "level_name" )) == 0 ) |
754 | 739 | { |
755 | - sprintf( pszOutString, "%s", level.LevelName.GetChars() ); | |
756 | - pszOutString += strlen( level.LevelName.GetChars() ); | |
757 | - | |
740 | + Output.AppendFormat( "%s", level.LevelName.GetChars() ); | |
758 | 741 | pszInString += strlen( "level_name" ); |
759 | 742 | } |
760 | 743 | else if ( strnicmp( pszInString + 1, "map_name", strlen( "map_name" )) == 0 ) |
761 | 744 | { |
762 | - sprintf( pszOutString, "%s", level.mapname ); | |
763 | - pszOutString += strlen( level.mapname ); | |
764 | - | |
745 | + Output.AppendFormat( "%s", level.mapname ); | |
765 | 746 | pszInString += strlen( "map_name" ); |
766 | 747 | } |
767 | 748 | else |
768 | - *pszOutString++ = '$'; | |
749 | + Output += '$'; | |
769 | 750 | } |
770 | - | |
771 | - } while ( *pszInString++ ); | |
751 | + } | |
752 | + | |
753 | + Input = Output; | |
772 | 754 | } |
773 | 755 | |
774 | 756 | //***************************************************************************** |
@@ -2021,24 +2003,23 @@ | ||
2021 | 2003 | // |
2022 | 2004 | static void botcmd_Say( CSkullBot *pBot ) |
2023 | 2005 | { |
2024 | - char szInString[1024]; | |
2025 | - char szOutString[1024]; | |
2026 | - | |
2027 | - sprintf( szInString, "%s", pBot->m_ScriptData.aszStringStack[pBot->m_ScriptData.lStringStackPosition - 1] ); | |
2006 | + FString chatString; | |
2007 | + | |
2008 | + chatString = pBot->m_ScriptData.aszStringStack[pBot->m_ScriptData.lStringStackPosition - 1]; | |
2028 | 2009 | pBot->PopStringStack( ); |
2029 | 2010 | |
2030 | 2011 | if ( bot_allowchat ) |
2031 | 2012 | { |
2032 | 2013 | // Format the message so color codes can appear. |
2033 | - V_ColorizeString( szInString ); | |
2014 | + V_ColorizeString( chatString ); | |
2034 | 2015 | |
2035 | 2016 | // Perform any chat string substitutions that need to be done. |
2036 | - BOTCMD_DoChatStringSubstitutions( pBot, szInString, szOutString ); | |
2017 | + BOTCMD_DoChatStringSubstitutions( pBot, chatString ); | |
2037 | 2018 | |
2038 | 2019 | if ( NETWORK_GetState( ) == NETSTATE_SERVER ) |
2039 | - SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString ); | |
2020 | + SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString ); | |
2040 | 2021 | else |
2041 | - CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString ); | |
2022 | + CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString ); | |
2042 | 2023 | } |
2043 | 2024 | |
2044 | 2025 | // We can now get rid of the chat bubble above the bot's head. |
@@ -2053,8 +2034,7 @@ | ||
2053 | 2034 | { |
2054 | 2035 | char szFilename[1024]; |
2055 | 2036 | char szSection[1024]; |
2056 | - char szInString[1024]; | |
2057 | - char szOutString[1024]; | |
2037 | + FString chatString; | |
2058 | 2038 | CChatFile *pFile; |
2059 | 2039 | |
2060 | 2040 | // We can now get rid of the chat bubble above the bot's head. |
@@ -2078,8 +2058,8 @@ | ||
2078 | 2058 | return; |
2079 | 2059 | } |
2080 | 2060 | |
2081 | - sprintf( szInString, "%s", pFile->ChooseRandomEntry( szSection )); | |
2082 | - if ( stricmp( szInString, "NULL" ) == 0 ) | |
2061 | + chatString = pFile->ChooseRandomEntry( szSection ); | |
2062 | + if ( chatString.CompareNoCase( "NULL" ) == 0 ) | |
2083 | 2063 | { |
2084 | 2064 | Printf( "botcmd_SayFromFile: Couldn't find section %s in file %s!\n", szSection, szFilename ); |
2085 | 2065 |
@@ -2091,15 +2071,15 @@ | ||
2091 | 2071 | if ( bot_allowchat ) |
2092 | 2072 | { |
2093 | 2073 | // Format the message so color codes can appear. |
2094 | - V_ColorizeString( szInString ); | |
2074 | + V_ColorizeString( chatString ); | |
2095 | 2075 | |
2096 | 2076 | // Perform any chat string substitutions that need to be done. |
2097 | - BOTCMD_DoChatStringSubstitutions( pBot, szInString, szOutString ); | |
2077 | + BOTCMD_DoChatStringSubstitutions( pBot, chatString ); | |
2098 | 2078 | |
2099 | 2079 | if ( NETWORK_GetState( ) == NETSTATE_SERVER ) |
2100 | - SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString ); | |
2080 | + SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString ); | |
2101 | 2081 | else |
2102 | - CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString ); | |
2082 | + CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString ); | |
2103 | 2083 | } |
2104 | 2084 | |
2105 | 2085 | // Free the file before leaving. |
@@ -2112,8 +2092,7 @@ | ||
2112 | 2092 | { |
2113 | 2093 | char szFilename[1024]; |
2114 | 2094 | char szSection[1024]; |
2115 | - char szInString[1024]; | |
2116 | - char szOutString[1024]; | |
2095 | + FString chatString; | |
2117 | 2096 | CChatFile *pFile; |
2118 | 2097 | |
2119 | 2098 | // We can now get rid of the chat bubble above the bot's head. |
@@ -2136,8 +2115,8 @@ | ||
2136 | 2115 | return; |
2137 | 2116 | } |
2138 | 2117 | |
2139 | - sprintf( szInString, "%s", pFile->ChooseRandomEntry( szSection )); | |
2140 | - if ( stricmp( szInString, "NULL" ) == 0 ) | |
2118 | + chatString = pFile->ChooseRandomEntry( szSection ); | |
2119 | + if ( chatString.CompareNoCase( "NULL" ) == 0 ) | |
2141 | 2120 | { |
2142 | 2121 | Printf( "botcmd_SayFromChatFile: Couldn't find section %s in file %s!\n", szSection, szFilename ); |
2143 | 2122 |
@@ -2149,15 +2128,15 @@ | ||
2149 | 2128 | if ( bot_allowchat ) |
2150 | 2129 | { |
2151 | 2130 | // Format the message so color codes can appear. |
2152 | - V_ColorizeString( szInString ); | |
2131 | + V_ColorizeString( chatString ); | |
2153 | 2132 | |
2154 | 2133 | // Perform any chat string substitutions that need to be done. |
2155 | - BOTCMD_DoChatStringSubstitutions( pBot, szInString, szOutString ); | |
2134 | + BOTCMD_DoChatStringSubstitutions( pBot, chatString ); | |
2156 | 2135 | |
2157 | 2136 | if ( NETWORK_GetState( ) == NETSTATE_SERVER ) |
2158 | - SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString ); | |
2137 | + SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString ); | |
2159 | 2138 | else |
2160 | - CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString ); | |
2139 | + CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString ); | |
2161 | 2140 | } |
2162 | 2141 | |
2163 | 2142 | // Free the file before leaving. |
@@ -2598,8 +2577,7 @@ | ||
2598 | 2577 | { |
2599 | 2578 | char szLumpname[1024]; |
2600 | 2579 | char szSection[1024]; |
2601 | - char szInString[1024]; | |
2602 | - char szOutString[1024]; | |
2580 | + FString chatString; | |
2603 | 2581 | CChatFile *pFile; |
2604 | 2582 | |
2605 | 2583 | // We can now get rid of the chat bubble above the bot's head. |
@@ -2623,8 +2601,8 @@ | ||
2623 | 2601 | return; |
2624 | 2602 | } |
2625 | 2603 | |
2626 | - sprintf( szInString, "%s", pFile->ChooseRandomEntry( szSection )); | |
2627 | - if ( stricmp( szInString, "NULL" ) == 0 ) | |
2604 | + chatString = pFile->ChooseRandomEntry( szSection ); | |
2605 | + if ( chatString.CompareNoCase( "NULL" ) == 0 ) | |
2628 | 2606 | { |
2629 | 2607 | Printf( "botcmd_SayFromLump: Couldn't find section %s in lump %s!\n", szSection, szLumpname ); |
2630 | 2608 |
@@ -2636,15 +2614,15 @@ | ||
2636 | 2614 | if ( bot_allowchat ) |
2637 | 2615 | { |
2638 | 2616 | // Format the message so color codes can appear. |
2639 | - V_ColorizeString( szInString ); | |
2617 | + V_ColorizeString( chatString ); | |
2640 | 2618 | |
2641 | 2619 | // Perform any chat string substitutions that need to be done. |
2642 | - BOTCMD_DoChatStringSubstitutions( pBot, szInString, szOutString ); | |
2620 | + BOTCMD_DoChatStringSubstitutions( pBot, chatString ); | |
2643 | 2621 | |
2644 | 2622 | if ( NETWORK_GetState( ) == NETSTATE_SERVER ) |
2645 | - SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString ); | |
2623 | + SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString ); | |
2646 | 2624 | else |
2647 | - CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString ); | |
2625 | + CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString ); | |
2648 | 2626 | } |
2649 | 2627 | |
2650 | 2628 | // Free the file before leaving. |
@@ -2657,8 +2635,7 @@ | ||
2657 | 2635 | { |
2658 | 2636 | char szLumpname[1024]; |
2659 | 2637 | char szSection[1024]; |
2660 | - char szInString[1024]; | |
2661 | - char szOutString[1024]; | |
2638 | + FString chatString; | |
2662 | 2639 | CChatFile *pFile; |
2663 | 2640 | |
2664 | 2641 | // We can now get rid of the chat bubble above the bot's head. |
@@ -2681,8 +2658,8 @@ | ||
2681 | 2658 | return; |
2682 | 2659 | } |
2683 | 2660 | |
2684 | - sprintf( szInString, "%s", pFile->ChooseRandomEntry( szSection )); | |
2685 | - if ( stricmp( szInString, "NULL" ) == 0 ) | |
2661 | + chatString = pFile->ChooseRandomEntry( szSection ); | |
2662 | + if ( chatString.CompareNoCase( "NULL" ) == 0 ) | |
2686 | 2663 | { |
2687 | 2664 | Printf( "botcmd_SayFromChatLump: Couldn't find section %s in lump %s!\n", szSection, szLumpname ); |
2688 | 2665 |
@@ -2694,15 +2671,15 @@ | ||
2694 | 2671 | if ( bot_allowchat ) |
2695 | 2672 | { |
2696 | 2673 | // Format the message so color codes can appear. |
2697 | - V_ColorizeString( szInString ); | |
2674 | + V_ColorizeString( chatString ); | |
2698 | 2675 | |
2699 | 2676 | // Perform any chat string substitutions that need to be done. |
2700 | - BOTCMD_DoChatStringSubstitutions( pBot, szInString, szOutString ); | |
2677 | + BOTCMD_DoChatStringSubstitutions( pBot, chatString ); | |
2701 | 2678 | |
2702 | 2679 | if ( NETWORK_GetState( ) == NETSTATE_SERVER ) |
2703 | - SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString ); | |
2680 | + SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString ); | |
2704 | 2681 | else |
2705 | - CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString ); | |
2682 | + CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString ); | |
2706 | 2683 | } |
2707 | 2684 | |
2708 | 2685 | // Free the file before leaving. |
@@ -263,7 +263,7 @@ | ||
263 | 263 | void BOTCMD_SetLastChatString( const char *pszString ); |
264 | 264 | void BOTCMD_SetLastChatPlayer( const char *pszString ); |
265 | 265 | void BOTCMD_SetLastJoinedPlayer( const char *pszString ); |
266 | -void BOTCMD_DoChatStringSubstitutions( CSkullBot *pBot, const char *pszInString, char *pszOutString ); | |
266 | +void BOTCMD_DoChatStringSubstitutions( CSkullBot *pBot, FString &Input ); | |
267 | 267 | bool BOTCMD_IgnoreItem( CSkullBot *pBot, LONG lIdx, bool bVisibilityCheck ); |
268 | 268 | |
269 | 269 | #endif // __BOTCOMMANDS_H__ |