Basic AI defending

This commit is contained in:
Anuken
2022-02-18 11:27:20 -05:00
parent 520b60770c
commit 027d037233
7 changed files with 210 additions and 57 deletions

View File

@@ -54,6 +54,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
static final ObjectSet<Building> tmpTiles = new ObjectSet<>();
static final Seq<Building> tempBuilds = new Seq<>();
static final BuildTeamChangeEvent teamChangeEvent = new BuildTeamChangeEvent();
static final BuildDamageEvent bulletDamageEvent = new BuildDamageEvent();
static int sleepingEntities = 0;
@Import float x, y, health, maxHealth;
@@ -262,6 +263,19 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
data.blocks.addFirst(new BlockPlan(tile.x, tile.y, (short)rotation, block.id, overrideConfig == null ? config() : overrideConfig));
}
public @Nullable Tile findClosestEdge(Position to, Boolf<Tile> solid){
Tile best = null;
float mindst = 0f;
for(var point : Edges.getEdges(block.size)){
Tile other = Vars.world.tile(tile.x + point.x, tile.y + point.y);
if(other != null && !solid.get(other) && (best == null || to.dst2(other) < mindst)){
best = other;
mindst = other.dst2(other);
}
}
return best;
}
/** Configure with the current, local player. */
public void configure(Object value){
//save last used config
@@ -1498,6 +1512,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
* @return whether the bullet should be removed. */
public boolean collision(Bullet other){
damage(other.team, other.damage() * other.type().buildingDamageMultiplier);
Events.fire(bulletDamageEvent.set(self(), other));
return true;
}
@@ -1507,6 +1522,12 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
damage(damage);
}
/** Handles splash damage with a bullet source. */
public void damage(Bullet bullet, Team source, float damage){
damage(source, damage);
Events.fire(bulletDamageEvent.set(self(), bullet));
}
/** Changes this building's team in a safe manner. */
public void changeTeam(Team next){
Team last = this.team;