1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
  
     | 
    
      /*
 *  File:       losparam.h
 *  Summary:    Parameters for the LOS algorithm
 */
#include "AppHdr.h"
#include "losparam.h"
#include "cloud.h"
#include "env.h"
#include "externs.h"
#include "mon-util.h"
#include "terrain.h"
opacity_type opacity_default::operator()(const coord_def& p) const
{
    // Secret doors in translucent walls shouldn't block LOS,
    // hence grid_appearance.
    dungeon_feature_type f = grid_appearance(p);
    if (feat_is_opaque(f))
        return OPC_OPAQUE;
    else if (is_opaque_cloud(env.cgrid(p)))
        return OPC_HALF;
    else if (f == DNGN_TREE)
        return OPC_HALF;
    else if (monster_at(p) && monster_at(p)->type == MONS_BUSH)
        return OPC_HALF;
    else
        return OPC_CLEAR;
}
opacity_type opacity_fullyopaque::operator()(const coord_def& p) const
{
    if (feat_is_opaque(env.grid(p)))
        return OPC_OPAQUE;
    else
        return OPC_CLEAR;
}
opacity_type opacity_no_trans::operator()(const coord_def& p) const
{
    opacity_type base = opc_default(p);
    dungeon_feature_type f = env.grid(p);
    if (feat_is_opaque(f) || feat_is_wall(f) || f == DNGN_TREE)
        return OPC_OPAQUE;
    else
        return base;
}
static bool mons_block_immob(const monsters* mons)
{
    if (mons == NULL)
        return false;
    switch (mons->id())
    {
    case MONS_BUSH:
    case MONS_PLANT:
    case MONS_OKLOB_PLANT:
    case MONS_FUNGUS:
        return true;
    default:
        return false;
    }
}
opacity_type opacity_immob::operator()(const coord_def& p) const
{
    opacity_type base = opc_no_trans(p);
    if (mons_block_immob(monster_at(p)))
        return OPC_OPAQUE;
    else
        return base;
}
// Make anything solid block in addition to normal LOS.
// That's just granite statues in addition to opacity_no_trans.
opacity_type opacity_solid::operator()(const coord_def& p) const
{
    dungeon_feature_type f = env.grid(p);
    if (feat_is_solid(f))
        return OPC_OPAQUE;
    else if (is_opaque_cloud(env.cgrid(p)))
        return OPC_HALF;
    else if (f == DNGN_TREE)
        return OPC_HALF;
    else if (monster_at(p) && monster_at(p)->type == MONS_BUSH)
        return OPC_HALF;
    else
        return OPC_CLEAR;
}
opacity_type opacity_monmove::operator()(const coord_def& p) const
{
    dungeon_feature_type feat = env.grid(p);
    if (feat < DNGN_MINMOVE || !mon.can_pass_through_feat(feat))
        return (OPC_OPAQUE);
    else
        return (OPC_CLEAR);
}
opacity_type opacity_no_actor::operator()(const coord_def& p) const
{
    if (feat_is_solid(env.grid(p)) || actor_at(p))
        return (OPC_OPAQUE);
    else
        return (OPC_CLEAR);
}
 
     |