Advertisement
Guest User

Improvement of trams traffic (by Den_spb)

a guest
May 28th, 2011
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.42 KB | None | 0 0
  1. {$CLEO} // Improvement of trams traffic (by Den_spb)
  2. var
  3. 0@: Integer
  4. 1@: Integer
  5. // 2-14 переменные для одноразовых значений
  6. 15@: Integer
  7. 16@: Integer
  8. 17@: Integer
  9. 18@: Float
  10. 19@: Float
  11. 20@: Integer
  12. 21@: Float
  13. 22@: Integer
  14. 23@: Integer
  15. end
  16. const
  17. TRAM = 0@
  18. TRAM_STRUCT = 1@
  19. FLAGS = 15@
  20. PASSENGER_0 = 16@
  21. PASSENGER_1 = 17@
  22. LAST_0BJECT_X = 18@
  23. LAST_0BJECT_Y = 19@
  24. 0BJECT = 20@
  25. Y_DIMENSION = 21@
  26. MAR_KER = 22@
  27. STOPS_C0UNT = 23@
  28. // BIT FLAGS:
  29. MANY_CARRIAGES = 0
  30. AUTODRIVE_OFF = 1
  31. TRAM_IS_STOPPING = 2
  32. CJ_IS_PASSENGER = 3
  33. end
  34. TRAM = -1
  35. 0A8C: write_memory 0x6F7863 size 2 value 0 virtual_protect 1 // при создании трамваев создавать и водителей для них
  36. LAST_0BJECT_X = 50000.0
  37. LAST_0BJECT_Y = 50000.0
  38. while true
  39. wait 0
  40. if or
  41. not player.Defined($PLAYER_CHAR)
  42. $ONMISSION <> 0
  43. then
  44. continue
  45. end
  46. if
  47. 856E: not car TRAM defined
  48. then
  49. if
  50. 8154: not actor $PLAYER_ACTOR in_zone 'SF' // San Fierro
  51. then
  52. continue
  53. end
  54. if
  55. gosub @SEARCH_TRAM
  56. then
  57. marker.CreateAboveCar(MAR_KER TRAM)
  58. 07E0: set_marker MAR_KER type_to 1
  59. 018B: set_marker MAR_KER radar_mode 2
  60. FLAGS = 0
  61. 0A97: TRAM_STRUCT = car TRAM struct
  62. TRAM_STRUCT += 0x5D4
  63. 0A8D: TRAM_STRUCT = read_memory TRAM_STRUCT size 4 virtual_protect 0
  64. 07E4: get_model 449 dimensions_cornerA_to 2@ 3@ 4@ dimensions_cornerB_to 5@ Y_DIMENSION 7@
  65. if
  66. TRAM_STRUCT > 0
  67. then
  68. Y_DIMENSION += 16.0
  69. 08BD: set FLAGS bit MANY_CARRIAGES
  70. else
  71. Y_DIMENSION += 12.0
  72. end
  73. 0209: 8@ = random_int_in_ranges 0 2
  74. if
  75. 8@ == 0
  76. then
  77. 0561: PASSENGER_0 = create_passenger_in_car TRAM seat 0
  78. actor.RemoveReferences(PASSENGER_0)
  79. else
  80. 0561: PASSENGER_1 = create_passenger_in_car TRAM seat 1
  81. actor.RemoveReferences(PASSENGER_1)
  82. end
  83. end
  84. else // tram defined
  85. 0AB5: store_actor $PLAYER_ACTOR closest_vehicle_to 2@ closest_ped_to 3@
  86. if and // посадка игрока в трамвай в качестве водителя или пассажира при нажатии клавиш
  87. 003B: 2@ == TRAM // (int)
  88. $ONMISSION == 0
  89. not actor.Driving($PLAYER_ACTOR)
  90. then
  91. if
  92. 0AB0: key_pressed 219 // [
  93. then
  94. 05CB: AS_actor $PLAYER_ACTOR enter_car TRAM as_driver -1 ms
  95. else
  96. if
  97. 0AB0: key_pressed 221 // ]
  98. then
  99. if
  100. 0431: car TRAM passenger_seat_free 0
  101. then
  102. 05CA: AS_actor $PLAYER_ACTOR enter_car TRAM passenger_seat 0 -1 ms
  103. else
  104. if
  105. 0431: car TRAM passenger_seat_free 1
  106. then
  107. 05CA: AS_actor $PLAYER_ACTOR enter_car TRAM passenger_seat 1 -1 ms
  108. end
  109. end
  110. end
  111. end
  112. end // cj entering tram
  113. 046C: 2@ = car TRAM driver
  114. if
  115. 856D: not actor 2@ defined
  116. then
  117. 08BD: set FLAGS bit AUTODRIVE_OFF
  118. 06DD: set_train TRAM speed 0.0
  119. end
  120. if // выполнение действий при произведённой посадке игрока в трамвай
  121. actor.InCar($PLAYER_ACTOR TRAM)
  122. then
  123. if
  124. 003C: $PLAYER_ACTOR == 2@ // (int)
  125. then
  126. 08BD: set FLAGS bit AUTODRIVE_OFF
  127. 06DD: set_train TRAM speed 0.0
  128. else
  129. if
  130. 88B7: not test FLAGS bit CJ_IS_PASSENGER
  131. then
  132. 08BD: set FLAGS bit CJ_IS_PASSENGER
  133. 0109: player $PLAYER_CHAR money += -5
  134. end
  135. end
  136. else
  137. 08C3: clear FLAGS bit CJ_IS_PASSENGER
  138. end // cj not in tram
  139. if
  140. 88B7: not test FLAGS bit AUTODRIVE_OFF // автоведение включено
  141. then
  142. if
  143. 88B7: not test FLAGS bit TRAM_IS_STOPPING // если не включён процесс остановки перед знаком остановки
  144. then
  145. if
  146. gosub @CHECK_OBSTACLES
  147. then
  148. 06DD: set_train TRAM speed 0.0
  149. { Car.StorePos(TRAM 2@ 3@ 10@) ///////////////////////////////////////////////////////////////////////////////////////////
  150. 10@ += 3.0
  151. 024F: create_corona_with_radius 1.0 type 2 lensflares 0 with_color 255 255 0 at 2@ 3@ 10@ ///////////////////// }
  152. else
  153. Car.StorePos(TRAM 2@ 3@ 10@)
  154. 0407: store_coords_to 5@ 6@ 4@ from_car TRAM with_offset 0.0 -1.0 0.0
  155. 0407: store_coords_to 7@ 8@ 4@ from_car TRAM with_offset 0.0 1.0 0.0
  156. 0509: 4@ = distance_between_XY LAST_0BJECT_X LAST_0BJECT_Y and_XY 5@ 6@
  157. 0509: 9@ = distance_between_XY LAST_0BJECT_X LAST_0BJECT_Y and_XY 7@ 8@
  158. if
  159. 0025: 9@ > 4@ // (float)
  160. then
  161. 0407: store_coords_to LAST_0BJECT_X LAST_0BJECT_Y 4@ from_car TRAM with_offset 0.0 -50000.0 0.0
  162. end
  163. if
  164. gosub @SEARCH_OBJECTS
  165. then
  166. object.StorePos(0BJECT LAST_0BJECT_X LAST_0BJECT_Y 12@)
  167. 06DD: set_train TRAM speed 0.0
  168. { 12@ += 2.0 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  169. 024F: create_corona_with_radius 1.0 type 2 lensflares 0 with_color 0 0 255 at LAST_0BJECT_X LAST_0BJECT_Y 12@ /////// }
  170. else
  171. 06DD: set_train TRAM speed 11.11
  172. end
  173. end
  174. else
  175. if
  176. 01C1: car TRAM stopped
  177. then
  178. if
  179. 32@ < -5000
  180. then
  181. 32@ = -5000
  182. if and
  183. 0431: car TRAM passenger_seat_free 0
  184. 0431: car TRAM passenger_seat_free 1
  185. then
  186. car.StorePos(TRAM 2@ 3@ 4@)
  187. if
  188. gosub @SEARCH_PASSENGERS
  189. then
  190. 0209: 8@ = random_int_in_ranges 0 2
  191. if
  192. 8@ == 0
  193. then
  194. 05CA: AS_actor 5@ enter_car TRAM passenger_seat 0 -1 ms
  195. else
  196. 05CA: AS_actor 5@ enter_car TRAM passenger_seat 1 -1 ms
  197. end
  198. end
  199. else
  200. if
  201. STOPS_C0UNT >= 2
  202. then
  203. 0432: PASSENGER_0 = get_actor_handle_from_car TRAM passenger_seat 0
  204. if and
  205. PASSENGER_0 > 0
  206. // 056D: actor PASSENGER_0 defined
  207. 803C: not $PLAYER_ACTOR == PASSENGER_0 // (int)
  208. then
  209. 0633: AS_actor PASSENGER_0 exit_car
  210. else
  211. 0432: PASSENGER_1 = get_actor_handle_from_car TRAM passenger_seat 1
  212. if and
  213. PASSENGER_1 > 0
  214. // 056D: actor PASSENGER_1 defined
  215. 803C: not $PLAYER_ACTOR == PASSENGER_1 // (int)
  216. then
  217. 0633: AS_actor PASSENGER_1 exit_car
  218. end
  219. end
  220. STOPS_C0UNT = 0
  221. else
  222. STOPS_C0UNT += 1
  223. end
  224. end
  225. else
  226. if
  227. 32@ >= 0
  228. then
  229. 08C3: clear FLAGS bit TRAM_IS_STOPPING
  230. 06DD: set_train TRAM speed 11.11
  231. end
  232. end
  233. end
  234. end // tram is stopping
  235. end // cj is not driver
  236. end // tram defined
  237. end
  238.  
  239. :SEARCH_TRAM // ищем трамвай
  240. 0A8D: 24@ = read_memory 0xB74494 size 4 virtual_protect 0
  241. 000A: 24@ += 0x4
  242. 0A8D: 24@ = read_memory 24@ size 4 virtual_protect 0
  243. for 25@ = 0 to 27904 step 0x100
  244. 0A8D: TRAM = read_memory 24@ size 1 virtual_protect 0
  245. 000A: 24@ += 0x1
  246. if and
  247. 0029: TRAM >= 0x00
  248. 001B: 0x80 > TRAM
  249. then
  250. 005A: TRAM += 25@ // (int)
  251. if
  252. 056E: (check) car TRAM defined
  253. then
  254. if
  255. 0137: car TRAM model == 449
  256. then
  257. 0A97: TRAM_STRUCT = car TRAM struct
  258. TRAM_STRUCT += 0x5D0
  259. 0A8D: TRAM_STRUCT = read_memory TRAM_STRUCT size 4 virtual_protect 0
  260. if
  261. TRAM_STRUCT == 0 // предыдущий вагон отсутствует (данный вагон является нулевым)
  262. then
  263. 0485: return_true
  264. return
  265. end
  266. end
  267. end
  268. end
  269. end
  270. TRAM = -1
  271. 8485: return_false
  272. return
  273.  
  274. :CHECK_OBSTACLES // ищем препятствия перед трамваем
  275. 07E4: get_model 449 dimensions_cornerA_to 2@ 3@ 4@ dimensions_cornerB_to 5@ 8@ 7@
  276. 2@ -= 0.1
  277. 5@ += 0.1
  278. repeat
  279. 0407: store_coords_to 9@ 10@ 11@ from_car TRAM with_offset 2@ 0.0 4@ //1
  280. 0407: store_coords_to 12@ 13@ 14@ from_car TRAM with_offset 2@ Y_DIMENSION 4@
  281. if
  282. 86BD: not no_obstacles_between 9@ 10@ 11@ and 12@ 13@ 14@ solid 0 car 1 actor 1 object 0 particle 0
  283. then
  284. 0485: return_true
  285. return
  286. end
  287. 0407: store_coords_to 9@ 10@ 11@ from_car TRAM with_offset 2@ Y_DIMENSION 4@ //2
  288. 0407: store_coords_to 12@ 13@ 14@ from_car TRAM with_offset 5@ Y_DIMENSION 4@
  289. if
  290. 86BD: not no_obstacles_between 9@ 10@ 11@ and 12@ 13@ 14@ solid 0 car 1 actor 1 object 0 particle 0
  291. then
  292. 0485: return_true
  293. return
  294. end
  295. 0407: store_coords_to 9@ 10@ 11@ from_car TRAM with_offset 5@ 0.0 4@ //3
  296. 0407: store_coords_to 12@ 13@ 14@ from_car TRAM with_offset 5@ Y_DIMENSION 4@
  297. if
  298. 86BD: not no_obstacles_between 9@ 10@ 11@ and 12@ 13@ 14@ solid 0 car 1 actor 1 object 0 particle 0
  299. then
  300. 0485: return_true
  301. return
  302. end
  303. 0407: store_coords_to 9@ 10@ 11@ from_car TRAM with_offset 2@ 8@ 4@ //6
  304. 0407: store_coords_to 12@ 13@ 14@ from_car TRAM with_offset 5@ 8@ 4@
  305. if
  306. 86BD: not no_obstacles_between 9@ 10@ 11@ and 12@ 13@ 14@ solid 0 car 1 actor 1 object 0 particle 0
  307. then
  308. 0485: return_true
  309. return
  310. end
  311. 0087: 3@ = 2@ // (float)
  312. repeat
  313. 0407: store_coords_to 9@ 10@ 11@ from_car TRAM with_offset 3@ 8@ 4@ //поперечн.
  314. 0407: store_coords_to 12@ 13@ 14@ from_car TRAM with_offset 3@ Y_DIMENSION 4@
  315. if
  316. 86BD: not no_obstacles_between 9@ 10@ 11@ and 12@ 13@ 14@ solid 0 car 1 actor 1 object 0 particle 0
  317. then
  318. 0485: return_true
  319. return
  320. end
  321. 3@ += 0.4 // старое значение 0.2
  322. until 0025: 3@ > 5@ // (float)
  323. 4@ += 1.0 // старое значение 0.5
  324. until 0025: 4@ > 7@ // (float)
  325. 8485: return_false
  326. return
  327.  
  328. :SEARCH_PASSENGERS // ищем пассажиров, желающих прокатиться на трамвае
  329. 0A8D: 27@ = read_memory 0xB74490 size 4 virtual_protect 0
  330. 000A: 27@ += 0x4
  331. 0A8D: 27@ = read_memory 27@ size 4 virtual_protect 0
  332. for 28@ = 0 to 35584 step 0x100
  333. 0A8D: 5@ = read_memory 27@ size 1 virtual_protect 0
  334. 000A: 27@ += 0x1
  335. if and
  336. 0029: 5@ >= 0x00
  337. 001B: 0x80 > 5@
  338. then
  339. 005A: 5@ += 28@ // (int)
  340. if and
  341. 056D: (check) actor 5@ defined
  342. 00FF: actor 5@ sphere 0 in_sphere 2@ 3@ 4@ radius 20.0 20.0 20.0 on_foot
  343. 8118: not actor 5@ dead
  344. then
  345. 089F: get_actor 5@ pedtype_to 6@
  346. if or
  347. 6@ == 4
  348. 6@ == 5
  349. then
  350. 080E: get_actor 5@ ped_event_to 6@
  351. if and
  352. 6@ == 13
  353. 803B: not 5@ == $PLAYER_ACTOR // (int)
  354. then
  355. 0485: return_true
  356. return
  357. end
  358. end
  359. end
  360. end
  361. end
  362. 8485: return_false
  363. return
  364.  
  365. :SEARCH_OBJECTS // ищем попутный светофор с запрещающим сигналом или знак трамвайной остановки
  366. 0A8D: 29@ = read_memory 0xB7449C size 4 virtual_protect 0
  367. 000A: 29@ += 0x4
  368. 0A8D: 29@ = read_memory 29@ size 4 virtual_protect 0
  369. for 30@ = 0 to 89344 step 0x100
  370. 0A8D: 0BJECT = read_memory 29@ size 1 virtual_protect 0
  371. 000A: 29@ += 0x1
  372. if and
  373. 0029: 0BJECT >= 0x00
  374. 001B: 0x80 > 0BJECT
  375. then
  376. 005A: 0BJECT += 30@ // (int)
  377. if and
  378. 03CA: (check) object 0BJECT exists
  379. 04E6: object 0BJECT near_point 2@ 3@ 10@ radius Y_DIMENSION Y_DIMENSION Y_DIMENSION flag 0
  380. then
  381. if and // проверяем модель объекта
  382. 89CC: not object 0BJECT model_is 3855 // GAY_TRAFFIC_LIGHT +
  383. 89CC: not object 0BJECT model_is 1315 // TRAFFICLIGHT1 +
  384. 89CC: not object 0BJECT model_is 1352 // CJ_TRAFFIC_LIGHT3 +
  385. 89CC: not object 0BJECT model_is 1350 // CJ_TRAFFIC_LIGHT4 +
  386. 89CC: not object 0BJECT model_is 1351 // CJ_TRAFFIC_LIGHT5 +
  387. 89CC: not object 0BJECT model_is 3516 // VGSSTRIPTLIGHTS1 +
  388. 89CC: not object 0BJECT model_is 1283 // MTRAFFIC1 +
  389. then
  390. if and
  391. 89CC: not object 0BJECT model_is 1284 // MTRAFFIC2 +
  392. 89CC: not object 0BJECT model_is 1375 // TRAMSTOP_SF +
  393. then
  394. continue
  395. end
  396. end
  397. object.StorePos(0BJECT 4@ 9@ 12@)
  398. 12@ += 1.0
  399. 0509: 14@ = distance_between_XY 2@ 3@ and_XY 4@ 9@
  400. 0509: 13@ = distance_between_XY 2@ 3@ and_XY LAST_0BJECT_X LAST_0BJECT_Y
  401. if or // находится ли новый объект ближе к трамваю, чем старый найденный объект и нет ли препятствий между трамваем и объектом
  402. 0025: 14@ > 13@ // (float)
  403. 86BD: not no_obstacles_between 2@ 3@ 10@ and 4@ 9@ 12@ solid 1 car 0 actor 0 object 0 particle 0
  404. then
  405. continue
  406. end
  407. 0509: 12@ = distance_between_XY 4@ 9@ and_XY 5@ 6@
  408. 0509: 13@ = distance_between_XY 4@ 9@ and_XY 7@ 8@
  409. if // находится ли новый объект перед трамваем
  410. 0035: 13@ >= 12@ // (float)
  411. then
  412. continue
  413. end
  414. if // проверки угла и цвета светофора (если это светофор)
  415. 09CC: object 0BJECT model_is 1375 // TRAMSTOP_SF +
  416. then
  417. if and
  418. 8045: not 4@ == LAST_0BJECT_X // (float)
  419. 8045: not 9@ == LAST_0BJECT_Y // (float)
  420. then
  421. 32@ = -900000
  422. 08BD: set FLAGS bit TRAM_IS_STOPPING
  423. 0485: return_true
  424. return
  425. end
  426. else // объект является светофором
  427. 0174: 6@ = car TRAM Z_angle //////////////////////////////////////////////////////////////////////////////////////////////////
  428. 0176: 8@ = object 0BJECT Z_angle
  429. 0063: 8@ -= 6@ // (float)
  430. 0656: get_angle 8@ absolute_degrees_to 8@
  431. if
  432. gosub @CHECK_TRAFFICLIGHT_ANGLE
  433. then
  434. 0176: 8@ = object 0BJECT Z_angle
  435. if and
  436. 8@ >= 60.0
  437. 8@ <= 150.0
  438. then
  439. 0AA7: call_function 0x49D3A0 num_params 0 pop 0 9@ // тип светофора 2 WE
  440. else
  441. if and
  442. 8@ >= 240.0
  443. 8@ <= 330.0
  444. then
  445. 0AA7: call_function 0x49D3A0 num_params 0 pop 0 9@ // тип светофора 2 WE
  446. else
  447. 0AA7: call_function 0x49D350 num_params 0 pop 0 9@ // тип светофора 1 NS
  448. end
  449. end
  450. for 8@ = 8 to 31
  451. 08C3: clear 9@ bit 8@
  452. end // значения функций: 0 - зелёный, 1 - желтый, 2 - красный
  453. if
  454. 9@ <> 0
  455. then
  456. 0485: return_true
  457. return
  458. end
  459. end
  460. end
  461. end
  462. end
  463. end
  464. 8485: return_false
  465. return
  466.  
  467. :CHECK_TRAFFICLIGHT_ANGLE // проверяем, является ли светофор попутным трамваю
  468. if or
  469. 8@ > 315.0
  470. 8@ < 45.0
  471. then
  472. 0485: return_true
  473. return
  474. end
  475. if or
  476. 09CC: object 0BJECT model_is 1283
  477. 09CC: object 0BJECT model_is 1284
  478. then
  479. if and
  480. 8@ > 135.0
  481. 8@ < 225.0
  482. then
  483. 0485: return_true
  484. return
  485. end
  486. end
  487. 8485: return_false
  488. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement