Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/net/tfminecraft/simplefactions/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public static boolean requireProvinces(org.bukkit.command.CommandSender sender)
public static double supplyHubMaxFee = 500.0;
public static int supplyHubOfferDays = 7;
public static int supplyHubAgreementDays = 14;
public static int supplyHubEstimateCandidates = 24;

public static double infrastructureFull = 20;
public static double infrastructureTarget = 0.75;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public static void loadConfig(FileConfiguration config) {
Cache.supplyHubOfferDays = Math.max(1, offerDays);
int agreementDays = config == null ? 14 : config.getInt("supply-hubs.agreement-days", 14);
Cache.supplyHubAgreementDays = Math.max(1, agreementDays);
int candidates = config == null ? 24 : config.getInt("supply-hubs.estimate-candidates", 24);
Cache.supplyHubEstimateCandidates = Math.max(1, candidates);
}

public static int limit(Guild guild) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public static Map<Guild, Double> tax(Faction faction, TaxTarget target, String i
}
}

/** Net income of every guild after recalculating this snapshot. Writes the live trade breakdowns. */
public static Map<Guild, Double> projectNets(ProvinceManager snapshot) {
return project(snapshot, IncomePreviewContext.scratch(), false);
}

private static Map<Guild, Double> project(
ProvinceManager snapshot, IncomePreviewContext context, boolean capitalsOnly) {
IncomePreviewContext.open(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ public void time() {
runDailyStep("hub agreements", () ->
net.tfminecraft.simplefactions.guild.hub.HubAgreementService.tick(
getAllGuilds(), System.currentTimeMillis()));
runDailyStep("hub estimates", () ->
net.tfminecraft.simplefactions.guild.hub.HubEstimates.scheduleDaily());
timer = 0;
day++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
public class ProvinceManager {
private Map<Integer, Province> provinces = new HashMap<>();
private Map<String, List<Link>> hubLinksOverride;
private boolean infrastructureSuppressed;
private Map<Integer, Double> extraInfrastructure;
private long stateVersion = 0;
private long lastCalculatedVersion = -1;

Expand Down Expand Up @@ -84,6 +86,19 @@ public void setHubLinksOverride(Map<String, List<Link>> links) {
hubLinksOverride = links;
}

/** Snapshot-only. The next recalculation writes 0 infrastructure on every province. */
public void setInfrastructureSuppressed(boolean suppressed) {
infrastructureSuppressed = suppressed;
}

/**
* Snapshot-only source added before the spread. Sea and water provinces are ignored.
* A null or empty map adds nothing. Copies do not inherit this.
*/
public void setExtraInfrastructure(Map<Integer, Double> extra) {
extraInfrastructure = extra == null || extra.isEmpty() ? null : Map.copyOf(extra);
}

private List<Link> hubLinksFor(Guild guild) {
if (hubLinksOverride != null && hubLinksOverride.containsKey(guild.getId())) {
return hubLinksOverride.get(guild.getId());
Expand Down Expand Up @@ -144,6 +159,12 @@ public void recalculateForSingleGuild(Guild g, boolean save) {
}

private void recalculateInfrastructure() {
if (infrastructureSuppressed) {
for (Province province : provinces.values()) {
province.setInfrastructure(0);
}
return;
}
Map<Integer, InfrastructureSpread.Node> graph = new HashMap<>();
for (Province province : provinces.values()) {
Faction realm = InfrastructureAccess.topRealm(province.getOwner());
Expand All @@ -154,6 +175,15 @@ private void recalculateInfrastructure() {
Map<Integer, Double> sources = InfrastructureSources.collect(
provinces, FactionManager.getAllGuilds(), FactionManager.getCopy(),
net.tfminecraft.simplefactions.map.infra.TrackProvinceCache.live().provinces());
if (extraInfrastructure != null) {
for (Map.Entry<Integer, Double> extra : extraInfrastructure.entrySet()) {
Province province = provinces.get(extra.getKey());
if (province == null || province.isSea() || extra.getValue() == null || extra.getValue() <= 0) {
continue;
}
sources.merge(extra.getKey(), extra.getValue(), Double::sum);
}
}
Map<Integer, InfrastructureSpread.Arrival> infrastructure = InfrastructureSpread.spread(
graph, sources, Cache.infrastructureWildernessSpread, Cache.infrastructureSpreadFloor);
for (Province province : provinces.values()) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ supply-hubs:
offer-days: 7
# Days a hub agreement runs.
agreement-days: 14
# How many ready installations, and how many provinces worth building, are fully
# estimated per guild each day. The closest ones are kept.
estimate-candidates: 24
# A hub takes the guild's trade power and production in its province and delivers a share
# to each of the guild's hubs it is connected to. Train track joins any two kinds; ports
# also connect across the sea, and airports through the air.
Expand Down
Loading
Loading