Fixed rubble-related crash, improved vtol AI
This commit is contained in:
BIN
core/assets-raw/sprites/blocks/extra/rubble-3-1.png
Normal file
BIN
core/assets-raw/sprites/blocks/extra/rubble-3-1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 459 B |
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 107 KiB |
@@ -520,7 +520,7 @@ public class Renderer extends RendererModule{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if((!debug || showUI) && Settings.getBool("healthbars")){
|
if((!debug || showUI) && Settings.getBool("healthbars")){
|
||||||
for(TeamData ally : state.teams.getTeams(true)){
|
for(TeamData ally : (debug ? state.teams.getTeams() : state.teams.getTeams(true))){
|
||||||
for(Unit e : unitGroups[ally.team.ordinal()].all()){
|
for(Unit e : unitGroups[ally.team.ordinal()].all()){
|
||||||
drawStats(e);
|
drawStats(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ public class BaseUnit extends Unit{
|
|||||||
((TileEntity)target).tile.block().flags.contains(flag);
|
((TileEntity)target).tile.block().flags.contains(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setState(UnitState state){
|
||||||
|
this.state.set(this, state);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptsAmmo(Item item) {
|
public boolean acceptsAmmo(Item item) {
|
||||||
return type.ammo.containsKey(item) && inventory.canAcceptAmmo(type.ammo.get(item));
|
return type.ammo.containsKey(item) && inventory.canAcceptAmmo(type.ammo.get(item));
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public class StateMachine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void set(BaseUnit unit, UnitState next){
|
public void set(BaseUnit unit, UnitState next){
|
||||||
|
if(next == state) return;
|
||||||
if(state != null) state.exited(unit);
|
if(state != null) state.exited(unit);
|
||||||
this.state = next;
|
this.state = next;
|
||||||
if(next != null) next.entered(unit);
|
if(next != null) next.entered(unit);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import io.anuke.ucore.util.Mathf;
|
|||||||
import static io.anuke.mindustry.Vars.world;
|
import static io.anuke.mindustry.Vars.world;
|
||||||
|
|
||||||
public class Vtol extends FlyingUnitType {
|
public class Vtol extends FlyingUnitType {
|
||||||
|
private float retreatHealth = 10f;
|
||||||
|
|
||||||
public Vtol(){
|
public Vtol(){
|
||||||
super("vtol");
|
super("vtol");
|
||||||
@@ -94,6 +95,15 @@ public class Vtol extends FlyingUnitType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void behavior(BaseUnit unit) {
|
||||||
|
if(unit.health <= retreatHealth &&
|
||||||
|
Geometry.findClosest(unit.x, unit.y, world.indexer().getAllied(unit.team, BlockFlag.repair)) != null){
|
||||||
|
unit.setState(retreat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public UnitState getStartState(){
|
public UnitState getStartState(){
|
||||||
return resupply;
|
return resupply;
|
||||||
}
|
}
|
||||||
@@ -119,7 +129,7 @@ public class Vtol extends FlyingUnitType {
|
|||||||
if(diff > 100f && vec.len() < circleLength){
|
if(diff > 100f && vec.len() < circleLength){
|
||||||
vec.setAngle(unit.velocity.angle());
|
vec.setAngle(unit.velocity.angle());
|
||||||
}else{
|
}else{
|
||||||
vec.setAngle(Mathf.slerpDelta(unit.velocity.angle(), vec.angle(), 0.4f));
|
vec.setAngle(Mathf.slerpDelta(unit.velocity.angle(), vec.angle(), 0.44f));
|
||||||
}
|
}
|
||||||
|
|
||||||
vec.setLength(speed*Timers.delta());
|
vec.setLength(speed*Timers.delta());
|
||||||
@@ -153,13 +163,12 @@ public class Vtol extends FlyingUnitType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update(BaseUnit unit) {
|
public void update(BaseUnit unit) {
|
||||||
|
|
||||||
if(!unit.inventory.hasAmmo()) {
|
if(!unit.inventory.hasAmmo()) {
|
||||||
unit.state.set(unit, resupply);
|
unit.state.set(unit, resupply);
|
||||||
}else if (unit.target == null){
|
}else if (unit.target == null){
|
||||||
if(unit.timer.get(timerTarget, 20)) {
|
if(unit.timer.get(timerTarget, 20)) {
|
||||||
Unit closest = Units.getClosestEnemy(unit.team, unit.x, unit.y,
|
Unit closest = Units.getClosestEnemy(unit.team, unit.x, unit.y,
|
||||||
unit.inventory.getAmmo().getRange(), other -> true);
|
unit.inventory.getAmmo().getRange(), other -> other.distanceTo(unit) < 60f);
|
||||||
if(closest != null){
|
if(closest != null){
|
||||||
unit.target = closest;
|
unit.target = closest;
|
||||||
}else {
|
}else {
|
||||||
@@ -170,7 +179,7 @@ public class Vtol extends FlyingUnitType {
|
|||||||
}else{
|
}else{
|
||||||
attack(unit, 150f);
|
attack(unit, 150f);
|
||||||
|
|
||||||
if (unit.timer.get(timerReload, 7) && Mathf.angNear(unit.angleTo(unit.target), unit.rotation, 16f)
|
if (unit.timer.get(timerReload, 7) && Mathf.angNear(unit.angleTo(unit.target), unit.rotation, 13f)
|
||||||
&& unit.distanceTo(unit.target) < unit.inventory.getAmmo().getRange()) {
|
&& unit.distanceTo(unit.target) < unit.inventory.getAmmo().getRange()) {
|
||||||
AmmoType ammo = unit.inventory.getAmmo();
|
AmmoType ammo = unit.inventory.getAmmo();
|
||||||
unit.inventory.useAmmo();
|
unit.inventory.useAmmo();
|
||||||
@@ -179,6 +188,24 @@ public class Vtol extends FlyingUnitType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
retreat = new UnitState() {
|
||||||
|
public void entered(BaseUnit unit) {
|
||||||
|
unit.target = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(BaseUnit unit) {
|
||||||
|
if(unit.health >= health){
|
||||||
|
unit.state.set(unit, attack);
|
||||||
|
}else if(!unit.targetHasFlag(BlockFlag.repair)){
|
||||||
|
if(unit.timer.get(timerTarget, 20)) {
|
||||||
|
Tile target = Geometry.findClosest(unit.x, unit.y, world.indexer().getAllied(unit.team, BlockFlag.repair));
|
||||||
|
if (target != null) unit.target = target.entity;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
circle(unit, 20f);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ public class TeamInfo {
|
|||||||
return ally ? allyData : enemyData;
|
return ally ? allyData : enemyData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ObjectSet<TeamData> getTeams() {
|
||||||
|
return allTeamData;
|
||||||
|
}
|
||||||
|
|
||||||
/**Register a team.
|
/**Register a team.
|
||||||
* @param team The team type enum.
|
* @param team The team type enum.
|
||||||
* @param ally Whether this team is an ally with the player or an enemy with the player.
|
* @param ally Whether this team is an ally with the player or an enemy with the player.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package io.anuke.mindustry.world.flags;
|
package io.anuke.mindustry.world.flags;
|
||||||
|
|
||||||
public enum BlockFlag {
|
public enum BlockFlag {
|
||||||
resupplyPoint, producer
|
resupplyPoint, producer, repair
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user