-
Notifications
You must be signed in to change notification settings - Fork 1
/
Movement.dm
370 lines (340 loc) · 10.9 KB
/
Movement.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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
mob/player/client
Bump(atom/A)
..()
switch(A.rtype)
if(43)
step(A, src.dir)
if(45)
var/Tiles/Barricades/B = A
if(B.big)
B.pushing += 1
spawn(1)
B.pushing -= 1
if(B.pushing >= B.need_pushing)
step(B, src.dir)
else
step(B, src.dir)
client
New()
..()
setMacros()
// These are here so the default movement commands don't interfere.
North()
South()
East()
West()
Northeast()
Northwest()
Southeast()
Southwest()
proc
// setMacros() injects movement commands into all macro lists.
setMacros()
var/macros=params2list(winget(src,null,"macro"))
for(var/m in macros)
winset(src,"NORTH","parent=[m];name=NORTH;command=north")
winset(src,"NORTH+UP","parent=[m];name=NORTH+UP;command=north-up")
winset(src,"WEST","parent=[m];name=WEST;command=west")
winset(src,"WEST+UP","parent=[m];name=WEST+UP;command=west-up")
winset(src,"SOUTH","parent=[m];name=SOUTH;command=south")
winset(src,"SOUTH+UP","parent=[m];name=SOUTH+UP;command=south-up")
winset(src,"EAST","parent=[m];name=EAST;command=east")
winset(src,"EAST+UP","parent=[m];name=EAST+UP;command=east-up")
mob/player/client
verb
north()
set
hidden=1
instant=1
src.keySet(NORTH)
north_up()
set
hidden=1
instant=1
src.keyDel(NORTH)
south()
set
hidden=1
instant=1
src.keySet(SOUTH)
south_up()
set
hidden=1
instant=1
src.keyDel(SOUTH)
east()
set
hidden=1
instant=1
if(src.is_dead)
if(length(ptracker))
src.spec_number ++
if(src.spec_number > length(ptracker)) src.spec_number = 1
var/mob/player/client/N = ptracker[src.spec_number]
if(N) src.client.eye = N; src.client.chat.addText("Spectating: [N]", ChatFont, true)
src.keySet(EAST)
east_up()
set
hidden=1
instant=1
src.keyDel(EAST)
west()
set
hidden=1
instant=1
if(src.is_dead)
if(length(ptracker))
src.spec_number --
if(src.spec_number <= 0) src.spec_number = length(ptracker)
var/mob/player/client/N = ptracker[src.spec_number]
if(N) src.client.eye = N; src.client.chat.addText("Spectating: [N]", ChatFont, true)
src.keySet(WEST)
west_up()
set
hidden=1
instant=1
src.keyDel(WEST)
#define DEFAULT 0
#define DIAGONAL 1
#define STRAFE 2
mob
player/client
// This is just so tile transitions animate smoothly.
// animate_movement=SLIDE_STEPS
var
// How many ticks to wait between steps.
// Must be a positive number or 0.
move_delay=2
// If movement needs to be disabled for some reason.
move_disabled=0
// Which style of movement the player will use.
// It can be DEFAULT, DIAGONAL, or STRAFE.
move_type=DIAGONAL
// This will prevent multiple instances of MovementLoop() from running.
move_int=0
// These track which directions the player wants to move in.
tmp
key1=0
key2=0
key3=0
key4=0
proc
// MovementLoop() is the main process which handles movement.
// It does a few simple checks to see if the player wants to
// move, can move, and is able to move. Once the player moves
// it will delay itself for a moment until the player is able
// to step again.
MovementLoop()
if(move_int)return
move_int=1
var/loop_delay=0
while(src)
if(loop_delay>=1)
sleep(world.tick_lag)
loop_delay--
else
if(key1||key2||key3||key4)
if(canMove())
switch(move_type)
if(DEFAULT)if(stepDefault())loop_delay+=move_delay
if(DIAGONAL)if(stepDiagonal())loop_delay+=move_delay
if(STRAFE)if(stepStrafe())loop_delay+=move_delay
sleep(world.tick_lag)
// canMove() is where you're able to prevent the player from moving.
// Use it for things like being dead, stunned, in a cutscene, and so on.
canMove()
if(move_disabled)return FALSE
return TRUE
// stepDefault() decides which direction the players wants to step in
// then sends them in that direction. This proc will not combine
// directions and instead simply check to make sure the player
// isn't holding opposite buttons. ie: North+South
//
// In order to prevent players from getting stuck on walls when
// stepping into them diagonally, diagonal steps are broken into
// two different steps along the x and y axes.
//
// After stepping it reports back if the player was able to step or
// not so MovementLoop() knows when to apply a step delay.
stepDefault()
var/dir
switch(key1)
if(NORTH)if(key2!=SOUTH&&key3!=SOUTH&&key4!=SOUTH)dir=NORTH
if(SOUTH)if(key2!=NORTH&&key3!=NORTH&&key4!=NORTH)dir=SOUTH
if(EAST)if(key2!=WEST&&key3!=WEST&&key4!=WEST)dir=EAST
if(WEST)if(key2!=EAST&&key3!=EAST&&key4!=EAST)dir=WEST
if(!dir)
switch(key2)
if(NORTH)if(key1!=SOUTH&&key3!=SOUTH&&key4!=SOUTH)dir=NORTH
if(SOUTH)if(key1!=NORTH&&key3!=NORTH&&key4!=NORTH)dir=SOUTH
if(EAST)if(key1!=WEST&&key3!=WEST&&key4!=WEST)dir=EAST
if(WEST)if(key1!=EAST&&key3!=EAST&&key4!=EAST)dir=WEST
if(!dir)
switch(key3)
if(NORTH)if(key1!=SOUTH&&key2!=SOUTH&&key4!=SOUTH)dir=NORTH
if(SOUTH)if(key1!=NORTH&&key2!=NORTH&&key4!=NORTH)dir=SOUTH
if(EAST)if(key1!=WEST&&key2!=WEST&&key4!=WEST)dir=EAST
if(WEST)if(key1!=EAST&&key2!=EAST&&key4!=EAST)dir=WEST
// If it hasn't got a dir by the third key it's not going
// to get one with the fourth since you can guarantee the
// opposite key is also being held.
if(dir)
var/turf/T = get_step(src, dir)
if(isturf(T))
var/items/I = locate(/items) in T
if(I) I.Get(src, 1)
step(src,dir)
return 1
else return 0
// stepStrafe() decides which direction the player wants to step in
// then sends them in that direction. It tracks directional priorities
// in order to know when the player should change directions. It is only
// a visual effect, players do not actually step into tiles sideways.
//
// In order to prevent players from getting stuck on walls when
// stepping into them diagonally, diagonal steps are broken into
// two different steps along the x and y axes.
//
// After stepping the player's direction is corrected and it reports
// back if the player was able to step or not so MovementLoop() knows
// when to apply a step delay.
stepStrafe()
var
dir_x
dir_y
dir_strafe
switch(key1)
if(NORTH)if(key2!=SOUTH&&key3!=SOUTH&&key4!=SOUTH)
dir_y=NORTH
dir_strafe=NORTH
if(SOUTH)if(key2!=NORTH&&key3!=NORTH&&key4!=NORTH)
dir_y=SOUTH
dir_strafe=SOUTH
if(EAST)if(key2!=WEST&&key3!=WEST&&key4!=WEST)
dir_x=EAST
dir_strafe=EAST
if(WEST)if(key2!=EAST&&key3!=EAST&&key4!=EAST)
dir_x=WEST
dir_strafe=WEST
switch(key2)
if(NORTH)if(key1!=SOUTH&&key3!=SOUTH&&key4!=SOUTH)dir_y=NORTH
if(SOUTH)if(key1!=NORTH&&key3!=NORTH&&key4!=NORTH)dir_y=SOUTH
if(EAST)if(key1!=WEST&&key3!=WEST&&key4!=WEST)dir_x=EAST
if(WEST)if(key1!=EAST&&key3!=EAST&&key4!=EAST)dir_x=WEST
switch(key3)
if(NORTH)if(key1!=SOUTH&&key2!=SOUTH&&key4!=SOUTH)dir_y=NORTH
if(SOUTH)if(key1!=NORTH&&key2!=NORTH&&key4!=NORTH)dir_y=SOUTH
if(EAST)if(key1!=WEST&&key2!=WEST&&key4!=WEST)dir_x=EAST
if(WEST)if(key1!=EAST&&key2!=EAST&&key4!=EAST)dir_x=WEST
switch(key4)
if(NORTH)if(key1!=SOUTH&&key2!=SOUTH&&key3!=SOUTH)dir_y=NORTH
if(SOUTH)if(key1!=NORTH&&key2!=NORTH&&key3!=NORTH)dir_y=SOUTH
if(EAST)if(key1!=WEST&&key2!=WEST&&key3!=WEST)dir_x=EAST
if(WEST)if(key1!=EAST&&key2!=EAST&&key3!=EAST)dir_x=WEST
if(dir_x)
if(dir_y)
step(src,dir_x+dir_y)
// If you don't want diagonal steps broken in two use this line.
//step(src,dir_x+dir_y)
if(dir_strafe)dir=dir_strafe
return 1
else
step(src,dir_x)
if(dir_strafe)dir=dir_strafe
return 1
else
if(dir_y)
step(src,dir_y)
if(dir_strafe)dir=dir_strafe
return 1
else return 0
// stepDiagonal() checks all the keys the player is holding then
// mixes them together into diagonal steps. In cases where both
// keys for one axis are being pressed they are both ignored.
//
// In order to prevent players from getting stuck on walls when
// stepping into them diagonally, diagonal steps are broken into
// two different steps along the x and y axes.
//
// After stepping the player's direction is corrected and it reports
// back if the player was able to step or not so MovementLoop() knows
// when to apply a step delay.
stepDiagonal()
var
dir_x
dir_y
switch(key1)
if(NORTH)if(key2!=SOUTH&&key3!=SOUTH&&key4!=SOUTH)dir_y=NORTH
if(SOUTH)if(key2!=NORTH&&key3!=NORTH&&key4!=NORTH)dir_y=SOUTH
if(EAST)if(key2!=WEST&&key3!=WEST&&key4!=WEST)dir_x=EAST
if(WEST)if(key2!=EAST&&key3!=EAST&&key4!=EAST)dir_x=WEST
switch(key2)
if(NORTH)if(key1!=SOUTH&&key3!=SOUTH&&key4!=SOUTH)dir_y=NORTH
if(SOUTH)if(key1!=NORTH&&key3!=NORTH&&key4!=NORTH)dir_y=SOUTH
if(EAST)if(key1!=WEST&&key3!=WEST&&key4!=WEST)dir_x=EAST
if(WEST)if(key1!=EAST&&key3!=EAST&&key4!=EAST)dir_x=WEST
switch(key3)
if(NORTH)if(key1!=SOUTH&&key2!=SOUTH&&key4!=SOUTH)dir_y=NORTH
if(SOUTH)if(key1!=NORTH&&key2!=NORTH&&key4!=NORTH)dir_y=SOUTH
if(EAST)if(key1!=WEST&&key2!=WEST&&key4!=WEST)dir_x=EAST
if(WEST)if(key1!=EAST&&key2!=EAST&&key4!=EAST)dir_x=WEST
switch(key4)
if(NORTH)if(key1!=SOUTH&&key2!=SOUTH&&key3!=SOUTH)dir_y=NORTH
if(SOUTH)if(key1!=NORTH&&key2!=NORTH&&key3!=NORTH)dir_y=SOUTH
if(EAST)if(key1!=WEST&&key2!=WEST&&key3!=WEST)dir_x=EAST
if(WEST)if(key1!=EAST&&key2!=EAST&&key3!=EAST)dir_x=WEST
if(dir_x)
if(dir_y)
var/turf/T = get_step(src, dir_x+dir_y)
if(isturf(T))
var/items/I = locate(/items) in T
if(I) I.Get(src, 1)
step(src,dir_x+dir_y)
// If you don't want diagonal steps broken in two use this line.
//step(src,dir_x+dir_y)
dir=dir_x+dir_y
return 1
else
var/turf/T = get_step(src, dir_x)
if(isturf(T))
var/items/I = locate(/items) in T
if(I) I.Get(src, 1)
step(src,dir_x)
dir=dir_x
return 1
else
if(dir_y)
var/turf/T = get_step(src, dir_y)
if(isturf(T))
var/items/I = locate(/items) in T
if(I) I.Get(src, 1)
step(src,dir_y)
dir=dir_y
return 1
else return 0
// keySet() and keyDel() are used to change the order in which the player
// has pressed their movement keys. It's crucial to preserve the sequence
// of key presses in order to determine which directions are prioritized.
keySet(dir)
if(key1)
if(key2)
if(key3)key4=dir
else key3=dir
else key2=dir
else key1=dir
keyDel(dir)
if(key1==dir)
key1=key2
key2=key3
key3=key4
key4=0
else
if(key2==dir)
key2=key3
key3=key4
key4=0
else
if(key3==dir)
key3=key4
key4=0
else key4=0