1
0

y_master.inc 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  1. /*----------------------------------------------------------------------------*-
  2. ======================
  3. YSI - Master Include
  4. ======================
  5. Description:
  6. Handles distribution of control of code segments across all running scripts
  7. with YSI to avoid conflicts of checkpoint streamers etc and allow features
  8. like "/commands" displaying all commands on the server.
  9. Now fully autonomous - to use the master system simply define which one you
  10. want and include the script:
  11. #define MASTER 14
  12. #include <YSI\Master>
  13. That will make the current script attempt to make itself the main master -
  14. you don't need ANY other code for initialisation anywhere (which took a
  15. while to figure out)...
  16. This is now over 2000 lines of repetitive and complex macros!
  17. Legal:
  18. Version: MPL 1.1
  19. The contents of this file are subject to the Mozilla Public License Version
  20. 1.1 (the "License"); you may not use this file except in compliance with
  21. the License. You may obtain a copy of the License at
  22. http://www.mozilla.org/MPL/
  23. Software distributed under the License is distributed on an "AS IS" basis,
  24. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  25. for the specific language governing rights and limitations under the
  26. License.
  27. The Original Code is the SA:MP script information include.
  28. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  29. Portions created by the Initial Developer are Copyright (C) 2008
  30. the Initial Developer. All Rights Reserved.
  31. Contributors:
  32. ZeeX, koolk
  33. Thanks:
  34. Peter, Cam - Support.
  35. ZeeX - Very productive conversations.
  36. koolk - IsPlayerinAreaEx code.
  37. TheAlpha - Danish translation.
  38. breadfish - German translation.
  39. Fireburn - Dutch translation.
  40. yom - French translation.
  41. 50p - Polish translation.
  42. Zamaroht - Spanish translation.
  43. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  44. for me to strive to better.
  45. Pixels^ - Running XScripters where the idea was born.
  46. Matite - Pestering me to release it and using it.
  47. Very special thanks to:
  48. Thiadmer - PAWN.
  49. Kye/Kalcor - SA:MP.
  50. SA:MP Team past, present and future - SA:MP.
  51. Version:
  52. 0.2
  53. Changelog:
  54. 06/08/10:
  55. Managed the ultimate - got completely transparent inclusion!
  56. 05/08/10:
  57. Completed new master system, now does all syncing and clients.
  58. 06/10/09:
  59. Rewrote using states.
  60. Added remote function macros.
  61. Reduced the number of masters to a single one. It must have them all.
  62. Vastly simplified the master model - ending the master ends everything.
  63. 06/01/08:
  64. Added code to not pass data if no other script exists.
  65. 17/11/07:
  66. Added code for a script to remove itself from the global list.
  67. 11/10/07:
  68. Not first version but added documentation months late.
  69. Functions:
  70. Public:
  71. -
  72. Core:
  73. -
  74. Stock:
  75. -
  76. Static:
  77. -
  78. Inline:
  79. -
  80. API:
  81. -
  82. Hooks:
  83. -
  84. Callbacks:
  85. -
  86. Definitions:
  87. -
  88. Enums:
  89. -
  90. Macros:
  91. RF - Declare a function which may be remote.
  92. RV - Declare a void function which may be remote.
  93. RS - Declare an optional callback.
  94. RFN - Declare an optional callback with no parameters.
  95. RFC - Declare a slower but shorter function.
  96. RFP - Declare a function with tags and give recall hints.
  97. RFPC - Combination of P and C.
  98. RFCP - Combination of P and C.
  99. Tags:
  100. -
  101. Variables:
  102. Global:
  103. _@ - ID of this script.
  104. Static:
  105. -
  106. Commands:
  107. -
  108. Compile options:
  109. YSI_NO_MASTER - Don't use the master system.
  110. YSI_IS_CLIENT - Script is a client only script.
  111. YSI_IS_SERVER - Script is a server only script.
  112. Operators:
  113. -
  114. Natives:
  115. -
  116. -*----------------------------------------------------------------------------*/
  117. #include <YSI\internal\y_version>
  118. // ALWAYS! The compiler defines this automatically, don't use it as this is
  119. // included multiple times to handle multiple master systems.
  120. #undef _inc_y_master
  121. /*#if defined YSIM_STORED_SETTINGS
  122. #define _YSIM_OVERRIDE
  123. #endif*/
  124. #if defined _YSIM_RESET_USER
  125. #undef _YSIM_RESET_USER
  126. #if !defined _YSIM_MANUAL_SET
  127. #endinput
  128. #endif
  129. //#define MASTER _YSIM_LAST_MANUAL
  130. #define _YSIM_OVERRIDE _YSIM_LAST_MANUAL
  131. #include <YSI\internal\y_overridemaster>
  132. #elseif defined MASTER
  133. #if !defined _YSIM_MANUAL_SET
  134. #define _YSIM_MANUAL_SET
  135. #endif
  136. #if defined _YSIM_LAST_MANUAL
  137. #undef _YSIM_LAST_MANUAL
  138. #endif
  139. #if MASTER == 0
  140. #define _YSIM_LAST_MANUAL 0
  141. // This master was already included, the user just didn't realise.
  142. /*#if defined _YSIM_FAKE_MANUAL_SET
  143. #define _YSIM_OVERRIDE 0
  144. #define YSIM_STORED_SETTINGS 0
  145. #undef _YSIM_FAKE_MANUAL_SET
  146. #endif*/
  147. #elseif MASTER == 1
  148. #define _YSIM_LAST_MANUAL 1
  149. #elseif MASTER == 2
  150. #define _YSIM_LAST_MANUAL 2
  151. #elseif MASTER == 3
  152. #define _YSIM_LAST_MANUAL 3
  153. #elseif MASTER == 4
  154. #define _YSIM_LAST_MANUAL 4
  155. #elseif MASTER == 5
  156. #define _YSIM_LAST_MANUAL 5
  157. #elseif MASTER == 6
  158. #define _YSIM_LAST_MANUAL 6
  159. #elseif MASTER == 7
  160. #define _YSIM_LAST_MANUAL 7
  161. #elseif MASTER == 8
  162. #define _YSIM_LAST_MANUAL 8
  163. #elseif MASTER == 9
  164. #define _YSIM_LAST_MANUAL 9
  165. #elseif MASTER == 10
  166. #define _YSIM_LAST_MANUAL 10
  167. #elseif MASTER == 11
  168. #define _YSIM_LAST_MANUAL 11
  169. #elseif MASTER == 12
  170. #define _YSIM_LAST_MANUAL 12
  171. #elseif MASTER == 13
  172. #define _YSIM_LAST_MANUAL 13
  173. #elseif MASTER == 14
  174. #define _YSIM_LAST_MANUAL 14
  175. #elseif MASTER == 15
  176. #define _YSIM_LAST_MANUAL 15
  177. #elseif MASTER == 16
  178. #define _YSIM_LAST_MANUAL 16
  179. #elseif MASTER == 17
  180. #define _YSIM_LAST_MANUAL 17
  181. #elseif MASTER == 18
  182. #define _YSIM_LAST_MANUAL 18
  183. #elseif MASTER == 19
  184. #define _YSIM_LAST_MANUAL 19
  185. #elseif MASTER == 20
  186. #define _YSIM_LAST_MANUAL 20
  187. #elseif MASTER == 21
  188. #define _YSIM_LAST_MANUAL 21
  189. #elseif MASTER == 22
  190. #define _YSIM_LAST_MANUAL 22
  191. #elseif MASTER == 23
  192. #define _YSIM_LAST_MANUAL 23
  193. #elseif MASTER == 24
  194. #define _YSIM_LAST_MANUAL 24
  195. #elseif MASTER == 25
  196. #define _YSIM_LAST_MANUAL 25
  197. #endif
  198. #else
  199. //#define YSIM_STORED_SETTINGS YSIM_RECALL_19
  200. //#define _YSIM_AUTODEF
  201. #if defined _YSIM_OVERRIDE
  202. #include <YSI\internal\y_overridemaster>
  203. #if !defined MASTER
  204. #error _YSIM_OVERRIDE used with an invalid master value.
  205. #endif
  206. #else
  207. #tryinclude <YSI\internal\y_automasters>
  208. #if !defined MASTER
  209. //#error "You must define a unique MASTER number from 0 to 25."
  210. // Default for user scripts.
  211. #define MASTER 0
  212. #if defined _YSIM_LAST_MANUAL
  213. #undef _YSIM_LAST_MANUAL
  214. #endif
  215. #define _YSIM_LAST_MANUAL 0
  216. #if !defined _YSIM_MANUAL_SET
  217. #define _YSIM_MANUAL_SET
  218. #endif
  219. // Detect reinclusions.
  220. /*#if defined _YSIM_FAKE_MANUAL_SET
  221. #define _YSIM_OVERRIDE 0
  222. #define YSIM_STORED_SETTINGS 0
  223. #undef _YSIM_FAKE_MANUAL_SET
  224. #endif*/
  225. #endif
  226. #endif
  227. #endif
  228. #if MASTER > 25 || MASTER < 0
  229. // There are some secret ones reserved purely for YSI!
  230. //#if !defined _YSIM_USED_AUTO || MASTER > 42
  231. //#if !defined _YSIM_OVERRIDE
  232. #error Invalid MASTER value, must be between 0 and 25 (inclusive).
  233. //#endif
  234. #endif
  235. #if defined YSIM_HAS_MASTER
  236. #undef YSIM_HAS_MASTER
  237. #endif
  238. #if defined YSIM_IS_CLIENT
  239. #undef YSIM_IS_CLIENT
  240. #endif
  241. #if defined YSIM_IS_SERVER
  242. #undef YSIM_IS_SERVER
  243. #endif
  244. #if defined YSIM_IS_STUB
  245. #undef YSIM_IS_STUB
  246. #endif
  247. #if defined YSIM_CLOUD
  248. #undef YSIM_CLOUD
  249. #endif
  250. //#if defined YSIM_NOT_CLIENT
  251. // #undef YSIM_NOT_CLIENT
  252. //#endif
  253. #if defined _YSIM_OVERRIDE
  254. // Get stored settings for YSI libraries. This allows the group system to
  255. // use the same master settings as another library without being there at
  256. // the time.
  257. #if YSIM_STORED_SETTINGS == 0
  258. #define YSIM_HAS_MASTER 0
  259. #else
  260. #define YSIM_HAS_MASTER 1
  261. #endif
  262. #if YSIM_STORED_SETTINGS == 1
  263. #define YSIM_IS_CLIENT 1
  264. #else
  265. #define YSIM_IS_CLIENT 0
  266. #endif
  267. #if YSIM_STORED_SETTINGS == 2
  268. #define YSIM_IS_SERVER 1
  269. #else
  270. #define YSIM_IS_SERVER 0
  271. #endif
  272. #if YSIM_STORED_SETTINGS == 3
  273. #define YSIM_CLOUD 1
  274. #else
  275. #define YSIM_CLOUD 0
  276. #endif
  277. #if YSIM_STORED_SETTINGS == 4
  278. #define YSIM_IS_STUB 1
  279. #else
  280. #define YSIM_IS_STUB 0
  281. #endif
  282. #else
  283. // Set up simple quick macros to query different current capabilities.
  284. #if (!defined YSI_NO_MASTER || defined YSIM_T_ENABLE) && !defined YSIM_T_DISABLE
  285. #define YSIM_HAS_MASTER 1
  286. #else
  287. #define YSIM_HAS_MASTER 0
  288. #endif
  289. #if (defined YSI_IS_CLIENT || defined YSIM_C_ENABLE) && !defined YSIM_C_DISABLE
  290. #define YSIM_IS_CLIENT 1
  291. #else
  292. #define YSIM_IS_CLIENT 0
  293. #endif
  294. #if (defined YSI_IS_SERVER || defined YSIM_S_ENABLE) && !defined YSIM_S_DISABLE
  295. #define YSIM_IS_SERVER 1
  296. #else
  297. #define YSIM_IS_SERVER 0
  298. #endif
  299. #if (defined YSI_IS_STUB || defined YSIM_U_ENABLE) && !defined YSIM_U_DISABLE
  300. #define YSIM_IS_STUB 1
  301. #else
  302. #define YSIM_IS_STUB 0
  303. #endif
  304. #if YSIM_HAS_MASTER && !YSIM_IS_CLIENT && !YSIM_IS_SERVER
  305. #define YSIM_CLOUD 1
  306. #else
  307. #define YSIM_CLOUD 0
  308. #endif
  309. #endif
  310. #if defined _inc_y_masteronce
  311. // Been included at least once, clean up from before.
  312. #undef RF
  313. #undef RF@p
  314. #undef RF@c
  315. #undef RF@v
  316. //#undef RF@n
  317. #undef RF@pc
  318. #undef RF@pv
  319. #undef RF@pcv
  320. #undef RF@vc
  321. #undef RF@t
  322. #undef RF@pt
  323. #undef RF@ct
  324. #undef RF@pct
  325. //#undef RF@vn
  326. // Remote string
  327. #undef RS
  328. #undef RS@p
  329. //#undef RS@c
  330. //#undef RS@cp
  331. // Remote calback
  332. //#undef RC
  333. //#undef RC@v
  334. // Remote hook
  335. #undef RH
  336. // Remote timer
  337. #undef RT
  338. // Remote private
  339. //#undef RP@v
  340. // Remote command
  341. #undef RC
  342. // Remote local
  343. //#undef RL
  344. // Remote text load
  345. #undef RX
  346. // Remote ALS
  347. #undef RA
  348. //#undef RA@p
  349. //#undef RC@v
  350. //#undef RC@n
  351. //#undef RC@vn
  352. #undef Master_Caller
  353. //#undef Master_Init
  354. #endif
  355. #include <YSI\y_utils>
  356. #include <YSI\internal\y_masteronce>
  357. // Clear up some artifacts
  358. #if defined YSIM_DEFINED
  359. #undef YSIM_DEFINED
  360. #endif
  361. #if defined _YCM
  362. #undef _YCM
  363. #endif
  364. // Now set the current script data.
  365. // IDIOT! These are mostly mutually exclusive! You don't need a horrible huge
  366. // bit array to store the fact that this is both a client AND a server!
  367. #if MASTER == 0
  368. #if defined _YCM_a@
  369. #define YSIM_DEFINED
  370. #else
  371. #define _YCM_a@
  372. // Save the settings.
  373. #if !YSIM_HAS_MASTER
  374. #define YSIM_RECALL_0 0
  375. #elseif YSIM_IS_CLIENT
  376. #define YSIM_RECALL_0 1
  377. #elseif YSIM_IS_SERVER
  378. #define YSIM_RECALL_0 2
  379. #elseif YSIM_CLOUD
  380. #define YSIM_RECALL_0 3
  381. #elseif YSIM_IS_STUB
  382. #define YSIM_RECALL_0 4
  383. #else
  384. #error Undefined master type on 0
  385. #endif
  386. #endif
  387. #define _YCM a@
  388. #elseif MASTER == 1
  389. #if defined _YCM_b@
  390. #define YSIM_DEFINED
  391. #else
  392. #define _YCM_b@
  393. // Save the settings.
  394. #if !YSIM_HAS_MASTER
  395. #define YSIM_RECALL_1 0
  396. #elseif YSIM_IS_CLIENT
  397. #define YSIM_RECALL_1 1
  398. #elseif YSIM_IS_SERVER
  399. #define YSIM_RECALL_1 2
  400. #elseif YSIM_CLOUD
  401. #define YSIM_RECALL_1 3
  402. #elseif YSIM_IS_STUB
  403. #define YSIM_RECALL_1 4
  404. #else
  405. #error Undefined master type on 1
  406. #endif
  407. #endif
  408. #define _YCM b@
  409. #elseif MASTER == 2
  410. #if defined _YCM_c@
  411. #define YSIM_DEFINED
  412. #else
  413. #define _YCM_c@
  414. // Save the settings.
  415. #if !YSIM_HAS_MASTER
  416. #define YSIM_RECALL_2 0
  417. #elseif YSIM_IS_CLIENT
  418. #define YSIM_RECALL_2 1
  419. #elseif YSIM_IS_SERVER
  420. #define YSIM_RECALL_2 2
  421. #elseif YSIM_CLOUD
  422. #define YSIM_RECALL_2 3
  423. #elseif YSIM_IS_STUB
  424. #define YSIM_RECALL_2 4
  425. #else
  426. #error Undefined master type on 2
  427. #endif
  428. #endif
  429. #define _YCM c@
  430. #elseif MASTER == 3
  431. #if defined _YCM_d@
  432. #define YSIM_DEFINED
  433. #else
  434. #define _YCM_d@
  435. // Save the settings.
  436. #if !YSIM_HAS_MASTER
  437. #define YSIM_RECALL_3 0
  438. #elseif YSIM_IS_CLIENT
  439. #define YSIM_RECALL_3 1
  440. #elseif YSIM_IS_SERVER
  441. #define YSIM_RECALL_3 2
  442. #elseif YSIM_CLOUD
  443. #define YSIM_RECALL_3 3
  444. #elseif YSIM_IS_STUB
  445. #define YSIM_RECALL_3 4
  446. #else
  447. #error Undefined master type on 3
  448. #endif
  449. #endif
  450. #define _YCM d@
  451. #elseif MASTER == 4
  452. #if defined _YCM_e@
  453. #define YSIM_DEFINED
  454. #else
  455. #define _YCM_e@
  456. // Save the settings.
  457. #if !YSIM_HAS_MASTER
  458. #define YSIM_RECALL_4 0
  459. #elseif YSIM_IS_CLIENT
  460. #define YSIM_RECALL_4 1
  461. #elseif YSIM_IS_SERVER
  462. #define YSIM_RECALL_4 2
  463. #elseif YSIM_CLOUD
  464. #define YSIM_RECALL_4 3
  465. #elseif YSIM_IS_STUB
  466. #define YSIM_RECALL_4 4
  467. #else
  468. #error Undefined master type on 4
  469. #endif
  470. #endif
  471. #define _YCM e@
  472. #elseif MASTER == 5
  473. #if defined _YCM_f@
  474. #define YSIM_DEFINED
  475. #else
  476. #define _YCM_f@
  477. // Save the settings.
  478. #if !YSIM_HAS_MASTER
  479. #define YSIM_RECALL_5 0
  480. #elseif YSIM_IS_CLIENT
  481. #define YSIM_RECALL_5 1
  482. #elseif YSIM_IS_SERVER
  483. #define YSIM_RECALL_5 2
  484. #elseif YSIM_CLOUD
  485. #define YSIM_RECALL_5 3
  486. #elseif YSIM_IS_STUB
  487. #define YSIM_RECALL_5 4
  488. #else
  489. #error Undefined master type on 5
  490. #endif
  491. #endif
  492. #define _YCM f@
  493. #elseif MASTER == 6
  494. #if defined _YCM_g@
  495. #define YSIM_DEFINED
  496. #else
  497. #define _YCM_g@
  498. // Save the settings.
  499. #if !YSIM_HAS_MASTER
  500. #define YSIM_RECALL_6 0
  501. #elseif YSIM_IS_CLIENT
  502. #define YSIM_RECALL_6 1
  503. #elseif YSIM_IS_SERVER
  504. #define YSIM_RECALL_6 2
  505. #elseif YSIM_CLOUD
  506. #define YSIM_RECALL_6 3
  507. #elseif YSIM_IS_STUB
  508. #define YSIM_RECALL_6 4
  509. #else
  510. #error Undefined master type on 6
  511. #endif
  512. #endif
  513. #define _YCM g@
  514. #elseif MASTER == 7
  515. #if defined _YCM_h@
  516. #define YSIM_DEFINED
  517. #else
  518. #define _YCM_h@
  519. // Save the settings.
  520. #if !YSIM_HAS_MASTER
  521. #define YSIM_RECALL_7 0
  522. #elseif YSIM_IS_CLIENT
  523. #define YSIM_RECALL_7 1
  524. #elseif YSIM_IS_SERVER
  525. #define YSIM_RECALL_7 2
  526. #elseif YSIM_CLOUD
  527. #define YSIM_RECALL_7 3
  528. #elseif YSIM_IS_STUB
  529. #define YSIM_RECALL_7 4
  530. #else
  531. #error Undefined master type on 7
  532. #endif
  533. #endif
  534. #define _YCM h@
  535. #elseif MASTER == 8
  536. #if defined _YCM_i@
  537. #define YSIM_DEFINED
  538. #else
  539. #define _YCM_i@
  540. // Save the settings.
  541. #if !YSIM_HAS_MASTER
  542. #define YSIM_RECALL_8 0
  543. #elseif YSIM_IS_CLIENT
  544. #define YSIM_RECALL_8 1
  545. #elseif YSIM_IS_SERVER
  546. #define YSIM_RECALL_8 2
  547. #elseif YSIM_CLOUD
  548. #define YSIM_RECALL_8 3
  549. #elseif YSIM_IS_STUB
  550. #define YSIM_RECALL_8 4
  551. #else
  552. #error Undefined master type on 8
  553. #endif
  554. #endif
  555. #define _YCM i@
  556. #elseif MASTER == 9
  557. #if defined _YCM_j@
  558. #define YSIM_DEFINED
  559. #else
  560. #define _YCM_j@
  561. // Save the settings.
  562. #if !YSIM_HAS_MASTER
  563. #define YSIM_RECALL_9 0
  564. #elseif YSIM_IS_CLIENT
  565. #define YSIM_RECALL_9 1
  566. #elseif YSIM_IS_SERVER
  567. #define YSIM_RECALL_9 2
  568. #elseif YSIM_CLOUD
  569. #define YSIM_RECALL_9 3
  570. #elseif YSIM_IS_STUB
  571. #define YSIM_RECALL_9 4
  572. #else
  573. #error Undefined master type on 9
  574. #endif
  575. #endif
  576. #define _YCM j@
  577. #elseif MASTER == 10
  578. #if defined _YCM_k@
  579. #define YSIM_DEFINED
  580. #else
  581. #define _YCM_k@
  582. // Save the settings.
  583. #if !YSIM_HAS_MASTER
  584. #define YSIM_RECALL_10 0
  585. #elseif YSIM_IS_CLIENT
  586. #define YSIM_RECALL_10 1
  587. #elseif YSIM_IS_SERVER
  588. #define YSIM_RECALL_10 2
  589. #elseif YSIM_CLOUD
  590. #define YSIM_RECALL_10 3
  591. #elseif YSIM_IS_STUB
  592. #define YSIM_RECALL_10 4
  593. #else
  594. #error Undefined master type on 10
  595. #endif
  596. #endif
  597. #define _YCM k@
  598. #elseif MASTER == 11
  599. #if defined _YCM_l@
  600. #define YSIM_DEFINED
  601. #else
  602. #define _YCM_l@
  603. // Save the settings.
  604. #if !YSIM_HAS_MASTER
  605. #define YSIM_RECALL_11 0
  606. #elseif YSIM_IS_CLIENT
  607. #define YSIM_RECALL_11 1
  608. #elseif YSIM_IS_SERVER
  609. #define YSIM_RECALL_11 2
  610. #elseif YSIM_CLOUD
  611. #define YSIM_RECALL_11 3
  612. #elseif YSIM_IS_STUB
  613. #define YSIM_RECALL_11 4
  614. #else
  615. #error Undefined master type on 11
  616. #endif
  617. #endif
  618. #define _YCM l@
  619. #elseif MASTER == 12
  620. #if defined _YCM_m@
  621. #define YSIM_DEFINED
  622. #else
  623. #define _YCM_m@
  624. // Save the settings.
  625. #if !YSIM_HAS_MASTER
  626. #define YSIM_RECALL_12 0
  627. #elseif YSIM_IS_CLIENT
  628. #define YSIM_RECALL_12 1
  629. #elseif YSIM_IS_SERVER
  630. #define YSIM_RECALL_12 2
  631. #elseif YSIM_CLOUD
  632. #define YSIM_RECALL_12 3
  633. #elseif YSIM_IS_STUB
  634. #define YSIM_RECALL_12 4
  635. #else
  636. #error Undefined master type on 12
  637. #endif
  638. #endif
  639. #define _YCM m@
  640. #elseif MASTER == 13
  641. #if defined _YCM_n@
  642. #define YSIM_DEFINED
  643. #else
  644. #define _YCM_n@
  645. // Save the settings.
  646. #if !YSIM_HAS_MASTER
  647. #define YSIM_RECALL_13 0
  648. #elseif YSIM_IS_CLIENT
  649. #define YSIM_RECALL_13 1
  650. #elseif YSIM_IS_SERVER
  651. #define YSIM_RECALL_13 2
  652. #elseif YSIM_CLOUD
  653. #define YSIM_RECALL_13 3
  654. #elseif YSIM_IS_STUB
  655. #define YSIM_RECALL_13 4
  656. #else
  657. #error Undefined master type on 13
  658. #endif
  659. #endif
  660. #define _YCM n@
  661. #elseif MASTER == 14
  662. #if defined _YCM_o@
  663. #define YSIM_DEFINED
  664. #else
  665. #define _YCM_o@
  666. // Save the settings.
  667. #if !YSIM_HAS_MASTER
  668. #define YSIM_RECALL_14 0
  669. #elseif YSIM_IS_CLIENT
  670. #define YSIM_RECALL_14 1
  671. #elseif YSIM_IS_SERVER
  672. #define YSIM_RECALL_14 2
  673. #elseif YSIM_CLOUD
  674. #define YSIM_RECALL_14 3
  675. #elseif YSIM_IS_STUB
  676. #define YSIM_RECALL_14 4
  677. #else
  678. #error Undefined master type on 14
  679. #endif
  680. #endif
  681. #define _YCM o@
  682. #elseif MASTER == 15
  683. #if defined _YCM_p@
  684. #define YSIM_DEFINED
  685. #else
  686. #define _YCM_p@
  687. // Save the settings.
  688. #if !YSIM_HAS_MASTER
  689. #define YSIM_RECALL_15 0
  690. #elseif YSIM_IS_CLIENT
  691. #define YSIM_RECALL_15 1
  692. #elseif YSIM_IS_SERVER
  693. #define YSIM_RECALL_15 2
  694. #elseif YSIM_CLOUD
  695. #define YSIM_RECALL_15 3
  696. #elseif YSIM_IS_STUB
  697. #define YSIM_RECALL_15 4
  698. #else
  699. #error Undefined master type on 15
  700. #endif
  701. #endif
  702. #define _YCM p@
  703. #elseif MASTER == 16
  704. #if defined _YCM_q@
  705. #define YSIM_DEFINED
  706. #else
  707. #define _YCM_q@
  708. // Save the settings.
  709. #if !YSIM_HAS_MASTER
  710. #define YSIM_RECALL_16 0
  711. #elseif YSIM_IS_CLIENT
  712. #define YSIM_RECALL_16 1
  713. #elseif YSIM_IS_SERVER
  714. #define YSIM_RECALL_16 2
  715. #elseif YSIM_CLOUD
  716. #define YSIM_RECALL_16 3
  717. #elseif YSIM_IS_STUB
  718. #define YSIM_RECALL_16 4
  719. #else
  720. #error Undefined master type on 16
  721. #endif
  722. #endif
  723. #define _YCM q@
  724. #elseif MASTER == 17
  725. #if defined _YCM_r@
  726. #define YSIM_DEFINED
  727. #else
  728. #define _YCM_r@
  729. // Save the settings.
  730. #if !YSIM_HAS_MASTER
  731. #define YSIM_RECALL_17 0
  732. #elseif YSIM_IS_CLIENT
  733. #define YSIM_RECALL_17 1
  734. #elseif YSIM_IS_SERVER
  735. #define YSIM_RECALL_17 2
  736. #elseif YSIM_CLOUD
  737. #define YSIM_RECALL_17 3
  738. #elseif YSIM_IS_STUB
  739. #define YSIM_RECALL_17 4
  740. #else
  741. #error Undefined master type on 17
  742. #endif
  743. #endif
  744. #define _YCM r@
  745. #elseif MASTER == 18
  746. #if defined _YCM_s@
  747. #define YSIM_DEFINED
  748. #else
  749. #define _YCM_s@
  750. // Save the settings.
  751. #if !YSIM_HAS_MASTER
  752. #define YSIM_RECALL_18 0
  753. #elseif YSIM_IS_CLIENT
  754. #define YSIM_RECALL_18 1
  755. #elseif YSIM_IS_SERVER
  756. #define YSIM_RECALL_18 2
  757. #elseif YSIM_CLOUD
  758. #define YSIM_RECALL_18 3
  759. #elseif YSIM_IS_STUB
  760. #define YSIM_RECALL_18 4
  761. #else
  762. #error Undefined master type on 18
  763. #endif
  764. #endif
  765. #define _YCM s@
  766. #elseif MASTER == 19
  767. #if defined _YCM_t@
  768. #define YSIM_DEFINED
  769. #else
  770. #define _YCM_t@
  771. // Save the settings.
  772. #if !YSIM_HAS_MASTER
  773. #define YSIM_RECALL_19 0
  774. #elseif YSIM_IS_CLIENT
  775. #define YSIM_RECALL_19 1
  776. #elseif YSIM_IS_SERVER
  777. #define YSIM_RECALL_19 2
  778. #elseif YSIM_CLOUD
  779. #define YSIM_RECALL_19 3
  780. #elseif YSIM_IS_STUB
  781. #define YSIM_RECALL_19 4
  782. #else
  783. #error Undefined master type on 19
  784. #endif
  785. #endif
  786. #define _YCM t@
  787. #elseif MASTER == 20
  788. #if defined _YCM_u@
  789. #define YSIM_DEFINED
  790. #else
  791. #define _YCM_u@
  792. // Save the settings.
  793. #if !YSIM_HAS_MASTER
  794. #define YSIM_RECALL_20 0
  795. #elseif YSIM_IS_CLIENT
  796. #define YSIM_RECALL_20 1
  797. #elseif YSIM_IS_SERVER
  798. #define YSIM_RECALL_20 2
  799. #elseif YSIM_CLOUD
  800. #define YSIM_RECALL_20 3
  801. #elseif YSIM_IS_STUB
  802. #define YSIM_RECALL_20 4
  803. #else
  804. #error Undefined master type on 20
  805. #endif
  806. #endif
  807. #define _YCM u@
  808. #elseif MASTER == 21
  809. #if defined _YCM_v@
  810. #define YSIM_DEFINED
  811. #else
  812. #define _YCM_v@
  813. // Save the settings.
  814. #if !YSIM_HAS_MASTER
  815. #define YSIM_RECALL_21 0
  816. #elseif YSIM_IS_CLIENT
  817. #define YSIM_RECALL_21 1
  818. #elseif YSIM_IS_SERVER
  819. #define YSIM_RECALL_21 2
  820. #elseif YSIM_CLOUD
  821. #define YSIM_RECALL_21 3
  822. #elseif YSIM_IS_STUB
  823. #define YSIM_RECALL_21 4
  824. #else
  825. #error Undefined master type on 21
  826. #endif
  827. #endif
  828. #define _YCM v@
  829. #elseif MASTER == 22
  830. #if defined _YCM_w@
  831. #define YSIM_DEFINED
  832. #else
  833. #define _YCM_w@
  834. // Save the settings.
  835. #if !YSIM_HAS_MASTER
  836. #define YSIM_RECALL_22 0
  837. #elseif YSIM_IS_CLIENT
  838. #define YSIM_RECALL_22 1
  839. #elseif YSIM_IS_SERVER
  840. #define YSIM_RECALL_22 2
  841. #elseif YSIM_CLOUD
  842. #define YSIM_RECALL_22 3
  843. #elseif YSIM_IS_STUB
  844. #define YSIM_RECALL_22 4
  845. #else
  846. #error Undefined master type on 22
  847. #endif
  848. #endif
  849. #define _YCM w@
  850. #elseif MASTER == 23
  851. #if defined _YCM_x@
  852. #define YSIM_DEFINED
  853. #else
  854. #define _YCM_x@
  855. // Save the settings.
  856. #if !YSIM_HAS_MASTER
  857. #define YSIM_RECALL_23 0
  858. #elseif YSIM_IS_CLIENT
  859. #define YSIM_RECALL_23 1
  860. #elseif YSIM_IS_SERVER
  861. #define YSIM_RECALL_23 2
  862. #elseif YSIM_CLOUD
  863. #define YSIM_RECALL_23 3
  864. #elseif YSIM_IS_STUB
  865. #define YSIM_RECALL_23 4
  866. #else
  867. #error Undefined master type on 23
  868. #endif
  869. #endif
  870. #define _YCM x@
  871. #elseif MASTER == 24
  872. #if defined _YCM_y@
  873. #define YSIM_DEFINED
  874. #else
  875. #define _YCM_y@
  876. // Save the settings.
  877. #if !YSIM_HAS_MASTER
  878. #define YSIM_RECALL_24 0
  879. #elseif YSIM_IS_CLIENT
  880. #define YSIM_RECALL_24 1
  881. #elseif YSIM_IS_SERVER
  882. #define YSIM_RECALL_24 2
  883. #elseif YSIM_CLOUD
  884. #define YSIM_RECALL_24 3
  885. #elseif YSIM_IS_STUB
  886. #define YSIM_RECALL_24 4
  887. #else
  888. #error Undefined master type on 24
  889. #endif
  890. #endif
  891. #define _YCM y@
  892. #elseif MASTER == 25
  893. #if defined _YCM_z@
  894. #define YSIM_DEFINED
  895. #else
  896. #define _YCM_z@
  897. // Save the settings.
  898. #if !YSIM_HAS_MASTER
  899. #define YSIM_RECALL_25 0
  900. #elseif YSIM_IS_CLIENT
  901. #define YSIM_RECALL_25 1
  902. #elseif YSIM_IS_SERVER
  903. #define YSIM_RECALL_25 2
  904. #elseif YSIM_CLOUD
  905. #define YSIM_RECALL_25 3
  906. #elseif YSIM_IS_STUB
  907. #define YSIM_RECALL_25 4
  908. #else
  909. #error Undefined master type on 25
  910. #endif
  911. #endif
  912. #define _YCM z@
  913. #endif
  914. // Check for non-unique masters here.
  915. #if defined YSIM_DEFINED && !defined _YSIM_OVERRIDE
  916. #error Non-unique master used.
  917. #endif
  918. #if YSIM_NOT_CLIENT && !defined YSIM_DEFINED
  919. // FIRST declare the next callback in the chain.
  920. //#if defined FILTERSCRIPT
  921. // public OnFilterScriptInit()
  922. //#else
  923. // public OnGameModeInit()
  924. //#endif
  925. public OnMasterSystemInit()
  926. {
  927. P:1(#_YCM "_OGM");
  928. // THEN rename the callbacks.
  929. #if defined _YCM_CALLBACK
  930. #undef _YCM_CALLBACK
  931. #endif
  932. #if MASTER == 0
  933. #define _YCM_CALLBACK a@OnScriptInit
  934. #endif
  935. #if MASTER == 1
  936. #define _YCM_CALLBACK b@OnScriptInit
  937. #endif
  938. #if MASTER == 2
  939. #define _YCM_CALLBACK c@OnScriptInit
  940. #endif
  941. #if MASTER == 3
  942. #define _YCM_CALLBACK d@OnScriptInit
  943. #endif
  944. #if MASTER == 4
  945. #define _YCM_CALLBACK e@OnScriptInit
  946. #endif
  947. #if MASTER == 5
  948. #define _YCM_CALLBACK f@OnScriptInit
  949. #endif
  950. #if MASTER == 6
  951. #define _YCM_CALLBACK g@OnScriptInit
  952. #endif
  953. #if MASTER == 7
  954. #define _YCM_CALLBACK h@OnScriptInit
  955. #endif
  956. #if MASTER == 8
  957. #define _YCM_CALLBACK i@OnScriptInit
  958. #endif
  959. #if MASTER == 9
  960. #define _YCM_CALLBACK j@OnScriptInit
  961. #endif
  962. #if MASTER == 10
  963. #define _YCM_CALLBACK k@OnScriptInit
  964. #endif
  965. #if MASTER == 11
  966. #define _YCM_CALLBACK l@OnScriptInit
  967. #endif
  968. #if MASTER == 12
  969. #define _YCM_CALLBACK m@OnScriptInit
  970. #endif
  971. #if MASTER == 13
  972. #define _YCM_CALLBACK n@OnScriptInit
  973. #endif
  974. #if MASTER == 14
  975. #define _YCM_CALLBACK o@OnScriptInit
  976. #endif
  977. #if MASTER == 15
  978. #define _YCM_CALLBACK p@OnScriptInit
  979. #endif
  980. #if MASTER == 16
  981. #define _YCM_CALLBACK q@OnScriptInit
  982. #endif
  983. #if MASTER == 17
  984. #define _YCM_CALLBACK r@OnScriptInit
  985. #endif
  986. #if MASTER == 18
  987. #define _YCM_CALLBACK s@OnScriptInit
  988. #endif
  989. #if MASTER == 19
  990. #define _YCM_CALLBACK t@OnScriptInit
  991. #endif
  992. #if MASTER == 20
  993. #define _YCM_CALLBACK u@OnScriptInit
  994. #endif
  995. #if MASTER == 21
  996. #define _YCM_CALLBACK v@OnScriptInit
  997. #endif
  998. #if MASTER == 22
  999. #define _YCM_CALLBACK w@OnScriptInit
  1000. #endif
  1001. #if MASTER == 23
  1002. #define _YCM_CALLBACK x@OnScriptInit
  1003. #endif
  1004. #if MASTER == 24
  1005. #define _YCM_CALLBACK y@OnScriptInit
  1006. #endif
  1007. #if MASTER == 25
  1008. #define _YCM_CALLBACK z@OnScriptInit
  1009. #endif
  1010. #if YSIM_IS_SERVER
  1011. // Steal the master.
  1012. _Master_Get(#_YCM, true);
  1013. CallRemoteFunction(#_YCM, "");
  1014. #else
  1015. #if YSIM_CLOUD
  1016. // Determine the next unique name,
  1017. // See if this script should be master.
  1018. if (_Master_Get(#_YCM))
  1019. {
  1020. P:2("Got master " #_YCM);
  1021. state _YCM:y;
  1022. }
  1023. else
  1024. {
  1025. state _YCM:n;
  1026. }
  1027. #endif
  1028. #endif
  1029. // FINALLY call the new next one.
  1030. CallLocalFunction(#_YCM_CALLBACK, "");
  1031. }
  1032. // Don't need extra checks here as we KNOW it is already defined.
  1033. #undef OnMasterSystemInit
  1034. #define OnMasterSystemInit _YCM_CALLBACK
  1035. forward _YCM_CALLBACK();
  1036. #endif
  1037. // There are the following remote function definitions:
  1038. //
  1039. // RF - A basic function.
  1040. // RF@p - A function with special parameters which need passing hints.
  1041. // RF@c - A function with lots of paramteres that needs special code.
  1042. // RF@v - A function with no return value.
  1043. // RF@t - A function with a tag result.
  1044. // RC - A callback function.
  1045. // RH - A y_hooks hook.
  1046. // RS - Return a string.
  1047. //
  1048. //
  1049. // Supported combinations:
  1050. //
  1051. // pc, cp
  1052. // pcv, pvc, cpv, cvp, vpc, vcp
  1053. // pv, vp
  1054. // cv, vc
  1055. // cpt ctp pct ptc tcp tpc
  1056. // ct tc
  1057. // pt tp
  1058. //
  1059. // p and c are for special parameter sets, n is for no parameters, so those two
  1060. // groups can never be mixed together. t is for tag result and v is for no
  1061. // return, so they can never be used together.
  1062. //
  1063. // Note that the callback thing won't work with OnPlayerCommandText as it has a
  1064. // different default return to everything else.
  1065. //
  1066. // These parts are redefined every time the master system is included.
  1067. #if YSIM_HAS_MASTER
  1068. #if YSIM_IS_CLIENT
  1069. // Defined the functions as remote calling stubs. Then rename the
  1070. // following code with a name unlikely to ever be used and define the
  1071. // functions as stock so the compiler removes all the code quietly.
  1072. #define RF:%1[%2](%3) stock %1(%3)return U@(8,YSIM_CALLER,_@),W@(#@%1,#%2#x,%3),U@(8,YSIM_CALLER,-1),V@(8,YSIM_RETURN);stock _@%1(%3)
  1073. #define RF@p:%1[%2](%3)<%4> stock %1(%3)return U@(8,YSIM_CALLER,_@),W@(#@%1,#%2,%4),U@(8,YSIM_CALLER,-1),V@(8,YSIM_RETURN);stock _@%1(%3)
  1074. #define RF@c RF
  1075. #define RF@v:%1[%2](%3) stock %1(%3)U@(8,YSIM_CALLER,_@),W@(#@%1,#%2#x,%3),U@(8,YSIM_CALLER,-1);stock _@%1(%3)
  1076. //#define RF@n:%1[]() stock %1()return U@(8,YSIM_CALLER,_@),W@(#@%1,""),U@(8,YSIM_CALLER,-1),V@(8,YSIM_RETURN);stock _@%1()
  1077. #define RF@pc RF@p
  1078. #define RF@pv:%1[%2](%3)<%4> stock %1(%3)U@(8,YSIM_CALLER,_@),W@(#@%1,#%2,%4),U@(8,YSIM_CALLER,-1);stock _@%1(%3)
  1079. #define RF@pcv RF@pv
  1080. #define RF@vc RF@v
  1081. //#define RF@vn:%1[]() stock %1()U@(8,YSIM_CALLER,_@),W@(#@%1,""),U@(8,YSIM_CALLER,-1);stock _@%1()
  1082. #define RF@t:%0:%1[%2](%3) stock %0:%1(%3)return U@(8,YSIM_CALLER,_@),W@(#@%1,#%2#x,%3),U@(8,YSIM_CALLER,-1),%0:V@(8,YSIM_RETURN);stock %0:_@%1(%3)
  1083. #define RF@pt:%0:%1[%2](%3)<%4> stock %0:%1(%3)return U@(8,YSIM_CALLER,_@),W@(#@%1,#%2,%4),U@(8,YSIM_CALLER,-1),%0:V@(8,YSIM_RETURN);stock %0:_@%1(%3)
  1084. #define RF@ct RF@t
  1085. //#define RF@nt:%0:%1[]() stock %0:%1()return U@(8,YSIM_CALLER,_@),W@(#@%1,""),U@(8,YSIM_CALLER,-1),%0:V@(8,YSIM_RETURN);stock %0:_@%1()
  1086. #define RF@pct RF@pt
  1087. #define RS:%1[%2](%3) stock %1(%3)return Y@(),W@(#@%1,#%2#x,%3),S@(),Q@;stock _@%1(%3)
  1088. #define RS@p:%1[%2](%3)<%4> stock %1(%3)return Y@(),W@(#@%1,#%2,%4),S@(),Q@;stock _@%1(%3)
  1089. //#define RC:%1(%3) stock _@%1(%3)
  1090. //#define RC@v RC
  1091. #define RH:%1_On%2(%3) stock _yH@%2_%1(%3)
  1092. #define RT:%0[%1](%2) stock _yT@%1_%0()
  1093. #if MASTER == 23
  1094. // Less strict (implicit user master).
  1095. #define RC:%0(%1) @yC_%0(a,b[],c,i);@yC_%0(a,b[],c,i)i==_@&&U@(8,YSIM_RETURN,_yC@%0(a,b,c));_yC@%0(%1)
  1096. #else
  1097. #define RC:%0(%1) static stock _yC@%0(%1)
  1098. #endif
  1099. //#define RP@v:%1[%2](%3) static stock %1(%3)U@(8,YSIM_CALLER,_@),W@(#@%1,#%2#x,%3),U@(8,YSIM_CALLER,-1);static stock _@%1(%3)
  1100. // Remote local - only calls the local version if we're master,
  1101. // doesn't call the remote version.
  1102. //#define RL:%1[%2](%3) stock %1(%3){}static stock _%1(%3)
  1103. #define RX:%0(%1) stock %0_yX@(%1)
  1104. // Shortcut for y_als hooks.
  1105. #define RA:%0_On%1(%3) public On%1(%3)ALS_CALL<%1> static stock _%0_%1(%3)
  1106. //#define RA:%0_%1[%2](%3) public %1(%3)<>return Bit_GetBit(Bit:gs_ALS,_:ALS_%0)&&P@(#ALS_PREFIX"_"#%2#x,%3),1;public %1(%3)<_YCM:y>
  1107. //#define RA@p:%0_%1[%2](%3)<%4> public %1(%3)ALS_CALL<%1,#%2,%4>static stock _%0_%1(%3)
  1108. //#define RA@p:%0_%1[%2](%3)<%4> public %1(%3)<>return Bit_GetBit(Bit:gs_ALS,_:ALS_%0)&&P@(#ALS_PREFIX"_"#%2,%4),1;public %1(%3)<_YCM:y>
  1109. #define Master_Caller() (-1)
  1110. #else
  1111. #if YSIM_IS_SERVER
  1112. #define RF:%1[%2](%3) @%1(%3);@%1(%3)U@(8,YSIM_RETURN,%1(%3));%1(%3)
  1113. #define RF@p:%1[%2](%3)<%4> @%1(%3);@%1(%3)U@(8,YSIM_RETURN,%1(%4));%1(%3)
  1114. #define RF@c RF
  1115. #define RF@v:%1[%2](%3) @%1(%3);@%1(%3)%1(%3);%1(%3)
  1116. //#define RF@n:%1[]() forward %1R();public %1R()U@(8,YSIM_RETURN,%1());%1()
  1117. #define RF@pc RF@p
  1118. #define RF@pv:%1[%2](%3)<%4> @%1(%3);@%1(%3)%1(%4);%1(%3)
  1119. #define RF@pcv RF@pv
  1120. #define RF@vc RF@v
  1121. //#define RF@vn:%1[]() forward %1R();public %1R()%1();%1()
  1122. #define RF@t:%0:%1[%2](%3) %0:%1(%3);@%1(%3);@%1(%3)U@(8,YSIM_RETURN,_:%1(%3));%0:%1(%3)
  1123. #define RF@pt:%0:%1[%2](%3)<%4> %0:%1(%3);@%1(%3);@%1(%3)U@(8,YSIM_RETURN,_:%1(%4));%0:%1(%3)
  1124. #define RF@ct RF@t
  1125. //#define RF@nt:%0:%1[]() forward %0:%1();forward %1R();public %1R()U@(8,YSIM_RETURN,_:%1());%0:%1()
  1126. #define RF@pct RF@pt
  1127. #define RS:%1[%2](%3) @%1(%3);@%1(%3)R@(%1(%3));%1(%3)
  1128. #define RS@p:%1[%2](%3)<%4> @%1(%3);@%1(%3)R@(%1(%4));%1(%3)
  1129. //#define RC:%1(%3) public %1(%3)
  1130. //#define RC@v RC
  1131. #define RH:%1_On%2(%3) @yH_%2_%1(%3);@yH_%2_%1(%3)
  1132. #define RT:%0[%1](%2) @yT_%1_%0();@yT_%1_%0()
  1133. #if MASTER == 23
  1134. // Less strict (implicit user master).
  1135. #define RC:%0(%1) @yC_%0(a,b[],c,i);@yC_%0(a,b[],c,i)i==_@&&U@(8,YSIM_RETURN,_yC@%0(a,b,c));_yC@%0(%1)
  1136. #else
  1137. #define RC:%0(%1) @yC_%0(a,b[],c);@yC_%0(a,b[],c)U@(8,YSIM_RETURN,yC@_%0(a,b,c));static yC@_%0(%1)
  1138. #endif
  1139. // Remote local - only calls the local version if we're master,
  1140. // doesn't call the remote version.
  1141. //#define RL:%1[%2](%3) %1(%3)
  1142. //#define RP@v:%1[%2](%3) forward @%1(%3);@%1(%3)%1(%3);static %1(%3)
  1143. // Shortcut for y_als hooks.
  1144. #define RA:%0_On%1(%3) public On%1(%3)
  1145. //#define RA@p:%0_%1[%2](%3)<%4> RA:%0_%1[%2](%3)
  1146. #define RX:%0(%1) %0@yX_(%1);public %0@yX_(%1)
  1147. #define Master_Caller() \
  1148. (V@(8,YSIM_CALLER))
  1149. //#define Master_Get(%1) state (_Master_Get(#%1)) ? (%1:y) : (%1:n)
  1150. //#define Master_Init(%1); _Master_Get(#%1);
  1151. #else
  1152. #if YSIM_IS_STUB
  1153. // This is used to provide abstractions between different
  1154. // coders on the same team. Setting a library as a stub means
  1155. // that people without the main implementation can use the code
  1156. // through remote function calls and then the whole code can be
  1157. // integrated in to itself. Example use:
  1158. //
  1159. // #tryinclude "streamer_implementation"
  1160. // #if defined _inc_streamer_implementation
  1161. // #endinput
  1162. // #endif
  1163. //
  1164. // #define YSIM_U_ENABLE
  1165. // #define MASTER 10
  1166. // #include <YSI\y_master>
  1167. //
  1168. // RF@p:CreateObject[ifff](modelid,Float:x,Float:y,Float:z)<modelid,x,y,z>;
  1169. //
  1170. #define RF:%1[%2](%3) stock %1(%3)return U@(8,YSIM_CALLER,_@),W@(#@%1,#%2#x,%3),U@(8,YSIM_CALLER,-1),V@(8,YSIM_RETURN)//;stock _@%1()
  1171. #define RF@p:%1[%2](%3)<%4> stock %1(%3)return U@(8,YSIM_CALLER,_@),W@(#@%1,#%2,%4),U@(8,YSIM_CALLER,-1),V@(8,YSIM_RETURN)//;stock _@%1()
  1172. #define RF@c RF
  1173. #define RF@v:%1[%2](%3) stock %1(%3)U@(8,YSIM_CALLER,_@),W@(#@%1,#%2#x,%3),U@(8,YSIM_CALLER,-1)//;stock _@%1()
  1174. //#define RF@n:%1[]() stock %1()return U@(8,YSIM_CALLER,_@),W@(#@%1,""),U@(8,YSIM_CALLER,-1),V@(8,YSIM_RETURN);stock _@%1()
  1175. #define RF@pc RF@p
  1176. #define RF@pv:%1[%2](%3)<%4> stock %1(%3)U@(8,YSIM_CALLER,_@),W@(#@%1,#%2,%4),U@(8,YSIM_CALLER,-1)//;stock _@%1()
  1177. #define RF@pcv RF@pv
  1178. #define RF@vc RF@v
  1179. //#define RF@vn:%1[]() stock %1()U@(8,YSIM_CALLER,_@),W@(#@%1,""),U@(8,YSIM_CALLER,-1);stock _@%1()
  1180. #define RF@t:%0:%1[%2](%3) stock %0:%1(%3)return U@(8,YSIM_CALLER,_@),W@(#@%1,#%2#x,%3),U@(8,YSIM_CALLER,-1),%0:V@(8,YSIM_RETURN)//;stock _@%1()
  1181. #define RF@pt:%0:%1[%2](%3)<%4> stock %0:%1(%3)return U@(8,YSIM_CALLER,_@),W@(#@%1,#%2,%4),U@(8,YSIM_CALLER,-1),%0:V@(8,YSIM_RETURN)//;stock _@%1()
  1182. #define RF@ct RF@t
  1183. //#define RF@nt:%0:%1[]() stock %0:%1()return U@(8,YSIM_CALLER,_@),W@(#@%1,""),U@(8,YSIM_CALLER,-1),%0:V@(8,YSIM_RETURN);stock %0:_@%1()
  1184. #define RF@pct RF@pt
  1185. // Doesn't have the end bit as the function isn't included.
  1186. #define RS:%1[%2](%3) stock %1(%3)return Y@(),W@(#@%1,#%2#x,%3),S@(),Q@//;stock _@%1()
  1187. #define RS@p:%1[%2](%3)<%4> stock %1(%3)return Y@(),W@(#@%1,#%2,%4),S@(),Q@//;stock _@%1()
  1188. // NOT DEFINED! Should not be used if this is a stub.
  1189. #define RC
  1190. // NOT DEFINED! Should not be used if this is a stub.
  1191. //#define RC@v
  1192. // NOT DEFINED! Should not be used if this is a stub.
  1193. #define RH
  1194. // NOT DEFINED! Should not be used if this is a stub.
  1195. #define RT
  1196. // Remote local - only calls the local version if we're master,
  1197. // doesn't call the remote version.
  1198. //#define RL:%1[%2](%3)
  1199. #define RX
  1200. //#define RP@v
  1201. // Shortcut for y_als hooks.
  1202. #define RA //:%0_%1(%3)
  1203. //#define RA@p:%0_%1[%2](%3)<%4>
  1204. // NOT DEFINED! Should not be used if this is a stub.
  1205. #define Master_Caller
  1206. #else
  1207. // This is a normal system with the possibility of being the
  1208. // master. This is the very complicated one to write!
  1209. #define RF:%1[%2](%3) @%1(%3);@%1(%3)<>{}@%1(%3)<_YCM:y>U@(8,YSIM_RETURN,%1(%3));%1(%3)<>return U@(8,YSIM_CALLER,_@),W@(#@%1,#%2#x,%3),U@(8,YSIM_CALLER,-1),V@(8,YSIM_RETURN);%1(%3)<_YCM:y>
  1210. #define RF@p:%1[%2](%3)<%4> @%1(%3);@%1(%3)<>{}@%1(%3)<_YCM:y>U@(8,YSIM_RETURN,%1(%4));%1(%3)<>return U@(8,YSIM_CALLER,_@),W@(#@%1,#%2,%4),U@(8,YSIM_CALLER,-1),V@(8,YSIM_RETURN);%1(%3)<_YCM:y>
  1211. #define RF@c:%1[%2](%3) @%1(%3);@%1(%3)<>{}@%1(%3)<_YCM:y>X@(%1(%3));%1(%3)<>return Y@(),W@(#@%1,#%2#x,%3),Z@();%1(%3)<_YCM:y>
  1212. #define RF@v:%1[%2](%3) @%1(%3);@%1(%3)<>{}@%1(%3)<_YCM:y>%1(%3);%1(%3)<>U@(8,YSIM_CALLER,_@),W@(#@%1,#%2#x,%3),U@(8,YSIM_CALLER,-1);%1(%3)<_YCM:y>
  1213. //#define RF@n:%1[]() forward %1R();public %1R()<>{}public %1R()<_YCM:y>U@(8,YSIM_RETURN,%1());%1()<>return U@(8,YSIM_CALLER,_@),W@(#@%1,""),U@(8,YSIM_CALLER,-1),V@(8,YSIM_RETURN);%1()<_YCM:y>
  1214. #define RF@pc:%1[%2](%3)<%4> @%1(%3);@%1(%3)<>{}@%1(%3)<_YCM:y>X@(%1(%4));%1(%3)<>return Y@(),W@(#@%1,#%2,%4),Z@();%1(%3)<_YCM:y>
  1215. #define RF@pv:%1[%2](%3)<%4> @%1(%3);@%1(%3)<>{}@%1(%3)<_YCM:y>%1(%4);%1(%3)<>U@(8,YSIM_CALLER,_@),W@(#@%1,#%2,%4),U@(8,YSIM_CALLER,-1);%1(%3)<_YCM:y>
  1216. #define RF@pcv:%1[%2](%3)<%4> @%1(%3);@%1(%3)<>{}@%1(%3)<_YCM:y>%1(%4);%1(%3)<>Y@(),W@(#@%1,#%2,%4),T@();%1(%3)<_YCM:y>
  1217. #define RF@vc:%1[%2](%3) @%1(%3);@%1(%3)<>{}@%1(%3)<_YCM:y>%1(%3);%1(%3)<>Y@(),W@(#@%1,#%2#x,%3),T@();%1(%3)<_YCM:y>
  1218. //#define RF@vn:%1[]() forward %1R();public %1R()<>{}public %1R()<_YCM:y>%1();%1()<>U@(8,YSIM_CALLER,_@),W@(#@%1,""),U@(8,YSIM_CALLER,-1);%1()<_YCM:y>
  1219. #define RF@t:%0:%1[%2](%3) %0:%1(%3);@%1(%3);@%1(%3)<>{}@%1(%3)<_YCM:y>U@(8,YSIM_RETURN,_:%1(%3));%0:%1(%3)<>return U@(8,YSIM_CALLER,_@),W@(#@%1,#%2#x,%3),U@(8,YSIM_CALLER,-1),%0:V@(8,YSIM_RETURN);%0:%1(%3)<_YCM:y>
  1220. #define RF@pt:%0:%1[%2](%3)<%4> %0:%1(%3);@%1(%3);@%1(%3)<>{}@%1(%3)<_YCM:y>U@(8,YSIM_RETURN,_:%1(%4));%0:%1(%3)<>return U@(8,YSIM_CALLER,_@),W@(#@%1,#%2,%4),U@(8,YSIM_CALLER,-1),%0:V@(8,YSIM_RETURN);%0:%1(%3)<_YCM:y>
  1221. #define RF@ct:%0:%1[%2](%3) %0:%1(%3);@%1(%3);@%1(%3)<>{}@%1(%3)<_YCM:y>X@(_:%1(%3));%0:%1(%3)<>return Y@(),W@(#@%1,#%2#x,%3),%0:Z@();%0:%1(%3)<_YCM:y>
  1222. //#define RF@nt:%0:%1[]() forward %0:%1();forward %1R();public %1R()<>{}public %1R()<_YCM:y>U@(8,YSIM_RETURN,_:%1());%0:%1()<>return U@(8,YSIM_CALLER,_@),W@(#@%1,""),U@(8,YSIM_CALLER,-1),%0:V@(8,YSIM_RETURN);%0:%1()<_YCM:y>
  1223. #define RF@pct:%0:%1[%2](%3)<%4> %0:%1(%3);@%1(%3);@%1(%3)<>{}@%1(%3)<_YCM:y>X@(_:%1(%4));%0:%1(%3)<>return Y@(),W@(#@%1,#%2,%4),%0:Z@();%0:%1(%3)<_YCM:y>
  1224. //#define RS:%1[%2](%3) forward %1R(%3);public %1R(%3)<>{}public %1R(%3)<_YCM:y>R@(%1(%3));%1(%3)<>return Y@(),W@(#@%1,#%2#x,%3),S@();%1(%3)<_YCM:y>
  1225. // Remote STRING (returns a string).
  1226. #define RS:%1[%2](%3) @%1(%3);@%1(%3)<>{}@%1(%3)<_YCM:y>R@(%1(%3));%1(%3)<>return Y@(),W@(#@%1,#%2#x,%3),S@(),Q@;%1(%3)<_YCM:y>
  1227. #define RS@p:%1[%2](%3)<%4> @%1(%3);@%1(%3)<>{}@%1(%3)<_YCM:y>R@(%1(%4));%1(%3)<>return Y@(),W@(#@%1,#%2,%4),S@(),Q@;%1(%3)<_YCM:y>
  1228. //#define RC:%1(%3) public %1(%3)<>return 1;public %1(%3)<_YCM:y>
  1229. //#define RC@v:%1(%3) public %1(%3)<>{}public %1(%3)<_YCM:y>
  1230. // Requires the y_hooks library.
  1231. #define RH:%1_On%2(%3) @yH_%2_%1(%3);@yH_%2_%1(%3)<>return 1;@yH_%2_%1(%3)<_YCM:y>
  1232. // Requires the y_timers library.
  1233. #define RT:%0[%1](%2) @yT_%1_%0();@yT_%1_%0()<>{}@yT_%1_%0()<_YCM:y>
  1234. /*#if
  1235. #define RC:%0(%1) forward @yC_%0(a,b[],c);@yC_%0(a,b[],c)<>{}@yC_%0(a,b[],c)<_YCM:y>U@(8,YSIM_RETURN,_yC@%0(a,b,c));_yC@%0(%1)
  1236. #else
  1237. // This code defines two publics so that if the master
  1238. // doesn't have a copy of the command it can still be called
  1239. // in another running script.
  1240. #define RC:%0(%1) forward @yC_%0(a,b[],c);forward @_yC%0(i,a,b,c[]);@yC_%0(a,b[],c)<>{}@yC_%0(a,b[],c)<_YCM:y>U@(8,YSIM_RETURN,_yC@%0(a,b,c));@_yC%0(i,a,b,c[])return i==_@&&U@(8,YSIM_RETURN,_yC@%0(a,b,c));_yC@%0(%1)
  1241. #endif*/
  1242. //#if defined _YSIM_USED_AUTO
  1243. #if MASTER == 23
  1244. // Less strict (implicit user master).
  1245. #define RC:%0(%1) @yC_%0(a,b[],c,i);@yC_%0(a,b[],c,i)i==_@&&U@(8,YSIM_RETURN,_yC@%0(a,b,c));_yC@%0(%1)
  1246. #else
  1247. // Strict libraries.
  1248. #define RC:%0(%1) @yC_%0(a,b[],c);@yC_%0(a,b[],c)<>{}@yC_%0(a,b[],c)<_YCM:y>U@(8,YSIM_RETURN,_yC@%0(a,b,c));_yC@%0(%1)
  1249. #endif
  1250. //#define RP@v:%1[%2](%3) forward @%1(%3);@%1(%3)<>{}@%1(%3)<_YCM:y>%1(%3);static %1(%3)<>U@(8,YSIM_CALLER,_@),W@(#@%1,#%2#x,%3),U@(8,YSIM_CALLER,-1);static %1(%3)<_YCM:y>
  1251. #define Master_Caller() \
  1252. ((V@(8,YSIM_CALLER)==-1)?(_@):(V@(8,YSIM_CALLER)))
  1253. // Remote local - only calls the local version if we're master,
  1254. // doesn't call the remote version.
  1255. //#define RL:%1[%2](%3) %1(%3)<>return 1;%1(%3)<_YCM:y>
  1256. #define RX:%0(%1) %0@yX_(%1);public %0@yX_(%1)<>{}public %0@yX_(%1)<_YCM:y>
  1257. // Shortcut for y_als hooks.
  1258. //#define RA:%0_%1(%3) public %1(%3)<>ALS_CALL<%1>public %1(%3)<_YCM:y>
  1259. #define RA:%0_On%1(%3) public On%1(%3)<>ALS_CALL<%1> public On%1(%3)<_YCM:y>
  1260. //#define RA:%0_%1[%2](%3) public %1(%3)<>return Bit_GetBit(Bit:gs_ALS,_:ALS_%0)&&P@(#ALS_PREFIX"_"#%2#x,%3),1;public %1(%3)<_YCM:y>
  1261. //#define RA@p:%0_%1[%2](%3)<%4> public %1(%3)<>ALS_CALL<%1,#%2,%4>public %1(%3)<_YCM:y>
  1262. //#define Master_Get(%1) state (_Master_Get(#%1)) ? (%1:y) : (%1:n)
  1263. //#define Master_Init(%1); if (_Master_Get(#%1)) state %1:y; else state %1:n;
  1264. #endif
  1265. #endif
  1266. #endif
  1267. #else
  1268. // Master system isn't used.
  1269. #define RF:%1[%2](%3) stock %1(%3)
  1270. #define RF@p:%1[%2](%3)<%4> RF:%1[%2](%3)
  1271. #define RF@c RF
  1272. #define RF@v RF
  1273. //#define RF@n RF
  1274. #define RF@pc RF@p
  1275. #define RF@pv RF@p
  1276. #define RF@pcv RF@p
  1277. #define RF@vc RF
  1278. //#define RF@vn RF
  1279. #define RF@t:%0:%1[%2](%3) stock %0:%1(%3)
  1280. #define RF@pt:%0:%1[%2](%3)<%4> RF@t:%0:%1[%2](%3)
  1281. #define RF@ct RF@t
  1282. //#define RF@nt RF@t
  1283. #define RF@pct RF@p
  1284. #define RS:%1[%2](%3) stock %1(%3)
  1285. #define RS@p:%1[%2](%3)<%4> stock %1(%3)
  1286. #define RS@c RS
  1287. #define RS@pc RS@p
  1288. //#define RC:%1(%3) public %1(%3)
  1289. //#define RC@v: RC
  1290. #define RT:%0[%1](%2) @yT_%1_%0();@yT_%1_%0()
  1291. //#define RP@v:%0[%1](%2) static stock %0(%2)
  1292. #define RH:%1_On%2(%3) @yH_%2_%1(%3);public @yH_%2_%1(%3)
  1293. #define RC:%0(%1) @yC_%0(%1);@yC_%0(%1)
  1294. #define RX:%0(%1) %0@yX_(%1);public %0@yX_(%1)
  1295. #define Master_Caller() (_@)
  1296. // Remote local - only calls the local version if we're master,
  1297. // doesn't call the remote version.
  1298. //#define RL:%1[%2](%3) stock %1(%3)
  1299. // Shortcut for y_als hooks.
  1300. #define RA:%0_On%1(%3) public On%1(%3)
  1301. //#define RA@p:%0_%1[%2](%3)<%4> RA:%0_%1[%2](%3)
  1302. //#define Master_Init(%1);
  1303. #endif
  1304. // Undefine this before the next call.
  1305. #undef MASTER
  1306. #if YSIM_CLOUD && !defined YSIM_DEFINED
  1307. // Define a load of fake functions to cater for the compiler's need to
  1308. // know all the possible states. y means master, n means not master, m
  1309. // means master system missing, p means previous (ending master), u
  1310. // means sort of uninitialised (though technically initialised). This
  1311. // also doubles as a handy call in function for resetting masters when a
  1312. // script ends. Just to clarify - this function is NOT called _YCM,
  1313. // that is a macro which is expanded every time this file is included.
  1314. forward _YCM();
  1315. public _YCM() <_YCM:y>
  1316. {
  1317. if (getproperty(8, #_YCM) != _@)
  1318. {
  1319. // Master, but not. A server has claimed this.
  1320. state _YCM:n;
  1321. }
  1322. else
  1323. {
  1324. P:2(#_YCM ":y called");
  1325. // Disable the current mastership.
  1326. state _YCM:p;
  1327. setproperty(8, #_YCM, -1);
  1328. // Called locally to begin the hand off process.
  1329. CallRemoteFunction(#_YCM, "");
  1330. }
  1331. }
  1332. public _YCM() <_YCM:n>
  1333. {
  1334. P:2(#_YCM ":n called");
  1335. // This has been called remotely from a script which owns the
  1336. // library masterhood (that's the only way this can ever be called).
  1337. if (_Master_Get(#_YCM))
  1338. {
  1339. P:2("Got master " #_YCM);
  1340. state _YCM:y;
  1341. }
  1342. }
  1343. public _YCM() <_YCM:m, _YCM:p, _YCM:u>
  1344. {
  1345. P:2(#_YCM ":mpu called");
  1346. // Do nothing at all (just define states).
  1347. }
  1348. public _YCM() <>
  1349. {
  1350. P:2(#_YCM ":<> called");
  1351. if (_Master_Get(#_YCM))
  1352. {
  1353. P:2("Got master " #_YCM);
  1354. state _YCM:y;
  1355. }
  1356. else
  1357. {
  1358. state _YCM:n;
  1359. }
  1360. // Do nothing at all (just define states).
  1361. }
  1362. #endif
  1363. #if defined YSIM_T_ENABLE
  1364. #undef YSIM_T_ENABLE
  1365. #endif
  1366. #if defined YSIM_T_DISABLE
  1367. #undef YSIM_T_DISABLE
  1368. #endif
  1369. #if defined YSIM_C_ENABLE
  1370. #undef YSIM_C_ENABLE
  1371. #endif
  1372. #if defined YSIM_C_DISABLE
  1373. #undef YSIM_C_DISABLE
  1374. #endif
  1375. #if defined YSIM_S_ENABLE
  1376. #undef YSIM_S_ENABLE
  1377. #endif
  1378. #if defined YSIM_S_DISABLE
  1379. #undef YSIM_S_DISABLE
  1380. #endif
  1381. #if defined YSIM_U_ENABLE
  1382. #undef YSIM_U_ENABLE
  1383. #endif
  1384. #if defined YSIM_U_DISABLE
  1385. #undef YSIM_U_DISABLE
  1386. #endif
  1387. // Allow YSI scripts to use the extended master system
  1388. #if defined _YSIM_USED_AUTO
  1389. #undef _YSIM_USED_AUTO
  1390. #endif
  1391. #if defined _YSIM_OVERRIDE
  1392. #undef _YSIM_OVERRIDE
  1393. #endif
  1394. #if defined YSIM_STORED_SETTINGS
  1395. #undef YSIM_STORED_SETTINGS
  1396. #endif