Skip to content

Commit

Permalink
More firearm datums + AI equipment & item bugfixes + AI now throw nad…
Browse files Browse the repository at this point in the history
…es at people in cover
  • Loading branch information
Zonespace27 committed Sep 19, 2024
1 parent 328dd91 commit 1e5e1cb
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 130 deletions.
2 changes: 2 additions & 0 deletions code/__DEFINES/equipment.dm
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
#define HEALING_ITEM (1<<16)
/// This item is classified as ammunition for the sake of human AI
#define AMMUNITION_ITEM (1<<17)
/// This item is classified as a grenade for the sake of human AI
#define GRENADE_ITEM (1<<18)
//==========================================================================================


Expand Down
1 change: 1 addition & 0 deletions code/__DEFINES/human_ai.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define HUMAN_AI_HEALTHITEMS "health"
#define HUMAN_AI_AMMUNITION "ammo"
#define HUMAN_AI_GRENADES "grenades"

/// Action is completed, delete this and move onto the next ongoing action
#define ONGOING_ACTION_COMPLETED "completed"
Expand Down
19 changes: 19 additions & 0 deletions code/game/objects/items/explosives/grenades/grenade.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
throw_range = 7
flags_atom = FPRINT|CONDUCT
flags_equip_slot = SLOT_WAIST
flags_item = GRENADE_ITEM
hitsound = 'sound/weapons/smash.ogg'
allowed_sensors = list(/obj/item/device/assembly/timer)
max_container_volume = 60
Expand Down Expand Up @@ -151,3 +152,21 @@
walk(src, null, null)
..()
return

/obj/item/explosive/grenade/ai_can_use(mob/living/carbon/human/user)
return TRUE

/obj/item/explosive/grenade/ai_use(mob/living/carbon/human/ai/user, turf/target_turf)
attack_self(user)
user.toggle_throw_mode(THROW_MODE_NORMAL)
user.ai_brain.ensure_primary_hand(src)
sleep(det_time * 0.4)
if(QDELETED(src) || (loc != user))
return

user.ai_brain.say_grenade_thrown_line()
sleep(det_time * 0.4)
if(QDELETED(src) || (loc != user))
return

user.throw_item(user.ai_brain.target_floor)
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,22 @@
return ONGOING_ACTION_COMPLETED

if(is_type_in_list(to_pickup, brain.all_medical_items))
brain.store_item(to_pickup, storage_spot)
brain.tied_human.put_in_hands(to_pickup, TRUE)
brain.store_item(to_pickup, storage_spot, HUMAN_AI_HEALTHITEMS)
return ONGOING_ACTION_COMPLETED

if(brain.primary_weapon && istype(to_pickup, /obj/item/ammo_magazine))
var/obj/item/ammo_magazine/mag = to_pickup
if(istype(brain.primary_weapon, mag.gun_type))
brain.store_item(to_pickup, storage_spot)
brain.tied_human.put_in_hands(to_pickup, TRUE)
brain.store_item(to_pickup, storage_spot, HUMAN_AI_AMMUNITION)
return ONGOING_ACTION_COMPLETED

if(istype(to_pickup, /obj/item/explosive/grenade))
var/obj/item/explosive/grenade/nade = to_pickup
if(!nade.active)
brain.tied_human.put_in_hands(to_pickup, TRUE)
brain.store_item(to_pickup, storage_spot, HUMAN_AI_GRENADES)
return ONGOING_ACTION_COMPLETED

return ONGOING_ACTION_COMPLETED
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/datum/ongoing_action/throw_grenade
name = "Throw Grenade"
var/obj/item/explosive/grenade/throwing
var/turf/target_turf
var/mid_throw = FALSE

/datum/ongoing_action/throw_grenade/New(datum/human_ai_brain/brain, list/arguments)
. = ..()
throwing = arguments[2]
target_turf = arguments[3]

/datum/ongoing_action/throw_grenade/Destroy(force, ...)
throwing = null
target_turf = null
return ..()

/datum/ongoing_action/throw_grenade/trigger_action()
if(QDELETED(throwing) || !target_turf)
return ONGOING_ACTION_COMPLETED

if(mid_throw)
return ONGOING_ACTION_UNFINISHED_BLOCK

mid_throw = TRUE
brain.holster_primary()
brain.equip_item_from_equipment_map(HUMAN_AI_GRENADES, throwing)
sleep(brain.short_action_delay * brain.action_delay_mult)
if(QDELETED(throwing) || (throwing.loc != brain.tied_human))
return ONGOING_ACTION_COMPLETED
throwing.ai_use(brain.tied_human, target_turf)
return ONGOING_ACTION_COMPLETED
1 change: 1 addition & 0 deletions code/modules/mob/living/carbon/human/ai/brain/ai_brain.dm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ GLOBAL_LIST_EMPTY(human_ai_brains)
target_floor = null
ongoing_order = null
GLOB.human_ai_brains -= src
gun_data = null
return ..()

/datum/human_ai_brain/process(delta_time)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Hostile spotted, engaging!",
"Enemy hostiles here!",
"Being fired upon!",
"Blast 'em!"
"Blast 'em!",
)

var/list/exit_combat_lines = list(
Expand All @@ -30,25 +30,42 @@
"Goddamn it.",
"Fuck!",
"Shit, our squad's down a man!",
"Squad integrity's failing!"
"Squad integrity's failing!",
)

var/list/grenade_thrown_lines = list(
"Nade out!",
"Tossing a grenade!",
"Smoking 'em out!",
"Throwing a nade!",
"Grenade out!",
"Tossing a nade!",
"Pineapple out!",
"Fragging 'em!",
)

var/in_combat_line_chance = 40
var/exit_combat_line_chance = 40
var/squad_member_death_line_chance = 20
var/grenade_thrown_line_chance = 60


/datum/human_ai_brain/proc/say_in_combat_line(chance = in_combat_line_chance)
if(!prob(chance))
if(!length(in_combat_lines) || !prob(chance))
return
tied_human.say(pick(in_combat_lines))

/datum/human_ai_brain/proc/say_exit_combat_line(chance = exit_combat_line_chance)
if(!prob(chance))
if(!length(exit_combat_lines) || !prob(chance))
return
tied_human.say(pick(exit_combat_lines))

/datum/human_ai_brain/proc/on_squad_member_death(mob/living/carbon/human/dead_member)
if(!prob(squad_member_death_line_chance))
if(!length(squad_member_death_lines) || !prob(squad_member_death_line_chance))
return
tied_human.say(pick(squad_member_death_lines))

/datum/human_ai_brain/proc/say_grenade_thrown_line(chance = grenade_thrown_line_chance)
if(!length(grenade_thrown_lines) || !prob(chance))
return
tied_human.say(pick(grenade_thrown_lines))
64 changes: 35 additions & 29 deletions code/modules/mob/living/carbon/human/ai/brain/ai_brain_factions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
VAR_PROTECTED/list/in_combat_lines = list()
VAR_PROTECTED/list/exit_combat_lines = list()
VAR_PROTECTED/list/squad_member_death_lines = list()
VAR_PROTECTED/list/grenade_thrown_lines = list()

VAR_PROTECTED/list/friendly_factions = list()
VAR_PROTECTED/list/neutral_factions = list()
Expand All @@ -19,6 +20,9 @@
if(length(squad_member_death_lines))
brain.squad_member_death_lines = squad_member_death_lines

if(length(grenade_thrown_lines))
brain.grenade_thrown_lines = grenade_thrown_lines

brain.shoot_to_kill = shoot_to_kill
brain.friendly_factions = friendly_factions
brain.neutral_factions = neutral_factions
Expand Down Expand Up @@ -102,35 +106,36 @@
FACTION_MERCENARY,
FACTION_TWE,
)
in_combat_lines = list( // zonenote: tweak these. They're entirely the stereotype of "communist russkie" when we can do better than that. also languages
"For the UPP!",
"Die, you animal!",
"Capitalist dog!",
"Shoot them!",
"For glorious Union!",
"Attacking!",
"We will bury them!",
"Uraaaa!!",
"URAAA!!",
"To your last breath!",
"You're worth nothing!",
"This is the end, for you!",
"Die!",
)
exit_combat_lines = list(
"I need a break...",
"Phew, that was tough work.",
"I think we can stop shooting now?",
"One step closer to victory!",
"Finally, break time.",
)
squad_member_death_lines = list(
"Man down!",
"Comrade!!",
"Get together!",
"Damn!",
"Taking hits!",
)
in_combat_lines = list( // zonenote: tweak these. They're entirely the stereotype of "communist russkie" when we can do better than that. also languages
"For the UPP!",
"Die, you animal!",
"Capitalist dog!",
"Shoot them!",
"For glorious Union!",
"Attacking!",
"We will bury them!",
"Uraaaa!!",
"URAAA!!",
"To your last breath!",
"You're worth nothing!",
"This is the end, for you!",
"Die!",
"*warcry",
)
exit_combat_lines = list(
"I need a break...",
"Phew, that was tough work.",
"I think we can stop shooting now?",
"One step closer to victory!",
"Finally, break time.",
)
squad_member_death_lines = list(
"Man down!",
"Comrade!!",
"Get together!",
"Damn!",
"Taking hits!",
)


/datum/human_ai_faction/wy
Expand Down Expand Up @@ -169,3 +174,4 @@
"Allied unit decomissioned.",
"Friendly unit disabled."
)
grenade_thrown_lines = list() // Wouldn't need to call this out
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@
return mag

/datum/human_ai_brain/proc/should_reload_primary()
return (primary_weapon?.current_mag?.current_rounds <= 0)
if(gun_data?.disposable)
return FALSE

if(primary_weapon?.current_mag?.current_rounds <= 0)
return TRUE
return FALSE
Loading

0 comments on commit 1e5e1cb

Please sign in to comment.