mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-04-22 21:41:23 -07:00
Mobile manual aiming / Mobile control changes [UNSTABLE]
This commit is contained in:
parent
583a12a47b
commit
30f5340a22
25 changed files with 223 additions and 224 deletions
|
|
@ -67,13 +67,11 @@ public class BuilderAI extends AIController{
|
|||
Units.nearby(unit.team, unit.x, unit.y, buildRadius, u -> {
|
||||
if(found) return;
|
||||
|
||||
if(u instanceof Builderc && u != unit && ((Builderc)u).activelyBuilding()){
|
||||
Builderc b = (Builderc)u;
|
||||
if(u instanceof Builderc b && u != unit && ((Builderc)u).activelyBuilding()){
|
||||
BuildPlan plan = b.buildPlan();
|
||||
|
||||
Building build = world.build(plan.x, plan.y);
|
||||
if(build instanceof ConstructBuild){
|
||||
ConstructBuild cons = (ConstructBuild)build;
|
||||
if(build instanceof ConstructBuild cons){
|
||||
float dist = Math.min(cons.dst(unit) - buildingRange, 0);
|
||||
|
||||
//make sure you can reach the request in time
|
||||
|
|
|
|||
|
|
@ -17,9 +17,7 @@ public class MinerAI extends AIController{
|
|||
protected void updateMovement(){
|
||||
Building core = unit.closestCore();
|
||||
|
||||
if(!(unit instanceof Minerc) || core == null) return;
|
||||
|
||||
Minerc miner = (Minerc)unit;
|
||||
if(!(unit instanceof Minerc miner) || core == null) return;
|
||||
|
||||
if(miner.mineTile() != null && !miner.mineTile().within(unit, unit.type().range)){
|
||||
miner.mineTile(null);
|
||||
|
|
|
|||
|
|
@ -249,8 +249,7 @@ public class NetServer implements ApplicationListener{
|
|||
}catch(ValidateException e){
|
||||
Log.debug("Validation failed for '@': @", e.player, e.getMessage());
|
||||
}catch(RuntimeException e){
|
||||
if(e.getCause() instanceof ValidateException){
|
||||
ValidateException v = (ValidateException)e.getCause();
|
||||
if(e.getCause() instanceof ValidateException v){
|
||||
Log.debug("Validation failed for '@': @", v.player, v.getMessage());
|
||||
}else{
|
||||
throw e;
|
||||
|
|
|
|||
|
|
@ -36,15 +36,13 @@ public class MassDriverBolt extends BulletType{
|
|||
@Override
|
||||
public void update(Bullet b){
|
||||
//data MUST be an instance of DriverBulletData
|
||||
if(!(b.data() instanceof DriverBulletData)){
|
||||
if(!(b.data() instanceof DriverBulletData data)){
|
||||
hit(b);
|
||||
return;
|
||||
}
|
||||
|
||||
float hitDst = 7f;
|
||||
|
||||
DriverBulletData data = (DriverBulletData)b.data();
|
||||
|
||||
//if the target is dead, just keep flying until the bullet explodes
|
||||
if(data.to.dead()){
|
||||
return;
|
||||
|
|
@ -83,9 +81,7 @@ public class MassDriverBolt extends BulletType{
|
|||
public void despawned(Bullet b){
|
||||
super.despawned(b);
|
||||
|
||||
if(!(b.data() instanceof DriverBulletData)) return;
|
||||
|
||||
DriverBulletData data = (DriverBulletData)b.data();
|
||||
if(!(b.data() instanceof DriverBulletData data)) return;
|
||||
|
||||
for(int i = 0; i < data.items.length; i++){
|
||||
int amountDropped = Mathf.random(0, data.items[i]);
|
||||
|
|
|
|||
|
|
@ -29,8 +29,7 @@ public class SapBulletType extends BulletType{
|
|||
|
||||
@Override
|
||||
public void draw(Bullet b){
|
||||
if(b.data instanceof Position){
|
||||
Position data = (Position)b.data;
|
||||
if(b.data instanceof Position data){
|
||||
Tmp.v1.set(data).lerp(b, b.fin());
|
||||
|
||||
Draw.color(color);
|
||||
|
|
@ -68,13 +67,11 @@ public class SapBulletType extends BulletType{
|
|||
}
|
||||
}
|
||||
|
||||
if(target instanceof Hitboxc){
|
||||
Hitboxc hit = (Hitboxc)target;
|
||||
if(target instanceof Hitboxc hit){
|
||||
|
||||
hit.collision(b, hit.x(), hit.y());
|
||||
b.collision(hit, hit.x(), hit.y());
|
||||
}else if(target instanceof Building){
|
||||
Building tile = (Building)target;
|
||||
}else if(target instanceof Building tile){
|
||||
|
||||
if(tile.collide(b)){
|
||||
tile.collision(b);
|
||||
|
|
|
|||
|
|
@ -1249,7 +1249,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||
case type -> block;
|
||||
case firstItem -> items == null ? null : items.first();
|
||||
case config -> block.configurations.containsKey(Item.class) || block.configurations.containsKey(Liquid.class) ? config() : null;
|
||||
case payloadType -> getPayload() instanceof UnitPayload p1 ? p1.unit.type() : getPayload() instanceof BlockPayload p2 ? p2.block() : null;
|
||||
case payloadType -> getPayload() instanceof UnitPayload p1 ? p1.unit.type() : getPayload() instanceof BuildPayload p2 ? p2.block() : null;
|
||||
default -> noSensed;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -95,14 +95,12 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
|
|||
type.hit(self(), x, y);
|
||||
float health = 0f;
|
||||
|
||||
if(other instanceof Healthc){
|
||||
Healthc h = (Healthc)other;
|
||||
if(other instanceof Healthc h){
|
||||
health = h.health();
|
||||
h.damage(damage);
|
||||
}
|
||||
|
||||
if(other instanceof Unit){
|
||||
Unit unit = (Unit)other;
|
||||
if(other instanceof Unit unit){
|
||||
unit.impulse(Tmp.v3.set(unit).sub(this.x, this.y).nor().scl(type.knockback * 80f));
|
||||
unit.apply(type.status, type.statusDuration);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{
|
|||
}
|
||||
|
||||
boolean canPickup(Unit unit){
|
||||
return payloadUsed() + unit.hitSize * unit.hitSize <= type.payloadCapacity + 0.001f;
|
||||
return payloadUsed() + unit.hitSize * unit.hitSize <= type.payloadCapacity + 0.001f && unit.team == team() && unit.isAI();
|
||||
}
|
||||
|
||||
boolean canPickup(Building build){
|
||||
return payloadUsed() + build.block.size * build.block.size * Vars.tilesize * Vars.tilesize <= type.payloadCapacity + 0.001f;
|
||||
return payloadUsed() + build.block.size * build.block.size * Vars.tilesize * Vars.tilesize <= type.payloadCapacity + 0.001f && build.canPickup();
|
||||
}
|
||||
|
||||
boolean canPickupPayload(Payload pay){
|
||||
|
|
@ -55,7 +55,7 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{
|
|||
|
||||
void pickup(Building tile){
|
||||
tile.tile.remove();
|
||||
payloads.add(new BlockPayload(tile));
|
||||
payloads.add(new BuildPayload(tile));
|
||||
Fx.unitPickup.at(tile);
|
||||
}
|
||||
|
||||
|
|
@ -86,8 +86,8 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{
|
|||
return true;
|
||||
}
|
||||
|
||||
if(payload instanceof BlockPayload){
|
||||
return dropBlock((BlockPayload)payload);
|
||||
if(payload instanceof BuildPayload){
|
||||
return dropBlock((BuildPayload)payload);
|
||||
}else if(payload instanceof UnitPayload){
|
||||
return dropUnit((UnitPayload)payload);
|
||||
}
|
||||
|
|
@ -118,8 +118,8 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{
|
|||
}
|
||||
|
||||
/** @return whether the tile has been successfully placed. */
|
||||
boolean dropBlock(BlockPayload payload){
|
||||
Building tile = payload.entity;
|
||||
boolean dropBlock(BuildPayload payload){
|
||||
Building tile = payload.build;
|
||||
int tx = Vars.world.toTile(x - tile.block.offset), ty = Vars.world.toTile(y - tile.block.offset);
|
||||
Tile on = Vars.world.tile(tx, ty);
|
||||
if(on != null && Build.validPlace(tile.block, tile.team, tx, ty, tile.rotation, false)){
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
|||
case payloadType -> self() instanceof Payloadc pay ?
|
||||
(pay.payloads().isEmpty() ? null :
|
||||
pay.payloads().peek() instanceof UnitPayload p1 ? p1.unit.type() :
|
||||
pay.payloads().peek() instanceof BlockPayload p2 ? p2.block() : null) : null;
|
||||
pay.payloads().peek() instanceof BuildPayload p2 ? p2.block() : null) : null;
|
||||
default -> noSensed;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||
}
|
||||
|
||||
@Remote(targets = Loc.both, called = Loc.server)
|
||||
public static void requestBlockPayload(Player player, Building tile){
|
||||
public static void requestBuildPayload(Player player, Building tile){
|
||||
if(player == null) return;
|
||||
|
||||
Unit unit = player.unit();
|
||||
|
|
@ -174,11 +174,11 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||
&& unit.within(tile, tilesize * tile.block.size * 1.2f + tilesize * 5f)){
|
||||
//pick up block directly
|
||||
if(tile.block.buildVisibility != BuildVisibility.hidden && tile.canPickup() && pay.canPickup(tile)){
|
||||
Call.pickedBlockPayload(unit, tile, true);
|
||||
Call.pickedBuildPayload(unit, tile, true);
|
||||
}else{ //pick up block payload
|
||||
Payload current = tile.getPayload();
|
||||
if(current != null && pay.canPickupPayload(current)){
|
||||
Call.pickedBlockPayload(unit, tile, false);
|
||||
Call.pickedBuildPayload(unit, tile, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -194,7 +194,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||
}
|
||||
|
||||
@Remote(targets = Loc.server, called = Loc.server)
|
||||
public static void pickedBlockPayload(Unit unit, Building tile, boolean onGround){
|
||||
public static void pickedBuildPayload(Unit unit, Building tile, boolean onGround){
|
||||
if(tile != null && unit instanceof Payloadc pay){
|
||||
if(onGround){
|
||||
if(tile.block.buildVisibility != BuildVisibility.hidden && tile.canPickup() && pay.canPickup(tile)){
|
||||
|
|
@ -360,9 +360,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||
|
||||
@Remote(targets = Loc.both, called = Loc.server, forward = true)
|
||||
public static void unitCommand(Player player){
|
||||
if(player == null || player.dead() || !(player.unit() instanceof Commanderc)) return;
|
||||
|
||||
Commanderc commander = (Commanderc)player.unit();
|
||||
if(player == null || player.dead() || !(player.unit() instanceof Commanderc commander)) return;
|
||||
|
||||
if(commander.isCommanding()){
|
||||
commander.clearCommand();
|
||||
|
|
@ -436,8 +434,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||
|
||||
public void tryPickupPayload(){
|
||||
Unit unit = player.unit();
|
||||
if(!(unit instanceof Payloadc)) return;
|
||||
Payloadc pay = (Payloadc)unit;
|
||||
if(!(unit instanceof Payloadc pay)) return;
|
||||
|
||||
Unit target = Units.closest(player.team(), pay.x(), pay.y(), unit.type().hitSize * 2.5f, u -> u.isAI() && u.isGrounded() && pay.canPickup(u) && u.within(unit, u.hitSize + unit.hitSize * 1.2f));
|
||||
if(target != null){
|
||||
|
|
@ -446,7 +443,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||
Building tile = world.buildWorld(pay.x(), pay.y());
|
||||
|
||||
if(tile != null && tile.team == unit.team){
|
||||
Call.requestBlockPayload(player, tile);
|
||||
Call.requestBuildPayload(player, tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,10 +60,15 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||
public Block lastBlock;
|
||||
/** Last placed request. Used for drawing block overlay. */
|
||||
public BuildPlan lastPlaced;
|
||||
/** Down tracking for panning.*/
|
||||
/** Down tracking for panning. */
|
||||
public boolean down = false;
|
||||
/** Whether manual shooting (point with finger) is enabled. */
|
||||
public boolean manualShooting = false;
|
||||
|
||||
public Teamc target, moveTarget;
|
||||
/** Current thing being shot at. */
|
||||
public Teamc target;
|
||||
/** Payload target being moved to. Can be a position (for dropping), or a unit/block. */
|
||||
public Position payloadTarget;
|
||||
|
||||
//region utility methods
|
||||
|
||||
|
|
@ -474,6 +479,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||
down = false;
|
||||
}
|
||||
|
||||
manualShooting = false;
|
||||
selecting = false;
|
||||
|
||||
//place down a line if in line mode
|
||||
|
|
@ -518,10 +524,26 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||
//handle long tap when player isn't building
|
||||
if(mode == none){
|
||||
|
||||
//control a unit/block
|
||||
Unit on = selectedUnit();
|
||||
if(on != null){
|
||||
Call.unitControl(player, on);
|
||||
//TODO find payload target
|
||||
if(player.unit() instanceof Payloadc pay){
|
||||
Vec2 pos = Core.input.mouseWorld(x, y);
|
||||
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){
|
||||
payloadTarget = target;
|
||||
}else{
|
||||
Building build = world.buildWorld(pos.x, pos.y);
|
||||
|
||||
if(build != null && build.team == player.team() && pay.canPickup(build)){
|
||||
payloadTarget = build;
|
||||
}else if(pay.hasPayload()){
|
||||
//drop off at position
|
||||
payloadTarget = new Vec2(pos);
|
||||
}else{
|
||||
manualShooting = true;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
manualShooting = true;
|
||||
}
|
||||
}else{
|
||||
|
||||
|
|
@ -581,17 +603,20 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||
tryBeginMine(cursor);
|
||||
}
|
||||
|
||||
//apply command on double tap
|
||||
if(count == 2 && Mathf.within(worldx, worldy, player.unit().x, player.unit().y, player.unit().hitSize * 2f)){
|
||||
if(player.unit() instanceof Commanderc){
|
||||
Call.unitCommand(player);
|
||||
}
|
||||
|
||||
if(player.unit() instanceof Payloadc){
|
||||
if(((Payloadc)player.unit()).hasPayload()){
|
||||
tryDropPayload();
|
||||
}else{
|
||||
tryPickupPayload();
|
||||
//control units.
|
||||
if(count == 2){
|
||||
//reset payload target
|
||||
payloadTarget = null;
|
||||
//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(player.unit() instanceof Commanderc){
|
||||
Call.unitCommand(player);
|
||||
}
|
||||
}else{
|
||||
//control a unit/block
|
||||
Unit on = selectedUnit();
|
||||
if(on != null){
|
||||
Call.unitControl(player, on);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -608,10 +633,14 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||
selectRequests.clear();
|
||||
removals.clear();
|
||||
mode = none;
|
||||
manualShooting = false;
|
||||
payloadTarget = null;
|
||||
}
|
||||
|
||||
if(player.dead()){
|
||||
mode = none;
|
||||
manualShooting = false;
|
||||
payloadTarget = null;
|
||||
}
|
||||
|
||||
//zoom camera
|
||||
|
|
@ -752,7 +781,8 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||
return false;
|
||||
}
|
||||
|
||||
if(!down) return false;
|
||||
//do not pan with manual shooting enabled
|
||||
if(!down || manualShooting) return false;
|
||||
|
||||
if(selecting){ //pan all requests
|
||||
shiftDeltaX += deltaX;
|
||||
|
|
@ -806,7 +836,6 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||
UnitType type = unit.type();
|
||||
if(type == null) return;
|
||||
|
||||
boolean flying = type.flying;
|
||||
boolean omni = unit.type().omniMovement;
|
||||
boolean legs = unit.isGrounded();
|
||||
boolean allowHealing = type.canHeal;
|
||||
|
|
@ -847,14 +876,26 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||
}
|
||||
}
|
||||
|
||||
if(moveTarget != null){
|
||||
targetPos.set(moveTarget);
|
||||
if(payloadTarget != null && unit instanceof Payloadc pay){
|
||||
targetPos.set(payloadTarget);
|
||||
attractDst = 0f;
|
||||
|
||||
if(unit.within(moveTarget, 2f * Time.delta)){
|
||||
handleTapTarget(moveTarget);
|
||||
moveTarget = null;
|
||||
if(unit.within(payloadTarget, 3f * Time.delta)){
|
||||
if(payloadTarget instanceof Vec2 && pay.hasPayload()){
|
||||
//vec -> dropping something
|
||||
tryDropPayload();
|
||||
}else if(payloadTarget instanceof Building build && pay.canPickup(build)){
|
||||
//building -> picking building up
|
||||
Call.requestBuildPayload(player, build);
|
||||
}else if(payloadTarget instanceof Unit other && pay.canPickup(other)){
|
||||
//unit -> picking unit up
|
||||
Call.requestUnitPayload(player, other);
|
||||
}
|
||||
|
||||
payloadTarget = null;
|
||||
}
|
||||
}else{
|
||||
payloadTarget = null;
|
||||
}
|
||||
|
||||
movement.set(targetPos).sub(player).limit(speed);
|
||||
|
|
@ -887,8 +928,11 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||
//update shooting if not building + not mining
|
||||
if(!player.builder().isBuilding() && player.miner().mineTile() == null){
|
||||
|
||||
//autofire
|
||||
if(target == null){
|
||||
//autofire targeting
|
||||
if(manualShooting){
|
||||
player.shooting = !boosted;
|
||||
unit.aim(player.mouseX = Core.input.mouseWorldX(), player.mouseY = Core.input.mouseWorldY());
|
||||
}else if(target == null){
|
||||
player.shooting = false;
|
||||
if(Core.settings.getBool("autotarget")){
|
||||
target = Units.closestTarget(unit.team, unit.x, unit.y, range, u -> u.team != Team.derelict, u -> u.team != Team.derelict);
|
||||
|
|
@ -899,10 +943,6 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||
target = null;
|
||||
}
|
||||
}
|
||||
|
||||
if(target != null && player.isMiner()){
|
||||
player.miner().mineTile(null);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
Vec2 intercept = Predict.intercept(unit, target, bulletSpeed);
|
||||
|
|
@ -919,10 +959,5 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||
unit.controlWeapons(player.shooting && !boosted);
|
||||
}
|
||||
|
||||
|
||||
protected void handleTapTarget(Teamc target){
|
||||
|
||||
}
|
||||
|
||||
//endregion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,64 +37,61 @@ public class TypeIO{
|
|||
public static void writeObject(Writes write, Object object){
|
||||
if(object == null){
|
||||
write.b((byte)0);
|
||||
}else if(object instanceof Integer){
|
||||
}else if(object instanceof Integer i){
|
||||
write.b((byte)1);
|
||||
write.i((Integer)object);
|
||||
}else if(object instanceof Long){
|
||||
write.i(i);
|
||||
}else if(object instanceof Long l){
|
||||
write.b((byte)2);
|
||||
write.l((Long)object);
|
||||
}else if(object instanceof Float){
|
||||
write.l(l);
|
||||
}else if(object instanceof Float f){
|
||||
write.b((byte)3);
|
||||
write.f((Float)object);
|
||||
}else if(object instanceof String){
|
||||
write.f(f);
|
||||
}else if(object instanceof String s){
|
||||
write.b((byte)4);
|
||||
writeString(write, (String)object);
|
||||
}else if(object instanceof Content){
|
||||
Content map = (Content)object;
|
||||
writeString(write, s);
|
||||
}else if(object instanceof Content map){
|
||||
write.b((byte)5);
|
||||
write.b((byte)map.getContentType().ordinal());
|
||||
write.s(map.id);
|
||||
}else if(object instanceof IntSeq){
|
||||
}else if(object instanceof IntSeq arr){
|
||||
write.b((byte)6);
|
||||
IntSeq arr = (IntSeq)object;
|
||||
write.s((short)arr.size);
|
||||
for(int i = 0; i < arr.size; i++){
|
||||
write.i(arr.items[i]);
|
||||
}
|
||||
}else if(object instanceof Point2){
|
||||
}else if(object instanceof Point2 p){
|
||||
write.b((byte)7);
|
||||
write.i(((Point2)object).x);
|
||||
write.i(((Point2)object).y);
|
||||
}else if(object instanceof Point2[]){
|
||||
write.i(p.x);
|
||||
write.i(p.y);
|
||||
}else if(object instanceof Point2[] p){
|
||||
write.b((byte)8);
|
||||
write.b(((Point2[])object).length);
|
||||
for(int i = 0; i < ((Point2[])object).length; i++){
|
||||
write.i(((Point2[])object)[i].pack());
|
||||
write.b(p.length);
|
||||
for(Point2 point2 : p){
|
||||
write.i(point2.pack());
|
||||
}
|
||||
}else if(object instanceof TechNode){
|
||||
TechNode map = (TechNode)object;
|
||||
}else if(object instanceof TechNode map){
|
||||
write.b(9);
|
||||
write.b((byte)map.content.getContentType().ordinal());
|
||||
write.s(map.content.id);
|
||||
}else if(object instanceof Boolean){
|
||||
}else if(object instanceof Boolean b){
|
||||
write.b((byte)10);
|
||||
write.bool((Boolean)object);
|
||||
}else if(object instanceof Double){
|
||||
write.bool(b);
|
||||
}else if(object instanceof Double d){
|
||||
write.b((byte)11);
|
||||
write.d((Double)object);
|
||||
}else if(object instanceof Building){
|
||||
write.b((byte)12);
|
||||
write.i(((Building)object).pos());
|
||||
}else if(object instanceof LAccess){
|
||||
write.d(d);
|
||||
}else if(object instanceof Building b){
|
||||
write.b(12);
|
||||
write.i(b.pos());
|
||||
}else if(object instanceof LAccess l){
|
||||
write.b((byte)13);
|
||||
write.s(((LAccess)object).ordinal());
|
||||
}else if(object instanceof byte[]){
|
||||
write.s(l.ordinal());
|
||||
}else if(object instanceof byte[] b){
|
||||
write.b((byte)14);
|
||||
write.i(((byte[])object).length);
|
||||
write.b((byte[])object);
|
||||
}else if(object instanceof UnitCommand){
|
||||
write.i(b.length);
|
||||
write.b(b);
|
||||
}else if(object instanceof UnitCommand c){
|
||||
write.b((byte)15);
|
||||
write.b(((UnitCommand)object).ordinal());
|
||||
write.b(c.ordinal());
|
||||
}else{
|
||||
throw new IllegalArgumentException("Unknown object type: " + object.getClass());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -397,11 +397,11 @@ public class LExecutor{
|
|||
//TODO copy pasted code
|
||||
if(tile != null && tile.team == unit.team){
|
||||
if(tile.block.buildVisibility != BuildVisibility.hidden && tile.canPickup() && pay.canPickup(tile)){
|
||||
Call.pickedBlockPayload(unit, tile, true);
|
||||
Call.pickedBuildPayload(unit, tile, true);
|
||||
}else{ //pick up block payload
|
||||
Payload current = tile.getPayload();
|
||||
if(current != null && pay.canPickupPayload(current)){
|
||||
Call.pickedBlockPayload(unit, tile, false);
|
||||
Call.pickedBuildPayload(unit, tile, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -494,8 +494,7 @@ public class LExecutor{
|
|||
@Override
|
||||
public void run(LExecutor exec){
|
||||
Object obj = exec.obj(target);
|
||||
if(obj instanceof Controllable){
|
||||
Controllable cont = (Controllable)obj;
|
||||
if(obj instanceof Controllable cont){
|
||||
if(type.isObj){
|
||||
cont.control(type, exec.obj(p1), exec.num(p2), exec.num(p3), exec.num(p4));
|
||||
}else{
|
||||
|
|
@ -541,8 +540,7 @@ public class LExecutor{
|
|||
int address = exec.numi(position);
|
||||
Building from = exec.building(target);
|
||||
|
||||
if(from instanceof MemoryBuild){
|
||||
MemoryBuild mem = (MemoryBuild)from;
|
||||
if(from instanceof MemoryBuild mem){
|
||||
|
||||
exec.setnum(output, address < 0 || address >= mem.memory.length ? 0 : mem.memory[address]);
|
||||
}
|
||||
|
|
@ -566,8 +564,7 @@ public class LExecutor{
|
|||
int address = exec.numi(position);
|
||||
Building from = exec.building(target);
|
||||
|
||||
if(from instanceof MemoryBuild){
|
||||
MemoryBuild mem = (MemoryBuild)from;
|
||||
if(from instanceof MemoryBuild mem){
|
||||
|
||||
if(address >= 0 && address < mem.memory.length){
|
||||
mem.memory[address] = exec.num(value);
|
||||
|
|
@ -594,8 +591,7 @@ public class LExecutor{
|
|||
Object target = exec.obj(from);
|
||||
Object sense = exec.obj(type);
|
||||
|
||||
if(target instanceof Senseable){
|
||||
Senseable se = (Senseable)target;
|
||||
if(target instanceof Senseable se){
|
||||
if(sense instanceof Content){
|
||||
exec.setnum(to, se.sense(((Content)sense)));
|
||||
}else if(sense instanceof LAccess){
|
||||
|
|
@ -823,8 +819,7 @@ public class LExecutor{
|
|||
if(Vars.headless) return;
|
||||
|
||||
Building build = exec.building(target);
|
||||
if(build instanceof LogicDisplayBuild){
|
||||
LogicDisplayBuild d = (LogicDisplayBuild)build;
|
||||
if(build instanceof LogicDisplayBuild d){
|
||||
if(d.commands.size + exec.graphicsBuffer.size < maxDisplayBuffer){
|
||||
for(int i = 0; i < exec.graphicsBuffer.size; i++){
|
||||
d.commands.addLast(exec.graphicsBuffer.items[i]);
|
||||
|
|
@ -886,8 +881,7 @@ public class LExecutor{
|
|||
public void run(LExecutor exec){
|
||||
|
||||
Building build = exec.building(target);
|
||||
if(build instanceof MessageBuild){
|
||||
MessageBuild d = (MessageBuild)build;
|
||||
if(build instanceof MessageBuild d){
|
||||
|
||||
d.message.setLength(0);
|
||||
d.message.append(exec.textBuffer, 0, Math.min(exec.textBuffer.length(), maxTextBuffer));
|
||||
|
|
|
|||
|
|
@ -182,8 +182,7 @@ public class BaseGenerator{
|
|||
}
|
||||
}
|
||||
|
||||
if(part.required instanceof Item){
|
||||
Item item = (Item)part.required;
|
||||
if(part.required instanceof Item item){
|
||||
for(Stile tile : result.tiles){
|
||||
if(tile.block instanceof Drill){
|
||||
|
||||
|
|
@ -206,8 +205,7 @@ public class BaseGenerator{
|
|||
Schematics.place(result, cx + result.width/2, cy + result.height/2, team);
|
||||
|
||||
//fill drills with items after placing
|
||||
if(part.required instanceof Item){
|
||||
Item item = (Item)part.required;
|
||||
if(part.required instanceof Item item){
|
||||
for(Stile tile : result.tiles){
|
||||
if(tile.block instanceof Drill){
|
||||
|
||||
|
|
|
|||
|
|
@ -170,8 +170,7 @@ public class Mods implements Loadable{
|
|||
//generate new icons
|
||||
for(Seq<Content> arr : content.getContentMap()){
|
||||
arr.each(c -> {
|
||||
if(c instanceof UnlockableContent && c.minfo.mod != null){
|
||||
UnlockableContent u = (UnlockableContent)c;
|
||||
if(c instanceof UnlockableContent u && c.minfo.mod != null){
|
||||
u.load();
|
||||
u.createIcons(packer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -361,8 +361,7 @@ public class ArcNetProvider implements NetProvider{
|
|||
}
|
||||
|
||||
public void writeFramework(ByteBuffer buffer, FrameworkMessage message){
|
||||
if(message instanceof Ping){
|
||||
Ping p = (Ping)message;
|
||||
if(message instanceof Ping p){
|
||||
buffer.put((byte)0);
|
||||
buffer.putInt(p.id);
|
||||
buffer.put(p.isReply ? 1 : (byte)0);
|
||||
|
|
@ -370,12 +369,10 @@ public class ArcNetProvider implements NetProvider{
|
|||
buffer.put((byte)1);
|
||||
}else if(message instanceof KeepAlive){
|
||||
buffer.put((byte)2);
|
||||
}else if(message instanceof RegisterUDP){
|
||||
RegisterUDP p = (RegisterUDP)message;
|
||||
}else if(message instanceof RegisterUDP p){
|
||||
buffer.put((byte)3);
|
||||
buffer.putInt(p.connectionID);
|
||||
}else if(message instanceof RegisterTCP){
|
||||
RegisterTCP p = (RegisterTCP)message;
|
||||
}else if(message instanceof RegisterTCP p){
|
||||
buffer.put((byte)4);
|
||||
buffer.putInt(p.connectionID);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -237,12 +237,10 @@ public class Net{
|
|||
*/
|
||||
public void handleClientReceived(Object object){
|
||||
|
||||
if(object instanceof StreamBegin){
|
||||
StreamBegin b = (StreamBegin)object;
|
||||
if(object instanceof StreamBegin b){
|
||||
streams.put(b.id, currentStream = new StreamBuilder(b));
|
||||
|
||||
}else if(object instanceof StreamChunk){
|
||||
StreamChunk c = (StreamChunk)object;
|
||||
}else if(object instanceof StreamChunk c){
|
||||
StreamBuilder builder = streams.get(c.id);
|
||||
if(builder == null){
|
||||
throw new RuntimeException("Received stream chunk without a StreamBegin beforehand!");
|
||||
|
|
|
|||
|
|
@ -175,8 +175,7 @@ public class UnitType extends UnlockableContent{
|
|||
public void getDependencies(Cons<UnlockableContent> cons){
|
||||
//units require reconstructors being researched
|
||||
for(Block block : content.blocks()){
|
||||
if(block instanceof Reconstructor){
|
||||
Reconstructor r = (Reconstructor)block;
|
||||
if(block instanceof Reconstructor r){
|
||||
for(UnitType[] recipe : r.upgrades){
|
||||
//result of reconstruction is this, so it must be a dependency
|
||||
if(recipe[1] == this){
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class BlockForge extends PayloadAcceptor{
|
|||
Draw.rect(outRegion, req.drawx(), req.drawy(), req.rotation * 90);
|
||||
}
|
||||
|
||||
public class BlockForgeBuild extends PayloadAcceptorBuild<BlockPayload>{
|
||||
public class BlockForgeBuild extends PayloadAcceptorBuild<BuildPayload>{
|
||||
public @Nullable Block recipe;
|
||||
public float progress, time, heat;
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ public class BlockForge extends PayloadAcceptor{
|
|||
|
||||
if(progress >= recipe.buildCost){
|
||||
consume();
|
||||
payload = new BlockPayload(recipe, team);
|
||||
payload = new BuildPayload(recipe, team);
|
||||
progress = 0f;
|
||||
}
|
||||
}else{
|
||||
|
|
|
|||
|
|
@ -50,13 +50,13 @@ public class BlockLoader extends PayloadAcceptor{
|
|||
Draw.rect(topRegion, req.drawx(), req.drawy());
|
||||
}
|
||||
|
||||
public class BlockLoaderBuild extends PayloadAcceptorBuild<BlockPayload>{
|
||||
public class BlockLoaderBuild extends PayloadAcceptorBuild<BuildPayload>{
|
||||
|
||||
@Override
|
||||
public boolean acceptPayload(Building source, Payload payload){
|
||||
return super.acceptPayload(source, payload) &&
|
||||
(payload instanceof BlockPayload) &&
|
||||
((((BlockPayload)payload).entity.block.hasItems && ((BlockPayload)payload).block().unloadable && ((BlockPayload)payload).block().itemCapacity >= 10)/* ||
|
||||
(payload instanceof BuildPayload) &&
|
||||
((((BuildPayload)payload).build.block.hasItems && ((BuildPayload)payload).block().unloadable && ((BuildPayload)payload).block().itemCapacity >= 10)/* ||
|
||||
((BlockPayload)payload).entity.block().hasLiquids && ((BlockPayload)payload).block().liquidCapacity >= 10f)*/);
|
||||
}
|
||||
|
||||
|
|
@ -101,8 +101,8 @@ public class BlockLoader extends PayloadAcceptor{
|
|||
for(int i = 0; i < items.length(); i++){
|
||||
if(items.get(i) > 0){
|
||||
Item item = content.item(i);
|
||||
if(payload.entity.acceptItem(payload.entity, item)){
|
||||
payload.entity.handleItem(payload.entity, item);
|
||||
if(payload.build.acceptItem(payload.build, item)){
|
||||
payload.build.handleItem(payload.build, item);
|
||||
items.remove(item, 1);
|
||||
break;
|
||||
}
|
||||
|
|
@ -127,13 +127,13 @@ public class BlockLoader extends PayloadAcceptor{
|
|||
}
|
||||
|
||||
public float fraction(){
|
||||
return payload == null ? 0f : payload.entity.items.total() / (float)payload.entity.block.itemCapacity;
|
||||
return payload == null ? 0f : payload.build.items.total() / (float)payload.build.block.itemCapacity;
|
||||
}
|
||||
|
||||
public boolean shouldExport(){
|
||||
return payload != null &&
|
||||
((payload.block().hasLiquids && payload.entity.liquids.total() >= payload.block().liquidCapacity - 0.001f) ||
|
||||
(payload.block().hasItems && payload.entity.items.total() >= payload.block().itemCapacity));
|
||||
((payload.block().hasLiquids && payload.build.liquids.total() >= payload.block().liquidCapacity - 0.001f) ||
|
||||
(payload.block().hasItems && payload.build.items.total() >= payload.block().itemCapacity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ public class BlockUnloader extends BlockLoader{
|
|||
//load up items a set amount of times
|
||||
for(int j = 0; j < itemsLoaded && !full(); j++){
|
||||
for(int i = 0; i < items.length(); i++){
|
||||
if(payload.entity.items.get(i) > 0){
|
||||
if(payload.build.items.get(i) > 0){
|
||||
Item item = content.item(i);
|
||||
payload.entity.items.remove(item, 1);
|
||||
payload.build.items.remove(item, 1);
|
||||
items.add(item, 1);
|
||||
break;
|
||||
}
|
||||
|
|
@ -56,12 +56,12 @@ public class BlockUnloader extends BlockLoader{
|
|||
|
||||
@Override
|
||||
public float fraction(){
|
||||
return payload == null ? 0f : 1f - payload.entity.items.total() / (float)payload.entity.block.itemCapacity;
|
||||
return payload == null ? 0f : 1f - payload.build.items.total() / (float)payload.build.block.itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExport(){
|
||||
return payload != null && (payload.block().hasItems && payload.entity.items.empty());
|
||||
return payload != null && (payload.block().hasItems && payload.build.items.empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,8 +129,7 @@ public class LogicBlock extends Block{
|
|||
|
||||
@Override
|
||||
public Object pointConfig(Object config, Cons<Point2> transformer){
|
||||
if(config instanceof byte[]){
|
||||
byte[] data = (byte[])config;
|
||||
if(config instanceof byte[] data){
|
||||
|
||||
try(DataInputStream stream = new DataInputStream(new InflaterInputStream(new ByteArrayInputStream(data)))){
|
||||
//discard version for now
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
package mindustry.world.blocks.payloads;
|
||||
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class BlockPayload implements Payload{
|
||||
public Building entity;
|
||||
|
||||
public BlockPayload(Block block, Team team){
|
||||
this.entity = block.newBuilding().create(block, team);
|
||||
}
|
||||
|
||||
public BlockPayload(Building entity){
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public Block block(){
|
||||
return entity.block;
|
||||
}
|
||||
|
||||
public void place(Tile tile){
|
||||
place(tile, 0);
|
||||
}
|
||||
|
||||
public void place(Tile tile, int rotation){
|
||||
tile.setBlock(entity.block, entity.team, rotation, () -> entity);
|
||||
entity.dropped();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float size(){
|
||||
return entity.block.size * tilesize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
write.b(payloadBlock);
|
||||
write.s(entity.block.id);
|
||||
write.b(entity.version());
|
||||
entity.writeAll(write);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(float x, float y, float rotation){
|
||||
entity.set(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
Drawf.shadow(entity.x, entity.y, entity.block.size * tilesize * 2f);
|
||||
Draw.rect(entity.block.icon(Cicon.full), entity.x, entity.y);
|
||||
}
|
||||
}
|
||||
60
core/src/mindustry/world/blocks/payloads/BuildPayload.java
Normal file
60
core/src/mindustry/world/blocks/payloads/BuildPayload.java
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
package mindustry.world.blocks.payloads;
|
||||
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class BuildPayload implements Payload{
|
||||
public Building build;
|
||||
|
||||
public BuildPayload(Block block, Team team){
|
||||
this.build = block.newBuilding().create(block, team);
|
||||
}
|
||||
|
||||
public BuildPayload(Building build){
|
||||
this.build = build;
|
||||
}
|
||||
|
||||
public Block block(){
|
||||
return build.block;
|
||||
}
|
||||
|
||||
public void place(Tile tile){
|
||||
place(tile, 0);
|
||||
}
|
||||
|
||||
public void place(Tile tile, int rotation){
|
||||
tile.setBlock(build.block, build.team, rotation, () -> build);
|
||||
build.dropped();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float size(){
|
||||
return build.block.size * tilesize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
write.b(payloadBlock);
|
||||
write.s(build.block.id);
|
||||
write.b(build.version());
|
||||
build.writeAll(write);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(float x, float y, float rotation){
|
||||
build.set(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
Drawf.shadow(build.x, build.y, build.block.size * tilesize * 2f);
|
||||
Draw.rect(build.block.icon(Cicon.full), build.x, build.y);
|
||||
}
|
||||
}
|
||||
|
|
@ -51,9 +51,9 @@ public interface Payload{
|
|||
byte type = read.b();
|
||||
if(type == payloadBlock){
|
||||
Block block = content.block(read.s());
|
||||
BlockPayload payload = new BlockPayload(block, Team.derelict);
|
||||
BuildPayload payload = new BuildPayload(block, Team.derelict);
|
||||
byte version = read.b();
|
||||
payload.entity.readAll(read, version);
|
||||
payload.build.readAll(read, version);
|
||||
return (T)payload;
|
||||
}else if(type == payloadUnit){
|
||||
byte id = read.b();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue