Skip to content

Commit

Permalink
Build override behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
xDanilcusx committed Nov 25, 2023
1 parent fb093b5 commit a42973d
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 9 deletions.
6 changes: 4 additions & 2 deletions code/__DEFINES/xeno_ai.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ PROBABILITY CALCULATIONS ARE HERE

#define XENO_SLASH 80

#define RETREAT_AT_PLASMA_LEVEL 0.2
#define RETREAT_AT_HEALTH_LEVEL 0.4
#define XENO_DOOR_BUILDING_CHANCE 25

#define PLASMA_RETREAT_PERCENTAGE 20
#define HEALTH_RETREAT_PERCENTAGE 40

#define LURKING_IGNORE_SHOT_CHANCE 75

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

/datum/component/ai_behavior_override/build
behavior_icon_state = "priority_move_order"

max_assigned = 1

/datum/component/ai_behavior_override/build/Initialize(...)
. = ..()

if(istype(parent, /mob))
return COMPONENT_INCOMPATIBLE

var/turf/open/location = get_turf(parent)
if(location.is_weedable() != FULLY_WEEDABLE)
return COMPONENT_INCOMPATIBLE

/datum/component/ai_behavior_override/build/Destroy(force, silent, ...)
var/turf/parent_turf = get_turf(parent)
if(QDELETED(parent) && parent_turf != parent)
parent_turf.AddComponent(/datum/component/ai_behavior_override/build)

return ..()

/datum/component/ai_behavior_override/build/check_behavior_validity(mob/living/carbon/xenomorph/checked_xeno, distance)
. = ..()
if(!.)
return

var/turf/open/location = get_turf(parent)
if(!istype(location))
qdel(src)
return FALSE

if(locate(/obj/structure/mineral_door/resin) in location)
qdel(src)
return FALSE

if(distance > 10)
return FALSE

if(checked_xeno.current_target)
return FALSE

if(!locate(/datum/action/xeno_action/activable/secrete_resin) in checked_xeno.actions)
return FALSE

if(checked_xeno.get_plasma_percentage() < PLASMA_RETREAT_PERCENTAGE)
if(checked_xeno.loc?:weeds)
checked_xeno.resting = TRUE
return FALSE

return TRUE

/datum/component/ai_behavior_override/build/process_override_behavior(mob/living/carbon/xenomorph/processing_xeno, delta_time)
. = ..()
if(!.)
return

processing_xeno.resting = FALSE

if(processing_xeno.loc?:density) // imagine putting droney in a bag
return FALSE

var/turf/parent_turf = get_turf(parent)

var/is_diagonal = (get_dir(processing_xeno, parent_turf) in diagonals)
if(is_diagonal || get_dist(processing_xeno, parent) > 1)
return processing_xeno.move_to_next_turf(parent_turf)

for(var/obj/structure/blocker in parent_turf.contents)
if(!blocker.unslashable && blocker.density || istype(blocker, /obj/structure/bed))
INVOKE_ASYNC(processing_xeno, TYPE_PROC_REF(/mob, do_click), blocker, "", list())
return TRUE

if(!parent_turf.weeds)
var/datum/action/xeno_action/onclick/plant_weeds/weeds_action = locate() in processing_xeno.actions
INVOKE_ASYNC(weeds_action, TYPE_PROC_REF(/datum/action/xeno_action/onclick/plant_weeds, use_ability_wrapper))
return TRUE

var/list/resin_types = processing_xeno.resin_build_order
processing_xeno.selected_resin = locate(/datum/resin_construction/resin_turf/wall) in resin_types

var/walls = 0
var/blocked_turfs = 0
for(var/turf/blocked_turf in orange(1, parent_turf) - parent_turf.AdjacentTurfs())
if(get_dir(blocked_turf, parent_turf) in diagonals)
continue

if(blocked_turf.density)
walls++

blocked_turfs++

if(blocked_turfs)
if(prob(XENO_DOOR_BUILDING_CHANCE) || (walls && blocked_turfs == 2))
processing_xeno.selected_resin = locate(/datum/resin_construction/resin_obj/door) in resin_types

var/datum/action/xeno_action/activable/secrete_resin/build_action = locate() in processing_xeno.actions
INVOKE_ASYNC(build_action, TYPE_PROC_REF(/datum/action/xeno_action/activable/secrete_resin, use_ability_wrapper), parent_turf)
return TRUE
4 changes: 2 additions & 2 deletions code/modules/admin/game_master/game_master.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ GLOBAL_VAR_INIT(radio_communication_clarity, 100)

// Behavior stuff
#define DEFAULT_BEHAVIOR_STRING "Attack"
#define SELECTABLE_XENO_BEHAVIORS list("Attack", "Capture", "Hive")
#define SELECTABLE_XENO_BEHAVIORS_ASSOC list("Attack" = /datum/component/ai_behavior_override/attack, "Capture" = /datum/component/ai_behavior_override/capture, "Hive" = /datum/component/ai_behavior_override/hive)
#define SELECTABLE_XENO_BEHAVIORS list("Attack", "Capture", "Hive", "Build")
#define SELECTABLE_XENO_BEHAVIORS_ASSOC list("Attack" = /datum/component/ai_behavior_override/attack, "Capture" = /datum/component/ai_behavior_override/capture, "Hive" = /datum/component/ai_behavior_override/hive, "Build" = /datum/component/ai_behavior_override/build)

// Objective stuff
#define OBJECTIVE_NUMBER_OPTIONS list("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine")
Expand Down
1 change: 1 addition & 0 deletions code/modules/mob/living/carbon/xenomorph/attack_alien.dm
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@
M.visible_message(SPAN_DANGER("[M] smashes \the [src] open!"), \
SPAN_DANGER("You smash \the [src] open!"), null, 5, CHAT_TYPE_XENO_COMBAT)
else
take_damage(M.melee_damage_upper)
M.visible_message(SPAN_DANGER("[M] smashes [src]!"), \
SPAN_DANGER("You smash [src]!"), null, 5, CHAT_TYPE_XENO_COMBAT)
return XENO_ATTACK_ACTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ GLOBAL_VAR_INIT(resin_lz_allowed, FALSE)
var/can_build_on_doors = TRUE // if it can be built on a tile with an open door or not

/datum/resin_construction/proc/can_build_here(turf/T, mob/living/carbon/xenomorph/X)
var/mob/living/carbon/xenomorph/blocker = locate() in T
if(blocker && blocker != X && blocker.stat != DEAD)
to_chat(X, SPAN_WARNING("Can't do that with [blocker] in the way!"))
return FALSE

if(!istype(T) || T.is_weedable() < FULLY_WEEDABLE)
to_chat(X, SPAN_WARNING("You can't do that here."))
return FALSE
Expand Down
1 change: 1 addition & 0 deletions colonialmarines.dme
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@
#include "code\datums\components\xeno\shield_slash.dm"
#include "code\datums\components\xeno\ai_behavior_overrides\attack_override_behavior.dm"
#include "code\datums\components\xeno\ai_behavior_overrides\base_override_behavior.dm"
#include "code\datums\components\xeno\ai_behavior_overrides\build_override_behavior.dm"
#include "code\datums\components\xeno\ai_behavior_overrides\capture_override_behavior.dm"
#include "code\datums\components\xeno\ai_behavior_overrides\hive_override_behavior.dm"
#include "code\datums\construction\construction_template.dm"
Expand Down

0 comments on commit a42973d

Please sign in to comment.