Advertisement
Guest User

Untitled

a guest
Jul 18th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.12 KB | None | 0 0
  1. /* Renegade Scripts.dll
  2. Copyright 2014 Tiberian Technologies
  3.  
  4. This file is part of the Renegade scripts.dll
  5. The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 2, or (at your option) any later
  8. version. See the file COPYING for more details.
  9. In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module that does not contain code covered by this licence.
  10. Only the source code to the module(s) containing the licenced code has to be released.
  11. */
  12. #include "general.h"
  13. #include "scripts.h"
  14. #include "agtfix.h"
  15. #include "engine_game.h"
  16. #include "BuildingGameObj.h"
  17. #include "BuildingAggregateClass.h"
  18.  
  19. #define PI 3.14159265
  20.  
  21. void GDI_AGT::Created(GameObject* AGTObj)
  22. {
  23. Commands->Enable_Hibernation(AGTObj, false);
  24.  
  25.  
  26. Vector3 AGTPos;
  27. Vector3 MissilePos;
  28. Vector3 GunPos[4];
  29.  
  30. AGTPos = Commands->Get_Position(AGTObj);
  31.  
  32. float AGTFacing=0;
  33. float AGTHeight=0;
  34. BuildingGameObj *AGTBuilding = AGTObj->As_BuildingGameObj();
  35. BuildingAggregateClass *AGTMCT = 0;
  36. if(AGTBuilding)
  37. {
  38. AGTMCT = AGTBuilding->Find_MCT();
  39. if(AGTMCT)
  40. {
  41. Vector3 MCTPos;
  42. AGTFacing = AGTMCT->Get_Facing();
  43. AGTMCT->Get_Position(&MCTPos);
  44. AGTHeight=MCTPos.Z+8.0f;
  45. }
  46.  
  47. }
  48.  
  49. //Calculations for setting coordinates at different angles.
  50. float CosFacing = cos(AGTFacing);
  51. float SinFacing = sin(AGTFacing);
  52.  
  53. //Check if single floor AGT, if not fall back to using building controller height.
  54. if(AGTPos.Z - AGTHeight < 11 && AGTMCT)
  55. AGTPos.Z=AGTHeight+9.2f;
  56.  
  57. //MissilePosition
  58. MissilePos.X = AGTPos.X;
  59. MissilePos.Y = AGTPos.Y;
  60. MissilePos.Z = AGTPos.Z + 3.5f;
  61.  
  62. //GunPosition 1
  63. GunPos[0] = AGTPos;
  64. //X Offsets
  65. GunPos[0].X += 5.0189999f * CosFacing;
  66. GunPos[0].Y += 5.0189999f * SinFacing;
  67. //Y Offsets
  68. GunPos[0].Y += -3.4089998f * CosFacing;
  69. GunPos[0].X += 3.4089998f * SinFacing;
  70. //Z offset
  71. GunPos[0].Z = AGTPos.Z - 9.0f;
  72.  
  73. //GunPosition 2
  74. GunPos[1] = AGTPos;
  75. //X Offsets
  76. GunPos[1].X += 5.0109998f * CosFacing;
  77. GunPos[1].Y += 5.0109998f * SinFacing;
  78. //Y Offsets
  79. GunPos[1].Y += 3.6720001f * CosFacing;
  80. GunPos[1].X += -3.6720001f * SinFacing;
  81. //Z offset
  82. GunPos[1].Z = AGTPos.Z - 9.0f;
  83.  
  84. //GunPosition 3
  85. GunPos[2] = AGTPos;
  86. //X Offsets
  87. GunPos[2].X += -5.0110002f * CosFacing;
  88. GunPos[2].Y += -5.0110002f * SinFacing;
  89. //Y Offsets
  90. GunPos[2].Y += 3.657f * CosFacing;
  91. GunPos[2].X += -3.657f * SinFacing;
  92. //Z offset
  93. GunPos[2].Z = AGTPos.Z - 9.0f;
  94.  
  95. //GunPosition 4
  96. GunPos[3] = AGTPos;
  97. //X Offsets
  98. GunPos[3].X += -5.0129999f * CosFacing;
  99. GunPos[3].Y += -5.0129999f * SinFacing;
  100. //Y Offsets
  101. GunPos[3].Y += -3.4060002f * CosFacing;
  102. GunPos[3].X += 3.4060002f * SinFacing;
  103. //Z offset
  104. GunPos[3].Z = AGTPos.Z - 9.0f;
  105.  
  106. GameObject* MissileObj = Commands->Create_Object("GDI_AGT", MissilePos);
  107. if (MissileObj) {
  108. Commands->Attach_Script(MissileObj, "GDI_AGT_Missile", "0");
  109. MissileID = Commands->Get_ID(MissileObj);
  110. }
  111.  
  112. for (int I = 0; I < 4; I++) {
  113. GameObject* GunObj = Commands->Create_Object("GDI_Ceiling_Gun_AGT", GunPos[I]);
  114. if (GunObj) {
  115. Commands->Attach_Script(GunObj, "GDI_AGT_Gun", "");
  116. Commands->Send_Custom_Event(AGTObj, GunObj, 0, MissileID, 0);
  117. GunID[I] = Commands->Get_ID(GunObj);
  118. }
  119. }
  120. }
  121.  
  122.  
  123. void GDI_AGT::Killed(GameObject* AGTObj, GameObject* KillerObj)
  124. {
  125. for (int I = 0; I < 4; I++) {
  126. Commands->Destroy_Object(Commands->Find_Object(GunID[I]));
  127. }
  128. Commands->Destroy_Object(Commands->Find_Object(MissileID));
  129. }
  130.  
  131. void GDI_AGT::Custom(GameObject* AGTObj, int type, int Param, GameObject* Sender) {
  132. if (type == CUSTOM_EVENT_BUILDING_POWER_CHANGED) {
  133. if (Param != 0) {
  134. Vector3 AGTPos;
  135. Vector3 MissilePos;
  136. Vector3 GunPos[4];
  137.  
  138. AGTPos = Commands->Get_Position(AGTObj);
  139.  
  140. float AGTFacing=0;
  141. float AGTHeight=0;
  142. BuildingGameObj *AGTBuilding = AGTObj->As_BuildingGameObj();
  143. BuildingAggregateClass *AGTMCT = 0;
  144. if(AGTBuilding)
  145. {
  146. AGTMCT = AGTBuilding->Find_MCT();
  147. if(AGTMCT)
  148. {
  149. Vector3 MCTPos;
  150. AGTFacing = AGTMCT->Get_Facing();
  151. AGTMCT->Get_Position(&MCTPos);
  152. AGTHeight=MCTPos.Z+8.0f;
  153. }
  154.  
  155. }
  156. //Calculations for setting coordinates at different angles.
  157. float CosFacing = cos(AGTFacing);
  158. float SinFacing = sin(AGTFacing);
  159.  
  160. //Check if single floor AGT, if not fall back to using building controller height.
  161. if(AGTPos.Z - AGTHeight < 11 && AGTMCT)
  162. AGTPos.Z=AGTHeight+9.2f;
  163.  
  164. MissilePos.X = AGTPos.X;
  165. MissilePos.Y = AGTPos.Y;
  166. MissilePos.Z = AGTPos.Z + 3.5f;
  167.  
  168. //GunPosition 1
  169. GunPos[0] = AGTPos;
  170. //X Offsets
  171. GunPos[0].X += 5.0189999f * CosFacing;
  172. GunPos[0].Y += 5.0189999f * SinFacing;
  173. //Y Offsets
  174. GunPos[0].Y += -3.4089998f * CosFacing;
  175. GunPos[0].X += 3.4089998f * SinFacing;
  176. //Z offset
  177. GunPos[0].Z = AGTPos.Z - 9.0f;
  178.  
  179. //GunPosition 2
  180. GunPos[1] = AGTPos;
  181. //X Offsets
  182. GunPos[1].X += 5.0109998f * CosFacing;
  183. GunPos[1].Y += 5.0109998f * SinFacing;
  184. //Y Offsets
  185. GunPos[1].Y += 3.6720001f * CosFacing;
  186. GunPos[1].X += -3.6720001f * SinFacing;
  187. //Z offset
  188. GunPos[1].Z = AGTPos.Z - 9.0f;
  189.  
  190. //GunPosition 3
  191. GunPos[2] = AGTPos;
  192. //X Offsets
  193. GunPos[2].X += -5.0110002f * CosFacing;
  194. GunPos[2].Y += -5.0110002f * SinFacing;
  195. //Y Offsets
  196. GunPos[2].Y += 3.657f * CosFacing;
  197. GunPos[2].X += -3.657f * SinFacing;
  198. //Z offset
  199. GunPos[2].Z = AGTPos.Z - 9.0f;
  200.  
  201. //GunPosition 4
  202. GunPos[3] = AGTPos;
  203. //X Offsets
  204. GunPos[3].X += -5.0129999f * CosFacing;
  205. GunPos[3].Y += -5.0129999f * SinFacing;
  206. //Y Offsets
  207. GunPos[3].Y += -3.4060002f * CosFacing;
  208. GunPos[3].X += 3.4060002f * SinFacing;
  209. //Z offset
  210. GunPos[3].Z = AGTPos.Z - 9.0f;
  211.  
  212. GameObject* MissileObj = Commands->Create_Object("GDI_AGT", MissilePos);
  213. if (MissileObj) {
  214. Commands->Attach_Script(MissileObj, "GDI_AGT_Missile", "0");
  215. MissileID = Commands->Get_ID(MissileObj);
  216. }
  217.  
  218. for (int I = 0; I < 4; I++) {
  219. GameObject* GunObj = Commands->Create_Object("GDI_Ceiling_Gun_AGT", GunPos[I]);
  220. if (GunObj) {
  221. Commands->Attach_Script(GunObj, "GDI_AGT_Gun", "");
  222. Commands->Send_Custom_Event(AGTObj, GunObj, 0, MissileID, 0);
  223. GunID[I] = Commands->Get_ID(GunObj);
  224. }
  225. }
  226. }
  227. else {
  228. // Kill the weapon object
  229. for (int I = 0; I < 4; I++) {
  230. Commands->Destroy_Object(Commands->Find_Object(GunID[I]));
  231. }
  232. Commands->Destroy_Object(Commands->Find_Object(MissileID));
  233. }
  234. }
  235. }
  236.  
  237.  
  238.  
  239. void GDI_AGT_Gun::Created(GameObject* GunObj)
  240. {
  241. EnemyID = NULL;
  242.  
  243. Commands->Set_Shield_Type(GunObj, "Blamo");
  244. Commands->Enable_Hibernation(GunObj, false);
  245. Commands->Innate_Enable(GunObj);
  246. Commands->Enable_Enemy_Seen(GunObj, true);
  247. }
  248.  
  249.  
  250. void GDI_AGT_Gun::Destroyed(GameObject* GunObj)
  251. {
  252. Commands->Action_Reset(GunObj, 100);
  253. }
  254.  
  255.  
  256. void GDI_AGT_Gun::Enemy_Seen(GameObject* GunObj, GameObject* EnemyObj)
  257. {
  258. // Check for an living target which is in range
  259. if (!IsValidEnemy(GunObj, EnemyObj))
  260. return;
  261.  
  262. // If the current enemy is still a valid target, ignore this enemy
  263. if (IsValidEnemy(GunObj, Commands->Find_Object(EnemyID)))
  264. return;
  265.  
  266. // Attack!
  267. ActionParamsStruct ActionParams;
  268. ActionParams.Set_Basic(this, 100, 1);
  269. ActionParams.Set_Attack(EnemyObj, 300, 0, true);
  270. ActionParams.AttackCheckBlocked = false;
  271. Commands->Action_Attack(GunObj, ActionParams);
  272.  
  273. Commands->Start_Timer(GunObj, this, .1f, 0);
  274.  
  275. EnemyID = Commands->Get_ID(EnemyObj);
  276. }
  277.  
  278.  
  279. void GDI_AGT_Gun::Timer_Expired(GameObject* GunObj, int Number)
  280. {
  281. switch (Number) {
  282. case 0:
  283. // If the current enemy is no longer a valid target, stop shooting,
  284. // otherwise restart the times
  285. if (!IsValidEnemy(GunObj, Commands->Find_Object(EnemyID))) {
  286. Commands->Action_Reset(GunObj, 100);
  287. EnemyID = NULL;
  288. } else {
  289. Commands->Start_Timer(GunObj, this, .1f, 0);
  290. }
  291. break;
  292. }
  293. }
  294.  
  295.  
  296. void GDI_AGT_Gun::Custom(GameObject* MissileObj, int type, int Param, GameObject* SenderObj)
  297. {
  298. switch (type)
  299. {
  300. case 0:
  301. MissileID = Param;
  302. break;
  303. }
  304. }
  305.  
  306.  
  307.  
  308. bool GDI_AGT_Gun::IsValidEnemy(GameObject* GunObj, GameObject* EnemyObj) {
  309. if (!EnemyObj)
  310. return false;
  311.  
  312. // TODO: Make switch for agt kills neutral?
  313. if (Commands->Get_Player_Type(EnemyObj) != 0)
  314. return false;
  315.  
  316. if (Commands->Get_Health(EnemyObj) <= 0)
  317. return false;
  318.  
  319. if (!Commands->Is_Object_Visible(GunObj, EnemyObj))
  320. return false;
  321.  
  322. if (Is_Harvester(EnemyObj))
  323. return false;
  324.  
  325. Commands->Send_Custom_Event(GunObj, Commands->Find_Object(MissileID), 0, Commands->Get_ID(EnemyObj), 0);
  326.  
  327. Vector3 GunObjPos = Commands->Get_Position(GunObj);
  328. Vector3 EnemyObjPos = Commands->Get_Position(EnemyObj);
  329. return Commands->Get_Distance(GunObjPos, EnemyObjPos) > 20;
  330. }
  331.  
  332.  
  333.  
  334.  
  335. void GDI_AGT_Missile::Created(GameObject* MissileObj)
  336. {
  337. EnemyID = NULL;
  338.  
  339. Commands->Set_Is_Rendered(MissileObj, false);
  340. Commands->Enable_Hibernation(MissileObj, false);
  341. }
  342.  
  343.  
  344. void GDI_AGT_Missile::Destroyed(GameObject* MissileObj)
  345. {
  346. Commands->Action_Reset(MissileObj, 100);
  347. }
  348.  
  349.  
  350. void GDI_AGT_Missile::Timer_Expired(GameObject* MissileObj, int Number)
  351. {
  352. switch (Number) {
  353. case 0:
  354. // If the current enemy is no longer a valid target, stop shooting,
  355. // otherwise restart the times
  356. if (!IsValidEnemy(MissileObj, Commands->Find_Object(EnemyID))) {
  357. Commands->Action_Reset(MissileObj, 100);
  358. EnemyID = NULL;
  359. } else {
  360. Commands->Start_Timer(MissileObj, this, .1f, 0);
  361. }
  362. break;
  363. }
  364. }
  365.  
  366.  
  367. void GDI_AGT_Missile::Custom(GameObject* MissileObj, int type, int Param, GameObject* SenderObj)
  368. {
  369. switch (type)
  370. {
  371. case 0:
  372. // If the current enemy is still a valid target, ignore this enemy
  373. if (IsValidEnemy(MissileObj, Commands->Find_Object(EnemyID)))
  374. return;
  375.  
  376. GameObject* EnemyObj = Commands->Find_Object(Param);
  377.  
  378. // Check for an living target which is in range
  379. if (!IsValidEnemy(MissileObj, EnemyObj))
  380. return;
  381.  
  382. // Attack!
  383. ActionParamsStruct ActionParams;
  384. ActionParams.Set_Basic(this, 100, 1);
  385. ActionParams.Set_Attack(EnemyObj, 300, 0, true);
  386. ActionParams.AttackCheckBlocked = false;
  387. Commands->Action_Attack(MissileObj, ActionParams);
  388.  
  389. Commands->Start_Timer(MissileObj, this, .1f, 0);
  390.  
  391. EnemyID = Param;
  392. }
  393. }
  394.  
  395.  
  396. bool GDI_AGT_Missile::IsValidEnemy(GameObject* MissileObj, GameObject* EnemyObj)
  397. {
  398. if (!EnemyObj)
  399. return false;
  400.  
  401. // TODO: Make switch for agt kills neutral?
  402. if (Commands->Get_Player_Type(EnemyObj) != 0)
  403. return false;
  404.  
  405. if (Commands->Get_Health(EnemyObj) <= 0)
  406. return false;
  407.  
  408. if (!Commands->Is_Object_Visible(MissileObj, EnemyObj))
  409. return false;
  410.  
  411. Vector3 MissileObjPos = Commands->Get_Position(MissileObj);
  412. Vector3 EnemyObjPos = Commands->Get_Position(EnemyObj);
  413.  
  414. return Commands->Get_Distance(MissileObjPos, EnemyObjPos) > 30;
  415. }
  416.  
  417.  
  418.  
  419. ScriptRegistrant<GDI_AGT> M00_Advanced_Guard_Tower_Registrant("M00_Advanced_Guard_Tower", "");
  420. ScriptRegistrant<GDI_AGT> GDI_AGT_Registrant("GDI_AGT", "");
  421. ScriptRegistrant<GDI_AGT_Gun> GDI_AGT_Gun_Registrant("GDI_AGT_Gun", "");
  422. ScriptRegistrant<GDI_AGT_Missile> GDI_AGT_Missile_Registrant("GDI_AGT_Missile", "");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement