int command_unmark_special(char *text, int len, int do_log) { int i; while (isspace(*text)) text++; if(*text) { for (i = 0; i < max_mark; i ++) { if (my_strcompare(marks[i].text, text) && (marks[i].x != -1) && !marks[i].server_side) { char str[512]; marks[i].x = marks[i].y = -1; if (do_log) { safe_snprintf(str, sizeof(str), unmarked_str, marks[i].text); LOG_TO_CONSOLE(c_orange1, str); } save_markings(); load_map_marks(); // simply to compact the array and make room for new marks break; } } } return 1; }
int put_mark_on_position(int map_x, int map_y, char * name) { if (map_x < 0 || map_x >= tile_map_size_x*6 || map_y < 0 || map_y >= tile_map_size_y*6 || max_mark>=MAX_USER_MARKS) { return 0; } marks[max_mark].x = map_x; marks[max_mark].y = map_y; memset(marks[max_mark].text,0,sizeof(marks[max_mark].text)); my_strncp(marks[max_mark].text,name,sizeof(marks[max_mark].text)); marks[max_mark].text[strlen(marks[max_mark].text)]=0; marks[max_mark].server_side=0; marks[max_mark].r=curmark_r; marks[max_mark].g=curmark_g; marks[max_mark].b=curmark_b; max_mark++; save_markings(); return 1; }
void delete_mark_on_map_on_mouse_position() { int min_mouse_x = (window_width-hud_x)/6; int min_mouse_y = 0; int mx , my , i; int max_mouse_x = min_mouse_x+((window_width-hud_x)/1.5); int max_mouse_y = window_height - hud_y; int screen_map_width = max_mouse_x - min_mouse_x; int screen_map_height = max_mouse_y - min_mouse_y; int min_distance; marking * closest_mark; // FIXME (Malaclypse): should be moved above the screen_map_* init, to avoid additional computation if (mouse_x < min_mouse_x || mouse_x > max_mouse_x || mouse_y < min_mouse_y || mouse_y > max_mouse_y) { return; } mx = ((mouse_x - min_mouse_x) * tile_map_size_x * 6) / screen_map_width; my = (tile_map_size_y * 6) - ((mouse_y * tile_map_size_y * 6) / screen_map_height); // delete mark closest to cursor min_distance = 20*20; // only check close marks closest_mark = NULL; for ( i = 0 ; i < max_mark ; i ++ ) { int distance, dx, dy; marking * const mark = &marks[i]; // skip masked marks if (mark->x < 0 || mark->server_side) continue; // get mark to cursor distance (squared) dx = mark->x - mx; dy = mark->y - my; distance = dx*dx + dy*dy; // prefer deleting closer and newer marks if (distance <= min_distance) { // found a closer mark closest_mark = mark; min_distance = distance; } } if (closest_mark != NULL) { // we found a close mark closest_mark->x = -1 ; closest_mark->y = -1 ; } save_markings(); load_map_marks(); // simply to compact the array and make room for new marks }
int command_unmark(char *text, int len) { int i; while (isspace(*text)) text++; if(*text) { for (i = 0; i < max_mark; i ++) { if (my_strcompare(marks[i].text, text) && (marks[i].x != -1) && !marks[i].server_side) { char str[512]; marks[i].x = marks[i].y = -1; save_markings(); safe_snprintf(str, sizeof(str), unmarked_str, marks[i].text); LOG_TO_CONSOLE(c_orange1, str); break; } } } return 1; }