-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
194 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
24 changes: 24 additions & 0 deletions
24
monkestation/code/modules/ocean_content/mobs/ai/behaviours/attempt_group_find.dm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/datum/ai_behavior/attempt_group_find | ||
var/group_to_find = /datum/group_planning | ||
|
||
/datum/ai_behavior/attempt_group_find/perform(seconds_per_tick, datum/ai_controller/controller, ...) | ||
. = ..() | ||
for(var/mob/living/basic/found_basic in view(7, controller.pawn)) | ||
if(BB_GROUP_DATUM in found_basic.ai_controller.blackboard) | ||
var/datum/group_planning/found_group = found_basic.ai_controller.blackboard[BB_GROUP_DATUM] | ||
if(!found_group) | ||
continue | ||
if(found_group.type != group_to_find) | ||
continue | ||
controller.blackboard[BB_GROUP_DATUM] = found_group | ||
found_group.group_mobs |= controller.pawn | ||
finish_action(controller, TRUE) | ||
break | ||
|
||
var/datum/group_planning/new_group = new group_to_find | ||
controller.blackboard[BB_GROUP_DATUM] = new_group | ||
new_group.group_mobs |= controller.pawn | ||
finish_action(controller, TRUE) | ||
|
||
/datum/ai_behavior/attempt_group_find/fish | ||
group_to_find = /datum/group_planning/fish |
28 changes: 28 additions & 0 deletions
28
monkestation/code/modules/ocean_content/mobs/ai/behaviours/group_move_towards.dm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/datum/ai_behavior/step_towards_turf/group_movement | ||
overwrites_main = TRUE | ||
|
||
/datum/ai_behavior/step_towards_turf/group_movement/setup(datum/ai_controller/controller, turf_key) | ||
var/datum/group_planning/listed_group = controller.blackboard[BB_GROUP_DATUM] | ||
var/turf/target_turf = listed_group.target | ||
|
||
if(!target_turf) | ||
listed_group.decide_next_action() | ||
target_turf = listed_group.target | ||
if(!target_turf) | ||
return FALSE | ||
|
||
if (target_turf.z != controller.pawn.z) | ||
return FALSE | ||
|
||
var/turf/destination = plot_movement(controller, target_turf) | ||
if (!destination) | ||
return FALSE | ||
set_movement_target(controller, destination) | ||
return ..() | ||
|
||
|
||
/datum/ai_behavior/step_towards_turf/group_movement/finish_action(datum/ai_controller/controller, succeeded, ...) | ||
. = ..() | ||
var/datum/group_planning/listed_group = controller.blackboard[BB_GROUP_DATUM] | ||
if(listed_group) | ||
listed_group.finish_action(controller) |
10 changes: 10 additions & 0 deletions
10
monkestation/code/modules/ocean_content/mobs/ai/controller.dm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/datum/ai_controller/basic_controller/fish | ||
blackboard = list( | ||
BB_GROUP_DATUM = null | ||
) | ||
|
||
ai_movement = /datum/ai_movement/basic_avoidance | ||
idle_behavior = /datum/idle_behavior/idle_random_walk | ||
planning_subtrees = list( | ||
/datum/ai_planning_subtree/simple_create_or_follow_commands/fish, | ||
) |
24 changes: 24 additions & 0 deletions
24
monkestation/code/modules/ocean_content/mobs/ai/subtrees/simple_try_attach_group.dm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/datum/ai_planning_subtree/simple_create_or_follow_commands | ||
var/group_finding_behaviour = /datum/ai_behavior/attempt_group_find | ||
|
||
/datum/ai_planning_subtree/simple_create_or_follow_commands/fish | ||
group_finding_behaviour = /datum/ai_behavior/attempt_group_find/fish | ||
|
||
|
||
/datum/ai_planning_subtree/simple_create_or_follow_commands/SelectBehaviors(datum/ai_controller/controller, seconds_per_tick) | ||
var/datum/group_planning/attached = controller.blackboard[BB_GROUP_DATUM] | ||
if(!attached) | ||
controller.queue_behavior(group_finding_behaviour) | ||
return | ||
|
||
if(length(attached.in_progress_mobs) && !(controller.pawn in attached.in_progress_mobs) && !(controller.pawn in attached.finished_mobs)) | ||
attached.add_to_current_action(controller) | ||
return | ||
|
||
if(!attached.next_action > world.time && !length(attached.in_progress_mobs)) | ||
return | ||
|
||
if(!attached.fetched_behaviour) | ||
attached.decide_next_action() | ||
attached.bulk_queue() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/mob/living/basic/aquatic/fish | ||
icon = 'monkestation/code/modules/ocean_content/icons/fish.dmi' | ||
icon_state = "fish" | ||
icon_living = "fish" | ||
icon_dead = "fish_dead" | ||
icon_gib = "fish_dead" | ||
|
||
mob_size = MOB_SIZE_SMALL | ||
faction = list(FACTION_CARP) | ||
speak_emote = list("glubs") | ||
|
||
habitable_atmos = list("min_oxy" = 2, "max_oxy" = 0, "min_plas" = 0, "max_plas" = 0, "min_co2" = 0, "max_co2" = 0, "min_n2" = 0, "max_n2" = 0) | ||
minimum_survivable_temperature = 0 | ||
maximum_survivable_temperature = 1200 | ||
|
||
ai_controller = /datum/ai_controller/basic_controller/fish | ||
|
||
|
68 changes: 68 additions & 0 deletions
68
monkestation/code/modules/ocean_content/mobs/group_planning.dm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/datum/group_planning | ||
///when our next queuing is done | ||
var/next_action = 0 | ||
///our cooldown time of actions | ||
var/cooldown_time = 10 SECONDS | ||
///list of mobs in our group | ||
var/list/group_mobs = list() | ||
///list of mobs still executing our queued_behavior | ||
var/list/in_progress_mobs = list() | ||
///list of finished mobs | ||
var/list/finished_mobs = list() | ||
///our behaviour that we are queing | ||
var/queued_behavior | ||
///do we need to fetch a new behaviour? | ||
var/fetched_behaviour = FALSE | ||
///list of all behaviours we can do | ||
var/list/usable_behaviours = list() | ||
///our current_target | ||
var/atom/target | ||
|
||
/datum/group_planning/proc/bulk_queue() | ||
for(var/mob/living/basic/listed as anything in group_mobs) | ||
if(!istype(listed) || !listed.ai_controller || listed.stat == DEAD) //cull dead members that shouldn't exist anymore | ||
if(isbasicmob(listed) && listed.ai_controller && (BB_GROUP_DATUM in listed.ai_controller.blackboard)) | ||
listed.ai_controller.blackboard[BB_GROUP_DATUM] = null | ||
group_mobs -= listed | ||
continue | ||
listed.ai_controller.queue_behavior(queued_behavior) | ||
in_progress_mobs |= listed | ||
|
||
/datum/group_planning/proc/decide_next_action() | ||
if(length(in_progress_mobs)) | ||
return /// we are still doing an action | ||
if(!length(usable_behaviours)) | ||
return //how did this happen | ||
queued_behavior = pick(usable_behaviours) | ||
fetched_behaviour = TRUE | ||
|
||
/datum/group_planning/proc/add_to_current_action(datum/ai_controller/controller) | ||
controller.queue_behavior(queued_behavior) | ||
in_progress_mobs |= controller.pawn | ||
|
||
|
||
/datum/group_planning/proc/finish_action(datum/ai_controller/controller) | ||
if(controller.pawn in in_progress_mobs) | ||
in_progress_mobs -= controller.pawn | ||
finished_mobs += controller.pawn | ||
if(!length(in_progress_mobs)) | ||
next_action = world.time + cooldown_time | ||
fetched_behaviour = FALSE | ||
finished_mobs = list() | ||
|
||
/datum/group_planning/fish | ||
cooldown_time = 25 SECONDS | ||
usable_behaviours = list(/datum/ai_behavior/step_towards_turf/group_movement) | ||
|
||
/datum/group_planning/fish/decide_next_action() | ||
. = ..() | ||
var/mob/living/basic/picked_mob = pick(group_mobs) | ||
|
||
var/list/turfs = view(7, picked_mob) | ||
var/turf/picked | ||
var/sanity = 25 | ||
|
||
while(!isopenturf(picked) && sanity > 0) | ||
sanity-- | ||
picked = get_turf(pick(turfs)) | ||
target = picked |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters