mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 10:12:45 +00:00
Optimized the code regarding the beam projectiles leaving a fleeting beam behind them, however the count of deletions is still quite high despite this. 30-50 deletions per second.
Also fixed the code for evidence bags.
This commit is contained in:
@@ -1,3 +1,13 @@
|
||||
var/list/beam_master = list()
|
||||
//Use: Caches beam state images and holds turfs that had these images overlaid.
|
||||
//Structure:
|
||||
//beam_master
|
||||
// icon_states/dirs of beams
|
||||
// image for that beam
|
||||
// references for fired beams
|
||||
// icon_states/dirs for each placed beam image
|
||||
// turfs that have that icon_state/dir
|
||||
|
||||
/obj/item/projectile/beam
|
||||
name = "laser"
|
||||
icon_state = "laser"
|
||||
@@ -7,46 +17,63 @@
|
||||
flag = "laser"
|
||||
eyeblur = 4
|
||||
var/frequency = 1
|
||||
var/ID = 0
|
||||
var/main = 0
|
||||
|
||||
fired()
|
||||
main = 1
|
||||
ID = rand(0,1000)
|
||||
var/first = 1
|
||||
var/obj/effect/effect/laserdealer/lasor = new /obj/effect/effect/laserdealer(null)
|
||||
var/reference = "\ref[src]" //So we do not have to recalculate it a ton
|
||||
var/first = 1 //So we don't make the overlay in the same tile as the firer
|
||||
|
||||
spawn(0)
|
||||
lasor.setup(ID)
|
||||
spawn(0)
|
||||
while(!bumped)
|
||||
step_towards(src, current)
|
||||
while(!bumped) //Move until we hit something
|
||||
step_towards(src, current) //Move~
|
||||
|
||||
for(var/mob/living/M in loc)
|
||||
Bump(M)
|
||||
if((!( current ) || loc == current))
|
||||
Bump(M) //Bump anyone we touch
|
||||
|
||||
if((!( current ) || loc == current)) //If we pass our target
|
||||
current = locate(min(max(x + xo, 1), world.maxx), min(max(y + yo, 1), world.maxy), z)
|
||||
|
||||
if((x == 1 || x == world.maxx || y == 1 || y == world.maxy))
|
||||
del(src)
|
||||
del(src) //Delete if it passes the world edge
|
||||
return
|
||||
if(!first)
|
||||
var/obj/item/projectile/beam/new_beam = new src.type(loc)
|
||||
processing_objects.Remove(new_beam)
|
||||
new_beam.dir = get_dir(src, current)
|
||||
new_beam.ID = ID
|
||||
new_beam.icon_state = icon_state
|
||||
|
||||
if(!first) //Add the overlay as we pass over tiles
|
||||
var/target_dir = get_dir(src, current) //So we don't call this too much
|
||||
|
||||
//If the icon has not been added yet
|
||||
if( !("[icon_state][target_dir]" in beam_master) )
|
||||
var/image/I = image(icon,icon_state,10,target_dir) //Generate it.
|
||||
beam_master["[icon_state][target_dir]"] = I //And cache it!
|
||||
|
||||
//Finally add the overlay
|
||||
loc.overlays += beam_master["[icon_state][target_dir]"]
|
||||
|
||||
//Add the turf to a list in the beam master so they can be cleaned up easily.
|
||||
if(reference in beam_master)
|
||||
var/list/turf_master = beam_master[reference]
|
||||
if("[icon_state][target_dir]" in turf_master)
|
||||
var/list/turfs = turf_master["[icon_state][target_dir]"]
|
||||
turfs += loc
|
||||
else
|
||||
turf_master["[icon_state][target_dir]"] = list(loc)
|
||||
else
|
||||
var/list/turfs = list()
|
||||
turfs["[icon_state][target_dir]"] = list(loc)
|
||||
beam_master[reference] = turfs
|
||||
else
|
||||
first = 0
|
||||
|
||||
cleanup(reference)
|
||||
return
|
||||
|
||||
/obj/effect/effect/laserdealer
|
||||
name = "laserdealio"
|
||||
|
||||
proc/setup(var/ID = 0)
|
||||
sleep(5)
|
||||
for(var/obj/item/projectile/beam/beam in world)
|
||||
if(ID == beam.ID)
|
||||
del(beam)
|
||||
spawn(0)
|
||||
del(src)
|
||||
proc/cleanup(reference) //Waits .3 seconds then removes the overlay.
|
||||
src = null
|
||||
sleep(3)
|
||||
var/list/turf_master = beam_master[reference]
|
||||
for(var/laser_state in turf_master)
|
||||
var/list/turfs = turf_master[laser_state]
|
||||
for(var/turf/T in turfs)
|
||||
T.overlays -= beam_master[laser_state]
|
||||
return
|
||||
|
||||
/obj/item/projectile/practice
|
||||
name = "laser"
|
||||
|
||||
Reference in New Issue
Block a user