tg Code complete, now to bugtest and clear compile errors.

This commit is contained in:
Fermi
2019-09-18 23:57:21 +01:00
parent c23d6f0113
commit dfa40a4b22
25 changed files with 427 additions and 110 deletions
+114 -11
View File
@@ -1,3 +1,6 @@
#define STANDARD_ORGAN_THRESHOLD 100
#define STANDARD_ORGAN_HEALING 0.001
/obj/item/organ
name = "organ"
icon = 'icons/obj/surgery.dmi'
@@ -8,11 +11,34 @@
var/zone = BODY_ZONE_CHEST
var/slot
// DO NOT add slots with matching names to different zones - it will break internal_organs_slot list!
var/vital = 0
//Was this organ implanted/inserted/etc, if true will not be removed during species change.
var/external = FALSE
var/synthetic = FALSE // To distinguish between organic and synthetic organs
var/organ_flags = 0
var/maxHealth = STANDARD_ORGAN_THRESHOLD
var/damage = 0 //total damage this organ has sustained
///Healing factor and decay factor function on % of maxhealth, and do not work by applying a static number per tick
var/healing_factor = 0 //fraction of maxhealth healed per on_life(), set to 0 for generic organs
var/decay_factor = 0 //same as above but when without a living owner, set to 0 for generic organs
var/high_threshold = STANDARD_ORGAN_THRESHOLD * 0.45 //when severe organ damage occurs
var/low_threshold = STANDARD_ORGAN_THRESHOLD * 0.1 //when minor organ damage occurs
///Organ variables for determining what we alert the owner with when they pass/clear the damage thresholds
var/prev_damage = 0
var/low_threshold_passed
var/high_threshold_passed
var/now_failing
var/now_fixed
var/high_threshold_cleared
var/low_threshold_cleared
/obj/item/organ/proc/Assemble_Failure_Message() //need to assemble a failure message since we can't have variables be based off of the same object's variables
var/name_length
//if no unique failure message is set, output the generic one, otherwise give the one we have set
if(!Unique_Failure_Msg)
name_length = lentext(name)
if(name[name_length] == "s") //plural case, done without much sanitization since I don't know any organ that ends with an "s" that isn't plural at the moment
Unique_Failure_Msg = "<span class='danger'>Subject's [name] are too damaged to function, and needs to be replaced or fixed!</span>"
else
Unique_Failure_Msg = "<span class='danger'>Subject's [name] is too damaged to function, and needs to be replaced or fixed!</span>"
return Unique_Failure_Msg
/obj/item/organ/proc/Insert(mob/living/carbon/M, special = 0, drop_if_replaced = TRUE)
if(!iscarbon(M) || owner == M)
@@ -33,31 +59,53 @@
for(var/X in actions)
var/datum/action/A = X
A.Grant(M)
STOP_PROCESSING(SSobj, src)
//Special is for instant replacement like autosurgeons
/obj/item/organ/proc/Remove(mob/living/carbon/M, special = 0)
/obj/item/organ/proc/Remove(mob/living/carbon/M, special = FALSE)
owner = null
if(M)
M.internal_organs -= src
if(M.internal_organs_slot[slot] == src)
M.internal_organs_slot.Remove(slot)
if(vital && !special && !(M.status_flags & GODMODE))
if((organ_flags & ORGAN_VITAL) && !special && !(M.status_flags & GODMODE))
M.death()
for(var/X in actions)
var/datum/action/A = X
A.Remove(M)
START_PROCESSING(SSobj, src)
/obj/item/organ/proc/on_find(mob/living/finder)
return
/obj/item/organ/proc/on_life()
return
/obj/item/organ/process()
on_death() //Kinda hate doing it like this, but I really don't want to call process directly.
/obj/item/organ/proc/on_death() //runs decay when outside of a person
if(organ_flags & (ORGAN_SYNTHETIC | ORGAN_FROZEN))
return
applyOrganDamage(maxHealth * decay_factor)
/obj/item/organ/proc/on_life() //repair organ damage if the organ is not failing
if(organ_flags & ORGAN_FAILING)
return
///Damage decrements by a percent of its maxhealth
var/healing_amount = -(maxHealth * healing_factor)
///Damage decrements again by a percent of its maxhealth, up to a total of 4 extra times depending on the owner's health
healing_amount -= owner.satiety > 0 ? 4 * healing_factor * owner.satiety / MAX_SATIETY : 0
applyOrganDamage(healing_amount) //FERMI_TWEAK
/obj/item/organ/examine(mob/user)
..()
if(status == ORGAN_ROBOTIC && crit_fail)
to_chat(user, "<span class='warning'>[src] seems to be broken!</span>")
. = ..()
if(organ_flags & ORGAN_FAILING)
if(status == ORGAN_ROBOTIC)
. += "<span class='warning'>[src] seems to be broken!</span>"
return
. += "<span class='warning'>[src] has decayed for too long, and has turned a sickly color! It doesn't look like it will work anymore!</span>"
return
if(damage > high_threshold)
. += "<span class='warning'>[src] is starting to look discolored.</span>"
/obj/item/organ/proc/prepare_eat()
@@ -78,6 +126,10 @@
foodtype = RAW | MEAT | GROSS
/obj/item/organ/Initialize()
. = ..()
START_PROCESSING(SSobj, src)
/obj/item/organ/Destroy()
if(owner)
// The special flag is important, because otherwise mobs can die
@@ -100,6 +152,57 @@
/obj/item/organ/item_action_slot_check(slot,mob/user)
return //so we don't grant the organ's action to mobs who pick up the organ.
///Adjusts an organ's damage by the amount "d", up to a maximum amount, which is by default max damage
/obj/item/organ/proc/applyOrganDamage(var/d, var/maximum = maxHealth) //use for damaging effects
if(!d) //Micro-optimization.
return
if(maximum < damage)
return
damage = CLAMP(damage + d, 0, maximum)
var/mess = check_damage_thresholds(owner)
prev_damage = damage
if(mess && owner)
to_chat(owner, mess)
///SETS an organ's damage to the amount "d", and in doing so clears or sets the failing flag, good for when you have an effect that should fix an organ if broken
/obj/item/organ/proc/setOrganDamage(var/d) //use mostly for admin heals
applyOrganDamage(d - damage)
/** check_damage_thresholds
* input: M (a mob, the owner of the organ we call the proc on)
* output: returns a message should get displayed.
* description: By checking our current damage against our previous damage, we can decide whether we've passed an organ threshold.
* If we have, send the corresponding threshold message to the owner, if such a message exists.
*/
/obj/item/organ/proc/check_damage_thresholds(var/M)
if(damage == prev_damage)
return
var/delta = damage - prev_damage
if(delta > 0)
if(damage >= maxHealth)
organ_flags |= ORGAN_FAILING
return now_failing
if(damage > high_threshold && prev_damage <= high_threshold)
return high_threshold_passed
if(damage > low_threshold && prev_damage <= low_threshold)
return low_threshold_passed
else
organ_flags &= ~ORGAN_FAILING
if(prev_damage > low_threshold && damage <= low_threshold)
return low_threshold_cleared
if(prev_damage > high_threshold && damage <= high_threshold)
return high_threshold_cleared
if(prev_damage == maxHealth)
return now_fixed
//Runs some code on the organ when damage is taken/healed
/obj/item/organ/proc/onDamage(var/d, var/maximum = maxHealth)
return
//Runs some code on the organ when damage is taken/healed
/obj/item/organ/proc/onSetDamage(var/d, var/maximum = maxHealth)
return
//Looking for brains?
//Try code/modules/mob/living/carbon/brain/brain_item.dm