setup.inc 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**--------------------------------------------------------------------------**\
  2. =======================================
  3. y_groups - Player group abstractions!
  4. =======================================
  5. Description:
  6. Admin levels, gangs, teams etc - they're all "groups" of people, this
  7. provides an abstraction for all of these collections.
  8. Legal:
  9. Version: MPL 1.1
  10. The contents of this file are subject to the Mozilla Public License Version
  11. 1.1 (the "License"); you may not use this file except in compliance with
  12. the License. You may obtain a copy of the License at
  13. http://www.mozilla.org/MPL/
  14. Software distributed under the License is distributed on an "AS IS" basis,
  15. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  16. for the specific language governing rights and limitations under the
  17. License.
  18. The Original Code is the YSI groups include.
  19. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  20. Portions created by the Initial Developer are Copyright (C) 2011
  21. the Initial Developer. All Rights Reserved.
  22. Contributors:
  23. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  24. Thanks:
  25. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  26. ZeeX - Very productive conversations.
  27. koolk - IsPlayerinAreaEx code.
  28. TheAlpha - Danish translation.
  29. breadfish - German translation.
  30. Fireburn - Dutch translation.
  31. yom - French translation.
  32. 50p - Polish translation.
  33. Zamaroht - Spanish translation.
  34. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  35. for me to strive to better.
  36. Pixels^ - Running XScripters where the idea was born.
  37. Matite - Pestering me to release it and using it.
  38. Very special thanks to:
  39. Thiadmer - PAWN, whose limits continue to amaze me!
  40. Kye/Kalcor - SA:MP.
  41. SA:MP Team past, present and future - SA:MP.
  42. Version:
  43. 1.0
  44. Changelog:
  45. 29/11/10:
  46. First version
  47. \**--------------------------------------------------------------------------**/
  48. #define _GROUP_LOCAL_NAME _GROUP_MAKE_TAG:e
  49. // Dummy values.
  50. #define INVALID_GROUP (Group:-1)
  51. #define GROUP_MASK (Group:0x80000000)
  52. #define GROUP_GLOBAL (Group:_MAX_GROUPS | GROUP_MASK) //-1)
  53. #define GROUP_FIX(%0) ((%0)&=~GROUP_MASK)
  54. #define GROUP_TEMP_FIX(%0) ((%0)&~GROUP_MASK)
  55. #define GROUP_MANGLE(%0) (Group:(%0) | GROUP_MASK)
  56. // This is currently "leaking" code to the final script - code that we don't
  57. // want! No longer.
  58. #if defined _YSI_HAS_y_groups || COMPILER_1ST_PASS
  59. #define NO_GROUPS(%0) if(_GROUP_INITIALISE(%0))
  60. #else
  61. #define NO_GROUPS(%0)
  62. #endif
  63. #define _GROUP_INITIALISE _GROUP_MAKE_NAME<..._InitialiseFromGroups>
  64. // Chain init functions.
  65. #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))))
  66. #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|||)
  67. #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|||)
  68. #define _Y_G@C0:_Y_G@C1:%0() _Y_G@C_0(%0)
  69. #define _Y_G@C1:%0(%1) _Y_G@C_1(%0,_:_Y_G@P:_Y_G@Q:_Y_G@R:%1|||)
  70. #define _Y_G@C_YES:_Y_G@C_NO:%0?||| (!(%0))?(0):
  71. #define _Y_G@C_NO:%0|||
  72. // Can strip out multiple brackets in one go.
  73. #define _Y_G@P:%0[]%1||| _Y_G@P:%0%1|||
  74. #define _Y_G@Q:%0&%1||| _Y_G@Q:%0%1|||
  75. #define _Y_G@R:%0||| %0
  76. // Set up the uniques to make removing them simpler.
  77. #define _GROUP_UNIQUE_SYMBOL 0
  78. #define _GROUP_UNIQUE_FUNCTION
  79. #if !defined MAX_GROUP_NAME
  80. #define MAX_GROUP_NAME (24)
  81. #endif
  82. #if defined MAX_GROUPS
  83. // Round up to the next nice number (or not, we could with long macros).
  84. #define _MAX_GROUPS (_:MAX_GROUPS)
  85. #else
  86. // 1 less than a nice number (with good reason).
  87. #define _MAX_GROUPS (_:127)
  88. #endif
  89. #define _MAX_GROUPS_G (_:_MAX_GROUPS + 1)
  90. // Note that these macros always do the last element before all the others
  91. // (which may or may not be in order). This is as the last element holds the
  92. // "default" group, which is the most likely to be a good match.
  93. #if _MAX_GROUPS < 32
  94. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[0]&%1[0])
  95. #elseif _MAX_GROUPS < 64
  96. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[1]&%1[1]||%0[0]&%1[0])
  97. #elseif _MAX_GROUPS < 96
  98. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[2]&%1[2]||%0[0]&%1[0]||%0[1]&%1[1])
  99. #elseif _MAX_GROUPS < 128
  100. #define _GROUPS_CHECK_ANY(%0,%1) if(%0[3]&%1[3]||%0[0]&%1[0]||%0[1]&%1[1]||%0[2]&%1[2])
  101. #elseif _MAX_GROUPS < 160
  102. #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])
  103. #elseif _MAX_GROUPS < 192
  104. #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])
  105. #elseif _MAX_GROUPS < 224
  106. #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])
  107. #elseif _MAX_GROUPS < 256
  108. #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])
  109. #elseif _MAX_GROUPS < 288
  110. #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])
  111. #elseif _MAX_GROUPS < 320
  112. #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])
  113. #elseif _MAX_GROUPS < 352
  114. #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])
  115. #elseif _MAX_GROUPS < 384
  116. #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])
  117. #elseif _MAX_GROUPS < 416
  118. #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])
  119. #elseif _MAX_GROUPS < 448
  120. #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])
  121. #elseif _MAX_GROUPS < 480
  122. #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])
  123. #elseif _MAX_GROUPS < 512
  124. #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])
  125. #elseif _MAX_GROUPS < 534
  126. #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])
  127. #else
  128. // The variable is now based on both input variables to avoid shadow
  129. // warnings when used within another check (as in "Group_FullPlayerUpdate").
  130. #define _GROUPS_CHECK_ANY(%0,%1) \
  131. for (new %1__g%0 = bits<_MAX_GROUPS_G>; %1__g%0--; ) if (%0[%1__g%0] & %1[%1__g%0])
  132. #endif
  133. stock
  134. BitArray:YSI_gGroupPlayers[MAX_PLAYERS]<_MAX_GROUPS_G>,
  135. BitArray:YSI_gTempGroups<_MAX_GROUPS_G>;
  136. stock const
  137. BitArray:YSI_g_cEmptyGroups<_MAX_GROUPS_G>;