Starsector API
Loading...
Searching...
No Matches
CoreBuildObjectiveTypePicker.java
Go to the documentation of this file.
1package com.fs.starfarer.api.plugins.impl;
2
3import com.fs.starfarer.api.campaign.CampaignFleetAPI;
4import com.fs.starfarer.api.campaign.FactionAPI;
5import com.fs.starfarer.api.campaign.SectorEntityToken;
6import com.fs.starfarer.api.campaign.GenericPluginManagerAPI.GenericPlugin;
7import com.fs.starfarer.api.impl.campaign.ids.Entities;
8import com.fs.starfarer.api.impl.campaign.ids.Factions;
9import com.fs.starfarer.api.impl.campaign.ids.Tags;
10import com.fs.starfarer.api.plugins.BuildObjectiveTypePicker;
11
12public class CoreBuildObjectiveTypePicker implements BuildObjectiveTypePicker, GenericPlugin {
13
14 public String pickObjectiveToBuild(BuildObjectiveParams params) {
15 CampaignFleetAPI fleet = params.fleet;
16 FactionAPI faction = params.faction;
17 SectorEntityToken stableLoc = params.stableLoc;
18
19 boolean hasComm = false;
20 boolean hasSensor = false;
21 boolean hasNav = false;
22 for (SectorEntityToken curr : stableLoc.getContainingLocation().getEntitiesWithTag(Tags.OBJECTIVE)) {
23 // don't own this, and not hostile, so won't be retaking either - ok to build duplicate
24 if (curr.getFaction() != faction && !curr.getFaction().isHostileTo(faction)) {
25 continue;
26 }
27 hasComm |= curr.hasTag(Tags.COMM_RELAY);
28 hasSensor |= curr.hasTag(Tags.SENSOR_ARRAY);
29 hasNav |= curr.hasTag(Tags.NAV_BUOY);
30 }
31
32 if (faction.getCustomBoolean(Factions.CUSTOM_PIRATE_BEHAVIOR)) {
33 if (!hasSensor && !hasNav) {
34 if ((float) Math.random() > 0.5f) {
35 return Entities.NAV_BUOY_MAKESHIFT;
36 }
37 return Entities.SENSOR_ARRAY_MAKESHIFT;
38 }
39 if (!hasSensor) {
40 return Entities.SENSOR_ARRAY_MAKESHIFT;
41 }
42 if (!hasNav) {
43 return Entities.NAV_BUOY_MAKESHIFT;
44 }
45 if (!hasComm) {
46 return Entities.COMM_RELAY_MAKESHIFT;
47 }
48 } else {
49 if (!hasComm) {
50 return Entities.COMM_RELAY_MAKESHIFT;
51 }
52 if (!hasNav) {
53 return Entities.NAV_BUOY_MAKESHIFT;
54 }
55 if (!hasSensor) {
56 return Entities.SENSOR_ARRAY_MAKESHIFT;
57 }
58 }
59 return null;
60 }
61
62
63
64 public int getHandlingPriority(Object params) {
65 if (params instanceof BuildObjectiveParams) {
66 return 0;
67 }
68 return -1;
69 }
70
71}