Formation cleanup
This commit is contained in:
@@ -11,4 +11,6 @@ import arc.math.geom.*;
|
|||||||
public interface FormationMember{
|
public interface FormationMember{
|
||||||
/** Returns the target location of this formation member. */
|
/** Returns the target location of this formation member. */
|
||||||
Vec3 formationPos();
|
Vec3 formationPos();
|
||||||
|
|
||||||
|
float formationSize();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import arc.math.geom.*;
|
|||||||
*/
|
*/
|
||||||
public abstract class FormationPattern{
|
public abstract class FormationPattern{
|
||||||
public int slots;
|
public int slots;
|
||||||
|
/** Spacing between members. */
|
||||||
|
public float spacing = 20f;
|
||||||
|
|
||||||
/** Returns the location of the given slot index. */
|
/** Returns the location of the given slot index. */
|
||||||
public abstract Vec3 calculateSlotLocation(Vec3 out, int slot);
|
public abstract Vec3 calculateSlotLocation(Vec3 out, int slot);
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package mindustry.ai.formations.patterns;
|
||||||
|
|
||||||
|
import arc.math.geom.*;
|
||||||
|
import mindustry.ai.formations.*;
|
||||||
|
|
||||||
|
public class ArrowFormation extends FormationPattern{
|
||||||
|
//total triangular numbers
|
||||||
|
private static final int totalTris = 30;
|
||||||
|
//triangular number table
|
||||||
|
private static final int[] triTable = new int[totalTris];
|
||||||
|
|
||||||
|
//calculat triangular numbers
|
||||||
|
static{
|
||||||
|
int sum = 0;
|
||||||
|
for(int i = 0; i < totalTris; i++){
|
||||||
|
triTable[i] = sum;
|
||||||
|
sum += (i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vec3 calculateSlotLocation(Vec3 out, int slot){
|
||||||
|
//TODO
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,6 @@ import arc.math.geom.*;
|
|||||||
import mindustry.ai.formations.*;
|
import mindustry.ai.formations.*;
|
||||||
|
|
||||||
public class SquareFormation extends FormationPattern{
|
public class SquareFormation extends FormationPattern{
|
||||||
public float spacing = 20;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vec3 calculateSlotLocation(Vec3 out, int slot){
|
public Vec3 calculateSlotLocation(Vec3 out, int slot){
|
||||||
|
|||||||
@@ -60,6 +60,15 @@ public class FormationAI extends AIController implements FormationMember{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float formationSize(){
|
||||||
|
if(unit instanceof Commanderc && ((Commanderc)unit).isCommanding()){
|
||||||
|
//TODO return formation size
|
||||||
|
//eturn ((Commanderc)unit).formation().
|
||||||
|
}
|
||||||
|
return unit.hitSize * 2f;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBeingControlled(Unit player){
|
public boolean isBeingControlled(Unit player){
|
||||||
return leader == player;
|
return leader == player;
|
||||||
|
|||||||
@@ -670,6 +670,12 @@ public class Fx{
|
|||||||
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
sporeSlowed = new Effect(40f, e -> {
|
||||||
|
color(Pal.spore);
|
||||||
|
|
||||||
|
Fill.circle(e.x, e.y, e.fslope() * 1.1f);
|
||||||
|
}),
|
||||||
|
|
||||||
oily = new Effect(42f, e -> {
|
oily = new Effect(42f, e -> {
|
||||||
color(Liquids.oil.color);
|
color(Liquids.oil.color);
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import mindustry.type.StatusEffect;
|
|||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class StatusEffects implements ContentList{
|
public class StatusEffects implements ContentList{
|
||||||
public static StatusEffect none, burning, freezing, wet, melting, sapped, tarred, overdrive, overclock, shielded, shocked, blasted, corroded, boss;
|
public static StatusEffect none, burning, freezing, wet, melting, sapped, tarred, overdrive, overclock, shielded, shocked, blasted, corroded, boss, sporeSlowed;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(){
|
public void load(){
|
||||||
@@ -82,6 +82,12 @@ public class StatusEffects implements ContentList{
|
|||||||
effectChance = 0.1f;
|
effectChance = 0.1f;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
sporeSlowed = new StatusEffect("sapped"){{
|
||||||
|
speedMultiplier = 0.8f;
|
||||||
|
effect = Fx.sapped;
|
||||||
|
effectChance = 0.04f;
|
||||||
|
}};
|
||||||
|
|
||||||
tarred = new StatusEffect("tarred"){{
|
tarred = new StatusEffect("tarred"){{
|
||||||
speedMultiplier = 0.6f;
|
speedMultiplier = 0.6f;
|
||||||
effect = Fx.oily;
|
effect = Fx.oily;
|
||||||
|
|||||||
@@ -255,6 +255,8 @@ public class Weathers implements ContentList{
|
|||||||
{
|
{
|
||||||
attrs.set(Attribute.spores, 0.5f);
|
attrs.set(Attribute.spores, 0.5f);
|
||||||
attrs.set(Attribute.light, -0.1f);
|
attrs.set(Attribute.light, -0.1f);
|
||||||
|
status = StatusEffects.sporeSlowed;
|
||||||
|
statusGround = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -45,18 +45,24 @@ abstract class CommanderComp implements Unitc{
|
|||||||
void command(Formation formation, Seq<Unit> units){
|
void command(Formation formation, Seq<Unit> units){
|
||||||
clearCommand();
|
clearCommand();
|
||||||
|
|
||||||
|
float spacing = 8f;
|
||||||
|
|
||||||
controlling.addAll(units);
|
controlling.addAll(units);
|
||||||
for(Unit unit : units){
|
for(Unit unit : units){
|
||||||
unit.controller(new FormationAI(base(), formation));
|
FormationAI ai;
|
||||||
|
unit.controller(ai = new FormationAI(base(), formation));
|
||||||
|
spacing = Math.max(spacing, ai.formationSize());
|
||||||
}
|
}
|
||||||
this.formation = formation;
|
this.formation = formation;
|
||||||
|
|
||||||
|
//update formation spacing based on max size
|
||||||
|
formation.pattern.spacing = spacing;
|
||||||
|
|
||||||
members.clear();
|
members.clear();
|
||||||
for(Unitc u : units){
|
for(Unitc u : units){
|
||||||
members.add((FormationAI)u.controller());
|
members.add((FormationAI)u.controller());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//TODO doesn't handle units that don't fit a formation
|
//TODO doesn't handle units that don't fit a formation
|
||||||
formation.addMembers(members);
|
formation.addMembers(members);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ public class Pal{
|
|||||||
|
|
||||||
sap = Color.valueOf("665c9f"),
|
sap = Color.valueOf("665c9f"),
|
||||||
|
|
||||||
|
spore = Color.valueOf("7457ce"),
|
||||||
|
|
||||||
shield = Color.valueOf("ffd37f").a(0.7f),
|
shield = Color.valueOf("ffd37f").a(0.7f),
|
||||||
shieldIn = Color.black.cpy().a(0f),
|
shieldIn = Color.black.cpy().a(0f),
|
||||||
|
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
if(commander.isCommanding()){
|
if(commander.isCommanding()){
|
||||||
commander.clearCommand();
|
commander.clearCommand();
|
||||||
}else{
|
}else{
|
||||||
SquareFormation pattern = new SquareFormation();
|
FormationPattern pattern = new SquareFormation();
|
||||||
Formation formation = new Formation(new Vec3(player.x, player.y, player.unit().rotation), pattern);
|
Formation formation = new Formation(new Vec3(player.x, player.y, player.unit().rotation), pattern);
|
||||||
formation.slotAssignmentStrategy = new DistanceAssignmentStrategy(pattern);
|
formation.slotAssignmentStrategy = new DistanceAssignmentStrategy(pattern);
|
||||||
|
|
||||||
@@ -282,8 +282,6 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
units.sort(u -> u.dst2(player.unit()));
|
units.sort(u -> u.dst2(player.unit()));
|
||||||
units.truncate(player.unit().type().commandLimit);
|
units.truncate(player.unit().type().commandLimit);
|
||||||
|
|
||||||
if(units.any()) pattern.spacing = units.max(u -> u.hitSize).hitSize * 2f;
|
|
||||||
|
|
||||||
commander.command(formation, units);
|
commander.command(formation, units);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public abstract class Weather extends MappableContent{
|
|||||||
public Prov<WeatherState> type = WeatherState::create;
|
public Prov<WeatherState> type = WeatherState::create;
|
||||||
public StatusEffect status = StatusEffects.none;
|
public StatusEffect status = StatusEffects.none;
|
||||||
public float statusDuration = 60f * 2;
|
public float statusDuration = 60f * 2;
|
||||||
|
public boolean statusAir = true, statusGround = true;
|
||||||
|
|
||||||
public Weather(String name, Prov<WeatherState> type){
|
public Weather(String name, Prov<WeatherState> type){
|
||||||
super(name);
|
super(name);
|
||||||
@@ -68,7 +69,11 @@ public abstract class Weather extends MappableContent{
|
|||||||
if(state.effectTimer <= 0){
|
if(state.effectTimer <= 0){
|
||||||
state.effectTimer = statusDuration - 5f;
|
state.effectTimer = statusDuration - 5f;
|
||||||
|
|
||||||
Groups.unit.each(u -> u.apply(status, statusDuration));
|
Groups.unit.each(u -> {
|
||||||
|
if(u.checkTarget(statusAir, statusGround)){
|
||||||
|
u.apply(status, statusDuration);
|
||||||
|
}
|
||||||
|
});
|
||||||
}else{
|
}else{
|
||||||
state.effectTimer -= Time.delta;
|
state.effectTimer -= Time.delta;
|
||||||
}
|
}
|
||||||
|
|||||||
11
core/src/mindustry/world/blocks/units/ControlCenter.java
Normal file
11
core/src/mindustry/world/blocks/units/ControlCenter.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package mindustry.world.blocks.units;
|
||||||
|
|
||||||
|
import mindustry.world.*;
|
||||||
|
|
||||||
|
public class ControlCenter extends Block{
|
||||||
|
|
||||||
|
public ControlCenter(String name){
|
||||||
|
super(name);
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user