diff --git a/code/__DEFINES/ai/pet_commands.dm b/code/__DEFINES/ai/pet_commands.dm index 1e692b9f805..7404cb9acda 100644 --- a/code/__DEFINES/ai/pet_commands.dm +++ b/code/__DEFINES/ai/pet_commands.dm @@ -7,3 +7,6 @@ #define BB_PET_TARGETING_STRATEGY "BB_pet_targeting" /// Typecache of weakrefs to mobs this mob is friends with, will follow their instructions and won't attack them #define BB_FRIENDS_LIST "BB_friends_list" + +///mothroach next meal key! +#define BB_MOTHROACH_NEXT_EAT "mothroach_next_eat" diff --git a/code/datums/elements/basic_eating.dm b/code/datums/elements/basic_eating.dm index 92b303c9be2..4f4f493e0ef 100644 --- a/code/datums/elements/basic_eating.dm +++ b/code/datums/elements/basic_eating.dm @@ -93,4 +93,5 @@ if(isstack(target)) //if stack, only consume 1 var/obj/item/stack/food_stack = target final_target = food_stack.split_stack(eater, 1) + eater.log_message("has eaten [target]!", LOG_ATTACK) qdel(final_target) diff --git a/code/modules/mob/living/basic/vermin/mothroach.dm b/code/modules/mob/living/basic/vermin/mothroach/mothroach.dm similarity index 88% rename from code/modules/mob/living/basic/vermin/mothroach.dm rename to code/modules/mob/living/basic/vermin/mothroach/mothroach.dm index 4c06665a14a..a0079065de4 100644 --- a/code/modules/mob/living/basic/vermin/mothroach.dm +++ b/code/modules/mob/living/basic/vermin/mothroach/mothroach.dm @@ -36,6 +36,10 @@ /mob/living/basic/mothroach/Initialize(mapload) . = ..() + var/static/list/food_types = list(/obj/item/clothing) + AddElement(/datum/element/basic_eating, food_types = food_types) + ai_controller.set_blackboard_key(BB_BASIC_FOODS, typecacheof(food_types)) + AddElement(/datum/element/ai_retaliate) AddElement(/datum/element/pet_bonus, "squeaks happily!") add_verb(src, /mob/living/proc/toggle_resting) ADD_TRAIT(src, TRAIT_VENTCRAWLER_ALWAYS, INNATE_TRAIT) @@ -64,16 +68,6 @@ else playsound(loc, 'sound/voice/moth/scream_moth.ogg', 50, TRUE) -/datum/ai_controller/basic_controller/mothroach - blackboard = list() - - ai_traits = STOP_MOVING_WHEN_PULLED - ai_movement = /datum/ai_movement/basic_avoidance - idle_behavior = /datum/idle_behavior/idle_random_walk - planning_subtrees = list( - /datum/ai_planning_subtree/random_speech/mothroach, - ) - /mob/living/basic/mothroach/bar name = "mothroach bartender" desc = "A mothroach serving drinks. Look at him go." diff --git a/code/modules/mob/living/basic/vermin/mothroach/mothroach_ai.dm b/code/modules/mob/living/basic/vermin/mothroach/mothroach_ai.dm new file mode 100644 index 00000000000..5ef330cdc64 --- /dev/null +++ b/code/modules/mob/living/basic/vermin/mothroach/mothroach_ai.dm @@ -0,0 +1,35 @@ +#define MOTHROACH_EAT_TIMER 1 MINUTES + +/datum/ai_controller/basic_controller/mothroach + blackboard = list( + BB_FLEE_TARGETING_STRATEGY = /datum/targeting_strategy/basic, + BB_TARGETING_STRATEGY = /datum/targeting_strategy/basic/allow_items, + ) + + ai_traits = STOP_MOVING_WHEN_PULLED + ai_movement = /datum/ai_movement/basic_avoidance + idle_behavior = /datum/idle_behavior/idle_random_walk + planning_subtrees = list( + /datum/ai_planning_subtree/find_food/mothroach, + /datum/ai_planning_subtree/target_retaliate/to_flee, + /datum/ai_planning_subtree/flee_target/from_flee_key, + /datum/ai_planning_subtree/basic_melee_attack_subtree, + /datum/ai_planning_subtree/random_speech/mothroach, + ) + +/datum/ai_controller/basic_controller/mothroach/TryPossessPawn(atom/new_pawn) + . = ..() + if(. & AI_CONTROLLER_INCOMPATIBLE) + return + RegisterSignal(new_pawn, COMSIG_MOB_ATE, PROC_REF(on_eaten)) + +/datum/ai_controller/basic_controller/mothroach/proc/on_eaten(datum/source) + SIGNAL_HANDLER + set_blackboard_key(BB_MOTHROACH_NEXT_EAT, world.time + MOTHROACH_EAT_TIMER) + +/datum/ai_planning_subtree/find_food/mothroach/SelectBehaviors(datum/ai_controller/controller, seconds_per_tick) + if(world.time < controller.blackboard[BB_MOTHROACH_NEXT_EAT]) + return + return ..() + +#undef MOTHROACH_EAT_TIMER diff --git a/code/modules/vending/wardrobes.dm b/code/modules/vending/wardrobes.dm index 7df148e28db..44892713926 100644 --- a/code/modules/vending/wardrobes.dm +++ b/code/modules/vending/wardrobes.dm @@ -1,3 +1,7 @@ +GLOBAL_VAR_INIT(roaches_deployed, FALSE) +#define MOTHROACH_START_CHANCE 5 +#define MAX_MOTHROACH_AMOUNT 3 + /obj/item/vending_refill/wardrobe icon_state = "refill_clothes" @@ -8,6 +12,29 @@ panel_type = "panel19" light_mask = "wardrobe-light-mask" +/obj/machinery/vending/wardrobe/Initialize(mapload) + . = ..() + if(!mapload) + return + if(GLOB.roaches_deployed || !is_station_level(z) || !prob(MOTHROACH_START_CHANCE)) + return + for(var/count in 1 to rand(1, MAX_MOTHROACH_AMOUNT)) + new /mob/living/basic/mothroach(src) + GLOB.roaches_deployed = TRUE + + +/obj/machinery/vending/wardrobe/on_dispense(obj/item/clothing/food) + if(!istype(food)) + return + for(var/mob/living/basic/mothroach/roach in contents) + food.take_damage(food.get_integrity() * 0.5) + +/obj/machinery/vending/wardrobe/take_damage(damage_amount, damage_type = BRUTE, damage_flag = 0, sound_effect = 1, attack_dir) + . = ..() + for(var/mob/living/basic/mothroach/roach in contents) + roach.ai_controller.set_blackboard_key(BB_BASIC_MOB_FLEE_TARGET, src) //scatter away! + roach.forceMove(drop_location()) + /obj/machinery/vending/wardrobe/sec_wardrobe name = "\improper SecDrobe" desc = "A vending machine for security and security-related clothing!" @@ -706,3 +733,6 @@ /obj/item/vending_refill/wardrobe/cent_wardrobe machine_name = "CentDrobe" light_color = LIGHT_COLOR_ELECTRIC_GREEN + +#undef MOTHROACH_START_CHANCE +#undef MAX_MOTHROACH_AMOUNT diff --git a/tgstation.dme b/tgstation.dme index af3ba887086..a9de34c4ece 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -5046,9 +5046,10 @@ #include "code\modules\mob\living\basic\vermin\crab.dm" #include "code\modules\mob\living\basic\vermin\frog.dm" #include "code\modules\mob\living\basic\vermin\lizard.dm" -#include "code\modules\mob\living\basic\vermin\mothroach.dm" #include "code\modules\mob\living\basic\vermin\mouse.dm" #include "code\modules\mob\living\basic\vermin\space_bat.dm" +#include "code\modules\mob\living\basic\vermin\mothroach\mothroach.dm" +#include "code\modules\mob\living\basic\vermin\mothroach\mothroach_ai.dm" #include "code\modules\mob\living\brain\brain.dm" #include "code\modules\mob\living\brain\brain_cybernetic.dm" #include "code\modules\mob\living\brain\brain_item.dm"