Moved rotation to Building

This commit is contained in:
Anuken
2020-07-29 10:19:07 -04:00
parent 749b9f5b30
commit 8729410cd8
49 changed files with 154 additions and 202 deletions

View File

@@ -49,7 +49,7 @@ abstract class BuilderComp implements Unitc{
while(it.hasNext()){
BuildPlan req = it.next();
Tile tile = world.tile(req.x, req.y);
if(tile == null || (req.breaking && tile.block() == Blocks.air) || (!req.breaking && (tile.rotation() == req.rotation || !req.block.rotate) && tile.block() == req.block)){
if(tile == null || (req.breaking && tile.block() == Blocks.air) || (!req.breaking && ((tile.build != null && tile.build.rotation == req.rotation) || !req.block.rotate) && tile.block() == req.block)){
it.remove();
}
}

View File

@@ -53,6 +53,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
transient Seq<Building> proximity = new Seq<>(8);
transient boolean updateFlow;
transient byte dump;
transient int rotation;
PowerModule power;
ItemModule items;
@@ -68,10 +69,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
private transient boolean initialized;
/** Sets this tile entity data to this and adds it if necessary. */
public Building init(Tile tile, Team team, boolean shouldAdd){
public Building init(Tile tile, Team team, boolean shouldAdd, int rotation){
if(!initialized){
create(tile.block(), team);
}
this.rotation = rotation;
this.tile = tile;
set(tile.drawx(), tile.drawy());
@@ -129,7 +131,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
public final void writeBase(Writes write){
write.f(health);
write.b(rotation());
write.b(rotation);
write.b(team.id);
if(items != null) items.write(write);
if(power != null) power.write(write);
@@ -231,25 +233,25 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
/** Multiblock front. */
public @Nullable Building front(){
int trns = block.size/2 + 1;
return nearby(Geometry.d4(rotation()).x * trns, Geometry.d4(rotation()).y * trns);
return nearby(Geometry.d4(rotation).x * trns, Geometry.d4(rotation).y * trns);
}
/** Multiblock back. */
public @Nullable Building back(){
int trns = block.size/2 + 1;
return nearby(Geometry.d4(rotation() + 2).x * trns, Geometry.d4(rotation() + 2).y * trns);
return nearby(Geometry.d4(rotation + 2).x * trns, Geometry.d4(rotation + 2).y * trns);
}
/** Multiblock left. */
public @Nullable Building left(){
int trns = block.size/2 + 1;
return nearby(Geometry.d4(rotation() + 1).x * trns, Geometry.d4(rotation() + 1).y * trns);
return nearby(Geometry.d4(rotation + 1).x * trns, Geometry.d4(rotation + 1).y * trns);
}
/** Multiblock right. */
public @Nullable Building right(){
int trns = block.size/2 + 1;
return nearby(Geometry.d4(rotation() + 3).x * trns, Geometry.d4(rotation() + 3).y * trns);
return nearby(Geometry.d4(rotation + 3).x * trns, Geometry.d4(rotation + 3).y * trns);
}
public int pos(){
@@ -257,15 +259,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
}
public float rotdeg(){
return tile.rotdeg();
}
public int rotation(){
return tile.rotation();
}
public void rotation(int rotation){
if(tile != null) tile.rotation(rotation);
return rotation * 90;
}
public Floor floor(){
@@ -398,7 +392,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
*/
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);
Tile next = tile.getNearby(Geometry.d4(rotation).x * trns, Geometry.d4(rotation).y * trns);
if(next != null && next.build != null && next.build.team() == team && next.build.acceptPayload(base(), todump)){
next.build.handlePayload(base(), todump);
@@ -481,7 +475,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
}
public float moveLiquidForward(float leakResistance, Liquid liquid){
Tile next = tile.getNearby(rotation());
Tile next = tile.getNearby(rotation);
if(next == null) return 0;

View File

@@ -89,7 +89,7 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc{
Building tile = payload.entity;
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())){
if(on != null && Build.validPlace(tile.block(), tile.team(), tx, ty, tile.rotation)){
int rot = (int)((rotation + 45f) / 90f) % 4;
payload.place(on, rot);

View File

@@ -3,6 +3,7 @@ package mindustry.entities.units;
import arc.func.*;
import arc.math.geom.*;
import arc.util.ArcAnnotate.*;
import mindustry.gen.*;
import mindustry.world.*;
import static mindustry.Vars.*;
@@ -134,6 +135,10 @@ public class BuildPlan{
return world.tile(x, y);
}
public @Nullable Building build(){
return world.build(x, y);
}
@Override
public String toString(){
return "BuildRequest{" +