From e79494b5cbbf9ed5850dbe787334b29e74aec284 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 19 Jun 2018 16:02:25 -0400 Subject: [PATCH] Implemented desktop carrying --- .../io/anuke/mindustry/entities/Player.java | 24 +++++++++++++------ .../mindustry/entities/traits/CarryTrait.java | 7 ++++++ .../anuke/mindustry/input/AndroidInput.java | 2 +- core/src/io/anuke/mindustry/type/Mech.java | 2 +- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index b80068fc39..bf958853d7 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -32,10 +32,7 @@ import io.anuke.ucore.entities.EntityGroup; import io.anuke.ucore.entities.trait.SolidTrait; import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Lines; -import io.anuke.ucore.util.Angles; -import io.anuke.ucore.util.Mathf; -import io.anuke.ucore.util.ThreadQueue; -import io.anuke.ucore.util.Timer; +import io.anuke.ucore.util.*; import java.io.DataInput; import java.io.DataOutput; @@ -448,13 +445,26 @@ public class Player extends Unit implements BuilderTrait, CarryTrait { if(mech.flying){ //prevent strafing backwards, have a penalty for doing so float angDist = Angles.angleDist(rotation, velocity.angle()) / 180f; - float penalty = 0.2f; + float penalty = 0.2f; //when going 180 degrees backwards, reduce speed to 0.2x speed *= Mathf.lerp(1f, penalty, angDist); } //drop from carrier on key press - if(Inputs.keyTap("drop_unit") && getCarrier() != null){ - getCarrier().dropCarry(); + if(Inputs.keyTap("drop_unit")){ + if(!mech.flying) { + if (getCarrier() != null) { + CallEntity.dropSelf(this); + } + }else if(getCarry() != null){ + dropCarry(); + }else{ + Unit unit = Units.getClosest(team, x, y, 8f, + u -> !u.isFlying() && u.getMass() <= mech.carryWeight); + + if(unit != null){ + carry(unit); + } + } } movement.set(0, 0); diff --git a/core/src/io/anuke/mindustry/entities/traits/CarryTrait.java b/core/src/io/anuke/mindustry/entities/traits/CarryTrait.java index 6413c817b4..9597711a38 100644 --- a/core/src/io/anuke/mindustry/entities/traits/CarryTrait.java +++ b/core/src/io/anuke/mindustry/entities/traits/CarryTrait.java @@ -32,6 +32,13 @@ public interface CarryTrait extends TeamTrait, SolidTrait, TargetTrait{ CallEntity.setCarryOf(this instanceof Player ? (Player)this : null, this, unit); } + @Remote(called = Loc.server, targets = Loc.both, forward = true, in = In.entities) + static void dropSelf(Player player){ + if(player.getCarrier() != null){ + player.getCarrier().dropCarry(); + } + } + @Remote(called = Loc.server, targets = Loc.both, forward = true, in = In.entities) static void setCarryOf(Player player, CarryTrait trait, CarriableTrait unit){ if(player != null){ //when a server recieves this called from a player, set the carrier to the player. diff --git a/core/src/io/anuke/mindustry/input/AndroidInput.java b/core/src/io/anuke/mindustry/input/AndroidInput.java index a71021c75e..f639a9255f 100644 --- a/core/src/io/anuke/mindustry/input/AndroidInput.java +++ b/core/src/io/anuke/mindustry/input/AndroidInput.java @@ -509,7 +509,7 @@ public class AndroidInput extends InputHandler implements GestureListener{ if(player.getCarry() != null){ player.dropCarry(); //drop off unit }else{ - Unit unit = Units.getClosest(player.getTeam(), Graphics.world(x, y).x, Graphics.world(x, y).y, 4f, u -> !u.isFlying()); + Unit unit = Units.getClosest(player.getTeam(), Graphics.world(x, y).x, Graphics.world(x, y).y, 4f, u -> !u.isFlying() && u.getMass() <= player.mech.carryWeight); if(unit != null){ player.pickupTarget = unit; diff --git a/core/src/io/anuke/mindustry/type/Mech.java b/core/src/io/anuke/mindustry/type/Mech.java index 307291fdf6..62814913ae 100644 --- a/core/src/io/anuke/mindustry/type/Mech.java +++ b/core/src/io/anuke/mindustry/type/Mech.java @@ -14,7 +14,7 @@ public class Mech extends Upgrade { public float armor = 1f; public int drillPower = -1; - public float carryWeight = 1f; + public float carryWeight = 10f; public float buildPower = 1f; public boolean canRepair = false;