Science.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: Science.h ////////////////////////////////////////////////////////////////////////////////
  24. // Author: Steven Johnson, Colin Day November 2001
  25. // Desc: Science descriptoins
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __SCIENCE_H_
  29. #define __SCIENCE_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "Common/Overridable.h"
  32. #include "Common/NameKeyGenerator.h"
  33. #include "Common/UnicodeString.h"
  34. class Player;
  35. //-------------------------------------------------------------------------------------------------
  36. enum ScienceType
  37. {
  38. SCIENCE_INVALID = -1
  39. };
  40. //-------------------------------------------------------------------------------------------------
  41. typedef std::vector<ScienceType> ScienceVec;
  42. //-------------------------------------------------------------------------------------------------
  43. class ScienceInfo : public Overridable
  44. {
  45. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( ScienceInfo, "ScienceInfo" )
  46. friend class ScienceStore;
  47. private:
  48. ScienceType m_science;
  49. UnicodeString m_name;
  50. UnicodeString m_description;
  51. ScienceVec m_rootSciences; // this is calced at runtime, NOT read from INI
  52. ScienceVec m_prereqSciences;
  53. Int m_sciencePurchasePointCost;
  54. Bool m_grantable;
  55. ScienceInfo() :
  56. m_science(SCIENCE_INVALID),
  57. m_sciencePurchasePointCost(0), // 0 means "cannot be purchased"
  58. m_grantable(true)
  59. {
  60. }
  61. void addRootSciences(ScienceVec& v) const;
  62. };
  63. EMPTY_DTOR(ScienceInfo);
  64. //-------------------------------------------------------------------------------------------------
  65. class ScienceStore : public SubsystemInterface
  66. {
  67. friend class ScienceInfo;
  68. public:
  69. void init();
  70. void reset();
  71. void update() { }
  72. Bool isValidScience(ScienceType st) const;
  73. Bool isScienceGrantable(ScienceType st) const;
  74. Bool getNameAndDescription(ScienceType st, UnicodeString& name, UnicodeString& description) const;
  75. Bool playerHasPrereqsForScience(const Player* player, ScienceType st) const;
  76. /**
  77. this is a subtle call, and should ALMOST NEVER be called by external code...
  78. this is used to determine if you have the "root" requirements for a given science,
  79. and thus could *potentially* obtain it if you got extra prereqs.
  80. Generally, you should call getPurchasableSciences() instead of this!
  81. */
  82. Bool playerHasRootPrereqsForScience(const Player* player, ScienceType st) const;
  83. Int getSciencePurchaseCost(ScienceType science) const;
  84. ScienceType getScienceFromInternalName(const AsciiString& name) const;
  85. AsciiString getInternalNameForScience(ScienceType science) const;
  86. /** return a list of the sciences the given player can purchase now, and a list he might be able to purchase in the future,
  87. but currently lacks prereqs or points for. (either might be an empty list) */
  88. void getPurchasableSciences(const Player* player, ScienceVec& purchasable, ScienceVec& potentiallyPurchasable) const;
  89. // this is intended ONLY for use by INI::scanScience.
  90. // Don't use it anywhere else. In particular, never, ever, ever
  91. // call this with a hardcoded science name. (srj)
  92. ScienceType friend_lookupScience(const char* scienceName) const;
  93. static void friend_parseScienceDefinition(INI* ini);
  94. // return a vector of all the currently-known science names
  95. // NOTE: this is really only for use by WorldBuilder! Please
  96. // do not use it in RTS!
  97. std::vector<AsciiString> friend_getScienceNames() const;
  98. private:
  99. const ScienceInfo* findScienceInfo(ScienceType st) const;
  100. typedef std::vector<ScienceInfo*> ScienceInfoVec;
  101. ScienceInfoVec m_sciences;
  102. };
  103. extern ScienceStore* TheScienceStore;
  104. #endif // __SCIENCE_H_