Removed AmmoType class completely

This commit is contained in:
Anuken
2019-01-07 16:01:27 -05:00
parent de02061b5e
commit 5743d30851
29 changed files with 480 additions and 811 deletions
@@ -1,254 +0,0 @@
package io.anuke.mindustry.content;
import io.anuke.mindustry.content.bullets.*;
import io.anuke.mindustry.content.fx.BulletFx;
import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.content.fx.ShootFx;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.type.ContentType;
public class AmmoTypes implements ContentList{
public static AmmoType
bulletCopper, bulletDense, bulletThorium, bulletSilicon, bulletPyratite,
bulletDenseBig, bulletPyratiteBig, bulletThoriumBig,
shock, bombExplosive, bombIncendiary, bombOil, shellCarbide, flamerThermite, weaponMissile, weaponMissileSwarm, bulletMech,
healBlaster, bulletGlaive,
flakExplosive, flakPlastic, flakSurge,
missileExplosive, missileIncindiary, missileSurge,
artilleryDense, artilleryPlastic, artilleryHoming, artilleryIncindiary, artilleryExplosive, unitArtillery,
basicFlame, lancerLaser, lightning, meltdownLaser, burstLaser,
fuseShotgun, oil, water, lava, cryofluid, arc;
@Override
public void load(){
//weapon specific
bulletMech = new AmmoType(StandardBullets.mechSmall){{
shootEffect = ShootFx.shootSmall;
smokeEffect = ShootFx.shootSmallSmoke;
reloadMultiplier = 1f;
inaccuracy = 5f;
}};
bulletGlaive = new AmmoType(Items.pyratite, StandardBullets.glaive, 3){{
shootEffect = ShootFx.shootSmall;
smokeEffect = ShootFx.shootSmallSmoke;
inaccuracy = 3f;
}};
healBlaster = new AmmoType(TurretBullets.healBullet){{
shootEffect = ShootFx.shootHeal;
smokeEffect = BulletFx.hitLaser;
reloadMultiplier = 1f;
inaccuracy = 2f;
}};
shock = new AmmoType(TurretBullets.lightning){{
shootEffect = BulletFx.hitLancer;
smokeEffect = Fx.none;
}};
shellCarbide = new AmmoType(WeaponBullets.shellCarbide){{
shootEffect = ShootFx.shootBig;
smokeEffect = ShootFx.shootBigSmoke;
}};
bombExplosive = new AmmoType(WeaponBullets.bombExplosive){{
shootEffect = Fx.none;
smokeEffect = Fx.none;
}};
bombIncendiary = new AmmoType(WeaponBullets.bombIncendiary){{
shootEffect = Fx.none;
smokeEffect = Fx.none;
}};
bombOil = new AmmoType(WeaponBullets.bombOil){{
shootEffect = Fx.none;
smokeEffect = Fx.none;
}};
flamerThermite = new AmmoType(TurretBullets.basicFlame){{
shootEffect = ShootFx.shootSmallFlame;
}};
weaponMissile = new AmmoType(MissileBullets.javelin){{
shootEffect = BulletFx.hitBulletSmall;
smokeEffect = Fx.none;
reloadMultiplier = 1.2f;
}};
weaponMissileSwarm = new AmmoType(MissileBullets.swarm){{
shootEffect = BulletFx.hitBulletSmall;
smokeEffect = ShootFx.shootSmallSmoke;
reloadMultiplier = 1.2f;
}};
//bullets
bulletCopper = new AmmoType(Items.copper, StandardBullets.copper, 5){{
shootEffect = ShootFx.shootSmall;
smokeEffect = ShootFx.shootSmallSmoke;
reloadMultiplier = 1f;
inaccuracy = 5f;
}};
bulletDense = new AmmoType(Items.densealloy, StandardBullets.dense, 2){{
shootEffect = ShootFx.shootSmall;
smokeEffect = ShootFx.shootSmallSmoke;
reloadMultiplier = 0.6f;
}};
bulletThorium = new AmmoType(Items.thorium, StandardBullets.thorium, 2){{
shootEffect = ShootFx.shootBig;
smokeEffect = ShootFx.shootBigSmoke;
}};
bulletSilicon = new AmmoType(Items.silicon, StandardBullets.homing, 5){{
shootEffect = ShootFx.shootSmall;
smokeEffect = ShootFx.shootSmallSmoke;
reloadMultiplier = 1.4f;
}};
bulletPyratite = new AmmoType(Items.pyratite, StandardBullets.tracer, 3){{
shootEffect = ShootFx.shootSmall;
smokeEffect = ShootFx.shootSmallSmoke;
inaccuracy = 3f;
}};
bulletDenseBig = new AmmoType(Items.densealloy, StandardBullets.denseBig, 1){{
shootEffect = ShootFx.shootBig;
smokeEffect = ShootFx.shootBigSmoke;
}};
bulletThoriumBig = new AmmoType(Items.thorium, StandardBullets.thoriumBig, 1){{
shootEffect = ShootFx.shootBig;
smokeEffect = ShootFx.shootBigSmoke;
}};
bulletPyratiteBig = new AmmoType(Items.pyratite, StandardBullets.tracerBig, 2){{
shootEffect = ShootFx.shootBig;
smokeEffect = ShootFx.shootBigSmoke;
inaccuracy = 3f;
}};
//flak
flakExplosive = new AmmoType(Items.blastCompound, FlakBullets.explosive, 5){{
shootEffect = ShootFx.shootBig;
smokeEffect = ShootFx.shootBigSmoke;
}};
flakPlastic = new AmmoType(Items.plastanium, FlakBullets.plastic, 5){{
shootEffect = ShootFx.shootBig;
smokeEffect = ShootFx.shootBigSmoke;
}};
flakSurge = new AmmoType(Items.surgealloy, FlakBullets.surge, 5){{
shootEffect = ShootFx.shootBig;
smokeEffect = ShootFx.shootBigSmoke;
reloadMultiplier = 1/2f;
}};
//missiles
missileExplosive = new AmmoType(Items.blastCompound, MissileBullets.explosive, 1){{
shootEffect = ShootFx.shootBig2;
smokeEffect = ShootFx.shootBigSmoke2;
reloadMultiplier = 1.2f;
}};
missileIncindiary = new AmmoType(Items.pyratite, MissileBullets.incindiary, 1){{
shootEffect = ShootFx.shootBig2;
smokeEffect = ShootFx.shootBigSmoke2;
reloadMultiplier = 1.0f;
}};
missileSurge = new AmmoType(Items.surgealloy, MissileBullets.surge, 1){{
shootEffect = ShootFx.shootBig2;
smokeEffect = ShootFx.shootBigSmoke2;
reloadMultiplier = 1.1f;
}};
//artillery
artilleryDense = new AmmoType(Items.densealloy, ArtilleryBullets.dense, 2){{
shootEffect = ShootFx.shootBig2;
smokeEffect = ShootFx.shootBigSmoke2;
}};
artilleryPlastic = new AmmoType(Items.plastanium, ArtilleryBullets.plastic, 2){{
shootEffect = ShootFx.shootBig2;
smokeEffect = ShootFx.shootBigSmoke2;
reloadMultiplier = 1.4f;
}};
artilleryHoming = new AmmoType(Items.silicon, ArtilleryBullets.homing, 1){{
shootEffect = ShootFx.shootBig2;
smokeEffect = ShootFx.shootBigSmoke2;
reloadMultiplier = 0.9f;
}};
artilleryIncindiary = new AmmoType(Items.pyratite, ArtilleryBullets.incindiary, 2){{
shootEffect = ShootFx.shootBig2;
smokeEffect = ShootFx.shootBigSmoke2;
reloadMultiplier = 1.2f;
}};
artilleryExplosive = new AmmoType(Items.blastCompound, ArtilleryBullets.explosive, 1){{
shootEffect = ShootFx.shootBig2;
smokeEffect = ShootFx.shootBigSmoke2;
reloadMultiplier = 1.6f;
}};
unitArtillery = new AmmoType(Items.blastCompound, ArtilleryBullets.unit, 1){{
shootEffect = ShootFx.shootBig2;
smokeEffect = ShootFx.shootBigSmoke2;
reloadMultiplier = 1.6f;
}};
//flame
basicFlame = new AmmoType(Liquids.oil, TurretBullets.basicFlame, 0.3f){{
shootEffect = ShootFx.shootSmallFlame;
}};
//power
lancerLaser = new AmmoType(TurretBullets.lancerLaser);
burstLaser = new AmmoType(TurretBullets.burstLaser){{
range = 60f;
}};
lightning = new AmmoType(TurretBullets.lightning);
arc = new AmmoType(TurretBullets.arc);
meltdownLaser = new AmmoType(TurretBullets.meltdownLaser);
fuseShotgun = new AmmoType(Items.densealloy, TurretBullets.fuseShot, 1f){{
shootEffect = Fx.none;
smokeEffect = ShootFx.shootBigSmoke2;
}};
//liquid
oil = new AmmoType(Liquids.oil, TurretBullets.oilShot, 0.3f);
water = new AmmoType(Liquids.water, TurretBullets.waterShot, 0.3f);
lava = new AmmoType(Liquids.lava, TurretBullets.lavaShot, 0.3f);
cryofluid = new AmmoType(Liquids.cryofluid, TurretBullets.cryoShot, 0.3f);
}
@Override
public ContentType type(){
return ContentType.ammo;
}
}
@@ -0,0 +1,17 @@
package io.anuke.mindustry.content;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.type.ContentType;
public class Bullets implements ContentList{
@Override
public void load(){
}
@Override
public ContentType type(){
return ContentType.bullet;
}
}
@@ -1,5 +1,6 @@
package io.anuke.mindustry.content; package io.anuke.mindustry.content;
import io.anuke.mindustry.content.bullets.*;
import io.anuke.mindustry.content.fx.Fx; import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.content.fx.ShootFx; import io.anuke.mindustry.content.fx.ShootFx;
import io.anuke.mindustry.game.ContentList; import io.anuke.mindustry.game.ContentList;
@@ -8,7 +9,7 @@ import io.anuke.mindustry.type.Weapon;
public class Weapons implements ContentList{ public class Weapons implements ContentList{
public static Weapon blaster, blasterSmall, glaiveBlaster, droneBlaster, healBlaster, healBlasterDrone, chainBlaster, shockgun, public static Weapon blaster, blasterSmall, glaiveBlaster, droneBlaster, healBlaster, healBlasterDrone, chainBlaster, shockgun,
sapper, swarmer, bomber, bomberTrident, flakgun, flamethrower, missiles, artillery, laserBurster, healBlasterDrone2; swarmer, bomber, bomberTrident, flakgun, flamethrower, missiles, artillery, laserBurster, healBlasterDrone2;
@Override @Override
public void load(){ public void load(){
@@ -18,7 +19,7 @@ public class Weapons implements ContentList{
reload = 14f; reload = 14f;
roundrobin = true; roundrobin = true;
ejectEffect = ShootFx.shellEjectSmall; ejectEffect = ShootFx.shellEjectSmall;
ammo = AmmoTypes.bulletMech; ammo = StandardBullets.mechSmall;
}}; }};
blasterSmall = new Weapon("blaster"){{ blasterSmall = new Weapon("blaster"){{
@@ -26,7 +27,7 @@ public class Weapons implements ContentList{
reload = 15f; reload = 15f;
roundrobin = true; roundrobin = true;
ejectEffect = ShootFx.shellEjectSmall; ejectEffect = ShootFx.shellEjectSmall;
ammo = AmmoTypes.bulletCopper; ammo = StandardBullets.copper;
}}; }};
glaiveBlaster = new Weapon("bomber"){{ glaiveBlaster = new Weapon("bomber"){{
@@ -34,7 +35,7 @@ public class Weapons implements ContentList{
reload = 10f; reload = 10f;
roundrobin = true; roundrobin = true;
ejectEffect = ShootFx.shellEjectSmall; ejectEffect = ShootFx.shellEjectSmall;
ammo = AmmoTypes.bulletGlaive; ammo = StandardBullets.glaive;
}}; }};
droneBlaster = new Weapon("blaster"){{ droneBlaster = new Weapon("blaster"){{
@@ -43,7 +44,7 @@ public class Weapons implements ContentList{
width = 1f; width = 1f;
roundrobin = true; roundrobin = true;
ejectEffect = ShootFx.shellEjectSmall; ejectEffect = ShootFx.shellEjectSmall;
ammo = AmmoTypes.bulletCopper; ammo = StandardBullets.copper;
}}; }};
healBlaster = new Weapon("heal-blaster"){{ healBlaster = new Weapon("heal-blaster"){{
@@ -52,7 +53,7 @@ public class Weapons implements ContentList{
roundrobin = false; roundrobin = false;
ejectEffect = Fx.none; ejectEffect = Fx.none;
recoil = 2f; recoil = 2f;
ammo = AmmoTypes.healBlaster; ammo = TurretBullets.healBullet;
}}; }};
missiles = new Weapon("missiles"){{ missiles = new Weapon("missiles"){{
@@ -64,7 +65,7 @@ public class Weapons implements ContentList{
ejectEffect = Fx.none; ejectEffect = Fx.none;
velocityRnd = 0.2f; velocityRnd = 0.2f;
spacing = 1f; spacing = 1f;
ammo = AmmoTypes.weaponMissile; ammo = MissileBullets.javelin;
}}; }};
swarmer = new Weapon("swarmer"){{ swarmer = new Weapon("swarmer"){{
@@ -77,7 +78,7 @@ public class Weapons implements ContentList{
roundrobin = true; roundrobin = true;
ejectEffect = Fx.none; ejectEffect = Fx.none;
shake = 3f; shake = 3f;
ammo = AmmoTypes.weaponMissileSwarm; ammo = MissileBullets.swarm;
}}; }};
chainBlaster = new Weapon("chain-blaster"){{ chainBlaster = new Weapon("chain-blaster"){{
@@ -85,7 +86,7 @@ public class Weapons implements ContentList{
reload = 28f; reload = 28f;
roundrobin = true; roundrobin = true;
ejectEffect = ShootFx.shellEjectSmall; ejectEffect = ShootFx.shellEjectSmall;
ammo = AmmoTypes.bulletCopper; ammo = StandardBullets.copper;
}}; }};
shockgun = new Weapon("shockgun"){{ shockgun = new Weapon("shockgun"){{
@@ -96,7 +97,7 @@ public class Weapons implements ContentList{
inaccuracy = 0f; inaccuracy = 0f;
velocityRnd = 0.2f; velocityRnd = 0.2f;
ejectEffect = Fx.none; ejectEffect = Fx.none;
ammo = AmmoTypes.shock; ammo = TurretBullets.lightning;
}}; }};
flakgun = new Weapon("flakgun"){{ flakgun = new Weapon("flakgun"){{
@@ -108,7 +109,7 @@ public class Weapons implements ContentList{
recoil = 3f; recoil = 3f;
velocityRnd = 0.1f; velocityRnd = 0.1f;
ejectEffect = ShootFx.shellEjectMedium; ejectEffect = ShootFx.shellEjectMedium;
ammo = AmmoTypes.shellCarbide; ammo = ArtilleryBullets.dense;
}}; }};
flamethrower = new Weapon("flamethrower"){{ flamethrower = new Weapon("flamethrower"){{
@@ -117,7 +118,7 @@ public class Weapons implements ContentList{
roundrobin = true; roundrobin = true;
recoil = 1f; recoil = 1f;
ejectEffect = Fx.none; ejectEffect = Fx.none;
ammo = AmmoTypes.flamerThermite; ammo = TurretBullets.basicFlame;
}}; }};
artillery = new Weapon("artillery"){{ artillery = new Weapon("artillery"){{
@@ -127,15 +128,7 @@ public class Weapons implements ContentList{
recoil = 5f; recoil = 5f;
shake = 2f; shake = 2f;
ejectEffect = ShootFx.shellEjectMedium; ejectEffect = ShootFx.shellEjectMedium;
ammo = AmmoTypes.unitArtillery; ammo = ArtilleryBullets.unit;
}};
sapper = new Weapon("sapper"){{
length = 1.5f;
reload = 12f;
roundrobin = true;
ejectEffect = ShootFx.shellEjectSmall;
ammo = AmmoTypes.bulletDense;
}}; }};
bomber = new Weapon("bomber"){{ bomber = new Weapon("bomber"){{
@@ -146,7 +139,7 @@ public class Weapons implements ContentList{
ejectEffect = Fx.none; ejectEffect = Fx.none;
velocityRnd = 1f; velocityRnd = 1f;
inaccuracy = 40f; inaccuracy = 40f;
ammo = AmmoTypes.bombExplosive; ammo = WeaponBullets.bombExplosive;
}}; }};
bomberTrident = new Weapon("bomber"){{ bomberTrident = new Weapon("bomber"){{
@@ -158,7 +151,7 @@ public class Weapons implements ContentList{
ejectEffect = Fx.none; ejectEffect = Fx.none;
velocityRnd = 1f; velocityRnd = 1f;
inaccuracy = 40f; inaccuracy = 40f;
ammo = AmmoTypes.bombExplosive; ammo = WeaponBullets.bombExplosive;
}}; }};
laserBurster = new Weapon("bomber"){{ laserBurster = new Weapon("bomber"){{
@@ -167,7 +160,7 @@ public class Weapons implements ContentList{
width = 0f; width = 0f;
roundrobin = true; roundrobin = true;
ejectEffect = Fx.none; ejectEffect = Fx.none;
ammo = AmmoTypes.lancerLaser; ammo = TurretBullets.lancerLaser;
}}; }};
healBlasterDrone = new Weapon("heal-blaster"){{ healBlasterDrone = new Weapon("heal-blaster"){{
@@ -177,7 +170,7 @@ public class Weapons implements ContentList{
roundrobin = true; roundrobin = true;
ejectEffect = Fx.none; ejectEffect = Fx.none;
recoil = 2f; recoil = 2f;
ammo = AmmoTypes.healBlaster; ammo = TurretBullets.healBullet;
}}; }};
healBlasterDrone2 = new Weapon("heal-blaster"){{ healBlasterDrone2 = new Weapon("heal-blaster"){{
@@ -187,7 +180,7 @@ public class Weapons implements ContentList{
roundrobin = true; roundrobin = true;
ejectEffect = Fx.none; ejectEffect = Fx.none;
recoil = 2f; recoil = 2f;
ammo = AmmoTypes.healBlaster; ammo = TurretBullets.healBullet;
}}; }};
} }
@@ -1,17 +1,14 @@
package io.anuke.mindustry.content.blocks; package io.anuke.mindustry.content.blocks;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.TextureRegion; import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.mindustry.content.AmmoTypes; import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.content.Liquids;
import io.anuke.mindustry.content.bullets.*;
import io.anuke.mindustry.content.fx.ShootFx; import io.anuke.mindustry.content.fx.ShootFx;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.game.ContentList; import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.defense.turrets.*; import io.anuke.mindustry.world.blocks.defense.turrets.*;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
public class TurretBlocks extends BlockList implements ContentList{ public class TurretBlocks extends BlockList implements ContentList{
public static Block duo, /*scatter,*/ public static Block duo, /*scatter,*/
@@ -20,7 +17,12 @@ public class TurretBlocks extends BlockList implements ContentList{
@Override @Override
public void load(){ public void load(){
duo = new DoubleTurret("duo"){{ duo = new DoubleTurret("duo"){{
ammoTypes = new AmmoType[]{AmmoTypes.bulletCopper, AmmoTypes.bulletDense, AmmoTypes.bulletPyratite, AmmoTypes.bulletSilicon}; ammo(
Items.copper, StandardBullets.copper,
Items.densealloy, StandardBullets.dense,
Items.pyratite, StandardBullets.tracer,
Items.silicon, StandardBullets.homing
);
reload = 25f; reload = 25f;
restitution = 0.03f; restitution = 0.03f;
range = 90f; range = 90f;
@@ -32,7 +34,11 @@ public class TurretBlocks extends BlockList implements ContentList{
}}; }};
hail = new ArtilleryTurret("hail"){{ hail = new ArtilleryTurret("hail"){{
ammoTypes = new AmmoType[]{AmmoTypes.artilleryDense, AmmoTypes.artilleryHoming, AmmoTypes.artilleryIncindiary}; ammo(
Items.densealloy, ArtilleryBullets.dense,
Items.silicon, ArtilleryBullets.homing,
Items.pyratite, ArtilleryBullets.incendiary
);
reload = 60f; reload = 60f;
recoil = 2f; recoil = 2f;
range = 230f; range = 230f;
@@ -41,29 +47,22 @@ public class TurretBlocks extends BlockList implements ContentList{
health = 120; health = 120;
}}; }};
scorch = new LiquidTurret("scorch"){ scorch = new LiquidTurret("scorch"){{
protected TextureRegion shootRegion; ammo(Liquids.oil, TurretBullets.basicFlame);
recoil = 0f;
@Override reload = 4f;
public void load(){ shootCone = 50f;
super.load(); ammoUseEffect = ShootFx.shellEjectSmall;
shootRegion = Core.atlas.find(name + "-shoot"); health = 160;
} }};
{
ammoTypes = new AmmoType[]{AmmoTypes.basicFlame};
recoil = 0f;
reload = 4f;
shootCone = 50f;
ammoUseEffect = ShootFx.shellEjectSmall;
health = 160;
drawer = (tile, entity) -> Draw.rect(entity.target != null ? shootRegion : region, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
}
};
wave = new LiquidTurret("wave"){{ wave = new LiquidTurret("wave"){{
ammoTypes = new AmmoType[]{AmmoTypes.water, AmmoTypes.lava, AmmoTypes.cryofluid, AmmoTypes.oil}; ammo(
Liquids.water, TurretBullets.waterShot,
Liquids.lava, TurretBullets.lavaShot,
Liquids.cryofluid, TurretBullets.cryoShot,
Liquids.oil, TurretBullets.oilShot
);
size = 2; size = 2;
recoil = 0f; recoil = 0f;
reload = 4f; reload = 4f;
@@ -88,7 +87,7 @@ public class TurretBlocks extends BlockList implements ContentList{
chargeTime = 60f; chargeTime = 60f;
chargeMaxDelay = 30f; chargeMaxDelay = 30f;
chargeEffects = 7; chargeEffects = 7;
shootType = AmmoTypes.lancerLaser; shootType = TurretBullets.lancerLaser;
recoil = 2f; recoil = 2f;
reload = 100f; reload = 100f;
cooldown = 0.03f; cooldown = 0.03f;
@@ -106,7 +105,7 @@ public class TurretBlocks extends BlockList implements ContentList{
}}; }};
arc = new PowerTurret("arc"){{ arc = new PowerTurret("arc"){{
shootType = AmmoTypes.arc; shootType = TurretBullets.arc;
reload = 85f; reload = 85f;
shootShake = 1f; shootShake = 1f;
shootCone = 40f; shootCone = 40f;
@@ -121,7 +120,11 @@ public class TurretBlocks extends BlockList implements ContentList{
}}; }};
swarmer = new BurstTurret("swarmer"){{ swarmer = new BurstTurret("swarmer"){{
ammoTypes = new AmmoType[]{AmmoTypes.missileExplosive, AmmoTypes.missileIncindiary, AmmoTypes.missileSurge}; ammo(
Items.blastCompound, MissileBullets.explosive,
Items.pyratite, MissileBullets.incindiary,
Items.surgealloy, MissileBullets.surge
);
reload = 50f; reload = 50f;
shots = 4; shots = 4;
burstSpacing = 5; burstSpacing = 5;
@@ -132,54 +135,37 @@ public class TurretBlocks extends BlockList implements ContentList{
health = 380; health = 380;
}}; }};
salvo = new BurstTurret("salvo"){ salvo = new BurstTurret("salvo"){{
TextureRegion[] panels = new TextureRegion[2]; ammo(
Items.copper, StandardBullets.copper,
Items.densealloy, StandardBullets.dense,
Items.pyratite, StandardBullets.tracer,
Items.silicon, StandardBullets.homing,
Items.thorium, StandardBullets.thorium
);
@Override size = 2;
public void load() { range = 120f;
super.load(); reload = 35f;
panels[0] = Core.atlas.find(name + "-panel-left"); restitution = 0.03f;
panels[1] = Core.atlas.find(name + "-panel-right"); ammoEjectBack = 3f;
} cooldown = 0.03f;
recoil = 3f;
{ shootShake = 2f;
size = 2; burstSpacing = 4;
range = 120f; shots = 3;
ammoTypes = new AmmoType[]{AmmoTypes.bulletCopper, AmmoTypes.bulletDense, AmmoTypes.bulletPyratite, AmmoTypes.bulletThorium, AmmoTypes.bulletSilicon}; ammoUseEffect = ShootFx.shellEjectBig;
reload = 35f; health = 360;
restitution = 0.03f; }};
ammoEjectBack = 3f;
cooldown = 0.03f;
recoil = 3f;
shootShake = 2f;
burstSpacing = 4;
shots = 3;
ammoUseEffect = ShootFx.shellEjectBig;
drawer = (tile, entity) -> {
Draw.rect(region, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
float offsetx = (int) (abscurve(Mathf.curve(entity.reload / reload, 0.3f, 0.2f)) * 3f);
float offsety = -(int) (abscurve(Mathf.curve(entity.reload / reload, 0.3f, 0.2f)) * 2f);
for(int i : Mathf.signs){
float rot = entity.rotation + 90 * i;
Draw.rect(panels[i == -1 ? 0 : 1],
tile.drawx() + tr2.x + Angles.trnsx(rot, offsetx, offsety),
tile.drawy() + tr2.y + Angles.trnsy(rot, -offsetx, offsety), entity.rotation - 90);
}
};
health = 360;
}
/** Converts a value range from 0-1 to a value range 0-1-0. */
float abscurve(float f){
return 1f - Math.abs(f - 0.5f) * 2f;
}
};
ripple = new ArtilleryTurret("ripple"){{ ripple = new ArtilleryTurret("ripple"){{
ammoTypes = new AmmoType[]{AmmoTypes.artilleryDense, AmmoTypes.artilleryHoming, AmmoTypes.artilleryIncindiary, AmmoTypes.artilleryExplosive, AmmoTypes.artilleryPlastic}; ammo(
Items.densealloy, ArtilleryBullets.dense,
Items.silicon, ArtilleryBullets.homing,
Items.pyratite, ArtilleryBullets.incendiary,
Items.blastCompound, ArtilleryBullets.explosive,
Items.plastanium, ArtilleryBullets.plastic
);
size = 3; size = 3;
shots = 4; shots = 4;
inaccuracy = 12f; inaccuracy = 12f;
@@ -197,7 +183,11 @@ public class TurretBlocks extends BlockList implements ContentList{
}}; }};
cyclone = new ItemTurret("cyclone"){{ cyclone = new ItemTurret("cyclone"){{
ammoTypes = new AmmoType[]{AmmoTypes.flakExplosive, AmmoTypes.flakPlastic, AmmoTypes.flakSurge}; ammo(
Items.blastCompound, FlakBullets.explosive,
Items.plastanium, FlakBullets.plastic,
Items.surgealloy, FlakBullets.surge
);
xRand = 4f; xRand = 4f;
reload = 8f; reload = 8f;
range = 145f; range = 145f;
@@ -211,7 +201,7 @@ public class TurretBlocks extends BlockList implements ContentList{
}}; }};
fuse = new ItemTurret("fuse"){{ fuse = new ItemTurret("fuse"){{
ammoTypes = new AmmoType[]{AmmoTypes.fuseShotgun}; ammo(Items.densealloy, TurretBullets.fuseShot);
reload = 50f; reload = 50f;
shootShake = 4f; shootShake = 4f;
range = 80f; range = 80f;
@@ -223,7 +213,11 @@ public class TurretBlocks extends BlockList implements ContentList{
}}; }};
spectre = new DoubleTurret("spectre"){{ spectre = new DoubleTurret("spectre"){{
ammoTypes = new AmmoType[]{AmmoTypes.bulletDenseBig, AmmoTypes.bulletPyratiteBig, AmmoTypes.bulletThoriumBig}; ammo(
Items.densealloy, StandardBullets.denseBig,
Items.pyratite, StandardBullets.tracerBig,
Items.thorium, StandardBullets.thoriumBig
);
reload = 6f; reload = 6f;
coolantMultiplier = 0.5f; coolantMultiplier = 0.5f;
maxCoolantUsed = 1.5f; maxCoolantUsed = 1.5f;
@@ -243,7 +237,7 @@ public class TurretBlocks extends BlockList implements ContentList{
}}; }};
meltdown = new LaserTurret("meltdown"){{ meltdown = new LaserTurret("meltdown"){{
shootType = AmmoTypes.meltdownLaser; shootType = TurretBullets.meltdownLaser;
shootEffect = ShootFx.shootBigSmoke2; shootEffect = ShootFx.shootBigSmoke2;
shootCone = 40f; shootCone = 40f;
recoil = 4f; recoil = 4f;
@@ -9,115 +9,99 @@ import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.game.ContentList; import io.anuke.mindustry.game.ContentList;
public class ArtilleryBullets extends BulletList implements ContentList{ public class ArtilleryBullets extends BulletList implements ContentList{
public static BulletType dense, plastic, plasticFrag, homing, incindiary, explosive, surge, unit; public static BulletType dense, plastic, plasticFrag, homing, incendiary, explosive, surge, unit;
@Override @Override
public void load(){ public void load(){
dense = new ArtilleryBulletType(3f, 0, "shell"){ dense = new ArtilleryBulletType(3f, 0, "shell"){{
{ hitEffect = BulletFx.flakExplosion;
hitEffect = BulletFx.flakExplosion; knockback = 0.8f;
knockback = 0.8f; lifetime = 50f;
lifetime = 50f; bulletWidth = bulletHeight = 11f;
bulletWidth = bulletHeight = 11f; collidesTiles = false;
collidesTiles = false; splashDamageRadius = 25f;
splashDamageRadius = 25f; splashDamage = 33f;
splashDamage = 33f; }};
}
};
plasticFrag = new BasicBulletType(2.5f, 6, "bullet"){ plasticFrag = new BasicBulletType(2.5f, 6, "bullet"){{
{ bulletWidth = 10f;
bulletWidth = 10f; bulletHeight = 12f;
bulletHeight = 12f; bulletShrink = 1f;
bulletShrink = 1f; lifetime = 15f;
lifetime = 15f; backColor = Palette.plastaniumBack;
backColor = Palette.plastaniumBack; frontColor = Palette.plastaniumFront;
frontColor = Palette.plastaniumFront; despawnEffect = Fx.none;
despawnEffect = Fx.none; }};
}
};
plastic = new ArtilleryBulletType(3.3f, 0, "shell"){ plastic = new ArtilleryBulletType(3.3f, 0, "shell"){{
{ hitEffect = BulletFx.plasticExplosion;
hitEffect = BulletFx.plasticExplosion; knockback = 1f;
knockback = 1f; lifetime = 55f;
lifetime = 55f; bulletWidth = bulletHeight = 13f;
bulletWidth = bulletHeight = 13f; collidesTiles = false;
collidesTiles = false; splashDamageRadius = 35f;
splashDamageRadius = 35f; splashDamage = 35f;
splashDamage = 35f; fragBullet = plasticFrag;
fragBullet = plasticFrag; fragBullets = 9;
fragBullets = 9; backColor = Palette.plastaniumBack;
backColor = Palette.plastaniumBack; frontColor = Palette.plastaniumFront;
frontColor = Palette.plastaniumFront; }};
}
};
homing = new ArtilleryBulletType(3f, 0, "shell"){ homing = new ArtilleryBulletType(3f, 0, "shell"){{
{ hitEffect = BulletFx.flakExplosion;
hitEffect = BulletFx.flakExplosion; knockback = 0.8f;
knockback = 0.8f; lifetime = 45f;
lifetime = 45f; bulletWidth = bulletHeight = 11f;
bulletWidth = bulletHeight = 11f; collidesTiles = false;
collidesTiles = false; splashDamageRadius = 25f;
splashDamageRadius = 25f; splashDamage = 33f;
splashDamage = 33f; homingPower = 2f;
homingPower = 2f; homingRange = 50f;
homingRange = 50f; }};
}
};
incindiary = new ArtilleryBulletType(3f, 0, "shell"){ incendiary = new ArtilleryBulletType(3f, 0, "shell"){{
{ hitEffect = BulletFx.blastExplosion;
hitEffect = BulletFx.blastExplosion; knockback = 0.8f;
knockback = 0.8f; lifetime = 60f;
lifetime = 60f; bulletWidth = bulletHeight = 13f;
bulletWidth = bulletHeight = 13f; collidesTiles = false;
collidesTiles = false; splashDamageRadius = 25f;
splashDamageRadius = 25f; splashDamage = 30f;
splashDamage = 30f; incendAmount = 4;
incendAmount = 4; incendSpread = 11f;
incendSpread = 11f; frontColor = Palette.lightishOrange;
frontColor = Palette.lightishOrange; backColor = Palette.lightOrange;
backColor = Palette.lightOrange; trailEffect = BulletFx.incendTrail;
trailEffect = BulletFx.incendTrail; }};
}
};
explosive = new ArtilleryBulletType(2f, 0, "shell"){ explosive = new ArtilleryBulletType(2f, 0, "shell"){{
{ hitEffect = BulletFx.blastExplosion;
hitEffect = BulletFx.blastExplosion; knockback = 0.8f;
knockback = 0.8f; lifetime = 70f;
lifetime = 70f; bulletWidth = bulletHeight = 14f;
bulletWidth = bulletHeight = 14f; collidesTiles = false;
collidesTiles = false; splashDamageRadius = 45f;
splashDamageRadius = 45f; splashDamage = 50f;
splashDamage = 50f; backColor = Palette.missileYellowBack;
backColor = Palette.missileYellowBack; frontColor = Palette.missileYellow;
frontColor = Palette.missileYellow; }};
}
};
unit = new ArtilleryBulletType(2f, 0, "shell"){ unit = new ArtilleryBulletType(2f, 0, "shell"){{
{ hitEffect = BulletFx.blastExplosion;
hitEffect = BulletFx.blastExplosion; knockback = 0.8f;
knockback = 0.8f; lifetime = 90f;
lifetime = 90f; bulletWidth = bulletHeight = 14f;
bulletWidth = bulletHeight = 14f; collides = true;
collides = true; collidesTiles = true;
collidesTiles = true; splashDamageRadius = 45f;
splashDamageRadius = 45f; splashDamage = 50f;
splashDamage = 50f; backColor = Palette.bulletYellowBack;
backColor = Palette.bulletYellowBack; frontColor = Palette.bulletYellow;
frontColor = Palette.bulletYellow; }};
}
};
surge = new ArtilleryBulletType(3f, 0, "shell"){ surge = new ArtilleryBulletType(3f, 0, "shell"){{
{ //TODO
//TODO }};
}
};
} }
} }
@@ -2,10 +2,11 @@ package io.anuke.mindustry.content.bullets;
import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.Color;
import io.anuke.mindustry.content.fx.BulletFx; import io.anuke.mindustry.content.fx.BulletFx;
import io.anuke.mindustry.content.fx.ShootFx;
import io.anuke.mindustry.entities.bullet.BasicBulletType; import io.anuke.mindustry.entities.bullet.BasicBulletType;
import io.anuke.mindustry.entities.bullet.BulletType; import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.game.ContentList; import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.graphics.Palette;
public class StandardBullets extends BulletList implements ContentList{ public class StandardBullets extends BulletList implements ContentList{
public static BulletType copper, dense, thorium, homing, tracer, mechSmall, glaive, denseBig, thoriumBig, tracerBig; public static BulletType copper, dense, thorium, homing, tracer, mechSmall, glaive, denseBig, thoriumBig, tracerBig;
@@ -13,96 +14,88 @@ public class StandardBullets extends BulletList implements ContentList{
@Override @Override
public void load(){ public void load(){
copper = new BasicBulletType(2.5f, 7, "bullet"){ copper = new BasicBulletType(2.5f, 7, "bullet"){{
{ bulletWidth = 7f;
bulletWidth = 7f; bulletHeight = 9f;
bulletHeight = 9f; shootEffect = ShootFx.shootSmall;
} smokeEffect = ShootFx.shootSmallSmoke;
}; ammoMultiplier = 5;
}};
dense = new BasicBulletType(3.5f, 18, "bullet"){ dense = new BasicBulletType(3.5f, 18, "bullet"){{
{ bulletWidth = 9f;
bulletWidth = 9f; bulletHeight = 12f;
bulletHeight = 12f; armorPierce = 0.2f;
armorPierce = 0.2f; reloadMultiplier = 0.6f;
} ammoMultiplier = 2;
}; }};
thorium = new BasicBulletType(4f, 29, "bullet"){ thorium = new BasicBulletType(4f, 29, "bullet"){{
{ bulletWidth = 10f;
bulletWidth = 10f; bulletHeight = 13f;
bulletHeight = 13f; armorPierce = 0.5f;
armorPierce = 0.5f; shootEffect = ShootFx.shootBig;
} smokeEffect = ShootFx.shootBigSmoke;
}; ammoMultiplier = 2;
}};
homing = new BasicBulletType(3f, 9, "bullet"){ homing = new BasicBulletType(3f, 9, "bullet"){{
{ bulletWidth = 7f;
bulletWidth = 7f; bulletHeight = 9f;
bulletHeight = 9f; homingPower = 5f;
homingPower = 5f; reloadMultiplier = 1.4f;
} ammoMultiplier = 5;
}; }};
tracer = new BasicBulletType(3.2f, 11, "bullet"){ tracer = new BasicBulletType(3.2f, 11, "bullet"){{
{ bulletWidth = 10f;
bulletWidth = 10f; bulletHeight = 12f;
bulletHeight = 12f; frontColor = Palette.lightishOrange;
frontColor = Palette.lightishOrange; backColor = Palette.lightOrange;
backColor = Palette.lightOrange; incendSpread = 3f;
incendSpread = 3f; incendAmount = 1;
incendAmount = 1; incendChance = 0.3f;
incendChance = 0.3f; inaccuracy = 3f;
} }};
};
glaive = new BasicBulletType(4f, 7.5f, "bullet"){ glaive = new BasicBulletType(4f, 7.5f, "bullet"){{
{ bulletWidth = 10f;
bulletWidth = 10f; bulletHeight = 12f;
bulletHeight = 12f; frontColor = Color.valueOf("feb380");
frontColor = Color.valueOf("feb380"); backColor = Color.valueOf("ea8878");
backColor = Color.valueOf("ea8878"); incendSpread = 3f;
incendSpread = 3f; incendAmount = 1;
incendAmount = 1; incendChance = 0.3f;
incendChance = 0.3f; }};
}
};
mechSmall = new BasicBulletType(4f, 9, "bullet"){ mechSmall = new BasicBulletType(4f, 9, "bullet"){{
{ bulletWidth = 11f;
bulletWidth = 11f; bulletHeight = 14f;
bulletHeight = 14f; lifetime = 40f;
lifetime = 40f; inaccuracy = 5f;
despawnEffect = BulletFx.hitBulletSmall; despawnEffect = BulletFx.hitBulletSmall;
} }};
};
denseBig = new BasicBulletType(7f, 42, "bullet"){ denseBig = new BasicBulletType(7f, 42, "bullet"){{
{ bulletWidth = 15f;
bulletWidth = 15f; bulletHeight = 21f;
bulletHeight = 21f; armorPierce = 0.2f;
armorPierce = 0.2f; }};
}
};
thoriumBig = new BasicBulletType(8f, 65, "bullet"){ thoriumBig = new BasicBulletType(8f, 65, "bullet"){{
{ bulletWidth = 16f;
bulletWidth = 16f; bulletHeight = 23f;
bulletHeight = 23f; armorPierce = 0.5f;
armorPierce = 0.5f; }};
}
};
tracerBig = new BasicBulletType(7f, 38, "bullet"){ tracerBig = new BasicBulletType(7f, 38, "bullet"){{
{ bulletWidth = 16f;
bulletWidth = 16f; bulletHeight = 21f;
bulletHeight = 21f; frontColor = Palette.lightishOrange;
frontColor = Palette.lightishOrange; backColor = Palette.lightOrange;
backColor = Palette.lightOrange; incendSpread = 3f;
incendSpread = 3f; incendAmount = 2;
incendAmount = 2; incendChance = 0.3f;
incendChance = 0.3f; }};
}
};
} }
} }
@@ -67,10 +67,6 @@ public class ContentLoader{
new TurretBullets(), new TurretBullets(),
new WeaponBullets(), new WeaponBullets(),
//ammotypes
new AmmoTypes(),
//weapons //weapons
new Weapons(), new Weapons(),
@@ -629,7 +629,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
protected void updateFlying(){ protected void updateFlying(){
if(Units.invalidateTarget(target, this) && !(target instanceof TileEntity && ((TileEntity) target).damaged() && target.getTeam() == team && if(Units.invalidateTarget(target, this) && !(target instanceof TileEntity && ((TileEntity) target).damaged() && target.getTeam() == team &&
mech.canHeal && dst(target) < getWeapon().getAmmo().getRange())){ mech.canHeal && dst(target) < getWeapon().getAmmo().range())){
target = null; target = null;
} }
@@ -709,11 +709,11 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
if(target == null){ if(target == null){
isShooting = false; isShooting = false;
if(Core.settings.getBool("autotarget")){ if(Core.settings.getBool("autotarget")){
target = Units.getClosestTarget(team, x, y, getWeapon().getAmmo().getRange()); target = Units.getClosestTarget(team, x, y, getWeapon().getAmmo().range());
if(mech.canHeal && target == null){ if(mech.canHeal && target == null){
target = Geometry.findClosest(x, y, world.indexer.getDamaged(Team.blue)); target = Geometry.findClosest(x, y, world.indexer.getDamaged(Team.blue));
if(target != null && dst(target) > getWeapon().getAmmo().getRange()){ if(target != null && dst(target) > getWeapon().getAmmo().range()){
target = null; target = null;
}else if(target != null){ }else if(target != null){
target = ((Tile) target).entity; target = ((Tile) target).entity;
@@ -725,14 +725,14 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
} }
} }
}else if(target.isValid() || (target instanceof TileEntity && ((TileEntity) target).damaged() && target.getTeam() == team && }else if(target.isValid() || (target instanceof TileEntity && ((TileEntity) target).damaged() && target.getTeam() == team &&
mech.canHeal && dst(target) < getWeapon().getAmmo().getRange())){ mech.canHeal && dst(target) < getWeapon().getAmmo().range())){
//rotate toward and shoot the target //rotate toward and shoot the target
if(mech.turnCursor){ if(mech.turnCursor){
rotation = Mathf.slerpDelta(rotation, angleTo(target), 0.2f); rotation = Mathf.slerpDelta(rotation, angleTo(target), 0.2f);
} }
Vector2 intercept = Vector2 intercept =
Predict.intercept(x, y, target.getX(), target.getY(), target.velocity().x - velocity.x, target.velocity().y - velocity.y, getWeapon().getAmmo().bullet.speed); Predict.intercept(x, y, target.getX(), target.getY(), target.velocity().x - velocity.x, target.velocity().y - velocity.y, getWeapon().getAmmo().speed);
pointerX = intercept.x; pointerX = intercept.x;
pointerY = intercept.y; pointerY = intercept.y;
@@ -48,7 +48,7 @@ public class Units{
/**See {@link #invalidateTarget(TargetTrait, Team, float, float, float)}*/ /**See {@link #invalidateTarget(TargetTrait, Team, float, float, float)}*/
public static boolean invalidateTarget(TargetTrait target, Unit targeter){ public static boolean invalidateTarget(TargetTrait target, Unit targeter){
return invalidateTarget(target, targeter.team, targeter.x, targeter.y, targeter.getWeapon().getAmmo().getRange()); return invalidateTarget(target, targeter.team, targeter.x, targeter.y, targeter.getWeapon().getAmmo().range());
} }
/**Returns whether there are any entities on this tile.*/ /**Returns whether there are any entities on this tile.*/
@@ -13,9 +13,7 @@ import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.traits.TargetTrait; import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.graphics.Palette; import io.anuke.mindustry.graphics.Palette;
/** /**An extended BulletType for most ammo-based bullets shot from turrets and units.*/
* A BulletType for most ammo-based bullets shot from turrets and units.
*/
public class BasicBulletType extends BulletType{ public class BasicBulletType extends BulletType{
public Color backColor = Palette.bulletYellowBack, frontColor = Palette.bulletYellow; public Color backColor = Palette.bulletYellowBack, frontColor = Palette.bulletYellow;
public float bulletWidth = 5f, bulletHeight = 7f; public float bulletWidth = 5f, bulletHeight = 7f;
@@ -4,7 +4,7 @@ import io.anuke.arc.entities.Effects;
import io.anuke.arc.entities.Effects.Effect; import io.anuke.arc.entities.Effects.Effect;
import io.anuke.mindustry.content.StatusEffects; import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.content.fx.BulletFx; import io.anuke.mindustry.content.fx.BulletFx;
import io.anuke.mindustry.content.fx.Fx; import io.anuke.mindustry.content.fx.ShootFx;
import io.anuke.mindustry.game.Content; import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.type.ContentType; import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.StatusEffect; import io.anuke.mindustry.type.StatusEffect;
@@ -21,9 +21,17 @@ public abstract class BulletType extends Content{
public Effect hitEffect, despawnEffect; public Effect hitEffect, despawnEffect;
/**Effect created when shooting.*/ /**Effect created when shooting.*/
public Effect shootEffect = Fx.none; public Effect shootEffect = ShootFx.shootSmall;
/**Extra smoke effect created when shooting.*/ /**Extra smoke effect created when shooting.*/
public Effect smokeEffect = Fx.none; public Effect smokeEffect = ShootFx.shootSmallSmoke;
/**Extra inaccuracy when firing.*/
public float inaccuracy = 0f;
/**How many bullets get created per ammo item/liquid.*/
public float ammoMultiplier = 1f;
/**Multiplied by turret reload speed to get final shoot speed.*/
public float reloadMultiplier = 1f;
/**Recoil from shooter entities.*/
public float recoil;
public float splashDamage = 0f; public float splashDamage = 0f;
/**Knockback in velocity.*/ /**Knockback in velocity.*/
@@ -57,6 +65,11 @@ public abstract class BulletType extends Content{
despawnEffect = BulletFx.hitBulletSmall; despawnEffect = BulletFx.hitBulletSmall;
} }
/**Returns maximum distance the bullet this bullet type has can travel.*/
public float range(){
return speed * lifetime;
}
public boolean collides(Bullet bullet, Tile tile){ public boolean collides(Bullet bullet, Tile tile){
return true; return true;
} }
@@ -184,7 +184,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
} }
public void targetClosest(){ public void targetClosest(){
target = Units.getClosestTarget(team, x, y, Math.max(getWeapon().getAmmo().getRange(), type.range), u -> type.targetAir || !u.isFlying()); target = Units.getClosestTarget(team, x, y, Math.max(getWeapon().getAmmo().range(), type.range), u -> type.targetAir || !u.isFlying());
} }
public TileEntity getClosestEnemyCore(){ public TileEntity getClosestEnemyCore(){
@@ -8,10 +8,10 @@ import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.Time; import io.anuke.arc.util.Time;
import io.anuke.mindustry.entities.Predict; import io.anuke.mindustry.entities.Predict;
import io.anuke.mindustry.entities.Units; import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.entities.traits.CarriableTrait; import io.anuke.mindustry.entities.traits.CarriableTrait;
import io.anuke.mindustry.entities.traits.CarryTrait; import io.anuke.mindustry.entities.traits.CarryTrait;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockFlag; import io.anuke.mindustry.world.meta.BlockFlag;
@@ -74,11 +74,11 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
}else{ }else{
attack(150f); attack(150f);
if((Angles.near(angleTo(target), rotation, 15f) || !getWeapon().getAmmo().bullet.keepVelocity) //bombers don't care about rotation if((Angles.near(angleTo(target), rotation, 15f) || !getWeapon().getAmmo().keepVelocity) //bombers don't care about rotation
&& dst(target) < Math.max(getWeapon().getAmmo().getRange(), type.range)){ && dst(target) < Math.max(getWeapon().getAmmo().range(), type.range)){
AmmoType ammo = getWeapon().getAmmo(); BulletType ammo = getWeapon().getAmmo();
Vector2 to = Predict.intercept(FlyingUnit.this, target, ammo.bullet.speed); Vector2 to = Predict.intercept(FlyingUnit.this, target, ammo.speed);
getWeapon().update(FlyingUnit.this, to.x, to.y); getWeapon().update(FlyingUnit.this, to.x, to.y);
} }
@@ -10,8 +10,8 @@ import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Predict; import io.anuke.mindustry.entities.Predict;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.Units; import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.type.ContentType; import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.Weapon; import io.anuke.mindustry.type.Weapon;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
@@ -43,11 +43,11 @@ public abstract class GroundUnit extends BaseUnit{
TileEntity core = getClosestEnemyCore(); TileEntity core = getClosestEnemyCore();
float dst = core == null ? 0 : dst(core); float dst = core == null ? 0 : dst(core);
if(core != null && dst < getWeapon().getAmmo().getRange() / 1.1f){ if(core != null && dst < getWeapon().getAmmo().range() / 1.1f){
target = core; target = core;
} }
if(dst > getWeapon().getAmmo().getRange() * 0.5f){ if(dst > getWeapon().getAmmo().range() * 0.5f){
moveToCore(); moveToCore();
} }
} }
@@ -187,13 +187,13 @@ public abstract class GroundUnit extends BaseUnit{
} }
if(!Units.invalidateTarget(target, this)){ if(!Units.invalidateTarget(target, this)){
if(dst(target) < getWeapon().getAmmo().getRange()){ if(dst(target) < getWeapon().getAmmo().range()){
rotate(angleTo(target)); rotate(angleTo(target));
if(Angles.near(angleTo(target), rotation, 13f)){ if(Angles.near(angleTo(target), rotation, 13f)){
AmmoType ammo = getWeapon().getAmmo(); BulletType ammo = getWeapon().getAmmo();
Vector2 to = Predict.intercept(GroundUnit.this, target, ammo.bullet.speed); Vector2 to = Predict.intercept(GroundUnit.this, target, ammo.speed);
getWeapon().update(GroundUnit.this, to.x, to.y); getWeapon().update(GroundUnit.this, to.x, to.y);
} }
@@ -292,16 +292,6 @@ public class TypeIO{
return content.liquid(buffer.get()); return content.liquid(buffer.get());
} }
@WriteClass(AmmoType.class)
public static void writeAmmo(ByteBuffer buffer, AmmoType type){
buffer.put(type.id);
}
@ReadClass(AmmoType.class)
public static AmmoType readAmmo(ByteBuffer buffer){
return content.getByID(ContentType.weapon, buffer.get());
}
@WriteClass(BulletType.class) @WriteClass(BulletType.class)
public static void writeBulletType(ByteBuffer buffer, BulletType type){ public static void writeBulletType(ByteBuffer buffer, BulletType type){
buffer.put(type.id); buffer.put(type.id);
@@ -13,7 +13,6 @@ import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.content.Liquids; import io.anuke.mindustry.content.Liquids;
import io.anuke.mindustry.content.blocks.*; import io.anuke.mindustry.content.blocks.*;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.type.Recipe;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Edges; import io.anuke.mindustry.world.Edges;
@@ -74,12 +73,14 @@ public class FortressGenerator{
float placeChance = difficultyScl*0.75f+0.25f; float placeChance = difficultyScl*0.75f+0.25f;
IntIntMap ammoPerType = new IntIntMap(); IntIntMap ammoPerType = new IntIntMap();
//todo implement
/*
for(Block turret : turrets){ for(Block turret : turrets){
if(!(turret instanceof ItemTurret)) continue; if(!(turret instanceof ItemTurret)) continue;
ItemTurret t = (ItemTurret)turret; ItemTurret t = (ItemTurret)turret;
int size = t.getAmmoTypes().length; int size = t.getAmmoTypes().length;
ammoPerType.put(t.id, Mathf.clamp((int)(size* difficultyScl) + gen.random.range(1), 0, size - 1)); ammoPerType.put(t.id, Mathf.clamp((int)(size* difficultyScl) + gen.random.range(1), 0, size - 1));
} }*/
TriFunction<Tile, Block, Predicate<Tile>, Boolean> checker = (current, block, pred) -> { TriFunction<Tile, Block, Predicate<Tile>, Boolean> checker = (current, block, pred) -> {
for(Point2 point : Edges.getEdges(block.size)){ for(Point2 point : Edges.getEdges(block.size)){
@@ -181,11 +182,12 @@ public class FortressGenerator{
if(block instanceof PowerTurret){ if(block instanceof PowerTurret){
tile.entity.power.satisfaction = 1.0f; tile.entity.power.satisfaction = 1.0f;
}else if(block instanceof ItemTurret){ //todo implement
/*}else if(block instanceof ItemTurret){
ItemTurret turret = (ItemTurret)block; ItemTurret turret = (ItemTurret)block;
AmmoType[] type = turret.getAmmoTypes(); AmmoType[] type = turret.getAmmoTypes();
int index = ammoPerType.get(block.id, 0); int index = ammoPerType.get(block.id, 0);
block.handleStack(type[index].item, block.acceptStack(type[index].item, 1000, tile, null), tile, null); block.handleStack(type[index].item, block.acceptStack(type[index].item, 1000, tile, null), tile, null);*/
}else if(block instanceof NuclearReactor){ }else if(block instanceof NuclearReactor){
tile.entity.items.add(Items.thorium, 30); tile.entity.items.add(Items.thorium, 30);
}else if(block instanceof LiquidTurret){ }else if(block instanceof LiquidTurret){
@@ -1,13 +0,0 @@
package io.anuke.mindustry.type;
/**Used to store ammo amounts in turrets.
* TODO move inside turret class?*/
public class AmmoEntry{
public AmmoType type;
public int amount;
public AmmoEntry(AmmoType type, int amount){
this.type = type;
this.amount = amount;
}
}
@@ -1,75 +0,0 @@
package io.anuke.mindustry.type;
import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.game.Content;
import io.anuke.arc.entities.Effects.Effect;
public class AmmoType extends Content {
/**The item used. Always null if liquid isn't.*/
public final Item item;
/**The liquid used. Always null if item isn't.*/
public final Liquid liquid;
/**The resulting bullet. Never null.*/
public final BulletType bullet;
/**
* For item ammo, this is amount given per ammo item.
* For liquid ammo, this is amount used per shot.
*/
public final float quantityMultiplier;
/**Reload speed multiplier.*/
public float reloadMultiplier = 1f;
/**Bullet recoil strength.*/
public float recoil = 0f;
/**Additional inaccuracy in degrees.*/
public float inaccuracy;
/**Effect created when shooting.*/
public Effect shootEffect = Fx.none;
/**Extra smoke effect created when shooting.*/
public Effect smokeEffect = Fx.none;
/**Range. Use a value < 0 to calculate from bullet.*/
public float range = -1f;
/**
* Creates an AmmoType with no liquid or item. Used for power-based ammo.
*/
public AmmoType(BulletType result){
this.item = null;
this.liquid = null;
this.bullet = result;
this.quantityMultiplier = 1f;
this.reloadMultiplier = 1f;
}
/**
* Creates an AmmoType with an item.
*/
public AmmoType(Item item, BulletType result, float multiplier){
this.item = item;
this.liquid = null;
this.bullet = result;
this.quantityMultiplier = multiplier;
}
/**
* Creates an AmmoType with a liquid.
*/
public AmmoType(Liquid liquid, BulletType result, float multiplier){
this.item = null;
this.liquid = liquid;
this.bullet = result;
this.quantityMultiplier = multiplier;
}
/**
* Returns maximum distance the bullet this ammo type has can travel.
*/
public float getRange(){
return range < 0 ? bullet.speed * bullet.lifetime : range;
}
@Override
public ContentType getContentType(){
return ContentType.ammo;
}
}
@@ -11,7 +11,6 @@ public enum ContentType {
weapon, weapon,
status, status,
unit, unit,
ammo,
weather, weather,
effect effect
} }
+6 -5
View File
@@ -13,6 +13,7 @@ import io.anuke.mindustry.Vars;
import io.anuke.mindustry.content.fx.Fx; import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.bullet.Bullet; import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.entities.traits.ShooterTrait; import io.anuke.mindustry.entities.traits.ShooterTrait;
import io.anuke.mindustry.game.Content; import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.gen.Call;
@@ -24,7 +25,7 @@ public class Weapon extends Content{
/**minimum cursor distance from player, fixes 'cross-eyed' shooting.*/ /**minimum cursor distance from player, fixes 'cross-eyed' shooting.*/
protected static float minPlayerDist = 20f; protected static float minPlayerDist = 20f;
/**ammo type map. set with setAmmo()*/ /**ammo type map. set with setAmmo()*/
protected AmmoType ammo; protected BulletType ammo;
/**shell ejection effect*/ /**shell ejection effect*/
protected Effect ejectEffect = Fx.none; protected Effect ejectEffect = Fx.none;
/**weapon reload in frames*/ /**weapon reload in frames*/
@@ -47,7 +48,7 @@ public class Weapon extends Content{
protected float velocityRnd = 0f; protected float velocityRnd = 0f;
/**whether to shoot the weapons in different arms one after another, rather than all at once*/ /**whether to shoot the weapons in different arms one after another, rather than all at once*/
protected boolean roundrobin = false; protected boolean roundrobin = false;
/**translator for vector calulations*/ /**vector for vector calulations*/
protected Vector2 tr = new Vector2(); protected Vector2 tr = new Vector2();
public TextureRegion equipRegion, region; public TextureRegion equipRegion, region;
@@ -81,7 +82,7 @@ public class Weapon extends Content{
Weapon weapon = shooter.getWeapon(); Weapon weapon = shooter.getWeapon();
Angles.shotgun(weapon.shots, weapon.spacing, rotation, f -> weapon.bullet(shooter, x, y, f + Mathf.range(weapon.inaccuracy))); Angles.shotgun(weapon.shots, weapon.spacing, rotation, f -> weapon.bullet(shooter, x, y, f + Mathf.range(weapon.inaccuracy)));
AmmoType ammo = weapon.ammo; BulletType ammo = weapon.ammo;
weapon.tr.trns(rotation + 180f, ammo.recoil); weapon.tr.trns(rotation + 180f, ammo.recoil);
@@ -109,7 +110,7 @@ public class Weapon extends Content{
return ContentType.weapon; return ContentType.weapon;
} }
public AmmoType getAmmo(){ public BulletType getAmmo(){
return ammo; return ammo;
} }
@@ -165,7 +166,7 @@ public class Weapon extends Content{
if(owner == null) return; if(owner == null) return;
tr.trns(angle, 3f); tr.trns(angle, 3f);
Bullet.create(ammo.bullet, Bullet.create(ammo,
owner, owner.getTeam(), x + tr.x, y + tr.y, angle, (1f - velocityRnd) + Mathf.random(velocityRnd)); owner, owner.getTeam(), x + tr.x, y + tr.y, angle, (1f - velocityRnd) + Mathf.random(velocityRnd));
} }
} }
@@ -1,11 +1,11 @@
package io.anuke.mindustry.world.blocks.defense.turrets; package io.anuke.mindustry.world.blocks.defense.turrets;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Vector2; import io.anuke.arc.math.geom.Vector2;
import io.anuke.mindustry.entities.Predict; import io.anuke.mindustry.entities.Predict;
import io.anuke.mindustry.entities.bullet.Bullet; import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.type.AmmoType; import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.arc.math.Mathf;
import static io.anuke.mindustry.Vars.tilesize; import static io.anuke.mindustry.Vars.tilesize;
@@ -21,23 +21,23 @@ public class ArtilleryTurret extends ItemTurret{
} }
@Override @Override
protected void shoot(Tile tile, AmmoType ammo){ protected void shoot(Tile tile, BulletType ammo){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
entity.recoil = recoil; entity.recoil = recoil;
entity.heat = 1f; entity.heat = 1f;
AmmoType type = peekAmmo(tile); BulletType type = peekAmmo(tile);
tr.trns(entity.rotation, size * tilesize / 2); tr.trns(entity.rotation, size * tilesize / 2);
Vector2 predict = Predict.intercept(tile, entity.target, type.bullet.speed); Vector2 predict = Predict.intercept(tile, entity.target, type.speed);
float dst = entity.dst(predict.x, predict.y); float dst = entity.dst(predict.x, predict.y);
float maxTraveled = type.bullet.lifetime * type.bullet.speed; float maxTraveled = type.lifetime * type.speed;
for(int i = 0; i < shots; i++){ for(int i = 0; i < shots; i++){
Bullet.create(ammo.bullet, tile.entity, tile.getTeam(), tile.drawx() + tr.x, tile.drawy() + tr.y, Bullet.create(ammo, tile.entity, tile.getTeam(), tile.drawx() + tr.x, tile.drawy() + tr.y,
entity.rotation + Mathf.range(inaccuracy + type.inaccuracy), 1f + Mathf.range(velocityInaccuracy), (dst / maxTraveled)); entity.rotation + Mathf.range(inaccuracy + type.inaccuracy), 1f + Mathf.range(velocityInaccuracy), (dst / maxTraveled));
} }
@@ -1,9 +1,9 @@
package io.anuke.mindustry.world.blocks.defense.turrets; package io.anuke.mindustry.world.blocks.defense.turrets;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.world.Tile;
import io.anuke.arc.util.Time;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.world.Tile;
import static io.anuke.mindustry.Vars.tilesize; import static io.anuke.mindustry.Vars.tilesize;
@@ -15,7 +15,7 @@ public class BurstTurret extends ItemTurret{
} }
@Override @Override
protected void shoot(Tile tile, AmmoType ammo){ protected void shoot(Tile tile, BulletType ammo){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
entity.heat = 1f; entity.heat = 1f;
@@ -28,7 +28,7 @@ public class BurstTurret extends ItemTurret{
entity.recoil = recoil; entity.recoil = recoil;
tr.trns(entity.rotation, size * tilesize / 2, Mathf.range(xRand)); tr.trns(entity.rotation, size * tilesize / 2, Mathf.range(xRand));
bullet(tile, ammo.bullet, entity.rotation + Mathf.range(inaccuracy)); bullet(tile, ammo, entity.rotation + Mathf.range(inaccuracy));
effects(tile); effects(tile);
useAmmo(tile); useAmmo(tile);
}); });
@@ -1,13 +1,13 @@
package io.anuke.mindustry.world.blocks.defense.turrets; package io.anuke.mindustry.world.blocks.defense.turrets;
import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.world.Tile;
import io.anuke.arc.entities.Effects; import io.anuke.arc.entities.Effects;
import io.anuke.arc.entities.Effects.Effect; import io.anuke.arc.entities.Effects.Effect;
import io.anuke.arc.util.Time;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.world.Tile;
import static io.anuke.mindustry.Vars.tilesize; import static io.anuke.mindustry.Vars.tilesize;
@@ -24,7 +24,7 @@ public class ChargeTurret extends PowerTurret{
} }
@Override @Override
public void shoot(Tile tile, AmmoType ammo){ public void shoot(Tile tile, BulletType ammo){
LaserTurretEntity entity = tile.entity(); LaserTurretEntity entity = tile.entity();
useAmmo(tile); useAmmo(tile);
@@ -47,7 +47,7 @@ public class ChargeTurret extends PowerTurret{
tr.trns(entity.rotation, size * tilesize / 2); tr.trns(entity.rotation, size * tilesize / 2);
entity.recoil = recoil; entity.recoil = recoil;
entity.heat = 1f; entity.heat = 1f;
bullet(tile, ammo.bullet, entity.rotation + Mathf.range(inaccuracy)); bullet(tile, ammo, entity.rotation + Mathf.range(inaccuracy));
effects(tile); effects(tile);
entity.shooting = false; entity.shooting = false;
}); });
@@ -1,8 +1,8 @@
package io.anuke.mindustry.world.blocks.defense.turrets; package io.anuke.mindustry.world.blocks.defense.turrets;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.world.Tile;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.Mathf;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.world.Tile;
import static io.anuke.mindustry.Vars.tilesize; import static io.anuke.mindustry.Vars.tilesize;
@@ -15,14 +15,14 @@ public class DoubleTurret extends ItemTurret{
} }
@Override @Override
protected void shoot(Tile tile, AmmoType ammo){ protected void shoot(Tile tile, BulletType ammo){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
entity.shots++; entity.shots++;
int i = Mathf.signs[entity.shots % 2]; int i = Mathf.signs[entity.shots % 2];
tr.trns(entity.rotation - 90, shotWidth * i, size * tilesize / 2); tr.trns(entity.rotation - 90, shotWidth * i, size * tilesize / 2);
bullet(tile, ammo.bullet, entity.rotation + Mathf.range(inaccuracy)); bullet(tile, ammo, entity.rotation + Mathf.range(inaccuracy));
effects(tile); effects(tile);
useAmmo(tile); useAmmo(tile);
@@ -1,26 +1,30 @@
package io.anuke.mindustry.world.blocks.defense.turrets; package io.anuke.mindustry.world.blocks.defense.turrets;
import io.anuke.arc.collection.ObjectMap; import io.anuke.arc.collection.ObjectMap;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Unit; import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.type.AmmoEntry; import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockStat; import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.values.ItemFilterValue; import io.anuke.mindustry.world.meta.values.ItemFilterValue;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class ItemTurret extends CooledTurret{ public class ItemTurret extends CooledTurret{
protected int maxAmmo = 50; protected int maxAmmo = 50;
protected AmmoType[] ammoTypes; protected ObjectMap<Item, BulletType> ammo = new ObjectMap<>();
protected ObjectMap<Item, AmmoType> ammoMap = new ObjectMap<>();
public ItemTurret(String name){ public ItemTurret(String name){
super(name); super(name);
hasItems = true; hasItems = true;
} }
public AmmoType[] getAmmoTypes(){ /**Initializes accepted ammo map. Format: [item1, bullet1, item2, bullet2...]*/
return ammoTypes; protected void ammo(Object... objects){
ammo = ObjectMap.of(objects);
} }
@Override @Override
@@ -28,19 +32,18 @@ public class ItemTurret extends CooledTurret{
super.setStats(); super.setStats();
stats.remove(BlockStat.itemCapacity); stats.remove(BlockStat.itemCapacity);
stats.add(BlockStat.inputItems, new ItemFilterValue(item -> ammo.containsKey(item)));
stats.add(BlockStat.inputItems, new ItemFilterValue(item -> ammoMap.containsKey(item)));
} }
@Override @Override
public int acceptStack(Item item, int amount, Tile tile, Unit source){ public int acceptStack(Item item, int amount, Tile tile, Unit source){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
AmmoType type = ammoMap.get(item); BulletType type = ammo.get(item);
if(type == null) return 0; if(type == null) return 0;
return Math.min((int) ((maxAmmo - entity.totalAmmo) / ammoMap.get(item).quantityMultiplier), amount); return Math.min((int) ((maxAmmo - entity.totalAmmo) / ammo.get(item).ammoMultiplier), amount);
} }
@Override @Override
@@ -61,47 +64,67 @@ public class ItemTurret extends CooledTurret{
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
if(entity == null) return; if(entity == null) return;
AmmoType type = ammoMap.get(item); BulletType type = ammo.get(item);
entity.totalAmmo += type.quantityMultiplier; entity.totalAmmo += type.ammoMultiplier;
entity.items.add(item, 1); entity.items.add(item, 1);
//find ammo entry by type //find ammo entry by type
for(int i = 0; i < entity.ammo.size; i++){ for(int i = 0; i < entity.ammo.size; i++){
AmmoEntry entry = entity.ammo.get(i); ItemEntry entry = (ItemEntry)entity.ammo.get(i);
//if found, put it to the right //if found, put it to the right
if(entry.type == type){ if(entry.item == item){
entry.amount += type.quantityMultiplier; entry.amount += type.ammoMultiplier;
entity.ammo.swap(i, entity.ammo.size - 1); entity.ammo.swap(i, entity.ammo.size - 1);
return; return;
} }
} }
//must not be found //must not be found
AmmoEntry entry = new AmmoEntry(type, (int) type.quantityMultiplier); entity.ammo.add(new ItemEntry(item, (int) type.ammoMultiplier));
entity.ammo.add(entry);
} }
@Override @Override
public boolean acceptItem(Item item, Tile tile, Tile source){ public boolean acceptItem(Item item, Tile tile, Tile source){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
return ammoMap != null && ammoMap.get(item) != null && entity.totalAmmo + ammoMap.get(item).quantityMultiplier <= maxAmmo; return ammo != null && ammo.get(item) != null && entity.totalAmmo + ammo.get(item).ammoMultiplier <= maxAmmo;
} }
@Override public class ItemTurretEntity extends TurretEntity{
public void init(){ @Override
super.init(); public void write(DataOutput stream) throws IOException{
stream.writeByte(ammo.size);
for(AmmoEntry entry : ammo){
ItemEntry i = (ItemEntry)entry;
stream.writeByte(i.item.id);
stream.writeShort(i.amount);
}
}
if(ammoTypes != null){ @Override
for(AmmoType type : ammoTypes){ public void read(DataInput stream) throws IOException{
if(type.item == null) continue; byte amount = stream.readByte();
if(ammoMap.containsKey(type.item)){ for(int i = 0; i < amount; i++){
throw new RuntimeException("Turret \"" + name + "\" has two conflicting ammo entries on item type " + type.item + "!"); Item item = Vars.content.item(stream.readByte());
}else{ short a = stream.readShort();
ammoMap.put(type.item, type); totalAmmo += a;
} ammo.add(new ItemEntry(item, a));
} }
} }
} }
class ItemEntry extends AmmoEntry{
protected Item item;
ItemEntry(Item item, int amount){
this.item = item;
this.amount = amount;
}
@Override
public BulletType type(){
return ammo.get(item);
}
}
} }
@@ -1,16 +1,15 @@
package io.anuke.mindustry.world.blocks.defense.turrets; package io.anuke.mindustry.world.blocks.defense.turrets;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.bullet.Bullet; import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.entities.bullet.BulletType; import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.type.Liquid; import io.anuke.mindustry.type.Liquid;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter; import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.util.Time;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import static io.anuke.mindustry.Vars.tilesize; import static io.anuke.mindustry.Vars.tilesize;
@@ -55,7 +54,7 @@ public class LaserTurret extends PowerTurret{
} }
if(entity.reload >= reload && entity.cons.valid()){ if(entity.reload >= reload && entity.cons.valid()){
AmmoType type = peekAmmo(tile); BulletType type = peekAmmo(tile);
shoot(tile, type); shoot(tile, type);
@@ -1,32 +1,41 @@
package io.anuke.mindustry.world.blocks.defense.turrets; package io.anuke.mindustry.world.blocks.defense.turrets;
import io.anuke.arc.collection.ObjectMap; import io.anuke.arc.collection.ObjectMap;
import io.anuke.arc.entities.Effects;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.entities.effect.Fire; import io.anuke.mindustry.entities.effect.Fire;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Liquid; import io.anuke.mindustry.type.Liquid;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockStat; import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.values.LiquidFilterValue; import io.anuke.mindustry.world.meta.values.LiquidFilterValue;
import io.anuke.arc.entities.Effects;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import static io.anuke.mindustry.Vars.tilesize; import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world; import static io.anuke.mindustry.Vars.world;
public abstract class LiquidTurret extends Turret{ public abstract class LiquidTurret extends Turret{
protected AmmoType[] ammoTypes; protected ObjectMap<Liquid, BulletType> ammo = new ObjectMap<>();
protected ObjectMap<Liquid, AmmoType> liquidAmmoMap = new ObjectMap<>();
public LiquidTurret(String name){ public LiquidTurret(String name){
super(name); super(name);
hasLiquids = true; hasLiquids = true;
} }
/**Initializes accepted ammo map. Format: [liquid1, bullet1, liquid2, bullet2...]*/
protected void ammo(Object... objects){
ammo = ObjectMap.of(objects);
}
@Override @Override
public void setStats(){ public void setStats(){
super.setStats(); super.setStats();
stats.add(BlockStat.inputLiquid, new LiquidFilterValue(item -> liquidAmmoMap.containsKey(item))); stats.add(BlockStat.inputLiquid, new LiquidFilterValue(item -> ammo.containsKey(item)));
} }
@Override @Override
@@ -58,12 +67,12 @@ public abstract class LiquidTurret extends Turret{
@Override @Override
protected void effects(Tile tile){ protected void effects(Tile tile){
AmmoType type = peekAmmo(tile); BulletType type = peekAmmo(tile);
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
Effects.effect(type.shootEffect, type.liquid.color, tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation); Effects.effect(type.shootEffect, entity.liquids.current().color, tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation);
Effects.effect(type.smokeEffect, type.liquid.color, tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation); Effects.effect(type.smokeEffect, entity.liquids.current().color, tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation);
if(shootShake > 0){ if(shootShake > 0){
Effects.shake(shootShake, shootShake, tile.entity); Effects.shake(shootShake, shootShake, tile.entity);
@@ -73,36 +82,23 @@ public abstract class LiquidTurret extends Turret{
} }
@Override @Override
public AmmoType useAmmo(Tile tile){ public BulletType useAmmo(Tile tile){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
if(tile.isEnemyCheat()) return liquidAmmoMap.get(entity.liquids.current()); if(tile.isEnemyCheat()) return ammo.get(entity.liquids.current());
AmmoType type = liquidAmmoMap.get(entity.liquids.current()); BulletType type = ammo.get(entity.liquids.current());
entity.liquids.remove(type.liquid, type.quantityMultiplier); entity.liquids.remove(entity.liquids.current(), type.ammoMultiplier);
return type; return type;
} }
@Override @Override
public AmmoType peekAmmo(Tile tile){ public BulletType peekAmmo(Tile tile){
return liquidAmmoMap.get(tile.entity.liquids.current()); return ammo.get(tile.entity.liquids.current());
} }
@Override @Override
public boolean hasAmmo(Tile tile){ public boolean hasAmmo(Tile tile){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
return liquidAmmoMap.get(entity.liquids.current()) != null && entity.liquids.total() >= liquidAmmoMap.get(entity.liquids.current()).quantityMultiplier; return ammo.get(entity.liquids.current()) != null && entity.liquids.total() >= ammo.get(entity.liquids.current()).ammoMultiplier;
}
@Override
public void init(){
super.init();
for(AmmoType type : ammoTypes){
if(liquidAmmoMap.containsKey(type.liquid)){
throw new RuntimeException("Turret \"" + name + "\" has two conflicting ammo entries on liquid type " + type.liquid + "!");
}else{
liquidAmmoMap.put(type.liquid, type);
}
}
} }
@Override @Override
@@ -112,8 +108,45 @@ public abstract class LiquidTurret extends Turret{
@Override @Override
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){ public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
return super.acceptLiquid(tile, source, liquid, amount) && liquidAmmoMap.get(liquid) != null return super.acceptLiquid(tile, source, liquid, amount) && ammo.get(liquid) != null
&& (tile.entity.liquids.current() == liquid || (liquidAmmoMap.containsKey(tile.entity.liquids.current()) && tile.entity.liquids.get(tile.entity.liquids.current()) <= liquidAmmoMap.get(tile.entity.liquids.current()).quantityMultiplier + 0.001f)); && (tile.entity.liquids.current() == liquid || (ammo.containsKey(tile.entity.liquids.current()) && tile.entity.liquids.get(tile.entity.liquids.current()) <= ammo.get(tile.entity.liquids.current()).ammoMultiplier + 0.001f));
}
public class LiquidTurretEntity extends TurretEntity{
@Override
public void write(DataOutput stream) throws IOException{
stream.writeByte(ammo.size);
for(AmmoEntry entry : ammo){
LiquidEntry i = (LiquidEntry)entry;
stream.writeByte(i.liquid.id);
stream.writeShort(i.amount);
}
}
@Override
public void read(DataInput stream) throws IOException{
byte amount = stream.readByte();
for(int i = 0; i < amount; i++){
Liquid liquid = Vars.content.liquid(stream.readByte());
short a = stream.readShort();
totalAmmo += a;
ammo.add(new LiquidEntry(liquid, a));
}
}
}
class LiquidEntry extends AmmoEntry{
protected Liquid liquid;
LiquidEntry(Liquid liquid, int amount){
this.liquid = liquid;
this.amount = amount;
}
@Override
public BulletType type(){
return ammo.get(liquid);
}
} }
} }
@@ -1,6 +1,6 @@
package io.anuke.mindustry.world.blocks.defense.turrets; package io.anuke.mindustry.world.blocks.defense.turrets;
import io.anuke.mindustry.type.AmmoType; import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockStat; import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.StatUnit; import io.anuke.mindustry.world.meta.StatUnit;
@@ -8,7 +8,7 @@ import io.anuke.mindustry.world.meta.StatUnit;
public abstract class PowerTurret extends CooledTurret{ public abstract class PowerTurret extends CooledTurret{
/** The percentage of power which will be used per shot. */ /** The percentage of power which will be used per shot. */
protected float powerUsed = 0.5f; protected float powerUsed = 0.5f;
protected AmmoType shootType; protected BulletType shootType;
public PowerTurret(String name){ public PowerTurret(String name){
super(name); super(name);
@@ -29,7 +29,7 @@ public abstract class PowerTurret extends CooledTurret{
} }
@Override @Override
public AmmoType useAmmo(Tile tile){ public BulletType useAmmo(Tile tile){
if(tile.isEnemyCheat()) return shootType; if(tile.isEnemyCheat()) return shootType;
// Make sure that power can not go negative in case of threading issues or similar // Make sure that power can not go negative in case of threading issues or similar
tile.entity.power.satisfaction -= Math.min(powerUsed, tile.entity.power.satisfaction); tile.entity.power.satisfaction -= Math.min(powerUsed, tile.entity.power.satisfaction);
@@ -37,7 +37,7 @@ public abstract class PowerTurret extends CooledTurret{
} }
@Override @Override
public AmmoType peekAmmo(Tile tile){ public BulletType peekAmmo(Tile tile){
return shootType; return shootType;
} }
} }
@@ -24,9 +24,6 @@ import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.entities.traits.TargetTrait; import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.graphics.Layer; import io.anuke.mindustry.graphics.Layer;
import io.anuke.mindustry.graphics.Palette; import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.type.AmmoEntry;
import io.anuke.mindustry.type.AmmoType;
import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockFlag; import io.anuke.mindustry.world.meta.BlockFlag;
@@ -34,11 +31,6 @@ import io.anuke.mindustry.world.meta.BlockGroup;
import io.anuke.mindustry.world.meta.BlockStat; import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.StatUnit; import io.anuke.mindustry.world.meta.StatUnit;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import static io.anuke.mindustry.Vars.content;
import static io.anuke.mindustry.Vars.tilesize; import static io.anuke.mindustry.Vars.tilesize;
public abstract class Turret extends Block{ public abstract class Turret extends Block{
@@ -197,8 +189,8 @@ public abstract class Turret extends Block{
if(validateTarget(tile)){ if(validateTarget(tile)){
AmmoType type = peekAmmo(tile); BulletType type = peekAmmo(tile);
float speed = type.bullet.speed; float speed = type.speed;
if(speed < 0.1f) speed = 9999999f; if(speed < 0.1f) speed = 9999999f;
Vector2 result = Predict.intercept(entity, entity.target, speed); Vector2 result = Predict.intercept(entity, entity.target, speed);
@@ -246,7 +238,7 @@ public abstract class Turret extends Block{
} }
/**Consume ammo and return a type.*/ /**Consume ammo and return a type.*/
public AmmoType useAmmo(Tile tile){ public BulletType useAmmo(Tile tile){
if(tile.isEnemyCheat()) return peekAmmo(tile); if(tile.isEnemyCheat()) return peekAmmo(tile);
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
@@ -255,15 +247,15 @@ public abstract class Turret extends Block{
if(entry.amount == 0) entity.ammo.pop(); if(entry.amount == 0) entity.ammo.pop();
entity.totalAmmo -= ammoPerShot; entity.totalAmmo -= ammoPerShot;
Time.run(reload / 2f, () -> ejectEffects(tile)); Time.run(reload / 2f, () -> ejectEffects(tile));
return entry.type; return entry.type();
} }
/** /**
* Get the ammo type that will be returned if useAmmo is called. * Get the ammo type that will be returned if useAmmo is called.
*/ */
public AmmoType peekAmmo(Tile tile){ public BulletType peekAmmo(Tile tile){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
return entity.ammo.peek().type; return entity.ammo.peek().type();
} }
/** /**
@@ -278,7 +270,7 @@ public abstract class Turret extends Block{
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
if(entity.reload >= reload){ if(entity.reload >= reload){
AmmoType type = peekAmmo(tile); BulletType type = peekAmmo(tile);
shoot(tile, type); shoot(tile, type);
@@ -288,18 +280,16 @@ public abstract class Turret extends Block{
} }
} }
protected void shoot(Tile tile, AmmoType ammo){ protected void shoot(Tile tile, BulletType type){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
entity.recoil = recoil; entity.recoil = recoil;
entity.heat = 1f; entity.heat = 1f;
AmmoType type = peekAmmo(tile);
tr.trns(entity.rotation, size * tilesize / 2f, Mathf.range(xRand)); tr.trns(entity.rotation, size * tilesize / 2f, Mathf.range(xRand));
for(int i = 0; i < shots; i++){ for(int i = 0; i < shots; i++){
bullet(tile, ammo.bullet, entity.rotation + Mathf.range(inaccuracy + type.inaccuracy) + (i-shots/2) * spread); bullet(tile, type, entity.rotation + Mathf.range(inaccuracy + type.inaccuracy) + (i-shots/2) * spread);
} }
effects(tile); effects(tile);
@@ -343,6 +333,12 @@ public abstract class Turret extends Block{
return new TurretEntity(); return new TurretEntity();
} }
public static abstract class AmmoEntry{
public int amount;
public abstract BulletType type();
}
public static class TurretEntity extends TileEntity{ public static class TurretEntity extends TileEntity{
public Array<AmmoEntry> ammo = new Array<>(); public Array<AmmoEntry> ammo = new Array<>();
public int totalAmmo; public int totalAmmo;
@@ -352,25 +348,5 @@ public abstract class Turret extends Block{
public float heat; public float heat;
public int shots; public int shots;
public TargetTrait target; public TargetTrait target;
@Override
public void write(DataOutput stream) throws IOException{
stream.writeByte(ammo.size);
for(AmmoEntry entry : ammo){
stream.writeByte(entry.type.id);
stream.writeShort(entry.amount);
}
}
@Override
public void read(DataInput stream) throws IOException{
byte amount = stream.readByte();
for(int i = 0; i < amount; i++){
AmmoType type = content.getByID(ContentType.ammo, stream.readByte());
short ta = stream.readShort();
ammo.add(new AmmoEntry(type, ta));
totalAmmo += ta;
}
}
} }
} }