From b789394efccab453c4485c88e17530f6b6e31d5e Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 15 Jun 2020 19:26:03 -0400 Subject: [PATCH] TextField fixes --- core/src/mindustry/content/UnitTypes.java | 1 - core/src/mindustry/entities/comp/WeaponsComp.java | 11 +++++++++-- core/src/mindustry/game/Rules.java | 2 ++ core/src/mindustry/type/UnitType.java | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index c356127a6b..ada48ba6a5 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -514,7 +514,6 @@ public class UnitTypes implements ContentList{ shootEffect = Fx.shootSmall; smokeEffect = Fx.shootSmallSmoke; tileDamageMultiplier = 0.15f; - ammoMultiplier = 2; }}; }}); }}; diff --git a/core/src/mindustry/entities/comp/WeaponsComp.java b/core/src/mindustry/entities/comp/WeaponsComp.java index 03bb238722..68ed127fb2 100644 --- a/core/src/mindustry/entities/comp/WeaponsComp.java +++ b/core/src/mindustry/entities/comp/WeaponsComp.java @@ -10,11 +10,13 @@ import mindustry.entities.units.*; import mindustry.gen.*; import mindustry.type.*; +import static mindustry.Vars.*; + @Component abstract class WeaponsComp implements Teamc, Posc, Rotc{ @Import float x, y, rotation; - /** minimum cursor distance from player, fixes 'cross-eyed' shooting */ + /** minimum cursor distance from unit, fixes 'cross-eyed' shooting */ static final float minAimDst = 20f; /** temporary weapon sequence number */ static int sequenceNum = 0; @@ -24,6 +26,7 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{ @ReadOnly transient float range, aimX, aimY; @ReadOnly transient boolean isRotate; boolean isShooting; + int ammo; void setWeaponRotation(float rotation){ for(WeaponMount mount : mounts){ @@ -94,7 +97,7 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{ mount.targetRotation = angleTo(mount.aimX, mount.aimY); } - if(mount.shoot){ + if(mount.shoot && (ammo > 0 || !state.rules.unitAmmo)){ float rotation = this.rotation - 90; //shoot if applicable @@ -116,11 +119,15 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{ if(mount.weapon.mirror) mount.side = !mount.side; mount.reload = weapon.reload; } + + ammo --; + if(ammo < 0) ammo = 0; } } } private void shoot(Weapon weapon, float x, float y, float aimX, float aimY, float rotation, int side){ + float baseX = this.x, baseY = this.y; weapon.shootSound.at(x, y, Mathf.random(0.8f, 1.0f)); diff --git a/core/src/mindustry/game/Rules.java b/core/src/mindustry/game/Rules.java index 6329bf8eab..915dd8d450 100644 --- a/core/src/mindustry/game/Rules.java +++ b/core/src/mindustry/game/Rules.java @@ -38,6 +38,8 @@ public class Rules{ public boolean canGameOver = true; /** Whether reactors can explode and damage other blocks. */ public boolean reactorExplosions = true; + /** Whether units use and require ammo. */ + public boolean unitAmmo = false; /** How fast unit pads build units. */ public float unitBuildSpeedMultiplier = 1f; /** How much health units start with. */ diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index 0f80ce6ba2..daaeb32938 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -51,6 +51,7 @@ public class UnitType extends UnlockableContent{ public boolean flipBackLegs = true; public int itemCapacity = 30; + public int ammoCapacity = 100; public int drillTier = -1; public float buildSpeed = 1f, mineSpeed = 1f; @@ -86,6 +87,7 @@ public class UnitType extends UnlockableContent{ Unitc unit = constructor.get(); unit.team(team); unit.type(this); + unit.ammo(ammoCapacity); //fill up on ammo upon creation return unit; }