From d502c48e32d50903ee0a253a94a82a93162de461 Mon Sep 17 00:00:00 2001 From: Rasmus Praestholm Date: Sat, 16 Jul 2016 23:51:46 -0400 Subject: [PATCH] Bug fixes, I hope! - last equipment commit left NPC ships without anything equipped (but the player with better equip logic). Now there are distinct blocks for PC vs NPC. - default config file for a new player ship updated to the new format so stuff will load first time. - under a rare condition (unknown details) a block with an engine item could be encountered that would terminate the game, yet just skipping that seemed to leave nothing broken. --- main/res/configs/playerSpawn.json | 2 +- main/src/org/destinationsol/game/SolGame.java | 3 - .../destinationsol/game/ship/ShipBuilder.java | 64 +++++++++++++------ .../org/destinationsol/game/ship/SolShip.java | 9 ++- 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/main/res/configs/playerSpawn.json b/main/res/configs/playerSpawn.json index 0b62f9915..45efe0df6 100644 --- a/main/res/configs/playerSpawn.json +++ b/main/res/configs/playerSpawn.json @@ -2,7 +2,7 @@ player: { ship: { hull: imperialSmall, - items: "rep:1:3 a1 s1 blaster", + items: "rep:1:3 a1-1 s1-1 blaster-1", money: 20, }, godModeShip: { diff --git a/main/src/org/destinationsol/game/SolGame.java b/main/src/org/destinationsol/game/SolGame.java index dd2ce445b..ed7666825 100644 --- a/main/src/org/destinationsol/game/SolGame.java +++ b/main/src/org/destinationsol/game/SolGame.java @@ -17,7 +17,6 @@ package org.destinationsol.game; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; import org.destinationsol.*; import org.destinationsol.common.DebugCol; @@ -525,12 +524,10 @@ private void setRespawnState(float money, ItemContainer ic, HullConfig hullConfi myRespawnMoney = .75f * money; myRespawnHull = hullConfig; myRespawnItems.clear(); - System.out.println("setRespawnState"); for (List group : ic) { for (SolItem item : group) { boolean equipped = myHero == null || myHero.maybeUnequip(this, item, false); if (equipped || SolMath.test(.75f)) { - System.out.println(item.getCode() + " " + item.isEquipped()); myRespawnItems.add(0, item); } } diff --git a/main/src/org/destinationsol/game/ship/ShipBuilder.java b/main/src/org/destinationsol/game/ship/ShipBuilder.java index 5cedf885e..33a62a1e3 100644 --- a/main/src/org/destinationsol/game/ship/ShipBuilder.java +++ b/main/src/org/destinationsol/game/ship/ShipBuilder.java @@ -76,38 +76,66 @@ public FarShip buildNewFar(SolGame game, Vector2 pos, Vector2 spd, float angle, Shield shield = null; Armor armor = null; - for (List group : ic) { - for (SolItem i : group) { - if (i instanceof Shield) { - if (i.isEquipped() > 0) { + // For the player use new logic that better respects what was explicitly equipped + if (pilot.isPlayer()) { + for (List group : ic) { + for (SolItem i : group) { + if (i instanceof Shield) { + if (i.isEquipped() > 0) { + shield = (Shield) i; + continue; + } + } + if (i instanceof Armor) { + if (i.isEquipped() > 0) { + armor = (Armor) i; + continue; + } + } + if (i instanceof GunItem) { + GunItem g = (GunItem) i; + if (i.isEquipped() > 0) { + int slot = i.isEquipped(); + if (g1 == null && hullConfig.getGunSlot(0).allowsRotation() != g.config.fixed && slot == 1) { + g1 = g; + continue; + } + if (hullConfig.getNrOfGunSlots() > 1 && g2 == null && hullConfig.getGunSlot(1).allowsRotation() != g.config.fixed && slot == 2) { + g2 = g; + } + if (g1 != g && g2 != g) { + i.setEquipped(0); // The gun couldn't fit in either slot + } + } + } + } + } + } else { + // For NPCs use the old logic that just equips whatever + for (List group : ic) { + for (SolItem i : group) { + if (i instanceof Shield) { shield = (Shield) i; continue; } - } - if (i instanceof Armor) { - if (i.isEquipped() > 0) { + if (i instanceof Armor) { armor = (Armor) i; continue; } - } - if (i instanceof GunItem) { - GunItem g = (GunItem) i; - if (i.isEquipped() > 0) { - int slot = i.isEquipped(); - if (g1 == null && hullConfig.getGunSlot(0).allowsRotation() != g.config.fixed && slot == 1) { + if (i instanceof GunItem) { + GunItem g = (GunItem) i; + if (g1 == null && hullConfig.getGunSlot(0).allowsRotation() != g.config.fixed) { g1 = g; continue; } - if (hullConfig.getNrOfGunSlots() > 1 && g2 == null && hullConfig.getGunSlot(1).allowsRotation() != g.config.fixed - && slot == 2) { + if (hullConfig.getNrOfGunSlots() > 1 && g2 == null && hullConfig.getGunSlot(1).allowsRotation() != g.config.fixed) { g2 = g; } - if (g1 != g && g2 != g) { - i.setEquipped(0); // The gun couldn't fit in either slot - } + continue; } } } + } if (giveAmmo) { diff --git a/main/src/org/destinationsol/game/ship/SolShip.java b/main/src/org/destinationsol/game/ship/SolShip.java index 0726ef75b..12314a47f 100644 --- a/main/src/org/destinationsol/game/ship/SolShip.java +++ b/main/src/org/destinationsol/game/ship/SolShip.java @@ -16,6 +16,7 @@ package org.destinationsol.game.ship; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.ContactImpulse; @@ -480,7 +481,10 @@ public boolean maybeEquip(SolGame game, SolItem item, boolean equip) { public boolean maybeEquip(SolGame game, SolItem item, boolean secondarySlot, boolean equip) { if (!secondarySlot) { if (item instanceof EngineItem) { - if (true) throw new AssertionError("no engine item support for now"); + if (true) { + Gdx.app.log("SolShip", "maybeEquip called for an engine item, can't do that!"); + //throw new AssertionError("engine items not supported"); + } EngineItem ei = (EngineItem) item; boolean ok = ei.isBig() == (myHull.config.getType() == HullConfig.Type.BIG); if (ok && equip) myHull.setEngine(game, this, ei); @@ -531,7 +535,8 @@ public boolean maybeUnequip(SolGame game, SolItem item, boolean secondarySlot, b if (!secondarySlot) { if (myHull.getEngine() == item) { if (true) { - throw new AssertionError("engine items not supported"); + Gdx.app.log("SolShip", "maybeUnequip called for an engine item, can't do that!"); + //throw new AssertionError("engine items not supported"); } if (unequip) { myHull.setEngine(game, this, null);