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;
|
||||
|
||||
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
|
||||
public void load(){
|
||||
@@ -274,5 +277,10 @@ public class BlockFx extends FxList implements ContentList{
|
||||
});
|
||||
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.Weapon;
|
||||
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.meta.BlockFlag;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
@@ -40,6 +41,7 @@ import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
/**Base class for AI units.*/
|
||||
public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
protected static int timerIndex = 0;
|
||||
|
||||
@@ -94,6 +96,17 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
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(){
|
||||
return type;
|
||||
}
|
||||
@@ -379,6 +392,10 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
state.set(getStartState());
|
||||
|
||||
health(maxHealth());
|
||||
|
||||
if(isCommanded()){
|
||||
onCommand(getCommand());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -46,14 +46,16 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
||||
|
||||
idle = new UnitState(){
|
||||
public void update(){
|
||||
retarget(() -> {
|
||||
targetClosest();
|
||||
targetClosestEnemyFlag(BlockFlag.target);
|
||||
if(!isCommanded()){
|
||||
retarget(() -> {
|
||||
targetClosest();
|
||||
targetClosestEnemyFlag(BlockFlag.target);
|
||||
|
||||
if(target != null){
|
||||
setState(attack);
|
||||
}
|
||||
});
|
||||
if(target != null){
|
||||
setState(attack);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
target = getClosestCore();
|
||||
if(target != null){
|
||||
@@ -106,7 +108,7 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(health >= maxHealth()){
|
||||
if(health >= maxHealth() && !isCommanded()){
|
||||
state.set(attack);
|
||||
}else if(!targetHasFlag(BlockFlag.repair)){
|
||||
retarget(() -> {
|
||||
@@ -128,7 +130,7 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
||||
public void onCommand(UnitCommand command){
|
||||
state.set(command == UnitCommand.retreat ? retreat :
|
||||
(command == UnitCommand.attack ? attack :
|
||||
(command == UnitCommand.idle ? resupply :
|
||||
(command == UnitCommand.idle ? idle :
|
||||
(null))));
|
||||
}
|
||||
|
||||
@@ -176,8 +178,8 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
||||
|
||||
@Override
|
||||
public void behavior(){
|
||||
if(health <= health * type.retreatPercent && !isWave &&
|
||||
Geometry.findClosest(x, y, world.indexer().getAllied(team, BlockFlag.repair)) != null){
|
||||
if(health <= health * type.retreatPercent && !isCommanded() &&
|
||||
Geometry.findClosest(x, y, world.indexer().getAllied(team, BlockFlag.repair)) != null){
|
||||
setState(retreat);
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ public abstract class GroundUnit extends BaseUnit{
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(health >= health){
|
||||
if(health >= health && !isCommanded()){
|
||||
state.set(attack);
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ public abstract class GroundUnit extends BaseUnit{
|
||||
|
||||
@Override
|
||||
public void behavior(){
|
||||
if(health <= health * type.retreatPercent && !isWave){
|
||||
if(health <= health * type.retreatPercent && !isCommanded()){
|
||||
setState(retreat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import io.anuke.annotations.Annotations.Loc;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.content.fx.BlockFx;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
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.Tile;
|
||||
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.scene.ui.ButtonGroup;
|
||||
import io.anuke.ucore.scene.ui.ImageButton;
|
||||
@@ -24,7 +27,8 @@ import static io.anuke.mindustry.Vars.*;
|
||||
public class CommandCenter extends Block{
|
||||
protected TextureRegion[] commandRegions = new TextureRegion[UnitCommand.values().length];
|
||||
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){
|
||||
super(name);
|
||||
@@ -60,7 +64,7 @@ public class CommandCenter extends Block{
|
||||
CommandCenterEntity entity = tile.entity();
|
||||
super.draw(tile);
|
||||
|
||||
Draw.colorl(0.3f);
|
||||
Draw.color(bottomColor);
|
||||
Draw.rect(commandRegions[entity.command.ordinal()], tile.drawx(), tile.drawy() - 1);
|
||||
Draw.color(topColor);
|
||||
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)
|
||||
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)){
|
||||
if(center.block() instanceof CommandCenter){
|
||||
CommandCenterEntity entity = center.entity();
|
||||
@@ -97,7 +103,7 @@ public class CommandCenter extends Block{
|
||||
return new CommandCenterEntity();
|
||||
}
|
||||
|
||||
class CommandCenterEntity extends TileEntity{
|
||||
UnitCommand command = UnitCommand.idle;
|
||||
public class CommandCenterEntity extends TileEntity{
|
||||
public UnitCommand command = UnitCommand.idle;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user