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.

79 lines
2.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implementation of CCustomAwardList
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //------------------------------------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #include "CustomAwardList.h"
  14. #include "memdbg.h"
  15. //------------------------------------------------------------------------------------------------------
  16. // Function: CCustomAwardList::readCustomAwards
  17. // Purpose: Factory method to read from a file and return a list of custom awards
  18. // Input: mapname - the name of the map determines the rule file to read the awards from
  19. // pmi - a pointer to the Match Info which will be passed to each custom award
  20. // Output: CCustomAwardList*
  21. //------------------------------------------------------------------------------------------------------
  22. CCustomAwardList* CCustomAwardList::readCustomAwards(string mapname)
  23. {
  24. char filename[255];
  25. g_pApp->os->chdir(g_pApp->ruleDirectory.c_str());
  26. sprintf(filename,"tfc.%s.rul",mapname.c_str());
  27. CTextFile ctf1(filename);
  28. CTextFile ctf2("tfc.rul");
  29. if (!ctf1.isValid() && ctf2.isValid())
  30. {
  31. if (stricmp(filename,"tfc..rul")==0)
  32. g_pApp->warning("Could not find mapname in the log file, map-specific custom rules will not be used");
  33. else
  34. g_pApp->warning("Could not find %s, map-specific custom rules will not be used",filename);
  35. }
  36. if (!ctf2.isValid() && ctf1.isValid())
  37. {
  38. g_pApp->warning("tfc.rul could not be found. Only map-specific rules will be used");
  39. }
  40. if (!ctf2.isValid() && !ctf1.isValid())
  41. {
  42. g_pApp->warning("Neither tfc.rul nor %s could be found. No custom rules will be used");
  43. return NULL;
  44. }
  45. CCustomAwardList* newList=new TRACKED CCustomAwardList;
  46. bool foundAward=false;
  47. CCustomAward* pcca=CCustomAward::readCustomAward(ctf1);
  48. while (pcca)
  49. {
  50. foundAward=true;
  51. newList->theList.push_back(pcca);
  52. pcca=CCustomAward::readCustomAward(ctf1);
  53. }
  54. pcca=CCustomAward::readCustomAward(ctf2);
  55. while (pcca)
  56. {
  57. foundAward=true;
  58. newList->theList.push_back(pcca);
  59. pcca=CCustomAward::readCustomAward(ctf2);
  60. }
  61. if (!foundAward)
  62. {
  63. delete newList;
  64. g_pApp->warning("Could not find any custom rules in either tfc.rul or %s. No custom rules will be used.\n",filename);
  65. newList=NULL;
  66. }
  67. return newList;
  68. }