Ammo system redesign
This commit is contained in:
@@ -2003,17 +2003,6 @@ public class Blocks implements ContentList{
|
|||||||
acceptCoolant = true;
|
acceptCoolant = true;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
resupplyPoint = new ResupplyPoint("resupply-point"){{
|
|
||||||
requirements(Category.units, BuildVisibility.ammoOnly, with(Items.lead, 20, Items.copper, 15, Items.silicon, 15));
|
|
||||||
|
|
||||||
size = 2;
|
|
||||||
range = 80f;
|
|
||||||
itemCapacity = 20;
|
|
||||||
ammoAmount = 5;
|
|
||||||
|
|
||||||
consumes.item(Items.copper, 1);
|
|
||||||
}};
|
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
//region payloads
|
//region payloads
|
||||||
|
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ public class UnitTypes implements ContentList{
|
|||||||
//air + payload, legacy
|
//air + payload, legacy
|
||||||
public static @EntityDef(value = {Unitc.class, Payloadc.class}, legacy = true) UnitType quad;
|
public static @EntityDef(value = {Unitc.class, Payloadc.class}, legacy = true) UnitType quad;
|
||||||
|
|
||||||
//air + payload + ammo distribution
|
//air + payload + legacy (different branch)
|
||||||
public static @EntityDef({Unitc.class, Payloadc.class, AmmoDistributec.class}) UnitType oct;
|
public static @EntityDef(value = {Unitc.class, Payloadc.class}, legacy = true) UnitType oct;
|
||||||
|
|
||||||
//air, legacy
|
//air, legacy
|
||||||
public static @EntityDef(value = {Unitc.class}, legacy = true) UnitType alpha, beta, gamma;
|
public static @EntityDef(value = {Unitc.class}, legacy = true) UnitType alpha, beta, gamma;
|
||||||
@@ -89,6 +89,7 @@ public class UnitTypes implements ContentList{
|
|||||||
hitSize = 10f;
|
hitSize = 10f;
|
||||||
health = 540;
|
health = 540;
|
||||||
armor = 4f;
|
armor = 4f;
|
||||||
|
ammoType = AmmoTypes.coal;
|
||||||
|
|
||||||
immunities.add(StatusEffects.burning);
|
immunities.add(StatusEffects.burning);
|
||||||
|
|
||||||
@@ -123,6 +124,7 @@ public class UnitTypes implements ContentList{
|
|||||||
health = 900;
|
health = 900;
|
||||||
armor = 9f;
|
armor = 9f;
|
||||||
mechFrontSway = 0.55f;
|
mechFrontSway = 0.55f;
|
||||||
|
ammoType = AmmoTypes.graphite;
|
||||||
|
|
||||||
weapons.add(new Weapon("artillery"){{
|
weapons.add(new Weapon("artillery"){{
|
||||||
top = false;
|
top = false;
|
||||||
@@ -156,6 +158,7 @@ public class UnitTypes implements ContentList{
|
|||||||
armor = 10f;
|
armor = 10f;
|
||||||
canDrown = false;
|
canDrown = false;
|
||||||
mechFrontSway = 1f;
|
mechFrontSway = 1f;
|
||||||
|
ammoType = AmmoTypes.thorium;
|
||||||
|
|
||||||
mechStepParticles = true;
|
mechStepParticles = true;
|
||||||
mechStepShake = 0.15f;
|
mechStepShake = 0.15f;
|
||||||
@@ -220,6 +223,7 @@ public class UnitTypes implements ContentList{
|
|||||||
canDrown = false;
|
canDrown = false;
|
||||||
mechFrontSway = 1.9f;
|
mechFrontSway = 1.9f;
|
||||||
mechSideSway = 0.6f;
|
mechSideSway = 0.6f;
|
||||||
|
ammoType = AmmoTypes.thorium;
|
||||||
|
|
||||||
weapons.add(
|
weapons.add(
|
||||||
new Weapon("reign-weapon"){{
|
new Weapon("reign-weapon"){{
|
||||||
@@ -558,6 +562,7 @@ public class UnitTypes implements ContentList{
|
|||||||
health = 200;
|
health = 200;
|
||||||
mechSideSway = 0.25f;
|
mechSideSway = 0.25f;
|
||||||
range = 40f;
|
range = 40f;
|
||||||
|
ammoType = AmmoTypes.coal;
|
||||||
|
|
||||||
weapons.add(new Weapon(){{
|
weapons.add(new Weapon(){{
|
||||||
reload = 24f;
|
reload = 24f;
|
||||||
@@ -595,6 +600,7 @@ public class UnitTypes implements ContentList{
|
|||||||
legMoveSpace = 1.4f;
|
legMoveSpace = 1.4f;
|
||||||
hovering = true;
|
hovering = true;
|
||||||
armor = 3f;
|
armor = 3f;
|
||||||
|
ammoType = AmmoTypes.coal;
|
||||||
|
|
||||||
allowLegStep = true;
|
allowLegStep = true;
|
||||||
visualElevation = 0.2f;
|
visualElevation = 0.2f;
|
||||||
@@ -965,6 +971,7 @@ public class UnitTypes implements ContentList{
|
|||||||
targetFlags = new BlockFlag[]{BlockFlag.factory, null};
|
targetFlags = new BlockFlag[]{BlockFlag.factory, null};
|
||||||
commandLimit = 5;
|
commandLimit = 5;
|
||||||
circleTarget = true;
|
circleTarget = true;
|
||||||
|
ammoType = AmmoTypes.graphite;
|
||||||
|
|
||||||
weapons.add(new Weapon(){{
|
weapons.add(new Weapon(){{
|
||||||
minShootVelocity = 0.75f;
|
minShootVelocity = 0.75f;
|
||||||
@@ -1003,6 +1010,7 @@ public class UnitTypes implements ContentList{
|
|||||||
targetFlags = new BlockFlag[]{BlockFlag.launchPad, BlockFlag.storage, BlockFlag.battery, null};
|
targetFlags = new BlockFlag[]{BlockFlag.launchPad, BlockFlag.storage, BlockFlag.battery, null};
|
||||||
engineOffset = 12f;
|
engineOffset = 12f;
|
||||||
engineSize = 3f;
|
engineSize = 3f;
|
||||||
|
ammoType = AmmoTypes.graphite;
|
||||||
|
|
||||||
weapons.add(new Weapon("zenith-missiles"){{
|
weapons.add(new Weapon("zenith-missiles"){{
|
||||||
reload = 40f;
|
reload = 40f;
|
||||||
@@ -1048,6 +1056,7 @@ public class UnitTypes implements ContentList{
|
|||||||
engineSize = 5.3f;
|
engineSize = 5.3f;
|
||||||
hitSize = 46f;
|
hitSize = 46f;
|
||||||
targetFlags = new BlockFlag[]{BlockFlag.generator, BlockFlag.core, null};
|
targetFlags = new BlockFlag[]{BlockFlag.generator, BlockFlag.core, null};
|
||||||
|
ammoType = AmmoTypes.thorium;
|
||||||
|
|
||||||
BulletType missiles = new MissileBulletType(2.7f, 14){{
|
BulletType missiles = new MissileBulletType(2.7f, 14){{
|
||||||
width = 8f;
|
width = 8f;
|
||||||
@@ -1123,6 +1132,7 @@ public class UnitTypes implements ContentList{
|
|||||||
destructibleWreck = false;
|
destructibleWreck = false;
|
||||||
armor = 13f;
|
armor = 13f;
|
||||||
targetFlags = new BlockFlag[]{BlockFlag.reactor, BlockFlag.core, null};
|
targetFlags = new BlockFlag[]{BlockFlag.reactor, BlockFlag.core, null};
|
||||||
|
ammoType = AmmoTypes.thorium;
|
||||||
|
|
||||||
BulletType fragBullet = new FlakBulletType(4f, 5){{
|
BulletType fragBullet = new FlakBulletType(4f, 5){{
|
||||||
shootEffect = Fx.shootBig;
|
shootEffect = Fx.shootBig;
|
||||||
@@ -1407,9 +1417,7 @@ public class UnitTypes implements ContentList{
|
|||||||
commandLimit = 6;
|
commandLimit = 6;
|
||||||
lowAltitude = true;
|
lowAltitude = true;
|
||||||
buildBeamOffset = 43;
|
buildBeamOffset = 43;
|
||||||
|
ammoCapacity = 1;
|
||||||
ammoCapacity = 1300;
|
|
||||||
ammoResupplyAmount = 20;
|
|
||||||
|
|
||||||
abilities.add(new ForceFieldAbility(140f, 4f, 7000f, 60f * 8), new RepairFieldAbility(130f, 60f * 2, 140f));
|
abilities.add(new ForceFieldAbility(140f, 4f, 7000f, 60f * 8), new RepairFieldAbility(130f, 60f * 2, 140f));
|
||||||
}};
|
}};
|
||||||
@@ -1477,6 +1485,7 @@ public class UnitTypes implements ContentList{
|
|||||||
accel = 0.3f;
|
accel = 0.3f;
|
||||||
rotateSpeed = 2.6f;
|
rotateSpeed = 2.6f;
|
||||||
rotateShooting = false;
|
rotateShooting = false;
|
||||||
|
ammoType = AmmoTypes.graphite;
|
||||||
|
|
||||||
trailLength = 20;
|
trailLength = 20;
|
||||||
trailX = 5.5f;
|
trailX = 5.5f;
|
||||||
@@ -1520,6 +1529,7 @@ public class UnitTypes implements ContentList{
|
|||||||
hitSize = 20f;
|
hitSize = 20f;
|
||||||
armor = 7f;
|
armor = 7f;
|
||||||
rotateShooting = false;
|
rotateShooting = false;
|
||||||
|
ammoType = AmmoTypes.graphite;
|
||||||
|
|
||||||
trailLength = 22;
|
trailLength = 22;
|
||||||
trailX = 7f;
|
trailX = 7f;
|
||||||
@@ -1583,6 +1593,7 @@ public class UnitTypes implements ContentList{
|
|||||||
inaccuracy = 5f;
|
inaccuracy = 5f;
|
||||||
velocityRnd = 0.1f;
|
velocityRnd = 0.1f;
|
||||||
shootSound = Sounds.missile;
|
shootSound = Sounds.missile;
|
||||||
|
ammoType = AmmoTypes.thorium;
|
||||||
|
|
||||||
ejectEffect = Fx.none;
|
ejectEffect = Fx.none;
|
||||||
bullet = new MissileBulletType(2.7f, 12){{
|
bullet = new MissileBulletType(2.7f, 12){{
|
||||||
@@ -1616,6 +1627,7 @@ public class UnitTypes implements ContentList{
|
|||||||
accel = 0.2f;
|
accel = 0.2f;
|
||||||
rotateSpeed = 1.3f;
|
rotateSpeed = 1.3f;
|
||||||
rotateShooting = false;
|
rotateShooting = false;
|
||||||
|
ammoType = AmmoTypes.thorium;
|
||||||
|
|
||||||
trailLength = 50;
|
trailLength = 50;
|
||||||
trailX = 18f;
|
trailX = 18f;
|
||||||
@@ -1701,6 +1713,7 @@ public class UnitTypes implements ContentList{
|
|||||||
accel = 0.19f;
|
accel = 0.19f;
|
||||||
rotateSpeed = 0.9f;
|
rotateSpeed = 0.9f;
|
||||||
rotateShooting = false;
|
rotateShooting = false;
|
||||||
|
ammoType = AmmoTypes.powerHigh;
|
||||||
|
|
||||||
float spawnTime = 60f * 15f;
|
float spawnTime = 60f * 15f;
|
||||||
|
|
||||||
@@ -1758,6 +1771,7 @@ public class UnitTypes implements ContentList{
|
|||||||
trailScl = 1.3f;
|
trailScl = 1.3f;
|
||||||
rotateShooting = false;
|
rotateShooting = false;
|
||||||
range = 100f;
|
range = 100f;
|
||||||
|
ammoType = AmmoTypes.power;
|
||||||
|
|
||||||
armor = 3f;
|
armor = 3f;
|
||||||
|
|
||||||
@@ -1835,6 +1849,7 @@ public class UnitTypes implements ContentList{
|
|||||||
trailX = 5.5f;
|
trailX = 5.5f;
|
||||||
trailY = -4f;
|
trailY = -4f;
|
||||||
trailScl = 1.9f;
|
trailScl = 1.9f;
|
||||||
|
ammoType = AmmoTypes.coal;
|
||||||
|
|
||||||
buildSpeed = 2f;
|
buildSpeed = 2f;
|
||||||
|
|
||||||
@@ -1903,6 +1918,7 @@ public class UnitTypes implements ContentList{
|
|||||||
hitSize = 20f;
|
hitSize = 20f;
|
||||||
armor = 6f;
|
armor = 6f;
|
||||||
rotateShooting = false;
|
rotateShooting = false;
|
||||||
|
ammoType = AmmoTypes.graphite;
|
||||||
|
|
||||||
trailLength = 23;
|
trailLength = 23;
|
||||||
trailX = 9f;
|
trailX = 9f;
|
||||||
@@ -2038,6 +2054,7 @@ public class UnitTypes implements ContentList{
|
|||||||
accel = 0.2f;
|
accel = 0.2f;
|
||||||
rotateSpeed = 1.4f;
|
rotateSpeed = 1.4f;
|
||||||
rotateShooting = false;
|
rotateShooting = false;
|
||||||
|
ammoType = AmmoTypes.powerHigh;
|
||||||
|
|
||||||
//clip size is massive due to energy field
|
//clip size is massive due to energy field
|
||||||
clipSize = 250f;
|
clipSize = 250f;
|
||||||
@@ -2081,6 +2098,7 @@ public class UnitTypes implements ContentList{
|
|||||||
accel = 0.2f;
|
accel = 0.2f;
|
||||||
rotateSpeed = 1.1f;
|
rotateSpeed = 1.1f;
|
||||||
rotateShooting = false;
|
rotateShooting = false;
|
||||||
|
ammoType = AmmoTypes.powerHigh;
|
||||||
|
|
||||||
trailLength = 70;
|
trailLength = 70;
|
||||||
trailX = 23f;
|
trailX = 23f;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public class Units{
|
|||||||
private static float cdist;
|
private static float cdist;
|
||||||
private static boolean boolResult;
|
private static boolean boolResult;
|
||||||
private static int intResult;
|
private static int intResult;
|
||||||
|
private static Building buildResult;
|
||||||
|
|
||||||
@Remote(called = Loc.server)
|
@Remote(called = Loc.server)
|
||||||
public static void unitCapDeath(Unit unit){
|
public static void unitCapDeath(Unit unit){
|
||||||
@@ -157,6 +158,26 @@ public class Units{
|
|||||||
return indexer.findEnemyTile(team, x, y, range, pred);
|
return indexer.findEnemyTile(team, x, y, range, pred);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return the closest building of the provided team that matches the predicate. */
|
||||||
|
public static @Nullable Building closestBuilding(Team team, float wx, float wy, float range, Boolf<Building> pred){
|
||||||
|
buildResult = null;
|
||||||
|
cdist = 0f;
|
||||||
|
|
||||||
|
var buildings = team.data().buildings;
|
||||||
|
if(buildings == null) return null;
|
||||||
|
buildings.intersect(wx - range, wy - range, range*2f, range*2f, b -> {
|
||||||
|
if(pred.get(b)){
|
||||||
|
float dst = b.dst(wx, wy) - b.hitSize()/2f;
|
||||||
|
if(dst <= range && (buildResult == null || dst <= cdist)){
|
||||||
|
cdist = dst;
|
||||||
|
buildResult = b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return buildResult;
|
||||||
|
}
|
||||||
|
|
||||||
/** Iterates through all buildings in a range. */
|
/** Iterates through all buildings in a range. */
|
||||||
public static void nearbyBuildings(float x, float y, float range, Cons<Building> cons){
|
public static void nearbyBuildings(float x, float y, float range, Cons<Building> cons){
|
||||||
indexer.allBuildings(x, y, range, cons);
|
indexer.allBuildings(x, y, range, cons);
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
package mindustry.entities.comp;
|
|
||||||
|
|
||||||
import arc.util.*;
|
|
||||||
import mindustry.annotations.Annotations.*;
|
|
||||||
import mindustry.game.*;
|
|
||||||
import mindustry.gen.*;
|
|
||||||
import mindustry.type.*;
|
|
||||||
import mindustry.world.blocks.units.*;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
abstract class AmmoDistributeComp implements Unitc{
|
|
||||||
@Import float x, y;
|
|
||||||
@Import UnitType type;
|
|
||||||
@Import Team team;
|
|
||||||
@Import float ammo;
|
|
||||||
|
|
||||||
private transient float ammoCooldown;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(){
|
|
||||||
if(ammoCooldown > 0f) ammoCooldown -= Time.delta;
|
|
||||||
|
|
||||||
if(ammo > 0 && ammoCooldown <= 0f && ResupplyPoint.resupply(team, x, y, type.ammoResupplyRange, Math.min(type.ammoResupplyAmount, ammo), type.ammoType.color, u -> u != self())){
|
|
||||||
ammo -= Math.min(type.ammoResupplyAmount, ammo);
|
|
||||||
ammoCooldown = 5f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -325,8 +325,6 @@ public class ClassMap{
|
|||||||
classes.put("ReconstructorBuild", mindustry.world.blocks.units.Reconstructor.ReconstructorBuild.class);
|
classes.put("ReconstructorBuild", mindustry.world.blocks.units.Reconstructor.ReconstructorBuild.class);
|
||||||
classes.put("RepairPoint", mindustry.world.blocks.units.RepairPoint.class);
|
classes.put("RepairPoint", mindustry.world.blocks.units.RepairPoint.class);
|
||||||
classes.put("RepairPointBuild", mindustry.world.blocks.units.RepairPoint.RepairPointBuild.class);
|
classes.put("RepairPointBuild", mindustry.world.blocks.units.RepairPoint.RepairPointBuild.class);
|
||||||
classes.put("ResupplyPoint", mindustry.world.blocks.units.ResupplyPoint.class);
|
|
||||||
classes.put("ResupplyPointBuild", mindustry.world.blocks.units.ResupplyPoint.ResupplyPointBuild.class);
|
|
||||||
classes.put("UnitBlock", mindustry.world.blocks.units.UnitBlock.class);
|
classes.put("UnitBlock", mindustry.world.blocks.units.UnitBlock.class);
|
||||||
classes.put("UnitBuild", mindustry.world.blocks.units.UnitBlock.UnitBuild.class);
|
classes.put("UnitBuild", mindustry.world.blocks.units.UnitBlock.UnitBuild.class);
|
||||||
classes.put("UnitFactory", mindustry.world.blocks.units.UnitFactory.class);
|
classes.put("UnitFactory", mindustry.world.blocks.units.UnitFactory.class);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import mindustry.gen.*;
|
|||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.mod.Mods.*;
|
import mindustry.mod.Mods.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
|
import mindustry.type.AmmoTypes.*;
|
||||||
import mindustry.type.weather.*;
|
import mindustry.type.weather.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
import mindustry.world.blocks.units.*;
|
import mindustry.world.blocks.units.*;
|
||||||
@@ -95,6 +96,16 @@ public class ContentParser{
|
|||||||
readFields(result, data);
|
readFields(result, data);
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
put(AmmoType.class, (type, data) -> {
|
||||||
|
if(data.isString()){
|
||||||
|
return field(AmmoTypes.class, data);
|
||||||
|
}
|
||||||
|
var bc = resolve(data.getString("type", ""), ItemAmmoType.class);
|
||||||
|
data.remove("type");
|
||||||
|
AmmoType result = make(bc);
|
||||||
|
readFields(result, data);
|
||||||
|
return result;
|
||||||
|
});
|
||||||
put(DrawBlock.class, (type, data) -> {
|
put(DrawBlock.class, (type, data) -> {
|
||||||
if(data.isString()){
|
if(data.isString()){
|
||||||
//try to instantiate
|
//try to instantiate
|
||||||
@@ -346,6 +357,16 @@ public class ContentParser{
|
|||||||
if(!value.has("sector") || !value.get("sector").isNumber()) throw new RuntimeException("SectorPresets must have a sector number.");
|
if(!value.has("sector") || !value.get("sector").isNumber()) throw new RuntimeException("SectorPresets must have a sector number.");
|
||||||
|
|
||||||
return new SectorPreset(name, locate(ContentType.planet, value.getString("planet", "serpulo")), value.getInt("sector"));
|
return new SectorPreset(name, locate(ContentType.planet, value.getString("planet", "serpulo")), value.getInt("sector"));
|
||||||
|
},
|
||||||
|
ContentType.ammo, (TypeParser<AmmoType>)(mod, name, value) -> {
|
||||||
|
if(value.isString()){
|
||||||
|
return (AmmoType)field(AmmoTypes.class, value.asString());
|
||||||
|
}
|
||||||
|
|
||||||
|
AmmoType item = make(resolve(value.getString("type", null), ItemAmmoType.class));
|
||||||
|
currentContent = item;
|
||||||
|
read(() -> readFields(item, value));
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -746,7 +767,7 @@ public class ContentParser{
|
|||||||
/** Tries to resolve a class from the class type map. */
|
/** Tries to resolve a class from the class type map. */
|
||||||
<T> Class<T> resolve(String base, Class<T> def){
|
<T> Class<T> resolve(String base, Class<T> def){
|
||||||
//no base class specified
|
//no base class specified
|
||||||
if(base.isEmpty() && def != null) return def;
|
if((base == null || base.isEmpty()) && def != null) return def;
|
||||||
|
|
||||||
//return mapped class if found in the global map
|
//return mapped class if found in the global map
|
||||||
var out = ClassMap.classes.get(!base.isEmpty() && Character.isLowerCase(base.charAt(0)) ? Strings.capitalize(base) : base);
|
var out = ClassMap.classes.get(!base.isEmpty() && Character.isLowerCase(base.charAt(0)) ? Strings.capitalize(base) : base);
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public class Net{
|
|||||||
String type = t.getClass().toString().toLowerCase();
|
String type = t.getClass().toString().toLowerCase();
|
||||||
boolean isError = false;
|
boolean isError = false;
|
||||||
|
|
||||||
if(e instanceof BufferUnderflowException || e instanceof BufferOverflowException){
|
if(e instanceof BufferUnderflowException || e instanceof BufferOverflowException || e.getCause() instanceof EOFException){
|
||||||
error = Core.bundle.get("error.io");
|
error = Core.bundle.get("error.io");
|
||||||
}else if(error.equals("mismatch") || e instanceof LZ4Exception || (e instanceof IndexOutOfBoundsException && e.getStackTrace()[0].getClassName().contains("java.nio"))){
|
}else if(error.equals("mismatch") || e instanceof LZ4Exception || (e instanceof IndexOutOfBoundsException && e.getStackTrace()[0].getClassName().contains("java.nio"))){
|
||||||
error = Core.bundle.get("error.mismatch");
|
error = Core.bundle.get("error.mismatch");
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ public class AmmoType extends Content{
|
|||||||
public String icon = Iconc.itemCopper + "";
|
public String icon = Iconc.itemCopper + "";
|
||||||
public Color color = Pal.ammo;
|
public Color color = Pal.ammo;
|
||||||
public Color barColor = Pal.ammo;
|
public Color barColor = Pal.ammo;
|
||||||
|
public float range = 85f;
|
||||||
|
|
||||||
public AmmoType(char icon, Color color){
|
public AmmoType(char icon, Color color){
|
||||||
this.icon = icon + "";
|
this.icon = icon + "";
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package mindustry.type;
|
package mindustry.type;
|
||||||
|
|
||||||
import mindustry.*;
|
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.ctype.*;
|
import mindustry.ctype.*;
|
||||||
|
import mindustry.entities.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.world.*;
|
|
||||||
import mindustry.world.meta.*;
|
|
||||||
|
|
||||||
public class AmmoTypes implements ContentList{
|
public class AmmoTypes implements ContentList{
|
||||||
public static AmmoType
|
public static AmmoType
|
||||||
@@ -14,6 +12,8 @@ public class AmmoTypes implements ContentList{
|
|||||||
power,
|
power,
|
||||||
powerHigh,
|
powerHigh,
|
||||||
copper,
|
copper,
|
||||||
|
graphite,
|
||||||
|
coal,
|
||||||
thorium;
|
thorium;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -22,6 +22,8 @@ public class AmmoTypes implements ContentList{
|
|||||||
power = new PowerAmmoType(1000);
|
power = new PowerAmmoType(1000);
|
||||||
powerHigh = new PowerAmmoType(2000);
|
powerHigh = new PowerAmmoType(2000);
|
||||||
copper = new ItemAmmoType(Items.copper);
|
copper = new ItemAmmoType(Items.copper);
|
||||||
|
graphite = new ItemAmmoType(Items.graphite);
|
||||||
|
coal = new ItemAmmoType(Items.coal);
|
||||||
thorium = new ItemAmmoType(Items.thorium);
|
thorium = new ItemAmmoType(Items.thorium);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,31 +42,29 @@ public class AmmoTypes implements ContentList{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resupply(Unit unit){
|
public void resupply(Unit unit){
|
||||||
float range = unit.hitSize + 60f;
|
float range = unit.hitSize + this.range;
|
||||||
Tile closest = Vars.indexer.findClosestFlag(unit.x, unit.y, unit.team, BlockFlag.battery);
|
|
||||||
|
|
||||||
if(closest != null && closest.build != null && unit.within(closest.build, range) && closest.build.power != null){
|
Building build = Units.closestBuilding(unit.team, unit.x, unit.y, range, u -> u.block.hasPower && u.block.consumes.getPower().buffered);
|
||||||
var build = closest.build;
|
|
||||||
|
|
||||||
if(build.block.consumes.hasPower() && build.block.consumes.getPower().buffered){
|
if(build != null){
|
||||||
float amount = closest.build.power.status * build.block.consumes.getPower().capacity;
|
float amount = build.power.status * build.block.consumes.getPower().capacity;
|
||||||
float powerPerAmmo = totalPower / unit.type.ammoCapacity;
|
float powerPerAmmo = totalPower / unit.type.ammoCapacity;
|
||||||
float ammoRequired = unit.type.ammoCapacity - unit.ammo;
|
float ammoRequired = unit.type.ammoCapacity - unit.ammo;
|
||||||
float powerRequired = ammoRequired * powerPerAmmo;
|
float powerRequired = ammoRequired * powerPerAmmo;
|
||||||
float powerTaken = Math.min(amount, powerRequired);
|
float powerTaken = Math.min(amount, powerRequired);
|
||||||
|
|
||||||
if(powerTaken > 1){
|
if(powerTaken > 1){
|
||||||
closest.build.power.status -= powerTaken / build.block.consumes.getPower().capacity;
|
build.power.status -= powerTaken / build.block.consumes.getPower().capacity;
|
||||||
unit.ammo += powerTaken / powerPerAmmo;
|
unit.ammo += powerTaken / powerPerAmmo;
|
||||||
|
|
||||||
Fx.itemTransfer.at(build.x, build.y, Math.max(powerTaken / 100f, 1f), Pal.power, unit);
|
Fx.itemTransfer.at(build.x, build.y, Math.max(powerTaken / 100f, 1f), Pal.power, unit);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ItemAmmoType extends AmmoType{
|
public static class ItemAmmoType extends AmmoType{
|
||||||
|
public int ammoPerItem = 15;
|
||||||
public Item item;
|
public Item item;
|
||||||
|
|
||||||
public ItemAmmoType(Item item){
|
public ItemAmmoType(Item item){
|
||||||
@@ -75,6 +75,22 @@ public class AmmoTypes implements ContentList{
|
|||||||
public ItemAmmoType(){
|
public ItemAmmoType(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resupply(Unit unit){
|
||||||
|
//do not resupply when it would waste resources
|
||||||
|
if(unit.type.ammoCapacity - unit.ammo < ammoPerItem) return;
|
||||||
|
|
||||||
|
float range = unit.hitSize + this.range;
|
||||||
|
|
||||||
|
Building build = Units.closestBuilding(unit.team, unit.x, unit.y, range, u -> u.block.allowResupply && u.items.has(item));
|
||||||
|
|
||||||
|
if(build != null){
|
||||||
|
Fx.itemTransfer.at(build.x, build.y, ammoPerItem / 2f, item.color, unit);
|
||||||
|
unit.ammo = Math.min(unit.ammo + ammoPerItem, unit.type.ammoCapacity);
|
||||||
|
build.items.remove(item, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(){
|
public void load(){
|
||||||
if(item != null){
|
if(item != null){
|
||||||
|
|||||||
@@ -89,9 +89,6 @@ public class UnitType extends UnlockableContent{
|
|||||||
public float legSplashDamage = 0f, legSplashRange = 5;
|
public float legSplashDamage = 0f, legSplashRange = 5;
|
||||||
public boolean flipBackLegs = true;
|
public boolean flipBackLegs = true;
|
||||||
|
|
||||||
public int ammoResupplyAmount = 10;
|
|
||||||
public float ammoResupplyRange = 100f;
|
|
||||||
|
|
||||||
public float mechSideSway = 0.54f, mechFrontSway = 0.1f;
|
public float mechSideSway = 0.54f, mechFrontSway = 0.1f;
|
||||||
public float mechStride = -1f;
|
public float mechStride = -1f;
|
||||||
public float mechStepShake = -1f;
|
public float mechStepShake = -1f;
|
||||||
|
|||||||
@@ -70,8 +70,10 @@ public class Block extends UnlockableContent{
|
|||||||
public boolean update;
|
public boolean update;
|
||||||
/** whether this block has health and can be destroyed */
|
/** whether this block has health and can be destroyed */
|
||||||
public boolean destructible;
|
public boolean destructible;
|
||||||
/** whether unloaders work on this block*/
|
/** whether unloaders work on this block */
|
||||||
public boolean unloadable = true;
|
public boolean unloadable = true;
|
||||||
|
/** whether units can resupply by taking items from this block */
|
||||||
|
public boolean allowResupply = false;
|
||||||
/** whether this is solid */
|
/** whether this is solid */
|
||||||
public boolean solid;
|
public boolean solid;
|
||||||
/** whether this block CAN be solid. */
|
/** whether this block CAN be solid. */
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import mindustry.logic.*;
|
|||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
import mindustry.world.consumers.*;
|
|
||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
@@ -42,7 +41,6 @@ public class LaunchPad extends Block{
|
|||||||
solid = true;
|
solid = true;
|
||||||
update = true;
|
update = true;
|
||||||
configurable = true;
|
configurable = true;
|
||||||
drawDisabled = false;
|
|
||||||
flags = EnumSet.of(BlockFlag.launchPad);
|
flags = EnumSet.of(BlockFlag.launchPad);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,12 +71,6 @@ public class LaunchPad extends Block{
|
|||||||
return !state.isCampaign() || net.client() ? SystemCursor.arrow : super.getCursor();
|
return !state.isCampaign() || net.client() ? SystemCursor.arrow : super.getCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
//cannot be disabled
|
|
||||||
@Override
|
|
||||||
public float efficiency(){
|
|
||||||
return power != null && (block.consumes.has(ConsumeType.power) && !block.consumes.getPower().buffered) ? power.status : 1f;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldConsume(){
|
public boolean shouldConsume(){
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import mindustry.logic.*;
|
|||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
import mindustry.world.blocks.units.*;
|
|
||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
import mindustry.world.modules.*;
|
import mindustry.world.modules.*;
|
||||||
|
|
||||||
@@ -32,13 +31,7 @@ public class CoreBlock extends StorageBlock{
|
|||||||
|
|
||||||
public UnitType unitType = UnitTypes.alpha;
|
public UnitType unitType = UnitTypes.alpha;
|
||||||
|
|
||||||
public final int timerResupply = timers++;
|
|
||||||
|
|
||||||
public int ammoAmount = 5;
|
|
||||||
public float resupplyRate = 10f;
|
|
||||||
public float resupplyRange = 60f;
|
|
||||||
public float captureInvicibility = 60f * 15f;
|
public float captureInvicibility = 60f * 15f;
|
||||||
public Item resupplyItem = Items.copper;
|
|
||||||
|
|
||||||
public CoreBlock(String name){
|
public CoreBlock(String name){
|
||||||
super(name);
|
super(name);
|
||||||
@@ -240,13 +233,7 @@ public class CoreBlock extends StorageBlock{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTile(){
|
public void updateTile(){
|
||||||
|
|
||||||
iframes -= Time.delta;
|
iframes -= Time.delta;
|
||||||
|
|
||||||
//resupply nearby units
|
|
||||||
if(items.has(resupplyItem) && timer(timerResupply, resupplyRate) && ResupplyPoint.resupply(this, resupplyRange, ammoAmount, resupplyItem.color)){
|
|
||||||
items.remove(resupplyItem, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public class StorageBlock extends Block{
|
|||||||
destructible = true;
|
destructible = true;
|
||||||
group = BlockGroup.transportation;
|
group = BlockGroup.transportation;
|
||||||
flags = EnumSet.of(BlockFlag.storage);
|
flags = EnumSet.of(BlockFlag.storage);
|
||||||
|
allowResupply = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
package mindustry.world.blocks.units;
|
|
||||||
|
|
||||||
import arc.func.*;
|
|
||||||
import arc.graphics.*;
|
|
||||||
import arc.struct.*;
|
|
||||||
import mindustry.content.*;
|
|
||||||
import mindustry.entities.*;
|
|
||||||
import mindustry.game.*;
|
|
||||||
import mindustry.gen.*;
|
|
||||||
import mindustry.graphics.*;
|
|
||||||
import mindustry.type.AmmoTypes.*;
|
|
||||||
import mindustry.world.*;
|
|
||||||
import mindustry.world.meta.*;
|
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
|
||||||
|
|
||||||
public class ResupplyPoint extends Block{
|
|
||||||
public final int timerResupply = timers++;
|
|
||||||
|
|
||||||
public int ammoAmount = 10;
|
|
||||||
public float resupplyRate = 5f;
|
|
||||||
public float range = 60f;
|
|
||||||
public Color ammoColor = Items.copper.color;
|
|
||||||
|
|
||||||
public ResupplyPoint(String name){
|
|
||||||
super(name);
|
|
||||||
solid = update = true;
|
|
||||||
hasItems = true;
|
|
||||||
flags = EnumSet.of(BlockFlag.resupply);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean outputsItems(){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
|
||||||
Drawf.dashCircle(x * tilesize + offset, y * tilesize + offset, range, Pal.placing);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ResupplyPointBuild extends Building{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void drawSelect(){
|
|
||||||
Drawf.dashCircle(x, y, range, team.color);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateTile(){
|
|
||||||
if(consValid() && timer(timerResupply, resupplyRate / timeScale) && resupply(this, range, ammoAmount, ammoColor)){
|
|
||||||
consume();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Tries to resupply nearby units.
|
|
||||||
* @return whether resupplying was successful. If unit ammo is disabled, always returns false. */
|
|
||||||
public static boolean resupply(Building tile, float range, float ammoAmount, Color ammoColor){
|
|
||||||
return resupply(tile.team, tile.x, tile.y, range, ammoAmount, ammoColor, u -> true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Tries to resupply nearby units.
|
|
||||||
* @return whether resupplying was successful. If unit ammo is disabled, always returns false. */
|
|
||||||
public static boolean resupply(Team team, float x, float y, float range, float ammoAmount, Color ammoColor, Boolf<Unit> valid){
|
|
||||||
if(!state.rules.unitAmmo) return false;
|
|
||||||
|
|
||||||
Unit unit = Units.closest(team, x, y, range, u -> u.type.ammoType instanceof ItemAmmoType && u.ammo <= u.type.ammoCapacity - ammoAmount && valid.get(u));
|
|
||||||
if(unit != null){
|
|
||||||
Fx.itemTransfer.at(x, y, ammoAmount / 2f, ammoColor, unit);
|
|
||||||
unit.ammo = Math.min(unit.ammo + ammoAmount, unit.type.ammoCapacity);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,8 +18,6 @@ public enum BlockFlag{
|
|||||||
rally,
|
rally,
|
||||||
/** Block that stored power for resupply. */
|
/** Block that stored power for resupply. */
|
||||||
battery,
|
battery,
|
||||||
/** Block used for resupply. */
|
|
||||||
resupply,
|
|
||||||
/** Any reactor block. */
|
/** Any reactor block. */
|
||||||
reactor,
|
reactor,
|
||||||
/** This flag is unused, and will be removed. */
|
/** This flag is unused, and will be removed. */
|
||||||
@@ -33,5 +31,5 @@ public enum BlockFlag{
|
|||||||
public final static BlockFlag[] all = values();
|
public final static BlockFlag[] all = values();
|
||||||
|
|
||||||
/** Values for logic only. Filters out some internal flags. */
|
/** Values for logic only. Filters out some internal flags. */
|
||||||
public final static BlockFlag[] allLogic = {core, storage, generator, turret, factory, repair, rally, battery, resupply, reactor};
|
public final static BlockFlag[] allLogic = {core, storage, generator, turret, factory, repair, rally, battery, reactor};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user