More intelligent suicide units / Bugfixes

This commit is contained in:
Anuken
2020-06-06 11:36:14 -04:00
parent 1e3a190d5a
commit 0f76aeba05
9 changed files with 144 additions and 54 deletions

View File

@@ -207,47 +207,53 @@ public class Damage{
}
}
public static void tileDamage(Team team, int startx, int starty, int radius, float baseDamage){
bits.clear();
propagation.clear();
int bitOffset = bits.width() / 2;
public static void tileDamage(Team team, int startx, int starty, int baseRadius, float baseDamage){
//tile damage is posted, so that destroying a block that causes a chain explosion will run in the next frame
//this prevents recursive damage calls from messing up temporary variables
Core.app.post(() -> {
propagation.addFirst(PropCell.get((byte)0, (byte)0, (short)baseDamage));
//clamp radius to fit bits
radius = Math.min(radius, bits.width() / 2);
bits.clear();
propagation.clear();
int bitOffset = bits.width() / 2;
while(!propagation.isEmpty()){
int prop = propagation.removeLast();
int x = PropCell.x(prop);
int y = PropCell.y(prop);
int damage = PropCell.damage(prop);
//manhattan distance used for calculating falloff, results in a diamond pattern
int dst = Math.abs(x) + Math.abs(y);
propagation.addFirst(PropCell.get((byte)0, (byte)0, (short)baseDamage));
//clamp radius to fit bits
int radius = Math.min(baseRadius, bits.width() / 2);
int scaledDamage = (int)(damage * (1f - (float)dst / radius));
while(!propagation.isEmpty()){
int prop = propagation.removeLast();
int x = PropCell.x(prop);
int y = PropCell.y(prop);
int damage = PropCell.damage(prop);
//manhattan distance used for calculating falloff, results in a diamond pattern
int dst = Math.abs(x) + Math.abs(y);
bits.set(bitOffset + x, bitOffset + y);
Tilec tile = world.ent(startx + x, starty + y);
int scaledDamage = (int)(damage * (1f - (float)dst / radius));
if(scaledDamage <= 0 || tile == null) continue;
bits.set(bitOffset + x, bitOffset + y);
Tile tile = world.tile(startx + x, starty + y);
//apply damage to entity if needed
if(tile.team() != team){
int health = (int)tile.health();
if(tile.health() > 0){
tile.damage(scaledDamage);
scaledDamage -= health;
if(scaledDamage <= 0 || tile == null) continue;
if(scaledDamage <= 0) continue;
//apply damage to entity if needed
if(tile.entity != null && tile.team() != team){
int health = (int)tile.entity.health();
if(tile.entity.health() > 0){
tile.entity.damage(scaledDamage);
scaledDamage -= health;
if(scaledDamage <= 0) continue;
}
}
for(Point2 p : Geometry.d4){
if(!bits.get(bitOffset + x + p.x, bitOffset + y + p.y)){
propagation.addFirst(PropCell.get((byte)(x + p.x), (byte)(y + p.y), (short)scaledDamage));
}
}
}
});
for(Point2 p : Geometry.d4){
if(!bits.get(bitOffset + x + p.x, bitOffset + y + p.y)){
propagation.addFirst(PropCell.get((byte)(x + p.x), (byte)(y + p.y), (short)scaledDamage));
}
}
}
}
private static void completeDamage(Team team, float x, float y, float radius, float damage){

View File

@@ -30,7 +30,7 @@ public class LiquidBulletType extends BulletType{
hitEffect = Fx.hitLiquid;
smokeEffect = Fx.none;
shootEffect = Fx.none;
drag = 0.009f;
drag = 0.001f;
knockback = 0.55f;
}
@@ -61,7 +61,14 @@ public class LiquidBulletType extends BulletType{
public void draw(Bulletc b){
Draw.color(liquid.color, Color.white, b.fout() / 100f);
Fill.circle(b.x(), b.y(), 0.5f + b.fout() * 2.5f);
Fill.circle(b.x(), b.y(), 3f);
}
@Override
public void despawned(Bulletc b){
super.despawned(b);
hit(b, b.x(), b.y());
}
@Override

View File

@@ -37,7 +37,7 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
void setupWeapons(UnitType def){
mounts = new WeaponMount[def.weapons.size];
range = 0f;
range = def.range;
for(int i = 0; i < mounts.length; i++){
mounts[i] = new WeaponMount(def.weapons.get(i));
range = Math.max(range, def.weapons.get(i).bullet.range());