Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. fnc_getNearestFlag =
  2. {
  3. private _zonePos = _this;
  4. private _returnFlag = objNull;
  5.  
  6. private _flagArray =+ G_Flags_Data;
  7. _flagArray = _flagArray apply { [_x distance2D _zonePos, _x] };
  8. _flagArray sort true;
  9.  
  10. _returnFlag =+ (_flagArray select 0) select 1;
  11.  
  12. _returnFlag
  13. };
  14.  
  15. fnc_getFlagArray =
  16. {
  17. private _flagToFind = _this;
  18. private _returnFlagArr = [];
  19.  
  20. {
  21. private _arrIdx = _x find _flagToFind;
  22. if (_arrIdx != -1) exitWith {_returnFlagArr =+ _x};
  23. } forEach G_Flags;
  24.  
  25. _returnFlagArr
  26. };
  27.  
  28. fnc_getArrayIndex =
  29. {
  30. private _searchValue = "";
  31. private _searchIndex = -1;
  32. private _searchArray = [];
  33. private _returnIndex = -1;
  34.  
  35. if (count(_this) == 2) then
  36. {
  37. _searchValue = _this select 0;
  38. _searchArray = _this select 1;
  39.  
  40. {
  41. if (_x == _searchValue) exitWith {_returnIndex = _forEachIndex};
  42. } forEach _searchArray;
  43. }
  44. else
  45. {
  46. _searchValue = _this select 0;
  47. _searchIndex = _this select 1;
  48. _searchArray = _this select 2;
  49.  
  50. {
  51. private _currVal = if (typeName _x == "ARRAY") then {_x select _searchIndex} else {_x};
  52. if (_currVal == _searchValue) exitWith {_returnIndex = _forEachIndex};
  53. } forEach _searchArray;
  54. };
  55.  
  56. _returnIndex
  57. };
  58.  
  59. fnc_dumpArray =
  60. {
  61. diag_log text format ["### Start Dumping Array"];
  62. {
  63. diag_log text format ["%2", _forEachIndex, _x];
  64. } forEach _this;
  65. diag_log text format ["### Done Dumping Array"];
  66. };
  67.  
  68. //Generation run
  69. if (isNil "G_Zones") then
  70. {
  71. private _worldSizeX = 100; //abs(getNumber (configFile >> "CfgWorlds" >> worldName >> "Grid" >> "Zoom2" >> "stepX"));
  72. private _worldSizeY = 100; //abs(getNumber (configFile >> "CfgWorlds" >> worldName >> "Grid" >> "Zoom2" >> "stepY"));
  73. private _mapSize = 12800; //getNumber (configFile >> "CfgWorlds" >> worldName >> "mapSize");
  74.  
  75. private _currX = _worldSizeX / 2;
  76. private _currY = _mapSize - (_worldSizeY / 2);
  77. private _cnt = 0;
  78. G_Zones = [];
  79.  
  80. //Get all flags
  81. G_Flags = allMissionObjects "Flag_Green_F";
  82. private _flagsLocal = [];
  83. {
  84. if (!isObjectHidden _x) then {_flagsLocal pushBack _x};
  85. } forEach G_Flags;
  86. G_Flags =+ _flagsLocal;
  87. G_Flags_data =+ G_Flags;
  88.  
  89. //Assign colors to flags
  90. private _colorClasses = [];
  91. private _newFlags = [];
  92. configProperties [configFile >> "CfgMarkerColors", "_colorClasses pushBack (configName _x)", true];
  93. {
  94. private _currEntry = [_x];
  95. _currEntry pushBack (selectRandom _colorClasses);
  96. _currEntry pushBack [];
  97. _newFlags pushBack _currEntry;
  98. } forEach G_Flags;
  99. G_Flags =+ _newFlags;
  100.  
  101. //Build all zones
  102. while {_currY >= 0} do
  103. {
  104. //Figure out if area has any land in it
  105. private _cntSub = 0;
  106. private _waterCheck = [];
  107. private _hasLand = false;
  108. private _closeToSpawn = false;
  109. private _currSubX = _currX - _worldSizeX;
  110. private _currSubY = _currY + _worldSizeY;
  111. while {_currSubY >= (_currY - _worldSizeY)} do
  112. {
  113. if (!surfaceIsWater [_currSubX, _currSubY]) exitWith {_hasLand = true};
  114.  
  115. if (_currSubX >= (_currX + _worldSizeX)) then
  116. {
  117. _currSubY = _currSubY - (_worldSizeY / 2);
  118. _currSubX = _currX - _worldSizeX;
  119. }
  120. else
  121. {
  122. _currSubX = _currSubX + (_worldSizeX / 2);
  123. };
  124.  
  125. _cntSub = _cntSub + 1;
  126. };
  127. //{deleteMarker _x} forEach _waterCheck;
  128.  
  129. //Check to see if it's close to spawn locations
  130. {
  131. if (((getMarkerPos _x) distance2D [_currX, _currY]) < 1000) exitWith {_closeToSpawn = true};
  132. } forEach ["respawn_west", "respawn_east"];
  133.  
  134. //Create marker for visual representation
  135. if (_hasLand && !_closeToSpawn) then
  136. {
  137. private _marker = createMarker [format["MapZone_%1", _cnt], [_currX, _currY]];
  138. _marker setMarkerShape "RECTANGLE";
  139. _marker setMarkerSize [_worldSizeX, _worldSizeY];
  140. _marker setMarkerBrush "Solid";
  141. _marker setMarkerColor "ColorBlack";
  142. _marker setMarkerAlpha 0.3;
  143.  
  144. G_Zones pushBack (format["MapZone_%1", _cnt]);
  145. };
  146.  
  147. //Move down if we hit the side boundary, otherwise keep going right
  148. if (_currX >= (_mapSize - _worldSizeX)) then
  149. {
  150. _currX = _worldSizeX / 2;
  151. _currY = _currY - (_worldSizeY * 2);
  152. }
  153. else
  154. {
  155. _currX = _currX + (_worldSizeX * 2);
  156. };
  157.  
  158. _cnt = _cnt + 1;
  159. };
  160.  
  161. //Assign zones to flags
  162. {
  163. private _nearestFlag = (getMarkerPos _x) call fnc_getNearestFlag;
  164. if (!isNull _nearestFlag) then
  165. {
  166. private _flagArr = _nearestFlag call fnc_getFlagArray;
  167.  
  168. _x setMarkerColor (_flagArr select 1);
  169.  
  170. //Add zone to flag array
  171. private _flagArrIdx = [_flagArr select 0, 0, G_Flags] Call fnc_getArrayIndex;
  172. if (_flagArrIdx != -1) then
  173. {
  174. private _flagZones = (G_Flags select _flagArrIdx) select 2;
  175. _flagZones pushBack [_x, (getMarkerPos _x), [_worldSizeX, _worldSizeY]];
  176. };
  177. };
  178. } forEach G_Zones;
  179.  
  180. //Assign values to flags
  181. {
  182. private _amtZone = 2.5 * (count (_x select 2));
  183. _x pushBack _amtZone;
  184. player globalChat format["%1 - $%2", _x select 0, _amtZone];
  185.  
  186. } forEach G_Flags;
  187. }
  188. else //Already built zones
  189. {
  190. {
  191. _x call fnc_dumpArray;
  192. (_x select 2) call fnc_dumpArray;
  193. } forEach G_Flags;
  194. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement