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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
float fsnap(float val,float fsize)
{
return rint(val / fsize) * fsize;
}
vector vsnap(vector point,float fsize)
{
vector vret;
vret_x = rint(point_x / fsize) * fsize;
vret_y = rint(point_y / fsize) * fsize;
vret_z = ceil(point_z / fsize) * fsize;
return vret;
}
float location_isok(vector point, float water_isok, float air_isok)
{
float pc,pc2;
if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
return 0;
pc = pointcontents(point);
pc2 = pointcontents(point - '0 0 1');
switch(pc)
{
case CONTENT_SOLID:
break;
case CONTENT_SLIME:
break;
case CONTENT_LAVA:
break;
case CONTENT_SKY:
break;
case CONTENT_EMPTY:
if (pc2 == CONTENT_SOLID)
return 1;
if (pc2 == CONTENT_EMPTY)
if(air_isok)
return 1;
if (pc2 == CONTENT_WATER)
if(water_isok)
return 1;
break;
case CONTENT_WATER:
if (water_isok)
return 1;
break;
}
return 0;
}
entity pathlib_nodeatpoint(vector where)
{
entity node;
++pathlib_searched_cnt;
where_x = fsnap(where_x,pathlib_gridsize);
where_y = fsnap(where_y,pathlib_gridsize);
node = findradius(where,pathlib_gridsize * 0.5);
while(node)
{
if(node.is_path_node == TRUE)
return node;
node = node.chain;
}
return world;
}
float tile_check_cross(vector where)
{
vector p,f,r;
f = PLIB_FORWARD * tile_check_size;
r = PLIB_RIGHT * tile_check_size;
// forward-right
p = where + f + r;
traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
if not (location_isok(trace_endpos,1,0))
return 0;
// Forward-left
p = where + f - r;
traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
if not (location_isok(trace_endpos,1,0))
return 0;
// Back-right
p = where - f + r;
traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
if not (location_isok(trace_endpos,1,0))
return 0;
//Back-left
p = where - f - r;
traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
if not (location_isok(trace_endpos,1,0))
return 0;
return 1;
}
float tile_check_plus(vector where)
{
vector p,f,r;
f = PLIB_FORWARD * tile_check_size;
r = PLIB_RIGHT * tile_check_size;
// forward
p = where + f;
traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
if not (location_isok(trace_endpos,1,0))
return 0;
//left
p = where - r;
traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
if not (location_isok(trace_endpos,1,0))
return 0;
// Right
p = where + r;
traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
if not (location_isok(trace_endpos,1,0))
return 0;
//Back
p = where - f;
traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self);
if not (location_isok(trace_endpos,1,0))
return 0;
return 1;
}
float tile_check_star(vector where)
{
if(tile_check_plus(where))
return tile_check_cross(where);
return 0;
}
|