コード例 #1
0
ファイル: monmove.cpp プロジェクト: Oddzball/Cataclysm-DDA
/*
 * Return valid points of an area extending 1 tile to either side and (maxdepth) tiles behind basher,
 * taking blocking into account, only if basher is directly infront of bashee
 */
std::vector<point> get_bashing_zone( point bashee, point basher, int maxdepth ) {
    std::vector<point> ret;
    maxdepth++;
    int diffx = basher.x - bashee.x;
    int diffy = basher.y - bashee.y;
    bool blocked[3] = { false, false, false };
    if ( diffx == 0 || diffy == 0 ) { // not directly adjacent to target? bail
        for(int offside=0; offside < 3; offside++) {
            for(int offdepth = 0; offdepth < maxdepth; offdepth++) {
                point hpos(0,0);
                if ( diffx == 0 ) { // vertical
                    hpos = point(basher.x - 1 + offside, basher.y + ( offdepth * diffy ));
                } else { // horizontal
                    hpos = point(basher.x + ( offdepth * diffx ), basher.y - 1 + offside );
                }
                if ( hpos.x != basher.x || hpos.y != basher.y ) { // zeds are beyond self-help
                    if ( g->m.move_cost(hpos.x, hpos.y) == 0 ) { // there's a wall or such here
                        blocked[offside] = true;
                    }
                    if ( blocked[offside] == false ) { // mobs behind walls are not helpful
                        // g->add_msg("bzone += %d,%d",hpos.x,hpos.y);
                        ret.push_back( hpos );
                    }
                }
            }
        }
    }
    return ret;
}
コード例 #2
0
ファイル: lib.c プロジェクト: BackupTheBerlios/freenx-svn
void hexdump(direction d, int fd, unsigned char *p, int n)
{
    register int l=0;
    char buf[78];
    unsigned char c;
#define hpos(x) (3*(x)+(((x)>7)?2:1))
#define apos(x) ((x)+60) /* (x+((x>7)?60:59)) */
#define hdigit(x) (((x)>9)?((x)-10+'a'):((x)+'0'))

    memset(buf, ' ', 77);
    buf[77]='\0';
    printf("%s %d:\n", (d==d_from) ? "From" : "To", fd);
    while (n-->0) {
	c=(unsigned char)*p++;
	buf[hpos(l)]   = hdigit(c>>4);
	buf[hpos(l)+1] = hdigit(c&15);
	buf[apos(l)] = (c<32||c>126) ? '.' : c;
	if (++l>15) {
	    puts(buf);
	    memset(buf, ' ', 77);
	    l=0;
	}
    }
    puts(buf);

#undef hpos
#undef apos
#undef hdigit
}