Skip to content

Commit d502c48

Browse files
committed
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.
1 parent 2f85b2b commit d502c48

File tree

4 files changed

+54
-24
lines changed

4 files changed

+54
-24
lines changed

main/res/configs/playerSpawn.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
player: {
33
ship: {
44
hull: imperialSmall,
5-
items: "rep:1:3 a1 s1 blaster",
5+
items: "rep:1:3 a1-1 s1-1 blaster-1",
66
money: 20,
77
},
88
godModeShip: {

main/src/org/destinationsol/game/SolGame.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.destinationsol.game;
1818

1919
import com.badlogic.gdx.graphics.Color;
20-
import com.badlogic.gdx.math.MathUtils;
2120
import com.badlogic.gdx.math.Vector2;
2221
import org.destinationsol.*;
2322
import org.destinationsol.common.DebugCol;
@@ -525,12 +524,10 @@ private void setRespawnState(float money, ItemContainer ic, HullConfig hullConfi
525524
myRespawnMoney = .75f * money;
526525
myRespawnHull = hullConfig;
527526
myRespawnItems.clear();
528-
System.out.println("setRespawnState");
529527
for (List<SolItem> group : ic) {
530528
for (SolItem item : group) {
531529
boolean equipped = myHero == null || myHero.maybeUnequip(this, item, false);
532530
if (equipped || SolMath.test(.75f)) {
533-
System.out.println(item.getCode() + " " + item.isEquipped());
534531
myRespawnItems.add(0, item);
535532
}
536533
}

main/src/org/destinationsol/game/ship/ShipBuilder.java

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,38 +76,66 @@ public FarShip buildNewFar(SolGame game, Vector2 pos, Vector2 spd, float angle,
7676
Shield shield = null;
7777
Armor armor = null;
7878

79-
for (List<SolItem> group : ic) {
80-
for (SolItem i : group) {
81-
if (i instanceof Shield) {
82-
if (i.isEquipped() > 0) {
79+
// For the player use new logic that better respects what was explicitly equipped
80+
if (pilot.isPlayer()) {
81+
for (List<SolItem> group : ic) {
82+
for (SolItem i : group) {
83+
if (i instanceof Shield) {
84+
if (i.isEquipped() > 0) {
85+
shield = (Shield) i;
86+
continue;
87+
}
88+
}
89+
if (i instanceof Armor) {
90+
if (i.isEquipped() > 0) {
91+
armor = (Armor) i;
92+
continue;
93+
}
94+
}
95+
if (i instanceof GunItem) {
96+
GunItem g = (GunItem) i;
97+
if (i.isEquipped() > 0) {
98+
int slot = i.isEquipped();
99+
if (g1 == null && hullConfig.getGunSlot(0).allowsRotation() != g.config.fixed && slot == 1) {
100+
g1 = g;
101+
continue;
102+
}
103+
if (hullConfig.getNrOfGunSlots() > 1 && g2 == null && hullConfig.getGunSlot(1).allowsRotation() != g.config.fixed && slot == 2) {
104+
g2 = g;
105+
}
106+
if (g1 != g && g2 != g) {
107+
i.setEquipped(0); // The gun couldn't fit in either slot
108+
}
109+
}
110+
}
111+
}
112+
}
113+
} else {
114+
// For NPCs use the old logic that just equips whatever
115+
for (List<SolItem> group : ic) {
116+
for (SolItem i : group) {
117+
if (i instanceof Shield) {
83118
shield = (Shield) i;
84119
continue;
85120
}
86-
}
87-
if (i instanceof Armor) {
88-
if (i.isEquipped() > 0) {
121+
if (i instanceof Armor) {
89122
armor = (Armor) i;
90123
continue;
91124
}
92-
}
93-
if (i instanceof GunItem) {
94-
GunItem g = (GunItem) i;
95-
if (i.isEquipped() > 0) {
96-
int slot = i.isEquipped();
97-
if (g1 == null && hullConfig.getGunSlot(0).allowsRotation() != g.config.fixed && slot == 1) {
125+
if (i instanceof GunItem) {
126+
GunItem g = (GunItem) i;
127+
if (g1 == null && hullConfig.getGunSlot(0).allowsRotation() != g.config.fixed) {
98128
g1 = g;
99129
continue;
100130
}
101-
if (hullConfig.getNrOfGunSlots() > 1 && g2 == null && hullConfig.getGunSlot(1).allowsRotation() != g.config.fixed
102-
&& slot == 2) {
131+
if (hullConfig.getNrOfGunSlots() > 1 && g2 == null && hullConfig.getGunSlot(1).allowsRotation() != g.config.fixed) {
103132
g2 = g;
104133
}
105-
if (g1 != g && g2 != g) {
106-
i.setEquipped(0); // The gun couldn't fit in either slot
107-
}
134+
continue;
108135
}
109136
}
110137
}
138+
111139
}
112140

113141
if (giveAmmo) {

main/src/org/destinationsol/game/ship/SolShip.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.destinationsol.game.ship;
1818

19+
import com.badlogic.gdx.Gdx;
1920
import com.badlogic.gdx.math.Vector2;
2021
import com.badlogic.gdx.physics.box2d.Body;
2122
import com.badlogic.gdx.physics.box2d.ContactImpulse;
@@ -480,7 +481,10 @@ public boolean maybeEquip(SolGame game, SolItem item, boolean equip) {
480481
public boolean maybeEquip(SolGame game, SolItem item, boolean secondarySlot, boolean equip) {
481482
if (!secondarySlot) {
482483
if (item instanceof EngineItem) {
483-
if (true) throw new AssertionError("no engine item support for now");
484+
if (true) {
485+
Gdx.app.log("SolShip", "maybeEquip called for an engine item, can't do that!");
486+
//throw new AssertionError("engine items not supported");
487+
}
484488
EngineItem ei = (EngineItem) item;
485489
boolean ok = ei.isBig() == (myHull.config.getType() == HullConfig.Type.BIG);
486490
if (ok && equip) myHull.setEngine(game, this, ei);
@@ -531,7 +535,8 @@ public boolean maybeUnequip(SolGame game, SolItem item, boolean secondarySlot, b
531535
if (!secondarySlot) {
532536
if (myHull.getEngine() == item) {
533537
if (true) {
534-
throw new AssertionError("engine items not supported");
538+
Gdx.app.log("SolShip", "maybeUnequip called for an engine item, can't do that!");
539+
//throw new AssertionError("engine items not supported");
535540
}
536541
if (unequip) {
537542
myHull.setEngine(game, this, null);

0 commit comments

Comments
 (0)