1
0

y_groupsecond.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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 group 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. 2.0
  44. Changelog:
  45. 21/10/12:
  46. Added Group_Get... functions.
  47. 20/10/12:
  48. Pretty much a ground-up API-compatible rewrite. Shorter and reliabler.
  49. 29/11/10:
  50. First version
  51. </remarks>
  52. \**--------------------------------------------------------------------------**/
  53. #undef _inc_y_groupsecond
  54. // This code, having been updated to use the later version of y_hooks,
  55. // unfortunately no longer has one function spread between two files, which was
  56. // a very unique (required) code feature. However this version should be better
  57. // overall (at least slightly).
  58. //#include "..\y_hooks"
  59. // This file contains generic code for setting all the stats to do with a single
  60. // element type. Groups can be defined for any element (classes, objects etc)
  61. // and each one will specialise this file to give different functions.
  62. #if !defined _GROUP_MAKE_NAME
  63. #error Please define _GROUP_MAKE_NAME before including y_groups.
  64. #endif
  65. #if !defined _GROUP_MAKE_LIMIT
  66. #error Please define _GROUP_MAKE_LIMIT before including y_groups.
  67. #endif
  68. #if !defined _GROUP_MAKE_TAG
  69. #define _GROUP_MAKE_TAG _
  70. #endif
  71. // Start of the multi-use file.
  72. static stock
  73. BitArray:_GROUP_GROUP_NAME[_GROUP_MAKE_LIMIT]<_:_MAX_GROUPS_G>,
  74. BitArray:_GROUP_DEFAULTS<_:_MAX_GROUPS_G>,
  75. BitArray:YSI_g_sEmpty<_:_MAX_GROUPS_G>,
  76. _yGI,
  77. _yGU,
  78. _yGA;
  79. // Define the callback chaining for the current
  80. #if YSIM_HAS_MASTER
  81. #if _YSIM_IS_CLIENT
  82. #define _gchain%0(%2) stock _GROUP_MAKE_NAME<%0...>(%2)
  83. // Should never be needed.
  84. #define _GROUP_SET_PLAYER _GROUP_MAKE_NAME<_Error_..._Client_Set>
  85. #else
  86. #if _YSIM_IS_SERVER
  87. #define _gchain%0(%2) _GROUP_MAKE_NAME<%0...>(%2);public _GROUP_MAKE_NAME<%0...>(%2);for(J@=1;J@;GROUP_CHAIN?<%0>(%2))
  88. #define _GROUP_SET_PLAYER _GROUP_MAKE_NAME<..._SetPlayer>
  89. #else
  90. #if _YSIM_IS_STUB
  91. #define _gchain%0(%2) stock _GROUP_MAKE_NAME<%0...>(%2)
  92. // Because of the interaction between the various things that
  93. // the groups and master systems this will NEVER be called in a
  94. // stub script - and if it is we now get a nice compile-time
  95. // error telling us so! It may, however, prove difficult to
  96. // trace!
  97. #define _GROUP_SET_PLAYER _GROUP_MAKE_NAME<_Error_..._Stub_Set>
  98. #else
  99. #define _gchain%0(%2) _GROUP_MAKE_NAME<%0...>(%2);public _GROUP_MAKE_NAME<%0...>(%2)<>GROUP_CHAIN?<%0>(%2);public _GROUP_MAKE_NAME<%0...>(%2)<_YCM:y>for(J@=1;J@;GROUP_CHAIN?<%0>(%2))
  100. #define _GROUP_SET_PLAYER _GROUP_MAKE_NAME<..._SetPlayer>
  101. #endif
  102. #endif
  103. #endif
  104. #else
  105. #define _gchain%0(%2) _GROUP_MAKE_NAME<%0...>(%2);public _GROUP_MAKE_NAME<%0...>(%2);for(J@=1;J@;GROUP_CHAIN?<%0>(%2))
  106. #define _GROUP_SET_PLAYER _GROUP_MAKE_NAME<..._SetPlayer>
  107. #endif
  108. /**--------------------------------------------------------------------------**\
  109. <summary>Group_FU</summary>
  110. <param name="playerid">Player to check.</param>
  111. <param name="el">Element to show or hide.</param>
  112. <param name="previous">(p) The old state of affairs.</param>
  113. <param name="current">(c) The new state of affairs.</param>
  114. <param name="reference">(r) What to compare changes to.</param>
  115. <returns>
  116. -
  117. </returns>
  118. <remarks>
  119. I did have a good reason for calling this "FU", but I forgot it! Anyway,
  120. the state of some groups has changed - either a player's groups or an
  121. elements groups have changed. If the player could previously see the
  122. element but now can't, hide it. If the player previously couldn't see it
  123. but now can, show it. If there is no change do nothing. The old version of
  124. this library would just re-show the element even if they could already see
  125. it, but this was a bad design as it could incur large overheads in other
  126. libraries when they had to do IO to enable or disable something for a
  127. player.
  128. The change can be in either the player's groups or the element's groups,
  129. either way this code will work regardless.
  130. Oh yeah, "FU" means "Full Update".
  131. </remarks>
  132. \**--------------------------------------------------------------------------**/
  133. static stock Group_FU(playerid, el, Bit:p[], Bit:c[], Bit:r[])
  134. {
  135. // "_GROUPS_CHECK" is a macro that expands to a massive unrolled "if"
  136. // statement checking up to 512 groups at once. Any more than that and this
  137. // code resorts to a loop instead. I say "at once"; it does 32 AT ONCE
  138. // (as in truly in parallel), starting with the most likely match (the
  139. // default group that every player and every element is usually in), and
  140. // loops over all the groups in 32 group chunks. When I say "loop", this
  141. // could be in the form of a huge "if" statement with every iteration put in
  142. // explicitly.
  143. // r = Reference (valid groups).
  144. // c = Current (new groups).
  145. // p = Previous (old groups).
  146. _GROUPS_CHECK_ANY(p,r)
  147. {
  148. // Could previously see this thing. The thing about this design is that
  149. // it can (best case) take just 2 comparisons to end - and that should
  150. // be the common case!
  151. _GROUPS_CHECK_ANY(c,r)
  152. {
  153. // Still can.
  154. return;
  155. }
  156. // Now can't.
  157. _GROUP_SET_PLAYER(_GROUP_MAKE_TAG:el, playerid, false);
  158. return;
  159. }
  160. // Couldn't see it before.
  161. _GROUPS_CHECK_ANY(c,r)
  162. {
  163. // They have whatever this thing is. Note that this may be called
  164. // MULTIPLE times for an element, without anything actually changing.
  165. // I.e. this could be set to "true" repeatedly while never being set
  166. // to "false".
  167. _GROUP_SET_PLAYER(_GROUP_MAKE_TAG:el, playerid, true);
  168. // We use "return" here because "_GROUPS_CHECK_ANY" MAY be a loop.
  169. return;
  170. }
  171. }
  172. /**--------------------------------------------------------------------------**\
  173. <summary>_yGI</summary>
  174. <param name="&ni">Next init function variable as returned by y_amx.</param>
  175. <param name="&na">Next add function variable as returned by y_amx.</param>
  176. <param name="&nu">Next update function variable as returned by y_amx.</param>
  177. <returns>
  178. -
  179. </returns>
  180. <remarks>
  181. This function is called when the group system first starts up to initialise
  182. the global group and all the various function pointers. The way the
  183. "_gchain" macro works means that the fact that "ni" etc are references is
  184. irrelevant; however, it does make the code LOOK much nicer and like
  185. assigning to the variables does have some wider meaning.
  186. If this is called with "ni = -1", it is special code to temporarilly set or
  187. restore the defaults for use with the "GROUP_ADD" macro.
  188. </remarks>
  189. \**--------------------------------------------------------------------------**/
  190. _gchain _yGI(&ni, &na, &nu)
  191. {
  192. if (ni == -1)
  193. {
  194. static
  195. BitArray:sStack<_MAX_GROUPS_G>;
  196. if (na)
  197. {
  198. //printf("PUSH %d", nu);
  199. // Called to "push" the default settings.
  200. sStack = _GROUP_DEFAULTS;
  201. //printf("ONE %d", nu);
  202. _GROUP_DEFAULTS = YSI_g_cEmptyGroups;
  203. //printf("TWO %d", nu);
  204. Bit_Let(_GROUP_DEFAULTS, nu);
  205. //printf("THREE %d", nu);
  206. for (new i = 0; i != bits<_MAX_GROUPS_G>; ++i)
  207. {
  208. YSI_g_sEmpty[i] = ~_GROUP_DEFAULTS[i];
  209. }
  210. //printf("DONE %d", nu);
  211. }
  212. else
  213. {
  214. //printf("POP");
  215. // Called to "pop" the default settings.
  216. _GROUP_DEFAULTS = sStack;
  217. YSI_g_sEmpty = YSI_g_cEmptyGroups;
  218. }
  219. }
  220. else
  221. {
  222. P:4(#_GROUP_MAKE_NAME<_yGI...> " called: %i, %i, %i", ni, na, nu);
  223. // Enable the default group. If I'm right, this way is actually better than
  224. // using variables as in most cases because "_MAX_GROUPS" is a constant so
  225. // all the other maths will be constant.
  226. Bit_Let(_GROUP_DEFAULTS, _MAX_GROUPS);
  227. // Don't need this loop anymore, it is done for every element individually.
  228. //for (new i = 0; i != _GROUP_MAKE_LIMIT; ++i)
  229. //{
  230. // // Basically, enable everything in the default group.
  231. // Bit_Let(_GROUP_GROUP_NAME[i], _MAX_GROUPS);
  232. //}
  233. // Set up the function chaining.
  234. ni = AMX_GetPublicPointerPrefix(ni, _yGI, _A<_yGI>);
  235. na = AMX_GetPublicPointerPrefix(na, _yGA, _A<_yGA>);
  236. nu = AMX_GetPublicPointerPrefix(nu, _yGU, _A<_yGU>);
  237. }
  238. }
  239. /**--------------------------------------------------------------------------**\
  240. <summary>Group_Exclusive...</summary>
  241. <param name="Group:g">Group to add this to.</param>
  242. <param name="_GROUP_MAKE_TAG:el">Element to add.</param>
  243. <returns>
  244. -
  245. </returns>
  246. <remarks>
  247. Add this element to ONLY this group and remove it from any others it might
  248. already be in. This is basically a simplified version of "GROUP_ADD".
  249. </remarks>
  250. \**--------------------------------------------------------------------------**/
  251. gforeign Group_Exclusive...(Group:g,_GROUP_MAKE_TAG:el);
  252. gglobal Group_Exclusive...(Group:g,_GROUP_MAKE_TAG:el)
  253. {
  254. if (GROUP_MASK <= g <= GROUP_GLOBAL)
  255. {
  256. GROUP_FIX(g);
  257. YSI_gTempGroups = _GROUP_DEFAULTS;
  258. _GROUP_DEFAULTS = YSI_g_cEmptyGroups;
  259. Bit_Let(_GROUP_DEFAULTS, _:g);
  260. for (new i = 0; i != bits<_MAX_GROUPS_G>; ++i)
  261. {
  262. YSI_g_sEmpty[i] = ~_GROUP_DEFAULTS[i];
  263. }
  264. _GROUP_INITIALISE(el);
  265. _GROUP_DEFAULTS = YSI_gTempGroups;
  266. YSI_g_sEmpty = YSI_g_cEmptyGroups;
  267. return 1;
  268. }
  269. return 0;
  270. }
  271. /**--------------------------------------------------------------------------**\
  272. <summary>_yGA</summary>
  273. <param name="&group">The group that was just created.</param>
  274. <returns>
  275. -
  276. </returns>
  277. <remarks>
  278. The given group was just created, loop over all elements and make sure they
  279. are NOT in this group - only the global group has a "default default" of
  280. true. We don't need to update any players with this as no-one will ever be
  281. in a brand new group.
  282. </remarks>
  283. \**--------------------------------------------------------------------------**/
  284. _gchain _yGA(&group)
  285. {
  286. P:4(#_GROUP_MAKE_NAME<_yGA...> " called: %i", _:group);
  287. // Adding a new group is now a lot harder than it was before, but on the
  288. // other hand, adding and using elements is vastly simpler so that's OK.
  289. new
  290. s = Bit_Slot(group),
  291. Bit:m = ~Bit_Mask(group);
  292. // Set the default "contains" for this group to false.
  293. _GROUP_DEFAULTS[s] &= m;
  294. // Disable every element in this group.
  295. for (new i = 0; i != _GROUP_MAKE_LIMIT; ++i)
  296. {
  297. _GROUP_GROUP_NAME[i][s] &= m;
  298. }
  299. }
  300. /**--------------------------------------------------------------------------**\
  301. <summary>_yGU</summary>
  302. <param name="&pid">The player who joined or left groups.</param>
  303. <param name="Bit:p[]">Their previous groups.</param>
  304. <param name="Bit:c[]">Their new groups.</param>
  305. <returns>
  306. -
  307. </returns>
  308. <remarks>
  309. The player "pid" just joined or left a group (or groups - can do multiple).
  310. Update their visibility accordingly. This function is ONLY called if there
  311. is a CHANGE - earlier functions confirm that they weren't already in (or
  312. not) this group(s) before the call.
  313. </remarks>
  314. \**--------------------------------------------------------------------------**/
  315. _gchain _yGU(&pid, Bit:p[], Bit:c[])
  316. {
  317. P:4(#_GROUP_MAKE_NAME<_yGU...> " called: %i, %s, %s", pid, Bit_Display(p, bits<_MAX_GROUPS_G>), Bit_Display(c, bits<_MAX_GROUPS_G>));
  318. // This code loops over every "thing" controlled by this script. For every
  319. // one it checks to see if the player can or can't see something that they
  320. // previously could or couldn't see. If their ability to see it has
  321. // changed then the "_GROUP_SET_PLAYER" function in the controlling library
  322. // is called to do the actual internal function of updating their state.
  323. for (new el = 0; el != _GROUP_MAKE_LIMIT; ++el)
  324. {
  325. Group_FU(pid, el, p, c, _GROUP_GROUP_NAME[el]);
  326. }
  327. }
  328. /**--------------------------------------------------------------------------**\
  329. <summary>_GROUP_INITIALISE</summary>
  330. <param name="x">The element that was added (maybe).</param>
  331. <param name="s">Was the element added or removed?</param>
  332. <returns>
  333. -
  334. </returns>
  335. <remarks>
  336. The name is a macro, so this function isn't actually called this. This is
  337. called when a new element is created, and as such it is NOT chained to other
  338. parts of the groups system because each part handles one type of element.
  339. Loop through all players and set up the element for them if they are in a
  340. group that this is also in by default.
  341. If x is "_GROUP_MAKE_LIMIT" then this is the test used in OnPlayerConnect in
  342. various libraries to see if the groups system exists, and if not locally
  343. initialise the player instead of leaving it up to this system.
  344. </remarks>
  345. \**--------------------------------------------------------------------------**/
  346. #if !defined _YSI_GROUPS_FIRST_HALF
  347. forward bool:_GROUP_INITIALISE(_GROUP_MAKE_TAG:x = _GROUP_MAKE_TAG:_GROUP_MAKE_LIMIT);
  348. #endif
  349. stock bool:_GROUP_INITIALISE(_GROUP_MAKE_TAG:x = _GROUP_MAKE_TAG:_GROUP_MAKE_LIMIT) <YSI_has_groups:y>
  350. {
  351. P:4(#_GROUP_INITIALISE " called: %i", x);
  352. // A new item has been added to the system - update all players according to
  353. // the default settings for a group.
  354. if (x != _GROUP_MAKE_TAG:_GROUP_MAKE_LIMIT)
  355. {
  356. //static
  357. // BitArray:sEmpty<_MAX_GROUPS_G>;
  358. //printf("%d %s %s", _:x, Bit_Display(_GROUP_DEFAULTS), Bit_Display(YSI_g_sEmpty));
  359. _GROUP_GROUP_NAME[_:x] = _GROUP_DEFAULTS;
  360. foreach (new playerid : Player)
  361. {
  362. // Uses "YSI_g_sEmpty" instead of a truly blank variable so that we
  363. // can ensure that NO other groups have this element when we use the
  364. // "GROUP_ADD" macro.
  365. Group_FU(playerid, _:x, YSI_g_sEmpty, _GROUP_DEFAULTS, YSI_gGroupPlayers[playerid]);
  366. }
  367. }
  368. return true;
  369. }
  370. /**--------------------------------------------------------------------------**\
  371. <summary>Group_Set...Default</summary>
  372. <param name="Group:g">Group to set for.</param>
  373. <param name="bool:s">Set or unset?</param>
  374. <returns>
  375. -
  376. </returns>
  377. <remarks>
  378. If "s" is true, then all elements are added to this group (i.e. the default
  379. is set to true and all previous settings are wiped out). If it is false
  380. then all elements are removed and a full update is done.
  381. </remarks>
  382. \**--------------------------------------------------------------------------**/
  383. gforeign Group_Set...Default(Group:g,bool:s);
  384. gglobal Group_Set...Default(Group:g,bool:s)
  385. {
  386. P:2(#_GROUP_MAKE_NAME<Group_Set...Default> " called: %i, %i", _:g, s);
  387. if (GROUP_MASK <= g <= GROUP_GLOBAL)
  388. {
  389. // There is now NO validity check for reasons of distruibution.
  390. GROUP_FIX(g);
  391. new
  392. slot = Bit_Slot(g),
  393. Bit:mask = Bit_Mask(g),
  394. Iterator:GP<MAX_PLAYERS>;
  395. foreach (new playerid : Player)
  396. {
  397. // Do this check here so it is only done once per player. This is a
  398. // good argument for moving iterators to be duplicated in every
  399. // script; however, the default "Group()" iterator implementation is
  400. // a function, not a standard iterator - actually it now isn't...
  401. if (YSI_gGroupPlayers[playerid][slot] & mask)
  402. {
  403. // Make a fast local iterator of all the players.
  404. Iter_Add(GP, playerid);
  405. }
  406. }
  407. static
  408. BitArray:sNext<_MAX_GROUPS_G>;
  409. if (s)
  410. {
  411. Bit_Let(_GROUP_DEFAULTS, _:g);
  412. for (new el = 0; el != _GROUP_MAKE_LIMIT; ++el)
  413. {
  414. sNext = _GROUP_GROUP_NAME[el];
  415. if (sNext[slot] & mask)
  416. {
  417. continue;
  418. }
  419. // Is this element NOT in the current group?
  420. Bit_Let(sNext, _:g);
  421. foreach (new playerid : GP)
  422. {
  423. Group_FU(playerid, el, _GROUP_GROUP_NAME[el], sNext, YSI_gGroupPlayers[playerid]);
  424. }
  425. _GROUP_GROUP_NAME[el] = sNext;
  426. }
  427. }
  428. else
  429. {
  430. Bit_Vet(_GROUP_DEFAULTS, _:g);
  431. for (new el = 0; el != _GROUP_MAKE_LIMIT; ++el)
  432. {
  433. sNext = _GROUP_GROUP_NAME[el];
  434. if (!(sNext[slot] & mask))
  435. {
  436. continue;
  437. }
  438. // Is this element in the current group?
  439. Bit_Vet(sNext, _:g);
  440. foreach (new playerid : GP)
  441. {
  442. Group_FU(playerid, el, _GROUP_GROUP_NAME[el], sNext, YSI_gGroupPlayers[playerid]);
  443. }
  444. _GROUP_GROUP_NAME[el] = sNext;
  445. }
  446. }
  447. return 1;
  448. }
  449. return 0;
  450. }
  451. /**--------------------------------------------------------------------------**\
  452. <summary>Group_SetGlobal...Default</summary>
  453. <param name="bool:s">Set or unset?</param>
  454. <returns>
  455. -
  456. </returns>
  457. <remarks>
  458. If "s" is true, then all elements are added to the global group (i.e. the
  459. default is set to true and all previous settings are wiped out). If it is
  460. false then all elements are removed and a full update is done.
  461. </remarks>
  462. \**--------------------------------------------------------------------------**/
  463. gforeign Group_SetGlobal...Default(bool:s);
  464. gglobal Group_SetGlobal...Default(bool:s)
  465. {
  466. P:2(#_GROUP_MAKE_NAME<Group_SetGlobal...Default> " called: %i", s);
  467. return _GROUP_MAKE_NAME<Group_Set...Default>(GROUP_GLOBAL, s);
  468. }
  469. /**--------------------------------------------------------------------------**\
  470. <summary>Group_Set...New</summary>
  471. <param name="Group:g">Group to set for.</param>
  472. <param name="bool:s">Set or unset?</param>
  473. <returns>
  474. -
  475. </returns>
  476. <remarks>
  477. Similar to "Group_Set...Default", but doesn't reset all existing elements,
  478. just sets the permissions for any future items.
  479. </remarks>
  480. \**--------------------------------------------------------------------------**/
  481. gforeign Group_Set...New(Group:g,bool:s);
  482. gglobal Group_Set...New(Group:g,bool:s)
  483. {
  484. P:2(#_GROUP_MAKE_NAME<Group_Set...New> " called: %i, %i", _:g, s);
  485. if (GROUP_MASK <= g <= GROUP_GLOBAL)
  486. {
  487. // There is now NO validity check for reasons of distruibution.
  488. Bit_Set(_GROUP_DEFAULTS, _:GROUP_TEMP_FIX(g), s);
  489. return 1;
  490. }
  491. return 0;
  492. }
  493. /**--------------------------------------------------------------------------**\
  494. <summary>Group_SetGlobal...New</summary>
  495. <param name="bool:s">Set or unset?</param>
  496. <returns>
  497. -
  498. </returns>
  499. <remarks>
  500. All elements created FROM THIS POINT ON will have this default setting.
  501. </remarks>
  502. \**--------------------------------------------------------------------------**/
  503. gforeign Group_SetGlobal...New(bool:s);
  504. gglobal Group_SetGlobal...New(bool:s)
  505. {
  506. P:2(#_GROUP_MAKE_NAME<Group_SetGlobal...New> " called: %i", s);
  507. return _GROUP_MAKE_NAME<Group_Set...New>(GROUP_GLOBAL, s);
  508. }
  509. /**--------------------------------------------------------------------------**\
  510. <summary>Group_Set...</summary>
  511. <param name="Group:g">Group to set for.</param>
  512. <param name="el">Element to set.</param>
  513. <param name="bool:s">Set or unset?</param>
  514. <returns>
  515. -
  516. </returns>
  517. <remarks>
  518. If "s" is true, then one element is added to the current group. False it is
  519. removed.
  520. </remarks>
  521. \**--------------------------------------------------------------------------**/
  522. gforeign Group_Set...(Group:g,_GROUP_MAKE_TAG:el,bool:s);
  523. gglobal Group_Set...(Group:g,_GROUP_MAKE_TAG:el,bool:s)
  524. {
  525. P:2(#_GROUP_MAKE_NAME<Group_Set...> " called: %i, %i, %i", _:g, _:el, s);
  526. // Set wether a group can use this item.
  527. if (0 <= _:el < _GROUP_MAKE_LIMIT && GROUP_MASK <= g <= GROUP_GLOBAL)
  528. {
  529. // There is now NO validity check for reasons of distruibution.
  530. GROUP_FIX(g);
  531. new
  532. slot = Bit_Slot(g),
  533. Bit:mask = Bit_Mask(g);
  534. //static
  535. // BitArray:sNext<_MAX_GROUPS_G>;
  536. if (s)
  537. {
  538. YSI_gTempGroups = _GROUP_GROUP_NAME[_:el];
  539. if (YSI_gTempGroups[slot] & mask)
  540. {
  541. // No point adding an element to a group that it is already in.
  542. return 1;
  543. }
  544. // Is this element NOT in the current group?
  545. Bit_Let(YSI_gTempGroups, _:g);
  546. }
  547. else
  548. {
  549. YSI_gTempGroups = _GROUP_GROUP_NAME[_:el];
  550. if (!(YSI_gTempGroups[slot] & mask))
  551. {
  552. return 1;
  553. }
  554. // Is this element in the current group?
  555. Bit_Vet(YSI_gTempGroups, _:g);
  556. }
  557. foreach (new playerid : Player)
  558. {
  559. if (YSI_gGroupPlayers[playerid][slot] & mask)
  560. {
  561. // The player is in the group in question, so they need a full
  562. // update.
  563. Group_FU(playerid, _:el, _GROUP_GROUP_NAME[_:el], YSI_gTempGroups, YSI_gGroupPlayers[playerid]);
  564. }
  565. }
  566. _GROUP_GROUP_NAME[_:el] = YSI_gTempGroups;
  567. return 1;
  568. }
  569. return 0;
  570. }
  571. /**--------------------------------------------------------------------------**\
  572. <summary>Group_SetGlobal...</summary>
  573. <param name="el">Element to set.</param>
  574. <param name="bool:s">Set or unset?</param>
  575. <returns>
  576. -
  577. </returns>
  578. <remarks>
  579. If "s" is true, then one element is added to the global group. False it is
  580. removed.
  581. </remarks>
  582. \**--------------------------------------------------------------------------**/
  583. gforeign Group_SetGlobal...(_GROUP_MAKE_TAG:el,bool:s);
  584. gglobal Group_SetGlobal...(_GROUP_MAKE_TAG:el,bool:s)
  585. {
  586. P:2(#_GROUP_MAKE_NAME<Group_SetGlobal...> " called: %i, %i", _:el, s);
  587. return _GROUP_MAKE_NAME<Group_Set...>(GROUP_GLOBAL, el, s);
  588. }
  589. /**--------------------------------------------------------------------------**\
  590. <summary>Group_Get...</summary>
  591. <param name="Group:g">Group to get from.</param>
  592. <param name="el">Element to get.</param>
  593. <returns>
  594. bool: Does the group have the element?
  595. </returns>
  596. <remarks>
  597. -
  598. </remarks>
  599. \**--------------------------------------------------------------------------**/
  600. gforeign bool:Group_Get...(Group:g,_GROUP_MAKE_TAG:el);
  601. gglobal bool:Group_Get...(Group:g,_GROUP_MAKE_TAG:el)
  602. {
  603. P:2(#_GROUP_MAKE_NAME<Group_Get...> " called: %i, %i", _:g, _:el);
  604. return (0 <= _:el < _GROUP_MAKE_LIMIT && GROUP_MASK <= g <= GROUP_GLOBAL && Bit_Get(_GROUP_GROUP_NAME[_:el], _:GROUP_TEMP_FIX(g)));
  605. }
  606. /**--------------------------------------------------------------------------**\
  607. <summary>Group_GetGlobal...</summary>
  608. <param name="el">Element to get.</param>
  609. <returns>
  610. bool: Does the global group have the element?
  611. </returns>
  612. <remarks>
  613. -
  614. </remarks>
  615. \**--------------------------------------------------------------------------**/
  616. gforeign Group_GetGlobal...(_GROUP_MAKE_TAG:el);
  617. gglobal Group_GetGlobal...(_GROUP_MAKE_TAG:el)
  618. {
  619. P:2(#_GROUP_MAKE_NAME<Group_GetGlobal...> " called: %i", _:el);
  620. return _GROUP_MAKE_NAME<Group_Get...>(GROUP_GLOBAL, el);
  621. }
  622. #undef _GROUP_MAKE_TAG
  623. #undef _gchain
  624. #undef _GROUP_SET_PLAYER