purchaseresponseevent.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. ** Command & Conquer Renegade(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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/purchaseresponseevent.cpp $*
  25. * *
  26. * $Author:: Tom_s $*
  27. * *
  28. * $Modtime:: 12/20/01 2:57p $*
  29. * *
  30. * $Revision:: 10 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "purchaseresponseevent.h"
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include "networkobjectfactory.h"
  39. #include "gamemode.h"
  40. #include "cnetwork.h"
  41. #include "consolefunction.h"
  42. #include "vendor.h"
  43. #include "translatedb.h"
  44. #include "string_ids.h"
  45. #include "textdisplay.h"
  46. #include "apppackettypes.h"
  47. #include "messagewindow.h"
  48. #include "wwaudio.h"
  49. DECLARE_NETWORKOBJECT_FACTORY(cPurchaseResponseEvent, NETCLASSID_PURCHASERESPONSEEVENT);
  50. //-----------------------------------------------------------------------------
  51. cPurchaseResponseEvent::cPurchaseResponseEvent(void)
  52. {
  53. PurchaserId = -1;
  54. ResponseId = -1;
  55. Set_App_Packet_Type(APPPACKETTYPE_PURCHASERESPONSEEVENT);
  56. }
  57. //-----------------------------------------------------------------------------
  58. void
  59. cPurchaseResponseEvent::Init(int response_id, int client_id)
  60. {
  61. WWASSERT(cNetwork::I_Am_Server());
  62. PurchaserId = client_id;
  63. ResponseId = response_id;
  64. if (cNetwork::I_Am_Client() && PurchaserId == cNetwork::Get_My_Id())
  65. {
  66. Act();
  67. }
  68. else
  69. {
  70. Set_Object_Dirty_Bit(client_id, BIT_CREATION, true);
  71. }
  72. }
  73. //-----------------------------------------------------------------------------
  74. void
  75. cPurchaseResponseEvent::Act(void)
  76. {
  77. if (!GameModeManager::Find("Combat")->Is_Active()) {
  78. return;
  79. }
  80. WWASSERT(cNetwork::I_Am_Client());
  81. /*
  82. if (PurchaserId != cNetwork::Get_My_Id()) {
  83. return;
  84. }
  85. */
  86. WWASSERT(PurchaserId == cNetwork::Get_My_Id());
  87. WideStringClass wide_string;
  88. if ( ResponseId == VendorClass::PERR_SUCCESS ) {
  89. wide_string.Format( L"%s\n", TRANSLATION(IDS_MP_CNC_PURCHASE_GRANTED) );
  90. //
  91. // Play a custom SFX for feedback
  92. //
  93. WWASSERT(WWAudioClass::Get_Instance() != NULL);
  94. WWAudioClass::Get_Instance()->Create_Instant_Sound("Purchase_Granted", Matrix3D(1));
  95. } else if ( ResponseId == VendorClass::PERR_NO_FUNDS ) {
  96. wide_string.Format( L"%s\n", TRANSLATION(IDS_MP_CNC_INSUFFICIENT_FUNDS) );
  97. } else if ( ResponseId == VendorClass::PERR_NO_FACTORY ) {
  98. wide_string.Format( L"%s\n", TRANSLATION(IDS_MP_CNC_FACTORY_UNAVAILABLE) );
  99. } else if ( ResponseId == VendorClass::PERR_OPERATION_PENDING ) {
  100. wide_string.Format( L"%s\n", TRANSLATION(IDS_MP_CNC_TRANSACTION_PENDING) );
  101. } else if ( ResponseId == VendorClass::PERR_NOT_IN_STOCK ) {
  102. wide_string.Format( L"%s\n", TRANSLATION(IDS_MP_CNC_NOT_IN_STOCK) );
  103. }
  104. //
  105. // Display the message...
  106. //
  107. CombatManager::Get_Message_Window ()->Add_Message (wide_string, Vector3 (0.7F, 0.7F, 0.7F));
  108. Set_Delete_Pending();
  109. }
  110. //-----------------------------------------------------------------------------
  111. void
  112. cPurchaseResponseEvent::Export_Creation(BitStreamClass & packet)
  113. {
  114. WWASSERT(cNetwork::I_Am_Server());
  115. cNetEvent::Export_Creation(packet);
  116. packet.Add(PurchaserId);
  117. packet.Add(ResponseId);
  118. Set_Delete_Pending();
  119. }
  120. //-----------------------------------------------------------------------------
  121. void
  122. cPurchaseResponseEvent::Import_Creation(BitStreamClass & packet)
  123. {
  124. WWASSERT(cNetwork::I_Am_Only_Client());
  125. cNetEvent::Import_Creation(packet);
  126. packet.Get(PurchaserId);
  127. packet.Get(ResponseId);
  128. Act();
  129. }