mirror of
https://github.com/vgstation-coders/vgstation13.git
synced 2025-12-10 18:32:03 +00:00
Ported component AI to the new component system (#30751)
* wip new component ai * wip 2 * he lives * fixes * comment
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
/datum/component/controller/mob
|
||||
var/walk_delay=4
|
||||
|
||||
/datum/component/controller/mob/RecieveSignal(var/message_type, var/list/args)
|
||||
if(isliving(container.holder))
|
||||
var/mob/living/M=container.holder
|
||||
//testing("Got command: \[[message_type]\]: [json_encode(args)]")
|
||||
switch(message_type)
|
||||
if(COMSIG_CLICKON)
|
||||
var/atom/A = args["target"]
|
||||
var/params
|
||||
if(args["def_zone"])
|
||||
var/list/L = list("def_zone" = args["def_zone"])
|
||||
params = list2params(L)
|
||||
M.ClickOn(A, params)
|
||||
if(COMSIG_STEP)
|
||||
step(M, args["dir"], walk_delay)
|
||||
|
||||
if(COMSIG_ADJUST_BODYTEMP) // list("temp"=TEMP_IN_KELVIN)
|
||||
M.bodytemperature += args["temp"]
|
||||
|
||||
if(COMSIG_SET_BODYTEMP) // list("temp"=TEMP_IN_KELVIN)
|
||||
M.bodytemperature = args["temp"]
|
||||
|
||||
if(COMSIG_STATE) // list("state"=HOSTILE_STANCE_ATTACK)
|
||||
setState(args["state"])
|
||||
@@ -1,42 +1,61 @@
|
||||
/datum/component/controller/movement
|
||||
var/walk_delay = 4
|
||||
|
||||
/datum/component/controller/movement/basic/RecieveSignal(var/message_type, var/list/args)
|
||||
if(isliving(container.holder))
|
||||
var/mob/living/M=container.holder
|
||||
switch(message_type)
|
||||
if(COMSIG_MOVE)
|
||||
if("loc" in args)
|
||||
M.start_walk_to(args["loc"], 1, walk_delay)
|
||||
if("dir" in args)
|
||||
M.set_glide_size(DELAY2GLIDESIZE(walk_delay))
|
||||
walk(M, args["dir"], walk_delay)
|
||||
/datum/component/controller/movement/initialize()
|
||||
parent.register_event(/event/comp_ai_cmd_move, src, .proc/cmd_move)
|
||||
return TRUE
|
||||
|
||||
/datum/component/controller/movement/Destroy()
|
||||
parent.unregister_event(/event/comp_ai_cmd_move, src, .proc/cmd_move)
|
||||
..()
|
||||
|
||||
/datum/component/controller/movement/proc/cmd_move(target)
|
||||
CRASH("not implemented")
|
||||
|
||||
/datum/component/controller/movement/basic/cmd_move(target)
|
||||
var/mob/living/dude = parent
|
||||
if(isatom(target))
|
||||
dude.start_walk_to(target, 1, walk_delay)
|
||||
else if(isnum(target))
|
||||
dude.set_glide_size(DELAY2GLIDESIZE(walk_delay))
|
||||
walk(dude, target, walk_delay)
|
||||
else
|
||||
CRASH("target [target] is not an atom or a dir")
|
||||
/datum/component/controller/movement/astar
|
||||
var/list/movement_nodes = list()
|
||||
var/target
|
||||
|
||||
/datum/component/controller/movement/astar/RecieveSignal(var/message_type, var/list/args)
|
||||
if(isliving(container.holder))
|
||||
var/mob/living/M=container.holder
|
||||
if(message_type == COMSIG_MOVE)
|
||||
if("loc" in args)
|
||||
if(args["loc"] == target)
|
||||
return //We're already on our way there
|
||||
target = args["loc"]
|
||||
AStar(src, .proc/receive_path, M, target, /turf/proc/AdjacentTurfsSpace, /turf/proc/Distance, 0, 30, id=M.get_visible_id())
|
||||
if("dir" in args)
|
||||
movement_nodes = list()
|
||||
walk(M, args["dir"], walk_delay)
|
||||
if(message_type == COMSIG_LIFE)
|
||||
if(movement_nodes && movement_nodes.len && target && (target != null))
|
||||
if(movement_nodes.len > 0)
|
||||
step_to(M, movement_nodes[1])
|
||||
movement_nodes -= movement_nodes[1]
|
||||
else if(movement_nodes.len == 1)
|
||||
step_to(src, target)
|
||||
movement_nodes.Cut()
|
||||
return 1
|
||||
/datum/component/controller/movement/astar/initialize()
|
||||
active_components += src
|
||||
return ..()
|
||||
|
||||
/datum/component/controller/movement/astar/Destroy()
|
||||
active_components -= src
|
||||
..()
|
||||
|
||||
/datum/component/controller/movement/astar/cmd_move(target)
|
||||
var/mob/living/dude = parent
|
||||
if(isatom(target))
|
||||
if(src.target == target)
|
||||
return //We're already on our way there
|
||||
src.target = target
|
||||
walk_to(dude, target, 0, walk_delay)
|
||||
else if(isnum(target))
|
||||
movement_nodes = list()
|
||||
dude.set_glide_size(DELAY2GLIDESIZE(walk_delay))
|
||||
walk(dude, target, walk_delay)
|
||||
else
|
||||
CRASH("target [target] is not an atom or a dir")
|
||||
|
||||
/datum/component/controller/movement/astar/process()
|
||||
if(movement_nodes && movement_nodes.len && target)
|
||||
if(movement_nodes.len > 0)
|
||||
step_to(parent, movement_nodes[1])
|
||||
movement_nodes -= movement_nodes[1]
|
||||
else if(movement_nodes.len == 1)
|
||||
step_to(parent, target)
|
||||
movement_nodes.Cut()
|
||||
return 1
|
||||
|
||||
/datum/component/controller/movement/astar/proc/receive_path(var/list/L)
|
||||
if(islist(L))
|
||||
|
||||
@@ -1,8 +1,20 @@
|
||||
/datum/component/controller/simple_animal
|
||||
var/disable_automove_on_busy=1
|
||||
var/disable_automove_on_busy = TRUE
|
||||
|
||||
/datum/component/controller/simple_animal/setBusy(var/yes)
|
||||
..(yes)
|
||||
/datum/component/controller/simple_animal/initialize()
|
||||
parent.register_event(/event/comp_ai_cmd_can_attack, src, .proc/cmd_can_attack)
|
||||
return ..()
|
||||
|
||||
/datum/component/controller/simple_animal/Destroy()
|
||||
parent.unregister_event(/event/comp_ai_cmd_can_attack, src, .proc/cmd_can_attack)
|
||||
..()
|
||||
|
||||
/datum/component/controller/simple_animal/proc/cmd_can_attack(target)
|
||||
var/mob/living/simple_animal/SA = parent
|
||||
return SA.CanAttack(target)
|
||||
|
||||
/datum/component/controller/simple_animal/cmd_set_busy(yes)
|
||||
..()
|
||||
if(disable_automove_on_busy)
|
||||
var/mob/living/simple_animal/SA = holder
|
||||
var/mob/living/simple_animal/SA = parent
|
||||
SA.stop_automated_movement = yes
|
||||
|
||||
Reference in New Issue
Block a user