Ammo system redesign
This commit is contained in:
@@ -70,8 +70,10 @@ public class Block extends UnlockableContent{
|
||||
public boolean update;
|
||||
/** whether this block has health and can be destroyed */
|
||||
public boolean destructible;
|
||||
/** whether unloaders work on this block*/
|
||||
/** whether unloaders work on this block */
|
||||
public boolean unloadable = true;
|
||||
/** whether units can resupply by taking items from this block */
|
||||
public boolean allowResupply = false;
|
||||
/** whether this is solid */
|
||||
public boolean solid;
|
||||
/** whether this block CAN be solid. */
|
||||
|
||||
@@ -22,7 +22,6 @@ import mindustry.logic.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.consumers.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
@@ -42,7 +41,6 @@ public class LaunchPad extends Block{
|
||||
solid = true;
|
||||
update = true;
|
||||
configurable = true;
|
||||
drawDisabled = false;
|
||||
flags = EnumSet.of(BlockFlag.launchPad);
|
||||
}
|
||||
|
||||
@@ -73,12 +71,6 @@ public class LaunchPad extends Block{
|
||||
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
|
||||
public boolean shouldConsume(){
|
||||
return true;
|
||||
|
||||
@@ -20,7 +20,6 @@ import mindustry.logic.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.units.*;
|
||||
import mindustry.world.meta.*;
|
||||
import mindustry.world.modules.*;
|
||||
|
||||
@@ -32,13 +31,7 @@ public class CoreBlock extends StorageBlock{
|
||||
|
||||
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 Item resupplyItem = Items.copper;
|
||||
|
||||
public CoreBlock(String name){
|
||||
super(name);
|
||||
@@ -240,13 +233,7 @@ public class CoreBlock extends StorageBlock{
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
|
||||
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
|
||||
|
||||
@@ -22,6 +22,7 @@ public class StorageBlock extends Block{
|
||||
destructible = true;
|
||||
group = BlockGroup.transportation;
|
||||
flags = EnumSet.of(BlockFlag.storage);
|
||||
allowResupply = true;
|
||||
}
|
||||
|
||||
@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,
|
||||
/** Block that stored power for resupply. */
|
||||
battery,
|
||||
/** Block used for resupply. */
|
||||
resupply,
|
||||
/** Any reactor block. */
|
||||
reactor,
|
||||
/** This flag is unused, and will be removed. */
|
||||
@@ -33,5 +31,5 @@ public enum BlockFlag{
|
||||
public final static BlockFlag[] all = values();
|
||||
|
||||
/** 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