Re-added command center
This commit is contained in:
@@ -6,6 +6,8 @@ import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class FlyingAI extends AIController{
|
||||
|
||||
@Override
|
||||
@@ -18,7 +20,7 @@ public class FlyingAI extends AIController{
|
||||
unit.wobble();
|
||||
}
|
||||
|
||||
if(target != null && unit.hasWeapons()){
|
||||
if(target != null && unit.hasWeapons() && command() == UnitCommand.attack){
|
||||
if(unit.type().weapons.first().rotate){
|
||||
moveTo(target, unit.range() * 0.8f);
|
||||
unit.lookAt(target);
|
||||
@@ -26,6 +28,15 @@ public class FlyingAI extends AIController{
|
||||
attack(80f);
|
||||
}
|
||||
}
|
||||
|
||||
if(target == null && command() == UnitCommand.attack && state.rules.waves && unit.team == state.rules.defaultTeam){
|
||||
moveTo(getClosestSpawner(), state.rules.dropZoneRadius + 120f);
|
||||
}
|
||||
|
||||
if(command() == UnitCommand.rally){
|
||||
target = targetFlag(unit.x, unit.y, BlockFlag.rally, false);
|
||||
moveTo(target, 60f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,6 +7,7 @@ import mindustry.entities.units.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@@ -19,13 +20,19 @@ public class GroundAI extends AIController{
|
||||
|
||||
Building core = unit.closestEnemyCore();
|
||||
|
||||
if(core != null){
|
||||
if(unit.within(core,unit.range() / 1.1f)){
|
||||
target = core;
|
||||
}
|
||||
if(core != null && unit.within(core, unit.range() / 1.1f)){
|
||||
target = core;
|
||||
}
|
||||
|
||||
if(!unit.within(core, unit.range() * 0.5f)){
|
||||
moveToCore(FlagTarget.enemyCores);
|
||||
if((core == null || !unit.within(core, unit.range() * 0.5f)) && command() == UnitCommand.attack){
|
||||
moveToCore(FlagTarget.enemyCores);
|
||||
}
|
||||
|
||||
if(command() == UnitCommand.rally){
|
||||
Teamc target = targetFlag(unit.x, unit.y, BlockFlag.rally, false);
|
||||
|
||||
if(target != null && !unit.within(target, 70f)){
|
||||
moveToCore(FlagTarget.rallyPoints);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +67,7 @@ public class GroundAI extends AIController{
|
||||
protected void moveToCore(FlagTarget path){
|
||||
Tile tile = unit.tileOn();
|
||||
if(tile == null) return;
|
||||
Tile targetTile = pathfinder.getTargetTile(tile, unit.team(), path);
|
||||
Tile targetTile = pathfinder.getTargetTile(tile, unit.team, path);
|
||||
|
||||
if(tile == targetTile) return;
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import mindustry.world.blocks.experimental.*;
|
||||
import mindustry.world.blocks.legacy.*;
|
||||
import mindustry.world.blocks.liquid.*;
|
||||
import mindustry.world.blocks.logic.*;
|
||||
import mindustry.world.blocks.logic.MessageBlock;
|
||||
import mindustry.world.blocks.power.*;
|
||||
import mindustry.world.blocks.production.*;
|
||||
import mindustry.world.blocks.sandbox.*;
|
||||
@@ -78,6 +77,7 @@ public class Blocks implements ContentList{
|
||||
duo, scatter, scorch, hail, arc, wave, lancer, swarmer, salvo, fuse, ripple, cyclone, spectre, meltdown, segment, parallax,
|
||||
|
||||
//units
|
||||
commandCenter,
|
||||
groundFactory, airFactory, navalFactory,
|
||||
additiveReconstructor, multiplicativeReconstructor, exponentialReconstructor, tetrativeReconstructor,
|
||||
repairPoint, resupplyPoint,
|
||||
@@ -1701,6 +1701,12 @@ public class Blocks implements ContentList{
|
||||
//endregion
|
||||
//region units
|
||||
|
||||
commandCenter = new CommandCenter("command-center"){{
|
||||
requirements(Category.units, ItemStack.with(Items.copper, 200, Items.lead, 250, Items.silicon, 250, Items.graphite, 100));
|
||||
size = 2;
|
||||
health = size * size * 55;
|
||||
}};
|
||||
|
||||
groundFactory = new UnitFactory("ground-factory"){{
|
||||
requirements(Category.units, with(Items.copper, 50, Items.lead, 120, Items.silicon, 80));
|
||||
plans = new UnitPlan[]{
|
||||
@@ -1864,7 +1870,6 @@ public class Blocks implements ContentList{
|
||||
//looked up by name, no ref needed
|
||||
new LegacyMechPad("legacy-mech-pad");
|
||||
new LegacyUnitFactory("legacy-unit-factory");
|
||||
new LegacyCommandCenter("legacy-command-center");
|
||||
|
||||
//endregion
|
||||
//region campaign
|
||||
|
||||
@@ -358,6 +358,10 @@ public class TechTree implements ContentList{
|
||||
});
|
||||
|
||||
node(groundFactory, () -> {
|
||||
node(commandCenter, () -> {
|
||||
|
||||
});
|
||||
|
||||
node(dagger, () -> {
|
||||
node(mace, () -> {
|
||||
node(fortress, () -> {
|
||||
|
||||
@@ -225,12 +225,15 @@ public class UI implements ApplicationListener, Loadable{
|
||||
}
|
||||
|
||||
public TextureRegionDrawable getIcon(String name){
|
||||
if(Icon.icons.containsKey(name)){
|
||||
return Icon.icons.get(name);
|
||||
}
|
||||
if(Icon.icons.containsKey(name)) return Icon.icons.get(name);
|
||||
return Core.atlas.getDrawable("error");
|
||||
}
|
||||
|
||||
public TextureRegionDrawable getIcon(String name, String def){
|
||||
if(Icon.icons.containsKey(name)) return Icon.icons.get(name);
|
||||
return getIcon(def);
|
||||
}
|
||||
|
||||
public void loadAnd(Runnable call){
|
||||
loadAnd("@loading", call);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package mindustry.entities.units;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
@@ -33,6 +35,10 @@ public class AIController implements UnitController{
|
||||
updateMovement();
|
||||
}
|
||||
|
||||
protected UnitCommand command(){
|
||||
return unit.team.data().command;
|
||||
}
|
||||
|
||||
protected void updateMovement(){
|
||||
|
||||
}
|
||||
@@ -115,6 +121,10 @@ public class AIController implements UnitController{
|
||||
|
||||
}
|
||||
|
||||
protected @Nullable Tile getClosestSpawner(){
|
||||
return Geometry.findClosest(unit.x, unit.y, Vars.spawner.getSpawns());
|
||||
}
|
||||
|
||||
protected void circle(Position target, float circleLength){
|
||||
circle(target, circleLength, unit.type().speed);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package mindustry.entities.units;
|
||||
import arc.*;
|
||||
|
||||
public enum UnitCommand{
|
||||
attack, retreat, rally, idle;
|
||||
attack, rally, idle;
|
||||
|
||||
private final String localized;
|
||||
public static final UnitCommand[] all = values();
|
||||
|
||||
@@ -34,7 +34,6 @@ public abstract class SaveFileReader{
|
||||
"titan-factory", "legacy-unit-factory",
|
||||
"fortress-factory", "legacy-unit-factory",
|
||||
|
||||
"command-center", "legacy-command-center",
|
||||
"mass-conveyor", "payload-conveyor"
|
||||
);
|
||||
|
||||
|
||||
@@ -92,6 +92,9 @@ public class TypeIO{
|
||||
write.b((byte)14);
|
||||
write.i(((byte[])object).length);
|
||||
write.b((byte[])object);
|
||||
}else if(object instanceof UnitCommand){
|
||||
write.b((byte)15);
|
||||
write.b(((UnitCommand)object).ordinal());
|
||||
}else{
|
||||
throw new IllegalArgumentException("Unknown object type: " + object.getClass());
|
||||
}
|
||||
@@ -116,6 +119,7 @@ public class TypeIO{
|
||||
case 12: return world.build(read.i());
|
||||
case 13: return LAccess.all[read.s()];
|
||||
case 14: int blen = read.i(); byte[] bytes = new byte[blen]; read.b(bytes); return bytes;
|
||||
case 15: return UnitCommand.all[read.b()];
|
||||
default: throw new IllegalArgumentException("Unknown object type: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package mindustry.world.blocks.legacy;
|
||||
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
public class LegacyCommandCenter extends LegacyBlock{
|
||||
|
||||
public LegacyCommandCenter(String name){
|
||||
super(name);
|
||||
update = true;
|
||||
}
|
||||
|
||||
public class LegacyCommandCenterBuild extends Building{
|
||||
@Override
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
read.b();
|
||||
}
|
||||
}
|
||||
}
|
||||
98
core/src/mindustry/world/blocks/units/CommandCenter.java
Normal file
98
core/src/mindustry/world/blocks/units/CommandCenter.java
Normal file
@@ -0,0 +1,98 @@
|
||||
package mindustry.world.blocks.units;
|
||||
|
||||
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.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
public class CommandCenter extends Block{
|
||||
public TextureRegionDrawable[] commandRegions = new TextureRegionDrawable[UnitCommand.all.length];
|
||||
public Color topColor = Pal.command, bottomColor = Color.valueOf("5e5e5e");
|
||||
public Effect effect = Fx.commandSend;
|
||||
|
||||
public CommandCenter(String name){
|
||||
super(name);
|
||||
|
||||
flags = EnumSet.of(BlockFlag.rally);
|
||||
destructible = true;
|
||||
solid = true;
|
||||
configurable = true;
|
||||
|
||||
config(UnitCommand.class, (CommandBuild build, UnitCommand command) -> {
|
||||
build.team.data().command = command;
|
||||
effect.at(build);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
super.load();
|
||||
|
||||
if(Vars.ui != null){
|
||||
for(UnitCommand cmd : UnitCommand.all){
|
||||
commandRegions[cmd.ordinal()] = Vars.ui.getIcon("command" + Strings.capitalize(cmd.name()), "cancel");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CommandBuild extends Building{
|
||||
|
||||
@Override
|
||||
public Object config(){
|
||||
return team.data().command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
super.draw();
|
||||
|
||||
float size = 6f;
|
||||
|
||||
Draw.color(bottomColor);
|
||||
Draw.rect(commandRegions[team.data().command.ordinal()].getRegion(), tile.drawx(), tile.drawy() - 1, size, size);
|
||||
Draw.color(topColor);
|
||||
Draw.rect(commandRegions[team.data().command.ordinal()].getRegion(), tile.drawx(), tile.drawy(), 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, () -> {
|
||||
if(team.data().command != cmd) configure(cmd);
|
||||
}).size(44).group(group).update(b -> b.setChecked(team.data().command == cmd));
|
||||
}
|
||||
table.add(buttons);
|
||||
table.row();
|
||||
table.label(() -> team.data().command.localized()).style(Styles.outlineLabel).center().growX().get().setAlignment(Align.center);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.b(team.data().command.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Reads read, byte version){
|
||||
super.read(read, version);
|
||||
team.data().command = UnitCommand.all[read.b()];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user