GroupScript.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. *
  20. * FILE
  21. * GroupScript.cpp
  22. *
  23. * DESCRIPTION
  24. * Group script
  25. *
  26. * PROGRAMMER
  27. * Denzil E. Long, Jr.
  28. *
  29. * VERSION INFO
  30. * $Author: Rich_d $
  31. * $Revision: 2 $
  32. * $Modtime: 6/14/00 12:55p $
  33. * $Archive: /Commando/Code/Scripts/GroupScript.cpp $
  34. *
  35. ******************************************************************************/
  36. #include "scripts.h"
  37. #include "groupcontrol.h"
  38. #include "group.h"
  39. #include "customevents.h"
  40. #include "dprint.h"
  41. DECLARE_SCRIPT(MXX_Group_Member_DEL, "GroupName:string")
  42. {
  43. const char* mGroupName;
  44. // Add the object to the group when it is created.
  45. void Created(GameObject* owner)
  46. {
  47. mGroupName = Get_Parameter("GroupName");
  48. assert(mGroupName != NULL);
  49. GroupController* controller = GroupController::Instance();
  50. assert(controller != NULL);
  51. controller->AddToGroup(mGroupName, owner);
  52. }
  53. // Remove the object from the group when it is destroyed.
  54. void Destroyed(GameObject* owner)
  55. {
  56. GroupController* controller = GroupController::Instance();
  57. assert(controller != NULL);
  58. controller->RemoveFromGroup(mGroupName, owner);
  59. }
  60. // Notify group that a member was killed.
  61. void Killed(GameObject* owner, GameObject* killer)
  62. {
  63. GroupController* controller = GroupController::Instance();
  64. assert(controller != NULL);
  65. GroupEventInfo info;
  66. info.GroupName = mGroupName;
  67. info.Event = GROUP_MEMBER_KILLED;
  68. info.Object = killer;
  69. Group* group = controller->FindGroup(mGroupName);
  70. assert(group != NULL);
  71. group->SendCustomEvent(owner, SCMD_GROUP_EVENT, (int)&info);
  72. }
  73. // Notify group that a member was damaged.
  74. void Damaged(GameObject* owner, GameObject* damager)
  75. {
  76. GroupController* controller = GroupController::Instance();
  77. assert(controller != NULL);
  78. GroupEventInfo info;
  79. info.GroupName = mGroupName;
  80. info.Event = GROUP_MEMBER_DAMAGED;
  81. info.Object = damager;
  82. Group* group = controller->FindGroup(mGroupName);
  83. assert(group != NULL);
  84. group->SendCustomEvent(owner, SCMD_GROUP_EVENT, (int)&info);
  85. }
  86. // Notify group that a member heard a sound.
  87. void Sound_Heard(GameObject* owner, const CombatSound& sound)
  88. {
  89. GroupController* controller = GroupController::Instance();
  90. assert(controller != NULL);
  91. GroupEventInfo info;
  92. info.GroupName = mGroupName;
  93. info.Event = GROUP_MEMBER_HEARD;
  94. info.Sound = &sound;
  95. Group* group = controller->FindGroup(mGroupName);
  96. assert(group != NULL);
  97. group->SendCustomEvent(owner, SCMD_GROUP_EVENT, (int)&info);
  98. }
  99. // Notify group that a member saw the enemy.
  100. void Enemy_Seen(GameObject* owner, GameObject* enemy)
  101. {
  102. GroupController* controller = GroupController::Instance();
  103. assert(controller != NULL);
  104. GroupEventInfo info;
  105. info.GroupName = mGroupName;
  106. info.Event = GROUP_MEMBER_SAW;
  107. info.Object = enemy;
  108. Group* group = controller->FindGroup(mGroupName);
  109. assert(group != NULL);
  110. group->SendCustomEvent(owner, SCMD_GROUP_EVENT, (int)&info);
  111. }
  112. #ifdef _DEBUG
  113. void Custom(GameObject* owner, int event, int data, GameObject* sender)
  114. {
  115. if (SCMD_GROUP_EVENT == event)
  116. {
  117. GroupEventInfo* info = (GroupEventInfo*)data;
  118. assert(info != NULL);
  119. int senderID = Commands->Get_ID(sender);
  120. int objectID = Commands->Get_ID(info->Object);
  121. switch (info->Event)
  122. {
  123. case GROUP_MEMBER_DAMAGED:
  124. DebugPrint("Group %s member %d damaged by object %d\n",
  125. info->GroupName, senderID, objectID);
  126. break;
  127. case GROUP_MEMBER_KILLED:
  128. DebugPrint("Group %s member %d killed by object %d\n",
  129. info->GroupName, senderID, objectID);
  130. break;
  131. case GROUP_MEMBER_HEARD:
  132. {
  133. const CombatSound* sound = info->Sound;
  134. objectID = Commands->Get_ID(sound->Creator);
  135. DebugPrint("Group %s member %d heard a sound from object %d\n",
  136. info->GroupName, senderID, objectID);
  137. }
  138. break;
  139. case GROUP_MEMBER_SAW:
  140. DebugPrint("Group %s member %d saw object %d\n",
  141. info->GroupName, senderID, objectID);
  142. break;
  143. default:
  144. break;
  145. }
  146. }
  147. }
  148. #endif
  149. };