mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-28 07:22:21 -08:00
Upgradeable cores
This commit is contained in:
parent
313cadb763
commit
80332e37d5
63 changed files with 365 additions and 290 deletions
|
|
@ -134,7 +134,7 @@ public class ApplicationTests{
|
|||
for(int x = bx - 1; x <= bx + 1; x++){
|
||||
for(int y = by - 1; y <= by + 1; y++){
|
||||
assertEquals(world.tile(x, y).block(), Blocks.coreShard);
|
||||
assertEquals(world.tile(x, y).entity, world.tile(bx, by).entity);
|
||||
assertEquals(world.tile(x, y).build, world.tile(bx, by).build);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -143,12 +143,12 @@ public class ApplicationTests{
|
|||
void blockInventories(){
|
||||
multiblock();
|
||||
Tile tile = world.tile(4, 4);
|
||||
tile.entity.items.add(Items.coal, 5);
|
||||
tile.entity.items.add(Items.titanium, 50);
|
||||
assertEquals(tile.entity.items.total(), 55);
|
||||
tile.entity.items.remove(Items.phasefabric, 10);
|
||||
tile.entity.items.remove(Items.titanium, 10);
|
||||
assertEquals(tile.entity.items.total(), 45);
|
||||
tile.build.items.add(Items.coal, 5);
|
||||
tile.build.items.add(Items.titanium, 50);
|
||||
assertEquals(tile.build.items.total(), 55);
|
||||
tile.build.items.remove(Items.phasefabric, 10);
|
||||
tile.build.items.remove(Items.titanium, 10);
|
||||
assertEquals(tile.build.items.total(), 45);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -216,16 +216,16 @@ public class ApplicationTests{
|
|||
|
||||
void updateBlocks(int times){
|
||||
for(Tile tile : world.tiles){
|
||||
if(tile.entity != null && tile.isCenter()){
|
||||
tile.entity.updateProximity();
|
||||
if(tile.build != null && tile.isCenter()){
|
||||
tile.build.updateProximity();
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < times; i++){
|
||||
Time.update();
|
||||
for(Tile tile : world.tiles){
|
||||
if(tile.entity != null && tile.isCenter()){
|
||||
tile.entity.update();
|
||||
if(tile.build != null && tile.isCenter()){
|
||||
tile.build.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -237,14 +237,14 @@ public class ApplicationTests{
|
|||
state.set(State.playing);
|
||||
|
||||
world.tile(0, 0).setBlock(Blocks.liquidSource);
|
||||
world.tile(0, 0).entity.configureAny(Liquids.water);
|
||||
world.tile(0, 0).build.configureAny(Liquids.water);
|
||||
|
||||
world.tile(2, 1).setBlock(Blocks.liquidTank);
|
||||
|
||||
updateBlocks(10);
|
||||
|
||||
assertTrue(world.tile(2, 1).entity.liquids.currentAmount() >= 1);
|
||||
assertTrue(world.tile(2, 1).entity.liquids.current() == Liquids.water);
|
||||
assertTrue(world.tile(2, 1).build.liquids.currentAmount() >= 1);
|
||||
assertTrue(world.tile(2, 1).build.liquids.current() == Liquids.water);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -255,7 +255,7 @@ public class ApplicationTests{
|
|||
Tile source = world.rawTile(0, 0), tank = world.rawTile(1, 4), junction = world.rawTile(0, 1), conduit = world.rawTile(0, 2);
|
||||
|
||||
source.setBlock(Blocks.liquidSource);
|
||||
source.entity.configureAny(Liquids.water);
|
||||
source.build.configureAny(Liquids.water);
|
||||
|
||||
junction.setBlock(Blocks.liquidJunction);
|
||||
|
||||
|
|
@ -265,8 +265,8 @@ public class ApplicationTests{
|
|||
|
||||
updateBlocks(10);
|
||||
|
||||
assertTrue(tank.entity.liquids.currentAmount() >= 1, "Liquid not moved through junction");
|
||||
assertTrue(tank.entity.liquids.current() == Liquids.water, "Tank has no water");
|
||||
assertTrue(tank.build.liquids.currentAmount() >= 1, "Liquid not moved through junction");
|
||||
assertTrue(tank.build.liquids.current() == Liquids.water, "Tank has no water");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -290,7 +290,7 @@ public class ApplicationTests{
|
|||
|
||||
world.tile(0, 0).setBlock(Blocks.conveyor);
|
||||
world.tile(0, 0).rotation(0);
|
||||
world.tile(0, 0).entity.acceptStack(Items.copper, 1000, null);
|
||||
world.tile(0, 0).build.acceptStack(Items.copper, 1000, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -367,14 +367,14 @@ public class ApplicationTests{
|
|||
state.set(State.playing);
|
||||
int length = 128;
|
||||
world.tile(0, 0).setBlock(Blocks.itemSource);
|
||||
world.tile(0, 0).entity.configureAny(Items.copper);
|
||||
world.tile(0, 0).build.configureAny(Items.copper);
|
||||
|
||||
Seq<Building> entities = Seq.with(world.tile(0, 0).entity);
|
||||
Seq<Building> entities = Seq.with(world.tile(0, 0).build);
|
||||
|
||||
for(int i = 0; i < length; i++){
|
||||
world.tile(i + 1, 0).setBlock(Blocks.conveyor);
|
||||
world.tile(i + 1, 0).rotation(0);
|
||||
entities.add(world.tile(i + 1, 0).entity);
|
||||
entities.add(world.tile(i + 1, 0).build);
|
||||
}
|
||||
|
||||
world.tile(length + 1, 0).setBlock(new Block("___"){{
|
||||
|
|
@ -501,7 +501,7 @@ public class ApplicationTests{
|
|||
assertEquals(Blocks.copperWallLarge, world.tile(0, 0).block());
|
||||
assertEquals(Blocks.air, world.tile(2, 2).block());
|
||||
assertEquals(Blocks.copperWallLarge, world.tile(1, 1).block());
|
||||
assertEquals(world.tile(1, 1).entity, world.tile(0, 0).entity);
|
||||
assertEquals(world.tile(1, 1).build, world.tile(0, 0).build);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -565,14 +565,14 @@ public class ApplicationTests{
|
|||
for(int x = 0; x < tiles.width; x++){
|
||||
for(int y = 0; y < tiles.height; y++){
|
||||
Tile tile = world.rawTile(x, y);
|
||||
if(tile.entity != null){
|
||||
if(tile.build != null){
|
||||
try{
|
||||
tile.entity.update();
|
||||
tile.build.update();
|
||||
}catch(Throwable t){
|
||||
fail("Failed to update block '" + tile.block() + "'.", t);
|
||||
}
|
||||
assertEquals(tile.block(), tile.entity.block());
|
||||
assertEquals(tile.block().health, tile.entity.health());
|
||||
assertEquals(tile.block(), tile.build.block());
|
||||
assertEquals(tile.block().health, tile.build.health());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -584,10 +584,10 @@ public class ApplicationTests{
|
|||
Tile core = world.tile(5, 5);
|
||||
core.setBlock(Blocks.coreShard, Team.sharded, 0);
|
||||
for(Item item : content.items()){
|
||||
core.entity.items.set(item, 3000);
|
||||
core.build.items.set(item, 3000);
|
||||
}
|
||||
|
||||
assertEquals(core.entity, state.teams.get(Team.sharded).core());
|
||||
assertEquals(core.build, state.teams.get(Team.sharded).core());
|
||||
}
|
||||
|
||||
void depositTest(Block block, Item item){
|
||||
|
|
@ -595,18 +595,18 @@ public class ApplicationTests{
|
|||
Tile tile = new Tile(0, 0, Blocks.air, Blocks.air, block);
|
||||
int capacity = tile.block().itemCapacity;
|
||||
|
||||
assertNotNull(tile.entity, "Tile should have an entity, but does not: " + tile);
|
||||
assertNotNull(tile.build, "Tile should have an entity, but does not: " + tile);
|
||||
|
||||
int deposited = tile.entity.acceptStack(item, capacity - 1, unit);
|
||||
int deposited = tile.build.acceptStack(item, capacity - 1, unit);
|
||||
assertEquals(capacity - 1, deposited);
|
||||
|
||||
tile.entity.handleStack(item, capacity - 1, unit);
|
||||
assertEquals(tile.entity.items.get(item), capacity - 1);
|
||||
tile.build.handleStack(item, capacity - 1, unit);
|
||||
assertEquals(tile.build.items.get(item), capacity - 1);
|
||||
|
||||
int overflow = tile.entity.acceptStack(item, 10, unit);
|
||||
int overflow = tile.build.acceptStack(item, 10, unit);
|
||||
assertEquals(1, overflow);
|
||||
|
||||
tile.entity.handleStack(item, 1, unit);
|
||||
assertEquals(capacity, tile.entity.items.get(item));
|
||||
tile.build.handleStack(item, 1, unit);
|
||||
assertEquals(capacity, tile.build.items.get(item));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
|
|||
};
|
||||
|
||||
tile = createFakeTile(0, 0, generator);
|
||||
entity = tile.ent();
|
||||
entity = tile.bc();
|
||||
}
|
||||
|
||||
/** Tests the consumption and efficiency when being supplied with liquids. */
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import mindustry.game.*;
|
|||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.power.*;
|
||||
import mindustry.world.modules.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
|
@ -87,21 +86,21 @@ public class PowerTestFixture{
|
|||
Reflect.set(Tile.class, tile, "floor", Blocks.sand);
|
||||
|
||||
// Simulate the "changed" method. Calling it through reflections would require half the game to be initialized.
|
||||
tile.entity = block.newEntity().init(tile, Team.sharded, false);
|
||||
tile.build = block.newEntity().init(tile, Team.sharded, false);
|
||||
if(block.hasPower){
|
||||
tile.entity.power.graph = new PowerGraph(){
|
||||
tile.build.power.graph = new PowerGraph(){
|
||||
//assume there's always something consuming power
|
||||
@Override
|
||||
public float getUsageFraction(){
|
||||
return 1f;
|
||||
}
|
||||
};
|
||||
tile.entity.power.graph.add(tile.entity);
|
||||
tile.build.power.graph.add(tile.build);
|
||||
}
|
||||
|
||||
// Assign incredibly high health so the block does not get destroyed on e.g. burning Blast Compound
|
||||
block.health = 100000;
|
||||
tile.entity.health(100000.0f);
|
||||
tile.build.health(100000.0f);
|
||||
|
||||
return tile;
|
||||
}catch(Exception ex){
|
||||
|
|
|
|||
|
|
@ -54,19 +54,19 @@ public class PowerTests extends PowerTestFixture{
|
|||
|
||||
void simulateDirectConsumption(float producedPower, float requiredPower, float expectedSatisfaction, String parameterDescription){
|
||||
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
|
||||
producerTile.<PowerGenerator.GeneratorEntity>ent().productionEfficiency = 1f;
|
||||
producerTile.<PowerGenerator.GeneratorEntity>bc().productionEfficiency = 1f;
|
||||
Tile directConsumerTile = createFakeTile(0, 1, createFakeDirectConsumer(requiredPower));
|
||||
|
||||
PowerGraph powerGraph = new PowerGraph();
|
||||
powerGraph.add(producerTile.entity);
|
||||
powerGraph.add(directConsumerTile.entity);
|
||||
powerGraph.add(producerTile.build);
|
||||
powerGraph.add(directConsumerTile.build);
|
||||
|
||||
assertEquals(producedPower * Time.delta(), powerGraph.getPowerProduced(), Mathf.FLOAT_ROUNDING_ERROR);
|
||||
assertEquals(requiredPower * Time.delta(), powerGraph.getPowerNeeded(), Mathf.FLOAT_ROUNDING_ERROR);
|
||||
|
||||
// Update and check for the expected power status of the consumer
|
||||
powerGraph.update();
|
||||
assertEquals(expectedSatisfaction, directConsumerTile.entity.power.status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match");
|
||||
assertEquals(expectedSatisfaction, directConsumerTile.build.power.status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -94,24 +94,24 @@ public class PowerTests extends PowerTestFixture{
|
|||
|
||||
if(producedPower > 0.0f){
|
||||
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
|
||||
producerTile.<PowerGenerator.GeneratorEntity>ent().productionEfficiency = 1f;
|
||||
powerGraph.add(producerTile.entity);
|
||||
producerTile.<PowerGenerator.GeneratorEntity>bc().productionEfficiency = 1f;
|
||||
powerGraph.add(producerTile.build);
|
||||
}
|
||||
Tile directConsumerTile = null;
|
||||
if(requestedPower > 0.0f){
|
||||
directConsumerTile = createFakeTile(0, 1, createFakeDirectConsumer(requestedPower));
|
||||
powerGraph.add(directConsumerTile.entity);
|
||||
powerGraph.add(directConsumerTile.build);
|
||||
}
|
||||
float maxCapacity = 100f;
|
||||
Tile batteryTile = createFakeTile(0, 2, createFakeBattery(maxCapacity));
|
||||
batteryTile.entity.power.status = initialBatteryCapacity / maxCapacity;
|
||||
batteryTile.build.power.status = initialBatteryCapacity / maxCapacity;
|
||||
|
||||
powerGraph.add(batteryTile.entity);
|
||||
powerGraph.add(batteryTile.build);
|
||||
|
||||
powerGraph.update();
|
||||
assertEquals(expectedBatteryCapacity / maxCapacity, batteryTile.entity.power.status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Expected battery status did not match");
|
||||
assertEquals(expectedBatteryCapacity / maxCapacity, batteryTile.build.power.status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Expected battery status did not match");
|
||||
if(directConsumerTile != null){
|
||||
assertEquals(expectedSatisfaction, directConsumerTile.entity.power.status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match");
|
||||
assertEquals(expectedSatisfaction, directConsumerTile.build.power.status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -119,24 +119,24 @@ public class PowerTests extends PowerTestFixture{
|
|||
@Test
|
||||
void directConsumptionStopsWithNoPower(){
|
||||
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(10.0f));
|
||||
producerTile.<PowerGenerator.GeneratorEntity>ent().productionEfficiency = 1.0f;
|
||||
producerTile.<PowerGenerator.GeneratorEntity>bc().productionEfficiency = 1.0f;
|
||||
Tile consumerTile = createFakeTile(0, 1, createFakeDirectConsumer(5.0f));
|
||||
|
||||
PowerGraph powerGraph = new PowerGraph();
|
||||
powerGraph.add(producerTile.entity);
|
||||
powerGraph.add(consumerTile.entity);
|
||||
powerGraph.add(producerTile.build);
|
||||
powerGraph.add(consumerTile.build);
|
||||
powerGraph.update();
|
||||
|
||||
assertEquals(1.0f, consumerTile.entity.power.status, Mathf.FLOAT_ROUNDING_ERROR);
|
||||
assertEquals(1.0f, consumerTile.build.power.status, Mathf.FLOAT_ROUNDING_ERROR);
|
||||
|
||||
powerGraph.remove(producerTile.entity);
|
||||
powerGraph.add(consumerTile.entity);
|
||||
powerGraph.remove(producerTile.build);
|
||||
powerGraph.add(consumerTile.build);
|
||||
powerGraph.update();
|
||||
|
||||
assertEquals(0.0f, consumerTile.entity.power.status, Mathf.FLOAT_ROUNDING_ERROR);
|
||||
assertEquals(0.0f, consumerTile.build.power.status, Mathf.FLOAT_ROUNDING_ERROR);
|
||||
if(consumerTile.block().consumes.hasPower()){
|
||||
ConsumePower consumePower = consumerTile.block().consumes.getPower();
|
||||
assertFalse(consumePower.valid(consumerTile.ent()));
|
||||
assertFalse(consumePower.valid(consumerTile.bc()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue