So I started trying to make a pretty smart ai that you can open diplomatic relations with, such as trade, marry your daughter and more. This would increase your relation with that faction. It all worked well but when i tried to add more factions and make them have relations between eachother and still keep track of it. Ye i failed. I tried using arrays and index for each faction and an array of intagers for the relations (0 is neutral, 100 is very likable, -100 is enemy). But it was very difficult to keep track of it all and at the same time focus on the relation to the player.
How is the ideal way to deal with this? Reducing the amount of factions would maybe work but i only tried with 9 and that shouldn’t be so hard right?
Is there a reason why you are limiting yourself to those data structures? Off hand I would use something like a Dictionary<Faction,Standing>. Or alternatively a List where FactionStanding has say an enum Faction field and an integer Standing field. The latter plays nicer with Unity serialization.
Then have defaults, and entities only have their own faction standings where they differ from the defaults. So to lookup a faction standing you look to see if the entity has it’s own, if not lookup the default.
Consider making a ScriptableObject asset. They’re editable in Unity’s inspector. Feel free to look over Love/Hate’s manual and API for ideas. Love/Hate does exactly what you describe, and it uses a ScriptableObject asset. A simple version might look like:
using UnityEngine;
using System;
using System.Collections.Generic;
[AddComponentMenu]
public class AllFactions : ScriptableObject
{
[Serializable]
public class Faction
{
public string name;
public int relation;
}
public List<Faction> factions;
}