Cleanup & refactor of projectors

This commit is contained in:
Anuken
2019-11-12 17:18:27 -05:00
parent 7d9963d542
commit 4b70b2fbcc
12 changed files with 103 additions and 76 deletions

View File

@@ -6,6 +6,7 @@ import io.anuke.arc.func.*;
import io.anuke.arc.math.*;
import io.anuke.arc.math.geom.*;
import io.anuke.mindustry.content.*;
import io.anuke.mindustry.entities.traits.*;
import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.game.*;
@@ -25,6 +26,7 @@ public class BlockIndexer{
/** Set of all ores that are being scanned. */
private final ObjectSet<Item> scanOres = new ObjectSet<>();
private final IntSet intSet = new IntSet();
private final ObjectSet<Item> itemSet = new ObjectSet<>();
/** Stores all ore quadtrants on the map. */
private ObjectMap<Item, ObjectSet<Tile>> ores = new ObjectMap<>();
@@ -138,6 +140,39 @@ public class BlockIndexer{
return flagMap[team.ordinal()][type.ordinal()];
}
public boolean eachBlock(TeamTrait trait, float range, Boolf<Tile> pred, Cons<Tile> cons){
return eachBlock(trait.getTeam(), trait.getX(), trait.getY(), range, pred, cons);
}
public boolean eachBlock(Team team, float wx, float wy, float range, Boolf<Tile> pred, Cons<Tile> cons){
intSet.clear();
int tx = world.toTile(wx);
int ty = world.toTile(wy);
int tileRange = (int)(range / tilesize + 1);
intSet.clear();
boolean any = false;
for(int x = -tileRange + tx; x <= tileRange + tx; x++){
for(int y = -tileRange + ty; y <= tileRange + ty; y++){
if(!Mathf.within(x * tilesize, y * tilesize, wx, wy, range)) continue;
Tile other = world.ltile(x, y);
if(other == null) continue;
if(other.getTeam() == team && !intSet.contains(other.pos()) && other.entity != null && pred.get(other)){
cons.get(other);
any = true;
intSet.add(other.pos());
}
}
}
return any;
}
/** Get all enemy blocks with a flag. */
public Array<Tile> getEnemy(Team team, BlockFlag type){
returnArray.clear();

View File

@@ -1252,6 +1252,7 @@ public class Blocks implements ContentList{
health = 1100;
itemCapacity = 4000;
size = 3;
mech = Mechs.vanguard;
}};
coreFoundation = new CoreBlock("core-foundation"){{
@@ -1260,6 +1261,7 @@ public class Blocks implements ContentList{
health = 2000;
itemCapacity = 9000;
size = 4;
mech = Mechs.vanguard;
}};
coreNucleus = new CoreBlock("core-nucleus"){{
@@ -1268,6 +1270,7 @@ public class Blocks implements ContentList{
health = 4000;
itemCapacity = 13000;
size = 5;
mech = Mechs.vanguard;
}};
vault = new Vault("vault"){{

View File

@@ -15,6 +15,8 @@ import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.type.*;
import static io.anuke.mindustry.Vars.indexer;
public class Mechs implements ContentList{
public static Mech vanguard, alpha, delta, tau, omega, dart, javelin, trident, glaive;
@@ -22,7 +24,12 @@ public class Mechs implements ContentList{
@Override
public void load(){
vanguard = new Mech("vanguard-ship", true){
float healRange = 60f;
float healReload = 200f;
float healPercent = 10f;
{
drillPower = 1;
mineSpeed = 4f;
@@ -62,6 +69,18 @@ public class Mechs implements ContentList{
public boolean alwaysUnlocked(){
return true;
}
@Override
public void updateAlt(Player player){
if(player.timer.get(Player.timerAbility, healReload)){
if(indexer.eachBlock(player, healRange, other -> other.entity.damaged(), other -> {
other.entity.healBy(other.entity.maxHealth() * healPercent);
Effects.effect(Fx.healBlockFull, Pal.heal, other.drawx(), other.drawy(), other.block().size);
})){
Effects.effect(Fx.healWave, player);
}
}
}
};
alpha = new Mech("alpha-mech", false){
@@ -79,19 +98,20 @@ public class Mechs implements ContentList{
weapon = new Weapon("shockgun"){{
shake = 2f;
length = 1f;
length = 0.5f;
reload = 70f;
alternate = true;
bullet = Bullets.lancerLaser;
recoil = 4f;
shootSound = Sounds.spark;
width = 5f;
shootSound = Sounds.laser;
bullet = new LaserBulletType(20f){{
bullet = new LaserBulletType(){{
damage = 20f;
recoil = 1f;
sideAngle = 45f;
sideWidth = 1f;
sideLength = 70f;
colors = new Color[]{Pal.heal.cpy().mul(1, 1, 1, 0.4f), Pal.heal, Color.white};
colors = new Color[]{Pal.heal.cpy().a(0.4f), Pal.heal, Color.white};
}};
}};
}

View File

@@ -4,8 +4,8 @@ import io.anuke.arc.*;
import io.anuke.arc.collection.*;
import io.anuke.arc.math.*;
import io.anuke.arc.math.geom.*;
import io.anuke.arc.util.*;
import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.content.*;
import io.anuke.mindustry.core.GameState.*;
import io.anuke.mindustry.game.EventType.*;

View File

@@ -30,6 +30,10 @@ public class LaserBulletType extends BulletType{
pierce = true;
}
public LaserBulletType(){
this(1f);
}
@Override
public float range(){
return length;

View File

@@ -1,6 +1,7 @@
package io.anuke.mindustry.entities.traits;
import io.anuke.mindustry.entities.EntityGroup;
import io.anuke.mindustry.*;
import io.anuke.mindustry.entities.*;
public interface Entity extends MoveTrait{
@@ -14,6 +15,14 @@ public interface Entity extends MoveTrait{
default void added(){}
default int tileX(){
return Vars.world.toTile(getX());
}
default int tileY(){
return Vars.world.toTile(getY());
}
EntityGroup targetGroup();
@SuppressWarnings("unchecked")

View File

@@ -1,8 +1,7 @@
package io.anuke.mindustry.entities.type;
import io.anuke.mindustry.*;
import io.anuke.mindustry.entities.EntityGroup;
import io.anuke.mindustry.entities.traits.Entity;
import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.entities.traits.*;
public abstract class BaseEntity implements Entity{
private static int lastid;
@@ -15,14 +14,6 @@ public abstract class BaseEntity implements Entity{
id = lastid++;
}
public int tileX(){
return Vars.world.toTile(x);
}
public int tileY(){
return Vars.world.toTile(y);
}
@Override
public int getID(){
return id;

View File

@@ -9,8 +9,7 @@ import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.*;
import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.mindustry.entities.EntityGroup;
import io.anuke.mindustry.entities.traits.HealthTrait;
import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.entities.traits.*;
import io.anuke.mindustry.game.*;
import io.anuke.mindustry.game.EventType.BlockDestroyEvent;
import io.anuke.mindustry.gen.*;
@@ -21,7 +20,7 @@ import java.io.*;
import static io.anuke.mindustry.Vars.*;
public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait, TeamTrait{
public static final float timeToSleep = 60f * 4; //4 seconds to fall asleep
private static final ObjectSet<Tile> tmpTiles = new ObjectSet<>();
/** This value is only used for debugging. */

View File

@@ -1,14 +1,13 @@
package io.anuke.mindustry.world.blocks.defense;
import io.anuke.arc.Core;
import io.anuke.arc.collection.IntSet;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.*;
import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.content.Fx;
import io.anuke.mindustry.entities.Effects;
import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.content.*;
import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.meta.*;
@@ -20,7 +19,6 @@ import static io.anuke.mindustry.Vars.*;
public class MendProjector extends Block{
private static Color color = Color.valueOf("84f491");
private static Color phase = Color.valueOf("ffd59e");
private static IntSet healed = new IntSet();
protected int timerUse = timers++;
@@ -78,24 +76,10 @@ public class MendProjector extends Block{
float realRange = range + entity.phaseHeat * phaseRangeBoost;
entity.charge = 0f;
int tileRange = (int)(realRange / tilesize + 1);
healed.clear();
for(int x = -tileRange + tile.x; x <= tileRange + tile.x; x++){
for(int y = -tileRange + tile.y; y <= tileRange + tile.y; y++){
if(!Mathf.within(x * tilesize, y * tilesize, tile.drawx(), tile.drawy(), realRange)) continue;
Tile other = world.ltile(x, y);
if(other == null) continue;
if(other.getTeamID() == tile.getTeamID() && !healed.contains(other.pos()) && other.entity != null && other.entity.health < other.entity.maxHealth()){
other.entity.healBy(other.entity.maxHealth() * (healPercent + entity.phaseHeat * phaseBoost) / 100f * entity.power.satisfaction);
Effects.effect(Fx.healBlockFull, Tmp.c1.set(color).lerp(phase, entity.phaseHeat), other.drawx(), other.drawy(), other.block().size);
healed.add(other.pos());
}
}
}
indexer.eachBlock(entity, realRange, other -> other.entity.damaged(), other -> {
other.entity.healBy(other.entity.maxHealth() * (healPercent + entity.phaseHeat * phaseBoost) / 100f * entity.power.satisfaction);
Effects.effect(Fx.healBlockFull, Tmp.c1.set(color).lerp(phase, entity.phaseHeat), other.drawx(), other.drawy(), other.block().size);
});
}
}

View File

@@ -1,12 +1,12 @@
package io.anuke.mindustry.world.blocks.defense;
import io.anuke.arc.Core;
import io.anuke.arc.collection.IntSet;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.*;
import io.anuke.arc.collection.*;
import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.arc.math.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.meta.*;
@@ -83,27 +83,10 @@ public class OverdriveProjector extends Block{
float realBoost = (speedBoost + entity.phaseHeat * speedBoostPhase) * entity.power.satisfaction;
entity.charge = 0f;
int tileRange = (int)(realRange / tilesize + 1);
healed.clear();
for(int x = -tileRange + tile.x; x <= tileRange + tile.x; x++){
for(int y = -tileRange + tile.y; y <= tileRange + tile.y; y++){
if(!Mathf.within(x * tilesize, y * tilesize, tile.drawx(), tile.drawy(), realRange)) continue;
Tile other = world.ltile(x, y);
if(other == null) continue;
if(other.getTeamID() == tile.getTeamID() && !healed.contains(other.pos()) && other.entity != null){
if(other.entity.timeScale <= realBoost){
other.entity.timeScaleDuration = Math.max(other.entity.timeScaleDuration, reload + 1f);
other.entity.timeScale = Math.max(other.entity.timeScale, realBoost);
}
healed.add(other.pos());
}
}
}
indexer.eachBlock(entity, realRange, other -> other.entity.timeScale <= realBoost, other -> {
other.entity.timeScaleDuration = Math.max(other.entity.timeScaleDuration, reload + 1f);
other.entity.timeScale = Math.max(other.entity.timeScale, realBoost);
});
}
}