Unit enter payload command
This commit is contained in:
@@ -17,7 +17,7 @@ public class UnitCommand extends MappableContent{
|
||||
@Deprecated
|
||||
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). */
|
||||
public final String icon;
|
||||
@@ -87,6 +87,11 @@ public class UnitCommand extends MappableContent{
|
||||
drawTarget = true;
|
||||
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){{
|
||||
switchToMove = false;
|
||||
drawTarget = true;
|
||||
|
||||
@@ -20,6 +20,7 @@ public class CommandAI extends AIController{
|
||||
protected static final int maxCommandQueueSize = 50, avoidInterval = 10;
|
||||
protected static final Vec2 vecOut = new Vec2(), vecMovePos = new Vec2();
|
||||
protected static final boolean[] noFound = {false};
|
||||
protected static final UnitPayload tmpPayload = new UnitPayload(null);
|
||||
|
||||
public Seq<Position> commandQueue = new Seq<>(5);
|
||||
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
|
||||
if(unit.team.isAI() && unit.team.rules().rtsAi && unit.type.naval){
|
||||
if(fallback == null) fallback = new GroundAI();
|
||||
@@ -198,7 +208,8 @@ public class CommandAI extends AIController{
|
||||
vecOut.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]);
|
||||
}
|
||||
|
||||
@@ -295,6 +306,11 @@ public class CommandAI extends AIController{
|
||||
}
|
||||
|
||||
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;
|
||||
targetPos = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user