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;
35 public SectorEntityToken entity;
36 public List<NamingTreeNode> children =
new ArrayList<NamingTreeNode>();
37 public StarSystemAPI system;
38 public NamingTreeNode(StarSystemAPI system) {
42 public boolean isPrimaryStar() {
43 return entity == system.getStar();
45 public boolean isSecondaryStar() {
46 return entity == system.getSecondary();
48 public boolean isTertiaryStar() {
49 return entity == system.getTertiary();
51 public boolean isMoon() {
52 return !isTerrain() && parent !=
null &&
53 parent.entity instanceof PlanetAPI &&
54 !((PlanetAPI)parent.entity).isStar();
56 public boolean isTerrain() {
57 return entity instanceof CampaignTerrainAPI;
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());
115 for (StarSystemAPI system : constellation.getSystems()) {
116 String base = constellationName.nameWithRomanSuffixIfAny;
117 if (constellationName.secondaryWithRomanSuffixIfAny !=
null) {
118 base = constellationName.secondaryWithRomanSuffixIfAny;
124 if (StarSystemGenerator.random.nextFloat() < specialNamesProbability || (constellation.
systems.size() <= 1 && specialNamesProbability > 0)) {
138 CampaignTerrainPlugin plugin =
null;
139 if (curr.entity !=
null) {
140 if (curr.isTerrain()) {
141 CampaignTerrainAPI terrain = (CampaignTerrainAPI) curr.entity;
142 plugin = terrain.getPlugin();
143 if (plugin instanceof AsteroidFieldTerrainPlugin) {
145 }
else if (plugin instanceof AsteroidBeltTerrainPlugin) {
147 }
else if (plugin instanceof RingSystemTerrainPlugin) {
148 RingSystemTerrainPlugin ringPlugin = (RingSystemTerrainPlugin) plugin;
149 if (ringPlugin.getNameForTooltip() !=
null && ringPlugin.getNameForTooltip().contains(
"Accretion")) {
152 }
else if (plugin instanceof NebulaTerrainPlugin) {
154 }
else if (plugin instanceof MagneticFieldTerrainPlugin) {
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;
178 if (!pick.spec.isReusable() && !noRename) {
184 String name = curr.system.getBaseName();
191 curr.name =
new NamePick(data, name,
null);
194 String name = pick.nameWithRomanSuffixIfAny;
195 List<SectorEntityToken> all = constellation.
allEntitiesAdded.get(curr.entity);
196 for (SectorEntityToken entity : all) {
202 entity.setName(name);
203 if (entity.getMarket() !=
null) entity.getMarket().setName(name);
204 updateJumpPointNameFor(entity);
205 if (entity instanceof CampaignTerrainAPI) {
206 ((CampaignTerrainAPI) entity).getPlugin().setTerrainName(name);
209 if (curr.system.getStar() == curr.entity) {
210 curr.system.setBaseName(name);
216 for (NamingTreeNode node : curr.children) {
217 assignSpecialNames(node);
228 system.setBaseName(name);
229 if (system.getStar() !=
null) {
230 system.getStar().setName(name);
231 updateJumpPointNameFor(system.getStar());
234 name = system.getBaseName();
237 int i = structuralNameOffset;
238 for (NamingTreeNode node : root.children) {
242 assignSNamesHelper(node, name, i);
244 if (node.entity instanceof PlanetAPI) {
245 PlanetAPI planet = (PlanetAPI) node.entity;
246 if (!planet.isStar()) {
254 if (parentName ==
null)
return;
256 String name = parentName;
258 if (curr.entity !=
null) {
259 CampaignTerrainAPI terrain =
null;
260 CampaignTerrainPlugin plugin =
null;
261 if (curr.entity instanceof CampaignTerrainAPI) {
262 terrain = (CampaignTerrainAPI) curr.entity;
263 plugin = terrain.getPlugin();
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();
275 if (plugin instanceof AsteroidFieldTerrainPlugin) {
276 name +=
" Asteroid Field";
277 }
else if (plugin instanceof NebulaTerrainPlugin) {
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);
300 for (SectorEntityToken entity : all) {
301 entity.setName(name);
302 if (entity.getMarket() !=
null) entity.getMarket().setName(name);
303 updateJumpPointNameFor(entity);
304 if (entity instanceof CampaignTerrainAPI) {
305 ((CampaignTerrainAPI) entity).getPlugin().setTerrainName(name);
312 for (NamingTreeNode node : curr.children) {
313 assignSNamesHelper(node, name, i);
315 if (node.entity instanceof PlanetAPI) {
316 PlanetAPI planet = (PlanetAPI) node.entity;
317 if (!planet.isStar()) {
325 if (!(entity instanceof PlanetAPI))
return;
326 if (!(entity.getContainingLocation() instanceof StarSystemAPI))
return;
328 StarSystemAPI system = (StarSystemAPI) entity.getContainingLocation();
330 for (JumpPointAPI point : system.getAutogeneratedJumpPointsInHyper()) {
331 if (point.getDestinationVisualEntity() == entity) {
332 PlanetAPI planet = (PlanetAPI) entity;
334 if (planet.isGasGiant()) {
335 name = planet.getName() +
" Gravity Well";
336 }
else if (planet.isStar()) {
337 name = planet.getName() +
", " + planet.getSpec().getName();
353 for (JumpPointAPI point : system.getAutogeneratedJumpPointsInHyper()) {
354 for (JumpDestination dest : point.getDestinations()) {
359 String name =
"the " + system.getNameWithLowercaseType();
360 dest.setLabelInInteractionDialog(name);
369 root =
new NamingTreeNode(system);
370 if (system.getStar() !=
null && system.getType() != StarSystemType.NEBULA) {
371 root.entity = system.getStar();
374 for (PlanetAPI planet : system.getPlanets()) {
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);
391 public void addChildren(StarSystemAPI system, NamingTreeNode curr) {
392 OUTER:
for (PlanetAPI planet : system.getPlanets()) {
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() &&
402 planet.getOrbitFocus() == curr.system.getCenter() &&
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) {
415 float angle1 = lagrangeParent.getCircularOrbitAngle();
416 float angle2 = planet.getCircularOrbitAngle();
418 if (Misc.getClosestTurnDirection(angle1, angle2) < 0) {
419 node.lagrangePointType = LagrangePointType.L4;
421 node.lagrangePointType = LagrangePointType.L5;
425 addChildren(system, node);
429 OUTER:
for (CampaignTerrainAPI terrain : system.getTerrainCopy()) {
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() &&
438 terrain.getOrbitFocus() == curr.system.getCenter() &&
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) {
450 float angle1 = lagrangeParent.getCircularOrbitAngle();
451 float angle2 = terrain.getCircularOrbitAngle();
453 if (Misc.getClosestTurnDirection(angle1, angle2) < 0) {
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);
483 if (system.getConstellation() ==
null)
return true;
485 String name = system.getBaseName();
487 NamePick constellationName = system.getConstellation().getNamePick();
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)
Object getSpec(Class c, String id, boolean nullOnNotFound)
String getNextGreekLetter(Object context)