mob/proc/Hunger()
set background = 1
spawn while(src)
sleep(125)
if(src.Hunger != 0 && src.Hunger != 100)
src.Vitals(5, "Hunger", "Subtraction")
switch(src.Hunger)
if(0)
if(src.Miscellaneous["Hunger"] != -0.15)
if(src.Miscellaneous["Hunger"] < 0)
var/Effect/Starvation/S = locate() in src.Effects
if(S) S.Deactivate(src)
else if(src.Miscellaneous["Hunger"] > 0)
var/Effect/Indigestion/I = locate() in src.Effects
if(I) I.Deactivate(src)
src.Miscellaneous["Hunger"] = -0.15
new /Effect/Starvation (src, src)
if(1 to 14)
if(src.Miscellaneous["Hunger"] != -0.1)
if(src.Miscellaneous["Hunger"] < 0)
var/Effect/Starvation/S = locate() in src.Effects
if(S) S.Deactivate(src)
else if(src.Miscellaneous["Hunger"] > 0)
var/Effect/Indigestion/I = locate() in src.Effects
if(I) I.Deactivate(src)
src.Miscellaneous["Hunger"] = -0.1
new /Effect/Starvation (src, src)
if(15 to 29)
if(src.Miscellaneous["Hunger"] != -0.05)
if(src.Miscellaneous["Hunger"] < 0)
var/Effect/Starvation/S = locate() in src.Effects
if(S) S.Deactivate(src)
else if(src.Miscellaneous["Hunger"] > 0)
var/Effect/Indigestion/I = locate() in src.Effects
if(I) I.Deactivate(src)
src.Miscellaneous["Hunger"] = -0.05
new /Effect/Starvation (src, src)
if(30 to 44)
if(src.Miscellaneous["Hunger"] != -0.03)
if(src.Miscellaneous["Hunger"] < 0)
var/Effect/Starvation/S = locate() in src.Effects
if(S) S.Deactivate(src)
else if(src.Miscellaneous["Hunger"] > 0)
var/Effect/Indigestion/I = locate() in src.Effects
if(I) I.Deactivate(src)
src.Miscellaneous["Hunger"] = -0.03
new /Effect/Starvation (src, src)
if(45 to 55)
if(src.Miscellaneous["Hunger"] != 0)
if(src.Miscellaneous["Hunger"] < 0)
var/Effect/Starvation/S = locate() in src.Effects
if(S) S.Deactivate(src)
else if(src.Miscellaneous["Hunger"] > 0)
var/Effect/Indigestion/I = locate() in src.Effects
if(I) I.Deactivate(src)
src.Miscellaneous["Hunger"] = 0
if(56 to 70)
if(src.Miscellaneous["Hunger"] != 0.1)
if(src.Miscellaneous["Hunger"] < 0)
var/Effect/Starvation/S = locate() in src.Effects
if(S) S.Deactivate(src)
else if(src.Miscellaneous["Hunger"] > 0)
var/Effect/Indigestion/I = locate() in src.Effects
if(I) I.Deactivate(src)
src.Miscellaneous["Hunger"] = 0.1
new /Effect/Indigestion (src, src)
if(71 to 85)
if(src.Miscellaneous["Hunger"] != 0.2)
if(src.Miscellaneous["Hunger"] < 0)
var/Effect/Starvation/S = locate() in src.Effects
if(S) S.Deactivate(src)
else if(src.Miscellaneous["Hunger"] > 0)
var/Effect/Indigestion/I = locate() in src.Effects
if(I) I.Deactivate(src)
src.Miscellaneous["Hunger"] = 0.2
new /Effect/Indigestion (src, src)
if(86 to 99)
if(src.Miscellaneous["Hunger"] != 0.3)
if(src.Miscellaneous["Hunger"] < 0)
var/Effect/Starvation/S = locate() in src.Effects
if(S) S.Deactivate(src)
else if(src.Miscellaneous["Hunger"] > 0)
var/Effect/Indigestion/I = locate() in src.Effects
if(I) I.Deactivate(src)
src.Miscellaneous["Hunger"] = 0.3
new /Effect/Indigestion (src, src)
if(100)
if(src.Miscellaneous["Hunger"] != 0.5)
if(src.Miscellaneous["Hunger"] < 0)
var/Effect/Starvation/S = locate() in src.Effects
if(S) S.Deactivate(src)
else if(src.Miscellaneous["Hunger"] > 0)
var/Effect/Indigestion/I = locate() in src.Effects
if(I) I.Deactivate(src)
src.Miscellaneous["Hunger"] = 0.5
new /Effect/Indigestion (src, src)
Effect
var
Name
Aura
Type
Colour
Active = 0
Potency = 0
Duration = 30
Stats[0]
Focus[0]
Effects[0]
Starvation
Name = "Starvation"
Aura = "Leaking Aura"
Type = "Negative"
Colour = "Sky Blue"
Potency = 0
Duration = 0
Stats = list("Vitality", "Vitality", "Tenacity", "Dexterity")
Focus = list("Health", "Stamina", "All", "All")
Effects = list("Hunger")
Activate(var/mob/M)
..()
if(src.Active == 1)
src.Active = 2
M.Status["Tenacity"] -= round(M.Tenacity * (Potency / 100))
M.Status["Dexterity"] -= round(M.Dexterity * (Potency / 100))
var/HLH = (M.Max_Health / 10) * (Potency / 100)
var/STM = (M.Max_Stamina / 10) * (Potency / 100)
M.Interaction = "Health: [HLH] | Stamina: [STM]"
M.Vitals(STM, "Stamina", "Subtraction")
M.Vitals(HLH, "Health", "Subtraction")
M.DeathCheck()
Deactivate(var/mob/M)
M.Status["Tenacity"] += round(M.Tenacity * (Potency / 100))
M.Status["Dexterity"] += round(M.Dexterity * (Potency / 100))
return ..()
Indigestion
Name = "Indigestion"
Aura = "Leaking Aura"
Type = "Negative"
Colour = "Brown"
Potency = 0
Duration = 0
Stats = list("Celerity", "Dexterity")
Focus = list("All", "All")
Effects = list("Hunger")
Activate(var/mob/M)
..()
if(src.Active == 1)
src.Active = 2
M.Status["Celerity"] -= round(M.Celerity * (Potency / 100))
M.Status["Dexterity"] -= round(M.Dexterity * (Potency / 100))
Deactivate(var/mob/M)
M.Status["Celerity"] += round(M.Celerity * (Potency / 100))
M.Status["Dexterity"] += round(M.Dexterity * (Potency / 100))
return ..()
New(mob/User, mob/Target)
if(src.Effects.Find("Hunger") && src.Potency == 0)
src.Potency = abs(Target.Miscellaneous["Hunger"]) * 100
Target.Effects.Add(src)
src.Ticker(User, Target)
proc
Ticker(var/mob/User, var/mob/Target)
Target.UpdateHUD(src, "Effect")
Target.Effect(src)
Activate(var/mob/M)
if(src.Active == 0)
src.Active = 1
Deactivate(var/mob/M)
src.Active = 0
M.Effects.Remove(src)
M.UpdateHUD(src, "Effect")
del src
mob/proc
Effect(var/Effect/E)
if(E.Duration > 0 && E.Duration)
for(var/Count = 1; Count <= E.Duration; Count++)
sleep(5)
E.Activate(src)
E.Deactivate(src)
else
E.Activate(src)
while(E.Active > 0)
sleep(5)
E.Activate(src)
E.Deactivate(src)
Explainations:
"Hunger()"
The first function is a constant loop that is called upon the creation of a new mob. As you can hopefully hypothesize, it's purpose is to slowly decrease over the mob's hunger over time, and gives them certain effects based on their level of starvation / indigestion.
"Effects"
Effects, a new datum I created, is simply used to create effects attached to mobs in a Object-Oriented way. Currently, there's a lot more Effects than just Starvation and Indigestion, however, the unique problem I'm having is involving the Hunger System I'm trying to set-up so I'm only showing those two for now.
"Effect()"
The mob's Effects function, which is to keep looping over the details of the intended Effect until either:
1) That Effect's Duration comes to an end
2) The Effect is no longer active,
3) Or the mob's death.
In the case of Starvation, it should be a case of the mob either dying or the Effect no longer being Active; while in the case of Indigestion, it is only until the Effect is no longer Active.
Problem Description:
In theory, in an alternate version of testing, the system works without incident and as intended, prior to actually using the Effect() with an Effect on a mob. The problem arises in the use of the sleep statement actually causing other functions to be halted -- Namely, the Hunger().
So, I tried replacing the sleep statement within the Effect() with spawn statement instead, which actually causes Dream Seeker to crash completely when it's time to update the mob's Hunger().
In another alternative, I tried switching the sleep statement within the Hunger() to spawn statement (the sleep statement in the Effects() was a spawn statement at the time), which caused extreme CPU latency (easily over 100%), and still caused it to crash when it was time to update the mob's Hunger.
So, is there anyone who can identify what is that I'm possibly doing wrong here or provide me with a feasible alternative?
spawn Target.Effect(src)
Or you can use the undocumented waitfor setting, which means delays/sleeps in Effect() will not block other procs:
In general, you can't replace sleep with spawn because they aren't the same kind of thing, since sleep is an instruction like new or del that just works in one line, and spawn is a control statement like if, for, while, etc., meaning it affects a block of code (e.g. indented section) after it.