-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6475 from Scoppio/feat/refactor-flags
Feat/refactor flags
- Loading branch information
Showing
21 changed files
with
1,024 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2025 - The MegaMek Team. All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* for more details. | ||
*/ | ||
package megamek.common; | ||
|
||
/** | ||
* Set of flags that can be used to determine how the ammo is used and its | ||
* special properties | ||
* @author Luana Coppio | ||
*/ | ||
public enum AmmoTypeFlag implements EquipmentFlag { | ||
|
||
F_BATTLEARMOR, // only used by BA squads | ||
F_PROTOMEK, // only used by ProtoMeks | ||
|
||
F_ENCUMBERING, // Encumbering ammo - if loaded on a BA it cant jump or make anti-mek attacks until dumped | ||
|
||
F_MG, // Machinegun ammo | ||
F_MML_LRM, // LRM type | ||
F_MML_SRM, // SRM type | ||
|
||
F_HOTLOAD, // Ammo can be hotloaded | ||
|
||
F_SCREEN, // Used by MHQ for loading ammo bins | ||
|
||
F_INTERNAL_BOMB, // Used for Internal Bomb Bay bombs; to differentiate them from other bombs | ||
F_GROUND_BOMB, // the ammo can be used to ground bomb | ||
F_OTHER_BOMB, // For tag, rl pods, missiles and the like | ||
F_SPACE_BOMB, // defines that the ammo can be used to space bomb | ||
|
||
F_AR10_BARRACUDA, // barracuda type | ||
F_AR10_KILLER_WHALE, // Killer Whale type | ||
F_AR10_WHITE_SHARK, // White shark type | ||
F_CAP_MISSILE, // Other Capital-Missile | ||
F_CRUISE_MISSILE, // Used by MHQ for loading ammo bins | ||
F_TELE_MISSILE, // Tele-Missile | ||
|
||
F_NUCLEAR, // Nuclear missile | ||
F_SANTA_ANNA, // Nuke Santa Anna Missile | ||
F_PEACEMAKER, // Nuke Peacemaker Missile | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
* Copyright (c) 2025 - The MegaMek Team. All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* for more details. | ||
*/ | ||
package megamek.common; | ||
|
||
import java.util.BitSet; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Represents a set of flags that can be used to represent the type and | ||
* special properties of the equipment. | ||
* @author Luana Coppio | ||
*/ | ||
public class EquipmentBitSet { | ||
|
||
private final BitSet bitSet; | ||
|
||
/** | ||
* Default constructor. | ||
*/ | ||
public EquipmentBitSet() { | ||
// This value is currently a bit above the double of what we need, but it's a power of 2, and it's a good | ||
// starting point since it will give a lot of runaway for new types of equipments, ammo and weapons to be added | ||
// Whenever we surpass this number, the bitset will increase on its own as needed, so its more of a performance | ||
// matter than a limitation. | ||
this.bitSet = new BitSet(512); | ||
} | ||
|
||
/** | ||
* Copy constructor. | ||
* @param other the EquipmentBitSet to copy | ||
*/ | ||
public EquipmentBitSet(EquipmentBitSet other) { | ||
this.bitSet = (BitSet) other.bitSet.clone(); | ||
} | ||
|
||
/** | ||
* Returns true if the flag is set in the EquipmentBitSet. | ||
* @param flag the flag to check | ||
* @return true if the flag is set in the EquipmentBitSet | ||
*/ | ||
public boolean get(EquipmentFlag flag) { | ||
return bitSet.get(flag.ordinal()); | ||
} | ||
|
||
public boolean contains(EquipmentBitSet other) { | ||
var checker = new EquipmentBitSet(this); | ||
checker.bitSet.and(other.bitSet); | ||
return checker.equals(other); | ||
} | ||
|
||
/** | ||
* Clears the flag in the EquipmentBitSet. | ||
* @param flag the flag to clear | ||
*/ | ||
public void clear(EquipmentFlag flag) { | ||
bitSet.clear(flag.ordinal()); | ||
} | ||
|
||
/** | ||
* Clears all flags in the EquipmentBitSet. | ||
*/ | ||
public void clear() { | ||
bitSet.clear(); | ||
} | ||
|
||
/** | ||
* Sets the flag in the EquipmentBitSet. | ||
* @param flag the flag to set | ||
*/ | ||
public void set(EquipmentFlag flag) { | ||
bitSet.set(flag.ordinal()); | ||
} | ||
|
||
|
||
/** | ||
* Returns a copy of this EquipmentBitSet with the flag set. | ||
* @param flag the flag to set | ||
* @return a copy of this EquipmentBitSet with the flag set | ||
*/ | ||
public EquipmentBitSet or(EquipmentFlag flag) { | ||
var newBitSet = new EquipmentBitSet(this); | ||
newBitSet.set(flag); | ||
return newBitSet; | ||
} | ||
|
||
/** | ||
* Returns a copy of this EquipmentBitSet with the flag cleared. | ||
* @param flag the flag to clear | ||
* @return a copy of this EquipmentBitSet with the flag cleared | ||
*/ | ||
public EquipmentBitSet andNot(EquipmentFlag flag) { | ||
var newBitSet = new EquipmentBitSet(this); | ||
newBitSet.clear(flag); | ||
return newBitSet; | ||
} | ||
|
||
/** | ||
* Returns a new empty EquipmentBitSet and the flag set if it is set in this EquipmentBitSet. | ||
* Example: | ||
* EquipmentBitSet a = new EquipmentBitSet(); | ||
* a.set(F_HEAT_SINK); | ||
* a.set(F_DOUBLE_HEATSINK); | ||
* a.and(F_HEAT_SINK) // EquipmentBitSet with only F_HEAT_SINK set if it was originally set | ||
* a.has(F_HEAT_SINK); // true | ||
* a.has(F_DOUBLE_HEATSINK); // false | ||
* @param flag the flag to check | ||
* @return a new empty EquipmentBitSet and the flag set if it is set in this EquipmentBitSet | ||
*/ | ||
public EquipmentBitSet and(EquipmentFlag flag) { | ||
var newBitSet = new EquipmentBitSet(); | ||
if (this.get(flag)) { | ||
newBitSet.set(flag); | ||
} | ||
return newBitSet; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "EntityBitSet{" + | ||
"bitSet=" + bitSet + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o instanceof EquipmentBitSet that) { | ||
return Objects.equals(bitSet, that.bitSet); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(bitSet); | ||
} | ||
} |
Oops, something went wrong.