forked from Sanerres/vgstation13
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atoms_movable.dm
340 lines (289 loc) · 9.22 KB
/
atoms_movable.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/atom/movable
// Recycling shit
var/w_type = NOT_RECYCLABLE // Waste category for sorters. See setup.dm
layer = 3
var/last_move = null
var/anchored = 0
var/move_speed = 10
var/l_move_time = 1
var/m_flag = 1
var/throwing = 0
var/throw_speed = 2
var/throw_range = 7
var/moved_recently = 0
var/mob/pulledby = null
var/area/areaMaster
// Garbage collection (controller).
//var/gcDestroyed
//var/timeDestroyed
var/sound_override = 0 //Do we make a sound when bumping into something?
var/hard_deleted = 0
//glide_size = 8
/atom/movable/New()
. = ..()
areaMaster = get_area_master(src)
/atom/movable/Destroy()
gcDestroyed = "Bye, world!"
tag = null
loc = null
..()
/proc/delete_profile(var/type, code = 0)
if(!ticker || ticker.current_state < 3) return
if(code == 0)
if (!("[type]" in del_profiling))
del_profiling["[type]"] = 0
del_profiling["[type]"] += 1
else if(code == 1)
if (!("[type]" in ghdel_profiling))
ghdel_profiling["[type]"] = 0
ghdel_profiling["[type]"] += 1
else
if (!("[type]" in gdel_profiling))
gdel_profiling["[type]"] = 0
gdel_profiling["[type]"] += 1
soft_dels += 1
/atom/movable/Del()
if (gcDestroyed)
if (hard_deleted)
delete_profile("[type]", 1)
else
garbageCollector.dequeue("\ref[src]") // hard deletions have already been handled by the GC queue.
delete_profile("[type]", 2)
else // direct del calls or nulled explicitly.
delete_profile("[type]", 0)
Destroy()
..()
// Used in shuttle movement and AI eye stuff.
// Primarily used to notify objects being moved by a shuttle/bluespace fuckup.
/atom/movable/proc/setLoc(var/T, var/teleported=0)
loc = T
// Update on_moved listeners.
INVOKE_EVENT(on_moved,list("loc"=loc))
/atom/movable/Move(newLoc,Dir=0,step_x=0,step_y=0)
if(!loc || !newLoc)
return 0
//set up glide sizes before the move
//ensure this is a step, not a jump
//. = ..(NewLoc,Dir,step_x,step_y)
var/move_delay = 5 * world.tick_lag
if(ismob(src))
var/mob/M = src
if(M.client)
move_delay = (3+(M.client.move_delayer.next_allowed - world.time))*world.tick_lag
glide_size = Ceiling(32 / move_delay * world.tick_lag) - 1 //We always split up movements into cardinals for issues with diagonal movements.
var/atom/oldloc = loc
if((bound_height != 32 || bound_width != 32) && (loc == newLoc))
return ..()
if(loc != newLoc)
if (!(Dir & (Dir - 1))) //Cardinal move
. = ..()
else //Diagonal move, split it into cardinal moves
if (Dir & 1)
if (Dir & 4)
if (step(src, NORTH))
. = step(src, EAST)
else if (step(src, EAST))
. = step(src, NORTH)
else if (Dir & 8)
if (step(src, NORTH))
. = step(src, WEST)
else if (step(src, WEST))
. = step(src, NORTH)
else if (Dir & 2)
if (Dir & 4)
if (step(src, SOUTH))
. = step(src, EAST)
else if (step(src, EAST))
. = step(src, SOUTH)
else if (Dir & 8)
if (step(src, SOUTH))
. = step(src, WEST)
else if (step(src, WEST))
. = step(src, SOUTH)
if(!loc || (loc == oldloc && oldloc != newLoc))
last_move = 0
return
last_move = Dir
src.move_speed = world.timeofday - src.l_move_time
src.l_move_time = world.timeofday
// Update on_moved listeners.
INVOKE_EVENT(on_moved,list("loc"=newLoc))
return .
/atom/movable/proc/recycle(var/datum/materials/rec)
if(materials)
for(var/matid in materials.storage)
var/datum/material/material = materials.getMaterial(matid)
rec.addAmount(matid, materials.storage[matid] / material.cc_per_sheet) //the recycler's material is read as 1 = 1 sheet
materials.storage[matid] = 0
return 1
return 0
// Previously known as HasEntered()
// This is automatically called when something enters your square
/atom/movable/Crossed(atom/movable/AM)
return
/atom/movable/Bump(atom/Obstacle, yes)
if(src.throwing)
src.throw_impact(Obstacle)
src.throwing = 0
if ((Obstacle && yes))
Obstacle.last_bumped = world.time
Obstacle.Bumped(src)
return
..()
return
/atom/movable/proc/forceMove(atom/destination)
if(destination)
if(loc)
loc.Exited(src)
loc = destination
loc.Entered(src)
if(isturf(destination))
var/area/A = get_area_master(destination)
A.Entered(src)
for(var/atom/movable/AM in loc)
AM.Crossed(src)
// Update on_moved listeners.
INVOKE_EVENT(on_moved,list("loc"=loc))
return 1
return 0
/atom/movable/proc/forceEnter(atom/destination)
if(destination)
if(loc)
loc.Exited(src)
loc = destination
loc.Entered(src)
if(isturf(destination))
var/area/A = get_area_master(destination)
A.Entered(src)
return 1
return 0
/atom/movable/proc/hit_check(var/speed, mob/user)
if(src.throwing)
for(var/atom/A in get_turf(src))
if(A == src) continue
if(istype(A,/mob/living))
if(A:lying) continue
src.throw_impact(A, speed, user)
if(src.throwing == 1)
src.throwing = 0
if(isobj(A))
if(A.density && !A.throwpass) // **TODO: Better behaviour for windows which are dense, but shouldn't always stop movement
src.throw_impact(A, speed, user)
src.throwing = 0
/atom/movable/proc/throw_at(atom/target, range, speed, override = 1)
if(!target || !src) return 0
if(override)
sound_override = 1
//use a modified version of Bresenham's algorithm to get from the atom's current position to that of the target
throwing = 1
throw_speed = speed
var/mob/user
if(usr)
user = usr
if(M_HULK in usr.mutations)
src.throwing = 2 // really strong throw!
var/dist_x = abs(target.x - src.x)
var/dist_y = abs(target.y - src.y)
var/dx
if (target.x > src.x)
dx = EAST
else
dx = WEST
var/dy
if (target.y > src.y)
dy = NORTH
else
dy = SOUTH
var/dist_travelled = 0
var/dist_since_sleep = 0
var/area/a = get_area(src.loc)
if(dist_x > dist_y)
var/error = dist_x/2 - dist_y
while(src && target &&((((src.x < target.x && dx == EAST) || (src.x > target.x && dx == WEST)) && dist_travelled < range) || (a && a.has_gravity == 0) || istype(src.loc, /turf/space)) && src.throwing && istype(src.loc, /turf))
// only stop when we've gone the whole distance (or max throw range) and are on a non-space tile, or hit something, or hit the end of the map, or someone picks it up
if(error < 0)
var/atom/step = get_step(src, dy)
if(!step) // going off the edge of the map makes get_step return null, don't let things go off the edge
break
src.Move(step)
hit_check(throw_speed, user)
error += dist_x
dist_travelled++
dist_since_sleep++
if(dist_since_sleep >= throw_speed)
dist_since_sleep = 0
sleep(1)
else
var/atom/step = get_step(src, dx)
if(!step) // going off the edge of the map makes get_step return null, don't let things go off the edge
break
src.Move(step)
hit_check(throw_speed, user)
error -= dist_y
dist_travelled++
dist_since_sleep++
if(dist_since_sleep >= throw_speed)
dist_since_sleep = 0
sleep(1)
a = get_area(src.loc)
else
var/error = dist_y/2 - dist_x
while(src && target &&((((src.y < target.y && dy == NORTH) || (src.y > target.y && dy == SOUTH)) && dist_travelled < range) || (a && a.has_gravity == 0) || istype(src.loc, /turf/space)) && src.throwing && istype(src.loc, /turf))
// only stop when we've gone the whole distance (or max throw range) and are on a non-space tile, or hit something, or hit the end of the map, or someone picks it up
if(error < 0)
var/atom/step = get_step(src, dx)
if(!step) // going off the edge of the map makes get_step return null, don't let things go off the edge
break
src.Move(step)
hit_check(throw_speed, user)
error += dist_y
dist_travelled++
dist_since_sleep++
if(dist_since_sleep >= throw_speed)
dist_since_sleep = 0
sleep(1)
else
var/atom/step = get_step(src, dy)
if(!step) // going off the edge of the map makes get_step return null, don't let things go off the edge
break
src.Move(step)
hit_check(throw_speed, user)
error -= dist_x
dist_travelled++
dist_since_sleep++
if(dist_since_sleep >= throw_speed)
dist_since_sleep = 0
sleep(1)
a = get_area(src.loc)
//done throwing, either because it hit something or it finished moving
src.throwing = 0
if(isobj(src)) src.throw_impact(get_turf(src), throw_speed, user)
/atom/movable/change_area(oldarea, newarea)
areaMaster = newarea
..()
//Overlays
/atom/movable/overlay
var/atom/master = null
anchored = 1
/atom/movable/overlay/New()
. = ..()
verbs.len = 0
/atom/movable/overlay/attackby(a, b, c)
if (src.master)
return src.master.attackby(a, b, c)
return
/atom/movable/overlay/attack_paw(a, b, c)
if (src.master)
return src.master.attack_paw(a, b, c)
return
/atom/movable/overlay/attack_hand(a, b, c)
if (src.master)
return src.master.attack_hand(a, b, c)
return
/////////////////////////////
// SINGULOTH PULL REFACTOR
/////////////////////////////
/atom/movable/proc/canSingulothPull(var/obj/machinery/singularity/singulo)
return singuloCanEat()
/atom/movable/proc/say_understands(var/mob/other)
return 1