Merge branch 'master' into healbullets-bullets
This commit is contained in:
@@ -65,7 +65,7 @@ public class Units{
|
||||
|
||||
/** @return whether a new instance of a unit of this team can be created. */
|
||||
public static boolean canCreate(Team team, UnitType type){
|
||||
return teamIndex.countType(team, type) < getCap(team);
|
||||
return team.data().countType(type) < getCap(team);
|
||||
}
|
||||
|
||||
public static int getCap(Team team){
|
||||
@@ -284,7 +284,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<Unit> cons){
|
||||
teamIndex.tree(team).intersect(x, y, width, height, cons);
|
||||
team.data().tree().intersect(x, y, width, height, cons);
|
||||
}
|
||||
|
||||
/** Iterates over all units in a circle around this position. */
|
||||
@@ -316,7 +316,7 @@ public class Units{
|
||||
//inactive teams have no cache, check everything
|
||||
//TODO cache all teams with units OR blocks
|
||||
for(Team other : Team.all){
|
||||
if(other != team && teamIndex.count(other) > 0){
|
||||
if(other != team && other.data().unitCount > 0){
|
||||
nearby(other, x, y, width, height, cons);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +146,9 @@ public abstract class BulletType extends Content{
|
||||
}
|
||||
|
||||
public void hitTile(Bullet b, Building tile, float initialHealth){
|
||||
if(status == StatusEffects.burning) {
|
||||
Fires.create(tile.tile);
|
||||
}
|
||||
hit(b);
|
||||
|
||||
if(healPercent > 0f && tile.team == b.team && !(tile.block instanceof ConstructBlock)){
|
||||
@@ -193,11 +196,16 @@ public abstract class BulletType extends Content{
|
||||
if(status != StatusEffects.none){
|
||||
Damage.status(b.team, x, y, splashDamageRadius, status, statusDuration, collidesAir, collidesGround);
|
||||
}
|
||||
|
||||
|
||||
if(healPercent > 0f) {
|
||||
indexer.eachBlock(b.team, x, y, splashDamageRadius, other -> other.damaged(), other -> {
|
||||
Fx.healBlockFull.at(other.x, other.y, other.block.size, Pal.heal);
|
||||
other.heal(healPercent / 100f * other.maxHealth());
|
||||
}
|
||||
|
||||
if(status == StatusEffects.burning) {
|
||||
indexer.eachBlock(null, x, y, splashDamageRadius, other -> other.team != b.team, other -> {
|
||||
Fires.create(other.tile);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,12 +31,12 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
|
||||
public void getCollisions(Cons<QuadTree> consumer){
|
||||
if(team.active()){
|
||||
for(Team team : team.enemies()){
|
||||
consumer.get(teamIndex.tree(team));
|
||||
consumer.get(team.data().tree());
|
||||
}
|
||||
}else{
|
||||
for(Team other : Team.all){
|
||||
if(other != team && teamIndex.count(other) > 0){
|
||||
consumer.get(teamIndex.tree(other));
|
||||
if(other != team && team.data().unitCount > 0){
|
||||
consumer.get(team.data().tree());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
core/src/mindustry/entities/comp/PosTeamDef.java
Normal file
9
core/src/mindustry/entities/comp/PosTeamDef.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package mindustry.entities.comp;
|
||||
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
//dummy target definition
|
||||
@EntityDef(value = Teamc.class, genio = false, isFinal = false)
|
||||
public class PosTeamDef{
|
||||
}
|
||||
@@ -27,7 +27,7 @@ import mindustry.world.blocks.environment.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@Component(base = true)
|
||||
abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, Itemsc, Rotc, Unitc, Weaponsc, Drawc, Boundedc, Syncc, Shieldc, Displayable, Senseable{
|
||||
abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, Itemsc, Rotc, Unitc, Weaponsc, Drawc, Boundedc, Syncc, Shieldc, Displayable, Senseable, Ranged{
|
||||
|
||||
@Import boolean hovering, dead;
|
||||
@Import float x, y, rotation, elevation, maxHealth, drag, armor, hitSize, health, ammo;
|
||||
@@ -38,6 +38,9 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
||||
private UnitType type;
|
||||
boolean spawnedByCore;
|
||||
|
||||
//TODO mark as non-transient when done
|
||||
transient double flag;
|
||||
|
||||
transient Seq<Ability> abilities = new Seq<>(0);
|
||||
private transient float resupplyTime = Mathf.random(10f);
|
||||
|
||||
@@ -63,6 +66,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
||||
return type.hasWeapons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float range(){
|
||||
return type.range;
|
||||
}
|
||||
@@ -76,6 +80,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
||||
public double sense(LAccess sensor){
|
||||
return switch(sensor){
|
||||
case totalItems -> stack().amount;
|
||||
case itemCapacity -> type.itemCapacity;
|
||||
case rotation -> rotation;
|
||||
case health -> health;
|
||||
case maxHealth -> maxHealth;
|
||||
@@ -85,6 +90,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
||||
case shooting -> isShooting() ? 1 : 0;
|
||||
case shootX -> aimX();
|
||||
case shootY -> aimY();
|
||||
case flag -> flag;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
@@ -93,6 +99,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
||||
public Object senseObject(LAccess sensor){
|
||||
return switch(sensor){
|
||||
case type -> type;
|
||||
case name -> controller instanceof Player p ? p.name : null;
|
||||
default -> noSensed;
|
||||
};
|
||||
|
||||
@@ -182,7 +189,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
||||
}
|
||||
|
||||
public int count(){
|
||||
return teamIndex.countType(team, type);
|
||||
return team.data().countType(type);
|
||||
}
|
||||
|
||||
public int cap(){
|
||||
@@ -224,13 +231,13 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
||||
//check if over unit cap
|
||||
if(count() > cap() && !spawnedByCore && !dead){
|
||||
Call.unitCapDeath(self());
|
||||
teamIndex.updateCount(team, type, -1);
|
||||
team.data().updateCount(type, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(){
|
||||
teamIndex.updateCount(team, type, -1);
|
||||
team.data().updateCount(type, -1);
|
||||
controller.removed(self());
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.ai.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
@@ -63,6 +64,23 @@ public class AIController implements UnitController{
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean invalid(Teamc target){
|
||||
return Units.invalidateTarget(target, unit.team, unit.x, unit.y);
|
||||
}
|
||||
|
||||
|
||||
protected void pathfind(int pathTarget){
|
||||
int costType = unit.pathType();
|
||||
|
||||
Tile tile = unit.tileOn();
|
||||
if(tile == null) return;
|
||||
Tile targetTile = pathfinder.getTargetTile(tile, pathfinder.getField(unit.team, costType, pathTarget));
|
||||
|
||||
if(tile == targetTile || (costType == Pathfinder.costWater && !targetTile.floor().isLiquid)) return;
|
||||
|
||||
unit.moveAt(vec.trns(unit.angleTo(targetTile), unit.type().speed));
|
||||
}
|
||||
|
||||
protected void updateWeapons(){
|
||||
if(targets.length != unit.mounts.length) targets = new Teamc[unit.mounts.length];
|
||||
|
||||
@@ -73,7 +91,7 @@ public class AIController implements UnitController{
|
||||
target = findTarget(unit.x, unit.y, unit.range(), unit.type().targetAir, unit.type().targetGround);
|
||||
}
|
||||
|
||||
if(Units.invalidateTarget(target, unit.team, unit.x, unit.y)){
|
||||
if(invalid(target)){
|
||||
target = null;
|
||||
}
|
||||
|
||||
@@ -99,13 +117,11 @@ public class AIController implements UnitController{
|
||||
boolean shoot = false;
|
||||
|
||||
if(targets[i] != null){
|
||||
shoot = targets[i].within(mountX, mountY, weapon.bullet.range());
|
||||
shoot = targets[i].within(mountX, mountY, weapon.bullet.range()) && shouldShoot();
|
||||
|
||||
if(shoot){
|
||||
Vec2 to = Predict.intercept(unit, targets[i], weapon.bullet.speed);
|
||||
mount.aimX = to.x;
|
||||
mount.aimY = to.y;
|
||||
}
|
||||
Vec2 to = Predict.intercept(unit, targets[i], weapon.bullet.speed);
|
||||
mount.aimX = to.x;
|
||||
mount.aimY = to.y;
|
||||
}
|
||||
|
||||
mount.shoot = shoot;
|
||||
@@ -113,6 +129,10 @@ public class AIController implements UnitController{
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean shouldShoot(){
|
||||
return true;
|
||||
}
|
||||
|
||||
protected Teamc targetFlag(float x, float y, BlockFlag flag, boolean enemy){
|
||||
Tile target = Geometry.findClosest(x, y, enemy ? indexer.getEnemy(unit.team, flag) : indexer.getAllied(unit.team, flag));
|
||||
return target == null ? null : target.build;
|
||||
@@ -157,11 +177,15 @@ public class AIController implements UnitController{
|
||||
}
|
||||
|
||||
protected void moveTo(Position target, float circleLength){
|
||||
moveTo(target, circleLength, 100f);
|
||||
}
|
||||
|
||||
protected void moveTo(Position target, float circleLength, float smooth){
|
||||
if(target == null) return;
|
||||
|
||||
vec.set(target).sub(unit);
|
||||
|
||||
float length = circleLength <= 0.001f ? 1f : Mathf.clamp((unit.dst(target) - circleLength) / 100f, -1f, 1f);
|
||||
float length = circleLength <= 0.001f ? 1f : Mathf.clamp((unit.dst(target) - circleLength) / smooth, -1f, 1f);
|
||||
|
||||
vec.setLength(unit.type().speed * length);
|
||||
if(length < -0.5f){
|
||||
|
||||
Reference in New Issue
Block a user