Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions main/src/omaloon/content/blocks/OlDistributionBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static void load(){
health = 65;
}};

tubeOverflowGate = new TubeGate("tube-overflow-gate"){{
tubeOverflowGate = new TubeOverflowGate("tube-overflow-gate"){{
requirements(Category.distribution, with(
OlItems.cobalt, 3,
OlItems.nickel, 2, OlItems.composite, 1
Expand All @@ -83,12 +83,11 @@ public static void load(){
health = 65;
}};

tubeUnderflowGate = new TubeGate("tube-underflow-gate"){{
tubeUnderflowGate = new TubeUnderflowGate("tube-underflow-gate"){{
requirements(Category.distribution, with(
OlItems.cobalt, 3,
OlItems.nickel, 2, OlItems.composite, 1
));
reverse = true;
researchCostMultiplier = 0.3f;
health = 65;
}};
Expand Down
61 changes: 0 additions & 61 deletions main/src/omaloon/world/blocks/distribution/TubeGate.java
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for separate classes when you just can reverse an overflow gate

This file was deleted.

83 changes: 83 additions & 0 deletions main/src/omaloon/world/blocks/distribution/TubeOverflowGate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package omaloon.world.blocks.distribution;

import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.*;
import arc.util.*;
import arc.graphics.g2d.*;
import mindustry.graphics.*;

import static mindustry.Vars.itemSize;

public class TubeOverflowGate extends TubeRouter {
public TubeOverflowGate(String name){
super(name);
rotate = false;
}

public class TubeOverflowGateBuild extends TubeRouterBuild {

@Override
public void draw(){
Draw.z(Layer.block - 0.2f);
Draw.rect(bottomRegion, x, y);

Draw.z(Layer.block - 0.1f);
Building target = getTileTarget(lastItem, lastInput, false);
float rot = 0f;

if(target != null && lastItem != null && lastInput != null){
int turn = arc.math.Mathf.mod(relativeTo(target) + 1 - relativeTo(lastInput), 4) - 1;
rot = turn * 90f * arc.math.Mathf.clamp(time);
float d = itemInterp.apply(arc.math.Mathf.clamp(time));

Draw.rect(
lastItem.uiIcon,
x + arc.math.Angles.trnsx(rot + relativeTo(lastInput) * 90f, 4f * d),
y + arc.math.Angles.trnsy(rot + relativeTo(lastInput) * 90f, 4f * d),
itemSize,
itemSize
);
}

Draw.z(Layer.block);

float rotatorAngle = 45f;
if(target != null && lastItem != null && lastInput != null){
int turn = arc.math.Mathf.mod(relativeTo(target) + 1 - relativeTo(lastInput), 4) - 1;
rotatorAngle = rot + relativeTo(lastInput) * 90f + (turn > 0 ? -45f : 45f);
}

Drawf.spinSprite(rotatorRegion, x, y, rotatorAngle);
Draw.rect(region, x, y);
if(sideRegion[0].found()) Draw.rect(sideRegion[0], x, y, rotdeg());
}

@Override
public Building getTileTarget(Item item, Tile from, boolean set){
if(item == null || from == null) return null;

int otherDir = relativeTo(from);
Building front = nearby((otherDir + 2) % 4);

if(front != null && front.acceptItem(this, item)){
return front;
}else{
return lookSides(item, from, set);
}
}

public @Nullable Building lookSides(Item item, Tile from, boolean set){
int otherDir = relativeTo(from);
for(int i = 0; i < 4; i += 2){
Building other = nearby((otherDir + 1 + i + targetRot) % 4);
if(set) targetRot = (byte)((i + targetRot + 2) % 4);
if(other == null || other.tile == from) continue;
if(other.acceptItem(this, item)){
return other;
}
}
return null;
}
}
}
27 changes: 21 additions & 6 deletions main/src/omaloon/world/blocks/distribution/TubeRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ public void setStats(){

public class TubeRouterBuild extends RouterBuild{
public byte targetRot = (byte)rotation;
public arc.struct.IntSeq buffer = new arc.struct.IntSeq();

@Override
public boolean acceptItem(Building source, Item item){
return super.acceptItem(source, item) && source != front();
return super.acceptItem(source, item) && source != front() && items.total() < itemCapacity;
}

@Override
public void handleItem(Building source, Item item){
buffer.add(item.id, source == null ? 0 : source.tile.pos());
items.add(item, 1);
}

@Override
Expand All @@ -76,9 +83,10 @@ public void draw(){
Draw.z(Layer.block - 0.1f);
Building target = getTileTarget(lastItem, lastInput, false);
float rot = 0f;
int turn = 0;

if(target != null && lastItem != null && lastInput != null){
int turn = Mathf.mod(relativeTo(target) + 1 - relativeTo(lastInput), 4) - 1;
turn = Mathf.mod(relativeTo(target) + 1 - relativeTo(lastInput), 4) - 1;

rot = turn * 90f * Mathf.clamp(time);
float d = itemInterp.apply(Mathf.clamp(time));
Expand All @@ -94,7 +102,8 @@ public void draw(){

Draw.z(Layer.block);

Drawf.spinSprite(rotatorRegion, x, y, rot + 45f);
float pushOffset = (turn == 1 ? 30f : (turn == -1 ? -30f : 0f));
Drawf.spinSprite(rotatorRegion, x, y, rot + 45f + pushOffset);
Draw.rect(region, x, y);
if(sideRegion[rotation > 1 ? 1 : 0].found()) Draw.rect(sideRegion[rotation > 1 ? 1 : 0], x, y, rotdeg());
}
Expand All @@ -116,20 +125,26 @@ public void draw(){

@Override
public void updateTile(){
if(lastItem == null && items.any()){
lastItem = items.first();
if(lastItem == null && buffer.size > 0){
int id = buffer.removeIndex(0);
int pos = buffer.removeIndex(0);
lastItem = mindustry.Vars.content.item(id);
lastInput = mindustry.Vars.world.tile(pos);
time = 0f;
}

Building target = getTileTarget(lastItem, lastInput, false);

if(lastItem != null && target != null){
time += 1f / speed * delta();
float speedMultiplier = 1f + (buffer.size / 2f);
time += 1f / speed * delta() * speedMultiplier;

if(time >= 1f || instantTransfer){
getTileTarget(lastItem, lastInput, true);
target.handleItem(this, lastItem);
items.remove(lastItem, 1);
lastItem = null;
if(time > 1f) time -= 1f; else time = 0f;
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions main/src/omaloon/world/blocks/distribution/TubeUnderflowGate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package omaloon.world.blocks.distribution;

import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.*;
import arc.util.*;

public class TubeUnderflowGate extends TubeOverflowGate {
public TubeUnderflowGate(String name) {
super(name);
}

public class TubeUnderflowGateBuild extends TubeOverflowGateBuild {
@Override
public Building getTileTarget(Item item, Tile from, boolean set){
if(item == null || from == null) return null;

int otherDir = relativeTo(from);
Building front = nearby((otherDir + 2) % 4);

Building side = lookSides(item, from, set);
if(side != null){
return side;
}else if (front != null && front.acceptItem(this, item)){
return front;
}

return null;
}
}
}