mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-15 18:27:36 +07:00
Unit enter payload command
This commit is contained in:
@ -354,6 +354,7 @@ command.rebuild = Rebuild
|
|||||||
command.assist = Assist Player
|
command.assist = Assist Player
|
||||||
command.move = Move
|
command.move = Move
|
||||||
command.boost = Boost
|
command.boost = Boost
|
||||||
|
command.enterPayload = Enter Payload Block
|
||||||
command.loadUnits = Load Units
|
command.loadUnits = Load Units
|
||||||
command.loadBlocks = Load Blocks
|
command.loadBlocks = Load Blocks
|
||||||
command.unloadPayload = Unload Payload
|
command.unloadPayload = Unload Payload
|
||||||
|
@ -17,7 +17,7 @@ public class UnitCommand extends MappableContent{
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public static final Seq<UnitCommand> all = new Seq<>();
|
public static final Seq<UnitCommand> all = new Seq<>();
|
||||||
|
|
||||||
public static UnitCommand moveCommand, repairCommand, rebuildCommand, assistCommand, mineCommand, boostCommand, loadUnitsCommand, loadBlocksCommand, unloadPayloadCommand;
|
public static UnitCommand moveCommand, repairCommand, rebuildCommand, assistCommand, mineCommand, boostCommand, enterPayloadCommand, loadUnitsCommand, loadBlocksCommand, unloadPayloadCommand;
|
||||||
|
|
||||||
/** Name of UI icon (from Icon class). */
|
/** Name of UI icon (from Icon class). */
|
||||||
public final String icon;
|
public final String icon;
|
||||||
@ -87,6 +87,11 @@ public class UnitCommand extends MappableContent{
|
|||||||
drawTarget = true;
|
drawTarget = true;
|
||||||
resetTarget = false;
|
resetTarget = false;
|
||||||
}};
|
}};
|
||||||
|
enterPayloadCommand = new UnitCommand("enterPayload", "downOpen", Binding.unit_command_enter_payload, null){{
|
||||||
|
switchToMove = false;
|
||||||
|
drawTarget = true;
|
||||||
|
resetTarget = false;
|
||||||
|
}};
|
||||||
loadUnitsCommand = new UnitCommand("loadUnits", "upload", Binding.unit_command_load_units, null){{
|
loadUnitsCommand = new UnitCommand("loadUnits", "upload", Binding.unit_command_load_units, null){{
|
||||||
switchToMove = false;
|
switchToMove = false;
|
||||||
drawTarget = true;
|
drawTarget = true;
|
||||||
|
@ -20,6 +20,7 @@ public class CommandAI extends AIController{
|
|||||||
protected static final int maxCommandQueueSize = 50, avoidInterval = 10;
|
protected static final int maxCommandQueueSize = 50, avoidInterval = 10;
|
||||||
protected static final Vec2 vecOut = new Vec2(), vecMovePos = new Vec2();
|
protected static final Vec2 vecOut = new Vec2(), vecMovePos = new Vec2();
|
||||||
protected static final boolean[] noFound = {false};
|
protected static final boolean[] noFound = {false};
|
||||||
|
protected static final UnitPayload tmpPayload = new UnitPayload(null);
|
||||||
|
|
||||||
public Seq<Position> commandQueue = new Seq<>(5);
|
public Seq<Position> commandQueue = new Seq<>(5);
|
||||||
public @Nullable Vec2 targetPos;
|
public @Nullable Vec2 targetPos;
|
||||||
@ -145,6 +146,15 @@ public class CommandAI extends AIController{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!net.client() && command == UnitCommand.enterPayloadCommand && unit.buildOn() != null && (targetPos == null || (world.buildWorld(targetPos.x, targetPos.y) != null && world.buildWorld(targetPos.x, targetPos.y) == unit.buildOn()))){
|
||||||
|
var build = unit.buildOn();
|
||||||
|
tmpPayload.unit = unit;
|
||||||
|
if(build.team == unit.team && build.acceptPayload(build, tmpPayload)){
|
||||||
|
Call.unitEnteredPayload(unit, build);
|
||||||
|
return; //no use updating after this, the unit is gone!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//acquiring naval targets isn't supported yet, so use the fallback dumb AI
|
//acquiring naval targets isn't supported yet, so use the fallback dumb AI
|
||||||
if(unit.team.isAI() && unit.team.rules().rtsAi && unit.type.naval){
|
if(unit.team.isAI() && unit.team.rules().rtsAi && unit.type.naval){
|
||||||
if(fallback == null) fallback = new GroundAI();
|
if(fallback == null) fallback = new GroundAI();
|
||||||
@ -198,7 +208,8 @@ public class CommandAI extends AIController{
|
|||||||
vecOut.set(targetPos);
|
vecOut.set(targetPos);
|
||||||
vecMovePos.set(targetPos);
|
vecMovePos.set(targetPos);
|
||||||
|
|
||||||
if(group != null && group.valid && groupIndex < group.units.size){
|
//the enter payload command requires an exact position
|
||||||
|
if(group != null && group.valid && groupIndex < group.units.size && command != UnitCommand.enterPayloadCommand){
|
||||||
vecMovePos.add(group.positions[groupIndex * 2], group.positions[groupIndex * 2 + 1]);
|
vecMovePos.add(group.positions[groupIndex * 2], group.positions[groupIndex * 2 + 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,6 +306,11 @@ public class CommandAI extends AIController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void finishPath(){
|
void finishPath(){
|
||||||
|
//the enter payload command never finishes until they are actually accepted
|
||||||
|
if(command == UnitCommand.enterPayloadCommand && commandQueue.size == 0 && targetPos != null && world.buildWorld(targetPos.x, targetPos.y) != null && world.buildWorld(targetPos.x, targetPos.y).block.acceptsPayloads){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Vec2 prev = targetPos;
|
Vec2 prev = targetPos;
|
||||||
targetPos = null;
|
targetPos = null;
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ public enum Binding implements KeyBind{
|
|||||||
unit_command_assist(KeyCode.unset),
|
unit_command_assist(KeyCode.unset),
|
||||||
unit_command_mine(KeyCode.unset),
|
unit_command_mine(KeyCode.unset),
|
||||||
unit_command_boost(KeyCode.unset),
|
unit_command_boost(KeyCode.unset),
|
||||||
|
unit_command_enter_payload(KeyCode.unset),
|
||||||
unit_command_load_units(KeyCode.unset),
|
unit_command_load_units(KeyCode.unset),
|
||||||
unit_command_load_blocks(KeyCode.unset),
|
unit_command_load_blocks(KeyCode.unset),
|
||||||
unit_command_unload_payload(KeyCode.unset),
|
unit_command_unload_payload(KeyCode.unset),
|
||||||
|
@ -557,6 +557,31 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remote(called = Loc.server)
|
||||||
|
public static void unitEnteredPayload(Unit unit, Building build){
|
||||||
|
if(unit == null || build == null || unit.team != build.team) return;
|
||||||
|
|
||||||
|
unit.remove();
|
||||||
|
|
||||||
|
//reset the enter command
|
||||||
|
if(unit.controller() instanceof CommandAI ai && ai.command == UnitCommand.enterPayloadCommand){
|
||||||
|
ai.clearCommands();
|
||||||
|
ai.command = UnitCommand.moveCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
//clear removed state of unit so it can be synced
|
||||||
|
if(Vars.net.client()){
|
||||||
|
Vars.netClient.clearRemovedEntity(unit.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
UnitPayload unitPay = new UnitPayload(unit);
|
||||||
|
|
||||||
|
if(build.acceptPayload(build, unitPay)){
|
||||||
|
Fx.unitDrop.at(build);
|
||||||
|
build.handlePayload(build, unitPay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.client, called = Loc.server)
|
@Remote(targets = Loc.client, called = Loc.server)
|
||||||
public static void dropItem(Player player, float angle){
|
public static void dropItem(Player player, float angle){
|
||||||
if(player == null) return;
|
if(player == null) return;
|
||||||
|
@ -810,7 +810,7 @@ public class UnitType extends UnlockableContent implements Senseable{
|
|||||||
if(commands.length == 0){
|
if(commands.length == 0){
|
||||||
Seq<UnitCommand> cmds = new Seq<>(UnitCommand.class);
|
Seq<UnitCommand> cmds = new Seq<>(UnitCommand.class);
|
||||||
|
|
||||||
cmds.add(UnitCommand.moveCommand);
|
cmds.add(UnitCommand.moveCommand, UnitCommand.enterPayloadCommand);
|
||||||
|
|
||||||
if(canBoost){
|
if(canBoost){
|
||||||
cmds.add(UnitCommand.boostCommand);
|
cmds.add(UnitCommand.boostCommand);
|
||||||
|
@ -57,6 +57,8 @@ public class Block extends UnlockableContent implements Senseable{
|
|||||||
public boolean conductivePower = false;
|
public boolean conductivePower = false;
|
||||||
/** If true, this block can output payloads; affects blending. */
|
/** If true, this block can output payloads; affects blending. */
|
||||||
public boolean outputsPayload = false;
|
public boolean outputsPayload = false;
|
||||||
|
/** If true, this block can input payloads; affects unit payload enter behavior. */
|
||||||
|
public boolean acceptsPayloads = false;
|
||||||
/** If true, payloads will attempt to move into this block. */
|
/** If true, payloads will attempt to move into this block. */
|
||||||
public boolean acceptsPayload = false;
|
public boolean acceptsPayload = false;
|
||||||
/** Visual flag use for blending of certain transportation blocks. */
|
/** Visual flag use for blending of certain transportation blocks. */
|
||||||
|
@ -30,6 +30,7 @@ public abstract class BlockProducer extends PayloadBlock{
|
|||||||
hasItems = true;
|
hasItems = true;
|
||||||
solid = true;
|
solid = true;
|
||||||
hasPower = true;
|
hasPower = true;
|
||||||
|
acceptsPayloads = false;
|
||||||
rotate = true;
|
rotate = true;
|
||||||
regionRotated1 = 1;
|
regionRotated1 = 1;
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ public class PayloadBlock extends Block{
|
|||||||
update = true;
|
update = true;
|
||||||
sync = true;
|
sync = true;
|
||||||
group = BlockGroup.payloads;
|
group = BlockGroup.payloads;
|
||||||
|
acceptsPayloads = true;
|
||||||
envEnabled |= Env.space | Env.underwater;
|
envEnabled |= Env.space | Env.underwater;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ public class PayloadConveyor extends Block{
|
|||||||
update = true;
|
update = true;
|
||||||
outputsPayload = true;
|
outputsPayload = true;
|
||||||
noUpdateDisabled = true;
|
noUpdateDisabled = true;
|
||||||
|
acceptsPayloads = true;
|
||||||
priority = TargetPriority.transport;
|
priority = TargetPriority.transport;
|
||||||
envEnabled |= Env.space | Env.underwater;
|
envEnabled |= Env.space | Env.underwater;
|
||||||
sync = true;
|
sync = true;
|
||||||
|
@ -37,6 +37,7 @@ public class PayloadSource extends PayloadBlock{
|
|||||||
noUpdateDisabled = true;
|
noUpdateDisabled = true;
|
||||||
clearOnDoubleTap = true;
|
clearOnDoubleTap = true;
|
||||||
regionRotated1 = 1;
|
regionRotated1 = 1;
|
||||||
|
acceptsPayloads = false;
|
||||||
commandable = true;
|
commandable = true;
|
||||||
|
|
||||||
config(Block.class, (PayloadSourceBuild build, Block block) -> {
|
config(Block.class, (PayloadSourceBuild build, Block block) -> {
|
||||||
|
Reference in New Issue
Block a user