GDG Factions Manager
Framework for Unity to easily manage factions in a game.
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
FactionManager Class Reference

This class handles all the information for the Faction System. This takes advantage of the singleton pattern to ensure that only one instance is available at any point in time. More...

Inheritance diagram for FactionManager:

Public Member Functions

void FixedUpdate ()
 Execute any function commands that may have been queued. This should be called on update to make sure that delayed commands are executed. Such commands include the restoration of temporary faction changes such as SetTemporaryHostile... which should return the ojects faction to normal after the duration expires. More...
 
int RegisterFactionMember (FactionEntity targetMember)
 Registers the member with its faction. This method will try to add the faction to the faction map if it doesn't already exist. It then registers the member with the faction member's list. More...
 
int RegisterFaction (string factionID)
 This method tries to register the faction. If the faction already exists nothing is done. More...
 
void PrintFactionTable ()
 Prints the faction table. Faction table is printed in the form Source Faction "to" Target Faction "=" Faction Value More...
 
void PrintFactionMambers (string factionID)
 Prints the members of the specified faction. More...
 
int GetReputation (FactionEntity oSource, FactionEntity oTarget)
 Returns an integer between 0 and 100 (inclusive) that represents how oSource feels about oTarget. More...
 
bool GetReactionIsFriendly (FactionEntity oSource, FactionEntity oTarget)
 Returns true if the source is friendly towards the target. More...
 
bool GetReactionIsNeutral (FactionEntity oSource, FactionEntity oTarget)
 Returns true if the source considers the target a Neutral More...
 
bool GetReactionIsHostile (FactionEntity oSource, FactionEntity oTarget)
 Returns true if the source is Hostile towards target. More...
 
int GetReputation (string sTargetID, string sSourceID)
 This answers the quastion: How do members from sSourceFactionID faction feel about sTargetFactionID? More...
 
void AdjustReputation (FactionEntity oTarget, FactionEntity oSourceFactionMember, int nAdjustment)
 Adjust how oSourceFactionMember's faction feels about oTarget by the amount specified in nAdjustment. More...
 
int AdjustReputation (string sTargetFactionID, string sSourceFactionID, int nAdjustment)
 Adjusts how members of sSourceFactionID feels about sTargetFactionID. More...
 
void SetIsTemporaryNeutral (FactionEntity oTarget, FactionEntity oSource, bool bDecays, float fDurationInSeconds)
 Make oSource temporarily neutral to oTarget using personal reputation. This will fail if oTarget and oSource are in the same faction or party as they can never be considered tempoarily anything but what the faction in general tells them to think. More...
 
void SetIsTemporaryNeutral (string sTargetFactionID, string sSourceFactionID, bool bDecays, float fDurationInSeconds)
 Makes the member of sTargetFactionID be viewed as neutral sSourceFactionID. More...
 
void SetIsTemporaryHostile (FactionEntity oTarget, FactionEntity oSource, bool bDecays, float fDurationInSeconds)
 Make oSource temporarily hostile to oTarget using personal reputation. This will fail if oTarget and oSource are in the same faction or party as they can never be considered tempoarily anything but what the faction in general tells them to think. More...
 
void SetIsTemporaryHostile (string sTargetFactionID, string sSourceFactionID, bool bDecays, float fDurationInSeconds)
 Makes the member of sTargetFactionID be viewed as hostile sSourceFactionID. More...
 
void SetIsTemporaryFriendly (FactionEntity oTarget, FactionEntity oSource, bool bDecays, float fDurationInSeconds)
 Make oSource temporarily friendly to oTarget using personal reputation. This will fail if oTarget and oSource are in the same faction or party as they can never be considered tempoarily anything but what the faction in general tells them to think. More...
 
void SetIsTemporaryFriendly (string sTargetFactionID, string sSourceFactionID, bool bDecays, float fDurationInSeconds)
 Makes the member of sTargetFactionID be viewed as friendly sSourceFactionID. More...
 
int NotifyFactionOfEvent (string factionID, FactionEvent fEvent)
 Notifies all members of a given faction of the event. More...
 
int ChangeFaction (FactionEntity oDeserter, string sToFactionID)
 Changes the faction of oChange to the faction specified by sToFactionID More...
 
int ChangeFaction (FactionEntity oDeserter, FactionEntity oToFactionMember)
 Changes the faction of oDeserter to that of oToFactionMember. More...
 
int AdjustWorldReputation (string sTargetFaction, int nAdjustment)
 This method adjusts how everyone in the world feels about sTargetFaction. More...
 
int AdjustWorldReputation (FactionEntity oTarget, int nAdjustment)
 Adjusts the world's view of the faction to which oTarget belongs. More...
 
double GetAverageOfFactionAttribute (string factionID, FactionCountableAttributeVisitor visitor)
 This method returns the average value of a given attribute accross the entire faction. More...
 
double GetAverageOfFactionAttribute (FactionEntity member, FactionCountableAttributeVisitor visitor)
 This method returns the average value of a given attribute accross the entire faction that member belongs to. More...
 
FactionEntity GetFactionMemberWithMinAttribute (string factionID, FactionCountableAttributeVisitor visitor)
 This method returns the member of the faction with the minimum in the desired attriute. The attribute to be explored is handled by the visitor reference. More...
 
FactionEntity GetFactionMemberWithMinAttribute (FactionEntity member, FactionCountableAttributeVisitor visitor)
 This method returns the member of the faction with the minimum in the desired attriute. The attribute to be explored is handled by the visitor reference. More...
 
FactionEntity GetFactionMemberWithMaxAttribute (string factionID, FactionCountableAttributeVisitor visitor)
 This method returns the member of the faction with the maximum in the desired attriute. The attribute to be explored is handled by the visitor reference. More...
 
FactionEntity GetFactionMemberWithMaxAttribute (FactionEntity member, FactionCountableAttributeVisitor visitor)
 This method returns the member of the faction with the maximum in the desired attriute. The attribute to be explored is handled by the visitor reference. More...
 
ArrayList GetMembersInFaction (string factionID)
 Returns the members of the faction specified by the faction ID. It returns null, if no faction is found. More...
 
string[] GetFactionIDs ()
 Returns all the Factions ID's registered with this manager. More...
 
void ResetFactions ()
 This method resets all the factions to the default start of all factions. That is, it makes every faction friendly to itself and neutral to everyone else. More...
 

Static Public Member Functions

static FactionManager GetInstance ()
 

Public Attributes

const string FACTION_MANAGER_NAME = "FACTION_MANAGER"
 
const int FACTION_SUCCESS = 0
 
const int FACTION_ERROR_FACTION_HOMO_OP = -30
 
const int FACTION_ERROR_MEMBER_NULL = -10
 
const int FACTION_ERROR_MEMBER_ALREADY_EXISTS = -11
 
const int FACTION_ERROR_FACTIONID_NULL = -20
 
const int FACTION_ERROR_FACTIONID_EXISTS = -21
 
const int FACTION_ERROR_FACTIONID_NOTFOUND = -22
 
const int FACTION_ERROR_FACTIONID_EMPTY = -22
 
const int FACTION_REPUTATION_FRIENDLY = 100
 
const int FACTION_REPUTATION_NEUTRAL = 89
 
const int FACTION_REPUTATION_HOSTILE = 10
 
const int FACTION_REPUTATION_MIN = -100
 
const int FACTION_REPUTATION_MAX = 100
 

Detailed Description

This class handles all the information for the Faction System. This takes advantage of the singleton pattern to ensure that only one instance is available at any point in time.

Member Function Documentation

void FactionManager.AdjustReputation ( FactionEntity  oTarget,
FactionEntity  oSourceFactionMember,
int  nAdjustment 
)

Adjust how oSourceFactionMember's faction feels about oTarget by the amount specified in nAdjustment.

Parameters
oTargetThe creature who will be viewed differently by an entire faction.
oSourceFactionMemberThe member of the faction that will have its opinion changed.
nAdjustmentThe amount (positive or negative) that the faction's opinion will change.
int FactionManager.AdjustReputation ( string  sTargetFactionID,
string  sSourceFactionID,
int  nAdjustment 
)

Adjusts how members of sSourceFactionID feels about sTargetFactionID.

Returns
The -1 if there was a failure to change the faction. For example you cannot change how members in a faction feel about other members in the same faction. On Success the adjustment is returned.
Parameters
sTargetFactionIDId of the faction which will be viewed differently by the other faction.
sSourceFactionId of the faction that will have its view changed.
int FactionManager.AdjustWorldReputation ( string  sTargetFaction,
int  nAdjustment 
)

This method adjusts how everyone in the world feels about sTargetFaction.

Returns
FACTION_SUCCESS.
Parameters
sTargetFactionThe ID of the faction that will be viewed differently by the world.
nAdjustmentNumber to adjust the faction by. Prefferably 0<= nAdjustment <=100.
int FactionManager.AdjustWorldReputation ( FactionEntity  oTarget,
int  nAdjustment 
)

Adjusts the world's view of the faction to which oTarget belongs.

Returns
FACTION SUCCESS on Success or one of the FACTION ERRORS
Parameters
oTargetEntity whose faction will be viewed differently by the everyone in world.
nAdjustmentAmount to adjust the reputation by 0<= nAdjustment <= 100
int FactionManager.ChangeFaction ( FactionEntity  oDeserter,
string  sToFactionID 
)

Changes the faction of oChange to the faction specified by sToFactionID

Returns
The new index on the faction list for this member. If it fails it returns one of the FACTION ERRORS
Parameters
oDeserterEntity whom will change factions.
sToFactionIDId of the faction that oDeserter will change to.
int FactionManager.ChangeFaction ( FactionEntity  oDeserter,
FactionEntity  oToFactionMember 
)

Changes the faction of oDeserter to that of oToFactionMember.

Returns
If successful it returns the index in the faction's member list of the oDeserter.
Parameters
oDeserterEntity to change the faction of.
oToFactionMemberMember of the faction that oDeserter will be converted to.
void FactionManager.FixedUpdate ( )

Execute any function commands that may have been queued. This should be called on update to make sure that delayed commands are executed. Such commands include the restoration of temporary faction changes such as SetTemporaryHostile... which should return the ojects faction to normal after the duration expires.

double FactionManager.GetAverageOfFactionAttribute ( string  factionID,
FactionCountableAttributeVisitor  visitor 
)

This method returns the average value of a given attribute accross the entire faction.

Example: if we wanted to get the average gold of a faction, we need to create a visitor that returns the amount of gold from a given entity and pass it as a reference here.

Returns
The average value of the attribute across the the faction.
Parameters
factionIDId of the faction to explore.
visitorVistor instance. This is in charge of returning the value for the attribute we want to explore.
double FactionManager.GetAverageOfFactionAttribute ( FactionEntity  member,
FactionCountableAttributeVisitor  visitor 
)

This method returns the average value of a given attribute accross the entire faction that member belongs to.

Example: if we wanted to get the average gold of a faction, we need to create a visitor that returns the amount of gold from a given entity and pass it as a reference here.

Returns
The average value of the attribute across the the faction.
Parameters
memberMember of the faction for which we want to calculate the average.
visitorVistor instance. This is in charge of returning the value for the attribute we want to explore.
string [] FactionManager.GetFactionIDs ( )

Returns all the Factions ID's registered with this manager.

Returns
List of registered ID
FactionEntity FactionManager.GetFactionMemberWithMaxAttribute ( string  factionID,
FactionCountableAttributeVisitor  visitor 
)

This method returns the member of the faction with the maximum in the desired attriute. The attribute to be explored is handled by the visitor reference.

Returns
The faction member with maximum attribute.
Parameters
factionIDId of the faction to explore.
visitorReference to the visitor that will handle the retrieval of the value.
FactionEntity FactionManager.GetFactionMemberWithMaxAttribute ( FactionEntity  member,
FactionCountableAttributeVisitor  visitor 
)

This method returns the member of the faction with the maximum in the desired attriute. The attribute to be explored is handled by the visitor reference.

Returns
The faction member with maximum attribute.
Parameters
memberMember of the faction to explore.
visitorReference to the visitor that will handle the retrieval of the value.
FactionEntity FactionManager.GetFactionMemberWithMinAttribute ( string  factionID,
FactionCountableAttributeVisitor  visitor 
)

This method returns the member of the faction with the minimum in the desired attriute. The attribute to be explored is handled by the visitor reference.

Returns
The faction member with minimum attribute.
Parameters
factionIDId of the faction to explore.
visitorReference to the visitor that will handle the retrieval of the value.
FactionEntity FactionManager.GetFactionMemberWithMinAttribute ( FactionEntity  member,
FactionCountableAttributeVisitor  visitor 
)

This method returns the member of the faction with the minimum in the desired attriute. The attribute to be explored is handled by the visitor reference.

Returns
The faction member with minimum attribute.
Parameters
memberMember of the faction to explore.
visitorReference to the visitor that will handle the retrieval of the value.
ArrayList FactionManager.GetMembersInFaction ( string  factionID)

Returns the members of the faction specified by the faction ID. It returns null, if no faction is found.

Returns
Returns the members of the faction specified by the faction ID. It returns null, if no faction is found.
Parameters
factionIDFaction I.
bool FactionManager.GetReactionIsFriendly ( FactionEntity  oSource,
FactionEntity  oTarget 
)

Returns true if the source is friendly towards the target.

Returns
True if target is friendly towards enemy.
Parameters
oSourceSource entity
oTargetTarget entity
bool FactionManager.GetReactionIsHostile ( FactionEntity  oSource,
FactionEntity  oTarget 
)

Returns true if the source is Hostile towards target.

Returns
True if target is hostile towards enemy.
Parameters
oSourceSource entity
oTargetTarget entity
bool FactionManager.GetReactionIsNeutral ( FactionEntity  oSource,
FactionEntity  oTarget 
)

Returns true if the source considers the target a Neutral

Returns
True if target is neutral towards enemy.
Parameters
oSourceSource entity
oTargetTarget entity
int FactionManager.GetReputation ( FactionEntity  oSource,
FactionEntity  oTarget 
)

Returns an integer between 0 and 100 (inclusive) that represents how oSource feels about oTarget.

Returns
The reputation.
Parameters
oSourceSource entity.
oTargetTarget entity.
int FactionManager.GetReputation ( string  sTargetID,
string  sSourceID 
)

This answers the quastion: How do members from sSourceFactionID faction feel about sTargetFactionID?

Returns
The reputation value.
Parameters
sTargetFactionIDId of the faction for which sSourceFactionID feels about.
sSourceFactionIDId of the faction for which is opinion is wanted.
int FactionManager.NotifyFactionOfEvent ( string  factionID,
FactionEvent  fEvent 
)

Notifies all members of a given faction of the event.

Returns
The faction event to send out.
Parameters
factionIDId of the faction to send the event to.
fEventFaction Event to send out.
void FactionManager.PrintFactionMambers ( string  factionID)

Prints the members of the specified faction.

Parameters
factionIDFaction I.
void FactionManager.PrintFactionTable ( )

Prints the faction table. Faction table is printed in the form Source Faction "to" Target Faction "=" Faction Value

int FactionManager.RegisterFaction ( string  factionID)

This method tries to register the faction. If the faction already exists nothing is done.

If the faction does not exist it is added and the faction's reaction to every other reaction is also mapped. By default factions are mapped Friendly to itself and Neutral to every other faction.

Parameters
factionIDId of the faction to register.
int FactionManager.RegisterFactionMember ( FactionEntity  targetMember)

Registers the member with its faction. This method will try to add the faction to the faction map if it doesn't already exist. It then registers the member with the faction member's list.

Returns
The position of the added member in the member faction list.
Parameters
targetMemberTarget member.
void FactionManager.ResetFactions ( )

This method resets all the factions to the default start of all factions. That is, it makes every faction friendly to itself and neutral to everyone else.

void FactionManager.SetIsTemporaryFriendly ( FactionEntity  oTarget,
FactionEntity  oSource,
bool  bDecays,
float  fDurationInSeconds 
)

Make oSource temporarily friendly to oTarget using personal reputation. This will fail if oTarget and oSource are in the same faction or party as they can never be considered tempoarily anything but what the faction in general tells them to think.

Parameters
oTargetThe object whose reputation will be altered.
oSourceThe creature whose opinion will change.
bDecaysIf this is TRUE, the friendlyness decays over fDurationInSeconds; otherwise it is indefinite.
fDurationInSecondsThis is only used if bDecays is TRUE, it is how long the neutrality lasts.
void FactionManager.SetIsTemporaryFriendly ( string  sTargetFactionID,
string  sSourceFactionID,
bool  bDecays,
float  fDurationInSeconds 
)

Makes the member of sTargetFactionID be viewed as friendly sSourceFactionID.

Parameters
sTargetFactionIDThe id of the faction whose reputation will be altered.
sSourceFactionIDThe id of the faction whose opinion will change.
bDecaysIf this is TRUE, the neutrality decays over fDurationInSeconds; otherwise it is indefinite.
fDurationInSecondsThis is only used if bDecays is TRUE, it is how long the neutrality lasts.
void FactionManager.SetIsTemporaryHostile ( FactionEntity  oTarget,
FactionEntity  oSource,
bool  bDecays,
float  fDurationInSeconds 
)

Make oSource temporarily hostile to oTarget using personal reputation. This will fail if oTarget and oSource are in the same faction or party as they can never be considered tempoarily anything but what the faction in general tells them to think.

Parameters
oTargetThe object whose reputation will be altered.
oSourceThe creature whose opinion will change.
bDecaysIf this is TRUE, the hostility decays over fDurationInSeconds; otherwise it is indefinite.
fDurationInSecondsThis is only used if bDecays is TRUE, it is how long the neutrality lasts.
void FactionManager.SetIsTemporaryHostile ( string  sTargetFactionID,
string  sSourceFactionID,
bool  bDecays,
float  fDurationInSeconds 
)

Makes the member of sTargetFactionID be viewed as hostile sSourceFactionID.

Parameters
sTargetFactionIDThe id of the faction whose reputation will be altered.
sSourceFactionIDThe id of the faction whose opinion will change.
bDecaysIf this is TRUE, the neutrality decays over fDurationInSeconds; otherwise it is indefinite.
fDurationInSecondsThis is only used if bDecays is TRUE, it is how long the neutrality lasts.
void FactionManager.SetIsTemporaryNeutral ( FactionEntity  oTarget,
FactionEntity  oSource,
bool  bDecays,
float  fDurationInSeconds 
)

Make oSource temporarily neutral to oTarget using personal reputation. This will fail if oTarget and oSource are in the same faction or party as they can never be considered tempoarily anything but what the faction in general tells them to think.

Parameters
oTargetThe object whose reputation will be altered.
oSourceThe creature whose opinion will change.
bDecaysIf this is TRUE, the neutrality decays over fDurationInSeconds; otherwise it is indefinite.
fDurationInSecondsThis is only used if bDecays is TRUE, it is how long the neutrality lasts.
void FactionManager.SetIsTemporaryNeutral ( string  sTargetFactionID,
string  sSourceFactionID,
bool  bDecays,
float  fDurationInSeconds 
)

Makes the member of sTargetFactionID be viewed as neutral sSourceFactionID.

Parameters
sTargetFactionIDThe id of the faction whose reputation will be altered.
sSourceFactionIDThe id of the faction whose opinion will change.
bDecaysIf this is TRUE, the neutrality decays over fDurationInSeconds; otherwise it is indefinite.
fDurationInSecondsThis is only used if bDecays is TRUE, it is how long the neutrality lasts.

The documentation for this class was generated from the following file: