diff --git a/src/cr0s/javara/entity/MobileEntity.java b/src/cr0s/javara/entity/MobileEntity.java index 7ae1697..aa8b6a5 100644 --- a/src/cr0s/javara/entity/MobileEntity.java +++ b/src/cr0s/javara/entity/MobileEntity.java @@ -302,4 +302,10 @@ public void resolveOrder(Order order) { this.moveTo(order.targetPosition); } } + + + public void setCellPos(Point exitPoint) { + this.posX = exitPoint.getX() * 24; + this.posY = exitPoint.getY() * 24; + } } diff --git a/src/cr0s/javara/entity/actor/activity/activities/MoveInfantry.java b/src/cr0s/javara/entity/actor/activity/activities/MoveInfantry.java index 16d0b24..cefbe25 100644 --- a/src/cr0s/javara/entity/actor/activity/activities/MoveInfantry.java +++ b/src/cr0s/javara/entity/actor/activity/activities/MoveInfantry.java @@ -12,6 +12,7 @@ import cr0s.javara.entity.actor.activity.activities.Turn.RotationDirection; import cr0s.javara.entity.building.EntityBuilding; import cr0s.javara.entity.infantry.EntityInfantry; +import cr0s.javara.entity.infantry.EntityInfantry.AnimationState; import cr0s.javara.entity.vehicle.common.EntityMcv; import cr0s.javara.render.World; import cr0s.javara.util.PointsUtil; @@ -115,17 +116,17 @@ private Point popPath(MobileEntity me) { blocker.notifyBlocking(me); this.hasNotifiedBlocker = true; } - + // Wait a bit if (!this.hasWaited) { this.waitTicksRemaining = me.getWaitAverageTime() + me.world.getRandomInt(-me.getWaitSpreadTime(), me.getWaitSpreadTime()); //System.out.println("Waiting time: " + this.waitTicksRemaining); this.hasWaited = true; + ((EntityInfantry) me).setCurrentAnimationState(AnimationState.WAITING); } if (--this.waitTicksRemaining >= 0) { // We're waiting now - //System.out.println("\tWaiting ticks: " + this.waitTicksRemaining); return null; } @@ -134,6 +135,8 @@ private Point popPath(MobileEntity me) { return null; } + + ((EntityInfantry) me).setCurrentAnimationState(AnimationState.MOVING); if (--this.ticksBeforeRepath <= 0) { this.ticksBeforeRepath = this.REPATHING_INTERVAL_TICKS; diff --git a/src/cr0s/javara/entity/building/EntityBarracks.java b/src/cr0s/javara/entity/building/EntityBarracks.java index c2056ff..f52ad8c 100644 --- a/src/cr0s/javara/entity/building/EntityBarracks.java +++ b/src/cr0s/javara/entity/building/EntityBarracks.java @@ -1,20 +1,28 @@ package cr0s.javara.entity.building; +import java.util.ArrayList; + import org.newdawn.slick.Color; import org.newdawn.slick.Graphics; import org.newdawn.slick.Image; import org.newdawn.slick.SlickException; import org.newdawn.slick.SpriteSheet; +import org.newdawn.slick.geom.Point; +import org.newdawn.slick.util.pathfinding.Path; import cr0s.javara.entity.IHaveCost; import cr0s.javara.entity.ISelectable; import cr0s.javara.entity.IShroudRevealer; +import cr0s.javara.entity.MobileEntity; +import cr0s.javara.entity.actor.EntityActor; import cr0s.javara.gameplay.Player; import cr0s.javara.gameplay.Team; import cr0s.javara.gameplay.Team.Alignment; import cr0s.javara.main.Main; +import cr0s.javara.render.EntityBlockingMap.SubCell; import cr0s.javara.resources.ResourceManager; import cr0s.javara.resources.ShpTexture; +import cr0s.javara.util.CellChooser; public class EntityBarracks extends EntityBuilding implements ISelectable, IPowerConsumer, IShroudRevealer, IHaveCost { @@ -37,7 +45,10 @@ public class EntityBarracks extends EntityBuilding implements ISelectable, IPowe private static final int SHROUD_REVEALING_RANGE = 10; private static final int BUILDING_COST = 400; - + + private Point rallyPoint; + private Point exitPoint; + public EntityBarracks(Float tileX, Float tileY, Team team, Player player) { super(tileX, tileY, team, player, WIDTH_TILES * 24, HEIGHT_TILES * 24, "xx xx ~~"); @@ -145,4 +156,51 @@ public Image getTexture() { public int getBuildingCost() { return BUILDING_COST; } + + public void deployEntity(EntityActor newInstance) { + if (newInstance instanceof MobileEntity) { + final MobileEntity me = (MobileEntity) newInstance; + + me.isVisible = true; + newInstance.setWorld(this.world); + + world.spawnEntityInWorld(newInstance); + + Path p = new Path(); + p.appendStep((int) exitPoint.getX(), (int) exitPoint.getY()); + p.appendStep((int) rallyPoint.getX(), (int) rallyPoint.getY()); + + SubCell freeSubCell = world.blockingEntityMap.getFreeSubCell(rallyPoint, SubCell.CENTER); + if (freeSubCell != null) { + me.currentSubcell = freeSubCell; + me.desiredSubcell = freeSubCell; + me.setCellPos(exitPoint); + + me.startMovingByPath(p, this); + } else { + SubCell sc = SubCell.CENTER; + + MobileEntity blocker = world.getMobileEntityInCell(exitPoint); + if (blocker != null) { + blocker.nudge(me, true); + } + + blocker = world.getMobileEntityInCell(rallyPoint); + if (blocker != null) { + blocker.nudge(me, true); + } + + me.setCellPos(exitPoint); + me.currentSubcell = sc; + me.desiredSubcell = sc; + me.startMovingByPath(p, this); + } + } + } + + @Override + public void onBuildFinished() { + this.exitPoint = new Point((posX) / 24, (posY + 1 * 24) / 24); + this.rallyPoint = new Point((posX + 24) / 24, (posY + 2 * 24) / 24); + } } diff --git a/src/cr0s/javara/entity/infantry/EntityGrenadeTrooper.java b/src/cr0s/javara/entity/infantry/EntityGrenadeTrooper.java index 949b15f..7f62cdb 100644 --- a/src/cr0s/javara/entity/infantry/EntityGrenadeTrooper.java +++ b/src/cr0s/javara/entity/infantry/EntityGrenadeTrooper.java @@ -6,6 +6,7 @@ import org.newdawn.slick.Graphics; import org.newdawn.slick.SpriteSheet; +import cr0s.javara.entity.IHaveCost; import cr0s.javara.entity.ISelectable; import cr0s.javara.entity.actor.activity.activities.MoveInfantry; import cr0s.javara.gameplay.Player; @@ -15,9 +16,15 @@ import cr0s.javara.resources.ResourceManager; import cr0s.javara.resources.ShpTexture; -public class EntityGrenadeTrooper extends EntityInfantry implements ISelectable { +public class EntityGrenadeTrooper extends EntityInfantry implements ISelectable, IHaveCost { - public EntityGrenadeTrooper(float posX, float posY, Team team, Player owner, + private final int BUILD_COST = 160; + + public EntityGrenadeTrooper(Float posX, Float posY, Team team, Player owner) { + this(posX, posY, team, owner, SubCell.CENTER); + } + + public EntityGrenadeTrooper(Float posX, Float posY, Team team, Player owner, SubCell sub) { super(posX, posY, team, owner, sub); @@ -29,11 +36,11 @@ public EntityGrenadeTrooper(float posX, float posY, Team team, Player owner, this.currentFrame = 0; this.standSequence = new Sequence(texture, 0, 8, 0, 0, owner.playerColor); - this.runSequence = new Sequence(texture, 16, 8, 6, 5, owner.playerColor); + this.runSequence = new Sequence(texture, 16, 8, 6, 2, owner.playerColor); this.runSequence.setIsLoop(true); - this.idleSequences.add(new Sequence(texture, 384, 0, 14, 10, owner.playerColor)); - this.idleSequences.add(new Sequence(texture, 399, 0, 16, 10, owner.playerColor)); + this.idleSequences.add(new Sequence(texture, 384, 0, 14, 2, owner.playerColor)); + this.idleSequences.add(new Sequence(texture, 399, 0, 16, 2, owner.playerColor)); } @Override @@ -78,4 +85,9 @@ public void cancelSelect() { public boolean isSelected() { return this.isSelected; } + + @Override + public int getBuildingCost() { + return BUILD_COST; + } } diff --git a/src/cr0s/javara/entity/infantry/EntityInfantry.java b/src/cr0s/javara/entity/infantry/EntityInfantry.java index b085f7b..a776e8f 100644 --- a/src/cr0s/javara/entity/infantry/EntityInfantry.java +++ b/src/cr0s/javara/entity/infantry/EntityInfantry.java @@ -30,28 +30,28 @@ public abstract class EntityInfantry extends MobileEntity implements IShroudRevealer { - private static final float DEFAULT_MOVE_SPEED = 0.01f; - + private static final float DEFAULT_MOVE_SPEED = 0.2f; + private static final int WIDTH = 50; private static final int HEIGHT = 39; public static final int MAX_FACING = 8; - + public static Point subcellOffsets[] = new Point[6]; - + static { subcellOffsets[SubCell.TOP_LEFT.ordinal()] = new Point(-21, -12); subcellOffsets[SubCell.TOP_RIGHT.ordinal()] = new Point(-5, -12); - + subcellOffsets[SubCell.CENTER.ordinal()] = new Point(-13, -6); - + subcellOffsets[SubCell.BOTTOM_LEFT.ordinal()] = new Point(-21, 2); subcellOffsets[SubCell.BOTTOM_RIGHT.ordinal()] = new Point(-5, 2); } - + protected ShpTexture texture; protected int currentFrame; - + protected Sequence currentSequence; protected Sequence standSequence; protected Sequence runSequence; @@ -59,9 +59,9 @@ public abstract class EntityInfantry extends MobileEntity implements IShroudReve protected ArrayList idleSequences = new ArrayList<>(); private int randomTicksBeforeIdleSeq = 0; - - public enum AnimationState { IDLE, ATTACKING, MOVING, IDLE_ANIMATING }; - protected AnimationState currentAnimationState; + + public enum AnimationState { IDLE, ATTACKING, MOVING, IDLE_ANIMATING, WAITING }; + private AnimationState currentAnimationState; private final static int MIN_IDLE_DELAY_TICKS = 350; @@ -70,23 +70,27 @@ public enum AnimationState { IDLE, ATTACKING, MOVING, IDLE_ANIMATING }; private final String SELECTED_SOUND = "ready"; private HashMap orderSounds; private final int MAX_VERSIONS = 4; - - public EntityInfantry(float posX, float posY, Team team, Player owner, SubCell sub) { + + public EntityInfantry(Float posX, Float posY, Team team, Player owner) { + this(posX, posY, team, owner, SubCell.CENTER); + } + + public EntityInfantry(Float posX, Float posY, Team team, Player owner, SubCell sub) { super(posX, posY, team, owner, WIDTH, HEIGHT); - + this.currentSubcell = sub; - + this.posX += subcellOffsets[sub.ordinal()].getX(); this.posY += subcellOffsets[sub.ordinal()].getY(); - + this.fillsSpace = FillsSpace.ONE_SUBCELL; - - this.currentAnimationState = AnimationState.IDLE; - + + this.setCurrentAnimationState(AnimationState.IDLE); + this.selectedSounds.put(SELECTED_SOUND, new Integer[] { 1, 3 } ); this.selectedSounds.put("report1", new Integer[] { 0, 1, 2, 3 } ); this.selectedSounds.put("yessir1", new Integer[] { 0, 1, 2, 3 } ); - + this.orderSounds = new HashMap<>(); this.orderSounds.put("ackno", new Integer[] { 0, 1, 2, 3 }); this.orderSounds.put("affirm1", new Integer[] { 0, 1, 2, 3 }); @@ -95,27 +99,27 @@ public EntityInfantry(float posX, float posY, Team team, Player owner, SubCell s this.orderSounds.put("ritaway", new Integer[] { 1, 3 }); this.orderSounds.put("roger", new Integer[] { 1, 3 }); this.orderSounds.put("ugotit", new Integer[] { 1, 3 }); - + this.unitVersion = SoundManager.getInstance().r.nextInt(4); // from 0 to 3 - - this.randomTicksBeforeIdleSeq = (int) (this.MIN_IDLE_DELAY_TICKS + Math.random() % (this.MAX_IDLE_DELAY_TICKS - this.MIN_IDLE_DELAY_TICKS)); + + this.randomTicksBeforeIdleSeq = (int) (this.MIN_IDLE_DELAY_TICKS + Math.random() * (this.MAX_IDLE_DELAY_TICKS - this.MIN_IDLE_DELAY_TICKS)); } - + @Override public Path findPathFromTo(MobileEntity e, int aGoalX, int aGoalY) { return world.getInfantryPathfinder().findPathFromTo((EntityInfantry) e, aGoalX, aGoalY); } - + @Override public boolean canEnterCell(Point cellPos) { return world.isCellPassable(cellPos, (this.desiredSubcell == null) ? this.currentSubcell : this.desiredSubcell); } - + @Override public float getMoveSpeed() { return DEFAULT_MOVE_SPEED; } - + @Override public float getTextureX() { return this.posX; @@ -125,60 +129,62 @@ public float getTextureX() { public float getTextureY() { return this.posY; } - + @Override public void updateEntity(int delta) { super.updateEntity(delta); - + if (this.currentSequence != null) { this.currentSequence.update(this.currentFacing); } - + this.boundingBox.setBounds(this.posX + this.texture.width / 3 + 2, this.posY + this.texture.height / 2 - 15, 13, 18); - if (this.currentActivity instanceof MoveInfantry || this.currentActivity instanceof MoveInfantry.MovePart) { - this.currentAnimationState = AnimationState.MOVING; + if ((this.currentActivity instanceof MoveInfantry || this.currentActivity instanceof MoveInfantry.MovePart) && this.getCurrentAnimationState() != AnimationState.WAITING) { + this.setCurrentAnimationState(AnimationState.MOVING); this.currentSequence = this.runSequence; } else if (currentActivity instanceof AttackInfantry) { - this.currentAnimationState = AnimationState.ATTACKING; + this.setCurrentAnimationState(AnimationState.ATTACKING); this.currentSequence = this.attackingSequence; } else if (this.isIdle()) { - if (this.currentAnimationState != AnimationState.IDLE && this.currentAnimationState != AnimationState.IDLE_ANIMATING) { - this.currentAnimationState = AnimationState.IDLE; + if (this.getCurrentAnimationState() != AnimationState.IDLE && this.getCurrentAnimationState() != AnimationState.IDLE_ANIMATING) { + this.setCurrentAnimationState(AnimationState.IDLE); this.currentSequence = this.standSequence; - } else if (this.currentAnimationState == AnimationState.IDLE) { + } else if (this.getCurrentAnimationState() == AnimationState.IDLE) { if (--this.randomTicksBeforeIdleSeq <= 0) { this.randomTicksBeforeIdleSeq = world.getRandomInt(this.MIN_IDLE_DELAY_TICKS, this.MAX_IDLE_DELAY_TICKS); - + if (this.idleSequences.size() > 0) { this.currentSequence = this.idleSequences.get(world.getRandomInt(0, this.idleSequences.size())); - this.currentAnimationState = AnimationState.IDLE_ANIMATING; + this.setCurrentAnimationState(AnimationState.IDLE_ANIMATING); } } else { // Waiting for idle animation in stand state this.currentSequence = this.standSequence; } - } else if (this.currentAnimationState == AnimationState.IDLE_ANIMATING) { + } else if (this.getCurrentAnimationState() == AnimationState.IDLE_ANIMATING) { if (this.currentSequence.isFinished()) { - this.currentAnimationState = AnimationState.IDLE; + this.setCurrentAnimationState(AnimationState.IDLE); this.currentSequence.reset(); } } + } else if (this.getCurrentAnimationState() == AnimationState.WAITING) { + this.currentSequence = this.standSequence; } } - + @Override public void renderEntity(Graphics g) { //if (this.sheet != null) { - this.currentSequence.render(this.posX, this.posY); + this.currentSequence.render(this.posX, this.posY); //} } - + @Override public void moveTo(Point destCell, EntityBuilding ignoreBuilding) { this.goalX = (int) destCell.getX(); this.goalY = (int) destCell.getY(); MoveInfantry move = new MoveInfantry(this, destCell, getMinimumEnoughRange(), ignoreBuilding); - + // If we already moving if (this.currentActivity instanceof MoveInfantry) { this.currentActivity.cancel(); @@ -186,23 +192,23 @@ public void moveTo(Point destCell, EntityBuilding ignoreBuilding) { this.currentActivity.queueActivity(move); return; } - + queueActivity(move); } - + @Override public void startMovingByPath(Path p, EntityBuilding ignoreBuilding) { this.goalX = (int) p.getX(p.getLength() - 1); this.goalY = (int) p.getY(p.getLength() - 1); - + queueActivity(new MoveInfantry(this, p, new Point(goalX, goalY), ignoreBuilding)); } - + @Override public boolean shouldRenderedInPass(int passNum) { return passNum == 1; } - + @Override public float getCenterPosX() { return this.boundingBox.getCenterX(); @@ -212,16 +218,16 @@ public float getCenterPosX() { public float getCenterPosY() { return this.boundingBox.getCenterY(); } - + public String getSelectSound() { return SELECTED_SOUND; } - + @Override public void playSelectedSound() { for (String s : this.selectedSounds.keySet()) { Integer[] versions = this.selectedSounds.get(s); - + boolean canPlay = false; for (int i = 0; i < Math.min(MAX_VERSIONS, versions.length); i++) { if (versions[i] == this.unitVersion) { @@ -229,26 +235,26 @@ public void playSelectedSound() { break; } } - + if (SoundManager.getInstance().r.nextBoolean() && canPlay) { SoundManager.getInstance().playUnitSoundGlobal(this, s, this.unitVersion); return; } } - + SoundManager.getInstance().playUnitSoundGlobal(this, SELECTED_SOUND, 1); } - + @Override public void playOrderSound() { // Play order sound for (String s : this.orderSounds.keySet()) { Integer[] versions = this.orderSounds.get(s); - + if (this.unitVersion >= versions.length) { continue; } - + boolean canPlay = false; for (int i = 0; i < Math.min(MAX_VERSIONS, versions.length); i++) { if (versions[i] == this.unitVersion) { @@ -256,17 +262,25 @@ public void playOrderSound() { break; } } - + if (SoundManager.getInstance().r.nextBoolean() && canPlay) { SoundManager.getInstance().playUnitSoundGlobal(this, s, this.unitVersion); return; } } - + if (SoundManager.getInstance().r.nextBoolean()) { SoundManager.getInstance().playUnitSoundGlobal(this, "ackno", this.unitVersion); } else { SoundManager.getInstance().playUnitSoundGlobal(this, "affirm1", this.unitVersion); } + } + + public AnimationState getCurrentAnimationState() { + return currentAnimationState; + } + + public void setCurrentAnimationState(AnimationState currentAnimationState) { + this.currentAnimationState = currentAnimationState; } } diff --git a/src/cr0s/javara/entity/infantry/EntityRiffleTrooper.java b/src/cr0s/javara/entity/infantry/EntityRiffleTrooper.java index 3dc5302..5fa735e 100644 --- a/src/cr0s/javara/entity/infantry/EntityRiffleTrooper.java +++ b/src/cr0s/javara/entity/infantry/EntityRiffleTrooper.java @@ -6,6 +6,7 @@ import org.newdawn.slick.Graphics; import org.newdawn.slick.SpriteSheet; +import cr0s.javara.entity.IHaveCost; import cr0s.javara.entity.ISelectable; import cr0s.javara.entity.actor.activity.activities.MoveInfantry; import cr0s.javara.gameplay.Player; @@ -15,9 +16,15 @@ import cr0s.javara.resources.ResourceManager; import cr0s.javara.resources.ShpTexture; -public class EntityRiffleTrooper extends EntityInfantry implements ISelectable { +public class EntityRiffleTrooper extends EntityInfantry implements ISelectable, IHaveCost { - public EntityRiffleTrooper(float posX, float posY, Team team, Player owner, + private final int BUILD_COST = 100; + + public EntityRiffleTrooper(Float posX, Float posY, Team team, Player owner) { + this(posX, posY, team, owner, SubCell.CENTER); + } + + public EntityRiffleTrooper(Float posX, Float posY, Team team, Player owner, SubCell sub) { super(posX, posY, team, owner, sub); @@ -29,11 +36,11 @@ public EntityRiffleTrooper(float posX, float posY, Team team, Player owner, this.currentFrame = 0; this.standSequence = new Sequence(texture, 0, 8, 0, 0, owner.playerColor); - this.runSequence = new Sequence(texture, 16, 8, 6, 5, owner.playerColor); + this.runSequence = new Sequence(texture, 16, 8, 6, 2, owner.playerColor); this.runSequence.setIsLoop(true); - this.idleSequences.add(new Sequence(texture, 256, 0, 16, 5, owner.playerColor)); - this.idleSequences.add(new Sequence(texture, 272, 0, 16, 5, owner.playerColor)); + this.idleSequences.add(new Sequence(texture, 256, 0, 16, 2, owner.playerColor)); + this.idleSequences.add(new Sequence(texture, 272, 0, 16, 2, owner.playerColor)); } @Override @@ -78,4 +85,9 @@ public void cancelSelect() { public boolean isSelected() { return this.isSelected; } + + @Override + public int getBuildingCost() { + return BUILD_COST; + } } diff --git a/src/cr0s/javara/entity/infantry/EntityRocketTrooper.java b/src/cr0s/javara/entity/infantry/EntityRocketTrooper.java index 2ee45d0..1bd26eb 100644 --- a/src/cr0s/javara/entity/infantry/EntityRocketTrooper.java +++ b/src/cr0s/javara/entity/infantry/EntityRocketTrooper.java @@ -6,6 +6,7 @@ import org.newdawn.slick.Graphics; import org.newdawn.slick.SpriteSheet; +import cr0s.javara.entity.IHaveCost; import cr0s.javara.entity.ISelectable; import cr0s.javara.entity.actor.activity.activities.MoveInfantry; import cr0s.javara.gameplay.Player; @@ -15,9 +16,15 @@ import cr0s.javara.resources.ResourceManager; import cr0s.javara.resources.ShpTexture; -public class EntityRocketTrooper extends EntityInfantry implements ISelectable { +public class EntityRocketTrooper extends EntityInfantry implements ISelectable, IHaveCost { - public EntityRocketTrooper(float posX, float posY, Team team, Player owner, + private int BUILD_COST = 300; + + public EntityRocketTrooper(Float posX, Float posY, Team team, Player owner) { + this(posX, posY, team, owner, SubCell.CENTER); + } + + public EntityRocketTrooper(Float posX, Float posY, Team team, Player owner, SubCell sub) { super(posX, posY, team, owner, sub); @@ -29,11 +36,11 @@ public EntityRocketTrooper(float posX, float posY, Team team, Player owner, this.currentFrame = 0; this.standSequence = new Sequence(texture, 0, 8, 0, 0, owner.playerColor); - this.runSequence = new Sequence(texture, 16, 8, 6, 5, owner.playerColor); + this.runSequence = new Sequence(texture, 16, 8, 6, 2, owner.playerColor); this.runSequence.setIsLoop(true); - this.idleSequences.add(new Sequence(texture, 272, 0, 14, 10, owner.playerColor)); - this.idleSequences.add(new Sequence(texture, 287, 0, 16, 10, owner.playerColor)); + this.idleSequences.add(new Sequence(texture, 272, 0, 14, 2, owner.playerColor)); + this.idleSequences.add(new Sequence(texture, 287, 0, 16, 2, owner.playerColor)); } @Override @@ -78,4 +85,9 @@ public void cancelSelect() { public boolean isSelected() { return this.isSelected; } + + @Override + public int getBuildingCost() { + return BUILD_COST; + } } diff --git a/src/cr0s/javara/gameplay/Base.java b/src/cr0s/javara/gameplay/Base.java index 90fe982..baed6f9 100644 --- a/src/cr0s/javara/gameplay/Base.java +++ b/src/cr0s/javara/gameplay/Base.java @@ -15,6 +15,7 @@ import cr0s.javara.entity.building.IOreCapacitor; import cr0s.javara.entity.building.IPowerConsumer; import cr0s.javara.entity.building.IPowerProducer; +import cr0s.javara.entity.infantry.EntityInfantry; import cr0s.javara.entity.vehicle.EntityVehicle; import cr0s.javara.gameplay.Team.Alignment; import cr0s.javara.main.Main; @@ -179,6 +180,10 @@ private void updateBuildings() { } else if (((EntityConstructionYard) b).getAlignment() == Alignment.SOVIET) { this.isSovietCYPresent = true; } + } else if (b instanceof EntityBarracks) { + this.isBarracksPresent = true; + //} else if (b instanceof EntityTent) { + //this.isTentPresent = true; } else if (b instanceof EntityWarFactory) { if (((EntityWarFactory) b).getAlignment() == Alignment.ALLIED) { this.isAlliedWarFactoryPresent = true; @@ -214,6 +219,8 @@ public void addBuilding(EntityBuilding building) { if (building instanceof EntityWarFactory) { building.setPrimary(!isMoreThanOneWarFactory()); + } else if (building instanceof EntityBarracks /*|| building instanceof EntityTent*/) { + building.setPrimary(!isMoreThanOneTentOrBarrack()); } } @@ -293,6 +300,52 @@ public void deployBuildedVehicle(EntityVehicle v) { getPrimaryWarFactory().deployEntity(EntityVehicle.newInstance(v)); } + public EntityBuilding getPrimaryBarrackOrTent() { + for (EntityBuilding b : this.buildings) { + if (b instanceof EntityBarracks /*|| b instanceof EntityTent*/) { + if (b.isPrimary()) { + return b; + } + } + } + + return null; + } + + public void setPrimaryTentOrBarrack(EntityBuilding b) { + for (EntityBuilding eb : this.buildings) { + if (eb instanceof EntityBarracks/* || eb instanceof EntityTent*/) { + eb.setPrimary(eb == b); + } + } + } + + public boolean isMoreThanOneTentOrBarrack() { + int count = 0; + + for (EntityBuilding eb : this.buildings) { + if (eb instanceof EntityBarracks/* || eb instanceof EntityTent*/) { + count++; + if (count > 1) { + return true; + } + } + } + + return false; + } + + public void deployTrainedInfantry(EntityInfantry i) { + EntityBuilding b = getPrimaryBarrackOrTent(); + if (b != null) { + if (b instanceof EntityBarracks) { + ((EntityBarracks) b).deployEntity(i.newInstance()); + }/* else if (b instanceof EntityTent) { + ((EntityTent) b).deployEntity(i.newInstance()); + }*/ + } + } + public EntityWarFactory getPrimaryWarFactory() { for (EntityBuilding b : this.buildings) { if (b instanceof EntityWarFactory) { @@ -327,7 +380,8 @@ public boolean isMoreThanOneWarFactory() { return false; } - + + public void giveOre(int aCapacity) { if (this.ore + aCapacity > 0.8f * this.oreCapacity) { if (this.owner == Main.getInstance().getPlayer()) { diff --git a/src/cr0s/javara/gameplay/Player.java b/src/cr0s/javara/gameplay/Player.java index ca6177d..64cf52f 100644 --- a/src/cr0s/javara/gameplay/Player.java +++ b/src/cr0s/javara/gameplay/Player.java @@ -92,7 +92,7 @@ public void spawn() { this.world.spawnEntityInWorld(mcv); - EntityHeavyTank eht = new EntityHeavyTank(24.0f * this.spawnX + 3 * 24, 24.0f * this.spawnY + 3 * 24, team, this); + /*EntityHeavyTank eht = new EntityHeavyTank(24.0f * this.spawnX + 3 * 24, 24.0f * this.spawnY + 3 * 24, team, this); eht.isVisible = true; this.world.spawnEntityInWorld(eht); @@ -125,7 +125,7 @@ public void spawn() { e.currentFacing = this.world.getRandomInt(0, EntityInfantry.MAX_FACING); e.isVisible = true; this.world.spawnEntityInWorld(e); - } + }*/ this.base.gainCash(5000); } diff --git a/src/cr0s/javara/gameplay/Production.java b/src/cr0s/javara/gameplay/Production.java index 0370177..539f4cd 100644 --- a/src/cr0s/javara/gameplay/Production.java +++ b/src/cr0s/javara/gameplay/Production.java @@ -42,6 +42,10 @@ public class Production { private SideBarItemsButton button; + private boolean notifiedNoFunds = false; + private final int NO_FUNDS_INTERVAL = 300; + private int ticksBeforeNotifyNoFunds = NO_FUNDS_INTERVAL; + public Production(Player p) { this.player = p; } @@ -65,7 +69,7 @@ public void startBuildingActor(EntityActor target, SideBarItemsButton btn) { this.isDeployed = false; } - public void update() { + public void update() { if (this.isBuilding && !this.isReady) { if (this.isOnHold) { return; @@ -77,9 +81,14 @@ public void update() { // Insufficient funds if (cashPerTick != 0 && !this.player.getBase().takeCash(cashPerTick)) { + if (!this.notifiedNoFunds) { + SoundManager.getInstance().playSpeechSoundGlobal("nofunds1"); + this.notifiedNoFunds = true; + } return; } + this.notifiedNoFunds = false; this.cashSpent += cashPerTick; this.buildedTicks++; @@ -117,10 +126,11 @@ public void deployCurrentActor() { if (this.targetActor instanceof EntityVehicle) { this.isReady = false; this.isDeployed = true; - System.out.println("Deploying vehicle"); this.player.getBase().deployBuildedVehicle((EntityVehicle) targetActor); } else if (this.targetActor instanceof EntityInfantry) { - + this.isReady = false; + this.isDeployed = true; + this.player.getBase().deployTrainedInfantry((EntityInfantry) targetActor); } } diff --git a/src/cr0s/javara/gameplay/ProductionQueue.java b/src/cr0s/javara/gameplay/ProductionQueue.java index 6f4e7ab..2ff36b0 100644 --- a/src/cr0s/javara/gameplay/ProductionQueue.java +++ b/src/cr0s/javara/gameplay/ProductionQueue.java @@ -12,12 +12,21 @@ import cr0s.javara.entity.building.EntityProc; import cr0s.javara.entity.building.EntityRadarDome; import cr0s.javara.entity.building.EntityWarFactory; +import cr0s.javara.entity.infantry.EntityGrenadeTrooper; import cr0s.javara.entity.infantry.EntityInfantry; +import cr0s.javara.entity.infantry.EntityRiffleTrooper; +import cr0s.javara.entity.infantry.EntityRocketTrooper; import cr0s.javara.entity.vehicle.EntityVehicle; +import cr0s.javara.entity.vehicle.common.EntityHarvester; +import cr0s.javara.entity.vehicle.common.EntityMcv; +import cr0s.javara.entity.vehicle.tank.EntityHeavyTank; import cr0s.javara.gameplay.Team.Alignment; import cr0s.javara.main.Main; +import cr0s.javara.render.EntityBlockingMap.SubCell; import cr0s.javara.ui.sbpages.SideBarItemsButton; import cr0s.javara.ui.sbpages.building.BuildingSidebarButton; +import cr0s.javara.ui.sbpages.infantry.InfantrySidebarButton; +import cr0s.javara.ui.sbpages.vehicle.VehicleSidebarButton; public class ProductionQueue { private Base base; @@ -96,7 +105,34 @@ public ProductionQueue(Player p) { this.alliedBuildings.put("weapicon.shp", new EntityWarFactory(0f, 0f, this.player.getTeam(), this.player)); this.alliedBuildings.put("domeicon.shp", new EntityRadarDome(0f, 0f, this.player.getTeam(), this.player)); - this.buildables.put("powricon.shp", this.sovietBuildings.get("powricon.shp")); + //this.buildables.put("powricon.shp", this.sovietBuildings.get("powricon.shp")); + + this.sovietVehicles.put("harvicon.shp", new EntityHarvester(0.0f, 0.0f, this.player.getTeam(), this.player)); + this.sovietVehicles.put("3tnkicon.shp", new EntityHeavyTank(0.0f, 0.0f, this.player.getTeam(), this.player)); + this.sovietVehicles.put("mcvcon.shp", new EntityMcv(0.0f, 0.0f, this.player.getTeam(), this.player)); + + /* + addButton(new InfantrySidebarButton("", "shokicon.shp", this.getPosition(), 0, 4, false, null)); + + //addButton(new InfantrySidebarButton("", "icon.shp", this.getPosition(), 1, 5, false, null)); + //addButton(new InfantrySidebarButton("", "icon.shp", this.getPosition(), 1, 5, false, null)); + + addButton(new InfantrySidebarButton("", "e4icon.shp", this.getPosition(), 0, 6, false, null)); + //addButton(new InfantrySidebarButton("", "icon.shp", this.getPosition(), 1, 6, false, null)); + + addButton(new InfantrySidebarButton("", "e3icon.shp", this.getPosition(), 0, 7, false, null)); + addButton(new InfantrySidebarButton("", "e7icon.shp", this.getPosition(), 1, 7, false, null)); + + addButton(new InfantrySidebarButton("", "e2icon.shp", this.getPosition(), 0, 8, false, null)); + //addButton(new InfantrySidebarButton("", "icon.shp", this.getPosition(), 1, 8, false, null)); + + addButton(new InfantrySidebarButton("", "e1icon.shp", this.getPosition(), 0, 9, false, null)); + addButton(new InfantrySidebarButton("", "e6icon.shp", this.getPosition(), 1, 9, false, null)); + */ + this.sovietInfantry.put("e1icon.shp", new EntityRiffleTrooper(0.0f, 0.0f, this.player.getTeam(), this.player, SubCell.CENTER)); + //this.sovietInfantry.put("e6icon.shp", new EntityEngineer(0.0f, 0.0f, this.player.getTeam(), this.player, SubCell.CENTER)); + this.sovietInfantry.put("e2icon.shp", new EntityGrenadeTrooper(0.0f, 0.0f, this.player.getTeam(), this.player, SubCell.CENTER)); + this.sovietInfantry.put("e3icon.shp", new EntityRocketTrooper(0.0f, 0.0f, this.player.getTeam(), this.player, SubCell.CENTER)); } public EntityActor getBuildableActor(SideBarItemsButton texture) { @@ -224,7 +260,7 @@ public boolean canBuild(EntityActor targetBuilding) { } public boolean isBuildable(String name) { - if ( this.buildables == null || this.buildables.isEmpty()) { + if (this.buildables == null || this.buildables.isEmpty()) { return false; } diff --git a/src/cr0s/javara/ui/GameSideBar.java b/src/cr0s/javara/ui/GameSideBar.java index d16052b..0662c61 100644 --- a/src/cr0s/javara/ui/GameSideBar.java +++ b/src/cr0s/javara/ui/GameSideBar.java @@ -11,6 +11,7 @@ import cr0s.javara.entity.actor.EntityActor; import cr0s.javara.entity.building.EntityBuilding; +import cr0s.javara.entity.infantry.EntityInfantry; import cr0s.javara.gameplay.Base; import cr0s.javara.gameplay.Player; import cr0s.javara.gameplay.Production; @@ -21,6 +22,7 @@ import cr0s.javara.resources.ResourceManager; import cr0s.javara.resources.SoundManager; import cr0s.javara.ui.sbpages.building.PageBuildingSoviet; +import cr0s.javara.ui.sbpages.infantry.PageInfantry; import cr0s.javara.ui.sbpages.vehicle.PageVehicle; import cr0s.javara.ui.sbpages.SideBarPage; @@ -57,7 +59,8 @@ public class GameSideBar { public static final String START_PAGE_NAME = "start"; public static final String PAGE_BUILDING_SOVIET = "sovbuild"; public static final String PAGE_VEHICLE = "vehicle"; - + public static final String PAGE_INFANTRY = "infantry"; + private Rectangle currentViewportRect = new Rectangle(0, 0, 0, 0); private Rectangle radarRect = new Rectangle(0, 0, 0, 0); private float previewScale; @@ -109,6 +112,7 @@ public void initSidebarPages() { if (this.sideBarPages.isEmpty()) { this.sideBarPages.put(PAGE_BUILDING_SOVIET, new PageBuildingSoviet(new Point(Main.getInstance().getContainer().getWidth() - BAR_WIDTH - BAR_SPACING_W + 1, BAR_SPACING_H + 1))); this.sideBarPages.put(PAGE_VEHICLE, new PageVehicle(new Point(Main.getInstance().getContainer().getWidth() - BAR_WIDTH - BAR_SPACING_W + 1, BAR_SPACING_H + 1))); + this.sideBarPages.put(PAGE_INFANTRY, new PageInfantry(new Point(Main.getInstance().getContainer().getWidth() - BAR_WIDTH - BAR_SPACING_W + 1, BAR_SPACING_H + 1))); } } @@ -347,9 +351,14 @@ public void productionButtonClick(Production production, int button, int buttonX production.restartBuilding(); } } else { + SoundManager.getInstance().playSfxGlobal("ramenu1", 0.8f); + if (!production.isReady() && !production.isBuilding()) { - SoundManager.getInstance().playSfxGlobal("ramenu1", 0.8f); - SoundManager.getInstance().playSpeechSoundGlobal("abldgin1"); + if (!(production.getTargetActor() instanceof EntityInfantry)) { + SoundManager.getInstance().playSpeechSoundGlobal("abldgin1"); + } else { + SoundManager.getInstance().playSpeechSoundGlobal("train1"); + } production.restartBuilding(); } } @@ -400,7 +409,8 @@ public void openPageByClick(int buttonX, int buttonY) { SoundManager.getInstance().playSfxGlobal("ramenu1", 0.8f); switchPage(PAGE_VEHICLE); } else if (buttonX == 1) { - + SoundManager.getInstance().playSfxGlobal("ramenu1", 0.8f); + switchPage(PAGE_INFANTRY); } break; @@ -432,6 +442,16 @@ public void startPageClick(int button, int buttonX, int buttonY) { if (buildingActor != null) { Production production = player.getBase().getProductionQueue().getCurrentVehicleProduction(); + productionButtonClick(production, button, buttonX, buttonY); + } else { + openPageByClick(buttonX, buttonY); + } + } else { + EntityActor buildingActor = player.getBase().getProductionQueue().getCurrentInfantryProduction().getTargetActor(); + + if (buildingActor != null) { + Production production = player.getBase().getProductionQueue().getCurrentInfantryProduction(); + productionButtonClick(production, button, buttonX, buttonY); } else { openPageByClick(buttonX, buttonY); diff --git a/src/cr0s/javara/ui/sbpages/infantry/InfantrySidebarButton.java b/src/cr0s/javara/ui/sbpages/infantry/InfantrySidebarButton.java new file mode 100644 index 0000000..1017753 --- /dev/null +++ b/src/cr0s/javara/ui/sbpages/infantry/InfantrySidebarButton.java @@ -0,0 +1,22 @@ +package cr0s.javara.ui.sbpages.infantry; + +import org.newdawn.slick.geom.Point; + +import cr0s.javara.entity.infantry.EntityInfantry; +import cr0s.javara.ui.sbpages.SideBarItemsButton; + +public class InfantrySidebarButton extends SideBarItemsButton { + + private EntityInfantry targetInfantry; + + public InfantrySidebarButton(String aDescription, String textureName, + Point pagePos, int aPosX, int aPosY, boolean aIsVisible, EntityInfantry aTargetInfantry) { + super(aDescription, textureName, pagePos, aPosX, aPosY, aIsVisible); + + this.targetInfantry = aTargetInfantry; + } + + public EntityInfantry getTargetInfantry() { + return this.targetInfantry; + } +} diff --git a/src/cr0s/javara/ui/sbpages/infantry/PageInfantry.java b/src/cr0s/javara/ui/sbpages/infantry/PageInfantry.java new file mode 100644 index 0000000..79b9cc6 --- /dev/null +++ b/src/cr0s/javara/ui/sbpages/infantry/PageInfantry.java @@ -0,0 +1,48 @@ +package cr0s.javara.ui.sbpages.infantry; + +import org.newdawn.slick.geom.Point; + +import cr0s.javara.main.Main; +import cr0s.javara.resources.SoundManager; +import cr0s.javara.ui.GameSideBar; +import cr0s.javara.ui.sbpages.SideBarItemsButton; +import cr0s.javara.ui.sbpages.SideBarPage; +import cr0s.javara.ui.sbpages.building.BuildingSidebarButton; + +public class PageInfantry extends SideBarPage { + + public PageInfantry(Point pos) { + super(pos); + + addButton(new InfantrySidebarButton("Shock Trooper", "shokicon.shp", this.getPosition(), 0, 4, false, null)); + + //addButton(new InfantrySidebarButton("", "icon.shp", this.getPosition(), 1, 5, false, null)); + //addButton(new InfantrySidebarButton("", "icon.shp", this.getPosition(), 1, 5, false, null)); + + addButton(new InfantrySidebarButton("Flamethrower", "e4icon.shp", this.getPosition(), 0, 6, false, null)); + //addButton(new InfantrySidebarButton("", "icon.shp", this.getPosition(), 1, 6, false, null)); + + addButton(new InfantrySidebarButton("Rocket Soldier", "e3icon.shp", this.getPosition(), 0, 7, false, null)); + addButton(new InfantrySidebarButton("Tanya", "e7icon.shp", this.getPosition(), 1, 7, false, null)); + + addButton(new InfantrySidebarButton("Grenade Trooper", "e2icon.shp", this.getPosition(), 0, 8, false, null)); + //addButton(new InfantrySidebarButton("", "icon.shp", this.getPosition(), 1, 8, false, null)); + + addButton(new InfantrySidebarButton("Riffle Trooper", "e1icon.shp", this.getPosition(), 0, 9, false, null)); + addButton(new InfantrySidebarButton("Engineer", "e6icon.shp", this.getPosition(), 1, 9, false, null)); + } + + @Override + public void update(int delta) { + for (SideBarItemsButton button : this.buttonsHash.values()) { + button.setVisible(Main.getInstance().getPlayer().getBase().getProductionQueue().isBuildable(button.getTextureName())); + } + } + + @Override + public void buttonClicked(SideBarItemsButton button) { + super.buttonClicked(button); + SoundManager.getInstance().playSpeechSoundGlobal("train1"); + } + +}