Functional payload factories
|
Before Width: | Height: | Size: 793 B |
|
Before Width: | Height: | Size: 430 B |
|
Before Width: | Height: | Size: 801 B |
|
Before Width: | Height: | Size: 430 B |
|
Before Width: | Height: | Size: 641 B After Width: | Height: | Size: 651 B |
|
Before Width: | Height: | Size: 955 B |
|
Before Width: | Height: | Size: 956 B |
|
Before Width: | Height: | Size: 880 B |
|
Before Width: | Height: | Size: 430 B |
|
Before Width: | Height: | Size: 883 B |
|
Before Width: | Height: | Size: 430 B |
|
Before Width: | Height: | Size: 953 B |
|
Before Width: | Height: | Size: 882 B |
|
Before Width: | Height: | Size: 430 B |
@@ -258,15 +258,15 @@ public class UnitTypes implements ContentList{
|
|||||||
alpha = new UnitType("alpha"){{
|
alpha = new UnitType("alpha"){{
|
||||||
flying = true;
|
flying = true;
|
||||||
mineSpeed = 2f;
|
mineSpeed = 2f;
|
||||||
|
buildSpeed = 0.5f;
|
||||||
drag = 0.05f;
|
drag = 0.05f;
|
||||||
mass = 2f;
|
mass = 2f;
|
||||||
speed = 2.4f;
|
speed = 2.4f;
|
||||||
rotateSpeed = 15f;
|
rotateSpeed = 15f;
|
||||||
accel = 0.1f;
|
accel = 0.1f;
|
||||||
range = 70f;
|
range = 70f;
|
||||||
itemCapacity = 70;
|
itemCapacity = 30;
|
||||||
health = 400;
|
health = 400;
|
||||||
buildSpeed = 0.85f;
|
|
||||||
engineOffset = 6f;
|
engineOffset = 6f;
|
||||||
hitsize = 8f;
|
hitsize = 8f;
|
||||||
|
|
||||||
@@ -292,7 +292,7 @@ public class UnitTypes implements ContentList{
|
|||||||
range = 70f;
|
range = 70f;
|
||||||
itemCapacity = 70;
|
itemCapacity = 70;
|
||||||
health = 400;
|
health = 400;
|
||||||
buildSpeed = 0.4f;
|
buildSpeed = 0.6f;
|
||||||
engineOffset = 6.5f;
|
engineOffset = 6.5f;
|
||||||
hitsize = 8f;
|
hitsize = 8f;
|
||||||
}};
|
}};
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ abstract class PosComp implements Position{
|
|||||||
set(this.x + x, this.y + y);
|
set(this.x + x, this.y + y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void trns(Position pos){
|
||||||
|
trns(pos.getX(), pos.getY());
|
||||||
|
}
|
||||||
|
|
||||||
int tileX(){
|
int tileX(){
|
||||||
return Vars.world.toTile(x);
|
return Vars.world.toTile(x);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,6 +197,11 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||||||
return tile.absoluteRelativeTo(cx, cy);
|
return tile.absoluteRelativeTo(cx, cy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable Tile frontLarge(){
|
||||||
|
int trns = block.size/2 + 1;
|
||||||
|
return tile.getNearby(Geometry.d4(rotation()).x * trns, Geometry.d4(rotation()).y * trns);
|
||||||
|
}
|
||||||
|
|
||||||
public @Nullable Tilec front(){
|
public @Nullable Tilec front(){
|
||||||
return nearby((rotation() + 4) % 4);
|
return nearby((rotation() + 4) % 4);
|
||||||
}
|
}
|
||||||
@@ -217,6 +222,10 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||||||
return tile.pos();
|
return tile.pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float rotdeg(){
|
||||||
|
return tile.rotation() * 90;
|
||||||
|
}
|
||||||
|
|
||||||
public int rotation(){
|
public int rotation(){
|
||||||
return tile.rotation();
|
return tile.rotation();
|
||||||
}
|
}
|
||||||
@@ -345,13 +354,30 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries dumping a payload.
|
* Tries moving a payload forwards.
|
||||||
|
* @param todump payload to dump.
|
||||||
|
* @return whether the payload was moved successfully
|
||||||
|
*/
|
||||||
|
public boolean movePayload(@NonNull Payload todump){
|
||||||
|
int trns = block.size/2 + 1;
|
||||||
|
Tile next = tile.getNearby(Geometry.d4(rotation()).x * trns, Geometry.d4(rotation()).y * trns);
|
||||||
|
|
||||||
|
if(next != null && next.entity != null && next.entity.team() == team() && next.entity.acceptPayload(this, todump)){
|
||||||
|
next.entity.handlePayload(this, todump);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries dumping a payload to any adjacent block.
|
||||||
* @param todump payload to dump.
|
* @param todump payload to dump.
|
||||||
* @return whether the payload was moved successfully
|
* @return whether the payload was moved successfully
|
||||||
*/
|
*/
|
||||||
public boolean dumpPayload(@NonNull Payload todump){
|
public boolean dumpPayload(@NonNull Payload todump){
|
||||||
Array<Tilec> proximity = proximity();
|
|
||||||
int dump = rotation();
|
int dump = rotation();
|
||||||
|
|
||||||
if(proximity.size == 0) return false;
|
if(proximity.size == 0) return false;
|
||||||
|
|||||||
@@ -7,12 +7,11 @@ import arc.math.*;
|
|||||||
import arc.scene.style.*;
|
import arc.scene.style.*;
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
|
||||||
import arc.util.ArcAnnotate.*;
|
import arc.util.ArcAnnotate.*;
|
||||||
|
import arc.util.*;
|
||||||
import arc.util.io.*;
|
import arc.util.io.*;
|
||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.content.*;
|
|
||||||
import mindustry.entities.*;
|
import mindustry.entities.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
import mindustry.game.EventType.*;
|
import mindustry.game.EventType.*;
|
||||||
@@ -29,7 +28,7 @@ import mindustry.world.meta.*;
|
|||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class UnitFactory extends Block{
|
public class UnitFactory extends Block{
|
||||||
public float launchVelocity = 5f;
|
public float payloadSpeed = 0.5f;
|
||||||
public @Load(value = "@-top", fallback = "factory-top") TextureRegion topRegion;
|
public @Load(value = "@-top", fallback = "factory-top") TextureRegion topRegion;
|
||||||
public @Load(value = "@-out", fallback = "factory-out") TextureRegion outRegion;
|
public @Load(value = "@-out", fallback = "factory-out") TextureRegion outRegion;
|
||||||
public int[] capacities;
|
public int[] capacities;
|
||||||
@@ -128,31 +127,13 @@ public class UnitFactory extends Block{
|
|||||||
|
|
||||||
public class UnitFactoryEntity extends TileEntity{
|
public class UnitFactoryEntity extends TileEntity{
|
||||||
public int currentPlan = -1;
|
public int currentPlan = -1;
|
||||||
public float progress, time, speedScl;
|
public float progress, time, speedScl, payloadPos;
|
||||||
public @Nullable Payload payload;
|
public @Nullable UnitPayload payload;
|
||||||
|
|
||||||
public float fraction(){
|
public float fraction(){
|
||||||
return currentPlan == -1 ? 0 : progress / plans[currentPlan].time;
|
return currentPlan == -1 ? 0 : progress / plans[currentPlan].time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void spawned(){
|
|
||||||
progress = 0f;
|
|
||||||
|
|
||||||
Effects.shake(2f, 3f, this);
|
|
||||||
Fx.producesmoke.at(this);
|
|
||||||
|
|
||||||
if(!net.client() && currentPlan != -1){
|
|
||||||
UnitPlan plan = plans[currentPlan];
|
|
||||||
Unitc unit = plan.unit.create(team);
|
|
||||||
unit.set(x, y );
|
|
||||||
unit.add();
|
|
||||||
unit.rotation(90);
|
|
||||||
unit.vel().y = launchVelocity + Mathf.range(1f);
|
|
||||||
unit.vel().x = Mathf.range(1f);
|
|
||||||
Events.fire(new UnitCreateEvent(unit));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buildConfiguration(Table table){
|
public void buildConfiguration(Table table){
|
||||||
Array<UnitType> units = Array.with(plans).map(u -> u.unit);
|
Array<UnitType> units = Array.with(plans).map(u -> u.unit);
|
||||||
@@ -200,7 +181,7 @@ public class UnitFactory extends Block{
|
|||||||
Shaders.build.time = -time / 20f;
|
Shaders.build.time = -time / 20f;
|
||||||
|
|
||||||
Draw.shader(Shaders.build);
|
Draw.shader(Shaders.build);
|
||||||
Draw.rect(region, x, y);
|
Draw.rect(region, x, y, rotation() * 90 - 90);
|
||||||
Draw.shader();
|
Draw.shader();
|
||||||
|
|
||||||
Draw.color(Pal.accent);
|
Draw.color(Pal.accent);
|
||||||
@@ -212,14 +193,39 @@ public class UnitFactory extends Block{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Draw.z(Layer.blockOver);
|
||||||
|
|
||||||
if(payload != null){
|
if(payload != null){
|
||||||
payload.draw(x, y, rotation() * 90);
|
payload.draw(
|
||||||
|
x + Angles.trnsx(rotation() * 90, payloadPos),
|
||||||
|
y + Angles.trnsy(rotation() * 90, payloadPos),
|
||||||
|
rotation() * 90
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Draw.z(Layer.blockOver);
|
Draw.z(Layer.blockOver + 0.1f);
|
||||||
|
|
||||||
Draw.rect(topRegion, x, y);
|
Draw.rect(topRegion, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void spawned(){
|
||||||
|
progress = 0f;
|
||||||
|
|
||||||
|
if(!net.client() && payload != null){
|
||||||
|
Unitc unit = payload.unit;
|
||||||
|
unit.set(x, y);
|
||||||
|
|
||||||
|
unit.rotation(rotation() * 90);
|
||||||
|
unit.vel().trns(rotation() * 90, payloadSpeed * 2f).add(Mathf.range(0.1f), Mathf.range(0.1f));
|
||||||
|
unit.trns(Tmp.v1.trns(rotation() * 90, size * tilesize/2f));
|
||||||
|
unit.trns(unit.vel());
|
||||||
|
unit.add();
|
||||||
|
Events.fire(new UnitCreateEvent(unit));
|
||||||
|
}
|
||||||
|
|
||||||
|
payload = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTile(){
|
public void updateTile(){
|
||||||
if(currentPlan < 0 || currentPlan >= plans.length){
|
if(currentPlan < 0 || currentPlan >= plans.length){
|
||||||
@@ -235,16 +241,30 @@ public class UnitFactory extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(payload != null){
|
if(payload != null){
|
||||||
|
payloadPos += edelta() * payloadSpeed;
|
||||||
|
if(payloadPos >= size * tilesize/2f){
|
||||||
|
payloadPos = size * tilesize/2f;
|
||||||
|
|
||||||
|
Tile front = frontLarge();
|
||||||
|
if(front != null && front.entity != null && front.block().outputsPayload){
|
||||||
|
if(movePayload(payload)){
|
||||||
|
payload = null;
|
||||||
|
}
|
||||||
|
}else if(front != null && !front.solid()){
|
||||||
|
//create unit
|
||||||
|
Call.onUnitFactorySpawn(tile);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentPlan != -1 && payload != null){
|
if(currentPlan != -1 && payload == null){
|
||||||
UnitPlan plan = plans[currentPlan];
|
UnitPlan plan = plans[currentPlan];
|
||||||
|
|
||||||
if(progress >= plan.time && Units.canCreate(team)){
|
if(progress >= plan.time && Units.canCreate(team)){
|
||||||
progress = 0f;
|
progress = 0f;
|
||||||
|
|
||||||
this.payload = new UnitPayload(plan.unit.create(team));
|
payloadPos = 0f;
|
||||||
|
payload = new UnitPayload(plan.unit.create(team));
|
||||||
consume();
|
consume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||