Replaced concept of "turns" with raw seconds
This commit is contained in:
@@ -484,6 +484,11 @@ public class Block extends UnlockableContent{
|
||||
|
||||
}
|
||||
|
||||
/** Called right before building of this block begins. */
|
||||
public void beforePlaceBegan(Tile tile, Block previous){
|
||||
|
||||
}
|
||||
|
||||
/** @return a message detailing why this block can't be placed. */
|
||||
public String unplaceableMessage(){
|
||||
return state.rules.bannedBlocks.contains(this) ? Core.bundle.get("banned") : buildPlaceability.message();
|
||||
|
||||
@@ -56,6 +56,8 @@ public class Build{
|
||||
Block previous = tile.block();
|
||||
Block sub = BuildBlock.get(result.size);
|
||||
|
||||
result.beforePlaceBegan(tile, previous);
|
||||
|
||||
tile.setBlock(sub, team, rotation);
|
||||
tile.<BuildEntity>bc().setConstruct(previous, result);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class CachedTile extends Tile{
|
||||
n.cons(new ConsumeModule(build));
|
||||
n.tile(this);
|
||||
n.block(block);
|
||||
if(block.hasItems) n.items(new ItemModule());
|
||||
if(block.hasItems) n.items = new ItemModule();
|
||||
if(block.hasLiquids) n.liquids(new LiquidModule());
|
||||
if(block.hasPower) n.power(new PowerModule());
|
||||
build = n;
|
||||
|
||||
@@ -151,7 +151,7 @@ public class MassDriver extends Block{
|
||||
|
||||
if(
|
||||
items.total() >= minDistribute && //must shoot minimum amount of items
|
||||
link.block().itemCapacity - link.items().total() >= minDistribute //must have minimum amount of space
|
||||
link.block().itemCapacity - link.items.total() >= minDistribute //must have minimum amount of space
|
||||
){
|
||||
MassDriverEntity other = (MassDriverEntity)link;
|
||||
other.waitingShooters.add(tile);
|
||||
|
||||
@@ -10,8 +10,8 @@ import arc.util.ArcAnnotate.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
@@ -25,6 +25,9 @@ import mindustry.world.modules.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class CoreBlock extends StorageBlock{
|
||||
//hacky way to pass item modules between methods
|
||||
private static ItemModule nextItems;
|
||||
|
||||
public UnitType unitType = UnitTypes.alpha;
|
||||
|
||||
public final int timerResupply = timers++;
|
||||
@@ -76,7 +79,7 @@ public class CoreBlock extends StorageBlock{
|
||||
new Bar(
|
||||
() -> Core.bundle.format("bar.capacity", ui.formatAmount(e.storageCapacity)),
|
||||
() -> Pal.items,
|
||||
() -> e.items().total() / ((float)e.storageCapacity * content.items().count(i -> i.unlockedNow()))
|
||||
() -> e.items.total() / ((float)e.storageCapacity * content.items().count(i -> i.unlockedNow()))
|
||||
));
|
||||
|
||||
bars.add("units", e ->
|
||||
@@ -100,6 +103,9 @@ public class CoreBlock extends StorageBlock{
|
||||
|
||||
@Override
|
||||
public boolean canPlaceOn(Tile tile, Team team){
|
||||
CoreEntity core = team.core();
|
||||
//must have all requirements
|
||||
if(core == null || (!state.rules.infiniteResources && !core.items.has(requirements))) return false;
|
||||
return canReplace(tile.block());
|
||||
}
|
||||
|
||||
@@ -110,6 +116,41 @@ public class CoreBlock extends StorageBlock{
|
||||
tile.setBlock(this, tile.team());
|
||||
Fx.placeBlock.at(tile, tile.block().size);
|
||||
Fx.upgradeCore.at(tile, tile.block().size);
|
||||
|
||||
//set up the correct items
|
||||
if(nextItems != null){
|
||||
//force-set the total items
|
||||
if(tile.team().core() != null){
|
||||
tile.team().core().items.set(nextItems);
|
||||
}
|
||||
|
||||
nextItems = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforePlaceBegan(Tile tile, Block previous){
|
||||
if(tile.build instanceof CoreEntity){
|
||||
//right before placing, create a "destination" item array which is all the previous items minus core requirements
|
||||
ItemModule items = tile.build.items.copy();
|
||||
if(!state.rules.infiniteResources){
|
||||
items.remove(requirements);
|
||||
}
|
||||
|
||||
nextItems = items;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
||||
if(!canPlaceOn(world.tile(x, y),player.team())){
|
||||
|
||||
drawPlaceText(Core.bundle.get((player.team().core() != null && player.team().core().items.has(requirements) && !state.rules.infiniteResources) ?
|
||||
"bar.corereq" :
|
||||
"bar.noresources"
|
||||
), x, y, valid);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,14 +202,14 @@ public class CoreBlock extends StorageBlock{
|
||||
public void onProximityUpdate(){
|
||||
for(Building other : state.teams.cores(team)){
|
||||
if(other.tile() != tile){
|
||||
items(other.items());
|
||||
this.items = other.items;
|
||||
}
|
||||
}
|
||||
state.teams.registerCore(this);
|
||||
|
||||
storageCapacity = itemCapacity + proximity().sum(e -> isContainer(e) && owns(e) ? e.block().itemCapacity : 0);
|
||||
proximity.each(e -> isContainer(e) && owns(e), t -> {
|
||||
t.items(items);
|
||||
t.items = items;
|
||||
((StorageBlockEntity)t).linkedCore = this;
|
||||
});
|
||||
|
||||
@@ -198,10 +239,10 @@ public class CoreBlock extends StorageBlock{
|
||||
Draw.rect("block-select", t.x() + offset * p.x, t.y() + offset * p.y, i * 90);
|
||||
}
|
||||
};
|
||||
if(proximity.contains(e -> isContainer(e) && e.items() == items)){
|
||||
if(proximity.contains(e -> isContainer(e) && e.items == items)){
|
||||
outline.get(this);
|
||||
}
|
||||
proximity.each(e -> isContainer(e) && e.items() == items, outline);
|
||||
proximity.each(e -> isContainer(e) && e.items == items, outline);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
@@ -228,15 +269,15 @@ public class CoreBlock extends StorageBlock{
|
||||
|
||||
@Override
|
||||
public void onRemoved(){
|
||||
int total = proximity.count(e -> e.items() != null && e.items() == items);
|
||||
int total = proximity.count(e -> e.items != null && e.items == items);
|
||||
float fract = 1f / total / state.teams.cores(team).size;
|
||||
|
||||
proximity.each(e -> isContainer(e) && e.items() == items && owns(e), t -> {
|
||||
proximity.each(e -> isContainer(e) && e.items == items && owns(e), t -> {
|
||||
StorageBlockEntity ent = (StorageBlockEntity)t;
|
||||
ent.linkedCore = null;
|
||||
ent.items(new ItemModule());
|
||||
ent.items = new ItemModule();
|
||||
for(Item item : content.items()){
|
||||
ent.items().set(item, (int)(fract * items.get(item)));
|
||||
ent.items.set(item, (int)(fract * items.get(item)));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -51,19 +51,19 @@ public class Unloader extends Block{
|
||||
if(timer(timerUnload, speed / timeScale())){
|
||||
for(Building other : proximity){
|
||||
if(other.interactable(team) && other.block().unloadable && other.block().hasItems
|
||||
&& ((sortItem == null && other.items().total() > 0) || (sortItem != null && other.items().has(sortItem)))){
|
||||
&& ((sortItem == null && other.items.total() > 0) || (sortItem != null && other.items.has(sortItem)))){
|
||||
//make sure the item can't be dumped back into this block
|
||||
dumpingTo = other;
|
||||
|
||||
//get item to be taken
|
||||
Item item = sortItem == null ? other.items().beginTake() : sortItem;
|
||||
Item item = sortItem == null ? other.items.beginTake() : sortItem;
|
||||
|
||||
//remove item if it's dumped correctly
|
||||
if(put(item)){
|
||||
if(sortItem == null){
|
||||
other.items().endTake(item);
|
||||
other.items.endTake(item);
|
||||
}else{
|
||||
other.items().remove(item, 1);
|
||||
other.items.remove(item, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,18 @@ public class ItemModule extends BlockModule{
|
||||
|
||||
private @Nullable WindowedMean[] flow;
|
||||
|
||||
public ItemModule copy(){
|
||||
ItemModule out = new ItemModule();
|
||||
out.set(this);
|
||||
return out;
|
||||
}
|
||||
|
||||
public void set(ItemModule other){
|
||||
total = other.total;
|
||||
takeRotation = other.takeRotation;
|
||||
System.arraycopy(other.items, 0, items, 0, items.length);
|
||||
}
|
||||
|
||||
public void update(boolean showFlow){
|
||||
if(showFlow){
|
||||
if(flow == null){
|
||||
|
||||
Reference in New Issue
Block a user