Defines | Functions

NPC Common

Various functions related to NPCs/Critters. More...


Detailed Description

Various functions related to NPCs/Critters.

Include npc_common_h.fos for usage.

Defines

#define _FreeHex   (map.IsHexPassed(hx, hy) && @ (map.GetCritter(hx, hy)) == null)
#define _AddHex
#define _OldHex   (hx == px && hy == py)
#define _ReturnHex   outX = hx; outY = hy; return true

Functions

bool AttackCritter (Critter& attacker, Critter& target, uint minhp)
bool AttackCritter (Critter& attacker, Critter& target)
bool HasIntelligentBrain (Critter& cr)
void UnsetCritterIllegalFlag (Critter& critter)
void UnsetCritterIllegalFlag (Critter& critter, int location)
void UnsetCritterIllegalFlag (uint id, int location)
void SetCritterIllegalFlag (Critter& critter, int reason)
void SetCritterIllegalFlag (Critter& critter, int location, int reason)
void PutAwayItems (Critter& critter)
int GetCritterIllegalFlag (Critter& critter, int location)
 Get illegal flag status of critter in a specific location.
int GetCritterIllegalFlag (Critter& critter)
 Clear illegal flags in critter's current location.
void ClearIllegalFlags (Critter& critter)
 Clear illegal flags in all towns.
bool IsFlaggedAsIllegal (Critter& critter)
bool IsFlaggedAsIllegal (Critter& critter, int location)
void Heal (Critter& cr)
 Heal a critter.
bool HasSameScript (Critter& critter1, Critter& critter2)
 Check if two critters has the same script assigned.
bool IsInLocation (Critter& critter, int locationPID)
 Check if a critter is in a specific location.
bool MoveByDir (Critter& critter, uint8 dir, uint steps, bool run)
uint GetNearGuards (Map@ map, uint16 hexX, uint16 hexY, uint radius, array< Critter@>@ crits)
 Gets all general purpose guards in a radius around given hex.
uint GetNearFactionGuards (Map@ map, uint16 hexX, uint16 hexY, uint radius, uint faction, array< Critter@>@ crits)
 Gets all faction guards in a radius around given hex.
ItemArmBestWeapon (Critter& critter)
 Arm the best weapon available to the NPC.
ItemArmFavoriteWeapon (Critter& critter)
 Tries to arm NPC with its favorite weapon.
void FindFreeHexes (Map@ map, uint16 hexX, uint16 hexY, int& num, array< uint16 >& coordsX, array< uint16 >& coordsY)
bool FindNearestFreeHex (Map@ map, uint16 hexX, uint16 hexY, uint16& outX, uint16& outY)
bool Flee (Critter& cr)
bool Flee (Critter& cr, bool Run)
 Flee to worldmap via closest exitgrid.
void MoveRandom (Critter& npc, uint maxDist)
 Issue random walk for a critter to a hex in stepDist distance, as long as the actual distance to home pos is less than maxDist.
void MoveRandom (Critter& npc, uint maxDist, bool Run)
void MoveRandom (Critter& npc, uint maxDist, uint stepDist, bool Run)
bool CanUseWeapon (Critter& critter, uint proto)
 Checks if a critter can use a weapon (has an animation for it).
bool CanUseWeapon (Critter& critter, Item@ weapon)
 Checks if a critter can use a weapon (has an animation for it).
bool HasUnusableWeapon (Critter& critter, uint bag)
 Checks if a critter can't use a weapon from a specific bag.
bool HasUnusableWeapon (Critter& critter)
 Checks if a critter can't use a weapon in his inventory.
bool HasUnusableWeapon (uint crpid, uint bag)
 Checks if a critter PID can't use a weapon from a specific bag.
void AddWaitPlan (Critter& critter, uint waittime)
 The critter will wait for the specified time without getting busy (it can speak to players).
void TryReportOffense (Critter@ cr, Critter@ offender, int reputationdrop)
string GetStoredFirstName (Critter& critter)
string GetStoredName (Critter& critter)
string GenerateNewName (Critter& critter)
uint GetCrittersWithScript (Map& map, uint16 pid, uint findType, string& scriptName, string& funcDeclaration, array< Critter@>@ critters)
 Gather all critters from a map that share the given script, and comply to the search parameters.
uint GetCrittersLoc (Location& loc, uint16 pid, uint findType, array< Critter@>@ critters)
void SetDeleteEvent (Critter& cr, uint time)
void DropDeleteEvent (Critter& cr)
uint cte_Delete (Critter& cr, int identifier, uint& rate)

Dialog functions



void r_MoveRandom (Critter& player, Critter@ npc, int val)
bool d_HasNumPlayersInParty (Critter& leader, Critter@ npc, int num)
 Checks if a party has specified numbers of members.
bool d_HasNotNumPlayersInParty (Critter& leader, Critter@ npc, int val)
 Checks if a party has NOT specified numbers of members.

Define Documentation

#define _FreeHex   (map.IsHexPassed(hx, hy) && @ (map.GetCritter(hx, hy)) == null)
#define _AddHex
Value:
do { coordsX.insertLast(hx); coordsY.insertLast(hy); free++; if(free == num) \
             return; } while(false)
#define _OldHex   (hx == px && hy == py)
#define _ReturnHex   outX = hx; outY = hy; return true

Function Documentation

bool AttackCritter ( Critter attacker,
Critter target,
uint  minhp 
)
bool AttackCritter ( Critter attacker,
Critter target 
)
bool HasIntelligentBrain ( Critter cr  ) 
void UnsetCritterIllegalFlag ( Critter critter  ) 
void UnsetCritterIllegalFlag ( Critter critter,
int  location 
)
void UnsetCritterIllegalFlag ( uint  id,
int  location 
)
void SetCritterIllegalFlag ( Critter critter,
int  reason 
)
void SetCritterIllegalFlag ( Critter critter,
int  location,
int  reason 
)
void PutAwayItems ( Critter critter  ) 
int GetCritterIllegalFlag ( Critter critter,
int  location 
)

Get illegal flag status of critter in a specific location.

int GetCritterIllegalFlag ( Critter critter  ) 

Clear illegal flags in critter's current location.

void ClearIllegalFlags ( Critter critter  ) 

Clear illegal flags in all towns.

bool IsFlaggedAsIllegal ( Critter critter  ) 
bool IsFlaggedAsIllegal ( Critter critter,
int  location 
)
void Heal ( Critter cr  ) 

Heal a critter.

Parameters:
cr Critter handle.
Remarks:
This function will remove poison, radiation, heal limbs and give the critter full HP.
bool HasSameScript ( Critter critter1,
Critter critter2 
)

Check if two critters has the same script assigned.

bool IsInLocation ( Critter critter,
int  locationPID 
)

Check if a critter is in a specific location.

bool MoveByDir ( Critter critter,
uint8  dir,
uint  steps,
bool  run 
)
uint GetNearGuards ( Map map,
uint16  hexX,
uint16  hexY,
uint  radius,
array< Critter@>@  crits 
)

Gets all general purpose guards in a radius around given hex.

uint GetNearFactionGuards ( Map map,
uint16  hexX,
uint16  hexY,
uint  radius,
uint  faction,
array< Critter@>@  crits 
)

Gets all faction guards in a radius around given hex.

Item@ ArmBestWeapon ( Critter critter  ) 

Arm the best weapon available to the NPC.

Remarks:
Firstly, weapons of the best skill of the NPC is tried, then in the following order: SK_BIG_GUNS, SK_ENERGY_WEAPONS, SK_SMALL_GUNS, SK_THROWING, SK_MELEE_WEAPONS
Item@ ArmFavoriteWeapon ( Critter critter  ) 

Tries to arm NPC with its favorite weapon.

void FindFreeHexes ( Map map,
uint16  hexX,
uint16  hexY,
int&  num,
array< uint16 >&  coordsX,
array< uint16 >&  coordsY 
)
bool FindNearestFreeHex ( Map map,
uint16  hexX,
uint16  hexY,
uint16&  outX,
uint16&  outY 
)
bool Flee ( Critter cr  ) 
bool Flee ( Critter cr,
bool  Run 
)

Flee to worldmap via closest exitgrid.

void MoveRandom ( Critter npc,
uint  maxDist 
)

Issue random walk for a critter to a hex in stepDist distance, as long as the actual distance to home pos is less than maxDist.

In this case, it issues walkplane closely to homepos.

Parameters:
maxDist Max distance in hexes.
stepDist Step distance, the actual distance of single move
void MoveRandom ( Critter npc,
uint  maxDist,
bool  Run 
)
void MoveRandom ( Critter npc,
uint  maxDist,
uint  stepDist,
bool  Run 
)
bool CanUseWeapon ( Critter critter,
uint  proto 
)

Checks if a critter can use a weapon (has an animation for it).

Parameters:
critter Critter handle.
proto Proto Id of the weapon to check.
bool CanUseWeapon ( Critter critter,
Item weapon 
)

Checks if a critter can use a weapon (has an animation for it).

Parameters:
critter Critter handle.
weapon Weapon to check.
bool HasUnusableWeapon ( Critter critter,
uint  bag 
)

Checks if a critter can't use a weapon from a specific bag.

Parameters:
critter Critter handle.
bag BagId to check.
Returns:
If no weapons are found at all, or if all weapons are usable, true. Otherwise, false.
Remarks:
Usable here refers to them having the animations needed to use the weapon.
bool HasUnusableWeapon ( Critter critter  ) 

Checks if a critter can't use a weapon in his inventory.

Parameters:
critter Critter handle.
Returns:
If no weapons are found at all, or if all weapons are usable, true. Otherwise, false.
Remarks:
Usable here refers to them having the animations needed to use the weapon.
bool HasUnusableWeapon ( uint  crpid,
uint  bag 
)

Checks if a critter PID can't use a weapon from a specific bag.

Parameters:
crpid Critter PID.
bag BagId to check.
Returns:
If no weapons are found at all, or if all weapons are usable, true. Otherwise, false.
Remarks:
Usable here refers to them having the animations needed to use the weapon.
void AddWaitPlan ( Critter critter,
uint  waittime 
)

The critter will wait for the specified time without getting busy (it can speak to players).

Parameters:
critter Critter handle.
waittime Time in ms.
void TryReportOffense ( Critter cr,
Critter offender,
int  reputationdrop 
)
string GetStoredFirstName ( Critter critter  ) 
string GetStoredName ( Critter critter  ) 
string GenerateNewName ( Critter critter  ) 
uint GetCrittersWithScript ( Map map,
uint16  pid,
uint  findType,
string scriptName,
string funcDeclaration,
array< Critter@>@  critters 
)

Gather all critters from a map that share the given script, and comply to the search parameters.

Parameters:
map Map to take the critters from.
pid Critters pid, 0 to take all.
findType Critters type and state, same as for generic find functions.
scriptName Name of the script, if module is not given then current is used.
funcDeclaration Declaration of the function in format retval s(args).
critters Array of critters to be filled with critters, or a null handle.
Returns:
Number of critters found.
uint GetCrittersLoc ( Location loc,
uint16  pid,
uint  findType,
array< Critter@>@  critters 
)
void SetDeleteEvent ( Critter cr,
uint  time 
)
void DropDeleteEvent ( Critter cr  ) 
uint cte_Delete ( Critter cr,
int  identifier,
uint&  rate 
)
void r_MoveRandom ( Critter player,
Critter npc,
int  val 
)
bool d_HasNumPlayersInParty ( Critter leader,
Critter npc,
int  num 
)

Checks if a party has specified numbers of members.

Parameters:
num The amount of players to check for.
Remarks:
A player is considered to be in the party if he has tagged the leader and is within 8 hexes of the leader.
bool d_HasNotNumPlayersInParty ( Critter leader,
Critter npc,
int  val 
)

Checks if a party has NOT specified numbers of members.

Parameters:
num The amount of players to check for.
Remarks:
A player is considered to be in the party if he has tagged the leader and is within 8 hexes of the leader.