1package com.fs.starfarer.api.impl.campaign.procgen;
3import java.util.ArrayList;
4import java.util.Collections;
5import java.util.Comparator;
8import org.lwjgl.util.vector.Vector2f;
10import com.fs.starfarer.api.Global;
11import com.fs.starfarer.api.campaign.CampaignTerrainAPI;
12import com.fs.starfarer.api.campaign.CampaignTerrainPlugin;
13import com.fs.starfarer.api.campaign.JumpPointAPI;
14import com.fs.starfarer.api.campaign.PlanetAPI;
15import com.fs.starfarer.api.campaign.SectorEntityToken;
16import com.fs.starfarer.api.campaign.StarSystemAPI;
17import com.fs.starfarer.api.campaign.JumpPointAPI.JumpDestination;
18import com.fs.starfarer.api.impl.campaign.procgen.Constellation.ConstellationType;
19import com.fs.starfarer.api.impl.campaign.procgen.ProcgenUsedNames.NamePick;
20import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator.LagrangePointType;
21import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator.StarSystemType;
22import com.fs.starfarer.api.impl.campaign.terrain.AsteroidBeltTerrainPlugin;
23import com.fs.starfarer.api.impl.campaign.terrain.AsteroidFieldTerrainPlugin;
24import com.fs.starfarer.api.impl.campaign.terrain.MagneticFieldTerrainPlugin;
25import com.fs.starfarer.api.impl.campaign.terrain.NebulaTerrainPlugin;
26import com.fs.starfarer.api.impl.campaign.terrain.RingSystemTerrainPlugin;
27import com.fs.starfarer.api.util.Misc;
31 public static class NamingTreeNode {
32 public NamingTreeNode parent;
33 public LagrangePointType lagrangePointType =
null;
36 public List<NamingTreeNode> children =
new ArrayList<NamingTreeNode>();
42 public boolean isPrimaryStar() {
43 return entity == system.
getStar();
45 public boolean isSecondaryStar() {
48 public boolean isTertiaryStar() {
51 public boolean isMoon() {
52 return !isTerrain() && parent !=
null &&
56 public boolean isTerrain() {
62 private NamePick constellationName;
63 private NamingTreeNode root;
65 private float specialNamesProbability = 0.5f;
66 private boolean renameSystem =
true;
67 private int structuralNameOffset = 0;
70 this.constellation = constellation;
74 this.specialNamesProbability = specialNamesProbability;
78 this.renameSystem = renameStar;
82 this.structuralNameOffset = structuralNameOffset;
86 if (constellation.
getSystems().isEmpty())
return;
97 constellationName =
new NamePick(data, name, secondary);
106 Collections.sort(constellation.
getSystems(),
new Comparator<StarSystemAPI>() {
107 public int compare(StarSystemAPI o1, StarSystemAPI o2) {
108 if (o1.getStar() == null || o2.getStar() != null) return 1;
109 if (o1.getStar() != null || o2.getStar() == null) return -1;
110 return (int) Math.signum(o1.getStar().getRadius() - o2.getStar().getRadius());
116 String base = constellationName.nameWithRomanSuffixIfAny;
117 if (constellationName.secondaryWithRomanSuffixIfAny !=
null) {
118 base = constellationName.secondaryWithRomanSuffixIfAny;
139 if (curr.entity !=
null) {
140 if (curr.isTerrain()) {
157 }
else if (curr.isMoon()) {
159 }
else if (curr.isPrimaryStar() || curr.isSecondaryStar() || curr.isTertiaryStar()) {
161 }
else if (curr.entity instanceof
PlanetAPI) {
167 String parent =
null;
168 if (curr.parent !=
null && curr.parent.name !=
null) {
169 parent = curr.parent.name.spec.
getName();
172 parent = constellationName.spec.
getName();
176 boolean noRename = curr.system.
getStar() == curr.entity && !renameSystem;
191 curr.name =
new NamePick(data, name,
null);
194 String name = pick.nameWithRomanSuffixIfAny;
195 List<SectorEntityToken> all = constellation.
allEntitiesAdded.get(curr.entity);
202 entity.setName(name);
203 if (entity.getMarket() !=
null) entity.getMarket().setName(name);
204 updateJumpPointNameFor(entity);
209 if (curr.system.
getStar() == curr.entity) {
216 for (NamingTreeNode node : curr.children) {
217 assignSpecialNames(node);
229 if (system.
getStar() !=
null) {
231 updateJumpPointNameFor(system.
getStar());
237 int i = structuralNameOffset;
238 for (NamingTreeNode node : root.children) {
242 assignSNamesHelper(node, name, i);
254 if (parentName ==
null)
return;
256 String name = parentName;
258 if (curr.entity !=
null) {
265 boolean rename =
true;
266 if (curr.isSecondaryStar()) {
268 }
else if (curr.isTertiaryStar()) {
271 String [] moonPostfixes = {
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N"};
272 if (curr.isTerrain()) {
273 if (curr.lagrangePointType !=
null) {
274 name +=
" " + curr.lagrangePointType.name();
276 name +=
" Asteroid Field";
283 }
else if (curr.isMoon()) {
284 if (curr.lagrangePointType !=
null) {
285 name +=
"-" + curr.lagrangePointType.name();
287 name +=
"-" + moonPostfixes[index];
299 List<SectorEntityToken> all = constellation.
allEntitiesAdded.get(curr.entity);
301 entity.setName(name);
302 if (entity.getMarket() !=
null) entity.getMarket().setName(name);
303 updateJumpPointNameFor(entity);
312 for (NamingTreeNode node : curr.children) {
313 assignSNamesHelper(node, name, i);
325 if (!(entity instanceof
PlanetAPI))
return;
331 if (point.getDestinationVisualEntity() == entity) {
335 name = planet.
getName() +
" Gravity Well";
336 }
else if (planet.
isStar()) {
354 for (JumpDestination dest : point.getDestinations()) {
360 dest.setLabelInInteractionDialog(name);
369 root =
new NamingTreeNode(system);
370 if (system.
getStar() !=
null && system.
getType() != StarSystemType.NEBULA) {
371 root.entity = system.
getStar();
375 if (!planet.isStar())
continue;
376 if (planet == system.
getStar())
continue;
379 NamingTreeNode node =
new NamingTreeNode(system);
380 node.entity = planet;
382 root.children.add(node);
385 addChildren(system, root);
386 for (NamingTreeNode node : root.children) {
387 addChildren(system, node);
393 if (planet.isStar())
continue;
394 if (planet == curr.entity)
continue;
396 for (NamingTreeNode n : curr.children) {
397 if (n.entity == planet)
continue OUTER;
401 boolean mainStarAndOrbitingSystemCenter = curr.entity == curr.system.
getStar() &&
403 lagrangeParent ==
null;
405 if (mainStarAndOrbitingSystemCenter ||
406 (planet.getOrbitFocus() == curr.entity && lagrangeParent ==
null) ||
407 lagrangeParent == curr.entity) {
408 NamingTreeNode node =
new NamingTreeNode(system);
409 node.entity = planet;
411 curr.children.add(node);
413 if (lagrangeParent !=
null && planet.
getOrbitFocus() !=
null) {
416 float angle2 = planet.getCircularOrbitAngle();
419 node.lagrangePointType = LagrangePointType.L4;
421 node.lagrangePointType = LagrangePointType.L5;
425 addChildren(system, node);
430 if (terrain == curr.entity)
continue;
432 for (NamingTreeNode n : curr.children) {
433 if (n.entity == terrain)
continue OUTER;
437 boolean mainStarAndOrbitingSystemCenter = curr.entity == curr.system.
getStar() &&
439 lagrangeParent ==
null;
440 if (mainStarAndOrbitingSystemCenter ||
441 (terrain.getOrbitFocus() == curr.entity && lagrangeParent ==
null) ||
442 lagrangeParent == curr.entity) {
443 NamingTreeNode node =
new NamingTreeNode(system);
444 node.entity = terrain;
446 curr.children.add(node);
448 if (lagrangeParent !=
null && terrain.
getOrbitFocus() !=
null) {
451 float angle2 = terrain.getCircularOrbitAngle();
454 node.lagrangePointType = LagrangePointType.L4;
456 node.lagrangePointType = LagrangePointType.L5;
460 addChildren(system, node);
464 Collections.sort(curr.children,
new Comparator<NamingTreeNode>() {
465 public int compare(NamingTreeNode o1, NamingTreeNode o2) {
466 Vector2f from = new Vector2f();
467 if (o1.parent != null && o1.parent.entity != null) {
468 from = o1.parent.entity.getLocation();
469 if (o1.parent == o1.system.getStar()) {
470 from = o1.system.getCenter().getLocation();
473 float d1 = Misc.getDistance(from, o1.entity.getLocation());
474 float d2 = Misc.getDistance(from, o2.entity.getLocation());
475 return (int) Math.signum(d1 - d2);
488 String base = constellationName.nameWithRomanSuffixIfAny;
489 if (constellationName.secondaryWithRomanSuffixIfAny !=
null) {
490 base = constellationName.secondaryWithRomanSuffixIfAny;
492 if (name.toLowerCase().contains(base.toLowerCase())) {
501 if (actual ==
null || actual.
getNamePick() ==
null)
return;
static SettingsAPI getSettings()
transient Map< SectorEntityToken, List< SectorEntityToken > > allEntitiesAdded
Map< SectorEntityToken, PlanetAPI > getLagrangeParentMap()
List< StarSystemAPI > getSystems()
void setAllEntitiesAdded(Map< SectorEntityToken, List< SectorEntityToken > > allEntitiesAdded)
Map< SectorEntityToken, List< SectorEntityToken > > getAllEntitiesAdded()
boolean isLeavePickedNameUnused()
List< StarSystemAPI > systems
void setLagrangeParentMap(Map< SectorEntityToken, PlanetAPI > lagrangeParentMap)
void setNamePick(NamePick namePick)
void setLeavePickedNameUnused(boolean leavePickedNameUnused)
transient Map< SectorEntityToken, PlanetAPI > lagrangeParentMap
void updateJumpPointDestinationNames(StarSystemAPI system)
void computeNamingTree(StarSystemAPI system)
void setSpecialNamesProbability(float specialNamesProbability)
void assignNames(String name, String secondary)
static boolean isNameSpecial(StarSystemAPI system)
void assignSpecialNames(NamingTreeNode curr)
void assignStructuralNames(StarSystemAPI system, String name)
void addChildren(StarSystemAPI system, NamingTreeNode curr)
static void assignSpecialNames(StarSystemAPI system)
void assignSNamesHelper(NamingTreeNode curr, String parentName, int index)
void updateJumpPointNameFor(SectorEntityToken entity)
NameAssigner(Constellation constellation)
void setStructuralNameOffset(int structuralNameOffset)
void setRenameSystem(boolean renameStar)
static final String TAG_PLANET
static final String TAG_ASTEROID_FIELD
static final String TAG_MAGNETIC_FIELD
static final String TAG_STAR
static final String TAG_ASTEROID_BELT
static final String TAG_ACCRETION
static final String TAG_CONSTELLATION
static final String TAG_MOON
static final String TAG_NEBULA
static NamePick pickName(String tag, String parent, LagrangePointType lagrangePoint)
static void notifyUsed(String name)
String getNameForTooltip()
static float getClosestTurnDirection(float facing, float desired)
Object getSpec(Class c, String id, boolean nullOnNotFound)
String getNextGreekLetter(Object context)
CampaignTerrainPlugin getPlugin()
List< PlanetAPI > getPlanets()
String getNameWithLowercaseType()
List< CampaignTerrainAPI > getTerrainCopy()
LocationAPI getContainingLocation()
float getCircularOrbitAngle()
void setName(String name)
SectorEntityToken getOrbitFocus()
void setBaseName(String baseName)
List< JumpPointAPI > getAutogeneratedJumpPointsInHyper()
SectorEntityToken getCenter()
Constellation getConstellation()