mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-27 15:02:03 -08:00
Polygonal protection bugfixes
This commit is contained in:
parent
f11f390c1f
commit
9088d9eb39
3 changed files with 35 additions and 6 deletions
|
|
@ -9,6 +9,7 @@ import mindustry.net.*;
|
|||
import mindustry.net.Packets.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.storage.CoreBlock.*;
|
||||
|
||||
public class EventType{
|
||||
|
||||
|
|
@ -283,6 +284,15 @@ public class EventType{
|
|||
}
|
||||
}
|
||||
|
||||
/** Called when a core block is placed/removed or its team is changed. */
|
||||
public static class CoreChangeEvent{
|
||||
public CoreBuild core;
|
||||
|
||||
public CoreChangeEvent(CoreBuild core){
|
||||
this.core = core;
|
||||
}
|
||||
}
|
||||
|
||||
public static class StateChangeEvent{
|
||||
public final State from, to;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,22 +28,24 @@ public class OverlayRenderer{
|
|||
private float buildFade, unitFade;
|
||||
private Sized lastSelect;
|
||||
private Seq<CoreEdge> cedges = new Seq<>();
|
||||
private int lastCores = -1;
|
||||
private boolean updatedCores;
|
||||
|
||||
public OverlayRenderer(){
|
||||
Events.on(WorldLoadEvent.class, e -> {
|
||||
cedges.clear();
|
||||
lastCores = -1;
|
||||
updatedCores = true;
|
||||
});
|
||||
|
||||
Events.on(CoreChangeEvent.class, e -> {
|
||||
updatedCores = true;
|
||||
});
|
||||
}
|
||||
|
||||
private void updateCoreEdges(){
|
||||
int count = state.teams.active.sum(t -> t.cores.size);
|
||||
if(count == lastCores){
|
||||
if(!updatedCores){
|
||||
return;
|
||||
}
|
||||
|
||||
lastCores = count;
|
||||
updatedCores = false;
|
||||
cedges.clear();
|
||||
|
||||
Seq<Vec2> pos = new Seq<>();
|
||||
|
|
@ -55,6 +57,7 @@ public class OverlayRenderer{
|
|||
}
|
||||
}
|
||||
|
||||
//if this is laggy, it could be shoved in another thread.
|
||||
var result = Voronoi.generate(pos.toArray(Vec2.class), 0, world.unitWidth(), 0, world.unitHeight());
|
||||
for(var edge : result){
|
||||
cedges.add(new CoreEdge(edge.x1, edge.y1, edge.x2, edge.y2, teams.get(edge.site1).team, teams.get(edge.site2).team));
|
||||
|
|
|
|||
|
|
@ -194,6 +194,20 @@ public class CoreBlock extends StorageBlock{
|
|||
super.damage(source, damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void created(){
|
||||
super.created();
|
||||
|
||||
Events.fire(new CoreChangeEvent(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeTeam(Team next){
|
||||
super.changeTeam(next);
|
||||
|
||||
Events.fire(new CoreChangeEvent(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double sense(LAccess sensor){
|
||||
if(sensor == LAccess.itemCapacity) return storageCapacity;
|
||||
|
|
@ -260,6 +274,8 @@ public class CoreBlock extends StorageBlock{
|
|||
spawner.getSpawns().add(tile);
|
||||
}
|
||||
}
|
||||
|
||||
Events.fire(new CoreChangeEvent(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue