Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef TF_AUTORP_H
  7. #define TF_AUTORP_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "igamesystem.h"
  12. #include "utlvector.h"
  13. #include "utlmap.h"
  14. enum matchresult_t
  15. {
  16. MATCHES_NOT,
  17. MATCHES_SINGULAR,
  18. MATCHES_PLURAL,
  19. };
  20. //-----------------------------------------------------------------------------
  21. // Purpose:
  22. //-----------------------------------------------------------------------------
  23. class CTFAutoRP : public CAutoGameSystem
  24. {
  25. public:
  26. CTFAutoRP() : CAutoGameSystem( "CTFAutoRP" )
  27. {
  28. m_pDataFileKV = NULL;
  29. m_pWordTable = new CUtlSymbolTable( 0, 32, true );
  30. }
  31. void ParseDataFile( void );
  32. void ApplyRPTo( char *pBuf, int iBufSize );
  33. private:
  34. struct wordreplacement_t
  35. {
  36. int iChance;
  37. int iPrePendCount;
  38. CUtlVector<const char*> a_pszPrepended; // Words that prepend the replacement
  39. CUtlVector<const char*> a_pszReplacements; // Words that replace the original word
  40. CUtlVector<const char*> a_pszPluralReplacements; // If the match was a plural match, use these replacements instead, if they exist. Otherwise, use a_pszReplacements.
  41. CUtlVector<CUtlSymbol> m_Words; // Word that matches this replacement
  42. CUtlVector<CUtlSymbol> m_Plurals; // Word that must come before to match this replacement, for double word replacements (i.e. "it is" -> "'tis")
  43. CUtlVector<CUtlSymbol> m_PrevWords; // Word that must come before to match this replacement, for double word replacements (i.e. "it is" -> "'tis")
  44. };
  45. struct replacementcheck_t
  46. {
  47. char szWord[128];
  48. int iWordLen;
  49. char szPrevWord[128];
  50. int iPrevLen;
  51. bool bUsedPrevWord;
  52. };
  53. private:
  54. const char *GetRandomPre( void );
  55. const char *GetRandomPost( void );
  56. void ModifySpeech( const char *pszInText, char *pszOutText, int iOutLen, bool bGeneratePreAndPost, bool bInPrePost );
  57. matchresult_t WordMatches( wordreplacement_t *pRep, replacementcheck_t *pCheck );
  58. bool ReplaceWord( replacementcheck_t *pCheck, char *szRep, int iRepSize, bool bSymbols, bool bWordListOnly );
  59. bool PerformReplacement( const char *pszReplacement, replacementcheck_t *pRepCheck, char *szStoredWord, int iStoredWordSize, char *pszOutText, int iOutLen );
  60. private:
  61. // Database
  62. KeyValues *m_pDataFileKV;
  63. // Storage of all replacement blocks
  64. CUtlVector<wordreplacement_t> m_a_Replacements;
  65. CUtlSymbolTable *m_pWordTable;
  66. // Extra lists for random selection
  67. CUtlVector<const char*> m_a_pszPrependedWords;
  68. CUtlVector<const char*> m_a_pszAppendedWords;
  69. // Current application
  70. CUtlVector<const char*> *m_pszCurrentList;
  71. int m_iCurrentReplacement;
  72. };
  73. extern CTFAutoRP *AutoRP( void );
  74. #endif // TF_AUTORP_H