Content class reorganization, beginning work on unit factory

This commit is contained in:
Anuken
2018-03-25 13:12:32 -04:00
parent 59530909d6
commit 3418979f4d
106 changed files with 1772 additions and 1662 deletions
@@ -1,5 +1,6 @@
package io.anuke.mindustry.game;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.ItemStack;
@@ -29,7 +30,7 @@ public class Inventory {
if(item.material) items[item.id] = 99999;
}
}else{
addItem(Item.iron, 40);
addItem(Items.iron, 40);
}
}
@@ -0,0 +1,99 @@
package io.anuke.mindustry.game;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.mindustry.world.Tile;
/**Wrapper around an ObjectMap for team data.*/
public class TeamInfo {
private final static ObjectSet<Team> empty = new ObjectSet<>();
private final static ObjectSet<TeamData> emptyData = new ObjectSet<>();
private ObjectMap<Team, TeamData> map = new ObjectMap<>();
private ObjectSet<Team> allies = new ObjectSet<>(),
enemies = new ObjectSet<>();
private ObjectSet<TeamData> allyData = new ObjectSet<>(),
enemyData = new ObjectSet<>();
public ObjectSet<TeamData> getTeams(boolean ally) {
return ally ? allyData : enemyData;
}
/**Register a team.
* @param team The team type enum.
* @param ally Whether this team is an ally with the player or an enemy with the player.
* In PvP situations with dedicated servers, the sides can be arbitrary.
*/
public void add(Team team, boolean ally){
if(has(team)) throw new RuntimeException("Can't define team information twice!");
TeamData data = new TeamData(team, ally);
if(ally) {
allies.add(team);
allyData.add(data);
}else {
enemies.add(team);
enemyData.add(data);
}
map.put(team, data);
}
/**Returns team data by type. Call {@link #has(Team)} first to make sure it's active!*/
public TeamData get(Team team){
if(!has(team)) throw new RuntimeException("This team is not active! Check has() before calling get().");
return map.get(team);
}
/**Returns whether the specified team is active, e.g. whether it is participating in the game.*/
public boolean has(Team team){
return map.containsKey(team);
}
/**Returns a set of all teams that are enemies of this team.
* For teams not active, an empty set is returned.
*/
public ObjectSet<Team> enemiesOf(Team team) {
boolean ally = allies.contains(team);
boolean enemy = enemies.contains(team);
//this team isn't even in the game, so target nothing!
if(!ally && !enemy) return empty;
return ally ? enemies : allies;
}
/**Returns a set of all teams that are enemies of this team.
* For teams not active, an empty set is returned.
*/
public ObjectSet<TeamData> enemyDataOf(Team team) {
boolean ally = allies.contains(team);
boolean enemy = enemies.contains(team);
//this team isn't even in the game, so target nothing!
if(!ally && !enemy) return emptyData;
return ally ? enemyData : allyData;
}
/**Returns whether or not these two teams are enemies.*/
public boolean areEnemies(Team team, Team other){
if(team == other) return false; //fast fail to be more efficient
boolean ally = allies.contains(team);
boolean ally2 = enemies.contains(other);
return ally == ally2;
}
public class TeamData {
public final Array<Tile> cores = new Array<>();
public final Team team;
public final boolean ally;
public TeamData(Team team, boolean ally) {
this.team = team;
this.ally = ally;
}
}
}
+18 -15
View File
@@ -1,10 +1,13 @@
package io.anuke.mindustry.game;
import com.badlogic.gdx.math.GridPoint2;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.content.blocks.DistributionBlocks;
import io.anuke.mindustry.content.blocks.ProductionBlocks;
import io.anuke.mindustry.content.blocks.WeaponBlocks;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.*;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.builders.button;
import io.anuke.ucore.scene.builders.label;
@@ -404,15 +407,15 @@ public class Tutorial{
canForward = false;
showBlock = true;
canPlace = true;
targetBlock = ProductionBlocks.pump;
//targetBlock = ProductionBlocks.pump;
blockPlaceX = 6;
blockPlaceY = -2;
}
void onSwitch(){
ui.<ImageButton>find("sectionbuttonproduction").fireClick();
state.inventory.addItem(Item.steel, 60);
state.inventory.addItem(Item.iron, 60);
state.inventory.addItem(Items.steel, 60);
state.inventory.addItem(Items.iron, 60);
}
},
conduitUse{
@@ -421,7 +424,7 @@ public class Tutorial{
canForward = false;
showBlock = true;
canPlace = true;
targetBlock = DistributionBlocks.conduit;
//targetBlock = DistributionBlocks.conduit;
blockPlaceX = 5;
blockPlaceY = -2;
blockRotation = 2;
@@ -438,8 +441,8 @@ public class Tutorial{
canForward = false;
showBlock = true;
canPlace = true;
targetBlock = DistributionBlocks.conduit;
blockPlaceX = 4;
//targetBlock = DistributionBlocks.conduit;
//blockPlaceX = 4;
blockPlaceY = -2;
blockRotation = 1;
}
@@ -454,7 +457,7 @@ public class Tutorial{
canForward = false;
showBlock = true;
canPlace = true;
targetBlock = DistributionBlocks.conduit;
//targetBlock = DistributionBlocks.conduit;
blockPlaceX = 4;
blockPlaceY = -1;
blockRotation = 1;
@@ -470,7 +473,7 @@ public class Tutorial{
canForward = false;
showBlock = true;
canPlace = true;
targetBlock = ProductionBlocks.combustiongenerator;
//targetBlock = ProductionBlocks.combustiongenerator;
blockPlaceX = 4;
blockPlaceY = 0;
}
@@ -478,8 +481,8 @@ public class Tutorial{
void onSwitch(){
//world.tile(blockPlaceX + world.getCore().x, blockPlaceY + world.getCore().y).setBlock(Blocks.air);
ui.<ImageButton>find("sectionbuttonpower").fireClick();
state.inventory.addItem(Item.steel, 60);
state.inventory.addItem(Item.iron, 60);
state.inventory.addItem(Items.steel, 60);
state.inventory.addItem(Items.iron, 60);
}
},
generatorExplain{
@@ -522,7 +525,7 @@ public class Tutorial{
canBack = false;
blockPlaceX = 1;
blockPlaceY = 4;
targetBlock = DefenseBlocks.repairturret;
//targetBlock = DefenseBlocks.repairturret;
}
void onSwitch(){
@@ -547,8 +550,8 @@ public class Tutorial{
}
void onSwitch(){
state.inventory.addItem(Item.stone, 40);
state.inventory.addItem(Item.iron, 40);
state.inventory.addItem(Items.stone, 40);
state.inventory.addItem(Items.iron, 40);
ui.<ImageButton>find("sectionbuttoncrafting").fireClick();
}
@@ -1,6 +1,7 @@
package io.anuke.mindustry.game;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.content.Weapons;
import io.anuke.mindustry.resource.Weapon;
public class UpgradeInventory {
@@ -20,6 +21,6 @@ public class UpgradeInventory {
public void reset(){
weapons.clear();
weapons.add(Weapon.blaster);
weapons.add(Weapons.blaster);
}
}