1
0

y_playerarray.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*----------------------------------------------------------------------------*-
  2. ========================================
  3. y_playerarray - Bit arrays of players!
  4. ========================================
  5. Description:
  6. This code provides arrays of players who can do things. This is for support
  7. of the text system which can take arrays of player ids, bit arrays or just a
  8. single ID.
  9. Legal:
  10. Version: MPL 1.1
  11. The contents of this file are subject to the Mozilla Public License Version
  12. 1.1 (the "License"); you may not use this file except in compliance with
  13. the License. You may obtain a copy of the License at
  14. http://www.mozilla.org/MPL/
  15. Software distributed under the License is distributed on an "AS IS" basis,
  16. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  17. for the specific language governing rights and limitations under the
  18. License.
  19. The Original Code is the SA:MP script information include.
  20. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  21. Portions created by the Initial Developer are Copyright (C) 2008
  22. the Initial Developer. All Rights Reserved.
  23. Contributors:
  24. ZeeX, koolk
  25. Thanks:
  26. Peter, Cam - Support.
  27. ZeeX - Very productive conversations.
  28. koolk - IsPlayerinAreaEx code.
  29. TheAlpha - Danish translation.
  30. breadfish - German translation.
  31. Fireburn - Dutch translation.
  32. yom - French translation.
  33. 50p - Polish translation.
  34. Zamaroht - Spanish translation.
  35. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  36. for me to strive to better.
  37. Pixels^ - Running XScripters where the idea was born.
  38. Matite - Pestering me to release it and using it.
  39. Very special thanks to:
  40. Thiadmer - PAWN.
  41. Kye/Kalcor - SA:MP.
  42. SA:MP Team past, present and future - SA:MP.
  43. Version:
  44. 1.0
  45. Changelog:
  46. 29/11/10:
  47. First version
  48. -*----------------------------------------------------------------------------*/
  49. #include <YSI\internal\y_version>
  50. #include <YSI\y_bit>
  51. #include <a_samp>
  52. #define PA_TYPE_NONE (-1)
  53. #define PA_TYPE_BOOL (-2)
  54. #define PA_TYPE_ID (-3)
  55. #define PA_TYPE_PA (-4)
  56. #define PlayerArray:%0<%1> Bit:%0[%1]//={Bit:-1}
  57. #define PA_DEC<%0> static stock PlayerArray:_YSI_g_sPlayerDataA[%0]<MAX_PLAYERS>;//const _YSI_g_sPlayerDataS=%0;
  58. #define PA_INT<%0,%2> PA_Init(_YSI_g_sPlayerDataA[(%0)],(%2));
  59. #define PA_ADD<%0,%1> PA+(_YSI_g_sPlayerDataA[(%0)],(%1));
  60. #define PA_REM<%0,%1> PA-(_YSI_g_sPlayerDataA[(%0)],(%1));
  61. #define PA_SET<%0,%1,%2> (%2)?(PA+(_YSI_g_sPlayerDataA[(%0)],(%1))):(PA-(_YSI_g_sPlayerDataA[(%0)],(%1)));
  62. //#define PA_Init() {Bit:-1}
  63. stock PA_Init(Bit:a[], bool:init = false, s = bits<MAX_PLAYERS>)
  64. {
  65. --s;
  66. new
  67. Bit:m = init ? (Bit:-1) : (Bit:0);
  68. a[0] = Bit:PA_TYPE_PA;
  69. while (s)
  70. {
  71. a[s--] = m;
  72. }
  73. }
  74. //#define PA_Get(%1,%2) bool:(%1[Bit_Slot(%2)+1]&Bit_Mask(%2))
  75. /*stock PA_Assign(PlayerArray:array<>, slot, value, count = bitsof (array))
  76. {
  77. if (slot >= count) return;
  78. if (set) array[Bit_Slot(slot) + 1] |= Bit_Mask(slot);
  79. else array[Bit_Slot(slot) + 1] &= ~Bit_Mask(slot);
  80. }*/
  81. stock Bit:operator+(Bit:oper2, PlayerArray:oper1)
  82. {
  83. return oper2 | Bit_Mask(_:oper1);
  84. }
  85. stock Bit:operator-(Bit:oper2, PlayerArray:oper1)
  86. {
  87. return oper2 & ~Bit_Mask(_:oper1);
  88. }
  89. stock bool:operator==(Bit:oper2, PlayerArray:oper1)
  90. {
  91. return bool:(oper2 & Bit_Mask(_:oper1));
  92. }
  93. stock bool:operator!=(Bit:oper2, PlayerArray:oper1)
  94. {
  95. return !(oper2 & Bit_Mask(_:oper1));
  96. }
  97. /*stock Bit:operator&(Bit:oper2, PlayerArray:oper1)
  98. {
  99. #pragma unused oper1
  100. return oper2;
  101. }
  102. stock Bit:operator|(Bit:oper2, PlayerArray:oper1)
  103. {
  104. #pragma unused oper1
  105. return oper2 & Bit_Mask(_:oper1);
  106. }*/
  107. //#define PA%0(%1,%2) (Bit:(%1[Bit_Slot(%2)+1]%0=PlayerArray:(%2))&Bit_Mask(%2))
  108. #define PA%0(%1,%2) (%1[Bit_Slot(%2)+1]%0=PlayerArray:(%2))
  109. /*stock PA_Set(PlayerArray:array<>, slot, bool:set, count = bitsof (array))
  110. {
  111. if (slot >= count) return;
  112. if (set) array[Bit_Slot(slot) + 1] |= Bit_Mask(slot);
  113. else array[Bit_Slot(slot) + 1] &= ~Bit_Mask(slot);
  114. }*/
  115. #undef PlayerArray
  116. #define PlayerArray:%0<%1> Bit:%0[bits<%1>+1]//={Bit:-1}