Atrinik Server  4.0
Data Structures | Macros | Typedefs | Functions | Variables
los.c File Reference
#include <global.h>
#include <toolkit/bresenham.h>
#include <player.h>
#include <object.h>

Go to the source code of this file.

Data Structures

struct  blstr
 

Macros

#define SPACE_BLOCK   0.5
 
#define BLOCKED_LOS_EXPAND   0x20
 

Typedefs

typedef struct blstr blocks
 

Functions

static void expand_sight (object *op)
 
void init_block (void)
 
void set_block (int x, int y, int bx, int by)
 
static void set_wall (object *op, int x, int y)
 
static void check_wall (object *op, int x, int y)
 
static void blinded_sight (object *op)
 
void update_los (object *op)
 
void clear_los (object *op)
 
int obj_in_line_of_sight (object *obj, rv_vector *rv)
 

Variables

static blocks block [MAP_CLIENT_X][MAP_CLIENT_Y]
 

Detailed Description

Line of sight related functions.

Definition in file los.c.

Macro Definition Documentation

#define SPACE_BLOCK   0.5

Distance must be less than this for the object to be blocked. An object is 1.0 wide, so if set to 0.5, it means the object that blocks half the view (0.0 is complete block) will block view in our tables. .4 or less lets you see through walls. .5 is about right.

Definition at line 42 of file los.c.

Function Documentation

static void blinded_sight ( object op)
static

Sets all viewable squares to blocked except for the central one that the player occupies. A little odd that you can see yourself (and what you're standing on), but really need for any reasonable game play.

Parameters
opPlayer's object for which to reset los.

Definition at line 295 of file los.c.

static void check_wall ( object op,
int  x,
int  y 
)
static

Used to initialize the array used by the LOS routines. Instead of light values, blocked_los[][] now tells the client update function what kind of tile we have: visible, sight blocked, blocksview trigger or out of map.

Parameters
opThe player object
xX position based on MAP_CLIENT_X
yY position based on MAP_CLIENT_Y

Definition at line 221 of file los.c.

void clear_los ( object op)

Clears/initializes the LOS array associated to the player controlling the object.

Parameters
opThe player object.

Definition at line 363 of file los.c.

static void expand_sight ( object op)
static

This goes through the array of what the given player is able to see, and expands the visible area a bit, so the player will, to a certain degree, be able to see into corners. This is somewhat suboptimal, would be better to improve the formula.

Parameters
opThe player object.
Todo:
Improve the formula.

Definition at line 380 of file los.c.

void init_block ( void  )

Initializes the array used by the LOS routines. This is NOT called for every LOS - only at server start to init the base block structure.

Since we are only doing the upper left quadrant, only these spaces could possibly get blocked, since these are the only ones further out that are still possibly in the sightline.

Definition at line 63 of file los.c.

int obj_in_line_of_sight ( object obj,
rv_vector rv 
)

Check if object is in line of sight, based on rv_vector. This will check also check for blocksview 1 objects.

Uses the Bresenham line algorithm.

Parameters
objThe object to check
rvrv_vector to get distances, map, etc from
Returns
1 if in line of sight, 0 otherwise

Definition at line 427 of file los.c.

void set_block ( int  x,
int  y,
int  bx,
int  by 
)

Used to initialize the array used by the LOS routines. What this sets if that x, y blocks the view of bx, by This then sets up a relation - for example, something at 5, 4 blocks view at 5, 3 which blocks view at 5, 2 etc. So when we check 5, 4 and find it block, we have the data to know that 5, 3 and 5, 2 and 5, 1 should also be blocked.

Parameters
xX position
yY position
bxBlocked X position
byBlocked Y position

Definition at line 145 of file los.c.

static void set_wall ( object op,
int  x,
int  y 
)
static

Used to initialize the array used by the LOS routines. x, y are indexes into the blocked[][] array. This recursively sets the blocked line of sight view. From the blocked[][] array, we know for example that if some particular space is blocked, it blocks the view of the spaces 'behind' it, and those blocked spaces behind it may block other spaces, etc. In this way, the chain of visibility is set.

Parameters
opPlayer object
xX position
yY position

Definition at line 177 of file los.c.

void update_los ( object op)

Recalculates the array which specifies what is visible for the given player object.

Parameters
opThe player object

Definition at line 314 of file los.c.