underBullet for ducts and related blocks

This commit is contained in:
Anuken
2022-04-11 13:06:39 -04:00
parent 6fe71dfe9c
commit 12eddd131b
10 changed files with 52 additions and 10 deletions

View File

@@ -531,6 +531,10 @@ public class BulletType extends Content implements Cloneable{
}
public @Nullable Bullet create(@Nullable Entityc owner, Team team, float x, float y, float angle, float damage, float velocityScl, float lifetimeScl, Object data, @Nullable Mover mover){
return create(owner, team, x, y, angle, damage, velocityScl, lifetimeScl, data, mover, -1f, -1f);
}
public @Nullable Bullet create(@Nullable Entityc owner, Team team, float x, float y, float angle, float damage, float velocityScl, float lifetimeScl, Object data, @Nullable Mover mover, float aimX, float aimY){
if(spawnUnit != null){
//don't spawn units clientside!
if(!net.client()){
@@ -555,6 +559,7 @@ public class BulletType extends Content implements Cloneable{
bullet.owner = owner;
bullet.team = team;
bullet.time = 0f;
bullet.aimTile = world.tileWorld(aimX, aimY);
bullet.initVel(angle, speed * velocityScl);
if(backMove){
bullet.set(x - bullet.vel.x * Time.delta, y - bullet.vel.y * Time.delta);

View File

@@ -50,7 +50,7 @@ import static mindustry.Vars.*;
@Component(base = true)
abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, QuadTreeObject, Displayable, Senseable, Controllable, Sized{
//region vars and initialization
static final float timeToSleep = 60f * 1, timeToUncontrol = 60f * 6;
static final float timeToSleep = 60f * 1, recentDamageTime = 60f * 5f;
static final ObjectSet<Building> tmpTiles = new ObjectSet<>();
static final Seq<Building> tempBuilds = new Seq<>();
static final BuildTeamChangeEvent teamChangeEvent = new BuildTeamChangeEvent();
@@ -91,6 +91,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
transient float healSuppressionTime = -1f;
transient float lastHealTime = -120f * 10f;
private transient float lastDamageTime = -recentDamageTime;
private transient float timeScale = 1f, timeScaleDuration;
private transient float dumpAccum;
@@ -406,6 +407,10 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
return lastHealTime + duration >= Time.time;
}
public boolean wasRecentlyDamaged(){
return lastDamageTime + recentDamageTime >= Time.time;
}
public Building nearby(int dx, int dy){
return world.build(tile.x + dx, tile.y + dy);
}
@@ -1781,6 +1786,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
if(dead()) return;
float dm = state.rules.blockHealth(team);
lastDamageTime = Time.time;
if(Mathf.zero(dm)){
damage = health + 1;

View File

@@ -37,6 +37,7 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
@ReadOnly
private float rotation;
transient @Nullable Tile aimTile;
transient @Nullable Mover mover;
transient boolean absorbed, hit;
transient @Nullable Trail trail;
@@ -173,7 +174,11 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
}
}
if(build != null && isAdded() && build.collide(self()) && type.testCollision(self(), build)
if(build != null && isAdded() &&
//should underBullet detection be disabled for piercing bullets?
//|| type.pierceBuilding
(!build.block.underBullets || (aimTile != null && aimTile.build == build))
&& build.collide(self()) && type.testCollision(self(), build)
&& !build.dead() && (type.collidesTeam || build.team != team) && !(type.pierceBuilding && hasCollided(build.id))){
boolean remove = false;