001package com.fs.starfarer.api.impl.campaign.enc; 002 003import org.lwjgl.util.vector.Vector2f; 004 005import com.fs.starfarer.api.Global; 006import com.fs.starfarer.api.campaign.StarSystemAPI; 007import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin; 008import com.fs.starfarer.api.impl.campaign.ids.Tags; 009import com.fs.starfarer.api.impl.campaign.intel.bases.LuddicPathBaseIntel; 010import com.fs.starfarer.api.impl.campaign.intel.bases.PirateBaseIntel; 011import com.fs.starfarer.api.util.Misc; 012 013public class BaseEPEncounterCreator implements EPEncounterCreator { 014 public static float PATHER_AMBUSH_RANGE_FOR_FULL_PROXIMITY_FACTOR = 4000f; 015 public static float PATHER_AMBUSH_MAX_RANGE = 16000f; 016 017 public static float PIRATE_AMBUSH_RANGE_FOR_FULL_PROXIMITY_FACTOR = 4000f; 018 public static float PIRATE_AMBUSH_MAX_RANGE = 16000f; 019 020 public static float RUINS_RANGE_FOR_FULL_PROXIMITY_FACTOR = 4000f; 021 public static float RUINS_MAX_RANGE = 16000f; 022 023 public static float CORE_PROXIMITY_MAX_RANGE = 30000f; 024 025 026 public String getId() { 027 return getClass().getSimpleName(); 028 } 029 030 public float getPointTimeoutMin() { 031 return 30f; 032 } 033 public float getPointTimeoutMax() { 034 return 90f; 035 } 036 037 public float getCreatorTimeoutMin() { 038 return 0; 039 } 040 041 public float getCreatorTimeoutMax() { 042 return 0; 043 } 044 045 public float getFrequencyForPoint(EncounterManager manager, EncounterPoint point) { 046 return 10f; 047 } 048 049 public void createEncounter(EncounterManager manager, EncounterPoint point) { 050 } 051 052 053 054 public static float getLuddicPathBaseProximityFactor(LuddicPathBaseIntel base, Vector2f locInHyper) { 055 if (base == null) return 0f; 056 float dist = Misc.getDistance(base.getEntity().getLocationInHyperspace(), locInHyper); 057 if (dist < PATHER_AMBUSH_RANGE_FOR_FULL_PROXIMITY_FACTOR) { 058 return 1f; 059 } 060 float f = 1f - (dist - PATHER_AMBUSH_RANGE_FOR_FULL_PROXIMITY_FACTOR) / (PATHER_AMBUSH_MAX_RANGE - PATHER_AMBUSH_RANGE_FOR_FULL_PROXIMITY_FACTOR); 061 if (f < 0f) f = 0f; 062 if (f > 1f) f = 1f; 063 return f; 064 065 } 066 public static LuddicPathBaseIntel getClosestLuddicPathBase(Vector2f locInHyper) { 067 return getClosestLuddicPathBase(locInHyper, true); 068 } 069 public static LuddicPathBaseIntel getClosestLuddicPathBase(Vector2f locInHyper, boolean onlyInProximity) { 070 LuddicPathBaseIntel closest = null; 071 float minDist = Float.MAX_VALUE; 072 for (IntelInfoPlugin p : Global.getSector().getIntelManager().getIntel(LuddicPathBaseIntel.class)) { 073 LuddicPathBaseIntel intel = (LuddicPathBaseIntel) p; 074 if (intel.getEntity() == null || !intel.getEntity().isAlive()) continue; 075 float dist = Misc.getDistance(intel.getEntity().getLocationInHyperspace(), locInHyper); 076 if (onlyInProximity && dist > PATHER_AMBUSH_MAX_RANGE) continue; 077 if (dist < minDist) { 078 minDist = dist; 079 closest = intel; 080 } 081 } 082 return closest; 083 } 084 085 public static float getPirateBaseProximityFactor(PirateBaseIntel base, Vector2f locInHyper) { 086 if (base == null) return 0f; 087 float dist = Misc.getDistance(base.getEntity().getLocationInHyperspace(), locInHyper); 088 if (dist < PIRATE_AMBUSH_RANGE_FOR_FULL_PROXIMITY_FACTOR) { 089 return 1f; 090 } 091 float f = 1f - (dist - PIRATE_AMBUSH_RANGE_FOR_FULL_PROXIMITY_FACTOR) / (PIRATE_AMBUSH_MAX_RANGE - PIRATE_AMBUSH_RANGE_FOR_FULL_PROXIMITY_FACTOR); 092 if (f < 0f) f = 0f; 093 if (f > 1f) f = 1f; 094 return f; 095 096 } 097 public static PirateBaseIntel getClosestPirateBase(Vector2f locInHyper) { 098 return getClosestPirateBase(locInHyper, true); 099 } 100 public static PirateBaseIntel getClosestPirateBase(Vector2f locInHyper, boolean onlyInProximity) { 101 PirateBaseIntel closest = null; 102 float minDist = Float.MAX_VALUE; 103 for (IntelInfoPlugin p : Global.getSector().getIntelManager().getIntel(PirateBaseIntel.class)) { 104 PirateBaseIntel intel = (PirateBaseIntel) p; 105 if (intel.getEntity() == null || !intel.getEntity().isAlive()) continue; 106 float dist = Misc.getDistance(intel.getEntity().getLocationInHyperspace(), locInHyper); 107 if (onlyInProximity && dist > PIRATE_AMBUSH_MAX_RANGE) continue; 108 if (dist < minDist) { 109 minDist = dist; 110 closest = intel; 111 } 112 } 113 return closest; 114 } 115 116 117 public static float getCoreProximityFactor(Vector2f locInHyper) { 118 Vector2f min = Misc.getCoreMin(); 119 Vector2f max = Misc.getCoreMax(); 120 Vector2f core = Misc.getCoreCenter(); 121 122 float across = Misc.getDistance(min, max); 123 float fullProximityAt = across * 0.5f; 124 fullProximityAt = Math.min(CORE_PROXIMITY_MAX_RANGE / 2f, fullProximityAt); 125 126 float dist = Misc.getDistance(core, locInHyper); 127 if (dist < fullProximityAt) { 128 return 1f; 129 } 130 float f = 1f - (dist - fullProximityAt) / (CORE_PROXIMITY_MAX_RANGE - fullProximityAt); 131 if (f < 0f) f = 0f; 132 if (f > 1f) f = 1f; 133 return f; 134 } 135 136 public static float getRuinsProximityFactor(StarSystemAPI system, Vector2f locInHyper) { 137 if (system == null) return 0f; 138 float dist = Misc.getDistance(system.getLocation(), locInHyper); 139 if (dist < RUINS_RANGE_FOR_FULL_PROXIMITY_FACTOR) { 140 return 1f; 141 } 142 float f = 1f - (dist - RUINS_RANGE_FOR_FULL_PROXIMITY_FACTOR) / (RUINS_MAX_RANGE - RUINS_RANGE_FOR_FULL_PROXIMITY_FACTOR); 143 if (f < 0f) f = 0f; 144 if (f > 1f) f = 1f; 145 return f; 146 } 147 148 149 public static StarSystemAPI getClosestSystemWithRuins(Vector2f locInHyper) { 150 return getClosestSystemWithRuins(locInHyper, true); 151 } 152 public static StarSystemAPI getClosestSystemWithRuins(Vector2f locInHyper, boolean onlyInProximity) { 153 StarSystemAPI closest = null; 154 float minDist = Float.MAX_VALUE; 155 for (StarSystemAPI curr : Global.getSector().getStarSystems()) { 156 if (curr.hasTag(Tags.THEME_RUINS_MAIN)) { 157 float dist = Misc.getDistance(curr.getLocation(), locInHyper); 158 if (onlyInProximity && dist > RUINS_MAX_RANGE) continue; 159 if (dist < minDist) { 160 minDist = dist; 161 closest = curr; 162 } 163 } 164 } 165 return closest; 166 } 167}