• R/O
  • SSH

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

This is a fork of Zandronum Beta for Mac Os (Silicon and Intel)


Commit MetaInfo

修订版9266146f34411ac926b4bbeeac0fab07d4b8f18e (tree)
时间2022-02-04 23:32:48
作者Adam Kaminski <kaminskiadam9@gmai...>
CommiterAdam Kaminski

Log Message

BOTCMD_DoChatStringSubstitutions now uses FString instead of C-style char arrays.

更改概述

差异

diff -r 54bfc2d7cccb -r 9266146f3441 src/botcommands.cpp
--- a/src/botcommands.cpp Tue Feb 01 09:35:13 2022 -0500
+++ b/src/botcommands.cpp Fri Feb 04 09:32:48 2022 -0500
@@ -623,42 +623,37 @@
623623
624624 //*****************************************************************************
625625 //
626-void BOTCMD_DoChatStringSubstitutions( CSkullBot *pBot, const char *pszInString, char *pszOutString )
626+void BOTCMD_DoChatStringSubstitutions( CSkullBot *pBot, FString &Input )
627627 {
628- do
628+ FString Output;
629+ const char *pszInString = Input.GetChars();
630+
631+ for ( ; pszInString != 0; pszInString++ )
629632 {
630633 // Continue to copy the instring to the outstring until we hit a '$'.
631634 if ( *pszInString != '$' )
632- *pszOutString++ = *pszInString;
635+ Output.AppendCStrPart( pszInString, 1 );
633636 else
634637 {
635638
636639 if (( strnicmp( pszInString + 1, "player_damagedby", strlen( "player_damagedby" )) == 0 ) && ( pBot->m_ulLastPlayerDamagedBy != MAXPLAYERS ))
637640 {
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() );
641642 pszInString += strlen( "player_damagedby" );
642643 }
643644 else if (( strnicmp( pszInString + 1, "player_enemy", strlen( "player_enemy" )) == 0 ) && ( pBot->m_ulPlayerEnemy != MAXPLAYERS ))
644645 {
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() );
648647 pszInString += strlen( "player_enemy" );
649648 }
650649 else if (( strnicmp( pszInString + 1, "player_killedby", strlen( "player_killedby" )) == 0 ) && ( pBot->m_ulPlayerKilledBy != MAXPLAYERS ))
651650 {
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() );
655652 pszInString += strlen( "player_killedby" );
656653 }
657654 else if (( strnicmp( pszInString + 1, "player_killed", strlen( "player_killed" )) == 0 ) && ( pBot->m_ulPlayerKilled != MAXPLAYERS ))
658655 {
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() );
662657 pszInString += strlen( "player_killed" );
663658 }
664659 else if ( strnicmp( pszInString + 1, "player_inlead", strlen( "player_inlead" )) == 0 )
@@ -675,9 +670,7 @@
675670 ulBestPlayer = ulIdx;
676671 }
677672
678- sprintf( pszOutString, "%s", players[ulBestPlayer].userinfo.GetName() );
679- pszOutString += strlen( players[ulBestPlayer].userinfo.GetName() );
680-
673+ Output.AppendFormat( "%s", players[ulBestPlayer].userinfo.GetName() );
681674 pszInString += strlen( "player_inlead" );
682675 }
683676 else if ( strnicmp( pszInString + 1, "player_lastplace", strlen( "player_lastplace" )) == 0 )
@@ -694,9 +687,7 @@
694687 ulBestPlayer = ulIdx;
695688 }
696689
697- sprintf( pszOutString, "%s", players[ulBestPlayer].userinfo.GetName() );
698- pszOutString += strlen( players[ulBestPlayer].userinfo.GetName() );
699-
690+ Output.AppendFormat( "%s", players[ulBestPlayer].userinfo.GetName() );
700691 pszInString += strlen( "player_lastplace" );
701692 }
702693 else if ( strnicmp( pszInString + 1, "player_random_notself", strlen( "player_random_notself" )) == 0 )
@@ -723,9 +714,7 @@
723714 while (( ulPlayer == static_cast<unsigned> ( pBot->GetPlayer( ) - players )) || ( playeringame[ulPlayer] == false ));
724715 }
725716
726- sprintf( pszOutString, "%s", players[ulPlayer].userinfo.GetName() );
727- pszOutString += strlen( players[ulPlayer].userinfo.GetName() );
728-
717+ Output.AppendFormat( "%s", players[ulPlayer].userinfo.GetName() );
729718 pszInString += strlen( "player_random_notself" );
730719 }
731720 else if ( strnicmp( pszInString + 1, "player_random", strlen( "player_random" )) == 0 )
@@ -738,37 +727,30 @@
738727 }
739728 while ( playeringame[ulPlayer] == false );
740729
741- sprintf( pszOutString, "%s", players[ulPlayer].userinfo.GetName() );
742- pszOutString += strlen( players[ulPlayer].userinfo.GetName() );
743-
730+ Output.AppendFormat( "%s", players[ulPlayer].userinfo.GetName() );
744731 pszInString += strlen( "player_random" );
745732 }
746733 else if (( strnicmp( pszInString + 1, "player_lastchat", strlen( "player_lastchat" )) == 0 ) && ( g_LastChatPlayer.Len( ) > 0 ))
747734 {
748- sprintf( pszOutString, "%s", g_LastChatPlayer.GetChars( ));
749- pszOutString += g_LastChatPlayer.Len( );
750-
735+ Output.AppendFormat( "%s", g_LastChatPlayer.GetChars() );
751736 pszInString += strlen( "player_lastchat" );
752737 }
753738 else if ( strnicmp( pszInString + 1, "level_name", strlen( "level_name" )) == 0 )
754739 {
755- sprintf( pszOutString, "%s", level.LevelName.GetChars() );
756- pszOutString += strlen( level.LevelName.GetChars() );
757-
740+ Output.AppendFormat( "%s", level.LevelName.GetChars() );
758741 pszInString += strlen( "level_name" );
759742 }
760743 else if ( strnicmp( pszInString + 1, "map_name", strlen( "map_name" )) == 0 )
761744 {
762- sprintf( pszOutString, "%s", level.mapname );
763- pszOutString += strlen( level.mapname );
764-
745+ Output.AppendFormat( "%s", level.mapname );
765746 pszInString += strlen( "map_name" );
766747 }
767748 else
768- *pszOutString++ = '$';
749+ Output += '$';
769750 }
770-
771- } while ( *pszInString++ );
751+ }
752+
753+ Input = Output;
772754 }
773755
774756 //*****************************************************************************
@@ -2021,24 +2003,23 @@
20212003 //
20222004 static void botcmd_Say( CSkullBot *pBot )
20232005 {
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];
20282009 pBot->PopStringStack( );
20292010
20302011 if ( bot_allowchat )
20312012 {
20322013 // Format the message so color codes can appear.
2033- V_ColorizeString( szInString );
2014+ V_ColorizeString( chatString );
20342015
20352016 // Perform any chat string substitutions that need to be done.
2036- BOTCMD_DoChatStringSubstitutions( pBot, szInString, szOutString );
2017+ BOTCMD_DoChatStringSubstitutions( pBot, chatString );
20372018
20382019 if ( NETWORK_GetState( ) == NETSTATE_SERVER )
2039- SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString );
2020+ SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString );
20402021 else
2041- CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString );
2022+ CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString );
20422023 }
20432024
20442025 // We can now get rid of the chat bubble above the bot's head.
@@ -2053,8 +2034,7 @@
20532034 {
20542035 char szFilename[1024];
20552036 char szSection[1024];
2056- char szInString[1024];
2057- char szOutString[1024];
2037+ FString chatString;
20582038 CChatFile *pFile;
20592039
20602040 // We can now get rid of the chat bubble above the bot's head.
@@ -2078,8 +2058,8 @@
20782058 return;
20792059 }
20802060
2081- sprintf( szInString, "%s", pFile->ChooseRandomEntry( szSection ));
2082- if ( stricmp( szInString, "NULL" ) == 0 )
2061+ chatString = pFile->ChooseRandomEntry( szSection );
2062+ if ( chatString.CompareNoCase( "NULL" ) == 0 )
20832063 {
20842064 Printf( "botcmd_SayFromFile: Couldn't find section %s in file %s!\n", szSection, szFilename );
20852065
@@ -2091,15 +2071,15 @@
20912071 if ( bot_allowchat )
20922072 {
20932073 // Format the message so color codes can appear.
2094- V_ColorizeString( szInString );
2074+ V_ColorizeString( chatString );
20952075
20962076 // Perform any chat string substitutions that need to be done.
2097- BOTCMD_DoChatStringSubstitutions( pBot, szInString, szOutString );
2077+ BOTCMD_DoChatStringSubstitutions( pBot, chatString );
20982078
20992079 if ( NETWORK_GetState( ) == NETSTATE_SERVER )
2100- SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString );
2080+ SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString );
21012081 else
2102- CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString );
2082+ CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString );
21032083 }
21042084
21052085 // Free the file before leaving.
@@ -2112,8 +2092,7 @@
21122092 {
21132093 char szFilename[1024];
21142094 char szSection[1024];
2115- char szInString[1024];
2116- char szOutString[1024];
2095+ FString chatString;
21172096 CChatFile *pFile;
21182097
21192098 // We can now get rid of the chat bubble above the bot's head.
@@ -2136,8 +2115,8 @@
21362115 return;
21372116 }
21382117
2139- sprintf( szInString, "%s", pFile->ChooseRandomEntry( szSection ));
2140- if ( stricmp( szInString, "NULL" ) == 0 )
2118+ chatString = pFile->ChooseRandomEntry( szSection );
2119+ if ( chatString.CompareNoCase( "NULL" ) == 0 )
21412120 {
21422121 Printf( "botcmd_SayFromChatFile: Couldn't find section %s in file %s!\n", szSection, szFilename );
21432122
@@ -2149,15 +2128,15 @@
21492128 if ( bot_allowchat )
21502129 {
21512130 // Format the message so color codes can appear.
2152- V_ColorizeString( szInString );
2131+ V_ColorizeString( chatString );
21532132
21542133 // Perform any chat string substitutions that need to be done.
2155- BOTCMD_DoChatStringSubstitutions( pBot, szInString, szOutString );
2134+ BOTCMD_DoChatStringSubstitutions( pBot, chatString );
21562135
21572136 if ( NETWORK_GetState( ) == NETSTATE_SERVER )
2158- SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString );
2137+ SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString );
21592138 else
2160- CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString );
2139+ CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString );
21612140 }
21622141
21632142 // Free the file before leaving.
@@ -2598,8 +2577,7 @@
25982577 {
25992578 char szLumpname[1024];
26002579 char szSection[1024];
2601- char szInString[1024];
2602- char szOutString[1024];
2580+ FString chatString;
26032581 CChatFile *pFile;
26042582
26052583 // We can now get rid of the chat bubble above the bot's head.
@@ -2623,8 +2601,8 @@
26232601 return;
26242602 }
26252603
2626- sprintf( szInString, "%s", pFile->ChooseRandomEntry( szSection ));
2627- if ( stricmp( szInString, "NULL" ) == 0 )
2604+ chatString = pFile->ChooseRandomEntry( szSection );
2605+ if ( chatString.CompareNoCase( "NULL" ) == 0 )
26282606 {
26292607 Printf( "botcmd_SayFromLump: Couldn't find section %s in lump %s!\n", szSection, szLumpname );
26302608
@@ -2636,15 +2614,15 @@
26362614 if ( bot_allowchat )
26372615 {
26382616 // Format the message so color codes can appear.
2639- V_ColorizeString( szInString );
2617+ V_ColorizeString( chatString );
26402618
26412619 // Perform any chat string substitutions that need to be done.
2642- BOTCMD_DoChatStringSubstitutions( pBot, szInString, szOutString );
2620+ BOTCMD_DoChatStringSubstitutions( pBot, chatString );
26432621
26442622 if ( NETWORK_GetState( ) == NETSTATE_SERVER )
2645- SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString );
2623+ SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString );
26462624 else
2647- CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString );
2625+ CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString );
26482626 }
26492627
26502628 // Free the file before leaving.
@@ -2657,8 +2635,7 @@
26572635 {
26582636 char szLumpname[1024];
26592637 char szSection[1024];
2660- char szInString[1024];
2661- char szOutString[1024];
2638+ FString chatString;
26622639 CChatFile *pFile;
26632640
26642641 // We can now get rid of the chat bubble above the bot's head.
@@ -2681,8 +2658,8 @@
26812658 return;
26822659 }
26832660
2684- sprintf( szInString, "%s", pFile->ChooseRandomEntry( szSection ));
2685- if ( stricmp( szInString, "NULL" ) == 0 )
2661+ chatString = pFile->ChooseRandomEntry( szSection );
2662+ if ( chatString.CompareNoCase( "NULL" ) == 0 )
26862663 {
26872664 Printf( "botcmd_SayFromChatLump: Couldn't find section %s in lump %s!\n", szSection, szLumpname );
26882665
@@ -2694,15 +2671,15 @@
26942671 if ( bot_allowchat )
26952672 {
26962673 // Format the message so color codes can appear.
2697- V_ColorizeString( szInString );
2674+ V_ColorizeString( chatString );
26982675
26992676 // Perform any chat string substitutions that need to be done.
2700- BOTCMD_DoChatStringSubstitutions( pBot, szInString, szOutString );
2677+ BOTCMD_DoChatStringSubstitutions( pBot, chatString );
27012678
27022679 if ( NETWORK_GetState( ) == NETSTATE_SERVER )
2703- SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString );
2680+ SERVER_SendChatMessage( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString );
27042681 else
2705- CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, szOutString );
2682+ CHAT_PrintChatString( pBot->GetPlayer( ) - players, CHATMODE_GLOBAL, chatString );
27062683 }
27072684
27082685 // Free the file before leaving.
diff -r 54bfc2d7cccb -r 9266146f3441 src/botcommands.h
--- a/src/botcommands.h Tue Feb 01 09:35:13 2022 -0500
+++ b/src/botcommands.h Fri Feb 04 09:32:48 2022 -0500
@@ -263,7 +263,7 @@
263263 void BOTCMD_SetLastChatString( const char *pszString );
264264 void BOTCMD_SetLastChatPlayer( const char *pszString );
265265 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 );
267267 bool BOTCMD_IgnoreItem( CSkullBot *pBot, LONG lIdx, bool bVisibilityCheck );
268268
269269 #endif // __BOTCOMMANDS_H__