001package com.fs.starfarer.api.combat; 002 003import java.util.EnumSet; 004import java.util.List; 005import java.util.Set; 006 007import java.awt.Color; 008 009import org.lwjgl.util.vector.Vector2f; 010 011import com.fs.starfarer.api.characters.PersonAPI; 012import com.fs.starfarer.api.combat.ShieldAPI.ShieldType; 013import com.fs.starfarer.api.combat.WeaponAPI.WeaponType; 014import com.fs.starfarer.api.combat.listeners.CombatListenerManagerAPI; 015import com.fs.starfarer.api.fleet.FleetMemberAPI; 016import com.fs.starfarer.api.graphics.SpriteAPI; 017import com.fs.starfarer.api.loading.WeaponSlotAPI; 018 019/** 020 * @author Alex Mosolov 021 * 022 * Copyright 2012 Fractal Softworks, LLC 023 */ 024public interface ShipAPI extends CombatEntityAPI { 025 026 027 public static enum HullSize { 028 DEFAULT, // also makes FIGHTER.ordinal() = 1, which is convenient 029 FIGHTER, 030 FRIGATE, 031 DESTROYER, 032 CRUISER, 033 CAPITAL_SHIP; 034 035 public HullSize smaller(boolean allowFighter) { 036 if (this == FRIGATE && allowFighter) return FIGHTER; 037 if (this == DESTROYER) return FRIGATE; 038 if (this == CRUISER) return DESTROYER; 039 if (this == CAPITAL_SHIP) return CRUISER; 040 return this; 041 } 042 043 public HullSize larger() { 044 if (this == FIGHTER) return FRIGATE; 045 if (this == FRIGATE) return DESTROYER; 046 if (this == DESTROYER) return CRUISER; 047 if (this == CRUISER) return CAPITAL_SHIP; 048 return this; 049 } 050 } 051 052 /** 053 * ID of FleetMemberAPI this Ship corresponds to. Can be null if there isn't one. 054 * @return 055 */ 056 String getFleetMemberId(); 057 058 059 /** 060 * @return Where the ship is aiming with the mouse pointer, in engine coordinates. Works for AI controlled ships too. 061 */ 062 Vector2f getMouseTarget(); 063 064 boolean isShuttlePod(); 065 boolean isDrone(); 066 boolean isFighter(); 067 boolean isFrigate(); 068 boolean isDestroyer(); 069 boolean isCruiser(); 070 boolean isCapital(); 071 072 HullSize getHullSize(); 073 074 075 ShipAPI getShipTarget(); 076 void setShipTarget(ShipAPI ship); 077 078 /** 079 * @return 0 or 1, never 100 (neutral). 080 */ 081 int getOriginalOwner(); 082 void setOriginalOwner(int originalOwner); 083 void resetOriginalOwner(); 084 085 MutableShipStatsAPI getMutableStats(); 086 087 boolean isHulk(); 088 089 List<WeaponAPI> getAllWeapons(); 090 091 ShipSystemAPI getPhaseCloak(); 092 ShipSystemAPI getSystem(); 093 ShipSystemAPI getTravelDrive(); 094 void toggleTravelDrive(); 095 096 097 void setShield(ShieldType type, float shieldUpkeep, float shieldEfficiency, float arc); 098 099 ShipHullSpecAPI getHullSpec(); 100 ShipVariantAPI getVariant(); 101 102 /** 103 * The ship will try to use its system next frame. 104 * Equivalent to the player pressing the "use system" button while controlling a ship. 105 * So, it may fail for various reasons - out of ammo, not enough flux, overloaded, etc. 106 */ 107 void useSystem(); 108 109 FluxTrackerAPI getFluxTracker(); 110 111 112 /** 113 * Use getWing().getWingMembers() instead. 114 * @return null, or list of fighter wing members. 115 */ 116 @Deprecated List<ShipAPI> getWingMembers(); 117 118 /** 119 * Use getWing().getLeader() instead. 120 * @return 121 */ 122 ShipAPI getWingLeader(); 123 124 boolean isWingLeader(); 125 126 FighterWingAPI getWing(); 127 128 List<ShipAPI> getDeployedDrones(); 129 ShipAPI getDroneSource(); 130 131 /** 132 * Useful for determining whether fighters are part of the same wing. 133 * @return 134 */ 135 Object getWingToken(); 136 137 138 ArmorGridAPI getArmorGrid(); 139 140 void setRenderBounds(boolean renderBounds); 141 142 143 void setCRAtDeployment(float cr); 144 float getCRAtDeployment(); 145 float getCurrentCR(); 146 void setCurrentCR(float cr); 147 148 float getWingCRAtDeployment(); 149 150 void setHitpoints(float value); 151 152 /** 153 * @return the time that counts for peak CR reduction purposes, not necessarily the full time. 154 */ 155 float getTimeDeployedForCRReduction(); 156 157 float getFullTimeDeployed(); 158 159 boolean losesCRDuringCombat(); 160 161 /** 162 * If controls are locked due to crash (or regular) mothballing; only applicable in "ESCAPE" battles. 163 * @return 164 */ 165 boolean controlsLocked(); 166 167 void setControlsLocked(boolean controlsLocked); 168 169 170 void setShipSystemDisabled(boolean systemDisabled); 171 172 173 174 /** 175 * All weapons ever disabled during the last battle. 176 * @return 177 */ 178 Set<WeaponAPI> getDisabledWeapons(); 179 180 /** 181 * Number of times a full engine flameout occurred during the last battle. 182 * @return 183 */ 184 int getNumFlameouts(); 185 186 float getHullLevelAtDeployment(); 187 188 /** 189 * Note: If also changing bounds, make sure they are still within the armor grid 190 * of the ship, which is determined by the original sprite. 191 * @param category under "graphics" in settings.json 192 * @param key id under category. 193 */ 194 void setSprite(String category, String key); 195 196 /** 197 * A wrapper around the internal implementation of a sprite. Creates a new wrapper with every call, should 198 * store the return value and reuse it when possible instead of calling this method every time. 199 * 200 * @return 201 */ 202 SpriteAPI getSpriteAPI(); 203 204 ShipEngineControllerAPI getEngineController(); 205 206 207 /** 208 * Should only be used by a ShipAIPlugin. 209 * @param command type of the command. 210 * @param param Generally a Vector2f with a "mouse" location. See ShipCommand.java for details. 211 * @param groupNumber Only used for weapon-group-related commands. 212 */ 213 void giveCommand(ShipCommand command, Object param, int groupNumber); 214 215 /** 216 * Only should be called if the AI needs to be changed dynamically. Otherwise, 217 * use ModPlugin.pickShipAI() instead. 218 * @param ai 219 */ 220 void setShipAI(ShipAIPlugin ai); 221 222 /** 223 * Does NOT return the same ai passed in to setShipAI(), but a wrapper around it. 224 * Can be used to save/restore the AI. 225 * @return 226 */ 227 ShipAIPlugin getShipAI(); 228 229 230 /** 231 * Sets the ship's AI to the core implementation. 232 */ 233 void resetDefaultAI(); 234 235 236 void turnOnTravelDrive(); 237 void turnOnTravelDrive(float dur); 238 void turnOffTravelDrive(); 239 240 boolean isRetreating(); 241 /** 242 * Should be set to "true" to allow the ship to go outside the map bounds and be picked up as "retreated" 243 * when it gets past the proper map boundary. 244 * @param retreating 245 */ 246 //void setRetreating(boolean retreating); 247 248 249 /** 250 * Call this if beginLandingAnimation() was already called, but 251 * the ship being landed on was destroyed before FighterLaunchBayAPI.land() is called. 252 * 253 * Will cause the fighter to reverse its landing animation and take off. 254 */ 255 void abortLanding(); 256 257 /** 258 * The fighter will become invulnerable and gradually get smaller/fade out. 259 * Purely visual. If nothing else is done, it will remain this way, 260 * so FighterLaunchBayAPI.land() should be called to remove it from the 261 * engine when the landing animation is complete. 262 * @param target Used to determine what ship the fighter's shadow is cast on. 263 */ 264 void beginLandingAnimation(ShipAPI target); 265 266 /** 267 * @return whether the landing animation has been kicked off (i.e. beginLandingAnimation() was called, and abortLanding() was not) 268 */ 269 boolean isLanding(); 270 271 272 /** 273 * @return whether the landing animation is finished. 274 */ 275 boolean isFinishedLanding(); 276 277 278 /** 279 * @return true if the ship is still in play, including fighters that are currently landed in a launch bay. 280 */ 281 boolean isAlive(); 282 283 284 boolean isInsideNebula(); 285 void setInsideNebula(boolean isInsideNebula); 286 boolean isAffectedByNebula(); 287 void setAffectedByNebula(boolean affectedByNebula); 288 289 /** 290 * CR cost to deploy, range is [0, 1]. 291 * For fighters returns cost for entire wing. 292 * @return 293 */ 294 float getDeployCost(); 295 296 /** 297 * Removes weapon from any groups it's in. Should be used in conjunction with permanently disabling the weapon. 298 * @param weapon 299 */ 300 void removeWeaponFromGroups(WeaponAPI weapon); 301 302 303 304 /** 305 * @param module WeaponAPI or ShipEngineAPI. 306 */ 307 void applyCriticalMalfunction(Object module); 308 309 float getBaseCriticalMalfunctionDamage(); 310 float getEngineFractionPermanentlyDisabled(); 311 312 313 /** 314 * Alpha the base ship should be rendered at. Includes alpha modifier from ship systems and 315 * from fighters taking off/landing. 316 * @return 317 */ 318 float getCombinedAlphaMult(); 319 320 321 float getLowestHullLevelReached(); 322 323 324 /** 325 * Null if the ship is not AI-controlled. 326 * @return 327 */ 328 ShipwideAIFlags getAIFlags(); 329 List<WeaponGroupAPI> getWeaponGroupsCopy(); 330 331 332 boolean isHoldFire(); 333 boolean isHoldFireOneFrame(); 334 void setHoldFireOneFrame(boolean holdFireOneFrame); 335 336 boolean isPhased(); 337 338 339 boolean isAlly(); 340 341 342 void setWeaponGlow(float glow, Color color, EnumSet<WeaponType> types); 343 void setVentCoreColor(Color color); 344 void setVentFringeColor(Color color); 345 Color getVentCoreColor(); 346 Color getVentFringeColor(); 347 348 349// void setVentCoreTexture(String textureId); 350// void setVentFringeTexture(String textureId); 351// String getVentFringeTexture(); 352// String getVentCoreTexture(); 353 String getHullStyleId(); 354 WeaponGroupAPI getWeaponGroupFor(WeaponAPI weapon); 355 356 void setCopyLocation(Vector2f loc, float copyAlpha, float copyFacing); 357 Vector2f getCopyLocation(); 358 359 360 void setAlly(boolean ally); 361 362 void applyCriticalMalfunction(Object module, boolean permanent); 363 364 365 String getId(); 366 367 368 String getName(); 369 370 371 void setJitter(Object source, Color color, float intensity, int copies, float range); 372 void setJitterUnder(Object source, Color color, float intensity, int copies, float range); 373 void setJitter(Object source, Color color, float intensity, int copies, float minRange, float range); 374 void setJitterUnder(Object source, Color color, float intensity, int copies, float minRange, float range); 375 376 377 float getTimeDeployedUnderPlayerControl(); 378 379 380 SpriteAPI getSmallTurretCover(); 381 SpriteAPI getSmallHardpointCover(); 382 SpriteAPI getMediumTurretCover(); 383 SpriteAPI getMediumHardpointCover(); 384 SpriteAPI getLargeTurretCover(); 385 SpriteAPI getLargeHardpointCover(); 386 387 boolean isDefenseDisabled(); 388 void setDefenseDisabled(boolean defenseDisabled); 389 390 391 void setPhased(boolean phased); 392 393 void setExtraAlphaMult(float transparency); 394 void setApplyExtraAlphaToEngines(boolean applyExtraAlphaToEngines); 395 396 397 void setOverloadColor(Color color); 398 void resetOverloadColor(); 399 Color getOverloadColor(); 400 401 402 boolean isRecentlyShotByPlayer(); 403 404 405 float getMaxSpeedWithoutBoost(); 406 407 408 float getHardFluxLevel(); 409 410 411 void fadeToColor(Object source, Color color, float durIn, float durOut, float maxShift); 412 413 414 boolean isShowModuleJitterUnder(); 415 416 /** 417 * False by default. May need to set to true for ships with large decorative weapons etc. 418 * @param showModuleJitterUnder 419 */ 420 void setShowModuleJitterUnder(boolean showModuleJitterUnder); 421 422 423 /** 424 * Location is relative to center of ship. 425 * @param color 426 * @param locX 427 * @param locY 428 * @param velX 429 * @param velY 430 * @param maxJitter 431 * @param in 432 * @param dur 433 * @param out 434 * @param additive 435 * @param combineWithSpriteColor 436 * @param aboveShip 437 */ 438 void addAfterimage(Color color, float locX, float locY, float velX, 439 float velY, float maxJitter, float in, float dur, float out, 440 boolean additive, boolean combineWithSpriteColor, boolean aboveShip); 441 442 443 PersonAPI getCaptain(); 444 445 446 WeaponSlotAPI getStationSlot(); 447 void setStationSlot(WeaponSlotAPI stationSlot); 448 449 ShipAPI getParentStation(); 450 void setParentStation(ShipAPI station); 451 452 453 Vector2f getFixedLocation(); 454 void setFixedLocation(Vector2f fixedLocation); 455 456 457 boolean hasRadarRibbonIcon(); 458 boolean isTargetable(); 459 460 461 void setStation(boolean isStation); 462 463 464 boolean isSelectableInWarroom(); 465 466 467 //boolean isAITargetable(); 468 469 470 boolean isShipWithModules(); 471 void setShipWithModules(boolean isShipWithModules); 472 List<ShipAPI> getChildModulesCopy(); 473 474 475 boolean isPiece(); 476 477 478 /** 479 * Visual clipping bounds for pieces of ships. Returns null for intact ships. 480 * @return 481 */ 482 BoundsAPI getVisualBounds(); 483 484 485 /** 486 * Rendering offset for weapons and such, due to ship center changes on a ship piece. 487 * (0, 0) for an intact ship. 488 * @return 489 */ 490 Vector2f getRenderOffset(); 491 492 493 /** 494 * Should be called on a ship that's already a hulk. 495 * Will return the smaller of the two pieces (the current ship becomes the larger piece), or 496 * null if it did not find a way to split the ship. Calling the method again in this case 497 * may result in a valid split being found. 498 * @return 499 */ 500 ShipAPI splitShip(); 501 502 503 int getNumFighterBays(); 504 505 506 boolean isPullBackFighters(); 507 void setPullBackFighters(boolean pullBackFighters); 508 509 boolean hasLaunchBays(); 510 List<FighterLaunchBayAPI> getLaunchBaysCopy(); 511 float getFighterTimeBeforeRefit(); 512 void setFighterTimeBeforeRefit(float fighterTimeBeforeRefit); 513 514 List<FighterWingAPI> getAllWings(); 515 516 float getSharedFighterReplacementRate(); 517 518 boolean areSignificantEnemiesInRange(); 519 520 521 List<WeaponAPI> getUsableWeapons(); 522 523 524 Vector2f getModuleOffset(); 525 526 527 float getMassWithModules(); 528 529 530 PersonAPI getOriginalCaptain(); 531 532 boolean isRenderEngines(); 533 void setRenderEngines(boolean renderEngines); 534 535 536 WeaponGroupAPI getSelectedGroupAPI(); 537 void setHullSize(HullSize hullSize); 538 void ensureClonedStationSlotSpec(); 539 void setMaxHitpoints(float maxArmor); 540 void setDHullOverlay(String spriteName); 541 boolean isStation(); 542 boolean isStationModule(); 543 boolean areAnyEnemiesInRange(); 544 545 void blockCommandForOneFrame(ShipCommand command); 546 547 float getMaxTurnRate(); 548 float getTurnAcceleration(); 549 float getTurnDeceleration(); 550 float getDeceleration(); 551 /** 552 * This does not return the actual current acceleration of the ship. 553 * Instead, it returns the possible acceleration of the ship, if it were accelerating forward. 554 * Lateral/backward acceleration is modified based on the ship size and maneuverability 555 * Note that physics in Starsector is pseudo-newtonian. There is a hard limit on velocity and no limit on possible jerk. 556 * @return the potential acceleration of the ship in question in su/s² 557 */ 558 float getAcceleration(); 559 float getMaxSpeed(); 560 float getFluxLevel(); 561 float getCurrFlux(); 562 float getMaxFlux(); 563 float getMinFluxLevel(); 564 float getMinFlux(); 565 566 void setLightDHullOverlay(); 567 void setMediumDHullOverlay(); 568 void setHeavyDHullOverlay(); 569 570 571 boolean isJitterShields(); 572 void setJitterShields(boolean jitterShields); 573 574 575 boolean isInvalidTransferCommandTarget(); 576 void setInvalidTransferCommandTarget(boolean invalidTransferCommandTarget); 577 578 void clearDamageDecals(); 579 580 581 void syncWithArmorGridState(); 582 void syncWeaponDecalsWithArmorDamage(); 583 584 585 boolean isDirectRetreat(); 586 587 void setRetreating(boolean retreating, boolean direct); 588 589 590 boolean isLiftingOff(); 591 592 593 void setVariantForHullmodCheckOnly(ShipVariantAPI variant); 594 595 596 Vector2f getShieldCenterEvenIfNoShield(); 597 float getShieldRadiusEvenIfNoShield(); 598 599 600 FleetMemberAPI getFleetMember(); 601 602 603 Vector2f getShieldTarget(); 604 void setShieldTargetOverride(float x, float y); 605 606 607 608 /** 609 * Will be null if no listeners added. 610 * @return 611 */ 612 CombatListenerManagerAPI getListenerManager(); 613 614 void addListener(Object listener); 615 void removeListener(Object listener); 616 void removeListenerOfClass(Class<?> c); 617 boolean hasListener(Object listener); 618 boolean hasListenerOfClass(Class<?> c); 619 <T> List<T> getListeners(Class<T> c); 620 621 622 Object getParamAboutToApplyDamage(); 623 void setParamAboutToApplyDamage(Object param); 624 625 626 float getFluxBasedEnergyWeaponDamageMultiplier(); 627 628 629 void setName(String name); 630 631 632 void setHulk(boolean isHulk); 633 634 635 void setCaptain(PersonAPI captain); 636 float getShipExplosionRadius(); 637 638 639 void setCircularJitter(boolean circular); 640 641 642 float getExtraAlphaMult(); 643 644 645 void setAlphaMult(float alphaMult); 646 float getAlphaMult(); 647 648 649 void setAnimatedLaunch(); 650 651 652 void setLaunchingShip(ShipAPI launchingShip); 653 654 655 boolean isNonCombat(boolean considerOrders); 656 657 658 float findBestArmorInArc(float facing, float arc); 659 float getAverageArmorInSlice(float direction, float arc); 660 661 662 void setHoldFire(boolean holdFire); 663 664 665 void cloneVariant(); 666 667 668 void setTimeDeployed(float timeDeployed); 669 670 671 void setFluxVentTextureSheet(String textureId); 672 String getFluxVentTextureSheet(); 673 674 float getAimAccuracy(); 675 676 677 float getForceCarrierTargetTime(); 678 void setForceCarrierTargetTime(float forceCarrierTargetTime); 679 float getForceCarrierPullBackTime(); 680 void setForceCarrierPullBackTime(float forceCarrierPullBackTime); 681 ShipAPI getForceCarrierTarget(); 682 void setForceCarrierTarget(ShipAPI forceCarrierTarget); 683 684 685 void setWing(FighterWingAPI wing); 686 float getExplosionScale(); 687 void setExplosionScale(float explosionScale); 688 Color getExplosionFlashColorOverride(); 689 void setExplosionFlashColorOverride(Color explosionFlashColorOverride); 690 Vector2f getExplosionVelocityOverride(); 691 void setExplosionVelocityOverride(Vector2f explosionVelocityOverride); 692 693 694 void setNextHitHullDamageThresholdMult(float threshold, float multBeyondThreshold); 695 696 697 boolean isEngineBoostActive(); 698 699 700 void makeLookDisabled(); 701 702 703 void setExtraAlphaMult2(float transparency); 704 705 706 float getExtraAlphaMult2(); 707 708 709 void setDrone(boolean isDrone); 710 711 712 CombatEngineLayers getLayer(); 713 void setLayer(CombatEngineLayers layer); 714 715 716 boolean isForceHideFFOverlay(); 717 void setForceHideFFOverlay(boolean forceHideFFOverlay); 718 719 720 Set<String> getTags(); 721 void addTag(String tag); 722 boolean hasTag(String tag); 723 724 725 void setSprite(SpriteAPI sprite); 726 727 728 float getPeakTimeRemaining(); 729 730 EnumSet<CombatEngineLayers> getActiveLayers(); 731 732 733 boolean isShipSystemDisabled(); 734 735 736 boolean isDoNotFlareEnginesWhenStrafingOrDecelerating(); 737 void setDoNotFlareEnginesWhenStrafingOrDecelerating(boolean doNotFlare); 738 739 740 PersonAPI getFleetCommander(); 741 742 743 boolean isDoNotRender(); 744 void setDoNotRender(boolean doNotRender); 745 float getHulkChanceOverride(); 746 void setHulkChanceOverride(float hulkChanceOverride); 747 float getImpactVolumeMult(); 748 void setImpactVolumeMult(float impactVolumeMult); 749 750 751 /** 752 * Potentially quite slow. 753 * @param from 754 * @param to 755 * @return 756 */ 757 Vector2f checkCollisionVsRay(Vector2f from, Vector2f to); 758 759 760 /** 761 * Also potentially quite slow. 762 * @param p 763 * @return 764 */ 765 boolean isPointInBounds(Vector2f p); 766 767 768 boolean isSpawnDebris(); 769 void setSpawnDebris(boolean spawnDebris); 770 771 float getDHullOverlayAngleOffset(); 772 void setDHullOverlayAngleOffset(float dHullOverlayAngleOffset); 773 774 float getExtraOverlayAngleOffset(); 775 void setExtraOverlayAngleOffset(float extraOverlayAngleOffset); 776 void setExtraOverlay(String spriteName); 777 float getExtraOverlayShadowOpacity(); 778 void setExtraOverlayShadowOpacity(float extraOverlayOpacity); 779 boolean isExtraOverlayMatchHullColor(); 780 void setExtraOverlayMatchHullColor(boolean extraOverlayMatchHullColor); 781 782 783 void resetSelectedGroup(); 784 void removeTag(String tag); 785 786 787 boolean isSkipNextDamagedExplosion(); 788 void setSkipNextDamagedExplosion(boolean skipNextDamagedExplosion); 789 void setDefaultAI(FleetMemberAPI member); 790 boolean isNoDamagedExplosions(); 791 void setNoDamagedExplosions(boolean noDamagedExplosions); 792 793 boolean isDoNotRenderSprite(); 794 void setDoNotRenderSprite(boolean doNotRenderSprite); 795 boolean isDoNotRenderShield(); 796 void setDoNotRenderShield(boolean doNotRenderShield); 797 boolean isDoNotRenderWeapons(); 798 void setDoNotRenderWeapons(boolean doNotRenderWeapons); 799 void setDoNotRenderVentingAnimation(boolean doNotRenderVentingAnimation); 800 boolean isDoNotRenderVentingAnimation(); 801 String getShipCollisionSoundOverride(); 802 void setShipCollisionSoundOverride(String shipCollisionSoundOverride); 803 String getAsteroidCollisionSoundOverride(); 804 void setAsteroidCollisionSoundOverride(String asteroidCollisionSoundOverride); 805 806 String getParentPieceId(); 807 void setParentPieceId(String parentPieceId); 808 809 810 void applyEffectsAfterShipAddedToCombatEngine(); 811 812 813 float getSinceLastDamageTaken(); 814 815 boolean isNoMuzzleFlash(); 816 void setNoMuzzleFlash(boolean noMuzzleFlash); 817 818 819 /** 820 * Being mostly ignored by enemy ships due to the IGNORE order. 821 * @return 822 */ 823 boolean isBeingIgnored(); 824 825 /** 826 * Being mostly ignored by enemy ships due to the IGNORE order. 827 * @return 828 */ 829 void setBeingIgnored(boolean beingIgnored); 830 831 832 void setLowestHullLevelReached(float lowestHullLevelReached); 833 834 835 void setFleetMember(FleetMemberAPI member); 836} 837 838 839 840 841 842