Added basic command center logic
This commit is contained in:
@@ -156,9 +156,7 @@ project(":core") {
|
|||||||
|
|
||||||
def comp = System.properties["release"] == null || System.properties["release"] == "false"
|
def comp = System.properties["release"] == null || System.properties["release"] == "false"
|
||||||
|
|
||||||
if(!comp){
|
if(!comp) println("Note: Compiling release build.")
|
||||||
println("Note: Compiling release build.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(new File(projectDir.parent, '../uCore').exists() && comp){
|
if(new File(projectDir.parent, '../uCore').exists() && comp){
|
||||||
compile project(":uCore")
|
compile project(":uCore")
|
||||||
|
|||||||
@@ -58,9 +58,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
|||||||
protected Squad squad;
|
protected Squad squad;
|
||||||
protected int spawner;
|
protected int spawner;
|
||||||
|
|
||||||
/**
|
/**internal constructor used for deserialization, DO NOT USE*/
|
||||||
* internal constructor used for deserialization, DO NOT USE
|
|
||||||
*/
|
|
||||||
public BaseUnit(){
|
public BaseUnit(){
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,9 +84,10 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
|||||||
threads.runDelay(unit::remove);
|
threads.runDelay(unit::remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**Called when a command is recieved from the command center.*/
|
||||||
* Initialize the type and team of this unit. Only call once!
|
public abstract void onCommand(UnitCommand command);
|
||||||
*/
|
|
||||||
|
/**Initialize the type and team of this unit. Only call once!*/
|
||||||
public void init(UnitType type, Team team){
|
public void init(UnitType type, Team team){
|
||||||
if(this.type != null) throw new RuntimeException("This unit is already initialized!");
|
if(this.type != null) throw new RuntimeException("This unit is already initialized!");
|
||||||
|
|
||||||
@@ -108,9 +107,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
|||||||
this.spawner = tile.packedPosition();
|
this.spawner = tile.packedPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**Sets this to a 'wave' unit, which means it has slightly different AI and will not run out of ammo.*/
|
||||||
* Sets this to a 'wave' unit, which means it has slightly different AI and will not run out of ammo.
|
|
||||||
*/
|
|
||||||
public void setWave(){
|
public void setWave(){
|
||||||
isWave = true;
|
isWave = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ import static io.anuke.mindustry.Vars.world;
|
|||||||
public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
||||||
protected static Translator vec = new Translator();
|
protected static Translator vec = new Translator();
|
||||||
protected static float wobblyness = 0.6f;
|
protected static float wobblyness = 0.6f;
|
||||||
|
|
||||||
|
protected Trail trail = new Trail(8);
|
||||||
|
protected CarriableTrait carrying;
|
||||||
protected final UnitState
|
protected final UnitState
|
||||||
|
|
||||||
resupply = new UnitState(){
|
resupply = new UnitState(){
|
||||||
@@ -115,14 +118,20 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
protected Trail trail = new Trail(8);
|
|
||||||
protected CarriableTrait carrying;
|
|
||||||
|
|
||||||
//instantiation only
|
//instantiation only
|
||||||
public FlyingUnit(){
|
public FlyingUnit(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCommand(UnitCommand command){
|
||||||
|
state.set(command == UnitCommand.retreat ? retreat :
|
||||||
|
(command == UnitCommand.attack ? attack :
|
||||||
|
(command == UnitCommand.idle ? resupply :
|
||||||
|
(null))));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CarriableTrait getCarry(){
|
public CarriableTrait getCarry(){
|
||||||
return carrying;
|
return carrying;
|
||||||
|
|||||||
@@ -31,9 +31,11 @@ public abstract class GroundUnit extends BaseUnit{
|
|||||||
|
|
||||||
protected float walkTime;
|
protected float walkTime;
|
||||||
protected float baseRotation;
|
protected float baseRotation;
|
||||||
|
protected Weapon weapon;
|
||||||
|
|
||||||
public final UnitState
|
public final UnitState
|
||||||
|
|
||||||
resupply = new UnitState(){
|
resupply = new UnitState(){
|
||||||
public void entered(){
|
public void entered(){
|
||||||
target = null;
|
target = null;
|
||||||
}
|
}
|
||||||
@@ -51,64 +53,71 @@ public abstract class GroundUnit extends BaseUnit{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
attack = new UnitState(){
|
attack = new UnitState(){
|
||||||
public void entered(){
|
public void entered(){
|
||||||
target = null;
|
target = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(){
|
public void update(){
|
||||||
TileEntity core = getClosestEnemyCore();
|
TileEntity core = getClosestEnemyCore();
|
||||||
float dst = core == null ? 0 : distanceTo(core);
|
float dst = core == null ? 0 : distanceTo(core);
|
||||||
|
|
||||||
if(core != null && inventory.hasAmmo() && dst < inventory.getAmmo().getRange() / 1.1f){
|
if(core != null && inventory.hasAmmo() && dst < inventory.getAmmo().getRange() / 1.1f){
|
||||||
target = core;
|
target = core;
|
||||||
}else{
|
}else{
|
||||||
retarget(() -> targetClosest());
|
retarget(() -> targetClosest());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!inventory.hasAmmo()){
|
if(!inventory.hasAmmo()){
|
||||||
state.set(resupply);
|
state.set(resupply);
|
||||||
}else if(target != null){
|
}else if(target != null){
|
||||||
if(core != null){
|
if(core != null){
|
||||||
if(dst > inventory.getAmmo().getRange() * 0.5f){
|
if(dst > inventory.getAmmo().getRange() * 0.5f){
|
||||||
moveToCore();
|
|
||||||
}
|
|
||||||
|
|
||||||
}else{
|
|
||||||
moveToCore();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(distanceTo(target) < inventory.getAmmo().getRange()){
|
|
||||||
rotate(angleTo(target));
|
|
||||||
|
|
||||||
if(Mathf.angNear(angleTo(target), rotation, 13f)){
|
|
||||||
AmmoType ammo = inventory.getAmmo();
|
|
||||||
|
|
||||||
Vector2 to = Predict.intercept(GroundUnit.this, target, ammo.bullet.speed);
|
|
||||||
|
|
||||||
getWeapon().update(GroundUnit.this, to.x, to.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}else{
|
|
||||||
moveToCore();
|
moveToCore();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
}else{
|
||||||
retreat = new UnitState(){
|
moveToCore();
|
||||||
public void entered(){
|
|
||||||
target = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(){
|
if(distanceTo(target) < inventory.getAmmo().getRange()){
|
||||||
if(health >= health){
|
rotate(angleTo(target));
|
||||||
state.set(attack);
|
|
||||||
|
if(Mathf.angNear(angleTo(target), rotation, 13f)){
|
||||||
|
AmmoType ammo = inventory.getAmmo();
|
||||||
|
|
||||||
|
Vector2 to = Predict.intercept(GroundUnit.this, target, ammo.bullet.speed);
|
||||||
|
|
||||||
|
getWeapon().update(GroundUnit.this, to.x, to.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
moveAwayFromCore();
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
protected Weapon weapon;
|
}else{
|
||||||
|
moveToCore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
retreat = new UnitState(){
|
||||||
|
public void entered(){
|
||||||
|
target = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(){
|
||||||
|
if(health >= health){
|
||||||
|
state.set(attack);
|
||||||
|
}
|
||||||
|
|
||||||
|
moveAwayFromCore();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCommand(UnitCommand command){
|
||||||
|
state.set(command == UnitCommand.retreat ? retreat :
|
||||||
|
(command == UnitCommand.attack ? attack :
|
||||||
|
(command == UnitCommand.idle ? resupply :
|
||||||
|
(null))));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(UnitType type, Team team){
|
public void init(UnitType type, Team team){
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package io.anuke.mindustry.entities.units;
|
||||||
|
|
||||||
|
public enum UnitCommand{
|
||||||
|
attack, retreat, idle
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import io.anuke.mindustry.entities.traits.CarriableTrait;
|
|||||||
import io.anuke.mindustry.entities.traits.CarryTrait;
|
import io.anuke.mindustry.entities.traits.CarryTrait;
|
||||||
import io.anuke.mindustry.entities.traits.ShooterTrait;
|
import io.anuke.mindustry.entities.traits.ShooterTrait;
|
||||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
import io.anuke.mindustry.entities.units.BaseUnit;
|
||||||
|
import io.anuke.mindustry.entities.units.UnitCommand;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.net.Packets.AdminAction;
|
import io.anuke.mindustry.net.Packets.AdminAction;
|
||||||
import io.anuke.mindustry.net.Packets.KickReason;
|
import io.anuke.mindustry.net.Packets.KickReason;
|
||||||
@@ -185,6 +186,16 @@ public class TypeIO{
|
|||||||
return AdminAction.values()[buffer.get()];
|
return AdminAction.values()[buffer.get()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WriteClass(UnitCommand.class)
|
||||||
|
public static void writeCommand(ByteBuffer buffer, UnitCommand reason){
|
||||||
|
buffer.put((byte) reason.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReadClass(UnitCommand.class)
|
||||||
|
public static UnitCommand readCommand(ByteBuffer buffer){
|
||||||
|
return UnitCommand.values()[buffer.get()];
|
||||||
|
}
|
||||||
|
|
||||||
@WriteClass(Effect.class)
|
@WriteClass(Effect.class)
|
||||||
public static void writeEffect(ByteBuffer buffer, Effect effect){
|
public static void writeEffect(ByteBuffer buffer, Effect effect){
|
||||||
buffer.putShort((short) effect.id);
|
buffer.putShort((short) effect.id);
|
||||||
|
|||||||
@@ -1,10 +1,25 @@
|
|||||||
package io.anuke.mindustry.world.blocks.units;
|
package io.anuke.mindustry.world.blocks.units;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
|
import io.anuke.mindustry.entities.Player;
|
||||||
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
|
import io.anuke.mindustry.entities.units.BaseUnit;
|
||||||
|
import io.anuke.mindustry.entities.units.UnitCommand;
|
||||||
|
import io.anuke.mindustry.net.In;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.meta.BlockFlag;
|
import io.anuke.mindustry.world.meta.BlockFlag;
|
||||||
|
import io.anuke.ucore.graphics.Draw;
|
||||||
|
import io.anuke.ucore.scene.ui.layout.Table;
|
||||||
import io.anuke.ucore.util.EnumSet;
|
import io.anuke.ucore.util.EnumSet;
|
||||||
|
|
||||||
|
import static io.anuke.mindustry.Vars.unitGroups;
|
||||||
|
import static io.anuke.mindustry.Vars.world;
|
||||||
|
|
||||||
public class CommandCenter extends Block{
|
public class CommandCenter extends Block{
|
||||||
|
protected TextureRegion[] commandRegions = new TextureRegion[UnitCommand.values().length];
|
||||||
|
|
||||||
public CommandCenter(String name){
|
public CommandCenter(String name){
|
||||||
super(name);
|
super(name);
|
||||||
@@ -15,5 +30,48 @@ public class CommandCenter extends Block{
|
|||||||
configurable = true;
|
configurable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(){
|
||||||
|
super.load();
|
||||||
|
|
||||||
|
for(UnitCommand cmd : UnitCommand.values()){
|
||||||
|
commandRegions[cmd.ordinal()] = Draw.region("command-" + cmd.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Tile tile){
|
||||||
|
CommandCenterEntity entity = tile.entity();
|
||||||
|
super.draw(tile);
|
||||||
|
|
||||||
|
Draw.rect(commandRegions[entity.command.ordinal()], tile.drawx(), tile.drawy());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void buildTable(Tile tile, Table table){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
@Remote(called = Loc.server, forward = true, in = In.blocks, targets = Loc.both)
|
||||||
|
public static void onCommandCenterSet(Player player, Tile tile, UnitCommand command){
|
||||||
|
for(Tile center : world.indexer().getAllied(tile.getTeam(), BlockFlag.comandCenter)){
|
||||||
|
if(center.block() instanceof CommandCenter){
|
||||||
|
CommandCenterEntity entity = tile.entity();
|
||||||
|
entity.command = command;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(BaseUnit unit : unitGroups[player.getTeam().ordinal()].all()){
|
||||||
|
unit.onCommand(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TileEntity getEntity(){
|
||||||
|
return new CommandCenterEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
class CommandCenterEntity extends TileEntity{
|
||||||
|
UnitCommand command = UnitCommand.idle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user