Atrinik Server  4.0
Macros | Functions
monster.c File Reference
#include <global.h>
#include <toolkit/packet.h>
#include <toolkit/string.h>
#include <monster_data.h>
#include <faction.h>
#include <plugin.h>
#include <monster_guard.h>
#include <arch.h>
#include <player.h>
#include <object.h>
#include <object_methods.h>
#include <waypoint.h>

Go to the source code of this file.

Macros

#define MAX_KNOWN_SPELLS   20
 

Functions

static int can_detect_enemy (object *op, object *enemy, rv_vector *rv)
 
static objectfind_nearest_enemy (object *ob)
 
static int move_randomly (object *op)
 
static int can_hit (object *ob1, rv_vector *rv)
 
static objectmonster_choose_random_spell (object *monster, uint32_t flags)
 
static int monster_cast_spell (object *head, object *part, int dir, rv_vector *rv, uint32_t flags)
 
static int monster_use_bow (object *head, object *part, int dir)
 
static int dist_att (int dir, object *part, rv_vector *rv)
 
static int run_att (int dir, object *ob, object *part, rv_vector *rv)
 
static int hitrun_att (int dir, object *ob)
 
static int wait_att (int dir, object *ob, object *part, rv_vector *rv)
 
static int disthit_att (int dir, object *ob, object *part, rv_vector *rv)
 
static int wait_att2 (int dir, rv_vector *rv)
 
static void circ1_move (object *ob)
 
static void circ2_move (object *ob)
 
static void pace_movev (object *ob)
 
static void pace_moveh (object *ob)
 
static void pace2_movev (object *ob)
 
static void pace2_moveh (object *ob)
 
static void rand_move (object *ob)
 
void set_npc_enemy (object *npc, object *enemy, rv_vector *rv)
 
static void monster_enemy_signal_map (object *npc, mapstruct *map, object *spawn_point, uint32_t dist)
 
void monster_enemy_signal (object *npc, object *enemy)
 
objectcheck_enemy (object *npc, rv_vector *rv)
 
objectfind_enemy (object *npc, rv_vector *rv)
 
static bool monster_can_move (object *op)
 
static void process_func (object *op)
 
 OBJECT_TYPE_INIT_DEFINE (monster)
 
static int can_detect_target (object *op, object *target, unsigned int range, unsigned int srange, rv_vector *rv)
 
static int monster_spell_useful (object *target, int spell_id)
 
static char * find_matching_message (const char *msg, const char *match)
 
int talk_to_npc (object *op, object *npc, char *txt)
 
int is_friend_of (object *op, object *obj)
 
int check_good_weapon (object *who, object *item)
 
int check_good_armour (object *who, object *item)
 
bool monster_is_ally_of (object *op, object *target)
 
void monster_drop_arrows (object *op)
 

Detailed Description

Monster memory, NPC interaction, AI, and other related functions are in this file, all used by the monster type objects.

Definition in file monster.c.

Function Documentation

static int can_detect_enemy ( object op,
object enemy,
rv_vector rv 
)
static

Controls if monster still can see/detect its enemy.

Includes visibility but also map and area control.

Parameters
opThe monster object.
enemyMonster object's enemy.
rvRange vector.
Returns
1 if can see/detect, 0 otherwise.

Definition at line 424 of file monster.c.

static int can_detect_target ( object op,
object target,
unsigned int  range,
unsigned int  srange,
rv_vector rv 
)
static

Check if monster can detect target (invisibility and being in range).

Parameters
opMonster.
targetThe target to check.
rangeRange this object can see.
srangeStealth range this object can see.
rvRange vector.
Returns
1 if can detect target, 0 otherwise.

Definition at line 830 of file monster.c.

static int can_hit ( object ob1,
rv_vector rv 
)
static

Check if object can hit another object.

Parameters
ob1Monster object.
rvRange vector.
Returns
1 if can hit, 0 otherwise.

Definition at line 1020 of file monster.c.

object* check_enemy ( object npc,
rv_vector rv 
)

Checks if NPC's enemy is still valid.

Parameters
npcThe NPC object.
rvRange vector of the enemy.
Returns
Enemy object if valid, NULL otherwise.

Definition at line 326 of file monster.c.

int check_good_armour ( object who,
object item 
)

Checks if using armor 'item' would be better for 'who'.

Parameters
whoCreature considering to apply item.
itemItem to check.
Returns
1 if item is a better object, 0 otherwise.

Definition at line 1811 of file monster.c.

int check_good_weapon ( object who,
object item 
)

Checks if using weapon 'item' would be better for 'who'.

Parameters
whoCreature considering to apply item.
itemItem to check.
Returns
1 if item is a better object, 0 otherwise.

Definition at line 1764 of file monster.c.

static void circ1_move ( object ob)
static

Circle type of move.

Parameters
obMonster.

Definition at line 1394 of file monster.c.

static void circ2_move ( object ob)
static

Different type of circle type move.

Parameters
obMonster.

Definition at line 1412 of file monster.c.

static int dist_att ( int  dir,
object part,
rv_vector rv 
)
static

Monster does a distance attack.

Parameters
dirDirection.
partPart of the object.
rvRange vector.
Returns
New direction.

Definition at line 1256 of file monster.c.

static int disthit_att ( int  dir,
object ob,
object part,
rv_vector rv 
)
static

Distance hit attack.

Parameters
dirDirection.
obMonster.
partPart of the monster.
rvRange vector.
Returns
New direction.

Definition at line 1362 of file monster.c.

object* find_enemy ( object npc,
rv_vector rv 
)

Tries to find an enemy for NPC. We pass the range vector since our caller will find the information useful.

Parameters
npcThe NPC object.
rvRange vector.
Returns
Enemy object if found, NULL otherwise.

Definition at line 350 of file monster.c.

static char* find_matching_message ( const char *  msg,
const char *  match 
)
static

This function takes the message to be parsed in 'msg', the text to match in 'match', and returns the portion of the message.

Parameters
msgMessage to parse.
matchText to try to match.
Returns
Returned portion which should be freed later, NULL if there was no match.

Definition at line 1530 of file monster.c.

static object * find_nearest_enemy ( object ob)
static

Finds nearest enemy for a monster.

Parameters
obThe monster.
Returns
Nearest enemy, NULL if none.

Definition at line 862 of file monster.c.

static int hitrun_att ( int  dir,
object ob 
)
static

Hit and run type of attack.

Parameters
dirDirection.
obMonster.
Returns
New direction.

Definition at line 1305 of file monster.c.

int is_friend_of ( object op,
object obj 
)

Check if object op is friend of obj.

Parameters
opThe first object
objThe second object to check against the first one
Returns
1 if both objects are friends, 0 otherwise

Definition at line 1685 of file monster.c.

static bool monster_can_move ( object op)
static

Check whether the monster is able to move at will. Certain things may disable normal movement, such as player talking to the monster, and the monster responding to the player and setting a period of time to wait for until resuming movement.

Parameters
opMonster.
Returns
Whether the monster can move.

Definition at line 465 of file monster.c.

static int monster_cast_spell ( object head,
object part,
int  dir,
rv_vector rv,
uint32_t  flags 
)
static

Tries to make a monster cast a spell.

Parameters
headHead of the monster.
partPart of the monster that we use to cast.
dirDirection to cast.
rvRange vector describing where the enemy is. If NULL, will attempt to find a friendly object to cast the spell on.
flagsFlags the spell must have.
Returns
1 if monster casted a spell, 0 otherwise.

Definition at line 1110 of file monster.c.

static object * monster_choose_random_spell ( object monster,
uint32_t  flags 
)
static

Choose a random spell this monster could cast.

Parameters
monsterThe monster object.
flagsFlags the spell must have.
Returns
Random spell object, NULL if no spell found.

Definition at line 1041 of file monster.c.

void monster_drop_arrows ( object op)

Makes the specified monster drop the arrows that were stuck into it.

Parameters
opMonster. Must be on a map.

Definition at line 1887 of file monster.c.

void monster_enemy_signal ( object npc,
object enemy 
)

Signal a change in monster's enemy.

Parameters
npcMonster/NPC.
enemyNew enemy.

Definition at line 270 of file monster.c.

static void monster_enemy_signal_map ( object npc,
mapstruct map,
object spawn_point,
uint32_t  dist 
)
static

Signal all linked monsters on the specified map about a possible enemy.

Parameters
npcMonster that is signaling.
mapMap to signal on.
spawn_pointNPC's spawn point.
distMaximum distance for non-linked spawn points.

Definition at line 224 of file monster.c.

static int monster_spell_useful ( object target,
int  spell_id 
)
static

Check if it's worth it for monster to cast a spell, based on the target.

Parameters
targetTarget.
spell_idSpell ID being checked.
Returns
1 if it's worth it, 0 otherwise.

Definition at line 1083 of file monster.c.

static int monster_use_bow ( object head,
object part,
int  dir 
)
static

Tries to make a (part of a) monster fire a bow.

Parameters
headHead of the monster.
partPart of the monster that we use to fire.
dirDirection to cast.
Returns
1 if monster fired something, 0 otherwise.

Definition at line 1230 of file monster.c.

static int move_randomly ( object op)
static

Randomly move a monster.

Parameters
opThe monster object to move.
Returns
1 if the monster was moved, 0 otherwise.

Definition at line 942 of file monster.c.

OBJECT_TYPE_INIT_DEFINE ( monster  )

Initialize the monster type object methods.

Definition at line 810 of file monster.c.

static void pace2_moveh ( object ob)
static

Another type of horizontal pace movement.

Parameters
obMonster.

Definition at line 1486 of file monster.c.

static void pace2_movev ( object ob)
static

Another type of vertical pace movement.

Parameters
obMonster.

Definition at line 1466 of file monster.c.

static void pace_moveh ( object ob)
static

Horizontal pace movement.

Parameters
obMonster.

Definition at line 1448 of file monster.c.

static void pace_movev ( object ob)
static

Vertical pace movement.

Parameters
obMonster.

Definition at line 1430 of file monster.c.

static void process_func ( object op)
static

Processes an object, giving it the opportunity to move or react.

Parameters
opThe object to process.

Definition at line 475 of file monster.c.

static void rand_move ( object ob)
static

Random movement.

Parameters
obMonster.

Definition at line 1506 of file monster.c.

static int run_att ( int  dir,
object ob,
object part,
rv_vector rv 
)
static

Monster runs.

Parameters
dirDirection.
obThe monster.
partPart of the monster.
rvRange vector.
Returns
New direction.

Definition at line 1284 of file monster.c.

void set_npc_enemy ( object npc,
object enemy,
rv_vector rv 
)

Update (or clear) an NPC's enemy. Perform most of the housekeeping related to switching enemies

You should always use this method to set (or clear) an NPC's enemy.

If enemy is given an aggro wp may be set up. If rv is given, it will be filled out with the vector to enemy

enemy and/or rv may be NULL.

Parameters
npcThe NPC object we're setting enemy for.
enemyThe enemy object, NULL if we're clearing the enemy for this NPC.
rvRange vector of the enemy.

Definition at line 85 of file monster.c.

int talk_to_npc ( object op,
object npc,
char *  txt 
)

Give an object the chance to handle something being said.

Plugin hooks will be called.

Parameters
opWho is talking.
npcObject to try to talk to.
txtWhat op is saying.
Returns
1 if the NPC replied to the player, 0 otherwise.

Definition at line 1615 of file monster.c.

static int wait_att ( int  dir,
object ob,
object part,
rv_vector rv 
)
static

Wait, and attack.

Parameters
dirDirection.
obMonster.
partPart of the monster.
rvRange vector.
Returns
New direction.

Definition at line 1331 of file monster.c.

static int wait_att2 ( int  dir,
rv_vector rv 
)
static

Wait and attack.

Parameters
dirDirection.
rvRange vector.
Returns
New direction.

Definition at line 1380 of file monster.c.