y_objects.inc 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102
  1. /*----------------------------------------------------------------------------*-
  2. ===============================
  3. Y Sever Includes - Objects Core
  4. ===============================
  5. Description:
  6. Handles object streaming for >150 objects per player. Also provides VW
  7. support and improved object attachment (i.e. it works). New versions
  8. combines mine and Peter's streaming systems to narrow down objects by
  9. approximation by a grid system then check all objects visible in near
  10. by sections.
  11. Legal:
  12. Copyright (C) 2007 Alex "Y_Less" Cole
  13. This program is free software; you can redistribute it and/or
  14. modify it under the terms of the GNU General Public License
  15. as published by the Free Software Foundation; either version 2
  16. of the License, or (at your option) any later version.
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. GNU General Public License for more details.
  21. You should have received a copy of the GNU General Public License
  22. along with this program; if not, write to the Free Software
  23. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  24. MA 02110-1301, USA.
  25. Version:
  26. 0.2.7
  27. Changelog:
  28. 27/12/07:
  29. Fixed a bug in the moved object list system.
  30. 26/11/07:
  31. Finished up master system.
  32. Fixed DestroyDynamicObject not removing client objects.
  33. 16/11/07:
  34. Removed global flag as it wasn't doing anything.
  35. 27/10/07:
  36. Fixed moving objects so they actually move
  37. 26/10/07:
  38. Added object children to attach objects to each other.
  39. 09/10/07:
  40. FINALLY found compile hang bug.
  41. Repaired removed code.
  42. Put object co-ordinate code in Object_ParseSet
  43. 23/09/07:
  44. Updated FindSector, AddToSector and RemoveFromSector to use new system.
  45. 22/09/07:
  46. Started work on new sector system, minor macro changes, lots of maths.
  47. Wrote squareroot macro.
  48. Updated constructor.
  49. 21/09/07:
  50. Overhauled sector code, skips columns and interiors plus more efficient.
  51. 20/09/07:
  52. Made some core functions static so they don't get called by accident.
  53. Changed auto-adjust code so it rounds to nearest whole log number.
  54. Moved zone-find code around to skip whole columns at once.
  55. Added zone sorting so they're done in order of distance.
  56. Added breakout code so once all objects are found processing is exited.
  57. 19/09/07:
  58. Added auto-adjusting zone sizes based on object limits.
  59. Altered zone find code to return only possible visible zones.
  60. Fixed rare hanging bug in close list code.
  61. 18/09/07:
  62. My birthday - yes I'm that sad to code on it and put it in a changelog.
  63. Rewrote sectors code to use known sectors instead of position.
  64. 17/09/07:
  65. Rewrote find code to find closest objects instead of random close ones.
  66. 03/08/07:
  67. Updated timer system.
  68. 07/05/07:
  69. Added groups support via default settings.
  70. Corrected (unused) flag - bit pointless but meh.
  71. 02/05/07:
  72. Added YSI_ prefix to all globals.
  73. Added dynamic object API calls.
  74. 30/04/07:
  75. Fixed bug in DestroyDynamicObject with OOB objects not 1st in list.
  76. Exported sector removal code to Object_RemoveFromSector.
  77. Added SECTOR parameter to E_OBJECT for ease of modification.
  78. 25/04/07:
  79. Added 3d checking.
  80. Added DestroyDynamicObject API function.
  81. Fixed location checking on attached objects.
  82. Fixed loop itteration for cyclic list structure.
  83. 24/04/07:
  84. Fixed range leave checking.
  85. Added moving objects list.
  86. 18/04/07:
  87. Second version - completely rewritten after a chat with Peter.
  88. 16/04/07:
  89. First version - adapted from my earlier e_objects.inc include.
  90. Functions:
  91. Public:
  92. Object_Loop - Main loop for checking.
  93. Object_CoOrdRemote - Does object location manipulation remotely.
  94. Object_Remote - Does normal functions remotely.
  95. Object_UpdateUnused - Adds an object to the remote unused list.
  96. Object_Broadcast - Saves an object remotely.
  97. Object_GetLimit - Gets the number of objects the remove master can hold.
  98. YSIM_Objects - Processes master system instructions.
  99. Object_AddRem - Remote wrapper for Object_Add.
  100. Core:
  101. Object_Object - Constructor.
  102. Object_OnPlayerDisconnect - Disconnects objects.
  103. Stock:
  104. Object_AddToWorld - Make visible in world.
  105. Object_RemoveFromWorld - Make invisible in world.
  106. Object_AddToPlayer - Make visible to player.
  107. Object_RemoveFromPlayer - Make invisible to player.
  108. Object_AddToAllWorlds - Make visible in all worlds.
  109. Object_RemoveFromAllWorlds - Make invisible in all worlds.
  110. Object_AddToAllPlayers - Make visible to all players.
  111. Object_RemoveFromAllPlayers - Make invisible to all players.
  112. Object_IsValidModel - Checks if an object is good to be displayed.
  113. Object_IsGlobal - Checks if an object is visible by default.
  114. Object_SetViewDistance - Sets an object's view distance.
  115. Object_IsDescendant - Checks if an object is related to another object.
  116. Static:
  117. Object_Add - Internal add function.
  118. Object_FindSector - Find a location's sector.
  119. Object_AddToOOB - Add an object to the OOB list.
  120. Object_AddToSector - Add an object to the specified list.
  121. Object_RemoveFromSector - Remove an object from the given sector.
  122. Object_FindSectors - Get near sectors.
  123. Object_ParseSet - Check objects in list.
  124. Object_Update - Updates the position of a moving object.
  125. Object_UpdateChildSectors - Updates the sectors of moved object children.
  126. Object_SetPos - Moves an object to the given position.
  127. Object_UpdateAttach - Updates children after dynamic stop.
  128. Object_Move - Reursive MoveDynamicObject for children.
  129. Object_RemoveFromParent - Removes an object from it's parent.
  130. Object_AddToParent - Adds an object to another object.
  131. Object_AttachToPlayer - Attaches objects to a player recursively.
  132. Object_CheckDescendant - Recursive call for Object_IsDescendant.
  133. Object_Destroy - Delete an object with no checks.
  134. Object_AddToUpdate - Safely adds an object to the moved update list.
  135. Inline:
  136. Object_IsValid - Internal validity check.
  137. Object_GetAttach - Get player an object's attached to.
  138. Object_SetAttach - objSet player an object's attached to.
  139. Object_HasPlayer - Checks if a player can see an object.
  140. API:
  141. MoveDynamicObject - Wrapper for MoveObject.
  142. StopDynamicObject - Wrapper for StopObject.
  143. IsValidDynamicObject - Wrapper for IsValidObject.
  144. CreateDynamicObject - Wrapper for CreateObject.
  145. CreatePlayerDynamicObject - Wrapper for CreatePlayerObject.
  146. CreateVWDynamicObject - Creates an object in only one world.
  147. CreatePlayerVWDynamicObject - Creates an object for one player in one world.
  148. DestroyDynamicObject - Wrapper for DestroyObject.
  149. GetDynamicObjectPos - Wrapper for GetObjectPos.
  150. GetDynamicObjectRot - Wrapper for GetObjectRot.
  151. SetDynamicObjectPos = Wrapper for SetObjectPos.
  152. SetDynamicObjectRot - Wrapper for SetObjectRot.
  153. AttachDynamicObjectToPlayer - Wrapper for AttachObjectToPlayer.
  154. DetachDynamicObjectFromPlayer - Removes an object from a player.
  155. AttachObjectToObject - Attaches an object to another object.
  156. RemoveObjectFromParent - Removes an object from another object.
  157. Callbacks:
  158. OnDynamicObjectMoved
  159. Definitions:
  160. OBJECT_SECTOR_SIZE - Size of edge of a grid square for approximations.
  161. MAX_DYN_OBJECTS - Maximum number of objects.
  162. OBJECT_VIEW_DISTANCE - Range to stream objects for.
  163. NO_OBJECT - No object pointer.
  164. NO_SECTOR - No sector pointer.
  165. OBJECT_NO_SECTOR - OOB object marker.
  166. OBJECT_LOOP_GRANULARITY - Number of itterations per second for the loop.
  167. NO_ATTACH_PLAYER - Marker for object not attached to anyone.
  168. OBJECT_WORLDS - Maximum number of worlds objects show up in.
  169. OBJECT_WORLD_COUNT - Size of bit array of worlds.
  170. OBJECT_PLAYER_COUNT - Size of bit array of players.
  171. Enums:
  172. E_OBJECT - Structure of the dynamic object data.
  173. e_OBJ_FLAG - Flags for the object.
  174. Macros:
  175. OBJECT_SECTOR_EDGE - Number of sectors on one edge of the world.
  176. OBJECT_SECTOR_ARRAY - Number of grid squares.
  177. OBJECT_SIGHT - OBJECT_VIEW_DISTANCE squared for speed.
  178. OBJECT_VIEW_RATIO - Number of sectors per view radius.
  179. OBJECT_VIEW_EDGES - Max width of view range in sectors.
  180. OBJECT_VIEW_SECTORS - Max sectors visible at once.
  181. NO_OBJECT_CHECK - Invalid model.
  182. OBJECT_BITS - Number of bits to hold all dynamic objects.
  183. e_OBJ_FLAG_MOVED - Extension of e_OBJ_FLAG, both move flags together.
  184. NEW_SECTOR - Sector based on origin sector and current offset.
  185. Tags:
  186. e_OBJ_FLAG - Flags for objects.
  187. Variables:
  188. Global:
  189. -
  190. Static:
  191. YSI_g_sObjectSectors - Array of pointers to sector object lists.
  192. YSI_g_sObjects - Array of objects.
  193. YSI_g_sOtherSector - Pointer to OOB object list.
  194. YSI_g_sMovingObjects - Pointer to moving object list.
  195. YSI_g_sNoObjects - Pointer to unused object list.
  196. Commands:
  197. -
  198. Compile options:
  199. NO_PERSONAL_OBJECTS - All players see all objects.
  200. NO_OBJECT_ATTACH - Objects can't be attached to each other.
  201. NO_OBJECTS_MOVE - No processing is done for moving objects.
  202. OBJECT_WORLDS 0 - All objects are visible in all worlds.
  203. Operators:
  204. -
  205. -*----------------------------------------------------------------------------*/
  206. #if !defined OBJECT_BOUNDS_MINX
  207. #if defined OBJECT_BOUNDS
  208. #define OBJECT_BOUNDS_MINX (-OBJECT_BOUNDS)
  209. #else
  210. #define OBJECT_BOUNDS_MINX (-5000)
  211. #endif
  212. #endif
  213. #if !defined OBJECT_BOUNDS_MINY
  214. #if defined OBJECT_BOUNDS
  215. #define OBJECT_BOUNDS_MINY (-OBJECT_BOUNDS)
  216. #else
  217. #define OBJECT_BOUNDS_MINY (-5000)
  218. #endif
  219. #endif
  220. #if !defined OBJECT_BOUNDS_MAXX
  221. #if defined OBJECT_BOUNDS
  222. #define OBJECT_BOUNDS_MAXX (OBJECT_BOUNDS)
  223. #else
  224. #define OBJECT_BOUNDS_MAXX (5000)
  225. #endif
  226. #endif
  227. #if !defined OBJECT_BOUNDS_MAXY
  228. #if defined OBJECT_BOUNDS
  229. #define OBJECT_BOUNDS_MAXY (OBJECT_BOUNDS)
  230. #else
  231. #define OBJECT_BOUNDS_MAXY (5000)
  232. #endif
  233. #endif
  234. #define OBJECT_BOUNDS_X_SIZE (OBJECT_BOUNDS_MAXX - OBJECT_BOUNDS_MINX)
  235. #define OBJECT_BOUNDS_Y_SIZE (OBJECT_BOUNDS_MAXY - OBJECT_BOUNDS_MINY)
  236. #if !defined MAX_DYN_OBJECTS
  237. #define MAX_DYN_OBJECTS (10000)
  238. #endif
  239. #define AVERAGE_OBJECTS_PER_SECTOR (500)
  240. #define OBJECT_DISTRIBUTION (((OBJECT_BOUNDS_X_SIZE * OBJECT_BOUNDS_Y_SIZE) / MAX_DYN_OBJECTS) * AVERAGE_OBJECTS_PER_SECTOR)
  241. #if !defined OBJECT_SECTOR_SIZE
  242. #if OBJECT_DISTRIBUTION <= 10
  243. #define OBJECT_SECTOR_SIZE (1)
  244. #endif
  245. #endif
  246. #if !defined OBJECT_SECTOR_SIZE
  247. #if OBJECT_DISTRIBUTION <= 100
  248. #define OBJECT_SECTOR_SIZE (5)
  249. #endif
  250. #endif
  251. #if !defined OBJECT_SECTOR_SIZE
  252. #if OBJECT_DISTRIBUTION <= 1000
  253. #define OBJECT_SECTOR_SIZE (10)
  254. #endif
  255. #endif
  256. #if !defined OBJECT_SECTOR_SIZE
  257. #if OBJECT_DISTRIBUTION <= 10000
  258. #define OBJECT_SECTOR_SIZE (50)
  259. #endif
  260. #endif
  261. #if !defined OBJECT_SECTOR_SIZE
  262. #if OBJECT_DISTRIBUTION <= 100000
  263. #define OBJECT_SECTOR_SIZE (100)
  264. #endif
  265. #endif
  266. #if !defined OBJECT_SECTOR_SIZE
  267. #if OBJECT_DISTRIBUTION <= 1000000
  268. #define OBJECT_SECTOR_SIZE (500)
  269. #endif
  270. #endif
  271. #if !defined OBJECT_SECTOR_SIZE
  272. #if OBJECT_DISTRIBUTION <= 10000000
  273. #define OBJECT_SECTOR_SIZE (1000)
  274. #endif
  275. #endif
  276. #if !defined OBJECT_SECTOR_SIZE
  277. #if OBJECT_DISTRIBUTION <= 100000000
  278. #define OBJECT_SECTOR_SIZE (5000)
  279. #endif
  280. #endif
  281. #if !defined OBJECT_SECTOR_SIZE
  282. #if OBJECT_DISTRIBUTION <= 1000000000
  283. #define OBJECT_SECTOR_SIZE (10000)
  284. #endif
  285. #endif
  286. #define OBJECT_SECTOR_X_EDGE (ceildiv(OBJECT_BOUNDS_X_SIZE, OBJECT_SECTOR_SIZE))
  287. #define OBJECT_SECTOR_Y_EDGE (ceildiv(OBJECT_BOUNDS_Y_SIZE, OBJECT_SECTOR_SIZE))
  288. #define OBJECT_SECTOR_ARRAY (OBJECT_SECTOR_X_EDGE * OBJECT_SECTOR_Y_EDGE)
  289. #define OBJECT_REAL_X_SECTOR_SIZE (float(OBJECT_BOUNDS_X_SIZE) / float(OBJECT_SECTOR_X_EDGE))
  290. #define OBJECT_REAL_Y_SECTOR_SIZE (float(OBJECT_BOUNDS_Y_SIZE) / float(OBJECT_SECTOR_Y_EDGE))
  291. #if !defined OBJECT_MAX_VIEW_DISTANCE
  292. #define OBJECT_MAX_VIEW_DISTANCE 500
  293. #endif
  294. #if !defined DEFAULT_OBJECT_VIEW
  295. #if defined OBJECT_VIEW_DISTANCE
  296. #define DEFAULT_OBJECT_VIEW (OBJECT_VIEW_DISTANCE)
  297. #else
  298. #define DEFAULT_OBJECT_VIEW (200)
  299. #endif
  300. #endif
  301. #define OBJECT_SIGHT (DEFAULT_OBJECT_VIEW * DEFAULT_OBJECT_VIEW)
  302. #define OBJECT_VIEW_RATIO (ceildiv(OBJECT_MAX_VIEW_DISTANCE, OBJECT_SECTOR_SIZE))
  303. #define OBJECT_VIEW_EDGES ((OBJECT_VIEW_RATIO * 2) + 1)
  304. #define OBJECT_VIEW_SECTORS (OBJECT_VIEW_EDGES * OBJECT_VIEW_EDGES)
  305. #define NO_OBJECT -1
  306. #define NO_OBJECT_CHECK (NO_OBJECT & _:e_OBJ_FLAG_MODEL)
  307. #define NO_SECTOR -1
  308. #define OBJECT_NO_SECTOR 0x7FFFFFFF
  309. #define OBJECT_LOD_SECTOR 0x6FFFFFFF
  310. #define OBJECT_INT_SECTOR 0x5FFFFFFF
  311. #define OBJECT_BITS Bit_Bits(MAX_DYN_OBJECTS)
  312. #if !defined OBJECT_LOOP_GRANULARITY
  313. #define OBJECT_LOOP_GRANULARITY 2
  314. #endif
  315. #define NO_ATTACH_PLAYER 0xFF
  316. #define NO_GATE (-1)
  317. #define SECTOR_CHECK_TIME (1000)
  318. #define SECTOR_CHECK_FREQUENCY ceildiv(SECTOR_CHECK_TIME, (1000 / OBJECT_LOOP_GRANULARITY))
  319. #define MAY_OBJECTS (150)
  320. #if !defined OBJECT_WORLDS
  321. #define OBJECT_WORLDS MAX_WORLDS
  322. #endif
  323. #if OBJECT_WORLDS > 32
  324. #define OBJECT_WORLD_COUNT Bit_Bits(OBJECT_WORLDS)
  325. #else
  326. #define OBJECT_WORLD_COUNT 2
  327. #endif
  328. #define GATE_AREA_TRIGGER (0x80000000)
  329. #define GATE_OPENING (0x40000000)
  330. #define ONE_OVER_ROOT_TWO (0.70710678118654752440084436210485)
  331. enum e_OBJ_FLAG (<<= 1)
  332. {
  333. e_OBJ_FLAG_MODEL = 0x00007FFF,
  334. e_OBJ_FLAG_ATTACH = 0x007F8000,
  335. e_OBJ_FLAG_ATTACHED = 0x00800000,
  336. e_OBJ_FLAG_JUMPED,
  337. e_OBJ_FLAG_MOVED1,
  338. e_OBJ_FLAG_MOVED2,
  339. e_OBJ_FLAG_ROTATED,
  340. e_OBJ_FLAG_ACTIVE,
  341. e_OBJ_FLAG_RECREATED,
  342. e_OBJ_FLAG_GATE
  343. }
  344. #define e_OBJ_FLAG_MOVED (e_OBJ_FLAG_MOVED1 | e_OBJ_FLAG_MOVED2)
  345. enum E_OBJECT
  346. {
  347. e_OBJ_FLAG:E_OBJECT_MODEL,
  348. #if defined _YSI_SETUP_MASTER
  349. E_OBJECT_SCRIPT,
  350. #endif
  351. Float:E_OBJECT_X,
  352. Float:E_OBJECT_Y,
  353. Float:E_OBJECT_Z,
  354. Float:E_OBJECT_RX,
  355. Float:E_OBJECT_RY,
  356. Float:E_OBJECT_RZ,
  357. Float:E_OBJECT_VIEW,
  358. #if OBJECT_WORLDS > 0
  359. Bit:E_OBJECT_WORLDS[OBJECT_WORLD_COUNT],
  360. #endif
  361. #if !defined NO_PERSONAL_OBJECTS
  362. Bit:E_OBJECT_PLAYERS[PLAYER_BIT_ARRAY],
  363. #endif
  364. #if !defined NO_OBJECTS_MOVE
  365. Float:E_OBJECT_MX,
  366. Float:E_OBJECT_MY,
  367. Float:E_OBJECT_MZ,
  368. Float:E_OBJECT_MS,
  369. #endif
  370. E_OBJECT_UPDATES,
  371. #if !defined NO_OBJECT_ATTACH
  372. E_OBJECT_PARENT,
  373. E_OBJECT_SIBLINGS,
  374. E_OBJECT_CHILDREN,
  375. #endif
  376. E_OBJECT_NEXT,
  377. E_OBJECT_SECTOR
  378. }
  379. enum E_OBJECT_ITTER
  380. {
  381. Float:E_OBJECT_ITTER_DISTANCE,
  382. E_OBJECT_ITTER_NEXT,
  383. E_OBJECT_ITTER_LAST,
  384. E_OBJECT_ITTER_OBJ,
  385. Float:E_OBJECT_ITTER_X,
  386. Float:E_OBJECT_ITTER_Y,
  387. Float:E_OBJECT_ITTER_Z
  388. }
  389. enum E_OBJ_SECTOR
  390. {
  391. E_OBJ_SECTOR_POINTER,
  392. Float:E_OBJ_SECTOR_MAX_VIEW
  393. }
  394. enum E_OSEC_ITTER
  395. {
  396. E_OSEC_ITTER_SECTOR,
  397. E_OSEC_ITTER_NEXT,
  398. Float:E_OSEC_ITTER_DIFF
  399. }
  400. enum
  401. {
  402. E_OBJECT_REMOTE_ISG,
  403. E_OBJECT_REMOTE_VIEW,
  404. E_OBJECT_REMOTE_DESTROY,
  405. E_OBJECT_REMOTE_SETPOS,
  406. E_OBJECT_REMOTE_SETROT,
  407. E_OBJECT_REMOTE_ADDW,
  408. E_OBJECT_REMOTE_REMW,
  409. E_OBJECT_REMOTE_ADDP,
  410. E_OBJECT_REMOTE_REMP,
  411. E_OBJECT_REMOTE_ALLWA,
  412. E_OBJECT_REMOTE_ALLWR,
  413. E_OBJECT_REMOTE_ALLPA,
  414. E_OBJECT_REMOTE_ALLPR,
  415. E_OBJECT_REMOTE_ISVALID,
  416. E_OBJECT_REMOTE_DETATCH,
  417. E_OBJECT_REMOTE_ATTACHOO,
  418. E_OBJECT_REMOTE_REMOO,
  419. E_OBJECT_REMOTE_STOP,
  420. E_OBJECT_REMOTE_GETROT,
  421. E_OBJECT_REMOTE_GETPOS,
  422. E_OBJECT_REMOTE_MOVETO,
  423. E_OBJECT_REMOTE_CHECKDESC,
  424. E_OBJECT_REMOTE_GET_AREA,
  425. E_OBJECT_REMOTE_GATE_POS,
  426. E_OBJECT_REMOTE_GATE
  427. }
  428. enum E_GATE_INFO
  429. {
  430. E_GATE_INFO_OBJECT,
  431. E_GATE_INFO_TIME,
  432. E_GATE_INFO_TRIGGER,
  433. E_GATE_INFO_XY,
  434. E_GATE_INFO_ZA
  435. }
  436. #if !defined MAX_GATE_OBJECTS
  437. #define MAX_GATE_OBJECTS 32
  438. #endif
  439. #if MAX_GATE_OBJECTS > 256
  440. #if !defined EXTENDED_GATE_CODE
  441. #define EXTENDED_GATE_CODE
  442. #endif
  443. #endif
  444. #if MAX_GATE_OBJECTS > 65536
  445. #if !defined NO_GATE_AREA_LOOKUP
  446. #error Only 65536 gates supported in lookup mode
  447. #endif
  448. #endif
  449. forward Object_Loop();
  450. #if defined _YSI_SETUP_MASTER
  451. forward Object_GetLimit();
  452. forward Object_AddRem(master, model, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  453. forward Object_Remote(ident, info, instruction);
  454. forward Object_CoOrdRemote(ident, instruction, Float:f1, Float:f2, Float:f3, Float:f4);
  455. forward Object_OnPlayerEnterArea(playerid, areaid);
  456. forward Object_Broadcast(id, e_OBJ_FLAG:model, master, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:view,
  457. Float:mx, Float:my, Float:mz, Float:ms, parent, siblings, children, Bit:worlds[], wCount, Bit:players[], pCount);
  458. forward YSIM_Objects(command);
  459. forward Object_UpdateUnused(obj);
  460. #if !defined NO_OBJECTS_MOVE
  461. forward Object_AttachRemote(objectid, playerid, Float:X, Float:Y, Float:Z, Float:RX, Float:RY, Float:RZ);
  462. #endif
  463. #endif
  464. #if defined _YSI_VISUAL_AREAS
  465. forward Object_GateClose(gate);
  466. #endif
  467. static
  468. Float:YSI_g_sXSectorLocations[OBJECT_SECTOR_X_EDGE + 1],
  469. Float:YSI_g_sYSectorLocations[OBJECT_SECTOR_Y_EDGE + 1],
  470. Float:YSI_g_sXSectorSize,
  471. Float:YSI_g_sYSectorSize,
  472. YSI_g_sObjectSectors[OBJECT_SECTOR_ARRAY][E_OBJ_SECTOR],
  473. YSI_g_sObjects[MAX_DYN_OBJECTS][E_OBJECT],
  474. YSI_g_sOtherSector = NO_OBJECT,
  475. YSI_g_sMovingObjects = NO_OBJECT,
  476. YSI_g_sLODObjects = NO_OBJECT,
  477. YSI_g_sInteriorObjects = NO_OBJECT,
  478. YSI_g_sPlayerObjects[MAX_PLAYERS][MAY_OBJECTS],
  479. YSI_g_sSomethingMoved = NO_OBJECT,
  480. #if defined _YSI_SETUP_MASTER
  481. YSI_g_sIsMaster,
  482. #endif
  483. #if defined _YSI_VISUAL_AREAS
  484. YSI_g_sGateInfo[MAX_GATE_OBJECTS][E_GATE_INFO],
  485. #if !defined NO_GATE_AREA_LOOKUP
  486. YSI_g_sGateAreas[ceildiv(MAX_AREAS, 2)],
  487. #endif
  488. #endif
  489. YSI_g_sNoObjects;
  490. /*----------------------------------------------------------------------------*-
  491. Function:
  492. Object_IsValid
  493. Params:
  494. objectid - Object to check
  495. Return:
  496. -
  497. Notes:
  498. Checks if a passed id is a valid object.
  499. -*----------------------------------------------------------------------------*/
  500. #define Object_IsValid(%1) \
  501. ((%1) >= 0 && (%1) < MAX_DYN_OBJECTS && YSI_g_sObjects[(%1)][E_OBJECT_MODEL] & e_OBJ_FLAG_ACTIVE)
  502. /*----------------------------------------------------------------------------*-
  503. Function:
  504. Object_GetAttach
  505. Params:
  506. flags - Flags to check.
  507. Return:
  508. Player the object is attached to.
  509. Notes:
  510. Actually checks a objSet of passed flags, not a passed object.
  511. -*----------------------------------------------------------------------------*/
  512. #define Object_GetAttach(%1) \
  513. ((_:(%1) >> 15) & NO_ATTACH_PLAYER)
  514. /*----------------------------------------------------------------------------*-
  515. Function:
  516. Object_IsAttached
  517. Params:
  518. flags - Flags to check.
  519. Return:
  520. If the object is attached to a player.
  521. Notes:
  522. Actually checks a objSet of passed flags, not a passed object.
  523. -*----------------------------------------------------------------------------*/
  524. #define Object_IsAttached(%1) \
  525. (Object_GetAttach(%1) != NO_ATTACH_PLAYER)
  526. /*----------------------------------------------------------------------------*-
  527. Function:
  528. Object_SetGateTarget
  529. Params:
  530. gate - Gate to objSet target for.
  531. Float:tx - X point to open to.
  532. Float:ty - Y point to open to.
  533. Float:tz - Z point to open to.
  534. Float:ts - Speed to open at.
  535. Return:
  536. -
  537. Notes:
  538. Stores a location into the two variables provided for targets. Uses
  539. complex bit shifting to fit the floats nicely into 2 cells. Assumes a max
  540. of +/-13107.2 for x, y and z and a max of 102.4 for the speed to compress.
  541. -*----------------------------------------------------------------------------*/
  542. #define Object_SetGateTarget(%1,%2,%3,%4,%5) \
  543. new \
  544. _o_sgt_y = floatround((%3) * 10); \
  545. YSI_g_sGateInfo[(%1)][E_GATE_INFO_XY] = ((floatround((%2) * 10) & 0x3FFFF) << 14) | (_o_sgt_y & 0x3FFF); \
  546. YSI_g_sGateInfo[(%1)][E_GATE_INFO_ZA] = ((_o_sgt_y & 0x3C000) << 14) | ((floatround((%4) * 10) & 0x3FFFF) << 10) | (floatround((%5) * 10) & 0x3FF)
  547. /*----------------------------------------------------------------------------*-
  548. Function:
  549. Object_SetAttach
  550. Params:
  551. flags - Flags to check.
  552. Return:
  553. -
  554. Notes:
  555. Actually checks a objSet of passed flags, not a passed object.
  556. -*----------------------------------------------------------------------------*/
  557. #define Object_SetAttach(%1) \
  558. e_OBJ_FLAG:(((%1) & NO_ATTACH_PLAYER) << 15)
  559. #if defined _YSI_SETUP_MASTER
  560. /*----------------------------------------------------------------------------*-
  561. Function:
  562. Object_Remote
  563. Params:
  564. ident - Object to do code on.
  565. info - Extra data for function.
  566. instruction - Function to perform.
  567. Return:
  568. -
  569. Notes:
  570. Performs operations on objects remotely.
  571. -*----------------------------------------------------------------------------*/
  572. public Object_Remote(ident, info, instruction)
  573. {
  574. setproperty(0, "YSIReq", 0);
  575. if (!YSI_g_sIsMaster) return 0;
  576. switch (instruction & 0x0FFF)
  577. {
  578. case E_OBJECT_REMOTE_VIEW:
  579. {
  580. Object_SetViewDistance(ident, Float:info);
  581. }
  582. case E_OBJECT_REMOTE_DESTROY:
  583. {
  584. if (Object_IsValid(ident)) Object_Destroy(ident);
  585. }
  586. case E_OBJECT_REMOTE_ADDW:
  587. {
  588. if (Object_IsValid(ident)) Bit_Set(YSI_g_sObjects[ident][E_OBJECT_WORLDS], info, 1, OBJECT_WORLD_COUNT);
  589. }
  590. case E_OBJECT_REMOTE_REMW:
  591. {
  592. if (Object_IsValid(ident)) Bit_Set(YSI_g_sObjects[ident][E_OBJECT_WORLDS], info, 0, OBJECT_WORLD_COUNT);
  593. }
  594. case E_OBJECT_REMOTE_ADDP:
  595. {
  596. if (Object_IsValid(ident)) Bit_Set(YSI_g_sObjects[ident][E_OBJECT_PLAYERS], info, 1, PLAYER_BIT_ARRAY);
  597. }
  598. case E_OBJECT_REMOTE_REMP:
  599. {
  600. if (Object_IsValid(ident)) Bit_Set(YSI_g_sObjects[ident][E_OBJECT_PLAYERS], info, 0, PLAYER_BIT_ARRAY);
  601. }
  602. case E_OBJECT_REMOTE_ALLWA:
  603. {
  604. if (Object_IsValid(ident)) Bit_SetAll(YSI_g_sObjects[ident][E_OBJECT_WORLDS], 1, OBJECT_WORLD_COUNT);
  605. }
  606. case E_OBJECT_REMOTE_ALLWR:
  607. {
  608. if (Object_IsValid(ident)) Bit_SetAll(YSI_g_sObjects[ident][E_OBJECT_WORLDS], 0, OBJECT_WORLD_COUNT);
  609. }
  610. case E_OBJECT_REMOTE_ALLPA:
  611. {
  612. if (Object_IsValid(ident))
  613. {
  614. Bit_SetAll(YSI_g_sObjects[ident][E_OBJECT_PLAYERS], 1, PLAYER_BIT_ARRAY);
  615. }
  616. }
  617. case E_OBJECT_REMOTE_ALLPR:
  618. {
  619. if (Object_IsValid(ident))
  620. {
  621. Bit_SetAll(YSI_g_sObjects[ident][E_OBJECT_PLAYERS], 0, PLAYER_BIT_ARRAY);
  622. }
  623. }
  624. case E_OBJECT_REMOTE_ISVALID:
  625. {
  626. if (Object_IsValid(ident)) setproperty(0, "YSIReq", 1);
  627. }
  628. case E_OBJECT_REMOTE_DETATCH:
  629. {
  630. DetachDynamicObjectFromPlayer(ident);
  631. }
  632. case E_OBJECT_REMOTE_ATTACHOO:
  633. {
  634. AttachObjectToObject(ident, info);
  635. }
  636. case E_OBJECT_REMOTE_REMOO:
  637. {
  638. RemoveObjectFromParent(ident);
  639. }
  640. case E_OBJECT_REMOTE_STOP:
  641. {
  642. StopDynamicObject(ident);
  643. }
  644. case E_OBJECT_REMOTE_GETROT:
  645. {
  646. if (!Object_IsValid(ident) || Object_IsAttached(YSI_g_sObjects[ident][E_OBJECT_MODEL]))
  647. {
  648. setproperty(0, "YSIReq", 0);
  649. setproperty(0, "YSIReq2", 0);
  650. setproperty(0, "YSIReq3", 0);
  651. }
  652. else
  653. {
  654. setproperty(0, "YSIReq", _:YSI_g_sObjects[ident][E_OBJECT_RX]);
  655. setproperty(0, "YSIReq2", _:YSI_g_sObjects[ident][E_OBJECT_RY]);
  656. setproperty(0, "YSIReq3", _:YSI_g_sObjects[ident][E_OBJECT_RZ]);
  657. }
  658. }
  659. case E_OBJECT_REMOTE_GETPOS:
  660. {
  661. if (!Object_IsValid(ident))
  662. {
  663. setproperty(0, "YSIReq", 0);
  664. setproperty(0, "YSIReq2", 0);
  665. setproperty(0, "YSIReq3", 0);
  666. }
  667. else
  668. {
  669. new
  670. Float:x,
  671. Float:y,
  672. Float:z;
  673. Object_GetPos(ident, x, y, z);
  674. setproperty(0, "YSIReq", _:x);
  675. setproperty(0, "YSIReq2", _:y);
  676. setproperty(0, "YSIReq3", _:z);
  677. }
  678. }
  679. case E_OBJECT_REMOTE_CHECKDESC:
  680. {
  681. if (Object_CheckDescendant(ident, info)) setproperty(0, "YSIReq", 1);
  682. }
  683. case E_OBJECT_REMOTE_GET_AREA:
  684. {
  685. if (ident >= 0 && ident < MAX_GATE_OBJECTS)
  686. {
  687. setproperty(0, "YSIReq", YSI_g_sGateInfo[ident][E_GATE_INFO_TRIGGER]);
  688. }
  689. }
  690. case E_OBJECT_REMOTE_GATE:
  691. {
  692. setproperty(0, "YSIReq", NO_GATE);
  693. #if !defined NO_OBJECTS_MOVE
  694. #if defined _YSI_VISUAL_AREAS
  695. if (Object_IsValid(ident) && !Object_IsAttached(YSI_g_sObjects[ident][E_OBJECT_MODEL]) && Area_IsValid(info))
  696. {
  697. new
  698. gate;
  699. while (gate < MAX_GATE_OBJECTS)
  700. {
  701. if (!YSI_g_sGateInfo[gate][E_GATE_INFO_OBJECT]) break;
  702. gate++;
  703. }
  704. if (gate == MAX_GATE_OBJECTS) return NO_GATE;
  705. DBGP4("Object_Remote() Gates: %d %d %d %d", gate, ident, instruction >>> 12, info);
  706. YSI_g_sGateInfo[gate][E_GATE_INFO_OBJECT] = ident | GATE_AREA_TRIGGER;
  707. YSI_g_sGateInfo[gate][E_GATE_INFO_TIME] = instruction >>> 12;
  708. YSI_g_sGateInfo[gate][E_GATE_INFO_TRIGGER] = info;
  709. YSI_g_sObjects[ident][E_OBJECT_MODEL] |= e_OBJ_FLAG_GATE;
  710. DBGP4("Object_Remote() Gate ID: %d", gate);
  711. #if !defined NO_GATE_AREA_LOOKUP
  712. new
  713. slot = info / 2,
  714. shift = (info % 2) * 16;
  715. YSI_g_sGateAreas[slot] = (YSI_g_sGateAreas[slot] & (0xFFFF0000 >>> shift)) | (gate << shift);
  716. DBGP4("Object_Remote() Lookup: %d %d %d", slot, shift, YSI_g_sGateAreas[slot]);
  717. #endif
  718. setproperty(0, "YSIReq", gate);
  719. DBGP4("Object_Remote() Return");
  720. return 1;
  721. }
  722. #endif
  723. #endif
  724. }
  725. }
  726. return 1;
  727. }
  728. /*----------------------------------------------------------------------------*-
  729. Function:
  730. YSIM_Objects
  731. Params:
  732. command - Instruction from the master system.
  733. Return:
  734. -
  735. Notes:
  736. Performs instructions on script start/end.
  737. -*----------------------------------------------------------------------------*/
  738. public YSIM_Objects(command)
  739. {
  740. #if OBJECT_WORLDS <= 0 || defined NO_PERSONAL_OBJECTS
  741. static
  742. sFake[2] = {-1, -1};
  743. #endif
  744. switch (command & 0xFF000000)
  745. {
  746. case E_MASTER_SET_MASTER:
  747. {
  748. YSI_g_sIsMaster = 1;
  749. }
  750. case E_MASTER_RELINQUISH:
  751. {
  752. new
  753. master = (command & 0x00FFFFFF);
  754. if (master == YSI_gMasterID)
  755. {
  756. CallRemoteFunction("Object_GetLimit", "");
  757. new
  758. parent = NO_OBJECT,
  759. siblings = NO_OBJECT,
  760. children = NO_OBJECT,
  761. Float:mx,
  762. Float:my,
  763. Float:mz,
  764. Float:ms,
  765. maxObjs = getproperty(0, "YSIReq"),
  766. i;
  767. for ( ; i < MAX_DYN_OBJECTS && i < maxObjs; i++)
  768. {
  769. if (YSI_g_sObjects[i][E_OBJECT_MODEL] & e_OBJ_FLAG_ACTIVE)
  770. {
  771. if (YSI_g_sObjects[i][E_OBJECT_SCRIPT] == master)
  772. {
  773. Object_Destroy(i, 0);
  774. }
  775. else
  776. {
  777. #if !defined NO_OBJECT_ATTACH
  778. parent = YSI_g_sObjects[i][E_OBJECT_PARENT];
  779. while (parent != NO_OBJECT && (YSI_g_sObjects[parent][E_OBJECT_SCRIPT] == master || parent > maxObjs))
  780. {
  781. Object_Destroy(parent, 0);
  782. parent = YSI_g_sObjects[i][E_OBJECT_PARENT];
  783. }
  784. siblings = YSI_g_sObjects[i][E_OBJECT_SIBLINGS];
  785. while (siblings != NO_OBJECT && (YSI_g_sObjects[siblings][E_OBJECT_SCRIPT] == master || siblings > maxObjs))
  786. {
  787. Object_Destroy(siblings, 0);
  788. siblings = YSI_g_sObjects[i][E_OBJECT_SIBLINGS];
  789. }
  790. children = YSI_g_sObjects[i][E_OBJECT_CHILDREN];
  791. while (children != NO_OBJECT && (YSI_g_sObjects[children][E_OBJECT_SCRIPT] == master || children > maxObjs))
  792. {
  793. Object_Destroy(children, 0);
  794. children = YSI_g_sObjects[i][E_OBJECT_CHILDREN];
  795. }
  796. #endif
  797. #if !defined NO_OBJECTS_MOVE
  798. mx = YSI_g_sObjects[i][E_OBJECT_MX];
  799. my = YSI_g_sObjects[i][E_OBJECT_MY];
  800. mz = YSI_g_sObjects[i][E_OBJECT_MZ];
  801. ms = YSI_g_sObjects[i][E_OBJECT_MS];
  802. #endif
  803. #if OBJECT_WORLDS > 0
  804. #if !defined NO_PERSONAL_OBJECTS
  805. CallRemoteFunction("Object_Broadcast", "iiifffffffffffiiiaiai", i,
  806. _:YSI_g_sObjects[i][E_OBJECT_MODEL],
  807. YSI_g_sObjects[i][E_OBJECT_SCRIPT],
  808. YSI_g_sObjects[i][E_OBJECT_X],
  809. YSI_g_sObjects[i][E_OBJECT_Y],
  810. YSI_g_sObjects[i][E_OBJECT_Z],
  811. YSI_g_sObjects[i][E_OBJECT_RX],
  812. YSI_g_sObjects[i][E_OBJECT_RY],
  813. YSI_g_sObjects[i][E_OBJECT_RZ],
  814. YSI_g_sObjects[i][E_OBJECT_VIEW],
  815. mx, my, mz, ms,
  816. parent, siblings, children,
  817. _:YSI_g_sObjects[i][E_OBJECT_WORLDS], OBJECT_WORLD_COUNT,
  818. _:YSI_g_sObjects[i][E_OBJECT_PLAYERS], PLAYER_BIT_ARRAY
  819. );
  820. #else
  821. CallRemoteFunction("Object_Broadcast", "iiifffffffffffiiiaiai", i,
  822. _:YSI_g_sObjects[i][E_OBJECT_MODEL],
  823. YSI_g_sObjects[i][E_OBJECT_SCRIPT],
  824. YSI_g_sObjects[i][E_OBJECT_X],
  825. YSI_g_sObjects[i][E_OBJECT_Y],
  826. YSI_g_sObjects[i][E_OBJECT_Z],
  827. YSI_g_sObjects[i][E_OBJECT_RX],
  828. YSI_g_sObjects[i][E_OBJECT_RY],
  829. YSI_g_sObjects[i][E_OBJECT_RZ],
  830. YSI_g_sObjects[i][E_OBJECT_VIEW],
  831. mx, my, mz, ms,
  832. parent, siblings, children,
  833. _:YSI_g_sObjects[i][E_OBJECT_WORLDS], OBJECT_WORLD_COUNT,
  834. sFake, 2
  835. );
  836. #endif
  837. #else
  838. #if !defined NO_PERSONAL_OBJECTS
  839. CallRemoteFunction("Object_Broadcast", "iiifffffffffffiiiaiai", i,
  840. _:YSI_g_sObjects[i][E_OBJECT_MODEL],
  841. YSI_g_sObjects[i][E_OBJECT_SCRIPT],
  842. YSI_g_sObjects[i][E_OBJECT_X],
  843. YSI_g_sObjects[i][E_OBJECT_Y],
  844. YSI_g_sObjects[i][E_OBJECT_Z],
  845. YSI_g_sObjects[i][E_OBJECT_RX],
  846. YSI_g_sObjects[i][E_OBJECT_RY],
  847. YSI_g_sObjects[i][E_OBJECT_RZ],
  848. YSI_g_sObjects[i][E_OBJECT_VIEW],
  849. mx, my, mz, ms,
  850. parent, siblings, children,
  851. sFake, 2,
  852. _:YSI_g_sObjects[i][E_OBJECT_PLAYERS], PLAYER_BIT_ARRAY
  853. );
  854. #else
  855. CallRemoteFunction("Object_Broadcast", "iiifffffffffffiiiaiai", i,
  856. _:YSI_g_sObjects[i][E_OBJECT_MODEL],
  857. YSI_g_sObjects[i][E_OBJECT_SCRIPT],
  858. YSI_g_sObjects[i][E_OBJECT_X],
  859. YSI_g_sObjects[i][E_OBJECT_Y],
  860. YSI_g_sObjects[i][E_OBJECT_Z],
  861. YSI_g_sObjects[i][E_OBJECT_RX],
  862. YSI_g_sObjects[i][E_OBJECT_RY],
  863. YSI_g_sObjects[i][E_OBJECT_RZ],
  864. YSI_g_sObjects[i][E_OBJECT_VIEW],
  865. mx, my, mz, ms,
  866. parent, siblings, children,
  867. sFake, 2,
  868. sFake, 2
  869. );
  870. #endif
  871. #endif
  872. continue;
  873. }
  874. }
  875. CallRemoteFunction("Object_UpdateUnused", "i", i);
  876. }
  877. while (i < maxObjs)
  878. {
  879. CallRemoteFunction("Object_UpdateUnused", "i", i);
  880. i++;
  881. }
  882. foreach (Player, playerid)
  883. {
  884. for (new obj = 1; obj <= MAY_OBJECTS; obj++)
  885. {
  886. if (IsValidPlayerObject(playerid, obj))
  887. {
  888. DestroyPlayerObject(playerid, obj);
  889. break;
  890. }
  891. }
  892. }
  893. }
  894. else
  895. {
  896. for (new i = 0; i < MAX_DYN_OBJECTS; i++)
  897. {
  898. if (YSI_g_sObjects[i][E_OBJECT_MODEL] & e_OBJ_FLAG_ACTIVE && YSI_g_sObjects[i][E_OBJECT_SCRIPT] == master)
  899. {
  900. Object_Destroy(i);
  901. }
  902. }
  903. }
  904. }
  905. case E_MASTER_NOT_MASTER:
  906. {
  907. YSI_g_sIsMaster = 0;
  908. }
  909. }
  910. }
  911. /*----------------------------------------------------------------------------*-
  912. Function:
  913. Object_GetLimit
  914. Params:
  915. -
  916. Return:
  917. -
  918. Notes:
  919. Sets up the new master for streaming and gets the number of objects it
  920. can handle.
  921. -*----------------------------------------------------------------------------*/
  922. public Object_GetLimit()
  923. {
  924. if (!YSI_g_sIsMaster) return;
  925. setproperty(0, "YSIReq", MAX_DYN_OBJECTS);
  926. YSI_g_sNoObjects = NO_OBJECT;
  927. }
  928. /*----------------------------------------------------------------------------*-
  929. Function:
  930. Object_Broadcast
  931. Params:
  932. id - Slot of the object.
  933. e_OBJ_FLAG:model - Object model data and flags.
  934. master - Script which owns the object.
  935. Float:x - X position.
  936. Float:y - Y position.
  937. Float:z - Z position.
  938. Float:rx - X rotation.
  939. Float:ry - Y rotation.
  940. Float:rz - Z rotation.
  941. Float:view - Object view distance.
  942. Float:mx - Movement x target.
  943. Float:my - Movement y target.
  944. Float:mz - Movement z target.
  945. Float:ms - Movement speed.
  946. parent - Object attachment parent.
  947. siblings - Object attachment sibling list.
  948. children - Object attachment children list.
  949. Bit:worlds[] - Worlds the object is in.
  950. wCount - Size of the world array.
  951. Bit:players[] - Players who can see the object.
  952. pCount - Size of the players array.
  953. Return:
  954. -
  955. Notes:
  956. Recieves data sent from the old master to the new master and stores it in
  957. the object data array.
  958. -*----------------------------------------------------------------------------*/
  959. public Object_Broadcast(id, e_OBJ_FLAG:model, master, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:view,
  960. Float:mx, Float:my, Float:mz, Float:ms, parent, siblings, children, Bit:worlds[], wCount, Bit:players[], pCount)
  961. {
  962. if (!YSI_g_sIsMaster) return 0;
  963. #if !defined NO_OBJECT_ATTACH
  964. YSI_g_sObjects[id][E_OBJECT_PARENT] = parent;
  965. YSI_g_sObjects[id][E_OBJECT_SIBLINGS] = siblings;
  966. YSI_g_sObjects[id][E_OBJECT_CHILDREN] = children;
  967. #else
  968. #pragma unused parent, siblings, children
  969. #endif
  970. #if !defined NO_OBJECTS_MOVE
  971. YSI_g_sObjects[id][E_OBJECT_MX] = mx;
  972. YSI_g_sObjects[id][E_OBJECT_MY] = my;
  973. YSI_g_sObjects[id][E_OBJECT_MZ] = mz;
  974. YSI_g_sObjects[id][E_OBJECT_MS] = ms;
  975. #else
  976. #pragma unused mx, my, mz, ms
  977. #endif
  978. YSI_g_sObjects[id][E_OBJECT_MODEL] = model | e_OBJ_FLAG_RECREATED;
  979. YSI_g_sObjects[id][E_OBJECT_SCRIPT] = master;
  980. YSI_g_sObjects[id][E_OBJECT_X] = x;
  981. YSI_g_sObjects[id][E_OBJECT_Y] = y;
  982. YSI_g_sObjects[id][E_OBJECT_Z] = z;
  983. YSI_g_sObjects[id][E_OBJECT_RX] = rx;
  984. YSI_g_sObjects[id][E_OBJECT_RY] = ry;
  985. YSI_g_sObjects[id][E_OBJECT_RZ] = rz;
  986. YSI_g_sObjects[id][E_OBJECT_VIEW] = view;
  987. #if OBJECT_WORLDS > 0
  988. for (new i = 0; i < wCount && i < Bit_Bits(OBJECT_WORLDS); i++)
  989. {
  990. YSI_g_sObjects[id][E_OBJECT_WORLDS][i] = worlds[i];
  991. }
  992. #else
  993. #pragma unused worlds, wCount
  994. #endif
  995. #if !defined NO_PERSONAL_OBJECTS
  996. for (new i = 0; i < pCount && i < PLAYER_BIT_ARRAY; i++)
  997. {
  998. YSI_g_sObjects[id][E_OBJECT_PLAYERS][i] = players[i];
  999. }
  1000. #else
  1001. #pragma unused players, pCount
  1002. #endif
  1003. Object_AddToUpdate(id);
  1004. Object_AddToSector(Object_FindSector(x, y, z), id, view);
  1005. return 1;
  1006. }
  1007. /*----------------------------------------------------------------------------*-
  1008. Function:
  1009. Object_UpdateUnused
  1010. Params:
  1011. obj - Object to add to the remote unused list.
  1012. Return:
  1013. -
  1014. Notes:
  1015. -
  1016. -*----------------------------------------------------------------------------*/
  1017. public Object_UpdateUnused(obj)
  1018. {
  1019. YSI_g_sObjects[obj][E_OBJECT_NEXT] = YSI_g_sNoObjects;
  1020. YSI_g_sNoObjects = obj;
  1021. }
  1022. /*----------------------------------------------------------------------------*-
  1023. Function:
  1024. Object_CoOrdRemote
  1025. Params:
  1026. ident - Object to do code on.
  1027. instruction - Function to perform.
  1028. Float:f1 - First float data.
  1029. Float:f2 - Second float data.
  1030. Float:f3 - Third float data.
  1031. Float:f4 - Fourth float data.
  1032. Return:
  1033. -
  1034. Notes:
  1035. Performs operations with locations on objects remotely.
  1036. -*----------------------------------------------------------------------------*/
  1037. public Object_CoOrdRemote(ident, instruction, Float:f1, Float:f2, Float:f3, Float:f4)
  1038. {
  1039. setproperty(0, "YSIReq", 0);
  1040. if (!YSI_g_sIsMaster) return 0;
  1041. switch (instruction)
  1042. {
  1043. case E_OBJECT_REMOTE_SETROT:
  1044. {
  1045. if (!Object_IsValid(ident) || Object_IsAttached(YSI_g_sObjects[ident][E_OBJECT_MODEL])) return 0;
  1046. YSI_g_sObjects[ident][E_OBJECT_RX] = f1;
  1047. YSI_g_sObjects[ident][E_OBJECT_RY] = f2;
  1048. YSI_g_sObjects[ident][E_OBJECT_RZ] = f3;
  1049. YSI_g_sObjects[ident][E_OBJECT_MODEL] |= e_OBJ_FLAG_ROTATED;
  1050. Object_AddToUpdate(ident);
  1051. setproperty(0, "YSIReq", 1);
  1052. return 1;
  1053. }
  1054. case E_OBJECT_REMOTE_SETPOS:
  1055. {
  1056. if (!Object_IsValid(ident) || Object_IsAttached(YSI_g_sObjects[ident][E_OBJECT_MODEL])) return 0;
  1057. #if !defined NO_OBJECT_ATTACH
  1058. Object_UpdateChildSectors(YSI_g_sObjects[ident][E_OBJECT_CHILDREN], f1, f2, f3);
  1059. #endif
  1060. setproperty(0, "YSIReq", Object_SetPos(ident, f1, f2, f3));
  1061. }
  1062. case E_OBJECT_REMOTE_MOVETO:
  1063. {
  1064. if (Object_IsValid(ident))
  1065. {
  1066. Object_Move(ident, f1, f2, f3, f4);
  1067. Object_AddToUpdate(ident);
  1068. setproperty(0, "YSIReq", 1);
  1069. return 1;
  1070. }
  1071. }
  1072. case E_OBJECT_REMOTE_GATE_POS:
  1073. {
  1074. Object_SetGateTarget(ident, f1, f2, f3, f4);
  1075. }
  1076. }
  1077. return 0;
  1078. }
  1079. #endif
  1080. /*----------------------------------------------------------------------------*-
  1081. Function:
  1082. Object_SetViewDistance
  1083. Params:
  1084. objectid - Object to objSet custom view distance for.
  1085. Float:view - Distance the object can be seen from.
  1086. Return:
  1087. -
  1088. Notes:
  1089. Sets how far away an object can be seen from.
  1090. -*----------------------------------------------------------------------------*/
  1091. stock Object_SetViewDistance(objectid, Float:view)
  1092. {
  1093. #if defined _YSI_SETUP_MASTER
  1094. if (YSI_g_sIsMaster)
  1095. {
  1096. #endif
  1097. if (Object_IsValid(objectid))
  1098. {
  1099. view *= view;
  1100. YSI_g_sObjects[objectid][E_OBJECT_VIEW] = view;
  1101. new
  1102. sector = YSI_g_sObjects[objectid][E_OBJECT_SECTOR];
  1103. if (view > OBJECT_MAX_VIEW_DISTANCE)
  1104. {
  1105. if (sector != OBJECT_LOD_SECTOR)
  1106. {
  1107. Object_RemoveFromSector(sector, objectid);
  1108. Object_AddToLOD(objectid);
  1109. }
  1110. }
  1111. else if (sector == OBJECT_LOD_SECTOR)
  1112. {
  1113. Object_RemoveFromSector(sector, objectid);
  1114. Object_AddToSector(Object_FindSector(YSI_g_sObjects[objectid][E_OBJECT_X], YSI_g_sObjects[objectid][E_OBJECT_Y], YSI_g_sObjects[objectid][E_OBJECT_Z]), objectid, view);
  1115. }
  1116. else if (sector < sizeof (YSI_g_sObjectSectors))
  1117. {
  1118. if (YSI_g_sObjectSectors[sector][E_OBJ_SECTOR_MAX_VIEW] < view) YSI_g_sObjectSectors[sector][E_OBJ_SECTOR_MAX_VIEW] = view;
  1119. }
  1120. return 1;
  1121. }
  1122. return 0;
  1123. #if defined _YSI_SETUP_MASTER
  1124. }
  1125. else
  1126. {
  1127. return CallRemoteFunction("Object_Remote", "iii", objectid, _:view, E_OBJECT_REMOTE_VIEW);
  1128. }
  1129. #endif
  1130. }
  1131. /*----------------------------------------------------------------------------*-
  1132. Function:
  1133. Object_AddToUpdate
  1134. Params:
  1135. objectid - Object to add to the update list.
  1136. Return:
  1137. -
  1138. Notes:
  1139. Safely adds an object to the moved update list.
  1140. -*----------------------------------------------------------------------------*/
  1141. static stock Object_AddToUpdate(objectid)
  1142. {
  1143. if (YSI_g_sObjects[objectid][E_OBJECT_UPDATES] == NO_OBJECT)
  1144. {
  1145. YSI_g_sObjects[objectid][E_OBJECT_UPDATES] = YSI_g_sSomethingMoved;
  1146. YSI_g_sSomethingMoved = objectid;
  1147. }
  1148. }
  1149. /*----------------------------------------------------------------------------*-
  1150. Function:
  1151. Object_Object
  1152. Params:
  1153. -
  1154. Return:
  1155. -
  1156. Notes:
  1157. Sets up variables for initial use.
  1158. -*----------------------------------------------------------------------------*/
  1159. Object_Object()
  1160. {
  1161. static
  1162. timer;
  1163. if (!timer)
  1164. {
  1165. #if defined _YSI_SETUP_MASTER
  1166. YSI_g_sIsMaster = Master_Add("YSIM_Objects");
  1167. #endif
  1168. YSI_g_sNoObjects = 0;
  1169. new
  1170. i;
  1171. while (i < MAX_DYN_OBJECTS)
  1172. {
  1173. YSI_g_sObjects[i][E_OBJECT_UPDATES] = NO_OBJECT;
  1174. YSI_g_sObjects[i++][E_OBJECT_NEXT] = i;
  1175. }
  1176. YSI_g_sObjects[MAX_DYN_OBJECTS - 1][E_OBJECT_NEXT] = NO_OBJECT;
  1177. for (i = 0; i < OBJECT_SECTOR_ARRAY; i++)
  1178. {
  1179. YSI_g_sObjectSectors[i][E_OBJ_SECTOR_POINTER] = NO_OBJECT;
  1180. YSI_g_sObjectSectors[i][E_OBJ_SECTOR_MAX_VIEW] = OBJECT_SIGHT;
  1181. }
  1182. YSI_g_sXSectorLocations[0] = OBJECT_BOUNDS_MINX;
  1183. for (i = 1; i < OBJECT_SECTOR_X_EDGE; i++)
  1184. {
  1185. YSI_g_sXSectorLocations[i] = (float(OBJECT_BOUNDS_X_SIZE * i) / OBJECT_SECTOR_X_EDGE) + OBJECT_BOUNDS_MINX;
  1186. }
  1187. YSI_g_sXSectorLocations[OBJECT_SECTOR_X_EDGE] = OBJECT_BOUNDS_MAXX;
  1188. YSI_g_sXSectorSize = (YSI_g_sXSectorLocations[1] - YSI_g_sXSectorLocations[0]);
  1189. YSI_g_sYSectorLocations[0] = OBJECT_BOUNDS_MINY;
  1190. for (i = 1; i < OBJECT_SECTOR_Y_EDGE; i++)
  1191. {
  1192. YSI_g_sYSectorLocations[i] = (float(OBJECT_BOUNDS_Y_SIZE * i) / OBJECT_SECTOR_Y_EDGE) + OBJECT_BOUNDS_MINY;
  1193. }
  1194. YSI_g_sYSectorLocations[OBJECT_SECTOR_Y_EDGE] = OBJECT_BOUNDS_MAXY;
  1195. YSI_g_sYSectorSize = (YSI_g_sYSectorLocations[1] - YSI_g_sYSectorLocations[0]);
  1196. #if defined _YSI_VISUAL_AREAS
  1197. #if defined NO_GATE_AREA_LOOKUP
  1198. for (i = 0; i < MAX_GATE_OBJECTS; i++)
  1199. {
  1200. YSI_g_sGateInfo[i][E_GATE_INFO_TRIGGER] = NO_GATE;
  1201. }
  1202. #else
  1203. for (i = 0; i < sizeof (YSI_g_sGateAreas); i++)
  1204. {
  1205. YSI_g_sGateAreas[i] = NO_GATE;
  1206. }
  1207. #endif
  1208. #endif
  1209. for (i = 0; i < MAX_PLAYERS; i++)
  1210. {
  1211. for (new j = 0; j < MAY_OBJECTS; j++)
  1212. {
  1213. YSI_g_sPlayerObjects[i][j] = NO_OBJECT;
  1214. }
  1215. }
  1216. timer = Timer_Add("Object_Loop", OBJECT_LOOP_GRANULARITY);
  1217. }
  1218. return 1;
  1219. }
  1220. /*----------------------------------------------------------------------------*-
  1221. Function:
  1222. CreateDynamicObject
  1223. Params:
  1224. model - Model of object.
  1225. Float:X - x position.
  1226. Float:Y - y position.
  1227. Float:Z - z position.
  1228. Float:RX - x rotation.
  1229. Float:RY - y rotation.
  1230. Float:RZ - z rotation.
  1231. Return:
  1232. -
  1233. Notes:
  1234. Dynamic wrapper for CreateObject.
  1235. -*----------------------------------------------------------------------------*/
  1236. stock CreateDynamicObject(model, Float:X, Float:Y, Float:Z, Float:RX = 0.0, Float:RY = 0.0, Float:RZ = 0.0)
  1237. {
  1238. new
  1239. object = Object_Add(model, X, Y, Z, RX, RY, RZ);
  1240. if (object != NO_OBJECT)
  1241. {
  1242. Object_AddToAllWorlds(object);
  1243. Object_AddToAllPlayers(object);
  1244. }
  1245. return object;
  1246. }
  1247. /*----------------------------------------------------------------------------*-
  1248. Function:
  1249. CreatePlayerDynamicObject
  1250. Params:
  1251. playerid - Player to create it for.
  1252. model - Model of object.
  1253. Float:X - x position.
  1254. Float:Y - y position.
  1255. Float:Z - z position.
  1256. Float:RX - x rotation.
  1257. Float:RY - y rotation.
  1258. Float:RZ - z rotation.
  1259. Return:
  1260. -
  1261. Notes:
  1262. Dynamic wrapper for CreatePlayerObject.
  1263. -*----------------------------------------------------------------------------*/
  1264. stock CreatePlayerDynamicObject(playerid, model, Float:X, Float:Y, Float:Z, Float:RX = 0.0, Float:RY = 0.0, Float:RZ = 0.0)
  1265. {
  1266. new
  1267. object;
  1268. #if !defined NO_PLAYER_ONLY
  1269. object = Object_Add(model, X, Y, Z, RX, RY, RZ);
  1270. if (object != NO_OBJECT)
  1271. {
  1272. Object_RemoveFromAllPlayers(object);
  1273. Object_AddToPlayer(object, playerid);
  1274. Object_AddToAllWorlds(object);
  1275. }
  1276. #else
  1277. #pragma unused playerid
  1278. object = CreateDynamicObject(model, X, Y, Z, RX, RY, RZ);
  1279. #endif
  1280. return object;
  1281. }
  1282. /*----------------------------------------------------------------------------*-
  1283. Function:
  1284. CreateVWDynamicObject
  1285. Params:
  1286. virtualworld - World to create it in.
  1287. model - Model of object.
  1288. Float:X - x position.
  1289. Float:Y - y position.
  1290. Float:Z - z position.
  1291. Float:RX - x rotation.
  1292. Float:RY - y rotation.
  1293. Float:RZ - z rotation.
  1294. Return:
  1295. -
  1296. Notes:
  1297. Dynamic wrapper for CreateObject with VW support.
  1298. -*----------------------------------------------------------------------------*/
  1299. stock CreateVWDynamicObject(virtualworld, model, Float:X, Float:Y, Float:Z, Float:RX = 0.0, Float:RY = 0.0, Float:RZ = 0.0)
  1300. {
  1301. new
  1302. object;
  1303. #if OBJECT_WORLDS > 0
  1304. object = Object_Add(model, X, Y, Z, RX, RY, RZ);
  1305. if (object != NO_OBJECT)
  1306. {
  1307. Object_RemoveFromAllWorlds(object);
  1308. Object_AddToWorld(object, virtualworld);
  1309. Object_AddToAllPlayers(object);
  1310. }
  1311. #else
  1312. #pragma unused virtualworld
  1313. object = CreateDynamicObject(model, X, Y, Z, RX, RY, RZ);
  1314. #endif
  1315. return object;
  1316. }
  1317. /*----------------------------------------------------------------------------*-
  1318. Function:
  1319. CreatePlayerVWDynamicObject
  1320. Params:
  1321. playerid 0 Player to create it for.
  1322. virtualworld - World to create it in.
  1323. model - Model of object.
  1324. Float:X - x position.
  1325. Float:Y - y position.
  1326. Float:Z - z position.
  1327. Float:RX - x rotation.
  1328. Float:RY - y rotation.
  1329. Float:RZ - z rotation.
  1330. Return:
  1331. -
  1332. Notes:
  1333. Dynamic wrapper for CreatePlayerObject with VW support.
  1334. -*----------------------------------------------------------------------------*/
  1335. stock CreatePlayerVWDynamicObject(playerid, virtualworld, model, Float:X, Float:Y, Float:Z, Float:RX = 0.0, Float:RY = 0.0, Float:RZ = 0.0)
  1336. {
  1337. new
  1338. object;
  1339. #if !defined NO_PLAYER_ONLY
  1340. #if OBJECT_WORLDS > 0
  1341. object = Object_Add(model, X, Y, Z, RX, RY, RZ);
  1342. if (object != NO_OBJECT)
  1343. {
  1344. Object_AddToWorld(object, virtualworld);
  1345. Object_AddToPlayer(object, playerid);
  1346. }
  1347. #else
  1348. object = CreatePlayerDynamicObject(playerid, model, X, Y, Z, RX, RY, RZ);
  1349. #pragma unused virtualworld
  1350. #endif
  1351. #else
  1352. #if OBJECT_WORLDS > 0
  1353. object = CreateVWDynamicObject(virtualworld, model, X, Y, Z, RX, RY, RZ);
  1354. #pragma unused playerid
  1355. #else
  1356. object = CreateDynamicObject(model, X, Y, Z, RX, RY, RZ);
  1357. #pragma unused playerid, virtualworld
  1358. #endif
  1359. #endif
  1360. return object;
  1361. }
  1362. /*----------------------------------------------------------------------------*-
  1363. Function:
  1364. Object_Add
  1365. Params:
  1366. model - The object model.
  1367. Float:x - X position.
  1368. Float:y - Y position.
  1369. Float:z - Z position.
  1370. Float:rx - X rotation.
  1371. Float:ry - Y rotation.
  1372. Float:rz - Z rotation.
  1373. Return:
  1374. -
  1375. Notes:
  1376. Internal object addition function. Checks if there are any slots open
  1377. and adds the object to the list if there are. Sets up initial flags and
  1378. stores the position.
  1379. -*----------------------------------------------------------------------------*/
  1380. static stock Object_Add(model, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
  1381. {
  1382. #if defined _YSI_SETUP_MASTER
  1383. if (!Object_IsValidModel(model)) return NO_OBJECT;
  1384. if (!YSI_g_sIsMaster)
  1385. {
  1386. CallRemoteFunction("Object_AddRem", "iiffffff", YSI_gMasterID, model, x, y, z, rx, ry, rz);
  1387. return getproperty(0, "YSIReq");
  1388. }
  1389. else
  1390. {
  1391. return Object_AddRem(YSI_gMasterID, model, x, y, z, rx, ry, rz);
  1392. }
  1393. }
  1394. /*----------------------------------------------------------------------------*-
  1395. Function:
  1396. Object_AddRem
  1397. Params:
  1398. master - The script which owns the object being made.
  1399. model - The object model.
  1400. Float:x - X position.
  1401. Float:y - Y position.
  1402. Float:z - Z position.
  1403. Float:rx - X rotation.
  1404. Float:ry - Y rotation.
  1405. Float:rz - Z rotation.
  1406. Return:
  1407. -
  1408. Notes:
  1409. Remote wrapper for Object_Add.
  1410. -*----------------------------------------------------------------------------*/
  1411. public Object_AddRem(master, model, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
  1412. {
  1413. DBGP3("Object_AddRem() start %d", YSI_gMasterID);
  1414. if (!YSI_g_sIsMaster) return NO_OBJECT;
  1415. DBGP3("Object_AddRem() Master");
  1416. setproperty(0, "YSIReq", NO_OBJECT);
  1417. #endif
  1418. model &= _:e_OBJ_FLAG_MODEL;
  1419. if (YSI_g_sNoObjects == NO_OBJECT) return NO_OBJECT;
  1420. #if !defined _YSI_SETUP_MASTER
  1421. if (!Object_IsValidModel(model)) return NO_OBJECT;
  1422. #endif
  1423. new
  1424. pointer = YSI_g_sNoObjects;
  1425. YSI_g_sNoObjects = YSI_g_sObjects[pointer][E_OBJECT_NEXT];
  1426. #if defined _YSI_SETUP_MASTER
  1427. YSI_g_sObjects[pointer][E_OBJECT_SCRIPT] = master;
  1428. #endif
  1429. YSI_g_sObjects[pointer][E_OBJECT_MODEL] = e_OBJ_FLAG:model | e_OBJ_FLAG_ACTIVE | e_OBJ_FLAG_RECREATED | Object_SetAttach(NO_ATTACH_PLAYER);
  1430. YSI_g_sObjects[pointer][E_OBJECT_X] = x;
  1431. YSI_g_sObjects[pointer][E_OBJECT_Y] = y;
  1432. YSI_g_sObjects[pointer][E_OBJECT_Z] = z;
  1433. YSI_g_sObjects[pointer][E_OBJECT_RX] = rx;
  1434. YSI_g_sObjects[pointer][E_OBJECT_RY] = ry;
  1435. YSI_g_sObjects[pointer][E_OBJECT_RZ] = rz;
  1436. YSI_g_sObjects[pointer][E_OBJECT_VIEW] = OBJECT_SIGHT;
  1437. #if !defined NO_OBJECT_ATTACH
  1438. YSI_g_sObjects[pointer][E_OBJECT_PARENT] = NO_OBJECT;
  1439. YSI_g_sObjects[pointer][E_OBJECT_SIBLINGS] = NO_OBJECT;
  1440. YSI_g_sObjects[pointer][E_OBJECT_CHILDREN] = NO_OBJECT;
  1441. #endif
  1442. Object_AddToUpdate(pointer);
  1443. Object_AddToSector(Object_FindSector(x, y, z), pointer, OBJECT_SIGHT);
  1444. #if defined _YSI_SETUP_MASTER
  1445. setproperty(0, "YSIReq", pointer);
  1446. #endif
  1447. return pointer;
  1448. }
  1449. /*----------------------------------------------------------------------------*-
  1450. Function:
  1451. Object_FindSector
  1452. Params:
  1453. Float:x - X point.
  1454. Float:y - Y point.
  1455. Float:z - Z point.
  1456. Return:
  1457. Point's sector.
  1458. Notes:
  1459. Finds the sector of a point.
  1460. -*----------------------------------------------------------------------------*/
  1461. static stock Object_FindSector(Float:x, Float:y, Float:z)
  1462. {
  1463. if (z > 800.0) return OBJECT_INT_SECTOR;
  1464. if (x < OBJECT_BOUNDS_MINX || x >= OBJECT_BOUNDS_MAXX || y < OBJECT_BOUNDS_MINY || y >= OBJECT_BOUNDS_MAXY) return OBJECT_NO_SECTOR;
  1465. x = floatsub(x, float(OBJECT_BOUNDS_MINX)) / OBJECT_REAL_X_SECTOR_SIZE;
  1466. y = floatsub(y, float(OBJECT_BOUNDS_MINY)) / OBJECT_REAL_Y_SECTOR_SIZE;
  1467. new
  1468. val;
  1469. val = (floatround(x, floatround_floor) * OBJECT_SECTOR_X_EDGE) + floatround(y, floatround_floor);
  1470. return val;
  1471. }
  1472. /*----------------------------------------------------------------------------*-
  1473. Function:
  1474. Object_AddToOOB
  1475. Params:
  1476. pointer - Index of the object to add.
  1477. Return:
  1478. -
  1479. Notes:
  1480. Adds an object to the linked list for objects out of bounds of the grid
  1481. system (i.e. stores objects out the +/-OBJECT_BOUNDS world limit).
  1482. -*----------------------------------------------------------------------------*/
  1483. static stock Object_AddToOOB(pointer)
  1484. {
  1485. if (YSI_g_sOtherSector == NO_OBJECT)
  1486. {
  1487. YSI_g_sOtherSector = pointer;
  1488. YSI_g_sObjects[pointer][E_OBJECT_NEXT] = pointer;
  1489. }
  1490. else
  1491. {
  1492. YSI_g_sObjects[pointer][E_OBJECT_NEXT] = YSI_g_sObjects[YSI_g_sOtherSector][E_OBJECT_NEXT];
  1493. YSI_g_sObjects[YSI_g_sOtherSector][E_OBJECT_NEXT] = pointer;
  1494. }
  1495. YSI_g_sObjects[pointer][E_OBJECT_SECTOR] = OBJECT_NO_SECTOR;
  1496. }
  1497. /*----------------------------------------------------------------------------*-
  1498. Function:
  1499. Object_AddToLOD
  1500. Params:
  1501. pointer - Index of the object to add.
  1502. Return:
  1503. -
  1504. Notes:
  1505. Adds an object to the linked list for objects with views > OBJECT_MAX_VIEW
  1506. -*----------------------------------------------------------------------------*/
  1507. static stock Object_AddToLOD(pointer)
  1508. {
  1509. if (YSI_g_sLODObjects == NO_OBJECT)
  1510. {
  1511. YSI_g_sLODObjects = pointer;
  1512. YSI_g_sObjects[pointer][E_OBJECT_NEXT] = pointer;
  1513. }
  1514. else
  1515. {
  1516. YSI_g_sObjects[pointer][E_OBJECT_NEXT] = YSI_g_sObjects[YSI_g_sLODObjects][E_OBJECT_NEXT];
  1517. YSI_g_sObjects[YSI_g_sLODObjects][E_OBJECT_NEXT] = pointer;
  1518. }
  1519. YSI_g_sObjects[pointer][E_OBJECT_SECTOR] = OBJECT_LOD_SECTOR;
  1520. }
  1521. /*----------------------------------------------------------------------------*-
  1522. Function:
  1523. Object_AddToINT
  1524. Params:
  1525. pointer - Index of the object to add.
  1526. Return:
  1527. -
  1528. Notes:
  1529. Adds an object to the linked list for objects in interiors.
  1530. -*----------------------------------------------------------------------------*/
  1531. static stock Object_AddToINT(pointer)
  1532. {
  1533. if (YSI_g_sInteriorObjects == NO_OBJECT)
  1534. {
  1535. YSI_g_sInteriorObjects = pointer;
  1536. YSI_g_sObjects[pointer][E_OBJECT_NEXT] = pointer;
  1537. }
  1538. else
  1539. {
  1540. YSI_g_sObjects[pointer][E_OBJECT_NEXT] = YSI_g_sObjects[YSI_g_sInteriorObjects][E_OBJECT_NEXT];
  1541. YSI_g_sObjects[YSI_g_sInteriorObjects][E_OBJECT_NEXT] = pointer;
  1542. }
  1543. YSI_g_sObjects[pointer][E_OBJECT_SECTOR] = OBJECT_LOD_SECTOR;
  1544. }
  1545. /*----------------------------------------------------------------------------*-
  1546. Function:
  1547. Object_AddToMovingList
  1548. Params:
  1549. pointer - Index of the object to add.
  1550. Return:
  1551. -
  1552. Notes:
  1553. Adds an object to the linked list for dynamic objects.
  1554. -*----------------------------------------------------------------------------*/
  1555. static stock Object_AddToMovingList(pointer)
  1556. {
  1557. if (YSI_g_sMovingObjects == NO_OBJECT)
  1558. {
  1559. YSI_g_sMovingObjects = pointer;
  1560. YSI_g_sObjects[pointer][E_OBJECT_NEXT] = pointer;
  1561. }
  1562. else
  1563. {
  1564. YSI_g_sObjects[pointer][E_OBJECT_NEXT] = YSI_g_sObjects[YSI_g_sMovingObjects][E_OBJECT_NEXT];
  1565. YSI_g_sObjects[YSI_g_sMovingObjects][E_OBJECT_NEXT] = pointer;
  1566. }
  1567. YSI_g_sObjects[pointer][E_OBJECT_SECTOR] = OBJECT_NO_SECTOR;
  1568. }
  1569. /*----------------------------------------------------------------------------*-
  1570. Function:
  1571. Object_AddToSector
  1572. Params:
  1573. sector - Sector of object.
  1574. pointer - Index of object.
  1575. Float:view - Distance the object can be seen from.
  1576. Return:
  1577. -
  1578. Notes:
  1579. Saves an object as being in a sector.
  1580. -*----------------------------------------------------------------------------*/
  1581. static stock Object_AddToSector(sector, pointer, Float:view)
  1582. {
  1583. if (sector == OBJECT_NO_SECTOR) Object_AddToOOB(pointer);
  1584. else if (sector == OBJECT_INT_SECTOR) Object_AddToINT(pointer);
  1585. else if (view > (OBJECT_MAX_VIEW_DISTANCE * OBJECT_MAX_VIEW_DISTANCE)) Object_AddToLOD(pointer);
  1586. else
  1587. {
  1588. new
  1589. data = YSI_g_sObjectSectors[sector][E_OBJ_SECTOR_POINTER];
  1590. if (data == NO_OBJECT)
  1591. {
  1592. YSI_g_sObjectSectors[sector][E_OBJ_SECTOR_POINTER] = pointer;
  1593. YSI_g_sObjects[pointer][E_OBJECT_NEXT] = pointer;
  1594. }
  1595. else
  1596. {
  1597. YSI_g_sObjects[pointer][E_OBJECT_NEXT] = YSI_g_sObjects[data][E_OBJECT_NEXT];
  1598. YSI_g_sObjects[data][E_OBJECT_NEXT] = pointer;
  1599. }
  1600. YSI_g_sObjects[pointer][E_OBJECT_SECTOR] = sector;
  1601. if (view > YSI_g_sObjectSectors[sector][E_OBJ_SECTOR_MAX_VIEW]) YSI_g_sObjectSectors[sector][E_OBJ_SECTOR_MAX_VIEW] = view;
  1602. }
  1603. }
  1604. /*----------------------------------------------------------------------------*-
  1605. Function:
  1606. DestroyDynamicObject
  1607. Params:
  1608. objectid - Object to destroy.
  1609. Return:
  1610. -
  1611. Notes:
  1612. Dynamic wrapper for DestroyObject. Removes the object from it's list by
  1613. using the cyclic property to find the previous object and repointing it to
  1614. the object after the removed one. This ay make it point to itself but
  1615. this is a good thing. The object is then added to the unassigned list in
  1616. the same way as it's added to a normal list and finally the object flags
  1617. are reset to destroy the data.
  1618. -*----------------------------------------------------------------------------*/
  1619. stock DestroyDynamicObject(objectid)
  1620. {
  1621. #if defined _YSI_SETUP_MASTER
  1622. if (YSI_g_sIsMaster)
  1623. {
  1624. #endif
  1625. if (Object_IsValid(objectid))
  1626. {
  1627. return Object_Destroy(objectid);
  1628. }
  1629. return 0;
  1630. #if defined _YSI_SETUP_MASTER
  1631. }
  1632. else
  1633. {
  1634. CallRemoteFunction("Object_Remote", "iii", objectid, 0, E_OBJECT_REMOTE_DESTROY);
  1635. return getproperty(0, "YSIReq");
  1636. }
  1637. #endif
  1638. }
  1639. /*----------------------------------------------------------------------------*-
  1640. Function:
  1641. Object_Destroy
  1642. Params:
  1643. objectid - Object to destroy.
  1644. remove - Wether to update client side objects.
  1645. Return:
  1646. -
  1647. Notes:
  1648. Does the hard work for DestroyDynamicObject.
  1649. -*----------------------------------------------------------------------------*/
  1650. static stock Object_Destroy(objectid, remove = 1)
  1651. {
  1652. Object_RemoveFromSector(YSI_g_sObjects[objectid][E_OBJECT_SECTOR], objectid);
  1653. if (YSI_g_sNoObjects == NO_OBJECT)
  1654. {
  1655. YSI_g_sNoObjects = objectid;
  1656. YSI_g_sObjects[objectid][E_OBJECT_NEXT] = objectid;
  1657. }
  1658. else
  1659. {
  1660. YSI_g_sObjects[objectid][E_OBJECT_NEXT] = YSI_g_sObjects[YSI_g_sNoObjects][E_OBJECT_NEXT];
  1661. YSI_g_sObjects[YSI_g_sNoObjects][E_OBJECT_NEXT] = objectid;
  1662. }
  1663. #if !defined NO_OBJECT_ATTACH
  1664. new
  1665. children = YSI_g_sObjects[objectid][E_OBJECT_CHILDREN],
  1666. parent = YSI_g_sObjects[objectid][E_OBJECT_PARENT],
  1667. old = NO_OBJECT,
  1668. last = NO_OBJECT;
  1669. while (children != NO_OBJECT)
  1670. {
  1671. last = children;
  1672. YSI_g_sObjects[children][E_OBJECT_PARENT] = parent;
  1673. children = YSI_g_sObjects[children][E_OBJECT_SIBLINGS];
  1674. }
  1675. if (parent != NO_OBJECT)
  1676. {
  1677. old = YSI_g_sObjects[parent][E_OBJECT_CHILDREN];
  1678. if (old == objectid)
  1679. {
  1680. old = YSI_g_sObjects[objectid][E_OBJECT_SIBLINGS];
  1681. }
  1682. else
  1683. {
  1684. children = old;
  1685. new
  1686. obj;
  1687. do
  1688. {
  1689. obj = children;
  1690. children = YSI_g_sObjects[children][E_OBJECT_SIBLINGS];
  1691. }
  1692. while (children != objectid);
  1693. YSI_g_sObjects[obj][E_OBJECT_SIBLINGS] = YSI_g_sObjects[objectid][E_OBJECT_SIBLINGS];
  1694. }
  1695. if (last != NO_OBJECT)
  1696. {
  1697. YSI_g_sObjects[last][E_OBJECT_SIBLINGS] = old;
  1698. }
  1699. YSI_g_sObjects[parent][E_OBJECT_CHILDREN] = YSI_g_sObjects[objectid][E_OBJECT_CHILDREN];
  1700. }
  1701. #endif
  1702. YSI_g_sObjects[objectid][E_OBJECT_MODEL] = e_OBJ_FLAG:0;
  1703. if (remove)
  1704. {
  1705. foreach (Player, playerid)
  1706. {
  1707. for (new i = 0; i < MAY_OBJECTS; i++)
  1708. {
  1709. if (YSI_g_sPlayerObjects[playerid][i] == objectid)
  1710. {
  1711. DestroyPlayerObject(playerid, i + 1);
  1712. break;
  1713. }
  1714. }
  1715. }
  1716. }
  1717. return 1;
  1718. }
  1719. /*----------------------------------------------------------------------------*-
  1720. Function:
  1721. Object_RemoveFromSector
  1722. Params:
  1723. sector - Sector list to modify.
  1724. objectid - Object to remove.
  1725. Return:
  1726. -
  1727. Notes:
  1728. Used to be part of DestroyDynamicObject but is needed by other API
  1729. functions.
  1730. -*----------------------------------------------------------------------------*/
  1731. static stock Object_RemoveFromSector(sector, objectid)
  1732. {
  1733. new
  1734. pointer = objectid,
  1735. last,
  1736. Float:newview = OBJECT_SIGHT;
  1737. do
  1738. {
  1739. last = pointer;
  1740. pointer = YSI_g_sObjects[last][E_OBJECT_NEXT];
  1741. if (last != objectid && YSI_g_sObjects[last][E_OBJECT_VIEW] > newview) newview = YSI_g_sObjects[last][E_OBJECT_VIEW];
  1742. }
  1743. while (pointer != objectid);
  1744. if (last == objectid)
  1745. {
  1746. if (YSI_g_sObjects[objectid][E_OBJECT_MODEL] & e_OBJ_FLAG_MOVED) YSI_g_sMovingObjects = NO_OBJECT;
  1747. else if (sector == OBJECT_NO_SECTOR) YSI_g_sOtherSector = NO_OBJECT;
  1748. else if (sector == OBJECT_LOD_SECTOR) YSI_g_sLODObjects = NO_OBJECT;
  1749. else if (sector == OBJECT_INT_SECTOR) YSI_g_sInteriorObjects = NO_OBJECT;
  1750. else
  1751. {
  1752. YSI_g_sObjectSectors[sector][E_OBJ_SECTOR_POINTER] = NO_OBJECT;
  1753. YSI_g_sObjectSectors[sector][E_OBJ_SECTOR_MAX_VIEW] = OBJECT_SIGHT;
  1754. }
  1755. }
  1756. else
  1757. {
  1758. if (YSI_g_sObjects[objectid][E_OBJECT_MODEL] & e_OBJ_FLAG_MOVED)
  1759. {
  1760. if (YSI_g_sMovingObjects == objectid) YSI_g_sMovingObjects = last;
  1761. }
  1762. else if (sector == OBJECT_NO_SECTOR)
  1763. {
  1764. if (YSI_g_sOtherSector == objectid) YSI_g_sOtherSector = last;
  1765. }
  1766. else if (sector == OBJECT_LOD_SECTOR)
  1767. {
  1768. if (YSI_g_sLODObjects == objectid) YSI_g_sLODObjects = last;
  1769. }
  1770. else if (sector == OBJECT_INT_SECTOR)
  1771. {
  1772. if (YSI_g_sInteriorObjects == objectid) YSI_g_sInteriorObjects = last;
  1773. }
  1774. else if (YSI_g_sObjectSectors[sector][E_OBJ_SECTOR_POINTER] == objectid)
  1775. {
  1776. YSI_g_sObjectSectors[sector][E_OBJ_SECTOR_POINTER] = last;
  1777. YSI_g_sObjectSectors[sector][E_OBJ_SECTOR_MAX_VIEW] = newview;
  1778. }
  1779. YSI_g_sObjects[last][E_OBJECT_NEXT] = YSI_g_sObjects[objectid][E_OBJECT_NEXT];
  1780. }
  1781. }
  1782. /*----------------------------------------------------------------------------*-
  1783. Function:
  1784. SetDynamicObjectPos
  1785. Params:
  1786. objectid - Object to objSet new position of.
  1787. Float:x - X co-ordinate.
  1788. Float:y - Y co-ordintae.
  1789. Float:z - Z co-ordinate.
  1790. Return:
  1791. -
  1792. Notes:
  1793. Updated to update child positions to (but NOT parent).
  1794. -*----------------------------------------------------------------------------*/
  1795. stock SetDynamicObjectPos(objectid, Float:x, Float:y, Float:z)
  1796. {
  1797. #if defined _YSI_SETUP_MASTER
  1798. if (YSI_g_sIsMaster)
  1799. {
  1800. #endif
  1801. if (!Object_IsValid(objectid) || Object_IsAttached(YSI_g_sObjects[objectid][E_OBJECT_MODEL])) return 0;
  1802. #if !defined NO_OBJECT_ATTACH
  1803. Object_UpdateChildSectors(YSI_g_sObjects[objectid][E_OBJECT_CHILDREN], x, y, z);
  1804. #endif
  1805. return Object_SetPos(objectid, x, y, z);
  1806. #if defined _YSI_SETUP_MASTER
  1807. }
  1808. else
  1809. {
  1810. CallRemoteFunction("Object_CoOrdRemote", "iiffff", objectid, E_OBJECT_REMOTE_SETPOS, x, y, z, 0.0);
  1811. return getproperty(0, "YSIReq");
  1812. }
  1813. #endif
  1814. }
  1815. /*----------------------------------------------------------------------------*-
  1816. Function:
  1817. Object_SetPos
  1818. Params:
  1819. objectid - Object to objSet new position of.
  1820. Float:x - X co-ordinate.
  1821. Float:y - Y co-ordintae.
  1822. Float:z - Z co-ordinate.
  1823. Return:
  1824. -
  1825. Notes:
  1826. Does the actual relocation of an object.
  1827. -*----------------------------------------------------------------------------*/
  1828. static stock Object_SetPos(objectid, Float:x, Float:y, Float:z)
  1829. {
  1830. new
  1831. newsec = Object_FindSector(x, y, z),
  1832. oldsec;
  1833. if (newsec != (oldsec = YSI_g_sObjects[objectid][E_OBJECT_SECTOR]))
  1834. {
  1835. Object_RemoveFromSector(oldsec, objectid);
  1836. Object_AddToSector(newsec, objectid, YSI_g_sObjects[objectid][E_OBJECT_VIEW]);
  1837. }
  1838. #if !defined NO_OBJECT_ATTACH
  1839. new
  1840. parent = YSI_g_sObjects[objectid][E_OBJECT_PARENT];
  1841. if (parent != NO_OBJECT)
  1842. {
  1843. new
  1844. Float:nx,
  1845. Float:ny,
  1846. Float:nz;
  1847. Object_GetPos(parent, nx, ny, nz);
  1848. YSI_g_sObjects[objectid][E_OBJECT_X] = x - nx;
  1849. YSI_g_sObjects[objectid][E_OBJECT_Y] = y - ny;
  1850. YSI_g_sObjects[objectid][E_OBJECT_Z] = z - nz;
  1851. }
  1852. else
  1853. {
  1854. #endif
  1855. YSI_g_sObjects[objectid][E_OBJECT_X] = x;
  1856. YSI_g_sObjects[objectid][E_OBJECT_Y] = y;
  1857. YSI_g_sObjects[objectid][E_OBJECT_Z] = z;
  1858. #if !defined NO_OBJECT_ATTACH
  1859. }
  1860. #endif
  1861. YSI_g_sObjects[objectid][E_OBJECT_MODEL] |= e_OBJ_FLAG_JUMPED;
  1862. Object_AddToUpdate(objectid);
  1863. return 1;
  1864. }
  1865. /*----------------------------------------------------------------------------*-
  1866. Function:
  1867. Object_UpdateChildSectors
  1868. Params:
  1869. objectid - Object to update children of.
  1870. Float:x - X co-ordinate of parent.
  1871. Float:y - Y co-ordintae of parent.
  1872. Float:z - Z co-ordinate of parent.
  1873. Return:
  1874. -
  1875. Notes:
  1876. Doesn't update the position parameter as that's relative to the parent for
  1877. child objects. Recursive function to update sectors of children of
  1878. children.
  1879. -*----------------------------------------------------------------------------*/
  1880. #if !defined NO_OBJECT_ATTACH
  1881. static stock Object_UpdateChildSectors(objectid, Float:x, Float:y, Float:z)
  1882. {
  1883. new
  1884. Float:nx,
  1885. Float:ny,
  1886. Float:nz,
  1887. newsec,
  1888. oldsec;
  1889. while (objectid != NO_OBJECT)
  1890. {
  1891. if (Object_IsAttached(objectid))
  1892. {
  1893. nx = x + YSI_g_sObjects[objectid][E_OBJECT_X];
  1894. ny = y + YSI_g_sObjects[objectid][E_OBJECT_Y];
  1895. nz = z + YSI_g_sObjects[objectid][E_OBJECT_Z];
  1896. newsec = Object_FindSector(nx, ny, nz);
  1897. if (newsec != (oldsec = YSI_g_sObjects[objectid][E_OBJECT_SECTOR]))
  1898. {
  1899. Object_RemoveFromSector(oldsec, objectid);
  1900. Object_AddToSector(newsec, objectid, YSI_g_sObjects[objectid][E_OBJECT_VIEW]);
  1901. }
  1902. Object_UpdateChildSectors(YSI_g_sObjects[objectid][E_OBJECT_CHILDREN], nx, ny, nz);
  1903. YSI_g_sObjects[objectid][E_OBJECT_MODEL] |= e_OBJ_FLAG_JUMPED;
  1904. }
  1905. objectid = YSI_g_sObjects[objectid][E_OBJECT_SIBLINGS];
  1906. }
  1907. }
  1908. #endif
  1909. /*----------------------------------------------------------------------------*-
  1910. Function:
  1911. SetDynamicObjectRot
  1912. Params:
  1913. objectid - Object to objSet new rotation of.
  1914. Float:x - X rotation.
  1915. Float:y - Y rotation.
  1916. Float:z - Z rotation.
  1917. Return:
  1918. -
  1919. Notes:
  1920. -
  1921. -*----------------------------------------------------------------------------*/
  1922. stock SetDynamicObjectRot(objectid, Float:x, Float:y, Float:z)
  1923. {
  1924. #if defined _YSI_SETUP_MASTER
  1925. if (YSI_g_sIsMaster)
  1926. {
  1927. #endif
  1928. if (!Object_IsValid(objectid) || Object_IsAttached(YSI_g_sObjects[objectid][E_OBJECT_MODEL])) return 0;
  1929. YSI_g_sObjects[objectid][E_OBJECT_RX] = x;
  1930. YSI_g_sObjects[objectid][E_OBJECT_RY] = y;
  1931. YSI_g_sObjects[objectid][E_OBJECT_RZ] = z;
  1932. YSI_g_sObjects[objectid][E_OBJECT_MODEL] |= e_OBJ_FLAG_ROTATED;
  1933. Object_AddToUpdate(objectid);
  1934. return 1;
  1935. #if defined _YSI_SETUP_MASTER
  1936. }
  1937. else
  1938. {
  1939. CallRemoteFunction("Object_CoOrdRemote", "iiffff", objectid, E_OBJECT_REMOTE_SETROT, x, y, z, 0.0);
  1940. return getproperty(0, "YSIReq");
  1941. }
  1942. #endif
  1943. }
  1944. /*----------------------------------------------------------------------------*-
  1945. Function:
  1946. GetDynamicObjectRot
  1947. Params:
  1948. objectid - Object to objSet new rotation of.
  1949. &Float:x - X rotation store.
  1950. &Float:y - Y rotation store.
  1951. &Float:z - Z rotation store.
  1952. Return:
  1953. -
  1954. Notes:
  1955. -
  1956. -*----------------------------------------------------------------------------*/
  1957. stock GetDynamicObjectRot(objectid, &Float:x, &Float:y, &Float:z)
  1958. {
  1959. #if defined _YSI_SETUP_MASTER
  1960. if (YSI_g_sIsMaster)
  1961. {
  1962. #endif
  1963. if (!Object_IsValid(objectid) || Object_IsAttached(YSI_g_sObjects[objectid][E_OBJECT_MODEL])) return 0;
  1964. x = YSI_g_sObjects[objectid][E_OBJECT_RX];
  1965. y = YSI_g_sObjects[objectid][E_OBJECT_RY];
  1966. z = YSI_g_sObjects[objectid][E_OBJECT_RZ];
  1967. return 1;
  1968. #if defined _YSI_SETUP_MASTER
  1969. }
  1970. else
  1971. {
  1972. CallRemoteFunction("Object_Remote", "iii", objectid, 0, E_OBJECT_REMOTE_GETROT);
  1973. x = Float:getproperty(0, "YSIReq");
  1974. y = Float:getproperty(0, "YSIReq2");
  1975. z = Float:getproperty(0, "YSIReq3");
  1976. deleteproperty(0, "YSIReq2");
  1977. deleteproperty(0, "YSIReq3");
  1978. }
  1979. #endif
  1980. }
  1981. /*----------------------------------------------------------------------------*-
  1982. Function:
  1983. Object_AddToWorld
  1984. Params:
  1985. object - Object to add.
  1986. world - World to add to.
  1987. Return:
  1988. -
  1989. Notes:
  1990. Makes an object visible in a world.
  1991. -*----------------------------------------------------------------------------*/
  1992. stock Object_AddToWorld(object, world)
  1993. {
  1994. #if OBJECT_WORLDS > 0
  1995. #if defined _YSI_SETUP_MASTER
  1996. if (YSI_g_sIsMaster)
  1997. {
  1998. #endif
  1999. if (Object_IsValid(object)) Bit_Set(YSI_g_sObjects[object][E_OBJECT_WORLDS], world, 1, OBJECT_WORLD_COUNT);
  2000. #if defined _YSI_SETUP_MASTER
  2001. }
  2002. else
  2003. {
  2004. CallRemoteFunction("Object_Remote", "iii", object, world, E_OBJECT_REMOTE_ADDW);
  2005. }
  2006. #endif
  2007. #else
  2008. #pragma unused object, world
  2009. #endif
  2010. }
  2011. /*----------------------------------------------------------------------------*-
  2012. Function:
  2013. Object_RemoveFromWorld
  2014. Params:
  2015. object - Object to remove.
  2016. world - World to remove from.
  2017. Return:
  2018. -
  2019. Notes:
  2020. Makes an object invisible in a world.
  2021. -*----------------------------------------------------------------------------*/
  2022. stock Object_RemoveFromWorld(object, world)
  2023. {
  2024. #if OBJECT_WORLDS > 0
  2025. #if defined _YSI_SETUP_MASTER
  2026. if (YSI_g_sIsMaster)
  2027. {
  2028. #endif
  2029. if (Object_IsValid(object)) Bit_Set(YSI_g_sObjects[object][E_OBJECT_WORLDS], world, 0, OBJECT_WORLD_COUNT);
  2030. #if defined _YSI_SETUP_MASTER
  2031. }
  2032. else
  2033. {
  2034. CallRemoteFunction("Object_Remote", "iii", object, world, E_OBJECT_REMOTE_REMW);
  2035. }
  2036. #endif
  2037. #else
  2038. #pragma unused object, world
  2039. #endif
  2040. }
  2041. /*----------------------------------------------------------------------------*-
  2042. Function:
  2043. Object_AddToPlayer
  2044. Params:
  2045. object - Object to add.
  2046. playerid - Player to add to.
  2047. Return:
  2048. -
  2049. Notes:
  2050. Makes an object visible to a player.
  2051. -*----------------------------------------------------------------------------*/
  2052. stock Object_AddToPlayer(object, playerid)
  2053. {
  2054. #if !defined NO_PERSONAL_OBJECTS
  2055. #if defined _YSI_SETUP_MASTER
  2056. if (YSI_g_sIsMaster)
  2057. {
  2058. #endif
  2059. if (Object_IsValid(object)) Bit_Set(YSI_g_sObjects[object][E_OBJECT_PLAYERS], playerid, 1, PLAYER_BIT_ARRAY);
  2060. #if defined _YSI_SETUP_MASTER
  2061. }
  2062. else
  2063. {
  2064. CallRemoteFunction("Object_Remote", "iii", object, playerid, E_OBJECT_REMOTE_ADDP);
  2065. }
  2066. #endif
  2067. #else
  2068. #pragma unused object, playerid
  2069. #endif
  2070. }
  2071. /*----------------------------------------------------------------------------*-
  2072. Function:
  2073. Object_RemoveFromWorld
  2074. Params:
  2075. object - Object to remove.
  2076. playerid - Player to remove from.
  2077. Return:
  2078. -
  2079. Notes:
  2080. Makes an object invisible to a player.
  2081. -*----------------------------------------------------------------------------*/
  2082. stock Object_RemoveFromPlayer(object, playerid)
  2083. {
  2084. #if !defined NO_PERSONAL_OBJECTS
  2085. #if defined _YSI_SETUP_MASTER
  2086. if (YSI_g_sIsMaster)
  2087. {
  2088. #endif
  2089. if (Object_IsValid(object)) Bit_Set(YSI_g_sObjects[object][E_OBJECT_PLAYERS], playerid, 0, PLAYER_BIT_ARRAY);
  2090. #if defined _YSI_SETUP_MASTER
  2091. }
  2092. else
  2093. {
  2094. CallRemoteFunction("Object_Remote", "iii", object, playerid, E_OBJECT_REMOTE_REMP);
  2095. }
  2096. #endif
  2097. #else
  2098. #pragma unused object, playerid
  2099. #endif
  2100. }
  2101. /*----------------------------------------------------------------------------*-
  2102. Function:
  2103. Object_AddToAllWorlds
  2104. Params:
  2105. object - Object to add.
  2106. Return:
  2107. -
  2108. Notes:
  2109. Makes an object visible in all worlds.
  2110. -*----------------------------------------------------------------------------*/
  2111. stock Object_AddToAllWorlds(object)
  2112. {
  2113. #if OBJECT_WORLDS > 0
  2114. #if defined _YSI_SETUP_MASTER
  2115. if (YSI_g_sIsMaster)
  2116. {
  2117. #endif
  2118. if (Object_IsValid(object)) Bit_SetAll(YSI_g_sObjects[object][E_OBJECT_WORLDS], 1, OBJECT_WORLD_COUNT);
  2119. #if defined _YSI_SETUP_MASTER
  2120. }
  2121. else
  2122. {
  2123. CallRemoteFunction("Object_Remote", "iii", object, 0, E_OBJECT_REMOTE_ALLWA);
  2124. }
  2125. #endif
  2126. #else
  2127. #pragma unused object
  2128. #endif
  2129. }
  2130. /*----------------------------------------------------------------------------*-
  2131. Function:
  2132. Object_RemoveFromAllWorlds
  2133. Params:
  2134. object - Object to remove.
  2135. Return:
  2136. -
  2137. Notes:
  2138. Makes an object invisible in all worlds.
  2139. -*----------------------------------------------------------------------------*/
  2140. stock Object_RemoveFromAllWorlds(object)
  2141. {
  2142. #if OBJECT_WORLDS > 0
  2143. #if defined _YSI_SETUP_MASTER
  2144. if (YSI_g_sIsMaster)
  2145. {
  2146. #endif
  2147. if (Object_IsValid(object)) Bit_SetAll(YSI_g_sObjects[object][E_OBJECT_WORLDS], 0, OBJECT_WORLD_COUNT);
  2148. #if defined _YSI_SETUP_MASTER
  2149. }
  2150. else
  2151. {
  2152. CallRemoteFunction("Object_Remote", "iii", object, 0, E_OBJECT_REMOTE_ALLWR);
  2153. }
  2154. #endif
  2155. #else
  2156. #pragma unused object
  2157. #endif
  2158. }
  2159. /*----------------------------------------------------------------------------*-
  2160. Function:
  2161. Object_AddToAllPlayers
  2162. Params:
  2163. object - Object to add.
  2164. Return:
  2165. -
  2166. Notes:
  2167. Makes an object visible to all players.
  2168. -*----------------------------------------------------------------------------*/
  2169. stock Object_AddToAllPlayers(object)
  2170. {
  2171. #if !defined NO_PERSONAL_OBJECTS
  2172. #if defined _YSI_SETUP_MASTER
  2173. if (YSI_g_sIsMaster)
  2174. {
  2175. #endif
  2176. if (Object_IsValid(object))
  2177. {
  2178. Bit_SetAll(YSI_g_sObjects[object][E_OBJECT_PLAYERS], 1, PLAYER_BIT_ARRAY);
  2179. }
  2180. #if defined _YSI_SETUP_MASTER
  2181. }
  2182. else
  2183. {
  2184. CallRemoteFunction("Object_Remote", "iii", object, 0, E_OBJECT_REMOTE_ALLPA);
  2185. }
  2186. #endif
  2187. #else
  2188. #pragma unused object
  2189. #endif
  2190. }
  2191. /*----------------------------------------------------------------------------*-
  2192. Function:
  2193. Object_RemoveFromAllPlayers
  2194. Params:
  2195. object - Object to remove.
  2196. Return:
  2197. -
  2198. Notes:
  2199. Makes an object invisible to all players.
  2200. -*----------------------------------------------------------------------------*/
  2201. stock Object_RemoveFromAllPlayers(object)
  2202. {
  2203. #if !defined NO_PERSONAL_OBJECTS
  2204. #if defined _YSI_SETUP_MASTER
  2205. if (YSI_g_sIsMaster)
  2206. {
  2207. #endif
  2208. if (Object_IsValid(object))
  2209. {
  2210. Bit_SetAll(YSI_g_sObjects[object][E_OBJECT_PLAYERS], 0, PLAYER_BIT_ARRAY);
  2211. }
  2212. #if defined _YSI_SETUP_MASTER
  2213. }
  2214. else
  2215. {
  2216. CallRemoteFunction("Object_Remote", "iii", object, 0, E_OBJECT_REMOTE_ALLPR);
  2217. }
  2218. #endif
  2219. #else
  2220. #pragma unused object
  2221. #endif
  2222. }
  2223. /*----------------------------------------------------------------------------*-
  2224. Function:
  2225. Object_GetPos
  2226. Params:
  2227. objectid - Object to get position of.
  2228. &Float:x - X return.
  2229. &Float:y - Y return.
  2230. &Float:z - Z return.
  2231. Return:
  2232. -
  2233. Notes:
  2234. -
  2235. -*----------------------------------------------------------------------------*/
  2236. static stock Object_GetPos(objectid, &Float:x, &Float:y, &Float:z)
  2237. {
  2238. new
  2239. playerid = Object_GetAttach(YSI_g_sObjects[objectid][E_OBJECT_MODEL]);
  2240. if (playerid != NO_ATTACH_PLAYER && IsPlayerConnected(playerid))
  2241. {
  2242. GetPlayerPos(playerid, x, y, z);
  2243. }
  2244. #if !defined NO_OBJECT_ATTACH
  2245. else if ((playerid = YSI_g_sObjects[objectid][E_OBJECT_PARENT]) != NO_OBJECT)
  2246. {
  2247. Object_GetPos(playerid, x, y, z);
  2248. }
  2249. #endif
  2250. #pragma tabsize 0
  2251. else
  2252. #pragma tabsize 4
  2253. {
  2254. x = YSI_g_sObjects[objectid][E_OBJECT_X];
  2255. y = YSI_g_sObjects[objectid][E_OBJECT_Y];
  2256. z = YSI_g_sObjects[objectid][E_OBJECT_Z];
  2257. return;
  2258. }
  2259. x += YSI_g_sObjects[objectid][E_OBJECT_X];
  2260. y += YSI_g_sObjects[objectid][E_OBJECT_Y];
  2261. z += YSI_g_sObjects[objectid][E_OBJECT_Z];
  2262. }
  2263. /*----------------------------------------------------------------------------*-
  2264. Function:
  2265. GetDynamicObjectPos
  2266. Params:
  2267. objectid - Object to get position of.
  2268. &Float:x - X return.
  2269. &Float:y - Y return.
  2270. &Float:z - Z return.
  2271. Return:
  2272. -
  2273. Notes:
  2274. API wrapper for Object_GetPos.
  2275. -*----------------------------------------------------------------------------*/
  2276. stock GetDynamicObjectPos(objectid, &Float:x, &Float:y, &Float:z)
  2277. {
  2278. #if defined _YSI_SETUP_MASTER
  2279. if (YSI_g_sIsMaster)
  2280. {
  2281. #endif
  2282. if (!Object_IsValid(objectid)) return 0;
  2283. Object_GetPos(objectid, x, y, z);
  2284. #if defined _YSI_SETUP_MASTER
  2285. }
  2286. else
  2287. {
  2288. CallRemoteFunction("Object_Remote", "iii", objectid, 0, E_OBJECT_REMOTE_GETPOS);
  2289. x = Float:getproperty(0, "YSIReq");
  2290. y = Float:getproperty(0, "YSIReq2");
  2291. z = Float:getproperty(0, "YSIReq3");
  2292. deleteproperty(0, "YSIReq2");
  2293. deleteproperty(0, "YSIReq3");
  2294. }
  2295. #endif
  2296. return 1;
  2297. }
  2298. /*----------------------------------------------------------------------------*-
  2299. Function:
  2300. Object_HasPlayer
  2301. Params:
  2302. objectid - Object to check.
  2303. playerid - Player to check.
  2304. worldid - World to check.
  2305. Return:
  2306. Whether the object is visible to that player in that world.
  2307. Notes:
  2308. This is a variable function. Depending on the compile time settings it may
  2309. or may not use all the parameters (it may use none).
  2310. -*----------------------------------------------------------------------------*/
  2311. #if !defined NO_PERSONAL_OBJECTS
  2312. #if OBJECT_WORLDS > 0
  2313. #define Object_HasPlayer(%1,%2,%3) \
  2314. (Bit_Get(YSI_g_sObjects[(%1)][E_OBJECT_WORLDS], (%3)) && Bit_Get(YSI_g_sObjects[(%1)][E_OBJECT_PLAYERS], (%2)))
  2315. #else
  2316. #define Object_HasPlayer(%1,%2,%3) \
  2317. (Bit_Get(YSI_g_sObjects[(%1)][E_OBJECT_PLAYERS], (%2)))
  2318. #endif
  2319. #else
  2320. #if OBJECT_WORLDS > 0
  2321. #define Object_HasPlayer(%1,%2,%3) \
  2322. (Bit_Get(YSI_g_sObjects[(%1)][E_OBJECT_WORLDS], (%3)))
  2323. #else
  2324. #define Object_HasPlayer(%1,%2,%3) \
  2325. (TRUE)
  2326. #endif
  2327. #endif
  2328. /*----------------------------------------------------------------------------*-
  2329. Function:
  2330. IsValidDynamicObject
  2331. Params:
  2332. objectid - Object to check.
  2333. Return:
  2334. Object_IsValid.
  2335. Notes:
  2336. -
  2337. -*----------------------------------------------------------------------------*/
  2338. stock IsValidDynamicObject(objectid)
  2339. {
  2340. #if defined _YSI_SETUP_MASTER
  2341. if (YSI_g_sIsMaster)
  2342. {
  2343. #endif
  2344. return Object_IsValid(objectid);
  2345. #if defined _YSI_SETUP_MASTER
  2346. }
  2347. else
  2348. {
  2349. CallRemoteFunction("Object_Remote", "iii", objectid, 0, E_OBJECT_REMOTE_ISVALID);
  2350. return getproperty(0, "YSIReq");
  2351. }
  2352. #endif
  2353. }
  2354. /*----------------------------------------------------------------------------*-
  2355. Function:
  2356. AttachDynamicObjectToPlayer
  2357. Params:
  2358. objectid - Object to attach.
  2359. playerid - Player to attach to.
  2360. Float:X - X offset.
  2361. Float:Y - Y offset.
  2362. Float:Z - Z offset.
  2363. Float:RX - X rotation.
  2364. Float:RY - Y rotation.
  2365. Float:RZ - Z rotation.
  2366. Float:S - Speed.
  2367. Return:
  2368. -
  2369. Notes:
  2370. Updated for children.
  2371. -*----------------------------------------------------------------------------*/
  2372. stock AttachDynamicObjectToPlayer(objectid, playerid, Float:X, Float:Y, Float:Z, Float:RX, Float:RY, Float:RZ)
  2373. {
  2374. #if !defined NO_OBJECTS_MOVE
  2375. #if defined _YSI_SETUP_MASTER
  2376. if (YSI_g_sIsMaster)
  2377. {
  2378. #endif
  2379. if (Object_IsValid(objectid) && Object_IsAttached(YSI_g_sObjects[objectid][E_OBJECT_MODEL]))
  2380. {
  2381. return Object_AttachToPlayer(objectid, playerid, X, Y, Z, RX, RY, RZ);
  2382. }
  2383. #if defined _YSI_SETUP_MASTER
  2384. }
  2385. else
  2386. {
  2387. CallRemoteFunction("Object_AttachRemote", "iiffffff", objectid, playerid, X, Y, Z, RX, RY, RZ);
  2388. return getproperty(0, "YSIReq");
  2389. }
  2390. #endif
  2391. #else
  2392. #pragma unused objectid, X, Y, Z, S
  2393. #endif
  2394. return 0;
  2395. }
  2396. #if !defined NO_OBJECTS_MOVE
  2397. #if defined _YSI_SETUP_MASTER
  2398. /*----------------------------------------------------------------------------*-
  2399. Function:
  2400. Object_AttachRemote
  2401. Params:
  2402. objectid - Object to attach.
  2403. playerid - Player to attach to.
  2404. Float:X - X offset.
  2405. Float:Y - Y offset.
  2406. Float:Z - Z offset.
  2407. Float:RX - X rotation.
  2408. Float:RY - Y rotation.
  2409. Float:RZ - Z rotation.
  2410. Float:S - Speed.
  2411. Return:
  2412. -
  2413. Notes:
  2414. Remote call for AttachDynamicObjectToPlayer.
  2415. -*----------------------------------------------------------------------------*/
  2416. public Object_AttachRemote(objectid, playerid, Float:X, Float:Y, Float:Z, Float:RX, Float:RY, Float:RZ)
  2417. {
  2418. if (!YSI_g_sIsMaster) return 0;
  2419. setproperty(0, "YSIReq", 0);
  2420. if (Object_IsValid(objectid) && Object_IsAttached(YSI_g_sObjects[objectid][E_OBJECT_MODEL]))
  2421. {
  2422. setproperty(0, "YSIReq", Object_AttachToPlayer(objectid, playerid, X, Y, Z, RX, RY, RZ));
  2423. return 1;
  2424. }
  2425. return 0;
  2426. }
  2427. #endif
  2428. /*----------------------------------------------------------------------------*-
  2429. Function:
  2430. Object_AttachToPlayer
  2431. Params:
  2432. objectid - Object to attach.
  2433. playerid - Player to attach to.
  2434. Float:X - X offset.
  2435. Float:Y - Y offset.
  2436. Float:Z - Z offset.
  2437. Float:RX - X rotation.
  2438. Float:RY - Y rotation.
  2439. Float:RZ - Z rotation.
  2440. Float:S - Speed.
  2441. Return:
  2442. -
  2443. Notes:
  2444. Recursive call for AttachDynamicObjectToPlayer.
  2445. -*----------------------------------------------------------------------------*/
  2446. static stock Object_AttachToPlayer(objectid, playerid, Float:X, Float:Y, Float:Z, Float:RX, Float:RY, Float:RZ)
  2447. {
  2448. YSI_g_sObjects[objectid][E_OBJECT_MODEL] |= e_OBJ_FLAG_ATTACHED;
  2449. YSI_g_sObjects[objectid][E_OBJECT_X] = X;
  2450. YSI_g_sObjects[objectid][E_OBJECT_Y] = Y;
  2451. YSI_g_sObjects[objectid][E_OBJECT_Z] = Z;
  2452. YSI_g_sObjects[objectid][E_OBJECT_RX] = RX;
  2453. YSI_g_sObjects[objectid][E_OBJECT_RY] = RY;
  2454. YSI_g_sObjects[objectid][E_OBJECT_RZ] = RZ;
  2455. Object_RemoveFromSector(YSI_g_sObjects[objectid][E_OBJECT_SECTOR], objectid);
  2456. Object_AddToMovingList(objectid);
  2457. YSI_g_sObjects[objectid][E_OBJECT_MODEL] = (YSI_g_sObjects[objectid][E_OBJECT_MODEL] & ~e_OBJ_FLAG_ATTACH) | Object_SetAttach(playerid);
  2458. Object_AddToUpdate(objectid);
  2459. #if !defined NO_OBJECT_ATTACH
  2460. new
  2461. child = YSI_g_sObjects[objectid][E_OBJECT_CHILDREN];
  2462. while (child != NO_OBJECT)
  2463. {
  2464. Object_AttachToPlayer(child, playerid, X + YSI_g_sObjects[child][E_OBJECT_X], Y + YSI_g_sObjects[child][E_OBJECT_Y], Z + YSI_g_sObjects[child][E_OBJECT_Z], RX, RY, RZ);
  2465. child = YSI_g_sObjects[child][E_OBJECT_SIBLINGS];
  2466. }
  2467. #endif
  2468. return 1;
  2469. }
  2470. #endif
  2471. /*----------------------------------------------------------------------------*-
  2472. Function:
  2473. DetachDynamicObjectFromPlayer
  2474. Params:
  2475. objectid - Object to detach.
  2476. Return:
  2477. -
  2478. Notes:
  2479. Detaches an object from a player.
  2480. -*----------------------------------------------------------------------------*/
  2481. stock DetachDynamicObjectFromPlayer(objectid)
  2482. {
  2483. #if !defined NO_OBJECTS_MOVE
  2484. #if defined _YSI_SETUP_MASTER
  2485. if (YSI_g_sIsMaster)
  2486. {
  2487. #endif
  2488. if (!Object_IsValid(objectid)) return;
  2489. new
  2490. playerid = Object_GetAttach(YSI_g_sObjects[objectid][E_OBJECT_MODEL]);
  2491. if (playerid != NO_ATTACH_PLAYER)
  2492. {
  2493. Object_RemoveFromSector(OBJECT_NO_SECTOR, objectid);
  2494. new
  2495. Float:x,
  2496. Float:y,
  2497. Float:z;
  2498. GetPlayerPos(playerid, x, y, z);
  2499. new
  2500. Float:nx = YSI_g_sObjects[objectid][E_OBJECT_X],
  2501. Float:ny = YSI_g_sObjects[objectid][E_OBJECT_Y],
  2502. Float:nz = YSI_g_sObjects[objectid][E_OBJECT_Z];
  2503. Object_SetPos(objectid, x + nx, y + ny, z + nz);
  2504. #if !defined NO_OBJECT_ATTACH
  2505. Object_UpdateAttach(YSI_g_sObjects[objectid][E_OBJECT_CHILDREN], nx, ny, nz, x + nx, y + ny, z + nz, false);
  2506. #endif
  2507. YSI_g_sObjects[objectid][E_OBJECT_MODEL] |= e_OBJ_FLAG_ATTACHED | e_OBJ_FLAG_ATTACH | e_OBJ_FLAG_RECREATED;
  2508. Object_AddToUpdate(objectid);
  2509. }
  2510. return;
  2511. #if defined _YSI_SETUP_MASTER
  2512. }
  2513. else
  2514. {
  2515. CallRemoteFunction("Object_Remote", "iii", objectid, 0, E_OBJECT_REMOTE_DETATCH);
  2516. }
  2517. #endif
  2518. #else
  2519. #pragma unused objectid
  2520. #endif
  2521. }
  2522. /*----------------------------------------------------------------------------*-
  2523. Function:
  2524. Object_UpdateAttach
  2525. Params:
  2526. child - Start of children list to positionally update.
  2527. Float:x - x offset of parent.
  2528. Float:y - y offset of parent.
  2529. Float:z - z offset of parent.
  2530. Float:rx - Real x location.
  2531. Float:ry - Real y location.
  2532. Float:rz - Real z location.
  2533. moved - Wether the object was previously moving or attached.
  2534. Return:
  2535. -
  2536. Notes:
  2537. Restores the object sectors and offsets from parents based on positions
  2538. relative to other items (origin or a player).
  2539. -*----------------------------------------------------------------------------*/
  2540. #if !defined NO_OBJECT_ATTACH
  2541. static stock Object_UpdateAttach(child, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, moving = true)
  2542. {
  2543. while (child != NO_OBJECT)
  2544. {
  2545. new
  2546. Float:nx = YSI_g_sObjects[child][E_OBJECT_X],
  2547. Float:ny = YSI_g_sObjects[child][E_OBJECT_Y],
  2548. Float:nz = YSI_g_sObjects[child][E_OBJECT_Z],
  2549. Float:mx = nx - x,
  2550. Float:my = ny - y,
  2551. Float:mz = nz - z;
  2552. Object_UpdateAttach(YSI_g_sObjects[child][E_OBJECT_CHILDREN], nx, ny, nz, rx + mx, ry + my, rz + mz);
  2553. YSI_g_sObjects[child][E_OBJECT_X] = mx;
  2554. YSI_g_sObjects[child][E_OBJECT_Y] = my;
  2555. YSI_g_sObjects[child][E_OBJECT_Z] = mz;
  2556. Object_RemoveFromSector(OBJECT_NO_SECTOR, child);
  2557. Object_AddToSector(Object_FindSector(rx + mx, ry + my, rz + mz), child, YSI_g_sObjects[child][E_OBJECT_VIEW]);
  2558. child = YSI_g_sObjects[child][E_OBJECT_SIBLINGS];
  2559. if (moving)
  2560. {
  2561. YSI_g_sObjects[child][E_OBJECT_MODEL] = (YSI_g_sObjects[child][E_OBJECT_MODEL] & ~(e_OBJ_FLAG_MOVED)) | e_OBJ_FLAG_RECREATED;
  2562. }
  2563. else
  2564. {
  2565. YSI_g_sObjects[child][E_OBJECT_MODEL] |= e_OBJ_FLAG_ATTACHED | e_OBJ_FLAG_ATTACH | e_OBJ_FLAG_RECREATED;
  2566. }
  2567. }
  2568. }
  2569. #endif
  2570. /*----------------------------------------------------------------------------*-
  2571. Function:
  2572. MoveDynamicObject
  2573. Params:
  2574. objectid - Object to move.
  2575. Float:X - X position of target.
  2576. Float:Y - Y position of target.
  2577. Float:Z - Z position of target.
  2578. Float:S - Speed.
  2579. Return:
  2580. -
  2581. Notes:
  2582. -
  2583. -*----------------------------------------------------------------------------*/
  2584. stock MoveDynamicObject(objectid, Float:X, Float:Y, Float:Z, Float:S)
  2585. {
  2586. #if !defined NO_OBJECTS_MOVE
  2587. #if defined _YSI_SETUP_MASTER
  2588. if (YSI_g_sIsMaster)
  2589. {
  2590. #endif
  2591. if (Object_IsValid(objectid))
  2592. {
  2593. Object_Move(objectid, X, Y, Z, S);
  2594. Object_AddToUpdate(objectid);
  2595. return 1;
  2596. }
  2597. #if defined _YSI_SETUP_MASTER
  2598. }
  2599. else
  2600. {
  2601. CallRemoteFunction("Object_CoOrdRemote", "iiffff", objectid, E_OBJECT_REMOTE_MOVETO, X, Y, Z, S);
  2602. return getproperty(0, "YSIReq");
  2603. }
  2604. #endif
  2605. #else
  2606. #pragma unused objectid, X, Y, Z, S
  2607. #endif
  2608. return 0;
  2609. }
  2610. #if !defined NO_OBJECTS_MOVE
  2611. /*----------------------------------------------------------------------------*-
  2612. Function:
  2613. Object_Move
  2614. Params:
  2615. objectid - Object to move.
  2616. Float:X - X position of target.
  2617. Float:Y - Y position of target.
  2618. Float:Z - Z position of target.
  2619. Float:S - Speed.
  2620. Return:
  2621. -
  2622. Notes:
  2623. Recursive function for MoveDynamicObject to move children.
  2624. -*----------------------------------------------------------------------------*/
  2625. static stock Object_Move(objectid, Float:X, Float:Y, Float:Z, Float:S)
  2626. {
  2627. if (xor:(YSI_g_sObjects[objectid][E_OBJECT_MODEL] & e_OBJ_FLAG_MOVED1) == xor:(YSI_g_sObjects[objectid][E_OBJECT_MODEL] & e_OBJ_FLAG_MOVED2))
  2628. {
  2629. YSI_g_sObjects[objectid][E_OBJECT_MODEL] ^= e_OBJ_FLAG_MOVED;
  2630. }
  2631. else
  2632. {
  2633. YSI_g_sObjects[objectid][E_OBJECT_MODEL] = (YSI_g_sObjects[objectid][E_OBJECT_MODEL] & ~e_OBJ_FLAG_MOVED) | e_OBJ_FLAG_MOVED1;
  2634. }
  2635. YSI_g_sObjects[objectid][E_OBJECT_MX] = X;
  2636. YSI_g_sObjects[objectid][E_OBJECT_MY] = Y;
  2637. YSI_g_sObjects[objectid][E_OBJECT_MZ] = Z;
  2638. YSI_g_sObjects[objectid][E_OBJECT_MS] = S;
  2639. Object_RemoveFromSector(YSI_g_sObjects[objectid][E_OBJECT_SECTOR], objectid);
  2640. Object_AddToMovingList(objectid);
  2641. #if !defined NO_OBJECT_ATTACH
  2642. new
  2643. child = YSI_g_sObjects[objectid][E_OBJECT_CHILDREN];
  2644. while (child != NO_OBJECT)
  2645. {
  2646. Object_Move(child, X + YSI_g_sObjects[child][E_OBJECT_X], Y + YSI_g_sObjects[child][E_OBJECT_Y], Z + YSI_g_sObjects[child][E_OBJECT_Z], S);
  2647. child = YSI_g_sObjects[child][E_OBJECT_SIBLINGS];
  2648. }
  2649. #endif
  2650. }
  2651. #endif
  2652. /*----------------------------------------------------------------------------*-
  2653. Function:
  2654. AttachObjectToObject
  2655. Params:
  2656. attachobject - Object to attach.
  2657. toobject - Object to attach to.
  2658. Return:
  2659. -
  2660. Notes:
  2661. Variables named to hopefully avoid confusion. Now checks the parent is not
  2662. a descendent of the child to avoid infinate loops.
  2663. -*----------------------------------------------------------------------------*/
  2664. stock AttachObjectToObject(attachobject, toobject)
  2665. {
  2666. #if !defined NO_OBJECT_ATTACH
  2667. #if defined _YSI_SETUP_MASTER
  2668. if (YSI_g_sIsMaster)
  2669. {
  2670. #endif
  2671. if (Object_IsValid(attachobject) && Object_IsValid(toobject))
  2672. {
  2673. if (Object_CheckDescendant(toobject, attachobject)) return 0;
  2674. new
  2675. Float:px,
  2676. Float:py,
  2677. Float:pz,
  2678. Float:cx,
  2679. Float:cy,
  2680. Float:cz;
  2681. Object_GetPos(toobject, px, py, pz);
  2682. Object_GetPos(attachobject, cx, cy, cz);
  2683. new
  2684. parent = YSI_g_sObjects[attachobject][E_OBJECT_PARENT];
  2685. if (parent != NO_OBJECT) Object_RemoveFromParent(attachobject, parent);
  2686. Object_AddToParent(attachobject, toobject);
  2687. YSI_g_sObjects[attachobject][E_OBJECT_X] = cx - px;
  2688. YSI_g_sObjects[attachobject][E_OBJECT_Y] = cy - py;
  2689. YSI_g_sObjects[attachobject][E_OBJECT_Z] = cz - pz;
  2690. return 1;
  2691. }
  2692. #if defined _YSI_SETUP_MASTER
  2693. }
  2694. else
  2695. {
  2696. CallRemoteFunction("Object_Remote", "iii", attachobject, toobject, E_OBJECT_REMOTE_ATTACHOO);
  2697. return getproperty(0, "YSIReq");
  2698. }
  2699. #endif
  2700. #else
  2701. #pragma unused attachobject, toobject
  2702. #endif
  2703. return 0;
  2704. }
  2705. /*----------------------------------------------------------------------------*-
  2706. Function:
  2707. Object_IsDesendant
  2708. Params:
  2709. objectid - Object to check.
  2710. ancestor - Object to check family tree of for objectid.
  2711. Return:
  2712. -
  2713. Notes:
  2714. Checks if objectid is a descendant of the ancestor object.
  2715. -*----------------------------------------------------------------------------*/
  2716. stock Object_IsDescendant(objectid, ancestor)
  2717. {
  2718. #if !defined NO_OBJECT_ATTACH
  2719. #if defined _YSI_SETUP_MASTER
  2720. if (YSI_g_sIsMaster)
  2721. {
  2722. #endif
  2723. if (Object_IsValid(objectid) && Object_IsValid(ancestor))
  2724. {
  2725. return Object_CheckDescendant(objectid, ancestor);
  2726. }
  2727. #if defined _YSI_SETUP_MASTER
  2728. }
  2729. else
  2730. {
  2731. CallRemoteFunction("Object_Remote", "iii", objectid, ancestor, E_OBJECT_REMOTE_CHECKDESC);
  2732. return getproperty(0, "YSIReq");
  2733. }
  2734. #endif
  2735. #else
  2736. #pragma unused objectid, ancestor
  2737. #endif
  2738. return 0;
  2739. }
  2740. /*----------------------------------------------------------------------------*-
  2741. Function:
  2742. Object_CheckDesendant
  2743. Params:
  2744. objectid - Object to check.
  2745. ancestor - Object to check family tree of for objectid.
  2746. Return:
  2747. -
  2748. Notes:
  2749. Recursive call for Object_IsDescendant.
  2750. -*----------------------------------------------------------------------------*/
  2751. static stock Object_CheckDescendant(objectid, ancestor)
  2752. {
  2753. if (objectid == ancestor) return 1;
  2754. new
  2755. child = YSI_g_sObjects[ancestor][E_OBJECT_CHILDREN];
  2756. while (child != NO_OBJECT)
  2757. {
  2758. if (Object_CheckDescendant(objectid, child)) return 1;
  2759. child = YSI_g_sObjects[child][E_OBJECT_SIBLINGS];
  2760. }
  2761. return 0;
  2762. }
  2763. /*----------------------------------------------------------------------------*-
  2764. Function:
  2765. RemoveObjectFromParent
  2766. Params:
  2767. objectid - Object to remove from it's parent.
  2768. Return:
  2769. -
  2770. Notes:
  2771. -
  2772. -*----------------------------------------------------------------------------*/
  2773. stock RemoveObjectFromParent(objectid)
  2774. {
  2775. #if !defined NO_OBJECT_ATTACH
  2776. #if defined _YSI_SETUP_MASTER
  2777. if (YSI_g_sIsMaster)
  2778. {
  2779. #endif
  2780. if (Object_IsValid(objectid))
  2781. {
  2782. new
  2783. parent = YSI_g_sObjects[objectid][E_OBJECT_PARENT];
  2784. if (parent != NO_OBJECT)
  2785. {
  2786. new
  2787. Float:x,
  2788. Float:y,
  2789. Float:z;
  2790. Object_GetPos(objectid, x, y, z);
  2791. Object_RemoveFromParent(objectid, parent);
  2792. YSI_g_sObjects[objectid][E_OBJECT_X] = x;
  2793. YSI_g_sObjects[objectid][E_OBJECT_Y] = y;
  2794. YSI_g_sObjects[objectid][E_OBJECT_Z] = z;
  2795. }
  2796. }
  2797. #if defined _YSI_SETUP_MASTER
  2798. }
  2799. else
  2800. {
  2801. CallRemoteFunction("Object_Remote", "iii", objectid, 0, E_OBJECT_REMOTE_REMOO);
  2802. }
  2803. #endif
  2804. #else
  2805. #pragma unused objectid
  2806. #endif
  2807. }
  2808. #if !defined NO_OBJECT_ATTACH
  2809. /*----------------------------------------------------------------------------*-
  2810. Function:
  2811. Object_RemoveFromParent
  2812. Params:
  2813. objectid - Object to remove from an object.
  2814. parent - Object to remove from.
  2815. Return:
  2816. -
  2817. Notes:
  2818. Removes an object from another object's children list. Has parent passed
  2819. as existance is checked in calling function so is already retrieved.
  2820. -*----------------------------------------------------------------------------*/
  2821. static stock Object_RemoveFromParent(objectid, parent)
  2822. {
  2823. new
  2824. children = YSI_g_sObjects[parent][E_OBJECT_CHILDREN],
  2825. next;
  2826. if (children == objectid)
  2827. {
  2828. YSI_g_sObjects[parent][E_OBJECT_CHILDREN] = YSI_g_sObjects[objectid][E_OBJECT_SIBLINGS];
  2829. }
  2830. else
  2831. {
  2832. while ((next = YSI_g_sObjects[children][E_OBJECT_SIBLINGS]) != objectid) children = next;
  2833. YSI_g_sObjects[children][E_OBJECT_SIBLINGS] = YSI_g_sObjects[objectid][E_OBJECT_SIBLINGS];
  2834. }
  2835. YSI_g_sObjects[objectid][E_OBJECT_PARENT] = NO_OBJECT;
  2836. YSI_g_sObjects[objectid][E_OBJECT_SIBLINGS] = NO_OBJECT;
  2837. }
  2838. /*----------------------------------------------------------------------------*-
  2839. Function:
  2840. Object_AddToParent
  2841. Params:
  2842. objectid - Object to attach.
  2843. parentid - Object to attach to.
  2844. Return:
  2845. -
  2846. Notes:
  2847. Adds an object to another objects child list.
  2848. -*----------------------------------------------------------------------------*/
  2849. static stock Object_AddToParent(objectid, parentid)
  2850. {
  2851. if (YSI_g_sObjects[objectid][E_OBJECT_PARENT] == NO_OBJECT)
  2852. {
  2853. YSI_g_sObjects[objectid][E_OBJECT_SIBLINGS] = YSI_g_sObjects[parentid][E_OBJECT_CHILDREN];
  2854. YSI_g_sObjects[objectid][E_OBJECT_PARENT] = parentid;
  2855. YSI_g_sObjects[parentid][E_OBJECT_CHILDREN] = objectid;
  2856. }
  2857. }
  2858. #endif
  2859. /*----------------------------------------------------------------------------*-
  2860. Function:
  2861. StopDynamicObject
  2862. Params:
  2863. objectid - Object to stop.
  2864. Return:
  2865. -
  2866. Notes:
  2867. Stops an object and reassigns it's sector.
  2868. -*----------------------------------------------------------------------------*/
  2869. stock StopDynamicObject(objectid)
  2870. {
  2871. #if defined _YSI_SETUP_MASTER
  2872. if (YSI_g_sIsMaster)
  2873. {
  2874. #endif
  2875. if (Object_IsValid(objectid))
  2876. {
  2877. Object_RemoveFromSector(OBJECT_NO_SECTOR, objectid);
  2878. new
  2879. Float:x,
  2880. Float:y,
  2881. Float:z;
  2882. Object_GetPos(objectid, x, y, z);
  2883. Object_AddToSector(Object_FindSector(x, y, z), objectid, YSI_g_sObjects[objectid][E_OBJECT_VIEW]);
  2884. YSI_g_sObjects[objectid][E_OBJECT_MODEL] = (YSI_g_sObjects[objectid][E_OBJECT_MODEL] & ~(e_OBJ_FLAG_MOVED)) | e_OBJ_FLAG_RECREATED;
  2885. Object_AddToUpdate(objectid);
  2886. #if !defined NO_OBJECT_ATTACH
  2887. Object_UpdateAttach(YSI_g_sObjects[objectid][E_OBJECT_CHILDREN], x, y, z, x, y, z);
  2888. #endif
  2889. }
  2890. #if defined _YSI_SETUP_MASTER
  2891. }
  2892. else
  2893. {
  2894. CallRemoteFunction("Object_Remote", "iii", objectid, 0, E_OBJECT_REMOTE_STOP);
  2895. }
  2896. #endif
  2897. }
  2898. #if !defined NO_OBJECTS_MOVE
  2899. /*----------------------------------------------------------------------------*-
  2900. Function:
  2901. Object_Update
  2902. Params:
  2903. objectid - Object to process.
  2904. Float:elapsedTime - Time since last update in seconds.
  2905. Return:
  2906. -
  2907. Notes:
  2908. Updates a moving object's position in our internal memory based on speed
  2909. and time (d = s * t)
  2910. -*----------------------------------------------------------------------------*/
  2911. static Object_Update(objectid, Float:elapsedTime)
  2912. {
  2913. new
  2914. Float:x = YSI_g_sObjects[objectid][E_OBJECT_X],
  2915. Float:y = YSI_g_sObjects[objectid][E_OBJECT_Y],
  2916. Float:z = YSI_g_sObjects[objectid][E_OBJECT_Z],
  2917. Float:mx = YSI_g_sObjects[objectid][E_OBJECT_MX],
  2918. Float:my = YSI_g_sObjects[objectid][E_OBJECT_MY],
  2919. Float:mz = YSI_g_sObjects[objectid][E_OBJECT_MZ],
  2920. Float:distance = elapsedTime * YSI_g_sObjects[objectid][E_OBJECT_MS];
  2921. x -= mx;
  2922. y -= my;
  2923. z -= mz;
  2924. new
  2925. Float:remaining = floatsqroot((x * x) + (y * y) + (z * z));
  2926. if (distance >= remaining)
  2927. {
  2928. YSI_g_sObjects[objectid][E_OBJECT_X] = mx;
  2929. YSI_g_sObjects[objectid][E_OBJECT_Y] = my;
  2930. YSI_g_sObjects[objectid][E_OBJECT_Z] = mz;
  2931. new
  2932. e_OBJ_FLAG:oldmove = YSI_g_sObjects[objectid][E_OBJECT_MODEL] & e_OBJ_FLAG_MOVED;
  2933. if (!Object_GateMoved(objectid)) CallRemoteFunction("OnDynamicObjectMoved", "i", objectid);
  2934. if (oldmove == YSI_g_sObjects[objectid][E_OBJECT_MODEL] & e_OBJ_FLAG_MOVED)
  2935. {
  2936. StopDynamicObject(objectid);
  2937. }
  2938. return 1;
  2939. }
  2940. else
  2941. {
  2942. remaining /= distance;
  2943. YSI_g_sObjects[objectid][E_OBJECT_X] += (0.0 - x) / remaining;
  2944. YSI_g_sObjects[objectid][E_OBJECT_Y] += (0.0 - y) / remaining;
  2945. YSI_g_sObjects[objectid][E_OBJECT_Z] += (0.0 - z) / remaining;
  2946. }
  2947. return 0;
  2948. }
  2949. #endif
  2950. /*----------------------------------------------------------------------------*-
  2951. Function:
  2952. Object_Loop
  2953. Params:
  2954. -
  2955. Return:
  2956. -
  2957. Notes:
  2958. Checks what objects are in the player's range repeatedly to stream them
  2959. as required. Only checks objects near the player, based on sectors, and
  2960. moving objects which are handled as their own 'sector'. If the player is
  2961. near the edge of the grid (+/-OBJECT_BOUNDS x/y) OOB objects are also checked, only
  2962. one sector is used for all those regardless of location. Moving objects
  2963. and already visible objects are assumed higher priority.
  2964. Now orders objects so only the closest are displayed.
  2965. Fixed moving objects.
  2966. -*----------------------------------------------------------------------------*/
  2967. public Object_Loop()
  2968. {
  2969. #if defined _YSI_SETUP_MASTER
  2970. if (!YSI_g_sIsMaster) return;
  2971. #endif
  2972. #if !defined NO_OBJECTS_MOVE
  2973. static
  2974. Float:s_fTime;
  2975. new
  2976. Float:tick = float(GetTickCount()) / 1000.0;
  2977. if (YSI_g_sMovingObjects != NO_OBJECT)
  2978. {
  2979. new
  2980. Float:fTime = tick - s_fTime,
  2981. objectid = YSI_g_sMovingObjects;
  2982. do
  2983. {
  2984. new
  2985. next = YSI_g_sObjects[objectid][E_OBJECT_NEXT];
  2986. if (YSI_g_sObjects[objectid][E_OBJECT_MODEL] & e_OBJ_FLAG_MOVED) Object_Update(objectid, fTime);
  2987. if (objectid == next) break;
  2988. objectid = next;
  2989. }
  2990. while (objectid != NO_OBJECT);
  2991. }
  2992. s_fTime = tick;
  2993. #endif
  2994. foreach (Player, playerid)
  2995. {
  2996. static
  2997. sectors[MAX_PLAYERS][OBJECT_VIEW_SECTORS][E_OSEC_ITTER],
  2998. secStart[MAX_PLAYERS] = {-1, ...},
  2999. Bit:objects[OBJECT_BITS],
  3000. sObjList[MAY_OBJECTS][E_OBJECT_ITTER];
  3001. new
  3002. Float:x,
  3003. Float:y,
  3004. Float:z,
  3005. world = GetPlayerVirtualWorld(playerid),
  3006. i,
  3007. j,
  3008. objStart = -1,
  3009. objEnd = -1,
  3010. objCount;
  3011. GetPlayerPos(playerid, x, y, z);
  3012. if (z < 800.0)
  3013. {
  3014. Object_FindSectors(playerid, x, y, sectors[playerid], secStart[playerid]);
  3015. i = secStart[playerid];
  3016. while (i != -1)
  3017. {
  3018. if (objCount >= MAY_OBJECTS && sectors[playerid][i][E_OSEC_ITTER_DIFF] >= sObjList[objEnd][E_OBJECT_ITTER_DISTANCE]) break;
  3019. else
  3020. {
  3021. if ((j = sectors[playerid][i][E_OSEC_ITTER_SECTOR]) == OBJECT_NO_SECTOR) Object_ParseSet(playerid, YSI_g_sOtherSector, x, y, z, world, sObjList, objStart, objEnd, objCount, false);
  3022. else Object_ParseSet(playerid, YSI_g_sObjectSectors[j][E_OBJ_SECTOR_POINTER], x, y, z, world, sObjList, objStart, objEnd, objCount, false);
  3023. }
  3024. i = sectors[playerid][i][E_OSEC_ITTER_NEXT];
  3025. }
  3026. }
  3027. else Object_ParseSet(playerid, YSI_g_sInteriorObjects, x, y, z, world, sObjList, objStart, objEnd, objCount, false);
  3028. #if !defined NO_OBJECTS_MOVE
  3029. Object_ParseSet(playerid, YSI_g_sMovingObjects, x, y, z, world, sObjList, objStart, objEnd, objCount, true);
  3030. #endif
  3031. Object_ParseSet(playerid, YSI_g_sLODObjects, x, y, z, world, sObjList, objStart, objEnd, objCount, false);
  3032. for (j = objStart; j != -1; j = sObjList[j][E_OBJECT_ITTER_NEXT])
  3033. {
  3034. Bit_Let(objects, sObjList[j][E_OBJECT_ITTER_OBJ]);
  3035. }
  3036. new
  3037. object;
  3038. for (i = 0; i < MAY_OBJECTS; i++)
  3039. {
  3040. new
  3041. objectid = i + 1;
  3042. if ((object = YSI_g_sPlayerObjects[playerid][i] & 0xFFFFFF) != (NO_OBJECT & 0xFFFFFF) && IsValidPlayerObject(playerid, objectid))
  3043. {
  3044. if (YSI_g_sSomethingMoved != NO_OBJECT)
  3045. {
  3046. new
  3047. e_OBJ_FLAG:flag = YSI_g_sObjects[object][E_OBJECT_MODEL];
  3048. if (Bit_Get(objects, object) && !(flag & e_OBJ_FLAG_RECREATED))
  3049. {
  3050. #if !defined NO_OBJECTS_MOVE
  3051. if (flag & e_OBJ_FLAG_ATTACHED)
  3052. {
  3053. AttachPlayerObjectToPlayer(playerid, objectid, Object_GetAttach(object), YSI_g_sObjects[object][E_OBJECT_X], YSI_g_sObjects[object][E_OBJECT_Y], YSI_g_sObjects[object][E_OBJECT_Z], YSI_g_sObjects[object][E_OBJECT_RX], YSI_g_sObjects[object][E_OBJECT_RY], YSI_g_sObjects[object][E_OBJECT_RZ]);
  3054. }
  3055. if (flag & e_OBJ_FLAG_MOVED != e_OBJ_FLAG:YSI_g_sPlayerObjects[playerid][i] & e_OBJ_FLAG_MOVED)
  3056. {
  3057. YSI_g_sPlayerObjects[playerid][i] = (YSI_g_sPlayerObjects[playerid][i] & 0xFFFFFF) | _:(flag & e_OBJ_FLAG_MOVED);
  3058. MovePlayerObject(playerid, objectid, YSI_g_sObjects[object][E_OBJECT_MX], YSI_g_sObjects[object][E_OBJECT_MY], YSI_g_sObjects[object][E_OBJECT_MZ], YSI_g_sObjects[object][E_OBJECT_MS]);
  3059. flag |= e_OBJ_FLAG_JUMPED;
  3060. }
  3061. #endif
  3062. if (flag & e_OBJ_FLAG_JUMPED)
  3063. {
  3064. Object_GetPos(object, x, y, z);
  3065. SetPlayerObjectPos(playerid, objectid, x, y, z);
  3066. }
  3067. if (flag & e_OBJ_FLAG_ROTATED)
  3068. {
  3069. SetPlayerObjectRot(playerid, objectid, YSI_g_sObjects[object][E_OBJECT_RX], YSI_g_sObjects[object][E_OBJECT_RY], YSI_g_sObjects[object][E_OBJECT_RZ]);
  3070. }
  3071. Bit_Set(objects, object, 0, OBJECT_BITS);
  3072. }
  3073. else
  3074. {
  3075. DestroyPlayerObject(playerid, objectid);
  3076. YSI_g_sPlayerObjects[playerid][i] = NO_OBJECT;
  3077. }
  3078. }
  3079. else
  3080. {
  3081. if (Bit_Get(objects, object))
  3082. {
  3083. Bit_Set(objects, object, 0, OBJECT_BITS);
  3084. }
  3085. else
  3086. {
  3087. DestroyPlayerObject(playerid, objectid);
  3088. YSI_g_sPlayerObjects[playerid][i] = NO_OBJECT;
  3089. }
  3090. }
  3091. }
  3092. }
  3093. for (i = objStart; i != -1; i = sObjList[i][E_OBJECT_ITTER_NEXT])
  3094. {
  3095. new
  3096. objSet = sObjList[i][E_OBJECT_ITTER_OBJ],
  3097. e_OBJ_FLAG:flag = YSI_g_sObjects[objSet][E_OBJECT_MODEL];
  3098. if (Bit_Get(objects, objSet))
  3099. {
  3100. new
  3101. obj = CreatePlayerObject(playerid, flag & e_OBJ_FLAG_MODEL, sObjList[i][E_OBJECT_ITTER_X], sObjList[i][E_OBJECT_ITTER_Y], sObjList[i][E_OBJECT_ITTER_Z], YSI_g_sObjects[objSet][E_OBJECT_RX], YSI_g_sObjects[objSet][E_OBJECT_RY], YSI_g_sObjects[objSet][E_OBJECT_RZ]);
  3102. if (obj != 0xFF)
  3103. {
  3104. YSI_g_sPlayerObjects[playerid][obj - 1] = objSet;
  3105. Bit_Set(objects, objSet, 0, OBJECT_BITS);
  3106. #if !defined NO_OBJECTS_MOVE
  3107. if (flag & e_OBJ_FLAG_MOVED)
  3108. {
  3109. MovePlayerObject(playerid, obj, YSI_g_sObjects[objSet][E_OBJECT_MX], YSI_g_sObjects[objSet][E_OBJECT_MY], YSI_g_sObjects[objSet][E_OBJECT_MZ], YSI_g_sObjects[objSet][E_OBJECT_MS]);
  3110. YSI_g_sPlayerObjects[playerid][obj - 1] |= _:(flag & e_OBJ_FLAG_MOVED);
  3111. }
  3112. if (flag & e_OBJ_FLAG_ATTACHED)
  3113. {
  3114. AttachPlayerObjectToPlayer(playerid, obj, Object_GetAttach(objSet), YSI_g_sObjects[objSet][E_OBJECT_X], YSI_g_sObjects[objSet][E_OBJECT_Y], YSI_g_sObjects[objSet][E_OBJECT_Z], YSI_g_sObjects[objSet][E_OBJECT_RX], YSI_g_sObjects[objSet][E_OBJECT_RY], YSI_g_sObjects[objSet][E_OBJECT_RZ]);
  3115. }
  3116. #endif
  3117. }
  3118. }
  3119. }
  3120. }
  3121. if (YSI_g_sSomethingMoved != NO_OBJECT)
  3122. {
  3123. for (new objectid = YSI_g_sSomethingMoved; objectid != NO_OBJECT; objectid = YSI_g_sObjects[objectid][E_OBJECT_UPDATES])
  3124. {
  3125. YSI_g_sObjects[objectid][E_OBJECT_MODEL] &= ~(e_OBJ_FLAG_ATTACHED | e_OBJ_FLAG_JUMPED | e_OBJ_FLAG_ROTATED | e_OBJ_FLAG_RECREATED);
  3126. YSI_g_sObjects[objectid][E_OBJECT_UPDATES] = NO_OBJECT;
  3127. }
  3128. YSI_g_sSomethingMoved = NO_OBJECT;
  3129. }
  3130. }
  3131. /*----------------------------------------------------------------------------*-
  3132. Function:
  3133. Object_ParseSet
  3134. Params:
  3135. playerid - Player to check for.
  3136. objSet - Pointer to first object in the list.
  3137. Float:x - Player's x position.
  3138. Float:y - Player's y position.
  3139. Float:z - Player's z position.
  3140. world - Player's world.
  3141. objList[][E_OBJECT_ITTER] - List of closest objects.
  3142. &objStart - Entrypoint to list.
  3143. &objEnd - Last object in list.
  3144. &objCount - Number of objects in list.
  3145. bool:dynam - Is this the dynamic objSet.
  3146. Return:
  3147. -
  3148. Notes:
  3149. Itterates through the linked list for one sector of objects and checks
  3150. their real location relative to the player, if in range displays them.
  3151. -*----------------------------------------------------------------------------*/
  3152. static Object_ParseSet(playerid, objSet, Float:x, Float:y, Float:z, world, objList[][E_OBJECT_ITTER], &objStart, &objEnd, &objCount, bool:dynam)
  3153. {
  3154. if (objSet == NO_OBJECT) return;
  3155. new
  3156. #if !defined NO_OBJECTS_MOVE && defined NO_OBJECT_ATTACH
  3157. attach,
  3158. #endif
  3159. start = objSet,
  3160. Float:px,
  3161. Float:py,
  3162. Float:pz,
  3163. Float:diff;
  3164. do
  3165. {
  3166. new
  3167. e_OBJ_FLAG:flag = YSI_g_sObjects[objSet][E_OBJECT_MODEL];
  3168. if (flag & e_OBJ_FLAG_ACTIVE)
  3169. {
  3170. if (Object_HasPlayer(objSet, playerid, world))
  3171. {
  3172. #if !defined NO_OBJECT_ATTACH
  3173. Object_GetPos(objSet, px, py, pz);
  3174. #pragma unused dynam
  3175. #else
  3176. #if !defined NO_OBJECTS_MOVE
  3177. if (!dynam || (attach = Object_GetAttach(YSI_g_sObjects[objSet][E_OBJECT_MODEL])) == NO_ATTACH_PLAYER || !IsPlayerConnected(attach))
  3178. {
  3179. #endif
  3180. px = YSI_g_sObjects[objSet][E_OBJECT_X];
  3181. py = YSI_g_sObjects[objSet][E_OBJECT_Y];
  3182. pz = YSI_g_sObjects[objSet][E_OBJECT_Z];
  3183. #if !defined NO_OBJECTS_MOVE
  3184. }
  3185. else
  3186. {
  3187. GetPlayerPos(attach, px, py, pz);
  3188. px += YSI_g_sObjects[objSet][E_OBJECT_X];
  3189. py += YSI_g_sObjects[objSet][E_OBJECT_Y];
  3190. pz += YSI_g_sObjects[objSet][E_OBJECT_Z];
  3191. }
  3192. #else
  3193. #pragma unused dynam
  3194. #endif
  3195. #endif
  3196. new
  3197. Float:ox = px - x,
  3198. Float:oy = py - y,
  3199. Float:oz = pz - z;
  3200. diff = ((ox * ox) + (oy * oy) + (oz * oz)) / YSI_g_sObjects[objSet][E_OBJECT_VIEW];
  3201. if (diff < 1.0)
  3202. {
  3203. if (objStart == -1)
  3204. {
  3205. objList[0][E_OBJECT_ITTER_NEXT] = -1;
  3206. objList[0][E_OBJECT_ITTER_LAST] = -1;
  3207. objList[0][E_OBJECT_ITTER_OBJ] = objSet;
  3208. objList[0][E_OBJECT_ITTER_DISTANCE] = diff;
  3209. objList[0][E_OBJECT_ITTER_X] = px;
  3210. objList[0][E_OBJECT_ITTER_Y] = py;
  3211. objList[0][E_OBJECT_ITTER_Z] = pz;
  3212. objStart = 0;
  3213. objEnd = 0;
  3214. objCount = 1;
  3215. }
  3216. else if (objCount < MAY_OBJECTS)
  3217. {
  3218. objList[objCount][E_OBJECT_ITTER_OBJ] = objSet;
  3219. objList[objCount][E_OBJECT_ITTER_DISTANCE] = diff;
  3220. objList[objCount][E_OBJECT_ITTER_X] = px;
  3221. objList[objCount][E_OBJECT_ITTER_Y] = py;
  3222. objList[objCount][E_OBJECT_ITTER_Z] = pz;
  3223. if (objList[objEnd][E_OBJECT_ITTER_DISTANCE] < diff)
  3224. {
  3225. objList[objCount][E_OBJECT_ITTER_LAST] = objEnd;
  3226. objList[objCount][E_OBJECT_ITTER_NEXT] = -1;
  3227. objList[objEnd][E_OBJECT_ITTER_NEXT] = objCount;
  3228. objEnd = objCount++;
  3229. }
  3230. else
  3231. {
  3232. new
  3233. i = objStart,
  3234. j = -1;
  3235. while (objList[i][E_OBJECT_ITTER_DISTANCE] < diff) i = objList[(j = i)][E_OBJECT_ITTER_NEXT];
  3236. objList[objCount][E_OBJECT_ITTER_NEXT] = i;
  3237. objList[objCount][E_OBJECT_ITTER_LAST] = j;
  3238. objList[i][E_OBJECT_ITTER_LAST] = objCount;
  3239. if (j == -1) objStart = objCount++;
  3240. else objList[j][E_OBJECT_ITTER_NEXT] = objCount++;
  3241. }
  3242. }
  3243. else if (objList[objEnd][E_OBJECT_ITTER_DISTANCE] > diff)
  3244. {
  3245. new
  3246. i = objStart,
  3247. j = -1,
  3248. newend = objList[objEnd][E_OBJECT_ITTER_LAST];
  3249. while (objList[i][E_OBJECT_ITTER_DISTANCE] < diff) i = objList[(j = i)][E_OBJECT_ITTER_NEXT];
  3250. objList[objEnd][E_OBJECT_ITTER_OBJ] = objSet;
  3251. objList[objEnd][E_OBJECT_ITTER_DISTANCE] = diff;
  3252. objList[objEnd][E_OBJECT_ITTER_X] = px;
  3253. objList[objEnd][E_OBJECT_ITTER_Y] = py;
  3254. objList[objEnd][E_OBJECT_ITTER_Z] = pz;
  3255. if (i != objEnd)
  3256. {
  3257. objList[objEnd][E_OBJECT_ITTER_NEXT] = i;
  3258. objList[objEnd][E_OBJECT_ITTER_LAST] = j;
  3259. objList[i][E_OBJECT_ITTER_LAST] = objEnd;
  3260. if (j == -1) objStart = objEnd;
  3261. else objList[j][E_OBJECT_ITTER_NEXT] = objEnd;
  3262. objEnd = newend;
  3263. objList[newend][E_OBJECT_ITTER_NEXT] = -1;
  3264. }
  3265. }
  3266. }
  3267. }
  3268. }
  3269. objSet = YSI_g_sObjects[objSet][E_OBJECT_NEXT];
  3270. }
  3271. while (objSet != start);
  3272. }
  3273. /*----------------------------------------------------------------------------*-
  3274. Function:
  3275. Object_FindSectors
  3276. Params:
  3277. playerid - Player we're finding the sectors for.
  3278. Float:x - X location to check.
  3279. Float:y - Y location to check.
  3280. sectors[OBJECT_VIEW_SECTORS][E_OSEC_ITTER] - Array to store all visible sectors.
  3281. &secStart - Start point to itterator
  3282. Return:
  3283. -
  3284. Notes:
  3285. Finds all the sectors which encompas points within the sight range of the
  3286. player. Initial checks are done as a square so some returned sectors may
  3287. not have points within a circular range of the player.
  3288. The original version tested if the edges of each sector were visible and
  3289. if not excluded them from the list. This would have been faster in terms
  3290. of objects checked but slower if there were no objects, which is likely to
  3291. be more frequently the case. The code also didn't actually work but that's
  3292. a minor point as the theory was there. This is also alot neater.
  3293. Rewritten to not use Object_FindSector on a new area, just calculate the
  3294. area from known initial area.
  3295. Now also only returns the zones visible, not the zones theoretically
  3296. visible (still assumes square vision though which the code doesn't use).
  3297. -*----------------------------------------------------------------------------*/
  3298. static Object_FindSectors(playerid, Float:x, Float:y, sectors[][E_OSEC_ITTER], &secStart)
  3299. {
  3300. static
  3301. sLastCheck[MAX_PLAYERS],
  3302. sLX[MAX_PLAYERS] = {cellmin, ...},
  3303. sLY[MAX_PLAYERS] = {cellmax, ...};
  3304. new
  3305. xsector = floatround(((x - OBJECT_BOUNDS_MINX) / YSI_g_sXSectorSize), floatround_floor),
  3306. ysector = floatround(((y - OBJECT_BOUNDS_MINY) / YSI_g_sYSectorSize), floatround_floor);
  3307. if (!sLastCheck[playerid] || sLX[playerid] != xsector || sLY[playerid] != ysector)
  3308. {
  3309. secStart = -1;
  3310. new
  3311. go = 0,
  3312. Float:diff = 10.0,
  3313. xstart = -OBJECT_VIEW_RATIO,
  3314. xend = OBJECT_VIEW_RATIO,
  3315. ystart = -OBJECT_VIEW_RATIO,
  3316. yend = OBJECT_VIEW_RATIO,
  3317. k;
  3318. if (xsector < -OBJECT_VIEW_RATIO)
  3319. {
  3320. xstart = cellmax;
  3321. go = 1;
  3322. diff = 0.0;
  3323. }
  3324. else if (xsector < OBJECT_VIEW_RATIO)
  3325. {
  3326. xstart = 0 - xsector;
  3327. go = 1;
  3328. new
  3329. Float:nd = ((x - OBJECT_BOUNDS_MINX) * (x - OBJECT_BOUNDS_MINX)) / (OBJECT_MAX_VIEW_DISTANCE * OBJECT_MAX_VIEW_DISTANCE);
  3330. if (nd < diff) diff = nd;
  3331. }
  3332. if (ysector < -OBJECT_VIEW_RATIO)
  3333. {
  3334. ystart = cellmax;
  3335. go = 1;
  3336. diff = 0.0;
  3337. }
  3338. else if (ysector < OBJECT_VIEW_RATIO)
  3339. {
  3340. ystart = 0 - ysector;
  3341. go = 1;
  3342. new
  3343. Float:nd = ((y - OBJECT_BOUNDS_MINY) * (y - OBJECT_BOUNDS_MINY)) / (OBJECT_MAX_VIEW_DISTANCE * OBJECT_MAX_VIEW_DISTANCE);
  3344. if (nd < diff) diff = nd;
  3345. }
  3346. if (xsector >= OBJECT_SECTOR_X_EDGE + OBJECT_VIEW_RATIO)
  3347. {
  3348. xend = cellmin;
  3349. go = 1;
  3350. diff = 0.0;
  3351. }
  3352. else if (xsector >= OBJECT_SECTOR_X_EDGE - OBJECT_VIEW_RATIO)
  3353. {
  3354. xend = OBJECT_SECTOR_X_EDGE - (xsector + 1);
  3355. if (xsector >= OBJECT_SECTOR_X_EDGE)
  3356. {
  3357. go = 1;
  3358. diff = 0.0;
  3359. }
  3360. else if (go == -1 || go > xend + 1)
  3361. {
  3362. go = 1;
  3363. new
  3364. Float:nd = ((x - OBJECT_BOUNDS_MAXX) * (x - OBJECT_BOUNDS_MAXX)) / (OBJECT_MAX_VIEW_DISTANCE * OBJECT_MAX_VIEW_DISTANCE);
  3365. if (nd < diff) diff = nd;
  3366. }
  3367. }
  3368. if (ysector >= OBJECT_SECTOR_Y_EDGE + OBJECT_VIEW_RATIO)
  3369. {
  3370. yend = cellmin;
  3371. go = 1;
  3372. diff = 0.0;
  3373. }
  3374. else if (ysector >= OBJECT_SECTOR_Y_EDGE - OBJECT_VIEW_RATIO)
  3375. {
  3376. yend = OBJECT_SECTOR_Y_EDGE - (ysector + 1);
  3377. if (ysector >= OBJECT_SECTOR_Y_EDGE)
  3378. {
  3379. go = 1;
  3380. diff = 0.0;
  3381. }
  3382. else if (go == -1 || go > yend + 1)
  3383. {
  3384. go = 1;
  3385. new
  3386. Float:nd = ((y - OBJECT_BOUNDS_MAXY) * (y - OBJECT_BOUNDS_MAXY)) / (OBJECT_MAX_VIEW_DISTANCE * OBJECT_MAX_VIEW_DISTANCE);
  3387. if (nd < diff) diff = nd;
  3388. }
  3389. }
  3390. if (go)
  3391. {
  3392. go = 0;
  3393. sectors[0][E_OSEC_ITTER_SECTOR] = OBJECT_NO_SECTOR;
  3394. sectors[0][E_OSEC_ITTER_DIFF] = diff;
  3395. sectors[0][E_OSEC_ITTER_NEXT] = -1;
  3396. secStart = 0;
  3397. k = 1;
  3398. }
  3399. else secStart = -1;
  3400. for (new i = xstart; i <= xend; i++)
  3401. {
  3402. new
  3403. xsec = xsector + i;
  3404. new
  3405. Float:xsmin = x - YSI_g_sXSectorLocations[xsec + 1],
  3406. Float:xsmax = YSI_g_sXSectorLocations[xsec] - x;
  3407. if (i > 0)
  3408. {
  3409. if (xsmax < OBJECT_MAX_VIEW_DISTANCE) go = 1;
  3410. else break;
  3411. }
  3412. else if (i < 0)
  3413. {
  3414. if (xsmin < OBJECT_MAX_VIEW_DISTANCE) go = 1;
  3415. }
  3416. else go = 1;
  3417. if (go)
  3418. {
  3419. go = 0;
  3420. for (new j = ystart; j <= yend; j++)
  3421. {
  3422. new
  3423. ysec = ysector + j,
  3424. cursec = (xsec * OBJECT_SECTOR_X_EDGE) + ysec;
  3425. diff = 10.0;
  3426. if (i || j)
  3427. {
  3428. new
  3429. Float:ysmin = y - YSI_g_sYSectorLocations[ysec + 1],
  3430. Float:ysmax = YSI_g_sYSectorLocations[ysec] - y;
  3431. if (j > 0)
  3432. {
  3433. if (ysmax < OBJECT_MAX_VIEW_DISTANCE) go = 1;
  3434. else
  3435. {
  3436. yend--;
  3437. break;
  3438. }
  3439. }
  3440. else if (j < 0)
  3441. {
  3442. if (ysmin < OBJECT_MAX_VIEW_DISTANCE) go = 1;
  3443. else ystart++;
  3444. }
  3445. else go = 1;
  3446. if (go)
  3447. {
  3448. go = 0;
  3449. if (!i) diff = (j < 0) ? (ysmin * ysmin) : (ysmax * ysmax);
  3450. else if (!j) diff = (i < 0) ? (xsmin * xsmin) : (xsmax * xsmax);
  3451. else if (i < 0) diff = (j < 0) ? ((ysmin * ysmin) + (xsmin * xsmin)) : ((ysmax * ysmax) + (xsmin * xsmin));
  3452. else if (i > 0) diff = (j < 0) ? ((ysmin * ysmin) + (xsmax * xsmax)) : ((ysmax * ysmax) + (xsmax * xsmax));
  3453. diff /= YSI_g_sObjectSectors[cursec][E_OBJ_SECTOR_MAX_VIEW];
  3454. }
  3455. }
  3456. else diff = 0.0;
  3457. if (diff < 1.0)
  3458. {
  3459. new
  3460. itterCur = secStart,
  3461. itterLast = -1;
  3462. while (itterCur != -1 && sectors[itterCur][E_OSEC_ITTER_DIFF] < diff) itterCur = sectors[(itterLast = itterCur)][E_OSEC_ITTER_NEXT];
  3463. if (itterLast == -1) secStart = k;
  3464. else sectors[itterLast][E_OSEC_ITTER_NEXT] = k;
  3465. sectors[k][E_OSEC_ITTER_NEXT] = itterCur;
  3466. sectors[k][E_OSEC_ITTER_SECTOR] = cursec;
  3467. sectors[k][E_OSEC_ITTER_DIFF] = diff;
  3468. k++;
  3469. }
  3470. }
  3471. }
  3472. }
  3473. sLastCheck[playerid] = SECTOR_CHECK_FREQUENCY;
  3474. sLX[playerid] = xsector;
  3475. sLY[playerid] = ysector;
  3476. }
  3477. sLastCheck[playerid]--;
  3478. return 1;
  3479. }
  3480. /*----------------------------------------------------------------------------*-
  3481. Function:
  3482. Object_IsValidModel
  3483. Params:
  3484. modelid - Model to check won't crash SA.
  3485. Return:
  3486. -
  3487. Notes:
  3488. I wrote this function a long time ago and have barely updated it at all.
  3489. The only changes are the formatting and the use of the Bit class now,
  3490. despite the fact this was the first large bit array I did and is thus
  3491. the founding array of the whole idea behind the bit class.
  3492. -*----------------------------------------------------------------------------*/
  3493. stock Object_IsValidModel(modelid)
  3494. {
  3495. static
  3496. modeldat[] =
  3497. {
  3498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -128,
  3499. -515899393, -134217729, -1, -1, 33554431, -1, -1, -1, -14337, -1, -33,
  3500. 127, 0, 0, 0, 0, 0, -8388608, -1, -1, -1, -16385, -1, -1, -1, -1, -1,
  3501. -1, -1, -33, -1, -771751937, -1, -9, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  3502. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  3503. -1, -1, -1, -1, -1, -1, -1, -1, 33554431, -25, -1, -1, -1, -1, -1, -1,
  3504. -1073676289, -2147483648, 34079999, 2113536, -4825600, -5, -1, -3145729,
  3505. -1, -16777217, -63, -1, -1, -1, -1, -201326593, -1, -1, -1, -1, -1,
  3506. -257, -1, 1073741823, -133122, -1, -1, -65, -1, -1, -1, -1, -1, -1,
  3507. -2146435073, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1073741823, -64, -1,
  3508. -1, -1, -1, -2635777, 134086663, 0, -64, -1, -1, -1, -1, -1, -1, -1,
  3509. -536870927, -131069, -1, -1, -1, -1, -1, -1, -1, -1, -16384, -1,
  3510. -33554433, -1, -1, -1, -1, -1, -1610612737, 524285, -128, -1,
  3511. 2080309247, -1, -1, -1114113, -1, -1, -1, 66977343, -524288, -1, -1, -1,
  3512. -1, -2031617, -1, 114687, -256, -1, -4097, -1, -4097, -1, -1,
  3513. 1010827263, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -32768, -1, -1, -1, -1, -1,
  3514. 2147483647, -33554434, -1, -1, -49153, -1148191169, 2147483647,
  3515. -100781080, -262145, -57, 134217727, -8388608, -1, -1, -1, -1, -1, -1,
  3516. -1, -1, -1, -1, -1, -1, -1, -1, -1048577, -1, -449, -1017, -1, -1, -1,
  3517. -1, -1, -1, -1, -1, -1, -1, -1, -1835009, -2049, -1, -1, -1, -1, -1, -1,
  3518. -8193, -1, -536870913, -1, -1, -1, -1, -1, -87041, -1, -1, -1, -1, -1,
  3519. -1, -209860, -1023, -8388609, -2096897, -1, -1048577, -1, -1, -1, -1,
  3520. -1, -1, -897, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1610612737,
  3521. -3073, -28673, -1, -1, -1, -1537, -1, -1, -13, -1, -1, -1, -1, -1985,
  3522. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1056964609, -1, -1, -1,
  3523. -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  3524. -236716037, -1, -1, -1, -1, -1, -1, -1, -536870913, 3, 0, 0, 0, 0, 0, 0,
  3525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  3526. 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  3527. -1, -1, -1, -1, -1, -2097153, -2109441, -1, 201326591, -4194304, -1, -1,
  3528. -241, -1, -1, -1, -1, -1, -1, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  3529. 0, -32768, -1, -1, -1, -2, -671096835, -1, -8388609, -66323585, -13,
  3530. -1793, -32257, -247809, -1, -1, -513, 16252911, 0, 0, 0, -131072,
  3531. 33554383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  3532. 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  3533. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8356095, 0, 0, 0, 0, 0,
  3534. 0, -256, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  3535. -268435449, -1, -1, -2049, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  3536. 92274627, -65536, -2097153, -268435457, 591191935, 1, 0, -16777216, -1,
  3537. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 127
  3538. };
  3539. return Bit_Get(Bit:modeldat, modelid);
  3540. }
  3541. /*----------------------------------------------------------------------------*-
  3542. Function:
  3543. Object_OnPlayerDisconnect
  3544. Params:
  3545. playerid - Player who left.
  3546. reason - Why they left.
  3547. Return:
  3548. -
  3549. Notes:
  3550. Just to automatically disconnect attached objects from players.
  3551. -*----------------------------------------------------------------------------*/
  3552. Object_OnPlayerDisconnect(playerid, reason)
  3553. {
  3554. #if defined _YSI_SETUP_MASTER
  3555. if (!YSI_g_sIsMaster) return 0;
  3556. #endif
  3557. for (new objectid = 0; objectid < MAY_OBJECTS; objectid++)
  3558. {
  3559. YSI_g_sPlayerObjects[playerid][objectid] = NO_OBJECT;
  3560. }
  3561. #if !defined NO_OBJECTS_MOVE
  3562. new
  3563. sets = YSI_g_sMovingObjects;
  3564. if (sets == NO_OBJECT) return 0;
  3565. new
  3566. start = sets;
  3567. do
  3568. {
  3569. new
  3570. e_OBJ_FLAG:flag = YSI_g_sObjects[sets][E_OBJECT_MODEL];
  3571. if (flag & e_OBJ_FLAG_ACTIVE)
  3572. {
  3573. if (Object_GetAttach(flag) == playerid) DetachDynamicObjectFromPlayer(sets);
  3574. }
  3575. sets = YSI_g_sObjects[sets][E_OBJECT_NEXT];
  3576. }
  3577. while (sets != start);
  3578. #endif
  3579. return 1;
  3580. #pragma unused reason
  3581. }
  3582. /*----------------------------------------------------------------------------*-
  3583. Function:
  3584. Object_SetAreaGate
  3585. Params:
  3586. objectid - Object to make into a gate.
  3587. areaid - Area to trigger gate in.
  3588. Float:tx - X point to open to.
  3589. Float:ty - Y point to open to.
  3590. Float:tz - Z point to open to.
  3591. Float:ts - Speed to open at.
  3592. Return:
  3593. -
  3594. Notes:
  3595. Just to automatically disconnect attached objects from players.
  3596. -*----------------------------------------------------------------------------*/
  3597. stock Object_SetAreaGate(objectid, areaid, Float:tx, Float:ty, Float:tz, Float:ts, time = 10000)
  3598. {
  3599. #if defined _YSI_SETUP_MASTER
  3600. if (YSI_g_sIsMaster)
  3601. {
  3602. #endif
  3603. #if !defined NO_OBJECTS_MOVE
  3604. #if defined _YSI_VISUAL_AREAS
  3605. if (Object_IsValid(objectid) && !Object_IsAttached(YSI_g_sObjects[objectid][E_OBJECT_MODEL]) && Area_IsValid(areaid))
  3606. {
  3607. new
  3608. gate;
  3609. while (gate < MAX_GATE_OBJECTS)
  3610. {
  3611. if (!YSI_g_sGateInfo[gate][E_GATE_INFO_OBJECT]) break;
  3612. gate++;
  3613. }
  3614. if (gate == MAX_GATE_OBJECTS) return NO_GATE;
  3615. YSI_g_sGateInfo[gate][E_GATE_INFO_OBJECT] = objectid | GATE_AREA_TRIGGER;
  3616. YSI_g_sGateInfo[gate][E_GATE_INFO_TIME] = time;
  3617. YSI_g_sGateInfo[gate][E_GATE_INFO_TRIGGER] = areaid;
  3618. YSI_g_sObjects[objectid][E_OBJECT_MODEL] |= e_OBJ_FLAG_GATE;
  3619. Object_SetGateTarget(gate, tx, ty, tz, ts);
  3620. #if !defined NO_GATE_AREA_LOOKUP
  3621. new
  3622. slot = areaid / 2,
  3623. shift = (areaid % 2) * 16;
  3624. YSI_g_sGateAreas[slot] = (YSI_g_sGateAreas[slot] & (0xFFFF0000 >>> shift)) | (gate << shift);
  3625. #endif
  3626. return gate;
  3627. }
  3628. #endif
  3629. #endif
  3630. return NO_GATE;
  3631. #if defined _YSI_SETUP_MASTER
  3632. }
  3633. else
  3634. {
  3635. DBGP4("Object_SetAreaGate() else: %d %d %d", objectid, areaid, time);
  3636. CallRemoteFunction("Object_Remote", "iii", objectid, areaid, E_OBJECT_REMOTE_GATE | (time << 12));
  3637. new
  3638. gate = getproperty(0, "YSIReq");
  3639. DBGP4("Object_SetAreaGate() gate: %d %d", gate, NO_GATE);
  3640. if (gate != NO_GATE)
  3641. {
  3642. DBGP3("Object_SetAreaGate() ok: %.2f %.2f %.2f %.2f", tx, ty, tz, ts);
  3643. CallRemoteFunction("Object_CoOrdRemote", "iiffff", gate, E_OBJECT_REMOTE_GATE_POS, tx, ty, tz, ts);
  3644. }
  3645. return gate;
  3646. }
  3647. #endif
  3648. }
  3649. #if defined _YSI_VISUAL_AREAS
  3650. /*----------------------------------------------------------------------------*-
  3651. Function:
  3652. Object_OnPlayerEnterArea
  3653. Params:
  3654. playerid - Player who entered an area.
  3655. areaid - Area they entered.
  3656. Return:
  3657. -
  3658. Notes:
  3659. Internal callback from YSI_areas.
  3660. -*----------------------------------------------------------------------------*/
  3661. #if defined _YSI_SETUP_MASTER
  3662. public Object_OnPlayerEnterArea(playerid, areaid)
  3663. if (!YSI_g_sIsMaster) return 0;
  3664. else
  3665. #else
  3666. Object_OnPlayerEnterArea(playerid, areaid)
  3667. #endif
  3668. {
  3669. DBGP2("Object_OnPlayerEnterArea() start");
  3670. #if defined _YSI_SETUP_MASTER
  3671. setproperty(0, "YSIReq", 0);
  3672. #else
  3673. #pragma unused playerid
  3674. #endif
  3675. #if defined NO_OBJECTS_MOVE
  3676. return 0;
  3677. #else
  3678. new
  3679. gate;
  3680. #if defined NO_GATE_AREA_LOOKUP
  3681. DBGP3("Object_OnPlayerEnterArea() Lookup");
  3682. while (gate < MAX_GATE_OBJECTS)
  3683. {
  3684. if (YSI_g_sGateInfo[gate][E_GATE_INFO_OBJECT] & GATE_AREA_TRIGGER && YSI_g_sGateInfo[gate][E_GATE_INFO_TRIGGER] == areaid) break;
  3685. }
  3686. if (gate == MAX_GATE_OBJECTS) return 0;
  3687. #else
  3688. gate = (YSI_g_sGateAreas[areaid / 2] >>> ((areaid % 2) * 16)) & 0xFFFF;
  3689. DBGP3("Object_OnPlayerEnterArea() Known %d %d %d", areaid, gate, YSI_g_sGateAreas[areaid / 2]);
  3690. if (gate == 0xFFFF) return 0;
  3691. #endif
  3692. #if defined _YSI_SETUP_MASTER
  3693. setproperty(0, "YSIReq", 1);
  3694. #endif
  3695. DBGP3("Object_OnPlayerEnterArea() Get");
  3696. new
  3697. objectid = YSI_g_sGateInfo[gate][E_GATE_INFO_OBJECT] & (~(GATE_AREA_TRIGGER | GATE_OPENING));
  3698. if (Object_IsValid(objectid))
  3699. {
  3700. DBGP3("Object_OnPlayerEnterArea() Valid");
  3701. if (YSI_g_sObjects[objectid][E_OBJECT_MODEL] & e_OBJ_FLAG_MOVED || YSI_g_sGateInfo[gate][E_GATE_INFO_OBJECT] & GATE_OPENING) return 1;
  3702. DBGP3("Object_OnPlayerEnterArea() Static");
  3703. new
  3704. Float:x,
  3705. Float:y,
  3706. Float:z,
  3707. Float:tx = (float((YSI_g_sGateInfo[gate][E_GATE_INFO_XY] >> 14) & 0x1FFFF) * ((YSI_g_sGateInfo[gate][E_GATE_INFO_XY] & 0x80000000) ? (-1.0) : (1.0)) / 10.0),
  3708. Float:ty = (float((YSI_g_sGateInfo[gate][E_GATE_INFO_XY] & 0x03FFF) | ((YSI_g_sGateInfo[gate][E_GATE_INFO_ZA] >> 14) & 0x1C000)) * ((YSI_g_sGateInfo[gate][E_GATE_INFO_ZA] & 0x80000000) ? (-1.0) : (1.0)) / 10.0),
  3709. Float:tz = (float((YSI_g_sGateInfo[gate][E_GATE_INFO_ZA] >> 10) & 0x1FFFF) * ((YSI_g_sGateInfo[gate][E_GATE_INFO_ZA] & 0x08000000) ? (-1.0) : (1.0)) / 10.0),
  3710. Float:s = (float(YSI_g_sGateInfo[gate][E_GATE_INFO_ZA] & 0x3FF) / 10.0);
  3711. Object_GetPos(objectid, x, y, z);
  3712. YSI_g_sGateInfo[gate][E_GATE_INFO_OBJECT] |= GATE_OPENING;
  3713. Object_SetGateTarget(gate, x, y, z, s);
  3714. Object_Move(objectid, tx, ty, tz, s);
  3715. Object_AddToUpdate(objectid);
  3716. DBGP3("Object_OnPlayerEnterArea() Moved");
  3717. }
  3718. else
  3719. {
  3720. YSI_g_sGateInfo[gate][E_GATE_INFO_TRIGGER] = NO_GATE;
  3721. #if !defined NO_GATE_AREA_LOOKUP
  3722. YSI_g_sGateAreas[areaid / 2] |= 0xFFFF << ((areaid % 2) * 16);
  3723. #endif
  3724. Area_Delete(areaid);
  3725. }
  3726. DBGP3("Object_OnPlayerEnterArea() end");
  3727. return 1;
  3728. #endif
  3729. }
  3730. #endif
  3731. #if !defined NO_OBJECTS_MOVE
  3732. /*----------------------------------------------------------------------------*-
  3733. Function:
  3734. Object_GateMoved
  3735. Params:
  3736. objectid - Object that moved.
  3737. Return:
  3738. -
  3739. Notes:
  3740. Checks if the object which moved is a gate.
  3741. -*----------------------------------------------------------------------------*/
  3742. static stock Object_GateMoved(objectid)
  3743. {
  3744. #if defined _YSI_VISUAL_AREAS
  3745. if (YSI_g_sObjects[objectid][E_OBJECT_MODEL] & e_OBJ_FLAG_GATE)
  3746. {
  3747. new
  3748. gate = 0;
  3749. while (gate < MAX_GATE_OBJECTS)
  3750. {
  3751. if (objectid == (YSI_g_sGateInfo[gate][E_GATE_INFO_OBJECT] & (~(GATE_AREA_TRIGGER | GATE_OPENING)))) break;
  3752. gate++;
  3753. }
  3754. if (gate == MAX_GATE_OBJECTS)
  3755. {
  3756. YSI_g_sObjects[objectid][E_OBJECT_MODEL] &= ~e_OBJ_FLAG_GATE;
  3757. return 0;
  3758. }
  3759. if (YSI_g_sGateInfo[gate][E_GATE_INFO_OBJECT] & (GATE_AREA_TRIGGER | GATE_OPENING) == (GATE_AREA_TRIGGER | GATE_OPENING))
  3760. {
  3761. SetTimerEx("Object_GateClose", 500000, 0, "i", gate);
  3762. }
  3763. return 1;
  3764. }
  3765. #else
  3766. #pragma unused objectid
  3767. #endif
  3768. return 0;
  3769. }
  3770. #endif
  3771. #if defined _YSI_VISUAL_AREAS
  3772. /*----------------------------------------------------------------------------*-
  3773. Function:
  3774. Object_GateClose
  3775. Params:
  3776. gate - Gate to close.
  3777. Return:
  3778. -
  3779. Notes:
  3780. Closes an area triggered gate after a delay.
  3781. -*----------------------------------------------------------------------------*/
  3782. public Object_GateClose(gate)
  3783. {
  3784. if (Area_IsEmpty(YSI_g_sGateInfo[gate][E_GATE_INFO_TRIGGER]))
  3785. {
  3786. new
  3787. objectid = YSI_g_sGateInfo[gate][E_GATE_INFO_OBJECT] & ~(GATE_AREA_TRIGGER | GATE_OPENING);
  3788. if (Object_IsValid(objectid))
  3789. {
  3790. new
  3791. Float:x,
  3792. Float:y,
  3793. Float:z,
  3794. Float:tx = (float((YSI_g_sGateInfo[gate][E_GATE_INFO_XY] >> 14) & 0x1FFFF) * ((YSI_g_sGateInfo[gate][E_GATE_INFO_XY] & 0x80000000) ? (-0.1) : (0.1))),
  3795. Float:ty = (float((YSI_g_sGateInfo[gate][E_GATE_INFO_XY] & 0x03FFF) | ((YSI_g_sGateInfo[gate][E_GATE_INFO_ZA] >> 14) & 0x1C000)) * ((YSI_g_sGateInfo[gate][E_GATE_INFO_ZA] & 0x80000000) ? (-0.1) : (0.1))),
  3796. Float:tz = (float((YSI_g_sGateInfo[gate][E_GATE_INFO_ZA] >> 10) & 0x1FFFF) * ((YSI_g_sGateInfo[gate][E_GATE_INFO_ZA] & 0x08000000) ? (-0.1) : (0.1))),
  3797. Float:s = (float(YSI_g_sGateInfo[gate][E_GATE_INFO_ZA] & 0x3FF) / 10.0);
  3798. Object_GetPos(objectid, x, y, z);
  3799. Object_SetGateTarget(gate, x, y, z, s);
  3800. Object_Move(objectid, tx, ty, tz, s);
  3801. Object_AddToUpdate(objectid);
  3802. }
  3803. else
  3804. {
  3805. new
  3806. areaid = YSI_g_sGateInfo[gate][E_GATE_INFO_TRIGGER];
  3807. YSI_g_sGateInfo[gate][E_GATE_INFO_TRIGGER] = NO_GATE;
  3808. #if !defined NO_GATE_AREA_LOOKUP
  3809. YSI_g_sGateAreas[areaid / 2] |= 0xFFFF << ((areaid % 2) * 16);
  3810. #endif
  3811. Area_Delete(areaid);
  3812. }
  3813. }
  3814. else
  3815. {
  3816. SetTimerEx("Object_GateClose", 1000, 0, "i", gate);
  3817. }
  3818. }
  3819. #endif
  3820. /*----------------------------------------------------------------------------*-
  3821. Function:
  3822. CreateGate
  3823. Params:
  3824. modelid - Model of the gate.
  3825. Float:x - X start location.
  3826. Float:y - Y start location.
  3827. Float:z - Z start location.
  3828. Float:tx - X target location.
  3829. Float:ty - Y target location.
  3830. Float:tz - Z target location.
  3831. Float:rx - X rotation.
  3832. Float:ry - Y rotation.
  3833. Float:rz - Z rotation.
  3834. Float:speed - Speed the gate will move at.
  3835. Return:
  3836. -
  3837. Notes:
  3838. Creates a gate.
  3839. -*----------------------------------------------------------------------------*/
  3840. stock CreateGate(modelid, Float:x, Float:y, Float:z, Float:tx, Float:ty, Float:tz, Float:rx = 0.0, Float:ry = 0.0, Float:rz = 0.0, Float:speed = 2.0)
  3841. {
  3842. #if defined _YSI_VISUAL_AREAS
  3843. new
  3844. obj = CreateDynamicObject(modelid, x, y, z, rx, ry, rz);
  3845. if (obj == NO_OBJECT) return NO_GATE;
  3846. new
  3847. Float:xx = floatabs(x - tx),
  3848. Float:yy = floatabs(y - ty),
  3849. area = Area_AddCircle(x, y, ((yy > xx) ? (yy) : (xx)) * 2.0, z + 20.0);
  3850. if (area == NO_AREA)
  3851. {
  3852. DestroyDynamicObject(obj);
  3853. return NO_GATE;
  3854. }
  3855. return Object_SetAreaGate(obj, area, tx, ty, tz, speed, 10000);
  3856. #else
  3857. #pragma unused modelid, x, y, z, tx, ty, tz, rx, ry, rz, speed
  3858. return NO_GATE;
  3859. #endif
  3860. }
  3861. /*----------------------------------------------------------------------------*-
  3862. Function:
  3863. Object_GetGateArea
  3864. Params:
  3865. gate - Gate to get the area of for permissions.
  3866. Return:
  3867. -
  3868. Notes:
  3869. Returns the areaid used by the gate for detection.
  3870. -*----------------------------------------------------------------------------*/
  3871. stock Object_GetGateArea(gate)
  3872. {
  3873. #if defined _YSI_SETUP_MASTER
  3874. if (YSI_g_sIsMaster)
  3875. {
  3876. #endif
  3877. #if defined _YSI_VISUAL_AREAS
  3878. if (gate >= 0 && gate < MAX_GATE_OBJECTS)
  3879. {
  3880. return YSI_g_sGateInfo[gate][E_GATE_INFO_TRIGGER];
  3881. }
  3882. #else
  3883. #pragma unused gate
  3884. #endif
  3885. return -1;
  3886. #if defined _YSI_SETUP_MASTER
  3887. }
  3888. else
  3889. {
  3890. CallRemoteFunction("Object_Remote", "iii", gate, 0, E_OBJECT_REMOTE_GET_AREA);
  3891. return getproperty(0, "YSIReq");
  3892. }
  3893. #endif
  3894. }