1
0

y_playerarray.inc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #if defined _INC_y_playerarray
  2. #endinput
  3. #endif
  4. #define _INC_y_playerarray
  5. /**
  6. * <library name="y_playerarray">
  7. * <section>
  8. * Description
  9. * </section>
  10. * This code provides arrays of players who can do things. This is for support
  11. * of the text system which can take arrays of player ids, bit arrays or just a
  12. * single ID.
  13. * <section>
  14. * Version
  15. * </section>
  16. * 1.0
  17. * </library>
  18. *//** *//*
  19. Legal:
  20. Version: MPL 1.1
  21. The contents of this file are subject to the Mozilla Public License Version
  22. 1.1 the "License"; you may not use this file except in compliance with
  23. the License. You may obtain a copy of the License at
  24. http://www.mozilla.org/MPL/
  25. Software distributed under the License is distributed on an "AS IS" basis,
  26. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  27. for the specific language governing rights and limitations under the
  28. License.
  29. The Original Code is the YSI framework.
  30. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  31. Portions created by the Initial Developer are Copyright C 2011
  32. the Initial Developer. All Rights Reserved.
  33. Contributors:
  34. Y_Less
  35. koolk
  36. JoeBullet/Google63
  37. g_aSlice/Slice
  38. Misiur
  39. samphunter
  40. tianmeta
  41. maddinat0r
  42. spacemud
  43. Crayder
  44. Dayvison
  45. Ahmad45123
  46. Zeex
  47. irinel1996
  48. Yiin-
  49. Chaprnks
  50. Konstantinos
  51. Masterchen09
  52. Southclaws
  53. PatchwerkQWER
  54. m0k1
  55. paulommu
  56. udan111
  57. Thanks:
  58. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  59. ZeeX - Very productive conversations.
  60. koolk - IsPlayerinAreaEx code.
  61. TheAlpha - Danish translation.
  62. breadfish - German translation.
  63. Fireburn - Dutch translation.
  64. yom - French translation.
  65. 50p - Polish translation.
  66. Zamaroht - Spanish translation.
  67. Los - Portuguese translation.
  68. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  69. me to strive to better.
  70. Pixels^ - Running XScripters where the idea was born.
  71. Matite - Pestering me to release it and using it.
  72. Very special thanks to:
  73. Thiadmer - PAWN, whose limits continue to amaze me!
  74. Kye/Kalcor - SA:MP.
  75. SA:MP Team past, present and future - SA:MP.
  76. Optional plugins:
  77. Gamer_Z - GPS.
  78. Incognito - Streamer.
  79. Me - sscanf2, fixes2, Whirlpool.
  80. */
  81. #include "..\YSI_Internal\y_version"
  82. #include <a_samp>
  83. #include "..\YSI_Core\y_debug"
  84. #include "..\YSI_Data\y_bit"
  85. #define PA_TYPE_NONE (-1)
  86. #define PA_TYPE_BOOL (-2)
  87. #define PA_TYPE_ID (-3)
  88. #define PA_TYPE_PA (-4)
  89. #if defined _YSI_SPECIAL_DEBUG
  90. #define PS_IS_PLAYER_CONNECTED(%0) (%0 != INVALID_PLAYER_ID)
  91. #else
  92. #define PS_IS_PLAYER_CONNECTED IsPlayerConnected
  93. #endif
  94. // Redefined later on. This is just for internal use.
  95. #define PlayerArray:%0<%1> Bit:%0[%1]
  96. #define PA_INIT:%1, Bit:PA_TYPE_PA,Bit:(-1*_:%1),Bit:(-1*_:%1),
  97. stock PA_Init(Bit:a[], bool:init = false, s = bits<MAX_PLAYERS>)
  98. {
  99. P:3("PA_Init called: %i, %i, %i", _:a, _:init, s);
  100. //--s;
  101. new
  102. Bit:m = init ? (Bit:-1) : (Bit:0);
  103. a[0] = Bit:PA_TYPE_PA;
  104. while (s)
  105. {
  106. a[s--] = m;
  107. }
  108. }
  109. #define PA_FastInit(%0) %0[0]=Bit:PA_TYPE_PA
  110. #define PA_GetBit(%1,%2) (%1[((%2)>>>CELLSHIFT)+1]&Bit:(1<<((%2)&cellbits-1)))
  111. #define PA_Get(%1,%2) bool:PA_GetBit(Bit:%1,_:%2)
  112. #define PA_Let(%1,%2) %1[((%2)>>>CELLSHIFT)+1]|=Bit:(1<<((%2)&cellbits-1))
  113. #define PA_Vet(%1,%2) %1[((%2)>>>CELLSHIFT)+1]&=Bit:~(1<<((%2)&cellbits-1))
  114. #define PA_GetCount(%1) Bit_GetCount(%1[1],bits<MAX_PLAYERS>)
  115. #define PA_Slot(%0) (Bit_Slot(%0) + 1)
  116. #define PA_Mask(%0) (Bit_Mask(%0))
  117. //#define PA_Set(%0,%1,%2) ((%2)?Bit_Let(%0,(%1)):Bit_Vet(%0,(%1)))
  118. stock PA_Set(PlayerArray:d<>, slot, bool:set)
  119. {
  120. P:3("PA_Set called: %s, %i, %i", Bit_Display(Bit:d[1]), slot, _:set);
  121. if (set)
  122. {
  123. PA_Let(d, slot);
  124. return 1;
  125. }
  126. else
  127. {
  128. PA_Vet(d, slot);
  129. return 0;
  130. }
  131. }
  132. stock Iter_Func@PA(start, PlayerArray:data<>)
  133. {
  134. P:3("YSI_gAPAFunc called: %s, %i", Bit_Display(Bit:data[1]), start);
  135. ++start;
  136. YSI_gAPAFunc_loop:
  137. new
  138. cur,
  139. i = Bit_Slot(start) + 1;
  140. if ((cur = (_:data[i] & (~((1 << start) - 1)))))
  141. {
  142. new
  143. ret = ((i - 1) * cellbits) + Cell_GetLowestBit(cur);
  144. // I'd like to replace this with code which doesn't call
  145. // IsPlayerConnected and doesn't use "goto", but it avoids massive tail
  146. // recursion (well, it is tail recursion which I've inlined).
  147. if (PS_IS_PLAYER_CONNECTED(ret))
  148. {
  149. return ret;
  150. }
  151. else
  152. {
  153. //return YSI_gAPAFunc(data, ret);
  154. start = ret + 1;
  155. goto YSI_gAPAFunc_loop;
  156. }
  157. }
  158. ++i;
  159. while (i != bits<MAX_PLAYERS> + 1)
  160. {
  161. if ((cur = _:data[i]))
  162. {
  163. new
  164. ret = ((i - 1) * cellbits) + Cell_GetLowestBit(cur);
  165. if (PS_IS_PLAYER_CONNECTED(ret))
  166. {
  167. return ret;
  168. }
  169. else
  170. {
  171. //return YSI_gAPAFunc(data, ret);
  172. start = ret + 1;
  173. goto YSI_gAPAFunc_loop;
  174. }
  175. }
  176. ++i;
  177. }
  178. return -1;
  179. }
  180. #define Iterator@PA iterstart(-1)
  181. #undef PlayerArray
  182. #define PlayerArray:%0<%1> Bit:%0[bits<%1>+1]//={Bit:-1}