diff --git a/code/datums/ai/basic_mobs/targetting_datums/with_object.dm b/code/datums/ai/basic_mobs/targetting_datums/with_object.dm new file mode 100644 index 00000000000000..039027b6aa5922 --- /dev/null +++ b/code/datums/ai/basic_mobs/targetting_datums/with_object.dm @@ -0,0 +1,39 @@ +/** + * Find mobs who are holding the configurable object type + * + * This is an extension of basic targeting behaviour, that allows you to + * only target the mob if they have a specific item in their hand. + * + */ +/datum/targetting_datum/basic/holding_object + // We will find mobs who are holding this object in their hands + var/object_type_path = null + +/** + * Create an instance of the holding object targeting datum + * + * * object_type_path Pass an object type path, this will be compared to the items + * in targets hands to filter the target list. + */ +/datum/targetting_datum/basic/holding_object/New(object_type_path) + if (!ispath(object_type_path)) + stack_trace("trying to create an item targeting datum with no valid typepath") + // Leaving object type as null will make this basically a noop + return + src.object_type_path = object_type_path + +///Returns true or false depending on if the target can be attacked by the mob +/datum/targetting_datum/basic/holding_object/can_attack(mob/living/living_mob, atom/target, vision_range, check_faction = FALSE) + if (object_type_path == null) + return FALSE // no op + if(!ismob(target)) + return FALSE // no hands no problems + + // Look at me, type casting like a grown up + var/mob/targetmob = target + // Check if our parent behaviour agrees we can attack this target (we ignore faction by default) + var/can_attack = ..() + if(can_attack && targetmob.is_holding_item_of_type(object_type_path)) + return TRUE // they have the item + // No valid target + return FALSE diff --git a/code/datums/ai/dog/dog_controller.dm b/code/datums/ai/dog/dog_controller.dm index 5a42cb43a1eb2c..fa0550d0197b90 100644 --- a/code/datums/ai/dog/dog_controller.dm +++ b/code/datums/ai/dog/dog_controller.dm @@ -18,8 +18,12 @@ /datum/ai_controller/basic_controller/dog/corgi blackboard = list( BB_DOG_HARASS_HARM = TRUE, + // IF you dont have this fleeing behavviour will just refuse to work, isn't that funny ha ha + BB_BASIC_MOB_FLEEING = TRUE, BB_VISION_RANGE = AI_DOG_VISION_RANGE, BB_PET_TARGETTING_DATUM = new /datum/targetting_datum/not_friends(), + // Find nearby mobs with tongs in hand. + BB_TARGETTING_DATUM = new /datum/targetting_datum/basic/holding_object(/obj/item/kitchen/tongs), BB_BABIES_PARTNER_TYPES = list(/mob/living/basic/pet/dog), BB_BABIES_CHILD_TYPES = list(/mob/living/basic/pet/dog/corgi/puppy = 95, /mob/living/basic/pet/dog/corgi/puppy/void = 5), ) @@ -29,6 +33,10 @@ /datum/ai_planning_subtree/make_babies, // Ian WILL prioritise sex over following your instructions /datum/ai_planning_subtree/pet_planning, /datum/ai_planning_subtree/dog_harassment, + // Find targets to run away from (uses the targetting datum from above) + /datum/ai_planning_subtree/simple_find_target, + // Flee from that target + /datum/ai_planning_subtree/flee_target, ) /datum/ai_controller/basic_controller/dog/corgi/get_access() diff --git a/tgstation.dme b/tgstation.dme index 75f4162ffd1816..e8eae21b359de2 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -871,6 +871,7 @@ #include "code\datums\ai\basic_mobs\pet_commands\play_dead.dm" #include "code\datums\ai\basic_mobs\targetting_datums\basic_targetting_datum.dm" #include "code\datums\ai\basic_mobs\targetting_datums\dont_target_friends.dm" +#include "code\datums\ai\basic_mobs\targetting_datums\with_object.dm" #include "code\datums\ai\cursed\cursed_behaviors.dm" #include "code\datums\ai\cursed\cursed_controller.dm" #include "code\datums\ai\cursed\cursed_subtrees.dm"