mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-12 03:37:27 +07:00
Condensed unit group array
This commit is contained in:
parent
9016c12d16
commit
2b22b7e7e4
@ -184,7 +184,7 @@ public class Vars implements Loadable{
|
|||||||
public static EntityGroup<ShieldEntity> shieldGroup;
|
public static EntityGroup<ShieldEntity> shieldGroup;
|
||||||
public static EntityGroup<Puddle> puddleGroup;
|
public static EntityGroup<Puddle> puddleGroup;
|
||||||
public static EntityGroup<Fire> fireGroup;
|
public static EntityGroup<Fire> fireGroup;
|
||||||
public static EntityGroup<BaseUnit>[] unitGroups;
|
public static EntityGroup<BaseUnit> unitGroup;
|
||||||
|
|
||||||
public static Player player;
|
public static Player player;
|
||||||
|
|
||||||
@ -239,11 +239,7 @@ public class Vars implements Loadable{
|
|||||||
puddleGroup = entities.add(Puddle.class).enableMapping();
|
puddleGroup = entities.add(Puddle.class).enableMapping();
|
||||||
shieldGroup = entities.add(ShieldEntity.class, false);
|
shieldGroup = entities.add(ShieldEntity.class, false);
|
||||||
fireGroup = entities.add(Fire.class).enableMapping();
|
fireGroup = entities.add(Fire.class).enableMapping();
|
||||||
unitGroups = new EntityGroup[Team.all.length];
|
unitGroup = entities.add(BaseUnit.class).enableMapping();
|
||||||
|
|
||||||
for(Team team : Team.all){
|
|
||||||
unitGroups[(int) team.id] = entities.add(BaseUnit.class).enableMapping();
|
|
||||||
}
|
|
||||||
|
|
||||||
for(EntityGroup<?> group : entities.all()){
|
for(EntityGroup<?> group : entities.all()){
|
||||||
group.setRemoveListener(entity -> {
|
group.setRemoveListener(entity -> {
|
||||||
|
@ -2,7 +2,6 @@ package mindustry.core;
|
|||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
import mindustry.entities.type.*;
|
import mindustry.entities.type.*;
|
||||||
import mindustry.entities.type.base.*;
|
|
||||||
import mindustry.game.EventType.*;
|
import mindustry.game.EventType.*;
|
||||||
import mindustry.game.*;
|
import mindustry.game.*;
|
||||||
|
|
||||||
@ -26,12 +25,8 @@ public class GameState{
|
|||||||
/** Current game state. */
|
/** Current game state. */
|
||||||
private State state = State.menu;
|
private State state = State.menu;
|
||||||
|
|
||||||
public int enemies(){
|
|
||||||
return net.client() ? enemies : unitGroups[(int) waveTeam.id].count(b -> !(b instanceof BaseDrone));
|
|
||||||
}
|
|
||||||
|
|
||||||
public BaseUnit boss(){
|
public BaseUnit boss(){
|
||||||
return unitGroups[(int) waveTeam.id].find(BaseUnit::isBoss);
|
return unitGroup.find(u -> u.isBoss() && u.getTeam() == waveTeam);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(State astate){
|
public void set(State astate){
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package mindustry.core;
|
package mindustry.core;
|
||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.core.GameState.*;
|
import mindustry.core.GameState.*;
|
||||||
import mindustry.ctype.*;
|
import mindustry.ctype.*;
|
||||||
@ -212,12 +212,15 @@ public class Logic implements ApplicationListener{
|
|||||||
public void update(){
|
public void update(){
|
||||||
|
|
||||||
if(!state.is(State.menu)){
|
if(!state.is(State.menu)){
|
||||||
|
if(!net.client()){
|
||||||
|
state.enemies = unitGroup.count(b -> b.getTeam() == waveTeam && b.countsAsEnemy());
|
||||||
|
}
|
||||||
|
|
||||||
if(!state.isPaused()){
|
if(!state.isPaused()){
|
||||||
Time.update();
|
Time.update();
|
||||||
|
|
||||||
if(state.rules.waves && state.rules.waveTimer && !state.gameOver){
|
if(state.rules.waves && state.rules.waveTimer && !state.gameOver){
|
||||||
if(!state.rules.waitForWaveToEnd || unitGroups[(int) waveTeam.id].size() == 0){
|
if(!state.rules.waitForWaveToEnd || state.enemies == 0){
|
||||||
state.wavetime = Math.max(state.wavetime - Time.delta(), 0);
|
state.wavetime = Math.max(state.wavetime - Time.delta(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,20 +235,15 @@ public class Logic implements ApplicationListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!state.isEditor()){
|
if(!state.isEditor()){
|
||||||
for(EntityGroup group : unitGroups){
|
unitGroup.update();
|
||||||
group.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
puddleGroup.update();
|
puddleGroup.update();
|
||||||
shieldGroup.update();
|
shieldGroup.update();
|
||||||
bulletGroup.update();
|
bulletGroup.update();
|
||||||
tileGroup.update();
|
tileGroup.update();
|
||||||
fireGroup.update();
|
fireGroup.update();
|
||||||
}else{
|
}else{
|
||||||
for(EntityGroup<?> group : unitGroups){
|
unitGroup.updateEvents();
|
||||||
group.updateEvents();
|
collisions.updatePhysics(unitGroup);
|
||||||
collisions.updatePhysics(group);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -257,12 +255,8 @@ public class Logic implements ApplicationListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!state.isEditor()){
|
if(!state.isEditor()){
|
||||||
|
//bulletGroup
|
||||||
for(EntityGroup group : unitGroups){
|
collisions.collideGroups(bulletGroup, unitGroup);
|
||||||
if(group.isEmpty()) continue;
|
|
||||||
collisions.collideGroups(bulletGroup, group);
|
|
||||||
}
|
|
||||||
|
|
||||||
collisions.collideGroups(bulletGroup, playerGroup);
|
collisions.collideGroups(bulletGroup, playerGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -660,7 +660,7 @@ public class NetServer implements ApplicationListener{
|
|||||||
byte[] stateBytes = syncStream.toByteArray();
|
byte[] stateBytes = syncStream.toByteArray();
|
||||||
|
|
||||||
//write basic state data.
|
//write basic state data.
|
||||||
Call.onStateSnapshot(player.con, state.wavetime, state.wave, state.enemies(), (short)stateBytes.length, net.compressSnapshot(stateBytes));
|
Call.onStateSnapshot(player.con, state.wavetime, state.wave, state.enemies, (short)stateBytes.length, net.compressSnapshot(stateBytes));
|
||||||
|
|
||||||
viewport.setSize(player.con.viewWidth, player.con.viewHeight).setCenter(player.con.viewX, player.con.viewY);
|
viewport.setSize(player.con.viewWidth, player.con.viewHeight).setCenter(player.con.viewX, player.con.viewY);
|
||||||
|
|
||||||
|
@ -126,6 +126,11 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
|||||||
this.team = team;
|
this.team = team;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return whether this unit counts toward the enemy amount in the wave UI. */
|
||||||
|
public boolean countsAsEnemy(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public UnitType getType(){
|
public UnitType getType(){
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,10 @@ public abstract class BaseDrone extends FlyingUnit{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public boolean countsAsEnemy(){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(UnitCommand command){
|
public void onCommand(UnitCommand command){
|
||||||
//do nothing, normal commands are not applicable here
|
//do nothing, normal commands are not applicable here
|
||||||
|
@ -94,7 +94,7 @@ public class MusicControl{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//dark based on enemies
|
//dark based on enemies
|
||||||
return Mathf.chance(state.enemies() / 70f + 0.1f);
|
return Mathf.chance(state.enemies / 70f + 0.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Plays and fades in a music track. This must be called every frame.
|
/** Plays and fades in a music track. This must be called every frame.
|
||||||
|
@ -165,7 +165,7 @@ public class Tutorial{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
deposit(() -> event("deposit")),
|
deposit(() -> event("deposit")),
|
||||||
waves(() -> state.wave > 2 && state.enemies() <= 0 && !spawner.isSpawning()){
|
waves(() -> state.wave > 2 && state.enemies <= 0 && !spawner.isSpawning()){
|
||||||
void begin(){
|
void begin(){
|
||||||
state.rules.waveTimer = true;
|
state.rules.waveTimer = true;
|
||||||
logic.runWave();
|
logic.runWave();
|
||||||
|
@ -557,7 +557,7 @@ public class HudFragment extends Fragment{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean canLaunch(){
|
private boolean canLaunch(){
|
||||||
return inLaunchWave() && state.enemies() <= 0;
|
return inLaunchWave() && state.enemies <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleMenus(){
|
private void toggleMenus(){
|
||||||
@ -604,7 +604,7 @@ public class HudFragment extends Fragment{
|
|||||||
|
|
||||||
if(inLaunchWave()){
|
if(inLaunchWave()){
|
||||||
builder.append("[#");
|
builder.append("[#");
|
||||||
Tmp.c1.set(Color.white).lerp(state.enemies() > 0 ? Color.white : Color.scarlet, Mathf.absin(Time.time(), 2f, 1f)).toString(builder);
|
Tmp.c1.set(Color.white).lerp(state.enemies > 0 ? Color.white : Color.scarlet, Mathf.absin(Time.time(), 2f, 1f)).toString(builder);
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
|
|
||||||
if(!canLaunch()){
|
if(!canLaunch()){
|
||||||
@ -618,18 +618,18 @@ public class HudFragment extends Fragment{
|
|||||||
builder.append("[]\n");
|
builder.append("[]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(state.enemies() > 0){
|
if(state.enemies > 0){
|
||||||
if(state.enemies() == 1){
|
if(state.enemies == 1){
|
||||||
builder.append(enemyf.get(state.enemies()));
|
builder.append(enemyf.get(state.enemies));
|
||||||
}else{
|
}else{
|
||||||
builder.append(enemiesf.get(state.enemies()));
|
builder.append(enemiesf.get(state.enemies));
|
||||||
}
|
}
|
||||||
builder.append("\n");
|
builder.append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(state.rules.waveTimer){
|
if(state.rules.waveTimer){
|
||||||
builder.append((state.rules.waitForWaveToEnd && unitGroups[(int) waveTeam.id].size() > 0) ? Core.bundle.get("wave.waveInProgress") : ( waitingf.get((int)(state.wavetime/60))));
|
builder.append((state.rules.waitForWaveToEnd && unitGroups[(int) waveTeam.id].size() > 0) ? Core.bundle.get("wave.waveInProgress") : ( waitingf.get((int)(state.wavetime/60))));
|
||||||
}else if(state.enemies() == 0){
|
}else if(state.enemies == 0){
|
||||||
builder.append(Core.bundle.get("waiting"));
|
builder.append(Core.bundle.get("waiting"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -646,7 +646,7 @@ public class HudFragment extends Fragment{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean canSkipWave(){
|
private boolean canSkipWave(){
|
||||||
return state.rules.waves && ((net.server() || player.isAdmin) || !net.active()) && state.enemies() == 0 && !spawner.isSpawning() && !state.rules.tutorial;
|
return state.rules.waves && ((net.server() || player.isAdmin) || !net.active()) && state.enemies == 0 && !spawner.isSpawning() && !state.rules.tutorial;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPlayButton(Table table){
|
private void addPlayButton(Table table){
|
||||||
|
Loading…
Reference in New Issue
Block a user