Fixed crashes with team IDs above 127

This commit is contained in:
Anuken
2020-07-03 12:36:12 -04:00
parent 3772b04c6b
commit 843a8c3e56
18 changed files with 48 additions and 68 deletions
+3 -5
View File
@@ -6,7 +6,6 @@ import arc.math.*;
import arc.math.geom.*; import arc.math.geom.*;
import arc.struct.EnumSet; import arc.struct.EnumSet;
import arc.struct.*; import arc.struct.*;
import arc.util.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.game.EventType.*; import mindustry.game.EventType.*;
import mindustry.game.*; import mindustry.game.*;
@@ -111,11 +110,10 @@ public class BlockIndexer{
} }
private GridBits structQuadrant(Team t){ private GridBits structQuadrant(Team t){
int id = Pack.u(t.id); if(structQuadrants[t.id] == null){
if(structQuadrants[id] == null){ structQuadrants[t.id] = new GridBits(Mathf.ceil(world.width() / (float)quadrantSize), Mathf.ceil(world.height() / (float)quadrantSize));
structQuadrants[id] = new GridBits(Mathf.ceil(world.width() / (float)quadrantSize), Mathf.ceil(world.height() / (float)quadrantSize));
} }
return structQuadrants[id]; return structQuadrants[t.id];
} }
/** Updates all the structure quadrants for a newly activated team. */ /** Updates all the structure quadrants for a newly activated team. */
+11 -11
View File
@@ -68,7 +68,7 @@ public class Pathfinder implements Runnable{
/** Packs a tile into its internal representation. */ /** Packs a tile into its internal representation. */
private int packTile(Tile tile){ private int packTile(Tile tile){
return PathTile.get(tile.cost, tile.getTeamID(), !tile.solid() && tile.floor().drownTime <= 0f, !tile.solid() && tile.floor().isLiquid); return PathTile.get(tile.cost, (byte)tile.getTeamID(), !tile.solid() && tile.floor().drownTime <= 0f, !tile.solid() && tile.floor().isLiquid);
} }
/** Starts or restarts the pathfinding thread. */ /** Starts or restarts the pathfinding thread. */
@@ -144,9 +144,9 @@ public class Pathfinder implements Runnable{
Core.app.post(() -> { Core.app.post(() -> {
//remove its used state //remove its used state
if(fieldMap[team.uid] != null){ if(fieldMap[team.id] != null){
fieldMap[team.uid].remove(data.target); fieldMap[team.id].remove(data.target);
fieldMapUsed[team.uid].remove(data.target); fieldMapUsed[team.id].remove(data.target);
} }
//remove from main thread list //remove from main thread list
mainList.remove(data); mainList.remove(data);
@@ -180,16 +180,16 @@ public class Pathfinder implements Runnable{
public Tile getTargetTile(Tile tile, Team team, PathTarget target){ public Tile getTargetTile(Tile tile, Team team, PathTarget target){
if(tile == null) return null; if(tile == null) return null;
if(fieldMap[team.uid] == null){ if(fieldMap[team.id] == null){
fieldMap[team.uid] = new ObjectMap<>(); fieldMap[team.id] = new ObjectMap<>();
fieldMapUsed[team.uid] = new ObjectSet<>(); fieldMapUsed[team.id] = new ObjectSet<>();
} }
Flowfield data = fieldMap[team.uid].get(target); Flowfield data = fieldMap[team.id].get(target);
if(data == null){ if(data == null){
//if this combination is not found, create it on request //if this combination is not found, create it on request
if(fieldMapUsed[team.uid].add(target)){ if(fieldMapUsed[team.id].add(target)){
//grab targets since this is run on main thread //grab targets since this is run on main thread
IntSeq targets = target.getPositions(team, new IntSeq()); IntSeq targets = target.getPositions(team, new IntSeq());
queue.post(() -> createPath(team, target, targets)); queue.post(() -> createPath(team, target, targets));
@@ -311,8 +311,8 @@ public class Pathfinder implements Runnable{
//add to main thread's list of paths //add to main thread's list of paths
Core.app.post(() -> { Core.app.post(() -> {
mainList.add(path); mainList.add(path);
if(fieldMap[team.uid] != null){ if(fieldMap[team.id] != null){
fieldMap[team.uid].put(target, path); fieldMap[team.id].put(target, path);
} }
}); });
@@ -13,9 +13,9 @@ public class TeamIndexProcess implements AsyncProcess{
private int[] counts = new int[Team.all.length]; private int[] counts = new int[Team.all.length];
public QuadTree<Unit> tree(Team team){ public QuadTree<Unit> tree(Team team){
if(trees[team.uid] == null) trees[team.uid] = new QuadTree<>(Vars.world.getQuadBounds(new Rect())); if(trees[team.id] == null) trees[team.id] = new QuadTree<>(Vars.world.getQuadBounds(new Rect()));
return trees[team.uid]; return trees[team.id];
} }
public int count(Team team){ public int count(Team team){
@@ -36,8 +36,8 @@ public class TeamIndexProcess implements AsyncProcess{
public void begin(){ public void begin(){
for(Team team : Team.all){ for(Team team : Team.all){
if(trees[team.uid] != null){ if(trees[team.id] != null){
trees[team.uid].clear(); trees[team.id].clear();
} }
} }
-1
View File
@@ -1689,7 +1689,6 @@ public class Blocks implements ContentList{
plans = new UnitPlan[]{ plans = new UnitPlan[]{
new UnitPlan(UnitTypes.wraith, 200f, with(Items.silicon, 10)), new UnitPlan(UnitTypes.wraith, 200f, with(Items.silicon, 10)),
new UnitPlan(UnitTypes.spirit, 200f, with(Items.silicon, 10)), new UnitPlan(UnitTypes.spirit, 200f, with(Items.silicon, 10)),
new UnitPlan(UnitTypes.draug, 200f, with(Items.silicon, 10)),
new UnitPlan(UnitTypes.phantom, 200f, with(Items.silicon, 10)), new UnitPlan(UnitTypes.phantom, 200f, with(Items.silicon, 10)),
}; };
size = 3; size = 3;
+6 -19
View File
@@ -13,7 +13,7 @@ import mindustry.type.*;
public class UnitTypes implements ContentList{ public class UnitTypes implements ContentList{
//ground //ground
public static @EntityDef({Unitc.class, Mechc.class}) UnitType mace, dagger, crawler, fortress, chaosArray, eradicator; public static @EntityDef({Unitc.class, Mechc.class}) UnitType mace, dagger, crawler, fortress, siegeArray, eradicator;
//ground + builder //ground + builder
public static @EntityDef({Unitc.class, Mechc.class, Builderc.class}) UnitType tau; public static @EntityDef({Unitc.class, Mechc.class, Builderc.class}) UnitType tau;
@@ -24,14 +24,14 @@ public class UnitTypes implements ContentList{
//legs //legs
public static @EntityDef({Unitc.class, Legsc.class}) UnitType cix, eruptor; public static @EntityDef({Unitc.class, Legsc.class}) UnitType cix, eruptor;
//air //air (no special traits)
public static @EntityDef({Unitc.class}) UnitType wraith, reaper, ghoul, revenant, lich; public static @EntityDef({Unitc.class}) UnitType wraith, reaper, ghoul, revenant, lich;
//air + mining
public static @EntityDef({Unitc.class, Minerc.class}) UnitType draug;
//air + building //air + building
public static @EntityDef({Unitc.class, Builderc.class}) UnitType phantom, spirit; public static @EntityDef({Unitc.class, Builderc.class}) UnitType spirit;
//air + mining
public static @EntityDef({Unitc.class, Minerc.class}) UnitType phantom;
//air + building + mining //air + building + mining
//TODO implement other starter drones //TODO implement other starter drones
@@ -403,19 +403,6 @@ public class UnitTypes implements ContentList{
}}); }});
}}; }};
draug = new UnitType("draug"){{
flying = true;
drag = 0.05f;
speed = 2f;
range = 50f;
accel = 0.2f;
health = 80;
mineSpeed = 0.9f;
engineSize = 1.8f;
engineOffset = 5.7f;
mineTier = 1;
}};
spirit = new UnitType("spirit"){{ spirit = new UnitType("spirit"){{
flying = true; flying = true;
drag = 0.05f; drag = 0.05f;
+1 -1
View File
@@ -52,7 +52,7 @@ public class DrawOperation{
}else if(type == OpType.rotation.ordinal()){ }else if(type == OpType.rotation.ordinal()){
return tile.rotation(); return tile.rotation();
}else if(type == OpType.team.ordinal()){ }else if(type == OpType.team.ordinal()){
return tile.getTeamID(); return (byte)tile.getTeamID();
}else if(type == OpType.overlay.ordinal()){ }else if(type == OpType.overlay.ordinal()){
return tile.overlayID(); return tile.overlayID();
} }
+2 -2
View File
@@ -55,7 +55,7 @@ public class EditorTile extends Tile{
op(OpType.block, block.id); op(OpType.block, block.id);
if(rotation != 0) op(OpType.rotation, (byte)rotation); if(rotation != 0) op(OpType.rotation, (byte)rotation);
if(team() != Team.derelict) op(OpType.team, team().id); if(team() != Team.derelict) op(OpType.team, (byte)team().id);
super.setBlock(type, team, rotation); super.setBlock(type, team, rotation);
} }
@@ -67,7 +67,7 @@ public class EditorTile extends Tile{
} }
if(getTeamID() == team.id) return; if(getTeamID() == team.id) return;
op(OpType.team, getTeamID()); op(OpType.team, (byte)getTeamID());
super.setTeam(team); super.setTeam(team);
} }
+1 -1
View File
@@ -139,7 +139,7 @@ public enum EditorTool{
if(tile.synthetic()){ if(tile.synthetic()){
Team dest = tile.team(); Team dest = tile.team();
if(dest == editor.drawTeam) return; if(dest == editor.drawTeam) return;
fill(editor, x, y, false, t -> t.getTeamID() == (int)dest.id && t.synthetic(), t -> t.setTeam(editor.drawTeam)); fill(editor, x, y, false, t -> t.getTeamID() == dest.id && t.synthetic(), t -> t.setTeam(editor.drawTeam));
} }
} }
} }
@@ -409,7 +409,7 @@ public class MapGenerateDialog extends BaseDialog{
this.floor = floor.id; this.floor = floor.id;
this.block = wall.id; this.block = wall.id;
this.ore = ore.id; this.ore = ore.id;
this.team = team.id; this.team = (byte)team.id;
this.rotation = (byte)rotation; this.rotation = (byte)rotation;
} }
@@ -747,8 +747,8 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
public void drawTeamTop(){ public void drawTeamTop(){
if(block.teamRegion.found()){ if(block.teamRegion.found()){
if(block.teamRegions[team.uid] == block.teamRegion) Draw.color(team.color); if(block.teamRegions[team.id] == block.teamRegion) Draw.color(team.color);
Draw.rect(block.teamRegions[team.uid], x, y); Draw.rect(block.teamRegions[team.id], x, y);
Draw.color(); Draw.color();
} }
} }
@@ -95,7 +95,7 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{
float ex = mineTile.worldx() + Mathf.sin(Time.time() + 48, swingScl, swingMag); float ex = mineTile.worldx() + Mathf.sin(Time.time() + 48, swingScl, swingMag);
float ey = mineTile.worldy() + Mathf.sin(Time.time() + 48, swingScl + 2f, swingMag); float ey = mineTile.worldy() + Mathf.sin(Time.time() + 48, swingScl + 2f, swingMag);
Draw.z(Layer.power); Draw.z(Layer.flyingUnit + 0.1f);
Draw.color(Color.lightGray, Color.white, 1f - flashScl + Mathf.absin(Time.time(), 0.5f, flashScl)); Draw.color(Color.lightGray, Color.white, 1f - flashScl + Mathf.absin(Time.time(), 0.5f, flashScl));
+1 -1
View File
@@ -157,7 +157,7 @@ public class DefaultWaves{
spacing = 3; spacing = 3;
}}, }},
new SpawnGroup(UnitTypes.chaosArray){{ new SpawnGroup(UnitTypes.siegeArray){{
begin = 41; begin = 41;
unitAmount = 1; unitAmount = 1;
unitScaling = 1; unitScaling = 1;
+4 -4
View File
@@ -134,16 +134,16 @@ public class Rules{
final TeamRule[] values = new TeamRule[Team.all.length]; final TeamRule[] values = new TeamRule[Team.all.length];
public TeamRule get(Team team){ public TeamRule get(Team team){
TeamRule out = values[team.uid]; TeamRule out = values[team.id];
if(out == null) values[team.uid] = (out = new TeamRule()); if(out == null) values[team.id] = (out = new TeamRule());
return out; return out;
} }
@Override @Override
public void write(Json json){ public void write(Json json){
for(Team team : Team.all){ for(Team team : Team.all){
if(values[team.uid] != null){ if(values[team.id] != null){
json.writeValue(team.uid + "", values[team.uid], TeamRule.class); json.writeValue(team.id + "", values[team.id], TeamRule.class);
} }
} }
} }
+4 -8
View File
@@ -4,7 +4,6 @@ import arc.*;
import arc.graphics.*; import arc.graphics.*;
import arc.math.*; import arc.math.*;
import arc.struct.*; import arc.struct.*;
import arc.util.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import mindustry.game.Rules.*; import mindustry.game.Rules.*;
import mindustry.game.Teams.*; import mindustry.game.Teams.*;
@@ -14,8 +13,7 @@ import mindustry.world.blocks.storage.CoreBlock.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
public class Team implements Comparable<Team>{ public class Team implements Comparable<Team>{
public final byte id; public final int id;
public final int uid;
public final Color color; public final Color color;
public final Color[] palette; public final Color[] palette;
public boolean hasPalette; public boolean hasPalette;
@@ -52,12 +50,10 @@ public class Team implements Comparable<Team>{
protected Team(int id, String name, Color color){ protected Team(int id, String name, Color color){
this.name = name; this.name = name;
this.color = color; this.color = color;
this.id = (byte)id; this.id = id;
int us = Pack.u(this.id); if(id < 6) baseTeams[id] = this;
uid = us; all[id] = this;
if(us < 6) baseTeams[us] = this;
all[us] = this;
palette = new Color[3]; palette = new Color[3];
palette[0] = color; palette[0] = color;
+3 -3
View File
@@ -62,10 +62,10 @@ public class Teams{
/** Returns team data by type. */ /** Returns team data by type. */
public TeamData get(Team team){ public TeamData get(Team team){
if(map[team.uid] == null){ if(map[team.id] == null){
map[team.uid] = new TeamData(team); map[team.id] = new TeamData(team);
} }
return map[team.uid]; return map[team.id];
} }
public Seq<CoreEntity> playerCores(){ public Seq<CoreEntity> playerCores(){
+2 -2
View File
@@ -98,7 +98,7 @@ public abstract class SaveVersion extends SaveFileReader{
"viewpos", Tmp.v1.set(player == null ? Vec2.ZERO : player).toString(), "viewpos", Tmp.v1.set(player == null ? Vec2.ZERO : player).toString(),
"controlledType", headless || control.input.controlledType == null ? "null" : control.input.controlledType.name, "controlledType", headless || control.input.controlledType == null ? "null" : control.input.controlledType.name,
"nocores", state.rules.defaultTeam.cores().isEmpty(), "nocores", state.rules.defaultTeam.cores().isEmpty(),
"playerteam", player == null ? state.rules.defaultTeam.uid : player.team().uid "playerteam", player == null ? state.rules.defaultTeam.id : player.team().id
).merge(tags)); ).merge(tags));
} }
@@ -119,7 +119,7 @@ public abstract class SaveVersion extends SaveFileReader{
player.set(Tmp.v1); player.set(Tmp.v1);
control.input.controlledType = content.getByName(ContentType.unit, map.get("controlledType", "<none>")); control.input.controlledType = content.getByName(ContentType.unit, map.get("controlledType", "<none>"));
Team team = Team.get(map.getInt("playerteam", state.rules.defaultTeam.uid)); Team team = Team.get(map.getInt("playerteam", state.rules.defaultTeam.id));
if(!net.client() && team != Team.derelict){ if(!net.client() && team != Team.derelict){
player.team(team); player.team(team);
} }
+1 -1
View File
@@ -631,7 +631,7 @@ public class Block extends UnlockableContent{
//load specific team regions //load specific team regions
teamRegions = new TextureRegion[Team.all.length]; teamRegions = new TextureRegion[Team.all.length];
for(Team team : Team.all){ for(Team team : Team.all){
teamRegions[team.uid] = teamRegion.found() ? Core.atlas.find(name + "-team-" + team.name, teamRegion) : teamRegion; teamRegions[team.id] = teamRegion.found() ? Core.atlas.find(name + "-team-" + team.name, teamRegion) : teamRegion;
} }
} }
+1 -1
View File
@@ -171,7 +171,7 @@ public class Tile implements Position, QuadTreeObject, Displayable{
return build == null ? y : build.tile.y; return build == null ? y : build.tile.y;
} }
public byte getTeamID(){ public int getTeamID(){
return team().id; return team().id;
} }