001package com.fs.starfarer.api.combat; 002 003import java.util.List; 004import java.util.Map; 005 006import java.awt.Color; 007 008import org.lwjgl.util.vector.Vector2f; 009 010import com.fs.starfarer.api.campaign.CombatDamageData; 011import com.fs.starfarer.api.combat.EmpArcEntityAPI.EmpArcParams; 012import com.fs.starfarer.api.combat.WeaponAPI.WeaponType; 013import com.fs.starfarer.api.combat.listeners.CombatListenerManagerAPI; 014import com.fs.starfarer.api.loading.DamagingExplosionSpec; 015import com.fs.starfarer.api.loading.WeaponSlotAPI; 016import com.fs.starfarer.api.loading.WeaponSpecAPI; 017import com.fs.starfarer.api.mission.FleetSide; 018 019/** 020 * @author Alex Mosolov 021 * 022 * Copyright 2012 Fractal Softworks, LLC 023 */ 024public interface CombatEngineAPI { 025 026 /** 027 * @return true if this battle is inside the campaign, false otherwise (i.e., mission or simulation, including in-campaign simulations). 028 * 029 */ 030 boolean isInCampaign(); 031 032 boolean isInCampaignSim(); 033 034 CombatUIAPI getCombatUI(); 035 036 void setHyperspaceMode(); 037 038 /** 039 * Use getObjectives() instead. 040 */ 041 @Deprecated 042 List<BattleObjectiveAPI> getAllObjectives(); 043 /** 044 * Use getShips() instead. 045 */ 046 @Deprecated 047 List<ShipAPI> getAllShips(); 048 049 List<BattleObjectiveAPI> getObjectives(); 050 List<ShipAPI> getShips(); 051 List<MissileAPI> getMissiles(); 052 List<CombatEntityAPI> getAsteroids(); 053 List<BeamAPI> getBeams(); 054 /** 055 * Includes missiles. 056 */ 057 List<DamagingProjectileAPI> getProjectiles(); 058 059 boolean isEntityInPlay(CombatEntityAPI entity); 060 061 FogOfWarAPI getFogOfWar(int owner); 062 063 void removeEntity(CombatEntityAPI entity); 064 065 CombatFleetManagerAPI getFleetManager(FleetSide side); 066 CombatFleetManagerAPI getFleetManager(int owner); 067 068 ShipAPI getPlayerShip(); 069 070 boolean isPaused(); 071 072 void endCombat(float delay); 073 void setDoNotEndCombat(boolean doNotEndCombat); 074 void endCombat(float delay, FleetSide winner); 075 076 077 ViewportAPI getViewport(); 078 079 /** 080 * @param entity 081 * @param point Location the damage is dealt at, in absolute engine coordinates (i.e. *not* relative to the ship). MUST fall within the sprite of a ship, given its current location and facing, for armor to properly be taken into account. 082 * @param damageAmount 083 * @param damageType 084 * @param empAmount 085 * @param bypassShields Whether shields are ignored completely. 086 * @param dealsSoftFlux Whether damage dealt to shields results in soft flux. 087 * @param source Should be a ShipAPI if the damage ultimately attributed to it. Can also be null. 088 * @param playSound Whether a sound based on the damage dealt should be played. 089 */ 090 void applyDamage(CombatEntityAPI entity, Vector2f point, 091 float damageAmount, DamageType damageType, float empAmount, 092 boolean bypassShields, boolean dealsSoftFlux, 093 Object source, boolean playSound); 094 095 void applyDamage(CombatEntityAPI entity, Vector2f point, 096 float damageAmount, DamageType damageType, float empAmount, 097 boolean bypassShields, boolean dealsSoftFlux, 098 Object source); 099 100 void applyDamage(Object damageModifierParam, CombatEntityAPI entity, Vector2f point, 101 float damageAmount, DamageType damageType, float empAmount, 102 boolean bypassShields, boolean dealsSoftFlux, 103 Object source, boolean playSound); 104 105 /** 106 * Particle with a somewhat brighter middle. 107 * @param brightness from 0 to 1 108 * @param duration in seconds 109 */ 110 111 void addHitParticle(Vector2f loc, Vector2f vel, float size, float brightness, float duration, Color color); 112 /** 113 * Standard glowy particle. 114 * @param brightness from 0 to 1 115 * @param duration in seconds 116 */ 117 public void addSmoothParticle(Vector2f loc, Vector2f vel, float size, float brightness, float duration, Color color); 118 119 /** 120 * Opaque smoke particle. 121 * @param brightness from 0 to 1 122 * @param duration in seconds 123 */ 124 public void addSmokeParticle(Vector2f loc, Vector2f vel, float size, float opacity, float duration, Color color); 125 126 127 /** 128 * Purely visual. 129 */ 130 void spawnExplosion(Vector2f loc, Vector2f vel, Color color, float size, float maxDuration); 131 132 /** 133 * @param size 0, 1, 2, or 3, with 3 being the largest. 134 * @param x location x 135 * @param y location y 136 * @param dx velocity x 137 * @param dy velocity y 138 * @return 139 */ 140 CombatEntityAPI spawnAsteroid(int size, float x, float y, float dx, float dy); 141 142 143 void addFloatingText(Vector2f loc, String text, float size, Color color, CombatEntityAPI attachedTo, float flashFrequency, float flashDuration); 144 void addFloatingDamageText(Vector2f loc, float damage, Color color, CombatEntityAPI attachedTo, CombatEntityAPI damageSource); 145 146 147 148 /** 149 * @param ship The ship launching this projectile. Can be null. 150 * @param weapon Firing weapon. Can be null. If not, used for figuring out range/damage bonuses, etc. 151 * @param weaponId ID of the weapon whose projectile to use. Required. 152 * @param point Location where the projectile will spawn. Required. 153 * @param angle Initial facing, in degrees (0 = 3 o'clock, 90 = 12 o'clock). 154 * @param shipVelocity Can be null. Otherwise, will be imparted to projectile. 155 * @return Projectile that was created, or null. 156 */ 157 public CombatEntityAPI spawnProjectile(ShipAPI ship, WeaponAPI weapon, String weaponId, 158 Vector2f point, float angle, Vector2f shipVelocity); 159 160 161 /** 162 * @param damageSource Ship that's ultimately responsible for dealing the damage of this EMP arc. Can be null. 163 * @param point starting point of the EMP arc, in absolute engine coordinates. 164 * @param pointAnchor The entity the starting point should move together with, if any. 165 * @param empTargetEntity Target of the EMP arc. If it's a ship, it will randomly pick an engine nozzle/weapon to arc to. Can also pass in a custom class implementing CombatEntityAPI to visually target the EMP at a specific location (and not do any damage). 166 * @param damageType 167 * @param damAmount 168 * @param empDamAmount 169 * @param maxRange Maximum range the arc can reach (useful for confining EMP arc targets to the area near point) 170 * @param impactSoundId Can be null. 171 * @param thickness Thickness of the arc (visual). 172 * @param fringe 173 * @param core 174 * @return 175 */ 176 public EmpArcEntityAPI spawnEmpArc(ShipAPI damageSource, 177 Vector2f point, 178 CombatEntityAPI pointAnchor, 179 CombatEntityAPI empTargetEntity, 180 DamageType damageType, 181 float damAmount, 182 float empDamAmount, 183 float maxRange, 184 String impactSoundId, 185 float thickness, 186 Color fringe, Color core); 187 188 public EmpArcEntityAPI spawnEmpArc(ShipAPI damageSource, 189 Vector2f point, 190 CombatEntityAPI pointAnchor, 191 CombatEntityAPI empTargetEntity, 192 DamageType damageType, 193 float damAmount, 194 float empDamAmount, 195 float maxRange, 196 String impactSoundId, 197 float thickness, 198 Color fringe, Color core, EmpArcParams params); 199 200 /** 201 * Same as spawnEmpArc, but goes through shields if they're blocking the line from the point to the chosen target. 202 */ 203 public EmpArcEntityAPI spawnEmpArcPierceShields(ShipAPI damageSource, 204 Vector2f point, CombatEntityAPI pointAnchor, 205 CombatEntityAPI empTargetEntity, DamageType damageType, 206 float damAmount, float empDamAmount, float maxRange, 207 String impactSoundId, float thickness, Color fringe, Color core); 208 public EmpArcEntityAPI spawnEmpArcPierceShields(ShipAPI damageSource, 209 Vector2f point, CombatEntityAPI pointAnchor, 210 CombatEntityAPI empTargetEntity, DamageType damageType, 211 float damAmount, float empDamAmount, float maxRange, 212 String impactSoundId, float thickness, Color fringe, Color core, EmpArcParams params); 213 214 215 float getMapWidth(); 216 float getMapHeight(); 217 218 /** 219 * BattleCreationContext used to initialize this battle. 220 * @return 221 */ 222 BattleCreationContext getContext(); 223 224 225 float getTotalElapsedTime(boolean includePaused); 226 227 /** 228 * Does *not* return 0 if the game is paused; actually the *current* frame. 229 * 230 * @return 231 */ 232 float getElapsedInLastFrame(); 233 234 /** 235 * Plugin has its init method called inside this method. 236 * @param plugin 237 */ 238 void addPlugin(EveryFrameCombatPlugin plugin); 239 240 void removePlugin(EveryFrameCombatPlugin plugin); 241 242 boolean isSimulation(); 243 boolean isMission(); 244 String getMissionId(); 245 246 247 void setPlayerShipExternal(ShipAPI ship); 248 boolean isUIShowingDialog(); 249 boolean isUIShowingHUD(); 250 boolean isUIAutopilotOn(); 251 252 253 /** 254 * Time elapsed while both sides can see at least one enemy ship. 255 * @return 256 */ 257 float getElapsedInContactWithEnemy(); 258 259 boolean isFleetsInContact(); 260 261 void setSideDeploymentOverrideSide(FleetSide sideDeploymentOverrideSide); 262 263 Map<String, Object> getCustomData(); 264 265 /** 266 * In the status list above the left side of the ship info widget in the bottom left. 267 * @param key 268 * @param spriteName 269 * @param title 270 * @param data 271 * @param isDebuff 272 */ 273 void maintainStatusForPlayerShip(Object key, String spriteName, String title, String data, boolean isDebuff); 274 275 void setPaused(boolean paused); 276 277 boolean playerHasNonAllyReserves(); 278 279 boolean playerHasAllyReserves(); 280 281 CombatDamageData getDamageData(); 282 283 MutableStat getTimeMult(); 284 285 void setMaxFleetPoints(FleetSide side, int fleetPoints); 286 287 CombatNebulaAPI getNebula(); 288 289 boolean isInFastTimeAdvance(); 290 291 /** 292 * Should work now. 293 */ 294 CombatEntityAPI spawnProjectile(ShipAPI ship, WeaponAPI weapon, 295 String weaponId, String projSpecId, Vector2f point, float angle, 296 Vector2f shipVelocity); 297 298 void updateStationModuleLocations(ShipAPI station); 299 300 301 /** 302 * All combat entities. 303 * @return 304 */ 305 CollisionGridAPI getAllObjectGrid(); 306 /** 307 * Ships only. 308 * @return 309 */ 310 CollisionGridAPI getShipGrid(); 311 /** 312 * Missiles only. 313 * @return 314 */ 315 CollisionGridAPI getMissileGrid(); 316 /** 317 * Asteroids only. 318 * @return 319 */ 320 CollisionGridAPI getAsteroidGrid(); 321 322 DamagingProjectileAPI spawnDamagingExplosion(DamagingExplosionSpec spec, ShipAPI source, Vector2f location); 323 DamagingProjectileAPI spawnDamagingExplosion(DamagingExplosionSpec spec, ShipAPI source, Vector2f location, boolean canDamageSource); 324 325 /** 326 * 0 = player, 1 = enemy, 2 = player allies, no player ships left. 327 * @return 328 */ 329 int getWinningSideId(); 330 boolean isCombatOver(); 331 332 void removeObject(Object object); 333 334 CombatEntityAPI addLayeredRenderingPlugin(CombatLayeredRenderingPlugin plugin); 335 336 boolean isEnemyInFullRetreat(); 337 338 339 boolean isMissileAlive(MissileAPI missile); 340 341 void spawnMuzzleFlashOrSmoke(ShipAPI ship, WeaponSlotAPI slot, WeaponSpecAPI spec, int barrel, float targetAngle); 342 343 CollisionGridAPI getAiGridMissiles(); 344 CollisionGridAPI getAiGridShips(); 345 CollisionGridAPI getAiGridAsteroids(); 346 347 /** 348 * Visible (i.e. not under fog) or recently seen. 349 * @param owner 350 * @param other 351 * @return 352 */ 353 boolean isAwareOf(int owner, CombatEntityAPI other); 354 355 /** 356 * Gives strafe left/right and accelerate forward/backward/decelerate commands to accomplish this. 357 * @param missile 358 * @param desiredHeading 359 * @param desiredSpeed 360 */ 361 void headInDirectionWithoutTurning(MissileAPI missile, float desiredHeading, float desiredSpeed); 362 363 /** 364 * Gives strafe left/right and accelerate forward/backward/decelerate commands to accomplish this. 365 * @param ship 366 * @param desiredHeading 367 * @param desiredSpeed 368 */ 369 void headInDirectionWithoutTurning(ShipAPI ship, float desiredHeading, float desiredSpeed); 370 371 /** 372 * accuracyFactor: 1 = best accuracy, 373 * >1 (up to around 2 at most normally) poor accuracy, <1 = leading target too much, not used. 374 * @param from 375 * @param accuracyFactor 376 * @param to 377 * @param projSpeed 378 * @return 379 */ 380 Vector2f getAimPointWithLeadForAutofire(CombatEntityAPI from, float accuracyFactor, CombatEntityAPI to, float projSpeed); 381 382 CombatListenerManagerAPI getListenerManager(); 383 384 void applyDamageModifiersToSpawnedProjectileWithNullWeapon(ShipAPI source, WeaponType type, boolean isBeam, DamageAPI damage); 385 386 void addHitParticle(Vector2f loc, Vector2f vel, float size, float brightness, float durationIn, float totalDuration, Color color); 387 388 /** 389 * Duration gets auto-computed. 390 * @param loc 391 * @param vel 392 * @param size 393 * @param brightness 394 * @param color 395 */ 396 void addHitParticle(Vector2f loc, Vector2f vel, float size, float brightness, Color color); 397 398 EmpArcEntityAPI spawnEmpArcVisual(Vector2f from, CombatEntityAPI fromAnchor, Vector2f to, CombatEntityAPI toAnchor, 399 float thickness, Color fringe, Color core); 400 EmpArcEntityAPI spawnEmpArcVisual(Vector2f from, CombatEntityAPI fromAnchor, Vector2f to, CombatEntityAPI toAnchor, 401 float thickness, Color fringe, Color core, EmpArcParams params); 402 403 void addSmoothParticle(Vector2f loc, Vector2f vel, float size, 404 float brightness, float rampUpFraction, float totalDuration, 405 Color color); 406 407 void addNegativeParticle(Vector2f loc, Vector2f vel, float size, float rampUpFraction, float totalDuration, Color color); 408 409 void addNebulaParticle(Vector2f loc, Vector2f vel, float size, 410 float endSizeMult, float rampUpFraction, 411 float fullBrightnessFraction, float totalDuration, Color color); 412 413 void addNegativeNebulaParticle(Vector2f loc, Vector2f vel, float size, 414 float endSizeMult, float rampUpFraction, 415 float fullBrightnessFraction, float totalDuration, Color color); 416 417 void addNebulaSmokeParticle(Vector2f loc, Vector2f vel, float size, 418 float endSizeMult, float rampUpFraction, 419 float fullBrightnessFraction, float totalDuration, Color color); 420 421 boolean hasAttachedFloaty(CombatEntityAPI entity); 422 423 void addNebulaParticle(Vector2f loc, Vector2f vel, float size, 424 float endSizeMult, float rampUpFraction, 425 float fullBrightnessFraction, float totalDuration, Color color, 426 boolean expandAsSqrt); 427 428 void addSwirlyNebulaParticle(Vector2f loc, Vector2f vel, float size, 429 float endSizeMult, float rampUpFraction, 430 float fullBrightnessFraction, float totalDuration, Color color, 431 boolean expandAsSqrt); 432 433 void addNegativeSwirlyNebulaParticle(Vector2f loc, Vector2f vel, 434 float size, float endSizeMult, float rampUpFraction, 435 float fullBrightnessFraction, float totalDuration, Color color); 436 437 boolean isInPlay(Object object); 438 439 void setCombatNotOverForAtLeast(float seconds); 440 void setCombatNotOverFor(float seconds); 441 float getCombatNotOverFor(); 442 443 void setCustomExit(String buttonTitle, String confirmString); 444 String getCustomExitButtonTitle(); 445 String getCustomExitButtonConfirmString(); 446 447 void addFloatingTextAlways(Vector2f loc, String text, float size, Color color, CombatEntityAPI attachedTo, 448 float flashFrequency, float flashDuration, float durInPlace, float durFloatingUp, float durFadingOut, float baseAlpha); 449 450 WeaponAPI createFakeWeapon(ShipAPI ship, String weaponId); 451 452 ShipAPI getShipPlayerIsTransferringCommandFrom(); 453 454 ShipAPI getShipPlayerIsTransferringCommandTo(); 455 456 ShipAPI getShipPlayerLastTransferredCommandTo(); 457 458 ShipAPI createFXDrone(ShipVariantAPI variant); 459 460 void addEntity(CombatEntityAPI entity); 461 462 void addNebulaSmoothParticle(Vector2f loc, Vector2f vel, float size, float endSizeMult, float rampUpFraction, 463 float fullBrightnessFraction, float totalDuration, Color color); 464 465 void addNebulaSmoothParticle(Vector2f loc, Vector2f vel, float size, float endSizeMult, float rampUpFraction, 466 float fullBrightnessFraction, float totalDuration, Color color, boolean expandAsSqrt); 467 468 Color getBackgroundColor(); 469 void setBackgroundColor(Color backgroundColor); 470 boolean isBackgroundGlowColorNonAdditive(); 471 void setBackgroundGlowColorNonAdditive(boolean backgroundGlowColorNonAdditive); 472 void setBackgroundGlowColor(Color backgroundGlowColor); 473 Color getBackgroundGlowColor(); 474 boolean isRenderStarfield(); 475 void setRenderStarfield(boolean renderStarfield); 476 477 void setShipPlayerLastTransferredCommandTo(ShipAPI ship); 478 479 void spawnMuzzleFlashOrSmoke(ShipAPI ship, Vector2f point, WeaponSpecAPI spec, float targetAngle); 480 481 boolean isInMissionSim(); 482 483 boolean isShipAlive(ShipAPI ship); 484 485 void spawnDebrisSmall(Vector2f loc, Vector2f vel, int num, float facing, float spread, float minVel, float velRange, 486 float maxRotation); 487 void spawnDebrisMedium(Vector2f loc, Vector2f vel, int num, float facing, float spread, float minVel, 488 float velRange, float maxRotation); 489 void spawnDebrisLarge(Vector2f loc, Vector2f vel, int num, float facing, float spread, float minVel, float velRange, 490 float maxRotation); 491 492 void addFloatingDamageText(Vector2f loc, float damage, float spread, Color color, CombatEntityAPI to, 493 CombatEntityAPI source); 494 495 MissileAIPlugin createProximityFuseAI(MissileAPI missile); 496 String getBackgroundSpriteName(); 497 498 boolean isInEngine(ShipAPI ship); 499 500 boolean hasPluginOfClass(Class c); 501 502 void applyImpact(Vector2f vel, float impact, CombatEntityAPI target, Vector2f point); 503 504 void playShipExplosionSound(ShipAPI ship); 505 506 CombatEntityAPI spawnAsteroid(String spriteName, float x, float y, float dx, float dy, boolean fromRing); 507 508 //float getElapsedInCurrentFrame(); 509 510} 511 512 513 514 515 516