y_areas_entry.inc 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603
  1. #if defined _INC_y_areas
  2. #endinput
  3. #endif
  4. #define _INC_y_areas
  5. /*
  6. Legal:
  7. Version: MPL 1.1
  8. The contents of this file are subject to the Mozilla Public License Version
  9. 1.1 the "License"; you may not use this file except in compliance with
  10. the License. You may obtain a copy of the License at
  11. http://www.mozilla.org/MPL/
  12. Software distributed under the License is distributed on an "AS IS" basis,
  13. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. for the specific language governing rights and limitations under the
  15. License.
  16. The Original Code is the YSI framework.
  17. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  18. Portions created by the Initial Developer are Copyright C 2011
  19. the Initial Developer. All Rights Reserved.
  20. Contributors:
  21. Y_Less
  22. koolk
  23. JoeBullet/Google63
  24. g_aSlice/Slice
  25. Misiur
  26. samphunter
  27. tianmeta
  28. maddinat0r
  29. spacemud
  30. Crayder
  31. Dayvison
  32. Ahmad45123
  33. Zeex
  34. irinel1996
  35. Yiin-
  36. Chaprnks
  37. Konstantinos
  38. Masterchen09
  39. Southclaws
  40. PatchwerkQWER
  41. m0k1
  42. paulommu
  43. udan111
  44. Thanks:
  45. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  46. ZeeX - Very productive conversations.
  47. koolk - IsPlayerinAreaEx code.
  48. TheAlpha - Danish translation.
  49. breadfish - German translation.
  50. Fireburn - Dutch translation.
  51. yom - French translation.
  52. 50p - Polish translation.
  53. Zamaroht - Spanish translation.
  54. Los - Portuguese translation.
  55. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  56. me to strive to better.
  57. Pixels^ - Running XScripters where the idea was born.
  58. Matite - Pestering me to release it and using it.
  59. Very special thanks to:
  60. Thiadmer - PAWN, whose limits continue to amaze me!
  61. Kye/Kalcor - SA:MP.
  62. SA:MP Team past, present and future - SA:MP.
  63. Optional plugins:
  64. Gamer_Z - GPS.
  65. Incognito - Streamer.
  66. Me - sscanf2, fixes2, Whirlpool.
  67. */
  68. #include "..\..\YSI_Core\y_utils"
  69. #include "..\..\YSI_Data\y_bit"
  70. #include "..\..\YSI_Data\y_playerarray"
  71. #include "..\..\YSI_Data\y_iterate"
  72. #include "..\..\YSI_Coding\y_inline"
  73. #include "..\..\YSI_Coding\y_remote"
  74. #if defined AREAS_USE_TIMER
  75. #include "..\..\YSI_Coding\y_timers"
  76. #endif
  77. #if !defined MAX_AREAS
  78. #define MAX_AREAS (1024)
  79. // Now supports as many as you want (pretty much), and in a VASTLY better way!
  80. #elseif MAX_AREAS >= 0x3FFFF
  81. #error This version does not support more than 262142 areas.
  82. #endif
  83. #define Y_AREAS_GROUP_NAME<%0...%1> %0Area%1
  84. #define Y_AREAS_GROUP_LIMIT MAX_AREAS
  85. #define Y_AREAS_GROUP_TAG _
  86. #include "..\..\YSI_Players\y_groups\y_groups__include"
  87. // Set commands as master 50.
  88. #define MASTER 50
  89. #define YSIM_U_DISABLE
  90. #include "..\..\YSI_Core\y_master"
  91. #include "..\..\YSI_Coding\y_hooks"
  92. stock _YSI_HAS_y_areas(_do_not_call_me_ever_, _like_never_)
  93. {
  94. P:E("You called _YSI_HAS_y_areas! Bad, don't do that!", _do_not_call_me_ever_, _like_never_);
  95. assert(false);
  96. return 0;
  97. }
  98. #define NO_AREA (-1)
  99. //#define SINGLE_SLOT_AREA (e_AREA_FLAGS_NEXT)
  100. #define AREA_NO_NEXT (_:e_AREA_FLAGS_NEXT)
  101. // This will divide the world up in to 400 blocks, the fact that 400=400 is
  102. // PURE fluke. Setting this to 500 would result in 256 blocks:
  103. //
  104. // ((AREAS_ZONE_BOUNDS / AREAS_ZONE_SIZE) ** 2) * 4
  105. //
  106. #if !defined AREAS_ZONE_SIZE
  107. #define AREAS_ZONE_SIZE 400
  108. #endif
  109. #if !defined AREAS_ZONE_BOUNDS
  110. #define AREAS_ZONE_BOUNDS 4000
  111. #endif
  112. // You can of course have more, but if you do have more the extras will be dealt
  113. // with separately. I can see three happening sometimes, but not often. More
  114. // than that will probably be very rare, and less will be more common, so we can
  115. // use the third slot usually to store the "NO_AREA" terminator.
  116. #if !defined AREAS_MAX_OVERLAPS
  117. #define AREAS_MAX_OVERLAPS (3)
  118. #endif
  119. #define AREAS_ZONE_ARRAY (ceildiv(AREAS_ZONE_BOUNDS * 2, AREAS_ZONE_SIZE))
  120. #if !defined AREA_WORLDS
  121. #define AREA_WORLDS 256
  122. #endif
  123. #define AREAS_ZONE_PARTS (ceildiv(AREAS_ZONE_BOUNDS, AREAS_ZONE_SIZE))
  124. #define Area_MakeZone(%0) (floatround((%0) / AREAS_ZONE_SIZE.0, floatround_floor)) // - AREAS_ZONE_PARTS)
  125. #define _AREAS_ADD_TO_ZONE(%0,%1,%2,%3) YSI_g_sAreas[%2][E_AREA_FLAGS]=(YSI_g_sAreas[%2][E_AREA_FLAGS]&e_AREA_FLAGS_REST)|(e_AREA_FLAGS:%0&e_AREA_FLAGS_NEXT|e_AREA_FLAGS:(%3<<18)&e_AREA_FLAGS_ZONE),%0=%1
  126. //#define _AREAS_ZONES_O(%0) return e_AREA_ZONE_O_%0
  127. //#define _AREAS_ZONES_I(%0) return e_AREA_ZONE_I_%0
  128. //#define _AREAS_ZONES_X(%0) return e_AREA_ZONE_X_%0
  129. #define _AREAS_ZONES_O(%0) return _AREAS_ADD_TO_ZONE(YSI_g_sZoneO%0,area,last,e_AREA_ZONE_O_%0)
  130. #define _AREAS_ZONES_I(%0) return _AREAS_ADD_TO_ZONE(YSI_g_sZoneI%0,area,last,e_AREA_ZONE_I_%0)
  131. #define _AREAS_ZONES_X(%0) return _AREAS_ADD_TO_ZONE(YSI_g_sZoneX%0,area,last,e_AREA_ZONE_X_%0)
  132. #define _AREAS_ZONES_I_GRID zx=1// zx=Area_MakeZone(minx);zy=Area_MakeZone(miny);if(zx==Area_MakeZone(maxx)&&zy==Area_MakeZone(maxy))return _AREAS_MAKE_ZONE(zx,zy),_AREAS_ADD_TO_ZONE(YSI_g_sZones[zy],area,last,zy)
  133. #define _AREAS_MAKE_ZONE(%0,%1) %1+=((%0)+AREAS_ZONE_PARTS)*AREAS_ZONE_ARRAY+AREAS_ZONE_PARTS
  134. //#define _AREA_DO_ALL(%0) sCur=%0;while(sCur!=AREA_NO_NEXT)if(Area_CheckArea(playerid,sW,sCur,sX,sY,sZ))return Area_DoEnter(playerid,(YSI_g_sPlayerArea[playerid]=sCur))
  135. #define _AREA_DO_ALL(%0) sNext=%0;while((sCur=sNext)!=AREA_NO_NEXT)if(Area_CheckArea(playerid,sW,sCur,sX,sY,sZ,sNext,sAreas,sAlready))Area_DoEnter(playerid,sCur,in)
  136. /*#define _AREA_DO_ALL(%0)
  137. sCur = zone;
  138. while (sCur != AREA_NO_NEXT)
  139. if (Area_CheckArea(playerid, sW, sCur, sX, sY, sZ))
  140. return Area_DoEnter(playerid, (YSI_g_sPlayerArea[playerid] = sCur));
  141. */
  142. #define _AREAS_DO_REMOVE(%0,%1,%2) new __z=-1,__y=%0;while(__y!=%1)__z=__y,__y=_:(YSI_g_sAreas[__z][E_AREA_FLAGS] & e_AREA_FLAGS_NEXT);return ((__z==-1)?(%0=%2):(_:(YSI_g_sAreas[__z][E_AREA_FLAGS]=YSI_g_sAreas[__z][E_AREA_FLAGS]&e_AREA_FLAGS_I_NEXT|(e_AREA_FLAGS:%2&e_AREA_FLAGS_NEXT))))
  143. enum e_AREA_FLAGS:
  144. {
  145. // These aren't used any more either, they get encoded in the "POS" array
  146. // (sort of) with polys.
  147. //e_AREA_FLAGS_NEXT = 0x2000 - 1 << 0, //0x00001FFF,
  148. e_AREA_FLAGS_NEXT = 0x0003FFFF,
  149. //e_AREA_FLAGS_ZONE = 1023 << 18, //0x0FFC0000,
  150. e_AREA_FLAGS_ZONE = 0x0FFC0000,
  151. e_AREA_FLAGS_I_NEXT = ~(e_AREA_FLAGS_NEXT),
  152. e_AREA_FLAGS_REST = ~(e_AREA_FLAGS_NEXT | e_AREA_FLAGS_ZONE),
  153. //e_AREA_FLAGS_TYPE = 0x38000000,
  154. e_AREA_FLAGS_SPHERE = 1 << 28, //0x08000000,
  155. e_AREA_FLAGS_POLY = 2 << 28, //0x10000000,
  156. e_AREA_FLAGS_CUBE = 3 << 28, //0x18000000,
  157. //e_AREA_FLAGS_BOX = 4 << 28, //0x20000000,
  158. e_AREA_FLAGS_OVOID = 4 << 28, //0x08000000,
  159. e_AREA_FLAGS_OVAL = 5 << 28, //0x28000000,
  160. // The reserved type is now in use as a poly area child.
  161. //e_AREA_FLAGS_RES_0 = 6 << 28, //0x28000000,
  162. e_AREA_FLAGS_CHILD = 6 << 28, //0x30000000,
  163. e_AREA_FLAGS_CIRCLE = 7 << 28, //0x30000000,
  164. // Type mask.
  165. e_AREA_FLAGS_UNUSED = 0b000 << 28, //0x00000000,
  166. e_AREA_FLAGS_TYPE = 0b111 << 28, //0x38000000,
  167. // The "USED" flag isn't really needed any more, it's encoded in the type.
  168. // It seems the "used" flag was never read anyway...
  169. e_AREA_FLAGS_ACTIVE = 1 << 31,
  170. //e_AREA_FLAGS_USED = 1 << 31
  171. // If this is true AND AREA_VERY_FAST is on, the bounds check is identical
  172. // to the sphere check, so only do one.
  173. //e_AREA_FLAGS_BOUNDS = 1 << 31
  174. //e_AREA_FLAGS_SPHERE = 1 << 31
  175. }
  176. // Go backwards, so these all have the upper bit set.
  177. enum (+= -1)
  178. {
  179. e_AREA_ZONE_I_N = -1,
  180. e_AREA_ZONE_I_NE, // -2
  181. e_AREA_ZONE_I_E, // -3
  182. e_AREA_ZONE_I_SE, // -4
  183. e_AREA_ZONE_I_S, // -5
  184. e_AREA_ZONE_I_SW, // -6
  185. e_AREA_ZONE_I_W, // -7
  186. e_AREA_ZONE_I_NW, // -8
  187. e_AREA_ZONE_I_, // -9
  188. // "Outer" zones. -4000 > x, y > 4000;
  189. e_AREA_ZONE_O_N, // -10
  190. e_AREA_ZONE_O_NE, // -11
  191. e_AREA_ZONE_O_E, // -12
  192. e_AREA_ZONE_O_SE, // -13
  193. e_AREA_ZONE_O_S, // -14
  194. e_AREA_ZONE_O_SW, // -15
  195. e_AREA_ZONE_O_W, // -16
  196. e_AREA_ZONE_O_NW, // -17
  197. //e_AREA_ZONE_O_, // Can't be in all of O, but none of I.
  198. // "Extra" zones. In a quadrant, but spanning the +-4000 boundary.
  199. e_AREA_ZONE_X_N, // -18
  200. e_AREA_ZONE_X_NE, // -19
  201. e_AREA_ZONE_X_E, // -20
  202. e_AREA_ZONE_X_SE, // -21
  203. e_AREA_ZONE_X_S, // -22
  204. e_AREA_ZONE_X_SW, // -23
  205. e_AREA_ZONE_X_W, // -24
  206. e_AREA_ZONE_X_NW, // -25
  207. // Extra zones. For when areas are too big for a quadrant.
  208. e_AREA_ZONE_X_, // -26
  209. e_AREA_ZONE_NONE = cellmin
  210. }
  211. // =============================================================================
  212. // =============================================================================
  213. // IMPORTANT NOTE: The order of elements in this enum is INCREDIBLY important.
  214. // Because this is three enums in one, they share some pieces of data that must
  215. // not get overridden.
  216. // =============================================================================
  217. // =============================================================================
  218. // This might just be the most complex enum I've ever made!
  219. enum E_AREA
  220. {
  221. //union
  222. //{
  223. // struct
  224. // {
  225. #if YSIM_HAS_MASTER
  226. E_AREA_MASTER,
  227. #endif
  228. // This has increased from 4 to 6, so we can store cubes and ovoids
  229. // in a single slot.
  230. Float:E_AREA_POS[6],
  231. PlayerArray:E_AREA_PLAYERS<MAX_PLAYERS>,
  232. // This MUST go between "E_AREA_PLAYERS" and "E_AREA_FLAGS" to
  233. // remain constant in subsequent unions.
  234. //#if defined AREA_VERY_FAST
  235. // Float:E_AREA_BOUNDING[4],
  236. //#endif
  237. // As must this.
  238. #if AREA_WORLDS > 0
  239. BitArray:E_AREA_WORLDS<AREA_WORLDS>,
  240. #endif
  241. // ALWAYS last (actually used by EVERY type).
  242. e_AREA_FLAGS:E_AREA_FLAGS,
  243. // }
  244. // // Start of poly data.
  245. // struct
  246. // {
  247. // Reset the enum counter to 0 (on the next item).
  248. _E_AREA_RESET_@1 = -1,
  249. // Now restart.
  250. #if YSIM_HAS_MASTER
  251. // Skip the master flag if it exists.
  252. _E_AREA_MASTER_@1,
  253. #endif
  254. // This is where polys differ from all others.
  255. E_AREA_POLY_COUNT,
  256. E_AREA_POLY_NEXT,
  257. //Float:E_AREA_POLY_POS[4],
  258. // This slot holds ONLY the polygon bounding data, it doesn't hold
  259. // any co-ordinates AT ALL.
  260. //Float:E_AREA_BOUNDING[4],
  261. Float:E_AREA_POLY_BOUND_X,
  262. Float:E_AREA_POLY_BOUND_Y,
  263. Float:E_AREA_POLY_BOUND_R,
  264. Float:E_AREA_POLY_BOUND_H,
  265. // Skip all the array and flag data, they stay the same.
  266. _E_AREA_ARRAYS_@1[E_AREA_FLAGS - E_AREA_PLAYERS],
  267. // Skip the flags.
  268. E_AREA_UNUSED_NEXT,
  269. // }
  270. // // Start of poly child data.
  271. // struct
  272. // {
  273. // Reset the enum counter to 0 (on the next item).
  274. _E_AREA_RESET_@2 = -1,
  275. // Now restart.
  276. #if YSIM_HAS_MASTER
  277. // Skip the master flag if it exists.
  278. _E_AREA_MASTER_@2,
  279. #endif
  280. // Store a link to the parent of this poly child.
  281. E_AREA_CHILD_PARENT,
  282. // And the next one in VERY rare cases (I hope).
  283. // THIS SHARES A SLOT WITH "E_AREA_POLY_NEXT", so we can always just
  284. // use that slot when iterating.
  285. #if _:(E_AREA_FLAGS - E_AREA_CHILD_PARENT) & 1
  286. // There are an ODD number of available slots. We can store an
  287. // extra pair iff we don't need to use "NEXT".
  288. //_E_AREA_SKIP_@2,
  289. E_AREA_CHILD_OPT_Y,
  290. #endif
  291. E_AREA_CHILD_OPT_X,
  292. // Just store a vast number of X/Y pairs in this child.
  293. Float:E_AREA_CHILD_ELEMS[_:E_AREA_FLAGS - _:E_AREA_CHILD_OPT_X - 1],
  294. // Skip the flags.
  295. _E_AREA_CHILD_ELEMS_END
  296. // }
  297. }
  298. #define CHILD_AREA_SLOTS ((_:_E_AREA_CHILD_ELEMS_END - _:E_AREA_CHILD_ELEMS))
  299. static stock
  300. YSI_g_sUnusedAreas = 0,
  301. //YSI_g_sLastUnused = MAX_AREAS - 1,
  302. YSI_g_sFreeCount = MAX_AREAS,
  303. YSI_g_sAreas[MAX_AREAS][E_AREA],
  304. YSI_g_sPlayerArea[MAX_PLAYERS][AREAS_MAX_OVERLAPS], // = {NO_AREA, ...},
  305. YSI_g_sHasCallbacks,
  306. YSI_g_sZones[AREAS_ZONE_ARRAY * AREAS_ZONE_ARRAY] = {AREA_NO_NEXT, ...},
  307. // "Inner" zones. -4000 <= x, y <= 4000; Z(x) != Z(y)
  308. YSI_g_sZoneIN = AREA_NO_NEXT, // -1
  309. YSI_g_sZoneINE = AREA_NO_NEXT, // -2
  310. YSI_g_sZoneIE = AREA_NO_NEXT, // -3
  311. YSI_g_sZoneISE = AREA_NO_NEXT, // -4
  312. YSI_g_sZoneIS = AREA_NO_NEXT, // -5
  313. YSI_g_sZoneISW = AREA_NO_NEXT, // -6
  314. YSI_g_sZoneIW = AREA_NO_NEXT, // -7
  315. YSI_g_sZoneINW = AREA_NO_NEXT, // -8
  316. // "Outer" zones. -4000 > x, y > 4000;
  317. YSI_g_sZoneON = AREA_NO_NEXT, // -9
  318. YSI_g_sZoneONE = AREA_NO_NEXT, // -10
  319. YSI_g_sZoneOE = AREA_NO_NEXT, // -11
  320. YSI_g_sZoneOSE = AREA_NO_NEXT, // -12
  321. YSI_g_sZoneOS = AREA_NO_NEXT, // -13
  322. YSI_g_sZoneOSW = AREA_NO_NEXT, // -14
  323. YSI_g_sZoneOW = AREA_NO_NEXT, // -15
  324. YSI_g_sZoneONW = AREA_NO_NEXT, // -16
  325. // "Extra" zones. In a quadrant, but spanning the +-4000 boundary.
  326. YSI_g_sZoneXN = AREA_NO_NEXT, // -17
  327. YSI_g_sZoneXNE = AREA_NO_NEXT, // -18
  328. YSI_g_sZoneXE = AREA_NO_NEXT, // -19
  329. YSI_g_sZoneXSE = AREA_NO_NEXT, // -20
  330. YSI_g_sZoneXS = AREA_NO_NEXT, // -21
  331. YSI_g_sZoneXSW = AREA_NO_NEXT, // -22
  332. YSI_g_sZoneXW = AREA_NO_NEXT, // -23
  333. YSI_g_sZoneXNW = AREA_NO_NEXT, // -24
  334. // Extra zones. For when areas are too big for a quadrant.
  335. YSI_g_sZoneI = AREA_NO_NEXT, // -25
  336. //YSI_g_sZoneO = AREA_NO_NEXT, // -26
  337. YSI_g_sZoneX = AREA_NO_NEXT; // -27
  338. forward Area_Loop();
  339. /*-------------------------------------------------------------------------*//**
  340. * <remarks>
  341. * Sets up required variables. Note that this hooks "OnScriptInit",
  342. * "OnGameModeInit" and "OnFilterScript". This is because ALL scripts need to
  343. * initialise some things, and only the master needs to initialise others.
  344. * </remarks>
  345. *//*------------------------------------------------------------------------**/
  346. MASTER_HOOK__ OnScriptInit()
  347. {
  348. for (new i = 0; i != MAX_AREAS - 1; ++i)
  349. {
  350. YSI_g_sAreas[i][E_AREA_UNUSED_NEXT] = (i + 1);
  351. }
  352. YSI_g_sAreas[MAX_AREAS - 1][E_AREA_UNUSED_NEXT] = AREA_NO_NEXT;
  353. //for (new i = 0; i != AREAS_ZONE_ARRAY * AREAS_ZONE_ARRAY; ++i)
  354. //{
  355. // YSI_g_sZones[i] = -1;
  356. //}
  357. return 1;
  358. }
  359. #if !defined FILTERSCRIPT
  360. HOOK__ OnGameModeInit()
  361. {
  362. if (!YSI_FILTERSCRIPT)
  363. {
  364. new
  365. buffer;
  366. YSI_g_sHasCallbacks = 0;
  367. YSI_g_sHasCallbacks |= funcidx("OnPlayerEnterArea") == -1 ? 0 : 1;
  368. YSI_g_sHasCallbacks |= funcidx("OnPlayerLeaveArea") == -1 ? 0 : 2;
  369. YSI_g_sHasCallbacks |= AMX_GetPublicEntry(0, buffer, "@yH_PlayerEnterArea") ? 4 : 0;
  370. YSI_g_sHasCallbacks |= AMX_GetPublicEntry(0, buffer, "@yH_PlayerLeaveArea") ? 8 : 0;
  371. }
  372. }
  373. #endif
  374. HOOK__ OnFilterScriptInit()
  375. {
  376. new
  377. buffer;
  378. YSI_g_sHasCallbacks = 0;
  379. YSI_g_sHasCallbacks |= funcidx("OnPlayerEnterArea") == -1 ? 0 : 1;
  380. YSI_g_sHasCallbacks |= funcidx("OnPlayerLeaveArea") == -1 ? 0 : 2;
  381. YSI_g_sHasCallbacks |= AMX_GetPublicEntry(0, buffer, "@yH_PlayerEnterArea") ? 4 : 0;
  382. YSI_g_sHasCallbacks |= AMX_GetPublicEntry(0, buffer, "@yH_PlayerLeaveArea") ? 8 : 0;
  383. }
  384. /*-------------------------------------------------------------------------*//**
  385. * <returns>
  386. * Number of unused area slots.
  387. * </returns>
  388. *//*------------------------------------------------------------------------**/
  389. P:D(Area_GetEmptySlotCount());
  390. #define Area_GetEmptySlotCount() \
  391. (YSI_g_sFreeCount)
  392. /*-------------------------------------------------------------------------*//**
  393. * <param name="num">Number of slots to add.</param>
  394. * <remarks>
  395. * Actually removes slots from the unused count.
  396. * </remarks>
  397. *//*------------------------------------------------------------------------**/
  398. P:D(Area_AddSlots(num));
  399. #define Area_AddSlots(%1) \
  400. YSI_g_sFreeCount -= (%1)
  401. /*-------------------------------------------------------------------------*//**
  402. * <param name="area">Area to check validity of</param>
  403. * <remarks>
  404. * An area slot could be used but still invalid if it's not the first slot in
  405. * an area set.
  406. * </remarks>
  407. *//*------------------------------------------------------------------------**/
  408. P:D(bool:Area_IsActive(area));
  409. #define Area_IsActive(%1) \
  410. ((%1) >= 0 && (%1) < MAX_AREAS && (YSI_g_sAreas[(%1)][E_AREA_FLAGS] & e_AREA_FLAGS_ACTIVE))
  411. /*-------------------------------------------------------------------------*//**
  412. * <param name="area">Area to print information about.</param>
  413. *//*------------------------------------------------------------------------**/
  414. FOREIGN__ void:Area_Debug(area);
  415. GLOBAL__ void:Area_Debug(area)
  416. {
  417. new
  418. e_AREA_FLAGS:flags = YSI_g_sAreas[area][E_AREA_FLAGS];
  419. if ((flags & e_AREA_FLAGS_ACTIVE))
  420. {
  421. switch (flags & e_AREA_FLAGS_TYPE)
  422. {
  423. case e_AREA_FLAGS_POLY:
  424. {
  425. new
  426. count = YSI_g_sAreas[area][E_AREA_POLY_COUNT];
  427. printf("Poly Area %d:", area);
  428. printf("\tPoints = %d", count);
  429. printf("\tNext = %d", YSI_g_sAreas[area][E_AREA_UNUSED_NEXT] & AREA_NO_NEXT);
  430. #if AREA_WORLDS > 0
  431. printf("\tWorlds = %s", Bit_Display(YSI_g_sAreas[area][E_AREA_WORLDS], bits<AREA_WORLDS>));
  432. #else
  433. printf("\tNo Worlds");
  434. #endif
  435. printf("\tPlayers = %s", Bit_Display(YSI_g_sAreas[area][E_AREA_PLAYERS][1], bits<MAX_PLAYERS>));
  436. printf("\tBounding Circle: %.2f, %.2f, %.2f, %.2f", YSI_g_sAreas[area][E_AREA_POLY_BOUND_X], YSI_g_sAreas[area][E_AREA_POLY_BOUND_Y], floatsqroot(YSI_g_sAreas[area][E_AREA_POLY_BOUND_R]), YSI_g_sAreas[area][E_AREA_POLY_BOUND_H]);
  437. new
  438. next = YSI_g_sAreas[area][E_AREA_POLY_NEXT];
  439. while (count > 0)
  440. {
  441. printf("\tPoints Set %d:", next);
  442. for (new i = 0, j = min(count, CHILD_AREA_SLOTS); i < j; i += 2)
  443. {
  444. printf("\t\t(%.2f, %.2f)", YSI_g_sAreas[next][E_AREA_CHILD_ELEMS][i], YSI_g_sAreas[next][E_AREA_CHILD_ELEMS][i + 1]);
  445. }
  446. next = YSI_g_sAreas[next][E_AREA_POLY_NEXT];
  447. count -= CHILD_AREA_SLOTS;
  448. }
  449. }
  450. }
  451. //return 1;
  452. }
  453. //return 0;
  454. }
  455. /*-------------------------------------------------------------------------*//**
  456. * <returns>
  457. * Next available slot.
  458. * </returns>
  459. * <remarks>
  460. * Gets an empty slot, removes it from the unused list and returs a pointer.
  461. * </remarks>
  462. *//*------------------------------------------------------------------------**/
  463. static stock Area_GetFreeSlot()
  464. {
  465. P:4("Area_GetFreeSlot called");
  466. if (YSI_g_sUnusedAreas == AREA_NO_NEXT) return NO_AREA;
  467. P:7("Area_GetFreeSlot: 1");
  468. new
  469. old = YSI_g_sUnusedAreas;
  470. YSI_g_sUnusedAreas = YSI_g_sAreas[old][E_AREA_UNUSED_NEXT];
  471. --YSI_g_sFreeCount;
  472. return old;
  473. }
  474. /*-------------------------------------------------------------------------*//**
  475. * <param name="area">Area to remove from the list.</param>
  476. * <remarks>
  477. * You can only remove areas which are at the start of a list.
  478. * </remarks>
  479. *//*------------------------------------------------------------------------**/
  480. FOREIGN__ void:Area_Delete(area);
  481. GLOBAL__ void:Area_Delete(area)
  482. {
  483. if (!Area_IsActive(area))
  484. {
  485. return; //0;
  486. }
  487. new
  488. e_AREA_FLAGS:flags = YSI_g_sAreas[area][E_AREA_FLAGS];
  489. switch (flags & e_AREA_FLAGS_TYPE)
  490. {
  491. case e_AREA_FLAGS_UNUSED:
  492. {
  493. return; //0;
  494. }
  495. case e_AREA_FLAGS_CHILD:
  496. {
  497. // This is just part of a poly, remove the whole thing.
  498. Area_Delete(YSI_g_sAreas[area][E_AREA_CHILD_PARENT]);
  499. }
  500. case e_AREA_FLAGS_POLY:
  501. {
  502. // Many blocks used - hard.
  503. new
  504. count = YSI_g_sAreas[area][E_AREA_POLY_COUNT],
  505. next = YSI_g_sAreas[area][E_AREA_POLY_NEXT],
  506. prev = YSI_g_sUnusedAreas;
  507. // All all of this poly area to the old area.
  508. while (count > 0)
  509. {
  510. // Increase the free count.
  511. ++YSI_g_sFreeCount;
  512. // Decrease the stored points.
  513. count -= CHILD_AREA_SLOTS;
  514. // Change the poly list to an unused list.
  515. YSI_g_sAreas[next][E_AREA_UNUSED_NEXT] = prev;
  516. prev = next;
  517. next = YSI_g_sAreas[next][E_AREA_POLY_NEXT];
  518. }
  519. // Remove the poly header.
  520. ++YSI_g_sFreeCount;
  521. YSI_g_sAreas[area][E_AREA_UNUSED_NEXT] = prev;
  522. YSI_g_sUnusedAreas = area;
  523. }
  524. default:
  525. {
  526. // Only one block used - easy.
  527. YSI_g_sAreas[area][E_AREA_UNUSED_NEXT] = YSI_g_sUnusedAreas;
  528. YSI_g_sUnusedAreas = area;
  529. ++YSI_g_sFreeCount;
  530. }
  531. }
  532. // Remove this one from the zone it was in.
  533. Area_DoRemove(_:(flags & e_AREA_FLAGS_ZONE), area, _:(flags & e_AREA_FLAGS_NEXT));
  534. //return 1;
  535. }
  536. /*-------------------------------------------------------------------------*//**
  537. * <param name="zone">The zone this area is in (right shifted 18).</param>
  538. * <param name="start">The first of the allocated areas being removed.</param>
  539. * <param name="end">The area in this zone after the last removed one.</param>
  540. * <remarks>
  541. * Very tightly integrated with "Area_Delete", to the point where I could just
  542. * make them one function if I wanted (but I won't).
  543. * </remarks>
  544. *//*------------------------------------------------------------------------**/
  545. static stock Area_DoRemove(zone, area, next)
  546. {
  547. //printf("remove %d %d %d %d", zone << 18, area, next, (e_AREA_ZONE_I_ << 18 & _:e_AREA_FLAGS_ZONE));
  548. // Actually "zone << 18", but that's not important.
  549. switch (zone)
  550. {
  551. case (e_AREA_ZONE_I_N << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneIN, area, next);}
  552. case (e_AREA_ZONE_I_NE << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneINE, area, next);}
  553. case (e_AREA_ZONE_I_E << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneIE, area, next);}
  554. case (e_AREA_ZONE_I_SE << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneISE, area, next);}
  555. case (e_AREA_ZONE_I_S << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneIS, area, next);}
  556. case (e_AREA_ZONE_I_SW << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneISW, area, next);}
  557. case (e_AREA_ZONE_I_W << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneIW, area, next);}
  558. case (e_AREA_ZONE_I_NW << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneINW, area, next);}
  559. case (e_AREA_ZONE_I_ << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneI, area, next);}
  560. // "Outer" zones. -4000 > x, y > 4000;
  561. case (e_AREA_ZONE_O_N << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneON, area, next);}
  562. case (e_AREA_ZONE_O_NE << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneONE, area, next);}
  563. case (e_AREA_ZONE_O_E << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneOE, area, next);}
  564. case (e_AREA_ZONE_O_SE << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneOSE, area, next);}
  565. case (e_AREA_ZONE_O_S << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneOS, area, next);}
  566. case (e_AREA_ZONE_O_SW << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneOSW, area, next);}
  567. case (e_AREA_ZONE_O_W << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneOW, area, next);}
  568. case (e_AREA_ZONE_O_NW << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneONW, area, next);}
  569. //e_AREA_ZONE_O_, // Can't be in all of O, but none of I.
  570. // "Extra" zones. In a quadrant, but spanning the +-4000 boundary.
  571. case (e_AREA_ZONE_X_N << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneXN, area, next);}
  572. case (e_AREA_ZONE_X_NE << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneXNE, area, next);}
  573. case (e_AREA_ZONE_X_E << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneXE, area, next);}
  574. case (e_AREA_ZONE_X_SE << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneXSE, area, next);}
  575. case (e_AREA_ZONE_X_S << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneXS, area, next);}
  576. case (e_AREA_ZONE_X_SW << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneXSW, area, next);}
  577. case (e_AREA_ZONE_X_W << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneXW, area, next);}
  578. case (e_AREA_ZONE_X_NW << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneXNW, area, next);}
  579. // Extra zones. For when areas are too big for a quadrant.
  580. case (e_AREA_ZONE_X_ << 18 & _:e_AREA_FLAGS_ZONE): {_AREAS_DO_REMOVE(YSI_g_sZoneX, area, next);}
  581. default: {_AREAS_DO_REMOVE(YSI_g_sZones[zone >> 18], area, next);}
  582. }
  583. return 0;
  584. }
  585. /*-------------------------------------------------------------------------*//**
  586. * <param name="x">Start of an area.</param>
  587. * <param name="y">Start of an area.</param>
  588. * <returns>
  589. * All the zones this position overlaps.
  590. * </returns>
  591. * <remarks>
  592. * The most zones you can be in at once is 9 - I_, I_S, I_E, I_SE, X_, X_S,
  593. * X_E, X_SE, Z_ (or similar corners - NOT in O_ though).
  594. * </remarks>
  595. *//*------------------------------------------------------------------------**/
  596. static stock Area_GetZones(Float:x, Float:y)
  597. {
  598. // Always end with e_AREA_ZONE_X_ as they will ALWAYS be in that one (that's
  599. // basically everywhere and means the area exists somewhere ever). Once
  600. // that zone is detected, stop next loop.
  601. static const
  602. scZones[16][9] =
  603. {
  604. {e_AREA_ZONE_O_N , e_AREA_ZONE_O_NE, e_AREA_ZONE_O_E , e_AREA_ZONE_X_N , e_AREA_ZONE_X_NE, e_AREA_ZONE_X_E , e_AREA_ZONE_X_ , e_AREA_ZONE_NONE, e_AREA_ZONE_NONE},
  605. {e_AREA_ZONE_O_NE, e_AREA_ZONE_O_E , e_AREA_ZONE_X_N , e_AREA_ZONE_X_NE, e_AREA_ZONE_X_E , e_AREA_ZONE_X_ , e_AREA_ZONE_NONE, e_AREA_ZONE_NONE, e_AREA_ZONE_NONE},
  606. {e_AREA_ZONE_O_SE, e_AREA_ZONE_O_E , e_AREA_ZONE_X_S , e_AREA_ZONE_X_SE, e_AREA_ZONE_X_E , e_AREA_ZONE_X_ , e_AREA_ZONE_NONE, e_AREA_ZONE_NONE, e_AREA_ZONE_NONE},
  607. {e_AREA_ZONE_O_S , e_AREA_ZONE_O_SE, e_AREA_ZONE_O_E , e_AREA_ZONE_X_S , e_AREA_ZONE_X_SE, e_AREA_ZONE_X_E , e_AREA_ZONE_X_ , e_AREA_ZONE_NONE, e_AREA_ZONE_NONE},
  608. {e_AREA_ZONE_O_N , e_AREA_ZONE_O_NE, e_AREA_ZONE_X_N , e_AREA_ZONE_X_NE, e_AREA_ZONE_X_E , e_AREA_ZONE_X_ , e_AREA_ZONE_NONE, e_AREA_ZONE_NONE, e_AREA_ZONE_NONE},
  609. {e_AREA_ZONE_NONE, e_AREA_ZONE_I_N , e_AREA_ZONE_I_NE, e_AREA_ZONE_I_E , e_AREA_ZONE_I_ , e_AREA_ZONE_X_N , e_AREA_ZONE_X_NE, e_AREA_ZONE_X_E , e_AREA_ZONE_X_ },
  610. {e_AREA_ZONE_NONE, e_AREA_ZONE_I_S , e_AREA_ZONE_I_SE, e_AREA_ZONE_I_E , e_AREA_ZONE_I_ , e_AREA_ZONE_X_S , e_AREA_ZONE_X_SE, e_AREA_ZONE_X_E , e_AREA_ZONE_X_ },
  611. {e_AREA_ZONE_O_S , e_AREA_ZONE_O_SE, e_AREA_ZONE_X_S , e_AREA_ZONE_X_SE, e_AREA_ZONE_X_E , e_AREA_ZONE_X_ , e_AREA_ZONE_NONE, e_AREA_ZONE_NONE, e_AREA_ZONE_NONE},
  612. {e_AREA_ZONE_O_N , e_AREA_ZONE_O_NW, e_AREA_ZONE_X_N , e_AREA_ZONE_X_NW, e_AREA_ZONE_X_W , e_AREA_ZONE_X_ , e_AREA_ZONE_NONE, e_AREA_ZONE_NONE, e_AREA_ZONE_NONE},
  613. {e_AREA_ZONE_NONE, e_AREA_ZONE_I_N , e_AREA_ZONE_I_NW, e_AREA_ZONE_I_W , e_AREA_ZONE_I_ , e_AREA_ZONE_X_N , e_AREA_ZONE_X_NW, e_AREA_ZONE_X_W , e_AREA_ZONE_X_ },
  614. {e_AREA_ZONE_NONE, e_AREA_ZONE_I_S , e_AREA_ZONE_I_SW, e_AREA_ZONE_I_W , e_AREA_ZONE_I_ , e_AREA_ZONE_X_S , e_AREA_ZONE_X_SW, e_AREA_ZONE_X_W , e_AREA_ZONE_X_ },
  615. {e_AREA_ZONE_O_S , e_AREA_ZONE_O_SW, e_AREA_ZONE_X_S , e_AREA_ZONE_X_SW, e_AREA_ZONE_X_W , e_AREA_ZONE_X_ , e_AREA_ZONE_NONE, e_AREA_ZONE_NONE, e_AREA_ZONE_NONE},
  616. {e_AREA_ZONE_O_N , e_AREA_ZONE_O_NW, e_AREA_ZONE_O_W , e_AREA_ZONE_X_N , e_AREA_ZONE_X_NW, e_AREA_ZONE_X_W , e_AREA_ZONE_X_ , e_AREA_ZONE_NONE, e_AREA_ZONE_NONE},
  617. {e_AREA_ZONE_O_NW, e_AREA_ZONE_O_W , e_AREA_ZONE_X_N , e_AREA_ZONE_X_NW, e_AREA_ZONE_X_W , e_AREA_ZONE_X_ , e_AREA_ZONE_NONE, e_AREA_ZONE_NONE, e_AREA_ZONE_NONE},
  618. {e_AREA_ZONE_O_SW, e_AREA_ZONE_O_W , e_AREA_ZONE_X_S , e_AREA_ZONE_X_SW, e_AREA_ZONE_X_W , e_AREA_ZONE_X_ , e_AREA_ZONE_NONE, e_AREA_ZONE_NONE, e_AREA_ZONE_NONE},
  619. {e_AREA_ZONE_O_S , e_AREA_ZONE_O_SW, e_AREA_ZONE_O_W , e_AREA_ZONE_X_S , e_AREA_ZONE_X_SW, e_AREA_ZONE_X_W , e_AREA_ZONE_X_ , e_AREA_ZONE_NONE, e_AREA_ZONE_NONE}
  620. };
  621. if (AREAS_ZONE_BOUNDS.0 <= x)
  622. {
  623. if (AREAS_ZONE_BOUNDS.0 <= y) return scZones[ 0];
  624. else if (0.0 <= y) return scZones[ 1];
  625. else if (-AREAS_ZONE_BOUNDS.0 <= y) return scZones[ 2];
  626. else return scZones[ 3];
  627. }
  628. else if (0.0 <= x)
  629. {
  630. if (AREAS_ZONE_BOUNDS.0 <= y) return scZones[ 4];
  631. else if (0.0 <= y) return scZones[ 5]; //, ret[0] = _AREAS_MAKE_ZONE(Area_MakeZone(x), Area_MakeZone(y)));
  632. else if (-AREAS_ZONE_BOUNDS.0 <= y) return scZones[ 6]; //, ret[0] = _AREAS_MAKE_ZONE(Area_MakeZone(x), Area_MakeZone(y)));
  633. else return scZones[ 7];
  634. }
  635. else if (-AREAS_ZONE_BOUNDS.0 <= x)
  636. {
  637. if (AREAS_ZONE_BOUNDS.0 <= y) return scZones[ 8];
  638. else if (0.0 <= y) return scZones[ 9]; //, ret[0] = _AREAS_MAKE_ZONE(Area_MakeZone(x), Area_MakeZone(y)));
  639. else if (-AREAS_ZONE_BOUNDS.0 <= y) return scZones[10]; //, ret[0] = _AREAS_MAKE_ZONE(Area_MakeZone(x), Area_MakeZone(y)));
  640. else return scZones[11];
  641. }
  642. else
  643. {
  644. if (AREAS_ZONE_BOUNDS.0 <= y) return scZones[12];
  645. else if (0.0 <= y) return scZones[13];
  646. else if (-AREAS_ZONE_BOUNDS.0 <= y) return scZones[14];
  647. else return scZones[15];
  648. }
  649. }
  650. /*-------------------------------------------------------------------------*//**
  651. * <param name="minx">Start of an area.</param>
  652. * <param name="miny">Start of an area.</param>
  653. * <param name="maxx">End of an area.</param>
  654. * <param name="maxy">End of an area.</param>
  655. * <param name="area">The area to add to the determined zone.</param>
  656. * <param name="last">The last slot that makes up the current zone.</param>
  657. * <remarks>
  658. * Finds the smallest zone that this area will fit in completely. Note that
  659. * due to a limitation in the code, any zones with a node touching the upper
  660. * edge of a zone will spill in to the next zone too. Only lower zone edges
  661. * are inclusive.
  662. * </remarks>
  663. *//*------------------------------------------------------------------------**/
  664. static stock Area_DetermineZone(Float:minx, Float:miny, Float:maxx, Float:maxy, area, last)
  665. {
  666. new
  667. zx,
  668. zy;
  669. // This optimises based on the fact that (by definition) maxx can't be lower
  670. // than minx and maxy can't be lower than miny, meaning we can skip certain
  671. // checks in some cases.
  672. if (AREAS_ZONE_BOUNDS.0 <= minx) // Western edge.
  673. {
  674. if (0.0 <= miny) // Southern edge.
  675. {
  676. _AREAS_ZONES_O(NE);
  677. //YSI_g_sAreas[last][E_AREA_FLAGS]=(YSI_g_sAreas[last][E_AREA_FLAGS]&e_AREA_FLAGS_REST)|(e_AREA_FLAGS:YSI_g_sZoneXNE&e_AREA_FLAGS_NEXT|e_AREA_FLAGS(e_AREA_ZONE_X_NE<<18)&e_AREA_FLAGS_ZONE),YSI_g_sZoneXNE=area;
  678. //return _AREAS_ADD_TO_ZONE(YSI_g_sZoneXNE,area,last,e_AREA_ZONE_X_NE)
  679. }
  680. else // Southern edge.
  681. {
  682. if (0.0 <= maxy) // Northern edge.
  683. {
  684. _AREAS_ZONES_O(E);
  685. }
  686. else // Northern edge.
  687. {
  688. _AREAS_ZONES_O(SE);
  689. }
  690. }
  691. }
  692. else if (0.0 <= minx) // Western edge.
  693. {
  694. if (AREAS_ZONE_BOUNDS.0 <= miny) // Southern edge.
  695. {
  696. _AREAS_ZONES_O(NE);
  697. }
  698. else if (0.0 <= miny) // Southern edge.
  699. {
  700. if (AREAS_ZONE_BOUNDS.0 <= maxx) // Eastern edge.
  701. {
  702. _AREAS_ZONES_X(NE);
  703. }
  704. else // Eastern edge.
  705. {
  706. // Interesting case - y > 0, 0 <= x < 4000.
  707. if (AREAS_ZONE_BOUNDS.0 <= maxy) // Northern edge.
  708. {
  709. _AREAS_ZONES_X(NE);
  710. }
  711. else // Northern edge.
  712. {
  713. //_AREAS_ZONES_I_GRID;
  714. zx = Area_MakeZone(minx);
  715. zy = Area_MakeZone(miny);
  716. if (zx == Area_MakeZone(maxx) && zy == Area_MakeZone(maxy))
  717. {
  718. zy += ((zx + AREAS_ZONE_PARTS) * AREAS_ZONE_ARRAY) + AREAS_ZONE_PARTS;
  719. YSI_g_sAreas[last][E_AREA_FLAGS] =
  720. (YSI_g_sAreas[last][E_AREA_FLAGS] & e_AREA_FLAGS_REST) |
  721. (e_AREA_FLAGS:YSI_g_sZones[zy] & e_AREA_FLAGS_NEXT) |
  722. (e_AREA_FLAGS:(zy << 18) & e_AREA_FLAGS_ZONE);
  723. P:7("Area_DetermineZone: Added to North-Eastern square");
  724. return YSI_g_sZones[zy] = area;
  725. }
  726. _AREAS_ZONES_I(NE);
  727. }
  728. }
  729. }
  730. else if (-AREAS_ZONE_BOUNDS.0 <= miny) // Southern edge.
  731. {
  732. if (AREAS_ZONE_BOUNDS.0 <= maxx) // Eastern edge.
  733. {
  734. if (0.0 <= maxy) // Northern edge.
  735. {
  736. _AREAS_ZONES_X(E);
  737. }
  738. else // Northern edge.
  739. {
  740. _AREAS_ZONES_X(SE);
  741. }
  742. }
  743. else // Eastern edge.
  744. {
  745. if (AREAS_ZONE_BOUNDS.0 <= maxy) // Northern edge.
  746. {
  747. _AREAS_ZONES_X(E);
  748. }
  749. if (0.0 <= maxy) // Northern edge.
  750. {
  751. _AREAS_ZONES_I(E);
  752. }
  753. else // Northern edge.
  754. {
  755. zx = Area_MakeZone(minx);
  756. zy = Area_MakeZone(miny);
  757. if (zx == Area_MakeZone(maxx) && zy == Area_MakeZone(maxy))
  758. {
  759. zy += ((zx + AREAS_ZONE_PARTS) * AREAS_ZONE_ARRAY) + AREAS_ZONE_PARTS;
  760. YSI_g_sAreas[last][E_AREA_FLAGS] =
  761. (YSI_g_sAreas[last][E_AREA_FLAGS] & e_AREA_FLAGS_REST) |
  762. (e_AREA_FLAGS:YSI_g_sZones[zy] & e_AREA_FLAGS_NEXT) |
  763. (e_AREA_FLAGS:(zy << 18) & e_AREA_FLAGS_ZONE);
  764. return YSI_g_sZones[zy] = area;
  765. }
  766. _AREAS_ZONES_I(SE);
  767. }
  768. }
  769. }
  770. else // Southern edge.
  771. {
  772. if (0.0 <= maxy) // Northern edge.
  773. {
  774. _AREAS_ZONES_X(E);
  775. }
  776. if (-AREAS_ZONE_BOUNDS.0 <= maxy) // Northern edge.
  777. {
  778. _AREAS_ZONES_X(SE);
  779. }
  780. else // Northern edge.
  781. {
  782. _AREAS_ZONES_O(SE);
  783. }
  784. }
  785. }
  786. else if (-AREAS_ZONE_BOUNDS.0 <= minx) // Western edge.
  787. {
  788. if (AREAS_ZONE_BOUNDS.0 <= miny) // Southern edge.
  789. {
  790. if (0.0 <= maxx) // Eastern edge.
  791. {
  792. _AREAS_ZONES_O(N);
  793. }
  794. else // Eastern edge.
  795. {
  796. _AREAS_ZONES_O(NW);
  797. }
  798. }
  799. else if (0.0 <= miny) // Southern edge.
  800. {
  801. if (AREAS_ZONE_BOUNDS.0 <= maxx) // Eastern edge.
  802. {
  803. _AREAS_ZONES_X(N);
  804. }
  805. else if (0.0 <= maxx) // Eastern edge.
  806. {
  807. if (AREAS_ZONE_BOUNDS.0 <= maxy) // Northern edge.
  808. {
  809. _AREAS_ZONES_X(N);
  810. }
  811. else // Northern edge.
  812. {
  813. _AREAS_ZONES_I(N);
  814. }
  815. }
  816. else // Eastern edge.
  817. {
  818. if (AREAS_ZONE_BOUNDS.0 <= maxy) // Northern edge.
  819. {
  820. _AREAS_ZONES_X(NW);
  821. }
  822. else // Northern edge.
  823. {
  824. zx = Area_MakeZone(minx);
  825. zy = Area_MakeZone(miny);
  826. if (zx == Area_MakeZone(maxx) && zy == Area_MakeZone(maxy))
  827. {
  828. zy += ((zx + AREAS_ZONE_PARTS) * AREAS_ZONE_ARRAY) + AREAS_ZONE_PARTS;
  829. YSI_g_sAreas[last][E_AREA_FLAGS] =
  830. (YSI_g_sAreas[last][E_AREA_FLAGS] & e_AREA_FLAGS_REST) |
  831. (e_AREA_FLAGS:YSI_g_sZones[zy] & e_AREA_FLAGS_NEXT) |
  832. (e_AREA_FLAGS:(zy << 18) & e_AREA_FLAGS_ZONE);
  833. return YSI_g_sZones[zy] = area;
  834. }
  835. _AREAS_ZONES_I(NW);
  836. }
  837. }
  838. }
  839. else if (-AREAS_ZONE_BOUNDS.0 <= miny) // Southern edge.
  840. {
  841. if (AREAS_ZONE_BOUNDS.0 <= maxx) // Eastern edge.
  842. {
  843. if (0.0 <= maxy) // Northern edge.
  844. {
  845. _AREAS_ZONES_X();
  846. }
  847. else // Northern edge.
  848. {
  849. _AREAS_ZONES_X(S);
  850. }
  851. }
  852. else if (0.0 <= maxx) // Eastern edge.
  853. {
  854. if (AREAS_ZONE_BOUNDS.0 <= maxy) // Northern edge.
  855. {
  856. _AREAS_ZONES_X();
  857. }
  858. else if (0.0 <= maxy) // Northern edge.
  859. {
  860. _AREAS_ZONES_I();
  861. }
  862. else // Northern edge.
  863. {
  864. _AREAS_ZONES_I(S);
  865. }
  866. }
  867. else // Eastern edge.
  868. {
  869. if (AREAS_ZONE_BOUNDS.0 <= maxy) // Northern edge.
  870. {
  871. _AREAS_ZONES_X(W);
  872. }
  873. else if (0.0 <= maxy) // Northern edge.
  874. {
  875. _AREAS_ZONES_I(W);
  876. }
  877. else // Northern edge.
  878. {
  879. zx = Area_MakeZone(minx);
  880. zy = Area_MakeZone(miny);
  881. if (zx == Area_MakeZone(maxx) && zy == Area_MakeZone(maxy))
  882. {
  883. zy += ((zx + AREAS_ZONE_PARTS) * AREAS_ZONE_ARRAY) + AREAS_ZONE_PARTS;
  884. YSI_g_sAreas[last][E_AREA_FLAGS] =
  885. (YSI_g_sAreas[last][E_AREA_FLAGS] & e_AREA_FLAGS_REST) |
  886. (e_AREA_FLAGS:YSI_g_sZones[zy] & e_AREA_FLAGS_NEXT) |
  887. (e_AREA_FLAGS:(zy << 18) & e_AREA_FLAGS_ZONE);
  888. return YSI_g_sZones[zy] = area;
  889. }
  890. _AREAS_ZONES_I(SW);
  891. }
  892. }
  893. }
  894. else // Southern edge.
  895. {
  896. if (0.0 <= maxx) // Eastern edge.
  897. {
  898. if (-AREAS_ZONE_BOUNDS.0 <= maxy) // Northern edge.
  899. {
  900. _AREAS_ZONES_X(S);
  901. }
  902. else // Northern edge.
  903. {
  904. _AREAS_ZONES_O(S);
  905. }
  906. }
  907. else // Eastern edge.
  908. {
  909. if (-AREAS_ZONE_BOUNDS.0 <= maxy) // Northern edge.
  910. {
  911. _AREAS_ZONES_X(SW);
  912. }
  913. else // Northern edge.
  914. {
  915. _AREAS_ZONES_O(SW);
  916. }
  917. }
  918. }
  919. }
  920. else // Western edge.
  921. {
  922. if (AREAS_ZONE_BOUNDS.0 <= miny) // Southern edge.
  923. {
  924. if (0.0 <= maxx) // Eastern edge.
  925. {
  926. _AREAS_ZONES_O(N);
  927. }
  928. else // Eastern edge.
  929. {
  930. // I missed this one and the compiler didn't complain about the
  931. // path not returning - I think I confused it!
  932. _AREAS_ZONES_O(NW);
  933. }
  934. }
  935. else if (0.0 <= miny) // Southern edge.
  936. {
  937. if (0.0 <= maxx) // Eastern edge.
  938. {
  939. _AREAS_ZONES_X(N);
  940. }
  941. else if (-AREAS_ZONE_BOUNDS.0 <= maxx) // Eastern edge.
  942. {
  943. _AREAS_ZONES_X(NW);
  944. }
  945. else // Eastern edge.
  946. {
  947. _AREAS_ZONES_O(NW);
  948. }
  949. }
  950. else if (-AREAS_ZONE_BOUNDS.0 <= miny) // Southern edge.
  951. {
  952. if (0.0 <= maxx) // Eastern edge.
  953. {
  954. if (0.0 <= maxy) // Northern edge.
  955. {
  956. _AREAS_ZONES_X();
  957. }
  958. else
  959. {
  960. _AREAS_ZONES_X(S);
  961. }
  962. }
  963. else if (-AREAS_ZONE_BOUNDS.0 <= maxx) // Eastern edge.
  964. {
  965. if (0.0 <= maxy) // Northern edge.
  966. {
  967. _AREAS_ZONES_X(W);
  968. }
  969. else // Northern edge.
  970. {
  971. _AREAS_ZONES_X(SW);
  972. }
  973. }
  974. else // Eastern edge.
  975. {
  976. if (0.0 <= maxy) // Northern edge.
  977. {
  978. _AREAS_ZONES_O(W);
  979. }
  980. else // Northern edge.
  981. {
  982. _AREAS_ZONES_O(SW);
  983. }
  984. }
  985. }
  986. else // Southern edge.
  987. {
  988. if (0.0 <= maxx) // Eastern edge.
  989. {
  990. if (0.0 <= maxy) // Northern edge.
  991. {
  992. _AREAS_ZONES_X();
  993. }
  994. else if (-AREAS_ZONE_BOUNDS.0 <= maxy) // Northern edge.
  995. {
  996. _AREAS_ZONES_X(S);
  997. }
  998. else // Northern edge.
  999. {
  1000. _AREAS_ZONES_O(S);
  1001. }
  1002. }
  1003. else if (-AREAS_ZONE_BOUNDS.0 <= maxx) // Eastern edge.
  1004. {
  1005. if (0.0 <= maxy) // Northern edge.
  1006. {
  1007. _AREAS_ZONES_X(W);
  1008. }
  1009. else if (-AREAS_ZONE_BOUNDS.0 <= maxy) // Northern edge.
  1010. {
  1011. _AREAS_ZONES_X(SW);
  1012. }
  1013. else // Northern edge.
  1014. {
  1015. _AREAS_ZONES_O(SW);
  1016. }
  1017. }
  1018. else // Eastern edge.
  1019. {
  1020. if (0.0 <= maxy) // Northern edge.
  1021. {
  1022. _AREAS_ZONES_O(W);
  1023. }
  1024. else // Northern edge.
  1025. {
  1026. _AREAS_ZONES_O(SW);
  1027. }
  1028. }
  1029. }
  1030. }
  1031. }
  1032. /*-------------------------------------------------------------------------*//**
  1033. * <param name="area">Area to set for.</param>
  1034. * <param name="set">Wether or not this area is usable in all worlds.</param>
  1035. *//*------------------------------------------------------------------------**/
  1036. /*-------------------------------------------------------------------------*//**
  1037. * <param name="area">Area to set for.</param>
  1038. * <param name="set">Wether or not this area is usable in all worlds.</param>
  1039. *//*------------------------------------------------------------------------**/
  1040. FOREIGN__ void:Area_SetAllWorlds(area, bool:set);
  1041. GLOBAL__ void:Area_SetAllWorlds(area, bool:set)
  1042. {
  1043. #if AREA_WORLDS > 0
  1044. if (Area_IsActive(area))
  1045. {
  1046. Bit_SetAll(YSI_g_sAreas[area][E_AREA_WORLDS], set, bits<AREA_WORLDS>);
  1047. //return 1;
  1048. }
  1049. #else
  1050. #pragma unused area, set
  1051. #endif
  1052. //return 0;
  1053. }
  1054. /*-------------------------------------------------------------------------*//**
  1055. * <param name="type">Type of area.</param>
  1056. * <param name="">Points.</param>
  1057. * <remarks>
  1058. * Types:
  1059. * CUBE, Cube
  1060. * CUBOID, Cuboid
  1061. * BOX, Box
  1062. * CIRCLE, Circle
  1063. * OVAL, Oval
  1064. * OVOID, Ovoid
  1065. * SPHERE, Sphere
  1066. * POLY, Poly
  1067. * </remarks>
  1068. *//*------------------------------------------------------------------------**/
  1069. P:D(Area_Add(type,Float:...));
  1070. #define Area_Add(%0,%1) Area_Add%0(%1)
  1071. #define Area_AddCUBE Area_AddCube
  1072. #define Area_AddCUBOID Area_AddCuboid
  1073. #define Area_AddBOX Area_AddBox
  1074. #define Area_AddCIRCLE Area_AddCircle
  1075. #define Area_AddOVAL Area_AddOval
  1076. #define Area_AddOVOID Area_AddOvoid
  1077. #define Area_AddSPHERE Area_AddSphere
  1078. #define Area_AddPOLY Area_AddPoly
  1079. /*-------------------------------------------------------------------------*//**
  1080. * <param name="minx">Lowest X corner of box</param>
  1081. * <param name="miny">Lowest Y corner of box.</param>
  1082. * <param name="minx">Lowest Z corner of box.</param>
  1083. * <param name="maxx">Highest X corner of box.</param>
  1084. * <param name="maxy">Highest Y corner of box.</param>
  1085. * <param name="maxz">Highest Z corner of box.</param>
  1086. * <returns>
  1087. * Area slot or NO_AREA
  1088. * </returns>
  1089. *//*------------------------------------------------------------------------**/
  1090. P:D(_AREA_MIN(&Float:minx,&Float:miny));
  1091. #define _AREA_MIN(%0,%1) if (%1 < %0) %0 ^= %1, %1 ^= %0, %0 ^= %1
  1092. FOREIGN__ Area_AddCuboid(Float:x0,Float:y0,Float:z0,Float:x1,Float:y1,Float:z1);
  1093. GLOBAL__ Area_AddCuboid(Float:x0,Float:y0,Float:z0,Float:x1,Float:y1,Float:z1)
  1094. {
  1095. new
  1096. slot = Area_GetFreeSlot();
  1097. if (slot == NO_AREA) return NO_AREA;
  1098. _AREA_MIN(x0, x1);
  1099. _AREA_MIN(y0, y1);
  1100. _AREA_MIN(z0, z1);
  1101. YSI_g_sAreas[slot][E_AREA_FLAGS] = e_AREA_FLAGS_CUBE | e_AREA_FLAGS_ACTIVE;
  1102. YSI_g_sAreas[slot][E_AREA_POS][0] = x0;
  1103. YSI_g_sAreas[slot][E_AREA_POS][1] = y0;
  1104. YSI_g_sAreas[slot][E_AREA_POS][2] = z0;
  1105. YSI_g_sAreas[slot][E_AREA_POS][3] = x1;
  1106. YSI_g_sAreas[slot][E_AREA_POS][4] = y1;
  1107. YSI_g_sAreas[slot][E_AREA_POS][5] = z1;
  1108. PA_FastInit(YSI_g_sAreas[slot][E_AREA_PLAYERS]);
  1109. NO_GROUPS<Area>(slot)
  1110. {
  1111. PA_Init(YSI_g_sAreas[slot][E_AREA_PLAYERS], true);
  1112. }
  1113. #if YSIM_HAS_MASTER
  1114. YSI_g_sAreas[slot][E_AREA_MASTER] = Master_Caller();
  1115. #endif
  1116. Area_SetAllWorlds(slot, true);
  1117. Area_DetermineZone(x0, y0, x1, y1, slot, slot);
  1118. /*#if defined AREA_VERY_FAST
  1119. new
  1120. rx = (x1 - z0) / 2.0,
  1121. ry = (y1 - y0) / 2.0,
  1122. rz = (z1 - z0) / 2.0;
  1123. YSI_g_sAreas[slot][E_AREA_BOUNDING][0] = x0 + rx;
  1124. YSI_g_sAreas[slot][E_AREA_BOUNDING][1] = y0 + ry;
  1125. YSI_g_sAreas[slot][E_AREA_BOUNDING][2] = z0 + rz;
  1126. if (rx > ry && rx > rz)
  1127. {
  1128. YSI_g_sAreas[slot][E_AREA_BOUNDING][3] = rx * rx;
  1129. }
  1130. else if (ry > rz)
  1131. {
  1132. YSI_g_sAreas[slot][E_AREA_BOUNDING][3] = ry * ry;
  1133. }
  1134. else
  1135. {
  1136. YSI_g_sAreas[slot][E_AREA_BOUNDING][3] = rz * rz;
  1137. }
  1138. #endif*/
  1139. return slot;
  1140. }
  1141. #undef _AREA_MIN
  1142. #define Area_AddCube Area_AddCuboid
  1143. /*-------------------------------------------------------------------------*//**
  1144. * <param name="minx">Lowest X corner of box</param>
  1145. * <param name="miny">Lowest Y corner of box.</param>
  1146. * <param name="maxx">Highest X corner of box.</param>
  1147. * <param name="maxy">Highest Y corner of box.</param>
  1148. * <returns>
  1149. * Area slot or NO_AREA
  1150. * </returns>
  1151. *//*------------------------------------------------------------------------**/
  1152. stock Area_AddBox(Float:minx, Float:miny, Float:maxx, Float:maxy)
  1153. {
  1154. return Area_AddCuboid(minx, miny, FLOAT_NEGATIVE_INFINITY, maxx, maxy, FLOAT_INFINITY);
  1155. }
  1156. /*
  1157. FOREIGN__ Area_AddBox(Float:minx, Float:miny, Float:maxx, Float:maxy);
  1158. GLOBAL__ Area_AddBox(Float:minx, Float:miny, Float:maxx, Float:maxy)
  1159. {
  1160. new
  1161. slot;
  1162. if (minx > maxx)
  1163. {
  1164. slot = _:minx;
  1165. minx = maxx;
  1166. maxx = Float:slot;
  1167. }
  1168. if (miny > maxy)
  1169. {
  1170. slot = _:miny;
  1171. miny = maxy;
  1172. maxy = Float:slot;
  1173. }
  1174. slot = Area_GetFreeSlot();
  1175. if (slot == NO_AREA) return NO_AREA;
  1176. YSI_g_sAreas[slot][E_AREA_FLAGS] = SINGLE_SLOT_AREA | e_AREA_FLAGS_BOX | e_AREA_FLAGS_USED | e_AREA_FLAGS_ACTIVE | e_AREA_FLAGS:(1 << 18);
  1177. YSI_g_sAreas[slot][E_AREA_POS][0] = minx;
  1178. YSI_g_sAreas[slot][E_AREA_POS][1] = miny;
  1179. YSI_g_sAreas[slot][E_AREA_POS][2] = maxx;
  1180. YSI_g_sAreas[slot][E_AREA_POS][3] = maxy;
  1181. PA_FastInit(YSI_g_sAreas[slot][E_AREA_PLAYERS]);
  1182. NO_GROUPS<Area>(slot)
  1183. {
  1184. PA_Init(YSI_g_sAreas[slot][E_AREA_PLAYERS], true);
  1185. }
  1186. #if YSIM_HAS_MASTER
  1187. YSI_g_sAreas[slot][E_AREA_MASTER] = Master_Caller();
  1188. #endif
  1189. Area_SetAllWorlds(slot, true);
  1190. Area_DetermineZone(minx, miny, maxx, maxy, slot, slot);
  1191. return slot;
  1192. }
  1193. */
  1194. /*-------------------------------------------------------------------------*//**
  1195. * <param name="x">X position of circle.</param>
  1196. * <param name="y">Y position of circle.</param>
  1197. * <param name="r">Radius of circle.</param>
  1198. * <param name="height">Ceiling of circle.</param>
  1199. * <param name="depth">Bottom of circle.</param>
  1200. * <returns>
  1201. * Area slot or NO_AREA
  1202. * </returns>
  1203. * <remarks>
  1204. * Technically a cylinder, no lower bound (ceiling added cos there was a
  1205. * spare slot in the 4 float design which may as well have been used).
  1206. * </remarks>
  1207. *//*------------------------------------------------------------------------**/
  1208. stock Area_AddCircle(Float:x, Float:y, Float:r, Float:height = FLOAT_INFINITY)
  1209. {
  1210. return Area_AddOval(x, y, r, r, height, FLOAT_NEGATIVE_INFINITY);
  1211. }
  1212. /*-------------------------------------------------------------------------*//**
  1213. * <param name="x">X position of circle.</param>
  1214. * <param name="y">Y position of circle.</param>
  1215. * <param name="rx">X Radius of oval.</param>
  1216. * <param name="ry">Y Radius of oval.</param>
  1217. * <param name="height">Ceiling of circle.</param>
  1218. * <param name="depth">Bottom of circle.</param>
  1219. * <returns>
  1220. * Area slot or NO_AREA
  1221. * </returns>
  1222. * <remarks>
  1223. * Technically a cylinder, no lower bound (ceiling added cos there was a
  1224. * spare slot in the 4 float design which may as well have been used).
  1225. * </remarks>
  1226. *//*------------------------------------------------------------------------**/
  1227. FOREIGN__ Area_AddOval(Float:x,Float:y,Float:rx,Float:ry,Float:h,Float:d);
  1228. GLOBAL__ Area_AddOval(Float:x,Float:y,Float:rx,Float:ry,Float:h,Float:d)
  1229. {
  1230. new
  1231. slot = Area_GetFreeSlot();
  1232. if (slot == NO_AREA) return NO_AREA;
  1233. //printf("%f %f %f %f", x - r, y - r, x + r, y + r);
  1234. YSI_g_sAreas[slot][E_AREA_FLAGS] = e_AREA_FLAGS_ACTIVE;
  1235. YSI_g_sAreas[slot][E_AREA_POS][0] = x;
  1236. YSI_g_sAreas[slot][E_AREA_POS][1] = y;
  1237. YSI_g_sAreas[slot][E_AREA_POS][2] = rx * rx;
  1238. YSI_g_sAreas[slot][E_AREA_POS][3] = ry * ry;
  1239. YSI_g_sAreas[slot][E_AREA_POS][4] = h;
  1240. YSI_g_sAreas[slot][E_AREA_POS][5] = d;
  1241. PA_FastInit(YSI_g_sAreas[slot][E_AREA_PLAYERS]);
  1242. NO_GROUPS<Area>(slot)
  1243. {
  1244. PA_Init(YSI_g_sAreas[slot][E_AREA_PLAYERS], true);
  1245. }
  1246. #if YSIM_HAS_MASTER
  1247. YSI_g_sAreas[slot][E_AREA_MASTER] = Master_Caller();
  1248. #endif
  1249. Area_SetAllWorlds(slot, true);
  1250. Area_DetermineZone(x - rx, y - ry, x + rx, y + ry, slot, slot);
  1251. if (rx == ry && h == FLOAT_INFINITY && d == FLOAT_NEGATIVE_INFINITY)
  1252. {
  1253. YSI_g_sAreas[slot][E_AREA_FLAGS] |= e_AREA_FLAGS_CIRCLE;
  1254. }
  1255. else
  1256. {
  1257. YSI_g_sAreas[slot][E_AREA_FLAGS] |= e_AREA_FLAGS_OVAL;
  1258. }
  1259. // Bounding sphere. I'm not convinced this is needed on the simple shapes,
  1260. // I may only use it on polys and special-case
  1261. /*#if defined AREA_VERY_FAST
  1262. YSI_g_sAreas[slot][E_AREA_BOUNDING][0] = x;
  1263. YSI_g_sAreas[slot][E_AREA_BOUNDING][1] = y;
  1264. // Z radius of the bounding sphere (may be VERY huge).
  1265. new
  1266. rz = (h - d) / 2.0;
  1267. YSI_g_sAreas[slot][E_AREA_BOUNDING][2] = h - rz;
  1268. if (rx > ry && rx > rz)
  1269. {
  1270. YSI_g_sAreas[slot][E_AREA_BOUNDING][3] = rx * rx;
  1271. }
  1272. else if (ry > rz)
  1273. {
  1274. YSI_g_sAreas[slot][E_AREA_BOUNDING][3] = ry * ry;
  1275. }
  1276. else
  1277. {
  1278. YSI_g_sAreas[slot][E_AREA_BOUNDING][3] = rz * rz;
  1279. }
  1280. #endif*/
  1281. return slot;
  1282. }
  1283. /*-------------------------------------------------------------------------*//**
  1284. * <param name="x">X position of sphere.</param>
  1285. * <param name="y">Y position of sphere.</param>
  1286. * <param name="z">Z position of sphere.</param>
  1287. * <param name="r">Radius of sphere.</param>
  1288. * <returns>
  1289. * Area slot or NO_AREA
  1290. * </returns>
  1291. *//*------------------------------------------------------------------------**/
  1292. stock Area_AddSphere(Float:x, Float:y, Float:z, Float:r)
  1293. {
  1294. return Area_AddOvoid(x, y, z, r, r, r);
  1295. }
  1296. /*-------------------------------------------------------------------------*//**
  1297. * <param name="x">X position of sphere.</param>
  1298. * <param name="y">Y position of sphere.</param>
  1299. * <param name="z">Z position of sphere.</param>
  1300. * <param name="rx">X radius of ovoid.</param>
  1301. * <param name="ry">Y radius of ovoid.</param>
  1302. * <param name="rz">Z radius of ovoid.</param>
  1303. * <returns>
  1304. * Area slot or NO_AREA
  1305. * </returns>
  1306. *//*------------------------------------------------------------------------**/
  1307. FOREIGN__ Area_AddOvoid(Float:x,Float:y,Float:z,Float:rx,Float:ry,Float:rz);
  1308. GLOBAL__ Area_AddOvoid(Float:x,Float:y,Float:z,Float:rx,Float:ry,Float:rz)
  1309. {
  1310. new
  1311. slot = Area_GetFreeSlot();
  1312. if (slot == NO_AREA) return NO_AREA;
  1313. YSI_g_sAreas[slot][E_AREA_FLAGS] = e_AREA_FLAGS_ACTIVE;
  1314. YSI_g_sAreas[slot][E_AREA_POS][0] = x;
  1315. YSI_g_sAreas[slot][E_AREA_POS][1] = y;
  1316. YSI_g_sAreas[slot][E_AREA_POS][2] = z;
  1317. YSI_g_sAreas[slot][E_AREA_POS][3] = rx * rx;
  1318. YSI_g_sAreas[slot][E_AREA_POS][4] = ry * ry;
  1319. YSI_g_sAreas[slot][E_AREA_POS][5] = rz * rz;
  1320. PA_FastInit(YSI_g_sAreas[slot][E_AREA_PLAYERS]);
  1321. NO_GROUPS<Area>(slot)
  1322. {
  1323. PA_Init(YSI_g_sAreas[slot][E_AREA_PLAYERS], true);
  1324. }
  1325. #if YSIM_HAS_MASTER
  1326. YSI_g_sAreas[slot][E_AREA_MASTER] = Master_Caller();
  1327. #endif
  1328. Area_SetAllWorlds(slot, true);
  1329. Area_DetermineZone(x - rx, y - ry, x + rx, y + ry, slot, slot);
  1330. // Create the bounding sphere for this zone. The player has to be inside
  1331. // the bounding sphere before they can be inside the oval. Of course, if
  1332. // the oval is also a sphere then these two checks are identical.
  1333. #if defined AREA_VERY_FAST
  1334. YSI_g_sAreas[slot][E_AREA_BOUNDING][0] = x;
  1335. YSI_g_sAreas[slot][E_AREA_BOUNDING][1] = y;
  1336. YSI_g_sAreas[slot][E_AREA_BOUNDING][2] = z;
  1337. if (rx > ry && rx > rz)
  1338. {
  1339. YSI_g_sAreas[slot][E_AREA_BOUNDING][3] = rx * rx;
  1340. }
  1341. else if (ry > rz)
  1342. {
  1343. YSI_g_sAreas[slot][E_AREA_BOUNDING][3] = ry * ry;
  1344. }
  1345. else
  1346. {
  1347. YSI_g_sAreas[slot][E_AREA_BOUNDING][3] = rz * rz;
  1348. }
  1349. if (rx == ry && rx == rz)
  1350. {
  1351. YSI_g_sAreas[slot][E_AREA_FLAGS] |= e_AREA_FLAGS_SPHERE;
  1352. }
  1353. else
  1354. #endif
  1355. {
  1356. // Create the zone bounds.
  1357. YSI_g_sAreas[slot][E_AREA_POS][0] = x;
  1358. YSI_g_sAreas[slot][E_AREA_POS][1] = y;
  1359. YSI_g_sAreas[slot][E_AREA_POS][2] = z;
  1360. YSI_g_sAreas[slot][E_AREA_POS][3] = rx * rx;
  1361. YSI_g_sAreas[slot][E_AREA_POS][4] = ry * ry;
  1362. YSI_g_sAreas[slot][E_AREA_POS][5] = rz * rz;
  1363. // Set this as not a sphere.
  1364. YSI_g_sAreas[slot][E_AREA_FLAGS] |= e_AREA_FLAGS_OVOID;
  1365. }
  1366. #pragma tabsize 4
  1367. return slot;
  1368. }
  1369. /*-------------------------------------------------------------------------*//**
  1370. * <param name="">X/Ys of points</param>
  1371. * <returns>
  1372. * Area slot or NO_AREA
  1373. * </returns>
  1374. * <remarks>
  1375. * Creates an irregular shape to detect players in. This is a 2d area made
  1376. * up of a load of XY points. If an odd number of parameters is passed the
  1377. * extra one is assumed to be a ceiling so you can ignore interiors or planes.
  1378. *
  1379. * The height parameter goes first as it's easiest to check.
  1380. *
  1381. * This is one of a few functions still written using the master system at a
  1382. * low level (the other obvious one is "Class_Add").
  1383. * </remarks>
  1384. *//*------------------------------------------------------------------------**/
  1385. #if YSIM_HAS_MASTER
  1386. #if _YSIM_IS_SERVER
  1387. forward Area_AddPoly(Float:x1, Float:y1, Float:x2, Float:y2, Float:x3, Float:y3, Float:...);
  1388. forward Area_AddPoly@(Float:points[], size, count);
  1389. stock Area_AddPoly(Float:x1, Float:y1, Float:x2, Float:y2, Float:x3, Float:y3, Float:...)
  1390. {
  1391. new
  1392. args = numargs();
  1393. if (args > 128)
  1394. {
  1395. return NO_AREA;
  1396. }
  1397. new
  1398. Float:points[128];
  1399. points[0] = x1;
  1400. points[1] = y1;
  1401. points[2] = x2;
  1402. points[3] = y2;
  1403. points[4] = x3;
  1404. points[5] = y3;
  1405. for (new i = 6; i != args; ++i)
  1406. {
  1407. points[i] = Float:getarg(i);
  1408. }
  1409. return Area_AddPoly@(points, sizeof (points), args);
  1410. }
  1411. public Area_AddPoly@(Float:points[], size, count)
  1412. #else
  1413. stock Area_AddPoly(Float:x1, Float:y1, Float:x2, Float:y2, Float:x3, Float:y3, Float:...) <>
  1414. {
  1415. new
  1416. args = numargs();
  1417. if (args > 128)
  1418. {
  1419. return NO_AREA;
  1420. }
  1421. new
  1422. Float:points[128];
  1423. points[0] = x1;
  1424. points[1] = y1;
  1425. points[2] = x2;
  1426. points[3] = y2;
  1427. points[4] = x3;
  1428. points[5] = y3;
  1429. for (new i = 6; i != args; ++i)
  1430. {
  1431. points[i] = Float:getarg(i);
  1432. }
  1433. new
  1434. p = getproperty(8, YSIM_CALLER);
  1435. setproperty(8, YSIM_CALLER, Master_ID());
  1436. CallRemoteFunction("Area_AddPoly@", "aii", points, sizeof (points), args);
  1437. setproperty(8, YSIM_CALLER, p);
  1438. return getproperty(8, YSIM_RETURN);
  1439. }
  1440. forward Area_AddPoly@(Float:points[], size, count);
  1441. stock Area_AddPoly(Float:x1, Float:y1, Float:x2, Float:y2, Float:x3, Float:y3, Float:...) <_YCM : m>
  1442. {
  1443. #pragma unused x1, y1, x2, y2, x3, y3
  1444. return NO_AREA;
  1445. }
  1446. #if _YSIM_IS_CLIENT
  1447. static stock Area_AddPoly_(Float:x1, Float:y1, Float:x2, Float:y2, Float:x3, Float:y3, Float:...)
  1448. #else
  1449. #if _YSIM_IS_STUB
  1450. #error _YSIM_IS_STUB set in y_areas.
  1451. #else
  1452. public Area_AddPoly@(Float:points[], size, count) <>
  1453. {
  1454. return 0;
  1455. }
  1456. stock Area_AddPoly(Float:x1, Float:y1, Float:x2, Float:y2, Float:x3, Float:y3, Float:...) <_YCM : y>
  1457. {
  1458. new
  1459. args = numargs();
  1460. if (args > 128)
  1461. {
  1462. return NO_AREA;
  1463. }
  1464. new
  1465. Float:points[128];
  1466. points[0] = x1;
  1467. points[1] = y1;
  1468. points[2] = x2;
  1469. points[3] = y2;
  1470. points[4] = x3;
  1471. points[5] = y3;
  1472. for (new i = 6; i != args; ++i)
  1473. {
  1474. points[i] = Float:getarg(i);
  1475. }
  1476. return Area_AddPoly@(points, sizeof (points), args);
  1477. }
  1478. public Area_AddPoly@(Float:points[], size, count) <_YCM : y>
  1479. #endif
  1480. #endif
  1481. #endif
  1482. #else
  1483. stock Area_AddPoly(Float:x1, Float:y1, Float:x2, Float:y2, Float:x3, Float:y3, Float:...)
  1484. {
  1485. new
  1486. args = numargs();
  1487. if (args > 128)
  1488. {
  1489. return NO_AREA;
  1490. }
  1491. new
  1492. Float:points[128];
  1493. points[0] = x1;
  1494. points[1] = y1;
  1495. points[2] = x2;
  1496. points[3] = y2;
  1497. points[4] = x3;
  1498. points[5] = y3;
  1499. for (new i = 6; i != args; ++i)
  1500. {
  1501. points[i] = Float:getarg(i);
  1502. }
  1503. return Area_AddPoly_(points, sizeof (points), args);
  1504. }
  1505. static stock Area_AddPoly_(Float:points[], size, count)
  1506. #endif
  1507. {
  1508. // This is the main chunk of the code.
  1509. new
  1510. Float:height = Float:isodd(count);
  1511. count &= ~1;
  1512. new
  1513. reqSlots = ceildiv(count, CHILD_AREA_SLOTS) + 1;
  1514. if (Area_GetEmptySlotCount() < reqSlots) return NO_AREA;
  1515. if (_:height)
  1516. {
  1517. height = points[count];
  1518. }
  1519. else
  1520. {
  1521. height = FLOAT_INFINITY;
  1522. }
  1523. // Get the header. This stores meta-data about the poly area, and the
  1524. // bounding cylinder, it doesn't actually store any points.
  1525. new
  1526. header = Area_GetFreeSlot();
  1527. // Initialise the header. Area type, players, worlds, and count.
  1528. // This stores the number of pairs, not the number of co-ordinates.
  1529. YSI_g_sAreas[header][E_AREA_POLY_COUNT] = count;
  1530. YSI_g_sAreas[header][E_AREA_FLAGS] = e_AREA_FLAGS_POLY | e_AREA_FLAGS_ACTIVE;
  1531. PA_FastInit(YSI_g_sAreas[header][E_AREA_PLAYERS]);
  1532. NO_GROUPS<Area>(header)
  1533. {
  1534. PA_Init(YSI_g_sAreas[header][E_AREA_PLAYERS], true);
  1535. }
  1536. #if YSIM_HAS_MASTER
  1537. YSI_g_sAreas[header][E_AREA_MASTER] = Master_Caller();
  1538. #endif
  1539. Area_SetAllWorlds(header, true);
  1540. // Now loop through and store all the data points.
  1541. new
  1542. slot,
  1543. prev = header,
  1544. done = 0,
  1545. Float:cur,
  1546. Float:minx = FLOAT_INFINITY,
  1547. Float:miny = FLOAT_INFINITY,
  1548. Float:maxx = FLOAT_NEGATIVE_INFINITY,
  1549. Float:maxy = FLOAT_NEGATIVE_INFINITY;
  1550. while (done < count)
  1551. //while (done < count)
  1552. {
  1553. slot = Area_GetFreeSlot();
  1554. YSI_g_sAreas[slot][E_AREA_FLAGS] = e_AREA_FLAGS_ACTIVE | e_AREA_FLAGS_CHILD;
  1555. // Rely purely on counts, not ended lists. This is because the system
  1556. // MAY (if I get around to it) reuse this data in the last slot to
  1557. //YSI_g_sAreas[slot][E_AREA_POLY_NEXT] = NO_AREA;
  1558. YSI_g_sAreas[slot][E_AREA_CHILD_PARENT] = header;
  1559. YSI_g_sAreas[prev][E_AREA_POLY_NEXT] = slot;
  1560. #if YSIM_HAS_MASTER
  1561. YSI_g_sAreas[slot][E_AREA_MASTER] = Master_Caller();
  1562. #endif
  1563. // Now loop and put points in this slot.
  1564. size = min(count, done + CHILD_AREA_SLOTS);
  1565. for (new idx = 0; done < size; )
  1566. {
  1567. // X point.
  1568. cur = points[done++];
  1569. //printf("%d X: %0.2f", done, cur);
  1570. //printf("%04x%04x %04x%04x %.2f %d %d", _:minx >>> 16, _:minx & 0xFFFF, _:maxx >>> 16, _:maxx & 0xFFFF, cur, cur > maxx, cur < minx);
  1571. if (cur > maxx) maxx = cur;
  1572. if (cur < minx) minx = cur;
  1573. YSI_g_sAreas[slot][E_AREA_CHILD_ELEMS][idx++] = cur;
  1574. // Y point.
  1575. cur = points[done++];
  1576. //printf("%d Y: %0.2f", done, cur);
  1577. // Can be both on the first loop (WILL be both on the first loop).
  1578. if (cur > maxy) maxy = cur;
  1579. if (cur < miny) miny = cur;
  1580. YSI_g_sAreas[slot][E_AREA_CHILD_ELEMS][idx++] = cur;
  1581. }
  1582. prev = slot;
  1583. //count -= CHILD_AREA_SLOTS * 2;
  1584. }
  1585. // Now clean up.
  1586. #if YSIM_HAS_MASTER
  1587. setproperty(8, YSIM_RETURN, header);
  1588. #endif
  1589. Area_DetermineZone(minx, miny, maxx, maxy, header, header);
  1590. // Create the bounding cylinder so we can quickly determine if it is even
  1591. // at all possible for the player to be in this polygon.
  1592. // TODO: This doesn't YET create an accurate bounding cylinder as the
  1593. // diagonals of a square are longer than the width and height, and that fact
  1594. // isn't taken in to account by the radius. The question is, why are these
  1595. // sums returning -0.0 for 20.0-0.0?
  1596. // BIZZARE BUG FIX.
  1597. //printf("%f %f %f %f", minx, miny, maxx, maxy);
  1598. //printf("%f %f", maxx - minx, maxy - miny);
  1599. //printf("%04x%04x", _:minx >>> 16, _:minx & 0xFFFF);
  1600. //printf("%04x%04x", _:maxx >>> 16, _:maxx & 0xFFFF);
  1601. //if (maxx && minx) printf("1: %d", (maxx = (maxx - minx) / 2.0));
  1602. //else if (maxx) printf("2: %d", (maxx /= 2.0));
  1603. //else printf("3: %d", (maxx = minx / 2.0));
  1604. //if (maxx < 0.0) maxx = -maxx;
  1605. //if (maxy && miny) maxy = (maxy - miny) / 2.0;
  1606. //else if (maxy) maxy /= 2.0;
  1607. //else maxy = miny / 2.0;
  1608. //if (maxy < 0.0) maxy = -maxy;
  1609. //printf("%f %f %f %f", (maxx - minx) / 2.0, (maxy - miny) / 2.0, minx + (maxx - minx) / 2.0, miny + (maxy - miny) / 2.0);
  1610. maxx = (maxx - minx) / 2.0;
  1611. maxy = (maxy - miny) / 2.0;
  1612. //printf("%f %f %f %f", maxx, maxy, minx + maxx, miny + maxy);
  1613. minx += maxx;
  1614. miny += maxy;
  1615. YSI_g_sAreas[header][E_AREA_POLY_BOUND_X] = minx;
  1616. YSI_g_sAreas[header][E_AREA_POLY_BOUND_Y] = miny;
  1617. // Now find the radius. Note that it might actually make more sense to not
  1618. // use the dead centre but a point which minimises the R^2 distance, but
  1619. // that will require a lot more work.
  1620. slot = YSI_g_sAreas[header][E_AREA_POLY_NEXT];
  1621. count = YSI_g_sAreas[header][E_AREA_POLY_COUNT];
  1622. cur = 0.0;
  1623. while (count > 0)
  1624. {
  1625. for (new i = 0, j = min(count, CHILD_AREA_SLOTS); i < j; i += 2)
  1626. {
  1627. // Get the difference between the points.
  1628. maxx = YSI_g_sAreas[slot][E_AREA_CHILD_ELEMS][i] - minx;
  1629. maxy = YSI_g_sAreas[slot][E_AREA_CHILD_ELEMS][i + 1] - miny;
  1630. maxx = maxx * maxx + maxy * maxy;
  1631. if (maxx > cur) cur = maxx;
  1632. }
  1633. slot = YSI_g_sAreas[slot][E_AREA_POLY_NEXT];
  1634. count -= CHILD_AREA_SLOTS;
  1635. }
  1636. YSI_g_sAreas[header][E_AREA_POLY_BOUND_R] = cur;
  1637. YSI_g_sAreas[header][E_AREA_POLY_BOUND_H] = height;
  1638. return header;
  1639. }
  1640. /*-------------------------------------------------------------------------*//**
  1641. * <param name="playerid">Player who connected</param>
  1642. *//*------------------------------------------------------------------------**/
  1643. MASTER_HOOK__ OnPlayerConnect(playerid)
  1644. {
  1645. for (new i = 0; i != AREAS_MAX_OVERLAPS; ++i)
  1646. {
  1647. YSI_g_sPlayerArea[playerid][i] = NO_AREA;
  1648. }
  1649. NO_GROUPS<Area>()
  1650. {
  1651. new
  1652. slot = Bit_Slot(playerid) + 1,
  1653. Bit:mask = Bit_Mask(playerid);
  1654. for (new i = 0; i != MAX_AREAS; ++i)
  1655. {
  1656. YSI_g_sAreas[i][E_AREA_PLAYERS][slot] |= mask;
  1657. }
  1658. }
  1659. return 1;
  1660. }
  1661. /*-------------------------------------------------------------------------*//**
  1662. * <param name="playerid">The player to check for.</param>
  1663. * <remarks>
  1664. * Main processing for the system. Takes one player and checks if they're in
  1665. * some sort of range of somewhere.
  1666. * </remarks>
  1667. *//*------------------------------------------------------------------------**/
  1668. #if defined AREAS_USE_TIMER
  1669. #error AREAS_USE_TIMER is currently unsupported sorry.
  1670. ptask Area_Loop[200](playerid)
  1671. {
  1672. new
  1673. Float:x,
  1674. Float:y,
  1675. Float:z,
  1676. area = YSI_g_sPlayerArea[playerid],
  1677. world = GetPlayerVirtualWorld(playerid);
  1678. GetPlayerPos(playerid, x, y, z);
  1679. if (area != NO_AREA)
  1680. {
  1681. if (Area_CheckArea(playerid, world, area, x, y, z)) continue;
  1682. YSI_g_sPlayerArea[playerid] = NO_AREA;
  1683. #if defined _YSI_GAMEMODE_PROPERTIES
  1684. if (!Property_OnPlayerLeaveArea(playerid, area))
  1685. #endif
  1686. CallRemoteFunction("OnPlayerLeaveArea", "ii", playerid, area);
  1687. }
  1688. for (area = 0; area < MAX_AREAS; area++)
  1689. {
  1690. if (Area_CheckArea(playerid, world, area, x, y, z))
  1691. {
  1692. YSI_g_sPlayerArea[playerid] = area;
  1693. CallRemoteFunction("OnPlayerEnterArea", "ii", playerid, area);
  1694. break;
  1695. }
  1696. }
  1697. }
  1698. #else
  1699. HOOK__ OnPlayerUpdate(playerid)
  1700. {
  1701. static
  1702. // Another hard-coded limit (max areas we can actually be in, more
  1703. // than the max that is globally stored, but still not infinate).
  1704. sAreas[16],
  1705. sZones[9],
  1706. Float:sX,
  1707. Float:sY,
  1708. Float:sZ,
  1709. sCur,
  1710. sNext,
  1711. sW,
  1712. sAlready;
  1713. new
  1714. in,
  1715. idx;
  1716. // Get all the zones for this player.
  1717. GetPlayerPos(playerid, sX, sY, sZ);
  1718. P:7("Areas_OnPlayerUpdate: pos = %f %f %f", sX, sY, sZ);
  1719. #if AREA_WORLDS > 0
  1720. sW = GetPlayerVirtualWorld(playerid);
  1721. #endif
  1722. for ( ; (sCur = _Area_GetPlayerAreas(playerid, idx)) != NO_AREA; )
  1723. {
  1724. // In this zone too.
  1725. if (Area_CheckArea(playerid, sW, sCur, sX, sY, sZ, sNext, sAreas, 0))
  1726. {
  1727. ++idx;
  1728. sAreas[in++] = sCur;
  1729. }
  1730. else
  1731. {
  1732. // No longer in the area they used to be in.
  1733. Area_DoLeave(playerid, sCur, idx);
  1734. // "Area_DoLeave" shifts all the slots, so you end up with not
  1735. // needing to change "idx" at all.
  1736. }
  1737. }
  1738. sAlready = in;
  1739. sZones = Area_GetZones(sX, sY);
  1740. for (idx = 0; ; )
  1741. {
  1742. P:7("Areas_OnPlayerUpdate: zone = %d", sZones[idx]);
  1743. switch (sZones[idx++])
  1744. {
  1745. case e_AREA_ZONE_I_N:
  1746. {
  1747. _AREA_DO_ALL(YSI_g_sZoneIN);
  1748. }
  1749. case e_AREA_ZONE_I_NE:
  1750. {
  1751. _AREA_DO_ALL(YSI_g_sZoneINE);
  1752. }
  1753. case e_AREA_ZONE_I_E:
  1754. {
  1755. _AREA_DO_ALL(YSI_g_sZoneIE);
  1756. }
  1757. case e_AREA_ZONE_I_SE:
  1758. {
  1759. _AREA_DO_ALL(YSI_g_sZoneISE);
  1760. }
  1761. case e_AREA_ZONE_I_S:
  1762. {
  1763. _AREA_DO_ALL(YSI_g_sZoneIS);
  1764. }
  1765. case e_AREA_ZONE_I_SW:
  1766. {
  1767. _AREA_DO_ALL(YSI_g_sZoneISW);
  1768. }
  1769. case e_AREA_ZONE_I_W:
  1770. {
  1771. _AREA_DO_ALL(YSI_g_sZoneIW);
  1772. }
  1773. case e_AREA_ZONE_I_NW:
  1774. {
  1775. _AREA_DO_ALL(YSI_g_sZoneINW);
  1776. }
  1777. case e_AREA_ZONE_I_:
  1778. {
  1779. _AREA_DO_ALL(YSI_g_sZoneI);
  1780. }
  1781. // "Outer" zones.
  1782. case e_AREA_ZONE_O_N:
  1783. {
  1784. _AREA_DO_ALL(YSI_g_sZoneON);
  1785. }
  1786. case e_AREA_ZONE_O_NE:
  1787. {
  1788. _AREA_DO_ALL(YSI_g_sZoneONE);
  1789. }
  1790. case e_AREA_ZONE_O_E:
  1791. {
  1792. _AREA_DO_ALL(YSI_g_sZoneOE);
  1793. }
  1794. case e_AREA_ZONE_O_SE:
  1795. {
  1796. _AREA_DO_ALL(YSI_g_sZoneOSE);
  1797. }
  1798. case e_AREA_ZONE_O_S:
  1799. {
  1800. _AREA_DO_ALL(YSI_g_sZoneOS);
  1801. }
  1802. case e_AREA_ZONE_O_SW:
  1803. {
  1804. _AREA_DO_ALL(YSI_g_sZoneOSW);
  1805. }
  1806. case e_AREA_ZONE_O_W:
  1807. {
  1808. _AREA_DO_ALL(YSI_g_sZoneOW);
  1809. }
  1810. case e_AREA_ZONE_O_NW:
  1811. {
  1812. _AREA_DO_ALL(YSI_g_sZoneONW);
  1813. }
  1814. //case e_AREA_ZONE_O_:
  1815. //{
  1816. // _AREA_DO_ALL(YSI_g_sZoneO);
  1817. //}
  1818. case e_AREA_ZONE_X_N:
  1819. {
  1820. _AREA_DO_ALL(YSI_g_sZoneXN);
  1821. }
  1822. case e_AREA_ZONE_X_NE:
  1823. {
  1824. _AREA_DO_ALL(YSI_g_sZoneXNE);
  1825. }
  1826. case e_AREA_ZONE_X_E:
  1827. {
  1828. _AREA_DO_ALL(YSI_g_sZoneXE);
  1829. }
  1830. case e_AREA_ZONE_X_SE:
  1831. {
  1832. _AREA_DO_ALL(YSI_g_sZoneXSE);
  1833. }
  1834. case e_AREA_ZONE_X_S:
  1835. {
  1836. _AREA_DO_ALL(YSI_g_sZoneXS);
  1837. }
  1838. case e_AREA_ZONE_X_SW:
  1839. {
  1840. _AREA_DO_ALL(YSI_g_sZoneXSW);
  1841. }
  1842. case e_AREA_ZONE_X_W:
  1843. {
  1844. _AREA_DO_ALL(YSI_g_sZoneXW);
  1845. }
  1846. case e_AREA_ZONE_X_NW:
  1847. {
  1848. _AREA_DO_ALL(YSI_g_sZoneXNW);
  1849. }
  1850. case e_AREA_ZONE_X_:
  1851. {
  1852. // Always the last zone in the list.
  1853. _AREA_DO_ALL(YSI_g_sZoneX);
  1854. break;
  1855. }
  1856. case e_AREA_ZONE_NONE:
  1857. {
  1858. // Specific zone (which).
  1859. _AREA_DO_ALL(YSI_g_sZones[((Area_MakeZone(sX) + AREAS_ZONE_PARTS) * AREAS_ZONE_ARRAY) + AREAS_ZONE_PARTS + Area_MakeZone(sY)]);
  1860. }
  1861. }
  1862. }
  1863. return 1;
  1864. }
  1865. #endif
  1866. /*-------------------------------------------------------------------------*//**
  1867. * <param name="playerid">Player being checked for.</param>
  1868. * <param name="world">VW the player is in.</param>
  1869. * <param name="area">Area to check against.</param>
  1870. * <param name="x">X position to check.</param>
  1871. * <param name="y">Y position to check.</param>
  1872. * <param name="z">Z position to check.</param>
  1873. * <remarks>
  1874. * Checks if the given position is in the give area. All parameters are passed
  1875. * to avoid calling functions over and over and over again. If the return is
  1876. * not true, "area" is updated to the next one in the chain.
  1877. * </remarks>
  1878. *//*------------------------------------------------------------------------**/
  1879. static stock Area_CheckArea(playerid, world, area, Float:x, Float:y, Float:z, &next, const areas[16], already)
  1880. {
  1881. new
  1882. e_AREA_FLAGS:flags = YSI_g_sAreas[area][E_AREA_FLAGS];
  1883. next = YSI_g_sAreas[area][E_AREA_UNUSED_NEXT] & AREA_NO_NEXT;
  1884. // Are they already in this area?
  1885. while (already--)
  1886. {
  1887. if (areas[already] == area)
  1888. {
  1889. return 0;
  1890. }
  1891. }
  1892. if ((flags & e_AREA_FLAGS_ACTIVE))
  1893. {
  1894. P:7("Area_CheckArea: %d %d %d %f %f %f = %d", playerid, world, area, Float:x, Float:y, Float:z, _:(flags & e_AREA_FLAGS_TYPE) >>> 28);
  1895. switch (flags & e_AREA_FLAGS_TYPE)
  1896. {
  1897. case e_AREA_FLAGS_CIRCLE:
  1898. {
  1899. // In range of a sphere perfectly level with them.
  1900. if (!IsPlayerInRangeOfPoint(playerid, YSI_g_sAreas[area][E_AREA_POS][2], YSI_g_sAreas[area][E_AREA_POS][0], YSI_g_sAreas[area][E_AREA_POS][1], z))
  1901. {
  1902. return 0;
  1903. }
  1904. }
  1905. case e_AREA_FLAGS_OVAL:
  1906. {
  1907. if (!Area_IsInCircle(x, y, x, YSI_g_sAreas[area][E_AREA_POS]))
  1908. {
  1909. return 0;
  1910. }
  1911. }
  1912. case e_AREA_FLAGS_OVOID:
  1913. {
  1914. if (!Area_IsInOvoid(x, y, z, YSI_g_sAreas[area][E_AREA_POS]))
  1915. {
  1916. return 0;
  1917. }
  1918. }
  1919. case e_AREA_FLAGS_SPHERE:
  1920. {
  1921. if (!IsPlayerInRangeOfPoint(playerid, YSI_g_sAreas[area][E_AREA_POS][3], YSI_g_sAreas[area][E_AREA_POS][0], YSI_g_sAreas[area][E_AREA_POS][1], YSI_g_sAreas[area][E_AREA_POS][2]))
  1922. {
  1923. return 0;
  1924. }
  1925. }
  1926. case e_AREA_FLAGS_POLY:
  1927. {
  1928. if (!Area_IsInPoly(x, y, z, area))
  1929. {
  1930. return 0;
  1931. }
  1932. }
  1933. case e_AREA_FLAGS_CUBE:
  1934. {
  1935. if (!Area_IsInCube(x, y, z, YSI_g_sAreas[area][E_AREA_POS]))
  1936. {
  1937. return 0;
  1938. }
  1939. }
  1940. }
  1941. P:7("Area_CheckArea: MAYBE");
  1942. if (PA_Get(YSI_g_sAreas[area][E_AREA_PLAYERS], playerid))
  1943. {
  1944. #if AREA_WORLDS > 0
  1945. if (Bit_Get(YSI_g_sAreas[area][E_AREA_WORLDS], world))
  1946. {
  1947. return 1;
  1948. }
  1949. #else
  1950. #pragma unused world
  1951. return 1;
  1952. #endif
  1953. }
  1954. }
  1955. return 0;
  1956. }
  1957. /*-------------------------------------------------------------------------*//**
  1958. * <param name="x">X position to check.</param>
  1959. * <param name="y">Y position to check.</param>
  1960. * <param name="z">Z position to check.</param>
  1961. * <param name="bounds">Data for the area position.</param>
  1962. * <remarks>
  1963. * Checks if a point is in a given circle.
  1964. * </remarks>
  1965. *//*------------------------------------------------------------------------**/
  1966. static stock Area_IsInCircle(Float:x, Float:y, Float:z, const Float:bounds[])
  1967. {
  1968. x -= bounds[0];
  1969. y -= bounds[1];
  1970. return (bounds[4] <= z <= bounds[5] && ((x * x) / bounds[2] + (y * y) / bounds[3]) < 1.0);
  1971. }
  1972. /*-------------------------------------------------------------------------*//**
  1973. * <param name="x">X position to check.</param>
  1974. * <param name="y">Y position to check.</param>
  1975. * <param name="z">Z position to check.</param>
  1976. * <param name="bounds">Data for the area position.</param>
  1977. * <remarks>
  1978. * Checks if a point is in a given sphere.
  1979. * </remarks>
  1980. *//*------------------------------------------------------------------------**/
  1981. /*static stock Area_IsInSphere(Float:x, Float:y, Float:z, Float:bounds[])
  1982. {
  1983. x -= bounds[0];
  1984. y -= bounds[1];
  1985. z -= bounds[2];
  1986. return (((x * x) + (y * y) + (z * z)) < bounds[3]);
  1987. }*/
  1988. /*-------------------------------------------------------------------------*//**
  1989. * <param name="x">X position to check.</param>
  1990. * <param name="y">Y position to check.</param>
  1991. * <param name="z">Z position to check.</param>
  1992. * <param name="bounds">Data for the area position.</param>
  1993. * <remarks>
  1994. * Checks if a point is in a given ovoid.
  1995. * </remarks>
  1996. *//*------------------------------------------------------------------------**/
  1997. static stock Area_IsInOvoid(Float:x, Float:y, Float:z, const Float:bounds[])
  1998. {
  1999. x -= bounds[0];
  2000. y -= bounds[1];
  2001. z -= bounds[2];
  2002. return (((x * x) / bounds[3] + (y * y) / bounds[4] + (z * z) / bounds[5]) < 1.0);
  2003. }
  2004. /*-------------------------------------------------------------------------*//**
  2005. * <param name="x">X position to check.</param>
  2006. * <param name="y">Y position to check.</param>
  2007. * <param name="z">Z position to check.</param>
  2008. * <param name="header">Pointer to the start of the polygon data in the array.</param>
  2009. * <remarks>
  2010. * Based on IsPlayerInAreaEx by koolk in the useful functions topic. The
  2011. * passed pointer is the pointer to the first set of co-ordinates in a one-
  2012. * way not looping linked list of points in the polygod as the data may be
  2013. * spread throughout the areas array. This is as otherwise there may be
  2014. * enough free spaces but not in one block.
  2015. *
  2016. * The code first checks if there is a height component as it's the easiest
  2017. * to check thus may save a load of pointless processing. If this passes it
  2018. * then does the main loop. This loops till there are no points left to do
  2019. * (monitored by decreasing count). When 2 points (four pieces of data) have
  2020. * been checked the poiner for the data is moved on to the next group and the
  2021. * checking continues.
  2022. *
  2023. * For simplicity's sake (and thus speed's sake) the lower pointes from the
  2024. * last check are saved amd used as the upper points for the next check to
  2025. * avoid loads of repeated array accesses and saving the last array position.
  2026. * </remarks>
  2027. *//*------------------------------------------------------------------------**/
  2028. /*static*/
  2029. stock Area_IsInPoly(Float:x, Float:y, Float:z, header)
  2030. {
  2031. // First check the bounding zone.
  2032. new
  2033. Float:bx = x - YSI_g_sAreas[header][E_AREA_POLY_BOUND_X],
  2034. Float:by = y - YSI_g_sAreas[header][E_AREA_POLY_BOUND_Y];
  2035. P:7("Area_IsInPoly: %f %f %f %d", x, y, z, header);
  2036. P:7("Area_IsInPoly: %f %f %f %d", YSI_g_sAreas[header][E_AREA_POLY_BOUND_H], (bx * bx + by * by),YSI_g_sAreas[header][E_AREA_POLY_BOUND_R], (z <= YSI_g_sAreas[header][E_AREA_POLY_BOUND_H] && (bx * bx + by * by) <= YSI_g_sAreas[header][E_AREA_POLY_BOUND_R]));
  2037. if (!(z <= YSI_g_sAreas[header][E_AREA_POLY_BOUND_H] && (bx * bx + by * by) <= YSI_g_sAreas[header][E_AREA_POLY_BOUND_R]))
  2038. {
  2039. return 0;
  2040. }
  2041. // Within the bounding cylinder, do the more complex checks.
  2042. new
  2043. count = YSI_g_sAreas[header][E_AREA_POLY_COUNT];
  2044. P:7("Area_IsInPoly: In the bounds: %d %d", count, CHILD_AREA_SLOTS);
  2045. if (count <= CHILD_AREA_SLOTS)
  2046. {
  2047. // Only uses one single child slot.
  2048. header = YSI_g_sAreas[header][E_AREA_POLY_NEXT];
  2049. new
  2050. lines,
  2051. done = 2,
  2052. Float:fx = YSI_g_sAreas[header][E_AREA_CHILD_ELEMS][0],
  2053. Float:fy = YSI_g_sAreas[header][E_AREA_CHILD_ELEMS][1],
  2054. Float:x0 = fx,
  2055. Float:y0 = fy,
  2056. Float:x1,
  2057. Float:y1;
  2058. while (done < count)
  2059. {
  2060. x1 = YSI_g_sAreas[header][E_AREA_CHILD_ELEMS][done++];
  2061. y1 = YSI_g_sAreas[header][E_AREA_CHILD_ELEMS][done++];
  2062. // Crosses this line.
  2063. //P:7("Area_IsInPoly: %f %f %f", y0, y, y1);
  2064. if (((y0 <= y <= y1) || (y1 <= y <= y0)) && ((x0 + ((y - y0) * (x1 - x0) / (y1 - y0))) <= x)) ++lines;
  2065. //P:7("Area_IsInPoly: %d %d %d %d %d", (y0 <= y <= y1), (y1 <= y <= y0), (y0 <= y <= y1) || (y1 <= y <= y0), (x0 + ((y - y0) * (x1 - x0) / (y1 - y0))) <= x, lines);
  2066. x0 = x1;
  2067. y0 = y1;
  2068. }
  2069. //P:7("Area_IsInPoly: %f %f %f", y0, y, fy);
  2070. if (((y0 <=y <= fy) || (fy <= y <= y0)) && (x0 + ((y - y0) * (fx - x0) / (fy - y0))) <= x) ++lines;
  2071. //P:7("Area_IsInPoly: %d %d %d %d %d", (y0 <= y <= fy), (fy <= y <= y0), (y0 <= y <= fy) || (fy <= y <= y0), (x0 + ((y - y0) * (fx - x0) / (fy - y0))) <= x, lines);
  2072. //P:7("Area_IsInPoly: Return %d", lines);
  2073. return isodd(lines);
  2074. }
  2075. else
  2076. {
  2077. // Has multiple children
  2078. header = YSI_g_sAreas[header][E_AREA_POLY_NEXT];
  2079. new
  2080. stp,
  2081. lines,
  2082. done = 2,
  2083. Float:fx = YSI_g_sAreas[header][E_AREA_CHILD_ELEMS][0],
  2084. Float:fy = YSI_g_sAreas[header][E_AREA_CHILD_ELEMS][1],
  2085. Float:x0 = fx,
  2086. Float:y0 = fy,
  2087. Float:x1,
  2088. Float:y1;
  2089. while (count > 0)
  2090. {
  2091. stp = min(count, CHILD_AREA_SLOTS);
  2092. while (done < stp)
  2093. {
  2094. x1 = YSI_g_sAreas[header][E_AREA_CHILD_ELEMS][done++];
  2095. y1 = YSI_g_sAreas[header][E_AREA_CHILD_ELEMS][done++];
  2096. // Crosses this line.
  2097. if (((y0 <= y <= y1) || (y1 <= y <= y0)) && (x0 + ((y - y0) * (x1 - x0) / (y1 - y0))) <= x) ++lines;
  2098. x0 = x1;
  2099. y0 = y1;
  2100. }
  2101. count -= CHILD_AREA_SLOTS;
  2102. done = 0;
  2103. header = YSI_g_sAreas[header][E_AREA_POLY_NEXT];
  2104. }
  2105. //x1 = YSI_g_sAreas[pointer][E_AREA_CHILD_ELEMS][0];
  2106. // Link the last and first points to complete the perimeter.
  2107. if (((y0 <=y <= fy) || (fy <= y <= y0)) && (x0 + ((y - y0) * (fx - x0) / (fy - y0))) <= x) ++lines;
  2108. //printf("Area_IsInPoly: Return %d", lines);
  2109. return isodd(lines);
  2110. }
  2111. }
  2112. /*-------------------------------------------------------------------------*//**
  2113. * <param name="x">X position to check.</param>
  2114. * <param name="y">Y position to check.</param>
  2115. * <param name="z">Z position to check.</param>
  2116. * <param name="lower">The lower corner of the cube.</param>
  2117. * <param name="upper">The upper corner of the cube.</param>
  2118. * <remarks>
  2119. * Checks if a point is in a given cube. This is another multi slot shape
  2120. * but is much simpler than the poly as it's always 2 slots so we can easilly
  2121. * get the data in one lump.
  2122. * </remarks>
  2123. *//*------------------------------------------------------------------------**/
  2124. static stock Area_IsInCube(Float:x, Float:y, Float:z, const Float:bounds[])
  2125. {
  2126. return (bounds[0] <= x <= bounds[3] && bounds[1] <= y <= bounds[4] && bounds[2] <= z <= bounds[5]);
  2127. }
  2128. /*-------------------------------------------------------------------------*//**
  2129. * <param name="x">X position to check.</param>
  2130. * <param name="y">Y position to check.</param>
  2131. * <param name="bounds">Data for the area position.</param>
  2132. * <remarks>
  2133. * Checks if a point is in a given box. There is no height check with this
  2134. * one as any one area slot has 4 points which for this are upper and lower
  2135. * x and y, adding a height check would make it require 2 slots and basically
  2136. * make it a cube check.
  2137. * </remarks>
  2138. *//*------------------------------------------------------------------------**/
  2139. /*static stock Area_IsInBox(Float:x, Float:y, Float:bounds[])
  2140. {
  2141. return (bounds[0] <= x <= bounds[2] && bounds[1] <= y <= bounds[3]);
  2142. }*/
  2143. /*-------------------------------------------------------------------------*//**
  2144. * <param name="playerid">Player to get area of.</param>
  2145. * <returns>
  2146. * The area a player is in or -1.
  2147. * </returns>
  2148. * <remarks>
  2149. * Deprecated.
  2150. * </remarks>
  2151. *//*------------------------------------------------------------------------**/
  2152. //foreign Area_GetPlayerArea(playerid);
  2153. #pragma deprecated Use Area_GetPlayerAreas
  2154. stock Area_GetPlayerArea(playerid)
  2155. {
  2156. if (VALID_PLAYERID(playerid))
  2157. {
  2158. return YSI_g_sPlayerArea[playerid][0];
  2159. }
  2160. return NO_AREA;
  2161. }
  2162. /*-------------------------------------------------------------------------*//**
  2163. * <param name="playerid">Player to set areas of.</param>
  2164. * <param name="idx">Which slot to set.</param>
  2165. * <param name="area">The area to store in that slot.</param>
  2166. * <remarks>
  2167. * Sets a player as in a slot.
  2168. * </remarks>
  2169. *//*------------------------------------------------------------------------**/
  2170. static stock
  2171. _Area_SetPlayerAreas(playerid, idx, area)
  2172. {
  2173. if (idx < AREAS_MAX_OVERLAPS)
  2174. {
  2175. YSI_g_sPlayerArea[playerid][idx] = area;
  2176. }
  2177. else
  2178. {
  2179. // Use PVars to store extended areas.
  2180. static
  2181. sProp[12] = "y_areas_";
  2182. valstr(sProp[8], idx);
  2183. if (area == NO_AREA)
  2184. {
  2185. DeletePVar(playerid, sProp);
  2186. }
  2187. else
  2188. {
  2189. SetPVarInt(playerid, sProp, area);
  2190. }
  2191. }
  2192. }
  2193. /*-------------------------------------------------------------------------*//**
  2194. * <summary>
  2195. * _Area_GetPlayerAreas
  2196. * Area_GetPlayerAreas
  2197. * </summary>
  2198. * <param name="playerid">Player to get areas of.</param>
  2199. * <param name="idx">Which area to get.</param>
  2200. * <returns>
  2201. * The area a player is in or -1.
  2202. * </returns>
  2203. * <remarks>
  2204. * Replaces Area_GetPlayerArea for multiple areas. Includes an internal
  2205. * version for tighter loops within this code to use once it is known that a
  2206. * player exists, and without using the global function system.
  2207. * </remarks>
  2208. *//*------------------------------------------------------------------------**/
  2209. static stock
  2210. _Area_GetPlayerAreas(playerid, idx)
  2211. {
  2212. if (idx < AREAS_MAX_OVERLAPS)
  2213. {
  2214. return YSI_g_sPlayerArea[playerid][idx];
  2215. }
  2216. else
  2217. {
  2218. // Use PVars to store extended areas.
  2219. static
  2220. sProp[12] = "y_areas_";
  2221. valstr(sProp[8], idx);
  2222. if (GetPVarType(playerid, sProp) == PLAYER_VARTYPE_INT)
  2223. {
  2224. return GetPVarInt(playerid, sProp);
  2225. }
  2226. }
  2227. return NO_AREA;
  2228. }
  2229. FOREIGN__ Area_GetPlayerAreas(playerid, idx);
  2230. GLOBAL__ Area_GetPlayerAreas(playerid, idx)
  2231. {
  2232. if (VALID_PLAYERID(playerid))
  2233. {
  2234. if (0 <= idx <= 999)
  2235. {
  2236. return _Area_GetPlayerAreas(playerid, idx);
  2237. }
  2238. }
  2239. return NO_AREA;
  2240. }
  2241. /*-------------------------------------------------------------------------*//**
  2242. * <param name="area">Area to set for.</param>
  2243. * <param name="playerid">Player to set for.</param>
  2244. * <param name="set">Wether or not the player can use the area.</param>
  2245. *//*------------------------------------------------------------------------**/
  2246. FOREIGN__ void:Area_SetPlayer(area, playerid, bool:set);
  2247. GLOBAL__ void:Area_SetPlayer(area, playerid, bool:set)
  2248. {
  2249. if (Area_IsActive(area))
  2250. {
  2251. PA_Set(YSI_g_sAreas[area][E_AREA_PLAYERS], playerid, set);
  2252. //return 1;
  2253. }
  2254. //return 0;
  2255. }
  2256. /*-------------------------------------------------------------------------*//**
  2257. * <param name="area">Area to get for.</param>
  2258. * <param name="playerid">Player to get for.</param>
  2259. * <remarks>
  2260. * Can the player USE this area (not are they in it)?
  2261. * </remarks>
  2262. *//*------------------------------------------------------------------------**/
  2263. FOREIGN__ bool:Area_GetPlayer(area, playerid);
  2264. GLOBAL__ bool:Area_GetPlayer(area, playerid)
  2265. {
  2266. if (Area_IsActive(area))
  2267. {
  2268. return PA_Get(YSI_g_sAreas[area][E_AREA_PLAYERS], playerid);
  2269. }
  2270. return false;
  2271. }
  2272. /*-------------------------------------------------------------------------*//**
  2273. * <param name="area">Area to set for.</param>
  2274. * <param name="world">World to set for.</param>
  2275. * <param name="set">Wether or not the area is active in this world.</param>
  2276. *//*------------------------------------------------------------------------**/
  2277. FOREIGN__ void:Area_SetWorld(area, world, bool:set);
  2278. GLOBAL__ void:Area_SetWorld(area, world, bool:set)
  2279. {
  2280. #if AREA_WORLDS > 0
  2281. if (Area_IsActive(area))
  2282. {
  2283. Bit_Set(YSI_g_sAreas[area][E_AREA_WORLDS], world, set);
  2284. //return 1;
  2285. }
  2286. #else
  2287. #pragma unused area, world, set
  2288. #endif
  2289. //return 0;
  2290. }
  2291. /*-------------------------------------------------------------------------*//**
  2292. * <param name="area">Area to set for.</param>
  2293. * <param name="world">World to set for.</param>
  2294. *//*------------------------------------------------------------------------**/
  2295. FOREIGN__ bool:Area_GetWorld(area, world);
  2296. GLOBAL__ bool:Area_GetWorld(area, world)
  2297. {
  2298. #if AREA_WORLDS > 0
  2299. if (Area_IsActive(area))
  2300. {
  2301. return Bit_Get(YSI_g_sAreas[area][E_AREA_WORLDS], world);
  2302. }
  2303. return false;
  2304. #else
  2305. #pragma unused area, world
  2306. return true;
  2307. #endif
  2308. }
  2309. /*-------------------------------------------------------------------------*//**
  2310. * <param name="area">Area to set for.</param>
  2311. * <param name="set">Wether or not all players can use this area.</param>
  2312. *//*------------------------------------------------------------------------**/
  2313. FOREIGN__ void:Area_SetAllPlayers(area, bool:set);
  2314. GLOBAL__ void:Area_SetAllPlayers(area, bool:set)
  2315. {
  2316. if (Area_IsActive(area))
  2317. {
  2318. PA_Init(YSI_g_sAreas[area][E_AREA_PLAYERS], set);
  2319. //return 1;
  2320. }
  2321. //return 0;
  2322. }
  2323. /*-------------------------------------------------------------------------*//**
  2324. * <param name="area">Area to check.</param>
  2325. * <returns>
  2326. * Is the passed area valid and active.
  2327. * </returns>
  2328. *//*------------------------------------------------------------------------**/
  2329. FOREIGN__ bool:Area_IsValid(area);
  2330. GLOBAL__ bool:Area_IsValid(area)
  2331. {
  2332. return bool:Area_IsActive(area);
  2333. }
  2334. /*-------------------------------------------------------------------------*//**
  2335. * <param name="area">Area to check.</param>
  2336. * <returns>
  2337. * Is the passed area valid and empty.
  2338. * </returns>
  2339. * <remarks>
  2340. * Currently very slow as it has to loop through multiple players! I may add
  2341. * an entry counter to zones to make this O(1) instead of O(nm).
  2342. * </remarks>
  2343. *//*------------------------------------------------------------------------**/
  2344. FOREIGN__ bool:Area_IsEmpty(area);
  2345. GLOBAL__ bool:Area_IsEmpty(area)
  2346. {
  2347. new
  2348. z;
  2349. if (Area_IsActive(area))
  2350. {
  2351. FOREACH__ (new playerid : Player)
  2352. {
  2353. for (new i = 0; ; ++i)
  2354. {
  2355. z = _Area_GetPlayerAreas(playerid, i);
  2356. if (z == NO_AREA)
  2357. {
  2358. break;
  2359. }
  2360. else if (z == area)
  2361. {
  2362. return false;
  2363. }
  2364. }
  2365. }
  2366. }
  2367. return true;
  2368. }
  2369. /*-------------------------------------------------------------------------*//**
  2370. * <param name="area">Area to set for.</param>
  2371. * <param name="callback">Callback to use.</param>
  2372. * <remarks>
  2373. * Adds a y_inline style callback (publics included) to an area to be called
  2374. * when a player enters it. This is NOT a remote function and instead records
  2375. * the data locally to call functions in the correct script (or they'll just
  2376. * end up crashing as you will be jumping to an arbitrary address in a script
  2377. * that doesn't have sensible code at that address.
  2378. * </remarks>
  2379. *//*------------------------------------------------------------------------**/
  2380. /*-------------------------------------------------------------------------*//**
  2381. * <param name="playerid">The player that just entered the area.</param>
  2382. * <param name="areaid">The area they entered.</param>
  2383. *//*------------------------------------------------------------------------**/
  2384. static stock Area_DoEnter(playerid, areaid, &idx)
  2385. {
  2386. // Save their area to the list of areas that they are currently in.
  2387. //YSI_g_sPlayerArea[playerid] = sCur;
  2388. _Area_SetPlayerAreas(playerid, idx++, areaid);
  2389. // Call the callback in all scripts.
  2390. CallRemoteFunction("OnPlayerEnterArea", "ii", playerid, areaid);
  2391. //broadcastfunc _Area_DoEnter(playerid, areaid);
  2392. }
  2393. /*remotefunc _Area_DoEnter(playerid, areaid)
  2394. {
  2395. if (YSI_g_sHasCallbacks & 1)
  2396. {
  2397. CallLocalFunction("OnPlayerEnterArea", "ii", playerid, areaid);
  2398. }
  2399. if (YSI_g_sHasCallbacks & 4)
  2400. {
  2401. //Hook_OnPlayerEnterArea(playerid, areaid);
  2402. }
  2403. return 1;
  2404. }*/
  2405. forward OnPlayerEnterArea(playerid, areaid);
  2406. /*-------------------------------------------------------------------------*//**
  2407. * <param name="playerid">The player that just left the area.</param>
  2408. * <param name="areaid">The area they left.</param>
  2409. *//*------------------------------------------------------------------------**/
  2410. //remotefunc Area_DoLeave(playerid, areaid)
  2411. static stock Area_DoLeave(playerid, areaid, idx)
  2412. {
  2413. // Remove this area from the list of areas.
  2414. new
  2415. cur;
  2416. // Shift up the zones.
  2417. while ((cur = _Area_GetPlayerAreas(playerid, idx + 1)) != NO_AREA)
  2418. {
  2419. _Area_SetPlayerAreas(playerid, idx++, cur);
  2420. }
  2421. _Area_SetPlayerAreas(playerid, idx, NO_AREA);
  2422. // Call the callback.
  2423. CallRemoteFunction("OnPlayerLeaveArea", "ii", playerid, areaid);
  2424. /*if (YSI_g_sHasCallbacks & 2)
  2425. {
  2426. CallLocalFunction("OnPlayerLeaveArea", "ii", playerid, areaid);
  2427. }
  2428. if (YSI_g_sHasCallbacks & 8)
  2429. {
  2430. //Hook_OnPlayerLeaveArea(playerid, areaid);
  2431. }*/
  2432. return 1;
  2433. }
  2434. forward OnPlayerLeaveArea(playerid, areaid);
  2435. //#undef _GROUP_MAKE_LIMIT
  2436. //#undef _GROUP_MAKE_NAME
  2437. #include "..\..\YSI_Core\y_master"