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<Puddle> puddleGroup;
|
||||
public static EntityGroup<Fire> fireGroup;
|
||||
public static EntityGroup<BaseUnit>[] unitGroups;
|
||||
public static EntityGroup<BaseUnit> unitGroup;
|
||||
|
||||
public static Player player;
|
||||
|
||||
@ -239,11 +239,7 @@ public class Vars implements Loadable{
|
||||
puddleGroup = entities.add(Puddle.class).enableMapping();
|
||||
shieldGroup = entities.add(ShieldEntity.class, false);
|
||||
fireGroup = entities.add(Fire.class).enableMapping();
|
||||
unitGroups = new EntityGroup[Team.all.length];
|
||||
|
||||
for(Team team : Team.all){
|
||||
unitGroups[(int) team.id] = entities.add(BaseUnit.class).enableMapping();
|
||||
}
|
||||
unitGroup = entities.add(BaseUnit.class).enableMapping();
|
||||
|
||||
for(EntityGroup<?> group : entities.all()){
|
||||
group.setRemoveListener(entity -> {
|
||||
|
@ -2,7 +2,6 @@ package mindustry.core;
|
||||
|
||||
import arc.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.entities.type.base.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.game.*;
|
||||
|
||||
@ -26,12 +25,8 @@ public class GameState{
|
||||
/** Current game state. */
|
||||
private State state = State.menu;
|
||||
|
||||
public int enemies(){
|
||||
return net.client() ? enemies : unitGroups[(int) waveTeam.id].count(b -> !(b instanceof BaseDrone));
|
||||
}
|
||||
|
||||
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){
|
||||
|
@ -1,8 +1,8 @@
|
||||
package mindustry.core;
|
||||
|
||||
import arc.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.core.GameState.*;
|
||||
import mindustry.ctype.*;
|
||||
@ -212,12 +212,15 @@ public class Logic implements ApplicationListener{
|
||||
public void update(){
|
||||
|
||||
if(!state.is(State.menu)){
|
||||
if(!net.client()){
|
||||
state.enemies = unitGroup.count(b -> b.getTeam() == waveTeam && b.countsAsEnemy());
|
||||
}
|
||||
|
||||
if(!state.isPaused()){
|
||||
Time.update();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -232,20 +235,15 @@ public class Logic implements ApplicationListener{
|
||||
}
|
||||
|
||||
if(!state.isEditor()){
|
||||
for(EntityGroup group : unitGroups){
|
||||
group.update();
|
||||
}
|
||||
|
||||
unitGroup.update();
|
||||
puddleGroup.update();
|
||||
shieldGroup.update();
|
||||
bulletGroup.update();
|
||||
tileGroup.update();
|
||||
fireGroup.update();
|
||||
}else{
|
||||
for(EntityGroup<?> group : unitGroups){
|
||||
group.updateEvents();
|
||||
collisions.updatePhysics(group);
|
||||
}
|
||||
unitGroup.updateEvents();
|
||||
collisions.updatePhysics(unitGroup);
|
||||
}
|
||||
|
||||
|
||||
@ -257,12 +255,8 @@ public class Logic implements ApplicationListener{
|
||||
}
|
||||
|
||||
if(!state.isEditor()){
|
||||
|
||||
for(EntityGroup group : unitGroups){
|
||||
if(group.isEmpty()) continue;
|
||||
collisions.collideGroups(bulletGroup, group);
|
||||
}
|
||||
|
||||
//bulletGroup
|
||||
collisions.collideGroups(bulletGroup, unitGroup);
|
||||
collisions.collideGroups(bulletGroup, playerGroup);
|
||||
}
|
||||
}
|
||||
|
@ -660,7 +660,7 @@ public class NetServer implements ApplicationListener{
|
||||
byte[] stateBytes = syncStream.toByteArray();
|
||||
|
||||
//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);
|
||||
|
||||
|
@ -126,6 +126,11 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
this.team = team;
|
||||
}
|
||||
|
||||
/** @return whether this unit counts toward the enemy amount in the wave UI. */
|
||||
public boolean countsAsEnemy(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public UnitType getType(){
|
||||
return type;
|
||||
}
|
||||
|
@ -32,6 +32,10 @@ public abstract class BaseDrone extends FlyingUnit{
|
||||
}
|
||||
};
|
||||
|
||||
public boolean countsAsEnemy(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(UnitCommand command){
|
||||
//do nothing, normal commands are not applicable here
|
||||
|
@ -94,7 +94,7 @@ public class MusicControl{
|
||||
}
|
||||
|
||||
//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.
|
||||
|
@ -165,7 +165,7 @@ public class Tutorial{
|
||||
}
|
||||
},
|
||||
deposit(() -> event("deposit")),
|
||||
waves(() -> state.wave > 2 && state.enemies() <= 0 && !spawner.isSpawning()){
|
||||
waves(() -> state.wave > 2 && state.enemies <= 0 && !spawner.isSpawning()){
|
||||
void begin(){
|
||||
state.rules.waveTimer = true;
|
||||
logic.runWave();
|
||||
|
@ -557,7 +557,7 @@ public class HudFragment extends Fragment{
|
||||
}
|
||||
|
||||
private boolean canLaunch(){
|
||||
return inLaunchWave() && state.enemies() <= 0;
|
||||
return inLaunchWave() && state.enemies <= 0;
|
||||
}
|
||||
|
||||
private void toggleMenus(){
|
||||
@ -604,7 +604,7 @@ public class HudFragment extends Fragment{
|
||||
|
||||
if(inLaunchWave()){
|
||||
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("]");
|
||||
|
||||
if(!canLaunch()){
|
||||
@ -618,18 +618,18 @@ public class HudFragment extends Fragment{
|
||||
builder.append("[]\n");
|
||||
}
|
||||
|
||||
if(state.enemies() > 0){
|
||||
if(state.enemies() == 1){
|
||||
builder.append(enemyf.get(state.enemies()));
|
||||
if(state.enemies > 0){
|
||||
if(state.enemies == 1){
|
||||
builder.append(enemyf.get(state.enemies));
|
||||
}else{
|
||||
builder.append(enemiesf.get(state.enemies()));
|
||||
builder.append(enemiesf.get(state.enemies));
|
||||
}
|
||||
builder.append("\n");
|
||||
}
|
||||
|
||||
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))));
|
||||
}else if(state.enemies() == 0){
|
||||
}else if(state.enemies == 0){
|
||||
builder.append(Core.bundle.get("waiting"));
|
||||
}
|
||||
|
||||
@ -646,7 +646,7 @@ public class HudFragment extends Fragment{
|
||||
}
|
||||
|
||||
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){
|
||||
|
Loading…
Reference in New Issue
Block a user