Skip to content

Commit 54ddcf5

Browse files
authored
add: следующая итерация датумного ИИ у обезьян + собаки! (#6622)
* до фиксов * ЗАКОМПИЛЛИЛОСЬ * ой. * еще пачка фиксов * вырезание диспозала * наконец-то блин * сделано * пиздаа * первая пачка багфиксов теперь собак можно приковать к кроватям, плюсом они могут из них выбираться. Фиксы рантаймов у мартых * фиксы
1 parent b2f1cc3 commit 54ddcf5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1936
-236
lines changed

code/__DEFINES/ai.dm

Lines changed: 157 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
#define GET_AI_BEHAVIOR(behavior_type) SSai_controllers.ai_behaviors[behavior_type]
1+
#define GET_AI_BEHAVIOR(behavior_type) SSai_behaviors.ai_behaviors[behavior_type]
22
#define HAS_AI_CONTROLLER_TYPE(thing, type) istype(thing?.ai_controller, type)
33

4-
#define AI_STATUS_ON 1
5-
#define AI_STATUS_OFF 2
4+
#define AI_STATUS_ON 1
5+
#define AI_STATUS_OFF 2
66

77

88
///Monkey checks
99
#define SHOULD_RESIST(source) (source.on_fire || source.buckled || HAS_TRAIT(source, TRAIT_RESTRAINED) || (source.pulledby && source.pulledby.grab_state > GRAB_PASSIVE))
10+
#define IS_DEAD_OR_INCAP(source) (source.incapacitated() || source.stat)
1011

11-
///Max pathing attempts before auto-fail
12-
#define MAX_PATHING_ATTEMPTS 30
12+
///For JPS pathing, the maximum length of a path we'll try to generate. Should be modularized depending on what we're doing later on
13+
#define AI_MAX_PATH_LENGTH 30 // 30 is possibly overkill since by default we lose interest after 14 tiles of distance, but this gives wiggle room for weaving around obstacles
14+
15+
///Cooldown on planning if planning failed last time
16+
17+
#define AI_FAILED_PLANNING_COOLDOWN 1.5 SECONDS
1318

1419
///Flags for ai_behavior new()
1520
#define AI_CONTROLLER_INCOMPATIBLE (1<<0)
@@ -19,16 +24,163 @@
1924
///Does this task let you perform the action while you move closer? (Things like moving and shooting)
2025
#define AI_BEHAVIOR_MOVE_AND_PERFORM (1<<1)
2126

27+
///AI flags
28+
#define STOP_MOVING_WHEN_PULLED (1<<0)
29+
30+
///Subtree defines
31+
32+
///This subtree should cancel any further planning, (Including from other subtrees)
33+
#define SUBTREE_RETURN_FINISH_PLANNING 1
34+
35+
//Generic BB keys
36+
#define BB_CURRENT_MIN_MOVE_DISTANCE "min_move_distance"
2237

2338
///Monkey AI controller blackboard keys
2439

2540
#define BB_MONKEY_AGRESSIVE "BB_monkey_agressive"
41+
#define BB_MONKEY_GUN_NEURONS_ACTIVATED "BB_monkey_gun_aware"
42+
#define BB_MONKEY_GUN_WORKED "BB_monkey_gun_worked"
2643
#define BB_MONKEY_BEST_FORCE_FOUND "BB_monkey_bestforcefound"
2744
#define BB_MONKEY_ENEMIES "BB_monkey_enemies"
2845
#define BB_MONKEY_BLACKLISTITEMS "BB_monkey_blacklistitems"
2946
#define BB_MONKEY_PICKUPTARGET "BB_monkey_pickuptarget"
3047
#define BB_MONKEY_PICKPOCKETING "BB_monkey_pickpocketing"
3148
#define BB_MONKEY_CURRENT_ATTACK_TARGET "BB_monkey_current_attack_target"
49+
#define BB_MONKEY_CURRENT_PRESS_TARGET "BB_monkey_current_press_target"
50+
#define BB_MONKEY_CURRENT_GIVE_TARGET "BB_monkey_current_give_target"
3251
#define BB_MONKEY_TARGET_DISPOSAL "BB_monkey_target_disposal"
3352
#define BB_MONKEY_DISPOSING "BB_monkey_disposing"
3453
#define BB_MONKEY_RECRUIT_COOLDOWN "BB_monkey_recruit_cooldown"
54+
#define BB_MONKEY_NEXT_HUNGRY "BB_monkey_next_hungry"
55+
56+
57+
///Haunted item controller defines
58+
59+
///Chance for haunted item to haunt someone
60+
#define HAUNTED_ITEM_ATTACK_HAUNT_CHANCE 10
61+
///Chance for haunted item to try to get itself let go.
62+
#define HAUNTED_ITEM_ESCAPE_GRASP_CHANCE 20
63+
///Chance for haunted item to warp somewhere new
64+
#define HAUNTED_ITEM_TELEPORT_CHANCE 4
65+
///Amount of aggro you get when picking up a haunted item
66+
#define HAUNTED_ITEM_AGGRO_ADDITION 2
67+
68+
///Blackboard keys for haunted items
69+
#define BB_TO_HAUNT_LIST "BB_to_haunt_list"
70+
///Actual mob the item is haunting at the moment
71+
#define BB_HAUNT_TARGET "BB_haunt_target"
72+
///Amount of successful hits in a row this item has had
73+
#define BB_HAUNTED_THROW_ATTEMPT_COUNT "BB_haunted_throw_attempt_count"
74+
75+
///Cursed item controller defines
76+
77+
//defines
78+
///how far a cursed item will still try to chase a target
79+
#define CURSED_VIEW_RANGE 7
80+
#define CURSED_ITEM_TELEPORT_CHANCE 4
81+
//blackboards
82+
83+
///Actual mob the item is haunting at the moment
84+
#define BB_CURSE_TARGET "BB_haunt_target"
85+
///Where the item wants to land on
86+
#define BB_TARGET_SLOT "BB_target_slot"
87+
///Amount of successful hits in a row this item has had
88+
#define BB_CURSED_THROW_ATTEMPT_COUNT "BB_cursed_throw_attempt_count"
89+
90+
///Vending machine AI controller blackboard keys
91+
#define BB_VENDING_CURRENT_TARGET "BB_vending_current_target"
92+
#define BB_VENDING_TILT_COOLDOWN "BB_vending_tilt_cooldown"
93+
#define BB_VENDING_UNTILT_COOLDOWN "BB_vending_untilt_cooldown"
94+
#define BB_VENDING_BUSY_TILTING "BB_vending_busy_tilting"
95+
#define BB_VENDING_LAST_HIT_SUCCESSFUL "BB_vending_last_hit_succesful"
96+
97+
///Robot customer AI controller blackboard keys
98+
#define BB_CUSTOMER_CURRENT_ORDER "BB_customer_current_order"
99+
#define BB_CUSTOMER_MY_SEAT "BB_customer_my_seat"
100+
#define BB_CUSTOMER_PATIENCE "BB_customer_patience"
101+
#define BB_CUSTOMER_CUSTOMERINFO "BB_customer_customerinfo"
102+
#define BB_CUSTOMER_EATING "BB_customer_eating"
103+
#define BB_CUSTOMER_ATTENDING_VENUE "BB_customer_attending_avenue"
104+
#define BB_CUSTOMER_LEAVING "BB_customer_leaving"
105+
#define BB_CUSTOMER_CURRENT_TARGET "BB_customer_current_target"
106+
/// Robot customer has said their can't find seat line at least once. Used to rate limit how often they'll complain after the first time.
107+
#define BB_CUSTOMER_SAID_CANT_FIND_SEAT_LINE "BB_customer_said_cant_find_seat_line"
108+
109+
110+
///Hostile AI controller blackboard keys
111+
#define BB_HOSTILE_ORDER_MODE "BB_HOSTILE_ORDER_MODE"
112+
#define BB_HOSTILE_FRIEND "BB_HOSTILE_FRIEND"
113+
#define BB_HOSTILE_ATTACK_WORD "BB_HOSTILE_ATTACK_WORD"
114+
#define BB_FOLLOW_TARGET "BB_FOLLOW_TARGET"
115+
#define BB_ATTACK_TARGET "BB_ATTACK_TARGET"
116+
#define BB_VISION_RANGE "BB_VISION_RANGE"
117+
118+
/// Basically, what is our vision/hearing range.
119+
#define BB_HOSTILE_VISION_RANGE 10
120+
/// After either being given a verbal order or a pointing order, ignore further of each for this duration
121+
#define AI_HOSTILE_COMMAND_COOLDOWN 2 SECONDS
122+
123+
// hostile command modes (what pointing at something/someone does depending on the last order the carp heard)
124+
/// Don't do anything (will still react to stuff around them though)
125+
#define HOSTILE_COMMAND_NONE 0
126+
/// Will attack a target.
127+
#define HOSTILE_COMMAND_ATTACK 1
128+
/// Will follow a target.
129+
#define HOSTILE_COMMAND_FOLLOW 2
130+
131+
///Dog AI controller blackboard keys
132+
133+
#define BB_SIMPLE_CARRY_ITEM "BB_SIMPLE_CARRY_ITEM"
134+
#define BB_FETCH_TARGET "BB_FETCH_TARGET"
135+
#define BB_FETCH_IGNORE_LIST "BB_FETCH_IGNORE_LISTlist"
136+
#define BB_FETCH_DELIVER_TO "BB_FETCH_DELIVER_TO"
137+
#define BB_DOG_FRIENDS "BB_DOG_FRIENDS"
138+
#define BB_DOG_ORDER_MODE "BB_DOG_ORDER_MODE"
139+
#define BB_DOG_PLAYING_DEAD "BB_DOG_PLAYING_DEAD"
140+
#define BB_DOG_HARASS_TARGET "BB_DOG_HARASS_TARGET"
141+
142+
/// Basically, what is our vision/hearing range for picking up on things to fetch/
143+
#define AI_DOG_VISION_RANGE 10
144+
/// What are the odds someone petting us will become our friend?
145+
#define AI_DOG_PET_FRIEND_PROB 15
146+
/// After this long without having fetched something, we clear our ignore list
147+
#define AI_FETCH_IGNORE_DURATION 30 SECONDS
148+
/// After being ordered to heel, we spend this long chilling out
149+
#define AI_DOG_HEEL_DURATION 20 SECONDS
150+
/// After either being given a verbal order or a pointing order, ignore further of each for this duration
151+
#define AI_DOG_COMMAND_COOLDOWN 2 SECONDS
152+
153+
// dog command modes (what pointing at something/someone does depending on the last order the dog heard)
154+
/// Don't do anything (will still react to stuff around them though)
155+
#define DOG_COMMAND_NONE 0
156+
/// Will try to pick up and bring back whatever you point to
157+
#define DOG_COMMAND_FETCH 1
158+
/// Will get within a few tiles of whatever you point at and continually growl/bark. If the target is a living mob who gets too close, the dog will attack them with bites
159+
#define DOG_COMMAND_ATTACK 2
160+
161+
//enumerators for parsing command speech
162+
#define COMMAND_HEEL "Heel"
163+
#define COMMAND_FETCH "Fetch"
164+
#define COMMAND_FOLLOW "Follow"
165+
#define COMMAND_STOP "Stop"
166+
#define COMMAND_ATTACK "Attack"
167+
#define COMMAND_DIE "Play Dead"
168+
169+
///bane ai
170+
#define BB_BANE_BATMAN "BB_bane_batman"
171+
//yep thats it
172+
173+
174+
//Hunting defines
175+
#define SUCCESSFUL_HUNT_COOLDOWN 5 SECONDS
176+
177+
///Hunting BB keys
178+
#define BB_CURRENT_HUNTING_TARGET "BB_current_hunting_target"
179+
#define BB_HUNTING_COOLDOWN "BB_HUNTING_COOLDOWN"
180+
181+
///Basic Mob Keys
182+
183+
///Targetting subtrees
184+
#define BB_BASIC_MOB_CURRENT_TARGET "BB_basic_current_target"
185+
#define BB_BASIC_MOB_CURRENT_TARGET_HIDING_LOCATION "BB_basic_current_target_hiding_location"
186+
#define BB_TARGETTING_DATUM "targetting_datum"

code/__DEFINES/dcs/signals.dm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#define COMSIG_GLOB_MOB_DEATH "!mob_death"
1919
/// global living say plug - use sparingly: (mob/speaker , message)
2020
#define COMSIG_GLOB_LIVING_SAY_SPECIAL "!say_special"
21+
/// a person somewhere has thrown something : (mob/living/carbon/carbon_thrower, target)
22+
#define COMSIG_GLOB_CARBON_THROW_THING "!throw_thing"
2123
/// called by datum/cinematic/play() : (datum/cinematic/new_cinematic)
2224
#define COMSIG_GLOB_PLAY_CINEMATIC "!play_cinematic"
2325
#define COMPONENT_GLOB_BLOCK_CINEMATIC (1<<0)
@@ -486,6 +488,8 @@
486488
#define SPEECH_FORCED 7 */
487489
////from mob/living/adjust_fire_stacks()
488490
#define COMSIG_MOB_ADJUST_FIRE "mob_adjust_fire"
491+
/// from base of /mob/living/attack_alien(): (user)
492+
#define COMSIG_MOB_ATTACK_ALIEN "mob_attack_alien"
489493

490494
////from mob/living/adjust_wet_stacks()
491495
#define COMSIG_MOB_ADJUST_WET "mob_adjust_wet"

code/__DEFINES/is_helpers.dm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
#define isbrain(A) (istype(A, /mob/living/carbon/brain))
2323

24+
// basic mobs
25+
#define isbasicmob(A) (istype(A, /mob/living/basic))
26+
2427
// Carbon mobs
2528
#define iscarbon(A) (istype(A, /mob/living/carbon))
2629

code/__DEFINES/monkeys.dm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
#define MONKEY_ATTACK_DISARM_PROB 50
2626
/// probability that monkey will get recruited when friend is attacked
2727
#define MONKEY_RECRUIT_PROB 25
28-
28+
/// probability for the monkey to aggro when attacked
29+
#define MONKEY_RETALIATE_PROB 85
2930
/// probability for the monkey to aggro when attacked with harm intent
3031
#define MONKEY_RETALIATE_HARM_PROB 95
3132
/// probability for the monkey to aggro when attacked with disarm intent

code/__DEFINES/subsystems.dm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
#define FIRE_PRIORITY_AIR 20
126126
#define FIRE_PRIORITY_NPC 20
127127
#define FIRE_PRIORITY_NPC_MOVEMENT 21
128+
#define FIRE_PRIORITY_NPC_ACTIONS 22
128129
#define FIRE_PRIORITY_PATHFINDING 23
129130
#define FIRE_PRIORITY_PROCESS 25
130131
#define FIRE_PRIORITY_THROWING 25

code/__DEFINES/traits/declarations.dm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,5 @@ Remember to update _globalvars/traits.dm if you're adding/removing/renaming trai
299299
#define TRAIT_BLOB_ZOMBIFIED "blob_zombified"
300300

301301
#define TRAIT_BEING_OFFERED "offered"
302+
/// This atom can ignore the "is on a turf" check for simple AI datum attacks, allowing them to attack from bags or lockers as long as any other conditions are met
303+
#define TRAIT_AI_BAGATTACK "bagattack"

code/__HELPERS/heap.dm

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,35 @@
1111
L = new()
1212
cmp = compare
1313

14-
/datum/heap/proc/IsEmpty()
15-
return !L.len
14+
/datum/heap/Destroy(force, ...)
15+
for(var/i in L) // because this is before the list helpers are loaded
16+
qdel(i)
17+
L = null
18+
return ..()
1619

17-
//Insert and place at its position a new node in the heap
18-
/datum/heap/proc/Insert(atom/A)
20+
/datum/heap/proc/is_empty()
21+
return !length(L)
22+
23+
/// insert and place at its position a new node in the heap
24+
/datum/heap/proc/insert(atom/A)
1925

2026
L.Add(A)
21-
Swim(L.len)
27+
swim(length(L))
2228

2329
//removes and returns the first element of the heap
2430
//(i.e the max or the min dependant on the comparison function)
25-
/datum/heap/proc/Pop()
26-
if(!L.len)
31+
/datum/heap/proc/pop()
32+
if(!length(L))
2733
return null
2834
. = L[1]
2935

30-
L[1] = L[L.len]
31-
L.Cut(L.len)
32-
33-
Sink(1)
36+
L[1] = L[length(L)]
37+
L.Cut(length(L))
38+
if(length(L))
39+
sink(1)
3440

3541
//Get a node up to its right position in the heap
36-
/datum/heap/proc/Swim(index)
42+
/datum/heap/proc/swim(index)
3743
var/parent = round(index * 0.5)
3844

3945
while(parent > 0 && (call(cmp)(L[index], L[parent]) > 0))
@@ -42,21 +48,21 @@
4248
parent = round(index * 0.5)
4349

4450
//Get a node down to its right position in the heap
45-
/datum/heap/proc/Sink(index)
46-
var/g_child = GetGreaterChild(index)
51+
/datum/heap/proc/sink(index)
52+
var/g_child = get_greater_child(index)
4753

4854
while(g_child > 0 && (call(cmp)(L[index], L[g_child]) < 0))
4955
L.Swap(index, g_child)
5056
index = g_child
51-
g_child = GetGreaterChild(index)
57+
g_child = get_greater_child(index)
5258

5359
//Returns the greater (relative to the comparison proc) of a node children
5460
//or 0 if there's no child
55-
/datum/heap/proc/GetGreaterChild(index)
56-
if(index * 2 > L.len)
61+
/datum/heap/proc/get_greater_child(index)
62+
if(index * 2 > length(L))
5763
return 0
5864

59-
if(index * 2 + 1 > L.len)
65+
if(index * 2 + 1 > length(L))
6066
return index * 2
6167

6268
if(call(cmp)(L[index * 2], L[index * 2 + 1]) < 0)
@@ -65,11 +71,11 @@
6571
return index * 2
6672

6773
//Replaces a given node so it verify the heap condition
68-
/datum/heap/proc/ReSort(atom/A)
74+
/datum/heap/proc/resort(atom/A)
6975
var/index = L.Find(A)
7076

71-
Swim(index)
72-
Sink(index)
77+
swim(index)
78+
sink(index)
7379

7480
/datum/heap/proc/List()
7581
. = L.Copy()

code/__HELPERS/paths/jps.dm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
return FALSE
116116

117117
var/datum/jps_node/current_processed_node = new(start, -1, 0, end)
118-
open.Insert(current_processed_node)
118+
open.insert(current_processed_node)
119119
found_turfs[start] = TRUE // i'm sure this is fine
120120
return TRUE
121121

@@ -127,8 +127,8 @@
127127
if(QDELETED(requester))
128128
return FALSE
129129

130-
while(!open.IsEmpty() && !path)
131-
var/datum/jps_node/current_processed_node = open.Pop() //get the lower f_value turf in the open list
130+
while(!open.is_empty() && !path)
131+
var/datum/jps_node/current_processed_node = open.pop() //get the lower f_value turf in the open list
132132
if(max_distance && (current_processed_node.number_tiles > max_distance))//if too many steps, don't process that path
133133
continue
134134

@@ -239,7 +239,7 @@
239239
if(interesting)
240240
var/datum/jps_node/newnode = new(current_turf, parent_node, steps_taken)
241241
if(parent_node) // if we're a diagonal subscan, we'll handle adding ourselves to the heap in the diag
242-
open.Insert(newnode)
242+
open.insert(newnode)
243243
return newnode
244244

245245

@@ -309,10 +309,10 @@
309309

310310
if(interesting || possible_child_node)
311311
var/datum/jps_node/newnode = new(current_turf, parent_node, steps_taken)
312-
open.Insert(newnode)
312+
open.insert(newnode)
313313
if(possible_child_node)
314314
possible_child_node.update_parent(newnode)
315-
open.Insert(possible_child_node)
315+
open.insert(possible_child_node)
316316
if(possible_child_node.tile == end || (mintargetdist && (get_dist(possible_child_node.tile, end) <= mintargetdist)))
317317
unwind_path(possible_child_node)
318318
return

code/_onclick/other_mobs.dm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,12 @@
119119

120120
/mob/living/simple_animal/hostile/OnUnarmedAttack(atom/atom, proximity_flag)
121121
GiveTarget(atom)
122-
122+
123123
if(target)
124124
return AttackingTarget()
125125

126126
/atom/proc/attack_animal(mob/user)
127+
SEND_SIGNAL(src, COMSIG_ATOM_ATTACK_ANIMAL, user)
127128
return
128129

129130
/mob/living/RestrainedClickOn(atom/A)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PROCESSING_SUBSYSTEM_DEF(basic_avoidance)
2+
name = "Basic Avoidance"
3+
flags = SS_NO_INIT
4+
wait = 2 SECONDS

0 commit comments

Comments
 (0)