/
ai.dm
284 lines (223 loc) · 7.42 KB
/
ai.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*
AI ClickOn()
The AI can double click to move the camera (this was already true but is cleaner),
or double click a mob to track them.
Note that AI have no need for the adjacency proc, and so this proc is a lot cleaner.
*/
/mob/living/silicon/ai/DblClickOn(atom/A, params)
if(control_disabled || incapacitated())
return
if(ismob(A))
ai_tracking_tool.track_mob(src, A)
else
A.move_camera_by_click()
/mob/living/silicon/ai/ClickOn(atom/A, params)
if(world.time <= next_click)
return
next_click = world.time + 1
var/list/modifiers = params2list(params)
if(SEND_SIGNAL(src, COMSIG_MOB_CLICKON, A, modifiers) & COMSIG_MOB_CANCEL_CLICKON)
return
if(!can_interact_with(A))
return
if(multicam_on)
var/turf/T = get_turf(A)
if(T)
for(var/atom/movable/screen/movable/pic_in_pic/ai/P in T.vis_locs)
if(P.ai == src)
P.Click(params)
break
if(check_click_intercept(params,A))
return
if(control_disabled || incapacitated())
return
var/turf/pixel_turf = get_turf_pixel(A)
if(isnull(pixel_turf))
return
if(!can_see(A))
return
if(LAZYACCESS(modifiers, SHIFT_CLICK))
if(LAZYACCESS(modifiers, CTRL_CLICK))
CtrlShiftClickOn(A)
return
ShiftClickOn(A)
return
if(LAZYACCESS(modifiers, ALT_CLICK)) // alt and alt-gr (rightalt)
ai_base_click_alt(A)
return
if(LAZYACCESS(modifiers, CTRL_CLICK))
CtrlClickOn(A)
return
if(LAZYACCESS(modifiers, MIDDLE_CLICK))
MiddleClickOn(A, params)
return
if(LAZYACCESS(modifiers, RIGHT_CLICK))
var/secondary_result = A.attack_ai_secondary(src, modifiers)
if(secondary_result == SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN || secondary_result == SECONDARY_ATTACK_CONTINUE_CHAIN)
return
else if(secondary_result != SECONDARY_ATTACK_CALL_NORMAL)
CRASH("attack_ai_secondary did not return a SECONDARY_ATTACK_* define.")
if(world.time <= next_move)
return
if(waypoint_mode)
waypoint_mode = 0
set_waypoint(A)
return
A.attack_ai(src)
/*
AI has no need for the UnarmedAttack() and RangedAttack() procs,
because the AI code is not generic; attack_ai() is used instead.
The below is only really for safety, or you can alter the way
it functions and re-insert it above.
*/
/mob/living/silicon/ai/UnarmedAttack(atom/A, proximity_flag, list/modifiers)
A.attack_ai(src)
/mob/living/silicon/ai/RangedAttack(atom/A)
A.attack_ai(src)
/atom/proc/attack_ai(mob/user)
return
/**
* What happens when the AI holds right-click on an item. Returns a SECONDARY_ATTACK_* value.
*
* Arguments:
* * user The mob holding the right click
* * modifiers The list of the custom click modifiers
*/
/atom/proc/attack_ai_secondary(mob/user, list/modifiers)
return SECONDARY_ATTACK_CALL_NORMAL
/*
Since the AI handles shift, ctrl, and alt-click differently
than anything else in the game, atoms have separate procs
for AI shift, ctrl, and alt clicking.
*/
/mob/living/silicon/ai/CtrlShiftClickOn(atom/target)
target.AICtrlShiftClick(src)
/mob/living/silicon/ai/ShiftClickOn(atom/target)
target.AIShiftClick(src)
/mob/living/silicon/ai/CtrlClickOn(atom/target)
target.AICtrlClick(src)
/// Reimplementation of base_click_alt for AI
/mob/living/silicon/ai/proc/ai_base_click_alt(atom/target)
// If for some reason we can't alt click
if(SEND_SIGNAL(src, COMSIG_MOB_ALTCLICKON, target) & COMSIG_MOB_CANCEL_CLICKON)
return
if(!isturf(target) && can_perform_action(target, (target.interaction_flags_click | SILENT_ADJACENCY)))
// Signal intercept
if(SEND_SIGNAL(target, COMSIG_CLICK_ALT, src) & CLICK_ACTION_ANY)
return
// AI alt click interaction succeeds
if(target.ai_click_alt(src) & CLICK_ACTION_ANY)
return
client.loot_panel.open(get_turf(target))
/*
The following criminally helpful code is just the previous code cleaned up;
I have no idea why it was in atoms.dm instead of respective files.
*/
/* Questions: Instead of an Emag check on every function, can we not add to airlocks onclick if emag return? */
/* Atom Procs */
/atom/proc/AICtrlClick(mob/living/silicon/ai/user)
return
/atom/proc/ai_click_alt(mob/living/silicon/ai/user)
return
/atom/proc/AIShiftClick(mob/living/silicon/ai/user)
return
/atom/proc/AICtrlShiftClick(mob/living/silicon/ai/user)
return
/* Airlocks */
/obj/machinery/door/airlock/AICtrlClick(mob/living/silicon/ai/user) // Bolts doors
if(obj_flags & EMAGGED)
return
toggle_bolt(user)
add_hiddenprint(user)
/obj/machinery/door/airlock/ai_click_alt(mob/living/silicon/ai/user)
if(obj_flags & EMAGGED)
return
if(!secondsElectrified)
shock_perm(user)
else
shock_restore(user)
/obj/machinery/door/airlock/AIShiftClick(mob/living/silicon/ai/user) // Opens and closes doors!
if(obj_flags & EMAGGED)
return
user_toggle_open(user)
add_hiddenprint(user)
/obj/machinery/door/airlock/AICtrlShiftClick(mob/living/silicon/ai/user) // Sets/Unsets Emergency Access Override
if(obj_flags & EMAGGED)
return
toggle_emergency(user)
add_hiddenprint(user)
/////////////
/* APC */
/////////////
/// Toggle APC power settings
/obj/machinery/power/apc/AICtrlClick(mob/living/silicon/ai/user)
if(!can_use(user, loud = TRUE))
return
toggle_breaker(user)
/// Toggle APC environment settings (atmos)
/obj/machinery/power/apc/AICtrlShiftClick(mob/living/silicon/ai/user)
if(!can_use(user, loud = TRUE))
return
if(!is_operational || failure_timer)
return
environ = environ ? APC_CHANNEL_OFF : APC_CHANNEL_ON
if (user)
add_hiddenprint(user)
var/enabled_or_disabled = environ ? "enabled" : "disabled"
balloon_alert(user, "environment power [enabled_or_disabled]")
user.log_message("[enabled_or_disabled] the [src] environment settings", LOG_GAME)
update_appearance()
update()
/// Toggle APC lighting settings
/obj/machinery/power/apc/AIShiftClick(mob/living/silicon/ai/user)
if(!can_use(user, loud = TRUE))
return
if(!is_operational || failure_timer)
return
lighting = lighting ? APC_CHANNEL_OFF : APC_CHANNEL_ON
if (user)
var/enabled_or_disabled = lighting ? "enabled" : "disabled"
add_hiddenprint(user)
balloon_alert(user, "lighting power toggled [enabled_or_disabled]")
user.log_message("turned [enabled_or_disabled] the [src] lighting settings", LOG_GAME)
update_appearance()
update()
/// Toggle APC equipment settings
/obj/machinery/power/apc/ai_click_alt(mob/living/silicon/ai/user)
if(!can_use(user, loud = TRUE))
return
if(!is_operational || failure_timer)
return
equipment = equipment ? APC_CHANNEL_OFF : APC_CHANNEL_ON
if (user)
var/enabled_or_disabled = equipment ? "enabled" : "disabled"
balloon_alert(user, "equipment power toggled [enabled_or_disabled]")
add_hiddenprint(user)
user.log_message("turned [enabled_or_disabled] the [src] equipment settings", LOG_GAME)
update_appearance()
update()
/obj/machinery/power/apc/attack_ai_secondary(mob/living/silicon/user, list/modifiers)
if(!can_use(user, loud = TRUE))
return
togglelock(user)
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
/* AI Turrets */
/obj/machinery/turretid/ai_click_alt(mob/living/silicon/ai/user) //toggles lethal on turrets
if(ailock)
return
toggle_lethal(user)
/obj/machinery/turretid/AICtrlClick(mob/living/silicon/ai/user) //turns off/on Turrets
if(ailock)
return
toggle_on(user)
/* Holopads */
/obj/machinery/holopad/ai_click_alt(mob/living/silicon/ai/user)
if (user)
balloon_alert(user, "disrupted all active calls")
add_hiddenprint(user)
hangup_all_calls()
//
// Override TurfAdjacent for AltClicking
//
/mob/living/silicon/ai/TurfAdjacent(turf/target_turf)
return (GLOB.cameranet && GLOB.cameranet.checkTurfVis(target_turf))