Cleanup continues

This commit is contained in:
Anuken
2020-02-04 18:00:32 -05:00
parent 012421afcb
commit a7b39e56bd
106 changed files with 2266 additions and 4543 deletions

View File

@@ -174,7 +174,7 @@ public class Vars implements Loadable{
public static NetServer netServer;
public static NetClient netClient;
public static Unitc player;
public static Playerc player;
@Override
public void loadAsync(){

View File

@@ -9,6 +9,7 @@ import mindustry.content.*;
import mindustry.entities.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.world.*;
import static mindustry.Vars.*;
@@ -34,7 +35,7 @@ public class WaveSpawner{
/** @return true if the player is near a ground spawn point. */
public boolean playerNear(){
return groundSpawns.contains(g -> Mathf.dst(g.x * tilesize, g.y * tilesize, player.x, player.y) < state.rules.dropZoneRadius && player.team() != state.rules.waveTeam);
return groundSpawns.contains(g -> Mathf.dst(g.x * tilesize, g.y * tilesize, player.x(), player.y()) < state.rules.dropZoneRadius && player.team() != state.rules.waveTeam);
}
public void spawnEnemies(){
@@ -48,9 +49,10 @@ public class WaveSpawner{
eachFlyerSpawn((spawnX, spawnY) -> {
for(int i = 0; i < spawned; i++){
BaseUnit unit = group.createUnit(state.rules.waveTeam);
unit.set(spawnX + Mathf.range(spread), spawnY + Mathf.range(spread));
unit.add();
//TODO
//Unitc unit = group.createUnit(state.rules.waveTeam);
//unit.set(spawnX + Mathf.range(spread), spawnY + Mathf.range(spread));
//unit.add();
}
});
}else{
@@ -61,10 +63,11 @@ public class WaveSpawner{
for(int i = 0; i < spawned; i++){
Tmp.v1.rnd(spread);
BaseUnit unit = group.createUnit(state.rules.waveTeam);
unit.set(spawnX + Tmp.v1.x, spawnY + Tmp.v1.y);
//TODO
//Unitc unit = group.createUnit(state.rules.waveTeam);
//unit.set(spawnX + Tmp.v1.x, spawnY + Tmp.v1.y);
Time.run(Math.min(i * 5, 60 * 2), () -> spawnEffect(unit));
//Time.run(Math.min(i * 5, 60 * 2), () -> spawnEffect(unit));
}
});
}
@@ -88,8 +91,8 @@ public class WaveSpawner{
if(state.rules.attackMode && state.teams.isActive(state.rules.waveTeam) && !state.teams.playerCores().isEmpty()){
Tilec firstCore = state.teams.playerCores().first();
for(Tilec core : state.rules.waveTeam.cores()){
Tmp.v1.set(firstCore).sub(core.x, core.y).limit(coreMargin + core.block.size*tilesize);
cons.accept(core.x + Tmp.v1.x, core.y + Tmp.v1.y, false);
Tmp.v1.set(firstCore).sub(core).limit(coreMargin + core.block().size*tilesize);
cons.accept(core.x() + Tmp.v1.x, core.y() + Tmp.v1.y, false);
}
}
}
@@ -104,7 +107,7 @@ public class WaveSpawner{
if(state.rules.attackMode && state.teams.isActive(state.rules.waveTeam)){
for(Tilec core : state.teams.get(state.rules.waveTeam).cores){
cons.get(core.x, core.y);
cons.get(core.x(), core.y());
}
}
}
@@ -136,8 +139,8 @@ public class WaveSpawner{
flySpawns.add(fspawn);
}
private void spawnEffect(BaseUnit unit){
Fx.unitSpawn.at(unit.x, unit.y, 0f, unit);
private void spawnEffect(Unitc unit){
Fx.unitSpawn.at(unit.x(), unit.y(), 0f, unit);
Time.run(30f, () -> {
unit.add();
Fx.spawn.at(unit);

View File

@@ -1281,7 +1281,6 @@ public class Blocks implements ContentList{
health = 1100;
itemCapacity = 4000;
size = 3;
mech = Mechs.vanguard;
}};
coreFoundation = new CoreBlock("core-foundation"){{
@@ -1290,7 +1289,6 @@ public class Blocks implements ContentList{
health = 2000;
itemCapacity = 9000;
size = 4;
mech = Mechs.vanguard;
}};
coreNucleus = new CoreBlock("core-nucleus"){{
@@ -1299,7 +1297,6 @@ public class Blocks implements ContentList{
health = 4000;
itemCapacity = 13000;
size = 5;
mech = Mechs.vanguard;
}};
vault = new Vault("vault"){{
@@ -1548,7 +1545,7 @@ public class Blocks implements ContentList{
@Override
public void init(Bulletc b){
for(int i = 0; i < rays; i++){
Damage.collideLine(b, b.team(), hitEffect, b.x, b.y, b.rot(), rayLength - Math.abs(i - (rays / 2)) * 20f);
Damage.collideLine(b, b.team(), hitEffect, b.x(), b.y(), b.rotation(), rayLength - Math.abs(i - (rays / 2)) * 20f);
}
}
@@ -1558,13 +1555,13 @@ public class Blocks implements ContentList{
Draw.color(Color.white, Pal.lancerLaser, b.fin());
//Draw.alpha(b.fout());
for(int i = 0; i < 7; i++){
Tmp.v1.trns(b.rot(), i * 8f);
Tmp.v1.trns(b.rotation(), i * 8f);
float sl = Mathf.clamp(b.fout() - 0.5f) * (80f - i * 10);
Drawf.tri(b.x + Tmp.v1.x, b.y + Tmp.v1.y, 4f, sl, b.rot() + 90);
Drawf.tri(b.x + Tmp.v1.x, b.y + Tmp.v1.y, 4f, sl, b.rot() - 90);
Drawf.tri(b.x() + Tmp.v1.x, b.y() + Tmp.v1.y, 4f, sl, b.rotation() + 90);
Drawf.tri(b.x() + Tmp.v1.x, b.y() + Tmp.v1.y, 4f, sl, b.rotation() - 90);
}
Drawf.tri(b.x, b.y, 20f * b.fout(), (rayLength + 50), b.rot());
Drawf.tri(b.x, b.y, 20f * b.fout(), 10f, b.rot() + 180f);
Drawf.tri(b.x(), b.y(), 20f * b.fout(), (rayLength + 50), b.rotation());
Drawf.tri(b.x(), b.y(), 20f * b.fout(), 10f, b.rotation() + 180f);
Draw.reset();
}
});
@@ -1783,56 +1780,56 @@ public class Blocks implements ContentList{
dartPad = new MechPad("dart-ship-pad"){{
requirements(Category.upgrade, ItemStack.with(Items.lead, 100, Items.graphite, 50, Items.copper, 75));
mech = Mechs.dart;
mech = UnitTypes.dart;
size = 2;
consumes.power(0.5f);
}};
alphaPad = new MechPad("alpha-mech-pad"){{
requirements(Category.upgrade, ItemStack.with(Items.lead, 100, Items.graphite, 50, Items.copper, 75));
mech = Mechs.alpha;
mech = UnitTypes.alpha;
size = 2;
consumes.power(0.5f);
}};
deltaPad = new MechPad("delta-mech-pad"){{
requirements(Category.upgrade, ItemStack.with(Items.lead, 175, Items.titanium, 175, Items.copper, 200, Items.silicon, 225, Items.thorium, 150));
mech = Mechs.delta;
mech = UnitTypes.delta;
size = 2;
consumes.power(0.7f);
}};
tauPad = new MechPad("tau-mech-pad"){{
requirements(Category.upgrade, ItemStack.with(Items.lead, 125, Items.titanium, 125, Items.copper, 125, Items.silicon, 125));
mech = Mechs.tau;
mech = UnitTypes.tau;
size = 2;
consumes.power(1f);
}};
omegaPad = new MechPad("omega-mech-pad"){{
requirements(Category.upgrade, ItemStack.with(Items.lead, 225, Items.graphite, 275, Items.silicon, 325, Items.thorium, 300, Items.surgealloy, 120));
mech = Mechs.omega;
mech = UnitTypes.omega;
size = 3;
consumes.power(1.2f);
}};
javelinPad = new MechPad("javelin-ship-pad"){{
requirements(Category.upgrade, ItemStack.with(Items.lead, 175, Items.silicon, 225, Items.titanium, 250, Items.plastanium, 200, Items.phasefabric, 100));
mech = Mechs.javelin;
mech = UnitTypes.javelin;
size = 2;
consumes.power(0.8f);
}};
tridentPad = new MechPad("trident-ship-pad"){{
requirements(Category.upgrade, ItemStack.with(Items.lead, 125, Items.copper, 125, Items.silicon, 125, Items.titanium, 150, Items.plastanium, 100));
mech = Mechs.trident;
mech = UnitTypes.trident;
size = 2;
consumes.power(1f);
}};
glaivePad = new MechPad("glaive-ship-pad"){{
requirements(Category.upgrade, ItemStack.with(Items.lead, 225, Items.silicon, 325, Items.titanium, 350, Items.plastanium, 300, Items.surgealloy, 100));
mech = Mechs.glaive;
mech = UnitTypes.glaive;
size = 3;
consumes.power(1.2f);
}};

View File

@@ -4,11 +4,10 @@ import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.*;
import mindustry.ctype.ContentList;
import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.entities.bullet.*;
import mindustry.entities.effect.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.*;
@@ -412,31 +411,31 @@ public class Bullets implements ContentList{
@Override
public void init(Bulletc b){
b.velocity().setLength(0.6f + Mathf.random(2f));
b.vel().setLength(0.6f + Mathf.random(2f));
}
@Override
public void draw(Bulletc b){
Draw.color(Pal.lightFlame, Pal.darkFlame, Color.gray, b.fin());
Fill.circle(b.x, b.y, 3f * b.fout());
Fill.circle(b.x(), b.y(), 3f * b.fout());
Draw.reset();
}
@Override
public void update(Bulletc b){
if(Mathf.chance(0.04 * Time.delta())){
Tile tile = world.tileWorld(b.x, b.y);
Tile tile = world.tileWorld(b.x(), b.y());
if(tile != null){
Fire.create(tile);
}
}
if(Mathf.chance(0.1 * Time.delta())){
Fx.fireballsmoke.at(b.x, b.y);
Fx.fireballsmoke.at(b.x(), b.y());
}
if(Mathf.chance(0.1 * Time.delta())){
Fx.ballfire.at(b.x, b.y);
Fx.ballfire.at(b.x(), b.y());
}
}
};
@@ -512,15 +511,15 @@ public class Bullets implements ContentList{
@Override
public void update(Bulletc b){
if(b.timer.get(1, 5f)){
Damage.collideLine(b, b.team(), hitEffect, b.x, b.y, b.rot(), length, true);
if(b.timer(1, 5f)){
Damage.collideLine(b, b.team(), hitEffect, b.x(), b.y(), b.rotation(), length, true);
}
Effects.shake(1f, 1f, b.x, b.y);
Effects.shake(1f, 1f, b.x(), b.y());
}
@Override
public void hit(Bulletc b, float hitx, float hity){
hitEffect.at(colors[2], hitx, hity);
hitEffect.at(hitx, hity, colors[2]);
if(Mathf.chance(0.4)){
Fire.create(world.tileWorld(hitx + Mathf.range(5f), hity + Mathf.range(5f)));
}
@@ -530,13 +529,13 @@ public class Bullets implements ContentList{
public void draw(Bulletc b){
float baseLen = (length) * b.fout();
Lines.lineAngle(b.x, b.y, b.rot(), baseLen);
Lines.lineAngle(b.x(), b.y(), b.rotation(), baseLen);
for(int s = 0; s < colors.length; s++){
Draw.color(tmpColor.set(colors[s]).mul(1f + Mathf.absin(Time.time(), 1f, 0.1f)));
for(int i = 0; i < tscales.length; i++){
Tmp.v1.trns(b.rot() + 180f, (lenscales[i] - 1f) * 35f);
Tmp.v1.trns(b.rotation() + 180f, (lenscales[i] - 1f) * 35f);
Lines.stroke((9f + Mathf.absin(Time.time(), 0.8f, 1.5f)) * b.fout() * strokes[s] * tscales[i]);
Lines.lineAngle(b.x + Tmp.v1.x, b.y + Tmp.v1.y, b.rot(), baseLen * lenscales[i], CapStyle.none);
Lines.lineAngle(b.x() + Tmp.v1.x, b.y() + Tmp.v1.y, b.rotation(), baseLen * lenscales[i], CapStyle.none);
}
}
Draw.reset();
@@ -587,7 +586,8 @@ public class Bullets implements ContentList{
@Override
public void init(Bulletc b){
Lightning.create(b.team(), Pal.lancerLaser, damage * (b.getOwner() instanceof Player ? state.rules.playerDamageMultiplier : 1f), b.x, b.y, b.rot(), 30);
//TODO owners are never players...
Lightning.create(b.team(), Pal.lancerLaser, damage * (b.owner() instanceof Playerc ? state.rules.playerDamageMultiplier : 1f), b.x(), b.y(), b.rotation(), 30);
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -1,461 +0,0 @@
package mindustry.content;
import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.*;
import mindustry.*;
import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.entities.bullet.*;
import mindustry.entities.effect.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
import static mindustry.Vars.indexer;
public class Mechs implements ContentList{
public static UnitDef vanguard, alpha, delta, tau, omega, dart, javelin, trident, glaive;
public static UnitDef starter;
@Override
public void load(){
vanguard = new UnitDef("vanguard-ship"){
float healRange = 60f;
float healReload = 200f;
float healPercent = 10f;
{
flying = true;
drillTier = 1;
minePower = 4f;
speed = 0.49f;
drag = 0.09f;
health = 200f;
weaponOffsetX = -1;
engineSize = 2.3f;
weaponOffsetY = -1;
engineColor = Pal.lightTrail;
cellTrnsY = 1f;
buildPower = 1.2f;
weapon = new Weapon("vanguard-blaster"){{
length = 1.5f;
reload = 30f;
alternate = true;
inaccuracy = 6f;
velocityRnd = 0.1f;
ejectEffect = Fx.none;
bullet = new HealBulletType(){{
healPercent = 3f;
backColor = engineColor;
homingPower = 20f;
bulletHeight = 4f;
bulletWidth = 1.5f;
damage = 3f;
speed = 4f;
lifetime = 40f;
shootEffect = Fx.shootHealYellow;
smokeEffect = hitEffect = despawnEffect = Fx.hitYellowLaser;
}};
}};
}
@Override
public boolean alwaysUnlocked(){
return true;
}
@Override
public void update(Player player){
if(player.timer.get(Player.timerAbility, healReload)){
if(indexer.eachBlock(player, healRange, other -> other.entity.damaged(), other -> {
other.entity.healBy(other.entity.maxHealth() * healPercent / 100f);
Fx.healBlockFull.at(other.drawx(), other.drawy(), other.block().size, Pal.heal);
})){
Fx.healWave.at(player);
}
}
}
};
alpha = new UnitDef("alpha-mech", false){
{
drillTier = -1;
speed = 0.5f;
boostSpeed = 0.95f;
itemCapacity = 15;
mass = 0.9f;
health = 150f;
buildPower = 0.9f;
weaponOffsetX = 1;
weaponOffsetY = -1;
engineColor = Pal.heal;
weapon = new Weapon("shockgun"){{
shake = 2f;
length = 0.5f;
reload = 70f;
alternate = true;
recoil = 4f;
width = 5f;
shootSound = Sounds.laser;
bullet = new LaserBulletType(){{
damage = 20f;
recoil = 1f;
sideAngle = 45f;
sideWidth = 1f;
sideLength = 70f;
colors = new Color[]{Pal.heal.cpy().a(0.4f), Pal.heal, Color.white};
}};
}};
}
@Override
public void update(Player player){
player.healBy(Time.delta() * 0.09f);
}
};
delta = new UnitDef("delta-mech", false){
{
drillPower = 1;
mineSpeed = 1.5f;
mass = 1.2f;
speed = 0.5f;
itemCapacity = 40;
boostSpeed = 0.95f;
buildPower = 1.2f;
engineColor = Color.valueOf("ffd37f");
health = 250f;
weaponOffsetX = 4f;
weapon = new Weapon("flamethrower"){{
length = 1.5f;
reload = 30f;
width = 4f;
alternate = true;
shots = 3;
inaccuracy = 40f;
shootSound = Sounds.spark;
bullet = new LightningBulletType(){{
damage = 5;
lightningLength = 10;
lightningColor = Pal.lightFlame;
}};
}};
}
};
tau = new UnitDef("tau-mech", false){
float healRange = 60f;
float healAmount = 10f;
float healReload = 160f;
boolean wasHealed;
{
drillPower = 4;
mineSpeed = 3f;
itemCapacity = 70;
weaponOffsetY = -1;
weaponOffsetX = 1;
mass = 1.75f;
speed = 0.44f;
drag = 0.35f;
boostSpeed = 0.8f;
canHeal = true;
health = 200f;
buildPower = 1.6f;
engineColor = Pal.heal;
weapon = new Weapon("heal-blaster"){{
length = 1.5f;
reload = 24f;
alternate = false;
ejectEffect = Fx.none;
recoil = 2f;
bullet = Bullets.healBullet;
shootSound = Sounds.pew;
}};
}
@Override
public void update(Player player){
if(player.timer.get(Player.timerAbility, healReload)){
wasHealed = false;
Units.nearby(player.team(), player.x, player.y, healRange, unit -> {
if(unit.health < unit.maxHealth()){
Fx.heal.at(unit);
wasHealed = true;
}
unit.healBy(healAmount);
});
if(wasHealed){
Fx.healWave.at(player);
}
}
}
};
omega = new UnitDef("omega-mech", false){
protected TextureRegion armorRegion;
{
drillPower = 2;
mineSpeed = 1.5f;
itemCapacity = 80;
speed = 0.36f;
boostSpeed = 0.6f;
mass = 4f;
shake = 4f;
weaponOffsetX = 1;
weaponOffsetY = 0;
engineColor = Color.valueOf("feb380");
health = 350f;
buildPower = 1.5f;
weapon = new Weapon("swarmer"){{
length = 1.5f;
recoil = 4f;
reload = 38f;
shots = 4;
spacing = 8f;
inaccuracy = 8f;
alternate = true;
ejectEffect = Fx.none;
shake = 3f;
bullet = Bullets.missileSwarm;
shootSound = Sounds.shootBig;
}};
}
@Override
public float getRotationAlpha(Player player){
return 0.6f - player.shootHeat * 0.3f;
}
@Override
public float spreadX(Player player){
return player.shootHeat * 2f;
}
@Override
public void load(){
super.load();
armorRegion = Core.atlas.find(name + "-armor");
}
@Override
public void update(Player player){
float scl = 1f - player.shootHeat / 2f*Time.delta();
player.velocity().scl(scl);
}
@Override
public float getExtraArmor(Player player){
return player.shootHeat * 30f;
}
@Override
public void draw(Player player){
if(player.shootHeat <= 0.01f) return;
Shaders.build.progress = player.shootHeat;
Shaders.build.region = armorRegion;
Shaders.build.time = Time.time() / 10f;
Shaders.build.color.set(Pal.accent).a = player.shootHeat;
Draw.shader(Shaders.build);
Draw.rect(armorRegion, player.x, player.y, player.rotation);
Draw.shader();
}
};
dart = new UnitDef("dart-ship"){
float effectRange = 60f;
float effectReload = 60f * 5;
float effectDuration = 60f * 10f;
{
flying = true;
drillPower = 1;
mineSpeed = 2f;
speed = 0.5f;
drag = 0.09f;
health = 200f;
weaponOffsetX = -1;
weaponOffsetY = -1;
engineColor = Pal.lightTrail;
cellTrnsY = 1f;
buildPower = 1.1f;
weapon = new Weapon("blaster"){{
length = 1.5f;
reload = 15f;
alternate = true;
ejectEffect = Fx.shellEjectSmall;
bullet = Bullets.standardCopper;
}};
}
@Override
public void update(Player player){
super.update(player);
if(player.timer.get(Player.timerAbility, effectReload)){
Units.nearby(player.team(), player.x, player.y, effectRange, unit -> {
//unit.applyEffect(StatusEffects.overdrive, effectDuration);
});
indexer.eachBlock(player, effectRange, other -> other.entity.damaged(), other -> {
other.entity.applyBoost(1.5f, effectDuration);
Fx.healBlockFull.at(other.drawx(), other.drawy(), other.block().size, Pal.heal);
});
Fx.overdriveWave.at(player);
}
}
};
javelin = new UnitDef("javelin-ship"){
float minV = 3.6f;
float maxV = 6f;
TextureRegion shield;
{
flying = true;
drillPower = -1;
speed = 0.11f;
drag = 0.01f;
mass = 2f;
health = 170f;
engineColor = Color.valueOf("d3ddff");
cellTrnsY = 1f;
weapon = new Weapon("missiles"){{
length = 1.5f;
reload = 70f;
shots = 4;
inaccuracy = 2f;
alternate = true;
ejectEffect = Fx.none;
velocityRnd = 0.2f;
spacing = 1f;
bullet = Bullets.missileJavelin;
shootSound = Sounds.missile;
}};
}
@Override
public void load(){
super.load();
shield = Core.atlas.find(name + "-shield");
}
@Override
public float getRotationAlpha(Player player){
return 0.5f;
}
@Override
public void update(Player player){
float scl = scld(player);
if(Mathf.chance(Time.delta() * (0.15 * scl))){
Fx.hitLancer.at(Pal.lancerLaser, player.x, player.y);
Lightning.create(player.team(), Pal.lancerLaser, 10f * Vars.state.rules.playerDamageMultiplier,
player.x + player.velocity().x, player.y + player.velocity().y, player.rotation, 14);
}
}
@Override
public void draw(Player player){
float scl = scld(player);
if(scl < 0.01f) return;
Draw.color(Pal.lancerLaser);
Draw.alpha(scl / 2f);
Draw.blend(Blending.additive);
Draw.rect(shield, player.x + Mathf.range(scl / 2f), player.y + Mathf.range(scl / 2f), player.rotation - 90);
Draw.blend();
}
float scld(Player player){
return Mathf.clamp((player.velocity().len() - minV) / (maxV - minV));
}
};
trident = new UnitDef("trident-ship"){
{
flying = true;
drillPower = 2;
speed = 0.15f;
drag = 0.034f;
mass = 2.5f;
turnCursor = false;
health = 250f;
itemCapacity = 30;
engineColor = Color.valueOf("84f491");
cellTrnsY = 1f;
buildPower = 2.5f;
weapon = new Weapon("bomber"){{
length = 0f;
width = 2f;
reload = 25f;
shots = 2;
shotDelay = 1f;
shots = 8;
alternate = true;
ejectEffect = Fx.none;
velocityRnd = 1f;
inaccuracy = 20f;
ignoreRotation = true;
bullet = new BombBulletType(16f, 25f, "shell"){{
bulletWidth = 10f;
bulletHeight = 14f;
hitEffect = Fx.flakExplosion;
shootEffect = Fx.none;
smokeEffect = Fx.none;
shootSound = Sounds.artillery;
}};
}};
}
@Override
public boolean canShoot(Player player){
return player.velocity().len() > 1.2f;
}
};
glaive = new UnitDef("glaive-ship"){
{
flying = true;
drillPower = 4;
mineSpeed = 1.3f;
speed = 0.32f;
drag = 0.06f;
mass = 3f;
health = 240f;
itemCapacity = 60;
engineColor = Color.valueOf("feb380");
cellTrnsY = 1f;
buildPower = 1.2f;
weapon = new Weapon("bomber"){{
length = 1.5f;
reload = 13f;
alternate = true;
ejectEffect = Fx.shellEjectSmall;
bullet = Bullets.standardGlaive;
shootSound = Sounds.shootSnap;
}};
}
};
starter = vanguard;
}
}

View File

@@ -23,7 +23,7 @@ public class StatusEffects implements ContentList{
opposite(wet,freezing);
trans(tarred, ((unit, time, newTime, result) -> {
unit.damage(1f);
Fx.burning.at(unit.x + Mathf.range(unit.getSize() / 2f), unit.y + Mathf.range(unit.getSize() / 2f));
Fx.burning.at(unit.x() + Mathf.range(unit.bounds() / 2f), unit.y() + Mathf.range(unit.bounds() / 2f));
result.set(this, Math.min(time + newTime, 300f));
}));
});

View File

@@ -1,10 +1,6 @@
package mindustry.content;
import arc.struct.*;
import mindustry.ctype.*;
import mindustry.entities.bullet.*;
import mindustry.entities.type.base.*;
import mindustry.gen.*;
import mindustry.type.*;
public class UnitTypes implements ContentList{
@@ -13,8 +9,12 @@ public class UnitTypes implements ContentList{
wraith, ghoul, revenant, lich, reaper,
dagger, crawler, titan, fortress, eruptor, chaosArray, eradicator;
public static UnitDef vanguard, alpha, delta, tau, omega, dart, javelin, trident, glaive;
public static UnitDef starter;
@Override
public void load(){
/*
draug = new UnitDef("draug", MinerDrone::new){{
flying = true;
drag = 0.01f;
@@ -372,5 +372,440 @@ public class UnitTypes implements ContentList{
shootSound = Sounds.shootBig;
}};
}};
/*
vanguard = new UnitDef("vanguard-ship"){
float healRange = 60f;
float healReload = 200f;
float healPercent = 10f;
{
flying = true;
drillTier = 1;
minePower = 4f;
speed = 0.49f;
drag = 0.09f;
health = 200f;
weaponOffsetX = -1;
engineSize = 2.3f;
weaponOffsetY = -1;
engineColor = Pal.lightTrail;
cellTrnsY = 1f;
buildPower = 1.2f;
weapon = new Weapon("vanguard-blaster"){{
length = 1.5f;
reload = 30f;
alternate = true;
inaccuracy = 6f;
velocityRnd = 0.1f;
ejectEffect = Fx.none;
bullet = new HealBulletType(){{
healPercent = 3f;
backColor = engineColor;
homingPower = 20f;
bulletHeight = 4f;
bulletWidth = 1.5f;
damage = 3f;
speed = 4f;
lifetime = 40f;
shootEffect = Fx.shootHealYellow;
smokeEffect = hitEffect = despawnEffect = Fx.hitYellowLaser;
}};
}};
}
@Override
public boolean alwaysUnlocked(){
return true;
}
@Override
public void update(Playerc player){
if(player.timer.get(Playerc.timerAbility, healReload)){
if(indexer.eachBlock(player, healRange, other -> other.entity.damaged(), other -> {
other.entity.healBy(other.entity.maxHealth() * healPercent / 100f);
Fx.healBlockFull.at(other.drawx(), other.drawy(), other.block().size, Pal.heal);
})){
Fx.healWave.at(player);
}
}
}
};
alpha = new UnitDef("alpha-mech", false){
{
drillTier = -1;
speed = 0.5f;
boostSpeed = 0.95f;
itemCapacity = 15;
mass = 0.9f;
health = 150f;
buildPower = 0.9f;
weaponOffsetX = 1;
weaponOffsetY = -1;
engineColor = Pal.heal;
weapon = new Weapon("shockgun"){{
shake = 2f;
length = 0.5f;
reload = 70f;
alternate = true;
recoil = 4f;
width = 5f;
shootSound = Sounds.laser;
bullet = new LaserBulletType(){{
damage = 20f;
recoil = 1f;
sideAngle = 45f;
sideWidth = 1f;
sideLength = 70f;
colors = new Color[]{Pal.heal.cpy().a(0.4f), Pal.heal, Color.white};
}};
}};
}
@Override
public void update(Playerc player){
player.healBy(Time.delta() * 0.09f);
}
};
delta = new UnitDef("delta-mech", false){
{
drillPower = 1;
mineSpeed = 1.5f;
mass = 1.2f;
speed = 0.5f;
itemCapacity = 40;
boostSpeed = 0.95f;
buildPower = 1.2f;
engineColor = Color.valueOf("ffd37f");
health = 250f;
weaponOffsetX = 4f;
weapon = new Weapon("flamethrower"){{
length = 1.5f;
reload = 30f;
width = 4f;
alternate = true;
shots = 3;
inaccuracy = 40f;
shootSound = Sounds.spark;
bullet = new LightningBulletType(){{
damage = 5;
lightningLength = 10;
lightningColor = Pal.lightFlame;
}};
}};
}
};
tau = new UnitDef("tau-mech", false){
float healRange = 60f;
float healAmount = 10f;
float healReload = 160f;
boolean wasHealed;
{
drillPower = 4;
mineSpeed = 3f;
itemCapacity = 70;
weaponOffsetY = -1;
weaponOffsetX = 1;
mass = 1.75f;
speed = 0.44f;
drag = 0.35f;
boostSpeed = 0.8f;
canHeal = true;
health = 200f;
buildPower = 1.6f;
engineColor = Pal.heal;
weapon = new Weapon("heal-blaster"){{
length = 1.5f;
reload = 24f;
alternate = false;
ejectEffect = Fx.none;
recoil = 2f;
bullet = Bullets.healBullet;
shootSound = Sounds.pew;
}};
}
@Override
public void update(Playerc player){
if(player.timer.get(Playerc.timerAbility, healReload)){
wasHealed = false;
Units.nearby(player.team(), player.x, player.y, healRange, unit -> {
if(unit.health < unit.maxHealth()){
Fx.heal.at(unit);
wasHealed = true;
}
unit.healBy(healAmount);
});
if(wasHealed){
Fx.healWave.at(player);
}
}
}
};
omega = new UnitDef("omega-mech", false){
protected TextureRegion armorRegion;
{
drillPower = 2;
mineSpeed = 1.5f;
itemCapacity = 80;
speed = 0.36f;
boostSpeed = 0.6f;
mass = 4f;
shake = 4f;
weaponOffsetX = 1;
weaponOffsetY = 0;
engineColor = Color.valueOf("feb380");
health = 350f;
buildPower = 1.5f;
weapon = new Weapon("swarmer"){{
length = 1.5f;
recoil = 4f;
reload = 38f;
shots = 4;
spacing = 8f;
inaccuracy = 8f;
alternate = true;
ejectEffect = Fx.none;
shake = 3f;
bullet = Bullets.missileSwarm;
shootSound = Sounds.shootBig;
}};
}
@Override
public float getRotationAlpha(Playerc player){
return 0.6f - player.shootHeat * 0.3f;
}
@Override
public float spreadX(Playerc player){
return player.shootHeat * 2f;
}
@Override
public void load(){
super.load();
armorRegion = Core.atlas.find(name + "-armor");
}
@Override
public void update(Playerc player){
float scl = 1f - player.shootHeat / 2f*Time.delta();
player.vel().scl(scl);
}
@Override
public float getExtraArmor(Playerc player){
return player.shootHeat * 30f;
}
@Override
public void draw(Playerc player){
if(player.shootHeat <= 0.01f) return;
Shaders.build.progress = player.shootHeat;
Shaders.build.region = armorRegion;
Shaders.build.time = Time.time() / 10f;
Shaders.build.color.set(Pal.accent).a = player.shootHeat;
Draw.shader(Shaders.build);
Draw.rect(armorRegion, player.x, player.y, player.rotation);
Draw.shader();
}
};
dart = new UnitDef("dart-ship"){
float effectRange = 60f;
float effectReload = 60f * 5;
float effectDuration = 60f * 10f;
{
flying = true;
drillPower = 1;
mineSpeed = 2f;
speed = 0.5f;
drag = 0.09f;
health = 200f;
weaponOffsetX = -1;
weaponOffsetY = -1;
engineColor = Pal.lightTrail;
cellTrnsY = 1f;
buildPower = 1.1f;
weapon = new Weapon("blaster"){{
length = 1.5f;
reload = 15f;
alternate = true;
ejectEffect = Fx.shellEjectSmall;
bullet = Bullets.standardCopper;
}};
}
@Override
public void update(Playerc player){
super.update(player);
if(player.timer.get(Playerc.timerAbility, effectReload)){
Units.nearby(player.team(), player.x, player.y, effectRange, unit -> {
//unit.applyEffect(StatusEffects.overdrive, effectDuration);
});
indexer.eachBlock(player, effectRange, other -> other.entity.damaged(), other -> {
other.entity.applyBoost(1.5f, effectDuration);
Fx.healBlockFull.at(other.drawx(), other.drawy(), other.block().size, Pal.heal);
});
Fx.overdriveWave.at(player);
}
}
};
javelin = new UnitDef("javelin-ship"){
float minV = 3.6f;
float maxV = 6f;
TextureRegion shield;
{
flying = true;
drillPower = -1;
speed = 0.11f;
drag = 0.01f;
mass = 2f;
health = 170f;
engineColor = Color.valueOf("d3ddff");
cellTrnsY = 1f;
weapon = new Weapon("missiles"){{
length = 1.5f;
reload = 70f;
shots = 4;
inaccuracy = 2f;
alternate = true;
ejectEffect = Fx.none;
velocityRnd = 0.2f;
spacing = 1f;
bullet = Bullets.missileJavelin;
shootSound = Sounds.missile;
}};
}
@Override
public void load(){
super.load();
shield = Core.atlas.find(name + "-shield");
}
@Override
public float getRotationAlpha(Playerc player){
return 0.5f;
}
@Override
public void update(Playerc player){
float scl = scld(player);
if(Mathf.chance(Time.delta() * (0.15 * scl))){
Fx.hitLancer.at(Pal.lancerLaser, player.x, player.y);
Lightning.create(player.team(), Pal.lancerLaser, 10f * Vars.state.rules.playerDamageMultiplier,
player.x + player.vel().x, player.y + player.vel().y, player.rotation, 14);
}
}
@Override
public void draw(Playerc player){
float scl = scld(player);
if(scl < 0.01f) return;
Draw.color(Pal.lancerLaser);
Draw.alpha(scl / 2f);
Draw.blend(Blending.additive);
Draw.rect(shield, player.x + Mathf.range(scl / 2f), player.y + Mathf.range(scl / 2f), player.rotation - 90);
Draw.blend();
}
float scld(Playerc player){
return Mathf.clamp((player.vel().len() - minV) / (maxV - minV));
}
};
trident = new UnitDef("trident-ship"){
{
flying = true;
drillPower = 2;
speed = 0.15f;
drag = 0.034f;
mass = 2.5f;
turnCursor = false;
health = 250f;
itemCapacity = 30;
engineColor = Color.valueOf("84f491");
cellTrnsY = 1f;
buildPower = 2.5f;
weapon = new Weapon("bomber"){{
length = 0f;
width = 2f;
reload = 25f;
shots = 2;
shotDelay = 1f;
shots = 8;
alternate = true;
ejectEffect = Fx.none;
velocityRnd = 1f;
inaccuracy = 20f;
ignoreRotation = true;
bullet = new BombBulletType(16f, 25f, "shell"){{
bulletWidth = 10f;
bulletHeight = 14f;
hitEffect = Fx.flakExplosion;
shootEffect = Fx.none;
smokeEffect = Fx.none;
shootSound = Sounds.artillery;
}};
}};
}
@Override
public boolean canShoot(Playerc player){
return player.vel().len() > 1.2f;
}
};
glaive = new UnitDef("glaive-ship"){
{
flying = true;
drillPower = 4;
mineSpeed = 1.3f;
speed = 0.32f;
drag = 0.06f;
mass = 3f;
health = 240f;
itemCapacity = 60;
engineColor = Color.valueOf("feb380");
cellTrnsY = 1f;
buildPower = 1.2f;
weapon = new Weapon("bomber"){{
length = 1.5f;
reload = 13f;
alternate = true;
ejectEffect = Fx.shellEjectSmall;
bullet = Bullets.standardGlaive;
shootSound = Sounds.shootSnap;
}};
}
};
starter = vanguard;*/
}
}

View File

@@ -263,7 +263,7 @@ public class ContentLoader{
return getBy(ContentType.zone);
}
public Array<UnitType> units(){
public Array<UnitDef> units(){
return getBy(ContentType.unit);
}
}

View File

@@ -13,7 +13,7 @@ import arc.util.*;
import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
@@ -63,7 +63,7 @@ public class Control implements ApplicationListener, Loadable{
});
Events.on(PlayEvent.class, event -> {
player.team(netServer.assignTeam(player, playerGroup.all()));
player.team(netServer.assignTeam(player, Groups.player.all()));
player.dead(true);
player.add();
@@ -204,10 +204,10 @@ public class Control implements ApplicationListener, Loadable{
}
void createPlayer(){
player = new Player();
player = new Playerc();
player.name = Core.settings.getString("name");
player.color.set(Core.settings.getInt("color-0"));
player.isLocal = true;
player.isLocal() = true;
player.isMobile = mobile;
if(mobile){
@@ -304,14 +304,14 @@ public class Control implements ApplicationListener, Loadable{
}
}
Geometry.circle(coreb.x, coreb.y, 10, (cx, cy) -> {
Geometry.circle(coreb.x(), coreb.y(), 10, (cx, cy) -> {
Tile tile = world.ltile(cx, cy);
if(tile != null && tile.getTeam() == state.rules.defaultTeam && !(tile.block() instanceof CoreBlock)){
tile.remove();
}
});
Geometry.circle(coreb.x, coreb.y, 5, (cx, cy) -> world.tile(cx, cy).clearOverlay());
Geometry.circle(coreb.x(), coreb.y(), 5, (cx, cy) -> world.tile(cx, cy).clearOverlay());
world.endMapLoad();

View File

@@ -1,9 +1,9 @@
package mindustry.core;
import arc.*;
import mindustry.entities.type.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.gen.*;
import static mindustry.Vars.*;
@@ -25,8 +25,8 @@ public class GameState{
/** Current game state. */
private State state = State.menu;
public BaseUnit boss(){
return unitGroup.find(u -> u.isBoss() && u.getTeam() == rules.waveTeam);
public Unitc boss(){
return Groups.unit.find(u -> u.isBoss() && u.team() == rules.waveTeam);
}
public void set(State astate){

View File

@@ -6,7 +6,6 @@ import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.ctype.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
@@ -79,7 +78,7 @@ public class Logic implements ApplicationListener{
while(it.hasNext()){
BrokenBlock b = it.next();
Block block = content.block(b.block);
if(event.tile.block().bounds(event.tile.x, event.tile.y, Tmp.r1).overlaps(block.bounds(b.x, b.y, Tmp.r2))){
if(event.tile.block().bounds(event.tile.x, event.tile.y, Tmp.r1).overlaps(block.bounds(b.x(), b.y(), Tmp.r2))){
it.remove();
}
}
@@ -206,7 +205,7 @@ public class Logic implements ApplicationListener{
if(!state.is(State.menu)){
if(!net.client()){
//TODO
//state.enemies = unitGroup.count(b -> b.getTeam() == state.rules.waveTeam && b.countsAsEnemy());
//state.enemies = Groups.unit.count(b -> b.getTeam() == state.rules.waveTeam && b.countsAsEnemy());
}
if(!state.isPaused()){
@@ -230,7 +229,7 @@ public class Logic implements ApplicationListener{
}
if(!state.isEditor()){
unitGroup.update();
Groups.unit.update();
puddleGroup.update();
shieldGroup.update();
bulletGroup.update();
@@ -238,12 +237,12 @@ public class Logic implements ApplicationListener{
fireGroup.update();
weatherGroup.update();
}else{
unitGroup.updateEvents();
collisions.updatePhysics(unitGroup);
Groups.unit.updateEvents();
collisions.updatePhysics(Groups.unit);
}
playerGroup.update();
Groups.player.update();
//effect group only contains item transfers in the headless version, update it!
if(headless){
@@ -252,7 +251,7 @@ public class Logic implements ApplicationListener{
if(!state.isEditor()){
//bulletGroup
collisions.collideGroups(bulletGroup, unitGroup);
collisions.collideGroups(bulletGroup, Groups.unit);
}*/
}

View File

@@ -13,7 +13,7 @@ import mindustry.annotations.Annotations.*;
import mindustry.core.GameState.*;
import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
@@ -60,7 +60,7 @@ public class NetClient implements ApplicationListener{
net.handleClient(Connect.class, packet -> {
Log.info("Connecting to server: {0}", packet.addressTCP);
player.isAdmin = false;
player.admin(false);
reset();
@@ -75,11 +75,11 @@ public class NetClient implements ApplicationListener{
});
ConnectPacket c = new ConnectPacket();
c.name = player.name;
c.name = player.name();
c.mods = mods.getModStrings();
c.mobile = mobile;
c.versionType = Version.type;
c.color = Color.rgba8888(player.color);
c.color = Color.rgba8888(player.color());
c.usid = getUsid(packet.addressTCP);
c.uuid = platform.getUUID();
@@ -133,14 +133,14 @@ public class NetClient implements ApplicationListener{
//called on all clients
@Remote(targets = Loc.server, variants = Variant.both)
public static void sendMessage(String message, String sender, Player playersender){
public static void sendMessage(String message, String sender, Playerc playersender){
if(Vars.ui != null){
Vars.ui.chatfrag.addMessage(message, sender);
}
if(playersender != null){
playersender.lastText = message;
playersender.textFadeTime = 1f;
playersender.lastText(message);
playersender.textFadeTime(1f);
}
}
@@ -154,7 +154,7 @@ public class NetClient implements ApplicationListener{
//called when a server recieves a chat message from a player
@Remote(called = Loc.server, targets = Loc.client)
public static void sendChatMessage(Player player, String message){
public static void sendChatMessage(Playerc player, String message){
if(message.length() > maxTextLength){
throw new ValidateException(player, "Player has sent a message above the text limit.");
}
@@ -172,18 +172,18 @@ public class NetClient implements ApplicationListener{
//special case; graphical server needs to see its message
if(!headless){
sendMessage(message, colorizeName(player.id, player.name), player);
sendMessage(message, colorizeName(player.id(), player.name()), player);
}
//server console logging
Log.info("&y{0}: &lb{1}", player.name, message);
Log.info("&y{0}: &lb{1}", player.name(), message);
//invoke event for all clients but also locally
//this is required so other clients get the correct name even if they don't know who's sending it yet
Call.sendMessage(message, colorizeName(player.id, player.name), player);
Call.sendMessage(message, colorizeName(player.id(), player.name()), player);
}else{
//log command to console but with brackets
Log.info("<&y{0}: &lm{1}&lg>", player.name, message);
Log.info("<&y{0}: &lm{1}&lg>", player.name(), message);
//a command was sent, now get the output
if(response.type != ResponseType.valid){
@@ -204,9 +204,9 @@ public class NetClient implements ApplicationListener{
}
public static String colorizeName(int id, String name){
Player player = playerGroup.getByID(id);
Playerc player = Groups.player.getByID(id);
if(name == null || player == null) return null;
return "[#" + player.color.toString().toUpperCase() + "]" + name;
return "[#" + player.color().toString().toUpperCase() + "]" + name;
}
@Remote(called = Loc.client, variants = Variant.one)
@@ -219,8 +219,8 @@ public class NetClient implements ApplicationListener{
}
@Remote(targets = Loc.client)
public static void onPing(Player player, long time){
Call.onPingResponse(player.con, time);
public static void onPing(Playerc player, long time){
Call.onPingResponse(player.con(), time);
}
@Remote(variants = Variant.one)
@@ -229,7 +229,7 @@ public class NetClient implements ApplicationListener{
}
@Remote(variants = Variant.one)
public static void onTraceInfo(Player player, TraceInfo info){
public static void onTraceInfo(Playerc player, TraceInfo info){
if(player != null){
ui.traces.show(player, info);
}
@@ -265,9 +265,6 @@ public class NetClient implements ApplicationListener{
ui.showText("", message);
}
//TODO these are commented out to enforce compatibility with 103! uncomment before 104 release
/*
@Remote(variants = Variant.both)
public static void onInfoPopup(String message, float duration, int align, int top, int left, int bottom, int right){
ui.showInfoPopup(message, duration, align, top, left, bottom, right);
@@ -278,14 +275,15 @@ public class NetClient implements ApplicationListener{
ui.showLabel(info, duration, worldx, worldy);
}
/*
@Remote(variants = Variant.both, unreliable = true)
public static void onEffect(Effect effect, float x, float y, float rotation, Color color){
effect.at(color, x, y, rotation);
effect.at(x, y, rotation, color);
}
@Remote(variants = Variant.both)
public static void onEffectReliable(Effect effect, float x, float y, float rotation, Color color){
effect.at(color, x, y, rotation);
effect.at(x, y, rotation, color);
}*/
@Remote(variants = Variant.both)
@@ -323,35 +321,33 @@ public class NetClient implements ApplicationListener{
@Remote
public static void onPlayerDisconnect(int playerid){
playerGroup.removeByID(playerid);
Groups.player.removeByID(playerid);
}
@Remote(variants = Variant.one, priority = PacketPriority.low, unreliable = true)
public static void onEntitySnapshot(byte groupID, short amount, short dataLen, byte[] data){
public static void onEntitySnapshot(short amount, short dataLen, byte[] data){
try{
netClient.byteStream.setBytes(net.decompressSnapshot(data, dataLen));
DataInputStream input = netClient.dataStream;
EntityGroup group = entities.get(groupID);
//go through each entity
for(int j = 0; j < amount; j++){
int id = input.readInt();
byte typeID = input.readByte();
SyncTrait entity = group == null ? null : (SyncTrait)group.getByID(id);
Syncc entity = Groups.sync.getByID(id);
boolean add = false, created = false;
if(entity == null && id == player.id){
if(entity == null && id == player.id()){
entity = player;
add = true;
}
//entity must not be added yet, so create it
if(entity == null){
entity = (SyncTrait)content.<TypeID>getByID(ContentType.typeid, typeID).constructor.get();
entity.resetID(id);
if(!netClient.isEntityUsed(entity.getID())){
entity = (Syncc)ClassMapping.map(typeID).get();
entity.id(id);
if(!netClient.isEntityUsed(entity.id())){
add = true;
}
created = true;
@@ -360,17 +356,14 @@ public class NetClient implements ApplicationListener{
//read the entity
entity.read(input);
if(created && entity.getInterpolator() != null && entity.getInterpolator().target != null){
if(created && entity.interpolator().target != null){
//set initial starting position
entity.setNet(entity.getInterpolator().target.x, entity.getInterpolator().target.y);
if(entity instanceof Unitc && entity.getInterpolator().targets.length > 0){
((Unitc)entity).rotation = entity.getInterpolator().targets[0];
}
entity.setNet(entity.interpolator().target.x, entity.interpolator().target.y);
}
if(add){
entity.add();
netClient.addRemovedEntity(entity.getID());
netClient.addRemovedEntity(entity.id());
}
}
}catch(IOException e){
@@ -391,7 +384,7 @@ public class NetClient implements ApplicationListener{
Log.warn("Missing entity at {0}. Skipping block snapshot.", tile);
break;
}
tile.entity.read(input, tile.entity.version());
tile.entity.read(input);
}
}catch(Exception e){
e.printStackTrace();
@@ -525,7 +518,7 @@ public class NetClient implements ApplicationListener{
Call.onClientShapshot(lastSent++, player.x, player.y,
player.pointerX, player.pointerY, player.rotation, player.baseRotation,
player.velocity().x, player.velocity().y,
player.vel().x, player.vel().y,
player.getMineTile(),
player.isBoosting, player.isShooting, ui.chatfrag.shown(), player.isBuilding,
requests,

View File

@@ -12,7 +12,7 @@ import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.net.Administration;
@@ -48,7 +48,7 @@ public class NetServer implements ApplicationListener{
//find team with minimum amount of players and auto-assign player to that.
TeamData re = state.teams.getActive().min(data -> {
int count = 0;
for(Player other : players){
for(Playerc other : players){
if(other.team() == data.team && other != player){
count++;
}
@@ -120,7 +120,7 @@ public class NetServer implements ApplicationListener{
return;
}
if(admins.getPlayerLimit() > 0 && playerGroup.size() >= admins.getPlayerLimit()){
if(admins.getPlayerLimit() > 0 && Groups.player.size() >= admins.getPlayerLimit()){
con.kick(KickReason.playerLimit);
return;
}
@@ -161,7 +161,7 @@ public class NetServer implements ApplicationListener{
boolean preventDuplicates = headless && netServer.admins.getStrict();
if(preventDuplicates){
for(Player player : playerGroup.all()){
for(Playerc player : Groups.player.all()){
if(player.name.trim().equalsIgnoreCase(packet.name.trim())){
con.kick(KickReason.nameInUse);
return;
@@ -194,7 +194,7 @@ public class NetServer implements ApplicationListener{
con.modclient = true;
}
Player player = new Player();
Playerc player = new Playerc();
player.isAdmin = admins.isAdmin(uuid, packet.usid);
player.con = con;
player.usid = packet.usid;
@@ -218,7 +218,7 @@ public class NetServer implements ApplicationListener{
con.player = player;
//playing in pvp mode automatically assigns players to teams
player.team(assignTeam(player, playerGroup.all()));
player.team(assignTeam(player, Groups.player.all()));
sendWorldData(player);
@@ -252,7 +252,7 @@ public class NetServer implements ApplicationListener{
}
private void registerCommands(){
clientCommands.<Player>register("help", "[page]", "Lists all commands.", (args, player) -> {
clientCommands.<Playerc>register("help", "[page]", "Lists all commands.", (args, player) -> {
if(args.length > 0 && !Strings.canParseInt(args[0])){
player.sendMessage("[scarlet]'page' must be a number.");
return;
@@ -278,8 +278,8 @@ public class NetServer implements ApplicationListener{
player.sendMessage(result.toString());
});
clientCommands.<Player>register("t", "<message...>", "Send a message only to your teammates.", (args, player) -> {
playerGroup.all().each(p -> p.getTeam() == player.team(), o -> o.sendMessage(args[0], player, "[#" + player.team().color.toString() + "]<T>" + NetClient.colorizeName(player.id, player.name)));
clientCommands.<Playerc>register("t", "<message...>", "Send a message only to your teammates.", (args, player) -> {
Groups.player.all().each(p -> p.getTeam() == player.team(), o -> o.sendMessage(args[0], player, "[#" + player.team().color.toString() + "]<T>" + NetClient.colorizeName(player.id, player.name())));
});
//duration of a a kick in seconds
@@ -290,13 +290,13 @@ public class NetServer implements ApplicationListener{
int voteCooldown = 60 * 1;
class VoteSession{
Player target;
Playerc target;
ObjectSet<String> voted = new ObjectSet<>();
VoteSession[] map;
Timer.Task task;
int votes;
public VoteSession(VoteSession[] map, Player target){
public VoteSession(VoteSession[] map, Playerc target){
this.target = target;
this.map = map;
this.task = Timer.schedule(() -> {
@@ -308,19 +308,19 @@ public class NetServer implements ApplicationListener{
}, voteDuration);
}
void vote(Player player, int d){
void vote(Playerc player, int d){
votes += d;
voted.addAll(player.uuid, admins.getInfo(player.uuid).lastIP);
Call.sendMessage(Strings.format("[orange]{0}[lightgray] has voted to kick[orange] {1}[].[accent] ({2}/{3})\n[lightgray]Type[orange] /vote <y/n>[] to agree.",
player.name, target.name, votes, votesRequired()));
player.name(), target.name, votes, votesRequired()));
}
boolean checkPass(){
if(votes >= votesRequired()){
Call.sendMessage(Strings.format("[orange]Vote passed.[scarlet] {0}[orange] will be banned from the server for {1} minutes.", target.name, (kickDuration/60)));
target.getInfo().lastKicked = Time.millis() + kickDuration*1000;
playerGroup.all().each(p -> p.uuid != null && p.uuid.equals(target.uuid), p -> p.con.kick(KickReason.vote));
Groups.player.all().each(p -> p.uuid != null && p.uuid.equals(target.uuid), p -> p.con.kick(KickReason.vote));
map[0] = null;
task.cancel();
return true;
@@ -333,18 +333,18 @@ public class NetServer implements ApplicationListener{
//current kick sessions
VoteSession[] currentlyKicking = {null};
clientCommands.<Player>register("votekick", "[player...]", "Vote to kick a player, with a cooldown.", (args, player) -> {
clientCommands.<Playerc>register("votekick", "[player...]", "Vote to kick a player, with a cooldown.", (args, player) -> {
if(!Config.enableVotekick.bool()){
player.sendMessage("[scarlet]Vote-kick is disabled on this server.");
return;
}
if(playerGroup.size() < 3){
if(Groups.player.size() < 3){
player.sendMessage("[scarlet]At least 3 players are needed to start a votekick.");
return;
}
if(player.isLocal){
if(player.isLocal()){
player.sendMessage("[scarlet]Just kick them yourself if you're the host.");
return;
}
@@ -352,19 +352,19 @@ public class NetServer implements ApplicationListener{
if(args.length == 0){
StringBuilder builder = new StringBuilder();
builder.append("[orange]Players to kick: \n");
for(Player p : playerGroup.all()){
for(Playerc p : Groups.player.all()){
if(p.isAdmin || p.con == null || p == player) continue;
builder.append("[lightgray] ").append(p.name).append("[accent] (#").append(p.id).append(")\n");
}
player.sendMessage(builder.toString());
}else{
Player found;
Playerc found;
if(args[0].length() > 1 && args[0].startsWith("#") && Strings.canParseInt(args[0].substring(1))){
int id = Strings.parseInt(args[0].substring(1));
found = playerGroup.find(p -> p.id == id);
found = Groups.player.find(p -> p.id == id);
}else{
found = playerGroup.find(p -> p.name.equalsIgnoreCase(args[0]));
found = Groups.player.find(p -> p.name.equalsIgnoreCase(args[0]));
}
if(found != null){
@@ -391,11 +391,11 @@ public class NetServer implements ApplicationListener{
}
});
clientCommands.<Player>register("vote", "<y/n>", "Vote to kick the current player.", (arg, player) -> {
clientCommands.<Playerc>register("vote", "<y/n>", "Vote to kick the current player.", (arg, player) -> {
if(currentlyKicking[0] == null){
player.sendMessage("[scarlet]Nobody is being voted on.");
}else{
if(player.isLocal){
if(player.isLocal()){
player.sendMessage("Local players can't vote. Kick the player yourself instead.");
return;
}
@@ -422,8 +422,8 @@ public class NetServer implements ApplicationListener{
});
clientCommands.<Player>register("sync", "Re-synchronize world state.", (args, player) -> {
if(player.isLocal){
clientCommands.<Playerc>register("sync", "Re-synchronize world state.", (args, player) -> {
if(player.isLocal()){
player.sendMessage("[scarlet]Re-synchronizing as the host is pointless.");
}else{
if(Time.timeSinceMillis(player.getInfo().lastSyncTime) < 1000 * 5){
@@ -439,14 +439,14 @@ public class NetServer implements ApplicationListener{
}
public int votesRequired(){
return 2 + (playerGroup.size() > 4 ? 1 : 0);
return 2 + (Groups.player.size() > 4 ? 1 : 0);
}
public Team assignTeam(Player current, Iterable<Player> players){
public Team assignTeam(Playerc current, Iterable<Playerc> players){
return assigner.assign(current, players);
}
public void sendWorldData(Player player){
public void sendWorldData(Playerc player){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DeflaterOutputStream def = new FastDeflaterOutputStream(stream);
NetworkIO.writeWorld(player, def);
@@ -457,7 +457,7 @@ public class NetServer implements ApplicationListener{
Log.debug("Packed {0} compressed bytes of world data.", stream.size());
}
public static void onDisconnect(Player player, String reason){
public static void onDisconnect(Playerc player, String reason){
//singleplayer multiplayer wierdness
if(player.con == null){
player.remove();
@@ -471,7 +471,7 @@ public class NetServer implements ApplicationListener{
Call.onPlayerDisconnect(player.id);
}
if(Config.showConnectMessages.bool()) Log.info("&lm[{1}] &lc{0} has disconnected. &lg&fi({2})", player.name, player.uuid, reason);
if(Config.showConnectMessages.bool()) Log.info("&lm[{1}] &lc{0} has disconnected. &lg&fi({2})", player.name(), player.uuid, reason);
}
player.remove();
@@ -480,7 +480,7 @@ public class NetServer implements ApplicationListener{
@Remote(targets = Loc.client, unreliable = true)
public static void onClientShapshot(
Player player,
Playerc player,
int snapshotID,
float x, float y,
float pointerX, float pointerY,
@@ -508,8 +508,8 @@ public class NetServer implements ApplicationListener{
float maxSpeed = boosting && !player.mech.flying ? player.mech.compoundSpeedBoost : player.mech.compoundSpeed;
float maxMove = elapsed / 1000f * 60f * Math.min(maxSpeed, player.mech.maxSpeed) * 1.2f;
player.pointerX = pointerX;
player.pointerY = pointerY;
player.mouseX(pointerX);
player.mouseY(pointerY);
player.setMineTile(mining);
player.isTyping = chatting;
player.isBoosting = boosting;
@@ -571,23 +571,23 @@ public class NetServer implements ApplicationListener{
//set interpolator target to *new* position so it moves toward it
player.getInterpolator().read(player.x, player.y, newx, newy, rotation, baseRotation);
player.velocity().set(xVelocity, yVelocity); //only for visual calculation purposes, doesn't actually update the player
player.vel().set(xVelocity, yVelocity); //only for visual calculation purposes, doesn't actually update the player
connection.lastRecievedClientSnapshot = snapshotID;
connection.lastRecievedClientTime = Time.millis();
}
@Remote(targets = Loc.client, called = Loc.server)
public static void onAdminRequest(Player player, Player other, AdminAction action){
public static void onAdminRequest(Playerc player, Playerc other, AdminAction action){
if(!player.isAdmin){
if(!player.admin()){
Log.warn("ACCESS DENIED: Player {0} / {1} attempted to perform admin action without proper security access.",
player.name, player.con.address);
player.name(), player.con().address);
return;
}
if(other == null || ((other.isAdmin && !player.isLocal) && other != player)){
Log.warn("{0} attempted to perform admin action on nonexistant or admin player.", player.name);
if(other == null || ((other.admin() && !player.isLocal()) && other != player)){
Log.warn("{0} attempted to perform admin action on nonexistant or admin player.", player.name());
return;
}
@@ -596,32 +596,32 @@ public class NetServer implements ApplicationListener{
//not a real issue, because server owners may want to do just that
state.wavetime = 0f;
}else if(action == AdminAction.ban){
netServer.admins.banPlayerIP(other.con.address);
other.con.kick(KickReason.banned);
Log.info("&lc{0} has banned {1}.", player.name, other.name);
netServer.admins.banPlayerIP(other.con().address);
other.kick(KickReason.banned);
Log.info("&lc{0} has banned {1}.", player.name(), other.name());
}else if(action == AdminAction.kick){
other.con.kick(KickReason.kick);
Log.info("&lc{0} has kicked {1}.", player.name, other.name);
other.kick(KickReason.kick);
Log.info("&lc{0} has kicked {1}.", player.name(), other.name());
}else if(action == AdminAction.trace){
TraceInfo info = new TraceInfo(other.con.address, other.uuid, other.con.modclient, other.con.mobile);
if(player.con != null){
Call.onTraceInfo(player.con, other, info);
TraceInfo info = new TraceInfo(other.con().address, other.uuid(), other.con().modclient, other.con.mobile);
if(player.con() != null){
Call.onTraceInfo(player.con(), other, info);
}else{
NetClient.onTraceInfo(other, info);
}
Log.info("&lc{0} has requested trace info of {1}.", player.name, other.name);
Log.info("&lc{0} has requested trace info of {1}.", player.name(), other.name());
}
}
@Remote(targets = Loc.client)
public static void connectConfirm(Player player){
if(player.con == null || player.con.hasConnected) return;
public static void connectConfirm(Playerc player){
if(player.con() == null || player.con().hasConnected) return;
player.add();
player.con.hasConnected = true;
player.con().hasConnected = true;
if(Config.showConnectMessages.bool()){
Call.sendMessage("[accent]" + player.name + "[accent] has connected.");
Log.info("&lm[{1}] &y{0} has connected. ", player.name, player.uuid);
Call.sendMessage("[accent]" + player.name() + "[accent] has connected.");
Log.info("&lm[{1}] &y{0} has connected. ", player.name(), player.uuid());
}
if(!Config.motd.string().equalsIgnoreCase("off")){
@@ -635,7 +635,7 @@ public class NetServer implements ApplicationListener{
if(state.rules.pvp){
int used = 0;
for(TeamData t : state.teams.getActive()){
if(playerGroup.count(p -> p.getTeam() == t.team) > 0){
if(Groups.player.count(p -> p.getTeam() == t.team) > 0){
used++;
}
}
@@ -710,14 +710,14 @@ public class NetServer implements ApplicationListener{
}
}
public void writeEntitySnapshot(Player player) throws IOException{
public void writeEntitySnapshot(Playerc player) throws IOException{
syncStream.reset();
Array<CoreEntity> cores = state.teams.cores(player.team());
dataStream.writeByte(cores.size);
for(CoreEntity entity : cores){
dataStream.writeInt(entity.tile.pos());
dataStream.writeInt(entity.tile().pos());
entity.items().write(dataStream);
}
@@ -730,44 +730,42 @@ public class NetServer implements ApplicationListener{
viewport.setSize(player.con.viewWidth, player.con.viewHeight).setCenter(player.con.viewX, player.con.viewY);
//check for syncable groups
for(EntityGroup<?> group : entities.all()){
if(group.isEmpty() || !(group.all().get(0) instanceof SyncTrait)) continue;
//make sure mapping is enabled for this group
if(!group.mappingEnabled()){
throw new RuntimeException("Entity group '" + group.getType() + "' contains SyncTrait entities, yet mapping is not enabled. In order for syncing to work, you must enable mapping for this group.");
}
//make sure mapping is enabled for this group
if(!group.mappingEnabled()){
throw new RuntimeException("Entity group '" + group.getType() + "' contains SyncTrait entities, yet mapping is not enabled. In order for syncing to work, you must enable mapping for this group.");
}
syncStream.reset();
syncStream.reset();
int sent = 0;
int sent = 0;
for(Entity entity : group.all()){
SyncTrait sync = (SyncTrait)entity;
for(Entity entity : group.all()){
SyncTrait sync = (SyncTrait)entity;
//write all entities now
dataStream.writeInt(entity.getID()); //write id
dataStream.writeByte(sync.getTypeID().id); //write type ID
sync.write(dataStream); //write entity
//write all entities now
dataStream.writeInt(entity.getID()); //write id
dataStream.writeByte(sync.getTypeID().id); //write type ID
sync.write(dataStream); //write entity
sent++;
sent++;
if(syncStream.size() > maxSnapshotSize){
dataStream.close();
byte[] syncBytes = syncStream.toByteArray();
Call.onEntitySnapshot(player.con, (byte)group.getID(), (short)sent, (short)syncBytes.length, net.compressSnapshot(syncBytes));
sent = 0;
syncStream.reset();
}
}
if(sent > 0){
if(syncStream.size() > maxSnapshotSize){
dataStream.close();
byte[] syncBytes = syncStream.toByteArray();
Call.onEntitySnapshot(player.con, (byte)group.getID(), (short)sent, (short)syncBytes.length, net.compressSnapshot(syncBytes));
sent = 0;
syncStream.reset();
}
}
if(sent > 0){
dataStream.close();
byte[] syncBytes = syncStream.toByteArray();
Call.onEntitySnapshot(player.con, (byte)group.getID(), (short)sent, (short)syncBytes.length, net.compressSnapshot(syncBytes));
}
}
String fixName(String name){
@@ -824,9 +822,9 @@ public class NetServer implements ApplicationListener{
try{
//iterate through each player
for(int i = 0; i < playerGroup.size(); i++){
Player player = playerGroup.all().get(i);
if(player.isLocal) continue;
for(int i = 0; i < Groups.player.size(); i++){
Playerc player = Groups.player.all().get(i);
if(player.isLocal()) continue;
if(player.con == null || !player.con.isConnected()){
onDisconnect(player, "disappeared");
@@ -835,12 +833,12 @@ public class NetServer implements ApplicationListener{
NetConnection connection = player.con;
if(!player.timer.get(Player.timerSync, serverSyncTime) || !connection.hasConnected) continue;
if(!player.timer.get(Playerc.timerSync, serverSyncTime) || !connection.hasConnected) continue;
writeEntitySnapshot(player);
}
if(playerGroup.size() > 0 && Core.settings.getBool("blocksync") && timer.get(timerBlockSync, blockSyncTime)){
if(Groups.player.size() > 0 && Core.settings.getBool("blocksync") && timer.get(timerBlockSync, blockSyncTime)){
writeBlockSnapshots();
}
@@ -850,6 +848,6 @@ public class NetServer implements ApplicationListener{
}
public interface TeamAssigner{
Team assign(Player player, Iterable<Player> players);
Team assign(Playerc player, Iterable<Playerc> players);
}
}

View File

@@ -12,7 +12,7 @@ import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
import mindustry.graphics.*;
@@ -242,7 +242,7 @@ public class Renderer implements ApplicationListener{
}
overlays.drawBottom();
playerGroup.draw(p -> p.isLocal, Player::drawBuildRequests);
Groups.player.draw(p -> p.isLocal, Playerc::drawBuildRequests);
if(shieldGroup.countInBounds() > 0){
if(settings.getBool("animatedshields") && Shaders.shield != null){
@@ -265,7 +265,7 @@ public class Renderer implements ApplicationListener{
overlays.drawTop();
playerGroup.draw(p -> !p.isDead(), Player::drawName);
Groups.player.draw(p -> !p.isDead(), Playerc::drawName);
if(state.rules.lighting){
lights.draw();
@@ -311,10 +311,10 @@ public class Renderer implements ApplicationListener{
Draw.rect("circle-shadow", u.x, u.y, size * rad, size * rad);
};
unitGroup.draw(unit -> !unit.isDead(), draw::get);
Groups.unit.draw(unit -> !unit.isDead(), draw::get);
if(!playerGroup.isEmpty()){
playerGroup.draw(unit -> !unit.isDead(), draw::get);
if(!Groups.player.isEmpty()){
Groups.player.draw(unit -> !unit.isDead(), draw::get);
}
Draw.color();
@@ -324,21 +324,21 @@ public class Renderer implements ApplicationListener{
float trnsX = -12, trnsY = -13;
Draw.color(0, 0, 0, 0.22f);
unitGroup.draw(unit -> unit.isFlying() && !unit.isDead(), baseUnit -> baseUnit.drawShadow(trnsX, trnsY));
playerGroup.draw(unit -> unit.isFlying() && !unit.isDead(), player -> player.drawShadow(trnsX, trnsY));
Groups.unit.draw(unit -> unit.isFlying() && !unit.isDead(), baseUnit -> baseUnit.drawShadow(trnsX, trnsY));
Groups.player.draw(unit -> unit.isFlying() && !unit.isDead(), player -> player.drawShadow(trnsX, trnsY));
Draw.color();
}
private void drawAllTeams(boolean flying){
unitGroup.draw(u -> u.isFlying() == flying && !u.isDead(), Unitc::drawUnder);
playerGroup.draw(p -> p.isFlying() == flying && !p.isDead(), Unitc::drawUnder);
Groups.unit.draw(u -> u.isFlying() == flying && !u.isDead(), Unitc::drawUnder);
Groups.player.draw(p -> p.isFlying() == flying && !p.isDead(), Unitc::drawUnder);
unitGroup.draw(u -> u.isFlying() == flying && !u.isDead(), Unitc::drawAll);
playerGroup.draw(p -> p.isFlying() == flying, Unitc::drawAll);
Groups.unit.draw(u -> u.isFlying() == flying && !u.isDead(), Unitc::drawAll);
Groups.player.draw(p -> p.isFlying() == flying, Unitc::drawAll);
unitGroup.draw(u -> u.isFlying() == flying && !u.isDead(), Unitc::drawOver);
playerGroup.draw(p -> p.isFlying() == flying, Unitc::drawOver);
Groups.unit.draw(u -> u.isFlying() == flying && !u.isDead(), Unitc::drawOver);
Groups.player.draw(p -> p.isFlying() == flying, Unitc::drawOver);
}
public void scaleCamera(float amount){

View File

@@ -10,10 +10,10 @@ public enum ContentType{
status,
unit,
weather,
effect,
effect_UNUSED,
zone,
loadout,
typeid,
loadout_UNUSED,
typeid_UNUSED,
error,
planet;

View File

@@ -176,7 +176,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
}
platform.publish(map);
}).padTop(-3).size(swidth * 2f + 10, 60f).update(b -> b.setText(editor.getTags().containsKey("steamid") ? editor.getTags().get("author").equals(player.name) ? "$workshop.listing" : "$view.workshop" : "$editor.publish.workshop"));
}).padTop(-3).size(swidth * 2f + 10, 60f).update(b -> b.setText(editor.getTags().containsKey("steamid") ? editor.getTags().get("author").equals(player.name()) ? "$workshop.listing" : "$view.workshop" : "$editor.publish.workshop"));
menu.cont.row();
}

View File

@@ -73,7 +73,7 @@ public class Damage{
}
}
public static void collideLine(Bullet hitter, Team team, Effect effect, float x, float y, float angle, float length){
public static void collideLine(Bulletc hitter, Team team, Effect effect, float x, float y, float angle, float length){
collideLine(hitter, team, effect, x, y, angle, length, false);
}
@@ -81,7 +81,7 @@ public class Damage{
* Damages entities in a line.
* Only enemies of the specified team are damaged.
*/
public static void collideLine(Bullet hitter, Team team, Effect effect, float x, float y, float angle, float length, boolean large){
public static void collideLine(Bulletc hitter, Team team, Effect effect, float x, float y, float angle, float length, boolean large){
collidedBlocks.clear();
tr.trns(angle, length);
Intc2 collider = (cx, cy) -> {
@@ -89,7 +89,7 @@ public class Damage{
if(tile != null && !collidedBlocks.contains(tile.pos()) && tile.entity != null && tile.getTeamID() != team.id && tile.entity.collide(hitter)){
tile.entity.collision(hitter);
collidedBlocks.add(tile.pos());
hitter.getBulletType().hit(hitter, tile.worldx(), tile.worldy());
hitter.type().hit(hitter, tile.worldx(), tile.worldy());
}
};
@@ -184,7 +184,7 @@ public class Damage{
entity.damage(amount);
//TODO better velocity displacement
float dst = tr.set(entity.getX() - x, entity.getY() - y).len();
entity.velocity().add(tr.setLength((1f - dst / radius) * 2f / entity.mass()));
entity.vel().add(tr.setLength((1f - dst / radius) * 2f / entity.mass()));
if(complete && damage >= 9999999f && entity == player){
Events.fire(Trigger.exclusionDeath);
@@ -235,8 +235,8 @@ public class Damage{
//apply damage to entity if needed
if(tile.entity != null && tile.getTeam() != team){
int health = (int)tile.entity.health;
if(tile.entity.health > 0){
int health = (int)tile.entity.health();
if(tile.entity.health() > 0){
tile.entity.damage(scaledDamage);
scaledDamage -= health;

View File

@@ -16,6 +16,9 @@ public class Effect{
/** Clip size. */
public float size;
public boolean ground;
public float groundDuration;
public Effect(float life, float clipsize, Cons<EffectContainer> renderer){
this.id = lastid++;
this.lifetime = life;
@@ -27,6 +30,17 @@ public class Effect{
this(life, 28f, renderer);
}
public Effect ground(){
ground = true;
return this;
}
public Effect ground(float duration){
ground = true;
this.groundDuration = duration;
return this;
}
public void at(Position pos){
Effects.createEffect(this, pos.getX(), pos.getY(), 0, Color.white, null);
}

View File

@@ -5,9 +5,7 @@ import arc.graphics.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import arc.util.pooling.*;
import mindustry.content.*;
import mindustry.entities.type.*;
import static mindustry.Vars.*;
@@ -40,13 +38,14 @@ public class Effects{
Rect pos = Tmp.r2.setSize(effect.size).setCenter(x, y);
if(view.overlaps(pos)){
EffectEntity entity = Pools.obtain(EffectEntity.class, EffectEntity::new);
entity.effect = effect;
entity.color.set(color);
entity.rotation = rotation;
entity.data = data;
entity.id++;
entity.set(x, y);
//TODO implement create() method here.
//EffectEntity entity = Pools.obtain(EffectEntity.class, EffectEntity::new);
//entity.effect = effect;
//entity.color.set(color);
//entity.rotation = rotation;
//entity.data = data;
//entity.id++;
//entity.set(x, y);
//if(data instanceof Entity){
// entity.setParent((Entity)data);
//}

View File

@@ -3,7 +3,7 @@ package mindustry.entities;
import arc.func.*;
import arc.math.*;
import arc.math.geom.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.world.*;
@@ -18,7 +18,7 @@ public class Units{
private static boolean boolResult;
/** @return whether this player can interact with a specific tile. if either of these are null, returns true.*/
public static boolean canInteract(Player player, Tile tile){
public static boolean canInteract(Playerc player, Tile tile){
return player == null || tile == null || tile.interactable(player.team());
}
@@ -148,7 +148,7 @@ public class Units{
/** Iterates over all units in a rectangle. */
public static void nearby(Team team, float x, float y, float width, float height, Cons<Unitc> cons){
unitGroup.intersect(x, y, width, height, u -> {
Groups.unit.intersect(x, y, width, height, u -> {
if(u.getTeam() == team){
cons.get(u);
}
@@ -157,7 +157,7 @@ public class Units{
/** Iterates over all units in a circle around this position. */
public static void nearby(Team team, float x, float y, float radius, Cons<Unitc> cons){
unitGroup.intersect(x - radius, y - radius, radius*2f, radius*2f, unit -> {
Groups.unit.intersect(x - radius, y - radius, radius*2f, radius*2f, unit -> {
if(unit.getTeam() == team && unit.withinDst(x, y, radius)){
cons.get(unit);
}
@@ -166,7 +166,7 @@ public class Units{
/** Iterates over all units in a rectangle. */
public static void nearby(float x, float y, float width, float height, Cons<Unitc> cons){
unitGroup.intersect(x, y, width, height, cons);
Groups.unit.intersect(x, y, width, height, cons);
}
/** Iterates over all units in a rectangle. */
@@ -176,7 +176,7 @@ public class Units{
/** Iterates over all units that are enemies of this team. */
public static void nearbyEnemies(Team team, float x, float y, float width, float height, Cons<Unitc> cons){
unitGroup.intersect(x, y, width, height, u -> {
Groups.unit.intersect(x, y, width, height, u -> {
if(team.isEnemy(u.getTeam())){
cons.get(u);
}
@@ -190,11 +190,11 @@ public class Units{
/** Iterates over all units. */
public static void all(Cons<Unitc> cons){
unitGroup.all().each(cons);
Groups.unit.all().each(cons);
}
public static void each(Team team, Cons<BaseUnit> cons){
unitGroup.all().each(t -> t.getTeam() == team, cons);
public static void each(Team team, Cons<Unitc> cons){
Groups.unit.all().each(t -> t.getTeam() == team, cons);
}
}

View File

@@ -27,7 +27,7 @@ public class ArtilleryBulletType extends BasicBulletType{
super.update(b);
if(b.timer.get(0, 3 + b.fslope() * 2f)){
trailEffect.at(b.x, b.y, b.fslope() * 4f, backColor);
trailEffect.at(b.x(), b.y(), b.fslope() * 4f, backColor);
}
}
@@ -39,9 +39,9 @@ public class ArtilleryBulletType extends BasicBulletType{
float height = bulletHeight * ((1f - bulletShrink) + bulletShrink * b.fout());
Draw.color(backColor);
Draw.rect(backRegion, b.x, b.y, bulletWidth * scale, height * scale, b.rot() - 90);
Draw.rect(backRegion, b.x(), b.y(), bulletWidth * scale, height * scale, b.rotation() - 90);
Draw.color(frontColor);
Draw.rect(frontRegion, b.x, b.y, bulletWidth * scale, height * scale, b.rot() - 90);
Draw.rect(frontRegion, b.x(), b.y(), bulletWidth * scale, height * scale, b.rotation() - 90);
Draw.color();
}
}

View File

@@ -38,9 +38,9 @@ public class BasicBulletType extends BulletType{
float height = bulletHeight * ((1f - bulletShrink) + bulletShrink * b.fout());
Draw.color(backColor);
Draw.rect(backRegion, b.x, b.y, bulletWidth, height, b.rot() - 90);
Draw.rect(backRegion, b.x(), b.y(), bulletWidth, height, b.rotation() - 90);
Draw.color(frontColor);
Draw.rect(frontRegion, b.x, b.y, bulletWidth, height, b.rot() - 90);
Draw.rect(frontRegion, b.x(), b.y(), bulletWidth, height, b.rotation() - 90);
Draw.color();
}
}

View File

@@ -210,7 +210,7 @@ public abstract class BulletType extends Content{
bullet.velocity.set(0, type.speed).setAngle(angle).scl(velocityScl);
if(type.keepVelocity){
bullet.velocity.add(owner instanceof VelocityTrait ? ((VelocityTrait)owner).velocity() : Vec2.ZERO);
bullet.velocity.add(owner instanceof VelocityTrait ? ((VelocityTrait)owner).vel() : Vec2.ZERO);
}
bullet.team = team;

View File

@@ -29,7 +29,7 @@ public class FlakBulletType extends BasicBulletType{
if(b.getData() instanceof Integer) return;
if(b.timer.get(2, 6)){
Units.nearbyEnemies(b.team(), rect.setSize(explodeRange * 2f).setCenter(b.x, b.y), unit -> {
Units.nearbyEnemies(b.team(), rect.setSize(explodeRange * 2f).setCenter(b.x(), b.y()), unit -> {
if(b.getData() instanceof Float) return;
if(unit.dst(b) < explodeRange){

View File

@@ -36,9 +36,9 @@ public class HealBulletType extends BulletType{
public void draw(Bulletc b){
Draw.color(backColor);
Lines.stroke(bulletWidth);
Lines.lineAngleCenter(b.x, b.y, b.rot(), bulletHeight);
Lines.lineAngleCenter(b.x(), b.y(), b.rotation(), bulletHeight);
Draw.color(frontColor);
Lines.lineAngleCenter(b.x, b.y, b.rot(), bulletHeight / 2f);
Lines.lineAngleCenter(b.x(), b.y(), b.rotation(), bulletHeight / 2f);
Draw.reset();
}

View File

@@ -41,7 +41,7 @@ public class LaserBulletType extends BulletType{
@Override
public void init(Bulletc b){
Damage.collideLine(b, b.team(), hitEffect, b.x, b.y, b.rot(), length);
Damage.collideLine(b, b.team(), hitEffect, b.x(), b.y(), b.rotation(), length);
}
@Override
@@ -51,18 +51,18 @@ public class LaserBulletType extends BulletType{
float cwidth = width;
float compound = 1f;
Lines.lineAngle(b.x, b.y, b.rot(), baseLen);
Lines.lineAngle(b.x(), b.y(), b.rotation(), baseLen);
Lines.precise(true);
for(Color color : colors){
Draw.color(color);
Lines.stroke((cwidth *= lengthFalloff) * b.fout());
Lines.lineAngle(b.x, b.y, b.rot(), baseLen, CapStyle.none);
Tmp.v1.trns(b.rot(), baseLen);
Drawf.tri(b.x + Tmp.v1.x, b.y + Tmp.v1.y, Lines.getStroke() * 1.22f, cwidth * 2f + width / 2f, b.rot());
Lines.lineAngle(b.x(), b.y(), b.rotation(), baseLen, CapStyle.none);
Tmp.v1.trns(b.rotation(), baseLen);
Drawf.tri(b.x + Tmp.v1.x, b.y + Tmp.v1.y, Lines.getStroke() * 1.22f, cwidth * 2f + width / 2f, b.rotation());
Fill.circle(b.x, b.y, 1f * cwidth * b.fout());
Fill.circle(b.x(), b.y(), 1f * cwidth * b.fout());
for(int i : Mathf.signs){
Drawf.tri(b.x, b.y, sideWidth * b.fout() * cwidth, sideLength * compound, b.rot() + sideAngle * i);
Drawf.tri(b.x(), b.y(), sideWidth * b.fout() * cwidth, sideLength * compound, b.rotation() + sideAngle * i);
}
compound *= lengthFalloff;

View File

@@ -25,6 +25,6 @@ public class LightningBulletType extends BulletType{
@Override
public void init(Bulletc b){
Lightning.create(b.team(), lightningColor, damage, b.x, b.y, b.rot(), lightningLength);
Lightning.create(b.team(), lightningColor, damage, b.x(), b.y(), b.rotation(), lightningLength);
}
}

View File

@@ -48,7 +48,7 @@ public class LiquidBulletType extends BulletType{
super.update(b);
if(liquid.canExtinguish()){
Tile tile = world.tileWorld(b.x, b.y);
Tile tile = world.tileWorld(b.x(), b.y());
if(tile != null && Fire.has(tile.x, tile.y)){
Fire.extinguish(tile, 100f);
b.remove();
@@ -61,7 +61,7 @@ public class LiquidBulletType extends BulletType{
public void draw(Bulletc b){
Draw.color(liquid.color, Color.white, b.fout() / 100f);
Fill.circle(b.x, b.y, 0.5f + b.fout() * 2.5f);
Fill.circle(b.x(), b.y(), 0.5f + b.fout() * 2.5f);
}
@Override

View File

@@ -27,10 +27,10 @@ public class MassDriverBolt extends BulletType{
float w = 11f, h = 13f;
Draw.color(Pal.bulletYellowBack);
Draw.rect("shell-back", b.x, b.y, w, h, b.rot() + 90);
Draw.rect("shell-back", b.x(), b.y(), w, h, b.rotation() + 90);
Draw.color(Pal.bulletYellow);
Draw.rect("shell", b.x, b.y, w, h, b.rot() + 90);
Draw.rect("shell", b.x(), b.y(), w, h, b.rotation() + 90);
Draw.reset();
}
@@ -92,8 +92,8 @@ public class MassDriverBolt extends BulletType{
for(int i = 0; i < data.items.length; i++){
int amountDropped = Mathf.random(0, data.items[i]);
if(amountDropped > 0){
float angle = b.rot() + Mathf.range(100f);
Fx.dropItem.at(b.x, b.y, angle, Color.white, content.item(i));
float angle = b.rotation() + Mathf.range(100f);
Fx.dropItem.at(b.x(), b.y(), angle, Color.white, content.item(i));
}
}
}

View File

@@ -30,11 +30,11 @@ public class MissileBulletType extends BasicBulletType{
super.update(b);
if(Mathf.chance(Time.delta() * 0.2)){
Fx.missileTrail.at(b.x, b.y, 2f, trailColor);
Fx.missileTrail.at(b.x(), b.y(), 2f, trailColor);
}
if(weaveMag > 0){
b.velocity().rotate(Mathf.sin(Time.time() + b.id * 4422, weaveScale, weaveMag) * Time.delta());
b.vel().rotate(Mathf.sin(Time.time() + b.id * 4422, weaveScale, weaveMag) * Time.delta());
}
}
}

View File

@@ -16,6 +16,7 @@ import arc.util.pooling.*;
import mindustry.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.core.*;
import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.entities.bullet.*;
@@ -25,7 +26,9 @@ import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.net.Administration.*;
import mindustry.net.*;
import mindustry.net.Packets.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.*;
@@ -179,6 +182,11 @@ public class EntityComps{
Object data;
BulletType type;
Interval timer = new Interval(6);
public boolean timer(int index, float time){
return timer.get(index, time);
}
@Override
public float getDamage(){
@@ -662,6 +670,136 @@ public class EntityComps{
}
}
@Component
abstract class PlayerComp implements UnitController, Entityc, Syncc{
@Nullable Unitc unit;
@ReadOnly Team team = Team.sharded;
String name = "noname";
@Nullable NetConnection con;
boolean admin, typing;
Color color = new Color();
float mouseX, mouseY;
@Nullable String lastText;
float textFadeTime;
public void update(){
if(unit != null){
x(unit.x());
y(unit.y());
unit.team(team);
}
textFadeTime -= Time.delta() / (60 * 5);
}
public void team(Team team){
if(unit != null){
unit.team(team);
}
}
public void unit(Unitc unit){
this.unit = unit;
unit.team(team);
}
String uuid(){
return con == null ? "AAAAAAAA" : con.uuid;
}
String usid(){
return con == null ? "AAAAAAAA" : con.usid;
}
void kick(KickReason reason){
con.kick(reason);
}
void kick(String reason){
con.kick(reason);
}
void drawName(){
BitmapFont font = Fonts.def;
GlyphLayout layout = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
final float nameHeight = 11;
final float textHeight = 15;
boolean ints = font.usesIntegerPositions();
font.setUseIntegerPositions(false);
font.getData().setScale(0.25f / Scl.scl(1f));
layout.setText(font, name);
if(!isLocal()){
Draw.color(0f, 0f, 0f, 0.3f);
Fill.rect(unit.x(), unit.y() + nameHeight - layout.height / 2, layout.width + 2, layout.height + 3);
Draw.color();
font.setColor(color);
font.draw(name, unit.x(), unit.y() + nameHeight, 0, Align.center, false);
if(admin){
float s = 3f;
Draw.color(color.r * 0.5f, color.g * 0.5f, color.b * 0.5f, 1f);
Draw.rect(Icon.adminSmall.getRegion(), unit.x() + layout.width / 2f + 2 + 1, unit.y() + nameHeight - 1.5f, s, s);
Draw.color(color);
Draw.rect(Icon.adminSmall.getRegion(), unit.x() + layout.width / 2f + 2 + 1, unit.y() + nameHeight - 1f, s, s);
}
}
if(Core.settings.getBool("playerchat") && ((textFadeTime > 0 && lastText != null) || typing)){
String text = textFadeTime <= 0 || lastText == null ? "[LIGHT_GRAY]" + Strings.animated(Time.time(), 4, 15f, ".") : lastText;
float width = 100f;
float visualFadeTime = 1f - Mathf.curve(1f - textFadeTime, 0.9f);
font.setColor(1f, 1f, 1f, textFadeTime <= 0 || lastText == null ? 1f : visualFadeTime);
layout.setText(font, text, Color.white, width, Align.bottom, true);
Draw.color(0f, 0f, 0f, 0.3f * (textFadeTime <= 0 || lastText == null ? 1f : visualFadeTime));
Fill.rect(unit.x(), unit.y() + textHeight + layout.height - layout.height/2f, layout.width + 2, layout.height + 3);
font.draw(text, unit.x() - width/2f, unit.y() + textHeight + layout.height, width, Align.center, true);
}
Draw.reset();
Pools.free(layout);
font.getData().setScale(1f);
font.setColor(Color.white);
font.setUseIntegerPositions(ints);
}
void sendMessage(String text){
if(isLocal()){
if(ui != null){
ui.chatfrag.addMessage(text, null);
}
}else{
Call.sendMessage(con, text, null, null);
}
}
void sendMessage(String text, Playerc from){
sendMessage(text, from, NetClient.colorizeName(from.id(), from.name()));
}
void sendMessage(String text, Playerc from, String fromName){
if(isLocal()){
if(ui != null){
ui.chatfrag.addMessage(text, fromName);
}
}else{
Call.sendMessage(con, text, fromName, from);
}
}
PlayerInfo getInfo(){
if(isLocal()){
throw new IllegalArgumentException("Local players cannot be traced and do not have info.");
}else{
return netServer.admins.getInfo(uuid());
}
}
}
@Component
abstract class TeamComp implements Posc, Healthc{
transient float x, y;
@@ -1194,6 +1332,25 @@ public class EntityComps{
current.progress = entity.progress;
}
/** Draw all current build requests. Does not draw the beam effect, only the positions. */
void drawBuildRequests(){
for(BuildRequest request : requests){
if(request.progress > 0.01f || (buildRequest() == request && request.initialized && (dst(request.x * tilesize, request.y * tilesize) <= placeDistance || state.isEditor()))) continue;
request.animScale = 1f;
if(request.breaking){
control.input.drawBreaking(request);
}else{
request.block.drawRequest(request, control.input.allRequests(),
Build.validPlace(team(), request.x, request.y, request.block, request.rotation) || control.input.requestMatches(request));
}
}
Draw.reset();
}
/** @return whether this request should be skipped, in favor of the next one. */
boolean shouldSkip(BuildRequest request, @Nullable Tilec core){
//requests that you have at least *started* are considered
@@ -1557,7 +1714,7 @@ public class EntityComps{
}
boolean isLocal(){
return this == Vars.player;
return this instanceof Unitc && ((Unitc)this).controller() == player || this == player;
}
<T> T as(Class<T> type){
@@ -1566,5 +1723,13 @@ public class EntityComps{
@InternalImpl
abstract int classId();
void read(DataInput input) throws IOException{
//TODO dynamic io
}
void write(DataOutput output) throws IOException{
//TODO dynamic io
}
}
}

View File

@@ -16,4 +16,7 @@ class EntityDefs{
@EntityDef({DecalComp.class})
class DecalDef{}
@EntityDef({PlayerComp.class})
class PlayerDef{}
}

View File

@@ -5,6 +5,11 @@ import mindustry.entities.def.EntityComps.*;
public class EntityGroupDefs{
@GroupDef(PlayerComp.class)
void player(){
}
@GroupDef(UnitComp.class)
void unit(){
@@ -16,7 +21,12 @@ public class EntityGroupDefs{
}
@GroupDef(DrawComp.class)
void drawers(){
void drawer(){
}
@GroupDef(SyncComp.class)
void sync(){
}
}

View File

@@ -1,89 +0,0 @@
package mindustry.entities.effect;
import arc.math.Mathf;
import arc.util.Time;
import mindustry.Vars;
import mindustry.entities.Effects;
import mindustry.entities.*;
import mindustry.entities.Effects.EffectRenderer;
import mindustry.world.Tile;
/**
* A ground effect contains an effect that is rendered on the ground layer as opposed to the top layer.
*/
public class GroundEffectEntity extends EffectEntity{
private boolean once;
@Override
public void update(){
GroundEffect effect = (GroundEffect)this.effect;
if(effect.isStatic){
time += Time.delta();
time = Mathf.clamp(time, 0, effect.staticLife);
if(!once && time >= lifetime()){
once = true;
time = 0f;
Tile tile = Vars.world.tileWorld(x, y);
if(tile != null && tile.floor().isLiquid){
remove();
}
}else if(once && time >= effect.staticLife){
remove();
}
}else{
super.update();
}
}
@Override
public void draw(){
GroundEffect effect = (GroundEffect)this.effect;
if(once && effect.isStatic)
Effects.renderEffect(id, effect, color, lifetime(), rotation, x, y, data);
else
Effects.renderEffect(id, effect, color, time, rotation, x, y, data);
}
@Override
public void reset(){
super.reset();
once = false;
}
/**
* An effect that is rendered on the ground layer as opposed to the top layer.
*/
public static class GroundEffect extends Effect{
/**
* How long this effect stays on the ground when static.
*/
public final float staticLife;
/**
* If true, this effect will stop and lie on the ground for a specific duration,
* after its initial lifetime is over.
*/
public final boolean isStatic;
public GroundEffect(float life, float staticLife, EffectRenderer draw){
super(life, draw);
this.staticLife = staticLife;
this.isStatic = true;
}
public GroundEffect(boolean isStatic, float life, EffectRenderer draw){
super(life, draw);
this.staticLife = 0f;
this.isStatic = isStatic;
}
public GroundEffect(float life, EffectRenderer draw){
super(life, draw);
this.staticLife = 0f;
this.isStatic = false;
}
}
}

View File

@@ -9,7 +9,7 @@ import arc.util.pooling.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;

View File

@@ -201,7 +201,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
unit.applyEffect(liquid.effect, 60 * 2);
if(unit.velocity().len() > 0.1){
if(unit.vel().len() > 0.1){
Fx.ripple.at(liquid.color, unit.x, unit.y);
}
});

View File

@@ -1,914 +0,0 @@
package mindustry.entities.type;
import arc.*;
import mindustry.annotations.Annotations.*;
import arc.struct.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import arc.util.pooling.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.core.*;
import mindustry.ctype.ContentType;
import mindustry.entities.*;
import mindustry.entities.units.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.input.*;
import mindustry.io.*;
import mindustry.net.Administration.*;
import mindustry.net.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import java.io.*;
import static mindustry.Vars.*;
public class Player extends Unitc implements BuilderMinerTrait, ShooterTrait{
public static final int timerSync = 2;
public static final int timerAbility = 3;
private static final float liftoffBoost = 0.2f;
private static final Rect rect = new Rect();
//region instance variables
public float baseRotation;
public float pointerX, pointerY;
public String name = "noname";
public @Nullable String uuid, usid;
public boolean isAdmin, isTransferring, isShooting, isBoosting, isMobile, isTyping, isBuilding = true;
public boolean buildWasAutoPaused = false;
public float boostHeat, shootHeat, destructTime;
public boolean achievedFlight;
public Color color = new Color();
public UnitDef mech = Mechs.starter;
public SpawnerTrait spawner, lastSpawner;
public int respawns;
public @Nullable NetConnection con;
public boolean isLocal = false;
public Interval timer = new Interval(6);
public Teamc target;
public Teamc moveTarget;
public @Nullable String lastText;
public float textFadeTime;
private float walktime, itemtime;
private Queue<BuildRequest> placeQueue = new Queue<>();
private Tile mining;
private Vec2 movement = new Vec2();
private boolean moved;
//endregion
//region unit and event overrides, utility methods
@Remote(targets = Loc.server, called = Loc.server)
public static void onPlayerDeath(Player player){
if(player == null) return;
player.dead = true;
player.placeQueue.clear();
player.onDeath();
}
@Override
public float getDamageMultipler(){
return status.getDamageMultiplier() * state.rules.playerDamageMultiplier;
}
@Override
public void onRespawn(Tile tile){
velocity.setZero();
boostHeat = 1f;
achievedFlight = true;
rotation = 90f;
baseRotation = 90f;
dead = false;
spawner = null;
respawns --;
Sounds.respawn.at(tile);
setNet(tile.drawx(), tile.drawy());
clearItem();
heal();
}
@Override
public boolean offloadImmediately(){
return true;
}
@Override
public TypeID getTypeID(){
return TypeIDs.player;
}
@Override
public UnitDef type(){
return mech;
}
@Override
public Weapons getWeapons(){
return null;
}
@Override
public void move(float x, float y){
if(!mech.flying){
collisions.move(this, x, y);
}else{
moveBy(x, y);
}
}
@Override
public float getMinePower(){
return mech.minePower;
}
@Override
public TextureRegion getIconRegion(){
return mech.icon(Cicon.full);
}
@Override
public void interpolate(){
super.interpolate();
if(interpolator.values.length > 1){
baseRotation = interpolator.values[1];
}
if(interpolator.target.dst(interpolator.last) > 1f){
walktime += Time.delta();
}
}
@Override
public float getBuildPower(Tile tile){
return mech.buildPower;
}
@Override
public float maxHealth(){
return mech.health * state.rules.playerHealthMultiplier;
}
@Override
public Tile getMineTile(){
return mining;
}
@Override
public void setMineTile(Tile tile){
this.mining = tile;
}
@Override
public boolean canMine(Item item){
return item.hardness <= mech.drillTier;
}
@Override
public float calculateDamage(float amount){
return amount * Mathf.clamp(1f - (status.getArmorMultiplier() + mech.getExtraArmor(this)) / 100f);
}
@Override
public void added(){
baseRotation = 90f;
}
@Override
public float mass(){
return mech.mass;
}
@Override
public boolean isFlying(){
return mech.flying || boostHeat > liftoffBoost;
}
@Override
public void damage(float amount){
hitTime = hitDuration;
if(!net.client()){
health -= calculateDamage(amount);
}
if(health <= 0 && !dead){
Call.onPlayerDeath(this);
}
}
@Override
public void set(float x, float y){
this.x = x;
this.y = y;
}
@Override
public Queue<BuildRequest> buildQueue(){
return placeQueue;
}
@Override
public String toString(){
return "Player{" + name + ", mech=" + mech.name + ", id=" + id + ", local=" + isLocal + ", " + x + ", " + y + "}";
}
@Override
public EntityGroup targetGroup(){
return playerGroup;
}
public void team(Team team){
this.team = team;
}
//endregion
//region draw methods
@Override
public float drawSize(){
return isLocal ? Float.MAX_VALUE : 40 + placeDistance;
}
@Override
public void drawShadow(float offsetX, float offsetY){
float scl = mech.flying ? 1f : boostHeat / 2f;
Draw.rect(getIconRegion(), x + offsetX * scl, y + offsetY * scl, rotation - 90);
}
@Override
public void draw(){
if(dead) return;
if(!movement.isZero() && moved && !state.isPaused()){
walktime += movement.len() * getFloorOn().speedMultiplier * 2f;
baseRotation = Mathf.slerpDelta(baseRotation, movement.angle(), 0.13f);
}
float ft = Mathf.sin(walktime, 6f, 2f) * (1f - boostHeat);
Floor floor = getFloorOn();
Draw.color();
Draw.mixcol(Color.white, hitTime / hitDuration);
if(!mech.flying){
if(floor.isLiquid){
Draw.color(Color.white, floor.color, 0.5f);
}
float boostTrnsY = -boostHeat * 3f;
float boostTrnsX = boostHeat * 3f;
float boostAng = boostHeat * 40f;
float light = 0.2f;
for(int i : Mathf.signs){
Draw.colorl(1f-light + Mathf.clamp(ft * i, 0, 1) *light);
Draw.rect(mech.legRegion,
x + Angles.trnsx(baseRotation, ft * i + boostTrnsY, -boostTrnsX * i),
y + Angles.trnsy(baseRotation, ft * i + boostTrnsY, -boostTrnsX * i),
mech.legRegion.getWidth() * i * Draw.scl,
(mech.legRegion.getHeight() - Mathf.clamp(ft * i, 0, 2)) * Draw.scl,
baseRotation - 90 + boostAng * i);
}
Draw.color();
Draw.rect(mech.baseRegion, x, y, baseRotation - 90);
}
if(floor.isLiquid){
Draw.color(Color.white, floor.color, drownTime);
}else{
Draw.color(Color.white);
}
Draw.rect(mech.region, x, y, rotation - 90);
mech.draw(this);
weapons.draw(this);
Draw.reset();
}
public void drawBackItems(){
drawBackItems(itemtime, isLocal);
}
@Override
public void drawStats(){
mech.drawStats(this);
}
@Override
public void drawOver(){
if(dead) return;
if(isBuilding() && isBuilding){
if(!state.isPaused()){
drawBuilding();
}
}else{
drawMining();
}
}
@Override
public void drawUnder(){
if(dead) return;
float size = mech.engineSize * (mech.flying ? 1f : boostHeat);
Draw.color(mech.engineColor);
Fill.circle(x + Angles.trnsx(rotation + 180, mech.engineOffset), y + Angles.trnsy(rotation + 180, mech.engineOffset),
size + Mathf.absin(Time.time(), 2f, size / 4f));
Draw.color(Color.white);
Fill.circle(x + Angles.trnsx(rotation + 180, mech.engineOffset - 1f), y + Angles.trnsy(rotation + 180, mech.engineOffset - 1f),
(size + Mathf.absin(Time.time(), 2f, size / 4f)) / 2f);
Draw.color();
}
public void drawName(){
BitmapFont font = Fonts.def;
GlyphLayout layout = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
final float nameHeight = 11;
final float textHeight = 15;
boolean ints = font.usesIntegerPositions();
font.setUseIntegerPositions(false);
font.getData().setScale(0.25f / Scl.scl(1f));
layout.setText(font, name);
if(!isLocal){
Draw.color(0f, 0f, 0f, 0.3f);
Fill.rect(x, y + nameHeight - layout.height / 2, layout.width + 2, layout.height + 3);
Draw.color();
font.setColor(color);
font.draw(name, x, y + nameHeight, 0, Align.center, false);
if(isAdmin){
float s = 3f;
Draw.color(color.r * 0.5f, color.g * 0.5f, color.b * 0.5f, 1f);
Draw.rect(Icon.adminSmall.getRegion(), x + layout.width / 2f + 2 + 1, y + nameHeight - 1.5f, s, s);
Draw.color(color);
Draw.rect(Icon.adminSmall.getRegion(), x + layout.width / 2f + 2 + 1, y + nameHeight - 1f, s, s);
}
}
if(Core.settings.getBool("playerchat") && ((textFadeTime > 0 && lastText != null) || isTyping)){
String text = textFadeTime <= 0 || lastText == null ? "[LIGHT_GRAY]" + Strings.animated(Time.time(), 4, 15f, ".") : lastText;
float width = 100f;
float visualFadeTime = 1f - Mathf.curve(1f - textFadeTime, 0.9f);
font.setColor(1f, 1f, 1f, textFadeTime <= 0 || lastText == null ? 1f : visualFadeTime);
layout.setText(font, text, Color.white, width, Align.bottom, true);
Draw.color(0f, 0f, 0f, 0.3f * (textFadeTime <= 0 || lastText == null ? 1f : visualFadeTime));
Fill.rect(x, y + textHeight + layout.height - layout.height/2f, layout.width + 2, layout.height + 3);
font.draw(text, x - width/2f, y + textHeight + layout.height, width, Align.center, true);
}
Draw.reset();
Pools.free(layout);
font.getData().setScale(1f);
font.setColor(Color.white);
font.setUseIntegerPositions(ints);
}
/** Draw all current build requests. Does not draw the beam effect, only the positions. */
public void drawBuildRequests(){
if(!isLocal) return;
for(BuildRequest request : buildQueue()){
if(request.progress > 0.01f || (buildRequest() == request && request.initialized && (dst(request.x * tilesize, request.y * tilesize) <= placeDistance || state.isEditor()))) continue;
request.animScale = 1f;
if(request.breaking){
control.input.drawBreaking(request);
}else{
request.block.drawRequest(request, control.input.allRequests(),
Build.validPlace(team(), request.x, request.y, request.block, request.rotation) || control.input.requestMatches(request));
}
}
Draw.reset();
}
//endregion
//region update methods
@Override
public void updateMechanics(){
if(isBuilding){
updateBuilding();
}
//mine only when not building
if(buildRequest() == null || !isBuilding){
updateMining();
}
}
@Override
public void update(){
hitTime -= Time.delta();
textFadeTime -= Time.delta() / (60 * 5);
itemtime = Mathf.lerpDelta(itemtime, Mathf.num(item.amount > 0), 0.1f);
if(Float.isNaN(x) || Float.isNaN(y)){
velocity.set(0f, 0f);
x = 0;
y = 0;
dead(true);
}
if(netServer.isWaitingForPlayers()){
dead(true);
}
if(!dead() && isOutOfBounds()){
destructTime += Time.delta();
if(destructTime >= boundsCountdown){
kill();
}
}else{
destructTime = 0f;
}
if(!dead() && isFlying()){
loops.play(Sounds.thruster, this, Mathf.clamp(velocity.len() * 2f) * 0.3f);
}
BuildRequest request = buildRequest();
if(isBuilding() && isBuilding && request.tile() != null && (request.tile().withinDst(x, y, placeDistance) || state.isEditor())){
loops.play(Sounds.build, request.tile(), 0.75f);
}
if(dead()){
isBoosting = false;
boostHeat = 0f;
if(respawns > 0 || !state.rules.limitedRespawns){
updateRespawning();
}
return;
}else{
spawner = null;
}
if(isLocal || net.server()){
avoidOthers();
}
Tile tile = world.tileWorld(x, y);
boostHeat = Mathf.lerpDelta(boostHeat, (tile != null && tile.solid()) || (isBoosting && ((!movement.isZero() && moved) || !isLocal)) ? 1f : 0f, 0.08f);
shootHeat = Mathf.lerpDelta(shootHeat, isShooting() ? 1f : 0f, 0.06f);
mech.update(this); //updated regardless
if(boostHeat > liftoffBoost + 0.1f){
achievedFlight = true;
}
if(boostHeat <= liftoffBoost + 0.05f && achievedFlight && !mech.flying){
if(tile != null){
Fx.unitLand.at(x, y, tile.floor().isLiquid ? 1f : 0.5f, tile.floor().color);
}
mech.onLand(this);
achievedFlight = false;
}
if(!isLocal){
interpolate();
updateMechanics(); //building happens even with non-locals
status.update(this); //status effect updating also happens with non locals for effect purposes
updateVelocityStatus(); //velocity too, for visual purposes
if(net.server()){
updateShooting(); //server simulates player shooting
}
return;
}else if(world.isZone()){
//unlock mech when used
data.unlockContent(mech);
}
if(control.input instanceof MobileInput){
updateTouch();
}else{
updateKeyboard();
}
isTyping = ui.chatfrag.shown();
updateMechanics();
if(!mech.flying){
clampPosition();
}
}
protected void updateKeyboard(){
Tile tile = world.tileWorld(x, y);
boolean canMove = !Core.scene.hasKeyboard() || ui.minimapfrag.shown();
isBoosting = Core.input.keyDown(Binding.dash) && !mech.flying;
//if player is in solid block
if(tile != null && tile.solid()){
isBoosting = true;
}
float speed = isBoosting && !mech.flying ? mech.boostSpeed : mech.speed;
if(mech.flying){
//prevent strafing backwards, have a penalty for doing so
float penalty = 0.2f; //when going 180 degrees backwards, reduce speed to 0.2x
speed *= Mathf.lerp(1f, penalty, Angles.angleDist(rotation, velocity.angle()) / 180f);
}
movement.setZero();
float xa = Core.input.axis(Binding.move_x);
float ya = Core.input.axis(Binding.move_y);
if(!(Core.scene.getKeyboardFocus() instanceof TextField)){
movement.y += ya * speed;
movement.x += xa * speed;
}
if(Core.input.keyDown(Binding.mouse_move)){
movement.x += Mathf.clamp((Core.input.mouseX() - Core.graphics.getWidth() / 2f) * 0.005f, -1, 1) * speed;
movement.y += Mathf.clamp((Core.input.mouseY() - Core.graphics.getHeight() / 2f) * 0.005f, -1, 1) * speed;
}
Vec2 vec = Core.input.mouseWorld(control.input.getMouseX(), control.input.getMouseY());
pointerX = vec.x;
pointerY = vec.y;
updateShooting();
movement.limit(speed).scl(Time.delta());
if(canMove){
velocity.add(movement.x, movement.y);
}else{
isShooting = false;
}
float prex = x, prey = y;
updateVelocityStatus();
moved = dst(prex, prey) > 0.001f;
if(canMove){
float baseLerp = mech.getRotationAlpha(this);
if(!isShooting() || !mech.faceTarget){
if(!movement.isZero()){
rotation = Mathf.slerpDelta(rotation, mech.flying ? velocity.angle() : movement.angle(), 0.13f * baseLerp);
}
}else{
float angle = control.input.mouseAngle(x, y);
this.rotation = Mathf.slerpDelta(this.rotation, angle, 0.1f * baseLerp);
}
}
}
protected void updateShooting(){
if(!state.isEditor() && isShooting() && mech.canShoot(this)){
weapons.update(this);
//if(!mech.turnCursor){
//shoot forward ignoring cursor
//mech.weapon.update(this, x + Angles.trnsx(rotation, mech.weapon.targetDistance), y + Angles.trnsy(rotation, mech.weapon.targetDistance));
//}else{
//mech.weapon.update(this, pointerX, pointerY);
//}
}
}
protected void updateTouch(){
if(Units.invalidateTarget(target, this) &&
!(target instanceof Tilec && ((Tilec)target).damaged() && target.isValid() && target.team() == team && mech.canHeal && dst(target) < mech.range && !(((Tilec)target).block instanceof BuildBlock))){
target = null;
}
if(state.isEditor()){
target = null;
}
float targetX = Core.camera.position.x, targetY = Core.camera.position.y;
float attractDst = 15f;
float speed = isBoosting && !mech.flying ? mech.boostSpeed : mech.speed;
if(moveTarget != null && !moveTarget.dead()){
targetX = moveTarget.getX();
targetY = moveTarget.getY();
boolean tapping = moveTarget instanceof Tilec && moveTarget.team() == team;
attractDst = 0f;
if(tapping){
velocity.setAngle(angleTo(moveTarget));
}
if(dst(moveTarget) <= 2f * Time.delta()){
if(tapping && !dead()){
Tile tile = ((Tilec)moveTarget).tile;
tile.block().tapped(tile, this);
}
moveTarget = null;
}
}else{
moveTarget = null;
}
movement.set((targetX - x) / Time.delta(), (targetY - y) / Time.delta()).limit(speed);
movement.setAngle(Mathf.slerp(movement.angle(), velocity.angle(), 0.05f));
if(dst(targetX, targetY) < attractDst){
movement.setZero();
}
float expansion = 3f;
hitbox(rect);
rect.x -= expansion;
rect.y -= expansion;
rect.width += expansion * 2f;
rect.height += expansion * 2f;
isBoosting = collisions.overlapsTile(rect) || dst(targetX, targetY) > 85f;
velocity.add(movement.scl(Time.delta()));
if(velocity.len() <= 0.2f && mech.flying){
rotation += Mathf.sin(Time.time() + id * 99, 10f, 1f);
}else if(target == null){
rotation = Mathf.slerpDelta(rotation, velocity.angle(), velocity.len() / 10f);
}
float lx = x, ly = y;
updateVelocityStatus();
moved = dst(lx, ly) > 0.001f;
if(mech.flying){
//hovering effect
x += Mathf.sin(Time.time() + id * 999, 25f, 0.08f);
y += Mathf.cos(Time.time() + id * 999, 25f, 0.08f);
}
//update shooting if not building, not mining and there's ammo left
if(!isBuilding() && getMineTile() == null){
//autofire
if(target == null){
isShooting = false;
if(Core.settings.getBool("autotarget")){
target = Units.closestTarget(team, x, y, mech.range, u -> u.team() != Team.derelict, u -> u.getTeam() != Team.derelict);
if(mech.canHeal && target == null){
target = Geometry.findClosest(x, y, indexer.getDamaged(Team.sharded));
if(target != null && dst(target) > mech.range){
target = null;
}else if(target != null){
target = ((Tile)target).entity;
}
}
if(target != null){
setMineTile(null);
}
}
}else if(target.isValid() || (target instanceof Tilec && ((Tilec)target).damaged() && target.team() == team && mech.canHeal && dst(target) < mech.range)){
//rotate toward and shoot the target
if(mech.faceTarget){
rotation = Mathf.slerpDelta(rotation, angleTo(target), 0.2f);
}
Vec2 intercept = Predict.intercept(this, target, getWeapon().bullet.speed);
pointerX = intercept.x;
pointerY = intercept.y;
updateShooting();
isShooting = true;
}
}
}
//endregion
//region utility methods
public void sendMessage(String text){
if(isLocal){
if(Vars.ui != null){
Vars.ui.chatfrag.addMessage(text, null);
}
}else{
Call.sendMessage(con, text, null, null);
}
}
public void sendMessage(String text, Player from){
sendMessage(text, from, NetClient.colorizeName(from.id, from.name));
}
public void sendMessage(String text, Player from, String fromName){
if(isLocal){
if(Vars.ui != null){
Vars.ui.chatfrag.addMessage(text, fromName);
}
}else{
Call.sendMessage(con, text, fromName, from);
}
}
public PlayerInfo getInfo(){
if(uuid == null){
throw new IllegalArgumentException("Local players cannot be traced and do not have info.");
}else{
return netServer.admins.getInfo(uuid);
}
}
/** Resets all values of the player. */
public void reset(){
resetNoAdd();
add();
}
public void resetNoAdd(){
status.clear();
team = Team.sharded;
item.amount = 0;
placeQueue.clear();
dead = true;
lastText = null;
isBuilding = true;
textFadeTime = 0f;
target = null;
moveTarget = null;
isShooting = isBoosting = isTransferring = isTyping = false;
spawner = lastSpawner = null;
health = maxHealth();
mining = null;
boostHeat = drownTime = hitTime = 0f;
mech = Mechs.starter;
placeQueue.clear();
respawns = state.rules.respawns;
}
public boolean isShooting(){
return isShooting && (boostHeat < 0.1f || mech.flying) && mining == null;
}
public void updateRespawning(){
if(state.isEditor()){
//instant respawn at center of map.
set(world.width() * tilesize/2f, world.height() * tilesize/2f);
dead(false);
}else if(spawner != null && spawner.isValid()){
spawner.updateSpawning(this);
}else if(!netServer.isWaitingForPlayers()){
if(!net.client()){
if(lastSpawner != null && lastSpawner.isValid()){
this.spawner = lastSpawner;
}else if(closestCore() != null){
this.spawner = (SpawnerTrait)closestCore();
}
}
}else if(closestCore() != null){
set(closestCore().getX(), closestCore().getY());
}
}
public void beginRespawning(SpawnerTrait spawner){
this.spawner = spawner;
this.lastSpawner = spawner;
this.dead = true;
setNet(spawner.getX(), spawner.getY());
spawner.updateSpawning(this);
}
//endregion
//region read and write methods
@Override
public byte version(){
return 0;
}
@Override
public void writeSave(DataOutput stream) throws IOException{
stream.writeBoolean(isLocal);
if(isLocal){
stream.writeByte(mech.id);
stream.writeInt(lastSpawner == null ? noSpawner : lastSpawner.getTile().pos());
super.writeSave(stream, false);
}
}
@Override
public void readSave(DataInput stream, byte version) throws IOException{
boolean local = stream.readBoolean();
if(local){
byte mechid = stream.readByte();
int spawner = stream.readInt();
Tile stile = world.tile(spawner);
Player player = headless ? this : Vars.player;
player.readSaveSuper(stream, version);
player.mech = content.getByID(ContentType.mech, mechid);
player.dead = false;
if(stile != null && stile.entity instanceof SpawnerTrait){
player.lastSpawner = (SpawnerTrait)stile.entity;
}
}
}
private void readSaveSuper(DataInput stream, byte version) throws IOException{
super.readSave(stream, version);
add();
}
@Override
public void write(DataOutput buffer) throws IOException{
super.writeSave(buffer, !isLocal);
TypeIO.writeStringData(buffer, name);
buffer.writeByte(Pack.byteValue(isAdmin) | (Pack.byteValue(dead) << 1) | (Pack.byteValue(isBoosting) << 2) | (Pack.byteValue(isTyping) << 3)| (Pack.byteValue(isBuilding) << 4));
buffer.writeInt(Color.rgba8888(color));
buffer.writeByte(mech.id);
buffer.writeInt(mining == null ? noSpawner : mining.pos());
buffer.writeInt(spawner == null || !spawner.hasUnit(this) ? noSpawner : spawner.getTile().pos());
buffer.writeShort((short)(baseRotation * 2));
writeBuilding(buffer);
}
@Override
public void read(DataInput buffer) throws IOException{
float lastx = x, lasty = y, lastrot = rotation, lastvx = velocity.x, lastvy = velocity.y;
super.readSave(buffer, version());
name = TypeIO.readStringData(buffer);
byte bools = buffer.readByte();
isAdmin = (bools & 1) != 0;
dead = (bools & 2) != 0;
boolean boosting = (bools & 4) != 0;
isTyping = (bools & 8) != 0;
boolean building = (bools & 16) != 0;
color.set(buffer.readInt());
mech = content.getByID(ContentType.mech, buffer.readByte());
int mine = buffer.readInt();
int spawner = buffer.readInt();
float baseRotation = buffer.readShort() / 2f;
readBuilding(buffer, !isLocal);
interpolator.read(lastx, lasty, x, y, rotation, baseRotation);
rotation = lastrot;
x = lastx;
y = lasty;
if(isLocal){
velocity.x = lastvx;
velocity.y = lastvy;
}else{
mining = world.tile(mine);
isBuilding = building;
isBoosting = boosting;
}
Tile tile = world.tile(spawner);
if(tile != null && tile.entity instanceof SpawnerTrait){
this.spawner = (SpawnerTrait)tile.entity;
}else{
this.spawner = null;
}
}
//endregion
}

View File

@@ -1,68 +0,0 @@
package mindustry.entities.type.base;
import arc.math.Mathf;
import arc.math.geom.Geometry;
import mindustry.entities.units.*;
import mindustry.world.Tile;
import mindustry.world.meta.BlockFlag;
import static mindustry.Vars.*;
public abstract class BaseDrone extends FlyingUnit{
public final StateMachine.UnitState retreat = new StateMachine.UnitState(){
public void entered(){
target = null;
}
public void update(){
if(health >= maxHealth()){
state.set(getStartState());
}else if(!targetHasFlag(BlockFlag.repair)){
if(retarget()){
Tile repairPoint = Geometry.findClosest(x, y, indexer.getAllied(team, BlockFlag.repair));
if(repairPoint != null){
target = repairPoint;
}else{
setState(getStartState());
}
}
}else{
circle(40f);
}
}
};
@Override
public boolean countsAsEnemy(){
return false;
}
@Override
public void onCommand(UnitCommand command){
//do nothing, normal commands are not applicable here
}
@Override
protected void updateRotation(){
if(target != null && shouldRotate() && target.dst(this) < type.range){
rotation = Mathf.slerpDelta(rotation, angleTo(target), 0.3f);
}else{
rotation = Mathf.slerpDelta(rotation, velocity.angle(), 0.3f);
}
}
@Override
public void behavior(){
if(health <= maxHealth() * type.retreatPercent && !state.is(retreat) && Geometry.findClosest(x, y, indexer.getAllied(team, BlockFlag.repair)) != null){
setState(retreat);
}
}
public boolean shouldRotate(){
return state.is(getStartState());
}
@Override
public abstract StateMachine.UnitState getStartState();
}

View File

@@ -1,238 +0,0 @@
package mindustry.entities.type.base;
import arc.*;
import arc.math.*;
import arc.struct.*;
import arc.util.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*;
import mindustry.game.Teams.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.blocks.BuildBlock.*;
import java.io.*;
import static mindustry.Vars.*;
public class BuilderDrone extends BaseDrone implements BuilderTrait{
private static final StaticReset reset = new StaticReset();
private static final IntIntMap totals = new IntIntMap();
protected Queue<BuildRequest> placeQueue = new Queue<>();
protected BuildRequest lastFound;
protected boolean isBreaking;
protected Player playerTarget;
public final StateMachine.UnitState
build = new StateMachine.UnitState(){
public void entered(){
if(!(target instanceof BuildEntity)){
target = null;
}
}
public void update(){
BuildEntity entity = (BuildEntity)target;
Tilec core = getClosestCore();
if(isBuilding() && entity == null && canRebuild()){
target = world.tile(buildRequest().x, buildRequest().y);
circle(placeDistance * 0.7f);
target = null;
BuildRequest request = buildRequest();
if(world.tile(request.x, request.y).entity instanceof BuildEntity){
target = world.tile(request.x, request.y).entity;
}
}else if(entity != null && core != null && (entity.progress < 1f || entity.progress > 0f) && entity.tile.block() instanceof BuildBlock){ //building is valid
if(!isBuilding() && dst(target) < placeDistance * 0.9f){ //within distance, begin placing
if(isBreaking){
buildQueue().addLast(new BuildRequest(entity.tile.x, entity.tile.y));
}else{
buildQueue().addLast(new BuildRequest(entity.tile.x, entity.tile.y, entity.tile.rotation(), entity.cblock));
if(lastFound != null && lastFound.hasConfig){
buildQueue().last().configure(lastFound.config);
}
}
}
circle(placeDistance * 0.7f);
velocity.scl(0.74f);
}else{ //else, building isn't valid, follow a player
target = null;
if(playerTarget == null || playerTarget.team() != team || !playerTarget.isValid()){
playerTarget = null;
if(retarget()){
float minDst = Float.POSITIVE_INFINITY;
int minDrones = Integer.MAX_VALUE;
//find player with min amount of drones
for(Player player : playerGroup.all()){
if(player.team() == team){
int drones = getDrones(player);
float dst = dst2(player);
if(playerTarget == null || drones < minDrones || (drones == minDrones && dst < minDst)){
minDrones = drones;
minDst = dst;
playerTarget = player;
}
}
}
}
if(getSpawner() != null){
target = getSpawner();
circle(40f);
target = null;
}
}else{
incDrones(playerTarget);
Teamc prev = target;
target = playerTarget;
float dst = 90f + (id % 10)*3;
float tdst = dst(target);
float scale = (Mathf.lerp(1f, 0.2f, 1f - Mathf.clamp((tdst - dst) / dst)));
circle(dst);
velocity.scl(scale);
target = prev;
}
}
}
};
public BuilderDrone(){
if(reset.check()){
Events.on(BuildSelectEvent.class, event -> {
if(!(event.tile.entity instanceof BuildEntity)) return;
for(BaseUnit unit : unitGroup.all()){
if(unit instanceof BuilderDrone && unit.getTeam() == getTeam()){
BuilderDrone drone = (BuilderDrone)unit;
if(drone.isBuilding()){
//stop building if opposite building begins.
BuildRequest req = drone.buildRequest();
if(req.breaking != event.breaking && req.x == event.tile.x && req.y == event.tile.y){
drone.clearBuilding();
drone.target = null;
}
}
}
}
});
}
}
int getDrones(Player player){
return Pack.leftShort(totals.get(player.id, 0));
}
void incDrones(Player player){
int num = totals.get(player.id, 0);
int amount = Pack.leftShort(num), frame = Pack.rightShort(num);
short curFrame = (short)(Core.graphics.getFrameId() % Short.MAX_VALUE);
if(frame != curFrame){
totals.put(player.id, Pack.shortInt((short)1, curFrame));
}else{
totals.put(player.id, Pack.shortInt((short)(amount + 1), curFrame));
}
}
boolean canRebuild(){
return true;
}
@Override
public float getBuildPower(Tile tile){
return type.buildPower;
}
@Override
public Queue<BuildRequest> buildQueue(){
return placeQueue;
}
@Override
public void update(){
super.update();
if(!isBuilding() && timer.get(timerTarget2, 15)){
for(Player player : playerGroup.all()){
if(player.team() == team && player.buildRequest() != null){
BuildRequest req = player.buildRequest();
Tile tile = world.tile(req.x, req.y);
if(tile != null && tile.entity instanceof BuildEntity){
BuildEntity b = tile.ent();
float dist = Math.min(b.dst(x, y) - placeDistance, 0);
if(dist / type.maxVelocity < b.buildCost * 0.9f){
lastFound = req;
target = b;
this.isBreaking = req.breaking;
setState(build);
break;
}
}
}
}
if(timer.get(timerTarget, 80) && Units.closestEnemy(getTeam(), x, y, 100f, u -> !(u instanceof BaseDrone)) == null && !isBuilding()){
TeamData data = team.data();
if(!data.brokenBlocks.isEmpty()){
BrokenBlock block = data.brokenBlocks.removeLast();
if(Build.validPlace(getTeam(), block.x, block.y, content.block(block.block), block.rotation)){
placeQueue.addFirst(new BuildRequest(block.x, block.y, block.rotation, content.block(block.block)).configure(block.config));
setState(build);
}
}
}
}
updateBuilding();
}
@Override
public boolean shouldRotate(){
return isBuilding();
}
@Override
public StateMachine.UnitState getStartState(){
return build;
}
@Override
public void drawOver(){
drawBuilding();
}
@Override
public float drawSize(){
return isBuilding() ? placeDistance * 2f : 30f;
}
@Override
public boolean canCreateBlocks(){
return true;
}
@Override
public void write(DataOutput data) throws IOException{
super.write(data);
writeBuilding(data);
}
@Override
public void read(DataInput data) throws IOException{
super.read(data);
readBuilding(data);
}
}

View File

@@ -1,255 +0,0 @@
package mindustry.entities.type.base;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import mindustry.*;
import mindustry.entities.*;
import mindustry.entities.bullet.*;
import mindustry.entities.units.*;
import mindustry.graphics.*;
import mindustry.world.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
public class FlyingUnit extends BaseUnit{
protected float[] weaponAngles = {0,0};
protected final StateMachine.UnitState
attack = new StateMachine.UnitState(){
public void entered(){
target = null;
}
public void update(){
if(Units.invalidateTarget(target, team, x, y)){
target = null;
}
if(retarget()){
targetClosest();
if(target == null) targetClosestEnemyFlag(BlockFlag.producer);
if(target == null) targetClosestEnemyFlag(BlockFlag.turret);
if(target == null && isCommanded() && getCommand() != UnitCommand.attack){
onCommand(getCommand());
}
}
if(getClosestSpawner() == null && getSpawner() != null && target == null){
target = getSpawner();
circle(80f + Mathf.randomSeed(id) * 120);
}else if(target != null){
attack(type.attackLength);
if((Angles.near(angleTo(target), rotation, type.shootCone) || getWeapon().ignoreRotation) //bombers and such don't care about rotation
&& dst(target) < getWeapon().bullet.range()){
BulletType ammo = getWeapon().bullet;
if(type.rotateWeapon){
for(boolean left : Mathf.booleans){
int wi = Mathf.num(left);
float wx = x + Angles.trnsx(rotation - 90, getWeapon().width * Mathf.sign(left));
float wy = y + Angles.trnsy(rotation - 90, getWeapon().width * Mathf.sign(left));
weaponAngles[wi] = Mathf.slerpDelta(weaponAngles[wi], Angles.angle(wx, wy, target.getX(), target.getY()), 0.1f);
Tmp.v2.trns(weaponAngles[wi], getWeapon().length);
getWeapon().update(FlyingUnit.this, wx + Tmp.v2.x, wy + Tmp.v2.y, weaponAngles[wi], left);
}
}else{
Vec2 to = Predict.intercept(FlyingUnit.this, target, ammo.speed);
getWeapon().update(FlyingUnit.this, to.x, to.y);
}
}
}else{
target = getClosestSpawner();
moveTo(Vars.state.rules.dropZoneRadius + 120f);
}
}
},
rally = new StateMachine.UnitState(){
public void update(){
if(retarget()){
targetClosestAllyFlag(BlockFlag.rally);
targetClosest();
if(target != null && !Units.invalidateTarget(target, team, x, y)){
setState(attack);
return;
}
if(target == null) target = getSpawner();
}
if(target != null){
circle(65f + Mathf.randomSeed(id) * 100);
}
}
},
retreat = new StateMachine.UnitState(){
public void entered(){
target = null;
}
public void update(){
if(retarget()){
target = getSpawner();
Tile repair = Geometry.findClosest(x, y, indexer.getAllied(team, BlockFlag.repair));
if(repair != null && damaged()) FlyingUnit.this.target = repair.entity;
if(target == null) target = getClosestCore();
}
circle(targetHasFlag(BlockFlag.repair) ? 20f : 60f + Mathf.randomSeed(id) * 50, 0.65f * type.speed);
}
};;
@Override
public void onCommand(UnitCommand command){
state.set(command == UnitCommand.retreat ? retreat :
command == UnitCommand.attack ? attack :
command == UnitCommand.rally ? rally :
null);
}
@Override
public void move(float x, float y){
moveBy(x, y);
}
@Override
public void update(){
super.update();
if(!net.client()){
updateRotation();
}
wobble();
}
@Override
public void drawUnder(){
drawEngine();
}
@Override
public void draw(){
Draw.mixcol(Color.white, hitTime / hitDuration);
Draw.rect(type.region, x, y, rotation - 90);
drawWeapons();
Draw.mixcol();
}
public void drawWeapons(){
for(int i : Mathf.signs){
float tra = rotation - 90, trY = -type.weapon.getRecoil(this, i > 0) + type.weaponOffsetY;
float w = -i * type.weapon.region.getWidth() * Draw.scl;
Draw.rect(type.weapon.region,
x + Angles.trnsx(tra, getWeapon().width * i, trY),
y + Angles.trnsy(tra, getWeapon().width * i, trY), w, type.weapon.region.getHeight() * Draw.scl, rotation - 90);
}
}
public void drawEngine(){
Draw.color(Pal.engine);
Fill.circle(x + Angles.trnsx(rotation + 180, type.engineOffset), y + Angles.trnsy(rotation + 180, type.engineOffset),
type.engineSize + Mathf.absin(Time.time(), 2f, type.engineSize / 4f));
Draw.color(Color.white);
Fill.circle(x + Angles.trnsx(rotation + 180, type.engineOffset - 1f), y + Angles.trnsy(rotation + 180, type.engineOffset - 1f),
(type.engineSize + Mathf.absin(Time.time(), 2f, type.engineSize / 4f)) / 2f);
Draw.color();
}
@Override
public void behavior(){
if(Units.invalidateTarget(target, this)){
for(boolean left : Mathf.booleans){
int wi = Mathf.num(left);
weaponAngles[wi] = Mathf.slerpDelta(weaponAngles[wi], rotation, 0.1f);
}
}
}
@Override
public StateMachine.UnitState getStartState(){
return attack;
}
protected void wobble(){
if(net.client()) return;
x += Mathf.sin(Time.time() + id * 999, 25f, 0.05f) * Time.delta();
y += Mathf.cos(Time.time() + id * 999, 25f, 0.05f) * Time.delta();
if(velocity.len() <= 0.05f){
//rotation += Mathf.sin(Time.time() + id * 99, 10f, 2f * type.speed)*Time.delta();
}
}
protected void updateRotation(){
rotation = velocity.angle();
}
protected void circle(float circleLength){
circle(circleLength, type.speed);
}
protected void circle(float circleLength, float speed){
if(target == null) return;
Tmp.v1.set(target.getX() - x, target.getY() - y);
if(Tmp.v1.len() < circleLength){
Tmp.v1.rotate((circleLength - Tmp.v1.len()) / circleLength * 180f);
}
Tmp.v1.setLength(speed * Time.delta());
velocity.add(Tmp.v1);
}
protected void moveTo(float circleLength){
if(target == null) return;
Tmp.v1.set(target.getX() - x, target.getY() - y);
float length = circleLength <= 0.001f ? 1f : Mathf.clamp((dst(target) - circleLength) / 100f, -1f, 1f);
Tmp.v1.setLength(type.speed * Time.delta() * length);
if(length < -0.5f){
Tmp.v1.rotate(180f);
}else if(length < 0){
Tmp.v1.setZero();
}
velocity.add(Tmp.v1);
}
protected void attack(float circleLength){
Tmp.v1.set(target.getX() - x, target.getY() - y);
float ang = angleTo(target);
float diff = Angles.angleDist(ang, rotation);
if(diff > 100f && Tmp.v1.len() < circleLength){
Tmp.v1.setAngle(velocity.angle());
}else{
Tmp.v1.setAngle(Mathf.slerpDelta(velocity.angle(), Tmp.v1.angle(), 0.44f));
}
Tmp.v1.setLength(type.speed * Time.delta());
velocity.add(Tmp.v1);
}
}

View File

@@ -1,259 +0,0 @@
package mindustry.entities.type.base;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import mindustry.*;
import mindustry.ai.Pathfinder.*;
import mindustry.entities.*;
import mindustry.entities.bullet.*;
import mindustry.entities.units.*;
import mindustry.game.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
public class GroundUnit extends BaseUnit{
protected static Vec2 vec = new Vec2();
protected float walkTime;
protected float stuckTime;
protected float baseRotation;
public final StateMachine.UnitState
attack = new StateMachine.UnitState(){
public void entered(){
target = null;
}
public void update(){
Tilec core = getClosestEnemyCore();
if(core == null){
Tile closestSpawn = getClosestSpawner();
if(closestSpawn == null || !withinDst(closestSpawn, Vars.state.rules.dropZoneRadius + 85f)){
moveToCore(PathTarget.enemyCores);
}
}else{
float dst = dst(core);
if(dst < getWeapon().bullet.range() / 1.1f){
target = core;
}
if(dst > getWeapon().bullet.range() * 0.5f){
moveToCore(PathTarget.enemyCores);
}
}
}
},
rally = new StateMachine.UnitState(){
public void update(){
Tile target = getClosest(BlockFlag.rally);
if(target != null && dst(target) > 80f){
moveToCore(PathTarget.rallyPoints);
}
}
},
retreat = new StateMachine.UnitState(){
public void entered(){
target = null;
}
public void update(){
moveAwayFromCore();
}
};
@Override
public void onCommand(UnitCommand command){
state.set(command == UnitCommand.retreat ? retreat :
command == UnitCommand.attack ? attack :
command == UnitCommand.rally ? rally :
null);
}
@Override
public void interpolate(){
super.interpolate();
if(interpolator.values.length > 1){
baseRotation = interpolator.values[1];
}
}
@Override
public void move(float x, float y){
float dst = Mathf.dst(x, y);
if(dst > 0.01f){
baseRotation = Mathf.slerp(baseRotation, Mathf.angle(x, y), type.baseRotateSpeed * (dst / type.speed));
}
super.move(x, y);
}
@Override
public StateMachine.UnitState getStartState(){
return attack;
}
@Override
public void update(){
super.update();
stuckTime = !vec.set(x, y).sub(lastPosition()).isZero(0.0001f) ? 0f : stuckTime + Time.delta();
if(!velocity.isZero()){
baseRotation = Mathf.slerpDelta(baseRotation, velocity.angle(), 0.05f);
}
if(stuckTime < 1f){
walkTime += Time.delta();
}
}
@Override
public void draw(){
Draw.mixcol(Color.white, hitTime / hitDuration);
float ft = Mathf.sin(walkTime * type.speed * 5f, 6f, 2f + type.hitsize / 15f);
Floor floor = getFloorOn();
if(floor.isLiquid){
Draw.color(Color.white, floor.color, 0.5f);
}
for(int i : Mathf.signs){
Draw.rect(type.legRegion,
x + Angles.trnsx(baseRotation, ft * i),
y + Angles.trnsy(baseRotation, ft * i),
type.legRegion.getWidth() * i * Draw.scl, type.legRegion.getHeight() * Draw.scl - Mathf.clamp(ft * i, 0, 2), baseRotation - 90);
}
if(floor.isLiquid){
Draw.color(Color.white, floor.color, drownTime * 0.4f);
}else{
Draw.color(Color.white);
}
Draw.rect(type.baseRegion, x, y, baseRotation - 90);
Draw.rect(type.region, x, y, rotation - 90);
for(int i : Mathf.signs){
float tra = rotation - 90, trY = -type.weapon.getRecoil(this, i > 0) + type.weaponOffsetY;
float w = -i * type.weapon.region.getWidth() * Draw.scl;
Draw.rect(type.weapon.region,
x + Angles.trnsx(tra, getWeapon().width * i, trY),
y + Angles.trnsy(tra, getWeapon().width * i, trY), w, type.weapon.region.getHeight() * Draw.scl, rotation - 90);
}
Draw.mixcol();
}
@Override
public void behavior(){
if(!Units.invalidateTarget(target, this)){
if(dst(target) < getWeapon().bullet.range()){
rotate(angleTo(target));
if(Angles.near(angleTo(target), rotation, 13f)){
BulletType ammo = getWeapon().bullet;
Vec2 to = Predict.intercept(GroundUnit.this, target, ammo.speed);
getWeapon().update(GroundUnit.this, to.x, to.y);
}
}
}
}
@Override
public void updateTargeting(){
super.updateTargeting();
if(Units.invalidateTarget(target, team, x, y, Float.MAX_VALUE)){
target = null;
}
if(retarget()){
targetClosest();
}
}
protected void patrol(){
vec.trns(baseRotation, type.speed * Time.delta());
velocity.add(vec.x, vec.y);
vec.trns(baseRotation, type.hitsizeTile * 5);
Tile tile = world.tileWorld(x + vec.x, y + vec.y);
if((tile == null || tile.solid() || tile.floor().drownTime > 0 || tile.floor().isLiquid) || stuckTime > 10f){
baseRotation += Mathf.sign(id % 2 - 0.5f) * Time.delta() * 3f;
}
rotation = Mathf.slerpDelta(rotation, velocity.angle(), type.rotatespeed);
}
protected void circle(float circleLength){
if(target == null) return;
vec.set(target.getX() - x, target.getY() - y);
if(vec.len() < circleLength){
vec.rotate((circleLength - vec.len()) / circleLength * 180f);
}
vec.setLength(type.speed * Time.delta());
velocity.add(vec);
}
protected void moveToCore(PathTarget path){
Tile tile = world.tileWorld(x, y);
if(tile == null) return;
Tile targetTile = pathfinder.getTargetTile(tile, team, path);
if(tile == targetTile) return;
velocity.add(vec.trns(angleTo(targetTile), type.speed * Time.delta()));
if(Units.invalidateTarget(target, this)){
rotation = Mathf.slerpDelta(rotation, baseRotation, type.rotatespeed);
}
}
protected void moveAwayFromCore(){
Team enemy = null;
for(Team team : team.enemies()){
if(team.active()){
enemy = team;
break;
}
}
if(enemy == null){
for(Team team : team.enemies()){
enemy = team;
break;
}
}
if(enemy == null) return;
Tile tile = world.tileWorld(x, y);
if(tile == null) return;
Tile targetTile = pathfinder.getTargetTile(tile, enemy, PathTarget.enemyCores);
Tilec core = getClosestCore();
if(tile == targetTile || core == null || dst(core) < 120f) return;
velocity.add(vec.trns(angleTo(targetTile), type.speed * Time.delta()));
rotation = Mathf.slerpDelta(rotation, baseRotation, type.rotatespeed);
}
}

View File

@@ -1,34 +0,0 @@
package mindustry.entities.type.base;
import arc.graphics.g2d.Draw;
import arc.math.Angles;
import arc.math.Mathf;
import mindustry.entities.Units;
public class HoverUnit extends FlyingUnit{
@Override
public void drawWeapons(){
for(int i : Mathf.signs){
float tra = rotation - 90, trY = -getWeapon().getRecoil(this, i > 0) + type.weaponOffsetY;
float w = i > 0 ? -12 : 12;
float wx = x + Angles.trnsx(tra, getWeapon().width * i, trY), wy = y + Angles.trnsy(tra, getWeapon().width * i, trY);
int wi = (i + 1) / 2;
Draw.rect(getWeapon().region, wx, wy, w, 12, weaponAngles[wi] - 90);
}
}
@Override
protected void attack(float circleLength){
moveTo(circleLength);
}
@Override
protected void updateRotation(){
if(!Units.invalidateTarget(target, this)){
rotation = Mathf.slerpDelta(rotation, angleTo(target), type.rotatespeed);
}else{
rotation = Mathf.slerpDelta(rotation, velocity.angle(), type.baseRotateSpeed);
}
}
}

View File

@@ -1,178 +0,0 @@
package mindustry.entities.type.base;
import arc.math.Mathf;
import arc.util.Structs;
import mindustry.content.Blocks;
import mindustry.gen.*;
import mindustry.entities.units.StateMachine.UnitState;
import mindustry.gen.Call;
import mindustry.type.Item;
import mindustry.type.ItemType;
import mindustry.world.Pos;
import mindustry.world.Tile;
import java.io.*;
import static mindustry.Vars.*;
/** A drone that only mines.*/
public class MinerDrone extends BaseDrone implements MinerTrait{
protected Item targetItem;
protected Tile mineTile;
public final UnitState
mine = new UnitState(){
public void entered(){
target = null;
}
public void update(){
Tilec entity = getClosestCore();
if(entity == null) return;
findItem();
//core full of the target item, do nothing
if(targetItem != null && entity.block.acceptStack(targetItem, 1, entity.tile, MinerDrone.this) == 0){
MinerDrone.this.clearItem();
return;
}
//if inventory is full, drop it off.
if(item.amount >= getItemCapacity() || (targetItem != null && !acceptsItem(targetItem))){
setState(drop);
}else{
if(retarget() && targetItem != null){
target = indexer.findClosestOre(x, y, targetItem);
}
if(target instanceof Tile){
moveTo(type.range / 1.5f);
if(dst(target) < type.range && mineTile != target){
setMineTile((Tile)target);
}
if(((Tile)target).block() != Blocks.air){
setState(drop);
}
}else{
//nothing to mine anymore, core full: circle spawnpoint
if(getSpawner() != null){
target = getSpawner();
circle(40f);
}
}
}
}
public void exited(){
setMineTile(null);
}
},
drop = new UnitState(){
public void entered(){
target = null;
}
public void update(){
if(item.amount == 0 || item.item.type != ItemType.material){
clearItem();
setState(mine);
return;
}
target = getClosestCore();
if(target == null) return;
Tilec tile = (Tilec)target;
if(dst(target) < type.range){
if(tile.tile.block().acceptStack(item.item, item.amount, tile.tile, MinerDrone.this) > 0){
Call.transferItemTo(item.item, item.amount, x, y, tile.tile);
}
clearItem();
setState(mine);
}
circle(type.range / 1.8f);
}
};
@Override
public UnitState getStartState(){
return mine;
}
@Override
public void update(){
super.update();
updateMining();
}
@Override
protected void updateRotation(){
if(mineTile != null && shouldRotate() && mineTile.dst(this) < type.range){
rotation = Mathf.slerpDelta(rotation, angleTo(mineTile), 0.3f);
}else{
rotation = Mathf.slerpDelta(rotation, velocity.angle(), 0.3f);
}
}
@Override
public boolean shouldRotate(){
return isMining();
}
@Override
public void drawOver(){
drawMining();
}
@Override
public boolean canMine(Item item){
return type.toMine.contains(item);
}
@Override
public float getMinePower(){
return type.minePower;
}
@Override
public Tile getMineTile(){
return mineTile;
}
@Override
public void setMineTile(Tile tile){
mineTile = tile;
}
@Override
public void write(DataOutput data) throws IOException{
super.write(data);
data.writeInt(mineTile == null || !state.is(mine) ? Pos.invalid : mineTile.pos());
}
@Override
public void read(DataInput data) throws IOException{
super.read(data);
mineTile = world.tile(data.readInt());
}
protected void findItem(){
Tilec entity = getClosestCore();
if(entity == null){
return;
}
targetItem = Structs.findMin(type.toMine, indexer::hasOre, (a, b) -> -Integer.compare(entity.items().get(a), entity.items().get(b)));
}
}

View File

@@ -1,73 +0,0 @@
package mindustry.entities.type.base;
import mindustry.entities.Units;
import mindustry.gen.*;
import mindustry.entities.units.StateMachine.UnitState;
import mindustry.world.Pos;
import mindustry.world.Tile;
import mindustry.world.blocks.*;
import java.io.*;
import static mindustry.Vars.world;
public class RepairDrone extends BaseDrone{
public final UnitState repair = new UnitState(){
public void entered(){
target = null;
}
public void update(){
if(retarget()){
target = Units.findDamagedTile(team, x, y);
}
if(target instanceof Tilec && ((Tilec)target).block instanceof BuildBlock){
target = null;
}
if(target != null){
if(target.dst(RepairDrone.this) > type.range){
circle(type.range * 0.9f);
}else{
getWeapon().update(RepairDrone.this, target.getX(), target.getY());
}
}else{
//circle spawner if there's nothing to repair
if(getSpawner() != null){
target = getSpawner();
circle(type.range * 1.5f, type.speed/2f);
target = null;
}
}
}
};
@Override
public boolean shouldRotate(){
return target != null;
}
@Override
public UnitState getStartState(){
return repair;
}
@Override
public void write(DataOutput data) throws IOException{
super.write(data);
data.writeInt(state.is(repair) && target instanceof Tilec ? ((Tilec)target).tile.pos() : Pos.invalid);
}
@Override
public void read(DataInput data) throws IOException{
super.read(data);
Tile repairing = world.tile(data.readInt());
if(repairing != null){
target = repairing.entity;
}
}
}

View File

@@ -3,7 +3,7 @@ package mindustry.game;
import arc.util.ArcAnnotate.*;
import mindustry.core.GameState.*;
import mindustry.ctype.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.type.*;
@@ -62,10 +62,10 @@ public class EventType{
}
public static class PlayerChatEvent{
public final Player player;
public final Playerc player;
public final String message;
public PlayerChatEvent(Player player, String message){
public PlayerChatEvent(Playerc player, String message){
this.player = player;
this.message = message;
}
@@ -144,11 +144,11 @@ public class EventType{
/** Called when the player withdraws items from a block. */
public static class WithdrawEvent{
public final Tile tile;
public final Player player;
public final Playerc player;
public final Item item;
public final int amount;
public WithdrawEvent(Tile tile, Player player, Item item, int amount){
public WithdrawEvent(Tile tile, Playerc player, Item item, int amount){
this.tile = tile;
this.player = player;
this.item = item;
@@ -159,11 +159,11 @@ public class EventType{
/** Called when a player deposits items to a block.*/
public static class DepositEvent{
public final Tile tile;
public final Player player;
public final Playerc player;
public final Item item;
public final int amount;
public DepositEvent(Tile tile, Player player, Item item, int amount){
public DepositEvent(Tile tile, Playerc player, Item item, int amount){
this.tile = tile;
this.player = player;
this.item = item;
@@ -174,9 +174,9 @@ public class EventType{
/** Called when the player taps a block. */
public static class TapEvent{
public final Tile tile;
public final Player player;
public final Playerc player;
public TapEvent(Tile tile, Player player){
public TapEvent(Tile tile, Playerc player){
this.tile = tile;
this.player = player;
}
@@ -185,10 +185,10 @@ public class EventType{
/** Called when the player sets a specific block. */
public static class TapConfigEvent{
public final Tile tile;
public final Player player;
public final Playerc player;
public final int value;
public TapConfigEvent(Tile tile, Player player, int value){
public TapConfigEvent(Tile tile, Playerc player, int value){
this.tile = tile;
this.player = player;
this.value = value;
@@ -262,10 +262,10 @@ public class EventType{
public final Tile tile;
public final Team team;
public final @Nullable
Player player;
Playerc player;
public final boolean breaking;
public BlockBuildEndEvent(Tile tile, @Nullable Player player, Team team, boolean breaking){
public BlockBuildEndEvent(Tile tile, @Nullable Playerc player, Team team, boolean breaking){
this.tile = tile;
this.team = team;
this.player = player;
@@ -323,10 +323,10 @@ public class EventType{
//TODO rename
public static class MechChangeEvent{
public final Player player;
public final Playerc player;
public final UnitDef mech;
public MechChangeEvent(Player player, UnitDef mech){
public MechChangeEvent(Playerc player, UnitDef mech){
this.player = player;
this.mech = mech;
}
@@ -334,42 +334,42 @@ public class EventType{
/** Called after connecting; when a player recieves world data and is ready to play.*/
public static class PlayerJoin{
public final Player player;
public final Playerc player;
public PlayerJoin(Player player){
public PlayerJoin(Playerc player){
this.player = player;
}
}
/** Called when a player connects, but has not joined the game yet.*/
public static class PlayerConnect{
public final Player player;
public final Playerc player;
public PlayerConnect(Player player){
public PlayerConnect(Playerc player){
this.player = player;
}
}
public static class PlayerLeave{
public final Player player;
public final Playerc player;
public PlayerLeave(Player player){
public PlayerLeave(Playerc player){
this.player = player;
}
}
public static class PlayerBanEvent{
public final Player player;
public final Playerc player;
public PlayerBanEvent(Player player){
public PlayerBanEvent(Playerc player){
this.player = player;
}
}
public static class PlayerUnbanEvent{
public final Player player;
public final Playerc player;
public PlayerUnbanEvent(Player player){
public PlayerUnbanEvent(Playerc player){
this.player = player;
}
}

View File

@@ -5,6 +5,7 @@ import arc.util.serialization.Json.Serializable;
import arc.util.serialization.JsonValue;
import mindustry.content.*;
import mindustry.ctype.ContentType;
import mindustry.gen.*;
import mindustry.type.*;
import static mindustry.Vars.content;
@@ -18,7 +19,7 @@ public class SpawnGroup implements Serializable{
public static final int never = Integer.MAX_VALUE;
/** The unit type spawned */
public UnitType type;
public UnitDef type;
/** When this spawn should end */
public int end = never;
/** When this spawn should start */
@@ -36,7 +37,7 @@ public class SpawnGroup implements Serializable{
/** Items this unit spawns with. Null to disable. */
public ItemStack items;
public SpawnGroup(UnitType type){
public SpawnGroup(UnitDef type){
this.type = type;
}
@@ -56,8 +57,11 @@ public class SpawnGroup implements Serializable{
* Creates a unit, and assigns correct values based on this group's data.
* This method does not add() the unit.
*/
public BaseUnit createUnit(Team team){
BaseUnit unit = type.create(team);
public Unitc createUnit(Team team){
//TODO
throw new IllegalArgumentException("TODO");
/*
Unitc unit = type.create(team);
if(effect != null){
unit.applyEffect(effect, 999999f);
@@ -67,7 +71,7 @@ public class SpawnGroup implements Serializable{
unit.addItem(items.item, items.amount);
}
return unit;
return unit;*/
}
@Override

View File

@@ -10,7 +10,7 @@ import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.EventType.*;
import mindustry.graphics.*;
import mindustry.type.*;

View File

@@ -12,7 +12,7 @@ import arc.util.*;
import arc.util.ArcAnnotate.*;
import arc.util.pooling.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.EventType.*;
import mindustry.io.*;
import mindustry.ui.*;
@@ -97,8 +97,8 @@ public class MinimapRenderer implements Disposable{
Draw.rect(unit.getIconRegion(), x + rx, y + ry, scale, scale, unit.rotation - 90);
Draw.reset();
if(withLabels && unit instanceof Player){
Player pl = (Player) unit;
if(withLabels && unit instanceof Playerc){
Playerc pl = (Playerc) unit;
if(!pl.isLocal){
// Only display names for other players.
drawLabel(x + rx, y + ry, pl.name, unit.getTeam().color);

View File

@@ -9,7 +9,7 @@ import arc.util.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.input.*;
import mindustry.type.*;
import mindustry.ui.*;
@@ -36,7 +36,7 @@ public class OverlayRenderer{
public void drawTop(){
if(Core.settings.getBool("indicators")){
for(Player player : playerGroup.all()){
for(Playerc player : Groups.player.all()){
if(Vars.player != player && Vars.player.team() == player.team()){
if(!rect.setSize(Core.camera.width * 0.9f, Core.camera.height * 0.9f)
.setCenter(Core.camera.position.x, Core.camera.position.y).contains(player.x, player.y)){

View File

@@ -6,11 +6,11 @@ import arc.graphics.Texture.TextureFilter;
import arc.graphics.g2d.Draw;
import arc.graphics.gl.FrameBuffer;
import arc.util.Disposable;
import mindustry.entities.type.Player;
import mindustry.gen.*;
import static arc.Core.camera;
import static arc.Core.graphics;
import static mindustry.Vars.playerGroup;
import static mindustry.Groups.player;
import static mindustry.Vars.renderer;
public class Pixelator implements Disposable{
@@ -55,7 +55,7 @@ public class Pixelator implements Disposable{
Draw.rect(Draw.wrap(buffer.getTexture()), Core.camera.position.x, Core.camera.position.y, Core.camera.width, -Core.camera.height);
Draw.blend();
playerGroup.draw(p -> !p.isDead(), Player::drawName);
Groups.player.draw(p -> !p.isDead(), Playerc::drawName);
Core.camera.position.set(px, py);
Core.settings.put("animatedwater", hadWater);

View File

@@ -132,6 +132,8 @@ public class DesktopInput extends InputHandler{
@Override
public void update(){
super.update();
if(net.active() && Core.input.keyTap(Binding.player_list)){
ui.listfrag.toggle();
}

View File

@@ -18,7 +18,7 @@ import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.effect.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
@@ -73,7 +73,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
@Remote(targets = Loc.client, called = Loc.server)
public static void dropItem(Player player, float angle){
public static void dropItem(Playerc player, float angle){
if(net.server() && player.item().amount <= 0){
throw new ValidateException(player, "Player cannot drop an item.");
}
@@ -83,7 +83,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
@Remote(targets = Loc.both, called = Loc.server, forward = true, unreliable = true)
public static void rotateBlock(Player player, Tile tile, boolean direction){
public static void rotateBlock(Playerc player, Tile tile, boolean direction){
if(net.server() && (!Units.canInteract(player, tile) ||
!netServer.admins.allowAction(player, ActionType.rotate, tile, action -> action.rotation = Mathf.mod(tile.rotation() + Mathf.sign(direction), 4)))){
throw new ValidateException(player, "Player cannot rotate a block.");
@@ -98,8 +98,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
@Remote(targets = Loc.both, forward = true, called = Loc.server)
public static void transferInventory(Player player, Tile tile){
if(player == null || player.timer == null) return;
public static void transferInventory(Playerc player, Tile tile){
if(player == null) return;
if(net.server() && (player.item().amount <= 0 || player.isTransferring|| !Units.canInteract(player, tile) ||
!netServer.admins.allowAction(player, ActionType.depositItem, tile, action -> {
action.itemAmount = player.item().amount;
@@ -152,7 +152,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
@Remote(targets = Loc.both, called = Loc.server, forward = true)
public static void onTileTapped(Player player, Tile tile){
public static void onTileTapped(Playerc player, Tile tile){
if(tile == null || player == null) return;
if(net.server() && (!Units.canInteract(player, tile) ||
!netServer.admins.allowAction(player, ActionType.tapTile, tile, action -> {}))) throw new ValidateException(player, "Player cannot tap a tile.");
@@ -161,7 +161,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
@Remote(targets = Loc.both, called = Loc.both, forward = true)
public static void onTileConfig(Player player, Tile tile, int value){
public static void onTileConfig(Playerc player, Tile tile, int value){
if(tile == null) return;
if(net.server() && (!Units.canInteract(player, tile) ||
@@ -183,7 +183,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
public void update(){
player.typing(ui.chatfrag.shown());
}
public float getMouseX(){
@@ -637,7 +637,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
&& tile.drop() != null && tile.drop().hardness <= player.mech.drillPower
&& !(tile.floor().playerUnmineable && tile.overlay().itemDrop == null)
&& player.acceptsItem(tile.drop())
&& tile.block() == Blocks.air && player.dst(tile.worldx(), tile.worldy()) <= Player.mineDistance;
&& tile.block() == Blocks.air && player.dst(tile.worldx(), tile.worldy()) <= Playerc.mineDistance;
}
/** Returns the tile at the specified MOUSE coordinates. */
@@ -897,4 +897,192 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
public int x, y, rotation;
public boolean last;
}
//TODO implement all of this!
/*
protected void updateKeyboard(){
Tile tile = world.tileWorld(x, y);
boolean canMove = !Core.scene.hasKeyboard() || ui.minimapfrag.shown();
isBoosting = Core.input.keyDown(Binding.dash) && !mech.flying;
//if player is in solid block
if(tile != null && tile.solid()){
isBoosting = true;
}
float speed = isBoosting && !mech.flying ? mech.boostSpeed : mech.speed;
if(mech.flying){
//prevent strafing backwards, have a penalty for doing so
float penalty = 0.2f; //when going 180 degrees backwards, reduce speed to 0.2x
speed *= Mathf.lerp(1f, penalty, Angles.angleDist(rotation, velocity.angle()) / 180f);
}
movement.setZero();
float xa = Core.input.axis(Binding.move_x);
float ya = Core.input.axis(Binding.move_y);
if(!(Core.scene.getKeyboardFocus() instanceof TextField)){
movement.y += ya * speed;
movement.x += xa * speed;
}
if(Core.input.keyDown(Binding.mouse_move)){
movement.x += Mathf.clamp((Core.input.mouseX() - Core.graphics.getWidth() / 2f) * 0.005f, -1, 1) * speed;
movement.y += Mathf.clamp((Core.input.mouseY() - Core.graphics.getHeight() / 2f) * 0.005f, -1, 1) * speed;
}
Vec2 vec = Core.input.mouseWorld(control.input.getMouseX(), control.input.getMouseY());
pointerX = vec.x;
pointerY = vec.y;
updateShooting();
movement.limit(speed).scl(Time.delta());
if(canMove){
velocity.add(movement.x, movement.y);
}else{
isShooting = false;
}
float prex = x, prey = y;
updateVelocityStatus();
moved = dst(prex, prey) > 0.001f;
if(canMove){
float baseLerp = mech.getRotationAlpha(this);
if(!isShooting() || !mech.faceTarget){
if(!movement.isZero()){
rotation = Mathf.slerpDelta(rotation, mech.flying ? velocity.angle() : movement.angle(), 0.13f * baseLerp);
}
}else{
float angle = control.input.mouseAngle(x, y);
this.rotation = Mathf.slerpDelta(this.rotation, angle, 0.1f * baseLerp);
}
}
}
protected void updateShooting(){
if(!state.isEditor() && isShooting() && mech.canShoot(this)){
weapons.update(this);
//if(!mech.turnCursor){
//shoot forward ignoring cursor
//mech.weapon.update(this, x + Angles.trnsx(rotation, mech.weapon.targetDistance), y + Angles.trnsy(rotation, mech.weapon.targetDistance));
//}else{
//mech.weapon.update(this, pointerX, pointerY);
//}
}
}
protected void updateTouch(){
if(Units.invalidateTarget(target, this) &&
!(target instanceof Tilec && ((Tilec)target).damaged() && target.isValid() && target.team() == team && mech.canHeal && dst(target) < mech.range && !(((Tilec)target).block instanceof BuildBlock))){
target = null;
}
if(state.isEditor()){
target = null;
}
float targetX = Core.camera.position.x, targetY = Core.camera.position.y;
float attractDst = 15f;
float speed = isBoosting && !mech.flying ? mech.boostSpeed : mech.speed;
if(moveTarget != null && !moveTarget.dead()){
targetX = moveTarget.getX();
targetY = moveTarget.getY();
boolean tapping = moveTarget instanceof Tilec && moveTarget.team() == team;
attractDst = 0f;
if(tapping){
velocity.setAngle(angleTo(moveTarget));
}
if(dst(moveTarget) <= 2f * Time.delta()){
if(tapping && !dead()){
Tile tile = ((Tilec)moveTarget).tile;
tile.block().tapped(tile, this);
}
moveTarget = null;
}
}else{
moveTarget = null;
}
movement.set((targetX - x) / Time.delta(), (targetY - y) / Time.delta()).limit(speed);
movement.setAngle(Mathf.slerp(movement.angle(), velocity.angle(), 0.05f));
if(dst(targetX, targetY) < attractDst){
movement.setZero();
}
float expansion = 3f;
hitbox(rect);
rect.x -= expansion;
rect.y -= expansion;
rect.width += expansion * 2f;
rect.height += expansion * 2f;
isBoosting = collisions.overlapsTile(rect) || dst(targetX, targetY) > 85f;
velocity.add(movement.scl(Time.delta()));
if(velocity.len() <= 0.2f && mech.flying){
rotation += Mathf.sin(Time.time() + id * 99, 10f, 1f);
}else if(target == null){
rotation = Mathf.slerpDelta(rotation, velocity.angle(), velocity.len() / 10f);
}
float lx = x, ly = y;
updateVelocityStatus();
moved = dst(lx, ly) > 0.001f;
if(mech.flying){
//hovering effect
x += Mathf.sin(Time.time() + id * 999, 25f, 0.08f);
y += Mathf.cos(Time.time() + id * 999, 25f, 0.08f);
}
//update shooting if not building, not mining and there's ammo left
if(!isBuilding() && getMineTile() == null){
//autofire
if(target == null){
isShooting = false;
if(Core.settings.getBool("autotarget")){
target = Units.closestTarget(team, x, y, mech.range, u -> u.team() != Team.derelict, u -> u.getTeam() != Team.derelict);
if(mech.canHeal && target == null){
target = Geometry.findClosest(x, y, indexer.getDamaged(Team.sharded));
if(target != null && dst(target) > mech.range){
target = null;
}else if(target != null){
target = ((Tile)target).entity;
}
}
if(target != null){
setMineTile(null);
}
}
}else if(target.isValid() || (target instanceof Tilec && ((Tilec)target).damaged() && target.team() == team && mech.canHeal && dst(target) < mech.range)){
//rotate toward and shoot the target
if(mech.faceTarget){
rotation = Mathf.slerpDelta(rotation, angleTo(target), 0.2f);
}
Vec2 intercept = Predict.intercept(this, target, getWeapon().bullet.speed);
pointerX = intercept.x;
pointerY = intercept.y;
updateShooting();
isShooting = true;
}
}
}
*/
}

View File

@@ -577,6 +577,8 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
public void update(){
super.update();
if(state.is(State.menu) ){
selectRequests.clear();
removals.clear();

View File

@@ -97,7 +97,7 @@ public class Placement{
int nodeLimit = 1000;
int totalNodes = 0;
PriorityQueue<Tile> queue = new PriorityQueue<>(10, (a, b) -> Float.compare(costs.get(a.pos(), 0f) + distanceHeuristic(a.x, a.y, end.x, end.y), costs.get(b.pos(), 0f) + distanceHeuristic(b.x, b.y, end.x, end.y)));
PriorityQueue<Tile> queue = new PriorityQueue<>(10, (a, b) -> Float.compare(costs.get(a.pos(), 0f) + distanceHeuristic(a.x, a.y, end.x, end.y), costs.get(b.pos(), 0f) + distanceHeuristic(b.x(), b.y(), end.x, end.y)));
queue.add(start);
boolean found = false;
while(!queue.isEmpty() && totalNodes++ < nodeLimit){

View File

@@ -1,24 +1,18 @@
package mindustry.io;
import mindustry.annotations.Annotations.ReadClass;
import mindustry.annotations.Annotations.WriteClass;
import arc.graphics.Color;
import mindustry.ctype.ContentType;
import mindustry.entities.Effects;
import mindustry.entities.*;
import mindustry.entities.bullet.BulletType;
import mindustry.entities.units.BuildRequest;
import mindustry.entities.type.*;
import arc.graphics.*;
import mindustry.annotations.Annotations.*;
import mindustry.ctype.*;
import mindustry.entities.bullet.*;
import mindustry.entities.units.*;
import mindustry.game.*;
import mindustry.net.Administration.TraceInfo;
import mindustry.net.Packets.AdminAction;
import mindustry.net.Packets.KickReason;
import mindustry.net.Administration.*;
import mindustry.net.Packets.*;
import mindustry.type.*;
import mindustry.world.*;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.*;
import static mindustry.Vars.*;
@@ -26,76 +20,6 @@ import static mindustry.Vars.*;
@SuppressWarnings("unused")
public class TypeIO{
@WriteClass(Player.class)
public static void writePlayer(ByteBuffer buffer, Player player){
if(player == null){
buffer.putInt(-1);
}else{
buffer.putInt(player.id);
}
}
@ReadClass(Player.class)
public static Player readPlayer(ByteBuffer buffer){
int id = buffer.getInt();
return id == -1 ? null : playerGroup.getByID(id);
}
@WriteClass(Unitc.class)
public static void writeUnit(ByteBuffer buffer, Unitc unit){
if(unit.getGroup() == null){
buffer.put((byte)-1);
return;
}
buffer.put((byte)unit.getGroup().getID());
buffer.putInt(unit.getID());
}
@ReadClass(Unitc.class)
public static Unitc readUnit(ByteBuffer buffer){
byte gid = buffer.get();
if(gid == -1) return null;
int id = buffer.getInt();
return (Unitc)entities.get(gid).getByID(id);
}
@WriteClass(ShooterTrait.class)
public static void writeShooter(ByteBuffer buffer, ShooterTrait trait){
buffer.put((byte)trait.getGroup().getID());
buffer.putInt(trait.getID());
}
@ReadClass(ShooterTrait.class)
public static ShooterTrait readShooter(ByteBuffer buffer){
byte gid = buffer.get();
int id = buffer.getInt();
return (ShooterTrait)entities.get(gid).getByID(id);
}
@WriteClass(Bullet.class)
public static void writeBullet(ByteBuffer buffer, Bullet bullet){
buffer.putInt(bullet.getID());
}
@ReadClass(Bullet.class)
public static Bullet readBullet(ByteBuffer buffer){
int id = buffer.getInt();
return bulletGroup.getByID(id);
}
@WriteClass(BaseUnit.class)
public static void writeBaseUnit(ByteBuffer buffer, BaseUnit unit){
buffer.put((byte) (int)unit.getTeam().id);
buffer.putInt(unit.getID());
}
@ReadClass(BaseUnit.class)
public static BaseUnit readBaseUnit(ByteBuffer buffer){
byte tid = buffer.get();
int id = buffer.getInt();
return unitGroup.getByID(id);
}
@WriteClass(Tile.class)
public static void writeTile(ByteBuffer buffer, Tile tile){
buffer.putInt(tile == null ? Pos.get(-1, -1) : tile.pos());
@@ -220,16 +144,6 @@ public class TypeIO{
return AdminAction.values()[buffer.get()];
}
@WriteClass(Effect.class)
public static void writeEffect(ByteBuffer buffer, Effect effect){
buffer.putShort((short)effect.id);
}
@ReadClass(Effect.class)
public static Effect readEffect(ByteBuffer buffer){
return Effects.getEffect(buffer.getShort());
}
@WriteClass(UnitDef.class)
public static void writeUnitDef(ByteBuffer buffer, UnitDef effect){
buffer.putShort(effect.id);

View File

@@ -2,7 +2,7 @@ package mindustry.io.versions;
import arc.func.Prov;
import mindustry.entities.effect.*;
import mindustry.entities.type.Player;
import mindustry.gen.*;
import mindustry.entities.type.base.*;
/*
@@ -78,7 +78,7 @@ public class LegacyTypeTable{
13 = Revenant
*/
private static final Prov[] build81Table = {
Player::new,
Playerc::new,
Fire::new,
Puddle::new,
MinerDrone::new,
@@ -95,7 +95,7 @@ public class LegacyTypeTable{
};
private static final Prov[] build80Table = {
Player::new,
Playerc::new,
Fire::new,
Puddle::new,
Bullet::new,
@@ -114,7 +114,7 @@ public class LegacyTypeTable{
};
private static final Prov[] build79Table = {
Player::new,
Playerc::new,
Fire::new,
Puddle::new,
Bullet::new,

View File

@@ -203,7 +203,7 @@ public class Map implements Comparable<Map>, Publishable{
@Override
public boolean prePublish(){
tags.put("author", player.name);
tags.put("author", player.name());
ui.editor.editor.getTags().put("author", tags.get("author"));
ui.editor.save();

View File

@@ -182,7 +182,7 @@ public abstract class BasicGenerator extends RandomGenerator{
Tile end = tiles.getn(endX, endY);
GridBits closed = new GridBits(width, height);
IntFloatMap costs = new IntFloatMap();
PriorityQueue<Tile> queue = new PriorityQueue<>(tiles.width() * tiles.height()/4, (a, b) -> Float.compare(costs.get(a.pos(), 0f) + dh.cost(a.x, a.y, end.x, end.y), costs.get(b.pos(), 0f) + dh.cost(b.x, b.y, end.x, end.y)));
PriorityQueue<Tile> queue = new PriorityQueue<>(tiles.width() * tiles.height()/4, (a, b) -> Float.compare(costs.get(a.pos(), 0f) + dh.cost(a.x, a.y, end.x, end.y), costs.get(b.pos(), 0f) + dh.cost(b.x(), b.y(), end.x, end.y)));
queue.add(start);
boolean found = false;
while(!queue.isEmpty()){

View File

@@ -20,7 +20,7 @@ import mindustry.content.TechTree.*;
import mindustry.ctype.*;
import mindustry.entities.Effects.*;
import mindustry.entities.bullet.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.*;
import mindustry.game.Objectives.*;
import mindustry.gen.*;
@@ -280,7 +280,7 @@ public class ContentParser{
UnitType unit;
if(locate(ContentType.unit, name) == null){
Class<BaseUnit> type = resolve(legacyUnitMap.get(Strings.capitalize(getType(value)), getType(value)), "mindustry.entities.type.base");
Class<Unitc> type = resolve(legacyUnitMap.get(Strings.capitalize(getType(value)), getType(value)), "mindustry.entities.type.base");
unit = new UnitDef(mod + "-" + name, supply(type));
}else{
unit = locate(ContentType.unit, name);

View File

@@ -5,11 +5,11 @@ import arc.func.*;
import arc.struct.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import arc.util.pooling.*;
import arc.util.pooling.Pool.*;
import arc.util.pooling.*;
import mindustry.*;
import mindustry.annotations.Annotations.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.*;
@@ -31,7 +31,7 @@ public class Administration{
//anti-spam
addChatFilter((player, message) -> {
long resetTime = Config.messageRateLimit.num() * 1000;
if(Config.antiSpam.bool() && !player.isLocal && !player.isAdmin){
if(Config.antiSpam.bool() && !player.isLocal() && !player.admin()){
//prevent people from spamming messages quickly
if(resetTime > 0 && Time.timeSinceMillis(player.getInfo().lastMessageTime) < resetTime){
//supress message
@@ -39,7 +39,7 @@ public class Administration{
player.getInfo().messageInfractions ++;
//kick player for spamming and prevent connection if they've done this several times
if(player.getInfo().messageInfractions >= Config.messageSpamKick.num() && Config.messageSpamKick.num() != 0){
player.con.kick("You have been kicked for spamming.", 1000 * 60 * 2);
player.con().kick("You have been kicked for spamming.", 1000 * 60 * 2);
}
return null;
}else{
@@ -86,7 +86,7 @@ public class Administration{
}
/** Filters out a chat message. */
public @Nullable String filterMessage(Player player, String message){
public @Nullable String filterMessage(Playerc player, String message){
String current = message;
for(ChatFilter f : chatFilters){
current = f.filter(player, message);
@@ -101,7 +101,7 @@ public class Administration{
}
/** @return whether this action is allowed by the action filters. */
public boolean allowAction(Player player, ActionType type, Tile tile, Cons<PlayerAction> setter){
public boolean allowAction(Playerc player, ActionType type, Tile tile, Cons<PlayerAction> setter){
PlayerAction act = Pools.obtain(PlayerAction.class, PlayerAction::new);
setter.get(act.set(player, type, tile));
for(ActionFilter filter : actionFilters){
@@ -172,7 +172,7 @@ public class Administration{
getCreateInfo(id).banned = true;
save();
Events.fire(new PlayerBanEvent(Vars.playerGroup.find(p -> id.equals(p.uuid))));
Events.fire(new PlayerBanEvent(Groups.player.find(p -> id.equals(p.uuid()))));
return true;
}
@@ -212,7 +212,7 @@ public class Administration{
info.banned = false;
bannedIPs.removeAll(info.ips, false);
save();
Events.fire(new PlayerUnbanEvent(Vars.playerGroup.find(p -> id.equals(p.uuid))));
Events.fire(new PlayerUnbanEvent(Groups.player.find(p -> id.equals(p.uuid()))));
return true;
}
@@ -515,7 +515,7 @@ public class Administration{
/** Handles chat messages from players and changes their contents. */
public interface ChatFilter{
/** @return the filtered message; a null string signals that the message should not be sent. */
@Nullable String filter(Player player, String message);
@Nullable String filter(Playerc player, String message);
}
/** Allows or disallows player actions. */
@@ -539,7 +539,7 @@ public class Administration{
/** Defines a (potentially dangerous) action that a player has done in the world.
* These objects are pooled; do not cache them! */
public static class PlayerAction implements Poolable{
public @NonNull Player player;
public @NonNull Playerc player;
public @NonNull ActionType type;
public @NonNull Tile tile;
@@ -554,7 +554,7 @@ public class Administration{
public @Nullable Item item;
public int itemAmount;
public PlayerAction set(Player player, ActionType type, Tile tile){
public PlayerAction set(Playerc player, ActionType type, Tile tile){
this.player = player;
this.type = type;
this.tile = tile;

View File

@@ -118,7 +118,7 @@ public class CrashSender{
ex(() -> value.addChild("revision", new JsonValue(Version.revision)));
ex(() -> value.addChild("net", new JsonValue(fn)));
ex(() -> value.addChild("server", new JsonValue(fs)));
ex(() -> value.addChild("players", new JsonValue(Vars.playerGroup.size())));
ex(() -> value.addChild("players", new JsonValue(Groups.player.size())));
ex(() -> value.addChild("state", new JsonValue(Vars.state.getState().name())));
ex(() -> value.addChild("os", new JsonValue(System.getProperty("os.name") + "x" + (OS.is64Bit ? "64" : "32"))));
ex(() -> value.addChild("trace", new JsonValue(parseException(exception))));

View File

@@ -3,7 +3,6 @@ package mindustry.net;
import arc.struct.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.entities.type.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.net.Administration.*;
@@ -16,8 +15,9 @@ import static mindustry.Vars.netServer;
public abstract class NetConnection{
public final String address;
public String uuid = "AAAAAAAA", usid = uuid;
public boolean mobile, modclient;
public @Nullable Player player;
public @Nullable Playerc player;
/** ID of last recieved client snapshot. */
public int lastRecievedClientSnapshot = -1;
@@ -37,8 +37,8 @@ public abstract class NetConnection{
public void kick(KickReason reason){
Log.info("Kicking connection {0}; Reason: {1}", address, reason.name());
if(player != null && (reason == KickReason.kick || reason == KickReason.banned || reason == KickReason.vote) && player.uuid != null){
PlayerInfo info = netServer.admins.getInfo(player.uuid);
if((reason == KickReason.kick || reason == KickReason.banned || reason == KickReason.vote)){
PlayerInfo info = netServer.admins.getInfo(uuid);
info.timesKicked++;
info.lastKicked = Math.max(Time.millis() + 30 * 1000, info.lastKicked);
}
@@ -59,11 +59,9 @@ public abstract class NetConnection{
public void kick(String reason, int kickDuration){
Log.info("Kicking connection {0}; Reason: {1}", address, reason.replace("\n", " "));
if(player != null && player.uuid != null){
PlayerInfo info = netServer.admins.getInfo(player.uuid);
info.timesKicked++;
info.lastKicked = Math.max(Time.millis() + kickDuration, info.lastKicked);
}
PlayerInfo info = netServer.admins.getInfo(uuid);
info.timesKicked++;
info.lastKicked = Math.max(Time.millis() + kickDuration, info.lastKicked);
Call.onKick(this, reason);

View File

@@ -2,7 +2,7 @@ package mindustry.net;
import arc.util.*;
import mindustry.core.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.*;
import mindustry.io.*;
import mindustry.maps.Map;
@@ -16,7 +16,7 @@ import static mindustry.Vars.*;
public class NetworkIO{
public static void writeWorld(Player player, OutputStream os){
public static void writeWorld(Playerc player, OutputStream os){
try(DataOutputStream stream = new DataOutputStream(os)){
stream.writeUTF(JsonIO.write(state.rules));
@@ -62,7 +62,7 @@ public class NetworkIO{
}
public static ByteBuffer writeServerData(){
String name = (headless ? Config.name.string() : player.name);
String name = (headless ? Config.name.string() : player.name());
String description = headless && !Config.desc.string().equals("off") ? Config.desc.string() : "";
String map = world.getMap() == null ? "None" : world.getMap().name();
@@ -71,7 +71,7 @@ public class NetworkIO{
writeString(buffer, name, 100);
writeString(buffer, map);
buffer.putInt(playerGroup.size());
buffer.putInt(Groups.player.size());
buffer.putInt(state.wave);
buffer.putInt(Version.build);
writeString(buffer, Version.type);

View File

@@ -1,14 +1,14 @@
package mindustry.net;
import mindustry.entities.type.Player;
import mindustry.gen.*;
/**
* Thrown when a client sends invalid information.
*/
public class ValidateException extends RuntimeException{
public final Player player;
public final Playerc player;
public ValidateException(Player player, String s){
public ValidateException(Playerc player, String s){
super(s);
this.player = player;
}

View File

@@ -21,7 +21,7 @@ import mindustry.ui.*;
//TODO change to UnitType or Shell or something
public class UnitDef extends UnlockableContent{
//TODO implement
public @NonNull Prov<? extends BaseUnit> constructor = () -> this.flying ? new FlyingUnit() : new GroundUnit();
public @NonNull Prov<? extends Unitc> constructor = () -> this.flying ? new FlyingUnit() : new GroundUnit();
public TypeID typeID;
public boolean flying;
@@ -57,8 +57,8 @@ public class UnitDef extends UnlockableContent{
typeID = new TypeID(name, constructor);
}
public BaseUnit create(Team team){
BaseUnit unit = constructor.get();
public Unitc create(Team team){
Unitc unit = constructor.get();
unit.init(this, team);
return unit;
}

View File

@@ -4,7 +4,7 @@ import arc.util.ArcAnnotate.*;
import mindustry.annotations.Annotations.*;
import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.type.Weather.*;
import java.io.*;

View File

@@ -41,7 +41,7 @@ public class AdminsDialog extends FloatingDialog{
res.addImageButton(Icon.cancel, () -> {
ui.showConfirm("$confirm", "$confirmunadmin", () -> {
netServer.admins.unAdminPlayer(info.id);
playerGroup.all().each(player -> {
Groups.player.all().each(player -> {
if(player != null && player.uuid != null && player.uuid.equals(info.id)){
player.isAdmin = false;
}

View File

@@ -253,7 +253,7 @@ public class JoinDialog extends FloatingDialog{
Core.settings.save();
}).grow().pad(8).get().setMaxLength(maxNameLength);
}else{
t.add(player.name).update(l -> l.setColor(player.color)).grow().pad(8);
t.add(player.name()).update(l -> l.setColor(player.color)).grow().pad(8);
}
ImageButton button = t.addImageButton(Tex.whiteui, Styles.clearFulli, 40, () -> {

View File

@@ -2,7 +2,7 @@ package mindustry.ui.dialogs;
import arc.Core;
import arc.scene.ui.layout.Table;
import mindustry.entities.type.Player;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.net.Administration.TraceInfo;
@@ -15,7 +15,7 @@ public class TraceDialog extends FloatingDialog{
setFillParent(false);
}
public void show(Player player, TraceInfo info){
public void show(Playerc player, TraceInfo info){
cont.clear();
Table table = new Table(Tex.clear);
@@ -23,7 +23,7 @@ public class TraceDialog extends FloatingDialog{
table.defaults().pad(1);
table.defaults().left();
table.add(Core.bundle.format("trace.playername", player.name));
table.add(Core.bundle.format("trace.playername", player.name()));
table.row();
table.add(Core.bundle.format("trace.ip", info.ip));
table.row();

View File

@@ -16,7 +16,7 @@ import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.core.GameState.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
import mindustry.net.Administration.*;
@@ -37,7 +37,7 @@ public class BlockInventoryFragment extends Fragment{
private Item lastItem;
@Remote(called = Loc.server, targets = Loc.both, forward = true)
public static void requestItem(Player player, Tile tile, Item item, int amount){
public static void requestItem(Playerc player, Tile tile, Item item, int amount){
if(player == null || tile == null || !tile.interactable(player.team())) return;
amount = Mathf.clamp(amount, 0, player.ttemCapacity());
int fa = amount;

View File

@@ -20,7 +20,7 @@ import mindustry.core.GameState.*;
import mindustry.ctype.ContentType;
import mindustry.ctype.UnlockableContent;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
@@ -209,9 +209,9 @@ public class HudFragment extends Fragment{
if(e == null){
Vec2 world = Core.input.mouseWorld();
Units.nearby(world.x, world.y, 1f, 1f, unit -> {
if(!found[0] && unit instanceof BaseUnit){
if(!found[0] && unit instanceof Unitc){
if(Core.input.keyTap(KeyCode.MOUSE_LEFT)){
Call.removeUnitEditor(player, (BaseUnit)unit);
Call.removeUnitEditor(player, (Unitc)unit);
}
found[0] = true;
unit.hitbox(Tmp.r1);
@@ -344,16 +344,16 @@ public class HudFragment extends Fragment{
}
@Remote(targets = Loc.both, forward = true, called = Loc.both)
public static void setPlayerTeamEditor(Player player, Team team){
public static void setPlayerTeamEditor(Playerc player, Team team){
if(state.isEditor() && player != null){
player.team(team);
}
}
@Remote(targets = Loc.both, called = Loc.server)
public static void spawnUnitEditor(Player player, UnitType type){
public static void spawnUnitEditor(Playerc player, UnitType type){
if(state.isEditor()){
BaseUnit unit = type.create(player.team());
Unitc unit = type.create(player.team());
unit.set(player.x, player.y);
unit.rotation = player.rotation;
unit.add();
@@ -361,7 +361,7 @@ public class HudFragment extends Fragment{
}
@Remote(targets = Loc.both, called = Loc.server, forward = true)
public static void removeUnitEditor(Player player, BaseUnit unit){
public static void removeUnitEditor(Playerc player, Unitc unit){
if(state.isEditor() && unit != null){
unit.remove();
}

View File

@@ -41,7 +41,7 @@ public class PlayerListFragment extends Fragment{
});
cont.table(Tex.buttonTrans, pane -> {
pane.label(() -> Core.bundle.format(playerGroup.size() == 1 ? "players.single" : "players", playerGroup.size()));
pane.label(() -> Core.bundle.format(Groups.player.size() == 1 ? "players.single" : "players", Groups.player.size()));
pane.row();
pane.pane(content).grow().get().setScrollingDisabled(true, false);
pane.row();
@@ -65,8 +65,8 @@ public class PlayerListFragment extends Fragment{
float h = 74f;
playerGroup.all().sort(Structs.comparing(Unitc::team));
playerGroup.all().each(user -> {
Groups.player.all().sort(Structs.comparing(Unitc::team));
Groups.player.all().each(user -> {
NetConnection connection = user.con;
if(connection == null && net.server() && !user.isLocal) return;
@@ -129,7 +129,7 @@ public class PlayerListFragment extends Fragment{
t.addImageButton(Icon.zoom, Styles.clearPartiali, () -> Call.onAdminRequest(user, AdminAction.trace));
}).padRight(12).size(bs + 10f, bs);
}else if(!user.isLocal && !user.isAdmin && net.client() && playerGroup.size() >= 3 && player.team() == user.getTeam()){ //votekick
}else if(!user.isLocal && !user.isAdmin && net.client() && Groups.player.size() >= 3 && player.team() == user.getTeam()){ //votekick
button.add().growY();
button.addImageButton(Icon.hammer, Styles.clearPartiali,

View File

@@ -20,7 +20,7 @@ import mindustry.annotations.Annotations.*;
import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.entities.effect.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.graphics.*;
@@ -467,12 +467,12 @@ public class Block extends BlockStorage{
}
/** Called when the block is tapped. */
public void tapped(Tile tile, Player player){
public void tapped(Tile tile, Playerc player){
}
/** Called when arbitrary configuration is applied to a tile. */
public void configured(Tile tile, @Nullable Player player, int value){
public void configured(Tile tile, @Nullable Playerc player, int value){
}
@@ -503,12 +503,12 @@ public class Block extends BlockStorage{
}
/** Returns whether this config menu should show when the specified player taps it. */
public boolean shouldShowConfigure(Tile tile, Player player){
public boolean shouldShowConfigure(Tile tile, Playerc player){
return true;
}
/** Whether this configuration should be hidden now. Called every frame the config is open. */
public boolean shouldHideConfigure(Tile tile, Player player){
public boolean shouldHideConfigure(Tile tile, Playerc player){
return false;
}

View File

@@ -9,7 +9,7 @@ import arc.math.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*;
@@ -55,7 +55,7 @@ public class BuildBlock extends Block{
public static void onDeconstructFinish(Tile tile, Block block, int builderID){
Team team = tile.getTeam();
Fx.breakBlock.at(tile.drawx(), tile.drawy(), block.size);
Events.fire(new BlockBuildEndEvent(tile, playerGroup.getByID(builderID), team, true));
Events.fire(new BlockBuildEndEvent(tile, Groups.player.getByID(builderID), team, true));
tile.remove();
if(shouldPlay()) Sounds.breaks.at(tile, calcPitch(false));
}
@@ -105,7 +105,7 @@ public class BuildBlock extends Block{
Call.onConstructFinish(tile, block, builderID, rotation, team, skipConfig);
tile.block().placed(tile);
Events.fire(new BlockBuildEndEvent(tile, playerGroup.getByID(builderID), team, false));
Events.fire(new BlockBuildEndEvent(tile, Groups.player.getByID(builderID), team, false));
if(shouldPlay()) Sounds.place.at(tile, calcPitch(true));
}
@@ -138,7 +138,7 @@ public class BuildBlock extends Block{
}
@Override
public void tapped(Tile tile, Player player){
public void tapped(Tile tile, Playerc player){
BuildEntity entity = tile.ent();
//if the target is constructible, begin constructing
@@ -279,7 +279,7 @@ public class BuildBlock extends Block{
progress = Mathf.clamp(progress - amount);
if(builder instanceof Player){
if(builder instanceof Playerc){
builderID = builder.getID();
}

View File

@@ -2,9 +2,8 @@ package mindustry.world.blocks;
import arc.graphics.g2d.*;
import arc.math.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.*;
@@ -12,7 +11,7 @@ import static mindustry.Vars.net;
public class RespawnBlock{
public static void drawRespawn(Tile tile, float heat, float progress, float time, Player player, Mech to){
public static void drawRespawn(Tile tile, float heat, float progress, float time, Playerc player, Mech to){
progress = Mathf.clamp(progress);
Draw.color(Pal.darkMetal);
@@ -67,7 +66,7 @@ public class RespawnBlock{
Draw.reset();
if(net.active() && player != null){
tile.block().drawPlaceText(player.name, tile.x, tile.y - (Math.max((tile.block().size-1)/2, 0)), true);
tile.block().drawPlaceText(player.name(), tile.x, tile.y - (Math.max((tile.block().size-1)/2, 0)), true);
}
}
}

View File

@@ -50,7 +50,7 @@ public class DeflectorWall extends Wall{
bullet.hitbox(rect2);
Vec2 position = Geometry.raycastRect(bullet.x - bullet.velocity().x*Time.delta(), bullet.y - bullet.velocity().y*Time.delta(), bullet.x + bullet.velocity().x*Time.delta(), bullet.y + bullet.velocity().y*Time.delta(),
Vec2 position = Geometry.raycastRect(bullet.x - bullet.vel().x*Time.delta(), bullet.y - bullet.vel().y*Time.delta(), bullet.x + bullet.vel().x*Time.delta(), bullet.y + bullet.vel().y*Time.delta(),
rect.setSize(size * tilesize + rect2.width*2 + rect2.height*2).setCenter(entity.getX(), entity.getY()));
if(position != null){
@@ -58,9 +58,9 @@ public class DeflectorWall extends Wall{
}
if(penX > penY){
bullet.velocity().x *= -1;
bullet.vel().x *= -1;
}else{
bullet.velocity().y *= -1;
bullet.vel().y *= -1;
}
//bullet.updateVelocity();

View File

@@ -8,7 +8,6 @@ import arc.graphics.g2d.*;
import arc.math.geom.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.world.*;
@@ -35,7 +34,7 @@ public class Door extends Wall{
}
@Remote(called = Loc.server)
public static void onDoorToggle(Player player, Tile tile, boolean open){
public static void onDoorToggle(Playerc player, Tile tile, boolean open){
DoorEntity entity = tile.ent();
if(entity != null){
entity.open = open;
@@ -80,7 +79,7 @@ public class Door extends Wall{
}
@Override
public void tapped(Tile tile, Player player){
public void tapped(Tile tile, Playerc player){
DoorEntity entity = tile.ent();
if((Units.anyEntities(tile) && entity.open) || !tile.entity.timer(timerToggle, 30f)){

View File

@@ -18,7 +18,7 @@ public class SurgeWall extends Wall{
public void handleBulletHit(Tilec entity, Bullet bullet){
super.handleBulletHit(entity, bullet);
if(Mathf.chance(lightningChance)){
Lightning.create(entity.team(), Pal.surge, lightningDamage, bullet.x, bullet.y, bullet.rot() + 180f, lightningLength);
Lightning.create(entity.team(), Pal.surge, lightningDamage, bullet.x, bullet.y, bullet.rotation() + 180f, lightningLength);
}
}
}

View File

@@ -6,7 +6,7 @@ import arc.scene.ui.layout.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.entities.bullet.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.EventType.*;
import mindustry.graphics.*;
import mindustry.type.*;

View File

@@ -23,8 +23,8 @@ public class BufferedItemBridge extends ExtendingItemBridge{
public void updateTransport(Tile tile, Tile other){
BufferedItemBridgeEntity entity = tile.ent();
if(entity.buffer.accepts() && entity.getItems().total() > 0){
entity.buffer.accept(entity.getItems().take());
if(entity.buffer.accepts() && entity.items().total() > 0){
entity.buffer.accept(entity.items().take());
}
Item item = entity.buffer.poll();

View File

@@ -8,7 +8,7 @@ import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.graphics.*;
import mindustry.type.*;
@@ -45,7 +45,7 @@ public class ItemBridge extends Block{
}
@Override
public void configured(Tile tile, Player player, int value){
public void configured(Tile tile, Playerc player, int value){
tile.<ItemBridgeEntity>ent().link = value;
}
@@ -201,13 +201,13 @@ public class ItemBridge extends Block{
ItemBridgeEntity entity = tile.ent();
if(entity.uptime >= 0.5f && entity.timer(timerTransport, transportTime)){
Item item = entity.getItems().take();
Item item = entity.items().take();
if(item != null && other.block().acceptItem(item, other, tile)){
other.block().handleItem(item, other, tile);
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f);
}else{
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 1f, 0.01f);
if(item != null) entity.getItems().add(item, 1);
if(item != null) entity.items().add(item, 1);
}
}
}

View File

@@ -9,7 +9,7 @@ import arc.util.pooling.Pool.*;
import arc.util.pooling.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.*;
@@ -45,7 +45,7 @@ public class MassDriver extends Block{
}
@Override
public void configured(Tile tile, Player player, int value){
public void configured(Tile tile, Playerc player, int value){
tile.<MassDriverEntity>ent().link = value;
}
@@ -80,7 +80,7 @@ public class MassDriver extends Block{
//switch states
if(entity.state == DriverState.idle){
//start accepting when idle and there's space
if(!entity.waitingShooters.isEmpty() && (itemCapacity - entity.getItems().total() >= minDistribute)){
if(!entity.waitingShooters.isEmpty() && (itemCapacity - entity.items().total() >= minDistribute)){
entity.state = DriverState.accepting;
}else if(hasLink){ //switch to shooting if there's a valid link.
entity.state = DriverState.shooting;
@@ -99,7 +99,7 @@ public class MassDriver extends Block{
if(entity.state == DriverState.accepting){
//if there's nothing shooting at this, bail - OR, items full
if(entity.currentShooter() == null || (itemCapacity - entity.getItems().total() < minDistribute)){
if(entity.currentShooter() == null || (itemCapacity - entity.items().total() < minDistribute)){
entity.state = DriverState.idle;
return;
}
@@ -108,7 +108,7 @@ public class MassDriver extends Block{
entity.rotation = Mathf.slerpDelta(entity.rotation, tile.angleTo(entity.currentShooter()), rotateSpeed * entity.efficiency());
}else if(entity.state == DriverState.shooting){
//if there's nothing to shoot at OR someone wants to shoot at this thing, bail
if(!hasLink || (!entity.waitingShooters.isEmpty() && (itemCapacity - entity.getItems().total() >= minDistribute))){
if(!hasLink || (!entity.waitingShooters.isEmpty() && (itemCapacity - entity.items().total() >= minDistribute))){
entity.state = DriverState.idle;
return;
}
@@ -240,10 +240,10 @@ public class MassDriver extends Block{
data.to = other;
int totalUsed = 0;
for(int i = 0; i < content.items().size; i++){
int maxTransfer = Math.min(entity.getItems().get(content.item(i)), ((MassDriver)tile.block()).itemCapacity - totalUsed);
int maxTransfer = Math.min(entity.items().get(content.item(i)), ((MassDriver)tile.block()).itemCapacity - totalUsed);
data.items[i] = maxTransfer;
totalUsed += maxTransfer;
entity.getItems().remove(content.item(i), maxTransfer);
entity.items().remove(content.item(i), maxTransfer);
}
float angle = tile.angleTo(target);
@@ -262,12 +262,12 @@ public class MassDriver extends Block{
}
protected void handlePayload(MassDriverEntity entity, Bullet bullet, DriverBulletData data){
int totalItems = entity.getItems().total();
int totalItems = entity.items().total();
//add all the items possible
for(int i = 0; i < data.items.length; i++){
int maxAdd = Math.min(data.items[i], itemCapacity * 2 - totalItems);
entity.getItems().add(content.item(i), maxAdd);
entity.items().add(content.item(i), maxAdd);
data.items[i] -= maxAdd;
totalItems += maxAdd;

View File

@@ -5,7 +5,7 @@ import arc.math.*;
import arc.scene.ui.layout.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.type.*;
import mindustry.world.*;
@@ -44,7 +44,7 @@ public class Sorter extends Block{
}
@Override
public void configured(Tile tile, Player player, int value){
public void configured(Tile tile, Playerc player, int value){
tile.<SorterEntity>ent().sortItem = content.item(value);
}

View File

@@ -11,7 +11,6 @@ import arc.scene.ui.layout.*;
import arc.util.*;
import arc.util.pooling.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.net.*;
@@ -36,7 +35,7 @@ public class MessageBlock extends Block{
}
@Remote(targets = Loc.both, called = Loc.both, forward = true)
public static void setMessageBlockText(Player player, Tile tile, String text){
public static void setMessageBlockText(Playerc player, Tile tile, String text){
if(!Units.canInteract(player, tile)) return;
if(net.server() && text.length() > maxTextLength){
throw new ValidateException(player, "Player has gone above text limit.");

View File

@@ -4,7 +4,6 @@ import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.graphics.*;
@@ -63,7 +62,7 @@ public class LightBlock extends Block{
}
@Override
public void configured(Tile tile, Player player, int value){
public void configured(Tile tile, Playerc player, int value){
tile.<LightEntity>ent().color = value;
}

View File

@@ -9,7 +9,7 @@ import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.ui.*;
import mindustry.world.*;
@@ -38,7 +38,7 @@ public class PowerNode extends PowerBlock{
}
@Override
public void configured(Tile tile, Player player, int value){
public void configured(Tile tile, Playerc player, int value){
Tilec entity = tile.entity;
Tile other = world.tile(value);
boolean contains = entity.getPower().links.contains(value), valid = other != null && other.entity != null && other.entity.power() != null;

View File

@@ -6,7 +6,7 @@ import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.ui.*;
import mindustry.world.*;

View File

@@ -4,7 +4,7 @@ import arc.*;
import arc.graphics.g2d.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.type.*;
import mindustry.world.*;
@@ -29,7 +29,7 @@ public class ItemSource extends Block{
}
@Override
public void configured(Tile tile, Player player, int value){
public void configured(Tile tile, Playerc player, int value){
tile.<ItemSourceEntity>ent().outputItem = content.item(value);
}
@@ -73,9 +73,9 @@ public class ItemSource extends Block{
ItemSourceEntity entity = tile.ent();
if(entity.outputItem == null) return;
entity.getItems().set(entity.outputItem, 1);
entity.items().set(entity.outputItem, 1);
tryDump(tile, entity.outputItem);
entity.getItems().set(entity.outputItem, 0);
entity.items().set(entity.outputItem, 0);
}
@Override

View File

@@ -8,7 +8,7 @@ import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.type.*;
@@ -108,7 +108,7 @@ public class LiquidSource extends Block{
}
@Override
public void configured(Tile tile, Player player, int value){
public void configured(Tile tile, Playerc player, int value){
tile.<LiquidSourceEntity>ent().source = value == -1 ? null : content.liquid(value);
}

View File

@@ -8,7 +8,7 @@ import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import mindustry.content.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.game.EventType.*;
import mindustry.graphics.*;
@@ -22,7 +22,7 @@ import mindustry.world.modules.*;
import static mindustry.Vars.*;
public class CoreBlock extends StorageBlock{
public Mech mech = Mechs.starter;
public UnitDef mech = UnitTypes.starter;
public CoreBlock(String name){
super(name);
@@ -38,15 +38,16 @@ public class CoreBlock extends StorageBlock{
}
@Remote(called = Loc.server)
public static void onUnitRespawn(Tile tile, Player player){
public static void onUnitRespawn(Tile tile, Playerc player){
if(player == null || tile.entity == null) return;
CoreEntity entity = tile.ent();
Fx.spawn.at(entity);
entity.progress = 0;
entity.spawnPlayer = player;
entity.spawnPlayer.onRespawn(tile);
entity.spawnPlayer.applyImpulse(0, 8f);
//TODO fix
//entity.spawnPlayer.onRespawn(tile);
//entity.spawnPlayer.applyImpulse(0, 8f);
entity.spawnPlayer = null;
}
@@ -58,7 +59,7 @@ public class CoreBlock extends StorageBlock{
new Bar(
() -> Core.bundle.format("bar.capacity", ui.formatAmount(((CoreEntity)e).storageCapacity)),
() -> Pal.items,
() -> e.items.total() / (float)(((CoreEntity)e).storageCapacity * content.items().count(i -> i.type == ItemType.material))
() -> e.items().total() / (float)(((CoreEntity)e).storageCapacity * content.items().count(i -> i.type == ItemType.material))
));
}
@@ -83,21 +84,21 @@ public class CoreBlock extends StorageBlock{
CoreEntity entity = tile.ent();
for(Tilec other : state.teams.cores(tile.getTeam())){
if(other.tile != tile){
entity.items() = other.items;
if(other.tile() != tile){
entity.items(other.items());
}
}
state.teams.registerCore(entity);
entity.storageCapacity = itemCapacity + entity.proximity().sum(e -> isContainer(e) ? e.block().itemCapacity : 0);
entity.proximity().each(this::isContainer, t -> {
t.entity.items() = entity.items();
t.entity.items(entity.items());
t.<StorageBlockEntity>ent().linkedCore = tile;
});
for(Tilec other : state.teams.cores(tile.getTeam())){
if(other.tile == tile) continue;
entity.storageCapacity += other.block.itemCapacity + other.proximity().sum(e -> isContainer(e) ? e.block().itemCapacity : 0);
if(other.tile() == tile) continue;
entity.storageCapacity += other.block().itemCapacity + other.proximity().sum(e -> isContainer(e) ? e.block().itemCapacity : 0);
}
if(!world.isGenerating()){
@@ -135,9 +136,10 @@ public class CoreBlock extends StorageBlock{
@Override
public float handleDamage(Tile tile, float amount){
if(player != null && tile.getTeam() == player.team()){
Events.fire(Trigger.teamCoreDamage);
}
//TODO implement
//if(player != null && tile.getTeam() == player.team()){
// Events.fire(Trigger.teamCoreDamage);
//}
return amount;
}
@@ -155,9 +157,9 @@ public class CoreBlock extends StorageBlock{
tile.entity.proximity().each(e -> isContainer(e) && e.entity.items() == tile.entity.items(), t -> {
StorageBlockEntity ent = (StorageBlockEntity)t.entity;
ent.linkedCore = null;
ent.items = new ItemModule();
ent.items(new ItemModule());
for(Item item : content.items()){
ent.items.set(item, (int)(fract * tile.entity.items().get(item)));
ent.items().set(item, (int)(fract * tile.entity.items().get(item)));
}
});
@@ -169,7 +171,7 @@ public class CoreBlock extends StorageBlock{
}
for(CoreEntity other : state.teams.cores(tile.getTeam())){
other.block.onProximityUpdate(other.tile);
other.block().onProximityUpdate(other.tile());
}
}
@@ -185,7 +187,8 @@ public class CoreBlock extends StorageBlock{
CoreEntity entity = tile.ent();
if(entity.heat > 0.001f){
RespawnBlock.drawRespawn(tile, entity.heat, entity.progress, entity.time, entity.spawnPlayer, mech);
//TODO implement
//RespawnBlock.drawRespawn(tile, entity.heat, entity.progress, entity.time, entity.spawnPlayer, mech);
}
}
@@ -203,6 +206,8 @@ public class CoreBlock extends StorageBlock{
public void update(Tile tile){
CoreEntity entity = tile.ent();
//TODO implement
/*
if(entity.spawnPlayer != null){
if(!entity.spawnPlayer.dead() || !entity.spawnPlayer.isAdded()){
entity.spawnPlayer = null;
@@ -219,7 +224,7 @@ public class CoreBlock extends StorageBlock{
}
}else{
entity.heat = Mathf.lerpDelta(entity.heat, 0f, 0.1f);
}
}*/
}
@Override
@@ -229,26 +234,11 @@ public class CoreBlock extends StorageBlock{
return entity.spawnPlayer != null;
}
public class CoreEntity extends Tilec implements SpawnerTrait{
protected Player spawnPlayer;
public class CoreEntity extends Tilec{
protected Playerc spawnPlayer;
protected float progress;
protected float time;
protected float heat;
protected int storageCapacity;
@Override
public boolean hasUnit(Unitc unit){
return unit == spawnPlayer;
}
@Override
public void updateSpawning(Player player){
if(!netServer.isWaitingForPlayers() && spawnPlayer == null){
spawnPlayer = player;
progress = 0f;
player.mech = mech;
player.beginRespawning(this);
}
}
}
}

View File

@@ -4,7 +4,7 @@ import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.type.*;
import mindustry.world.*;
@@ -54,7 +54,7 @@ public class Unloader extends Block{
}
@Override
public void configured(Tile tile, Player player, int value){
public void configured(Tile tile, Playerc player, int value){
tile.entity.items().clear();
tile.<UnloaderEntity>ent().sortItem = content.item(value);
}
@@ -65,14 +65,14 @@ public class Unloader extends Block{
if(tile.entity.timer(timerUnload, speed / entity.timeScale) && tile.entity.items().total() == 0){
for(Tile other : tile.entity.proximity()){
if(other.interactable(tile.getTeam()) && other.block().unloadable && other.block().hasItems && entity.getItems().total() == 0 &&
if(other.interactable(tile.getTeam()) && other.block().unloadable && other.block().hasItems && entity.items().total() == 0 &&
((entity.sortItem == null && other.entity.items().total() > 0) || hasItem(other, entity.sortItem))){
offloadNear(tile, removeItem(other, entity.sortItem));
}
}
}
if(entity.getItems().total() > 0){
if(entity.items().total() > 0){
tryDump(tile);
}
}
@@ -85,10 +85,10 @@ public class Unloader extends Block{
Tilec entity = tile.entity;
if(item == null){
return entity.getItems().take();
return entity.items().take();
}else{
if(entity.getItems().has(item)){
entity.getItems().remove(item, 1);
if(entity.items().has(item)){
entity.items().remove(item, 1);
return item;
}
@@ -103,9 +103,9 @@ public class Unloader extends Block{
private boolean hasItem(Tile tile, Item item){
Tilec entity = tile.entity;
if(item == null){
return entity.getItems().total() > 0;
return entity.items().total() > 0;
}else{
return entity.getItems().has(item);
return entity.items().has(item);
}
}

View File

@@ -10,7 +10,7 @@ import arc.struct.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*;
import mindustry.graphics.*;
@@ -102,7 +102,7 @@ public class CommandCenter extends Block{
}
@Override
public void configured(Tile tile, Player player, int value){
public void configured(Tile tile, Playerc player, int value){
UnitCommand command = UnitCommand.all[value];
((CommandCenter)tile.block()).effect.at(tile);

View File

@@ -9,10 +9,11 @@ import arc.math.geom.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import mindustry.content.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.game.EventType.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.meta.*;
@@ -22,7 +23,7 @@ import java.io.*;
import static mindustry.Vars.*;
public class MechPad extends Block{
public @NonNull Mech mech;
public @NonNull UnitDef mech;
public float buildTime = 60 * 5;
public MechPad(String name){
@@ -43,7 +44,7 @@ public class MechPad extends Block{
}
@Remote(targets = Loc.both, called = Loc.server)
public static void onMechFactoryTap(Player player, Tile tile){
public static void onMechFactoryTap(Playerc player, Tile tile){
if(player == null || tile == null || !(tile.block() instanceof MechPad) || !checkValidTap(tile, player)) return;
MechFactoryEntity entity = tile.ent();
@@ -64,9 +65,9 @@ public class MechPad extends Block{
if(entity.player == null) return;
Mech mech = ((MechPad)tile.block()).mech;
boolean resetSpawner = !entity.sameMech && entity.player.mech == mech;
entity.player.mech = !entity.sameMech && entity.player.mech == mech ? Mechs.starter : mech;
entity.player.mech = !entity.sameMech && entity.player.mech == mech ? UnitTypes.starter : mech;
Player player = entity.player;
Playerc player = entity.player;
entity.progress = 0;
entity.player.onRespawn(tile);
@@ -76,7 +77,7 @@ public class MechPad extends Block{
Events.fire(new MechChangeEvent(player, player.mech));
}
protected static boolean checkValidTap(Tile tile, Player player){
protected static boolean checkValidTap(Tile tile, Playerc player){
MechFactoryEntity entity = tile.ent();
return !player.dead() && tile.interactable(player.team()) && Math.abs(player.x - tile.drawx()) <= tile.block().size * tilesize &&
Math.abs(player.y - tile.drawy()) <= tile.block().size * tilesize && entity.consValid() && entity.player == null;
@@ -93,12 +94,12 @@ public class MechPad extends Block{
}
@Override
public void tapped(Tile tile, Player player){
public void tapped(Tile tile, Playerc player){
MechFactoryEntity entity = tile.ent();
if(checkValidTap(tile, player)){
Call.onMechFactoryTap(player, tile);
}else if(player.isLocal && mobile && !player.dead() && entity.consValid() && entity.player == null){
}else if(player.isLocal() && mobile && !player.dead() && entity.consValid() && entity.player == null){
//deselect on double taps
player.moveTarget = player.moveTarget == tile.entity ? null : tile.entity;
}
@@ -109,7 +110,7 @@ public class MechPad extends Block{
MechFactoryEntity entity = tile.ent();
if(entity.player != null){
RespawnBlock.drawRespawn(tile, entity.heat, entity.progress, entity.time, entity.player, (!entity.sameMech && entity.player.mech == mech ? Mechs.starter : mech));
RespawnBlock.drawRespawn(tile, entity.heat, entity.progress, entity.time, entity.player, (!entity.sameMech && entity.player.mech == mech ? UnitTypes.starter : mech));
}
}
@@ -133,7 +134,7 @@ public class MechPad extends Block{
}
public class MechFactoryEntity extends Tilec implements SpawnerTrait{
Player player;
Playerc player;
boolean sameMech;
float progress;
float time;
@@ -145,7 +146,7 @@ public class MechPad extends Block{
}
@Override
public void updateSpawning(Player unit){
public void updateSpawning(Playerc unit){
if(player == null){
progress = 0f;
player = unit;

View File

@@ -1,33 +1,27 @@
package mindustry.world.blocks.units;
import arc.*;
import mindustry.annotations.Annotations.Loc;
import mindustry.annotations.Annotations.Remote;
import arc.struct.EnumSet;
import arc.graphics.g2d.*;
import arc.math.Mathf;
import mindustry.Vars;
import mindustry.content.Fx;
import mindustry.entities.Effects;
import mindustry.entities.type.*;
import mindustry.game.EventType.*;
import mindustry.gen.Call;
import mindustry.graphics.Pal;
import mindustry.graphics.Shaders;
import arc.math.*;
import arc.struct.*;
import mindustry.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.ui.Bar;
import mindustry.ui.Cicon;
import mindustry.world.Block;
import mindustry.world.Tile;
import mindustry.world.consumers.ConsumeItems;
import mindustry.world.consumers.ConsumeType;
import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.consumers.*;
import mindustry.world.meta.*;
import java.io.*;
import static mindustry.Vars.*;
import static mindustry.Vars.net;
public class UnitFactory extends Block{
public UnitType unitType;
public UnitDef unitType;
public float produceTime = 1000f;
public float launchVelocity = 0f;
public TextureRegion topRegion;
@@ -58,12 +52,14 @@ public class UnitFactory extends Block{
Fx.producesmoke.at(tile.drawx(), tile.drawy());
if(!net.client()){
BaseUnit unit = factory.unitType.create(tile.getTeam());
//TODO create the unit
/*
Unitc unit = factory.unitType.create(tile.getTeam());
unit.setSpawner(tile);
unit.set(tile.drawx() + Mathf.range(4), tile.drawy() + Mathf.range(4));
unit.add();
unit.velocity().y = factory.launchVelocity;
Events.fire(new UnitCreateEvent(unit));
unit.vel().y = factory.launchVelocity;
Events.fire(new UnitCreateEvent(unit));*/
}
}

View File

@@ -53,8 +53,8 @@ public class ConsumeItemFilter extends Consume{
public void trigger(Tilec entity){
for(int i = 0; i < content.items().size; i++){
Item item = content.item(i);
if(entity.getItems() != null && entity.getItems().has(item) && this.filter.get(item)){
entity.getItems().remove(item, 1);
if(entity.items() != null && entity.items().has(item) && this.filter.get(item)){
entity.items().remove(item, 1);
break;
}
}
@@ -64,7 +64,7 @@ public class ConsumeItemFilter extends Consume{
public boolean valid(Tilec entity){
for(int i = 0; i < content.items().size; i++){
Item item = content.item(i);
if(entity.getItems() != null && entity.getItems().has(item) && this.filter.get(item)){
if(entity.items() != null && entity.items().has(item) && this.filter.get(item)){
return true;
}
}

View File

@@ -54,13 +54,13 @@ public class ConsumeItems extends Consume{
@Override
public void trigger(Tilec entity){
for(ItemStack stack : items){
entity.getItems().remove(stack);
entity.items().remove(stack);
}
}
@Override
public boolean valid(Tilec entity){
return entity.getItems() != null && entity.getItems().has(items);
return entity.items() != null && entity.items().has(items);
}
@Override

View File

@@ -3,7 +3,7 @@ package mindustry.world.consumers;
import arc.struct.*;
import arc.scene.ui.layout.*;
import arc.util.ArcAnnotate.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.ui.Cicon;