00001 /* 00002 * File: losparam.h 00003 * Summary: Parameters for the LOS algorithm 00004 */ 00005 00006 #ifndef LOSPARAM_H 00007 #define LOSPARAM_H 00008 00009 // Note: find_ray relies on the fact that 2*OPC_HALF == OPC_OPAQUE. 00010 // On the other hand, losight tracks this explicitly. 00011 enum opacity_type 00012 { 00013 OPC_CLEAR = 0, 00014 OPC_HALF = 1, // for opaque clouds; two or more block 00015 OPC_OPAQUE = 2, 00016 00017 NUM_OPACITIES 00018 }; 00019 00020 class opacity_func 00021 { 00022 public: 00023 virtual opacity_type operator()(const coord_def& p) const = 0; 00024 virtual ~opacity_func() {} 00025 virtual opacity_func* clone() const = 0; 00026 }; 00027 00028 #define CLONE(typename) \ 00029 typename* clone() const \ 00030 { \ 00031 return (new typename(*this)); \ 00032 } 00033 00034 // Default LOS rules. 00035 class opacity_default : public opacity_func 00036 { 00037 public: 00038 CLONE(opacity_default) 00039 00040 opacity_type operator()(const coord_def& p) const; 00041 }; 00042 static opacity_default opc_default; 00043 00044 // Default LOS rules, but only consider fully opaque features blocking. 00045 // In particular, clouds don't affect the result. 00046 class opacity_fullyopaque : public opacity_func 00047 { 00048 public: 00049 CLONE(opacity_fullyopaque) 00050 00051 opacity_type operator()(const coord_def& p) const; 00052 }; 00053 static opacity_fullyopaque opc_fullyopaque; 00054 00055 // Make transparent features block in addition to normal LOS. 00056 // * Translocations opacity: blink, apportation, portal projectile. 00057 // * Various "I feel safe"-related stuff. 00058 class opacity_no_trans : public opacity_func 00059 { 00060 public: 00061 CLONE(opacity_no_trans) 00062 00063 opacity_type operator()(const coord_def& p) const; 00064 }; 00065 static opacity_no_trans opc_no_trans; 00066 00067 // Make immobile monsters block in addition to no_trans. 00068 // This is used for monster movement. 00069 class opacity_immob : public opacity_func 00070 { 00071 public: 00072 CLONE(opacity_immob) 00073 00074 opacity_type operator()(const coord_def& p) const; 00075 }; 00076 static opacity_immob opc_immob; 00077 00078 // Make anything solid block in addition to normal LOS. 00079 class opacity_solid : public opacity_func 00080 { 00081 public: 00082 CLONE(opacity_solid) 00083 00084 opacity_type operator()(const coord_def& p) const; 00085 }; 00086 static opacity_solid opc_solid; 00087 00088 // Opacity for monster movement, based on the late monster_los. 00089 class opacity_monmove : public opacity_func 00090 { 00091 public: 00092 opacity_monmove(const monster& m) 00093 : mon(m) 00094 { 00095 } 00096 00097 CLONE(opacity_monmove) 00098 00099 opacity_type operator()(const coord_def& p) const; 00100 private: 00101 const monster& mon; 00102 }; 00103 00104 // Make any actor (as well as solid features) block. 00105 // Note that the blocking actors are still "visible". 00106 class opacity_no_actor : public opacity_func 00107 { 00108 public: 00109 CLONE(opacity_no_actor) 00110 00111 opacity_type operator()(const coord_def& p) const; 00112 }; 00113 static opacity_no_actor opc_no_actor; 00114 00115 // Subclasses of this are passed to losight() to modify the 00116 // LOS calculation. Implementations will have to translate between 00117 // relative coordinates (-8,-8)..(8,8) and real coordinates, 00118 // specify how opaque the cells are and determine what values 00119 // are written to the visible cells. 00120 class los_param 00121 { 00122 public: 00123 virtual ~los_param() {} 00124 00125 // Whether the translated coordinate lies within the map 00126 // (including boundary) and within the LOS area 00127 virtual bool los_bounds(const coord_def& p) const = 0; 00128 00129 virtual opacity_type opacity(const coord_def& p) const = 0; 00130 }; 00131 00132 #endif