FactionMatrix - jimdroberts/FishMMO GitHub Wiki

Description

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).


API Access

Fields

  • 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.

Methods

  • 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.


Basic Usage

Setup

  1. Ensure you have a list of FactionTemplate objects to represent your factions.
  2. Create a new FactionMatrix by passing the list of factions to the constructor.
  3. The matrix will be initialized with all relationships set to Neutral.

Example

// 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;

Best Practices

  • 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.
⚠️ **GitHub.com Fallback** ⚠️