mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2025-12-30 04:02:33 +00:00
Merge pull request #9459 from variableundefined/NPCPoolPort
SS Port: NPCAI & NPCPool
This commit is contained in:
@@ -2,7 +2,6 @@ var/global/datum/controller/process/npcai/npcai_master
|
||||
|
||||
/datum/controller/process/npcai
|
||||
var/current_cycle
|
||||
var/saved_voice = 0
|
||||
|
||||
/datum/controller/process/npcai/setup()
|
||||
name = "npc ai"
|
||||
@@ -36,25 +35,6 @@ var/global/datum/controller/process/npcai/npcai_master
|
||||
catchBadType(M)
|
||||
simple_animal_list -= M
|
||||
|
||||
if(ticker.current_state == GAME_STATE_FINISHED && !saved_voice)
|
||||
var/mob/living/carbon/human/interactive/M = safepick(snpc_list)
|
||||
if(M)
|
||||
M.saveVoice()
|
||||
saved_voice = 1
|
||||
|
||||
for(last_object in snpc_list)
|
||||
var/mob/living/carbon/human/interactive/M = last_object
|
||||
if(istype(M) && !QDELETED(M))
|
||||
try
|
||||
if(!M.alternateProcessing || M.forceProcess)
|
||||
M.doProcess()
|
||||
catch(var/exception/e)
|
||||
catchException(e, M)
|
||||
SCHECK
|
||||
else
|
||||
catchBadType(M)
|
||||
snpc_list -= M
|
||||
|
||||
current_cycle++
|
||||
|
||||
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
var/global/datum/controller/process/npcpool/npc_master
|
||||
|
||||
/datum/controller/process/npcpool
|
||||
var/list/canBeUsed = list()
|
||||
var/list/canBeUsed_non = list()
|
||||
var/list/needsDelegate = list()
|
||||
var/list/needsAssistant = list()
|
||||
var/list/needsHelp_non = list()
|
||||
var/list/botPool_l = list() //list of all npcs using the pool
|
||||
var/list/botPool_l_non = list() //list of all non SNPC mobs using the pool
|
||||
|
||||
/datum/controller/process/npcpool/setup()
|
||||
name = "npc pool"
|
||||
schedule_interval = 100
|
||||
start_delay = 17
|
||||
log_startup_progress("NPC pool ticker starting up.")
|
||||
|
||||
/datum/controller/process/npcpool/copyStateFrom(var/datum/controller/process/npcpool/target)
|
||||
canBeUsed = target.canBeUsed
|
||||
canBeUsed_non = target.canBeUsed_non
|
||||
needsDelegate = target.needsDelegate
|
||||
needsAssistant = target.needsAssistant
|
||||
needsHelp_non = target.needsHelp_non
|
||||
botPool_l = target.botPool_l
|
||||
botPool_l_non = target.botPool_l_non
|
||||
|
||||
|
||||
DECLARE_GLOBAL_CONTROLLER(npcpool, npc_master)
|
||||
|
||||
/datum/controller/process/npcpool/proc/insertBot(toInsert)
|
||||
if(istype(toInsert, /mob/living/carbon/human/interactive))
|
||||
botPool_l |= toInsert
|
||||
|
||||
/datum/controller/process/npcpool/proc/removeBot(toRemove)
|
||||
botPool_l -= toRemove
|
||||
|
||||
/datum/controller/process/npcpool/statProcess()
|
||||
..()
|
||||
stat(null, "T [botPool_l.len + botPool_l_non.len] | D [needsDelegate.len] | A [needsAssistant.len + needsHelp_non.len] | U [canBeUsed.len + canBeUsed_non.len]")
|
||||
|
||||
/datum/controller/process/npcpool/doWork()
|
||||
//bot delegation and coordination systems
|
||||
//General checklist/Tasks for delegating a task or coordinating it (for SNPCs)
|
||||
// 1. Bot proximity to task target: if too far, delegate, if close, coordinate
|
||||
// 2. Bot Health/status: check health with bots in local area, if their health is higher, delegate task to them, else coordinate
|
||||
// 3. Process delegation: if a bot (or bots) has been delegated, assign them to the task.
|
||||
// 4. Process coordination: if a bot(or bots) has been asked to coordinate, assign them to help.
|
||||
// 5. Do all assignments: goes through the delegated/coordianted bots and assigns the right variables/tasks to them.
|
||||
|
||||
listclearnulls(canBeUsed)
|
||||
|
||||
//SNPC handling
|
||||
for(var/mob/living/carbon/human/interactive/check in botPool_l)
|
||||
if(!check)
|
||||
botPool_l -= check
|
||||
continue
|
||||
var/checkInRange = view(SNPC_MAX_RANGE_FIND, check)
|
||||
if(!(locate(check.TARGET) in checkInRange))
|
||||
needsDelegate |= check
|
||||
|
||||
else if(check.IsDeadOrIncap(0))
|
||||
needsDelegate |= check
|
||||
|
||||
else if(check.doing & SNPC_FIGHTING)
|
||||
needsAssistant |= check
|
||||
|
||||
else
|
||||
canBeUsed |= check
|
||||
SCHECK
|
||||
|
||||
if(needsDelegate.len)
|
||||
needsDelegate -= pick(needsDelegate) // cheapo way to make sure stuff doesn't pingpong around in the pool forever. delegation runs seperately to each loop so it will work much smoother
|
||||
|
||||
for(var/mob/living/carbon/human/interactive/check in needsDelegate)
|
||||
if(!check)
|
||||
needsDelegate -= check
|
||||
continue
|
||||
if(canBeUsed.len)
|
||||
var/mob/living/carbon/human/interactive/candidate = pick(canBeUsed)
|
||||
var/facCount = 0
|
||||
var/helpProb = 0
|
||||
for(var/C in check.faction)
|
||||
for(var/D in candidate.faction)
|
||||
if(D == C)
|
||||
helpProb = min(100, helpProb + 25)
|
||||
facCount++
|
||||
if(facCount == 1 && helpProb > 0)
|
||||
helpProb = 100
|
||||
if(prob(helpProb))
|
||||
if(candidate.takeDelegate(check))
|
||||
needsDelegate -= check
|
||||
canBeUsed -= candidate
|
||||
candidate.change_eye_color(255, 0, 0)
|
||||
SCHECK
|
||||
|
||||
if(needsAssistant.len)
|
||||
needsAssistant -= pick(needsAssistant)
|
||||
|
||||
for(var/mob/living/carbon/human/interactive/check in needsAssistant)
|
||||
if(!check)
|
||||
needsAssistant -= check
|
||||
continue
|
||||
if(canBeUsed.len)
|
||||
var/mob/living/carbon/human/interactive/candidate = pick(canBeUsed)
|
||||
var/facCount = 0
|
||||
var/helpProb = 0
|
||||
for(var/C in check.faction)
|
||||
for(var/D in candidate.faction)
|
||||
if(D == C)
|
||||
helpProb = min(100, helpProb + 25)
|
||||
facCount++
|
||||
if(facCount == 1 && helpProb > 0)
|
||||
helpProb = 100
|
||||
if(prob(helpProb))
|
||||
if(candidate.takeDelegate(check, 0))
|
||||
needsAssistant -= check
|
||||
canBeUsed -= candidate
|
||||
candidate.change_eye_color(255, 255, 0)
|
||||
SCHECK
|
||||
24
code/controllers/subsystem/npcai.dm
Normal file
24
code/controllers/subsystem/npcai.dm
Normal file
@@ -0,0 +1,24 @@
|
||||
SUBSYSTEM_DEF(npcai)
|
||||
name = "NPC AI" // Simple AI controller, isolated from the SNPC one (NPCPool).
|
||||
flags = SS_POST_FIRE_TIMING|SS_NO_INIT|SS_BACKGROUND
|
||||
priority = FIRE_PRIORITY_NPC
|
||||
runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME
|
||||
var/list/simple_animal_list = list()
|
||||
|
||||
/datum/controller/subsystem/npcai/stat_entry()
|
||||
..("SimAnimals:[simple_animal_list.len]")
|
||||
|
||||
/datum/controller/subsystem/npcai/fire(resumed = FALSE)
|
||||
if(!resumed)
|
||||
src.simple_animal_list = simple_animal_list.Copy()
|
||||
for(var/mob/living/simple_animal/M in simple_animal_list)
|
||||
if(istype(M) && !QDELETED(M))
|
||||
if(!M.client && M.stat == CONSCIOUS)
|
||||
M.process_ai()
|
||||
if(MC_TICK_CHECK)
|
||||
return
|
||||
else
|
||||
simple_animal_list -= M
|
||||
|
||||
/datum/controller/subsystem/npcai/Recover()
|
||||
simple_animal_list = SSnpcai.simple_animal_list
|
||||
127
code/controllers/subsystem/npcpool.dm
Normal file
127
code/controllers/subsystem/npcpool.dm
Normal file
@@ -0,0 +1,127 @@
|
||||
#define PROCESSING_NPCS 0
|
||||
#define PROCESSING_DELEGATES 1
|
||||
#define PROCESSING_ASSISTANTS 2
|
||||
|
||||
SUBSYSTEM_DEF(npcpool)
|
||||
name = "NPC Pool"
|
||||
flags = SS_POST_FIRE_TIMING|SS_NO_INIT|SS_BACKGROUND
|
||||
priority = FIRE_PRIORITY_NPC
|
||||
runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME
|
||||
|
||||
var/list/canBeUsed = list()
|
||||
var/list/needsDelegate = list()
|
||||
var/list/needsAssistant = list()
|
||||
|
||||
var/list/processing = list()
|
||||
var/list/currentrun = list()
|
||||
var/stage
|
||||
|
||||
/datum/controller/subsystem/npcpool/stat_entry()
|
||||
..("NPCS:[processing.len]|D:[needsDelegate.len]|A:[needsAssistant.len]|U:[canBeUsed.len]")
|
||||
|
||||
/datum/controller/subsystem/npcpool/proc/stop_processing(mob/living/carbon/human/interactive/I)
|
||||
processing -= I
|
||||
currentrun -= I
|
||||
needsDelegate -= I
|
||||
canBeUsed -= I
|
||||
needsAssistant -= I
|
||||
|
||||
/datum/controller/subsystem/npcpool/fire(resumed = FALSE)
|
||||
//bot delegation and coordination systems
|
||||
//General checklist/Tasks for delegating a task or coordinating it (for SNPCs)
|
||||
// 1. Bot proximity to task target: if too far, delegate, if close, coordinate
|
||||
// 2. Bot Health/status: check health with bots in local area, if their health is higher, delegate task to them, else coordinate
|
||||
// 3. Process delegation: if a bot (or bots) has been delegated, assign them to the task.
|
||||
// 4. Process coordination: if a bot(or bots) has been asked to coordinate, assign them to help.
|
||||
// 5. Do all assignments: goes through the delegated/coordianted bots and assigns the right variables/tasks to them.
|
||||
|
||||
if (!resumed)
|
||||
currentrun = processing.Copy()
|
||||
stage = PROCESSING_NPCS
|
||||
//cache for sanic speed (lists are references anyways)
|
||||
var/list/cachecurrentrun = currentrun
|
||||
var/list/cachecanBeUsed = canBeUsed
|
||||
|
||||
if(stage == PROCESSING_NPCS)
|
||||
while(cachecurrentrun.len)
|
||||
var/mob/living/carbon/human/interactive/thing = cachecurrentrun[cachecurrentrun.len]
|
||||
--cachecurrentrun.len
|
||||
|
||||
thing.InteractiveProcess()
|
||||
|
||||
var/checkInRange = view(SNPC_MAX_RANGE_FIND,thing)
|
||||
if(thing.IsDeadOrIncap(FALSE) || !(locate(thing.TARGET) in checkInRange))
|
||||
needsDelegate += thing
|
||||
else if(thing.doing & SNPC_FIGHTING)
|
||||
needsAssistant += thing
|
||||
else
|
||||
cachecanBeUsed += thing
|
||||
|
||||
if (MC_TICK_CHECK)
|
||||
return
|
||||
stage = PROCESSING_DELEGATES
|
||||
cachecurrentrun = needsDelegate //localcache
|
||||
currentrun = cachecurrentrun
|
||||
|
||||
if(stage == PROCESSING_DELEGATES)
|
||||
while(cachecurrentrun.len && cachecanBeUsed.len)
|
||||
var/mob/living/carbon/human/interactive/check = cachecurrentrun[cachecurrentrun.len]
|
||||
var/mob/living/carbon/human/interactive/candidate = cachecanBeUsed[cachecanBeUsed.len]
|
||||
--cachecurrentrun.len
|
||||
|
||||
var/helpProb = 0
|
||||
var/list/chfac = check.faction
|
||||
var/list/canfac = candidate.faction
|
||||
var/facCount = LAZYLEN(chfac) * LAZYLEN(canfac)
|
||||
|
||||
for(var/C in chfac)
|
||||
if(C in canfac)
|
||||
helpProb = min(100,helpProb + 25)
|
||||
if(helpProb >= 100)
|
||||
break
|
||||
|
||||
if(facCount == 1 && helpProb)
|
||||
helpProb = 100
|
||||
|
||||
if(prob(helpProb) && candidate.takeDelegate(check))
|
||||
--cachecanBeUsed.len
|
||||
candidate.change_eye_color(255, 0, 0)
|
||||
candidate.update_icons()
|
||||
|
||||
if(MC_TICK_CHECK)
|
||||
return
|
||||
stage = PROCESSING_ASSISTANTS
|
||||
cachecurrentrun = needsAssistant //localcache
|
||||
currentrun = cachecurrentrun
|
||||
|
||||
//no need for the stage check
|
||||
|
||||
while(cachecurrentrun.len && cachecanBeUsed.len)
|
||||
var/mob/living/carbon/human/interactive/check = cachecurrentrun[cachecurrentrun.len]
|
||||
var/mob/living/carbon/human/interactive/candidate = cachecanBeUsed[cachecanBeUsed.len]
|
||||
--cachecurrentrun.len
|
||||
|
||||
var/helpProb = 0
|
||||
var/list/chfac = check.faction
|
||||
var/list/canfac = candidate.faction
|
||||
var/facCount = LAZYLEN(chfac) * LAZYLEN(canfac)
|
||||
|
||||
for(var/C in chfac)
|
||||
if(C in canfac)
|
||||
helpProb = min(100,helpProb + 25)
|
||||
if(helpProb >= 100)
|
||||
break
|
||||
|
||||
if(facCount == 1 && helpProb)
|
||||
helpProb = 100
|
||||
|
||||
if(prob(helpProb) && candidate.takeDelegate(check,FALSE))
|
||||
--cachecanBeUsed.len
|
||||
candidate.change_eye_color(255, 255, 0)
|
||||
candidate.update_icons()
|
||||
|
||||
if(!cachecurrentrun.len || MC_TICK_CHECK) //don't change SS state if it isn't necessary
|
||||
return
|
||||
|
||||
/datum/controller/subsystem/npcpool/Recover()
|
||||
processing = SSnpcpool.processing
|
||||
@@ -85,7 +85,7 @@
|
||||
debug_variables(SSmobs)
|
||||
feedback_add_details("admin_verb","DMob")
|
||||
if("NPC AI")
|
||||
debug_variables(npcai_master)
|
||||
debug_variables(SSnpcai)
|
||||
feedback_add_details("admin_verb","DNPCAI")
|
||||
if("Shuttle")
|
||||
debug_variables(SSshuttle)
|
||||
|
||||
Reference in New Issue
Block a user