static Uint32 pf_movement_timer_callback(Uint32 interval, void* UNUSED(param)) { SDL_Event e; e.type = SDL_USEREVENT; e.user.code = EVENT_MOVEMENT_TIMER; SDL_PushEvent(&e); if (get_our_actor()) return get_our_actor()->step_duration * 10; else return interval; }
void print_items(void) { int i; actor *me; me = get_our_actor(); if (me) if(me->fighting) { LOG_TO_CONSOLE(c_red1, "You can't do this during combat!"); return; } /* request the description for each item */ number_to_print = next_item_to_print = 0; printing_category = selected_category; for (i = 0; i < no_storage && i < STORAGE_ITEMS_SIZE; i++) { if (storage_items[i].quantity) { Uint8 str[3]; print_quanities[number_to_print++] = storage_items[i].quantity; str[0]=LOOK_AT_STORAGE_ITEM; *((Uint16*)(str+1))=SDL_SwapLE16(storage_items[i].pos); my_tcp_send(my_socket, str, 3); } } }
int pf_find_path(int x, int y) { actor *me; int i; int attempts= 0; pf_destroy_path(); me = get_our_actor(); if (!me) return -1; pf_src_tile = pf_get_tile(me->x_tile_pos, me->y_tile_pos); pf_dst_tile = pf_get_tile(x, y); if (!pf_dst_tile || pf_dst_tile->z == 0) return 0; for (i = 0; i < tile_map_size_x*tile_map_size_y*6*6; i++) { pf_tile_map[i].state = PF_STATE_NONE; pf_tile_map[i].parent = NULL; } pf_open.tiles = calloc(tile_map_size_x*tile_map_size_y*6*6, sizeof(PF_TILE*)); pf_open.count = 0; pf_add_tile_to_open_list(NULL, pf_src_tile); while ((pf_cur_tile = pf_get_next_open_tile()) && attempts++ < MAX_PATHFINDER_ATTEMPTS) { if (pf_cur_tile == pf_dst_tile) { pf_follow_path = 1; pf_movement_timer_callback(0, NULL); pf_movement_timer = SDL_AddTimer(me->step_duration * 10, pf_movement_timer_callback, NULL); break; } pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x, pf_cur_tile->y+1)); pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x+1, pf_cur_tile->y+1)); pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x+1, pf_cur_tile->y)); pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x+1, pf_cur_tile->y-1)); pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x, pf_cur_tile->y-1)); pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x-1, pf_cur_tile->y-1)); pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x-1, pf_cur_tile->y)); pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x-1, pf_cur_tile->y+1)); } free(pf_open.tiles); return pf_follow_path; }
int put_mark_on_current_position(const char *name) { actor *me = get_our_actor (); if (me != NULL) { if (put_mark_on_position(me->x_tile_pos, me->y_tile_pos, name)) return 1; } return 0; }
// On a regular basis, send the "#save" command to the server and save local data. // void auto_save_local_and_server(void) { time_t time_delta = 60 * 90; actor *me; me = get_our_actor(); if(!disconnected && me && !me->fighting && ((last_save_time + time_delta) <= time(NULL))) { last_save_time = time(NULL); save_local_data(NULL, 0); send_input_text_line("#save", 5); } }
void update_session_distance(void) { static int last_x = -1, last_y = -1; actor *me = get_our_actor (); if (me == NULL) return; if ((me->x_tile_pos != last_x) || (me->y_tile_pos != last_y)) { last_x = me->x_tile_pos; last_y = me->y_tile_pos; distance_moved++; } }
void display_map_marks(){ actor *me; float x,y,z; int i,ax,ay; float dx = (TILESIZE_X / 6); float dy = (TILESIZE_Y / 6); float fr = mark_z_rot/360; float j,ff=0; me = get_our_actor(); if(!me) return; ax = me->x_pos; ay = me->y_pos; glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_ALPHA_TEST); for(i=0;i<max_mark;i++){ x=marks[i].x/2.0; y=marks[i].y/2.0; x += (TILESIZE_X / 2); y += (TILESIZE_Y / 2); if(DST(ax,ay,x,y)>MARK_DIST||marks[i].x<0||!marks_3d) continue; z = get_tile_height(marks[i].x, marks[i].y); for(j=z-fr/5,ff=1;j<z+2;j+=0.1,ff=(2-(j-z))/2) { if(marks[i].server_side) glColor4f(0.0f, 0.0f, 1.0f, 0.9f-(j-z)/3); else glColor4f((float)marks[i].r/255, (float)marks[i].g/255, (float)marks[i].b/255, 0.7f-(j-z)/3); glBegin(GL_QUADS); glVertex3f(x-dx*ff,y-dy*ff,j); glVertex3f(x-dx*ff,y+dy*ff,j); glVertex3f(x+dx*ff,y+dy*ff,j); glVertex3f(x+dx*ff,y-dy*ff,j); glEnd(); } } glDisable(GL_ALPHA_TEST); //glEnable(GL_LIGHTING); glDisable(GL_BLEND); glEnable(GL_TEXTURE_2D); }
void put_mark_on_current_position(char *name) { actor *me = get_our_actor (); if (me != NULL) { put_mark_on_position(me->x_tile_pos, me->y_tile_pos, name); /* Lachesis: reusing available code marks[max_mark].x = me->x_tile_pos; marks[max_mark].y = me->y_tile_pos; memset(marks[max_mark].text,0,500); my_strncp(marks[max_mark].text,name,500); marks[max_mark].text[strlen(marks[max_mark].text)]=0; max_mark++; save_markings(); */ } }
/* * Handler for clicks into minimap. Coordinates are given as window pixels with origin at bottom-left corner */ static int minimap_walkto(int mx, int my) { float fmx = mx, fmy = my; actor *me; if ( (me = get_our_actor ()) == NULL) return 0; rotate_click_coords(&fmx,&fmy); fmx = me->x_tile_pos - minimap_tiles_distance + minimap_tiles_distance * 2 * fmx/float_minimap_size; fmy = me->y_tile_pos - minimap_tiles_distance + minimap_tiles_distance * 2 * fmy/float_minimap_size; /* Do path finding */ if (pf_find_path(fmx, fmy)) { return 1; } return 0; }
void draw_game_map (int map, int mouse_mini) { int screen_x=0; int screen_y=0; int x=-1,y=-1; float x_size=0,y_size=0; GLuint map_small, map_large; actor *me; static int fallback_text = -1; // if we don't have a continent texture (instance may be), fallback to blank paper if (cont_text < 0) { if (fallback_text < 0) #ifdef NEW_TEXTURES { fallback_text = load_texture_cached("./textures/paper1", tt_gui); } #else /* NEW_TEXTURES */ fallback_text = load_texture_cache ("./textures/paper1.bmp", 0); #endif /* NEW_TEXTURES */ cont_text = fallback_text; } if(map){ #ifdef NEW_TEXTURES map_small = cont_text; #else /* NEW_TEXTURES */ map_small=get_texture_id(cont_text); #endif /* NEW_TEXTURES */ if(inspect_map_text == 0) { map_large=map_text; } else { map_large = inspect_map_text; } } else { map_small=map_text; #ifdef NEW_TEXTURES map_large = cont_text; #else /* NEW_TEXTURES */ map_large=get_texture_id(cont_text); #endif /* NEW_TEXTURES */ if(cur_map!=-1){ x_size = ((float)(continent_maps[cur_map].x_end - continent_maps[cur_map].x_start)) / tile_map_size_x; y_size = ((float)(continent_maps[cur_map].y_end - continent_maps[cur_map].y_start)) / tile_map_size_y; } else { x_size=y_size=0; } } glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glViewport(0, 0 + hud_y, window_width-hud_x, window_height-hud_y); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(300, (GLdouble)0, (GLdouble)0, 200, -250.0, 250.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glDisable(GL_TEXTURE_2D); glColor3f(0.0f, 0.0f, 0.0f); glBegin(GL_QUADS); glVertex2i(0, 0); glVertex2i(300, 0); glVertex2i(300, 200); glVertex2i(0, 200); glEnd(); glEnable(GL_TEXTURE_2D); glColor3f(1.0f,1.0f,1.0f); #ifdef NEW_TEXTURES bind_texture(map_large); glBegin(GL_QUADS); glTexCoord2f(1.0f, 1.0f); glVertex3i(50,0,0); glTexCoord2f(1.0f, 0.0f); glVertex3i(50,200,0); glTexCoord2f(0.0f, 0.0f); glVertex3i(250,200,0); glTexCoord2f(0.0f, 1.0f); glVertex3i(250,0,0); glEnd(); #else /* NEW_TEXTURES */ bind_texture_id(map_large); glBegin(GL_QUADS); glTexCoord2f(1.0f,0.0f); glVertex3i(50,0,0); glTexCoord2f(1.0f,1.0f); glVertex3i(50,200,0); glTexCoord2f(0.0f,1.0f); glVertex3i(250,200,0); glTexCoord2f(0.0f,0.0f); glVertex3i(250,0,0); glEnd(); #endif /* NEW_TEXTURES */ if (mouse_mini) glColor4f (1.0f, 1.0f, 1.0f, 1.0f); else glColor4f (0.7f, 0.7f, 0.7f, 0.7f); glEnable(GL_ALPHA_TEST); #ifdef NEW_TEXTURES bind_texture(map_small); glBegin(GL_QUADS); glTexCoord2f(1.0f, 1.0f); glVertex3i(250,150,0); glTexCoord2f(1.0f, 0.0f); glVertex3i(250,200,0); glTexCoord2f(0.0f, 0.0f); glVertex3i(300,200,0); glTexCoord2f(0.0f, 1.0f); glVertex3i(300,150,0); glEnd(); #else /* NEW_TEXTURES */ bind_texture_id(map_small); glBegin(GL_QUADS); glTexCoord2f(1.0f,0.0f); glVertex3i(250,150,0); glTexCoord2f(1.0f,1.0f); glVertex3i(250,200,0); glTexCoord2f(0.0f,1.0f); glVertex3i(300,200,0); glTexCoord2f(0.0f,0.0f); glVertex3i(300,150,0); glEnd(); #endif /* NEW_TEXTURES */ glDisable(GL_ALPHA_TEST); glColor3f(1.0f,1.0f,1.0f); #ifdef NEW_TEXTURES bind_texture(legend_text); glBegin(GL_QUADS); glTexCoord2f(1.0f, 1.0f); glVertex3i(250,50,0); glTexCoord2f(1.0f, 0.0f); glVertex3i(250,150,0); glTexCoord2f(0.0f, 0.0f); glVertex3i(300,150,0); glTexCoord2f(0.0f, 1.0f); glVertex3i(300,50,0); glEnd(); #else /* NEW_TEXTURES */ get_and_set_texture_id(legend_text); glBegin(GL_QUADS); glTexCoord2f(1.0f,0.0f); glVertex3i(250,50,0); glTexCoord2f(1.0f,1.0f); glVertex3i(250,150,0); glTexCoord2f(0.0f,1.0f); glVertex3i(300,150,0); glTexCoord2f(0.0f,0.0f); glVertex3i(300,50,0); glEnd(); #endif /* NEW_TEXTURES */ // this is necessary for the text over map // need to execute this for any map now // because of the coordinate display - Lachesis if(map/*&&(adding_mark||max_mark>0)*/){ glViewport(0, 0 + hud_y, window_width-hud_x, window_height-hud_y); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho((GLdouble)0, (GLdouble)300, (GLdouble)200, (GLdouble)0, -250.0, 250.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); // Draw help for toggling the mini-map { char buf[80]; char keybuf[20]; glEnable(GL_TEXTURE_2D); safe_snprintf(buf, sizeof(buf), "%s %s", win_minimap, get_key_string(K_MINIMAP, keybuf, sizeof(keybuf))); glColor3f (1.0f, 1.0f, 0.0f); draw_string_zoomed(25 - 1.5*strlen(buf), 150 + 43, (const unsigned char *)buf, 1, 0.3); } // draw a temporary mark until the text is entered if (adding_mark) { int x = mark_x; int y = mark_y; screen_x=(51+200*x/(tile_map_size_x*6)); screen_y=201-200*y/(tile_map_size_y*6); glColor3f(1.0f,1.0f,0.0f); glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); glVertex2i(screen_x-9*mapmark_zoom,screen_y-9*mapmark_zoom); glVertex2i(screen_x+6*mapmark_zoom,screen_y+6*mapmark_zoom); glVertex2i(screen_x+6*mapmark_zoom,screen_y-9*mapmark_zoom); glVertex2i(screen_x-9*mapmark_zoom,screen_y+6*mapmark_zoom); glEnd(); glEnable(GL_TEXTURE_2D); glColor3f(1.0f,1.0f,0.0f); draw_string_zoomed (screen_x, screen_y, (unsigned char*)input_text_line.data, 1, mapmark_zoom); } draw_mark_filter(); if(inspect_map_text == 0) { draw_marks(marks, max_mark, tile_map_size_x, tile_map_size_y); draw_coordinates(tile_map_size_x, tile_map_size_y); } else { draw_marks(temp_marks, max_temp_mark, temp_tile_map_size_x, temp_tile_map_size_y); draw_coordinates(temp_tile_map_size_x, temp_tile_map_size_y); } } //if we're following a path, draw the destination on the map if (pf_follow_path && inspect_map_text == 0) { int px = pf_dst_tile->x; int py = pf_dst_tile->y; if (!map) { if (cur_map!=-1) { screen_x = 300 - (50 + 200 * ( (px * x_size / 6) + continent_maps[cur_map].x_start) / 512); screen_y = 200 * ( (py * y_size / 6) + continent_maps[cur_map].y_start) / 512; } else { screen_x = screen_y = 0; } } else { screen_x=51 +200*px/(tile_map_size_x*6); screen_y=201-200*py/(tile_map_size_y*6); } glColor3f(1.0f,0.0f,0.0f); glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); glVertex2i(screen_x-9*mapmark_zoom,screen_y-9*mapmark_zoom); glVertex2i(screen_x+6*mapmark_zoom,screen_y+6*mapmark_zoom); glVertex2i(screen_x+6*mapmark_zoom,screen_y-9*mapmark_zoom); glVertex2i(screen_x-9*mapmark_zoom,screen_y+6*mapmark_zoom); glEnd(); } //ok, now let's draw our possition... if ( (me = get_our_actor ()) != NULL && inspect_map_text == 0) { x = me->x_tile_pos; y = me->y_tile_pos; } else { //We don't exist (usually happens when teleporting) x = -1; y = -1; } if (!map) { if (cur_map != -1) { screen_x = 300 - (50 + 200 * ( (x * x_size / 6) + continent_maps[cur_map].x_start) / 512); screen_y = 200 * ( (y * y_size / 6) + continent_maps[cur_map].y_start) / 512; } else { screen_x = screen_y = 0; } } else { screen_x=51 +200*x/(tile_map_size_x*6); screen_y=201-200*y/(tile_map_size_y*6); } if ( (map || !dungeon) && x != -1 ) { glColor3f (0.0f, 0.0f, 1.0f); glDisable (GL_TEXTURE_2D); glBegin (GL_LINES); glVertex2i(screen_x-9*mapmark_zoom,screen_y-9*mapmark_zoom); glVertex2i(screen_x+6*mapmark_zoom,screen_y+6*mapmark_zoom); glVertex2i(screen_x+6*mapmark_zoom,screen_y-9*mapmark_zoom); glVertex2i(screen_x-9*mapmark_zoom,screen_y+6*mapmark_zoom); glEnd(); } if(!map && show_continent_map_boundaries && cont_text!=fallback_text) { int i; /* Convert mouse coordinates to map coordinates (stolen from pf_get_mouse_position()) */ int min_mouse_x = (window_width-hud_x)/6; int min_mouse_y = 0; 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 m_px = ((mouse_x-min_mouse_x) * 512) / screen_map_width; int m_py = 512 - ((mouse_y * 512) / screen_map_height); int mouse_over = -1; glColor3f (0.267f, 0.267f, 0.267f); glDisable (GL_TEXTURE_2D); glBegin(GL_LINES); /* Draw borders for the maps except the one with the mouse over it */ glColor3f (0.267f, 0.267f, 0.267f); for(i = 0; continent_maps[i].name != NULL; i++) { if(continent_maps[i].cont == continent_maps[cur_map].cont) { if(!mouse_mini && mouse_over == -1 && m_px > continent_maps[i].x_start && m_px < continent_maps[i].x_end && m_py > continent_maps[i].y_start && m_py < continent_maps[i].y_end) { /* Mouse over this map */ mouse_over = i; } else { int x_start = 300-(50+200*continent_maps[i].x_start/512); int x_end = 300-(50+200*continent_maps[i].x_end/512); int y_start = 200*continent_maps[i].y_start / 512; int y_end = 200*continent_maps[i].y_end / 512; glVertex2i(x_start, y_start); glVertex2i(x_start, y_end); glVertex2i(x_start, y_end); glVertex2i(x_end, y_end); glVertex2i(x_end, y_end); glVertex2i(x_end, y_start); glVertex2i(x_end, y_start); glVertex2i(x_start, y_start); } } } /* Draw border for the map with the mouse over it */ if(mouse_over >= 0) { float flash_effect_colour = 0.90f - sin((float)SDL_GetTicks()/100.0f) / 10.0f; int x_start = 300-(50+200*continent_maps[mouse_over].x_start/512); int x_end = 300-(50+200*continent_maps[mouse_over].x_end/512); int y_start = 200*continent_maps[mouse_over].y_start / 512; int y_end = 200*continent_maps[mouse_over].y_end / 512; glColor3f(flash_effect_colour, flash_effect_colour, flash_effect_colour); glVertex2i(x_start, y_start); glVertex2i(x_start, y_end); glVertex2i(x_start, y_end); glVertex2i(x_end, y_end); glVertex2i(x_end, y_end); glVertex2i(x_end, y_start); glVertex2i(x_end, y_start); glVertex2i(x_start, y_start); } glEnd(); } #ifdef DEBUG_MAP_SOUND // If we are in map view (not continent view) draw the sound area boundaries if (map) { print_sound_boundaries(cur_tab_map); } #endif // DEBUG_MAP_SOUND if (map) { glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); } glEnable (GL_TEXTURE_2D); glColor3f (1.0f, 1.0f, 1.0f); glMatrixMode (GL_MODELVIEW); glPopMatrix (); glMatrixMode (GL_PROJECTION); glPopMatrix (); glMatrixMode (GL_MODELVIEW); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE }
void display_map_markers() { int ax, ay; float z,x,y; int i; GLdouble model[16],proj[16]; GLint view[4]; GLdouble hx,hy,hz; float banner_width; float font_scale = 1.0f/ALT_INGAME_FONT_X_LEN; float font_size_x=font_scale*SMALL_INGAME_FONT_X_LEN; float font_size_y=font_scale*SMALL_INGAME_FONT_Y_LEN; char tmpb[4]; actor *me; me = get_our_actor(); if(!me) return; ax = me->x_pos; ay = me->y_pos; glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetIntegerv(GL_VIEWPORT, view); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(view[0],view[2]+view[0],view[1],view[3]+view[1],0.0f,-1.0f); glDepthFunc(GL_LEQUAL); glEnable(GL_TEXTURE_2D); glColor4f(1.0,1.0,1.0,1.0); glDisable(GL_LIGHTING); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); for(i=0;i<max_mark;i++){ x=marks[i].x/2.0; y=marks[i].y/2.0; x += (TILESIZE_X / 2); y += (TILESIZE_Y / 2); if(DST(ax,ay,x,y)>MARK_DIST||marks[i].x<0||!marks_3d) continue; z = get_tile_height(marks[i].x, marks[i].y)+2.3; gluProject(x, y, z, model, proj, view, &hx, &hy, &hz); //shorten text memcpy(tmpb,marks[i].text+MARK_CLIP_POS,4); marks[i].text[MARK_CLIP_POS]=marks[i].text[MARK_CLIP_POS+1]=marks[i].text[MARK_CLIP_POS+2]='.'; marks[i].text[MARK_CLIP_POS+3]=0; banner_width = ((float)get_string_width((unsigned char*)marks[i].text)*(font_size_x*name_zoom))/2.0; draw_ortho_ingame_string(hx-banner_width, hy, hz, (unsigned char*)marks[i].text, 4, font_size_x, font_size_y); //restore text memcpy(marks[i].text+MARK_CLIP_POS,tmpb,4); } glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); //glEnable(GL_LIGHTING); glDepthFunc(GL_LESS); }
static int display_misc_handler(window_info *win) { const int scaled_5 = (int)(0.5 + win->current_scale * 5); const int scaled_28 = (int)(0.5 + win->current_scale * 28); int base_y_start = win->len_y; const float compass_u_start = (float)32/256; const float compass_v_start = (float)193/256; const float compass_u_end = (float)95/256; const float compass_v_end = 1.0f; const float needle_u_start = (float)4/256; const float needle_v_start = (float)201/256; const float needle_u_end = (float)14/256; const float needle_v_end = (float)247/256; #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE bind_texture(hud_text); // allow for transparency glEnable(GL_ALPHA_TEST);//enable alpha filtering, so we have some alpha key glAlphaFunc(GL_GREATER, 0.09f); //draw the compass base_y_start -= compass_size; glBegin(GL_QUADS); draw_2d_thing(compass_u_start, compass_v_start, compass_u_end, compass_v_end, 0, base_y_start, compass_size, base_y_start + compass_size); glEnd(); //draw the compass needle glPushMatrix(); glTranslatef(compass_size/2, base_y_start + compass_size/2, 0); glRotatef(rz, 0.0f, 0.0f, 1.0f); glBegin(GL_QUADS); draw_2d_thing(needle_u_start, needle_v_start, needle_u_end, needle_v_end, -scaled_5, -scaled_28, scaled_5, scaled_28); glEnd(); glPopMatrix(); //draw the clock if(view_analog_clock > 0) { const int scaled_4 = (int)(0.5 + win->current_scale * 4); const int scaled_6 = (int)(0.5 + win->current_scale * 6); const float clock_u_start = 0.0f; const float clock_v_start = (float)128/256; const float clock_u_end = (float)63/256; const float clock_v_end = (float)191/256; const float clock_needle_u_start = (float)21/256; const float clock_needle_v_start = (float)193/256; const float clock_needle_u_end = (float)31/256; const float clock_needle_v_end = (float)223/256; const int scaled_24 = (int)(0.5 + win->current_scale * 24); base_y_start -= analog_clock_size; // draw the clock face glBegin(GL_QUADS); draw_2d_thing(clock_u_start, clock_v_start, clock_u_end, clock_v_end,0, base_y_start, analog_clock_size, base_y_start + analog_clock_size); glEnd(); //draw the clock needle glAlphaFunc(GL_GREATER, 0.05f); glPushMatrix(); glTranslatef(analog_clock_size/2, base_y_start + analog_clock_size/2, 0); glRotatef(real_game_minute, 0.0f, 0.0f, 1.0f); glBegin(GL_QUADS); draw_2d_thing(clock_needle_u_start, clock_needle_v_start, clock_needle_u_end, clock_needle_v_end, -scaled_4, -scaled_24, scaled_6, scaled_6); glEnd(); glPopMatrix(); glDisable(GL_ALPHA_TEST); } #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE //Digital Clock if(view_digital_clock > 0) { const int scaled_6 = (int)(0.5 + win->current_scale * 6); char str[10]; if (show_game_seconds) safe_snprintf(str, sizeof(str), "%1d:%02d:%02d", real_game_minute/60, real_game_minute%60, real_game_second); else safe_snprintf(str, sizeof(str), " %1d:%02d ", real_game_minute/60, real_game_minute%60); base_y_start -= digital_clock_height; draw_string_shadowed_width(scaled_6/2, scaled_6/2 + base_y_start, (unsigned char*)str, win->len_x-scaled_6, 1,0.77f, 0.57f, 0.39f,0.0f,0.0f,0.0f); } /* if mouse over the either of the clocks - display the time & date */ if (mouse_over_clock) { char str[20]; const char *the_date = get_date(NULL); int centre_y = (view_analog_clock) ?win->len_y - compass_size - analog_clock_size/2 : base_y_start + digital_clock_height/2; safe_snprintf(str, sizeof(str), "%1d:%02d:%02d", real_game_minute/60, real_game_minute%60, real_game_second); draw_string_small_shadowed_zoomed(-win->small_font_len_x*(strlen(str)+0.5), centre_y-win->small_font_len_y, (unsigned char*)str, 1, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, win->current_scale); if (the_date != NULL) { safe_snprintf(str, sizeof(str), "%s", the_date); draw_string_small_shadowed_zoomed(-win->small_font_len_x*(strlen(str)+0.5), centre_y, (unsigned char*)str, 1, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, win->current_scale); } mouse_over_clock = 0; } /* if mouse over the compass - display the coords */ if (mouse_over_compass) { char str[12]; actor *me = get_our_actor (); if (me != NULL) { safe_snprintf(str, sizeof(str), "%d,%d", me->x_tile_pos, me->y_tile_pos); draw_string_small_shadowed_zoomed(-win->small_font_len_x*(strlen(str)+0.5), win->len_y-compass_size, (unsigned char*)str, 1, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, win->current_scale); } mouse_over_compass = 0; } /* if the knowledge bar is enabled, show progress in bar and ETA as hover over */ if (view_knowledge_bar) { char str[20]; char *use_str = idle_str; int percentage_done = 0; int x = (int)(0.5 + win->current_scale * 3); int y = base_y_start - side_stats_bar_height - ((knowledge_bar_height - side_stats_bar_height) / 2); int off = 0; if (is_researching()) { percentage_done = (int)(100 * get_research_fraction()); safe_snprintf(str, sizeof(str), "%d%%", percentage_done); use_str = str; } off = ((win->len_x - x - 1) - (win->small_font_len_x * strlen(use_str))) / 2; draw_side_stats_bar(win, x, y, 0, percentage_done, 100, 1); draw_string_small_shadowed_zoomed(x+off+gx_adjust, y+gy_adjust, (unsigned char *)use_str, 1,1.0f,1.0f,1.0f,0.0f,0.0f,0.0f, win->current_scale); if (mouse_over_knowledge_bar) { use_str = (is_researching()) ?get_research_eta_str(str, sizeof(str)) : not_researching_str; draw_string_small_shadowed_zoomed(-win->small_font_len_x* (strlen(use_str)+0.5), y+gy_adjust, (unsigned char*)use_str, 1,1.0f,1.0f,1.0f,0.0f,0.0f,0.0f, win->current_scale); mouse_over_knowledge_bar = 0; } base_y_start -= knowledge_bar_height; } /* if the timer is visible, draw it */ base_y_start -= display_timer(win, base_y_start); /* Optionally display the stats bar. If the current window size does not provide enough room, display only some skills and allow scrolling to view the rest */ if(show_stats_in_hud && have_stats) { char str[20]; int box_x = (int)(0.5 + win->current_scale * 3); int text_x = box_x + ((win->len_x - box_x - 1) - (7 * win->small_font_len_x))/2; int thestat; int y = 0; int skill_modifier; // trade the number of quickbar slots if there is not enough space for the minimum stats calc_statbar_shown(base_y_start + win->pos_y); #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE for (thestat=0; thestat<NUM_WATCH_STAT-1; thestat++) { int hover_offset = 0; /* skill skills until we have the skill displayed first */ if (thestat < first_disp_stat) continue; /* end now if we have display all we can */ if (thestat > (first_disp_stat+num_disp_stat-1)) break; if (show_statbars_in_hud) draw_side_stats_bar(win, box_x, y+1, statsinfo[thestat].skillattr->base, *statsinfo[thestat].exp, *statsinfo[thestat].next_lev, 0); safe_snprintf(str,sizeof(str),"%-3s %3i", statsinfo[thestat].skillnames->shortname, statsinfo[thestat].skillattr->base ); if (statsinfo[thestat].is_selected == 1) draw_string_small_shadowed_zoomed(text_x+gx_adjust, y+gy_adjust, (unsigned char*)str, 1,0.77f, 0.57f, 0.39f,0.0f,0.0f,0.0f, win->current_scale); else draw_string_small_shadowed_zoomed(text_x+gx_adjust, y+gy_adjust, (unsigned char*)str, 1,1.0f,1.0f,1.0f,0.0f,0.0f,0.0f, win->current_scale); if((thestat!=NUM_WATCH_STAT-2) && floatingmessages_enabled && (skill_modifier = statsinfo[thestat].skillattr->cur - statsinfo[thestat].skillattr->base) != 0){ safe_snprintf(str,sizeof(str),"%+i",skill_modifier); hover_offset = strlen(str)+1; if(skill_modifier > 0){ draw_string_small_shadowed_zoomed(-win->small_font_len_x * (strlen(str)+0.5), y+gy_adjust, (unsigned char*)str, 1,0.3f, 1.0f, 0.3f,0.0f,0.0f,0.0f, win->current_scale); } else { draw_string_small_shadowed_zoomed(-win->small_font_len_x * (strlen(str)+0.5), y+gy_adjust, (unsigned char*)str, 1,1.0f, 0.1f, 0.2f,0.0f,0.0f,0.0f, win->current_scale); } } /* if the mouse is over the stat bar, draw the XP remaining */ if (stat_mouse_is_over == thestat) { safe_snprintf(str,sizeof(str),"%li",(*statsinfo[thestat].next_lev - *statsinfo[thestat].exp)); draw_string_small_shadowed_zoomed(-win->small_font_len_x*(strlen(str)+0.5+hover_offset), y+gy_adjust, (unsigned char*)str, 1,1.0f,1.0f,1.0f,0.0f,0.0f,0.0f, win->current_scale); stat_mouse_is_over = -1; } y+=side_stats_bar_height; } base_y_start -= y; } // check if we need to resize the window if (base_y_start != 0) init_misc_display(); { static int last_window_width = -1; static int last_window_height = -1; static int last_hud_x = -1; if (window_width != last_window_width || window_height != last_window_height || last_hud_x != hud_x) { reset_cm_regions(); last_window_width = window_width; last_window_height = window_height; last_hud_x = hud_x; } } #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE return 1; }
int display_minimap_handler(window_info *win) { float zoom_multip; float size_x = float_minimap_size / (tile_map_size_x * 6); float size_y = float_minimap_size / (tile_map_size_y * 6); float px = 0.0f, py = 0.0f; actor *me; float x,y; int i; if(win->pos_x > window_width - 50) move_window(minimap_win,win->pos_id,win->pos_loc,window_width-minimap_size,win->pos_y); if(win->pos_y > window_height - 50) move_window(minimap_win,win->pos_id,win->pos_loc,win->pos_x,window_height-minimap_size); if (enable_controls) { draw_minimap_title_bar(win); enable_controls = 0; } zoom_multip = minimap_get_zoom(); if(!minimap_texture) { //there's no minimap for this map :( draw a X glTranslatef(0.0f, 16.0f, 0.0f); glPushMatrix(); glDisable(GL_TEXTURE_2D); //draw black background glColor3f(0.0f,0.0f,0.0f); glBegin(GL_POLYGON); for (i=0; i<=360; i +=10) { x = sin((i)*0.0174532925f)/2*float_minimap_size+float_minimap_size/2; y = cos((i)*0.0174532925f)/2*float_minimap_size+float_minimap_size/2; glVertex2f(x, y); } glEnd(); glPopMatrix(); draw_compass(); return 0; } //draw minimap //get player position in window coordinates if( (me = get_our_actor ()) == NULL) { //Don't know who we are? can't draw then return 0; } px = me->x_tile_pos * size_x; py = float_minimap_size - (me->y_tile_pos * size_y); glTranslatef(0.0f, 16.0f, 0.0f); glDisable(GL_TEXTURE_2D); //draw black background glColor3f(0.0f,0.0f,0.0f); glBegin(GL_POLYGON); for (i=0; i<=360; i +=10) { x = sin((i)*0.0174532925f)/2*float_minimap_size+float_minimap_size/2; y = cos((i)*0.0174532925f)/2*float_minimap_size+float_minimap_size/2; glVertex2f(x, y); } glEnd(); draw_map(win,zoom_multip, px, py); draw_actor_points(zoom_multip, px, py); #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE return 0; }
void update_camera() { const float c_delta = 0.1f; static int last_update = 0; int time_diff = cur_time - last_update; static float old_camera_x = 0; static float old_camera_y = 0; static float old_camera_z = 0; float adjust; actor *me = get_our_actor(); old_rx=rx; old_rz=rz; new_zoom_level=old_zoom_level=zoom_level; //printf("kludge: %f, hold: %f, rx: %f, rz %f, zoom: %f\n",camera_kludge, hold_camera,rx,rz,zoom_level); if (fol_cam && !fol_cam_behind) rz = hold_camera; if (me) camera_kludge = -me->z_rot; /* This is a BIG hack to not polluate the code but if this feature * is accepted and the flag is removed, all the code that * follows will have to be changed in order to get rid of * camera_rotation_duration and camera_tilt_duration. */ camera_rotation_duration = camera_rotation_speed != 0.0 ? time_diff : 0.0; camera_tilt_duration = camera_tilt_speed != 0.0 ? time_diff : 0.0; if(camera_rotation_duration > 0){ if (time_diff <= camera_rotation_duration) rz+=camera_rotation_speed*time_diff; else rz+=camera_rotation_speed*camera_rotation_duration; camera_rotation_duration-=time_diff; adjust_view++; } if(camera_x_duration > 0){ if(camera_x_speed>1E-4 || camera_x_speed<-1E-4){ if (time_diff <= camera_x_duration) camera_x-=camera_x_speed*time_diff; else camera_x-=camera_x_speed*camera_x_duration; if(fabs(camera_x-old_camera_x) >= c_delta){ adjust_view++; } } camera_x_duration-=time_diff; } if(camera_y_duration > 0){ if(camera_y_speed>1E-4 || camera_y_speed<-1E-4){ if (time_diff <= camera_y_duration) camera_y-=camera_y_speed*time_diff; else camera_y-=camera_y_speed*camera_y_duration; if(fabs(camera_y-old_camera_y) >= c_delta){ adjust_view++; } } camera_y_duration-=time_diff; } if(camera_z_duration > 0){ if(camera_z_speed>1E-4 || camera_z_speed<-1E-4){ if (time_diff <= camera_z_duration) camera_z-=camera_z_speed*time_diff; else camera_z-=camera_z_speed*camera_z_duration; if(fabs(camera_z-old_camera_z) >= c_delta){ adjust_view++; } } camera_z_duration-=time_diff; } if(camera_tilt_duration > 0) { if (time_diff <= camera_tilt_duration) rx+=camera_tilt_speed*time_diff; else rx+=camera_tilt_speed*camera_tilt_duration; camera_tilt_duration-=time_diff; adjust_view++; } if(camera_zoom_duration > 0) { if (time_diff <= camera_zoom_duration) new_zoom_level += camera_zoom_speed*(camera_zoom_dir==1?0.003f:-0.003f)*time_diff; else new_zoom_level += camera_zoom_speed*(camera_zoom_dir==1?0.003f:-0.003f)*camera_zoom_duration; camera_zoom_duration-=time_diff; adjust_view++; } else camera_zoom_speed = 1; if (camera_rotation_speed > 0.0) { camera_rotation_speed -= time_diff * camera_rotation_deceleration; if (camera_rotation_speed < 0.0) camera_rotation_speed = 0.0; } else if (camera_rotation_speed < 0.0) { camera_rotation_speed += time_diff * camera_rotation_deceleration; if (camera_rotation_speed > 0.0) camera_rotation_speed = 0.0; } if (camera_tilt_speed > 0.0) { camera_tilt_speed -= time_diff * camera_tilt_deceleration; if (camera_tilt_speed < 0.0) camera_tilt_speed = 0.0; } else if (camera_tilt_speed < 0.0) { camera_tilt_speed += time_diff * camera_tilt_deceleration; if (camera_tilt_speed > 0.0) camera_tilt_speed = 0.0; } clamp_camera(); if (ext_cam && !first_person && me && rx <= -min_tilt_angle && rx >= -max_tilt_angle) { float rot_x[9], rot_z[9], rot[9], dir[3]; float vect[3] = {0.0, 0.0, new_zoom_level*camera_distance}; int tx, ty; float tz; // we compute the camera position MAT3_ROT_X(rot_x, -rx*M_PI/180.0); MAT3_ROT_Z(rot_z, -rz*M_PI/180.0); MAT3_MULT(rot, rot_z, rot_x); MAT3_VECT3_MULT(dir, rot, vect); // we take the tile where the camera is tx = (int)((dir[0] - camera_x)*2); ty = (int)((dir[1] - camera_y)*2); if (get_tile_walkable(tx, ty)) { tz = get_tile_height(tx, ty); } else { // if the tile is outside the map, we take the height at the actor position tz = get_tile_height(me->x_tile_pos, me->y_tile_pos); } // here we use a shift of 0.2 to avoid to be too close to the ground if (tz + 0.2 > dir[2] - camera_z) { if (ext_cam_auto_zoom) // new behaviour { // if the camera is under the ground, we change the zoom level if (fabsf(dir[2]) > 1E-4) new_zoom_level *= (tz + camera_z + 0.2) / dir[2]; else new_zoom_level = 0.0; if (new_zoom_level < 1.0) { new_zoom_level = 1.0; camera_tilt_duration = camera_zoom_duration = 0; camera_tilt_speed = 0.0; if (fabsf(tz + camera_z + 0.2f) < fabsf(vect[2]) - 0.01) rx = -90.0 + 180.0 * asinf((tz + camera_z + 0.2) / vect[2]) / M_PI; } else if (new_zoom_level > old_zoom_level) { new_zoom_level = old_zoom_level; camera_tilt_duration = camera_zoom_duration = 0; camera_tilt_speed = 0.0; } } else // old freecam behaviour { new_zoom_level = old_zoom_level; camera_tilt_duration = camera_zoom_duration = 0; camera_tilt_speed = 0.0; if (fabsf(tz + camera_z + 0.2f) < fabsf(vect[2]) - 0.01) rx = -90.0 + 180.0 * asinf((tz + camera_z + 0.2) / vect[2]) / M_PI; } } } if(adjust_view){ set_all_intersect_update_needed(main_bbox_tree); old_camera_x= camera_x; old_camera_y= camera_y; old_camera_z= camera_z; } hold_camera = rz; if (fol_cam) { static int fol_cam_stop = 0; if ((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(2)) || camera_rotation_speed != 0) fol_cam_stop = 1; else if (me && me->moving && fol_cam_stop) fol_cam_stop = 0; if (last_kludge != camera_kludge && !fol_cam_stop) { set_all_intersect_update_needed(main_bbox_tree); adjust = (camera_kludge-last_kludge); //without this the camera will zip the wrong way when camera_kludge //flips from 180 <-> -180 if (adjust >= 180) adjust -= 360.0; else if (adjust <= -180) adjust += 360.0; if (fabs(adjust) < fol_strn) { last_kludge=camera_kludge; } else { last_kludge += fol_strn*( adjust*(fol_quad*fol_strn + fol_lin)+ fol_con*(adjust>0?1:-1))/ (fol_quad+fol_lin+fol_con+.000001f);//cheap no/0 } } if (fol_cam_behind) { if (!fol_cam_stop) rz = -last_kludge; else last_kludge = -rz; } else rz -= last_kludge; } //Make Character Turn with Camera if (have_mouse && !on_the_move (get_our_actor ())) { adjust = rz; //without this the character will turn the wrong way when camera_kludge //and character are in certain positions if (adjust >= 180) adjust -= 360.0; else if (adjust <= -180) adjust += 360.0; adjust+=camera_kludge; if (adjust >= 180) adjust -= 360.0; else if (adjust <= -180) adjust += 360.0; if (adjust > 35){ Uint8 str[2]; str[0] = TURN_LEFT; my_tcp_send (my_socket, str, 1); } else if (adjust < -35){ Uint8 str[2]; str[0] = TURN_RIGHT; my_tcp_send (my_socket, str, 1); } } adjust_view = 0; last_update = cur_time; }
void move_camera () { float x, y, z; // float head_pos[3]; float follow_speed; actor *me = get_our_actor (); if(!me){ return; } x = (float)me->x_pos+0.25f; y = (float)me->y_pos+0.25f; // cal_get_actor_bone_local_position(me, get_actor_bone_id(me, head_bone), NULL, head_pos); /* Schmurk: I've commented this out because I don't see why the position of * the camera should be different from the head position in ext cam and fpv */ /* if (first_person){ */ /* z = (ext_cam?-1.7f:-2.1f) + height_map[me->y_tile_pos*tile_map_size_x*6+me->x_tile_pos]*0.2f + head_pos[2]; */ /* } else if (ext_cam){ */ /* z = -1.6f + height_map[me->y_tile_pos*tile_map_size_x*6+me->x_tile_pos]*0.2f + head_pos[2]; */ if (first_person || ext_cam) { // the camera position corresponds to the head position z = get_tile_height(me->x_tile_pos, me->y_tile_pos); // z += (head_pos[2]+0.1)*get_actor_scale(me); //attachment_props *att_props = get_attachment_props_if_held(me); //z += (me->sitting ? 0.7 : 1.5) * get_actor_scale(me); if (me->attached_actor>=0) z+=me->z_pos + me->attachment_shift[Z]+2.0*get_actor_scale(me); else z += (me->sitting ? 0.7 : 1.5) * get_actor_scale(me); } else { z = get_tile_height(me->x_tile_pos, me->y_tile_pos) + sitting; } if(first_person||ext_cam){ follow_speed = 150.0f; } else { follow_speed = 300.0f; } if(reset_camera_at_next_update){ camera_x = -x; camera_y = -y; camera_z = -z; camera_x_duration=0; camera_y_duration=0; camera_z_duration=0; reset_camera_at_next_update = 0; set_all_intersect_update_needed(main_bbox_tree); } else { //move near the actor, but smoothly camera_x_speed=(x+camera_x)/follow_speed; camera_x_duration=follow_speed; camera_y_speed=(y+camera_y)/follow_speed; camera_y_duration=follow_speed; camera_z_speed=(z+camera_z)/follow_speed; camera_z_duration=follow_speed; } if (first_person){ // glTranslatef(head_pos[0], head_pos[1], 0.0); } else { glTranslatef(0.0f, 0.0f, -zoom_level*camera_distance); } glRotatef(rx, 1.0f, 0.0f, 0.0f); glRotatef(rz, 0.0f, 0.0f, 1.0f); glTranslatef(camera_x, camera_y, camera_z); }
void pf_move() { int x, y; actor *me; if (!pf_follow_path || !(me = get_our_actor())) { return; } x = me->x_tile_pos; y = me->y_tile_pos; if (PF_DIFF(x, pf_dst_tile->x) < 2 && PF_DIFF(y, pf_dst_tile->y) < 2) { pf_destroy_path(); } else { PF_TILE *t = pf_get_tile(x, y); int i = 0, j = 0; for (pf_cur_tile = pf_dst_tile; pf_cur_tile; pf_cur_tile = pf_cur_tile->parent) { if (pf_cur_tile == t) { break; } i++; } if (pf_cur_tile == t) { #ifdef FUZZY_PATHS int limit= i-(10+rand()%3); #else //FUZZY_PATHS int limit= i-12; #endif //FUZZY_PATHS for (pf_cur_tile = pf_dst_tile; pf_cur_tile; pf_cur_tile = pf_cur_tile->parent) { if (j++ == limit) { break; } } if (pf_cur_tile) { Uint8 str[5]; str[0] = MOVE_TO; *((short *)(str+1)) = SDL_SwapLE16((short)pf_cur_tile->x); *((short *)(str+3)) = SDL_SwapLE16((short)pf_cur_tile->y); my_tcp_send(my_socket, str, 5); return; } } for (pf_cur_tile = pf_dst_tile; pf_cur_tile; pf_cur_tile = pf_cur_tile->parent) { if (PF_DIFF(x, pf_cur_tile->x) <= 12 && PF_DIFF(y, pf_cur_tile->y) <= 12 && !pf_is_tile_occupied(pf_cur_tile->x, pf_cur_tile->y)) { Uint8 str[5]; str[0] = MOVE_TO; *((short *)(str+1)) = SDL_SwapLE16((short)pf_cur_tile->x); *((short *)(str+3)) = SDL_SwapLE16((short)pf_cur_tile->y); my_tcp_send(my_socket, str, 5); break; } } } }