Build weapon
This commit is contained in:
@@ -2680,7 +2680,7 @@ public class UnitTypes{
|
|||||||
targetAir = false;
|
targetAir = false;
|
||||||
mineSpeed = 8f;
|
mineSpeed = 8f;
|
||||||
mineTier = 3;
|
mineTier = 3;
|
||||||
buildSpeed = 1.4f;
|
buildSpeed = 2f;
|
||||||
drag = 0.06f;
|
drag = 0.06f;
|
||||||
speed = 2.6f;
|
speed = 2.6f;
|
||||||
rotateSpeed = 3f;
|
rotateSpeed = 3f;
|
||||||
@@ -2702,21 +2702,23 @@ public class UnitTypes{
|
|||||||
new UnitEngine(49 / 4f, -62 / 4f, es, 315f)
|
new UnitEngine(49 / 4f, -62 / 4f, es, 315f)
|
||||||
);
|
);
|
||||||
|
|
||||||
Vec2[] positions = {new Vec2(30f, 50f), new Vec2(60f, -15f)};
|
Vec2[] positions = {/*new Vec2(30f, 50f), */new Vec2(60f, -15f)};
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for(var pos : positions){
|
for(var pos : positions){
|
||||||
int fi = i;
|
int fi = i;
|
||||||
weapons.add(new Weapon("incite-weapon"){{
|
//TODO change to BuildWeapon properly, remove standard build beam and rotation
|
||||||
|
weapons.add(new BuildWeapon("incite-weapon"){{
|
||||||
rotate = true;
|
rotate = true;
|
||||||
reload = fi == 0 ? 25f : 35f;
|
reload = fi == 0 ? 25f : 35f;
|
||||||
rotateSpeed = 4f;
|
rotateSpeed = 7f;
|
||||||
x = pos.x/4f;
|
x = pos.x/4f;
|
||||||
y = pos.y/4f;
|
y = pos.y/4f;
|
||||||
shootY = 5.75f;
|
shootY = 5.75f;
|
||||||
recoil = 2f;
|
recoil = 2f;
|
||||||
rotationLimit = 90f;
|
|
||||||
layerOffset = -0.01f;
|
drawBuildBeam = false;
|
||||||
|
rotateToBuilding = false;
|
||||||
|
|
||||||
bullet = new BasicBulletType(5f, 17){{
|
bullet = new BasicBulletType(5f, 17){{
|
||||||
width = 7f;
|
width = 7f;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
|
|||||||
|
|
||||||
private transient BuildPlan lastActive;
|
private transient BuildPlan lastActive;
|
||||||
private transient int lastSize;
|
private transient int lastSize;
|
||||||
private transient float buildAlpha = 0f;
|
transient float buildAlpha = 0f;
|
||||||
|
|
||||||
public boolean canBuild(){
|
public boolean canBuild(){
|
||||||
return type.buildSpeed > 0 && buildSpeedMultiplier > 0;
|
return type.buildSpeed > 0 && buildSpeedMultiplier > 0;
|
||||||
@@ -257,13 +257,14 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drawBuilding(){
|
public void drawBuilding(){
|
||||||
|
//TODO make this more generic so it works with builder "weapons"
|
||||||
boolean active = activelyBuilding();
|
boolean active = activelyBuilding();
|
||||||
if(!active && lastActive == null) return;
|
if(!active && lastActive == null) return;
|
||||||
|
|
||||||
Draw.z(Layer.flyingUnit);
|
Draw.z(Layer.flyingUnit);
|
||||||
|
|
||||||
BuildPlan plan = active ? buildPlan() : lastActive;
|
BuildPlan plan = active ? buildPlan() : lastActive;
|
||||||
Tile tile = world.tile(plan.x, plan.y);
|
Tile tile = plan.tile();
|
||||||
var core = team.core();
|
var core = team.core();
|
||||||
|
|
||||||
if(tile == null || !within(plan, state.rules.infiniteResources ? Float.MAX_VALUE : type.buildRange)){
|
if(tile == null || !within(plan, state.rules.infiniteResources ? Float.MAX_VALUE : type.buildRange)){
|
||||||
@@ -278,14 +279,32 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
|
|||||||
Draw.z(Layer.flyingUnit);
|
Draw.z(Layer.flyingUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(type.drawBuildBeam){
|
||||||
|
float focusLen = type.buildBeamOffset + Mathf.absin(Time.time, 3f, 0.6f);
|
||||||
|
float px = x + Angles.trnsx(rotation, focusLen);
|
||||||
|
float py = y + Angles.trnsy(rotation, focusLen);
|
||||||
|
|
||||||
|
drawBuildingBeam(px, py);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawBuildingBeam(float px, float py){
|
||||||
|
boolean active = activelyBuilding();
|
||||||
|
if(!active && lastActive == null) return;
|
||||||
|
|
||||||
|
Draw.z(Layer.flyingUnit);
|
||||||
|
|
||||||
|
BuildPlan plan = active ? buildPlan() : lastActive;
|
||||||
|
Tile tile = world.tile(plan.x, plan.y);
|
||||||
|
|
||||||
|
if(tile == null || !within(plan, state.rules.infiniteResources ? Float.MAX_VALUE : type.buildRange)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int size = plan.breaking ? active ? tile.block().size : lastSize : plan.block.size;
|
int size = plan.breaking ? active ? tile.block().size : lastSize : plan.block.size;
|
||||||
float tx = plan.drawx(), ty = plan.drawy();
|
float tx = plan.drawx(), ty = plan.drawy();
|
||||||
|
|
||||||
Lines.stroke(1f, plan.breaking ? Pal.remove : Pal.accent);
|
Lines.stroke(1f, plan.breaking ? Pal.remove : Pal.accent);
|
||||||
float focusLen = type.buildBeamOffset + Mathf.absin(Time.time, 3f, 0.6f);
|
|
||||||
float px = x + Angles.trnsx(rotation, focusLen);
|
|
||||||
float py = y + Angles.trnsy(rotation, focusLen);
|
|
||||||
|
|
||||||
Draw.z(Layer.buildBeam);
|
Draw.z(Layer.buildBeam);
|
||||||
|
|
||||||
Draw.alpha(buildAlpha);
|
Draw.alpha(buildAlpha);
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
|||||||
|
|
||||||
/** @return where the unit wants to look at. */
|
/** @return where the unit wants to look at. */
|
||||||
public float prefRotation(){
|
public float prefRotation(){
|
||||||
if(activelyBuilding()){
|
if(activelyBuilding() && type.rotateToBuilding){
|
||||||
return angleTo(buildPlan());
|
return angleTo(buildPlan());
|
||||||
}else if(mineTile != null){
|
}else if(mineTile != null){
|
||||||
return angleTo(mineTile);
|
return angleTo(mineTile);
|
||||||
|
|||||||
@@ -401,6 +401,16 @@ public class BlockRenderer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO remove
|
||||||
|
Draw.z(Layer.overlayUI);
|
||||||
|
Lines.stroke(1f, Color.green);
|
||||||
|
|
||||||
|
blockTree.intersect(camera.bounds(Tmp.r1), tile -> {
|
||||||
|
Lines.rect(tile.getHitbox(Tmp.r2));
|
||||||
|
});
|
||||||
|
|
||||||
|
Draw.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
static class BlockQuadtree extends QuadTree<Tile>{
|
static class BlockQuadtree extends QuadTree<Tile>{
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ public class UnitType extends UnlockableContent{
|
|||||||
public float payloadCapacity = 8;
|
public float payloadCapacity = 8;
|
||||||
public float aimDst = -1f;
|
public float aimDst = -1f;
|
||||||
public float buildBeamOffset = 3.8f;
|
public float buildBeamOffset = 3.8f;
|
||||||
|
public boolean drawBuildBeam = true;
|
||||||
|
public boolean rotateToBuilding = true;
|
||||||
public int commandLimit = 8;
|
public int commandLimit = 8;
|
||||||
public float commandRadius = 150f;
|
public float commandRadius = 150f;
|
||||||
public float visualElevation = -1f;
|
public float visualElevation = -1f;
|
||||||
|
|||||||
63
core/src/mindustry/type/weapons/BuildWeapon.java
Normal file
63
core/src/mindustry/type/weapons/BuildWeapon.java
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
package mindustry.type.weapons;
|
||||||
|
|
||||||
|
import arc.math.*;
|
||||||
|
import mindustry.entities.units.*;
|
||||||
|
import mindustry.gen.*;
|
||||||
|
import mindustry.type.*;
|
||||||
|
|
||||||
|
/** Purely visual turret. Does not shoot anything. */
|
||||||
|
public class BuildWeapon extends Weapon{
|
||||||
|
|
||||||
|
public BuildWeapon(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public BuildWeapon(String name){
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
rotate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(Unit unit, WeaponMount mount){
|
||||||
|
//no
|
||||||
|
mount.shoot = false;
|
||||||
|
//yes
|
||||||
|
mount.rotate = true;
|
||||||
|
|
||||||
|
//always aim at build plan
|
||||||
|
if(unit.activelyBuilding()){
|
||||||
|
mount.aimX = unit.buildPlan().drawx();
|
||||||
|
mount.aimY = unit.buildPlan().drawy();
|
||||||
|
}else{
|
||||||
|
//aim for front
|
||||||
|
float weaponRotation = unit.rotation - 90;
|
||||||
|
mount.aimX = unit.x + Angles.trnsx(unit.rotation - 90, x, y) + Angles.trnsx(weaponRotation, this.shootX, this.shootY);
|
||||||
|
mount.aimY = unit.y + Angles.trnsy(unit.rotation - 90, x, y) + Angles.trnsy(weaponRotation, this.shootX, this.shootY);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.update(unit, mount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Unit unit, WeaponMount mount){
|
||||||
|
super.draw(unit, mount);
|
||||||
|
|
||||||
|
if(unit.activelyBuilding()){
|
||||||
|
|
||||||
|
float
|
||||||
|
rotation = unit.rotation - 90,
|
||||||
|
weaponRotation = rotation + (rotate ? mount.rotation : 0),
|
||||||
|
wx = unit.x + Angles.trnsx(rotation, x, y) + Angles.trnsx(weaponRotation, 0, -mount.recoil),
|
||||||
|
wy = unit.y + Angles.trnsy(rotation, x, y) + Angles.trnsy(weaponRotation, 0, -mount.recoil),
|
||||||
|
px = wx + Angles.trnsx(weaponRotation, this.shootX, this.shootY),
|
||||||
|
py = wy + Angles.trnsy(weaponRotation, this.shootX, this.shootY);
|
||||||
|
|
||||||
|
unit.drawBuildingBeam(px, py);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user