Skip to content

Commit

Permalink
Merge pull request #210 from KittyNoodle/shields
Browse files Browse the repository at this point in the history
Siege Warfare: Energy Shield Edition
  • Loading branch information
dwasint authored Aug 2, 2023
2 parents c6ec415 + b215f07 commit c736248
Show file tree
Hide file tree
Showing 9 changed files with 1,007 additions and 1 deletion.
35 changes: 35 additions & 0 deletions code/__HELPERS/maths.dm
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,41 @@
line += locate(current_x_step, current_y_step, starting_z)
return line

/**
* Get a list of turfs in a perimeter given the `center_atom` and `radius`.
* Automatically rounds down decimals and does not accept values less than positive 1 as they dont play well with it.
* Is efficient on large circles but ugly on small ones
* Uses [Jesko`s method to the midpoint circle Algorithm](https://en.wikipedia.org/wiki/Midpoint_circle_algorithm).
*/
/proc/get_perimeter(atom/center, radius)
if(radius < 1)
return
var/rounded_radius = round(radius)
var/x = center.x
var/y = center.y
var/z = center.z
var/t1 = rounded_radius/16
var/dx = rounded_radius
var/dy = 0
var/t2
var/list/perimeter = list()
while(dx >= dy)
perimeter += locate(x + dx, y + dy, z)
perimeter += locate(x - dx, y + dy, z)
perimeter += locate(x + dx, y - dy, z)
perimeter += locate(x - dx, y - dy, z)
perimeter += locate(x + dy, y + dx, z)
perimeter += locate(x - dy, y + dx, z)
perimeter += locate(x + dy, y - dx, z)
perimeter += locate(x - dy, y - dx, z)
dy += 1
t1 += dy
t2 = t1 - dx
if(t2 > 0)
t1 = t2
dx -= 1
return perimeter

///Format a power value in W, kW, MW, or GW.
/proc/display_power(powerused)
if(powerused < 1000) //Less than a kW
Expand Down
8 changes: 7 additions & 1 deletion code/datums/elements/blocks_explosives.dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// Apply this element to a movable atom when you want it to block explosions
/// It will mirror the blocking down to that movable's turf, keeping explosion work cheap
/datum/element/blocks_explosives
element_flags = ELEMENT_DETACH_ON_HOST_DESTROY

/datum/element/blocks_explosives/Attach(datum/target)
if(!ismovable(target))
Expand All @@ -18,8 +19,13 @@
else if(moving_target.loc)
block_loc(moving_target.loc, moving_target.explosion_block)

/datum/element/blocks_explosives/Detach(datum/source)
/datum/element/blocks_explosives/Detach(atom/movable/source)
. = ..()
if(length(source.locs) > 1)
for(var/atom/location as anything in source.locs)
unblock_loc(location, source.explosion_block)
else if(source.loc)
unblock_loc(source.loc, source.explosion_block)
REMOVE_TRAIT(source, TRAIT_BLOCKING_EXPLOSIVES, TRAIT_GENERIC)

/// Call this when our blocking well, changes. we'll update our turf(s) with the details
Expand Down
Loading

0 comments on commit c736248

Please sign in to comment.