Added unit ammo support, multi-ammo inventories
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
#Autogenerated file. Do not modify.
|
#Autogenerated file. Do not modify.
|
||||||
#Tue Apr 24 21:35:40 EDT 2018
|
#Wed Apr 25 20:39:35 EDT 2018
|
||||||
version=pre-alpha
|
version=pre-alpha
|
||||||
androidBuildCode=1094
|
androidBuildCode=1094
|
||||||
name=Mindustry
|
name=Mindustry
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package io.anuke.mindustry.entities;
|
package io.anuke.mindustry.entities;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
import io.anuke.mindustry.resource.*;
|
import io.anuke.mindustry.resource.*;
|
||||||
|
|
||||||
public class UnitInventory {
|
public class UnitInventory {
|
||||||
private final AmmoEntry ammo = new AmmoEntry(AmmoType.getByID(0), 0);
|
private Array<AmmoEntry> ammos = new Array<>();
|
||||||
|
private int totalAmmo;
|
||||||
private ItemStack item;
|
private ItemStack item;
|
||||||
private int capacity, ammoCapacity;
|
private int capacity, ammoCapacity;
|
||||||
|
|
||||||
@@ -13,15 +15,18 @@ public class UnitInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AmmoType getAmmo() {
|
public AmmoType getAmmo() {
|
||||||
return ammo.type;
|
return ammos.size == 0 ? null : ammos.peek().type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAmmo(){
|
public boolean hasAmmo(){
|
||||||
return ammo.amount > 0;
|
return totalAmmo > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void useAmmo(){
|
public void useAmmo(){
|
||||||
ammo.amount --;
|
AmmoEntry entry = ammos.peek();
|
||||||
|
entry.amount --;
|
||||||
|
if(entry.amount == 0) ammos.pop();
|
||||||
|
totalAmmo --;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ammoCapacity(){
|
public int ammoCapacity(){
|
||||||
@@ -29,13 +34,27 @@ public class UnitInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean canAcceptAmmo(AmmoType type){
|
public boolean canAcceptAmmo(AmmoType type){
|
||||||
return ammo.amount + type.quantityMultiplier <= ammoCapacity;
|
return totalAmmo + type.quantityMultiplier <= ammoCapacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAmmo(AmmoType type){
|
public void addAmmo(AmmoType type){
|
||||||
if(ammo.type != type) ammo.amount = 0;
|
totalAmmo += type.quantityMultiplier;
|
||||||
ammo.type = type;
|
|
||||||
ammo.amount += Math.min((int)type.quantityMultiplier, ammoCapacity - ammo.amount);
|
//find ammo entry by type
|
||||||
|
for(int i = ammos.size - 1; i >= 0; i --){
|
||||||
|
AmmoEntry entry = ammos.get(i);
|
||||||
|
|
||||||
|
//if found, put it to the right
|
||||||
|
if(entry.type == type){
|
||||||
|
entry.amount += type.quantityMultiplier;
|
||||||
|
ammos.swap(i, ammos.size-1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//must not be found
|
||||||
|
AmmoEntry entry = new AmmoEntry(type, (int)type.quantityMultiplier);
|
||||||
|
ammos.add(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int capacity(){
|
public int capacity(){
|
||||||
@@ -60,8 +79,8 @@ public class UnitInventory {
|
|||||||
|
|
||||||
public void clear(){
|
public void clear(){
|
||||||
item = null;
|
item = null;
|
||||||
ammo.amount = 0;
|
ammos.clear();
|
||||||
ammo.type = AmmoType.getByID(0);
|
totalAmmo = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasItem(){
|
public boolean hasItem(){
|
||||||
|
|||||||
@@ -40,17 +40,16 @@ public class BaseUnit extends Unit{
|
|||||||
rotation = Mathf.slerpDelta(rotation, angle, type.rotatespeed);
|
rotation = Mathf.slerpDelta(rotation, angle, type.rotatespeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptsAmmo(Item item) {
|
public boolean acceptsAmmo(Item item) {
|
||||||
return false;
|
return type.ammo.containsKey(item) && inventory.canAcceptAmmo(type.ammo.get(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addAmmo(Item item) {
|
public void addAmmo(Item item) {
|
||||||
|
inventory.addAmmo(type.ammo.get(item));
|
||||||
}
|
}
|
||||||
//TODO
|
|
||||||
@Override
|
@Override
|
||||||
public float getSize() {
|
public float getSize() {
|
||||||
return 8;
|
return 8;
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package io.anuke.mindustry.entities.units;
|
|||||||
|
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.utils.ObjectSet;
|
import com.badlogic.gdx.utils.ObjectSet;
|
||||||
import io.anuke.mindustry.content.bullets.TurretBullets;
|
|
||||||
import io.anuke.mindustry.content.fx.Fx;
|
import io.anuke.mindustry.content.fx.Fx;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.Unit;
|
||||||
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
||||||
|
import io.anuke.mindustry.resource.AmmoType;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.ucore.core.Effects;
|
import io.anuke.ucore.core.Effects;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
@@ -52,7 +52,6 @@ public class FlyingUnitType extends UnitType {
|
|||||||
public void behavior(BaseUnit unit) {
|
public void behavior(BaseUnit unit) {
|
||||||
vec.set(unit.target.x - unit.x, unit.target.y - unit.y);
|
vec.set(unit.target.x - unit.x, unit.target.y - unit.y);
|
||||||
|
|
||||||
float ang = vec.angle();
|
|
||||||
float len = vec.len();
|
float len = vec.len();
|
||||||
|
|
||||||
float circleLength = 40f;
|
float circleLength = 40f;
|
||||||
@@ -65,8 +64,11 @@ public class FlyingUnitType extends UnitType {
|
|||||||
|
|
||||||
unit.velocity.add(vec); //TODO clamp it so it doesn't glitch out at low fps
|
unit.velocity.add(vec); //TODO clamp it so it doesn't glitch out at low fps
|
||||||
|
|
||||||
if(unit.timer.get(timerReload, reload) && len < range){
|
if(unit.inventory.hasAmmo() && unit.timer.get(timerReload, reload) && len < range){
|
||||||
shoot(unit, TurretBullets.basicIron, unit.rotation, 4f);
|
AmmoType ammo = unit.inventory.getAmmo();
|
||||||
|
unit.inventory.useAmmo();
|
||||||
|
|
||||||
|
shoot(unit, ammo, unit.rotation, 4f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
package io.anuke.mindustry.entities.units;
|
package io.anuke.mindustry.entities.units;
|
||||||
|
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
|
import io.anuke.mindustry.content.fx.ExplosionFx;
|
||||||
import io.anuke.mindustry.entities.Bullet;
|
import io.anuke.mindustry.entities.Bullet;
|
||||||
import io.anuke.mindustry.entities.BulletType;
|
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.Unit;
|
||||||
import io.anuke.mindustry.entities.Units;
|
import io.anuke.mindustry.entities.Units;
|
||||||
import io.anuke.mindustry.content.fx.ExplosionFx;
|
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.mindustry.net.NetEvents;
|
import io.anuke.mindustry.net.NetEvents;
|
||||||
|
import io.anuke.mindustry.resource.AmmoType;
|
||||||
|
import io.anuke.mindustry.resource.Item;
|
||||||
import io.anuke.ucore.core.Effects;
|
import io.anuke.ucore.core.Effects;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.util.Angles;
|
import io.anuke.ucore.util.Angles;
|
||||||
@@ -41,6 +43,7 @@ public abstract class UnitType {
|
|||||||
protected float drag = 0.1f;
|
protected float drag = 0.1f;
|
||||||
protected float maxVelocity = 5f;
|
protected float maxVelocity = 5f;
|
||||||
protected float reload = 40f;
|
protected float reload = 40f;
|
||||||
|
protected ObjectMap<Item, AmmoType> ammo = new ObjectMap<>();
|
||||||
|
|
||||||
public UnitType(String name){
|
public UnitType(String name){
|
||||||
this.id = lastid++;
|
this.id = lastid++;
|
||||||
@@ -48,12 +51,14 @@ public abstract class UnitType {
|
|||||||
types.add(this);
|
types.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void draw(BaseUnit unit);
|
protected void setAmmo(AmmoType... types){
|
||||||
|
for(AmmoType type : types){
|
||||||
public void drawOver(BaseUnit unit){
|
ammo.put(type.item, type);
|
||||||
//TODO doesn't do anything
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract void draw(BaseUnit unit);
|
||||||
|
|
||||||
public boolean isFlying(){
|
public boolean isFlying(){
|
||||||
return isFlying;
|
return isFlying;
|
||||||
}
|
}
|
||||||
@@ -93,10 +98,14 @@ public abstract class UnitType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shoot(BaseUnit unit, BulletType type, float rotation, float translation){
|
public void shoot(BaseUnit unit, AmmoType type, float rotation, float translation){
|
||||||
Bullet.create(type, unit,
|
Bullet.create(type.bullet, unit,
|
||||||
unit.x + Angles.trnsx(rotation, translation),
|
unit.x + Angles.trnsx(rotation, translation),
|
||||||
unit.y + Angles.trnsy(rotation, translation), rotation);
|
unit.y + Angles.trnsy(rotation, translation), rotation);
|
||||||
|
Effects.effect(type.shootEffect, unit.x + Angles.trnsx(rotation, translation),
|
||||||
|
unit.y + Angles.trnsy(rotation, translation), rotation, unit);
|
||||||
|
Effects.effect(type.smokeEffect, unit.x + Angles.trnsx(rotation, translation),
|
||||||
|
unit.y + Angles.trnsy(rotation, translation), rotation, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDeath(BaseUnit unit){
|
public void onDeath(BaseUnit unit){
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package io.anuke.mindustry.entities.units.types;
|
package io.anuke.mindustry.entities.units.types;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.content.AmmoTypes;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.Unit;
|
||||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
import io.anuke.mindustry.entities.units.BaseUnit;
|
||||||
import io.anuke.mindustry.entities.units.FlyingUnitType;
|
import io.anuke.mindustry.entities.units.FlyingUnitType;
|
||||||
@@ -10,6 +11,7 @@ public class Vtol extends FlyingUnitType {
|
|||||||
|
|
||||||
public Vtol(){
|
public Vtol(){
|
||||||
super("vtol");
|
super("vtol");
|
||||||
|
setAmmo(AmmoTypes.basicIron);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ public class CoreBlock extends StorageBlock {
|
|||||||
itemCapacity = 2000;
|
itemCapacity = 2000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean acceptItem(Item item, Tile tile, Tile source) {
|
||||||
|
return tile.entity.items.totalItems() < itemCapacity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawSelect(Tile tile){
|
public void drawSelect(Tile tile){
|
||||||
Draw.color("accent");
|
Draw.color("accent");
|
||||||
|
|||||||
Reference in New Issue
Block a user