int find_ball_area( int x, int y, int *green_c ) { int area = 1; if( IS_COLOR( 3*x, y, ORANGE ) ) correct_c++; if( x < b_min_x ) b_min_x = x; if( x > b_max_x ) b_max_x = x; if( y < b_min_y ) b_min_y = y; if( y > b_max_y ) b_max_y = y; // Märgime läbitud pikslid ära data[ y ] [ 3*x + 0 ] = 255; data[ y ] [ 3*x + 1 ] = 0; data[ y ] [ 3*x + 2 ] = 0; // Laieneme rekursiivselt kõrvalasuvatesse samavärvi pikslitesse if( x > 0 && IS_AD_COLOR( 3*(x-1), y, ORANGE ) ) area += find_ball_area( x-1, y, green_c ); if( x < gwidth-1 && IS_AD_COLOR( 3*(x+1), y, ORANGE ) ) area += find_ball_area( x+1, y, green_c ); if( y > 0 && IS_AD_COLOR( 3*x, y-1, ORANGE ) ) area += find_ball_area( x, y-1, green_c ); if( y < gheight-1 && IS_AD_COLOR( 3*x, y+1, ORANGE ) ) area += find_ball_area( x, y+1, green_c ); // Kontrollime rohelisi piksleid if( x > 30 && IS_COLOR( 3*(x-10), y , GREEN ) ) (*green_c)++; if( x < gwidth-30 && IS_COLOR( 3*(x+10), y , GREEN ) ) (*green_c)++; if( y > 10 && IS_COLOR( 3*x, y-10 , GREEN ) ) (*green_c)++; return area; }
bool check_for_line( int x, int y, int b_min_x, int b_max_x ) { float m; float b; int new_x, new_y; int last[5] = { 0, 0, 0, 0, 0 }; int cur = 0; int white_c, black_c; int cur_x; bool gr_chk = false; for( int k = 0; k < 3; k++ ) { if( k == 0 ) cur_x = x; if( k == 1 ) cur_x = b_min_x; if( k == 2 ) cur_x = b_max_x; // Leian joone võrrandi if( y == gheight ) return false; m = (float) ( gwidth/2 - cur_x ) / (float) ( gheight - y ); b = (float) cur_x - m*(float)y; gr_chk = false; for( int i = y; i < gheight; i++ ) { black_c = 0; white_c = 0; new_y = i; new_x = int ( m*i + b ); if( !gr_chk ){ if ( IS_COLOR( 3*new_x, new_y, GREEN ) ) gr_chk = true; } else { if( IS_COLOR( 3*new_x, new_y, WHITE ) ) last[cur] = WHITE; else if( IS_COLOR( 3*new_x, new_y, BLACK ) ) last[cur] = BLACK; else last[cur] = 0; if( cur < 4 ) cur++; else cur = 0; for( int j = 0; j < 5; j++ ) { if( last[j] == WHITE ) white_c++; else if( last[j] == BLACK ) black_c++; } if( black_c > 0 && white_c > 0 ) return true; } } } return false; }
int find_gate_area( int x, int y, int color ) { int area = 1; // Väravatuvastuse jaoks vajalik, nende järgi saab keskpunkti leida if( x < g_min_x ) g_min_x = x; if( x > g_max_x ) g_max_x = x; if( y < g_min_y ) g_min_y = y; if( y > g_max_y ) g_max_y = y; if( y > gate_min_low[ x / 5 ] ) gate_min_low[ x / 5 ] = y; if( IS_COLOR( 3*x, y, color ) ) correct_c++; // Märgime läbitud pikslid ära data[ y ] [ 3*x + 0 ] = 255; data[ y ] [ 3*x + 1 ] = 0; data[ y ] [ 3*x + 2 ] = 0; // Laieneme rekursiivselt kõrvalasuvatesse samavärvi pikslitesse if( x > 4 && IS_AD_COLOR( 3*(x-5), y, color ) ) area += find_gate_area( x-5, y, color ); if( x < gwidth-5 && IS_AD_COLOR( 3*(x+5), y, color ) ) area += find_gate_area( x+5, y, color ); if( y > 4 && IS_AD_COLOR( 3*x, y-5, color ) ) area += find_gate_area( x, y-5, color ); if( y < gheight-5 && IS_AD_COLOR( 3*x, y+5, color ) ) area += find_gate_area( x, y+5, color ); return area; }
/* * @brief Draws at most len chars or size bytes of the specified string. Color escape * sequences are not visible chars. Returns the number of chars drawn. */ size_t R_DrawSizedString(r_pixel_t x, r_pixel_t y, const char *s, size_t len, size_t size, int32_t color) { size_t i, j; i = j = 0; while (*s && i < len && j < size) { if (IS_COLOR(s)) { // color escapes color = *(s + 1) - '0'; j += 2; s += 2; continue; } if (IS_LEGACY_COLOR(s)) { // legacy colors color = CON_COLOR_ALT; j++; s++; continue; } R_DrawChar(x, y, *s, color); x += r_draw.font->char_width; // next char position in line i++; j++; s++; } return i; }
/** * @brief */ static void Sv_DrawConsole_Buffer(void) { char *lines[sv_console.height]; const size_t count = Con_Tail(&sv_console, lines, sv_console.height); size_t row = sv_console.height; for (size_t i = 0; i < count; i++) { const size_t j = count - i - 1; char *line = lines[j]; char *s = line; Sv_DrawConsole_Color(j ? StrrColor(lines[j - 1]) : CON_COLOR_DEFAULT); size_t col = 1; while (*s) { if (IS_LEGACY_COLOR(s)) { Sv_DrawConsole_Color(CON_COLOR_ALT); } else if (IS_COLOR(s)) { Sv_DrawConsole_Color(*(s + 1) - '0'); s++; } else if (isascii(*s)) { mvaddch((int32_t) row, (int32_t) col++, *s); } s++; } g_free(line); row--; } Sv_DrawConsole_Color(CON_COLOR_DEFAULT); }
void black_ch() { for(int i=gheight-1; i>=0; i--) for(int j=gwidth-3; j>=0; j--) { if( IS_COLOR( 3*j, i, YELLOW ) ) { data [i][3*j + 0 ] = 0; data [i][3*j + 1 ] = 255; data [i][3*j + 2 ] = 0; } } }
static void set_entity_color( void ) { Group group; load_group( &group ); if( IS_COLOR( group ) ) header.color = atoi( group.value ); else error( "Bad color group" ); if( setup.verbose ) message( " ENTITY color: %hu", header.color ); }
void detect_gate( int *x, int *y, int *x1, int *y1, int *x2, int *y2, int color ) { int g_area; float aspect; double color_coef; *x = -1; *y = -1; for( int i = 0; i < gwidth-1; i += 20 ) { for( int j = gheight-1; j >= 0; j -= 20 ) { if( IS_AD_COLOR( 3*i, j, color ) ) { g_min_x = gwidth; g_max_x = 0; g_min_y = gheight; g_max_y = 0; correct_c = 0; memset( gate_min_low, 0, sizeof(gate_min_low) ); g_area = find_gate_area( i, j, color ); if( g_min_y != g_max_y ) aspect = (float) (g_max_x - g_min_x) / (g_max_y - g_min_y); else aspect = 0.0f; if( g_area > 20 && aspect > 0.5f && aspect < 7.0 && ( (double)correct_c / (double)g_area ) > 0.025 ) { if( color == BLUE ) color_coef = 1.5; else color_coef = 2.0; double min_area; if(g_max_y < 200) min_area = (0.3289*pow((double)g_max_y, 1.6197)) / (1.5*color_coef); else min_area = (0.3289*pow((double)g_max_y, 1.6197)) / (4.0*color_coef); double max_area = (0.3289*pow((double)g_max_y, 1.6197)) * 1.2; printf("%f\n", min_area); if( g_area < min_area || g_area > max_area ) break; *x = g_min_x + ( g_max_x - g_min_x ) / 2; *y = g_max_y; *x1 = g_min_x; *y1 = gate_min_low[ g_min_x / 5 + 2 ]; *x2 = g_max_x; *y2 = gate_min_low[ g_max_x / 5 - 2 ]; draw_gate_lines(); draw_dot( *x, *y ); if( *x1 > 5 && *x1 < gwidth - 5 && *y1 > 5 && *y1 < gheight - 5 ) draw_dot( *x1, *y1 ); if( *x2 > 5 && *x2 < gwidth - 5 && *y2 > 5 && *y2 < gheight - 5 ) draw_dot( *x2, *y2 ); return; } else break; } if( !(IS_COLOR( 3*i, j, GREEN )) && !(IS_COLOR( 3*i, j, WHITE )) && !(IS_COLOR( 3*i, j, BLACK )) ) break; /*data[j][3*i+0] = 255; data[j][3*i+1] = 255; data[j][3*i+2] = 255;*/ } } }
/* * G_ClientUserInfoChanged */ void G_ClientUserInfoChanged(g_edict_t *ent, const char *user_info) { const char *s; char *c; char name[MAX_NET_NAME]; int player_num, i; boolean_t color; g_client_t *cl; // check for malformed or illegal info strings if (!ValidateUserInfo(user_info)) { user_info = "\\name\\newbie\\skin\\qforcer/enforcer"; } cl = ent->client; // set name, use a temp buffer to compute length and crutch up bad names s = GetUserInfo(user_info, "name"); strncpy(name, s, sizeof(name) - 1); name[sizeof(name) - 1] = 0; color = false; c = name; i = 0; // trim to 15 printable chars while (i < 15) { if (!*c) break; if (IS_COLOR(c)) { color = true; c += 2; continue; } c++; i++; } name[c - name] = 0; if (!i) // name had nothing printable strcpy(name, "newbie"); if (color) // reset to white strcat(name, "^7"); if (strncmp(cl->persistent.net_name, name, sizeof(cl->persistent.net_name))) { if (*cl->persistent.net_name != '\0') gi.BroadcastPrint(PRINT_MEDIUM, "%s changed name to %s\n", cl->persistent.net_name, name); strncpy(cl->persistent.net_name, name, sizeof(cl->persistent.net_name) - 1); cl->persistent.net_name[sizeof(cl->persistent.net_name) - 1] = 0; } #ifdef HAVE_MYSQL if(mysql != NULL) { // escape name for safe db insertions StripColor(cl->persistent.net_name, name); mysql_real_escape_string(mysql, name, cl->persistent.sql_name, sizeof(cl->persistent.sql_name)); } #endif // set skin if ((g_level.teams || g_level.ctf) && cl->persistent.team) // players must use team_skin to change s = cl->persistent.team->skin; else s = GetUserInfo(user_info, "skin"); if (*s != '\0') // something valid-ish was provided strncpy(cl->persistent.skin, s, sizeof(cl->persistent.skin) - 1); else { strcpy(cl->persistent.skin, "qforcer/enforcer"); cl->persistent.skin[sizeof(cl->persistent.skin) - 1] = 0; } // set color s = GetUserInfo(user_info, "color"); cl->persistent.color = ColorByName(s, 243); player_num = ent - g_game.edicts - 1; // combine name and skin into a config_string gi.ConfigString(CS_CLIENT_INFO + player_num, va("%s\\%s", cl->persistent.net_name, cl->persistent.skin)); // save off the user_info in case we want to check something later strncpy(ent->client->persistent.user_info, user_info, sizeof(ent->client->persistent.user_info) - 1); }