Skip to content

Commit

Permalink
Massive Sanity Edits (#1353)
Browse files Browse the repository at this point in the history
* Update _sanityloss_controller.dm

* Massive Insanity Edits

* Update _ai_controller.dm

* Reverts some weird/unnecessary changes.

* Update _ai_controller.dm

* Update hostile.dm
  • Loading branch information
LanceSmites328 authored Sep 22, 2023
1 parent 12ce47a commit d5b366d
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 23 deletions.
2 changes: 1 addition & 1 deletion code/__DEFINES/ai.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

///Monkey checks
#define SHOULD_RESIST(source) (source.on_fire || source.buckled || HAS_TRAIT(source, TRAIT_RESTRAINED) || (source.pulledby && source.pulledby.grab_state > GRAB_PASSIVE))
#define IS_DEAD_OR_INCAP(source) (HAS_TRAIT(source, TRAIT_INCAPACITATED) || HAS_TRAIT(source, TRAIT_HANDS_BLOCKED) || IS_IN_STASIS(source) || source.stat)
#define IS_DEAD_OR_INCAP(source) (HAS_TRAIT(source, TRAIT_INCAPACITATED) || IS_IN_STASIS(source) || source.stat)

///Max pathing attempts before auto-fail
#define MAX_PATHING_ATTEMPTS 16
Expand Down
2 changes: 2 additions & 0 deletions code/datums/ai/_ai_controller.dm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ have ways of interacting with a specific atom and control it. They posses a blac
/datum/ai_controller/proc/PossessPawn(atom/new_pawn)
if(pawn) //Reset any old signals
UnpossessPawn(FALSE)
return

if(istype(new_pawn.ai_controller)) //Existing AI, kill it.
QDEL_NULL(new_pawn.ai_controller)
Expand All @@ -60,6 +61,7 @@ have ways of interacting with a specific atom and control it. They posses a blac
set_ai_status(AI_STATUS_ON)

RegisterSignal(pawn, COMSIG_MOB_LOGIN, .proc/on_sentience_gained)
return

///Abstract proc for initializing the pawn to the new controller
/datum/ai_controller/proc/TryPossessPawn(atom/new_pawn)
Expand Down
2 changes: 2 additions & 0 deletions code/datums/ai/generic_actions.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/datum/ai_behavior/resist
required_distance = 0

/datum/ai_behavior/resist/perform(delta_time, datum/ai_controller/controller)
. = ..()
Expand Down
68 changes: 52 additions & 16 deletions code/datums/ai/sanity/_sanityloss_controller.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
BB_INSANE_PICKUPTARGET = null,\
BB_INSANE_CURRENT_ATTACK_TARGET = null)
max_target_distance = 20
var/resist_chance = 90
var/resist_chance = 60
var/datum/ai_behavior/say_line/insanity_lines/lines_type = /datum/ai_behavior/say_line/insanity_lines

/datum/ai_controller/insane/TryPossessPawn(atom/new_pawn)
Expand All @@ -20,6 +20,18 @@
RegisterSignal(new_pawn, COMSIG_LIVING_START_PULL, .proc/on_startpulling)
return ..() //Run parent at end

/datum/ai_controller/insane/UnpossessPawn(destroy)
UnregisterSignal(pawn, list(
COMSIG_PARENT_ATTACKBY,
COMSIG_ATOM_ATTACK_ANIMAL,
COMSIG_ATOM_ATTACK_HAND,
COMSIG_ATOM_BULLET_ACT,
COMSIG_ATOM_HITBY,
COMSIG_MOVABLE_CROSSED,
COMSIG_LIVING_START_PULL
))
return ..()

/datum/ai_controller/insane/able_to_run()
var/mob/living/carbon/human/human_pawn = pawn

Expand All @@ -29,11 +41,8 @@

/datum/ai_controller/insane/SelectBehaviors(delta_time)
current_behaviors = list()
var/mob/living/living_pawn = pawn

if(SHOULD_RESIST(living_pawn) && DT_PROB(resist_chance, delta_time))
current_behaviors += GET_AI_BEHAVIOR(/datum/ai_behavior/resist)
return
if(ResistCheck() && DT_PROB(resist_chance, delta_time))
current_behaviors |= GET_AI_BEHAVIOR(/datum/ai_behavior/resist)
return

/datum/ai_controller/insane/proc/retaliate(mob/living/L)
Expand Down Expand Up @@ -72,16 +81,20 @@

/datum/ai_controller/insane/proc/on_startpulling(datum/source, atom/movable/puller, state, force)
SIGNAL_HANDLER
return

/datum/ai_controller/insane/proc/ResistCheck()
var/mob/living/living_pawn = pawn
if(!living_pawn.stat)
INVOKE_ASYNC(living_pawn, .mob/living/verb/resist)
if(living_pawn.pulledby || SHOULD_RESIST(living_pawn))
return TRUE
return FALSE

/datum/ai_controller/insane/murder
lines_type = /datum/ai_behavior/say_line/insanity_lines
resist_chance = 80 // Anger powered break out attempts
var/list/currently_scared = list()
var/timerid = null
var/interest = 3

/datum/ai_controller/insane/murder/PerformMovement(delta_time)
if(!isnull(timerid))
Expand All @@ -93,12 +106,22 @@
if(!able_to_run() || !current_movement_target || QDELETED(current_movement_target) || current_movement_target.z != living_pawn.z || get_dist(living_pawn, current_movement_target) > max_target_distance)
timerid = null
return FALSE
timerid = addtimer(CALLBACK(src, .proc/MoveTo, delta_time), (living_pawn.cached_multiplicative_slowdown + 0.2))
var/mob/living/selected_enemy = blackboard[BB_INSANE_CURRENT_ATTACK_TARGET]
timerid = addtimer(CALLBACK(src, .proc/MoveTo, delta_time), (living_pawn.cached_multiplicative_slowdown*1.2)) // SLIGHTLY slower than what they should be *BUT* takes corners better.

var/turf/our_turf = get_turf(living_pawn)
var/turf/target_turf = get_step_towards(living_pawn, current_movement_target)
if(!is_type_in_typecache(target_turf, GLOB.dangerous_turfs))
living_pawn.Move(target_turf, get_dir(our_turf, target_turf))
if(!(selected_enemy in viewers(7, living_pawn))) // If you can't see the target enough
interest--
else
interest = 3
if(interest <= 0) // Give up
interest = 3
blackboard[BB_INSANE_CURRENT_ATTACK_TARGET] = null
CancelActions()
return
if(get_dist(living_pawn, current_movement_target) > max_target_distance)
CancelActions()
pathing_attempts = 0
Expand All @@ -117,10 +140,8 @@
if(selected_enemy)
if(selected_enemy.status_flags & GODMODE)
blackboard[BB_INSANE_CURRENT_ATTACK_TARGET] = null
if(!(selected_enemy in livinginrange(10, living_pawn)))
blackboard[BB_INSANE_CURRENT_ATTACK_TARGET] = null
return
if(selected_enemy.status_flags & GODMODE)
if(!(selected_enemy in livinginrange(10, living_pawn)))
blackboard[BB_INSANE_CURRENT_ATTACK_TARGET] = null
return
if(selected_enemy.stat != DEAD)
Expand All @@ -132,19 +153,34 @@
blackboard[BB_INSANE_CURRENT_ATTACK_TARGET] = null
return

for(var/mob/living/L in view(9, living_pawn))
if(TryFindWeapon()) // Find a weapon before a new enemy.
return

var/list/potential_enemies = viewers(9, living_pawn)

if(!LAZYLEN(potential_enemies)) // We aint see shit!
return

var/attempt_count = 0
for(var/mob/living/L in potential_enemies) // Oh the CHOICES!
if(L == living_pawn)
continue
if(L.status_flags & GODMODE)
continue
if(L.stat == DEAD)
continue
if(prob(33))
attempt_count++
if(DT_PROB(33, attempt_count) || potential_enemies.len == 1) // Target spotted (bold)
blackboard[BB_INSANE_CURRENT_ATTACK_TARGET] = L
return

if(TryFindWeapon())
return
/datum/ai_controller/insane/murder/ResistCheck()
var/mob/living/living_pawn = pawn
if(living_pawn.pulledby && living_pawn.pulledby?.grab_state < GRAB_AGGRESSIVE)
blackboard[BB_INSANE_CURRENT_ATTACK_TARGET] = living_pawn.pulledby
else
return SHOULD_RESIST(living_pawn)
return FALSE

/datum/ai_controller/insane/murder/proc/TryFindWeapon()
var/mob/living/living_pawn = pawn
Expand Down
18 changes: 14 additions & 4 deletions code/datums/ai/sanity/sanityloss_behaviors.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
var/mob/living/target = controller.blackboard[BB_INSANE_CURRENT_ATTACK_TARGET]
var/mob/living/living_pawn = controller.pawn

if(!target || target.stat == DEAD || target.status_flags & GODMODE)
if(!target || target?.stat == DEAD || target?.status_flags & GODMODE)
finish_action(controller, TRUE) //Target == owned

if(isturf(target.loc) && !IS_DEAD_OR_INCAP(living_pawn))
Expand All @@ -53,7 +53,6 @@
else
living_pawn.a_intent = INTENT_HARM
attack(controller, target, delta_time)
addtimer(CALLBACK(src, .proc/attack, controller, target, delta_time), CLICK_CD_MELEE * 0.75)


/datum/ai_behavior/insanity_attack_mob/finish_action(datum/ai_controller/controller, succeeded)
Expand All @@ -65,15 +64,15 @@
/// attack using a held weapon otherwise bite the enemy, then if we are angry there is a chance we might calm down a little
/datum/ai_behavior/insanity_attack_mob/proc/attack(datum/ai_controller/insane/murder/controller, mob/living/target, delta_time)
var/mob/living/living_pawn = controller.pawn
if(!living_pawn)
return

if(!living_pawn.Adjacent(target))
return

if(living_pawn.next_move > world.time)
return

living_pawn.changeNext_move(CLICK_CD_MELEE * 0.75) //We play half-fair

var/obj/item/weapon = null
var/highest_force = 5
for(var/obj/item/I in living_pawn.held_items)
Expand All @@ -96,9 +95,15 @@

// attack with weapon if we have one
if(weapon)
if(istype(weapon, /obj/item/ego_weapon))
var/obj/item/ego_weapon/EGO = weapon
living_pawn.changeNext_move(CLICK_CD_MELEE * EGO.attack_speed)
else
living_pawn.changeNext_move(CLICK_CD_MELEE)
weapon.melee_attack_chain(living_pawn, target)
else
living_pawn.UnarmedAttack(target)
living_pawn.changeNext_move(CLICK_CD_MELEE)

/datum/ai_behavior/insane_equip
behavior_flags = AI_BEHAVIOR_REQUIRE_MOVEMENT
Expand Down Expand Up @@ -207,6 +212,11 @@

/datum/ai_behavior/insanity_wander_center/proc/MoveInPath(datum/ai_controller/insane/wander/controller)
var/mob/living/living_pawn = controller.pawn
if(!living_pawn)
controller.pathing_attempts = 0
controller.current_path = list() // Reset the path and stop
finish_action(controller, TRUE)
return
// Insanity lines
if(world.time > controller.last_message + 4 SECONDS)
controller.last_message = world.time
Expand Down
2 changes: 0 additions & 2 deletions code/datums/status_effects/panic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,10 @@
/datum/status_effect/panicked_type/on_apply()
. = ..()
owner.add_overlay(mutable_appearance('icons/effects/effects.dmi', icon, -ABOVE_MOB_LAYER))
ADD_TRAIT(owner, TRAIT_GRAB_IMMUNE, TRAUMA_TRAIT)

/datum/status_effect/panicked_type/on_remove()
. = ..()
owner.cut_overlay(mutable_appearance('icons/effects/effects.dmi', icon, -ABOVE_MOB_LAYER))
REMOVE_TRAIT(owner, TRAIT_GRAB_IMMUNE, TRAUMA_TRAIT)

/datum/status_effect/panicked_type/be_replaced()
owner.cut_overlay(mutable_appearance('icons/effects/effects.dmi', icon, -ABOVE_MOB_LAYER))
Expand Down
14 changes: 14 additions & 0 deletions code/modules/mob/living/carbon/human/human_movement.dm
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,17 @@
if(dna.species.space_move(src))
return TRUE
return ..()

/mob/living/carbon/human/CanAllowThrough(atom/movable/mover, turf/target)
. = ..()
if(.) // If we're already letting them through, then might as well not check anything else.
return
if(!sanity_lost) // If we're not crazy, why the hell would we do these things?
return
if(ishostile(mover)) // Is it a threat that we now don't care about?
return TRUE
if(ishuman(mover)) // Is it another crazy person?
var/mob/living/carbon/human/H = mover
if(H.sanity_lost)
return TRUE
return
19 changes: 19 additions & 0 deletions code/modules/mob/living/simple_animal/hostile/hostile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,25 @@
else
return ..()

/mob/living/simple_animal/hostile/CanAllowThrough(atom/movable/mover, turf/target)
. = ..()
if(.)
return
if(target == mover) // "I'm KILLING YOU, I'm KILLING YOU" - Jerma985
return FALSE
if(ishostile(mover))
var/mob/living/simple_animal/hostile/H = mover
if(H.target)
return
if(LAZYLEN(H.patrol_path)) // Don't block patrolling guys
return TRUE
return
if(ishuman(mover))
var/mob/living/carbon/human/H = mover
if(H.sanity_lost) // Don't block crazy people
return TRUE
return

/mob/living/simple_animal/hostile/proc/dodge(moving_to,move_direction)
//Assuming we move towards the target we want to swerve toward them to get closer
var/cdir = turn(move_direction,45)
Expand Down

0 comments on commit d5b366d

Please sign in to comment.