y_groups_setup.inc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. Legal:
  3. Version: MPL 1.1
  4. The contents of this file are subject to the Mozilla Public License Version
  5. 1.1 the "License"; you may not use this file except in compliance with
  6. the License. You may obtain a copy of the License at
  7. http://www.mozilla.org/MPL/
  8. Software distributed under the License is distributed on an "AS IS" basis,
  9. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  10. for the specific language governing rights and limitations under the
  11. License.
  12. The Original Code is the YSI framework.
  13. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  14. Portions created by the Initial Developer are Copyright C 2011
  15. the Initial Developer. All Rights Reserved.
  16. Contributors:
  17. Y_Less
  18. koolk
  19. JoeBullet/Google63
  20. g_aSlice/Slice
  21. Misiur
  22. samphunter
  23. tianmeta
  24. maddinat0r
  25. spacemud
  26. Crayder
  27. Dayvison
  28. Ahmad45123
  29. Zeex
  30. irinel1996
  31. Yiin-
  32. Chaprnks
  33. Konstantinos
  34. Masterchen09
  35. Southclaws
  36. PatchwerkQWER
  37. m0k1
  38. paulommu
  39. udan111
  40. Thanks:
  41. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  42. ZeeX - Very productive conversations.
  43. koolk - IsPlayerinAreaEx code.
  44. TheAlpha - Danish translation.
  45. breadfish - German translation.
  46. Fireburn - Dutch translation.
  47. yom - French translation.
  48. 50p - Polish translation.
  49. Zamaroht - Spanish translation.
  50. Los - Portuguese translation.
  51. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  52. me to strive to better.
  53. Pixels^ - Running XScripters where the idea was born.
  54. Matite - Pestering me to release it and using it.
  55. Very special thanks to:
  56. Thiadmer - PAWN, whose limits continue to amaze me!
  57. Kye/Kalcor - SA:MP.
  58. SA:MP Team past, present and future - SA:MP.
  59. Optional plugins:
  60. Gamer_Z - GPS.
  61. Incognito - Streamer.
  62. Me - sscanf2, fixes2, Whirlpool.
  63. */
  64. #if defined _INC_y_groups_setup
  65. #endinput
  66. #endif
  67. #define _INC_y_groups_setup
  68. #define _GROUP_LOCAL_NAME _GROUP_MAKE_TAG:e
  69. // Dummy values.
  70. #define INVALID_GROUP (Group:-1)
  71. // IF THIS VALUE EVER CHANGES, CHANGE y_playerset AS WELL - IT MAY BE INCLUDED
  72. // BEFORE y_groups BUT NEEDS THE MACRO.
  73. //
  74. // TODO: Fix that fact with better y_groups segmenting.
  75. #define GROUP_MASK (Group:0x80000000)
  76. #define GROUP_GLOBAL (Group:_MAX_GROUPS | GROUP_MASK) //-1)
  77. #define GROUP_FIX(%0) ((%0)&=~GROUP_MASK)
  78. #define GROUP_TEMP_FIX(%0) ((%0)&~GROUP_MASK)
  79. #define GROUP_MANGLE(%0) (Group:(%0) | GROUP_MASK)
  80. #define GFOREIGN__%1(%2); _GROUP_MAKE_NAME<FOREIGN__%1>(%2);
  81. #define GGLOBAL__%1(%2) _GROUP_MAKE_NAME<GLOBAL__%1>(%2)
  82. #define GPUBLIC__ MASTER_FUNC__
  83. //#define _GROUP_SET_PLAYER _GROUP_MAKE_NAME<..._SetPlayer>
  84. #define _GROUP_MAKE_FUNC<%4>:%0<%1> u@(u[_:_Y_G@C4:_Y_G@C5:0]);%0<%1><%4>$
  85. #define _Y_G@C4:_Y_G@C5:%0;%1<%2:%3><%4>$ %0;%1<%2:%4%3>
  86. #define _Y_G@C5:%0;%1<%3><%4>$ %0;%1<%4%3>
  87. // This is currently "leaking" code to the final script - code that we don't
  88. // want! No longer.
  89. #if defined _YSI_HAS_y_groups || __COMPILER_1ST_PASS
  90. #define NO_GROUPS<%1>(%0) if(%1_InitialiseFromGroups(%0))
  91. #else
  92. #define NO_GROUPS<%1>(%0)
  93. #endif
  94. // Chain init functions.
  95. #define GROUP_CHAIN%9<%0>(%1) (J@=_:(_Y_G@C_YES:_Y_G@C_NO:%0%9|||(_:_Y_G@C3:_Y_G@C2:_Y_G@C0:_Y_G@C1:%0(%1))))
  96. #define _Y_G@C3:_Y_G@C2:_Y_G@C0:_Y_G@C1:%0(%1,%2,%3) _Y_G@C_3(%0,_:_Y_G@P:_Y_G@Q:_Y_G@R:%1,_:%2,_:%3|||)
  97. #define _Y_G@C2:_Y_G@C0:_Y_G@C1:%0(%1,%2) _Y_G@C_2(%0,_:_Y_G@P:_Y_G@Q:_Y_G@R:%1,_:%2|||)
  98. #define _Y_G@C0:_Y_G@C1:%0() _Y_G@C_0(%0)
  99. #define _Y_G@C1:%0(%1) _Y_G@C_1(%0,_:_Y_G@P:_Y_G@Q:_Y_G@R:%1|||)
  100. #define _Y_G@C_YES:_Y_G@C_NO:%0?||| (!(%0))?(0):
  101. #define _Y_G@C_NO:%0|||
  102. // Can strip out multiple brackets in one go.
  103. #define _Y_G@P:%0[]%1||| _Y_G@P:%0%1|||
  104. #define _Y_G@Q:%0&%1||| _Y_G@Q:%0%1|||
  105. #define _Y_G@R:%0||| %0
  106. #if !defined MAX_GROUP_NAME
  107. #define MAX_GROUP_NAME (24)
  108. #endif
  109. #if defined MAX_GROUPS
  110. // Round up to the next nice number (or not, we could with long macros).
  111. #define _MAX_GROUPS (_:MAX_GROUPS)
  112. #else
  113. // 1 less than a nice number (with good reason).
  114. #define _MAX_GROUPS (_:127)
  115. #endif
  116. #define _MAX_GROUPS_G (_:_MAX_GROUPS + 1)
  117. // Note that these macros always do the last element before all the others
  118. // (which may or may not be in order). This is as the last element holds the
  119. // "default" group, which is the most likely to be a good match.
  120. #if _MAX_GROUPS < 32
  121. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[0]&%1[0])
  122. #elseif _MAX_GROUPS < 64
  123. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[1]&%1[1]||%0[0]&%1[0])
  124. #elseif _MAX_GROUPS < 96
  125. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[2]&%1[2]||%0[0]&%1[0]||%0[1]&%1[1])
  126. #elseif _MAX_GROUPS < 128
  127. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[3]&%1[3]||%0[0]&%1[0]||%0[1]&%1[1]||%0[2]&%1[2])
  128. #elseif _MAX_GROUPS < 160
  129. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[4]&%1[4]||%0[0]&%1[0]||%0[1]&%1[1]||%0[2]&%1[2]||%0[3]&%1[3])
  130. #elseif _MAX_GROUPS < 192
  131. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[5]&%1[5]||%0[0]&%1[0]||%0[1]&%1[1]||%0[2]&%1[2]||%0[3]&%1[3]||%0[4]&%1[4])
  132. #elseif _MAX_GROUPS < 224
  133. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[6]&%1[6]||%0[0]&%1[0]||%0[1]&%1[1]||%0[2]&%1[2]||%0[3]&%1[3]||%0[4]&%1[4]||%0[5]&%1[5])
  134. #elseif _MAX_GROUPS < 256
  135. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[7]&%1[7]||%0[0]&%1[0]||%0[1]&%1[1]||%0[2]&%1[2]||%0[3]&%1[3]||%0[4]&%1[4]||%0[5]&%1[5]||%0[6]&%1[6])
  136. #elseif _MAX_GROUPS < 288
  137. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[8]&%1[8]||%0[0]&%1[0]||%0[1]&%1[1]||%0[2]&%1[2]||%0[3]&%1[3]||%0[4]&%1[4]||%0[5]&%1[5]||%0[6]&%1[6]||%0[7]&%1[7])
  138. #elseif _MAX_GROUPS < 320
  139. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[9]&%1[9]||%0[0]&%1[0]||%0[1]&%1[1]||%0[2]&%1[2]||%0[3]&%1[3]||%0[4]&%1[4]||%0[5]&%1[5]||%0[6]&%1[6]||%0[7]&%1[7]||%0[8]&%1[8])
  140. #elseif _MAX_GROUPS < 352
  141. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[10]&%1[10]||%0[0]&%1[0]||%0[1]&%1[1]||%0[2]&%1[2]||%0[3]&%1[3]||%0[4]&%1[4]||%0[5]&%1[5]||%0[6]&%1[6]||%0[7]&%1[7]||%0[8]&%1[8]||%0[9]&%1[9])
  142. #elseif _MAX_GROUPS < 384
  143. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[11]&%1[11]||%0[0]&%1[0]||%0[1]&%1[1]||%0[2]&%1[2]||%0[3]&%1[3]||%0[4]&%1[4]||%0[5]&%1[5]||%0[6]&%1[6]||%0[7]&%1[7]||%0[8]&%1[8]||%0[9]&%1[9]||%0[10]&%1[10])
  144. #elseif _MAX_GROUPS < 416
  145. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[12]&%1[12]||%0[0]&%1[0]||%0[1]&%1[1]||%0[2]&%1[2]||%0[3]&%1[3]||%0[4]&%1[4]||%0[5]&%1[5]||%0[6]&%1[6]||%0[7]&%1[7]||%0[8]&%1[8]||%0[9]&%1[9]||%0[10]&%1[10]||%0[11]&%1[11])
  146. #elseif _MAX_GROUPS < 448
  147. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[13]&%1[13]||%0[0]&%1[0]||%0[1]&%1[1]||%0[2]&%1[2]||%0[3]&%1[3]||%0[4]&%1[4]||%0[5]&%1[5]||%0[6]&%1[6]||%0[7]&%1[7]||%0[8]&%1[8]||%0[9]&%1[9]||%0[10]&%1[10]||%0[11]&%1[11]||%0[12]&%1[12])
  148. #elseif _MAX_GROUPS < 480
  149. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[14]&%1[14]||%0[0]&%1[0]||%0[1]&%1[1]||%0[2]&%1[2]||%0[3]&%1[3]||%0[4]&%1[4]||%0[5]&%1[5]||%0[6]&%1[6]||%0[7]&%1[7]||%0[8]&%1[8]||%0[9]&%1[9]||%0[10]&%1[10]||%0[11]&%1[11]||%0[12]&%1[12]||%0[13]&%1[13])
  150. #elseif _MAX_GROUPS < 512
  151. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[15]&%1[15]||%0[0]&%1[0]||%0[1]&%1[1]||%0[2]&%1[2]||%0[3]&%1[3]||%0[4]&%1[4]||%0[5]&%1[5]||%0[6]&%1[6]||%0[7]&%1[7]||%0[8]&%1[8]||%0[9]&%1[9]||%0[10]&%1[10]||%0[11]&%1[11]||%0[12]&%1[12]||%0[13]&%1[13]||%0[14]&%1[14])
  152. #elseif _MAX_GROUPS < 534
  153. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[16]&%1[16]||%0[0]&%1[0]||%0[1]&%1[1]||%0[2]&%1[2]||%0[3]&%1[3]||%0[4]&%1[4]||%0[5]&%1[5]||%0[6]&%1[6]||%0[7]&%1[7]||%0[8]&%1[8]||%0[9]&%1[9]||%0[10]&%1[10]||%0[11]&%1[11]||%0[12]&%1[12]||%0[13]&%1[13]||%0[14]&%1[14]||%0[15]&%1[15])
  154. #else
  155. // The variable is now based on both input variables to avoid shadow
  156. // warnings when used within another check (as in "Group_FullPlayerUpdate").
  157. #define _GROUPS_CHECK_ANY(%0,%1) \
  158. for (new %1__g%0 = bits<_MAX_GROUPS_G>; %1__g%0--; ) if ((%0[%1__g%0] & %1[%1__g%0]) && !((%1__g%0 = 0)))
  159. #endif
  160. stock
  161. BitArray:YSI_gGroupPlayers[MAX_PLAYERS]<_MAX_GROUPS_G>,
  162. BitArray:YSI_gTempGroups<_MAX_GROUPS_G>;
  163. stock const
  164. BitArray:YSI_g_cEmptyGroups<_MAX_GROUPS_G>;