Factions

Factions are a mapping. The mapping code (/lib/props/factions.c) is inherited
by the file /lib/player.c 

The file /lib/secure/include/props.h was modfied so that factions.c could be 
inherited properly by the required files. 

The factions code is based on the properties.c code in Dead Souls - the
function names and elements of the mapping have been changed. Factions are
added to the player file using AddFaction() and reputation and faction level
timers are stamped when the faction is created or modified.

The function to add/create a faction:

mixed AddFaction(string fac){

    int flev = 1;
    int ltime = SEASONS_D->GetTime();
    int rlev = 1;
    int rtime = SEASONS_D->GetTime();
    
    if( !stringp(fac) ) return 0;
    if( Factions[fac] ) return 0;
    Factions[fac] = (["faction level":flev,"level_timer":ltime,"reputation":rlev,
                      "reputation_timer": rtime ]);
    return Factions[fac];
}


Variables used in the AddFaction() function:

1. string fac = Faction name (user designated)
2. int flev   = faction level (user designated)
3. int ltime  = level timer (assigned in the function)
4. int rlev   = reputation level (assigned in the function)
5. int rtime  = reputation timer (assigned in the function) 

A sample factions mapping as saved in the player file:

Factions ([ "Orcs of the Bloody Moon" : (["reputation" : 20, "level_timer" : 
            729384181, "faction level" : 10, "reputation_timer" :
            729384219 ]) ])

Factions consist of:
1. A faction name
2. Faction level
3. Faction level timer
4. Reputation (level)
5. Reputation timer

The level and reputation timers are compared to mudtime. If the player
has no interactions with the faction during one year of mudtime the faction 
level will be reduced by one. If a player interacts with a faction member NPC 
in some way during the mudtime year, the level timer is reset to the time of
interaction. The same works for reputations, except the reputation timer is 
set for 30 days, where the reputation would decrease by one. Note that the way
the reputation timer is coded in factions.c that the players reputation will 
not drop below 0 due to time alone if that player is a member of the faction
(has a faction level greater than 0).

How do factions work in The Brass Ring?

Factions are used for player-npc interactions. A faction is just a name and can
be represented by a group or a single NPC.

NPC interaction determines if the player can join a faction. NPC trainers, 
quest givers, shop owners, etc. are used to add factions in the player object. 
Faction level and reputation determine the degree of interaction an NPC will 
have with the player. A NPC may not offer the player membership in the faction
unless the player fulfills a request by the NPC in the form of a quest. 

Furthermore, reputation levels determine the increase in faction level. Once a
player reaches a certain reputation level with the faction then their faction 
level increases.

For example: a player known to be associated with the "Orcs of the Bloody
Moon", and having a high reputation with that faction, may have trouble getting
quests from an NPC belonging to the faction of "The Knights of Ambrial".

Reputation levels in the faction will vary. Quests are good ways to increase 
or decrease the players reputation with various factions. Let's say the player,
Quixotic the Abnormal, belongs to "the Orcs of the Bloody Moon" faction and 
goes on a quest for Snotbreath, the Orc Warlord, to retrieve the mighty dingus
held by Sir Rottingham of the "Knights of Ambrial". Upon retrieval and 
presentation of the dingus to Snotbreath, the players reputation increases
with "the Orcs of the Bloody Moon" and drastically decreases with "the Knights
of Ambrial".  This can be acheived by using the functions:

this_player()->AddReputation("the Orcs of the Bloody Moon",1)
this_player()->AddReputation("the Knights of Ambrial",-5)

Every time there is a change in reputation a new reputation timestamp is added.
As noted before, if Quixotic does not interact with another member of "the 
Orcs of the Bloody Moon" within 30 days of the timestamp his reputation with 
that faction will decrease by one and a new timestamp set.
  

Setting NPC Factions

The function:

mapping SetFactions(mapping facs){
    if(sizeof(Factions)) return (Factions[facs] += facs);
    else return (Factions = facs);
}  

is used for setting a faction in a NPC as follows:

SetFactions( (["Merchants" : (["faction level" : 8, "reputation" :5]), 
               "Thief Guild" : (["faction level" : 14, "reputation" : 12])
              ]) );

The NPC belongs to the Merchants faction (faction level = 8; reputation = 5)
and Thief Guild faction (faction level = 14; reputation = 12).
