mirror of
https://github.com/yogstation13/Yogstation.git
synced 2025-02-26 09:04:50 +00:00
Refactors mech construction datums
This commit is contained in:
@@ -1,44 +1,50 @@
|
||||
#define FORWARD -1
|
||||
#define BACKWARD 1
|
||||
#define FORWARD 1
|
||||
#define BACKWARD -1
|
||||
|
||||
#define ITEM_DELETE "delete"
|
||||
#define ITEM_MOVE_INSIDE "move_inside"
|
||||
|
||||
|
||||
/datum/construction
|
||||
var/list/steps
|
||||
var/atom/holder
|
||||
var/result
|
||||
var/list/steps_desc
|
||||
var/index = 1
|
||||
|
||||
/datum/construction/New(atom)
|
||||
..()
|
||||
holder = atom
|
||||
if(!holder) //don't want this without a holder
|
||||
qdel(src)
|
||||
set_desc(steps.len)
|
||||
return
|
||||
update_holder(index)
|
||||
|
||||
/datum/construction/proc/next_step()
|
||||
steps.len--
|
||||
if(!steps.len)
|
||||
/datum/construction/proc/on_step()
|
||||
if(index > steps.len)
|
||||
spawn_result()
|
||||
else
|
||||
set_desc(steps.len)
|
||||
return
|
||||
update_holder(index)
|
||||
|
||||
/datum/construction/proc/action(obj/item/I, mob/user)
|
||||
return
|
||||
/datum/construction/proc/action(obj/item/I, mob/living/user)
|
||||
return check_step(I, user)
|
||||
|
||||
/datum/construction/proc/check_step(obj/item/I, mob/user) //check last step only
|
||||
var/valid_step = is_right_key(I)
|
||||
if(valid_step)
|
||||
if(custom_action(valid_step, I, user))
|
||||
next_step()
|
||||
return 1
|
||||
return 0
|
||||
/datum/construction/proc/update_index(diff)
|
||||
index += diff
|
||||
on_step()
|
||||
|
||||
/datum/construction/proc/is_right_key(obj/item/I) // returns current step num if I is of the right type.
|
||||
var/list/L = steps[steps.len]
|
||||
/datum/construction/proc/check_step(obj/item/I, mob/living/user)
|
||||
var/diff = is_right_key(I)
|
||||
if(diff && custom_action(I, user, diff))
|
||||
update_index(diff)
|
||||
return TRUE
|
||||
return FALSE
|
||||
|
||||
/datum/construction/proc/is_right_key(obj/item/I) // returns index step
|
||||
var/list/L = steps[index]
|
||||
if(check_used_item(I, L["key"]))
|
||||
return steps.len
|
||||
return 0
|
||||
return FORWARD //to the first step -> forward
|
||||
else if(check_used_item(I, L["back_key"]))
|
||||
return BACKWARD //to the last step -> backwards
|
||||
return FALSE
|
||||
|
||||
/datum/construction/proc/check_used_item(obj/item/I, key)
|
||||
if(!key)
|
||||
@@ -52,77 +58,47 @@
|
||||
|
||||
return FALSE
|
||||
|
||||
|
||||
/datum/construction/proc/custom_action(step, obj/item/I, user)
|
||||
return 1
|
||||
|
||||
/datum/construction/proc/check_all_steps(obj/item/I, mob/user) //check all steps, remove matching one.
|
||||
for(var/i=1;i<=steps.len;i++)
|
||||
var/list/L = steps[i]
|
||||
if(check_used_item(I, L["key"]))
|
||||
if(custom_action(i, I, user))
|
||||
steps[i] = null//stupid byond list from list removal...
|
||||
listclearnulls(steps)
|
||||
if(!steps.len)
|
||||
spawn_result()
|
||||
return 1
|
||||
return 0
|
||||
|
||||
/datum/construction/proc/custom_action(obj/item/I, mob/living/user, diff)
|
||||
return TRUE
|
||||
|
||||
/datum/construction/proc/spawn_result()
|
||||
if(result)
|
||||
new result(get_turf(holder))
|
||||
new result(drop_location())
|
||||
qdel(holder)
|
||||
return
|
||||
|
||||
/datum/construction/proc/spawn_mecha_result()
|
||||
if(result)
|
||||
var/obj/mecha/m = new result(get_turf(holder))
|
||||
var/obj/item/oldcell = locate (/obj/item/stock_parts/cell) in m
|
||||
QDEL_NULL(oldcell)
|
||||
m.CheckParts(holder.contents)
|
||||
SSblackbox.record_feedback("tally", "mechas_created", 1, m.name)
|
||||
QDEL_NULL(holder)
|
||||
/datum/construction/proc/update_holder(step_index)
|
||||
var/list/step = steps[step_index]
|
||||
|
||||
/datum/construction/proc/set_desc(index as num)
|
||||
var/list/step = steps[index]
|
||||
holder.desc = step["desc"]
|
||||
return
|
||||
if(step["desc"])
|
||||
holder.desc = step["desc"]
|
||||
|
||||
if(step["icon_state"])
|
||||
holder.icon_state = step["icon_state"]
|
||||
|
||||
/datum/construction/proc/drop_location()
|
||||
return holder.drop_location()
|
||||
|
||||
/datum/construction/reversible
|
||||
var/index
|
||||
|
||||
/datum/construction/reversible/New(atom)
|
||||
..()
|
||||
index = steps.len
|
||||
return
|
||||
|
||||
/datum/construction/reversible/proc/update_index(diff as num)
|
||||
index+=diff
|
||||
if(index==0)
|
||||
spawn_result()
|
||||
else
|
||||
set_desc(index)
|
||||
return
|
||||
|
||||
/datum/construction/reversible/is_right_key(obj/item/I) // returns index step
|
||||
var/list/L = steps[index]
|
||||
if(check_used_item(I, L["key"]))
|
||||
return FORWARD //to the first step -> forward
|
||||
else if(check_used_item(I, L["backkey"]))
|
||||
return BACKWARD //to the last step -> backwards
|
||||
// Unordered construction.
|
||||
// Takes a list of part types, to be added in any order, as steps.
|
||||
// Calls spawn_result() when every type has been added.
|
||||
/datum/construction/unordered/check_step(obj/item/I, mob/living/user)
|
||||
for(var/typepath in steps)
|
||||
if(istype(I, typepath) && custom_action(I, user, typepath))
|
||||
steps -= typepath
|
||||
on_step()
|
||||
return TRUE
|
||||
return FALSE
|
||||
|
||||
/datum/construction/reversible/check_step(obj/item/I, mob/user)
|
||||
var/diff = is_right_key(I)
|
||||
if(diff)
|
||||
if(custom_action(index, diff, I, user))
|
||||
update_index(diff)
|
||||
return 1
|
||||
return 0
|
||||
/datum/construction/unordered/on_step()
|
||||
if(!steps.len)
|
||||
spawn_result()
|
||||
else
|
||||
update_holder(steps.len)
|
||||
|
||||
/datum/construction/reversible/custom_action(index, diff, obj/item/I, user)
|
||||
return 1
|
||||
/datum/construction/unordered/update_holder(steps_left)
|
||||
return
|
||||
|
||||
/datum/construction/unordered/custom_action(obj/item/I, mob/living/user, typepath)
|
||||
return TRUE
|
||||
|
||||
Reference in New Issue
Block a user