MultiplayerSettings.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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: MultiplayerSettings.cpp ///////////////////////////////////////////////////////////////////////////
  24. // The MultiplayerSettings object
  25. // Author: Matthew D. Campbell, January 2002
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #define DEFINE_TERRAIN_LOD_NAMES
  30. #define DEFINE_TIME_OF_DAY_NAMES
  31. #include "Common/MultiplayerSettings.h"
  32. #include "Common/INI.h"
  33. #include "GameNetwork/GameInfo.h" // for PLAYERTEMPLATE_*
  34. // PUBLIC DATA ////////////////////////////////////////////////////////////////////////////////////
  35. MultiplayerSettings *TheMultiplayerSettings = NULL; ///< The MultiplayerSettings singleton
  36. ///////////////////////////////////////////////////////////////////////////////////////////////////
  37. // PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
  38. ///////////////////////////////////////////////////////////////////////////////////////////////////
  39. const FieldParse MultiplayerColorDefinition::m_colorFieldParseTable[] =
  40. {
  41. { "TooltipName", INI::parseAsciiString, NULL, offsetof( MultiplayerColorDefinition, m_tooltipName ) },
  42. { "RGBColor", INI::parseRGBColor, NULL, offsetof( MultiplayerColorDefinition, m_rgbValue ) },
  43. { "RGBNightColor", INI::parseRGBColor, NULL, offsetof( MultiplayerColorDefinition, m_rgbValueNight ) },
  44. { NULL, NULL, NULL, 0 } // keep this last
  45. };
  46. const FieldParse MultiplayerSettings::m_multiplayerSettingsFieldParseTable[] =
  47. {
  48. { "StartCountdownTimer", INI::parseInt, NULL, offsetof( MultiplayerSettings, m_startCountdownTimerSeconds ) },
  49. { "MaxBeaconsPerPlayer", INI::parseInt, NULL, offsetof( MultiplayerSettings, m_maxBeaconsPerPlayer ) },
  50. { "UseShroud", INI::parseBool, NULL, offsetof( MultiplayerSettings, m_isShroudInMultiplayer ) },
  51. { "ShowRandomPlayerTemplate", INI::parseBool, NULL, offsetof( MultiplayerSettings, m_showRandomPlayerTemplate ) },
  52. { "ShowRandomStartPos", INI::parseBool, NULL, offsetof( MultiplayerSettings, m_showRandomStartPos ) },
  53. { "ShowRandomColor", INI::parseBool, NULL, offsetof( MultiplayerSettings, m_showRandomColor ) },
  54. { NULL, NULL, NULL, 0 } // keep this last
  55. };
  56. //-------------------------------------------------------------------------------------------------
  57. //-------------------------------------------------------------------------------------------------
  58. MultiplayerSettings::MultiplayerSettings()
  59. {
  60. m_maxBeaconsPerPlayer = 3;
  61. //
  62. m_startCountdownTimerSeconds = 0;
  63. m_numColors = 0;
  64. m_isShroudInMultiplayer = TRUE;
  65. m_showRandomPlayerTemplate = TRUE;
  66. m_showRandomStartPos = TRUE;
  67. m_showRandomColor = TRUE;
  68. m_observerColor;
  69. m_randomColor;
  70. m_gotDefaultStartingMoney = false;
  71. } // end MultiplayerSettings
  72. MultiplayerColorDefinition::MultiplayerColorDefinition()
  73. {
  74. m_tooltipName.clear();
  75. m_rgbValue.setFromInt(0xFFFFFFFF);
  76. m_rgbValueNight=m_rgbValue;
  77. m_color = 0xFFFFFFFF;
  78. m_colorNight = m_color;
  79. }
  80. MultiplayerColorDefinition * MultiplayerSettings::getColor(Int which)
  81. {
  82. if (which == PLAYERTEMPLATE_RANDOM)
  83. {
  84. return &m_randomColor;
  85. }
  86. else if (which == PLAYERTEMPLATE_OBSERVER)
  87. {
  88. return &m_observerColor;
  89. }
  90. else if (which < 0 || which >= getNumColors())
  91. {
  92. return NULL;
  93. }
  94. return &m_colorList[which];
  95. }
  96. MultiplayerColorDefinition * MultiplayerSettings::findMultiplayerColorDefinitionByName(AsciiString name)
  97. {
  98. MultiplayerColorIter iter = m_colorList.begin();
  99. while (iter != m_colorList.end())
  100. {
  101. if (iter->second.getTooltipName() == name)
  102. return &(iter->second);
  103. ++iter;
  104. }
  105. return NULL;
  106. }
  107. MultiplayerColorDefinition * MultiplayerSettings::newMultiplayerColorDefinition(AsciiString name)
  108. {
  109. MultiplayerColorDefinition tmp;
  110. Int numColors = getNumColors();
  111. m_colorList[numColors] = tmp;
  112. m_numColors = m_colorList.size();
  113. return &m_colorList[numColors];
  114. }
  115. void MultiplayerSettings::addStartingMoneyChoice( const Money & money, Bool isDefault )
  116. {
  117. m_startingMoneyList.push_back( money );
  118. if ( isDefault )
  119. {
  120. DEBUG_ASSERTCRASH( !m_gotDefaultStartingMoney, ("Cannot have more than one default MultiplayerStartingMoneyChoice") );
  121. m_defaultStartingMoney = money;
  122. m_gotDefaultStartingMoney = true;
  123. }
  124. }
  125. MultiplayerColorDefinition * MultiplayerColorDefinition::operator =(const MultiplayerColorDefinition& other)
  126. {
  127. m_tooltipName = other.getTooltipName();
  128. m_rgbValue = other.getRGBValue();
  129. m_color = other.getColor();
  130. m_rgbValueNight = other.getRGBNightValue();
  131. m_colorNight = other.getNightColor();
  132. return this;
  133. }
  134. void MultiplayerColorDefinition::setColor( RGBColor rgb )
  135. {
  136. m_color = rgb.getAsInt() | 0xFF << 24;
  137. }
  138. void MultiplayerColorDefinition::setNightColor( RGBColor rgb )
  139. {
  140. m_colorNight = rgb.getAsInt() | 0xFF << 24;
  141. }