xFernando_xD

FOREACH

Oct 13th, 2011
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.67 KB | None | 0 0
  1. #define _FOREACH_LOCAL_VERSION 2
  2.  
  3. // Foreach is testing us.
  4. #if defined _FOREACH_INC_TEST
  5. #define _FOREACH_CUR_VERSION _FOREACH_LOCAL_VERSION
  6. #endinput
  7. #endif
  8. #if !defined _FOREACH_NO_TEST
  9. #define _FOREACH_INC_TEST
  10. #tryinclude <YSI\y_iterate>
  11. #undef _FOREACH_INC_TEST
  12. // <y_iterate> exists - test which is newer.
  13. #if defined _inc_y_iterate
  14. #if !defined _FOREACH_CUR_VERSION
  15. // y_iterate exists, but it's an old version - don't try use this
  16. // system or the variables will conflict.
  17. #endinput
  18. #endif
  19. #if _FOREACH_CUR_VERSION > _FOREACH_LOCAL_VERSION
  20. // y_iterate is newer.
  21. #undef _inc_y_iterate
  22. #define _FOREACH_NO_TEST
  23. #include <YSI\y_iterate>
  24. #endinput
  25. #endif
  26. #endif
  27. #endif
  28.  
  29. #if !defined _samp_included
  30. #error "Please include a_samp or a_npc before foreach"
  31. #endif
  32.  
  33. #if defined SendChat || defined FOREACH_NO_PLAYERS
  34. #define BOTSYNC_IS_BOT (true)
  35. #endif
  36.  
  37. #if defined IsPlayerNPC
  38. #define _FOREACH_BOT
  39. #endif
  40.  
  41. #if !defined BOTSYNC_IS_BOT
  42. static
  43. bool:YSI_g_OPC = false,
  44. bool:YSI_g_OPDC = false;
  45. #endif
  46.  
  47. #if defined YSI_ITTER_NO_SORT
  48. #error YSI_ITTER_NO_SORT is no longer supported by foreach.
  49. #endif
  50.  
  51. /*----------------------------------------------------------------------------*-
  52. Function:
  53. Itter_Create2
  54. Params:
  55. name - Itterator identifier.
  56. size0 - Number of iterators.
  57. size1 - Number of items per iterator.
  58. Return:
  59. -
  60. Notes:
  61. Creates a new array of itterator start/array pair.
  62. -*----------------------------------------------------------------------------*/
  63.  
  64. #define Iter_Create2 Itter_Create2
  65. #define Itter_Create2(%1,%2,%3) \
  66. new \
  67. YSI_gS%1[%2] = {-1, ...}, \
  68. YSI_gC%1[%2] = {0}, \
  69. YSI_gA%1[%2][%3]
  70.  
  71. #define IteratorArray:%1[%2]<%3> \
  72. YSI_gS%1[%2] = {-1, ...}, \
  73. YSI_gC%1[%2] = {0}, \
  74. YSI_gA%1[%2][%3]
  75.  
  76. /*----------------------------------------------------------------------------*-
  77. Function:
  78. Itter_Init2
  79. Params:
  80. itter - Name of the itterator array to initialise.
  81. Return:
  82. -
  83. Notes:
  84. Wrapper for Itter_InitInternal.
  85.  
  86. native Iter_Init(IteratorArray:Name[]<>);
  87.  
  88. -*----------------------------------------------------------------------------*/
  89.  
  90. #define Iter_Init Itter_Init
  91. #define Itter_Init(%1) \
  92. Itter_InitInternal(YSI_gA%1, sizeof (YSI_gA%1), sizeof (YSI_gA%1[]))
  93.  
  94. /*----------------------------------------------------------------------------*-
  95. Function:
  96. Itter_Create
  97. Params:
  98. name - Itterator identifier.
  99. size - Number of values.
  100. Return:
  101. -
  102. Notes:
  103. Creates a new itterator start/array pair.
  104. -*----------------------------------------------------------------------------*/
  105.  
  106. #define Iter_Create Itter_Create
  107. #define Itter_Create(%1,%2) \
  108. new \
  109. YSI_gS%1 = -1, \
  110. YSI_gC%1 = 0, \
  111. YSI_gA%1[%2] = {-1, ...}
  112.  
  113. /*----------------------------------------------------------------------------*-
  114. Array:
  115. Iterator
  116. Notes:
  117. Creates a new itterator start/array pair.
  118. -*----------------------------------------------------------------------------*/
  119.  
  120. #define Iterator:%1<%2> \
  121. YSI_gS%1 = -1, \
  122. YSI_gC%1 = 0, \
  123. YSI_gA%1[%2] = {-1, ...}
  124.  
  125. /*----------------------------------------------------------------------------*-
  126. Function:
  127. Itter_Add
  128. Params:
  129. itter - Name of the itterator to add the data to.
  130. value - Value to add to the itterator.
  131. Return:
  132. -
  133. Notes:
  134. Wrapper for Itter_AddInternal.
  135.  
  136. native Iter_Add(Iterator:Name<>, value);
  137.  
  138. -*----------------------------------------------------------------------------*/
  139.  
  140. #define Iter_Add Itter_Add
  141. #define Itter_Add(%1,%2) \
  142. Itter_AddInternal(YSI_gS%1, YSI_gC%1, YSI_gA%1, %2)
  143.  
  144. /*----------------------------------------------------------------------------*-
  145. Function:
  146. Itter_Free
  147. Params:
  148. itter - Name of the itterator to get the first free slot in.
  149. Return:
  150. -
  151. Notes:
  152. Wrapper for Itter_FreeInternal.
  153.  
  154. native Iter_Free(Iterator:Name<>);
  155.  
  156. -*----------------------------------------------------------------------------*/
  157.  
  158. #define Iter_Free Itter_Free
  159. #define Itter_Free(%1) \
  160. Itter_FreeInternal(YSI_gS%1, YSI_gC%1, YSI_gA%1, sizeof (YSI_gA%1))
  161.  
  162. /*----------------------------------------------------------------------------*-
  163. Function:
  164. Itter_Remove
  165. Params:
  166. itter - Name of the itterator to remove data from.
  167. value - Data to remove.
  168. Return:
  169. -
  170. Notes:
  171. Wrapper for Itter_RemoveInternal.
  172.  
  173. native Iter_Remove(Iterator:Name<>, value);
  174.  
  175. -*----------------------------------------------------------------------------*/
  176.  
  177. #define Iter_Remove Itter_Remove
  178. #define Itter_Remove(%1,%2) \
  179. Itter_RemoveInternal(YSI_gS%1, YSI_gC%1, YSI_gA%1, %2)
  180.  
  181. /*----------------------------------------------------------------------------*-
  182. Function:
  183. Itter_Random
  184. Params:
  185. itter - Name of the itterator to get a random slot from.
  186. Return:
  187. -
  188. Notes:
  189. Wrapper for Itter_RandomInternal.
  190.  
  191. native Iter_Random(Iterator:Name<>);
  192.  
  193. -*----------------------------------------------------------------------------*/
  194.  
  195. #define Iter_Random Itter_Random
  196. #define Itter_Random(%1) \
  197. Itter_RandomInternal(YSI_gS%1, YSI_gC%1, YSI_gA%1)
  198.  
  199. /*----------------------------------------------------------------------------*-
  200. Function:
  201. Itter_Debug
  202. Params:
  203. itter - Name of the itterator to output debug information from.
  204. Return:
  205. -
  206. Notes:
  207. Wrapper for Itter_ShowArray.
  208. -*----------------------------------------------------------------------------*/
  209.  
  210. #define Iter_Debug Itter_Debug
  211. #define Itter_Debug(%1) \
  212. Itter_ShowArray(YSI_gS%1, YSI_gA%1, YSI_gC%1)
  213.  
  214. /*----------------------------------------------------------------------------*-
  215. Function:
  216. Itter_Count
  217. Params:
  218. itter - Name of the itterator to get a random slot from4.
  219. Return:
  220. -
  221. Notes:
  222. Returns the number of items in this itterator.
  223.  
  224. native Iter_Count(Iterator:Name<>);
  225.  
  226. -*----------------------------------------------------------------------------*/
  227.  
  228. #define Iter_Count Itter_Count
  229. #define Itter_Count(%1) \
  230. YSI_gC%1
  231.  
  232. /*----------------------------------------------------------------------------*-
  233. Function:
  234. Itter_Clear
  235. Params:
  236. itter - Name of the itterator empty.
  237. Return:
  238. -
  239. Notes:
  240. Wrapper for Itter_ClearInternal.
  241.  
  242. native Iter_Clear(IteratorArray:Name[]<>);
  243.  
  244. -*----------------------------------------------------------------------------*/
  245.  
  246. #define Iter_Clear Itter_Clear
  247. #define Itter_Clear(%1) \
  248. Itter_ClearInternal(YSI_gS%1, YSI_gC%1, YSI_gA%1)
  249.  
  250. /*----------------------------------------------------------------------------*-
  251. Create the internal itterators.
  252. -*----------------------------------------------------------------------------*/
  253.  
  254. #if !defined BOTSYNC_IS_BOT
  255. new
  256. Iterator:Player<MAX_PLAYERS>;
  257.  
  258. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  259. new
  260. Iterator:Bot<MAX_PLAYERS>,
  261. Iterator:Character<MAX_PLAYERS>;
  262.  
  263. #define YSI_gNPCS YSI_gBotS
  264. #define YSI_gNPCC YSI_gBotC
  265. #define YSI_gNPCA YSI_gBotA
  266. #endif
  267. #endif
  268.  
  269. /*----------------------------------------------------------------------------*-
  270. Function:
  271. foreach
  272. Params:
  273. data - Data to itterate through.
  274. as - Variable to set value to.
  275. Return:
  276. -
  277. Notes:
  278. Not exactly the same as PHP foreach, just itterates through a list and
  279. returns the value of the current slot but uses that slot as the next index
  280. too. Variables must be in the form YSI_g<name>S for the start index and
  281. YSI_g<name>A for the data array where <name> is what's entered in data.
  282. -*----------------------------------------------------------------------------*/
  283.  
  284. #define foreach(%1,%2) \
  285. for (new %2 = YSI_gS%1; _:%2 != -1; %2 = YSI_gA%1[%2])
  286.  
  287. /*----------------------------------------------------------------------------*-
  288. Function:
  289. foreachex
  290. Params:
  291. data - Data to itterate through.
  292. as - Variable to set value to.
  293. Return:
  294. -
  295. Notes:
  296. Similar to foreach but doesn't declare a new variable for the itterator.
  297. -*----------------------------------------------------------------------------*/
  298.  
  299. #define foreachex(%1,%2) \
  300. for (%2 = YSI_gS%1; _:%2 != -1; %2 = YSI_gA%1[%2])
  301.  
  302. /*----------------------------------------------------------------------------*-
  303. Function:
  304. Itter_OnPlayerConnect
  305. Params:
  306. playerid - Player who joined.
  307. Return:
  308. -
  309. Notes:
  310. Adds a player to the loop data. Now sorts the list too. Note that I found
  311. the most bizzare bug ever (I *think* it may be a compiler but, but it
  312. requires further investigation), basically it seems that multiple variables
  313. were being treated as the same variable (namely YSI_gBotS and
  314. YSI_gCharacterS were the same and YSI_gBotC and YSI_gCharacterC were the
  315. same). Adding print statements which reference these variables seem to fix
  316. the problem, and I've tried to make sure that the values will never actually
  317. get printed.
  318. -*----------------------------------------------------------------------------*/
  319.  
  320. #if !defined BOTSYNC_IS_BOT
  321. public
  322. OnPlayerConnect(playerid)
  323. {
  324. #if defined _FOREACH_BOT
  325. if (!IsPlayerNPC(playerid))
  326. {
  327. Itter_Add(Player, playerid);
  328. }
  329. #if !defined FOREACH_NO_BOTS
  330. else
  331. {
  332. Itter_Add(Bot, playerid);
  333. }
  334. #pragma tabsize 4
  335. Itter_Add(Character, playerid);
  336. #endif
  337. #else
  338. Itter_Add(Player, playerid);
  339. #endif
  340. if (YSI_g_OPC)
  341. {
  342. return CallLocalFunction("Itter_OnPlayerConnect", "i", playerid);
  343. }
  344. return 1;
  345. }
  346.  
  347. #if defined _ALS_OnPlayerConnect
  348. #undef OnPlayerConnect
  349. #else
  350. #define _ALS_OnPlayerConnect
  351. #endif
  352. #define OnPlayerConnect Itter_OnPlayerConnect
  353.  
  354. forward
  355. Itter_OnPlayerConnect(playerid);
  356. #endif
  357.  
  358. /*----------------------------------------------------------------------------*-
  359. Function:
  360. Itter_OnGameModeInit
  361. Params:
  362. -
  363. Return:
  364. -
  365. Notes:
  366. There are WIERD bugs in this script, seemingly caused by the compiler, so
  367. this hopefully fixes them. The OnFilterScriptInit code is written to be
  368. very fast by utilising the internal array structure instead of the regular
  369. Add functions.
  370. -*----------------------------------------------------------------------------*/
  371.  
  372. #if !defined BOTSYNC_IS_BOT
  373. #if defined FILTERSCRIPT
  374. public
  375. OnFilterScriptInit()
  376. {
  377. if (YSI_gCPlayer)
  378. {
  379. print("foreach error: Something went wrong again! Please tell Y_less");
  380. // Try reset.
  381. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  382. printf("%d", YSI_gSBot);
  383. printf("%d", YSI_gCBot);
  384. printf("%d", YSI_gSCharacter);
  385. printf("%d", YSI_gCCharacter);
  386.  
  387. #endif
  388. printf("%d", YSI_gSPlayer);
  389. printf("%d", YSI_gCPlayer);
  390. }
  391. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  392. new
  393. lastBot = -1,
  394. lastCharacter = -1;
  395. #endif
  396. new
  397. lastPlayer = -1;
  398. for (new i = 0; i != MAX_PLAYERS; ++i)
  399. {
  400. if (IsPlayerConnected(i))
  401. {
  402. #if defined _FOREACH_BOT
  403. if (!IsPlayerNPC(i))
  404. {
  405. if (lastPlayer == -1)
  406. {
  407. YSI_gSPlayer = i;
  408. }
  409. else
  410. {
  411. YSI_gAPlayer[lastPlayer] = i;
  412. }
  413. ++YSI_gCPlayer;
  414. lastPlayer = i;
  415. }
  416. #if !defined FOREACH_NO_BOTS
  417. else
  418. {
  419. if (lastBot == -1)
  420. {
  421. YSI_gSBot = i;
  422. }
  423. else
  424. {
  425. YSI_gABot[lastBot] = i;
  426. }
  427. ++YSI_gCBot;
  428. lastBot = i;
  429. }
  430. #pragma tabsize 4
  431. if (lastCharacter == -1)
  432. {
  433. YSI_gSCharacter = i;
  434. }
  435. else
  436. {
  437. YSI_gACharacter[lastCharacter] = i;
  438. }
  439. ++YSI_gCCharacter;
  440. lastCharacter = i;
  441. #endif
  442. #else
  443. if (lastPlayer == -1)
  444. {
  445. YSI_gSPlayer = i;
  446. }
  447. else
  448. {
  449. YSI_gAPlayer[lastPlayer] = i;
  450. }
  451. ++YSI_gCPlayer;
  452. lastPlayer = i;
  453. #endif
  454. }
  455. }
  456. YSI_g_OPC = (funcidx("Itter_OnPlayerConnect") != -1);
  457. YSI_g_OPDC = (funcidx("Itter_OnPlayerDisconnect") != -1);
  458. CallLocalFunction("Itter_OnFilterScriptInit", "");
  459. }
  460.  
  461. #if defined _ALS_OnFilterScriptInit
  462. #undef OnFilterScriptInit
  463. #else
  464. #define _ALS_OnFilterScriptInit
  465. #endif
  466. #define OnFilterScriptInit Itter_OnFilterScriptInit
  467.  
  468. forward Itter_OnFilterScriptInit();
  469. #else
  470. public
  471. OnGameModeInit()
  472. {
  473. if (YSI_gCPlayer)
  474. {
  475. print("foreach error: Something went wrong again! Is this a Filterscript and have you");
  476. print("foreach error: got \"#define FILTERSCRIPT\" above all your includes? Resetting...");
  477. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  478. printf("%d", YSI_gSBot);
  479. printf("%d", YSI_gCBot);
  480. printf("%d", YSI_gSCharacter);
  481. printf("%d", YSI_gCCharacter);
  482. YSI_gCBot = 0;
  483. YSI_gCCharacter = 0;
  484. YSI_gSBot = -1;
  485. YSI_gSCharacter = -1;
  486. #endif
  487. printf("%d", YSI_gSPlayer);
  488. printf("%d", YSI_gCPlayer);
  489. YSI_gCPlayer = 0;
  490. YSI_gSPlayer = -1;
  491. for (new i = 0; i != MAX_PLAYERS; ++i)
  492. {
  493. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  494. YSI_gABot[i] = -1;
  495. YSI_gACharacter[i] = -1;
  496. #endif
  497. YSI_gAPlayer[i] = -1;
  498. }
  499. }
  500. YSI_g_OPC = (funcidx("Itter_OnPlayerConnect") != -1);
  501. YSI_g_OPDC = (funcidx("Itter_OnPlayerDisconnect") != -1);
  502. CallLocalFunction("Itter_OnGameModeInit", "");
  503. }
  504.  
  505. #if defined _ALS_OnGameModeInit
  506. #undef OnGameModeInit
  507. #else
  508. #define _ALS_OnGameModeInit
  509. #endif
  510. #define OnGameModeInit Itter_OnGameModeInit
  511.  
  512. forward
  513. Itter_OnGameModeInit();
  514. #endif
  515. #endif
  516.  
  517. /*----------------------------------------------------------------------------*-
  518. Function:
  519. Itter_OnPlayerDisconnect
  520. Params:
  521. playerid - Player who left.
  522. Return:
  523. -
  524. Notes:
  525. Removes a player from the loop data.
  526. -*----------------------------------------------------------------------------*/
  527.  
  528. #if !defined BOTSYNC_IS_BOT
  529. public
  530. OnPlayerDisconnect(playerid, reason)
  531. {
  532. #if defined _FOREACH_BOT
  533. if (!IsPlayerNPC(playerid))
  534. {
  535. Itter_Remove(Player, playerid);
  536. }
  537. #if !defined FOREACH_NO_BOTS
  538. else
  539. {
  540. Itter_Remove(Bot, playerid);
  541. }
  542. #pragma tabsize 4
  543. Itter_Remove(Character, playerid);
  544. #endif
  545. #else
  546. Itter_Remove(Player, playerid);
  547. #endif
  548. if (YSI_g_OPDC)
  549. {
  550. return CallLocalFunction("Itter_OnPlayerDisconnect", "ii", playerid, reason);
  551. }
  552. return 1;
  553. }
  554.  
  555. #if defined _ALS_OnPlayerDisconnect
  556. #undef OnPlayerDisconnect
  557. #else
  558. #define _ALS_OnPlayerDisconnect
  559. #endif
  560. #define OnPlayerDisconnect Itter_OnPlayerDisconnect
  561.  
  562. forward
  563. Itter_OnPlayerDisconnect(playerid, reason);
  564. #endif
  565.  
  566. /*----------------------------------------------------------------------------*-
  567. Function:
  568. Itter_ShowArray
  569. Params:
  570. start - Itterator start point.
  571. members[] - Itterator contents.
  572. size - Number of itterator values
  573. Return:
  574. -
  575. Notes:
  576. Pure debug function. Has regular prints not debug prints
  577. as it's only called when debug is on.
  578. -*----------------------------------------------------------------------------*/
  579.  
  580. stock
  581. Itter_ShowArray(start, members[], size)
  582. {
  583. static
  584. sString[61];
  585. new
  586. i,
  587. j = 10;
  588. printf("Start: %d", start);
  589. printf("Size: %d", size);
  590. while (i < size)
  591. {
  592. sString[0] = '\0';
  593. while (i < j && i < size)
  594. {
  595. format(sString, sizeof (sString), "%s, %d", sString, members[i]);
  596. i++;
  597. }
  598. printf("Array (%d): %s", j, sString);
  599. j += 10;
  600. }
  601. }
  602.  
  603. /*----------------------------------------------------------------------------*-
  604. Function:
  605. Itter_RandomInternal
  606. Params:
  607. start - Array start index.
  608. count - Number of items in the itterator.
  609. array[] - Itterator data.
  610. Return:
  611. -
  612. Notes:
  613. Returns a random value from an iterator.
  614. -*----------------------------------------------------------------------------*/
  615.  
  616. stock
  617. Itter_RandomInternal(start, count, array[])
  618. {
  619. if (count == 0)
  620. {
  621. return -1;
  622. }
  623. new
  624. rnd = random(count),
  625. cur = start;
  626. while (cur != -1)
  627. {
  628. if (rnd--)
  629. {
  630. cur = array[cur];
  631. }
  632. else
  633. {
  634. return cur;
  635. }
  636. }
  637. return -1;
  638. }
  639.  
  640. /*----------------------------------------------------------------------------*-
  641. Function:
  642. Itter_FreeInternal
  643. Params:
  644. start - Array start index.
  645. count - Number of items in the itterator.
  646. array[] - Itterator data.
  647. size - Size of the itterator.
  648. Return:
  649. -
  650. Notes:
  651. Finds the first free slot in the itterator. Itterators now HAVE to be
  652. sorted for this function to work correctly as it uses that fact to decide
  653. wether a slot is unused or the last one. If you want to use the slot
  654. straight after finding it the itterator will need to re-find it to add in
  655. the data.
  656. -*----------------------------------------------------------------------------*/
  657.  
  658. stock
  659. Itter_FreeInternal(start, count, array[], size)
  660. {
  661. if (count == size)
  662. {
  663. return -1;
  664. }
  665. else if (count == 0)
  666. {
  667. return 0;
  668. }
  669. new
  670. first = 0;
  671. while (first != -1)
  672. {
  673. if (first == start)
  674. {
  675. start = array[start];
  676. }
  677. else if (array[first] == -1)
  678. {
  679. return first;
  680. }
  681. ++first;
  682. }
  683. return -1;
  684. }
  685.  
  686. /*----------------------------------------------------------------------------*-
  687. Function:
  688. Itter_AddInternal
  689. Params:
  690. &start - Array start index.
  691. &count - Number of items in the itterator.
  692. array[] - Itterator data.
  693. value - Item to add.
  694. Return:
  695. -
  696. Notes:
  697. Adds a value to a given itterator set.
  698. -*----------------------------------------------------------------------------*/
  699.  
  700. stock
  701. Itter_AddInternal(&start, &count, array[], value)
  702. {
  703. if (array[value] != -1)
  704. {
  705. return 0;
  706. }
  707. ++count;
  708. if (start == -1)
  709. {
  710. start = value;
  711. }
  712. else if (start > value)
  713. {
  714. array[value] = start;
  715. start = value;
  716. }
  717. else
  718. {
  719. new
  720. cur = start,
  721. last;
  722. do
  723. {
  724. last = cur;
  725. cur = array[cur];
  726. if (cur > value)
  727. {
  728. array[value] = cur;
  729. array[last] = value;
  730. return 1;
  731. }
  732. }
  733. while (cur != -1);
  734. array[last] = value;
  735. }
  736. return 1;
  737. }
  738.  
  739. /*----------------------------------------------------------------------------*-
  740. Function:
  741. Itter_RemoveInternal
  742. Params:
  743. &start - Array start index.
  744. &count - Number of items in the itterator.
  745. array[] - Itterator data.
  746. value - Item to remove.
  747. Return:
  748. -
  749. Notes:
  750. Removes a value from an itterator.
  751. -*----------------------------------------------------------------------------*/
  752.  
  753. stock
  754. Itter_RemoveInternal(&start, &count, array[], value)
  755. {
  756. if (start == -1)
  757. {
  758. return 0;
  759. }
  760. if (start == value)
  761. {
  762. start = array[value];
  763. }
  764. else
  765. {
  766. new
  767. cur = start;
  768. while (array[cur] != value)
  769. {
  770. cur = array[cur];
  771. if (cur == -1)
  772. {
  773. return 0;
  774. }
  775. }
  776. array[cur] = array[value];
  777. }
  778. array[value] = -1;
  779. --count;
  780. return 1;
  781. }
  782.  
  783. /*----------------------------------------------------------------------------*-
  784. Function:
  785. Itter_ClearInternal
  786. Params:
  787. &start - Array start index.
  788. &count - Number of items in the itterator.
  789. array[] - Itterator data.
  790. Return:
  791. -
  792. Notes:
  793. Resets an iterator.
  794. -*----------------------------------------------------------------------------*/
  795.  
  796. stock
  797. Itter_ClearInternal(&start, &count, array[])
  798. {
  799. if (start != -1)
  800. {
  801. new
  802. cur = start,
  803. next = array[cur];
  804. start = -1;
  805. count = 0;
  806. while (next != -1)
  807. {
  808. array[cur] = -1;
  809. cur = next;
  810. next = array[cur];
  811. }
  812. }
  813. }
  814.  
  815. /*----------------------------------------------------------------------------*-
  816. Function:
  817. Itter_InitInternal
  818. Params:
  819. array[][] - Itterator array to initialise.
  820. s0 - Size of first dimension.
  821. s1 - Size of second dimension.
  822. Return:
  823. -
  824. Notes:
  825. Multi-dimensional arrays can't be initialised at compile time, so need to be
  826. done at run time, which is slightly annoying.
  827. -*----------------------------------------------------------------------------*/
  828.  
  829. stock
  830. Itter_InitInternal(arr[][], s0, s1)
  831. {
  832. for (new i = 0; i != s0; ++i)
  833. {
  834. for (new j = 0; j != s1; ++j)
  835. {
  836. arr[i][j] = -1;
  837. }
  838. }
  839.  
  840.  
Advertisement
Add Comment
Please, Sign In to add comment