fnc_moduleOrbitalDroidDispenser.sqf 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #include "function_macros.hpp"
  2. LOG("Spawned Orbital Drop Droid Dispenser Logic");
  3. _logic = _this select 0;
  4. _units = _this select 1;
  5. _activated = _this select 2;
  6. if ({local _x} count (objectcurators _logic) > 0) then {
  7. //--- Reveal the circle to curators
  8. _logic hideobject false;
  9. _logic setpos position _logic;
  10. };
  11. if !(isserver) exitwith {};
  12. if (_activated) then {
  13. _ammo = _logic getvariable ["type",gettext (configfile >> "cfgvehicles" >> typeof _logic >> "ammo")];
  14. if (_ammo != "") then {
  15. _cfgAmmo = configfile >> "cfgammo" >> _ammo;
  16. //if !(isclass _cfgAmmo) exitwith {["CfgAmmo class '%1' not found.",_ammo] call bis_fnc_error;};
  17. // It seems BI broke this part...
  18. // _dirVar = _fnc_scriptname + typeof _logic;
  19. // _logic setdir (missionnamespace getvariable [_dirVar,direction _logic]); //--- Restore custom direction
  20. _pos = getposatl _logic;
  21. _posAmmo = +_pos;
  22. _posAmmo set [2,0];
  23. _dir = direction _logic;
  24. _simulation = tolower gettext (configfile >> "cfgammo" >> _ammo >> "simulation");
  25. _altitude = 0;
  26. _velocity = [];
  27. _attach = false;
  28. _radio = "";
  29. _delay = 60;
  30. _sound = "";
  31. _soundSourceClass = "";
  32. _hint = [];
  33. _shakeStrength = 0;
  34. _shakeRadius = 0;
  35. switch (_simulation) do {
  36. case "shotshell": {
  37. _altitude = 1000;
  38. _velocity = [0,0,-100];
  39. _radio = "SentGenIncoming";
  40. _sounds = if (getnumber (_cfgAmmo >> "hit") < 200) then {["mortar1","mortar2"]} else {["shell1","shell2","shell3","shell4"]};
  41. _sound = selectRandom _sounds;
  42. _hint = ["Curator","PlaceOrdnance"];
  43. _shakeStrength = 0.01;
  44. _shakeRadius = 300;
  45. };
  46. case "shotsubmunitions": {
  47. _posAmmo = [_posAmmo,500,_dir + 180] call bis_fnc_relpos;
  48. _altitude = 1000 - ((getterrainheightasl _posAmmo) - (getterrainheightasl _pos));
  49. _posAmmo set [2,_altitude];
  50. _velocity = [sin _dir * 68,cos _dir * 68,-100];
  51. _radio = "SentGenIncoming";
  52. _hint = ["Curator","PlaceOrdnance"];
  53. _shakeStrength = 0.02;
  54. _shakeRadius = 500;
  55. };
  56. case "shotilluminating": {
  57. _altitude = 66;
  58. _velocity = [wind select 0,wind select 1,30];
  59. _sound = "SN_Flare_Fired_4";
  60. _soundSourceClass = "SoundFlareLoop_F";
  61. };
  62. case "shotnvgmarker";
  63. case "shotsmokex": {
  64. _altitude = 0;
  65. _velocity = [0,0,0];
  66. _attach = true;
  67. };
  68. default {["Ammo simulation '%1' is not supported",_simulation] call bis_fnc_error;};
  69. };
  70. _fnc_playRadio = {
  71. if (_radio != "") then {
  72. _entities = (getposatl _logic) nearentities ["All",100];
  73. _sides = [];
  74. {
  75. if (isplayer _x) then {
  76. _side = side group _x;
  77. if (_side in [east,west,resistance,civilian]) then {
  78. //--- Play radio (only if it wasn't played recently)
  79. if (CBA_missionTime > _x getVariable ["BIS_fnc_moduleProjectile_radio",-_delay]) then {
  80. [[_side,_radio,"side"],"bis_fnc_sayMessage",_x] call bis_fnc_mp;
  81. _x setVariable ["BIS_fnc_moduleProjectile_radio",CBA_missionTime + _delay];
  82. };
  83. };
  84. };
  85. } foreach _entities;
  86. };
  87. };
  88. if (count _hint > 0 && {count objectcurators _logic > 0}) then {
  89. [[_hint,nil,nil,nil,nil,nil,nil,true],"bis_fnc_advHint",objectcurators _logic] call bis_fnc_mp;
  90. };
  91. if (count _velocity == 3) then {
  92. _altitude = (_logic getvariable ["altitude",_altitude]) call bis_fnc_parsenumber;
  93. _radio = _logic getvariable ["radio",_radio];
  94. //--- Create projectile
  95. _posAmmo set [2,_altitude];
  96. _projectile = createvehicle [_ammo,_posAmmo,[],0,"none"];
  97. _projectile setpos _posAmmo;
  98. _projectile setvelocity _velocity;
  99. if (_attach) then {_projectile attachto [_logic,[0,0,_altitude]];};
  100. // Added by ace_zeus for ace_frag compatibility
  101. if (!isNil ace_frag_fnc_addPfhRound) then {
  102. [objNull, _ammo, _projectile, true] call ace_frag_fnc_addPfhRound;
  103. };
  104. //--- Play sound
  105. if (_sound != "") then {[[_logic,_sound,"say3D"],"bis_fnc_sayMessage"] call bis_fnc_mp;};
  106. //--- Create sound source
  107. _soundSource = if (_soundSourceClass != "") then {createSoundSource [_soundSourceClass,_pos,[],0]} else {objnull};
  108. // Added by ace_zeus to toggle ordnance radio message
  109. if (ace_zeus_radioOrdnance) then {
  110. //--- Play radio warning
  111. [] call _fnc_playRadio;
  112. };
  113. //--- Update
  114. if (_attach) then {
  115. waituntil {
  116. _soundSource setposatl getposatl _projectile;
  117. sleep 1;
  118. isnull _projectile || isnull _logic
  119. };
  120. } else {
  121. waituntil {
  122. _soundSource setposatl getposatl _projectile;
  123. if (getposatl _logic distance _pos > 0 || direction _logic != _dir) then {
  124. _posNew = getposasl _logic;
  125. _dirDiff = direction _logic - _dir;
  126. _posNew = [_posNew,[getposasl _projectile,_pos] call bis_fnc_distance2d,direction _logic + 180] call bis_fnc_relpos;
  127. _posNew set [2,getposasl _projectile select 2];
  128. _projectile setvelocity ([velocity _projectile,-_dirDiff] call bis_fnc_rotatevector2d);
  129. _projectile setposasl _posNew;
  130. _pos = getposatl _logic;
  131. _dir = direction _logic;
  132. //missionnamespace setvariable [_dirVar,_dir]; See L37
  133. };
  134. sleep 0.1;
  135. isnull _projectile || isnull _logic
  136. };
  137. };
  138. deletevehicle _projectile;
  139. deletevehicle _soundSource;
  140. LOG("Server, continuing on");
  141. _position = position _logic;
  142. LOGF_1("Firing Droid Dispenser Artillery at '%1'", _position);
  143. _spawner = GVAR(spawnerDefaultObject) createVehicle _position;
  144. LOGF_2("Created Droid Dispenser Object '%1' at '%2'", _spawner, _position);
  145. [_spawner] call FUNC(droidDispenserInit);
  146. {
  147. _x addCuratorEditableObjects [[_spawner], true];
  148. } forEach allCurators;
  149. if (count objectcurators _logic > 0) then {
  150. //--- Delete curator spawned logic
  151. if (_shakeStrength > 0) then {
  152. if (_simulation == "shotsubmunitions") then {sleep 0.5;};
  153. [[_shakeStrength,0.7,[position _logic,_shakeRadius]],"bis_fnc_shakeCuratorCamera"] call bis_fnc_mp;
  154. };
  155. deletevehicle _logic;
  156. } else {
  157. //--- Repeat to achieve permanent effect
  158. _repeat = _logic getvariable ["repeat",0] > 0;
  159. if (_repeat) then {
  160. [_logic,_units,_activated] call bis_fnc_moduleprojectile;
  161. } else {
  162. deletevehicle _logic;
  163. };
  164. };
  165. } else {
  166. deletevehicle _logic;
  167. };
  168. } else {
  169. ["Cannot create projectile, 'ammo' config attribute is missing in %1",typeof _logic] call bis_fnc_error;
  170. };
  171. };