Skip to content

Commit c412b86

Browse files
Drefvelinryanbarlow97claude
authored
Name the trade networks and add a viewer (#123)
* Name the trade networks and add a viewer Each network gets a name: the map's for the global one, otherwise the guild with the most trade at its stops. /guild networks and a button on the Supply Hubs screen list the networks with their stops, hubs and member shares. The map export gains trade_networks and trade_edges. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Ignore case when a guild name already starts with The Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Ryan <7389646+ryanbarlow97@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 539e702 commit c412b86

13 files changed

Lines changed: 1193 additions & 7 deletions

File tree

‎src/main/java/net/tfminecraft/simplefactions/enums/SFGUI.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public enum SFGUI {
8181
HUB_PROPOSAL_LIST,
8282
HUB_NEGOTIATION,
8383
HUB_OFFER_LIST,
84+
TRADE_NETWORK_LIST,
85+
TRADE_NETWORK_NODES,
8486
PLAYER_LEDGER_VIEW,
8587
COMPANY_VIEW,
8688
COMPANY_SLOTS_VIEW,

‎src/main/java/net/tfminecraft/simplefactions/guild/hub/SupplyHubCommands.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.tfminecraft.simplefactions.installation.Installation;
1717
import net.tfminecraft.simplefactions.loaders.InstallationConfigLoader;
1818
import net.tfminecraft.simplefactions.managers.FactionManager;
19+
import net.tfminecraft.simplefactions.managers.inventory.NetworkViewer;
1920
import net.tfminecraft.simplefactions.managers.RelationManager;
2021
import net.tfminecraft.simplefactions.map.provinces.Province;
2122
import net.tfminecraft.simplefactions.objects.Faction;
@@ -37,6 +38,19 @@ public static boolean guild(Player player, String[] args) {
3738
return true;
3839
}
3940

41+
/** Opens the trade network list for the player's guild. */
42+
public static boolean networks(Player player) {
43+
if (player == null) return true;
44+
if (!Cache.requireProvinces(player)) return true;
45+
Guild guild = FactionManager.getGuildByMember(player.getName());
46+
if (guild == null) {
47+
player.sendMessage("§cYou are not in a guild");
48+
return true;
49+
}
50+
NetworkViewer.open(player, guild, 0);
51+
return true;
52+
}
53+
4054
public static void notifyRemoved(Guild guild, List<SupplyHub> removed) {
4155
if (guild == null || removed == null || removed.isEmpty()) {
4256
return;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package net.tfminecraft.simplefactions.guild.network;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
import java.util.Map;
7+
import java.util.Set;
8+
9+
import net.tfminecraft.simplefactions.Cache;
10+
import net.tfminecraft.simplefactions.SimpleFactions;
11+
import net.tfminecraft.simplefactions.guild.Guild;
12+
import net.tfminecraft.simplefactions.guild.hub.Highway.HubSite;
13+
import net.tfminecraft.simplefactions.guild.hub.HighwaySnapshot;
14+
import net.tfminecraft.simplefactions.guild.hub.SupplyHubService;
15+
import net.tfminecraft.simplefactions.guild.network.NetworkSummary.GuildLabel;
16+
import net.tfminecraft.simplefactions.guild.network.NetworkSummary.Summary;
17+
import net.tfminecraft.simplefactions.managers.FactionManager;
18+
import net.tfminecraft.simplefactions.map.provinces.Province;
19+
import net.tfminecraft.simplefactions.objects.Faction;
20+
21+
/** Reads the current snapshot into {@link NetworkSummary}. Does not recalculate trade. */
22+
public final class CurrentNetworks {
23+
private CurrentNetworks() { }
24+
25+
public static List<Summary> now() {
26+
return from(HighwaySnapshot.current());
27+
}
28+
29+
public static List<Summary> from(HighwaySnapshot snapshot) {
30+
HighwaySnapshot source = snapshot == null ? HighwaySnapshot.current() : snapshot;
31+
return NetworkSummary.summarize(
32+
source.graph(),
33+
hubs(source),
34+
guilds(),
35+
factions(),
36+
Cache.chapterName,
37+
CurrentNetworks::trade);
38+
}
39+
40+
private static Map<String, Set<HubSite>> hubs(HighwaySnapshot snapshot) {
41+
Map<String, Set<HubSite>> hubbed = new HashMap<>();
42+
for (Guild guild : SupplyHubService.allGuilds()) {
43+
if (guild == null || guild.getId() == null) continue;
44+
Set<HubSite> sites = snapshot.hubbed(guild.getId());
45+
if (sites.isEmpty()) continue;
46+
hubbed.put(guild.getId(), sites);
47+
}
48+
return hubbed;
49+
}
50+
51+
private static List<GuildLabel> guilds() {
52+
List<GuildLabel> labels = new ArrayList<>();
53+
for (Guild guild : SupplyHubService.allGuilds()) {
54+
if (guild == null || guild.getId() == null) continue;
55+
labels.add(new GuildLabel(guild.getId(), guild.getName()));
56+
}
57+
return labels;
58+
}
59+
60+
private static Map<String, String> factions() {
61+
Map<String, String> names = new HashMap<>();
62+
if (FactionManager.factions == null) return names;
63+
for (Faction faction : FactionManager.factions) {
64+
if (faction == null || faction.getId() == null) continue;
65+
names.put(faction.getId(), faction.getName());
66+
}
67+
return names;
68+
}
69+
70+
private static double trade(String guildId, int provinceId) {
71+
SimpleFactions plugin = SimpleFactions.getInstance();
72+
if (plugin == null || plugin.getProvinceManager() == null || guildId == null) return 0;
73+
Province province = plugin.getProvinceManager().get(provinceId);
74+
if (province == null) return 0;
75+
Guild guild = FactionManager.getGuildByString(guildId);
76+
return guild == null ? 0 : province.getRawGuildTrade(guild);
77+
}
78+
}

0 commit comments

Comments
 (0)