Skip to content

Commit

Permalink
Bug fixes, I hope!
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Cervator committed Jul 17, 2016
1 parent 2f85b2b commit d502c48
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 24 deletions.
2 changes: 1 addition & 1 deletion main/res/configs/playerSpawn.json
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
3 changes: 0 additions & 3 deletions main/src/org/destinationsol/game/SolGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SolItem> 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);
}
}
Expand Down
64 changes: 46 additions & 18 deletions main/src/org/destinationsol/game/ship/ShipBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,38 +76,66 @@ public FarShip buildNewFar(SolGame game, Vector2 pos, Vector2 spd, float angle,
Shield shield = null;
Armor armor = null;

for (List<SolItem> 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<SolItem> 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<SolItem> 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) {
Expand Down
9 changes: 7 additions & 2 deletions main/src/org/destinationsol/game/ship/SolShip.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d502c48

Please sign in to comment.