Skip to content

Commit

Permalink
more hitboxes & shit
Browse files Browse the repository at this point in the history
  • Loading branch information
MLGTASTICa committed Aug 12, 2024
1 parent b35fae7 commit 04b978a
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 16 deletions.
2 changes: 0 additions & 2 deletions code/__DEFINES/__atomFlags.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@
/// Our hitbox is offset by an attachment.
#define AF_HITBOX_OFFSET_BY_ATTACHMENT (1<<5)
#define AF_IGNORE_ON_BULLETSCAN (1<<6)
/// Bullets won't be able to hit this one and cause a mid-air collision
#define AF_BULLET_PASS (1<<7)
/// This atom will get ignored by explosions
#define AF_EXPLOSION_IGNORANT (1<<8)
2 changes: 1 addition & 1 deletion code/_compile_options.dm
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
// 2 for preloading absolutely everything;
#define LOWMEMORYMODE 1

#define HITBOX_DEBUG 1
#define BULLETDEBUG 1

//Update this whenever you need to take advantage of more recent byond features
#define MIN_COMPILER_VERSION 514
Expand Down
2 changes: 2 additions & 0 deletions code/controllers/subsystems/bullets.dm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ SUBSYSTEM_DEF(bullets)
distanceToTarget = distStartToFinish2D()
cannotHit.Add(firer)
updatePathByAngle()
#ifdef BULLETDEBUG
message_admins("Bullet created with Z-target at [targetZ] and starting at [globalZ]")
#endif
SSbullets.bullet_queue.Add(src)

/datum/bullet_data/proc/redirect(currentX, currentY, currentZ, targetX, targetY, targetZ)
Expand Down
4 changes: 3 additions & 1 deletion code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
update_plane()

hitbox = getHitbox(hitbox)
#ifdef HITBOX_DEBUG
#ifdef BULLETDEBUG
if(hitbox)
addtimer(CALLBACK(hitbox, TYPE_PROC_REF(/datum/hitboxDatum, visualize), src), 1 MINUTE)
#endif
Expand Down Expand Up @@ -354,7 +354,9 @@

/atom/proc/bullet_act(obj/item/projectile/P, def_zone, hitboxFlags)
P.on_hit(src, def_zone)
#ifdef BULLETDEBUG
message_admins("Bullet stopped by [src]")
#endif
. = PROJECTILE_STOP

/atom/proc/block_bullet(mob/user, var/obj/item/projectile/damage_source, def_zone)
Expand Down
1 change: 1 addition & 0 deletions code/game/objects/effects/effect_system.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ would spawn and follow the beaker, even if it is carried or thrown.
*/

/obj/effect
atomFlags = AF_IGNORE_ON_BULLETSCAN | AF_EXPLOSION_IGNORANT
var/random_rotation = 0 //If 1, pick a random cardinal direction. if 2, pick a randomised angle
var/random_offset = 0
weight = 0
Expand Down
9 changes: 4 additions & 5 deletions code/game/objects/explosion.dm
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,9 @@ proc/fragment_explosion(var/turf/epicenter, var/range, var/f_type, var/f_amount
if(!epicenter || !f_type)
return

var/list/target_turfs = orange(range, epicenter)
var/fragments_per_projectile = f_amount/target_turfs.len //This is rounded but only later
var/fragments_per_projectile = round(3.14*range*range)
var/list/launchedList = list()
for(var/turf/T in target_turfs)
for(var/turf/T in orange(range, epicenter))
var/obj/item/projectile/bullet/pellet/fragment/P = new f_type(epicenter)

P.PrepareForLaunch()
Expand All @@ -168,7 +167,7 @@ proc/fragment_explosion(var/turf/epicenter, var/range, var/f_type, var/f_amount
P.range_step = f_step

P.shot_from = epicenter
P.atomFlags = AF_BULLET_PASS|AF_EXPLOSION_IGNORANT
P.atomFlags = AF_IGNORE_ON_BULLETSCAN|AF_EXPLOSION_IGNORANT
/// has to be exxagerate due to how far the turfs are
P.launch(T, zStart = LEVEL_LYING ,zOffset = rand(LEVEL_LYING+5, LEVEL_CHEST))
launchedList.Add(P)
Expand All @@ -178,7 +177,7 @@ proc/fragment_explosion(var/turf/epicenter, var/range, var/f_type, var/f_amount
for(var/mob/living/M in epicenter)
P.attack_mob(M, 0, 100)
/// 3 ticks should be enough
addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(removeFlags), launchedList.Copy(), AF_BULLET_PASS | AF_EXPLOSION_IGNORANT), 3)
addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(removeFlags), launchedList.Copy(), AF_IGNORE_ON_BULLETSCAN | AF_EXPLOSION_IGNORANT), SSbullets.wait * 3)

/proc/removeFlags(list/targets, flagsToRemove)
for(var/atom/thing as anything in targets)
Expand Down
1 change: 1 addition & 0 deletions code/game/objects/structures.dm
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
take_damage(P.get_structure_damage())
if(QDELETED(src))
return PROJECTILE_CONTINUE
return PROJECTILE_STOP


/obj/structure/New()
Expand Down
5 changes: 5 additions & 0 deletions code/game/objects/structures/lattice.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
layer = LATTICE_LAYER //under pipes
// flags = CONDUCT

/// This would be too bad if it was actually always blocking(and not really make sense for players.) SPCR 2024
/obj/structure/lattice/bullet_act(obj/item/projectile/P, def_zone, hitboxFlags)
return PROJECTILE_CONTINUE


/obj/structure/lattice/Initialize()
. = ..()
///// Z-Level Stuff
Expand Down
1 change: 1 addition & 0 deletions code/game/objects/structures/low_wall.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
anchored = TRUE
layer = LOW_WALL_LAYER
icon = 'icons/obj/structures/low_wall.dmi'
hitbox = /datum/hitboxDatum/atom/lowWall
icon_state = "metal"
throwpass = TRUE
var/connected = TRUE
Expand Down
14 changes: 13 additions & 1 deletion code/game/objects/structures/window.dm
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ proc/end_grab_onto(mob/living/user, mob/living/target)
desc = "It looks thin and flimsy. A few knocks with... anything, really should shatter it."
icon_state = "window"
basestate = "window"
hitbox = /datum/hitboxDatum/atom/window/directional
glasstype = /obj/item/stack/material/glass
maximal_heat = T0C + 200 // Was 100. Spaceship windows surely surpass coffee pots.
damage_per_fire_tick = 3 // Was 2. Made weaker than rglass per tick.
Expand All @@ -576,6 +577,7 @@ proc/end_grab_onto(mob/living/user, mob/living/target)
dir = SOUTH|EAST
icon = 'icons/obj/structures/windows.dmi'
icon_state = "fwindow"
hitbox = /datum/hitboxDatum/turf/window
alpha = 120
maxHealth = 40
resistance = RESISTANCE_FLIMSY
Expand All @@ -585,6 +587,7 @@ proc/end_grab_onto(mob/living/user, mob/living/target)
name = "plasma window"
desc = "A borosilicate alloy window. It seems to be quite strong."

hitbox = /datum/hitboxDatum/atom/window/directional
icon_state = "plasmawindow"
shardtype = /obj/item/material/shard/plasma
glasstype = /obj/item/stack/material/glass/plasmaglass
Expand All @@ -597,6 +600,7 @@ proc/end_grab_onto(mob/living/user, mob/living/target)
dir = SOUTH|EAST
icon = 'icons/obj/structures/windows.dmi'
basestate = "pwindow"
hitbox = /datum/hitboxDatum/turf/window
icon_state = "plasmawindow_mask"
alpha = 150
maxHealth = 200
Expand All @@ -608,6 +612,7 @@ proc/end_grab_onto(mob/living/user, mob/living/target)
desc = "It looks rather strong. Might take a few good hits to shatter it."
icon_state = "rwindow"
basestate = "rwindow"
hitbox = /datum/hitboxDatum/atom/window/directional
reinf = 1
maximal_heat = T0C + 750 // Fused quartz.
damage_per_fire_tick = 2
Expand All @@ -627,6 +632,7 @@ proc/end_grab_onto(mob/living/user, mob/living/target)
dir = SOUTH|EAST
icon = 'icons/obj/structures/windows.dmi'
icon_state = "fwindow"
hitbox = /datum/hitboxDatum/turf/window
alpha = 150
maxHealth = 80
resistance = RESISTANCE_FRAGILE
Expand All @@ -637,6 +643,7 @@ proc/end_grab_onto(mob/living/user, mob/living/target)
desc = "A borosilicate alloy window, with rods supporting it. It seems to be very strong."
basestate = "plasmarwindow"
icon_state = "plasmarwindow"
hitbox = /datum/hitboxDatum/atom/window/directional
shardtype = /obj/item/material/shard/plasma
glasstype = /obj/item/stack/material/glass/plasmarglass
maximal_heat = T0C + 5453 // Safe use temperature at 6000 kelvin.
Expand All @@ -646,6 +653,7 @@ proc/end_grab_onto(mob/living/user, mob/living/target)

/obj/structure/window/reinforced/plasma/full
dir = SOUTH|EAST
hitbox = /datum/hitboxDatum/turf/window
icon = 'icons/obj/structures/windows.dmi'
basestate = "rpwindow"
icon_state = "plasmarwindow_mask"
Expand All @@ -658,12 +666,14 @@ proc/end_grab_onto(mob/living/user, mob/living/target)
name = "tinted window"
desc = "It looks rather strong and opaque. Might take a few good hits to shatter it."
icon_state = "twindow"
hitbox = /datum/hitboxDatum/atom/window/directional
basestate = "twindow"
opacity = 1

/obj/structure/window/reinforced/tinted/frosted
name = "frosted window"
desc = "It looks rather strong and frosted over. Looks like it might take a few less hits then a normal reinforced window."
hitbox = /datum/hitboxDatum/atom/window/directional
icon_state = "fwindow"
basestate = "fwindow"

Expand All @@ -673,6 +683,7 @@ proc/end_grab_onto(mob/living/user, mob/living/target)
icon = 'icons/obj/podwindows.dmi'
icon_state = "window"
basestate = "window"
hitbox = /datum/hitboxDatum/turf/window
maxHealth = 300
resistance = RESISTANCE_IMPROVED
reinf = 1
Expand All @@ -681,12 +692,13 @@ proc/end_grab_onto(mob/living/user, mob/living/target)

/obj/structure/window/reinforced/polarized
name = "electrochromic window"

hitbox = /datum/hitboxDatum/atom/window/directional
desc = "Adjusts its tint with voltage. Might take a few good hits to shatter it."
var/id

/obj/structure/window/reinforced/polarized/full
dir = SOUTH|EAST
hitbox = /datum/hitboxDatum/turf/window
icon = 'icons/obj/structures/windows.dmi'
icon_state = "fwindow"
flags = null
Expand Down
4 changes: 1 addition & 3 deletions code/modules/lighting/lighting_overlay.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@

weight = 0

atomFlags = AF_IGNORE_ON_BULLETSCAN
atomFlags = AF_IGNORE_ON_BULLETSCAN | AF_EXPLOSION_IGNORANT

var/needs_update = FALSE

/// More efficient to have the proc return bullet_continue ,avoiding another check for every object on a turf SPCR 2024
/atom/movable/lighting_overlay/bullet_act(obj/item/projectile/P, def_zone, hitboxFlags)
return PROJECTILE_CONTINUE



/atom/movable/lighting_overlay/New(var/atom/loc, var/no_update = FALSE)
. = ..()
verbs.Cut()
Expand Down
1 change: 1 addition & 0 deletions code/modules/power/apc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
anchored = TRUE
use_power = NO_POWER_USE
req_access = list(access_engine_equip)
//hitbox = /datum/hitboxDatum/atom/apc
var/need_sound
var/area/area
var/areastring
Expand Down
33 changes: 33 additions & 0 deletions code/modules/projectiles/hitbox_datums.dm
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,38 @@ boolean lineLine(float x1, float y1, float x2, float y2, float x3, float y3, flo
LISTWEST = list(BBOX(10,9,23,25,LEVEL_CHEST-1,LEVEL_CHEST+2,null))
)

/datum/hitboxDatum/atom/window/directional
boundingBoxes = list(
LISTNORTH = list(BBOX(1,26,32,32, LEVEL_TURF, LEVEL_ABOVE, null)),
LISTSOUTH = list(BBOX(1,1,32,7, LEVEL_TURF, LEVEL_ABOVE, null)),
LISTEAST = list(BBOX(26,1,32,32, LEVEL_TURF, LEVEL_ABOVE, null)),
LISTWEST = list(BBOX(1,1,7,32, LEVEL_TURF, LEVEL_ABOVE, null))
)

/datum/hitboxDatum/atom/lowWall
boundingBoxes = list(
LISTNORTH = list(BBOX(0,0,32,32, LEVEL_TURF, LEVEL_LOWWALL, null)),
LISTSOUTH = list(BBOX(0,0,32,32, LEVEL_TURF, LEVEL_LOWWALL, null)),
LISTEAST = list(BBOX(0,0,32,32, LEVEL_TURF, LEVEL_LOWWALL, null)),
LISTWEST = list(BBOX(0,0,32,32, LEVEL_TURF, LEVEL_LOWWALL, null))
)

/datum/hitboxDatum/turf
boundingBoxes = BBOX(0,0,32,32,LEVEL_BELOW ,LEVEL_ABOVE,null)

/datum/hitboxDatum/turf/visualize(atom/owner)
var/list/hitbox = boundingBoxes
var/icon/Icon = icon('icons/hitbox.dmi', "box")
var/multX = hitbox[3] - hitbox[1] + 1
var/multY = hitbox[4] - hitbox[2] + 1
Icon.Scale(multX, multY)
var/mutable_appearance/newOverlay = mutable_appearance(Icon, "hitbox")
newOverlay.color = RANDOM_RGB
newOverlay.pixel_x = hitbox[1] - 1
newOverlay.pixel_y = hitbox[2] - 1
newOverlay.alpha = 200
owner.overlays.Add(newOverlay)

/datum/hitboxDatum/turf/intersects(atom/owner, ownerDirection, startX, startY, startZ, pStepX, pStepY, pStepZ)
var/worldX
var/worldY
Expand Down Expand Up @@ -354,6 +383,9 @@ boolean lineLine(float x1, float y1, float x2, float y2, float x3, float y3, flo
/datum/hitboxDatum/turf/floor
boundingBoxes = BBOX(0,0,32,32,LEVEL_BELOW ,LEVEL_TURF,null)

/datum/hitboxDatum/turf/window
boundingBoxes = BBOX(0,0,32,32, LEVEL_LOWWALL, LEVEL_ABOVE, null)

/// This checks line by line instead of a box. Less efficient.
/datum/hitboxDatum/atom/polygon
boundingBoxes = list(
Expand Down Expand Up @@ -404,6 +436,7 @@ boolean lineLine(float x1, float y1, float x2, float y2, float x3, float y3, flo
/datum/hitboxDatum/atom/polygon/visualize(atom/owner)
/// too hard to get offsets for lines ((( SPCR 2024
return

/// Indexed by whatever the fuck dirs getHitboxData() returns from the pipe
/datum/hitboxDatum/atom/polygon/atmosphericPipe
boundingBoxes = list(
Expand Down
4 changes: 1 addition & 3 deletions code/modules/projectiles/projectile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ GLOBAL_LIST(projectileDamageConstants)
// yep , it checks itself , more efficient to handle it here..
if(P == src)
return PROJECTILE_CONTINUE
if(atomFlags & AF_BULLET_PASS || P.atomFlags & AF_BULLET_PASS)
return PROJECTILE_CONTINUE
if(abs(P.dataRef.globalZ - dataRef.globalZ) > 0.1)
return PROJECTILE_CONTINUE
if(abs(P.dataRef.globalX - dataRef.globalX) > 0.1)
Expand Down Expand Up @@ -581,7 +579,7 @@ GLOBAL_LIST(projectileDamageConstants)
/// third slot rezerved for flags passed back by hitbox intersect
var/hitFlags = null
if(target.hitbox && !target.hitbox.intersects(target, target.dir, startX, startY, startZ, pStepX, pStepY, pStepZ, &hitFlags))
return PROJECTILE_CONTINUE
continue
if(target.bullet_act(src, def_zone, hitFlags) & PROJECTILE_STOP)
onBlockingHit(target)
return PROJECTILE_STOP
Expand Down

0 comments on commit 04b978a

Please sign in to comment.