Fix ContinuousLiquidTurret not changing bullets when changing liquids. (#7561)
* Wrong liquid, don't keep bullet alive. * Better transition * Annihilate unnecessary code duplication * Further reduce duplicated code * Unnecessary imports
This commit is contained in:
@@ -72,6 +72,11 @@ public class ContinuousLiquidTurret extends ContinuousTurret{
|
|||||||
super.updateTile();
|
super.updateTile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canConsume(){
|
||||||
|
return hasCorrectAmmo() && super.canConsume();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BulletType useAmmo(){
|
public BulletType useAmmo(){
|
||||||
//does not consume ammo upon firing
|
//does not consume ammo upon firing
|
||||||
@@ -85,7 +90,11 @@ public class ContinuousLiquidTurret extends ContinuousTurret{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasAmmo(){
|
public boolean hasAmmo(){
|
||||||
return ammoTypes.get(liquids.current()) != null && liquids.currentAmount() >= 1f / ammoTypes.get(liquids.current()).ammoMultiplier;
|
return hasCorrectAmmo() && ammoTypes.get(liquids.current()) != null && liquids.currentAmount() >= 1f / ammoTypes.get(liquids.current()).ammoMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasCorrectAmmo(){
|
||||||
|
return !bullets.any() || bullets.first().bullet.type == peekAmmo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -81,30 +81,7 @@ public class ContinuousTurret extends Turret{
|
|||||||
|
|
||||||
if(bullets.any()){
|
if(bullets.any()){
|
||||||
for(var entry : bullets){
|
for(var entry : bullets){
|
||||||
float
|
updateBullet(entry);
|
||||||
bulletX = x + Angles.trnsx(rotation - 90, shootX + entry.x, shootY + entry.y),
|
|
||||||
bulletY = y + Angles.trnsy(rotation - 90, shootX + entry.x, shootY + entry.y),
|
|
||||||
angle = rotation + entry.rotation;
|
|
||||||
|
|
||||||
entry.bullet.rotation(angle);
|
|
||||||
entry.bullet.set(bulletX, bulletY);
|
|
||||||
|
|
||||||
//target length of laser
|
|
||||||
float shootLength = Math.min(dst(targetPos), range);
|
|
||||||
//current length of laser
|
|
||||||
float curLength = dst(entry.bullet.aimX, entry.bullet.aimY);
|
|
||||||
//resulting length of the bullet (smoothed)
|
|
||||||
float resultLength = Mathf.approachDelta(curLength, shootLength, aimChangeSpeed);
|
|
||||||
//actual aim end point based on length
|
|
||||||
Tmp.v1.trns(rotation, lastLength = resultLength).add(x, y);
|
|
||||||
|
|
||||||
entry.bullet.aimX = Tmp.v1.x;
|
|
||||||
entry.bullet.aimY = Tmp.v1.y;
|
|
||||||
|
|
||||||
if(isShooting() && hasAmmo()){
|
|
||||||
entry.bullet.time = entry.bullet.lifetime * entry.bullet.type.optimalLifeFract * shootWarmup;
|
|
||||||
entry.bullet.keepAlive = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wasShooting = true;
|
wasShooting = true;
|
||||||
@@ -113,6 +90,33 @@ public class ContinuousTurret extends Turret{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void updateBullet(BulletEntry entry){
|
||||||
|
float
|
||||||
|
bulletX = x + Angles.trnsx(rotation - 90, shootX + entry.x, shootY + entry.y),
|
||||||
|
bulletY = y + Angles.trnsy(rotation - 90, shootX + entry.x, shootY + entry.y),
|
||||||
|
angle = rotation + entry.rotation;
|
||||||
|
|
||||||
|
entry.bullet.rotation(angle);
|
||||||
|
entry.bullet.set(bulletX, bulletY);
|
||||||
|
|
||||||
|
//target length of laser
|
||||||
|
float shootLength = Math.min(dst(targetPos), range);
|
||||||
|
//current length of laser
|
||||||
|
float curLength = dst(entry.bullet.aimX, entry.bullet.aimY);
|
||||||
|
//resulting length of the bullet (smoothed)
|
||||||
|
float resultLength = Mathf.approachDelta(curLength, shootLength, aimChangeSpeed);
|
||||||
|
//actual aim end point based on length
|
||||||
|
Tmp.v1.trns(rotation, lastLength = resultLength).add(x, y);
|
||||||
|
|
||||||
|
entry.bullet.aimX = Tmp.v1.x;
|
||||||
|
entry.bullet.aimY = Tmp.v1.y;
|
||||||
|
|
||||||
|
if(isShooting() && hasAmmo()){
|
||||||
|
entry.bullet.time = entry.bullet.lifetime * entry.bullet.type.optimalLifeFract * shootWarmup;
|
||||||
|
entry.bullet.keepAlive = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateReload(){
|
protected void updateReload(){
|
||||||
//continuous turrets don't have a concept of reload, they are always firing when possible
|
//continuous turrets don't have a concept of reload, they are always firing when possible
|
||||||
|
|||||||
Reference in New Issue
Block a user