Merge pull request #10404 from mwerezak/stack-fix

Material stack related fixes
This commit is contained in:
PsiOmegaDelta
2015-08-08 09:56:25 +02:00
44 changed files with 217 additions and 185 deletions

View File

@@ -178,23 +178,29 @@ var/global/list/breach_burn_descriptors = list(
//Handles repairs (and also upgrades).
/obj/item/clothing/suit/space/attackby(obj/item/W as obj, mob/user as mob)
if(istype(W,/obj/item/stack/material/plastic) || istype(W,/obj/item/stack/material/steel))
if(istype(W,/obj/item/stack/material))
var/repair_power = 0
switch(W.get_material_name())
if(DEFAULT_WALL_MATERIAL)
repair_power = 2
if("plastic")
repair_power = 1
if(!repair_power)
return
if(istype(src.loc,/mob/living))
user << "\red How do you intend to patch a hardsuit while someone is wearing it?"
user << "<span class='warning'>How do you intend to patch a hardsuit while someone is wearing it?</span>"
return
if(!damage || !burn_damage)
user << "There is no surface damage on \the [src] to repair."
return
var/obj/item/stack/material/P = W
if(P.get_amount() < 3)
P.use(P.get_amount())
repair_breaches(BURN, ( istype(P,/obj/item/stack/material/plastic) ? P.get_amount() : (P.get_amount()*2) ), user)
else
P.use(3)
repair_breaches(BURN, ( istype(P,/obj/item/stack/material/plastic) ? 3 : 5), user)
var/obj/item/stack/P = W
var/use_amt = min(P.get_amount(), 3)
if(use_amt && P.use(use_amt))
repair_breaches(BURN, use_amt * repair_power, user)
return
else if(istype(W, /obj/item/weapon/weldingtool))

View File

@@ -7,7 +7,7 @@
return
// Pass repair items on to the chestpiece.
if(chest && (istype(W,/obj/item/stack/material/plastic) || istype(W,/obj/item/stack/material/steel) || istype(W, /obj/item/weapon/weldingtool)))
if(chest && (istype(W,/obj/item/stack/material) || istype(W, /obj/item/weapon/weldingtool)))
return chest.attackby(W,user)
// Lock or unlock the access panel.

View File

@@ -39,8 +39,13 @@
update_strings()
return 1
/obj/item/stack/material/get_material()
return material
/obj/item/stack/material/proc/update_strings()
// Update from material datum.
singular_name = material.sheet_singular_name
if(amount>1)
name = "[material.use_name] [material.sheet_plural_name]"
desc = "A stack of [material.use_name] [material.sheet_plural_name]."
@@ -187,15 +192,15 @@
/obj/item/stack/material/glass/reinforced
name = "reinforced glass"
icon_state = "sheet-rglass"
default_type = "reinforced glass"
default_type = "rglass"
/obj/item/stack/material/glass/phoronglass
name = "phoron glass"
singular_name = "phoron glass sheet"
icon_state = "sheet-phoronglass"
default_type = "phoron glass"
default_type = "phglass"
/obj/item/stack/material/glass/phoronrglass
name = "reinforced phoron glass"
icon_state = "sheet-phoronrglass"
default_type = "reinforced phoron glass"
default_type = "rphglass"

View File

@@ -34,5 +34,5 @@
/obj/item/stack/material/cyborg/glass/reinforced
icon_state = "sheet-rglass"
default_type = "reinforced glass"
default_type = "rglass"
charge_costs = list(500, 1000)

View File

@@ -27,6 +27,17 @@
// Assoc list containing all material datums indexed by name.
var/list/name_to_material
//Returns the material the object is made of, if applicable.
//Will we ever need to return more than one value here? Or should we just return the "dominant" material.
/obj/proc/get_material()
return null
//mostly for convenience
/obj/proc/get_material_name()
var/material/material = get_material()
if(material)
return material.name
// Builds the datum list above.
/proc/populate_material_list(force_remake=0)
if(name_to_material && !force_remake) return // Already set up!
@@ -44,6 +55,12 @@ var/list/name_to_material
populate_material_list()
return name_to_material[name]
/proc/material_display_name(name)
var/material/material = get_material_by_name(name)
if(material)
return material.display_name
return null
// Material definition and procs follow.
/material
var/name // Unique name for use in indexing the list.
@@ -312,7 +329,7 @@ var/list/name_to_material
icon_colour = "#666666"
/material/steel/holographic
name = "holographic " + DEFAULT_WALL_MATERIAL
name = "holo" + DEFAULT_WALL_MATERIAL
display_name = DEFAULT_WALL_MATERIAL
stack_type = null
shard_type = SHARD_NONE
@@ -422,7 +439,8 @@ var/list/name_to_material
return (hardness > 35) //todo
/material/glass/reinforced
name = "reinforced glass"
name = "rglass"
display_name = "reinforced glass"
stack_type = /obj/item/stack/material/glass/reinforced
flags = MATERIAL_BRITTLE
icon_colour = "#00E1FF"
@@ -440,7 +458,8 @@ var/list/name_to_material
rod_product = null
/material/glass/phoron
name = "phoron glass"
name = "phglass"
display_name = "phoron glass"
stack_type = /obj/item/stack/material/glass/phoronglass
flags = MATERIAL_BRITTLE
ignition_point = PHORON_MINIMUM_BURN_TEMPERATURE+300
@@ -452,7 +471,8 @@ var/list/name_to_material
rod_product = /obj/item/stack/material/glass/phoronrglass
/material/glass/phoron/reinforced
name = "reinforced phoron glass"
name = "rphglass"
display_name = "reinforced phoron glass"
stack_type = /obj/item/stack/material/glass/phoronrglass
stack_origin_tech = "materials=4;phorontech=2"
composite_material = list() //todo
@@ -473,7 +493,7 @@ var/list/name_to_material
stack_origin_tech = "materials=3"
/material/plastic/holographic
name = "holographic plastic"
name = "holoplastic"
display_name = "plastic"
stack_type = null
shard_type = SHARD_NONE
@@ -551,7 +571,7 @@ var/list/name_to_material
sheet_plural_name = "planks"
/material/wood/holographic
name = "holographic wood"
name = "holowood"
display_name = "wood"
stack_type = null
shard_type = SHARD_NONE

View File

@@ -210,7 +210,7 @@
var/can_make = Clamp(ores_stored[metal],0,sheets_per_tick-sheets)
if(can_make%2>0) can_make--
var/material/M = name_to_material[O.compresses_to]
var/material/M = get_material_by_name(O.compresses_to)
if(!istype(M) || !can_make || ores_stored[metal] < 1)
continue
@@ -224,7 +224,7 @@
var/can_make = Clamp(ores_stored[metal],0,sheets_per_tick-sheets)
var/material/M = name_to_material[O.smelts_to]
var/material/M = get_material_by_name(O.smelts_to)
if(!istype(M) || !can_make || ores_stored[metal] < 1)
continue

View File

@@ -37,26 +37,26 @@
/obj/machinery/mineral/mint/process()
if ( src.input)
var/obj/item/stack/material/O
O = locate(/obj/item/stack/material, input.loc)
var/obj/item/stack/O
O = locate(/obj/item/stack, input.loc)
if(O)
if (istype(O,/obj/item/stack/material/gold))
amt_gold += 100 * O.get_amount()
qdel(O)
if (istype(O,/obj/item/stack/material/silver))
amt_silver += 100 * O.get_amount()
qdel(O)
if (istype(O,/obj/item/stack/material/diamond))
amt_diamond += 100 * O.get_amount()
qdel(O)
if (istype(O,/obj/item/stack/material/phoron))
amt_phoron += 100 * O.get_amount()
qdel(O)
if (istype(O,/obj/item/stack/material/uranium))
amt_uranium += 100 * O.get_amount()
qdel(O)
if (istype(O,/obj/item/stack/material/steel))
amt_iron += 100 * O.get_amount()
var/processed = 1
switch(O.get_material_name())
if("gold")
amt_gold += 100 * O.get_amount()
if("silver")
amt_silver += 100 * O.get_amount()
if("diamond")
amt_diamond += 100 * O.get_amount()
if("phoron")
amt_phoron += 100 * O.get_amount()
if("uranium")
amt_uranium += 100 * O.get_amount()
if(DEFAULT_WALL_MATERIAL)
amt_iron += 100 * O.get_amount()
else
processed = 0
if(processed)
qdel(O)
/obj/machinery/mineral/mint/attack_hand(user as mob)

View File

@@ -249,15 +249,16 @@
target = null
repairing = 0
update_icons()
else if(istype(A, /obj/item/stack/material/steel) && amount + 3 < maxAmount)
var/obj/item/stack/material/steel/M = A
visible_message("<span class='notice'>[src] begins to make tiles.</span>")
repairing = 1
update_icons()
if(do_after(50))
if(M)
M.use(1)
addTiles(4)
else if(istype(A, /obj/item/stack/material) && amount + 4 <= maxAmount)
var/obj/item/stack/material/M = A
if(M.get_material_name() == DEFAULT_WALL_MATERIAL)
visible_message("<span class='notice'>[src] begins to make tiles.</span>")
repairing = 1
update_icons()
if(do_after(50))
if(M)
M.use(1)
addTiles(4)
/mob/living/bot/floorbot/explode()
turn_off()

View File

@@ -37,7 +37,7 @@
for(var/obj/I in contents)
for(var/mob/M in I.contents)
M.death()
if(istype(I,/obj/item/stack/material))//Only deconsturcts one sheet at a time instead of the entire stack
if(istype(I,/obj/item/stack/material))//Only deconstructs one sheet at a time instead of the entire stack
var/obj/item/stack/material/S = I
if(S.get_amount() > 1)
S.use(1)

View File

@@ -251,7 +251,7 @@ var/list/solars_list = list()
playsound(src.loc, 'sound/items/Ratchet.ogg', 75, 1)
return 1
if(istype(W, /obj/item/stack/material/glass))
if(istype(W, /obj/item/stack/material) && (W.get_material_name() == "glass" || W.get_material_name() == "rglass"))
var/obj/item/stack/material/S = W
if(S.use(2))
glass_type = W.type

View File

@@ -254,9 +254,9 @@
else
user << "<span class='notice'>You need at least five segments of cable coil to complete this task.</span>"
return
else if(istype(W,/obj/item/stack/material/plastic))
else if(istype(W,/obj/item/stack/material) && W.get_material_name() == "plastic")
if(buildstate == 3)
var/obj/item/stack/material/plastic/P = W
var/obj/item/stack/material/P = W
if(P.use(3))
user << "<span class='notice'>You assemble and install a heavy plastic lath onto the crossbow.</span>"
buildstate++

View File

@@ -167,9 +167,9 @@
buildstate++
update_icon()
return
else if(istype(W,/obj/item/stack/material/steel))
else if(istype(W,/obj/item/stack/material) && W.get_material_name() == DEFAULT_WALL_MATERIAL)
if(buildstate == 2)
var/obj/item/stack/material/steel/M = W
var/obj/item/stack/material/M = W
if(M.use(5))
user << "<span class='notice'>You assemble a chassis around the cannon frame.</span>"
buildstate++

View File

@@ -104,16 +104,13 @@ using metal and glass, it uses glass and reagents (usually sulfuric acis).
return 1
if(O.is_open_container())
return 0
// if(!istype(O, /obj/item/stack/material/glass) && !istype(O, /obj/item/stack/material/gold) && !istype(O, /obj/item/stack/material/diamond) && !istype(O, /obj/item/stack/material/uranium))
// user << "<span class='notice'>You cannot insert this item into \the [src]!</span>"
// return 1
if(stat)
return 1
if(busy)
user << "<span class='notice'>\The [src] is busy. Please wait for completion of previous operation.</span>"
return 1
if(istype(O, /obj/item/stack/material/glass) || istype(O, /obj/item/stack/material/gold) || istype(O, /obj/item/stack/material/diamond) || istype(O, /obj/item/stack/material/uranium))
if(istype(O, /obj/item/stack/material) && O.get_material_name() in list("glass", "gold", "diamond", "uranium"))
var/obj/item/stack/material/stack = O
if((TotalMaterials() + stack.perunit) > max_material_amount)

View File

@@ -144,28 +144,27 @@ Note: Must be placed west/left of and R&D console to function.
icon_state = "protolathe"
busy = 1
use_power(max(1000, (3750 * amount / 10)))
var/stacktype = stack.type
stack.use(amount)
if(do_after(user, 16))
var/material/material = stack.get_material()
if(istype(material) && do_after(user, 16) && stack.use(amount))
user << "<span class='notice'>You add [amount] sheets to \the [src].</span>"
icon_state = "protolathe"
switch(stacktype)
if(/obj/item/stack/material/steel)
m_amount += amount * 3750
if(/obj/item/stack/material/glass)
g_amount += amount * 3750
if(/obj/item/stack/material/gold)
gold_amount += amount * 2000
if(/obj/item/stack/material/silver)
silver_amount += amount * 2000
if(/obj/item/stack/material/phoron)
phoron_amount += amount * 2000
if(/obj/item/stack/material/uranium)
uranium_amount += amount * 2000
if(/obj/item/stack/material/diamond)
diamond_amount += amount * 2000
else
new stacktype(loc, amount)
var/amount_to_add = amount * material.stack_per_sheet
switch(material.name)
if(DEFAULT_WALL_MATERIAL)
m_amount += amount_to_add
if("glass")
g_amount += amount_to_add
if("gold")
gold_amount += amount_to_add
if("silver")
silver_amount += amount_to_add
if("phoron")
phoron_amount += amount_to_add
if("uranium")
uranium_amount += amount_to_add
if("diamond")
diamond_amount += amount_to_add
busy = 0
updateUsrDialog()
return

View File

@@ -439,25 +439,24 @@ won't update every console in existence) but it's more of a hassle to do. Also,
else if(href_list["lathe_ejectsheet"] && linked_lathe) //Causes the protolathe to eject a sheet of material
var/desired_num_sheets = text2num(href_list["amount"])
var/res_amount, type
var/material/M = name_to_material[href_list["lathe_ejectsheet"]]
var/material/M = get_material_by_name(href_list["lathe_ejectsheet"])
if(istype(M))
type = M.stack_type
switch(name_to_material[href_list["lathe_ejectsheet"]])
if(DEFAULT_WALL_MATERIAL)
res_amount = "m_amount"
if("glass")
res_amount = "g_amount"
if("gold")
res_amount = "gold_amount"
if("silver")
res_amount = "silver_amount"
if("phoron")
res_amount = "phoron_amount"
if("uranium")
res_amount = "uranium_amount"
if("diamond")
res_amount = "diamond_amount"
switch(M.name)
if(DEFAULT_WALL_MATERIAL)
res_amount = "m_amount"
if("glass")
res_amount = "g_amount"
if("gold")
res_amount = "gold_amount"
if("silver")
res_amount = "silver_amount"
if("phoron")
res_amount = "phoron_amount"
if("uranium")
res_amount = "uranium_amount"
if("diamond")
res_amount = "diamond_amount"
if(ispath(type) && hasvar(linked_lathe, res_amount))
var/obj/item/stack/material/sheet = new type(linked_lathe.loc)

View File

@@ -63,11 +63,11 @@
icon_state = "holo_preview"
color = "#EEEEEE"
New()
material = get_material_by_name("holographic [DEFAULT_TABLE_MATERIAL]")
material = get_material_by_name("holo[DEFAULT_TABLE_MATERIAL]")
..()
woodentable/holotable
icon_state = "holo_preview"
New()
material = get_material_by_name("holographic wood")
material = get_material_by_name("holowood")
..()

View File

@@ -200,7 +200,7 @@
// Returns the material to set the table to.
/obj/structure/table/proc/common_material_add(obj/item/stack/material/S, mob/user, verb) // Verb is actually verb without 'e' or 'ing', which is added. Works for 'plate'/'plating' and 'reinforce'/'reinforcing'.
var/material/M = name_to_material[S.default_type]
var/material/M = S.get_material()
if(!istype(M))
user << "<span class='warning'>You cannot [verb]e \the [src] with \the [S].</span>"
return null