FactionMatrix - jimdroberts/FishMMO GitHub Wiki
Represents a matrix of faction relationships, where each cell defines the alliance level between two factions. Used to determine how factions interact (e.g., ally, enemy, neutral).
-
public FactionAllianceLevel[] Factions
Flat array representing the alliance level between each pair of factions. Indexed as [x + y * count], where x and y are faction indices.
-
public FactionMatrix(List Factions)
Constructs a new FactionMatrix for the given list of factions, initializing all relationships to Neutral. Factions (List): List of all faction templates to include in the matrix.
- Ensure you have a list of FactionTemplate objects to represent your factions.
- Create a new FactionMatrix by passing the list of factions to the constructor.
- The matrix will be initialized with all relationships set to Neutral.
// Example 1: Creating a FactionMatrix for 3 factions
var factions = new List<FactionTemplate> { factionA, factionB, factionC };
var matrix = new FactionMatrix(factions);
// All relationships are set to Neutral by default.
// Example 2: Accessing and modifying a relationship
int x = 0; // index of first faction
int y = 1; // index of second faction
matrix.Factions[x + y * factions.Count] = FactionAllianceLevel.Ally;
- Always use the correct indices when accessing the Factions array ([x + y * count]).
- Initialize the matrix with the full list of factions to avoid out-of-bounds errors.
- Use the matrix to keep relationships symmetric if your game logic requires it.