Revert "[MIRROR] Port material containers to datum components" (#2597)

* Revert "sprite fix on kitsune tails"

This reverts commit 44d5b21a43.

* Revert "Update vg_clothing_packs.dm (#2591)"

This reverts commit 7f46280d6b.

* Revert "Automatic changelog generation for PR #2590 [ci skip]"

This reverts commit 201e07033f.

* Revert "[MIRROR] Gives the detective a mass spectrometer (#2590)"

This reverts commit 5c98b9a13b.

* Revert "Quick sync (#2587)"

This reverts commit 92e055be97.

* Revert "Automatic changelog generation for PR #2557 [ci skip]"

This reverts commit 241a10d88d.

* Revert "Decreases hacked ai module cost (#2557)"

This reverts commit d959b7538a.

* Revert "[MIRROR] Port material containers to datum components (#2562)"

This reverts commit 32300086d5.
This commit is contained in:
Poojawa
2017-09-04 09:07:40 -05:00
committed by GitHub
parent f39bf40e76
commit 5f1d88ffeb
20 changed files with 362 additions and 372 deletions
-97
View File
@@ -1,97 +0,0 @@
/datum/component
var/enabled = TRUE // Enables or disables the components
var/dupe_mode = COMPONENT_DUPE_HIGHLANDER // How components of the same type are handled in the same parent
var/list/signal_procs // list of signals -> callbacks
var/datum/parent // parent datum
/datum/component/New(datum/P, ...)
var/dm = dupe_mode
if(dm != COMPONENT_DUPE_ALLOWED)
var/datum/component/old = P.GetExactComponent(type)
if(old)
switch(dm)
if(COMPONENT_DUPE_HIGHLANDER)
P.RemoveComponent(old)
old = null //in case SendSignal() blocks
if(COMPONENT_DUPE_UNIQUE)
qdel(src)
return
P.SendSignal(COMSIG_COMPONENT_ADDED, list(src), FALSE)
LAZYADD(P.datum_components, src)
parent = P
/datum/component/Destroy()
RemoveNoSignal()
return ..()
/datum/component/proc/RemoveNoSignal()
var/datum/P = parent
if(P)
LAZYREMOVE(P.datum_components, src)
parent = null
/datum/component/proc/RegisterSignal(sig_type, proc_on_self, override = FALSE)
var/list/procs = signal_procs
if(!procs)
procs = list()
signal_procs = procs
if(!override)
. = procs[sig_type]
if(.)
stack_trace("[sig_type] overridden. Use override = TRUE to suppress this warning")
procs[sig_type] = CALLBACK(src, proc_on_self)
/datum/var/list/datum_components //list of /datum/component
// Send a signal to all other components in the container.
/datum/proc/SendSignal(sigtype, list/sig_args, async = FALSE)
var/list/comps = datum_components
. = FALSE
for(var/I in comps)
var/datum/component/C = I
if(!C.enabled)
continue
var/list/sps = C.signal_procs
var/datum/callback/CB = LAZYACCESS(sps, sigtype)
if(!CB)
continue
if(!async)
. |= CB.Invoke(sig_args)
else
. |= CB.InvokeAsync(sig_args)
/datum/proc/GetComponent(c_type)
for(var/I in datum_components)
if(istype(I, c_type))
return I
/datum/proc/GetExactComponent(c_type)
for(var/I in datum_components)
var/datum/component/C = I
if(C.type == c_type)
return I
/datum/proc/GetComponents(c_type)
. = list()
for(var/I in datum_components)
if(istype(I, c_type))
. += I
/datum/proc/AddComponents(list/new_types)
for(var/new_type in new_types)
AddComponent(new_type)
/datum/proc/AddComponent(new_type, ...)
var/nt = new_type
args[1] = src
var/datum/component/C = new nt(arglist(args))
return QDELING(C) ? GetComponent(new_type) : C
/datum/proc/RemoveComponent(datum/component/C)
if(!C)
return
C.RemoveNoSignal()
SendSignal(COMSIG_COMPONENT_REMOVING, list(C), FALSE)
qdel(C)
+1 -1
View File
@@ -105,4 +105,4 @@ Stands have a lot of procs which mimic mob procs. Rather than inserting hooks fo
* Called when a component recieves any signal and is enabled
* Default implementation looks if the signal is registered and runs the appropriate proc
### See signals and their arguments in __DEFINES\components.dm
### See/Define signals and their arguments in __DEFINES\components.dm
-6
View File
@@ -1,6 +0,0 @@
//These components require a powered machine as a parent to run
/datum/component/powered
/datum/component/powered/ReceiveSignal(sigtype, list/sig_args, async)
var/obj/machinery/M = parent
return M.is_operational() && ..()
@@ -5,34 +5,22 @@
amount - raw amount of the mineral this container is holding, calculated by the defined value MINERAL_MATERIAL_AMOUNT=2000.
max_amount - max raw amount of mineral this container can hold.
sheet_type - type of the mineral sheet the container handles, used for output.
parent - object that this container is being used by, used for output.
owner - object that this container is being used by, used for output.
MAX_STACK_SIZE - size of a stack of mineral sheets. Constant.
*/
/datum/component/material_container
/datum/material_container
var/total_amount = 0
var/max_amount
var/sheet_type
var/list/materials
var/show_on_examine
var/list/allowed_typecache
var/last_inserted_type
var/last_amount_inserted
var/last_insert_success
var/datum/callback/precondition
var/obj/owner
var/list/materials = list()
//MAX_STACK_SIZE = 50
//MINERAL_MATERIAL_AMOUNT = 2000
/datum/component/material_container/Initialize(list/mat_list, max_amt = 0, _show_on_examine = FALSE, list/allowed_types, datum/callback/_precondition)
materials = list()
/datum/material_container/New(obj/O, list/mat_list, max_amt = 0)
owner = O
max_amount = max(0, max_amt)
show_on_examine = _show_on_examine
if(allowed_types)
allowed_typecache = typecacheof(allowed_types)
precondition = _precondition
RegisterSignal(COMSIG_PARENT_ATTACKBY, .proc/OnAttackBy)
RegisterSignal(COMSIG_PARENT_EXAMINE, .proc/OnExamine)
var/list/possible_mats = list()
for(var/mat_type in subtypesof(/datum/material))
@@ -43,47 +31,12 @@
var/mat_path = possible_mats[id]
materials[id] = new mat_path()
/datum/component/material_container/proc/OnExamine(mob/user)
for(var/I in materials)
var/datum/material/M = materials[I]
var/amt = amount(M.id)
if(amt)
to_chat(user, "<span class='notice'>It has [amt] units of [lowertext(M.name)] stored.</span>")
/datum/component/material_container/proc/OnAttackBy(obj/item/I, mob/living/user)
var/list/tc = allowed_typecache
if(user.a_intent == INTENT_HARM || (I.flags_2 & HOLOGRAM_2) || (tc && !is_type_in_typecache(I, tc)))
return FALSE
. = TRUE
last_insert_success = FALSE
var/datum/callback/pc = precondition
if(pc && !pc.Invoke())
return
var/material_amount = get_item_material_amount(I)
if(!material_amount)
to_chat(user, "<span class='warning'>[I] does not contain sufficient amounts of metal or glass to be accepted by [parent].</span>")
return
if(!has_space(material_amount))
to_chat(user, "<span class='warning'>[parent] is full. Please remove metal or glass from [parent] in order to insert more.</span>")
return
if(!user.temporarilyRemoveItemFromInventory(I))
to_chat(user, "<span class='warning'>[I] is stuck to you and cannot be placed into [parent].</span>")
return
var/inserted = insert_item(I)
if(inserted)
last_insert_success = TRUE
if(istype(I, /obj/item/stack))
to_chat(user, "<span class='notice'>You insert [inserted] sheet[inserted>1 ? "s" : ""] into [parent].</span>")
if(!QDELETED(I))
user.put_in_active_hand(I)
else
to_chat(user, "<span class='notice'>You insert a material total of [inserted] into [parent].</span>")
qdel(I)
else
user.put_in_active_hand(I)
/datum/material_container/Destroy()
owner = null
return ..()
//For inserting an amount of material
/datum/component/material_container/proc/insert_amount(amt, id = null)
/datum/material_container/proc/insert_amount(amt, id = null)
if(amt > 0 && has_space(amt))
var/total_amount_saved = total_amount
if(id)
@@ -99,7 +52,7 @@
return (total_amount - total_amount_saved)
return 0
/datum/component/material_container/proc/insert_stack(obj/item/stack/S, amt = 0)
/datum/material_container/proc/insert_stack(obj/item/stack/S, amt = 0)
if(amt <= 0)
return 0
if(amt > S.amount)
@@ -114,12 +67,10 @@
return 0
insert_materials(S,amt)
last_inserted_type = S.type
S.use(amt)
last_amount_inserted = amt
return amt
/datum/component/material_container/proc/insert_item(obj/item/I, multiplier = 1)
/datum/material_container/proc/insert_item(obj/item/I, multiplier = 1)
if(!I)
return 0
if(istype(I, /obj/item/stack))
@@ -131,11 +82,9 @@
return 0
insert_materials(I, multiplier)
last_inserted_type = I.type
last_amount_inserted = material_amount
return material_amount
/datum/component/material_container/proc/insert_materials(obj/item/I, multiplier = 1) //for internal usage only
/datum/material_container/proc/insert_materials(obj/item/I, multiplier = 1) //for internal usage only
var/datum/material/M
for(var/MAT in materials)
M = materials[MAT]
@@ -144,7 +93,7 @@
//For consuming material
//mats is a list of types of material to use and the corresponding amounts, example: list(MAT_METAL=100, MAT_GLASS=200)
/datum/component/material_container/proc/use_amount(list/mats, multiplier=1)
/datum/material_container/proc/use_amount(list/mats, multiplier=1)
if(!mats || !mats.len)
return 0
@@ -163,7 +112,7 @@
return total_amount_save - total_amount
/datum/component/material_container/proc/use_amount_type(amt, id)
/datum/material_container/proc/use_amount_type(amt, id)
var/datum/material/M = materials[id]
if(M)
if(M.amount >= amt)
@@ -172,7 +121,7 @@
return amt
return 0
/datum/component/material_container/proc/can_use_amount(amt, id, list/mats)
/datum/material_container/proc/can_use_amount(amt, id, list/mats)
if(amt && id)
var/datum/material/M = materials[id]
if(M && M.amount >= amt)
@@ -187,7 +136,7 @@
return FALSE
//For spawning mineral sheets; internal use only
/datum/component/material_container/proc/retrieve(sheet_amt, datum/material/M, target = null)
/datum/material_container/proc/retrieve(sheet_amt, datum/material/M, target = null)
if(!M.sheet_type)
return 0
if(sheet_amt > 0)
@@ -195,12 +144,12 @@
sheet_amt = round(M.amount / MINERAL_MATERIAL_AMOUNT)
var/count = 0
while(sheet_amt > MAX_STACK_SIZE)
new M.sheet_type(get_turf(parent), MAX_STACK_SIZE)
new M.sheet_type(get_turf(owner), MAX_STACK_SIZE)
count += MAX_STACK_SIZE
use_amount_type(sheet_amt * MINERAL_MATERIAL_AMOUNT, M.id)
sheet_amt -= MAX_STACK_SIZE
if(round((sheet_amt * MINERAL_MATERIAL_AMOUNT) / MINERAL_MATERIAL_AMOUNT))
var/obj/item/stack/sheet/s = new M.sheet_type(get_turf(parent), sheet_amt)
var/obj/item/stack/sheet/s = new M.sheet_type(get_turf(owner), sheet_amt)
if(target)
s.forceMove(target)
count += sheet_amt
@@ -208,15 +157,15 @@
return count
return 0
/datum/component/material_container/proc/retrieve_sheets(sheet_amt, id, target = null)
/datum/material_container/proc/retrieve_sheets(sheet_amt, id, target = null)
if(materials[id])
return retrieve(sheet_amt, materials[id], target)
return 0
/datum/component/material_container/proc/retrieve_amount(amt, id, target)
/datum/material_container/proc/retrieve_amount(amt, id, target)
return retrieve_sheets(amount2sheet(amt), id, target)
/datum/component/material_container/proc/retrieve_all(target = null)
/datum/material_container/proc/retrieve_all(target = null)
var/result = 0
var/datum/material/M
for(var/MAT in materials)
@@ -224,10 +173,10 @@
result += retrieve_sheets(amount2sheet(M.amount), MAT, target)
return result
/datum/component/material_container/proc/has_space(amt = 0)
/datum/material_container/proc/has_space(amt = 0)
return (total_amount + amt) <= max_amount
/datum/component/material_container/proc/has_materials(list/mats, multiplier=1)
/datum/material_container/proc/has_materials(list/mats, multiplier=1)
if(!mats || !mats.len)
return 0
@@ -238,23 +187,23 @@
return 0
return 1
/datum/component/material_container/proc/amount2sheet(amt)
/datum/material_container/proc/amount2sheet(amt)
if(amt >= MINERAL_MATERIAL_AMOUNT)
return round(amt / MINERAL_MATERIAL_AMOUNT)
return 0
/datum/component/material_container/proc/sheet2amount(sheet_amt)
/datum/material_container/proc/sheet2amount(sheet_amt)
if(sheet_amt > 0)
return sheet_amt * MINERAL_MATERIAL_AMOUNT
return 0
/datum/component/material_container/proc/amount(id)
/datum/material_container/proc/amount(id)
var/datum/material/M = materials[id]
return M ? M.amount : 0
//returns the amount of material relevant to this container;
//if this container does not support glass, any glass in 'I' will not be taken into account
/datum/component/material_container/proc/get_item_material_amount(obj/item/I)
/datum/material_container/proc/get_item_material_amount(obj/item/I)
if(!istype(I))
return 0
var/material_amount = 0
@@ -329,4 +278,4 @@
/datum/material/biomass
name = "Biomass"
id = MAT_BIOMASS
id = MAT_BIOMASS