Skip to content

Commit 6253147

Browse files
committed
Issue MekHQ#6619: Move RestoreUnitAction::copyC3Networks from MekHQ to MegaMek's C3Utils
1 parent d5b570b commit 6253147

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

megamek/src/megamek/common/Entity.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5942,7 +5942,7 @@ public boolean hasAnyC3System() {
59425942
return hasC3() || hasNhC3();
59435943
}
59445944

5945-
public String getC3NetId() {
5945+
public @Nullable String getC3NetId() {
59465946
if (c3NetIdString == null) {
59475947
if (hasC3()) {
59485948
c3NetIdString = "C3." + getId();
@@ -6012,6 +6012,16 @@ public void setC3NetIdSelf() {
60126012
}
60136013
}
60146014

6015+
/**
6016+
* Explicitly set the C3 Net ID using a string.
6017+
* @see megamek.common.util.C3Util
6018+
* @see #setC3NetId(Entity)
6019+
* @param c3NetId string value the id should be set to
6020+
*/
6021+
public void setC3NetId(@Nullable String c3NetId) {
6022+
c3NetIdString = c3NetId;
6023+
}
6024+
60156025
/**
60166026
* Determine the remaining number of other C3 Master computers that can connect to this <code>Entity</code>.
60176027
* <p>

megamek/src/megamek/common/util/C3Util.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,24 @@ public static List<Entity> wireC3(Game game, Entity entity) {
9999

100100
return affectedUnits;
101101
}
102+
103+
/**
104+
* Copies the C3 network setup from the source to the target.
105+
*
106+
* @param source The source {@link Entity}.
107+
* @param target The target {@link Entity}.
108+
*/
109+
public static void copyC3Networks(Entity source, Entity target) {
110+
target.setC3UUIDAsString(source.getC3UUIDAsString());
111+
target.setC3Master(source.getC3Master(), false);
112+
target.setC3MasterIsUUIDAsString(source.getC3MasterIsUUIDAsString());
113+
114+
// Reassign the C3NetId
115+
target.setC3NetId(source.getC3NetId());
116+
117+
for (int pos = 0; pos < Entity.MAX_C3i_NODES; ++pos) {
118+
target.setC3iNextUUIDAsString(pos, source.getC3iNextUUIDAsString(pos));
119+
target.setNC3NextUUIDAsString(pos, source.getNC3NextUUIDAsString(pos));
120+
}
121+
}
102122
}

0 commit comments

Comments
 (0)