Skip to content

Commit

Permalink
Merge pull request Anuken#3 from Quezler/nydus
Browse files Browse the repository at this point in the history
updateing code
  • Loading branch information
Blockzilla101 committed Apr 7, 2020
2 parents a6991d6 + c226cde commit 397a13b
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 60 deletions.
2 changes: 1 addition & 1 deletion core/src/mindustry/content/Blocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ public void draw(Tile tile){}
requirements(Category.power, ItemStack.with(Items.lead, 10, Items.silicon, 15));
powerProduction = 0.06f;

flags = EnumSet.of(BlockFlag.scalable);
flags = EnumSet.of(BlockFlag.scalable, BlockFlag.solar);
upscale = () -> largeSolarPanel;
}};

Expand Down
1 change: 0 additions & 1 deletion core/src/mindustry/content/UnitTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public void load(){
minePower = 0.9f;
engineSize = 1.8f;
engineOffset = 5.7f;
itemCapacity = Integer.MAX_VALUE;
weapon = new Weapon("you have incurred my wrath. prepare to die."){{
bullet = Bullets.lancerLaser;
}};
Expand Down
4 changes: 2 additions & 2 deletions core/src/mindustry/entities/type/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,12 @@ public void update(){
}
});

if(item.amount > 0 && item.item != null && item.item.type == ItemType.material && itemtime >= 0.9f && getClosestCore() != null){
if(item.amount > 0 && item.item != null && item.item.type == ItemType.material && itemtime >= 0.9f && getClosestCore() != null && velocity.isZero(0.01f)){
if(getClosestCore().dst(this) <= mineTransferRange){
Call.transferItemTo(item.item, item.amount, x, y, getClosestCore().tile);
clearItem();
}else{
Player proxy = (Player)Units.closest(team, x, y, mineTransferRange, u -> u instanceof Player && u != this && u.acceptsItem(item.item) && u.getClosestCore().dst(u) < getClosestCore().dst(this));
Player proxy = (Player)Units.closest(team, x, y, mineTransferRange, u -> u instanceof Player && u != this && u.acceptsItem(item.item) && u.getClosestCore().dst(u) < getClosestCore().dst(this) && velocity.isZero(0.01f));
if(proxy != null){
proxy.addItem(item.item, item.amount-1);
Call.transferItemToUnit(item.item, x, y, proxy);
Expand Down
2 changes: 1 addition & 1 deletion core/src/mindustry/plugin/spiderchat/SpiderChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class SpiderChat extends Plugin implements ApplicationListener{

public void message(Player player, String raw){
if(raw.startsWith("!")){
playerGroup.all().select(p -> p.isAdmin).each(p -> p.sendMessage(player.prefix() + " [orange]> [lightgray]" + raw));
playerGroup.all().select(p -> p.isAdmin).each(p -> p.sendMessage(player.prefix() + " [orange]!! [white]" + raw.substring(1)));
}else{
Call.sendMessage(player.prefix() + " [orange]> [white]" + raw);
}
Expand Down
6 changes: 6 additions & 0 deletions core/src/mindustry/world/blocks/power/PowerGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class PowerGraph{
private final static Queue<Tile> queue = new Queue<>();
private final static Array<Tile> outArray1 = new Array<>();
private final static Array<Tile> outArray2 = new Array<>();
private final static Array<Tile> outArray3 = new Array<>();
private final static IntSet closedSet = new IntSet();

private final ObjectSet<Tile> producers = new ObjectSet<>();
Expand Down Expand Up @@ -270,6 +271,7 @@ private void removeSingle(Tile tile){
}

public void remove(Tile tile){
tile.block.getPowerConnections(tile, outArray3);
removeSingle(tile);
//begin by clearing the closed set
closedSet.clear();
Expand Down Expand Up @@ -305,6 +307,10 @@ public void remove(Tile tile){
//update the graph once so direct consumers without any connected producer lose their power
graph.update();
}

outArray3.each(t -> {
if(t.block instanceof PowerNode) t.block.placed(t);
});
}

private boolean otherConsumersAreValid(Tile tile, Consume consumePower){
Expand Down
2 changes: 1 addition & 1 deletion core/src/mindustry/world/blocks/power/SolarGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class SolarGenerator extends PowerGenerator{
public SolarGenerator(String name){
super(name);
// Remove the BlockFlag.producer flag to make this a lower priority target than other generators.
flags = EnumSet.of();
flags = EnumSet.of(BlockFlag.solar);
entityType = GeneratorEntity::new;
}

Expand Down
57 changes: 8 additions & 49 deletions core/src/mindustry/world/blocks/units/UnitFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
import arc.graphics.g2d.*;
import arc.math.Mathf;
import mindustry.Vars;
import mindustry.content.*;
import mindustry.content.Fx;
import mindustry.entities.Effects;
import mindustry.entities.traits.*;
import mindustry.entities.type.*;
import mindustry.entities.type.base.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*;
import mindustry.gen.Call;
import mindustry.graphics.Pal;
Expand All @@ -22,8 +20,6 @@
import mindustry.ui.Cicon;
import mindustry.world.Block;
import mindustry.world.Tile;
import mindustry.world.blocks.production.*;
import mindustry.world.blocks.storage.CoreBlock.*;
import mindustry.world.consumers.ConsumeItems;
import mindustry.world.consumers.ConsumeType;
import mindustry.world.meta.*;
Expand All @@ -39,8 +35,6 @@ public class UnitFactory extends Block{
public int maxSpawn = 4;
public int[] capacities;

private static final int mine = 100;

public UnitFactory(String name){
super(name);
update = true;
Expand All @@ -64,37 +58,16 @@ public static void onUnitFactorySpawn(Tile tile, int spawns){
Effects.shake(2f, 3f, entity);
Effects.effect(Fx.producesmoke, tile.drawx(), tile.drawy());

if(factory.unitType == UnitTypes.draug){

CoreEntity core = state.teams.closestCore(tile.drawy(), tile.drawy(), tile.getTeam());
if(core != null && tile.dst(core) <= mineTransferRange){
if(core.block.acceptStack(Items.copper, mine, core.tile, null) > 0) Call.transferItemTo(Items.copper, core.block.acceptStack(Items.copper, mine, core.tile, null), tile.drawx(), tile.drawy(), core.tile);
if(core.block.acceptStack(Items.lead, mine, core.tile, null) > 0) Call.transferItemTo(Items.lead, core.block.acceptStack(Items.lead, mine, core.tile, null), tile.drawx(), tile.drawy(), core.tile);
}else{
entity.items.set(Items.copper, mine);
entity.items.set(Items.lead, mine);
netServer.titanic.add(tile);
}
return;
}

if(!net.client()){
spawn(tile, factory.unitType);
// if(factory.unitType == UnitTypes.draug) spawn(tile, UnitTypes.spirit);
// if(factory.unitType == UnitTypes.draug) spawn(tile, UnitTypes.phantom);
BaseUnit unit = factory.unitType.create(tile.getTeam());
unit.setSpawner(tile);
unit.set(tile.drawx() + Mathf.range(4), tile.drawy() + Mathf.range(4));
unit.add();
unit.velocity().y = factory.launchVelocity;
Events.fire(new UnitCreateEvent(unit));
}
}

protected static void spawn(Tile tile, UnitType type){
BaseUnit unit = type.create(tile.getTeam());
unit.setSpawner(tile);
unit.set(tile.drawx() + Mathf.range(4), tile.drawy() + Mathf.range(4));
if(!(unit instanceof BaseDrone)) UnitDrops.seed(unit);
unit.add();
unit.velocity().y = ((UnitFactory)tile.block()).launchVelocity;
Events.fire(new UnitCreateEvent(unit));
}

@Override
public void init(){
super.init();
Expand Down Expand Up @@ -141,8 +114,6 @@ public void unitRemoved(Tile tile, Unit unit){
UnitFactoryEntity entity = tile.ent();
entity.spawned--;
entity.spawned = Math.max(entity.spawned, 0);

// if(((UnitFactory)tile.block()).unitType == UnitTypes.draug) entity.damage(entity.health);
}

@Override
Expand Down Expand Up @@ -185,19 +156,7 @@ public void draw(Tile tile){
public void update(Tile tile){
UnitFactoryEntity entity = tile.ent();

if(unitType == UnitTypes.draug && entity.items.total() > 0){
Tile dump = tryDump(tile, null);
if(dump != null){
netServer.titanic.add(tile);
netServer.titanic.add(tryDump(tile, null));
}
}

if(entity.spawned >= maxSpawn){
if(unitType == UnitTypes.draug && entity.items.total() < (mine * 2)){
entity.spawned = 0;
netServer.titanic.add(tile);
}
return;
}

Expand Down Expand Up @@ -234,7 +193,7 @@ public static class UnitFactoryEntity extends TileEntity implements FactoryTrait
float buildTime;
float time;
float speedScl;
public int spawned;
int spawned;

@Override
public void write(DataOutput stream) throws IOException{
Expand Down
3 changes: 2 additions & 1 deletion core/src/mindustry/world/meta/BlockFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public enum BlockFlag{
upgradable,
/** Graphite. */
yoinkable,
junction;
junction,
solar;

public final static BlockFlag[] all = values();
}
1 change: 1 addition & 0 deletions server/src/mindustry/server/ServerLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void init(){
Core.app.addListener(new SpecialDelivery());

Core.app.addListener(new JunctionYeeter());
Core.app.addListener(new PowerFlower());

mods.eachClass(Mod::init);

Expand Down
9 changes: 5 additions & 4 deletions server/src/mindustry/server/nydus/JunctionYeeter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.world.*;
import mindustry.world.blocks.distribution.*;
import mindustry.world.meta.*;

import static mindustry.Vars.*;
Expand All @@ -23,13 +24,13 @@ public void update(){
if(tile.block != Blocks.junction) return;

if(air(tile, Compass.north) && air(tile, Compass.south)){
if(tile.getNearby(Compass.east).front() == tile) Core.app.post(() -> tile.constructNet(tile.getNearby(Compass.east).block, tile.getNearby(Compass.east).getTeam(), tile.getNearby(Compass.east).rotation));
if(tile.getNearby(Compass.west).front() == tile) Core.app.post(() -> tile.constructNet(tile.getNearby(Compass.west).block, tile.getNearby(Compass.west).getTeam(), tile.getNearby(Compass.west).rotation));
if(tile.getNearby(Compass.east).front() == tile && tile.getNearby(Compass.east).block instanceof Conveyor) Core.app.post(() -> tile.constructNet(tile.getNearby(Compass.east).block, tile.getNearby(Compass.east).getTeam(), tile.getNearby(Compass.east).rotation));
if(tile.getNearby(Compass.west).front() == tile && tile.getNearby(Compass.west).block instanceof Conveyor) Core.app.post(() -> tile.constructNet(tile.getNearby(Compass.west).block, tile.getNearby(Compass.west).getTeam(), tile.getNearby(Compass.west).rotation));
}

if(air(tile, Compass.east) && air(tile, Compass.west)){
if(tile.getNearby(Compass.north).front() == tile) Core.app.post(() -> tile.constructNet(tile.getNearby(Compass.north).block, tile.getNearby(Compass.north).getTeam(), tile.getNearby(Compass.north).rotation));
if(tile.getNearby(Compass.south).front() == tile) Core.app.post(() -> tile.constructNet(tile.getNearby(Compass.south).block, tile.getNearby(Compass.south).getTeam(), tile.getNearby(Compass.south).rotation));
if(tile.getNearby(Compass.north).front() == tile && tile.getNearby(Compass.north).block instanceof Conveyor) Core.app.post(() -> tile.constructNet(tile.getNearby(Compass.north).block, tile.getNearby(Compass.north).getTeam(), tile.getNearby(Compass.north).rotation));
if(tile.getNearby(Compass.south).front() == tile && tile.getNearby(Compass.south).block instanceof Conveyor) Core.app.post(() -> tile.constructNet(tile.getNearby(Compass.south).block, tile.getNearby(Compass.south).getTeam(), tile.getNearby(Compass.south).rotation));
}
});
});
Expand Down
34 changes: 34 additions & 0 deletions server/src/mindustry/server/nydus/PowerFlower.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package mindustry.server.nydus;

import arc.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
import mindustry.world.blocks.power.*;
import mindustry.world.meta.*;

import static mindustry.Vars.*;

public class PowerFlower implements ApplicationListener{

@Override
public void init(){
Events.on(BlockBuildEndEvent.class, event -> {
Core.app.post(() -> {
final int[] solar = {0};
state.teams.getActive().each(teamData -> {
indexer.getAllied(teamData.team, BlockFlag.solar).each(tile -> {
if(tile.block instanceof SolarGenerator){
solar[0] += (tile.block.size * tile.block.size);
}
});
});

float multiplier = 1f + (solar[0] * 0.01f);

if(multiplier == state.rules.solarPowerMultiplier) return;
state.rules.solarPowerMultiplier = multiplier;
Call.onSetRules(state.rules);
});
});
}
}

0 comments on commit 397a13b

Please sign in to comment.