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

View File

@@ -6,7 +6,6 @@ import arc.math.*;
import arc.math.geom.*;
import arc.struct.EnumSet;
import arc.struct.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
@@ -111,11 +110,10 @@ public class BlockIndexer{
}
private GridBits structQuadrant(Team t){
int id = Pack.u(t.id);
if(structQuadrants[id] == null){
structQuadrants[id] = new GridBits(Mathf.ceil(world.width() / (float)quadrantSize), Mathf.ceil(world.height() / (float)quadrantSize));
if(structQuadrants[t.id] == null){
structQuadrants[t.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. */

View File

@@ -68,7 +68,7 @@ public class Pathfinder implements Runnable{
/** Packs a tile into its internal representation. */
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. */
@@ -144,9 +144,9 @@ public class Pathfinder implements Runnable{
Core.app.post(() -> {
//remove its used state
if(fieldMap[team.uid] != null){
fieldMap[team.uid].remove(data.target);
fieldMapUsed[team.uid].remove(data.target);
if(fieldMap[team.id] != null){
fieldMap[team.id].remove(data.target);
fieldMapUsed[team.id].remove(data.target);
}
//remove from main thread list
mainList.remove(data);
@@ -180,16 +180,16 @@ public class Pathfinder implements Runnable{
public Tile getTargetTile(Tile tile, Team team, PathTarget target){
if(tile == null) return null;
if(fieldMap[team.uid] == null){
fieldMap[team.uid] = new ObjectMap<>();
fieldMapUsed[team.uid] = new ObjectSet<>();
if(fieldMap[team.id] == null){
fieldMap[team.id] = new ObjectMap<>();
fieldMapUsed[team.id] = new ObjectSet<>();
}
Flowfield data = fieldMap[team.uid].get(target);
Flowfield data = fieldMap[team.id].get(target);
if(data == null){
//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
IntSeq targets = target.getPositions(team, new IntSeq());
queue.post(() -> createPath(team, target, targets));
@@ -311,8 +311,8 @@ public class Pathfinder implements Runnable{
//add to main thread's list of paths
Core.app.post(() -> {
mainList.add(path);
if(fieldMap[team.uid] != null){
fieldMap[team.uid].put(target, path);
if(fieldMap[team.id] != null){
fieldMap[team.id].put(target, path);
}
});

View File

@@ -13,9 +13,9 @@ public class TeamIndexProcess implements AsyncProcess{
private int[] counts = new int[Team.all.length];
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){
@@ -36,8 +36,8 @@ public class TeamIndexProcess implements AsyncProcess{
public void begin(){
for(Team team : Team.all){
if(trees[team.uid] != null){
trees[team.uid].clear();
if(trees[team.id] != null){
trees[team.id].clear();
}
}

View File

@@ -1689,7 +1689,6 @@ public class Blocks implements ContentList{
plans = new UnitPlan[]{
new UnitPlan(UnitTypes.wraith, 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)),
};
size = 3;

View File

@@ -13,7 +13,7 @@ import mindustry.type.*;
public class UnitTypes implements ContentList{
//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
public static @EntityDef({Unitc.class, Mechc.class, Builderc.class}) UnitType tau;
@@ -24,14 +24,14 @@ public class UnitTypes implements ContentList{
//legs
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;
//air + mining
public static @EntityDef({Unitc.class, Minerc.class}) UnitType draug;
//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
//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"){{
flying = true;
drag = 0.05f;

View File

@@ -52,7 +52,7 @@ public class DrawOperation{
}else if(type == OpType.rotation.ordinal()){
return tile.rotation();
}else if(type == OpType.team.ordinal()){
return tile.getTeamID();
return (byte)tile.getTeamID();
}else if(type == OpType.overlay.ordinal()){
return tile.overlayID();
}

View File

@@ -55,7 +55,7 @@ public class EditorTile extends Tile{
op(OpType.block, block.id);
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);
}
@@ -67,7 +67,7 @@ public class EditorTile extends Tile{
}
if(getTeamID() == team.id) return;
op(OpType.team, getTeamID());
op(OpType.team, (byte)getTeamID());
super.setTeam(team);
}

View File

@@ -139,7 +139,7 @@ public enum EditorTool{
if(tile.synthetic()){
Team dest = tile.team();
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));
}
}
}

View File

@@ -409,7 +409,7 @@ public class MapGenerateDialog extends BaseDialog{
this.floor = floor.id;
this.block = wall.id;
this.ore = ore.id;
this.team = team.id;
this.team = (byte)team.id;
this.rotation = (byte)rotation;
}

View File

@@ -747,8 +747,8 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
public void drawTeamTop(){
if(block.teamRegion.found()){
if(block.teamRegions[team.uid] == block.teamRegion) Draw.color(team.color);
Draw.rect(block.teamRegions[team.uid], x, y);
if(block.teamRegions[team.id] == block.teamRegion) Draw.color(team.color);
Draw.rect(block.teamRegions[team.id], x, y);
Draw.color();
}
}

View File

@@ -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 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));

View File

@@ -157,7 +157,7 @@ public class DefaultWaves{
spacing = 3;
}},
new SpawnGroup(UnitTypes.chaosArray){{
new SpawnGroup(UnitTypes.siegeArray){{
begin = 41;
unitAmount = 1;
unitScaling = 1;

View File

@@ -134,16 +134,16 @@ public class Rules{
final TeamRule[] values = new TeamRule[Team.all.length];
public TeamRule get(Team team){
TeamRule out = values[team.uid];
if(out == null) values[team.uid] = (out = new TeamRule());
TeamRule out = values[team.id];
if(out == null) values[team.id] = (out = new TeamRule());
return out;
}
@Override
public void write(Json json){
for(Team team : Team.all){
if(values[team.uid] != null){
json.writeValue(team.uid + "", values[team.uid], TeamRule.class);
if(values[team.id] != null){
json.writeValue(team.id + "", values[team.id], TeamRule.class);
}
}
}

View File

@@ -4,7 +4,6 @@ import arc.*;
import arc.graphics.*;
import arc.math.*;
import arc.struct.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import mindustry.game.Rules.*;
import mindustry.game.Teams.*;
@@ -14,8 +13,7 @@ import mindustry.world.blocks.storage.CoreBlock.*;
import static mindustry.Vars.*;
public class Team implements Comparable<Team>{
public final byte id;
public final int uid;
public final int id;
public final Color color;
public final Color[] palette;
public boolean hasPalette;
@@ -52,12 +50,10 @@ public class Team implements Comparable<Team>{
protected Team(int id, String name, Color color){
this.name = name;
this.color = color;
this.id = (byte)id;
this.id = id;
int us = Pack.u(this.id);
uid = us;
if(us < 6) baseTeams[us] = this;
all[us] = this;
if(id < 6) baseTeams[id] = this;
all[id] = this;
palette = new Color[3];
palette[0] = color;

View File

@@ -62,10 +62,10 @@ public class Teams{
/** Returns team data by type. */
public TeamData get(Team team){
if(map[team.uid] == null){
map[team.uid] = new TeamData(team);
if(map[team.id] == null){
map[team.id] = new TeamData(team);
}
return map[team.uid];
return map[team.id];
}
public Seq<CoreEntity> playerCores(){

View File

@@ -98,7 +98,7 @@ public abstract class SaveVersion extends SaveFileReader{
"viewpos", Tmp.v1.set(player == null ? Vec2.ZERO : player).toString(),
"controlledType", headless || control.input.controlledType == null ? "null" : control.input.controlledType.name,
"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));
}
@@ -119,7 +119,7 @@ public abstract class SaveVersion extends SaveFileReader{
player.set(Tmp.v1);
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){
player.team(team);
}

View File

@@ -631,7 +631,7 @@ public class Block extends UnlockableContent{
//load specific team regions
teamRegions = new TextureRegion[Team.all.length];
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;
}
}

View File

@@ -171,7 +171,7 @@ public class Tile implements Position, QuadTreeObject, Displayable{
return build == null ? y : build.tile.y;
}
public byte getTeamID(){
public int getTeamID(){
return team().id;
}