From aec98c5255eca271134c81d1abb0a27ba021c5a1 Mon Sep 17 00:00:00 2001 From: Vhati Date: Mon, 22 Jan 2018 04:24:53 -0500 Subject: [PATCH] Added FTL 1.5.4+ Boarder drone body sprites to the Floorplan --- .../net/blerf/ftl/parser/SavedGameParser.java | 3 ++ .../blerf/ftl/ui/SavedGameFloorplanPanel.java | 45 +++++++++++++++++++ .../floorplan/DefaultSpriteImageProvider.java | 7 +++ .../ftl/ui/floorplan/DroneBodySprite.java | 18 ++++++++ 4 files changed, 73 insertions(+) diff --git a/src/main/java/net/blerf/ftl/parser/SavedGameParser.java b/src/main/java/net/blerf/ftl/parser/SavedGameParser.java index 99b4c4a9..ba247e21 100644 --- a/src/main/java/net/blerf/ftl/parser/SavedGameParser.java +++ b/src/main/java/net/blerf/ftl/parser/SavedGameParser.java @@ -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 { diff --git a/src/main/java/net/blerf/ftl/ui/SavedGameFloorplanPanel.java b/src/main/java/net/blerf/ftl/ui/SavedGameFloorplanPanel.java index 9233052b..1fcc4ac7 100644 --- a/src/main/java/net/blerf/ftl/ui/SavedGameFloorplanPanel.java +++ b/src/main/java/net/blerf/ftl/ui/SavedGameFloorplanPanel.java @@ -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; @@ -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; @@ -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 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(); diff --git a/src/main/java/net/blerf/ftl/ui/floorplan/DefaultSpriteImageProvider.java b/src/main/java/net/blerf/ftl/ui/floorplan/DefaultSpriteImageProvider.java index 81970041..e54a465b 100644 --- a/src/main/java/net/blerf/ftl/ui/floorplan/DefaultSpriteImageProvider.java +++ b/src/main/java/net/blerf/ftl/ui/floorplan/DefaultSpriteImageProvider.java @@ -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"); @@ -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". diff --git a/src/main/java/net/blerf/ftl/ui/floorplan/DroneBodySprite.java b/src/main/java/net/blerf/ftl/ui/floorplan/DroneBodySprite.java index 5bd10d34..ff7be285 100644 --- a/src/main/java/net/blerf/ftl/ui/floorplan/DroneBodySprite.java +++ b/src/main/java/net/blerf/ftl/ui/floorplan/DroneBodySprite.java @@ -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; @@ -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 );