Toolkit_Actions.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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_Actions.cpp
  22. *
  23. * DESCRIPTION
  24. * Designer Toolkit for Mission Construction - Actions Subset
  25. *
  26. * PROGRAMMER
  27. * Design Team
  28. *
  29. * VERSION INFO
  30. * $Author: Ryan_v $
  31. * $Revision: 10 $
  32. * $Modtime: 11/03/00 2:25p $
  33. * $Archive: /Commando/Code/Scripts/Toolkit_Actions.cpp $
  34. *
  35. ******************************************************************************/
  36. #include "toolkit.h"
  37. /*Editor Script - M00_Action
  38. Animations are not handled with this script - they are handled separately.
  39. Parameters:
  40. _Move_Target_ID = The Target ID to move towards.
  41. _Move_Following = Whether this unit should follow the Target ID or not.
  42. _Move_Destination = The Vector3 location of the movement destination.
  43. _Move_Waypath_ID = The ID of a waypath to follow.
  44. _Move_Waypath_Start_ID = The starting point to use on the waypath.
  45. _Move_Waypath_End_ID = The ending point to use on the waypath.
  46. _Move_Waypath_Splined = Whether to use splined movement or not on waypaths.
  47. _Move_Waypath_Looping = If the unit should circle on the waypath.
  48. _Move_Patrol_Radius = A radius to use if patrolling an area.
  49. _Move_Patrol_Loiter_Time = How long to wait at each point until patrolling again.
  50. _Move_Arrive_Distance = The distance to close to with the destination.
  51. _Move_Speed = The speed at which the unit moves.
  52. _Move_Crouch = Whether to move crouched or not.
  53. _Move_Backwards = Whether to move backwards or not.
  54. _Move_Pathfind = Whether to use pathfinding data for movement or not.
  55. _Attack_Target_ID = The attack target's ID.
  56. _Attack_Location = The location of the attack (if no target).
  57. _Attack_Range = The maximum effective range of the attack.
  58. _Attack_Deviation = The deviation of the attack.
  59. _Attack_Primary = Whether to use the primary weapon or not.
  60. _Attack_Crouched = Whether to crouch when firing or not.
  61. */
  62. DECLARE_SCRIPT(M00_Action, "Start_Now=0:int, Receive_Type=14:int, Receive_Param_On=1:int, Receive_Param_Off=0:int, Action_Priority=99:int, Action_ID=0:int, _Move_Target_ID=0:int, _Move_Following=0:int, _Move_Destination:vector3, _Move_Waypath_ID=0:int, _Move_Waypath_Start_ID=0:int, _Move_Waypath_End_ID:int, _Move_Waypath_Splined=0:int, _Move_Arrive_Distance=1.0:float, _Move_Speed=1.0:float, _Move_Crouch=0:int, _Move_Backwards=0:int, _Move_Pathfind=1:int, _Attack_Target_ID=0:int, _Attack_Location:vector3, _Attack_Range=100.0:float, _Attack_Deviation=0.0:float, _Attack_Primary=1:int, _Attack_Crouched=0:int, Debug_Mode=0:int")
  63. {
  64. bool debug_mode;
  65. bool script_active;
  66. bool attacking;
  67. bool primary_weapon;
  68. Vector3 current_position;
  69. Vector3 current_fire_position;
  70. Vector3 current_attack_location;
  71. Vector3 empty_vector;
  72. void Created(GameObject* obj)
  73. {
  74. ActionParamsStruct params;
  75. script_active = false;
  76. attacking = false;
  77. debug_mode = (Get_Int_Parameter("Debug_Mode") == 1) ? true : false;
  78. GameObject* move_target;
  79. GameObject* attack_target;
  80. move_target = Commands->Find_Object(Get_Int_Parameter("_Move_Target_ID"));
  81. attack_target = Commands->Find_Object(Get_Int_Parameter("_Attack_Target_ID"));
  82. primary_weapon = (Get_Int_Parameter("_Attack_Primary") == 1) ? true : false;
  83. current_attack_location = Get_Vector3_Parameter("_Attack_Location");
  84. empty_vector = Vector3(0.0f,0.0f,0.0f);
  85. params.Set_Basic(this, Get_Int_Parameter("Action_Priority"), Get_Int_Parameter("Action_ID"));
  86. params.Set_Movement(Get_Vector3_Parameter("_Move_Destination"), Get_Float_Parameter("_Move_Speed"), Get_Float_Parameter("_Move_Arrive_Distance"));
  87. params.Set_Attack(Get_Vector3_Parameter("_Attack_Location"), Get_Float_Parameter("_Attack_Range"), Get_Float_Parameter("_Attack_Deviation"), primary_weapon);
  88. params.MoveBackup = (Get_Int_Parameter("_Move_Backwards") == 1) ? true : false;
  89. params.MoveFollow = (Get_Int_Parameter("_Move_Following") == 1) ? true : false;
  90. params.MoveCrouched = (Get_Int_Parameter("_Move_Crouch") == 1) ? true : false;
  91. params.MovePathfind = (Get_Int_Parameter("_Move_Pathfind") == 1) ? true : false;
  92. params.AttackCrouched = (Get_Int_Parameter("_Attack_Crouched") == 1) ? true : false;
  93. params.WaypathID = Get_Int_Parameter("_Move_Waypath_ID");
  94. params.WaypointStartID = Get_Int_Parameter("_Move_Waypath_Start_ID");
  95. params.WaypointEndID = Get_Int_Parameter("_Move_Waypath_End_ID");
  96. params.WaypathSplined = (Get_Int_Parameter("_Move_Waypath_Splined") == 1) ? true : false;
  97. if (attack_target)
  98. {
  99. // Attacking a target, override the attack location values
  100. params.Set_Attack(attack_target, Get_Float_Parameter("_Attack_Range"), Get_Float_Parameter("_Attack_Deviation"), primary_weapon);
  101. attacking = true;
  102. }
  103. if (current_attack_location != empty_vector)
  104. {
  105. // Attacking a location, be sure to turn on attacking bool
  106. attacking = true;
  107. }
  108. if (move_target)
  109. {
  110. // Moving toward a target, override other movement values
  111. params.Set_Movement(move_target, Get_Float_Parameter("_Move_Speed"), Get_Float_Parameter("_Move_Arrive_Distance"));
  112. params.WaypathID = 0;
  113. params.WaypointStartID = 0;
  114. params.WaypointEndID = 0;
  115. params.WaypathSplined = false;
  116. }
  117. if (params.MoveLocation != empty_vector)
  118. {
  119. // Moving to a location, override other movement values
  120. params.WaypathID = 0;
  121. params.WaypointStartID = 0;
  122. params.WaypointEndID = 0;
  123. params.WaypathSplined = false;
  124. }
  125. if (Get_Int_Parameter("Start_Now"))
  126. {
  127. SCRIPT_DEBUG_MESSAGE(("M00_Action ACTIVATED.\n"));
  128. script_active = true;
  129. if (script_active)
  130. {
  131. // Check if we are firing and moving, or just moving.
  132. if (attacking)
  133. {
  134. SCRIPT_DEBUG_MESSAGE(("M00_Action is moving and attacking.\n"));
  135. Commands->Action_Attack(obj, params);
  136. }
  137. else
  138. {
  139. SCRIPT_DEBUG_MESSAGE(("M00_Action is moving only - no attack.\n"));
  140. Commands->Action_Goto(obj, params);
  141. }
  142. }
  143. }
  144. }
  145. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  146. {
  147. SCRIPT_DEBUG_MESSAGE(("M00_Action received custom type %d, param %d.\n", type, param));
  148. if (type == Get_Int_Parameter("Receive_Type"))
  149. {
  150. if (param == Get_Int_Parameter("Receive_Param_On"))
  151. {
  152. GameObject* move_target;
  153. GameObject* attack_target;
  154. move_target = Commands->Find_Object(Get_Int_Parameter("_Move_Target_ID"));
  155. attack_target = Commands->Find_Object(Get_Int_Parameter("_Attack_Target_ID"));
  156. ActionParamsStruct params;
  157. params.Set_Basic(this, Get_Int_Parameter("Action_Priority"), Get_Int_Parameter("Action_ID"));
  158. params.Set_Movement(Get_Vector3_Parameter("_Move_Destination"), Get_Float_Parameter("_Move_Speed"), Get_Float_Parameter("_Move_Arrive_Distance"));
  159. params.Set_Attack(Get_Vector3_Parameter("_Attack_Location"), Get_Float_Parameter("_Attack_Range"), Get_Float_Parameter("_Attack_Deviation"), primary_weapon);
  160. params.MoveBackup = (Get_Int_Parameter("_Move_Backwards") == 1) ? true : false;
  161. params.MoveFollow = (Get_Int_Parameter("_Move_Following") == 1) ? true : false;
  162. params.MoveCrouched = (Get_Int_Parameter("_Move_Crouch") == 1) ? true : false;
  163. params.MovePathfind = (Get_Int_Parameter("_Move_Pathfind") == 1) ? true : false;
  164. params.AttackCrouched = (Get_Int_Parameter("_Attack_Crouched") == 1) ? true : false;
  165. params.WaypathID = Get_Int_Parameter("_Move_Waypath_ID");
  166. params.WaypointStartID = Get_Int_Parameter("_Move_Waypath_Start_ID");
  167. params.WaypointEndID = Get_Int_Parameter("_Move_Waypath_End_ID");
  168. params.WaypathSplined = (Get_Int_Parameter("_Move_Waypath_Splined") == 1) ? true : false;
  169. SCRIPT_DEBUG_MESSAGE(("M00_Action ACTIVATED.\n"));
  170. if (attack_target)
  171. {
  172. // Attacking a target, override the attack location values
  173. params.Set_Attack(attack_target, Get_Float_Parameter("_Attack_Range"), Get_Float_Parameter("_Attack_Deviation"), primary_weapon);
  174. attacking = true;
  175. }
  176. if (current_attack_location != empty_vector)
  177. {
  178. // Attacking a location, be sure to turn on attacking bool
  179. attacking = true;
  180. }
  181. if (move_target)
  182. {
  183. // Moving toward a target, override other movement values
  184. params.Set_Movement(move_target, Get_Float_Parameter("_Move_Speed"), Get_Float_Parameter("_Move_Arrive_Distance"));
  185. params.WaypathID = 0;
  186. params.WaypointStartID = 0;
  187. params.WaypointEndID = 0;
  188. params.WaypathSplined = false;
  189. }
  190. if (params.MoveLocation != empty_vector)
  191. {
  192. // Moving to a location, override other movement values
  193. params.WaypathID = 0;
  194. params.WaypointStartID = 0;
  195. params.WaypointEndID = 0;
  196. params.WaypathSplined = false;
  197. }
  198. if (script_active)
  199. {
  200. // Check if we are firing and moving, or just moving.
  201. if (attacking)
  202. {
  203. SCRIPT_DEBUG_MESSAGE(("M00_Action is moving and attacking.\n"));
  204. Commands->Action_Attack(obj, params);
  205. }
  206. else
  207. {
  208. SCRIPT_DEBUG_MESSAGE(("M00_Action is moving only - no attack.\n"));
  209. Commands->Action_Goto(obj, params);
  210. }
  211. }
  212. }
  213. if (param == Get_Int_Parameter("Receive_Param_Off"))
  214. {
  215. SCRIPT_DEBUG_MESSAGE(("M00_Action DEACTIVATED.\n"));
  216. script_active = false;
  217. Commands->Action_Reset(obj, Get_Int_Parameter("Action_Priority")+1);
  218. }
  219. }
  220. }
  221. void Action_Complete(GameObject * obj, int action_id, ActionCompleteReason reason)
  222. {
  223. if (script_active)
  224. {
  225. if (action_id == Get_Int_Parameter("Action_ID"))
  226. {
  227. switch (reason)
  228. {
  229. case (ACTION_COMPLETE_LOW_PRIORITY):
  230. {
  231. SCRIPT_DEBUG_MESSAGE(("M00_Action returned a Low Priority Warning.\n"));
  232. break;
  233. }
  234. case (ACTION_COMPLETE_PATH_BAD_START):
  235. {
  236. SCRIPT_DEBUG_MESSAGE(("ERROR - M00_Action returned a Path Bad Start Error!\n"));
  237. break;
  238. }
  239. case (ACTION_COMPLETE_PATH_BAD_DEST):
  240. {
  241. SCRIPT_DEBUG_MESSAGE(("ERROR - M00_Action returned a Path Bad Destination Error!\n"));
  242. break;
  243. }
  244. case (ACTION_COMPLETE_MOVE_NO_PROGRESS_MADE):
  245. {
  246. SCRIPT_DEBUG_MESSAGE(("ERROR - M00_Action returned a No Progress Made Error!\n"));
  247. break;
  248. }
  249. case (ACTION_COMPLETE_ATTACK_OUT_OF_RANGE):
  250. {
  251. SCRIPT_DEBUG_MESSAGE(("ERROR - M00_Action returned an Attack Out Of Range Error!\n"));
  252. break;
  253. }
  254. case (MOVEMENT_COMPLETE_ARRIVED):
  255. {
  256. SCRIPT_DEBUG_MESSAGE(("M00_Action returned a Movement Complete Arrived.\n"));
  257. break;
  258. }
  259. default:
  260. {
  261. SCRIPT_DEBUG_MESSAGE(("M00_Action returned with default success.\n"));
  262. break;
  263. }
  264. }
  265. }
  266. }
  267. }
  268. };
  269. DECLARE_SCRIPT(M00_Action_Set_Home_Location, "Start_Now=1:int, Receive_Type:int, Receive_Param_On:int, Home_Location:vector3, Wander_Distance=99999.0:float")
  270. {
  271. void Created(GameObject* obj)
  272. {
  273. if (Get_Int_Parameter("Start_Now"))
  274. {
  275. Set_Innate_Position (obj);
  276. }
  277. }
  278. void Custom( GameObject * obj, int type, int param, GameObject * sender )
  279. {
  280. if (type == Get_Int_Parameter("Receive_Type"))
  281. {
  282. if (param == Get_Int_Parameter("Receive_Param_On"))
  283. {
  284. Set_Innate_Position (obj);
  285. }
  286. }
  287. }
  288. void Set_Innate_Position (GameObject* obj)
  289. {
  290. Commands->Set_Innate_Soldier_Home_Location(obj, Get_Vector3_Parameter("Home_Location"), Get_Float_Parameter("Wander_Distance"));
  291. }
  292. };
  293. DECLARE_SCRIPT (M00_Action_Innate_Follow_Waypath, "Waypath_ID:int")
  294. {
  295. void Created (GameObject* obj)
  296. {
  297. Perform_Action (obj);
  298. }
  299. void Action_Complete(GameObject * obj, int action_id, ActionCompleteReason complete_reason)
  300. {
  301. //Commands->Start_Timer (obj, this, 3.0f, 32);
  302. }
  303. void Timer_Expired (GameObject * obj, int timer_id)
  304. {
  305. if (timer_id == 32)
  306. {
  307. Perform_Action (obj);
  308. }
  309. }
  310. void Perform_Action (GameObject* obj)
  311. {
  312. /*
  313. ActionParamsStruct params;
  314. params.Set_Basic(this, 29, 11);
  315. params.Set_Movement(Vector3(0.0f,0.0f,0.0f), 0.5f, 1.0f);
  316. params.WaypathID = Get_Int_Parameter("Waypath_ID");
  317. Commands->Action_Goto (obj, params);
  318. */
  319. }
  320. };
  321. DECLARE_SCRIPT (M00_Action_Innate_Follow_Player, "")
  322. {
  323. void Created (GameObject* obj)
  324. {
  325. Commands->Start_Timer (obj, this, 1.0f, 33);
  326. }
  327. void Timer_Expired (GameObject* obj, int timer_id)
  328. {
  329. if (timer_id == 33)
  330. {
  331. Vector3 my_loc = Commands->Get_Position(obj);
  332. GameObject * nearest = Commands->Get_A_Star (my_loc);
  333. if (nearest)
  334. {
  335. ActionParamsStruct params;
  336. params.Set_Basic(this, 39, 11);
  337. params.Set_Movement(nearest, 1.0f, 3.0f);
  338. Commands->Action_Goto (nearest, params);
  339. Commands->Start_Timer (obj, this, 10.0f, 33);
  340. }
  341. }
  342. }
  343. };