RailBulletType improvements

This commit is contained in:
Anuken
2022-02-25 13:24:18 -05:00
parent 28dab2fa05
commit 7245364a55
10 changed files with 74 additions and 52 deletions
+1 -1
View File
@@ -214,7 +214,7 @@ public class Damage{
//try to heal the tile
if(collide && hitter.type.testCollision(hitter, tile)){
hitter.type.hitTile(hitter, tile, health, false);
hitter.type.hitTile(hitter, tile, cx * tilesize, cy * tilesize, health, false);
}
}
};
@@ -255,12 +255,12 @@ public class BulletType extends Content implements Cloneable{
/** If direct is false, this is an indirect hit and the tile was already damaged.
* TODO this is a mess. */
public void hitTile(Bullet b, Building build, float initialHealth, boolean direct){
public void hitTile(Bullet b, Building build, float x, float y, float initialHealth, boolean direct){
if(makeFire && build.team != b.team){
Fires.create(build.tile);
}
if(heals()&& build.team == b.team && !(build.block instanceof ConstructBlock)){
if(heals() && build.team == b.team && !(build.block instanceof ConstructBlock)){
healEffect.at(build.x, build.y, build.block.size, healColor);
build.heal(healPercent / 100f * build.maxHealth + healAmount);
}else if(build.team != b.team && direct){
@@ -9,14 +9,16 @@ import mindustry.gen.*;
public class RailBulletType extends BulletType{
//for calculating the furthest point
static float furthest = 0;
static boolean any = false;
public Effect pierceEffect = Fx.hitBulletSmall, updateEffect = Fx.none;
public Effect pierceEffect = Fx.hitBulletSmall, pointEffect = Fx.none, lineEffect = Fx.none;
public Effect endEffect;
/** Multiplier of damage decreased per health pierced. */
public float pierceDamageFactor = 1f;
public float length = 100f;
public float updateEffectSeg = 20f;
public float pointEffectSpace = 20f;
public RailBulletType(){
speed = 0f;
@@ -34,18 +36,18 @@ public class RailBulletType extends BulletType{
return length;
}
void handle(Bullet b, Posc pos, float initialHealth){
void handle(Bullet b, float initialHealth, float x, float y){
float sub = Math.max(initialHealth*pierceDamageFactor, 0);
if(b.damage <= 0){
b.fdata = Math.min(b.fdata, b.dst(pos));
b.fdata = Math.min(b.fdata, b.dst(x, y));
return;
}
if(b.damage > 0){
pierceEffect.at(pos.getX(), pos.getY(), b.rotation());
pierceEffect.at(x, y, b.rotation());
hitEffect.at(pos.getX(), pos.getY());
hitEffect.at(x, y);
}
//subtract health from each consecutive pierce
@@ -53,8 +55,10 @@ public class RailBulletType extends BulletType{
//bullet was stopped, decrease furthest distance
if(b.damage <= 0f){
furthest = Math.min(furthest, b.dst(pos));
furthest = Math.min(furthest, b.dst(x, y));
}
any = true;
}
@Override
@@ -63,12 +67,23 @@ public class RailBulletType extends BulletType{
b.fdata = length;
furthest = length;
any = false;
Damage.collideLine(b, b.team, b.type.hitEffect, b.x, b.y, b.rotation(), length, false, false);
float resultLen = furthest;
Vec2 nor = Tmp.v1.trns(b.rotation(), 1f).nor();
for(float i = 0; i <= resultLen; i += updateEffectSeg){
updateEffect.at(b.x + nor.x * i, b.y + nor.y * i, b.rotation());
if(pointEffect != Fx.none){
for(float i = 0; i <= resultLen; i += pointEffectSpace){
pointEffect.at(b.x + nor.x * i, b.y + nor.y * i, b.rotation(), trailColor);
}
}
if(!any){
endEffect.at(b.x + nor.x * resultLen, b.y + nor.y * resultLen, b.rotation(), hitColor);
}
if(lineEffect != Fx.none){
lineEffect.at(b.x, b.y, b.rotation(), hitColor, new Vec2(b.x, b.y).mulAdd(nor, resultLen));
}
}
@@ -80,11 +95,11 @@ public class RailBulletType extends BulletType{
@Override
public void hitEntity(Bullet b, Hitboxc entity, float health){
super.hitEntity(b, entity, health);
handle(b, entity, health);
handle(b, health, entity.getX(), entity.getY());
}
@Override
public void hitTile(Bullet b, Building build, float initialHealth, boolean direct){
handle(b, build, initialHealth);
public void hitTile(Bullet b, Building build, float x, float y, float initialHealth, boolean direct){
handle(b, initialHealth, x, y);
}
}
@@ -132,9 +132,9 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
//copy-paste of World#raycastEach, inlined for lambda capture performance.
@Override
public void tileRaycast(int x0f, int y0f, int x1, int y1){
int x = x0f, dx = Math.abs(x1 - x), sx = x < x1 ? 1 : -1;
int y = y0f, dy = Math.abs(y1 - y), sy = y < y1 ? 1 : -1;
public void tileRaycast(int x1, int y1, int x2, int y2){
int x = x1, dx = Math.abs(x2 - x), sx = x < x2 ? 1 : -1;
int y = y1, dy = Math.abs(y2 - y), sy = y < y2 ? 1 : -1;
int e2, err = dx - dy;
int ww = world.width(), wh = world.height();
@@ -173,13 +173,13 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
}
}
type.hitTile(self(), build, health, true);
type.hitTile(self(), build, x * tilesize, y * tilesize, health, true);
//stop raycasting when building is hit
if(type.pierceBuilding) return;
}
if(x == x1 && y == y1) break;
if(x == x2 && y == y2) break;
e2 = 2 * err;
if(e2 > -dy){
@@ -92,6 +92,10 @@ public abstract class DrawPart{
return p -> (get(p) - amount) / (1f - amount);
}
default PartProgress curve(float offset, float duration){
return p -> (get(p) - offset) / duration;
}
default PartProgress shorten(float amount){
return p -> get(p) / (1f - amount);
}