y_areas.inc 86 KB

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