Improved unit commands
This commit is contained in:
@@ -16,7 +16,10 @@ import io.anuke.ucore.util.Tmp;
|
|||||||
import static io.anuke.mindustry.Vars.tilesize;
|
import static io.anuke.mindustry.Vars.tilesize;
|
||||||
|
|
||||||
public class BlockFx extends FxList implements ContentList{
|
public class BlockFx extends FxList implements ContentList{
|
||||||
public static Effect reactorsmoke, nuclearsmoke, nuclearcloud, redgeneratespark, generatespark, fuelburn, plasticburn, pulverize, pulverizeRed, pulverizeRedder, pulverizeSmall, pulverizeMedium, producesmoke, smeltsmoke, formsmoke, blastsmoke, lava, dooropen, doorclose, dooropenlarge, doorcloselarge, purify, purifyoil, purifystone, generate, mine, mineBig, mineHuge, smelt, teleportActivate, teleport, teleportOut, ripple, bubble;
|
public static Effect reactorsmoke, nuclearsmoke, nuclearcloud, redgeneratespark, generatespark, fuelburn, plasticburn,
|
||||||
|
pulverize, pulverizeRed, pulverizeRedder, pulverizeSmall, pulverizeMedium, producesmoke, smeltsmoke, formsmoke, blastsmoke,
|
||||||
|
lava, dooropen, doorclose, dooropenlarge, doorcloselarge, purify, purifyoil, purifystone, generate, mine, mineBig, mineHuge,
|
||||||
|
smelt, teleportActivate, teleport, teleportOut, ripple, bubble, commandSend;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(){
|
public void load(){
|
||||||
@@ -274,5 +277,10 @@ public class BlockFx extends FxList implements ContentList{
|
|||||||
});
|
});
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
commandSend = new Effect(30, e -> {
|
||||||
|
Lines.stroke(e.fout() * 2f);
|
||||||
|
Lines.poly(e.x, e.y, 40, 4f + e.fin() * 120f);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import io.anuke.mindustry.type.Item;
|
|||||||
import io.anuke.mindustry.type.ItemStack;
|
import io.anuke.mindustry.type.ItemStack;
|
||||||
import io.anuke.mindustry.type.Weapon;
|
import io.anuke.mindustry.type.Weapon;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.mindustry.world.blocks.units.CommandCenter.CommandCenterEntity;
|
||||||
import io.anuke.mindustry.world.blocks.units.UnitFactory.UnitFactoryEntity;
|
import io.anuke.mindustry.world.blocks.units.UnitFactory.UnitFactoryEntity;
|
||||||
import io.anuke.mindustry.world.meta.BlockFlag;
|
import io.anuke.mindustry.world.meta.BlockFlag;
|
||||||
import io.anuke.ucore.core.Effects;
|
import io.anuke.ucore.core.Effects;
|
||||||
@@ -40,6 +41,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
|
/**Base class for AI units.*/
|
||||||
public abstract class BaseUnit extends Unit implements ShooterTrait{
|
public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||||
protected static int timerIndex = 0;
|
protected static int timerIndex = 0;
|
||||||
|
|
||||||
@@ -94,6 +96,17 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
|||||||
this.team = team;
|
this.team = team;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isCommanded(){
|
||||||
|
return !isWave && world.indexer().getAllied(team, BlockFlag.comandCenter).size != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitCommand getCommand(){
|
||||||
|
if(isCommanded()){
|
||||||
|
return world.indexer().getAllied(team, BlockFlag.comandCenter).first().<CommandCenterEntity>entity().command;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public UnitType getType(){
|
public UnitType getType(){
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@@ -379,6 +392,10 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
|||||||
state.set(getStartState());
|
state.set(getStartState());
|
||||||
|
|
||||||
health(maxHealth());
|
health(maxHealth());
|
||||||
|
|
||||||
|
if(isCommanded()){
|
||||||
|
onCommand(getCommand());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -46,14 +46,16 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
|||||||
|
|
||||||
idle = new UnitState(){
|
idle = new UnitState(){
|
||||||
public void update(){
|
public void update(){
|
||||||
retarget(() -> {
|
if(!isCommanded()){
|
||||||
targetClosest();
|
retarget(() -> {
|
||||||
targetClosestEnemyFlag(BlockFlag.target);
|
targetClosest();
|
||||||
|
targetClosestEnemyFlag(BlockFlag.target);
|
||||||
|
|
||||||
if(target != null){
|
if(target != null){
|
||||||
setState(attack);
|
setState(attack);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
target = getClosestCore();
|
target = getClosestCore();
|
||||||
if(target != null){
|
if(target != null){
|
||||||
@@ -106,7 +108,7 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update(){
|
public void update(){
|
||||||
if(health >= maxHealth()){
|
if(health >= maxHealth() && !isCommanded()){
|
||||||
state.set(attack);
|
state.set(attack);
|
||||||
}else if(!targetHasFlag(BlockFlag.repair)){
|
}else if(!targetHasFlag(BlockFlag.repair)){
|
||||||
retarget(() -> {
|
retarget(() -> {
|
||||||
@@ -128,7 +130,7 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
|||||||
public void onCommand(UnitCommand command){
|
public void onCommand(UnitCommand command){
|
||||||
state.set(command == UnitCommand.retreat ? retreat :
|
state.set(command == UnitCommand.retreat ? retreat :
|
||||||
(command == UnitCommand.attack ? attack :
|
(command == UnitCommand.attack ? attack :
|
||||||
(command == UnitCommand.idle ? resupply :
|
(command == UnitCommand.idle ? idle :
|
||||||
(null))));
|
(null))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,8 +178,8 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void behavior(){
|
public void behavior(){
|
||||||
if(health <= health * type.retreatPercent && !isWave &&
|
if(health <= health * type.retreatPercent && !isCommanded() &&
|
||||||
Geometry.findClosest(x, y, world.indexer().getAllied(team, BlockFlag.repair)) != null){
|
Geometry.findClosest(x, y, world.indexer().getAllied(team, BlockFlag.repair)) != null){
|
||||||
setState(retreat);
|
setState(retreat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ public abstract class GroundUnit extends BaseUnit{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update(){
|
public void update(){
|
||||||
if(health >= health){
|
if(health >= health && !isCommanded()){
|
||||||
state.set(attack);
|
state.set(attack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +211,7 @@ public abstract class GroundUnit extends BaseUnit{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void behavior(){
|
public void behavior(){
|
||||||
if(health <= health * type.retreatPercent && !isWave){
|
if(health <= health * type.retreatPercent && !isCommanded()){
|
||||||
setState(retreat);
|
setState(retreat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
|||||||
import com.badlogic.gdx.utils.ObjectSet;
|
import com.badlogic.gdx.utils.ObjectSet;
|
||||||
import io.anuke.annotations.Annotations.Loc;
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
import io.anuke.annotations.Annotations.Remote;
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
|
import io.anuke.mindustry.content.fx.BlockFx;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
import io.anuke.mindustry.entities.units.BaseUnit;
|
||||||
@@ -13,6 +14,8 @@ import io.anuke.mindustry.gen.Call;
|
|||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.meta.BlockFlag;
|
import io.anuke.mindustry.world.meta.BlockFlag;
|
||||||
|
import io.anuke.ucore.core.Effects;
|
||||||
|
import io.anuke.ucore.core.Effects.Effect;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.scene.ui.ButtonGroup;
|
import io.anuke.ucore.scene.ui.ButtonGroup;
|
||||||
import io.anuke.ucore.scene.ui.ImageButton;
|
import io.anuke.ucore.scene.ui.ImageButton;
|
||||||
@@ -24,7 +27,8 @@ import static io.anuke.mindustry.Vars.*;
|
|||||||
public class CommandCenter extends Block{
|
public class CommandCenter extends Block{
|
||||||
protected TextureRegion[] commandRegions = new TextureRegion[UnitCommand.values().length];
|
protected TextureRegion[] commandRegions = new TextureRegion[UnitCommand.values().length];
|
||||||
protected Color topColor = Color.valueOf("eab678");
|
protected Color topColor = Color.valueOf("eab678");
|
||||||
protected Color bottomColor = Color.valueOf("d4986b");
|
protected Color bottomColor = Color.valueOf("5e5e5e");
|
||||||
|
protected Effect effect = BlockFx.commandSend;
|
||||||
|
|
||||||
public CommandCenter(String name){
|
public CommandCenter(String name){
|
||||||
super(name);
|
super(name);
|
||||||
@@ -60,7 +64,7 @@ public class CommandCenter extends Block{
|
|||||||
CommandCenterEntity entity = tile.entity();
|
CommandCenterEntity entity = tile.entity();
|
||||||
super.draw(tile);
|
super.draw(tile);
|
||||||
|
|
||||||
Draw.colorl(0.3f);
|
Draw.color(bottomColor);
|
||||||
Draw.rect(commandRegions[entity.command.ordinal()], tile.drawx(), tile.drawy() - 1);
|
Draw.rect(commandRegions[entity.command.ordinal()], tile.drawx(), tile.drawy() - 1);
|
||||||
Draw.color(topColor);
|
Draw.color(topColor);
|
||||||
Draw.rect(commandRegions[entity.command.ordinal()], tile.drawx(), tile.drawy());
|
Draw.rect(commandRegions[entity.command.ordinal()], tile.drawx(), tile.drawy());
|
||||||
@@ -80,6 +84,8 @@ public class CommandCenter extends Block{
|
|||||||
|
|
||||||
@Remote(called = Loc.server, forward = true, targets = Loc.both)
|
@Remote(called = Loc.server, forward = true, targets = Loc.both)
|
||||||
public static void onCommandCenterSet(Player player, Tile tile, UnitCommand command){
|
public static void onCommandCenterSet(Player player, Tile tile, UnitCommand command){
|
||||||
|
Effects.effect(((CommandCenter)tile.block()).effect, tile);
|
||||||
|
|
||||||
for(Tile center : world.indexer().getAllied(tile.getTeam(), BlockFlag.comandCenter)){
|
for(Tile center : world.indexer().getAllied(tile.getTeam(), BlockFlag.comandCenter)){
|
||||||
if(center.block() instanceof CommandCenter){
|
if(center.block() instanceof CommandCenter){
|
||||||
CommandCenterEntity entity = center.entity();
|
CommandCenterEntity entity = center.entity();
|
||||||
@@ -97,7 +103,7 @@ public class CommandCenter extends Block{
|
|||||||
return new CommandCenterEntity();
|
return new CommandCenterEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
class CommandCenterEntity extends TileEntity{
|
public class CommandCenterEntity extends TileEntity{
|
||||||
UnitCommand command = UnitCommand.idle;
|
public UnitCommand command = UnitCommand.idle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user