Added stances for payloads

This commit is contained in:
Anuken 2023-09-22 18:22:19 -04:00
parent f633fb0af5
commit b6c28bc27d
6 changed files with 49 additions and 12 deletions

View File

@ -360,6 +360,9 @@ stance.holdfire = Stance: Hold Fire
stance.pursuetarget = Stance: Pursue Target stance.pursuetarget = Stance: Pursue Target
stance.patrol = Stance: Patrol Path stance.patrol = Stance: Patrol Path
stance.ram = Stance: Ram\n[lightgray]Straight line movement, no pathfinding stance.ram = Stance: Ram\n[lightgray]Straight line movement, no pathfinding
stance.loadPayload = Stance: Load Units
stance.loadBlocks = Stance: Load Blocks
stance.unloadPayload = Stance: Unload Payload
openlink = Open Link openlink = Open Link
copylink = Copy Link copylink = Copy Link
back = Back back = Back

View File

@ -31,14 +31,6 @@ public class UnitCommand{
switchToMove = false; switchToMove = false;
drawTarget = true; drawTarget = true;
resetTarget = false; resetTarget = false;
}},
loadPayloadCommand = new UnitCommand("loadPayload", "download", u -> null){{
switchToMove = false;
drawTarget = true;
}},
unloadPayloadCommand = new UnitCommand("unloadPayload", "upload", u -> null){{
switchToMove = false;
drawTarget = true;
}}; }};
/** Unique ID number. */ /** Unique ID number. */

View File

@ -16,7 +16,10 @@ public class UnitStance{
holdFire = new UnitStance("holdfire", "none"), holdFire = new UnitStance("holdfire", "none"),
pursueTarget = new UnitStance("pursuetarget", "right"), pursueTarget = new UnitStance("pursuetarget", "right"),
patrol = new UnitStance("patrol", "refresh"), patrol = new UnitStance("patrol", "refresh"),
ram = new UnitStance("ram", "rightOpen"); ram = new UnitStance("ram", "rightOpen"),
loadPayload = new UnitStance("loadPayload", "download"),
loadBlocks = new UnitStance("loadBlocks", "down"),
unloadPayload = new UnitStance("unloadPayload", "upload");
/** Unique ID number. */ /** Unique ID number. */
public final int id; public final int id;

View File

@ -11,6 +11,10 @@ import mindustry.entities.*;
import mindustry.entities.units.*; import mindustry.entities.units.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.world.*; import mindustry.world.*;
import mindustry.world.blocks.payloads.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
public class CommandAI extends AIController{ public class CommandAI extends AIController{
protected static final int maxCommandQueueSize = 50; protected static final int maxCommandQueueSize = 50;
@ -67,6 +71,7 @@ public class CommandAI extends AIController{
//this should not be possible //this should not be possible
if(stance == UnitStance.stop) stance = UnitStance.shoot; if(stance == UnitStance.stop) stance = UnitStance.shoot;
//pursue the target if relevant
if(stance == UnitStance.pursueTarget && target != null && attackTarget == null && targetPos == null){ if(stance == UnitStance.pursueTarget && target != null && attackTarget == null && targetPos == null){
commandTarget(target, false); commandTarget(target, false);
} }
@ -107,6 +112,37 @@ public class CommandAI extends AIController{
public void defaultBehavior(){ public void defaultBehavior(){
if(!net.client() && unit instanceof Payloadc pay){
//auto-drop everything
if(stance == UnitStance.unloadPayload && pay.hasPayload()){
Call.payloadDropped(unit, unit.x, unit.y);
}
//try to pick up what's under it
if(stance == UnitStance.loadPayload){
Unit target = Units.closest(unit.team, unit.x, unit.y, unit.type.hitSize * 2f, u -> u.isAI() && u != unit && u.isGrounded() && pay.canPickup(u) && u.within(unit, u.hitSize + unit.hitSize));
if(target != null){
Call.pickedUnitPayload(unit, target);
}
}
//try to pick up a block
if(stance == UnitStance.loadBlocks && (targetPos == null || unit.within(targetPos, 1f))){
Building build = world.buildWorld(unit.x, unit.y);
if(build != null && state.teams.canInteract(unit.team, build.team)){
//pick up block's payload
Payload current = build.getPayload();
if(current != null && pay.canPickupPayload(current)){
Call.pickedBuildPayload(unit, build, false);
//pick up whole building directly
}else if(build.block.buildVisibility != BuildVisibility.hidden && build.canPickup() && pay.canPickup(build)){
Call.pickedBuildPayload(unit, build, true);
}
}
}
}
//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();

View File

@ -333,7 +333,7 @@ public class Units{
cdist = 0f; cdist = 0f;
nearby(team, x, y, range, e -> { nearby(team, x, y, range, e -> {
if(!predicate.get(e)) return; if(!e.isValid() || !predicate.get(e)) return;
float dist = e.dst2(x, y); float dist = e.dst2(x, y);
if(result == null || dist < cdist){ if(result == null || dist < cdist){
@ -351,7 +351,7 @@ public class Units{
cdist = 0f; cdist = 0f;
nearby(team, x, y, range, e -> { nearby(team, x, y, range, e -> {
if(!predicate.get(e)) return; if(!e.isValid() || !predicate.get(e)) return;
float dist = sort.cost(e, x, y); float dist = sort.cost(e, x, y);
if(result == null || dist < cdist){ if(result == null || dist < cdist){
@ -370,7 +370,7 @@ public class Units{
cdist = 0f; cdist = 0f;
nearby(team, x - range, y - range, range*2f, range*2f, e -> { nearby(team, x - range, y - range, range*2f, range*2f, e -> {
if(!predicate.get(e)) return; if(!e.isValid() || !predicate.get(e)) return;
float dist = e.dst2(x, y); float dist = e.dst2(x, y);
if(result == null || dist < cdist){ if(result == null || dist < cdist){

View File

@ -840,6 +840,9 @@ public class UnitType extends UnlockableContent implements Senseable{
if(crushDamage > 0){ if(crushDamage > 0){
seq.add(UnitStance.ram); seq.add(UnitStance.ram);
} }
if(example instanceof Payloadc){
seq.addAll(UnitStance.loadPayload, UnitStance.loadBlocks, UnitStance.unloadPayload);
}
stances = seq.toArray(UnitStance.class); stances = seq.toArray(UnitStance.class);
}else{ }else{
stances = new UnitStance[]{UnitStance.stop}; stances = new UnitStance[]{UnitStance.stop};