Many various internal changes

This commit is contained in:
Anuken
2019-12-26 17:46:01 -05:00
parent 36ec88e2e2
commit de5979f4ee
53 changed files with 435 additions and 575 deletions

View File

@@ -4,7 +4,7 @@ import arc.*;
import arc.func.*;
import mindustry.maps.*;
import static mindustry.Vars.waveTeam;
import static mindustry.Vars.*;
/** Defines preset rule sets. */
public enum Gamemode{
@@ -22,7 +22,7 @@ public enum Gamemode{
attack(rules -> {
rules.unitDrops = true;
rules.attackMode = true;
}, map -> map.teams.contains((int) waveTeam.id)),
}, map -> map.teams.contains((int)state.rules.waveTeam.id)),
pvp(rules -> {
rules.pvp = true;
rules.enemyCoreBuildRadius = 600f;

View File

@@ -83,7 +83,7 @@ public class MusicControl{
/** Whether to play dark music.*/
private boolean isDark(){
if(!state.teams.get(player.getTeam()).cores.isEmpty() && state.teams.get(player.getTeam()).cores.first().entity.healthf() < 0.85f){
if(state.teams.get(player.getTeam()).hasCore() && state.teams.get(player.getTeam()).core().healthf() < 0.85f){
//core damaged -> dark
return true;
}

View File

@@ -78,6 +78,10 @@ public class Rules{
public boolean lighting = false;
/** Ambient light color, used when lighting is enabled. */
public Color ambientLight = new Color(0.01f, 0.01f, 0.04f, 0.99f);
/** team of the player by default */
public Team defaultTeam = Team.sharded;
/** team of the enemy in waves/sectors */
public Team waveTeam = Team.crux;
/** Copies this ruleset exactly. Not very efficient at all, do not use often. */
public Rules copy(){

View File

@@ -254,7 +254,7 @@ public class Schematics implements Loadable{
Tile tile = world.tile(st.x + ox, st.y + oy);
if(tile == null) return;
world.setBlock(tile, st.block, defaultTeam);
tile.set(st.block, state.rules.defaultTeam);
tile.rotation(st.rotation);
if(st.block.posConfig){
tile.configureAny(Pos.get(tile.x - st.x + Pos.x(st.config), tile.y - st.y + Pos.y(st.config)));

View File

@@ -2,34 +2,66 @@ package mindustry.game;
import arc.*;
import arc.graphics.*;
import arc.struct.*;
import arc.util.*;
import mindustry.graphics.*;
public class Team{
/** All registered teams. */
public final static Array<Team> all = new Array<>();
public final static Team
derelict = new Team("derelict", Color.valueOf("4d4e58")),
sharded = new Team("sharded", Pal.accent.cpy()),
crux = new Team("crux", Color.valueOf("e82d2d")),
green = new Team("green", Color.valueOf("4dd98b")),
purple = new Team("purple", Color.valueOf("9a4bdf")),
blue = new Team("blue", Color.royal.cpy());
public class Team implements Comparable<Team>{
public final Color color;
public final int intColor;
public final String name;
public final int id;
public final byte id;
public Team(String name, Color color){
/** All 256 registered teams. */
private static final Team[] all = new Team[256];
/** The 6 base teams used in the editor. */
private static final Team[] baseTeams = new Team[6];
public final static Team
derelict = new Team(0, "derelict", Color.valueOf("4d4e58")),
sharded = new Team(1, "sharded", Pal.accent.cpy()),
crux = new Team(2, "crux", Color.valueOf("e82d2d")),
green = new Team(3, "green", Color.valueOf("4dd98b")),
purple = new Team(4, "purple", Color.valueOf("9a4bdf")),
blue = new Team(5, "blue", Color.royal.cpy());
static{
//create the whole 256 placeholder teams
for(int i = 6; i < all.length; i++){
new Team(i, "team#" + i, Color.HSVtoRGB(360f * (float)(i) / all.length, 100f, 100f, 1f));
}
}
public static Team get(int id){
return all[Pack.u((byte)id)];
}
/** @return the 6 base team colors. */
public static Team[] base(){
return baseTeams;
}
/** @return all the teams - do not use this for lookup! */
public static Team[] all(){
return all;
}
protected Team(int id, String name, Color color){
this.name = name;
this.color = color;
this.intColor = Color.rgba8888(color);
this.id = all.size;
all.add(this);
this.id = (byte)id;
int us = Pack.u(this.id);
if(us < 6) baseTeams[us] = this;
all[us] = this;
}
public String localized(){
return Core.bundle.get("team." + name + ".name");
return Core.bundle.get("team." + name + ".name", name);
}
@Override
public int compareTo(Team team){
return Integer.compare(id, team.id);
}
}

View File

@@ -1,44 +1,82 @@
package mindustry.game;
import arc.func.*;
import arc.math.geom.*;
import arc.struct.*;
import mindustry.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import mindustry.entities.type.*;
import mindustry.world.*;
import mindustry.world.blocks.storage.CoreBlock.*;
import static mindustry.Vars.state;
/** Class for various team-based utilities. */
public class Teams{
/** Maps team IDs to team data. */
private Array<TeamData> map = new Array<>();
private TeamData[] map = new TeamData[256];
/** Active teams. */
private Array<TeamData> active = new Array<>();
public <T> T eachEnemyCore(Team team, Func<TileEntity, T> ret){
T out = null;
//todo each enemy, each enemy core...
return out;
public @Nullable CoreEntity closestEnemyCore(float x, float y, Team team){
for(TeamData data : active){
if(areEnemies(team, data.team)){
CoreEntity tile = Geometry.findClosest(x, y, data.cores);
if(tile != null){
return tile;
}
}
}
return null;
}
/**
* Register a team.
* @param team The team type enum.
*/
public void add(Team team){
map[team.id] = new TeamData(team);
public @Nullable CoreEntity closestCore(float x, float y, Team team){
return Geometry.findClosest(x, y, get(team).cores);
}
public boolean eachEnemyCore(Team team, Boolf<CoreEntity> ret){
for(TeamData data : active){
if(areEnemies(team, data.team)){
for(CoreEntity tile : data.cores){
if(ret.get(tile)){
return true;
}
}
}
}
return false;
}
public void eachEnemyCore(Team team, Cons<TileEntity> ret){
for(TeamData data : active){
if(areEnemies(team, data.team)){
for(TileEntity tile : data.cores){
ret.get(tile);
}
}
}
}
/** Returns team data by type. */
public TeamData get(Team team){
if(map[team.id] == null){
add(team);
if(map[Pack.u(team.id)] == null){
map[Pack.u(team.id)] = new TeamData(team);
}
return map[team.id];
return map[Pack.u(team.id)];
}
public Array<CoreEntity> playerCores(){
return get(state.rules.defaultTeam).cores;
}
/** Do not modify! */
public Array<CoreEntity> cores(Team team){
return get(team).cores;
}
/** Returns whether a team is active, e.g. whether it has any cores remaining. */
public boolean isActive(Team team){
//the enemy wave team is always active
return team == Vars.waveTeam || get(team).cores.size > 0;
return team == state.rules.waveTeam || get(team).cores.size > 0;
}
/** Returns whether {@param other} is an enemy of {@param #team}. */
@@ -47,20 +85,63 @@ public class Teams{
return team != other;
}
/** Allocates a new array with the active teams.
* Never call in the main game loop.*/
public Array<TeamData> getActive(){
return Array.select(map, t -> t != null);
public boolean canInteract(Team team, Team other){
return team == other || other == Team.derelict;
}
public static class TeamData{
public final ObjectSet<Tile> cores = new ObjectSet<>();
/** Do not modify. */
public Array<TeamData> getActive(){
return active;
}
public void registerCore(CoreEntity core){
TeamData data = get(core.getTeam());
//add core if not present
if(!data.cores.contains(core)){
data.cores.add(core);
}
//register in active list if needed
if(data.active() && !active.contains(data)){
active.add(data);
}
}
public void unregisterCore(CoreEntity entity){
TeamData data = get(entity.getTeam());
//remove core
data.cores.remove(entity);
//unregister in active list
if(!data.active()){
active.remove(data);
}
}
public class TeamData{
private final Array<CoreEntity> cores = new Array<>();
public final Team team;
public Queue<BrokenBlock> brokenBlocks = new Queue<>();
public TeamData(Team team){
this.team = team;
}
public boolean active(){
return team == state.rules.waveTeam || cores.size > 0;
}
public boolean hasCore(){
return cores.size > 0;
}
public boolean noCores(){
return cores.isEmpty();
}
public TileEntity core(){
return cores.first();
}
}
/** Represents a block made by this team that was destroyed somewhere on the map.

View File

@@ -10,6 +10,7 @@ import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.type.*;
import mindustry.game.EventType.*;
import mindustry.graphics.*;
import mindustry.type.*;
@@ -161,7 +162,7 @@ public class Tutorial{
},
withdraw(() -> event("withdraw")){
void begin(){
state.teams.get(defaultTeam).cores.first().entity.items.add(Items.copper, 10);
state.teams.playerCores().first().items.add(Items.copper, 10);
}
},
deposit(() -> event("deposit")),
@@ -239,18 +240,18 @@ public class Tutorial{
//utility
static void placeBlocks(){
Tile core = state.teams.get(defaultTeam).cores.first();
TileEntity core = state.teams.playerCores().first();
for(int i = 0; i < blocksToBreak; i++){
world.removeBlock(world.ltile(core.x + blockOffset, core.y + i));
world.tile(core.x + blockOffset, core.y + i).setBlock(Blocks.scrapWall, defaultTeam);
world.ltile(core.tile.x + blockOffset, core.tile.y + i).remove();
world.tile(core.tile.x + blockOffset, core.tile.y + i).setBlock(Blocks.scrapWall, state.rules.defaultTeam);
}
}
static boolean blocksBroken(){
Tile core = state.teams.get(defaultTeam).cores.first();
TileEntity core = state.teams.playerCores().first();
for(int i = 0; i < blocksToBreak; i++){
if(world.tile(core.x + blockOffset, core.y + i).block() == Blocks.scrapWall){
if(world.tile(core.tile.x + blockOffset, core.tile.y + i).block() == Blocks.scrapWall){
return false;
}
}
@@ -270,7 +271,7 @@ public class Tutorial{
}
static int item(Item item){
return state.teams.get(defaultTeam).cores.isEmpty() ? 0 : state.teams.get(defaultTeam).cores.first().entity.items.get(item);
return state.teams.get(state.rules.defaultTeam).noCores() ? 0 : state.teams.playerCores().first().items.get(item);
}
static boolean toggled(String name){