Unified command

This commit is contained in:
Anuken
2020-10-07 16:37:48 -04:00
parent 261c1b1611
commit 773e4c7053
17 changed files with 74 additions and 68 deletions

View File

@@ -643,7 +643,7 @@ public class EntityProcess extends BaseProcessor{
//assign IDs //assign IDs
definitions.sort(Structs.comparing(t -> t.naming.toString())); definitions.sort(Structs.comparing(t -> t.naming.toString()));
for(EntityDefinition def : definitions){ for(EntityDefinition def : definitions){
String name = def.naming.fullName(); String name = def.name;
if(map.containsKey(name)){ if(map.containsKey(name)){
def.classID = map.getInt(name); def.classID = map.getInt(name);
}else{ }else{

View File

@@ -2,11 +2,11 @@
alpha=0 alpha=0
atrax=1 atrax=1
block=2 mindustry.gen.BlockUnitUnit=2
corvus=24 mindustry.gen.LegsUnit=24
flare=3 mindustry.gen.UnitEntity=3
mace=4 mindustry.gen.MechUnit=4
mega=5 mindustry.gen.BuilderMinerPayloadUnit=5
mindustry.entities.comp.BuildingComp=6 mindustry.entities.comp.BuildingComp=6
mindustry.entities.comp.BulletComp=7 mindustry.entities.comp.BulletComp=7
mindustry.entities.comp.DecalComp=8 mindustry.entities.comp.DecalComp=8
@@ -20,12 +20,12 @@ mindustry.entities.comp.PuddleComp=13
mindustry.type.Weather.WeatherStateComp=14 mindustry.type.Weather.WeatherStateComp=14
mindustry.world.blocks.campaign.LaunchPad.LaunchPayloadComp=15 mindustry.world.blocks.campaign.LaunchPad.LaunchPayloadComp=15
mindustry.world.blocks.defense.ForceProjector.ForceDrawComp=22 mindustry.world.blocks.defense.ForceProjector.ForceDrawComp=22
mono=16 mindustry.gen.MinerUnit=16
nova=17 mindustry.gen.BuilderMechMinerUnit=17
oct=26 mindustry.gen.AmmoDistributeBuilderPayloadUnit=26
poly=18 mindustry.gen.BuilderMinerUnit=18
pulsar=19 pulsar=19
quad=23 mindustry.gen.BuilderPayloadUnit=23
risso=20 mindustry.gen.UnitWaterMove=20
spiroct=21 mindustry.gen.BuilderLegsUnit=21
vela=25 vela=25

View File

@@ -0,0 +1 @@
{fields:[{name:ammo,type:float},{name:armor,type:float},{name:controller,type:mindustry.entities.units.UnitController},{name:elevation,type:float},{name:flag,type:double},{name:health,type:float},{name:isShooting,type:boolean},{name:mounts,type:"mindustry.entities.units.WeaponMount[]"},{name:payloads,type:arc.struct.Seq<mindustry.world.blocks.payloads.Payload>},{name:plans,type:arc.struct.Queue<mindustry.entities.units.BuildPlan>},{name:rotation,type:float},{name:shield,type:float},{name:spawnedByCore,type:boolean},{name:stack,type:mindustry.type.ItemStack},{name:statuses,type:arc.struct.Seq<mindustry.entities.units.StatusEntry>},{name:team,type:mindustry.game.Team},{name:type,type:mindustry.type.UnitType},{name:x,type:float},{name:y,type:float}]}

View File

@@ -0,0 +1 @@
{fields:[{name:ammo,type:float},{name:armor,type:float},{name:baseRotation,type:float},{name:controller,type:mindustry.entities.units.UnitController},{name:elevation,type:float},{name:flag,type:double},{name:health,type:float},{name:isShooting,type:boolean},{name:mineTile,type:mindustry.world.Tile},{name:mounts,type:"mindustry.entities.units.WeaponMount[]"},{name:plans,type:arc.struct.Queue<mindustry.entities.units.BuildPlan>},{name:rotation,type:float},{name:shield,type:float},{name:spawnedByCore,type:boolean},{name:stack,type:mindustry.type.ItemStack},{name:statuses,type:arc.struct.Seq<mindustry.entities.units.StatusEntry>},{name:team,type:mindustry.game.Team},{name:type,type:mindustry.type.UnitType},{name:x,type:float},{name:y,type:float}]}

View File

@@ -0,0 +1 @@
{fields:[{name:ammo,type:float},{name:armor,type:float},{name:controller,type:mindustry.entities.units.UnitController},{name:elevation,type:float},{name:flag,type:double},{name:health,type:float},{name:isShooting,type:boolean},{name:mounts,type:"mindustry.entities.units.WeaponMount[]"},{name:rotation,type:float},{name:shield,type:float},{name:spawnedByCore,type:boolean},{name:stack,type:mindustry.type.ItemStack},{name:statuses,type:arc.struct.Seq<mindustry.entities.units.StatusEntry>},{name:team,type:mindustry.game.Team},{name:type,type:mindustry.type.UnitType},{name:x,type:float},{name:y,type:float}]}

View File

@@ -44,7 +44,7 @@ public class BaseAI{
CoreBlock block = (CoreBlock)data.core().block; CoreBlock block = (CoreBlock)data.core().block;
//create AI core unit //create AI core unit
if(!Groups.unit.contains(u -> u.team() == data.team && u.type() == block.unitType)){ if(!state.isEditor() && !Groups.unit.contains(u -> u.team() == data.team && u.type() == block.unitType)){
Unit unit = block.unitType.create(data.team); Unit unit = block.unitType.create(data.team);
unit.set(data.core()); unit.set(data.core());
unit.add(); unit.add();

View File

@@ -69,10 +69,6 @@ public class FormationAI extends AIController implements FormationMember{
@Override @Override
public float formationSize(){ public float formationSize(){
if(unit instanceof Commanderc && ((Commanderc)unit).isCommanding()){
//TODO return formation size
//eturn ((Commanderc)unit).formation().
}
return unit.hitSize * 1f; return unit.hitSize * 1f;
} }

View File

@@ -19,14 +19,14 @@ public class UnitTypes implements ContentList{
//mech //mech
public static @EntityDef({Unitc.class, Mechc.class}) UnitType mace, dagger, crawler, fortress, scepter, reign; public static @EntityDef({Unitc.class, Mechc.class}) UnitType mace, dagger, crawler, fortress, scepter, reign;
//mech + builder + miner + commander //mech + builder + miner
public static @EntityDef({Unitc.class, Mechc.class, Builderc.class, Minerc.class, Commanderc.class}) UnitType nova, pulsar, quasar; public static @EntityDef({Unitc.class, Mechc.class, Builderc.class, Minerc.class}) UnitType nova, pulsar, quasar;
//mech + commander //mech
public static @EntityDef({Unitc.class, Mechc.class, Commanderc.class}) UnitType vela; public static @EntityDef({Unitc.class, Mechc.class}) UnitType vela;
//legs + commander //legs
public static @EntityDef({Unitc.class, Legsc.class, Commanderc.class}) UnitType corvus; public static @EntityDef({Unitc.class, Legsc.class}) UnitType corvus;
//legs //legs
public static @EntityDef({Unitc.class, Legsc.class}) UnitType atrax; public static @EntityDef({Unitc.class, Legsc.class}) UnitType atrax;
@@ -49,14 +49,14 @@ public class UnitTypes implements ContentList{
//air + building + payload //air + building + payload
public static @EntityDef({Unitc.class, Builderc.class, Payloadc.class}) UnitType quad; public static @EntityDef({Unitc.class, Builderc.class, Payloadc.class}) UnitType quad;
//air + building + payload + command //air + building + payload
public static @EntityDef({Unitc.class, Builderc.class, Payloadc.class, Commanderc.class, AmmoDistributec.class}) UnitType oct; public static @EntityDef({Unitc.class, Builderc.class, Payloadc.class, AmmoDistributec.class}) UnitType oct;
//air + building + mining //air + building + mining
public static @EntityDef({Unitc.class, Builderc.class, Minerc.class}) UnitType alpha, beta, gamma; public static @EntityDef({Unitc.class, Builderc.class, Minerc.class}) UnitType alpha, beta, gamma;
//water + commander //water
public static @EntityDef({Unitc.class, WaterMovec.class, Commanderc.class}) UnitType risso, minke, bryde, sei, omura; public static @EntityDef({Unitc.class, WaterMovec.class}) UnitType risso, minke, bryde, sei, omura;
//special block unit type //special block unit type
public static @EntityDef({Unitc.class, BlockUnitc.class}) UnitType block; public static @EntityDef({Unitc.class, BlockUnitc.class}) UnitType block;
@@ -1660,6 +1660,7 @@ public class UnitTypes implements ContentList{
health = 120f; health = 120f;
engineOffset = 6f; engineOffset = 6f;
hitSize = 8f; hitSize = 8f;
commandLimit = 3;
weapons.add(new Weapon("small-basic-weapon"){{ weapons.add(new Weapon("small-basic-weapon"){{
reload = 17f; reload = 17f;
@@ -1696,6 +1697,7 @@ public class UnitTypes implements ContentList{
hitSize = 9f; hitSize = 9f;
rotateShooting = false; rotateShooting = false;
lowAltitude = true; lowAltitude = true;
commandLimit = 5;
weapons.add(new Weapon("small-mount-weapon"){{ weapons.add(new Weapon("small-mount-weapon"){{
top = false; top = false;
@@ -1734,6 +1736,7 @@ public class UnitTypes implements ContentList{
health = 190f; health = 190f;
engineOffset = 6f; engineOffset = 6f;
hitSize = 10f; hitSize = 10f;
commandLimit = 7;
weapons.add(new Weapon("small-mount-weapon"){{ weapons.add(new Weapon("small-mount-weapon"){{
top = false; top = false;

View File

@@ -208,7 +208,7 @@ abstract class BuilderComp implements Unitc{
BuildPlan plan = buildPlan(); BuildPlan plan = buildPlan();
Tile tile = world.tile(plan.x, plan.y); Tile tile = world.tile(plan.x, plan.y);
if(!within(tile, buildingRange) && !state.isEditor()){ if((!within(tile, buildingRange) && !state.isEditor()) || tile == null){
return; return;
} }

View File

@@ -215,9 +215,12 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
return true; return true;
} }
public void applyBoost(float intensity, float duration){ public void applyBoost(float intensity, float duration){
//do not refresh time scale when getting a weaker intensity
if(intensity >= this.timeScale){
timeScaleDuration = Math.max(timeScaleDuration, duration);
}
timeScale = Math.max(timeScale, intensity); timeScale = Math.max(timeScale, intensity);
timeScaleDuration = Math.max(timeScaleDuration, duration);
} }
public Building nearby(int dx, int dy){ public Building nearby(int dx, int dy){

View File

@@ -9,22 +9,25 @@ import mindustry.ai.types.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.entities.*; import mindustry.entities.*;
import mindustry.entities.units.*; import mindustry.entities.units.*;
import mindustry.game.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.type.*;
/** A unit that can command other units. */ /** A unit that can command other units. */
@Component @Component
abstract class CommanderComp implements Unitc{ abstract class CommanderComp implements Entityc, Posc{
private static final Seq<FormationMember> members = new Seq<>(); private static final Seq<FormationMember> members = new Seq<>();
private static final Seq<Unit> units = new Seq<>(); private static final Seq<Unit> units = new Seq<>();
@Import float x, y, rotation; @Import float x, y, rotation, hitSize;
@Import Team team;
@Import UnitType type;
transient @Nullable Formation formation; transient @Nullable Formation formation;
transient Seq<Unit> controlling = new Seq<>(); transient Seq<Unit> controlling = new Seq<>(10);
/** minimum speed of any unit in the formation. */ /** minimum speed of any unit in the formation. */
transient float minFormationSpeed; transient float minFormationSpeed;
@Override
public void update(){ public void update(){
if(formation != null){ if(formation != null){
formation.anchor.set(x, y, /*rotation*/ 0); //TODO rotation set to 0 because rotating is pointless formation.anchor.set(x, y, /*rotation*/ 0); //TODO rotation set to 0 because rotating is pointless
@@ -32,18 +35,15 @@ abstract class CommanderComp implements Unitc{
} }
} }
@Override
public void remove(){ public void remove(){
clearCommand(); clearCommand();
} }
@Override
public void killed(){ public void killed(){
clearCommand(); clearCommand();
} }
//make sure to reset command state when the controller is switched //make sure to reset command state when the controller is switched
@Override
public void controller(UnitController next){ public void controller(UnitController next){
clearCommand(); clearCommand();
} }
@@ -58,14 +58,15 @@ abstract class CommanderComp implements Unitc{
units.clear(); units.clear();
Units.nearby(team(), x, y, 200f, u -> { Units.nearby(team, x, y, 150f, u -> {
if(u.isAI() && include.get(u) && u != self()){ if(u.isAI() && include.get(u) && u != self() && u.type().flying == type.flying && u.hitSize <= hitSize * 1.1f){
units.add(u); units.add(u);
} }
}); });
units.sort(u -> u.dst2(this)); //sort by hitbox size, then by distance
units.truncate(type().commandLimit); units.sort(Structs.comps(Structs.comparingFloat(u -> -u.hitSize), Structs.comparingFloat(u -> u.dst2(this))));
units.truncate(type.commandLimit);
command(formation, units); command(formation, units);
} }
@@ -73,8 +74,8 @@ abstract class CommanderComp implements Unitc{
void command(Formation formation, Seq<Unit> units){ void command(Formation formation, Seq<Unit> units){
clearCommand(); clearCommand();
float spacing = hitSize() * 0.65f; float spacing = hitSize * 0.65f;
minFormationSpeed = type().speed; minFormationSpeed = type.speed;
controlling.addAll(units); controlling.addAll(units);
for(Unit unit : units){ for(Unit unit : units){

View File

@@ -28,7 +28,7 @@ import mindustry.world.blocks.payloads.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
@Component(base = true) @Component(base = true)
abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, Itemsc, Rotc, Unitc, Weaponsc, Drawc, Boundedc, Syncc, Shieldc, Displayable, Senseable, Ranged{ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, Itemsc, Rotc, Unitc, Weaponsc, Drawc, Boundedc, Syncc, Shieldc, Commanderc, Displayable, Senseable, Ranged{
@Import boolean hovering, dead; @Import boolean hovering, dead;
@Import float x, y, rotation, elevation, maxHealth, drag, armor, hitSize, health, ammo; @Import float x, y, rotation, elevation, maxHealth, drag, armor, hitSize, health, ammo;

View File

@@ -606,12 +606,12 @@ public class DesktopInput extends InputHandler{
float baseSpeed = unit.type().speed; float baseSpeed = unit.type().speed;
//limit speed to minimum formation speed to preserve formation //limit speed to minimum formation speed to preserve formation
if(unit instanceof Commanderc && ((Commanderc)unit).isCommanding()){ if(unit.isCommanding()){
//add a tiny multiplier to let units catch up just in case //add a tiny multiplier to let units catch up just in case
baseSpeed = ((Commanderc)unit).minFormationSpeed() * 0.95f; baseSpeed = unit.minFormationSpeed * 0.95f;
} }
float speed = baseSpeed * Mathf.lerp(1f, unit.type().canBoost ? unit.type().boostMultiplier : 1f, unit.elevation) * strafePenalty; float speed = baseSpeed * Mathf.lerp(1f, unit.isCommanding() ? 1f : unit.type().canBoost ? unit.type().boostMultiplier : 1f, unit.elevation) * strafePenalty;
float xa = Core.input.axis(Binding.move_x); float xa = Core.input.axis(Binding.move_x);
float ya = Core.input.axis(Binding.move_y); float ya = Core.input.axis(Binding.move_y);
boolean boosted = (unit instanceof Mechc && unit.isFlying()); boolean boosted = (unit instanceof Mechc && unit.isFlying());
@@ -661,10 +661,8 @@ public class DesktopInput extends InputHandler{
} }
//update commander inut //update commander inut
if(unit instanceof Commanderc){ if(Core.input.keyTap(Binding.command)){
if(Core.input.keyTap(Binding.command)){ Call.unitCommand(player);
Call.unitCommand(player);
}
} }
} }
} }

View File

@@ -364,7 +364,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
if(commander.isCommanding()){ if(commander.isCommanding()){
commander.clearCommand(); commander.clearCommand();
}else{ }else if(player.unit().type().commandLimit > 0){
//TODO try out some other formations //TODO try out some other formations
commander.commandNearby(new CircleFormation()); commander.commandNearby(new CircleFormation());

View File

@@ -365,7 +365,7 @@ public class MobileInput extends InputHandler implements GestureListener{
} }
//draw targeting crosshair //draw targeting crosshair
if(target != null && !state.isEditor()){ if(target != null && !state.isEditor() && !manualShooting){
if(target != lastTarget){ if(target != lastTarget){
crosshairScale = 0f; crosshairScale = 0f;
lastTarget = target; lastTarget = target;
@@ -525,7 +525,6 @@ public class MobileInput extends InputHandler implements GestureListener{
if(mode == none){ if(mode == none){
Vec2 pos = Core.input.mouseWorld(x, y); Vec2 pos = Core.input.mouseWorld(x, y);
//TODO find payload target
if(player.unit() instanceof Payloadc pay){ if(player.unit() instanceof Payloadc pay){
Unit target = Units.closest(player.team(), pos.x, pos.y, 8f, u -> u.isAI() && u.isGrounded() && pay.canPickup(u) && u.within(pos, u.hitSize + 8f)); Unit target = Units.closest(player.team(), pos.x, pos.y, 8f, u -> u.isAI() && u.isGrounded() && pay.canPickup(u) && u.within(pos, u.hitSize + 8f));
if(target != null){ if(target != null){
@@ -540,10 +539,12 @@ public class MobileInput extends InputHandler implements GestureListener{
payloadTarget = new Vec2(pos); payloadTarget = new Vec2(pos);
}else{ }else{
manualShooting = true; manualShooting = true;
this.target = null;
} }
} }
}else{ }else{
manualShooting = true; manualShooting = true;
this.target = null;
} }
if(!state.isPaused()) Fx.select.at(pos); if(!state.isPaused()) Fx.select.at(pos);
@@ -610,10 +611,8 @@ public class MobileInput extends InputHandler implements GestureListener{
//reset payload target //reset payload target
payloadTarget = null; payloadTarget = null;
//apply command on double tap when own unit is tapped //apply command on double tap when own unit is tapped
if(Mathf.within(worldx, worldy, player.unit().x, player.unit().y, player.unit().hitSize)){ if(Mathf.within(worldx, worldy, player.unit().x, player.unit().y, player.unit().hitSize * 0.6f + 8f)){
if(player.unit() instanceof Commanderc){ Call.unitCommand(player);
Call.unitCommand(player);
}
}else{ }else{
//control a unit/block //control a unit/block
Unit on = selectedUnit(); Unit on = selectedUnit();
@@ -859,12 +858,12 @@ public class MobileInput extends InputHandler implements GestureListener{
float baseSpeed = unit.type().speed; float baseSpeed = unit.type().speed;
//limit speed to minimum formation speed to preserve formation //limit speed to minimum formation speed to preserve formation
if(unit instanceof Commanderc && ((Commanderc)unit).isCommanding()){ if(unit.isCommanding()){
//add a tiny multiplier to let units catch up just in case //add a tiny multiplier to let units catch up just in case
baseSpeed = ((Commanderc)unit).minFormationSpeed() * 0.98f; baseSpeed = unit.minFormationSpeed * 0.98f;
} }
float speed = baseSpeed * Mathf.lerp(1f, type.canBoost ? type.boostMultiplier : 1f, unit.elevation) * strafePenalty; float speed = baseSpeed * Mathf.lerp(1f, unit.isCommanding() ? 1f : type.canBoost ? type.boostMultiplier : 1f, unit.elevation) * strafePenalty;
float range = unit.hasWeapons() ? unit.range() : 0f; float range = unit.hasWeapons() ? unit.range() : 0f;
float bulletSpeed = unit.hasWeapons() ? type.weapons.first().bullet.speed : 0f; float bulletSpeed = unit.hasWeapons() ? type.weapons.first().bullet.speed : 0f;
float mouseAngle = unit.angleTo(unit.aimX(), unit.aimY()); float mouseAngle = unit.angleTo(unit.aimX(), unit.aimY());
@@ -946,6 +945,8 @@ public class MobileInput extends InputHandler implements GestureListener{
} }
} }
} }
unit.aim(Tmp.v1.trns(unit.rotation, 1000f).add(unit));
}else{ }else{
Vec2 intercept = Predict.intercept(unit, target, bulletSpeed); Vec2 intercept = Predict.intercept(unit, target, bulletSpeed);
@@ -955,7 +956,6 @@ public class MobileInput extends InputHandler implements GestureListener{
unit.aim(player.mouseX, player.mouseY); unit.aim(player.mouseX, player.mouseY);
} }
} }
unit.controlWeapons(player.shooting && !boosted); unit.controlWeapons(player.shooting && !boosted);

View File

@@ -424,9 +424,11 @@ public class LExecutor{
ai.plan.set(x, y, rot, block); ai.plan.set(x, y, rot, block);
ai.plan.config = null; ai.plan.config = null;
builder.clearBuilding(); if(ai.plan.tile() != null){
builder.updateBuilding(true); builder.clearBuilding();
builder.addBuild(ai.plan); builder.updateBuilding(true);
builder.addBuild(ai.plan);
}
} }
} }
case getBlock -> { case getBlock -> {

View File

@@ -50,7 +50,7 @@ public class UnitType extends UnlockableContent{
public float groundLayer = Layer.groundUnit; public float groundLayer = Layer.groundUnit;
public float payloadCapacity = 8; public float payloadCapacity = 8;
public float aimDst = -1f; public float aimDst = -1f;
public int commandLimit = 24; public int commandLimit = 8;
public float visualElevation = -1f; public float visualElevation = -1f;
public boolean allowLegStep = false; public boolean allowLegStep = false;
public boolean hovering = false; public boolean hovering = false;