From 56e56b31a60142d83d148dade0866b8c8db7ce50 Mon Sep 17 00:00:00 2001 From: Razharas Date: Tue, 21 Jan 2014 21:56:53 +0400 Subject: [PATCH] Implemented crude crafting Debug messages are still inside, pushing only cozx pete asked me to Conflicts: code/_globalvars/lists/objects.dm code/game/objects/structures/tables_racks.dm --- code/__HELPERS/global_lists.dm | 15 +++- code/game/objects/structures/tables_racks.dm | 82 ++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/code/__HELPERS/global_lists.dm b/code/__HELPERS/global_lists.dm index 293e4961eea..e1ec0585d68 100644 --- a/code/__HELPERS/global_lists.dm +++ b/code/__HELPERS/global_lists.dm @@ -19,6 +19,7 @@ var/global/list/landmarks_list = list() //list of all landmarks created var/global/list/surgery_steps = list() //list of all surgery steps |BS12 var/global/list/side_effects = list() //list of all medical sideeffects types by thier names |BS12 var/global/list/mechas_list = list() //list of all mechs. Used by hostile mobs target tracking. +var/global/list/table_recipes = list() //list of all table craft recipes //Languages/species/whitelist. var/global/list/all_species[0] @@ -102,6 +103,8 @@ var/global/list/backbaglist = list("Nothing", "Backpack", "Satchel", "Satchel Al if(S.flags & IS_WHITELISTED) whitelisted_species += S.name + init_subtypes(/datum/table_recipe, table_recipes) + /* // Uncomment to debug chemical reaction list. /client/verb/debug_chemical_list() @@ -112,4 +115,14 @@ var/global/list/backbaglist = list("Nothing", "Backpack", "Satchel", "Satchel Al for(var/t in L) . += " has: [t]\n" world << . -*/ \ No newline at end of file +*/ + + +//creates every subtype of prototype (excluding prototype) and adds it to list L. +//if no list/L is provided, one is created. +/proc/init_subtypes(prototype, list/L) + if(!istype(L)) L = list() + for(var/path in typesof(prototype)) + if(path == prototype) continue + L += new path() + return L \ No newline at end of file diff --git a/code/game/objects/structures/tables_racks.dm b/code/game/objects/structures/tables_racks.dm index 1b35d07e868..ef56c38303e 100644 --- a/code/game/objects/structures/tables_racks.dm +++ b/code/game/objects/structures/tables_racks.dm @@ -10,6 +10,19 @@ /* * Tables */ + +/datum/table_recipe + var/name = "" + var/reqs[] + var/result_path + +/datum/table_recipe/flame_thrower + name = "Flamethrower" + result_path = /obj/item/weapon/flamethrower + reqs = list("/obj/item/weapon/weldingtool" = 1, + "/obj/item/device/assembly/igniter" = 1, + "/obj/item/stack/rods" = 2) + /obj/structure/table name = "table" desc = "A square piece of metal standing on four metal legs. It can not move." @@ -22,6 +35,7 @@ var/parts = /obj/item/weapon/table_parts var/flipped = 0 var/health = 100 + var/list/table_contents = list() /obj/structure/table/proc/update_adjacent() for(var/direction in list(1,2,4,8,5,6,9,10)) @@ -41,12 +55,78 @@ update_adjacent() ..() + /obj/structure/table/proc/destroy() new parts(loc) density = 0 del(src) +/obj/structure/table/proc/check_contents(datum/table_recipe/TR) + var/datum/table_recipe/R = TR + world.log << "Here comes the [TR]" + var/i = R.reqs.len + world.log << "Its req.length is [i]" + for(var/A in R.reqs) + world.log << "It needs [R.reqs[A]] [A], and there is only [table_contents[A]]" + if(table_contents[A] < R.reqs[A]) + break + else + i-- + if(i<=0) + return 1 + else + return 0 + +/obj/structure/table/proc/del_reqs(datum/table_recipe/TR) + var/datum/table_recipe/R = TR + for(var/A in R.reqs) + var/obj/item/I = locate(text2path(A)) in loc + if(istype(I, /obj/item/stack)) + var/obj/item/stack/S = I + S.amount -= R.reqs[A] + else + for(var/i=R.reqs[A],i>=0,i--) + I = locate(text2path(A)) in loc + del(I) + +/obj/structure/table/interact(mob/user) + for(var/A in table_recipes) + world.log << "[A]" + table_contents = list() + for(var/obj/item/I in loc) + if(istype(I, /obj/item/stack)) + var/obj/item/stack/S = I + table_contents["[I.type]"] += S.amount + else + table_contents["[I.type]"] += 1 + if(!table_contents.len) + return + var/dat = "

Construction menu

" + dat += "
" + for(var/datum/table_recipe/R in table_recipes) + if(check_contents(R)) + dat += "[R.name]
" + + dat += "
" + + var/datum/browser/popup = new(user, "table", "Table", 300, 300) + popup.set_content(dat) + popup.open() + return + +/obj/structure/table/Topic(href, href_list) + if(usr.stat || !Adjacent(usr) || usr.lying) + return + if(href_list["make"]) + var/datum/table_recipe/TR = locate(href_list["make"]) + if(check_contents(TR)) + del_reqs(TR) + var/obj/item/I = new TR.result_path + I.loc = loc + usr << "You crafted [I.name]." + attack_hand(usr) + /obj/structure/table/update_icon() if(flipped) var/type = 0 @@ -283,6 +363,8 @@ visible_message("[user] smashes [src] apart!") user.say(pick(";RAAAAAAAARGH!", ";HNNNNNNNNNGGGGGGH!", ";GWAAAAAAAARRRHHH!", "NNNNNNNNGGGGGGGGHH!", ";AAAAAAARRRGH!" )) destroy() + else + interact(user) /obj/structure/table/attack_tk() // no telehulk sorry return