Core cleanup / Turret draw class

This commit is contained in:
Anuken
2021-11-12 20:09:27 -05:00
parent 757977b7b9
commit 2f0daa6fc4
19 changed files with 92 additions and 80 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 864 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 862 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 514 B

After

Width:  |  Height:  |  Size: 864 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 512 B

After

Width:  |  Height:  |  Size: 862 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -407,7 +407,6 @@
63301=neoplasm|liquid-neoplasm-ui 63301=neoplasm|liquid-neoplasm-ui
63300=scuttler|unit-scuttler-ui 63300=scuttler|unit-scuttler-ui
63299=breach|block-breach-ui 63299=breach|block-breach-ui
63298=core-bastion|block-core-bastion-ui
63297=plasma-bore|block-plasma-bore-ui 63297=plasma-bore|block-plasma-bore-ui
63296=steam-vent|block-steam-vent-ui 63296=steam-vent|block-steam-vent-ui
63295=pressure-turbine|block-pressure-turbine-ui 63295=pressure-turbine|block-pressure-turbine-ui
@@ -432,7 +431,7 @@
63276=einforced-liquid-tank|block-einforced-liquid-tank-ui 63276=einforced-liquid-tank|block-einforced-liquid-tank-ui
63275=reinforced-liquid-tank|block-reinforced-liquid-tank-ui 63275=reinforced-liquid-tank|block-reinforced-liquid-tank-ui
63274=reinforced-bridge-conduit|block-reinforced-bridge-conduit-ui 63274=reinforced-bridge-conduit|block-reinforced-bridge-conduit-ui
63273=core-aegis|block-core-aegis-ui
63272=core-citadel|block-core-citadel-ui 63272=core-citadel|block-core-citadel-ui
63271=core-acropolis|block-core-acropolis-ui 63271=core-acropolis|block-core-acropolis-ui
63270=heat-reactor|block-heat-reactor-ui 63270=heat-reactor|block-heat-reactor-ui
63269=core-bastion|block-core-bastion-ui

Binary file not shown.

View File

@@ -96,7 +96,7 @@ public class Blocks implements ContentList{
//storage //storage
coreShard, coreFoundation, coreNucleus, vault, container, unloader, coreShard, coreFoundation, coreNucleus, vault, container, unloader,
//storage - erekir //storage - erekir
coreBastion, coreAegis, coreCitadel, coreAcropolis, coreBastion, coreCitadel, coreAcropolis,
//turrets //turrets
duo, scatter, scorch, hail, arc, wave, lancer, swarmer, salvo, fuse, ripple, cyclone, foreshadow, spectre, meltdown, segment, parallax, tsunami, 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; researchCostMultiplier = 0.11f;
}}; }};
//TODO remove - too small
coreBastion = new CoreBlock("core-bastion"){{ 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 //TODO cost
requirements(Category.effect, BuildVisibility.editorOnly, with(Items.beryllium, 2000, Items.graphite, 2000, Items.tungsten, 1000)); requirements(Category.effect, BuildVisibility.editorOnly, with(Items.beryllium, 2000, Items.graphite, 2000, Items.tungsten, 1000));

View File

@@ -8,15 +8,13 @@ public class Loadouts implements ContentList{
basicShard, basicShard,
basicFoundation, basicFoundation,
basicNucleus, basicNucleus,
basicBastion, basicBastion;
basicAegis;
@Override @Override
public void load(){ public void load(){
basicShard = Schematics.readBase64("bXNjaAB4nD2K2wqAIBiD5ymibnoRn6YnEP1BwUMoBL19FuJ2sbFvUFgYZDaJsLeQrkinN9UJHImsNzlYE7WrIUastuSbnlKx2VJJt+8IQGGKdfO/8J5yrGJSMegLg+YUIA=="); basicShard = Schematics.readBase64("bXNjaAB4nD2K2wqAIBiD5ymibnoRn6YnEP1BwUMoBL19FuJ2sbFvUFgYZDaJsLeQrkinN9UJHImsNzlYE7WrIUastuSbnlKx2VJJt+8IQGGKdfO/8J5yrGJSMegLg+YUIA==");
basicFoundation = Schematics.readBase64("bXNjaAB4nD1OSQ6DMBBzFhVu8BG+0X8MQyoiJTNSukj8nlCi2Adbtg/GA4OBF8oB00rvyE/9ykafqOIw58A7SWRKy1ZiShhZ5RcOLZhYS1hefQ1gRIeptH9jq/qW2lvc1d2tgWsOfVX/tOwE86AYBA=="); basicFoundation = Schematics.readBase64("bXNjaAB4nD1OSQ6DMBBzFhVu8BG+0X8MQyoiJTNSukj8nlCi2Adbtg/GA4OBF8oB00rvyE/9ykafqOIw58A7SWRKy1ZiShhZ5RcOLZhYS1hefQ1gRIeptH9jq/qW2lvc1d2tgWsOfVX/tOwE86AYBA==");
basicNucleus = Schematics.readBase64("bXNjaAB4nD2MUQqAIBBEJy0s6qOLdJXuYNtCgikYBd2+LNmdj308hkGHtkId7M4YFns4mk/yfB4a48602eDI+mlNznu0FMPFd0wYKCaewl8F0EOueqM+yKSLVfJrNKWnSw/FZGzEGXFG9sy/px4gEBW1"); basicNucleus = Schematics.readBase64("bXNjaAB4nD2MUQqAIBBEJy0s6qOLdJXuYNtCgikYBd2+LNmdj308hkGHtkId7M4YFns4mk/yfB4a48602eDI+mlNznu0FMPFd0wYKCaewl8F0EOueqM+yKSLVfJrNKWnSw/FZGzEGXFG9sy/px4gEBW1");
basicBastion = Schematics.readBase64("bXNjaAF4nGNgZmBmZmDJS8xNZWBNzMsEUtwpqcXJRZkFJZn5eQyClfmlCin5Cnn5JQqpFZnFJVwMbDmJSak5xQxM0bGMDDzJ+UWpukmJxWDVDAyMIAQkACJxFp8="); basicBastion = Schematics.readBase64("bXNjaAF4nGNgYWBhZmDJS8xNZWBNzMsEUtwpqcXJRZkFJZn5eQyClfmlCin5Cnn5JQqpFZnFJVwMbDmJSak5xQxM0bGMDDzJ+UWpukmJxWDVDAyMIAQkACMdFqE=");
basicAegis = Schematics.readBase64("bXNjaAF4nGNgYWBhZmDJS8xNZeDPyc/PVkhKzcjMS1GozC9l4E5JLU4uyiwoyczPY2BgYMtJTErNKWZgio5lZOBKzi9K1U1MTc8sBkoxghCQAAA85RNL");
} }
} }

View File

@@ -49,7 +49,7 @@ public class ErekirPlanetGenerator extends PlanetGenerator{
@Override @Override
public Schematic getDefaultLoadout(){ public Schematic getDefaultLoadout(){
return Loadouts.basicAegis; return Loadouts.basicBastion;
} }
float rawHeight(Vec3 position){ float rawHeight(Vec3 position){

View File

@@ -196,9 +196,11 @@ public class ForceProjector extends Block{
if(buildup > 0f){ if(buildup > 0f){
Draw.alpha(buildup / shieldHealth * 0.75f); Draw.alpha(buildup / shieldHealth * 0.75f);
Draw.z(Layer.blockAdditive);
Draw.blend(Blending.additive); Draw.blend(Blending.additive);
Draw.rect(topRegion, x, y); Draw.rect(topRegion, x, y);
Draw.blend(); Draw.blend();
Draw.z(Layer.block);
Draw.reset(); Draw.reset();
} }

View File

@@ -52,9 +52,8 @@ public class LaserTurret extends PowerTurret{
if(bulletLife > 0 && bullet != null){ if(bulletLife > 0 && bullet != null){
wasShooting = true; wasShooting = true;
tr.trns(rotation, shootLength, 0f);
bullet.rotation(rotation); bullet.rotation(rotation);
bullet.set(x + tr.x, y + tr.y); bullet.set(x + bulletOffset.x, y + bulletOffset.y);
bullet.time(0f); bullet.time(0f);
heat = 1f; heat = 1f;
recoil = recoilAmount; recoil = recoilAmount;
@@ -106,7 +105,7 @@ public class LaserTurret extends PowerTurret{
@Override @Override
protected void bullet(BulletType type, float angle){ 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; bulletLife = shootDuration;
} }

View File

@@ -30,7 +30,6 @@ public class LiquidTurret extends Turret{
shootSound = Sounds.none; shootSound = Sounds.none;
smokeEffect = Fx.none; smokeEffect = Fx.none;
shootEffect = Fx.none; shootEffect = Fx.none;
outlinedIcon = 1;
} }
/** Initializes accepted ammo map. Format: [liquid1, bullet1, liquid2, bullet2...] */ /** Initializes accepted ammo map. Format: [liquid1, bullet1, liquid2, bullet2...] */
@@ -79,9 +78,9 @@ public class LiquidTurret extends Turret{
super.draw(); super.draw();
if(liquidRegion.found()){ 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 @Override
@@ -126,24 +125,6 @@ public class LiquidTurret extends Turret{
super.findTarget(); 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 @Override
public BulletType useAmmo(){ public BulletType useAmmo(){
if(cheating()) return ammoTypes.get(liquids.current()); if(cheating()) return ammoTypes.get(liquids.current());

View File

@@ -16,14 +16,15 @@ import mindustry.core.*;
import mindustry.entities.*; import mindustry.entities.*;
import mindustry.entities.Units.*; import mindustry.entities.Units.*;
import mindustry.entities.bullet.*; import mindustry.entities.bullet.*;
import mindustry.game.*;
import mindustry.game.EventType.*; import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.logic.*; import mindustry.logic.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.blocks.*; import mindustry.world.blocks.*;
import mindustry.world.consumers.*; import mindustry.world.consumers.*;
import mindustry.world.drawturret.*;
import mindustry.world.meta.*; import mindustry.world.meta.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
@@ -78,29 +79,31 @@ public class Turret extends ReloadTurret{
public Sortf unitSort = UnitSorts.closest; public Sortf unitSort = UnitSorts.closest;
protected Vec2 tr = new Vec2();
protected Vec2 tr2 = new Vec2();
public @Nullable String basePrefix; public @Nullable String basePrefix;
public @Load(value = "@-base", fallback = "block-@size") TextureRegion baseRegion; public @Load(value = "@-base", fallback = "block-@size") TextureRegion baseRegion;
public @Load("@-heat") TextureRegion heatRegion; public @Load("@-heat") TextureRegion heatRegion;
public float elevation = -1f; public float elevation = -1f;
public Cons<TurretBuild> drawer = tile -> Draw.rect(region, tile.x + tr2.x, tile.y + tr2.y, tile.rotation - 90); public DrawTurret draw = new DrawTurret();
public Cons<TurretBuild> heatDrawer = tile -> {
if(tile.heat <= 0.00001f) return;
Draw.color(heatColor, tile.heat); /** @deprecated use bulletOffset; this will always be zero. **/
Draw.blend(Blending.additive); @Deprecated
Draw.rect(heatRegion, tile.x + tr2.x, tile.y + tr2.y, tile.rotation - 90); protected Vec2 tr = new Vec2();
Draw.blend(); /** @deprecated use recoilOffset; this will always be zero. **/
Draw.color(); @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){ public Turret(String name){
super(name); super(name);
liquidCapacity = 20f; liquidCapacity = 20f;
quickRotate = false; quickRotate = false;
outlinedIcon = 1;
} }
@Override @Override
@@ -136,6 +139,8 @@ public class Turret extends ReloadTurret{
public void load(){ public void load(){
super.load(); super.load();
draw.load(this);
if(basePrefix != null){ if(basePrefix != null){
baseRegion = Core.atlas.find(basePrefix + "-block-" + size); baseRegion = Core.atlas.find(basePrefix + "-block-" + size);
} }
@@ -143,7 +148,7 @@ public class Turret extends ReloadTurret{
@Override @Override
public TextureRegion[] icons(){ public TextureRegion[] icons(){
return new TextureRegion[]{baseRegion, region}; return draw.icons(this);
} }
public static abstract class AmmoEntry{ public static abstract class AmmoEntry{
@@ -153,6 +158,12 @@ public class Turret extends ReloadTurret{
} }
public class TurretBuild extends ReloadTurretBuild implements ControlBlock{ 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 Seq<AmmoEntry> ammo = new Seq<>();
public int totalAmmo; public int totalAmmo;
public float recoil, heat, logicControlTime = -1; public float recoil, heat, logicControlTime = -1;
@@ -252,14 +263,10 @@ public class Turret extends ReloadTurret{
Draw.z(Layer.turret); 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); draw.draw(Turret.this, this);
drawer.get(this); draw.drawHeat(Turret.this, this);
if(heatRegion != Core.atlas.find("error")){
heatDrawer.get(this);
}
} }
@Override @Override
@@ -274,6 +281,8 @@ public class Turret extends ReloadTurret{
unit.tile(this); unit.tile(this);
unit.rotation(rotation); unit.rotation(rotation);
unit.team(team); unit.team(team);
recoilOffset.trns(rotation, -recoil);
bulletOffset.trns(rotation, shootLength);
if(logicControlTime > 0){ if(logicControlTime > 0){
logicControlTime -= Time.delta; logicControlTime -= Time.delta;
@@ -400,15 +409,14 @@ public class Turret extends ReloadTurret{
if(chargeTime > 0){ if(chargeTime > 0){
useAmmo(); useAmmo();
tr.trns(rotation, shootLength); chargeBeginEffect.at(x + bulletOffset.x, y + bulletOffset.y, rotation);
chargeBeginEffect.at(x + tr.x, y + tr.y, rotation); chargeSound.at(x + bulletOffset.x, y + bulletOffset.y, 1);
chargeSound.at(x + tr.x, y + tr.y, 1);
for(int i = 0; i < chargeEffects; i++){ for(int i = 0; i < chargeEffects; i++){
Time.run(Mathf.random(chargeMaxDelay), () -> { Time.run(Mathf.random(chargeMaxDelay), () -> {
if(dead) return; if(dead) return;
tr.trns(rotation, shootLength); bulletOffset.trns(rotation, shootLength);
chargeEffect.at(x + tr.x, y + tr.y, rotation); chargeEffect.at(x + bulletOffset.x, y + bulletOffset.y, rotation);
}); });
} }
@@ -416,7 +424,7 @@ public class Turret extends ReloadTurret{
Time.run(chargeTime, () -> { Time.run(chargeTime, () -> {
if(dead) return; if(dead) return;
tr.trns(rotation, shootLength); bulletOffset.trns(rotation, shootLength);
recoil = recoilAmount; recoil = recoilAmount;
heat = 1f; heat = 1f;
bullet(type, rotation + Mathf.range(inaccuracy + type.inaccuracy)); bullet(type, rotation + Mathf.range(inaccuracy + type.inaccuracy));
@@ -430,7 +438,7 @@ public class Turret extends ReloadTurret{
int ii = i; int ii = i;
Time.run(burstSpacing * i, () -> { Time.run(burstSpacing * i, () -> {
if(dead || !hasAmmo()) return; 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); bullet(type, rotation + Mathf.range(inaccuracy + type.inaccuracy) + (ii - (int)(shots / 2f)) * spread);
effects(); effects();
useAmmo(); useAmmo();
@@ -445,10 +453,10 @@ public class Turret extends ReloadTurret{
if(alternate){ if(alternate){
float i = (shotCounter % shots) - (shots-1)/2f; 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)); bullet(type, rotation + Mathf.range(inaccuracy + type.inaccuracy));
}else{ }else{
tr.trns(rotation, shootLength, Mathf.range(xRand)); bulletOffset.trns(rotation, shootLength, Mathf.range(xRand));
for(int i = 0; i < shots; i++){ for(int i = 0; i < shots; i++){
bullet(type, rotation + Mathf.range(inaccuracy + type.inaccuracy) + (i - (int)(shots / 2f)) * spread); 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){ 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(){ protected void effects(){
Effect fshootEffect = shootEffect == Fx.none ? peekAmmo().shootEffect : shootEffect; Effect fshootEffect = shootEffect == Fx.none ? peekAmmo().shootEffect : shootEffect;
Effect fsmokeEffect = smokeEffect == Fx.none ? peekAmmo().smokeEffect : smokeEffect; Effect fsmokeEffect = smokeEffect == Fx.none ? peekAmmo().smokeEffect : smokeEffect;
fshootEffect.at(x + tr.x, y + tr.y, rotation); fshootEffect.at(x + bulletOffset.x, y + bulletOffset.y, rotation);
fsmokeEffect.at(x + tr.x, y + tr.y, rotation); fsmokeEffect.at(x + bulletOffset.x, y + bulletOffset.y, rotation);
shootSound.at(x + tr.x, y + tr.y, Mathf.random(0.9f, 1.1f)); shootSound.at(x + bulletOffset.x, y + bulletOffset.y, Mathf.random(0.9f, 1.1f));
if(shootShake > 0){ if(shootShake > 0){
Effect.shake(shootShake, shootShake, this); Effect.shake(shootShake, shootShake, this);

View File

@@ -5,7 +5,7 @@ import arc.math.*;
import mindustry.world.*; import mindustry.world.*;
import mindustry.world.blocks.production.GenericCrafter.*; 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. */ * This is used mostly for mods. */
public class DrawBlock{ public class DrawBlock{
protected static final Rand rand = new Rand(); protected static final Rand rand = new Rand();

View 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};
}
}