forked from Darkrp-community/OpenKeep
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds in idle trees and eating behaviours
- Loading branch information
Showing
15 changed files
with
169 additions
and
56 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
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,3 @@ | ||
/datum/idle_behavior | ||
/datum/idle_behavior/proc/perform_idle_behavior(delta_time, datum/ai_controller/controller) | ||
return |
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,73 @@ | ||
/**find and set | ||
* Finds an item near themselves, sets a blackboard key as it. Very useful for ais that need to use machines or something. | ||
* if you want to do something more complicated than find a single atom, change the search_tactic() proc | ||
* cool tip: search_tactic() can set lists | ||
*/ | ||
/datum/ai_behavior/find_and_set | ||
action_cooldown = 2 SECONDS | ||
|
||
/datum/ai_behavior/find_and_set/perform(delta_time, datum/ai_controller/controller, set_key, locate_path, search_range) | ||
. = ..() | ||
var/find_this_thing = search_tactic(controller, locate_path, search_range) | ||
if(find_this_thing) | ||
controller.blackboard[set_key] = WEAKREF(find_this_thing) | ||
finish_action(controller, TRUE) | ||
else | ||
finish_action(controller, FALSE) | ||
|
||
/datum/ai_behavior/find_and_set/proc/search_tactic(datum/ai_controller/controller, locate_path, search_range) | ||
return locate(locate_path) in oview(search_range, controller.pawn) | ||
|
||
/** | ||
* Variant of find and set that fails if the living pawn doesn't hold something | ||
*/ | ||
/datum/ai_behavior/find_and_set/pawn_must_hold_item | ||
|
||
/datum/ai_behavior/find_and_set/pawn_must_hold_item/search_tactic(datum/ai_controller/controller) | ||
var/mob/living/living_pawn = controller.pawn | ||
if(!living_pawn.get_inactive_held_item() && !living_pawn.get_active_held_item()) | ||
return //we want to fail the search if we don't have something held | ||
return ..() | ||
|
||
/** | ||
* Variant of find and set that also requires the item to be edible. checks hands too | ||
*/ | ||
/datum/ai_behavior/find_and_set/edible | ||
|
||
/datum/ai_behavior/find_and_set/edible/search_tactic(datum/ai_controller/controller, locate_path, search_range) | ||
var/mob/living/living_pawn = controller.pawn | ||
var/list/food_candidates = list() | ||
for(var/held_candidate as anything in living_pawn.held_items) | ||
if(!held_candidate || !istype(held_candidate, /obj/item/reagent_containers/food)) | ||
continue | ||
food_candidates += held_candidate | ||
var/list/local_results = locate(locate_path) in oview(search_range, controller.pawn) | ||
for(var/local_candidate in local_results) | ||
if(!istype(local_candidate, /obj/item/reagent_containers/food)) | ||
continue | ||
food_candidates += local_candidate | ||
if(food_candidates.len) | ||
return pick(food_candidates) | ||
|
||
/** | ||
* Variant of find and set that only checks in hands, search range should be excluded for this | ||
*/ | ||
/datum/ai_behavior/find_and_set/in_hands | ||
|
||
/datum/ai_behavior/find_and_set/in_hands/search_tactic(datum/ai_controller/controller, locate_path) | ||
var/mob/living/living_pawn = controller.pawn | ||
return locate(locate_path) in living_pawn.held_items | ||
|
||
/** | ||
* Variant of find and set that takes a list of things to find. | ||
*/ | ||
/datum/ai_behavior/find_and_set/in_list | ||
|
||
/datum/ai_behavior/find_and_set/in_list/search_tactic(datum/ai_controller/controller, locate_paths, search_range) | ||
var/list/found = list() | ||
for(var/locate_path in locate_paths) | ||
var/single_locate = ..(controller, locate_path, search_range) | ||
if(single_locate) | ||
found += single_locate | ||
if(found.len) | ||
return pick(found) |
This file was deleted.
Oops, something went wrong.
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
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
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/idle_behavior/idle_random_walk | ||
///Chance that the mob random walks per second | ||
var/walk_chance = 10 | ||
|
||
/datum/idle_behavior/idle_random_walk/perform_idle_behavior(delta_time, datum/ai_controller/controller) | ||
. = ..() | ||
var/mob/living/living_pawn = controller.pawn | ||
if(prob(walk_chance * delta_time) && (living_pawn.mobility_flags & MOBILITY_MOVE) && isturf(living_pawn.loc) && !living_pawn.pulledby) | ||
var/move_dir = pick(GLOB.alldirs) | ||
living_pawn.Move(get_step(living_pawn, move_dir), move_dir) |
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 @@ | ||
/// similar to finding a target but looks for food types in the | ||
/datum/ai_planning_subtree/find_food | ||
|
||
/datum/ai_planning_subtree/find_food/SelectBehaviors(datum/ai_controller/controller, delta_time) | ||
. = ..() | ||
var/atom/target = controller.blackboard[BB_BASIC_MOB_CURRENT_TARGET] | ||
if(target && !QDELETED(target)) | ||
return | ||
var/list/wanted = controller.blackboard[BB_BASIC_FOODS] | ||
controller.queue_behavior(/datum/ai_behavior/find_and_set/in_list, BB_BASIC_MOB_CURRENT_TARGET, wanted) |
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
9 changes: 9 additions & 0 deletions
9
code/datums/ai/targetting_datum/simple_targetting_allow_item.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,9 @@ | ||
/// Subtype more forgiving for items. | ||
/// Careful, this can go wrong and keep a mob hyperfocused on an item it can't lose aggro on | ||
/datum/targetting_datum/basic/allow_items | ||
|
||
/datum/targetting_datum/basic/allow_items/can_attack(mob/living/living_mob, atom/the_target) | ||
. = ..() | ||
if(isitem(the_target)) | ||
// trust fall exercise | ||
return TRUE |
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