Certain team-specific rules

This commit is contained in:
Anuken
2020-06-15 12:00:32 -04:00
parent 90b0650af9
commit b5660a50ca
61 changed files with 291 additions and 237 deletions

View File

@@ -3,6 +3,8 @@ package mindustry.game;
import arc.graphics.*;
import arc.struct.*;
import arc.util.ArcAnnotate.*;
import arc.util.serialization.*;
import arc.util.serialization.Json.*;
import mindustry.content.*;
import mindustry.io.*;
import mindustry.type.*;
@@ -14,18 +16,26 @@ import mindustry.world.*;
* Does not store game state, just configuration.
*/
public class Rules{
/** Whether the player team has infinite resources. */
/** Whether ever team has infinite resources and instant build speed. */
public boolean infiniteResources;
/** Team-specific rules. */
public TeamRules teams = new TeamRules();
/** Whether the waves come automatically on a timer. If not, waves come when the play button is pressed. */
public boolean waveTimer = true;
/** Whether waves are spawnable at all. */
public boolean waves;
/** Whether the enemy AI has infinite resources in most of their buildings and turrets. */
public boolean enemyCheat;
/** Whether the enemy AI has infinite resources in their core only. TODO remove */
public boolean enemyInfiniteResources = true;
/** Whether the game objective is PvP. Note that this enables automatic hosting. */
public boolean pvp;
/** Whether to pause the wave timer until all enemies are destroyed. */
public boolean waitEnemies = false;
/** Determinates if gamemode is attack mode */
public boolean attackMode = false;
/** Whether this is the editor gamemode. */
public boolean editor = false;
/** Whether the tutorial is enabled. False by default. */
public boolean tutorial = false;
/** Whether a gameover can happen at all. Set this to false to implement custom gameover conditions. */
public boolean canGameOver = true;
/** Whether reactors can explode and damage other blocks. */
public boolean reactorExplosions = true;
/** How fast unit pads build units. */
@@ -60,18 +70,6 @@ public class Rules{
public @Nullable Sector sector;
/** Spawn layout. */
public Seq<SpawnGroup> spawns = new Seq<>();
/** Whether to pause the wave timer until all enemies are destroyed. */
public boolean waitEnemies = false;
/** Determinates if gamemode is attack mode */
public boolean attackMode = false;
/** Whether this is the editor gamemode. */
public boolean editor = false;
/** Whether the tutorial is enabled. False by default. */
public boolean tutorial = false;
/** Whether a gameover can happen at all. Set this to false to implement custom gameover conditions. */
public boolean canGameOver = true;
/** EXPERIMENTAL building AI. TODO remove */
public boolean buildAI = true;
/** Starting items put in cores */
public Seq<ItemStack> loadout = Seq.with(ItemStack.with(Items.copper, 100));
/** Weather events that occur here. */
@@ -92,6 +90,16 @@ public class Rules{
/** special tags for additional info */
public StringMap tags = new StringMap();
/** A team-specific ruleset. */
public static class TeamRule{
/** Whether to use building AI. */
public boolean ai;
/** If true, blocks don't require power or resources. */
public boolean cheat;
/** If true, resources are not consumed when building. */
public boolean infiniteResources;
}
/** Copies this ruleset exactly. Not efficient at all, do not use often. */
public Rules copy(){
return JsonIO.copy(this);
@@ -111,4 +119,31 @@ public class Rules{
return Gamemode.survival;
}
}
/** A simple map for storing TeamRules in an efficient way without hashing. */
public static class TeamRules implements Serializable{
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());
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);
}
}
}
@Override
public void read(Json json, JsonValue jsonData){
for(JsonValue value : jsonData){
values[Integer.parseInt(value.name)] = json.readValue(TeamRule.class, value);
}
}
}
}

View File

@@ -246,7 +246,7 @@ public class Schematics implements Loadable{
Draw.rect(Tmp.tr1, buffer.getWidth()/2f, buffer.getHeight()/2f, buffer.getWidth(), -buffer.getHeight());
Draw.color();
Seq<BuildRequest> requests = schematic.tiles.map(t -> new BuildRequest(t.x, t.y, t.rotation, t.block).configure(t.config));
Seq<BuildPlan> requests = schematic.tiles.map(t -> new BuildPlan(t.x, t.y, t.rotation, t.block).configure(t.config));
Draw.flush();
//scale each request to fit schematic
@@ -276,8 +276,8 @@ public class Schematics implements Loadable{
}
/** Creates an array of build requests from a schematic's data, centered on the provided x+y coordinates. */
public Seq<BuildRequest> toRequests(Schematic schem, int x, int y){
return schem.tiles.map(t -> new BuildRequest(t.x + x - schem.width/2, t.y + y - schem.height/2, t.rotation, t.block).original(t.x, t.y, schem.width, schem.height).configure(t.config))
public Seq<BuildPlan> toRequests(Schematic schem, int x, int y){
return schem.tiles.map(t -> new BuildPlan(t.x + x - schem.width/2, t.y + y - schem.height/2, t.rotation, t.block).original(t.x, t.y, schem.width, schem.height).configure(t.config))
.removeAll(s -> !s.block.isVisible() || !s.block.unlockedCur());
}
@@ -558,7 +558,7 @@ public class Schematics implements Loadable{
int ox = schem.width/2, oy = schem.height/2;
schem.tiles.each(req -> {
req.config = BuildRequest.pointConfig(req.config, p -> {
req.config = BuildPlan.pointConfig(req.config, p -> {
int cx = p.x, cy = p.y;
int lx = cx;

View File

@@ -6,6 +6,7 @@ import arc.math.*;
import arc.struct.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import mindustry.game.Rules.*;
import mindustry.game.Teams.*;
import mindustry.graphics.*;
import mindustry.world.blocks.storage.CoreBlock.*;
@@ -55,6 +56,11 @@ public class Team implements Comparable<Team>{
all[us] = this;
}
/** @return the team-specific rules. */
public TeamRule rules(){
return state.rules.teams.get(this);
}
public Seq<Team> enemies(){
return state.teams.enemiesOf(this);
}

View File

@@ -174,7 +174,7 @@ public class Teams{
/** @return whether this team is controlled by the AI and builds bases. */
public boolean hasAI(){
return state.rules.attackMode && team == state.rules.waveTeam && state.rules.buildAI;
return state.rules.attackMode && team.rules().ai;
}
@Override