Re-adding object pooling for beam projectiles. Fixed the double damage bug with a spawn().

What was happening was returntopool was nulling the variable that prevented the projectile from bumping something twice, and for whatever reason despite having no loc the proj would bump the same mob twice then be in the void again. The spawn() allows the bump proc to finish and then the projectile is returned to the pool.
This commit is contained in:
d3athrow
2014-05-22 09:46:11 -05:00
parent cbcbdbe021
commit 7f4c0be941
10 changed files with 52 additions and 32 deletions

View File

@@ -114,7 +114,7 @@
A.fired() A.fired()
*/ */
proc/Emit() proc/Emit()
var/obj/item/projectile/beam/emitter/A = new /obj/item/projectile/beam/emitter(src.loc) var/obj/item/projectile/beam/emitter/A = getFromPool(/obj/item/projectile/beam/emitter, loc)
A.frequency = frequency A.frequency = frequency
A.damage = mega_energy * 500 A.damage = mega_energy * 500
playsound(get_turf(src), 'sound/weapons/emitter.ogg', 25, 1) playsound(get_turf(src), 'sound/weapons/emitter.ogg', 25, 1)

View File

@@ -92,7 +92,7 @@
src.fire_delay = rand(20,100) src.fire_delay = rand(20,100)
src.shot_number = 0 src.shot_number = 0
use_power(1000) use_power(1000)
var/obj/item/projectile/beam/emitter/A = new /obj/item/projectile/beam/emitter(src.loc) var/obj/item/projectile/beam/emitter/A = getFromPool(/obj/item/projectile/beam/emitter, loc)
playsound(get_turf(src), 'sound/weapons/emitter.ogg', 25, 1) playsound(get_turf(src), 'sound/weapons/emitter.ogg', 25, 1)
if(prob(35)) if(prob(35))
var/datum/effect/effect/system/spark_spread/s = new /datum/effect/effect/system/spark_spread var/datum/effect/effect/system/spark_spread/s = new /datum/effect/effect/system/spark_spread

View File

@@ -292,7 +292,7 @@
var/turf/T = get_turf(src) var/turf/T = get_turf(src)
var/turf/U = get_turf(A) var/turf/U = get_turf(A)
var/obj/item/projectile/beam/LE = new /obj/item/projectile/beam(loc) var/obj/item/projectile/beam/LE = getFromPool(/obj/item/projectile/beam, loc)
LE.icon = 'icons/effects/genetics.dmi' LE.icon = 'icons/effects/genetics.dmi'
LE.icon_state = "eyelasers" LE.icon_state = "eyelasers"
playsound(usr.loc, 'sound/weapons/taser2.ogg', 75, 1) playsound(usr.loc, 'sound/weapons/taser2.ogg', 75, 1)
@@ -333,7 +333,7 @@
"You hear the loud crackle of electricity!") "You hear the loud crackle of electricity!")
var/datum/powernet/PN = cable.get_powernet() var/datum/powernet/PN = cable.get_powernet()
var/available = 0 var/available = 0
var/obj/item/projectile/beam/lightning/L = new /obj/item/projectile/beam/lightning/(get_turf(src)) var/obj/item/projectile/beam/lightning/L = getFromPool(/obj/item/projectile/beam/lightning, loc)
if(PN) if(PN)
available = PN.avail available = PN.avail
L.damage = PN.get_electrocute_damage() L.damage = PN.get_electrocute_damage()
@@ -359,7 +359,8 @@
s.set_up(5, 1, src) s.set_up(5, 1, src)
s.start() s.start()
if(L.damage <= 0) if(L.damage <= 0)
del(L) returnToPool(L)
//del(L)
if(L) if(L)
playsound(get_turf(src), 'sound/effects/eleczap.ogg', 75, 1) playsound(get_turf(src), 'sound/effects/eleczap.ogg', 75, 1)
L.tang = L.adjustAngle(get_angle(U,T)) L.tang = L.adjustAngle(get_angle(U,T))

View File

@@ -199,7 +199,7 @@ its easier to just keep the beam vertical.
//Maxdistance is the longest range the beam will persist before it gives up. //Maxdistance is the longest range the beam will persist before it gives up.
var/EndTime=world.time+time var/EndTime=world.time+time
var/broken = 0 var/broken = 0
var/obj/item/projectile/beam/lightning/light = new var/obj/item/projectile/beam/lightning/light = getFromPool(/obj/item/projectile/beam/lightning)
while(BeamTarget&&world.time<EndTime&&get_dist(src,BeamTarget)<maxdistance&&z==BeamTarget.z) while(BeamTarget&&world.time<EndTime&&get_dist(src,BeamTarget)<maxdistance&&z==BeamTarget.z)
//If the BeamTarget gets deleted, the time expires, or the BeamTarget gets out //If the BeamTarget gets deleted, the time expires, or the BeamTarget gets out

View File

@@ -1020,7 +1020,8 @@ Auto Patrol: []"},
if((src.lasercolor == "b") && (src.disabled == 0)) if((src.lasercolor == "b") && (src.disabled == 0))
if(istype(Proj, /obj/item/projectile/beam/lastertag/red)) if(istype(Proj, /obj/item/projectile/beam/lastertag/red))
src.disabled = 1 src.disabled = 1
del (Proj) //del (Proj)
returnToPool(Proj)
sleep(100) sleep(100)
src.disabled = 0 src.disabled = 0
else else
@@ -1028,7 +1029,8 @@ Auto Patrol: []"},
else if((src.lasercolor == "r") && (src.disabled == 0)) else if((src.lasercolor == "r") && (src.disabled == 0))
if(istype(Proj, /obj/item/projectile/beam/lastertag/blue)) if(istype(Proj, /obj/item/projectile/beam/lastertag/blue))
src.disabled = 1 src.disabled = 1
del (Proj) //del (Proj)
returnToPool(Proj)
sleep(100) sleep(100)
src.disabled = 0 src.disabled = 0
else else

View File

@@ -236,17 +236,17 @@
if (src.lasers) if (src.lasers)
switch(lasertype) switch(lasertype)
if(1) if(1)
A = new /obj/item/projectile/beam(loc) A = getFromPool(/obj/item/projectile/beam, loc)
if(2) if(2)
A = new /obj/item/projectile/beam/heavylaser(loc) A = getFromPool(/obj/item/projectile/beam/heavylaser, loc)
if(3) if(3)
A = new /obj/item/projectile/beam/pulse(loc) A = getFromPool(/obj/item/projectile/beam/pulse, loc)
if(4) if(4)
A = new /obj/item/projectile/change(loc) A = getFromPool(/obj/item/projectile/change, loc)
if(5) if(5)
A = new /obj/item/projectile/beam/lastertag/blue(loc) A = getFromPool(/obj/item/projectile/beam/lastertag/blue, loc)
if(6) if(6)
A = new /obj/item/projectile/beam/lastertag/red(loc) A = getFromPool(/obj/item/projectile/beam/lastertag/red, loc)
A.original = target A.original = target
use_power(500) use_power(500)
else else

View File

@@ -124,7 +124,7 @@
else else
src.fire_delay = rand(20,100) src.fire_delay = rand(20,100)
src.shot_number = 0 src.shot_number = 0
var/obj/item/projectile/beam/emitter/A = new /obj/item/projectile/beam/emitter(src.loc) var/obj/item/projectile/beam/emitter/A = getFromPool(/obj/item/projectile/beam/emitter, loc)
playsound(get_turf(src), 'sound/weapons/emitter.ogg', 25, 1) playsound(get_turf(src), 'sound/weapons/emitter.ogg', 25, 1)
if(prob(35)) if(prob(35))
var/datum/effect/effect/system/spark_spread/s = new /datum/effect/effect/system/spark_spread var/datum/effect/effect/system/spark_spread/s = new /datum/effect/effect/system/spark_spread

View File

@@ -67,13 +67,14 @@
proc/check_fire(var/mob/living/target as mob, var/mob/living/user as mob) //Checks if you can hit them or not. proc/check_fire(var/mob/living/target as mob, var/mob/living/user as mob) //Checks if you can hit them or not.
if(!istype(target) || !istype(user)) if(!istype(target) || !istype(user))
return 0 return 0
var/obj/item/projectile/test/in_chamber = new /obj/item/projectile/test(get_step_to(user,target)) //Making the test.... var/obj/item/projectile/test/in_chamber = getFromPool(/obj/item/projectile/test, get_step_to(user, target)) //Making the test....
in_chamber.target = target in_chamber.target = target
in_chamber.flags = flags //Set the flags... in_chamber.flags = flags //Set the flags...
in_chamber.pass_flags = pass_flags //And the pass flags to that of the real projectile... in_chamber.pass_flags = pass_flags //And the pass flags to that of the real projectile...
in_chamber.firer = user in_chamber.firer = user
var/output = in_chamber.process() //Test it! var/output = in_chamber.process() //Test it!
del(in_chamber) //No need for it anymore //del(in_chamber) //No need for it anymore
returnToPool(in_chamber)
return output //Send it back to the gun! return output //Send it back to the gun!
Bump(atom/A as mob|obj|turf|area) Bump(atom/A as mob|obj|turf|area)
@@ -164,10 +165,11 @@
O.bullet_act(src) O.bullet_act(src)
for(var/mob/M in A) for(var/mob/M in A)
M.bullet_act(src, def_zone) M.bullet_act(src, def_zone)
if(!istype(src, /obj/item/projectile/beam/lightning)) spawn()//if(!istype(src, /obj/item/projectile/beam/lightning))
density = 0 density = 0
invisibility = 101 invisibility = 101
del(src) //del(src)
returnToPool(src)
return 1 return 1
@@ -182,14 +184,16 @@
process() process()
if(kill_count < 1) if(kill_count < 1)
del(src) //del(src)
returnToPool(src)
return return
kill_count-- kill_count--
spawn while(src) spawn while(src)
if((!( current ) || loc == current)) if((!( current ) || loc == current))
current = locate(min(max(x + xo, 1), world.maxx), min(max(y + yo, 1), world.maxy), z) 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)) if((x == 1 || x == world.maxx || y == 1 || y == world.maxy))
del(src) //del(src)
returnToPool(src)
return return
step_towards(src, current) step_towards(src, current)
sleep(1) sleep(1)
@@ -201,9 +205,11 @@
return return
proc/dumbfire(var/dir) // for spacepods, go snowflake go proc/dumbfire(var/dir) // for spacepods, go snowflake go
if(!dir) if(!dir)
del(src) //del(src)
returnToPool(src)
if(kill_count < 1) if(kill_count < 1)
del(src) //del(src)
returnToPool(src)
kill_count-- kill_count--
spawn while(src) spawn while(src)
var/turf/T = get_step(src, dir) var/turf/T = get_step(src, dir)

View File

@@ -163,7 +163,8 @@ var/list/beam_master = list()
if(src.loc != current) if(src.loc != current)
tang = adjustAngle(get_angle(src.loc,current)) tang = adjustAngle(get_angle(src.loc,current))
icon_state = "[tang]" icon_state = "[tang]"
del(src) //del(src)
returnToPool(src)
return return
/*cleanup(reference) //Waits .3 seconds then removes the overlay. /*cleanup(reference) //Waits .3 seconds then removes the overlay.
//world << "setting invisibility" //world << "setting invisibility"
@@ -194,12 +195,16 @@ var/list/beam_master = list()
if((!( current ) || loc == current)) //If we pass our target 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) 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)) if((x == 1 || x == world.maxx || y == 1 || y == world.maxy))
del(src) //Delete if it passes the world edge //del(src) //Delete if it passes the world edge
returnToPool(src)
return return
step_towards(src, current) //Move~ step_towards(src, current) //Move~
if(isnull(loc))
return
if(kill_count < 1) if(kill_count < 1)
del(src) //del(src)
returnToPool(src)
return return
kill_count-- kill_count--
@@ -239,16 +244,20 @@ var/list/beam_master = list()
var/reference = "\ref[src]" //So we do not have to recalculate it a ton 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 var/first = 1 //So we don't make the overlay in the same tile as the firer
if(!dir) if(!dir)
del(src) //del(src)
returnToPool(src)
spawn while(src) //Move until we hit something spawn while(src) //Move until we hit something
if((x == 1 || x == world.maxx || y == 1 || y == world.maxy)) if((x == 1 || x == world.maxx || y == 1 || y == world.maxy))
del(src) //Delete if it passes the world edge //del(src) //Delete if it passes the world edge
returnToPool(src)
return return
var/turf/T = get_step(src, dir) var/turf/T = get_step(src, dir)
step_towards(src, T) //Move~ step_towards(src, T) //Move~
if(isnull(loc))
return
if(kill_count < 1) if(kill_count < 1)
del(src) //del(src)
returnToPool(src)
kill_count-- kill_count--
if(!bumped && !isturf(original)) if(!bumped && !isturf(original))

View File

@@ -192,10 +192,12 @@ obj/item/projectile/kinetic/New()
// Now we bump as a bullet, if the atom is a non-turf. // Now we bump as a bullet, if the atom is a non-turf.
if(!isturf(A)) if(!isturf(A))
..(A) ..(A)
qdel(src) // Comment this out if you want to shoot through the asteroid, ERASER-style. //qdel(src) // Comment this out if you want to shoot through the asteroid, ERASER-style.
returnToPool(src)
return 1 return 1
else else
qdel(src) //qdel(src)
returnToPool(src)
return 0 return 0
/obj/item/effect/kinetic_blast /obj/item/effect/kinetic_blast