Support for unit missiles

This commit is contained in:
Anuken
2021-12-07 16:58:11 -05:00
parent f5e9df1265
commit 0b7d8f371e
16 changed files with 276 additions and 77 deletions

View File

@@ -69,7 +69,7 @@ abstract class CommanderComp implements Entityc, Posc{
units.clear();
Units.nearby(team, x, y, type.commandRadius, u -> {
if(u.isAI() && include.get(u) && u != self() && u.type.flying == type.flying && u.hitSize <= hitSize * 1.1f){
if(u.isAI() && include.get(u) && u != self() && u.type.flying == type.flying && u.hitSize <= hitSize * 1.1f && u.type.playerControllable){
units.add(u);
}
});

View File

@@ -5,6 +5,7 @@ import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.core.*;
import mindustry.gen.*;
import mindustry.world.*;
import mindustry.world.blocks.environment.*;
@@ -50,9 +51,9 @@ abstract class PosComp implements Position{
return tile == null ? Blocks.air : tile.block();
}
boolean onSolid(){
Tile tile = tileOn();
return tile == null || tile.solid();
@Nullable
Building buildOn(){
return world.buildWorld(x, y);
}
@Nullable
@@ -60,6 +61,11 @@ abstract class PosComp implements Position{
return world.tileWorld(x, y);
}
boolean onSolid(){
Tile tile = tileOn();
return tile == null || tile.solid();
}
@Override
public float getX(){
return x;

View File

@@ -0,0 +1,28 @@
package mindustry.entities.comp;
import arc.math.*;
import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
//basically just TimedComp but kills instead of removing.
@Component
abstract class TimedKillComp implements Entityc, Healthc, Scaled{
float time, lifetime;
//called last so pooling and removal happens then.
@MethodPriority(100)
@Override
public void update(){
time = Math.min(time + Time.delta, lifetime);
if(time >= lifetime){
kill();
}
}
@Override
public float fin(){
return time / lifetime;
}
}

View File

@@ -1,26 +0,0 @@
package mindustry.entities.comp;
import arc.math.*;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
@Component
abstract class TrailComp implements Unitc{
@Import UnitType type;
@Import float x, y, rotation;
transient Trail trail = new Trail(6);
@Override
public void update(){
trail.length = type.trailLength;
float scale = elevation();
float offset = type.engineOffset/2f + type.engineOffset/2f*scale;
float cx = x + Angles.trnsx(rotation + 180, offset), cy = y + Angles.trnsy(rotation + 180, offset);
trail.update(cx, cy);
}
}

View File

@@ -20,6 +20,7 @@ import mindustry.entities.units.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.logic.*;
import mindustry.type.*;
import mindustry.ui.*;
@@ -46,6 +47,8 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
boolean spawnedByCore;
double flag;
transient @Nullable Trail trail;
transient float shadowAlpha = -1f;
transient Seq<Ability> abilities = new Seq<>(0);
transient float healTime;
@@ -339,6 +342,11 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
public void remove(){
team.data().updateCount(type, -1);
controller.removed(self());
//make sure trail doesn't just go poof
if(trail != null && trail.size() > 0){
Fx.trailFade.at(x, y, trail.width(), team.color, trail.copy());
}
}
@Override
@@ -390,6 +398,16 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
}
}
if(trail != null){
trail.length = type.trailLength;
float scale = elevation();
float offset = type.engineOffset/2f + type.engineOffset/2f*scale;
float cx = x + Angles.trnsx(rotation + 180, offset), cy = y + Angles.trnsy(rotation + 180, offset);
trail.update(cx, cy);
}
drag = type.drag * (isGrounded() ? (floorOn().dragMultiplier) : 1f) * dragMultiplier * state.rules.dragMultiplier;
//apply knockback based on spawns