Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.19 KB | None | 0 0
  1. #define MAX_MATSYNTH_MATTER 60
  2. #define MAT_SYNTH_ROBO 50
  3.  
  4. #define MAT_COST_COMMON 1
  5. #define MAT_COST_MEDIUM 5
  6. #define MAT_COST_RARE 15
  7.  
  8. /obj/item/device/material_synth
  9. name = "material synthesizer"
  10. desc = "A device capable of producing very little material with a great deal of investment. Use wisely."
  11. icon = 'icons/obj/device.dmi'
  12. icon_state = "mat_synthoff"
  13.  
  14. flags = FPRINT
  15. siemens_coefficient = 1
  16. w_class = W_CLASS_MEDIUM
  17. origin_tech = Tc_ENGINEERING + "=4;" + Tc_MATERIALS + "=5;" + Tc_POWERSTORAGE + "=3"
  18.  
  19. var/mode = 1 //0 is material selection, 1 is material production
  20. var/emagged = 0
  21.  
  22. var/obj/item/stack/sheet/active_material = /obj/item/stack/sheet/metal
  23. var/list/materials_scanned = list("metal" = /obj/item/stack/sheet/metal,
  24. "glass" = /obj/item/stack/sheet/glass/glass,
  25. "reinforced glass" = /obj/item/stack/sheet/glass/rglass,
  26. "plasteel" = /obj/item/stack/sheet/plasteel)
  27.  
  28. var/list/can_scan = list(/obj/item/stack/sheet/metal,
  29. /obj/item/stack/sheet/glass/,
  30. /obj/item/stack/sheet/wood,
  31. /obj/item/stack/sheet/plasteel,
  32. /obj/item/stack/sheet/mineral)
  33. var/matter = 0
  34.  
  35. /obj/item/device/material_synth/robot/engiborg //Cyborg version, has less materials but can make rods n shit as well as scan.
  36. materials_scanned = list("metal" = /obj/item/stack/sheet/metal,
  37. "glass" = /obj/item/stack/sheet/glass/glass,
  38. "reinforced glass" = /obj/item/stack/sheet/glass/rglass,
  39. "floor tiles" = /obj/item/stack/tile/plasteel,
  40. "metal rods" = /obj/item/stack/rods)
  41.  
  42. /obj/item/device/material_synth/robot/engiborg/New() //We have to do this during New() because BYOND can't pull a typesof() during compile time.
  43. . = ..() //Can I make can_scan inherit from parent mat synths can_scan then exclude clown/phazon?
  44. can_scan = list(/obj/item/stack/sheet/metal,
  45. /obj/item/stack/sheet/glass/,
  46. /obj/item/stack/sheet/wood,
  47. /obj/item/stack/sheet/plasteel,
  48. /obj/item/stack/sheet/mineral) - list(/obj/item/stack/sheet/mineral/clown, /obj/item/stack/sheet/mineral/phazon)
  49.  
  50. /obj/item/device/material_synth/robot/mommi //MoMMI version, a few more materials to start with.
  51. materials_scanned = list("metal" = /obj/item/stack/sheet/metal,
  52. "glass" = /obj/item/stack/sheet/glass/glass,
  53. "reinforced glass" = /obj/item/stack/sheet/glass/rglass,
  54. "plasteel" = /obj/item/stack/sheet/plasteel,
  55. "plasma glass" = /obj/item/stack/sheet/glass/plasmaglass,
  56. "reinforced plasma glass" = /obj/item/stack/sheet/glass/plasmarglass)
  57.  
  58. /obj/item/device/material_synth/update_icon()
  59. icon_state = "mat_synth[mode ? "on" : "off"]"
  60.  
  61. /obj/item/device/material_synth/proc/create_material(mob/user, var/material)
  62. var/obj/item/stack/sheet/material_type = material
  63.  
  64. if(isrobot(user))
  65. var/mob/living/silicon/robot/R = user
  66. if(R && R.cell && R.cell.charge && material_type)
  67. var/modifier = MAT_COST_COMMON
  68. if(initial(active_material.perunit) < 3750)
  69. modifier = MAT_COST_MEDIUM
  70. if(initial(active_material.perunit) < 2000)
  71. modifier = MAT_COST_RARE
  72. var/amount = input(user, "How many sheets of [initial(material_type.name)] do you want to synthesize", "Material Synthesizer") as num
  73. amount = Clamp(round(amount, 1), 0, 50)
  74. if(amount)
  75. if(TakeCost(amount, modifier, R))
  76. var/obj/item/stack/sheet/inside_sheet = (locate(material_type) in R.module.modules)
  77. if(!inside_sheet)
  78. var/obj/item/stack/sheet/created_sheet = new material_type(R.module)
  79. R.module.modules += created_sheet
  80. if(amount <= created_sheet.max_amount)
  81. created_sheet.amount += (amount-created_sheet.amount)
  82. to_chat(R, "<span class='notice'>Added [amount] of [initial(material_type.name)] to the stack.</span>")
  83. else
  84. if(created_sheet.amount <= created_sheet.max_amount)
  85. var/transfer_amount = min(created_sheet.max_amount - created_sheet.amount, amount)
  86. created_sheet.amount += (transfer_amount-1)
  87. amount -= transfer_amount
  88. if(amount >= 1 && (created_sheet.amount >= created_sheet.max_amount))
  89. to_chat(R, "<span class='warning'>Dropping [amount], you cannot hold anymore of [initial(material_type.name)].</span>")
  90. var/obj/item/stack/sheet/dropped_sheet = new material_type(get_turf(src))
  91. dropped_sheet.amount = (amount - 1)
  92.  
  93. else
  94. if((inside_sheet.amount + amount) <= inside_sheet.max_amount)
  95. inside_sheet.amount += amount
  96. to_chat(R, "<span class='notice'>Added [amount] of [initial(material_type.name)] to the stack.</span>")
  97. return
  98. else
  99. if(inside_sheet.amount <= inside_sheet.max_amount)
  100. var/transfer_amount = min(inside_sheet.max_amount - inside_sheet.amount, amount)
  101. inside_sheet.amount += transfer_amount
  102. amount -= transfer_amount
  103. if(amount >= 1 && (inside_sheet.amount >= inside_sheet.max_amount))
  104. to_chat(R, "<span class='warning'>Dropping [amount], you cannot hold anymore of [initial(material_type.name)].</span>")
  105. var/obj/item/stack/sheet/dropped_sheet = new material_type(get_turf(src))
  106. dropped_sheet.amount = amount
  107. R.module.rebuild()
  108. R.hud_used.update_robot_modules_display()
  109. return
  110. else
  111. to_chat(R, "<span class='warning'>You can't make that much [initial(material_type.name)] without shutting down!</span>")
  112. return
  113.  
  114. return
  115.  
  116. else if(R.cell.charge)
  117. to_chat(R, "<span class='warning'>You need to select a sheet type first!</span>")
  118. return
  119. else
  120. if (material_type && matter >= 1)
  121. var/modifier
  122. var/unit_can_produce
  123. var/tospawn
  124. var/per_unit = initial(active_material.perunit)
  125.  
  126. if (per_unit < 2000)
  127. modifier = MAT_COST_RARE
  128. else if (per_unit < 3750)
  129. modifier = MAT_COST_MEDIUM
  130. else
  131. modifier = MAT_COST_COMMON
  132.  
  133. unit_can_produce = round(matter / modifier)
  134.  
  135. if (unit_can_produce >= 1)
  136. tospawn = input(user, "How many sheets of [initial(material_type.name)] do you want to synthesize? (0 - [unit_can_produce])", "Material Synthesizer") as num
  137. tospawn = Clamp(round(tospawn), 0, unit_can_produce)
  138.  
  139. if (tospawn >= 1)
  140. var/obj/item/stack/sheet/spawned_sheet = new material_type(get_turf(src))
  141. spawned_sheet.amount = tospawn
  142.  
  143. TakeCost(tospawn, modifier, user)
  144. else
  145. to_chat(user, "<span class='warning'>\The [src] matter is not enough to create the selected material!</span>")
  146. return
  147. else if (matter >= 1)
  148. to_chat(user, "<span class='warning'>You must select a sheet type first!</span>")
  149. return
  150. else
  151. to_chat(user, "<span class='warning'>\The [src] is empty!</span>")
  152.  
  153. return 1
  154.  
  155. /obj/item/device/material_synth/afterattack(atom/target, mob/user, proximity_flag, click_parameters)
  156. if(!proximity_flag)
  157. return 0 // not adjacent
  158. if(is_type_in_list(target, can_scan)) //Can_scan, can you?
  159. for(var/matID in materials_scanned)
  160. if(materials_scanned[matID] == target.type)
  161. to_chat(user, "<span class='warning'>You have already scanned \the [target].</span>")
  162. return
  163. materials_scanned["[initial(target.name)]"] = target.type
  164. to_chat(user, "<span class='notice'>You successfully scan \the [target] into \the [src]'s material banks.</span>")
  165. return 1
  166. else if(istype(target, /obj/item/stack/sheet)) //We can't scan it, but, only display an error when trying to scan a sheet.
  167. to_chat(user, "<span class='warning'>Your [src.name] does not contain this functionality to scan this type of material.</span>")
  168. return ..()
  169.  
  170. /obj/item/device/material_synth/examine(mob/user)
  171. ..()
  172. if(istype(src, /obj/item/device/material_synth/robot))
  173. to_chat(user, "It's been set to draw power from a power cell.")
  174. else
  175. to_chat(user, "It currently holds [matter]/[MAX_MATSYNTH_MATTER] matter-units.")
  176.  
  177. /obj/item/device/material_synth/attackby(var/obj/O, mob/user)
  178. if(istype(O, /obj/item/weapon/rcd_ammo))
  179. var/obj/item/weapon/rcd_ammo/RA = O
  180. if(matter + 10 > MAX_MATSYNTH_MATTER)
  181. to_chat(user, "<span class='warning'>\The [src] can't take any more material right now.</span>")
  182. return
  183. else
  184. matter += 10
  185. playsound(get_turf(src), 'sound/machines/click.ogg', 20, 1)
  186. qdel(RA)
  187. to_chat(user, "<span class='notice'>The material synthetizer now holds [matter]/[MAX_MATSYNTH_MATTER] matter-units.</span>")
  188. if(istype(O, /obj/item/weapon/card/emag))
  189. if(!emagged)
  190. emagged = 1
  191. var/matter_rng = rand(5, 25)
  192. if(matter >= matter_rng)
  193. var/obj/item/device/spawn_item = pick(existing_typesof(/obj/item/device)) //we make any kind of device. It's a surprise!
  194. user.visible_message("<span class='warning'>\The [src] in [user]'s hands appears to be trying to synthesize... \a [initial(spawn_item.name)]?</span>", \
  195. "<span class='warning'>\The [src] pops and fizzles in your hands, before creating... \a [initial(spawn_item.name)]?</span>", \
  196. "<span class='warning'>You hear a loud popping noise.</span>")
  197. sleep(10)
  198. new spawn_item(get_turf(src))
  199. matter -= matter_rng
  200. return 1
  201. else
  202. to_chat(user, "<span class='danger'>The lack of matter in \the [src] shorts out the device!</span>")
  203. explosion(src.loc, 0, 0, 1, 2) //traitors - fuck them, am I right?
  204. qdel(src)
  205. else
  206. to_chat(user, "<span class='warning'>You don't think you can do that again.</span>")
  207. return
  208. return ..()
  209.  
  210. /obj/item/device/material_synth/attack_self(mob/user)
  211. if(materials_scanned.len)
  212. var/selection = materials_scanned[input("Select the material you'd like to synthesize", "Change Material Type") as null|anything in materials_scanned]
  213. if(selection)
  214. active_material = selection
  215. to_chat(user, "<span class='notice'>You switch \the [src] to synthesize [initial(active_material.name)]</span>")
  216. else
  217. active_material = null
  218. return
  219. else
  220. to_chat(user, "<span class='warning'>ERROR: NO MATERIAL DATA FOUND</span>")
  221. return 0
  222. create_material(user, active_material)
  223.  
  224. /obj/item/device/material_synth/proc/TakeCost(var/spawned, var/modifier, mob/user)
  225. if(spawned)
  226. matter -= round(spawned * modifier)
  227.  
  228. /obj/item/device/material_synth/robot/TakeCost(var/spawned, var/modifier, mob/user)
  229. if(isrobot(user))
  230. var/mob/living/silicon/robot/R = user
  231. return R.cell.use(spawned * modifier * MAT_SYNTH_ROBO)
  232. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement