1
0

foreach.inc 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. /*----------------------------------------------------------------------------*\
  2. ===========================
  3. foreach efficient looping
  4. ===========================
  5. Description:
  6. Provides efficient looping through sparse data sets, such as connected
  7. players. Significantly improved from the original version to be a generic
  8. loop system, rather then purely a player loop system. When used for
  9. players this has constant time O(n) for number of connected players (n),
  10. unlike standard player loops which are O(MAX_PLAYERS), regardless of the
  11. actual number of connected players. Even when n is MAX_PLAYERS this is
  12. still faster.
  13. Legal:
  14. Version: MPL 1.1
  15. The contents of this file are subject to the Mozilla Public License Version
  16. 1.1 (the "License"); you may not use this file except in compliance with
  17. the License. You may obtain a copy of the License at
  18. http://www.mozilla.org/MPL/
  19. Software distributed under the License is distributed on an "AS IS" basis,
  20. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  21. for the specific language governing rights and limitations under the
  22. License.
  23. The Original Code is the YSI foreach include.
  24. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  25. Portions created by the Initial Developer are Copyright (C) 2011
  26. the Initial Developer. All Rights Reserved.
  27. Contributors:
  28. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  29. Thanks:
  30. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  31. ZeeX - Very productive conversations.
  32. koolk - IsPlayerinAreaEx code.
  33. TheAlpha - Danish translation.
  34. breadfish - German translation.
  35. Fireburn - Dutch translation.
  36. yom - French translation.
  37. 50p - Polish translation.
  38. Zamaroht - Spanish translation.
  39. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  40. for me to strive to better.
  41. Pixels^ - Running XScripters where the idea was born.
  42. Matite - Pestering me to release it and using it.
  43. Very special thanks to:
  44. Thiadmer - PAWN, whose limits continue to amaze me!
  45. Kye/Kalcor - SA:MP.
  46. SA:MP Team past, present and future - SA:MP.
  47. Version:
  48. 0.4.1
  49. Changelog:
  50. 16/07/12:
  51. Fixed a bug with "loadfs" blocking callbacks.
  52. Slightly reduced the memory consumption of constant strings.
  53. 25/05/12:
  54. Added a delay timer to remove players for "Kick" crashes.
  55. 05/01/12:
  56. Fixed multi-dimensional iterators.
  57. Fixed "FOREACH_NO_BOTS".
  58. Made "Iterator:" support multi-dimensional arrays.
  59. 07/12/11:
  60. Underlying implementation tweak for more consistent code.
  61. Added Iter_Contains.
  62. 06/12/11:
  63. Minor fixes.
  64. 31/10/11:
  65. Changed the underlying loop code to be slightly faster.
  66. Added support for Iter_SafeRemove, prompting refactoring.
  67. 17/09/11:
  68. Fixed arrays under the new syntax.
  69. 28/04/11:
  70. Moved iterator identifiers to end of variables.
  71. Rewrote "foreach" to accept two syntaxes for "foreach (new i : Iter)".
  72. 16/08/10:
  73. Removed all the "2" versions of the functions.
  74. 14/08/10:
  75. Added Iter_Clear to reset an array.
  76. 06/08/10:
  77. Added special array declaration format.
  78. 18/12/09:
  79. Added Itter_Func2 functions for multi-dimensional iterators.
  80. Renamed foreact et al as keywords in the documentation.
  81. Changed licensing from GPL to MPL.
  82. 02/09/09:
  83. Fixed (again) for 0.3.
  84. Added free slot finding.
  85. 21/08/09:
  86. Updated to include random functions.
  87. Made entirely stand alone.
  88. Ported to 0.3 (separate version).
  89. Added automatic callback hook code.
  90. Removed debug information from stand alone version.
  91. 06/01/08:
  92. Added debug information.
  93. 09/10/07:
  94. Moved to system.
  95. 16/09/07:
  96. Added list sorting.
  97. Made this part of Y SeRver Includes, not Y Sever Includes.
  98. Made list sorting optional.
  99. Fixed version number.
  100. 08/09/07:
  101. First version.
  102. Functions:
  103. Public:
  104. OnPlayerDisconnect - Called when a player leaves to remove them.
  105. OnPlayerConnect - Called when a player connects to add them.
  106. Core:
  107. -
  108. Stock:
  109. Itter_ShowArray - Displays the contents of the array.
  110. Itter_AddInternal - Add a value to an itterator.
  111. Itter_RemoveInternal - Remove a value from an itterator.
  112. Itter_RandomInternal - Get a random item from an itterator.
  113. Itter_FreeInternal - Gets the first free slot in the itterator.
  114. Itter_InitInternal - Initialises a multi-dimensional itterator.
  115. Itter_ContainsInternal - Checks if a value is in an iterator.
  116. Static:
  117. -
  118. Inline:
  119. Itter_Create - Create a new itterator value set.
  120. Itter_Add - Wraps Itter_AddInternal.
  121. Itter_SafeRemove - Wraps Itter_SafeRemoveInternal.
  122. Itter_Remove - Wraps Itter_RemoveInternal.
  123. Itter_Random - Wraps Itter_RandomInternal.
  124. Itter_Count - Gets the number of items in an itterator.
  125. Itter_Debug - Wraps around Itter_ShowArray.
  126. Itter_Free - Wraps around Itter_FreeInternal.
  127. Itter_Contains - Wraps around Itter_ContainsInternal.
  128. API:
  129. -
  130. Callbacks:
  131. -
  132. Hooks:
  133. Itter_OnPlayerConnect - Hook for the OnPlayerConnect callback.
  134. Itter_OnPlayerDisconnect - Hook for the OnPlayerDisconnect callback.
  135. Itter_OnGameModeInit - Only exists to make the code compile correctly...
  136. Definitions:
  137. -
  138. Enums:
  139. -
  140. Macros:
  141. -
  142. Keywords:
  143. foreach - Command to loop an iterator.
  144. foreachex - Like foreach but without a new variable.
  145. foreach2 - Command to loop through an iterator array.
  146. foreachex - Like foreach2 but without a new variable.
  147. Tags:
  148. Iterator - Declare an iterator.
  149. Variables:
  150. Global:
  151. -
  152. Static:
  153. YSI_g_OPC - Records wether Itter_OnPlayerConnect exists for speed.
  154. YSI_g_OPDC - Records wether Itter_OnPlayerDisconnect exists for speed.
  155. Commands:
  156. -
  157. Compile options:
  158. YSI_ITTER_NO_SORT - Removed.
  159. FOREACH_NO_BOTS - Remove the bot iterators for smaller code.
  160. FOREACH_NO_PLAYERS - Remove all default code for player itteration.
  161. Operators:
  162. -
  163. Iterators:
  164. Player - List of all players connected.
  165. Bot - List of all bots (npcs) connected.
  166. NPC - Alias of Bot.
  167. Character - All players and bots.
  168. \*----------------------------------------------------------------------------*/
  169. #define _FOREACH_LOCAL_VERSION 17
  170. // Foreach is testing us.
  171. #if defined _FOREACH_INC_TEST
  172. #define _FOREACH_CUR_VERSION _FOREACH_LOCAL_VERSION
  173. #endinput
  174. #endif
  175. #if !defined _FOREACH_NO_TEST
  176. #define _FOREACH_INC_TEST
  177. #tryinclude <YSI\y_iterate>
  178. #undef _FOREACH_INC_TEST
  179. // <foreach> exists - test which is newer.
  180. #if defined _inc_y_iterate
  181. #if _FOREACH_CUR_VERSION > _FOREACH_LOCAL_VERSION
  182. // Foreach is newer.
  183. #undef _inc_y_iterate
  184. #define _FOREACH_NO_TEST
  185. #include <YSI\y_iterate>
  186. #endinput
  187. #endif
  188. #endif
  189. #endif
  190. #if !defined _samp_included
  191. #error "Please include a_samp or a_npc before foreach"
  192. #endif
  193. //#include <YSI\y_debug>
  194. //#include <YSI\y_hooks>
  195. #if defined SendChat || defined FOREACH_NO_PLAYERS
  196. #define BOTSYNC_IS_BOT (true)
  197. #endif
  198. #if defined IsPlayerNPC
  199. #define _FOREACH_BOT
  200. #endif
  201. #if defined YSI_ITTER_NO_SORT
  202. #error YSI_ITTER_NO_SORT is no longer supported by foreach.
  203. #endif
  204. #define _Y_ITER_ARRAY: _:_Y_ITER_C0:
  205. #define _Y_ITER_ARRAY_SIZE(%1) _:_Y_ITER_C1:_Y_ITER_C2:sizeof %1@YSII_Ag-1
  206. #define _Y_ITER_C0:%0[%1]@YSII_%4g%3) %0@YSII_%4g[%1]%3)
  207. #define _Y_ITER_C1:_Y_ITER_C2:%0[%1]@YSII_Ag%3) %0@YSII_Ag[]%3)
  208. #define _Y_ITER_C2:sizeof%0(%1)@YSII_Ag-1;_:(%2=_Y_ITER_ARRAY:%3(%4)@YSII_Ag[%5])!=_Y_ITER_ARRAY_SIZE(%6);) -1;_:(%2=%3@YSII_Ag(%4,%5))!=-1;)
  209. #define _Y_ITER_C3:%0[%1]@YSII_Cg,%2[%3]@YSII_Ag[%4]={%5} _Y_ITER_C3:%0@YSII_Cg[%1],%0@YSII_Ag[%1][%4]
  210. #if !defined BOTSYNC_IS_BOT
  211. static stock
  212. YSI_g_sCallbacks = 0;
  213. #endif
  214. #if !defined BOTSYNC_IS_BOT
  215. forward Itter_OPDCInternal(playerid);
  216. #endif
  217. /*----------------------------------------------------------------------------*\
  218. Function:
  219. Itter_Create2
  220. Params:
  221. name - Itterator identifier.
  222. size0 - Number of iterators.
  223. size1 - Number of items per iterator.
  224. Return:
  225. -
  226. Notes:
  227. Creates a new array of itterator start/array pair.
  228. \*----------------------------------------------------------------------------*/
  229. // If this ever changes, update the size reference in y_users.
  230. /*#define Iter_Create2 Itter_Create2
  231. #define Itter_Create2(%1,%2,%3) \
  232. new \
  233. %1@YSII_Sg[%2] = {-1, ...}, \
  234. %1@YSII_Cg[%2] = {0}, \
  235. %1@YSII_Ag[%2][%3]*/
  236. #define IteratorArray:%1[%2]<%3> %1@YSII_Cg[%2],%1@YSII_Ag[%2][%3+1]//,%1@YSII_Rg[%2][%3+1]
  237. /*----------------------------------------------------------------------------*\
  238. Array:
  239. Iterator
  240. Notes:
  241. Creates a new itterator start/array pair.
  242. \*----------------------------------------------------------------------------*/
  243. #define Iterator:%1<%2> _Y_ITER_C3:%1@YSII_Cg,%1@YSII_Ag[(%2)+1]={(%2)*2,(%2)*2-1,...}
  244. #define iterator%0<%1> Iterator:%0<%1>
  245. /*----------------------------------------------------------------------------*\
  246. Function:
  247. Itter_Init2
  248. Params:
  249. itter - Name of the itterator array to initialise.
  250. Return:
  251. -
  252. Notes:
  253. Wrapper for Itter_InitInternal.
  254. native Iter_Init(IteratorArray:Name[]<>);
  255. \*----------------------------------------------------------------------------*/
  256. #define Iter_Init Itter_Init
  257. #define Itter_Init(%1) \
  258. Itter_InitInternal(%1@YSII_Ag,sizeof %1@YSII_Ag,sizeof %1@YSII_Ag[]-1)
  259. /*----------------------------------------------------------------------------*\
  260. Function:
  261. Itter_Create
  262. Params:
  263. name - Itterator identifier.
  264. size - Number of values.
  265. Return:
  266. -
  267. Notes:
  268. Creates a new itterator start/array pair.
  269. \*----------------------------------------------------------------------------*/
  270. // If this ever changes, update the size reference in y_users.
  271. /*#define Iter_Create Itter_Create
  272. #define Itter_Create(%1,%2) \
  273. new \
  274. %1@YSII_Sg = -1, \
  275. %1@YSII_Cg = 0, \
  276. %1@YSII_Ag[%2] = {-1, ...}*/
  277. /*----------------------------------------------------------------------------*\
  278. Function:
  279. Itter_Add
  280. Params:
  281. itter - Name of the itterator to add the data to.
  282. value - Value to add to the itterator.
  283. Return:
  284. -
  285. Notes:
  286. Wrapper for Itter_AddInternal.
  287. native Iter_Add(Iterator:Name<>, value);
  288. \*----------------------------------------------------------------------------*/
  289. #define Iter_Add Itter_Add
  290. #define Itter_Add(%1,%2) Itter_AddInternal(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag,%2,_Y_ITER_ARRAY_SIZE(%1))
  291. /*#define Iter_AddSafe Itter_AddSafe
  292. #define Itter_AddSafe(%1,%2) \
  293. Itter_AddSafeInternal(%1@YSII_Sg, %1@YSII_Cg, %1@YSII_Ag, %1@YSII_Rg, %2)*/
  294. /*----------------------------------------------------------------------------*\
  295. Function:
  296. Itter_Free
  297. Params:
  298. itter - Name of the itterator to get the first free slot in.
  299. Return:
  300. -
  301. Notes:
  302. Wrapper for Itter_FreeInternal.
  303. native Iter_Free(Iterator:Name<>);
  304. \*----------------------------------------------------------------------------*/
  305. #define Iter_Free Itter_Free
  306. #define Itter_Free(%1) Itter_FreeInternal(_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1))
  307. /*----------------------------------------------------------------------------*\
  308. Function:
  309. Itter_Remove
  310. Params:
  311. itter - Name of the itterator to remove data from.
  312. value - Data to remove.
  313. Return:
  314. -
  315. Notes:
  316. Wrapper for Itter_RemoveInternal.
  317. native Iter_Remove(Iterator:Name<>, value);
  318. \*----------------------------------------------------------------------------*/
  319. #define Iter_Remove Itter_Remove
  320. #define Itter_Remove(%1,%2) Itter_RemoveInternal(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag,%2,_Y_ITER_ARRAY_SIZE(%1))
  321. /*----------------------------------------------------------------------------*\
  322. Function:
  323. Itter_Contains
  324. Params:
  325. itter - Name of the itterator to check membership of.
  326. value - Value to check.
  327. Return:
  328. -
  329. Notes:
  330. Checks if the given value is in the given iterator.
  331. native Iter_Remove(Iterator:Name<>, value);
  332. \*----------------------------------------------------------------------------*/
  333. #define Iter_Contains Itter_Contains
  334. #define Itter_Contains(%1,%2) Itter_ContainsInternal(_Y_ITER_ARRAY:%1@YSII_Ag,%2,_Y_ITER_ARRAY_SIZE(%1))
  335. /*----------------------------------------------------------------------------*\
  336. Function:
  337. Itter_SafeRemove
  338. Params:
  339. itter - Name of the itterator to remove data from.
  340. value - Data to remove.
  341. next - Container for the pointer to the next element.
  342. Return:
  343. -
  344. Notes:
  345. Wrapper for Itter_SafeRemoveInternal. Common use:
  346. Iter_SafeRemove(iter, i, i);
  347. native Iter_SafeRemove(Iterator:Name<>, value, &next);
  348. \*----------------------------------------------------------------------------*/
  349. #define Iter_SafeRemove Itter_SafeRemove
  350. #define Itter_SafeRemove(%1,%2,%3) Itter_SafeRemoveInternal(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag,%2,%3,_Y_ITER_ARRAY_SIZE(%1))
  351. /*----------------------------------------------------------------------------*\
  352. Function:
  353. Itter_Random
  354. Params:
  355. itter - Name of the itterator to get a random slot from.
  356. Return:
  357. -
  358. Notes:
  359. Wrapper for Itter_RandomInternal.
  360. native Iter_Random(Iterator:Name<>);
  361. \*----------------------------------------------------------------------------*/
  362. #define Iter_Random Itter_Random
  363. #define Itter_Random(%1) Itter_RandomInternal(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1))
  364. /*----------------------------------------------------------------------------*\
  365. Function:
  366. Itter_Debug
  367. Params:
  368. itter - Name of the itterator to output debug information from.
  369. Return:
  370. -
  371. Notes:
  372. Wrapper for Itter_ShowArray.
  373. \*----------------------------------------------------------------------------*/
  374. //#define Iter_Debug Itter_Debug
  375. //#define Itter_Debug(%1) Itter_ShowArray(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag)
  376. /*----------------------------------------------------------------------------*\
  377. Function:
  378. Itter_Count
  379. Params:
  380. itter - Name of the itterator to get a random slot from4.
  381. Return:
  382. -
  383. Notes:
  384. Returns the number of items in this itterator.
  385. native Iter_Count(Iterator:Name<>);
  386. \*----------------------------------------------------------------------------*/
  387. #define Iter_Count Itter_Count
  388. #define Itter_Count(%1) (_Y_ITER_ARRAY:%1@YSII_Cg)
  389. /*----------------------------------------------------------------------------*\
  390. Function:
  391. Itter_Clear
  392. Params:
  393. itter - Name of the itterator empty.
  394. Return:
  395. -
  396. Notes:
  397. Wrapper for Itter_ClearInternal.
  398. native Iter_Clear(IteratorArray:Name[]<>);
  399. \*----------------------------------------------------------------------------*/
  400. #define Iter_Clear Itter_Clear
  401. #define Itter_Clear(%1) Itter_ClearInternal(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1))
  402. /*----------------------------------------------------------------------------*\
  403. Create the internal itterators.
  404. \*----------------------------------------------------------------------------*/
  405. #if !defined BOTSYNC_IS_BOT
  406. new
  407. Iterator:Player<MAX_PLAYERS>;
  408. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  409. new
  410. Iterator:Bot<MAX_PLAYERS>,
  411. Iterator:Character<MAX_PLAYERS>;
  412. //#define NPC@YSII_Sg Bot@YSII_Sg
  413. #define NPC@YSII_Cg Bot@YSII_Cg
  414. #define NPC@YSII_Ag Bot@YSII_Ag
  415. //#define NPC@YSII_Eg Bot@YSII_Eg
  416. //#define NPC@YSII_Rg Bot@YSII_Rg
  417. #endif
  418. #endif
  419. /*----------------------------------------------------------------------------*\
  420. Variables to optimise memory usage by only having one copy of each string.
  421. Note that only strings used more than once are put here because only they
  422. have any gain to being located in only one place.
  423. \*----------------------------------------------------------------------------*/
  424. static stock
  425. YSI_gsOnPlayerConnect[] = "Itter_OnPlayerConnect",
  426. YSI_gsOnPlayerDisconnect[] = "Itter_OnPlayerDisconnect",
  427. YSI_gsOnGameModeInit[] = "Itter_OnGameModeInit",
  428. YSI_gsSpecifier@[] = "",
  429. YSI_gsSpecifier@i[] = "i";
  430. /*----------------------------------------------------------------------------*\
  431. Function:
  432. foreach
  433. Params:
  434. data - Data to itterate through.
  435. as - Variable to set value to.
  436. Return:
  437. -
  438. Notes:
  439. Not exactly the same as PHP foreach, just itterates through a list and
  440. returns the value of the current slot but uses that slot as the next index
  441. too. Variables must be in the form @YSII_<gname>S for the start index and
  442. @YSII_<gname>A for the data array where <name> is what's entered in data.
  443. \*----------------------------------------------------------------------------*/
  444. //#define foreach(%1,%2)
  445. // for (new %2 = %1@YSII_Sg; _:%2 != -1; %2 = %1@YSII_Ag[%2])
  446. #define foreach%1(%0) for(new Y_FOREACH_SECOND|||Y_FOREACH_THIRD|||%0|||)
  447. // This allows us to use "new" multiple times - stripping off ONLY whole words.
  448. #define new%0|||%9|||%1:%2||| %9|||%0|||%1|||%2|||
  449. // This one is called if the new syntax is required, but the state of "new" is
  450. // as-yet unknown. This attempts to call "%1" as a macro, if it starts with
  451. // "new" as a whole word then it will (and will also helpfully strip off the
  452. // "new" keyword for us).
  453. #define Y_FOREACH_THIRD|||%0|||%1|||%2||| %1=Y_FOREACH_FIFTH|||Y_FOREACH_FOURTH|||%1:%2|||
  454. // This is called if the "new" macro is called for a second time.
  455. #define Y_FOREACH_FOURTH|||%0=Y_FOREACH_FIFTH|||%1|||%2||| new Y_FOREACH_SIXTH;%0|||Y_FOREACH_SEVENTH|||%2|||
  456. // This is called when there are tags on the "new" declaration.
  457. #define Y_FOREACH_SEVENTH|||%9Y_FOREACH_SIXTH;%0|||%1|||%2||| new %0:%1=%0:_Y_ITER_ARRAY_SIZE(%2);_:(%1=_Y_ITER_ARRAY:%2@YSII_Ag[%1])!=_Y_ITER_ARRAY_SIZE(%2);
  458. // This is called when there aren't.
  459. #define Y_FOREACH_SIXTH;%0|||Y_FOREACH_SEVENTH|||%2||| %0=_Y_ITER_ARRAY_SIZE(%2);_:(%0=_Y_ITER_ARRAY:%2@YSII_Ag[%0])!=_Y_ITER_ARRAY_SIZE(%2);
  460. //hta:%0=hta:%2@YSII_Sg;_:%0!=-1;%0=hta:%2@YSII_Ag[%0]
  461. //#define Y_FOREACH_FOURTH|||%0=Y_FOREACH_FIFTH|||%1|||%2||| new hta:%0=hta:%2@YSII_Sg;_:%0!=-1;%0=hta:%2@YSII_Ag[%0]
  462. // Move any tags from the second half to the first half.
  463. //#define hta:%0=hta:%1:%2;_:%3!=-1;%4=hta:%5:%6[%7] %0:%1=%2;_:%1!=-1;%1=%6[%1]
  464. // This is called if "%1" didn't have "new" at the start.
  465. #define Y_FOREACH_FIFTH|||Y_FOREACH_FOURTH|||%1:%2||| _Y_ITER_ARRAY_SIZE(%2);_:(%1=_Y_ITER_ARRAY:%2@YSII_Ag[%1])!=_Y_ITER_ARRAY_SIZE(%2);
  466. //%1=%2@YSII_Sg;_:Y_FOREACH_NONEW:%1!=-1;%1=%2@YSII_Ag[%1]
  467. // This is the old version, but DON'T add "new" because that already exists from
  468. // the failed "new" macro call above.
  469. #define Y_FOREACH_SECOND|||Y_FOREACH_THIRD|||%1,%2||| %2=_Y_ITER_ARRAY_SIZE(%1);_:(%2=_Y_ITER_ARRAY:%1@YSII_Ag[%2])!=_Y_ITER_ARRAY_SIZE(%1);
  470. //#define Y_FOREACH_NONEW:new%0!=-1;new%1=%2[new%3] %0!=-1;%1=%2[%3]
  471. //#define Y_FOREACH_EIGHTH:%0[%1]@YSII_Sg;%2;%3=%4[%5]@YSII_Ag[%6] %0@YSII_Sg[%1];%2;%3=%4@YSII_Ag[%5][%6]
  472. /*----------------------------------------------------------------------------*\
  473. Function:
  474. foreachex
  475. Params:
  476. data - Data to itterate through.
  477. as - Variable to set value to.
  478. Return:
  479. -
  480. Notes:
  481. Similar to foreach but doesn't declare a new variable for the itterator.
  482. \*----------------------------------------------------------------------------*/
  483. #define foreachex(%1,%2) foreach(%2:%1)
  484. //for (%2=_Y_ITER_ARRAY_SIZE(%1);(%2=_Y_ITER_ARRAY:%1@YSII_Ag[%2])!=_Y_ITER_ARRAY_SIZE(%1);)
  485. /*----------------------------------------------------------------------------*\
  486. Function:
  487. Itter_OnPlayerConnect
  488. Params:
  489. playerid - Player who joined.
  490. Return:
  491. -
  492. Notes:
  493. Adds a player to the loop data. Now sorts the list too. Note that I found
  494. the most bizzare bug ever (I *think* it may be a compiler but, but it
  495. requires further investigation), basically it seems that multiple variables
  496. were being treated as the same variable (namely @YSII_EgotS and
  497. @YSII_CgharacterS were the same and @YSII_EgotC and @YSII_CgharacterC were the
  498. same). Adding print statements which reference these variables seem to fix
  499. the problem, and I've tried to make sure that the values will never actually
  500. get printed.
  501. \*----------------------------------------------------------------------------*/
  502. #if !defined BOTSYNC_IS_BOT
  503. public OnPlayerConnect(playerid)
  504. {
  505. #if defined _FOREACH_BOT
  506. if (!IsPlayerNPC(playerid))
  507. {
  508. Itter_Add(Player, playerid);
  509. }
  510. #if !defined FOREACH_NO_BOTS
  511. else
  512. {
  513. Itter_Add(Bot, playerid);
  514. }
  515. #pragma tabsize 4
  516. Itter_Add(Character, playerid);
  517. #endif
  518. #else
  519. Itter_Add(Player, playerid);
  520. #endif
  521. if (YSI_g_sCallbacks & 2)
  522. {
  523. CallLocalFunction(YSI_gsOnPlayerConnect, YSI_gsSpecifier@i, playerid);
  524. }
  525. return 1;
  526. }
  527. #if defined _ALS_OnPlayerConnect
  528. #undef OnPlayerConnect
  529. #else
  530. #define _ALS_OnPlayerConnect
  531. #endif
  532. #define OnPlayerConnect Itter_OnPlayerConnect
  533. forward OnPlayerConnect(playerid);
  534. #endif
  535. /*----------------------------------------------------------------------------*\
  536. Function:
  537. Itter_OnFilterScriptInit
  538. Params:
  539. -
  540. Return:
  541. -
  542. Notes:
  543. Fixes a bug where callbacks are not detected when "loadfs" is used after the
  544. GM has already started. If this is a GM this is just never used called.
  545. \*----------------------------------------------------------------------------*/
  546. #if !defined BOTSYNC_IS_BOT
  547. public OnFilterScriptInit()
  548. {
  549. if (funcidx(YSI_gsOnPlayerDisconnect) != -1)
  550. {
  551. YSI_g_sCallbacks |= 1;
  552. }
  553. if (funcidx(YSI_gsOnPlayerConnect) != -1)
  554. {
  555. YSI_g_sCallbacks |= 2;
  556. }
  557. CallLocalFunction("Itter_OnFilterScriptInit", YSI_gsSpecifier@);
  558. return 1;
  559. }
  560. #if defined _ALS_OnFilterScriptInit
  561. #undef OnFilterScriptInit
  562. #else
  563. #define _ALS_OnFilterScriptInit
  564. #endif
  565. #define OnFilterScriptInit Itter_OnFilterScriptInit
  566. forward OnFilterScriptInit();
  567. #endif
  568. /*----------------------------------------------------------------------------*\
  569. Function:
  570. Itter_OnGameModeInit
  571. Params:
  572. -
  573. Return:
  574. -
  575. Notes:
  576. There are WIERD bugs in this script, seemingly caused by the compiler, so
  577. this hopefully fixes them. The OnFilterScriptInit code is written to be
  578. very fast by utilising the internal array structure instead of the regular
  579. Add functions.
  580. \*----------------------------------------------------------------------------*/
  581. #if !defined BOTSYNC_IS_BOT
  582. public OnGameModeInit()
  583. {
  584. // Clear everything.
  585. if (funcidx(YSI_gsOnPlayerDisconnect) != -1)
  586. {
  587. YSI_g_sCallbacks |= 1;
  588. }
  589. if (funcidx(YSI_gsOnPlayerConnect) != -1)
  590. {
  591. YSI_g_sCallbacks |= 2;
  592. }
  593. if (!Player@YSII_Cg)
  594. {
  595. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  596. CallLocalFunction(YSI_gsOnGameModeInit, YSI_gsSpecifier@, Bot@YSII_Cg, Character@YSII_Cg, Player@YSII_Cg);
  597. #else
  598. CallLocalFunction(YSI_gsOnGameModeInit, YSI_gsSpecifier@, Player@YSII_Cg);
  599. #endif
  600. return 1;
  601. }
  602. // Do the forward iterator list.
  603. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  604. Bot@YSII_Cg = _Y_ITER_C3:0;
  605. Bot@YSII_Ag[MAX_PLAYERS] = MAX_PLAYERS;
  606. Character@YSII_Ag[MAX_PLAYERS] = MAX_PLAYERS;
  607. Character@YSII_Cg = _Y_ITER_C3:0;
  608. new
  609. lastBot = MAX_PLAYERS,
  610. lastCharacter = MAX_PLAYERS;
  611. #endif
  612. Player@YSII_Cg = _Y_ITER_C3:0;
  613. Player@YSII_Ag[MAX_PLAYERS] = MAX_PLAYERS;
  614. new
  615. lastPlayer = MAX_PLAYERS;
  616. for (new i = 0; i != MAX_PLAYERS; ++i)
  617. {
  618. if (IsPlayerConnected(i))
  619. {
  620. #if defined _FOREACH_BOT
  621. // Had to do "if ! else" due to compile options.
  622. if (!IsPlayerNPC(i))
  623. {
  624. Player@YSII_Ag[lastPlayer] = i;
  625. ++Player@YSII_Cg;
  626. lastPlayer = i;
  627. }
  628. #if !defined FOREACH_NO_BOTS
  629. else
  630. {
  631. Bot@YSII_Ag[lastBot] = i;
  632. ++Bot@YSII_Cg;
  633. lastBot = i;
  634. }
  635. #pragma tabsize 4
  636. Character@YSII_Ag[lastCharacter] = i;
  637. ++Character@YSII_Cg;
  638. lastCharacter = i;
  639. #endif
  640. #else
  641. Player@YSII_Ag[lastPlayer] = i;
  642. ++Player@YSII_Cg;
  643. lastPlayer = i;
  644. #endif
  645. }
  646. else
  647. {
  648. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  649. Bot@YSII_Ag[i] = MAX_PLAYERS + 1;
  650. //Bot@YSII_Rg[i] = -1;
  651. Character@YSII_Ag[i] = MAX_PLAYERS + 1;
  652. //Character@YSII_Rg[i] = -1;
  653. #endif
  654. Player@YSII_Ag[i] = MAX_PLAYERS + 1;
  655. //Player@YSII_Rg[i] = -1;
  656. }
  657. }
  658. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  659. Bot@YSII_Ag[lastPlayer] = MAX_PLAYERS;
  660. Character@YSII_Ag[lastPlayer] = MAX_PLAYERS;
  661. #endif
  662. Player@YSII_Ag[lastPlayer] = MAX_PLAYERS;
  663. CallLocalFunction(YSI_gsOnGameModeInit, YSI_gsSpecifier@);
  664. return 1;
  665. }
  666. #if defined _ALS_OnGameModeInit
  667. #undef OnGameModeInit
  668. #else
  669. #define _ALS_OnGameModeInit
  670. #endif
  671. #define OnGameModeInit Itter_OnGameModeInit
  672. forward OnGameModeInit();
  673. #endif
  674. /*----------------------------------------------------------------------------*\
  675. Function:
  676. Itter_OnPlayerDisconnect
  677. Params:
  678. playerid - Player who left.
  679. Return:
  680. -
  681. Notes:
  682. Removes a player from the loop data. No longer uses "hook" to ENSURE that
  683. this is always last. Previously I think that the order of evaluation in
  684. y_hooks meant that this got called before the user "OnPlayerDisconnect".
  685. \*----------------------------------------------------------------------------*/
  686. #if !defined BOTSYNC_IS_BOT
  687. public OnPlayerDisconnect(playerid, reason)
  688. {
  689. if (YSI_g_sCallbacks & 1)
  690. {
  691. CallLocalFunction(YSI_gsOnPlayerDisconnect, "ii", playerid, reason);
  692. }
  693. SetTimerEx("Itter_OPDCInternal", 0, false, YSI_gsSpecifier@i, playerid);
  694. return 1;
  695. }
  696. #if defined _ALS_OnPlayerDisconnect
  697. #undef OnPlayerDisconnect
  698. #else
  699. #define _ALS_OnPlayerDisconnect
  700. #endif
  701. #define OnPlayerDisconnect Itter_OnPlayerDisconnect
  702. forward OnPlayerDisconnect(playerid, reason);
  703. #endif
  704. /*----------------------------------------------------------------------------*\
  705. Function:
  706. Itter_OPDCInternal
  707. Params:
  708. playerid - Player who left.
  709. Return:
  710. -
  711. Notes:
  712. Called AFTER "OnPlayerDisconnect" so that using "Kick" inside a "foreach"
  713. loop doesn't crash the server due to an OOB error.
  714. \*----------------------------------------------------------------------------*/
  715. #if !defined BOTSYNC_IS_BOT
  716. public Itter_OPDCInternal(playerid)
  717. {
  718. if (IsPlayerConnected(playerid))
  719. {
  720. return;
  721. }
  722. #if defined _FOREACH_BOT
  723. if (!IsPlayerNPC(playerid))
  724. {
  725. Itter_Remove(Player, playerid);
  726. }
  727. #if !defined FOREACH_NO_BOTS
  728. else
  729. {
  730. Itter_Remove(Bot, playerid);
  731. }
  732. #pragma tabsize 4
  733. Itter_Remove(Character, playerid);
  734. #endif
  735. #else
  736. Itter_Remove(Player, playerid);
  737. #endif
  738. }
  739. #endif
  740. /*----------------------------------------------------------------------------*\
  741. Function:
  742. Itter_ShowArray
  743. Params:
  744. start - Itterator start point.
  745. members[] - Itterator contents.
  746. size - Number of itterator values
  747. Return:
  748. -
  749. Notes:
  750. Pure debug function. Has regular prints not debug prints
  751. as it's only called when debug is on.
  752. \*----------------------------------------------------------------------------*/
  753. /*stock
  754. Itter_ShowArray(size, members[])
  755. {
  756. static
  757. sString[61];
  758. new
  759. i,
  760. j = 10;
  761. printf("Start: %d", start);
  762. printf("Size: %d", size);
  763. while (i < size)
  764. {
  765. sString[0] = '\0';
  766. while (i < j && i < size)
  767. {
  768. format(sString, sizeof (sString), "%s, %d", sString, members[i]);
  769. i++;
  770. }
  771. printf("Array (%d): %s", j, sString);
  772. j += 10;
  773. }
  774. }*/
  775. /*----------------------------------------------------------------------------*\
  776. Function:
  777. Itter_RandomInternal
  778. Params:
  779. count - Number of items in the itterator.
  780. array[] - Itterator data.
  781. size - Size of the iterator.
  782. Return:
  783. -
  784. Notes:
  785. Returns a random value from an iterator.
  786. \*----------------------------------------------------------------------------*/
  787. stock
  788. Itter_RandomInternal(count, array[], size)
  789. {
  790. if (count == 0)
  791. {
  792. return -1;
  793. }
  794. new
  795. rnd = random(count),
  796. cur = array[size];
  797. while (cur != size)
  798. {
  799. if (rnd-- == 0)
  800. {
  801. return cur;
  802. }
  803. cur = array[cur];
  804. }
  805. return -1;
  806. }
  807. /*----------------------------------------------------------------------------*\
  808. Function:
  809. Itter_FreeInternal
  810. Params:
  811. count - Number of items in the itterator.
  812. array[] - Itterator data.
  813. size - Size of the itterator.
  814. Return:
  815. -
  816. Notes:
  817. Finds the first free slot in the itterator. Itterators now HAVE to be
  818. sorted for this function to work correctly as it uses that fact to decide
  819. wether a slot is unused or the last one. If you want to use the slot
  820. straight after finding it the itterator will need to re-find it to add in
  821. the data.
  822. \*----------------------------------------------------------------------------*/
  823. stock
  824. Itter_FreeInternal(array[], size)
  825. {
  826. for (new i = 0; i != size; ++i)
  827. {
  828. if (array[i] > size)
  829. {
  830. return i;
  831. }
  832. }
  833. return -1;
  834. }
  835. /*----------------------------------------------------------------------------*\
  836. Function:
  837. Itter_AddInternal
  838. Params:
  839. &start - Array start index.
  840. &count - Number of items in the itterator.
  841. array[] - Itterator data.
  842. value - Item to add.
  843. Return:
  844. -
  845. Notes:
  846. Adds a value to a given itterator set. Now detects when you try and add the
  847. last item multiple times, as well as all the other items. Now simplified even
  848. further with the new internal representation.
  849. \*----------------------------------------------------------------------------*/
  850. stock
  851. Itter_AddInternal(&count, array[], value, size)
  852. {
  853. if (0 <= value < size && array[value] > size)
  854. {
  855. new
  856. last = size,
  857. next = array[last];
  858. while (next < value)
  859. {
  860. last = next;
  861. next = array[last];
  862. }
  863. array[last] = value;
  864. array[value] = next;
  865. ++count;
  866. return 1;
  867. }
  868. return 0;
  869. }
  870. /*----------------------------------------------------------------------------*\
  871. Function:
  872. Itter_RemoveInternal
  873. Params:
  874. &count - Number of items in the itterator.
  875. array[] - Itterator data.
  876. value - Item to remove.
  877. Return:
  878. -
  879. Notes:
  880. Removes a value from an itterator.
  881. \*----------------------------------------------------------------------------*/
  882. stock
  883. Itter_RemoveInternal(&count, array[], value, size)
  884. {
  885. new
  886. last;
  887. return Itter_SafeRemoveInternal(count, array, value, last, size);
  888. }
  889. /*----------------------------------------------------------------------------*\
  890. Function:
  891. Itter_SafeRemoveInternal
  892. Params:
  893. &count - Number of items in the itterator.
  894. array[] - Iterator data.
  895. back[] - Reverse iterator data.
  896. value - Item to remove.
  897. &last - Pointer in which to store the last pointer.
  898. Return:
  899. -
  900. Notes:
  901. Removes a value from an itterator safely.
  902. \*----------------------------------------------------------------------------*/
  903. stock
  904. Itter_SafeRemoveInternal(&count, array[], value, &last, size)
  905. {
  906. if (0 <= value < size && array[value] <= size)
  907. {
  908. last = size;
  909. new
  910. next = array[last];
  911. while (next != value)
  912. {
  913. last = next;
  914. next = array[last];
  915. }
  916. array[last] = array[value];
  917. array[value] = size + 1;
  918. --count;
  919. return 1;
  920. }
  921. return 0;
  922. }
  923. /*----------------------------------------------------------------------------*\
  924. Function:
  925. Itter_ContainsInternal
  926. Params:
  927. array[] - Itterator data.
  928. value - Item to check.
  929. size - Size of the iterator.
  930. Return:
  931. -
  932. Notes:
  933. Checks if this item is in the iterator.
  934. \*----------------------------------------------------------------------------*/
  935. stock
  936. Itter_ContainsInternal(array[], value, size)
  937. {
  938. return 0 <= value < size && array[value] <= size;
  939. }
  940. /*----------------------------------------------------------------------------*\
  941. Function:
  942. Itter_ClearInternal
  943. Params:
  944. &count - Number of items in the itterator.
  945. array[] - Itterator data.
  946. size - Size of the iterator.
  947. Return:
  948. -
  949. Notes:
  950. Resets an iterator.
  951. \*----------------------------------------------------------------------------*/
  952. stock
  953. Itter_ClearInternal(&count, array[], size)
  954. {
  955. for (new i = 0, t = size + 1; i < size; ++i)
  956. {
  957. array[i] = t;
  958. }
  959. array[size] = size;
  960. count = 0;
  961. }
  962. /*----------------------------------------------------------------------------*\
  963. Function:
  964. Itter_InitInternal
  965. Params:
  966. array[][] - Itterator array to initialise.
  967. s0 - Size of first dimension.
  968. s1 - Size of second dimension.
  969. Return:
  970. -
  971. Notes:
  972. Multi-dimensional arrays can't be initialised at compile time, so need to be
  973. done at run time, which is slightly annoying.
  974. \*----------------------------------------------------------------------------*/
  975. stock
  976. Itter_InitInternal(arr[][], s0, s1)
  977. {
  978. for (new i = 0, t = s1 + 1; i < s0; ++i)
  979. {
  980. for (new j = 0; j < s1; ++j)
  981. {
  982. arr[i][j] = t;
  983. }
  984. arr[i][s1] = s1;
  985. }
  986. }
  987. /*----------------------------------------------------------------------------*\
  988. Function:
  989. Itter_PrevInternal
  990. Params:
  991. array[] - Itterator data.
  992. size - Size of the iterator.
  993. slot - The current slot.
  994. Return:
  995. -
  996. Notes:
  997. Gets the element in an iterator that points to the current element.
  998. \*----------------------------------------------------------------------------*/
  999. stock
  1000. Itter_PrevInternal(array[], size, slot)
  1001. {
  1002. if (0 <= slot <= size && array[slot] <= size)
  1003. {
  1004. new
  1005. last = size;
  1006. //for (new next = array[size]; next != size; next = array[next])
  1007. for ( ; ; )
  1008. {
  1009. new
  1010. next = array[last];
  1011. if (next == slot)
  1012. {
  1013. return last;
  1014. }
  1015. last = next;
  1016. }
  1017. }
  1018. return size;
  1019. }
  1020. /*----------------------------------------------------------------------------*\
  1021. Function:
  1022. Iter_Begin
  1023. Params:
  1024. iter - Name of the iterator to get the start of.
  1025. Return:
  1026. -
  1027. Notes:
  1028. Gets a point BEFORE the start of the iterator (the theoretical beginning).
  1029. \*----------------------------------------------------------------------------*/
  1030. #define Iter_Begin(%1) (_Y_ITER_ARRAY_SIZE(%1))
  1031. #define Itter_Begin(%1) (_Y_ITER_ARRAY_SIZE(%1))
  1032. /*----------------------------------------------------------------------------*\
  1033. Function:
  1034. Iter_End
  1035. Params:
  1036. iter - Name of the iterator to
  1037. Return:
  1038. -
  1039. Notes:
  1040. Gets a point AFTER the end of the iterator (think "MAX_PLAYERS").
  1041. \*----------------------------------------------------------------------------*/
  1042. #define Iter_End(%1) (_Y_ITER_ARRAY_SIZE(%1))
  1043. #define Itter_End(%1) (_Y_ITER_ARRAY_SIZE(%1))
  1044. /*----------------------------------------------------------------------------*\
  1045. Function:
  1046. Iter_First
  1047. Params:
  1048. iter - Name of the iterator to
  1049. Return:
  1050. -
  1051. Notes:
  1052. Gets the first element in an iterator.
  1053. \*----------------------------------------------------------------------------*/
  1054. #define Iter_First(%1) (_Y_ITER_ARRAY:%1@YSII_Ag[_Y_ITER_ARRAY_SIZE(%1)])
  1055. #define Itter_First(%1) (_Y_ITER_ARRAY:%1@YSII_Ag[_Y_ITER_ARRAY_SIZE(%1)])
  1056. /*----------------------------------------------------------------------------*\
  1057. Function:
  1058. Iter_Last
  1059. Params:
  1060. iter - Name of the iterator to
  1061. Return:
  1062. -
  1063. Notes:
  1064. Gets the last element in an iterator.
  1065. \*----------------------------------------------------------------------------*/
  1066. #define Iter_Last(%1) Itter_PrevInternal(_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1),_Y_ITER_ARRAY_SIZE(%1))
  1067. #define Itter_Last(%1) Itter_PrevInternal(_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1),_Y_ITER_ARRAY_SIZE(%1))
  1068. /*----------------------------------------------------------------------------*\
  1069. Function:
  1070. Iter_Next
  1071. Params:
  1072. iter - Name of the iterator to
  1073. Return:
  1074. -
  1075. Notes:
  1076. Gets the element in an interator after the current one.
  1077. \*----------------------------------------------------------------------------*/
  1078. #define Iter_Next(%1,%2) (_Y_ITER_ARRAY:%1@YSII_Ag[(%2)])
  1079. #define Itter_Next(%1,%2) (_Y_ITER_ARRAY:%1@YSII_Ag[(%2)])
  1080. /*----------------------------------------------------------------------------*\
  1081. Function:
  1082. Iter_Prev
  1083. Params:
  1084. iter - Name of the iterator to
  1085. Return:
  1086. -
  1087. Notes:
  1088. Gets the element in an iterator before the current one. Slow.
  1089. \*----------------------------------------------------------------------------*/
  1090. #define Iter_Prev(%1,%2) Itter_PrevInternal(_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1),(%2))
  1091. #define Itter_Prev(%1,%2) Itter_PrevInternal(_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1),(%2))