Prototype unit cap mechanic
This commit is contained in:
@@ -106,6 +106,9 @@ public class Block extends UnlockableContent{
|
||||
public EnumSet<BlockFlag> flags = EnumSet.of();
|
||||
/** Targeting priority of this block, as seen by enemies.*/
|
||||
public TargetPriority priority = TargetPriority.base;
|
||||
/** How much this block affects the unit cap by.
|
||||
* The block flags must contain unitModifier in order for this to work. */
|
||||
public int unitCapModifier = 0;
|
||||
/** Whether the block can be tapped and selected to configure. */
|
||||
public boolean configurable;
|
||||
/** Whether this block consumes touchDown events when tapped. */
|
||||
|
||||
@@ -8,6 +8,7 @@ import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
@@ -28,7 +29,8 @@ public class CoreBlock extends StorageBlock{
|
||||
solid = true;
|
||||
update = true;
|
||||
hasItems = true;
|
||||
flags = EnumSet.of(BlockFlag.core, BlockFlag.producer);
|
||||
flags = EnumSet.of(BlockFlag.core, BlockFlag.producer, BlockFlag.unitModifier);
|
||||
unitCapModifier = 30;
|
||||
activeSound = Sounds.respawning;
|
||||
activeSoundVolume = 1f;
|
||||
}
|
||||
@@ -59,6 +61,13 @@ public class CoreBlock extends StorageBlock{
|
||||
() -> Pal.items,
|
||||
() -> e.items().total() / (float)(((CoreEntity)e).storageCapacity * content.items().count(i -> i.type == ItemType.material))
|
||||
));
|
||||
|
||||
bars.add("units", e ->
|
||||
new Bar(
|
||||
() -> Core.bundle.format("bar.units", teamIndex.count(e.team()), Units.getCap(e.team())),
|
||||
() -> Pal.power,
|
||||
() -> (float)teamIndex.count(e.team()) / Units.getCap(e.team())
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
package mindustry.world.blocks.units;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.ai.BlockIndexer.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class CommandCenter extends Block{
|
||||
protected TextureRegionDrawable[] commandRegions = new TextureRegionDrawable[UnitCommand.all.length];
|
||||
protected Color topColor = Pal.command;
|
||||
protected Color bottomColor = Color.valueOf("5e5e5e");
|
||||
protected Effect effect = Fx.commandSend;
|
||||
|
||||
public CommandCenter(String name){
|
||||
super(name);
|
||||
|
||||
flags = EnumSet.of(BlockFlag.comandCenter);
|
||||
destructible = true;
|
||||
solid = true;
|
||||
configurable = true;
|
||||
config(Integer.class, (tile, value) -> {
|
||||
UnitCommand command = UnitCommand.all[value];
|
||||
((CommandCenter)tile.block()).effect.at(tile);
|
||||
|
||||
for(Tile center : indexer.getAllied(tile.team(), BlockFlag.comandCenter)){
|
||||
if(center.block() instanceof CommandCenter){
|
||||
CommandCenterEntity entity = center.ent();
|
||||
entity.command = command;
|
||||
}
|
||||
}
|
||||
|
||||
Groups.unit.each(t -> t.team() == tile.team(), u -> u.controller().command(command));
|
||||
Events.fire(new CommandIssueEvent(tile, command));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
super.load();
|
||||
|
||||
if(ui != null){
|
||||
for(UnitCommand cmd : UnitCommand.all){
|
||||
commandRegions[cmd.ordinal()] = ui.getIcon("command" + Strings.capitalize(cmd.name()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CommandCenterEntity extends TileEntity{
|
||||
public UnitCommand command = UnitCommand.attack;
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
super.draw();
|
||||
|
||||
float size = 6f;
|
||||
|
||||
Draw.color(bottomColor);
|
||||
Draw.rect(commandRegions[command.ordinal()].getRegion(), x, y - 1, size, size);
|
||||
Draw.color(topColor);
|
||||
Draw.rect(commandRegions[command.ordinal()].getRegion(), x, y, size, size);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildConfiguration(Table table){
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
Table buttons = new Table();
|
||||
|
||||
for(UnitCommand cmd : UnitCommand.all){
|
||||
buttons.button(commandRegions[cmd.ordinal()], Styles.clearToggleTransi, () -> configure(cmd.ordinal()))
|
||||
.size(44).group(group).update(b -> b.setChecked(command == cmd));
|
||||
}
|
||||
table.add(buttons);
|
||||
table.row();
|
||||
table.label(() -> command.localized()).style(Styles.outlineLabel).center().growX().get().setAlignment(Align.center);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placed(){
|
||||
super.placed();
|
||||
TileArray set = indexer.getAllied(team, BlockFlag.comandCenter);
|
||||
|
||||
if(set.size() > 0){
|
||||
CommandCenterEntity oe = set.first().ent();
|
||||
command = oe.command;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoved(){
|
||||
super.onRemoved();
|
||||
|
||||
TileArray set = indexer.getAllied(team, BlockFlag.comandCenter);
|
||||
|
||||
if(set.size() == 1){
|
||||
Groups.unit.each(t -> t.team() == team, u -> u.controller().command(UnitCommand.all[0]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer config(){
|
||||
return command.ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.b(command.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
command = UnitCommand.all[read.b()];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,7 +220,7 @@ public class UnitFactory extends Block{
|
||||
if(currentPlan != -1){
|
||||
UnitPlan plan = plans[currentPlan];
|
||||
|
||||
if(progress >= plan.time/* && !Units.anyEntities(tile, !plan.unit.flying)*/){
|
||||
if(progress >= plan.time/* && !Units.anyEntities(tile, !plan.unit.flying)*/ && Units.canCreate(team)){
|
||||
progress = 0f;
|
||||
|
||||
Call.onUnitFactorySpawn(tile);
|
||||
|
||||
@@ -4,18 +4,14 @@ package mindustry.world.meta;
|
||||
public enum BlockFlag{
|
||||
/** Enemy core; primary target for all units. */
|
||||
core,
|
||||
/** Rally point for units.*/
|
||||
rally,
|
||||
/** Producer of important goods. */
|
||||
producer,
|
||||
/** A turret. */
|
||||
turret,
|
||||
/** Only the command center block.*/
|
||||
comandCenter,
|
||||
/** Repair point. */
|
||||
repair,
|
||||
/** Upgrade pad. */
|
||||
mechPad;
|
||||
/** Any block that boosts unit capacity. */
|
||||
unitModifier;
|
||||
|
||||
public final static BlockFlag[] all = values();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user