Skip to content

Commit

Permalink
Added explosion variety to space battles. (#1146)
Browse files Browse the repository at this point in the history
  • Loading branch information
hemoridos committed Jun 2, 2024
1 parent 9bbbbdf commit d238d1b
Show file tree
Hide file tree
Showing 19 changed files with 501 additions and 393 deletions.
296 changes: 148 additions & 148 deletions data/generic/campaign/main/battle.xml

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions data/generic/schemas/battle.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@
<xs:documentation>Some projectiles may turn while travelling (e.g., rockets). Defines how much time it takes to do a one step rotation. The larger this number is the faster the projectile will turn.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="explosion-anim" type="xs:string" use="required">
<xs:annotation>
<xs:documentation>Ratio of simulation time and distance travelled. The smaller this number is the faster the projectile will travel.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
<xs:complexType name="space-entities">
<xs:annotation>
Expand Down Expand Up @@ -204,6 +209,11 @@
<xs:documentation>The base hitpoints of the entity in skirmish.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="explosion-anim" type="xs:string" use="required">
<xs:annotation>
<xs:documentation>Ratio of simulation time and distance travelled. The smaller this number is the faster the projectile will travel.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
<xs:complexType name="ground-shields">
<xs:annotation>
Expand Down Expand Up @@ -251,6 +261,11 @@
<xs:documentation>The percentage of the shield hitpoints in respect to the base hitpoints.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="explosion-anim" type="xs:string" use="required">
<xs:annotation>
<xs:documentation>Ratio of simulation time and distance travelled. The smaller this number is the faster the projectile will travel.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
<xs:complexType name="ground-projectors">
<xs:annotation>
Expand Down Expand Up @@ -318,6 +333,11 @@
<xs:documentation>Defines how much time it takes to do a one step rotation. The larger this number is the faster the projector will turn.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="explosion-anim" type="xs:string" use="optional">
<xs:annotation>
<xs:documentation>Ratio of simulation time and distance travelled. The smaller this number is the faster the projectile will travel.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
<xs:complexType name="ground-vehicles">
<xs:annotation>
Expand Down
140 changes: 70 additions & 70 deletions data/generic/skirmish/human/battle.xml

Large diffs are not rendered by default.

230 changes: 128 additions & 102 deletions dlc/gump891202-racemod-0.1/generic/skirmish/racemod-0.1/battle.xml

Large diffs are not rendered by default.

15 changes: 0 additions & 15 deletions src/hu/openig/gfx/SpacewarGFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,6 @@ public class SpacewarGFX {
/** Zoom button. */
@Btn2(name = "spacewar/button_zoom")
public BufferedImage[] zoom;
/** Small explosion animation. */
@Anim(name = "spacewar/explosion_1", width = 20)
public BufferedImage[] explosionSmall;
/** Medium explosion animation. */
@Anim(name = "spacewar/explosion_2", width = 30)
public BufferedImage[] explosionMedium;
/** Large explosion animation. */
@Anim(name = "spacewar/explosion_3", width = 60)
public BufferedImage[] explosionLarge;
/** Tiny explosion animation. */
@Anim(name = "spacewar/explosion_hit", width = 9)
public BufferedImage[] explosionTiny;
/** Green explosion. */
@Anim(name = "spacewar/explosion_4", width = 40)
public BufferedImage[] explosionGreen;
// /** The planet. */
// @Img(name = "spacewar/planet")
// public BufferedImage planet;
Expand Down
2 changes: 1 addition & 1 deletion src/hu/openig/mechanics/SimpleSpaceWarMovementHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ boolean isBlocked(Location loc, WarUnit unit) {
@Override
boolean ignoreObstacles(Location loc, WarUnit unit) {
SpacewarStructure sws = (SpacewarStructure) unit;
if (sws.kamikaze > 0 && loc.equals(sws.getAttackTarget().location())) {
if (sws.kamikaze > 0 && unitsForPathfinding.get(loc) != null && unitsForPathfinding.get(loc).contains(sws.attackUnit)) {
return true;
}
return super.ignoreObstacles(loc, unit);
Expand Down
4 changes: 3 additions & 1 deletion src/hu/openig/model/BattleGroundProjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public class BattleGroundProjector {
/** The symmetrically trimmed height of the object image at 0 rotation angle. */
public int trimmedHeight;
/** The destruction sound. */
public SoundType destruction;
public SoundType destructionSound;
/** The animation of the destruction explosion. */
public ExplosionType destructionExplosion;
/** The projectile used. */
public String projectile;
/** The information image. */
Expand Down
4 changes: 3 additions & 1 deletion src/hu/openig/model/BattleGroundShield.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class BattleGroundShield {
/** The symmetrically trimmed height of the object image at 0 rotation angle. */
public int trimmedHeight;
/** The destruction sound. */
public SoundType destruction;
public SoundType destructionSound;
/** The animation of the destruction explosion. */
public ExplosionType destructionExplosion;
/** The shield percentage. */
public int shields;
/** The information image. */
Expand Down
2 changes: 1 addition & 1 deletion src/hu/openig/model/BattleModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class BattleModel {
/** The probabilities for backfiring, if not present, there is no limit. */
public final Map<Difficulty, Double> backfires = new HashMap<>();
/** The explosion images. */
public final Map<ExplosionType, BufferedImage[]> groundExplosions = new HashMap<>();
public final Map<ExplosionType, BufferedImage[]> explosionAnimations = new HashMap<>();
/** The flying rocket [phase][angle]. */
public BufferedImage[][] groundRocket;
/** The direct attack units. */
Expand Down
3 changes: 3 additions & 0 deletions src/hu/openig/model/BattleProjectile.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public enum Mode {
public String id;
/** The sound effect to play when fired. */
public SoundType sound;
/** The on impact explosion animation identifier. */
public ExplosionType impactExplosion;
/** The normal [rotation][phase] image matrix. */
public BufferedImage[][] matrix;
/** The alternative [rotation][phase] image matrix. */
Expand All @@ -58,6 +60,7 @@ public enum Mode {
public BattleProjectile copy() {
BattleProjectile result = new BattleProjectile();
result.sound = sound;
result.impactExplosion = impactExplosion;
result.matrix = matrix;
result.alternative = alternative;
result.delay = delay;
Expand Down
6 changes: 4 additions & 2 deletions src/hu/openig/model/BattleSpaceEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ public class BattleSpaceEntity {
public int trimmedWidth;
/** The symmetrically trimmed height of the object image at 0 rotation angle. */
public int trimmedHeight;
/** The sound effect for explosion. */
public SoundType destruction;
/** The sound effect for destruction explosion. */
public SoundType destructionSound;
/** The animation of the destruction explosion. */
public ExplosionType destructionExplosion;
/** The rotation speed: full rotation time in milliseconds. */
public int rotationTime;
/** The movement speed: milliseconds per pixel. */
Expand Down
15 changes: 14 additions & 1 deletion src/hu/openig/model/ExplosionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ public enum ExplosionType {
/** Explosion. */
GROUND_ROCKET("groundwar/rocket_explosions", 9),
/** Explosion. */
GROUND_ROCKET_2("groundwar/rocket_explosions_2", 9)
GROUND_ROCKET_2("groundwar/rocket_explosions_2", 9),

/** Small explosion animation. */
EXPLOSION_SMALL("spacewar/explosion_1", 11),
/** Medium explosion animation. */
EXPLOSION_MEDIUM("spacewar/explosion_2", 11),
/** Large explosion animation. */
EXPLOSION_LARGE("spacewar/explosion_3", 18),
/** Tiny explosion animation. */
EXPLOSION_TINY("spacewar/explosion_hit", 5),
/** Green explosion. */
EXPLOSION_GREEN("spacewar/explosion_4", 30),
/** Multi explosion animation.The actual animation is a combinations of multiple explosion animations. */
EXPLOSION_MULTI("spacewar/explosion_3", 18),
;
/** The explosion image resource. */
public final String image;
Expand Down
4 changes: 2 additions & 2 deletions src/hu/openig/model/GroundwarManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ void damageArea(double cx, double cy, double damage, int area, Player owner) {
* @param type the type of the explosion animation
*/
void createExplosion(GroundwarUnit target, ExplosionType type) {
GroundwarExplosion exp = new GroundwarExplosion(world.battle.groundExplosions.get(type));
GroundwarExplosion exp = new GroundwarExplosion(world.battle.explosionAnimations.get(type));
exp.x = target.x;
exp.y = target.y;
exp.target = target;
Expand All @@ -535,7 +535,7 @@ void createExplosion(GroundwarUnit target, ExplosionType type) {
* @param type the type of the explosion animation
*/
void createExplosion(double x, double y, ExplosionType type) {
GroundwarExplosion exp = new GroundwarExplosion(world.battle.groundExplosions.get(type));
GroundwarExplosion exp = new GroundwarExplosion(world.battle.explosionAnimations.get(type));
exp.x = x;
exp.y = y;
ground.explosions.add(exp);
Expand Down
9 changes: 9 additions & 0 deletions src/hu/openig/model/SpacewarExplosion.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
public class SpacewarExplosion extends SpacewarObject {
/** The phase counter for the animation if any. */
public int phase;
/** The delay counter for the animation to start playing. */
public int delay = 0;
/** The phase image of the beam (e.g., the rotating meson bubble). */
public final BufferedImage[] phases;
/** The structure to remove when the explosion is at the middle. */
Expand All @@ -31,6 +33,9 @@ public SpacewarExplosion(BufferedImage[] phases) {
}
@Override
public BufferedImage get() {
if (delay > 0) {
return null;
}
return phases[(phase) % phases.length];
}
/** @return true if the animation is at the middle. */
Expand All @@ -43,6 +48,10 @@ public boolean isMiddle() {
* @return true if the end is reached
*/
public boolean next() {
if (delay > 0) {
delay--;
return false;
}
return ++phase == phases.length;
}
}
2 changes: 2 additions & 0 deletions src/hu/openig/model/SpacewarProjectile.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class SpacewarProjectile extends SpacewarObject {
public SpacewarStructure source;
/** The targeted structure. */
public SpacewarStructure target;
/** The explosion animation on impact. */
public BufferedImage[] impactExplosionAnim;
/** The impact sound. */
public SoundType impactSound;
/**
Expand Down
3 changes: 3 additions & 0 deletions src/hu/openig/model/SpacewarStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public enum StructureType {
public int ecmLevel;
/** The destruction sound. */
public SoundType destruction;
/** The destruction explosion. */
public ExplosionType destructionExplosion;
/** The structure type. */
public StructureType type;
/** The available weapon ports. */
Expand Down Expand Up @@ -337,6 +339,7 @@ public SpacewarStructure copy() {
r.trimmedHeight = trimmedHeight;
r.count = count;
r.destruction = destruction;
r.destructionExplosion = destructionExplosion;
r.ecmLevel = ecmLevel;
r.hp = hp;
r.hpMax = hpMax;
Expand Down
20 changes: 12 additions & 8 deletions src/hu/openig/model/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -2298,6 +2298,11 @@ public int testScore() {
* @param xbattle the battle definition
*/
void processBattle(XElement xbattle) {
for (ExplosionType et : ExplosionType.values()) {
BufferedImage img = rl.getImage(et.image);
battle.explosionAnimations.put(et, ImageUtils.splitByWidth(img, img.getWidth() / et.frames));
}

for (XElement xproj : xbattle.childElement("projectiles").childrenWithName("projectile")) {
BattleProjectile bp = new BattleProjectile();

Expand All @@ -2318,6 +2323,7 @@ void processBattle(XElement xbattle) {
if (xproj.has("sound")) {
bp.sound = SoundType.valueOf(xproj.get("sound"));
}
bp.impactExplosion = ExplosionType.valueOf(xproj.get("explosion-anim"));
bp.baseDamage = xproj.getInt("damage");
bp.range = xproj.getInt("range");
bp.delay = xproj.getInt("delay");
Expand Down Expand Up @@ -2357,7 +2363,8 @@ void processBattle(XElement xbattle) {
}

se.infoImageName = xspace.get("image");
se.destruction = SoundType.valueOf(xspace.get("sound"));
se.destructionSound = SoundType.valueOf(xspace.get("sound"));
se.destructionExplosion = ExplosionType.valueOf(xspace.get("explosion-anim"));
if (xspace.has("movement-speed")) {
se.movementSpeed = xspace.getInt("movement-speed");
}
Expand Down Expand Up @@ -2405,10 +2412,11 @@ void processBattle(XElement xbattle) {
}
se.infoImageName = xdefense.get("image");
if (xdefense.has("sound")) {
se.destruction = SoundType.valueOf(xdefense.get("sound"));
se.destructionSound = SoundType.valueOf(xdefense.get("sound"));
} else {
System.err.println("Missing sound for " + id);
}
se.destructionExplosion = ExplosionType.valueOf(xdefense.get("explosion-anim"));
se.projectile = xdefense.get("projectile");
se.rotationTime = xdefense.getInt("rotation-time");
se.baseDamage = xdefense.getInt("damage");
Expand Down Expand Up @@ -2436,10 +2444,11 @@ void processBattle(XElement xbattle) {
}
se.infoImageName = xdefense.get("image");
if (xdefense.has("sound")) {
se.destruction = SoundType.valueOf(xdefense.get("sound"));
se.destructionSound = SoundType.valueOf(xdefense.get("sound"));
} else {
System.err.println("Missing sound for " + id);
}
se.destructionExplosion = ExplosionType.valueOf(xdefense.get("explosion-anim"));
se.shields = xdefense.getInt("shield");

battle.groundShields.put(id, se);
Expand Down Expand Up @@ -2575,11 +2584,6 @@ void processBattle(XElement xbattle) {
}
}

for (ExplosionType et : ExplosionType.values()) {
BufferedImage img = rl.getImage(et.image);
battle.groundExplosions.put(et, ImageUtils.splitByWidth(img, img.getWidth() / et.frames));
}

BufferedImage rimg = rl.getImage("inventions/weapons/vehicles/rocket_matrix");
battle.groundRocket = ImageUtils.split(rimg, rimg.getWidth() / 16, rimg.getHeight() / 3);

Expand Down
7 changes: 4 additions & 3 deletions src/hu/openig/screen/items/PlanetScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -4180,7 +4180,7 @@ void drawUnits(Graphics2D g2) {
}
if (u.paralizedTTL > 0) {
// draw green paralization effect
BufferedImage[] expl = world().battle.groundExplosions.get(ExplosionType.GROUND_GREEN);
BufferedImage[] expl = world().battle.explosionAnimations.get(ExplosionType.GROUND_GREEN);
int idx = (PARALIZED_TTL - u.paralizedTTL) % expl.length;

BufferedImage icon = expl[idx];
Expand Down Expand Up @@ -5459,7 +5459,8 @@ boolean rotateGroundwarGunStep(GroundwarGun gun, Point target) {
* @param type the type of the explosion animation
*/
void createExplosion(GroundwarUnit target, ExplosionType type) {
GroundwarExplosion exp = new GroundwarExplosion(world().battle.groundExplosions.get(type));
GroundwarExplosion exp = new GroundwarExplosion(world().battle.explosionAnimations.get(type));
ExplosionType.valueOf("GROUND_YELLOW");
Point center = centerOf(target);
exp.x = center.x;
exp.y = center.y;
Expand All @@ -5473,7 +5474,7 @@ void createExplosion(GroundwarUnit target, ExplosionType type) {
* @param type the type of the explosion animation
*/
void createExplosion(int x, int y, ExplosionType type) {
GroundwarExplosion exp = new GroundwarExplosion(world().battle.groundExplosions.get(type));
GroundwarExplosion exp = new GroundwarExplosion(world().battle.explosionAnimations.get(type));
exp.x = x;
exp.y = y;
explosions.add(exp);
Expand Down
Loading

0 comments on commit d238d1b

Please sign in to comment.