001package com.fs.starfarer.api.impl.campaign.procgen; 002 003import java.util.ArrayList; 004import java.util.HashMap; 005import java.util.List; 006import java.util.Map; 007 008import org.lwjgl.util.vector.Vector2f; 009 010import com.fs.starfarer.api.campaign.PlanetAPI; 011import com.fs.starfarer.api.campaign.SectorEntityToken; 012import com.fs.starfarer.api.campaign.StarSystemAPI; 013import com.fs.starfarer.api.impl.campaign.procgen.ProcgenUsedNames.NamePick; 014 015public class Constellation { 016 017 public static enum ConstellationType { 018 NORMAL, 019 NEBULA, 020 } 021 protected StarAge age; 022 protected transient Map<SectorEntityToken, PlanetAPI> lagrangeParentMap = new HashMap<SectorEntityToken, PlanetAPI>(); 023 protected transient Map<SectorEntityToken, List<SectorEntityToken>> allEntitiesAdded = new HashMap<SectorEntityToken, List<SectorEntityToken>>(); 024 protected NamePick namePick; 025 protected List<StarSystemAPI> systems = new ArrayList<StarSystemAPI>(); 026 protected ConstellationType type = ConstellationType.NORMAL; 027 protected String nameOverride = null; 028 029 protected transient boolean leavePickedNameUnused = false; 030 031 public Constellation(ConstellationType type, StarAge age) { 032 this.type = type; 033 this.age = age; 034 } 035 036 public boolean isLeavePickedNameUnused() { 037 return leavePickedNameUnused; 038 } 039 040 public void setLeavePickedNameUnused(boolean leavePickedNameUnused) { 041 this.leavePickedNameUnused = leavePickedNameUnused; 042 } 043 044 public StarAge getAge() { 045 return age; 046 } 047 048 public void setAge(StarAge age) { 049 this.age = age; 050 } 051 052 public Vector2f getLocation() { 053 Vector2f loc = new Vector2f(); 054 if (systems.isEmpty()) return loc; 055 056 for (StarSystemAPI system : systems) { 057 Vector2f.add(loc, system.getLocation(), loc); 058 } 059 060 loc.scale(1f / (float) systems.size()); 061 return loc; 062 } 063 064 public ConstellationType getType() { 065 return type; 066 } 067 068 public void setType(ConstellationType type) { 069 this.type = type; 070 } 071 072 public String getNameOverride() { 073 return nameOverride; 074 } 075 076 public void setNameOverride(String nameOverride) { 077 this.nameOverride = nameOverride; 078 } 079 080 public String getName() { 081 if (nameOverride != null) return nameOverride; 082 return namePick.nameWithRomanSuffixIfAny; 083 } 084 085 public String getNameWithType() { 086 if (nameOverride != null) return nameOverride; 087 String constellationText = getName() + " Constellation"; 088 if (getType() == ConstellationType.NEBULA) { 089 constellationText = getName() + " Nebula"; 090 } 091 return constellationText; 092 } 093 094 public String getNameWithLowercaseType() { 095 if (nameOverride != null) return nameOverride; 096 String name = getNameWithType(); 097 name = name.replaceAll("Constellation", "constellation"); 098 name = name.replaceAll("Nebula", "nebula"); 099 return name; 100 } 101 102 public NamePick getNamePick() { 103 return namePick; 104 } 105 public void setNamePick(NamePick namePick) { 106 this.namePick = namePick; 107 } 108 public List<StarSystemAPI> getSystems() { 109 return systems; 110 } 111 112 public Map<SectorEntityToken, PlanetAPI> getLagrangeParentMap() { 113 return lagrangeParentMap; 114 } 115 116 public void setLagrangeParentMap(Map<SectorEntityToken, PlanetAPI> lagrangeParentMap) { 117 this.lagrangeParentMap = lagrangeParentMap; 118 } 119 120 public Map<SectorEntityToken, List<SectorEntityToken>> getAllEntitiesAdded() { 121 return allEntitiesAdded; 122 } 123 124 public void setAllEntitiesAdded( 125 Map<SectorEntityToken, List<SectorEntityToken>> allEntitiesAdded) { 126 this.allEntitiesAdded = allEntitiesAdded; 127 } 128 129 public StarSystemAPI getSystemWithMostPlanets() { 130 int most = -1; 131 StarSystemAPI result = null; 132 for (StarSystemAPI curr : systems) { 133 int count = curr.getPlanets().size(); 134 if (count > most) { 135 most = count; 136 result = curr; 137 } 138 } 139 return result; 140 } 141} 142 143 144 145