Skip to content

Commit

Permalink
[MIRROR] using another as a shield uses 3 adjacent 8-dirs instead of …
Browse files Browse the repository at this point in the history
…only reverse
  • Loading branch information
Spookerton authored and SuhEugene committed Jan 15, 2024
1 parent 556c977 commit c95f31c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 60 deletions.
29 changes: 25 additions & 4 deletions code/_global_vars/lists/mapping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,51 @@ GLOBAL_LIST_INIT(cardinalz, list(NORTH, SOUTH, EAST, WEST, UP, DOWN))
GLOBAL_LIST_INIT(cornerdirs, list(NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST))
GLOBAL_LIST_INIT(cornerdirsz, list(NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST, NORTH|UP, EAST|UP, WEST|UP, SOUTH|UP, NORTH|DOWN, EAST|DOWN, WEST|DOWN, SOUTH|DOWN))
GLOBAL_LIST_INIT(alldirs, list(NORTH, SOUTH, EAST, WEST, NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST))
GLOBAL_LIST_INIT(reverse_dir, list( // reverse_dir[dir] = reverse of dir

/// reverse_dir[dir] = reverse of dir
GLOBAL_LIST_INIT(reverse_dir, list(
2, 1, 3, 8, 10, 9, 11, 4, 6, 5, 7, 12, 14, 13, 15,
32, 34, 33, 35, 40, 42, 41, 43, 36, 38, 37, 39, 44, 46, 45, 47,
16, 18, 17, 19, 24, 26, 25, 27, 20, 22, 21, 23, 28, 30, 29, 31,
48, 50, 49, 51, 56, 58, 57, 59, 52, 54, 53, 55, 60, 62, 61, 63
))

GLOBAL_LIST_INIT(flip_dir, list( // flip_dir[dir] = 180 degree rotation of dir. Unlike reverse_dir, UP remains UP & DOWN remains DOWN.
/// flip_dir[dir] = 180 degree rotation of dir. Unlike reverse_dir, UP remains UP & DOWN remains DOWN.
GLOBAL_LIST_INIT(flip_dir, list(
2, 1, 3, 8, 10, 9, 11, 4, 6, 5, 7, 12, 14, 13, 15,
16, 18, 17, 19, 24, 26, 25, 27, 20, 22, 21, 23, 28, 30, 29, 31, // UP - Same as first line but +16
32, 34, 33, 35, 40, 42, 41, 43, 36, 38, 37, 39, 44, 46, 45, 47, // DOWN - Same as first line but +32
48, 50, 49, 51, 56, 58, 57, 59, 52, 54, 53, 55, 60, 62, 61, 63 // UP+DOWN - Same as first line but +48
))

GLOBAL_LIST_INIT(cw_dir, list( // cw_dir[dir] = clockwise rotation of dir. Unlike reverse_dir, UP remains UP & DOWN remains DOWN.
/// cw_dir[dir] = clockwise 4-rotation of dir. Unlike reverse_dir, UP remains UP & DOWN remains DOWN.
GLOBAL_LIST_INIT(cw_dir, list(
4, 8, 12, 2, 6, 10, 14, 1, 5, 9, 13, 3, 7, 11, 15,
16, 20, 24, 28, 18, 22, 26, 30, 17, 21, 25, 19, 29, 23, 27, 31, // UP - Same as first line but +16
32, 36, 40, 44, 34, 38, 42, 46, 33, 37, 41, 45, 35, 39, 43, 47, // DOWN - Same as first line but +32
48, 52, 56, 40, 50, 54, 58, 62, 49, 53, 57, 61, 51, 55, 59, 63 // UP+DOWN - Same as first line but +48
))

GLOBAL_LIST_INIT(ccw_dir, list( // ccw_dir[dir] = counter-clockwise rotation of dir. Unlike reverse_dir, UP remains UP & DOWN remains DOWN.
/// cw_dir_8[dir] = clockwise 8-rotation of dir. Ignores invalid dir combinations.
GLOBAL_LIST_INIT(cw_dir_8, list(
5, 10, 0, 6, 4, 2, 0, 9, 1, 8, 0, 0, 0, 0, 0, 0,
21, 26, 0, 22, 20, 18, 0, 25, 17, 24, 0, 0, 0, 0, 0, 0,
37, 42, 0, 38, 36, 34, 0, 41, 33, 40, 0, 0, 0, 0, 0, 0,
53, 58, 0, 54, 52, 50, 0, 57, 49, 56, 0, 0, 0, 0, 0, 0
))

/// ccw_dir[dir] = counter-clockwise 4-rotation of dir. Unlike reverse_dir, UP remains UP & DOWN remains DOWN.
GLOBAL_LIST_INIT(ccw_dir, list(
8, 4, 12, 1, 9, 5, 13, 2, 10, 6, 14, 3, 11, 7, 15,
16, 24, 20, 28, 17, 25, 21, 29, 18, 26, 22, 30, 19, 27, 23, 31, // UP - Same as first line but +16
32, 40, 36, 44, 33, 41, 37, 45, 34, 42, 38, 46, 35, 43, 39, 47, // DOWN - Same as first line but +32
48, 56, 52, 60, 49, 57, 53, 61, 50, 58, 54, 62, 51, 59, 55, 63 // UP+DOWN - Same as first line but +48
))

/// ccw_dir_8[dir] = counter-clockwise 8-rotation of dir. Ignores invalid dir combinations.
GLOBAL_LIST_INIT(ccw_dir_8, list(
9, 6, 0, 5, 1, 4, 0, 10, 8, 2, 0, 0, 0, 0, 0, 0,
25, 22, 0, 21, 17, 20, 0, 26, 24, 18, 0, 0, 0, 0, 0, 0,
41, 38, 0, 37, 33, 36, 0, 42, 40, 34, 0, 0, 0, 0, 0, 0,
57, 54, 0, 53, 49, 52, 0, 58, 56, 50, 0, 0, 0, 0, 0, 0
))
97 changes: 41 additions & 56 deletions code/modules/projectiles/projectile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -283,66 +283,51 @@

return 1

/obj/item/projectile/Bump(atom/A as mob|obj|turf|area, forced=0)
if(A == src)
return 0 //no

if(A == firer)
forceMove(A.loc)
return 0 //cannot shoot yourself

if((bumped && !forced) || (A in permutated))
return 0

var/passthrough = 0 //if the projectile should continue flying
var/distance = get_dist(starting,loc)

bumped = 1
if(ismob(A))
var/mob/M = A
if(istype(A, /mob/living))
//if they have a neck grab on someone, that person gets hit instead
var/obj/item/grab/G = locate() in M
if(G && G.shield_assailant() && src.dir == GLOB.reverse_dir[M.dir])
G.affecting.visible_message(SPAN_DANGER("\The [M] uses \the [G.affecting] as a shield!"))
if(Bump(G.affecting, forced=1))
return //If Bump() returns 0 (keep going) then we continue on to attack M.

passthrough = !attack_mob(M, distance)
else
passthrough = 1 //so ghosts don't stop bullets
/obj/item/projectile/Bump(atom/atom, forced)
if (atom == src)
return FALSE
if (atom == firer)
forceMove(atom.loc)
return FALSE
if (bumped && !forced || (atom in permutated))
return FALSE
bumped = TRUE
var/passthrough
var/distance = get_dist(starting, loc)
if (ismob(atom))
passthrough = TRUE
if (istype(atom, /mob/living))
var/obj/item/grab/grab = locate() in atom
var/dirs = GLOB.reverse_dir[atom.dir & 0xF]
dirs = list(dirs, GLOB.cw_dir_8[dirs], GLOB.ccw_dir_8[dirs])
if (grab?.shield_assailant() && (dir in dirs))
grab.affecting.visible_message(SPAN_DANGER("\The [atom] uses \the [grab.affecting] as a shield!"))
if (Bump(grab.affecting, TRUE))
return
passthrough = !attack_mob(atom, distance)
else
passthrough = (A.bullet_act(src, def_zone) == PROJECTILE_CONTINUE) //backwards compatibility
if(isturf(A))
for(var/obj/O in A)
O.bullet_act(src)
for(var/mob/living/M in A)
attack_mob(M, distance)

//penetrating projectiles can pass through things that otherwise would not let them
if(!passthrough && penetrating > 3)
if(check_penetrate(A))
passthrough = 1
penetrating--

//the bullet passes through a dense object!
if(passthrough)
//move ourselves onto A so we can continue on our way.
var/turf/T = get_turf(A)
if(T)
forceMove(T)
permutated.Add(A)
bumped = 0 //reset bumped variable!
return 0

//stop flying
on_impact(A)

set_density(0)
passthrough = atom.bullet_act(src, def_zone) == PROJECTILE_CONTINUE
if (isturf(atom))
for (var/obj/obj in atom)
obj.bullet_act(src)
for (var/mob/living/mob in atom)
attack_mob(mob, distance)
if (!passthrough && penetrating > 3)
if (check_penetrate(atom))
passthrough = TRUE
--penetrating
if (passthrough && isturf(atom))
forceMove(atom)
permutated += atom
bumped = FALSE
return FALSE
on_impact(atom)
set_density(FALSE)
set_invisibility(INVISIBILITY_ABSTRACT)

qdel(src)
return 1
return TRUE


/obj/item/projectile/ex_act()
return //explosions probably shouldn't delete projectiles
Expand Down

0 comments on commit c95f31c

Please sign in to comment.