Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.90 KB | None | 0 0
  1. // The lighting system
  2. //
  3. // consists of light fixtures (/obj/machinery/light) and light tube/bulb items (/obj/item/weapon/light)
  4.  
  5.  
  6. // status values shared between lighting fixtures and items
  7. #define LIGHT_OK 0
  8. #define LIGHT_EMPTY 1
  9. #define LIGHT_BROKEN 2
  10. #define LIGHT_BURNED 3
  11.  
  12. // the standard tube light fixture
  13.  
  14. /obj/machinery/light
  15. name = "light fixture"
  16. icon = 'lighting.dmi'
  17. var/base_state = "tube" // base description and icon_state
  18. icon_state = "tube1"
  19. desc = "A lighting fixture."
  20. anchored = 1
  21. layer = 5 // They were appearing under mobs which is a little weird - Ostaf
  22. var/on = 0 // 1 if on, 0 if off
  23. var/burnchance = 0.001
  24. var/status = LIGHT_OK // LIGHT_OK, _EMPTY, _BURNED or _BROKEN
  25. var/isalert = 0
  26. var/switching = 0
  27. var/flickering = 0 // 0 or 1. Prevents ghosts from flickering lights while that light is already being flickered
  28.  
  29. var/light_type = /obj/item/weapon/light/tube // the type of light item
  30.  
  31. var/brightnessred = 8
  32. var/brightnessgreen = 8
  33. var/brightnessblue = 8
  34.  
  35. var/fitting = "tube"
  36. var/switchcount = 0 // count of number of times switched on/off
  37. // this is used to calc the probability the light burns out
  38.  
  39. var/rigged = 0 // true if rigged to explode
  40.  
  41. blue
  42. brightnessblue = 7
  43. brightnessred = 5
  44. brightnessgreen = 5
  45.  
  46. // the smaller bulb light fixture
  47.  
  48. /obj/machinery/light/small
  49. icon_state = "bulb1"
  50. base_state = "bulb"
  51. fitting = "bulb"
  52. brightnessred = 5
  53. brightnessgreen = 5
  54. brightnessblue = 4
  55. desc = "A small lighting fixture."
  56. light_type = /obj/item/weapon/light/bulb
  57.  
  58. red
  59. brightnessgreen = 0
  60. brightnessblue = 0
  61.  
  62. // the desk lamp
  63. /obj/machinery/light/lamp
  64. name = "desk lamp"
  65. icon_state = "lamp1"
  66. base_state = "lamp"
  67. fitting = "bulb"
  68. brightnessred = 5
  69. brightnessgreen = 5
  70. brightnessblue = 4
  71. desc = "A desk lamp"
  72. light_type = /obj/item/weapon/light/bulb
  73.  
  74. var/switchon = 0 // independent switching for lamps - not controlled by area lightswitch
  75.  
  76. // green-shaded desk lamp
  77. /obj/machinery/light/lamp/green
  78. brightnessred = 3
  79. brightnessgreen = 5
  80. brightnessblue = 3
  81. icon_state = "green1"
  82. base_state = "green"
  83. desc = "A green-shaded desk lamp"
  84.  
  85.  
  86. // create a new lighting fixture
  87. /obj/machinery/light/New()
  88. ..()
  89. spawn(1)
  90. update()
  91.  
  92. // update the icon_state and luminosity of the light depending on its state
  93. // skip_check is currently used for ghosts flickering lights. It skips the status check, so that burned lights can also work.
  94. // It also skips the burning probability check. In flickering, that means the light has a chance of burning only when it reverts to its default state
  95. /obj/machinery/light/proc/update(var/skip_check = 0)
  96. set background=1
  97. if (switching)
  98. return
  99. if(!skip_check)
  100. switch(status) // set icon_states
  101. if(LIGHT_OK)
  102. icon_state = "[base_state][on]"
  103. if(LIGHT_EMPTY)
  104. icon_state = "[base_state]-empty"
  105. on = 0
  106. if(LIGHT_BURNED)
  107. icon_state = "[base_state]-burned"
  108. on = 0
  109. if(LIGHT_BROKEN)
  110. icon_state = "[base_state]-broken"
  111. on = 0
  112. else
  113. icon_state = "[base_state][on]"
  114.  
  115. var/oldlum = ul_Luminosity()
  116.  
  117. //luminosity = on * brightness
  118. ul_SetLuminosity(on * brightnessred, on * brightnessgreen * !isalert, on * brightnessblue * !isalert) // *UL*
  119.  
  120. // if the state changed, inc the switching counter
  121. if(oldlum != ul_Luminosity())
  122. switchcount++
  123.  
  124. // now check to see if the bulb is burned out
  125. if(status == LIGHT_OK)
  126. if(on && rigged)
  127. explode()
  128. if( prob(min(60, switchcount*switchcount*burnchance)) && !skip_check )
  129. status = LIGHT_BURNED
  130. icon_state = "[base_state]-burned"
  131. on = 0
  132. ul_SetLuminosity(0)
  133.  
  134.  
  135.  
  136. // attempt to set the light's on/off status
  137. // will not switch on if broken/burned/empty
  138. /obj/machinery/light/proc/seton(var/s)
  139. on = (s && status == LIGHT_OK)
  140. update()
  141.  
  142. // examine verb
  143. /obj/machinery/light/examine()
  144. set src in oview(1)
  145. if(usr && !usr.stat)
  146. switch(status)
  147. if(LIGHT_OK)
  148. usr << "[desc] It is turned [on? "on" : "off"]."
  149. if(LIGHT_EMPTY)
  150. usr << "[desc] The [fitting] has been removed."
  151. if(LIGHT_BURNED)
  152. usr << "[desc] The [fitting] is burnt out."
  153. if(LIGHT_BROKEN)
  154. usr << "[desc] The [fitting] has been smashed."
  155.  
  156.  
  157. // flicker lights on and off - ghosts
  158. /obj/machinery/light/proc/flicker(var/obj/machinery/light/L in view(1,usr))
  159.  
  160. set name = "Flicker"
  161.  
  162. if(L.flickering)
  163. return
  164.  
  165. L.flickering = 1
  166.  
  167. if(L.status == LIGHT_EMPTY || L.status == LIGHT_BROKEN)
  168. usr << "There is no [L.fitting] in this light."
  169. return
  170. if(on)
  171. usr << "Your touch robs the [L.fitting] of its energy!"
  172. else
  173. usr << "Your touch breathes energy into the [L.fitting]!"
  174.  
  175. L.on = !L.on
  176. L.update(1) // Flicker once
  177. sleep(10)
  178.  
  179. L.on = !src.on
  180. L.update(1) // Flicker back to initial state
  181. sleep(10)
  182.  
  183. L.on = !L.on
  184. L.update(1) // Flicker again
  185. sleep(30)
  186.  
  187. L.on = !L.on
  188. L.update() // And return to default state
  189. L.flickering = 0
  190.  
  191. return
  192.  
  193.  
  194. // attack with item - insert light (if right type), otherwise try to break the light
  195. /obj/machinery/light/attackby(obj/item/W, mob/user)
  196.  
  197. if (istype(user, /mob/living/silicon))
  198. return
  199.  
  200. // attempt to insert light
  201. if(istype(W, /obj/item/weapon/light))
  202. if(status != LIGHT_EMPTY)
  203. user << "There is a [fitting] already inserted."
  204. return
  205. else
  206. src.add_fingerprint(user)
  207. var/obj/item/weapon/light/L = W
  208. if(istype(L, light_type))
  209. status = L.status
  210. user << "You insert the [L.name]."
  211. switchcount = L.switchcount
  212. rigged = L.rigged
  213. del(L)
  214.  
  215. on = has_power()
  216. update()
  217. user.update_clothing()
  218. if(on && rigged)
  219. explode()
  220. else
  221. user << "This type of light requires a [fitting]."
  222. return
  223.  
  224. // attempt to break the light
  225.  
  226. else if(status != LIGHT_BROKEN && status != LIGHT_EMPTY)
  227.  
  228.  
  229. if(prob(1+W.force * 5))
  230.  
  231. user << "You hit the light, and it smashes!"
  232. for(var/mob/M in viewers(src))
  233. if(M == user)
  234. continue
  235. M.show_message("[user.name] smashed the light!", 3, "You hear a tinkle of breaking glass", 2)
  236. if(on && (W.flags & CONDUCT))
  237. if(!user.mutations & 2)
  238. src.electrocute(user, 50, null, 20000)
  239. broken()
  240.  
  241.  
  242. else
  243. user << "You hit the light!"
  244.  
  245. // attempt to stick weapon into light socket
  246. else if(status == LIGHT_EMPTY)
  247. user << "You stick \the [W.name] into the light socket!"
  248. if(has_power() && (W.flags & CONDUCT))
  249. var/datum/effects/system/spark_spread/s = new /datum/effects/system/spark_spread
  250. s.set_up(3, 1, src)
  251. s.start()
  252. if(!user.mutations & 2)
  253. src.electrocute(user, 75, null, 20000)
  254.  
  255.  
  256. // returns whether this light has power
  257. // true if area has power and lightswitch is on
  258. /obj/machinery/light/proc/has_power()
  259. var/area/A = src.loc.loc
  260. return A.master.lightswitch && A.master.power_light
  261.  
  262.  
  263. // attack with hand - remove tube/bulb
  264. // if hands aren't protected and the light is on, burn the player
  265.  
  266. /obj/machinery/light/attack_hand(mob/user)
  267. if (istype(user, /mob/living/silicon/ai)) //Added by Strumpetplaya - AI shouldn't be able to
  268. return //grab lights. This fixes that.
  269. add_fingerprint(user)
  270.  
  271. if(status == LIGHT_EMPTY)
  272. user << "There is no [fitting] in this light."
  273. return
  274.  
  275. // make it burn hands if not wearing fire-insulated gloves
  276. if(on)
  277. var/prot = 0
  278. var/mob/living/carbon/human/H = user
  279.  
  280. if(istype(H))
  281.  
  282. if(H.gloves)
  283. var/obj/item/clothing/gloves/G = H.gloves
  284. prot = (G.heat_transfer_coefficient < 0.5) // *** TODO: better handling of glove heat protection
  285. else
  286. prot = 1
  287.  
  288. if(prot > 0 || (user.mutations & 2))
  289. user << "You remove the light [fitting]"
  290. else
  291. user << "You try to remove the light [fitting], but you burn your hand on it!"
  292.  
  293. var/datum/organ/external/affecting = H.organs["[user.hand ? "l" : "r" ]_hand"]
  294.  
  295. affecting.take_damage( 0, 5 ) // 5 burn damage
  296.  
  297. H.UpdateDamageIcon()
  298. H.fireloss += 5
  299. H.updatehealth()
  300. return // if burned, don't remove the light
  301.  
  302. // create a light tube/bulb item and put it in the user's hand
  303. var/obj/item/weapon/light/L = new light_type()
  304. L.status = status
  305. L.rigged = rigged
  306. L.loc = usr
  307. L.layer = 20
  308. if(user.hand)
  309. user.l_hand = L
  310. else
  311. user.r_hand = L
  312.  
  313. // light item inherits the switchcount, then zero it
  314. L.switchcount = switchcount
  315. switchcount = 0
  316.  
  317.  
  318. L.update()
  319. L.add_fingerprint(user)
  320.  
  321. status = LIGHT_EMPTY
  322. update()
  323. user.update_clothing()
  324.  
  325. // break the light and make sparks if was on
  326.  
  327. /obj/machinery/light/proc/broken()
  328. if(status == LIGHT_EMPTY)
  329. return
  330.  
  331. if(status == LIGHT_OK || status == LIGHT_BURNED)
  332. playsound(src.loc, 'Glasshit.ogg', 75, 1)
  333. if(on)
  334. var/datum/effects/system/spark_spread/s = new /datum/effects/system/spark_spread
  335. s.set_up(3, 1, src)
  336. s.start()
  337. status = LIGHT_BROKEN
  338. update()
  339.  
  340. // explosion effect
  341. // destroy the whole light fixture or just shatter it
  342.  
  343. /obj/machinery/light/ex_act(severity)
  344. switch(severity)
  345. if(1.0)
  346. del(src)
  347. return
  348. if(2.0)
  349. if (prob(75))
  350. broken()
  351. if(3.0)
  352. if (prob(50))
  353. broken()
  354. return
  355.  
  356. //blob effect
  357.  
  358. /obj/machinery/light/blob_act()
  359. if(prob(50))
  360. broken()
  361.  
  362.  
  363. // timed process
  364. // use power
  365.  
  366. #define LIGHTING_POWER_FACTOR 25 //25W per unit luminosity
  367.  
  368. /obj/machinery/light/process()
  369. set background=1
  370. if(on)
  371. use_power(ul_Luminosity() * LIGHTING_POWER_FACTOR, LIGHT)
  372. if(switching)
  373. return
  374. var/area/A = get_area(src)
  375. if (isalert != A.redalert)
  376. switching = 1
  377. spawn(rand(0, 5))
  378. on = 0
  379. switching = 0
  380. update()
  381. switching = 1
  382. isalert = A.redalert
  383. on = 1
  384. sleep(10)
  385. switching = 0
  386. update()
  387.  
  388.  
  389. // called when area power state changes
  390.  
  391. /obj/machinery/light/power_change()
  392. spawn(rand(0,15))
  393. var/area/A = src.loc.loc
  394. A = A.master
  395. seton(A.lightswitch && A.power_light)
  396.  
  397.  
  398. // called when on fire
  399.  
  400. /obj/machinery/light/temperature_expose(datum/gas_mixture/air, exposed_temperature, exposed_volume)
  401. if(prob(max(0, exposed_temperature - 673))) //0% at <400C, 100% at >500C
  402. broken()
  403.  
  404. // explode the light
  405.  
  406. /obj/machinery/light/proc/explode()
  407. var/turf/T = get_turf(src.loc)
  408. spawn(0)
  409. broken() // break it first to give a warning
  410. sleep(2)
  411. explosion(T, 0, 1, 2, 2, 1)
  412. sleep(1)
  413. del(src)
  414.  
  415.  
  416.  
  417.  
  418. // special handling for desk lamps
  419.  
  420.  
  421. // if attack with hand, only "grab" attacks are an attempt to remove bulb
  422. // otherwise, switch the lamp on/off
  423.  
  424. /obj/machinery/light/lamp/attack_hand(mob/user)
  425.  
  426. if(user.a_intent == "grab")
  427. ..() // do standard hand attack
  428. else
  429. switchon = !switchon
  430. user << "You switch [switchon ? "on" : "off"] the [name]."
  431. seton(switchon && powered(LIGHT))
  432.  
  433.  
  434. // called when area power state changes
  435. // override since lamp does not use area lightswitch
  436.  
  437. /obj/machinery/light/lamp/power_change()
  438. spawn(rand(0,15))
  439. var/area/A = src.loc.loc
  440. A = A.master
  441. seton(switchon && A.power_light)
  442.  
  443. // returns whether this lamp has power
  444. // true if area has power and lamp switch is on
  445.  
  446. /obj/machinery/light/lamp/has_power()
  447. var/area/A = src.loc.loc
  448. return switchon && A.master.power_light
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455. // the light item
  456. // can be tube or bulb subtypes
  457. // will fit into empty /obj/machinery/light of the corresponding type
  458.  
  459. /obj/item/weapon/light
  460. icon = 'lighting.dmi'
  461. flags = FPRINT | TABLEPASS
  462. force = 2
  463. throwforce = 5
  464. w_class = 2
  465. var/status = 0 // LIGHT_OK, LIGHT_BURNED or LIGHT_BROKEN
  466. var/base_state
  467. var/switchcount = 0 // number of times switched
  468. m_amt = 60
  469. var/rigged = 0 // true if rigged to explode
  470.  
  471. /obj/item/weapon/light/tube
  472. name = "light tube"
  473. desc = "A replacement light tube."
  474. icon_state = "ltube"
  475. base_state = "ltube"
  476. item_state = "c_tube"
  477. g_amt = 100
  478.  
  479. /obj/item/weapon/light/bulb
  480. name = "light bulb"
  481. desc = "A replacement light bulb."
  482. icon_state = "lbulb"
  483. base_state = "lbulb"
  484. item_state = "contvapour"
  485. g_amt = 50
  486.  
  487. // update the icon state and description of the light
  488. /obj/item/weapon/light
  489. proc/update()
  490. switch(status)
  491. if(LIGHT_OK)
  492. icon_state = base_state
  493. desc = "A replacement [name]."
  494. if(LIGHT_BURNED)
  495. icon_state = "[base_state]-burned"
  496. desc = "A burnt-out [name]."
  497. if(LIGHT_BROKEN)
  498. icon_state = "[base_state]-broken"
  499. desc = "A broken [name]."
  500.  
  501.  
  502. /obj/item/weapon/light/New()
  503. ..()
  504. update()
  505.  
  506.  
  507. // attack bulb/tube with object
  508. // if a syringe, can inject plasma to make it explode
  509. /obj/item/weapon/light/attackby(var/obj/item/I, var/mob/user)
  510. if(istype(I, /obj/item/weapon/reagent_containers/syringe))
  511. var/obj/item/weapon/reagent_containers/syringe/S = I
  512.  
  513. user << "You inject the solution into the [src]."
  514.  
  515. if(S.reagents.has_reagent("plasma", 5))
  516.  
  517. rigged = 1
  518.  
  519. S.reagents.clear_reagents()
  520. else
  521. ..()
  522. return
  523.  
  524. // called after an attack with a light item
  525. // shatter light, unless it was an attempt to put it in a light socket
  526. // now only shatter if the intent was harm
  527.  
  528. /obj/item/weapon/light/afterattack(atom/target, mob/user)
  529. if(istype(target, /obj/machinery/light))
  530. return
  531. if(user.a_intent != "hurt")
  532. return
  533.  
  534. if(status == LIGHT_OK || status == LIGHT_BURNED)
  535. user << "The [name] shatters!"
  536. status = LIGHT_BROKEN
  537. force = 5
  538. playsound(src.loc, 'Glasshit.ogg', 75, 1)
  539. update()
  540.  
  541.  
  542.  
  543. // a box of replacement light items
  544.  
  545. /obj/item/weapon/storage/lightbox
  546. name = "replacement lights"
  547. icon = 'storage.dmi'
  548. icon_state = "light"
  549. item_state = "syringe_kit"
  550.  
  551. /obj/item/weapon/storage/lightbox/New()
  552. ..()
  553. new /obj/item/weapon/light/tube(src)
  554. new /obj/item/weapon/light/tube(src)
  555. new /obj/item/weapon/light/tube(src)
  556.  
  557. new /obj/item/weapon/light/bulb(src)
  558. new /obj/item/weapon/light/bulb(src)
  559. new /obj/item/weapon/light/bulb(src)
  560.  
  561. /obj/item/weapon/storage/lightbox/tubes/New()
  562. ..()
  563. new /obj/item/weapon/light/tube(src)
  564. new /obj/item/weapon/light/tube(src)
  565. new /obj/item/weapon/light/tube(src)
  566.  
  567. new /obj/item/weapon/light/tube(src)
  568. new /obj/item/weapon/light/tube(src)
  569. new /obj/item/weapon/light/tube(src)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement