Toolkit_Animations.cpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. * Toolkit_Animations.cpp
  22. *
  23. * DESCRIPTION
  24. * Designer Toolkit for Mission Construction - Animations Subset
  25. *
  26. * PROGRAMMER
  27. * Design Team
  28. *
  29. * VERSION INFO
  30. * $Author: Ryan_v $
  31. * $Revision: 4 $
  32. * $Modtime: 10/06/00 4:18p $
  33. * $Archive: /Commando/Code/Scripts/Toolkit_Animations.cpp $
  34. *
  35. ******************************************************************************/
  36. #include "toolkit.h"
  37. /*
  38. Function - M00_Controller_Animation_RMV
  39. This function handles any animation calls.
  40. Parameters:
  41. GameObject * obj = The object the animation is being called upon.
  42. GameObjObserverClass * script = this
  43. const char * animation_name = The name of the animation.
  44. bool loop = Whether the animation should loop or not.
  45. int priority = The Action Priority of this animation.
  46. int action_id = The Action ID.
  47. int drop_frame = The frame at which an item should be dropped.
  48. const char * drop_object = The object to be dropped.
  49. const char * drop_bone = The bone from which the object is dropped.
  50. */
  51. void M00_Controller_Animation_RMV (GameObject * obj, GameObjObserverClass * script, const char * animation_name, bool loop, int priority, int action_id, int drop_frame, const char * drop_object, const char * drop_bone)
  52. {
  53. ActionParamsStruct params;
  54. params.Set_Basic(script, priority, action_id);
  55. params.Set_Animation(animation_name, loop);
  56. Commands->Action_Play_Animation(obj, params);
  57. if (drop_frame != 0)
  58. {
  59. if (drop_object != NULL)
  60. {
  61. if (drop_bone != NULL)
  62. {
  63. Commands->Send_Custom_Event(obj, obj, M00_CUSTOM_ANIMATION_DROP_OBJECT, 0, drop_frame/30);
  64. }
  65. }
  66. }
  67. }
  68. /*
  69. Editor Script - M00_Animation_Play_On_Activation_RMV
  70. This script plays an animation when the object it is attached to receives a custom.
  71. Parameters:
  72. Animation = The animation to play.
  73. Loop = Whether the animation should loop or not. 1 for looping. 0 for not.
  74. */
  75. DECLARE_SCRIPT(M00_Animation_Play_RMV, "Start_Now=0:int, Receive_Type:int, Receive_Param_On=1:int, Receive_Param_Off=0:int, Action_Priority:int, Action_ID:int, Animation:string, Loop=0:int, Debug_Mode=0:int")
  76. {
  77. int priority, action_id;
  78. bool debug_mode;
  79. void Created(GameObject * obj)
  80. {
  81. priority = Get_Int_Parameter("Action_Priority");
  82. action_id = Get_Int_Parameter("Action_ID");
  83. debug_mode = (Get_Int_Parameter("Debug_Mode") == 1) ? true : false;
  84. if (Get_Int_Parameter("Start_Now"))
  85. {
  86. SCRIPT_DEBUG_MESSAGE(("M00_Animation_Play_RMV ACTIVATED.\n"));
  87. Do_Animation(obj);
  88. }
  89. }
  90. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  91. {
  92. SCRIPT_DEBUG_MESSAGE(("M00_Animation_Play_RMV received custom type %d, param %d.\n", type, param));
  93. if (type == Get_Int_Parameter("Receive_Type"))
  94. {
  95. if (param == Get_Int_Parameter("Receive_Param_On"))
  96. {
  97. SCRIPT_DEBUG_MESSAGE(("M00_Animation_Play_RMV ACTIVATED.\n"));
  98. Do_Animation(obj);
  99. }
  100. if (param == Get_Int_Parameter("Receive_Param_Off"))
  101. {
  102. Commands->Action_Reset(obj, (priority + 1));
  103. SCRIPT_DEBUG_MESSAGE(("M00_Animation_Play_RMV DEACTIVATED.\n"));
  104. }
  105. }
  106. }
  107. void Do_Animation(GameObject* obj)
  108. {
  109. const char *anim = Get_Parameter("Animation");
  110. int loop_int = Get_Int_Parameter("Loop");
  111. bool loop = (loop_int == 1) ? true : false;
  112. M00_Controller_Animation_RMV (obj, this, anim, loop, priority, action_id, 0, 0, 0);
  113. }
  114. };
  115. /*
  116. Editor Script - M00_Animation_Play_Drop_Object_RMV
  117. This script plays an animation when the object it is attached to receives a custom.
  118. Parameters:
  119. Animation = The animation to play.
  120. Drop_Frame = The frame at which an object should drop.
  121. Drop_Object = The object to drop.
  122. Drop_Bone = The bone from which to drop the object.
  123. */
  124. DECLARE_SCRIPT(M00_Animation_Play_Drop_Object_RMV, "Start_Now=0:int, Receive_Type:int, Receive_Param_On=1:int, Receive_Param_Off=1:int, Action_Priority:int, Action_ID:int, Animation:string, Drop_Frame:int, Drop_Object:string, Drop_Bone:string, Debug_Mode=0:int")
  125. {
  126. int priority, action_id;
  127. bool debug_mode;
  128. void Created(GameObject * obj)
  129. {
  130. priority = Get_Int_Parameter("Action_Priority");
  131. action_id = Get_Int_Parameter("Action_ID");
  132. debug_mode = (Get_Int_Parameter("Debug_Mode") == 1) ? true : false;
  133. if (Get_Int_Parameter("Start_Now"))
  134. {
  135. SCRIPT_DEBUG_MESSAGE(("M00_Animation_Play_Drop_Object_RMV ACTIVATED.\n"));
  136. const char *anim = Get_Parameter("Animation");
  137. int frame = Get_Int_Parameter("Drop_Frame");
  138. const char *object = Get_Parameter("Drop_Object");
  139. const char *bone = Get_Parameter("Drop_Bone");
  140. M00_Controller_Animation_RMV (obj, this, anim, 0, priority, action_id, frame, object, bone);
  141. }
  142. }
  143. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  144. {
  145. const char *anim = Get_Parameter("Animation");
  146. int frame = Get_Int_Parameter("Drop_Frame");
  147. const char *object = Get_Parameter("Drop_Object");
  148. const char *bone = Get_Parameter("Drop_Bone");
  149. SCRIPT_DEBUG_MESSAGE(("M00_Animation_Play_Drop_Object_RMV received custom type %d, param %d.\n", type, param));
  150. if (type == Get_Int_Parameter("Receive_Type"))
  151. {
  152. if (param == Get_Int_Parameter("Receive_Param_On"))
  153. {
  154. SCRIPT_DEBUG_MESSAGE(("M00_Animation_Play_Drop_Object_RMV ACTIVATED.\n"));
  155. M00_Controller_Animation_RMV (obj, this, anim, 0, priority, action_id, frame, object, bone);
  156. }
  157. if (param == Get_Int_Parameter("Receive_Param_Off"))
  158. {
  159. Commands->Action_Reset(obj, (priority + 1));
  160. SCRIPT_DEBUG_MESSAGE(("M00_Animation_Play_Drop_Object_RMV DEACTIVATED.\n"));
  161. }
  162. }
  163. if ((type == M00_CUSTOM_ANIMATION_DROP_OBJECT) && (param == 0))
  164. {
  165. Commands->Create_Object_At_Bone(obj, object, bone);
  166. SCRIPT_DEBUG_MESSAGE(("Object %s created by M00_Animation_Play_Drop_Object_RMV.\n", object));
  167. }
  168. }
  169. };
  170. /*
  171. Editor Script - M00_Animation_Drop_Object_Attach_Script_RMV
  172. This script plays an animation when the object it is attached to receives a custom, drops
  173. a new object at a specified frame of the animation, and then attaches a script to the
  174. new object.
  175. Parameters:
  176. Animation = The animation to play.
  177. Drop_Frame = The frame at which to drop the object.
  178. Drop_Object = The object to drop.
  179. Drop_Bone = The bone from which the object is dropped.
  180. Script_Name = The name of the script to attach.
  181. Script_Params = The parameters for the attached script.
  182. */
  183. DECLARE_SCRIPT(M00_Animation_Play_Drop_Object_Attach_Script_RMV, "Start_Now=0:int, Receive_Type:int, Receive_Param_On=1:int, Receive_Param_Off=0:int, Action_Priority:int, Action_ID:int, Animation:string, Drop_Frame:int, Drop_Object:string, Drop_Bone:string, Script_Name:string, Script_Params:string, Debug_Mode=0:int")
  184. {
  185. int priority, action_id;
  186. bool debug_mode;
  187. void Created(GameObject * obj)
  188. {
  189. priority = Get_Int_Parameter("Action_Priority");
  190. action_id = Get_Int_Parameter("Action_ID");
  191. debug_mode = (Get_Int_Parameter("Debug_Mode") == 1) ? true : false;
  192. if (Get_Int_Parameter("Start_Now"))
  193. {
  194. SCRIPT_DEBUG_MESSAGE(("M00_Animation_Play_Drop_Object_Attach_Script_RMV ACTIVATED.\n"));
  195. const char *anim = Get_Parameter("Animation");
  196. int frame = Get_Int_Parameter("Drop_Frame");
  197. const char *object = Get_Parameter("Drop_Object");
  198. const char *bone = Get_Parameter("Drop_Bone");
  199. M00_Controller_Animation_RMV (obj, this, anim, 0, priority, action_id, frame, object, bone);
  200. }
  201. }
  202. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  203. {
  204. const char *anim = Get_Parameter("Animation");
  205. int frame = Get_Int_Parameter("Drop_Frame");
  206. const char *object = Get_Parameter("Drop_Object");
  207. const char *bone = Get_Parameter("Drop_Bone");
  208. SCRIPT_DEBUG_MESSAGE(("M00_Animation_Play_Drop_Object_Attach_Script_RMV received custom type %d, param %d.\n", type, param));
  209. if (type == Get_Int_Parameter("Receive_Type"))
  210. {
  211. if (param == Get_Int_Parameter("Receive_Param_On"))
  212. {
  213. SCRIPT_DEBUG_MESSAGE(("M00_Animation_Play_Drop_Object_Attach_Script_RMV ACTIVATED.\n"));
  214. M00_Controller_Animation_RMV (obj, this, anim, 0, priority, action_id, frame, object, bone);
  215. }
  216. if (param == Get_Int_Parameter("Receive_Param_Off"))
  217. {
  218. SCRIPT_DEBUG_MESSAGE(("M00_Animation_Play_Drop_Object_Attach_Script_RMV DEACTIVATED.\n"));
  219. Commands->Action_Reset(obj, (priority + 1));
  220. }
  221. }
  222. if ((type == M00_CUSTOM_ANIMATION_DROP_OBJECT) && (param == 0))
  223. {
  224. GameObject *new_object = Commands->Create_Object_At_Bone(obj, object, bone);
  225. SCRIPT_DEBUG_MESSAGE(("Object %s created by M00_Animation_Play_Drop_Object_Attach_Script_RMV.\n", object));
  226. const char *script = Get_Parameter("Script_Name");
  227. const char *params = Get_Parameter("Script_Params");
  228. char fixed_params[255];
  229. Fix_Params(params, fixed_params);
  230. Commands->Attach_Script(new_object, script, fixed_params);
  231. SCRIPT_DEBUG_MESSAGE(("Script %s attached to new object by M00_Animation_Play_Drop_Object_Attach_Script_RMV.", script));
  232. }
  233. }
  234. void Fix_Params(const char *input, char * output)
  235. {
  236. // copy string, converting | to ,
  237. while ( *input != 0 ) {
  238. if ( *input == '|' ) {
  239. *output++ = ',';
  240. input++;
  241. } else {
  242. *output++ = *input++;
  243. }
  244. }
  245. *output = 0; // null terminate
  246. }
  247. };