forked from xWar131x/TPT2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
adventure_lib.tpt2
55 lines (48 loc) · 2.49 KB
/
adventure_lib.tpt2
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
#package Adventure v3.3
; The name of the variable that stores "target positions" state.
; Doubles as the start of the variable-hiding block.
#target_pos_var "<size=0>adv.target_pos"
#target_positions global.string.get({target_pos_var})
; Convert a vector that has been pre-split into its two components into
; stringified form. This only works for non-negative numbers.
#posToString(x, y) sub(d2s(({x}) + 200.), 1, 2) . sub(d2s(({y}) + 200.), 1, 2)
; Convert a length-4 stringified vector to vector form.
; This evaluates str twice, so that should be a small expression.
; This *will* work with negative values, if they're small enough.
#strToVec(str) vec(s2d(sub({str}, 0, 2), -1.), s2d(sub({str}, 2, 2), -1.))
; Macros for working with BFS queues. The queue is structured as a
; length-4 stringified position followed by a length-1 direction.
#firstElementPos {strToVec(queue)}
#firstElementDir sub(queue, 4, 1)
; Calculate the difficulty of the room the player is in.
; This formulation is a bit harder to follow than the traditional one
; that uses absolute values, but it require fewer operations.
;
; This takes a parameter "offset", which is added to the difficulty.
; This exists because it can be constant-folded in to this calculation,
; whereas if we add it later it's a separate addition.
#cur_difficulty(offset) (\
max(\
254. - x(adventure.roomCoords()),\
x(adventure.roomCoords())\
) + max(\
254. - y(adventure.roomCoords()),\
y(adventure.roomCoords())\
) + ({offset} - 254.)\
)
; Calculate if the given difficulty (i.e. distance) is "survivable",
; i.e. can be cleared automatically without taking damage. This includes
; comparing against maxDifficulty, which technically doesn't affect your
; ability to survive, but does determine how the AI chooses rooms.
#survivable(difficulty) (\
ceil(i2d(adventure.playerAttack()) * if(adventure.hasItem("impaler"), 1.1, 1.)) >=\
round({difficulty} * 0.38 + 1.) + round({difficulty} * 0.08)\
|| i2d(adventure.playerArmor()) >= ceil({difficulty} * 0.39)\
) && i2d(leon.adventure.maxDifficulty) >= {difficulty}\
&& (adventure.hasItem("lantern") || {difficulty} < 100.)
; Convert a U/D/R/L direction into a direction vector by using index
; and lookup tables. These are arranged so that if the lookup fails
; (i.e. if the direction is "W" for wait), the s2d will default to (0.,0.).
#nextX(d) s2d(sub("X 0 0 1-1", index(" U D R L", {d}, 0), 2), 0.)
#nextY(d) s2d(sub("X 1-1 0 0", index(" U D R L", {d}, 0), 2), 0.)
#nextDir(d) vec({nextX({d})}, {nextY({d})})