Atrinik Server 2.5
Data Structures | Defines | Typedefs | Functions | Variables
server/los.c File Reference
#include <global.h>
#include <math.h>

Go to the source code of this file.

Data Structures

struct  blstr

Defines

#define SPACE_BLOCK   0.5
#define MAX_MASK_SIZE   81
#define NR_LIGHT_MASK   10
#define MAX_LIGHT_SOURCE   13
#define BLOCKED_LOS_EXPAND   0x20

Typedefs

typedef struct blstr blocks

Functions

static void expand_sight (object *op)
void init_block ()
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)
static int get_real_light_source_value (int l)
static void remove_light_mask (mapstruct *map, int x, int y, int mid)
static int add_light_mask (mapstruct *map, int x, int y, int mid)
void adjust_light_source (mapstruct *map, int x, int y, int light)
static void restore_light_mask (mapstruct *restore_map, mapstruct *map, int x, int y, int mid)
void check_light_source_list (mapstruct *map)
static void remove_light_mask_other (mapstruct *map, int x, int y, int mid)
void remove_light_source_list (mapstruct *map)
int obj_in_line_of_sight (object *obj, rv_vector *rv)

Variables

static blocks block [MAP_CLIENT_X][MAP_CLIENT_Y]
static int lmask_x [MAX_MASK_SIZE]
static int lmask_y [MAX_MASK_SIZE]
static int light_mask [MAX_LIGHT_SOURCE+1]
static int light_mask_width [NR_LIGHT_MASK]
static int light_mask_size [NR_LIGHT_MASK]
static int light_masks [NR_LIGHT_MASK][MAX_MASK_SIZE]

Detailed Description

Line of sight related functions.

Definition in file los.c.


Define 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 39 of file los.c.


Function Documentation

void adjust_light_source ( mapstruct map,
int  x,
int  y,
int  light 
)

Add or remove a light source to a map space. Adjust the light source map counter and apply the area of light it invokes around it.

Parameters:
mapThe map of this light
xX position of light
yY position of light
lightGlow radius of the light

Definition at line 754 of file los.c.

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 475 of file los.c.

void check_light_source_list ( mapstruct map)

Check light source list of specified map. This will also check all tiled maps attached to the map.

Parameters:
mapThe map to check.

Definition at line 890 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 389 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 556 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 571 of file los.c.

void init_block ( )

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 226 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 1193 of file los.c.

void remove_light_source_list ( mapstruct map)

Remove light sources list from a map.

Parameters:
mapThe map to remove from

Definition at line 1166 of file los.c.

static void restore_light_mask ( mapstruct restore_map,
mapstruct map,
int  x,
int  y,
int  mid 
) [static]

After loading a map, we check here all possible connected maps for overlapping light sources. When we find one, we add the overlapping area to our new loaded map.

Parameters:
restore_mapMap to restore from
mapMap
xX position
yY position
midLight value

Definition at line 834 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 312 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 346 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 494 of file los.c.


Variable Documentation

int light_mask[MAX_LIGHT_SOURCE+1] [static]
Initial value:
{
    0,
    1,
    2, 3,
    4, 5, 6, 6,
    7, 7, 8, 8,
    8, 9
}

Definition at line 68 of file los.c.

int light_mask_size[NR_LIGHT_MASK] [static]
Initial value:
{
    0, 9, 25, 25, 49,
    49, 49, 81, 81, 81
}

Definition at line 84 of file los.c.

int light_mask_width[NR_LIGHT_MASK] [static]
Initial value:
{
    0, 1, 2, 2, 3,
    3, 3, 4, 4, 4
}

Definition at line 78 of file los.c.

int lmask_x[MAX_MASK_SIZE] [static]
Initial value:
{
    0, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1,
    0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1,
    0, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, -1, -2, -3, -4, -4, -4, -4, -4, -4, -4, -4, -4, -3, -2, -1
}

Definition at line 54 of file los.c.

int lmask_y[MAX_MASK_SIZE] [static]
Initial value:
{
    0, -1, -1, 0, 1, 1, 1, 0, -1, -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2,
    -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3,
    4, 4, 4, 4, 4, 3, 2, 1, 0, -1, -2, -3, -4, -4, -4, -4, -4, -4, -4, -4, -4, -3, -2, -1, 0, 1, 2, 3, 4, 4, 4, 4
}

Definition at line 61 of file los.c.