Core cleanup / Turret draw class
This commit is contained in:
@@ -96,7 +96,7 @@ public class Blocks implements ContentList{
|
||||
//storage
|
||||
coreShard, coreFoundation, coreNucleus, vault, container, unloader,
|
||||
//storage - erekir
|
||||
coreBastion, coreAegis, coreCitadel, coreAcropolis,
|
||||
coreBastion, coreCitadel, coreAcropolis,
|
||||
|
||||
//turrets
|
||||
duo, scatter, scorch, hail, arc, wave, lancer, swarmer, salvo, fuse, ripple, cyclone, foreshadow, spectre, meltdown, segment, parallax, tsunami,
|
||||
@@ -1822,19 +1822,7 @@ public class Blocks implements ContentList{
|
||||
researchCostMultiplier = 0.11f;
|
||||
}};
|
||||
|
||||
//TODO remove - too small
|
||||
coreBastion = new CoreBlock("core-bastion"){{
|
||||
requirements(Category.effect, BuildVisibility.editorOnly, with(Items.beryllium, 1000, Items.graphite, 1000));
|
||||
|
||||
unitType = UnitTypes.evoke;
|
||||
health = 3000;
|
||||
itemCapacity = 3000; //TODO more or less?
|
||||
size = 3;
|
||||
|
||||
unitCapModifier = 10;
|
||||
}};
|
||||
|
||||
coreAegis = new CoreBlock("core-aegis"){{
|
||||
//TODO cost
|
||||
requirements(Category.effect, BuildVisibility.editorOnly, with(Items.beryllium, 2000, Items.graphite, 2000, Items.tungsten, 1000));
|
||||
|
||||
|
||||
@@ -8,15 +8,13 @@ public class Loadouts implements ContentList{
|
||||
basicShard,
|
||||
basicFoundation,
|
||||
basicNucleus,
|
||||
basicBastion,
|
||||
basicAegis;
|
||||
basicBastion;
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
basicShard = Schematics.readBase64("bXNjaAB4nD2K2wqAIBiD5ymibnoRn6YnEP1BwUMoBL19FuJ2sbFvUFgYZDaJsLeQrkinN9UJHImsNzlYE7WrIUastuSbnlKx2VJJt+8IQGGKdfO/8J5yrGJSMegLg+YUIA==");
|
||||
basicFoundation = Schematics.readBase64("bXNjaAB4nD1OSQ6DMBBzFhVu8BG+0X8MQyoiJTNSukj8nlCi2Adbtg/GA4OBF8oB00rvyE/9ykafqOIw58A7SWRKy1ZiShhZ5RcOLZhYS1hefQ1gRIeptH9jq/qW2lvc1d2tgWsOfVX/tOwE86AYBA==");
|
||||
basicNucleus = Schematics.readBase64("bXNjaAB4nD2MUQqAIBBEJy0s6qOLdJXuYNtCgikYBd2+LNmdj308hkGHtkId7M4YFns4mk/yfB4a48602eDI+mlNznu0FMPFd0wYKCaewl8F0EOueqM+yKSLVfJrNKWnSw/FZGzEGXFG9sy/px4gEBW1");
|
||||
basicBastion = Schematics.readBase64("bXNjaAF4nGNgZmBmZmDJS8xNZWBNzMsEUtwpqcXJRZkFJZn5eQyClfmlCin5Cnn5JQqpFZnFJVwMbDmJSak5xQxM0bGMDDzJ+UWpukmJxWDVDAyMIAQkACJxFp8=");
|
||||
basicAegis = Schematics.readBase64("bXNjaAF4nGNgYWBhZmDJS8xNZeDPyc/PVkhKzcjMS1GozC9l4E5JLU4uyiwoyczPY2BgYMtJTErNKWZgio5lZOBKzi9K1U1MTc8sBkoxghCQAAA85RNL");
|
||||
basicBastion = Schematics.readBase64("bXNjaAF4nGNgYWBhZmDJS8xNZWBNzMsEUtwpqcXJRZkFJZn5eQyClfmlCin5Cnn5JQqpFZnFJVwMbDmJSak5xQxM0bGMDDzJ+UWpukmJxWDVDAyMIAQkACMdFqE=");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class ErekirPlanetGenerator extends PlanetGenerator{
|
||||
|
||||
@Override
|
||||
public Schematic getDefaultLoadout(){
|
||||
return Loadouts.basicAegis;
|
||||
return Loadouts.basicBastion;
|
||||
}
|
||||
|
||||
float rawHeight(Vec3 position){
|
||||
|
||||
@@ -196,9 +196,11 @@ public class ForceProjector extends Block{
|
||||
|
||||
if(buildup > 0f){
|
||||
Draw.alpha(buildup / shieldHealth * 0.75f);
|
||||
Draw.z(Layer.blockAdditive);
|
||||
Draw.blend(Blending.additive);
|
||||
Draw.rect(topRegion, x, y);
|
||||
Draw.blend();
|
||||
Draw.z(Layer.block);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -52,9 +52,8 @@ public class LaserTurret extends PowerTurret{
|
||||
|
||||
if(bulletLife > 0 && bullet != null){
|
||||
wasShooting = true;
|
||||
tr.trns(rotation, shootLength, 0f);
|
||||
bullet.rotation(rotation);
|
||||
bullet.set(x + tr.x, y + tr.y);
|
||||
bullet.set(x + bulletOffset.x, y + bulletOffset.y);
|
||||
bullet.time(0f);
|
||||
heat = 1f;
|
||||
recoil = recoilAmount;
|
||||
@@ -106,7 +105,7 @@ public class LaserTurret extends PowerTurret{
|
||||
|
||||
@Override
|
||||
protected void bullet(BulletType type, float angle){
|
||||
bullet = type.create(this, team, x + tr.x, y + tr.y, angle);
|
||||
bullet = type.create(this, team, x + bulletOffset.x, y + bulletOffset.y, angle);
|
||||
bulletLife = shootDuration;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ public class LiquidTurret extends Turret{
|
||||
shootSound = Sounds.none;
|
||||
smokeEffect = Fx.none;
|
||||
shootEffect = Fx.none;
|
||||
outlinedIcon = 1;
|
||||
}
|
||||
|
||||
/** Initializes accepted ammo map. Format: [liquid1, bullet1, liquid2, bullet2...] */
|
||||
@@ -79,9 +78,9 @@ public class LiquidTurret extends Turret{
|
||||
super.draw();
|
||||
|
||||
if(liquidRegion.found()){
|
||||
Drawf.liquid(liquidRegion, x + tr2.x, y + tr2.y, liquids.total() / liquidCapacity, liquids.current().color, rotation - 90);
|
||||
Drawf.liquid(liquidRegion, x + recoilOffset.x, y + recoilOffset.y, liquids.total() / liquidCapacity, liquids.current().color, rotation - 90);
|
||||
}
|
||||
if(topRegion.found()) Draw.rect(topRegion, x + tr2.x, y + tr2.y, rotation - 90);
|
||||
if(topRegion.found()) Draw.rect(topRegion, x + recoilOffset.x, y + recoilOffset.y, rotation - 90);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -126,24 +125,6 @@ public class LiquidTurret extends Turret{
|
||||
super.findTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void effects(){
|
||||
BulletType type = peekAmmo();
|
||||
|
||||
Effect fshootEffect = shootEffect == Fx.none ? type.shootEffect : shootEffect;
|
||||
Effect fsmokeEffect = smokeEffect == Fx.none ? type.smokeEffect : smokeEffect;
|
||||
|
||||
fshootEffect.at(x + tr.x, y + tr.y, rotation, liquids.current().color);
|
||||
fsmokeEffect.at(x + tr.x, y + tr.y, rotation, liquids.current().color);
|
||||
shootSound.at(tile);
|
||||
|
||||
if(shootShake > 0){
|
||||
Effect.shake(shootShake, shootShake, tile.build);
|
||||
}
|
||||
|
||||
recoil = recoilAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BulletType useAmmo(){
|
||||
if(cheating()) return ammoTypes.get(liquids.current());
|
||||
|
||||
@@ -16,14 +16,15 @@ import mindustry.core.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.Units.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.logic.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.consumers.*;
|
||||
import mindustry.world.drawturret.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
@@ -78,29 +79,31 @@ public class Turret extends ReloadTurret{
|
||||
|
||||
public Sortf unitSort = UnitSorts.closest;
|
||||
|
||||
protected Vec2 tr = new Vec2();
|
||||
protected Vec2 tr2 = new Vec2();
|
||||
|
||||
public @Nullable String basePrefix;
|
||||
public @Load(value = "@-base", fallback = "block-@size") TextureRegion baseRegion;
|
||||
public @Load("@-heat") TextureRegion heatRegion;
|
||||
public float elevation = -1f;
|
||||
|
||||
public Cons<TurretBuild> drawer = tile -> Draw.rect(region, tile.x + tr2.x, tile.y + tr2.y, tile.rotation - 90);
|
||||
public Cons<TurretBuild> heatDrawer = tile -> {
|
||||
if(tile.heat <= 0.00001f) return;
|
||||
public DrawTurret draw = new DrawTurret();
|
||||
|
||||
Draw.color(heatColor, tile.heat);
|
||||
Draw.blend(Blending.additive);
|
||||
Draw.rect(heatRegion, tile.x + tr2.x, tile.y + tr2.y, tile.rotation - 90);
|
||||
Draw.blend();
|
||||
Draw.color();
|
||||
};
|
||||
/** @deprecated use bulletOffset; this will always be zero. **/
|
||||
@Deprecated
|
||||
protected Vec2 tr = new Vec2();
|
||||
/** @deprecated use recoilOffset; this will always be zero. **/
|
||||
@Deprecated
|
||||
protected Vec2 tr2 = new Vec2();
|
||||
/** @deprecated set the draw field instead, this does nothing */
|
||||
@Deprecated
|
||||
public Cons<TurretBuild> drawer = tile -> {};
|
||||
/** @deprecated set the draw field instead, this does nothing */
|
||||
@Deprecated
|
||||
public Cons<TurretBuild> heatDrawer = tile -> {};
|
||||
|
||||
public Turret(String name){
|
||||
super(name);
|
||||
liquidCapacity = 20f;
|
||||
quickRotate = false;
|
||||
outlinedIcon = 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -136,6 +139,8 @@ public class Turret extends ReloadTurret{
|
||||
public void load(){
|
||||
super.load();
|
||||
|
||||
draw.load(this);
|
||||
|
||||
if(basePrefix != null){
|
||||
baseRegion = Core.atlas.find(basePrefix + "-block-" + size);
|
||||
}
|
||||
@@ -143,7 +148,7 @@ public class Turret extends ReloadTurret{
|
||||
|
||||
@Override
|
||||
public TextureRegion[] icons(){
|
||||
return new TextureRegion[]{baseRegion, region};
|
||||
return draw.icons(this);
|
||||
}
|
||||
|
||||
public static abstract class AmmoEntry{
|
||||
@@ -153,6 +158,12 @@ public class Turret extends ReloadTurret{
|
||||
}
|
||||
|
||||
public class TurretBuild extends ReloadTurretBuild implements ControlBlock{
|
||||
//TODO storing these as instance variables is bad design, but it's probably too late to change everything
|
||||
/** Turret sprite offset, based on recoil. Updated every frame. */
|
||||
public Vec2 recoilOffset = new Vec2();
|
||||
/** Turret bullet position offset. Updated every frame. */
|
||||
public Vec2 bulletOffset = new Vec2();
|
||||
|
||||
public Seq<AmmoEntry> ammo = new Seq<>();
|
||||
public int totalAmmo;
|
||||
public float recoil, heat, logicControlTime = -1;
|
||||
@@ -252,14 +263,10 @@ public class Turret extends ReloadTurret{
|
||||
|
||||
Draw.z(Layer.turret);
|
||||
|
||||
tr2.trns(rotation, -recoil);
|
||||
Drawf.shadow(region, x + recoilOffset.x - elevation, y + recoilOffset.y - elevation, rotation - 90);
|
||||
|
||||
Drawf.shadow(region, x + tr2.x - elevation, y + tr2.y - elevation, rotation - 90);
|
||||
drawer.get(this);
|
||||
|
||||
if(heatRegion != Core.atlas.find("error")){
|
||||
heatDrawer.get(this);
|
||||
}
|
||||
draw.draw(Turret.this, this);
|
||||
draw.drawHeat(Turret.this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -274,6 +281,8 @@ public class Turret extends ReloadTurret{
|
||||
unit.tile(this);
|
||||
unit.rotation(rotation);
|
||||
unit.team(team);
|
||||
recoilOffset.trns(rotation, -recoil);
|
||||
bulletOffset.trns(rotation, shootLength);
|
||||
|
||||
if(logicControlTime > 0){
|
||||
logicControlTime -= Time.delta;
|
||||
@@ -400,15 +409,14 @@ public class Turret extends ReloadTurret{
|
||||
if(chargeTime > 0){
|
||||
useAmmo();
|
||||
|
||||
tr.trns(rotation, shootLength);
|
||||
chargeBeginEffect.at(x + tr.x, y + tr.y, rotation);
|
||||
chargeSound.at(x + tr.x, y + tr.y, 1);
|
||||
chargeBeginEffect.at(x + bulletOffset.x, y + bulletOffset.y, rotation);
|
||||
chargeSound.at(x + bulletOffset.x, y + bulletOffset.y, 1);
|
||||
|
||||
for(int i = 0; i < chargeEffects; i++){
|
||||
Time.run(Mathf.random(chargeMaxDelay), () -> {
|
||||
if(dead) return;
|
||||
tr.trns(rotation, shootLength);
|
||||
chargeEffect.at(x + tr.x, y + tr.y, rotation);
|
||||
bulletOffset.trns(rotation, shootLength);
|
||||
chargeEffect.at(x + bulletOffset.x, y + bulletOffset.y, rotation);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -416,7 +424,7 @@ public class Turret extends ReloadTurret{
|
||||
|
||||
Time.run(chargeTime, () -> {
|
||||
if(dead) return;
|
||||
tr.trns(rotation, shootLength);
|
||||
bulletOffset.trns(rotation, shootLength);
|
||||
recoil = recoilAmount;
|
||||
heat = 1f;
|
||||
bullet(type, rotation + Mathf.range(inaccuracy + type.inaccuracy));
|
||||
@@ -430,7 +438,7 @@ public class Turret extends ReloadTurret{
|
||||
int ii = i;
|
||||
Time.run(burstSpacing * i, () -> {
|
||||
if(dead || !hasAmmo()) return;
|
||||
tr.trns(rotation, shootLength, Mathf.range(xRand));
|
||||
bulletOffset.trns(rotation, shootLength, Mathf.range(xRand));
|
||||
bullet(type, rotation + Mathf.range(inaccuracy + type.inaccuracy) + (ii - (int)(shots / 2f)) * spread);
|
||||
effects();
|
||||
useAmmo();
|
||||
@@ -445,10 +453,10 @@ public class Turret extends ReloadTurret{
|
||||
if(alternate){
|
||||
float i = (shotCounter % shots) - (shots-1)/2f;
|
||||
|
||||
tr.trns(rotation - 90, spread * i + Mathf.range(xRand), shootLength);
|
||||
bulletOffset.trns(rotation - 90, spread * i + Mathf.range(xRand), shootLength);
|
||||
bullet(type, rotation + Mathf.range(inaccuracy + type.inaccuracy));
|
||||
}else{
|
||||
tr.trns(rotation, shootLength, Mathf.range(xRand));
|
||||
bulletOffset.trns(rotation, shootLength, Mathf.range(xRand));
|
||||
|
||||
for(int i = 0; i < shots; i++){
|
||||
bullet(type, rotation + Mathf.range(inaccuracy + type.inaccuracy) + (i - (int)(shots / 2f)) * spread);
|
||||
@@ -465,18 +473,18 @@ public class Turret extends ReloadTurret{
|
||||
}
|
||||
|
||||
protected void bullet(BulletType type, float angle){
|
||||
float lifeScl = type.scaleVelocity ? Mathf.clamp(Mathf.dst(x + tr.x, y + tr.y, targetPos.x, targetPos.y) / type.range(), minRange / type.range(), range / type.range()) : 1f;
|
||||
float lifeScl = type.scaleVelocity ? Mathf.clamp(Mathf.dst(x + bulletOffset.x, y + bulletOffset.y, targetPos.x, targetPos.y) / type.range(), minRange / type.range(), range / type.range()) : 1f;
|
||||
|
||||
type.create(this, team, x + tr.x, y + tr.y, angle, 1f + Mathf.range(velocityInaccuracy), lifeScl);
|
||||
type.create(this, team, x + bulletOffset.x, y + bulletOffset.y, angle, 1f + Mathf.range(velocityInaccuracy), lifeScl);
|
||||
}
|
||||
|
||||
protected void effects(){
|
||||
Effect fshootEffect = shootEffect == Fx.none ? peekAmmo().shootEffect : shootEffect;
|
||||
Effect fsmokeEffect = smokeEffect == Fx.none ? peekAmmo().smokeEffect : smokeEffect;
|
||||
|
||||
fshootEffect.at(x + tr.x, y + tr.y, rotation);
|
||||
fsmokeEffect.at(x + tr.x, y + tr.y, rotation);
|
||||
shootSound.at(x + tr.x, y + tr.y, Mathf.random(0.9f, 1.1f));
|
||||
fshootEffect.at(x + bulletOffset.x, y + bulletOffset.y, rotation);
|
||||
fsmokeEffect.at(x + bulletOffset.x, y + bulletOffset.y, rotation);
|
||||
shootSound.at(x + bulletOffset.x, y + bulletOffset.y, Mathf.random(0.9f, 1.1f));
|
||||
|
||||
if(shootShake > 0){
|
||||
Effect.shake(shootShake, shootShake, this);
|
||||
|
||||
@@ -5,7 +5,7 @@ import arc.math.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.production.GenericCrafter.*;
|
||||
|
||||
/** An implementation of custom rendering behavior for a block.
|
||||
/** An implementation of custom rendering behavior for a crafter block.
|
||||
* This is used mostly for mods. */
|
||||
public class DrawBlock{
|
||||
protected static final Rand rand = new Rand();
|
||||
|
||||
37
core/src/mindustry/world/drawturret/DrawTurret.java
Normal file
37
core/src/mindustry/world/drawturret/DrawTurret.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package mindustry.world.drawturret;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import mindustry.world.blocks.defense.turrets.*;
|
||||
import mindustry.world.blocks.defense.turrets.Turret.*;
|
||||
|
||||
/** Extend to implement custom drawing behavior for a turret. */
|
||||
public class DrawTurret{
|
||||
protected static final Rand rand = new Rand();
|
||||
|
||||
/** Draws the block. */
|
||||
public void draw(Turret block, TurretBuild build){
|
||||
Draw.rect(block.region, build.x + build.recoilOffset.x, build.y + build.recoilOffset.y, build.rotation - 90);
|
||||
}
|
||||
|
||||
public void drawHeat(Turret block, TurretBuild build){
|
||||
if(build.heat <= 0.00001f || !block.heatRegion.found()) return;
|
||||
|
||||
Draw.color(block.heatColor, build.heat);
|
||||
Draw.blend(Blending.additive);
|
||||
Draw.rect(block.heatRegion, build.x + build.recoilOffset.x, build.y + build.recoilOffset.y, build.rotation - 90);
|
||||
Draw.blend();
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
/** Load any relevant texture regions. */
|
||||
public void load(Turret block){
|
||||
|
||||
}
|
||||
|
||||
/** @return the generated icons to be used for this block. */
|
||||
public TextureRegion[] icons(Turret block){
|
||||
return new TextureRegion[]{block.baseRegion, block.region};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user