Skip to content

Commit

Permalink
Added FTL 1.5.4+ Boarder drone body sprites to the Floorplan
Browse files Browse the repository at this point in the history
  • Loading branch information
Vhati committed Jan 22, 2018
1 parent 0b030b1 commit aec98c5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/net/blerf/ftl/parser/SavedGameParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9237,6 +9237,9 @@ public String toString() {
* Boarder drones exclusively store body info in ExtendedDronePodInfo.
* The traditional DroneState's body fields remain at inoperative defaults.
*
* In FTL 1.01-1.03.3, Boarder drone bodies were actual crew on foreign
* ships.
*
* @see DroneState
*/
public static class BoarderDronePodInfo extends ExtendedDronePodInfo {
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/net/blerf/ftl/ui/SavedGameFloorplanPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import net.blerf.ftl.parser.DataManager;
import net.blerf.ftl.parser.SavedGameParser;
import net.blerf.ftl.parser.SavedGameParser.BatteryInfo;
import net.blerf.ftl.parser.SavedGameParser.BoarderDronePodInfo;
import net.blerf.ftl.parser.SavedGameParser.CloakingInfo;
import net.blerf.ftl.parser.SavedGameParser.ClonebayInfo;
import net.blerf.ftl.parser.SavedGameParser.CrewState;
Expand All @@ -76,6 +77,8 @@
import net.blerf.ftl.parser.SavedGameParser.DronePodState;
import net.blerf.ftl.parser.SavedGameParser.DroneState;
import net.blerf.ftl.parser.SavedGameParser.DroneType;
import net.blerf.ftl.parser.SavedGameParser.ExtendedDroneInfo;
import net.blerf.ftl.parser.SavedGameParser.ExtendedDronePodInfo;
import net.blerf.ftl.parser.SavedGameParser.ExtendedSystemInfo;
import net.blerf.ftl.parser.SavedGameParser.RoomState;
import net.blerf.ftl.parser.SavedGameParser.ShieldsInfo;
Expand Down Expand Up @@ -1075,6 +1078,48 @@ public void setGameState( SavedGameParser.SavedGameState gameState ) {
nearbyBundle.setFTLConstants( ftlConstants );
shipBundles.add( nearbyBundle );
addBundle( nearbyBundle, gameState.getNearbyShip(), false );

// Boarder drone body sprites from opposing ships (FTL 1.5.4+).
// In FTL 1.01-1.03.3, they would've been actual crew.
for ( ShipBundle bundle : shipBundles ) {
for ( ShipBundle otherBundle : shipBundles ) {
if ( bundle == otherBundle ) continue;

for ( SpriteReference<DroneState> droneRef : bundle.getDroneRefs() ) {
if ( droneRef.get() == null ) continue;

DroneBlueprint droneBlueprint = DataManager.get().getDrone( droneRef.get().getDroneId() );
DroneType droneType = DroneType.findById( droneBlueprint.getType() );
if ( !DroneType.BOARDER.equals( droneType ) ) continue;

ExtendedDroneInfo droneInfo = droneRef.get().getExtendedDroneInfo();
if ( droneInfo == null ) continue;

DronePodState dronePod = droneInfo.getDronePod();
if ( dronePod == null ) {
log.warn( "Boarder drone has extended info but lacks a drone pod!?" );
continue;
}

BoarderDronePodInfo boarderPodInfo = dronePod.getExtendedInfo( BoarderDronePodInfo.class );
if ( dronePod == null ) {
log.warn( "Boarder drone has extended info and a pod but lacks extended pod info!?" );
continue;
}

int bodySpriteX = otherBundle.getOriginX() + boarderPodInfo.getBodyX();
int bodySpriteY = otherBundle.getOriginY() + boarderPodInfo.getBodyY();

BufferedImage bodyImage = spriteImageProvider.getDroneBodyImage( droneType, droneRef.get().isPlayerControlled() );

DroneBodySprite droneBodySprite = new DroneBodySprite( droneRef, bodyImage );
droneBodySprite.setSize( droneBodySprite.getPreferredSize() );
droneBodySprite.setLocation( bodySpriteX - droneBodySprite.getPreferredSize().width/2, bodySpriteY - droneBodySprite.getPreferredSize().height/2 );
otherBundle.getDroneBodySprites().add( droneBodySprite );
shipPanel.add( droneBodySprite, DRONE_LAYER );
}
}
}
}

fitViewToViewport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ public BufferedImage getDroneBodyImage( DroneType droneType, boolean playerContr
imgRace = "battle";
originalSuffix = (( playerControlled ) ? "_sheet" : "_enemy_sheet");
}
if ( DroneType.BOARDER.equals( droneType ) ) { // Boarder, always foreign to the ship.
imgRace = "battle";
originalSuffix = (( playerControlled ) ? "_sheet" : "_enemy_sheet");
}
else if ( DroneType.REPAIR.equals( droneType ) ) { // Always local to the ship.
imgRace = "repair";
originalSuffix = (( playerControlled ) ? "_sheet" : "_enemy_sheet");
Expand Down Expand Up @@ -262,6 +266,9 @@ else if ( DataManager.get().hasResourceInputStream( originalPath ) ) {
* Humans have a separate female image. Ghost crew have human images (with
* programmatically reduced opacity).
*
* In FTL 1.01-1.03.3, Boarder drones' bodies were actually crew on the
* foreign ship.
*
* Image names have varied:
* FTL 1.01: Drones had "[X]_sheet" / "[X]_enemy_sheet".
* FTL 1.01: Crew had "[X]_player_[green|yellow]" / "[X]_enemy_red".
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/net/blerf/ftl/ui/floorplan/DroneBodySprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
import javax.swing.JComponent;

import net.blerf.ftl.parser.DataManager;
import net.blerf.ftl.parser.SavedGameParser.BoarderDronePodInfo;
import net.blerf.ftl.parser.SavedGameParser.DroneState;
import net.blerf.ftl.parser.SavedGameParser.DronePodState;
import net.blerf.ftl.parser.SavedGameParser.DroneType;
import net.blerf.ftl.parser.SavedGameParser.ExtendedDroneInfo;
import net.blerf.ftl.parser.SavedGameParser.ExtendedDronePodInfo;
import net.blerf.ftl.ui.ReferenceSprite;
import net.blerf.ftl.ui.SpriteReference;
import net.blerf.ftl.xml.DroneBlueprint;
Expand Down Expand Up @@ -51,6 +55,20 @@ public void referenceChanged() {
bodyVisible = true;
}
}
else if ( DroneType.BOARDER.equals( droneType ) ) {
ExtendedDroneInfo droneInfo = droneRef.get().getExtendedDroneInfo();
if ( droneInfo != null ) {
DronePodState dronePod = droneInfo.getDronePod();
if ( dronePod != null ) {
BoarderDronePodInfo boarderPodInfo = dronePod.getExtendedInfo( BoarderDronePodInfo.class );
if ( boarderPodInfo != null ) {
if ( boarderPodInfo.getBodyRoomId() >= 0 ) {
bodyVisible = true;
}
}
}
}
}
}

this.setVisible( bodyVisible );
Expand Down

0 comments on commit aec98c5

Please sign in to comment.