Bugfixes / Possibly fixed unit tests

This commit is contained in:
Anuken 2019-02-08 17:05:09 -05:00
parent bb0ee26e4f
commit a87e2a56d2
10 changed files with 30 additions and 72 deletions

View File

@ -13,5 +13,5 @@ varying vec2 v_texCoord;
void main() {
vec4 color = texture2D(u_texture, v_texCoord.xy);
color = vec4(0.0, 0.0, 0.0, 1.0 - color.r);
gl_FragColor = color * v_color;
gl_FragColor = color;
}

View File

@ -53,6 +53,8 @@ public class Vars{
public static final float itemSize = 5f;
/**extra padding around the world; units outside this bound will begin to self-destruct.*/
public static final float worldBounds = 100f;
/**units outside of this bound will simply die instantly*/
public static final float finalWorldBounds = worldBounds + 500;
/**ticks spent out of bound until self destruct.*/
public static final float boundsCountdown = 60*7;
/**size of tiles in units*/

View File

@ -185,9 +185,7 @@ public class World implements ApplicationListener{
addDarkness(tiles);
int padding = 50;
EntityQuery.resizeTree(-padding * tilesize, -padding * tilesize, (tiles.length + padding) * tilesize, (tiles[0].length + padding) * tilesize);
EntityQuery.resizeTree(-finalWorldBounds, -finalWorldBounds, tiles.length * tilesize + finalWorldBounds, tiles[0].length + finalWorldBounds);
generating = false;
Events.fire(new WorldLoadEvent());

View File

@ -5,7 +5,6 @@ import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Fill;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.Time;
import io.anuke.arc.util.Tmp;
@ -16,41 +15,20 @@ import io.anuke.mindustry.entities.units.UnitState;
import io.anuke.mindustry.graphics.Pal;
import io.anuke.mindustry.graphics.Shaders;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockFlag;
import static io.anuke.mindustry.Vars.world;
public abstract class FlyingUnit extends BaseUnit{
protected float[] weaponAngles = {0, 0};
protected final UnitState
idle = new UnitState(){
public void update(){
retarget(() -> {
targetClosest();
targetClosestEnemyFlag(BlockFlag.target);
if(target != null){
setState(attack);
}
});
target = getClosestCore();
if(target != null){
circle(50f);
}
velocity.scl(0.8f);
}
},
attack = new UnitState(){
public void entered(){
target = null;
}
public void update(){
if(Units.invalidateTarget(target, team, x, y)){
target = null;
}
@ -60,19 +38,15 @@ public abstract class FlyingUnit extends BaseUnit{
retarget(() -> {
targetClosest();
if(target == null){
setState(patrol);
return;
}
if(target == null) targetClosestEnemyFlag(BlockFlag.target);
if(target == null) targetClosestEnemyFlag(BlockFlag.producer);
if(target == null) targetClosestEnemyFlag(BlockFlag.turret);
if(target == null){
setState(idle);
setState(patrol);
}
});
}else{
attack(type.attackLength);
@ -103,6 +77,7 @@ public abstract class FlyingUnit extends BaseUnit{
public void update(){
retarget(() -> {
targetClosest();
targetClosestEnemyFlag(BlockFlag.target);
if(target != null){
setState(attack);
@ -115,24 +90,6 @@ public abstract class FlyingUnit extends BaseUnit{
circle(60f + Mathf.absin(Time.time() + id * 23525, 70f, 1200f));
}
}
},
retreat = new UnitState(){
public void entered(){
target = null;
}
public void update(){
if(health >= maxHealth()){
state.set(attack);
}else if(!targetHasFlag(BlockFlag.repair)){
retarget(() -> {
Tile target = Geometry.findClosest(x, y, world.indexer.getAllied(team, BlockFlag.repair));
if(target != null) FlyingUnit.this.target = target.entity;
});
}else{
circle(20f);
}
}
};
@Override
@ -183,17 +140,13 @@ public abstract class FlyingUnit extends BaseUnit{
@Override
public void behavior(){
if(Units.invalidateTarget(target, this)){
for(boolean left : Mathf.booleans){
int wi = Mathf.num(left);
weaponAngles[wi] = Mathf.slerpDelta(weaponAngles[wi],rotation, 0.1f);
}
}
if(health <= health * type.retreatPercent &&
Geometry.findClosest(x, y, world.indexer.getAllied(team, BlockFlag.repair)) != null){
setState(retreat);
}
}
@Override

View File

@ -57,19 +57,6 @@ public abstract class GroundUnit extends BaseUnit{
}
}
}
},
retreat = new UnitState(){
public void entered(){
target = null;
}
public void update(){
if(health >= maxHealth()){
state.set(attack);
}
moveAwayFromCore();
}
};
@Override
@ -158,9 +145,6 @@ public abstract class GroundUnit extends BaseUnit{
@Override
public void behavior(){
if(health <= health * type.retreatPercent){
setState(retreat);
}
if(!Units.invalidateTarget(target, this)){
if(dst(target) < getWeapon().bullet.range()){

View File

@ -292,4 +292,12 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
public EntityGroup targetGroup(){
return tileGroup;
}
@Override
public String toString(){
return "TileEntity{" +
"tile=" + tile +
", health=" + health +
'}';
}
}

View File

@ -258,6 +258,10 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
velocity.limit(maxVelocity()).scl(1f + (status.getSpeedMultiplier()-1f) * Time.delta());
if(x < -finalWorldBounds || y < -finalWorldBounds || x >= world.width() * tilesize + finalWorldBounds || y >= world.height() * tilesize + finalWorldBounds){
kill();
}
if(isFlying()){
move(velocity.x * Time.delta(), velocity.y * Time.delta());
}else{

View File

@ -14,6 +14,10 @@ public class StateMachine{
if(next != null) next.entered();
}
public UnitState current(){
return state;
}
public boolean is(UnitState state){
return this.state == state;
}

View File

@ -642,6 +642,8 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
public boolean pan(float x, float y, float deltaX, float deltaY){
if(Core.scene.hasDialog()) return false;
float scale = Core.camera.width / Core.graphics.getWidth();
deltaX *= scale;
deltaY *= scale;

View File

@ -51,6 +51,7 @@ public class PowerTests extends PowerTestFixture{
}
void simulateDirectConsumption(float producedPower, float requiredPower, float expectedSatisfaction, String parameterDescription){
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1f;
Tile directConsumerTile = createFakeTile(0, 1, createFakeDirectConsumer(requiredPower));
PowerGraph powerGraph = new PowerGraph();
@ -90,6 +91,7 @@ public class PowerTests extends PowerTestFixture{
}
void simulateBufferedConsumption(float producedPower, float maxBuffer, float powerConsumedPerTick, float initialSatisfaction, float expectedSatisfaction, String parameterDescription){
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1f;
Tile bufferedConsumerTile = createFakeTile(0, 1, createFakeBufferedConsumer(maxBuffer, maxBuffer > 0.0f ? maxBuffer/powerConsumedPerTick : 1.0f));
bufferedConsumerTile.entity.power.satisfaction = initialSatisfaction;
@ -134,6 +136,7 @@ public class PowerTests extends PowerTestFixture{
if(producedPower > 0.0f){
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1f;
powerGraph.add(producerTile);
}
Tile directConsumerTile = null;