Refactors ghost query to not use sleep (#17267)

* Refactors ghost query to not use sleeep

* Update ghost_query.dm

* don't need this anymore
This commit is contained in:
Cameron Lennox
2025-03-12 11:58:25 -04:00
committed by GitHub
parent 23111933eb
commit ba029d73ad
7 changed files with 113 additions and 66 deletions
+43 -31
View File
@@ -18,6 +18,7 @@ var/list/blob_cores = list()
var/resource_delay = 0
var/point_rate = 2
var/ai_controlled = TRUE
var/datum/ghost_query/Q //This is used so we can unregister ourself.
// Spawn this if you want a ghost to be able to play as the blob.
/obj/structure/blob/core/player
@@ -152,38 +153,8 @@ var/list/blob_cores = list()
/obj/structure/blob/core/proc/create_overmind(client/new_overmind, override_delay)
if(overmind_get_delay > world.time && !override_delay)
return
if(!ai_controlled) // Do we want a bona fide player blob?
overmind_get_delay = world.time + 15 SECONDS //if this fails, we'll try again in 15 seconds
if(overmind)
qdel(overmind)
var/client/C = null
if(!new_overmind)
var/datum/ghost_query/Q = new /datum/ghost_query/blob()
var/list/winner = Q.query()
if(winner.len)
var/mob/observer/dead/D = winner[1]
C = D.client
else
C = new_overmind
if(C)
if(!desired_blob_type && !isnull(difficulty_threshold))
desired_blob_type = get_random_blob_type()
var/mob/observer/blob/B = new(loc, TRUE, 60, desired_blob_type)
B.key = C.key
B.blob_core = src
src.overmind = B
update_icon()
if(B.mind && !B.mind.special_role)
B.mind.special_role = "Blob Overmind"
return TRUE
return FALSE
else // An AI opponent.
if(ai_controlled)
if(!desired_blob_type && !isnull(difficulty_threshold))
desired_blob_type = get_random_blob_type()
var/mob/observer/blob/B = new(loc, TRUE, 60, desired_blob_type)
@@ -193,6 +164,47 @@ var/list/blob_cores = list()
update_icon()
return TRUE
overmind_get_delay = world.time + 15 SECONDS //if this fails, we'll try again in 15 seconds
if(overmind)
qdel(overmind)
var/client/C = null
if(!new_overmind)
Q = new /datum/ghost_query/blob()
RegisterSignal(Q, COMSIG_GHOST_QUERY_COMPLETE, PROC_REF(get_winner))
Q.query()
else
C = new_overmind
overmind_creation(C)
/obj/structure/blob/core/proc/get_winner()
if(Q && Q.candidates.len) //Q should NEVER get deleted but...whatever, sanity.
var/mob/observer/dead/D = Q.candidates[1]
var/client/C
C = D.client
overmind_creation(C)
UnregisterSignal(Q, COMSIG_GHOST_QUERY_COMPLETE)
qdel_null(Q) //get rid of the query
/obj/structure/blob/core/proc/overmind_creation(var/client/new_overmind)
if(new_overmind)
if(!desired_blob_type && !isnull(difficulty_threshold))
desired_blob_type = get_random_blob_type()
var/mob/observer/blob/B = new(loc, TRUE, 60, desired_blob_type)
B.key = new_overmind.key
B.blob_core = src
src.overmind = B
update_icon()
if(B.mind && !B.mind.special_role)
B.mind.special_role = "Blob Overmind"
return TRUE
return FALSE
/obj/structure/blob/core/proc/get_random_blob_type()
if(!difficulty_threshold)
return
+10 -4
View File
@@ -180,6 +180,7 @@
locked = 0
mecha = null//This does not appear to be used outside of reference in mecha.dm.
var/ghost_query_type = null
var/datum/ghost_query/Q //This is used so we can unregister ourself.
/obj/item/mmi/digital/New()
src.brainmob = new(src)
@@ -245,13 +246,18 @@
return
searching = 1
var/datum/ghost_query/Q = new ghost_query_type()
var/list/winner = Q.query()
if(winner.len)
var/mob/observer/dead/D = winner[1]
Q = new ghost_query_type()
RegisterSignal(Q, COMSIG_GHOST_QUERY_COMPLETE, PROC_REF(get_winner))
Q.query()
/obj/item/mmi/digital/proc/get_winner()
if(Q && Q.candidates.len) //Q should NEVER get deleted but...whatever, sanity.
var/mob/observer/dead/D = Q.candidates[1]
transfer_personality(D)
else
reset_search()
UnregisterSignal(Q, COMSIG_GHOST_QUERY_COMPLETE)
qdel_null(Q) //get rid of the query
/obj/item/mmi/digital/proc/reset_search() //We give the players sixty seconds to decide, then reset the timer.
if(src.brainmob && src.brainmob.key)
@@ -42,6 +42,7 @@
var/has_reproduced = FALSE
var/used_dominate // world.time when the dominate power was last used.
var/datum/ghost_query/Q // Used to unregister our signal
/mob/living/simple_mob/animal/borer/roundstart
roundstart = TRUE
@@ -180,11 +181,16 @@
host = null
/mob/living/simple_mob/animal/borer/proc/request_player()
var/datum/ghost_query/Q = new /datum/ghost_query/borer()
var/list/winner = Q.query() // This will sleep the proc for awhile.
if(winner.len)
var/mob/observer/dead/D = winner[1]
Q = new /datum/ghost_query/borer()
RegisterSignal(Q, COMSIG_GHOST_QUERY_COMPLETE, PROC_REF(get_winner))
Q.query() // This will sleep the proc for awhile.
/mob/living/simple_mob/animal/borer/proc/get_winner()
if(Q && Q.candidates.len) //Q should NEVER get deleted but...whatever, sanity.
var/mob/observer/dead/D = Q.candidates[1]
transfer_personality(D)
UnregisterSignal(Q, COMSIG_GHOST_QUERY_COMPLETE)
qdel_null(Q) //get rid of the query
/mob/living/simple_mob/animal/borer/proc/transfer_personality(mob/candidate)
if(!candidate || !candidate.mind)