Jump to content
Eternal Lands Official Forums
Sign in to follow this  
RotationZ

Exp / Min

Recommended Posts

Idea:

 

Change the Xp / Min counter in such a way that u can see:

Harv xp/min

Att xp/min

or ofc, the way its now Oa xp/min

 

So that the first skill in the starts bar is divided by the minutes played...

 

Loving the Xp/Min already :inquisitive:

Share this post


Link to post
Share on other sites

Made something a while back, problem is there is an error in there after playing for xx hours without resetting the counters. Somehow the overall exp gets bugged and shows like 10% of the actual value.

 

 

How to add scrolling to code tags?

session.c

#include <stdlib.h>
#include <stddef.h>
#include <ctype.h>
#include "session.h"
#include "asc.h"
#include "elwindows.h"
#include "init.h"
#include "global.h"
#include "hud.h"
#include "multiplayer.h"
#include "platform.h"
#include "stats.h"
#include "translate.h"
#include "counters.h"
#ifdef OPENGL_TRACE
#include "gl_init.h"
#endif
#include "widgets.h"

int session_win = -1;
static int reconnecting = 0;
static int last_port = -1;
static unsigned char last_server_address[60];
static int show_reset_help = 0;

player_attribs session_stats;
Uint32 session_start_time;

int display_session_handler(window_info *win);

static int mouseover_session_reset_handler(void)
{
if (!disable_double_click && show_help_text)
	show_reset_help = 1;
return 0;
}


/*
Placed the reset button a bit to the right.
*/ 
void fill_session_win(void)
{
int reset_button_id = -1;
set_window_handler(session_win, ELW_HANDLER_DISPLAY, &display_session_handler);

reset_button_id=button_add_extended(session_win, reset_button_id, NULL, 475, 3, 0, 0, 0, 1.0f, 0.77f, 0.57f, 0.39f, reset_str);
widget_set_OnClick(session_win, reset_button_id, session_reset_handler);
widget_set_OnMouseover(session_win, reset_button_id, mouseover_session_reset_handler);

}

int display_session_handler(window_info *win)
{
/*
Changed use of timediff & added timediffms (old timediff really...) & added timenextlvl variables.
*/
int x, y, timediff, timediffms, timenextlvl;
char buffer[80];
player_attribs cur_stats = your_info;

x = 10;
y = 21;

/*
Write the column names at correct distance, simply used x+z where z is a number not a variable.
*/

glColor3f(1.0f, 1.0f, 1.0f);
draw_string_small(x, y, (unsigned char*)"Skill", 1);

glColor3f(1.0f, 1.0f, 1.0f);
draw_string_small(x + 125, y, (unsigned char*)"Experience", 1);

glColor3f(1.0f, 1.0f, 1.0f);
draw_string_small(x + 250, y, (unsigned char*)"Per Hour", 1);

glColor3f(1.0f, 1.0f, 1.0f);
draw_string_small(x + 350, y, (unsigned char*)"Next LvL", 1);

glDisable(GL_TEXTURE_2D);
glColor3f(0.77f, 0.57f, 0.39f);
glBegin(GL_LINES);
glVertex3i(0, 37, 0);
glVertex3i(win->len_x, 37, 0);
glEnd();
glEnable(GL_TEXTURE_2D);
glColor3f(1.0f, 1.0f, 1.0f);
y = 55;

/*
I set the variable timediff to count seconds instead of ms so 'Per Hour' and 'Next LvL' are visually updated every second rather then in real time.
If timedifference is zero (after reset) set it to 1 unit,
even tho with timediffms this problem will not occur I put it in there for consistency.
*/
timediff = cur_time/1000 - session_start_time/1000;
timediffms = cur_time - session_start_time;
if (timediffms < 1){timediffms = 1;}
if (timediff < 1){timediff = 1;}

/*
Draw Skill_name, Exp_diff, Exp_hour, Time_to_lvl.
Rather use the expression then a seperate line that binds the expression to a new variable... Calculation is more correct (issues with roundoff using integers are less)

For 'Per Hour' the calculation is trivial.

Check for Exp_diff > 0 in the first if statement, prevents zero division in the timenextlvl caluclation.
When calculating 'timenextlvl' we are not interested in very large numbers, like anything above 100 Hours.
Capping the max displayed time fixes a zero division (due to roundoff errors).

Each skill row is the same code with different skill names. 
A list with skill names inserted in the right position, might look better and is easyer to configure.
*/	

draw_string_small(x, y, attributes.attack_skill.name , 1);
safe_snprintf(buffer, sizeof(buffer), "%d", cur_stats.attack_exp - session_stats.attack_exp);
draw_string_small(x + 125, y, (unsigned char*)buffer, 1);
safe_snprintf(buffer, sizeof(buffer), "%d", 3600*(cur_stats.attack_exp - session_stats.attack_exp)/(timediff));
draw_string_small(x + 250, y, (unsigned char*)buffer, 1);
if ((cur_stats.attack_exp - session_stats.attack_exp) < 1){draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);}   
else {
   timenextlvl = (int)(((double)cur_stats.attack_exp_next_lev - (double)cur_stats.attack_exp)/(((double)cur_stats.attack_exp - (double)session_stats.attack_exp)/(timediff)));
   if (timenextlvl < 360000){		  
	  safe_snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", timenextlvl/3600, (timenextlvl/60)%60, (timenextlvl/1)%60);
	  draw_string_small(x + 350, y, (unsigned char*)buffer, 1);
   }		  
   else{
	  draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);
   }			  
}	
y += 16;

draw_string_small(x, y, attributes.defense_skill.name , 1);
safe_snprintf(buffer, sizeof(buffer), "%d", cur_stats.defense_exp - session_stats.defense_exp);
draw_string_small(x + 125, y, (unsigned char*)buffer, 1);
safe_snprintf(buffer, sizeof(buffer), "%d", 3600*(cur_stats.defense_exp - session_stats.defense_exp)/(timediff));
draw_string_small(x + 250, y, (unsigned char*)buffer, 1);
if ((cur_stats.defense_exp - session_stats.defense_exp) < 1){draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);}   
else {
   timenextlvl = (int)(((double)cur_stats.defense_exp_next_lev - (double)cur_stats.defense_exp)/(((double)cur_stats.defense_exp - (double)session_stats.defense_exp)/(timediff)));
   if (timenextlvl < 360000){		  
	  safe_snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", timenextlvl/3600, (timenextlvl/60)%60, (timenextlvl/1)%60);
	  draw_string_small(x + 350, y, (unsigned char*)buffer, 1);
   }		  
   else{
	  draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);
   }			  
}
  	y += 16;

draw_string_small(x, y, attributes.harvesting_skill.name , 1);
safe_snprintf(buffer, sizeof(buffer), "%d", cur_stats.harvesting_exp - session_stats.harvesting_exp);
draw_string_small(x + 125, y, (unsigned char*)buffer, 1);
safe_snprintf(buffer, sizeof(buffer), "%d", 3600*(cur_stats.harvesting_exp - session_stats.harvesting_exp)/(timediff));
draw_string_small(x + 250, y, (unsigned char*)buffer, 1);
if ((cur_stats.harvesting_exp - session_stats.harvesting_exp) < 1){draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);}   
else {
   timenextlvl = (int)(((double)cur_stats.harvesting_exp_next_lev - (double)cur_stats.harvesting_exp)/(((double)cur_stats.harvesting_exp - (double)session_stats.harvesting_exp)/(timediff)));
   if (timenextlvl < 360000){		  
	  safe_snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", timenextlvl/3600, (timenextlvl/60)%60, (timenextlvl/1)%60);
	  draw_string_small(x + 350, y, (unsigned char*)buffer, 1);
   }		  
   else{
	  draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);
   }			  
}	
y += 16;

draw_string_small(x, y, attributes.alchemy_skill.name , 1);
safe_snprintf(buffer, sizeof(buffer), "%d", cur_stats.alchemy_exp - session_stats.alchemy_exp);
draw_string_small(x + 125, y, (unsigned char*)buffer, 1);
safe_snprintf(buffer, sizeof(buffer), "%d", 3600*(cur_stats.alchemy_exp - session_stats.alchemy_exp)/(timediff));
draw_string_small(x + 250, y, (unsigned char*)buffer, 1);
if ((cur_stats.alchemy_exp - session_stats.alchemy_exp) < 1){draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);}   
else {
   timenextlvl = (int)(((double)cur_stats.alchemy_exp_next_lev - (double)cur_stats.alchemy_exp)/(((double)cur_stats.alchemy_exp - (double)session_stats.alchemy_exp)/(timediff)));
   if (timenextlvl < 360000){		  
	  safe_snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", timenextlvl/3600, (timenextlvl/60)%60, (timenextlvl/1)%60);
	  draw_string_small(x + 350, y, (unsigned char*)buffer, 1);
   }		  
   else{
	  draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);
   }			  
}
y += 16;

draw_string_small(x, y, attributes.magic_skill.name , 1);
safe_snprintf(buffer, sizeof(buffer), "%d", cur_stats.magic_exp - session_stats.magic_exp);
draw_string_small(x + 125, y, (unsigned char*)buffer, 1);
safe_snprintf(buffer, sizeof(buffer), "%d", 3600*(cur_stats.magic_exp - session_stats.magic_exp)/(timediff));
draw_string_small(x + 250, y, (unsigned char*)buffer, 1);
if ((cur_stats.magic_exp - session_stats.magic_exp) < 1){draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);}   
else {
   timenextlvl = (int)(((double)cur_stats.magic_exp_next_lev - (double)cur_stats.magic_exp)/(((double)cur_stats.magic_exp - (double)session_stats.magic_exp)/(timediff)));
   if (timenextlvl < 360000){		  
	  safe_snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", timenextlvl/3600, (timenextlvl/60)%60, (timenextlvl/1)%60);
	  draw_string_small(x + 350, y, (unsigned char*)buffer, 1);
   }		  
   else{
	  draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);
   }			  
}	
y += 16;

draw_string_small(x, y, attributes.potion_skill.name , 1);
safe_snprintf(buffer, sizeof(buffer), "%d", cur_stats.potion_exp - session_stats.potion_exp);
draw_string_small(x + 125, y, (unsigned char*)buffer, 1);
safe_snprintf(buffer, sizeof(buffer), "%d", 3600*(cur_stats.potion_exp - session_stats.potion_exp)/(timediff));
draw_string_small(x + 250, y, (unsigned char*)buffer, 1);
if ((cur_stats.potion_exp - session_stats.potion_exp) < 1){draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);}   
else {
   timenextlvl = (int)(((double)cur_stats.potion_exp_next_lev - (double)cur_stats.potion_exp)/(((double)cur_stats.potion_exp - (double)session_stats.potion_exp)/(timediff)));
   if (timenextlvl < 360000){		  
	  safe_snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", timenextlvl/3600, (timenextlvl/60)%60, (timenextlvl/1)%60);
	  draw_string_small(x + 350, y, (unsigned char*)buffer, 1);
   }		  
   else{
	  draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);
   }			  
}	
y += 16;

draw_string_small(x, y, attributes.summoning_skill.name , 1);
safe_snprintf(buffer, sizeof(buffer), "%d", cur_stats.summoning_exp - session_stats.summoning_exp);
draw_string_small(x + 125, y, (unsigned char*)buffer, 1);
safe_snprintf(buffer, sizeof(buffer), "%d", 3600*(cur_stats.summoning_exp - session_stats.summoning_exp)/(timediff));
draw_string_small(x + 250, y, (unsigned char*)buffer, 1);
if ((cur_stats.summoning_exp - session_stats.summoning_exp) < 1){draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);}   
else {
   timenextlvl = (int)(((double)cur_stats.summoning_exp_next_lev - (double)cur_stats.summoning_exp)/(((double)cur_stats.summoning_exp - (double)session_stats.summoning_exp)/(timediff)));
   if (timenextlvl < 360000){		  
	safe_snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", timenextlvl/3600, (timenextlvl/60)%60, (timenextlvl/1)%60);
	  draw_string_small(x + 350, y, (unsigned char*)buffer, 1);
   }		  
   else{
	  draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);
   }			  
}	
y += 16;

draw_string_small(x, y, attributes.manufacturing_skill.name , 1);
safe_snprintf(buffer, sizeof(buffer), "%d", cur_stats.manufacturing_exp - session_stats.manufacturing_exp);
draw_string_small(x + 125, y, (unsigned char*)buffer, 1);
safe_snprintf(buffer, sizeof(buffer), "%d", 3600*(cur_stats.manufacturing_exp - session_stats.manufacturing_exp)/(timediff));
draw_string_small(x + 250, y, (unsigned char*)buffer, 1);
if ((cur_stats.manufacturing_exp - session_stats.manufacturing_exp) < 1){draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);}   
else {
   timenextlvl = (int)(((double)cur_stats.manufacturing_exp_next_lev - (double)cur_stats.manufacturing_exp)/(((double)cur_stats.manufacturing_exp - (double)session_stats.manufacturing_exp)/(timediff)));
   if (timenextlvl < 360000){		  
	  safe_snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", timenextlvl/3600, (timenextlvl/60)%60, (timenextlvl/1)%60);
	  draw_string_small(x + 350, y, (unsigned char*)buffer, 1);
   }		  
   else{
	  draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);
   }			  
}	
y += 16;

draw_string_small(x, y, attributes.crafting_skill.name , 1);
safe_snprintf(buffer, sizeof(buffer), "%d", cur_stats.crafting_exp - session_stats.crafting_exp);
draw_string_small(x + 125, y, (unsigned char*)buffer, 1);
safe_snprintf(buffer, sizeof(buffer), "%d", 3600*(cur_stats.crafting_exp - session_stats.crafting_exp)/(timediff));
draw_string_small(x + 250, y, (unsigned char*)buffer, 1);
if ((cur_stats.crafting_exp - session_stats.crafting_exp) < 1){draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);}   
else {
   timenextlvl = (int)(((double)cur_stats.crafting_exp_next_lev - (double)cur_stats.crafting_exp)/(((double)cur_stats.crafting_exp - (double)session_stats.crafting_exp)/(timediff)));
   if (timenextlvl < 360000){		  
	  safe_snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", timenextlvl/3600, (timenextlvl/60)%60, (timenextlvl/1)%60);
	  draw_string_small(x + 350, y, (unsigned char*)buffer, 1);
   }		  
   else{
	  draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);
   }			  
}	
y += 16;

draw_string_small(x, y, attributes.engineering_skill.name , 1);
safe_snprintf(buffer, sizeof(buffer), "%d", cur_stats.engineering_exp - session_stats.engineering_exp);
draw_string_small(x + 125, y, (unsigned char*)buffer, 1);
safe_snprintf(buffer, sizeof(buffer), "%d", 3600*(cur_stats.engineering_exp - session_stats.engineering_exp)/(timediff));
draw_string_small(x + 250, y, (unsigned char*)buffer, 1);
if ((cur_stats.engineering_exp - session_stats.engineering_exp) < 1){draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);}   
else {
   timenextlvl = (int)(((double)cur_stats.engineering_exp_next_lev - (double)cur_stats.engineering_exp)/(((double)cur_stats.engineering_exp - (double)session_stats.engineering_exp)/(timediff)));
   if (timenextlvl < 360000){		  
	  safe_snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", timenextlvl/3600, (timenextlvl/60)%60, (timenextlvl/1)%60);
	  draw_string_small(x + 350, y, (unsigned char*)buffer, 1);
   }		  
   else{
	  draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);
   }			  
}	
y += 16;

draw_string_small(x, y, attributes.tailoring_skill.name , 1);
safe_snprintf(buffer, sizeof(buffer), "%d", cur_stats.tailoring_exp - session_stats.tailoring_exp);
draw_string_small(x + 125, y, (unsigned char*)buffer, 1);
safe_snprintf(buffer, sizeof(buffer), "%d", 3600*(cur_stats.tailoring_exp - session_stats.tailoring_exp)/(timediff));
draw_string_small(x + 250, y, (unsigned char*)buffer, 1);
if ((cur_stats.tailoring_exp - session_stats.tailoring_exp) < 1){draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);}   
else {
   timenextlvl = (int)(((double)cur_stats.tailoring_exp_next_lev - (double)cur_stats.tailoring_exp)/(((double)cur_stats.tailoring_exp - (double)session_stats.tailoring_exp)/(timediff)));
   if (timenextlvl < 360000){		  
	  safe_snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", timenextlvl/3600, (timenextlvl/60)%60, (timenextlvl/1)%60);
	  draw_string_small(x + 350, y, (unsigned char*)buffer, 1);
   }		  
   else{
	  draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);
   }			  
}
y += 16;

draw_string_small(x, y, attributes.ranging_skill.name , 1);
safe_snprintf(buffer, sizeof(buffer), "%d", cur_stats.ranging_exp - session_stats.ranging_exp);
draw_string_small(x + 125, y, (unsigned char*)buffer, 1);
safe_snprintf(buffer, sizeof(buffer), "%d", 3600*(cur_stats.ranging_exp - session_stats.ranging_exp)/(timediff));
draw_string_small(x + 250, y, (unsigned char*)buffer, 1);
if ((cur_stats.ranging_exp - session_stats.ranging_exp) < 1){draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);}   
else {
   timenextlvl = (int)(((double)cur_stats.ranging_exp_next_lev - (double)cur_stats.ranging_exp)/(((double)cur_stats.ranging_exp - (double)session_stats.ranging_exp)/(timediff)));
   if (timenextlvl < 360000){		  
	  safe_snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", timenextlvl/3600, (timenextlvl/60)%60, (timenextlvl/1)%60);
	  draw_string_small(x + 350, y, (unsigned char*)buffer, 1);
   }		  
   else{
	  draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);
   }			  
}
y += 16;

//------------------------- OVERALL START -------------------------------//
/*
For Overall draw Skill_name, Exp_diff, Exp_hour, Time_to_lvl. And experience per minute with '/ min' behind the number at fixed location.
Overall exp/hour is bugged for large Exp_diff while Exp_min still works (issue for long session times)
*/
draw_string_small(x, y, attributes.overall_skill.name , 1);
safe_snprintf(buffer, sizeof(buffer), "%d", cur_stats.overall_exp - session_stats.overall_exp);
draw_string_small(x + 125, y, (unsigned char*)buffer, 1);

safe_snprintf(buffer, sizeof(buffer), "%d", 3600*(cur_stats.overall_exp - session_stats.overall_exp)/(timediff));
draw_string_small(x + 250, y, (unsigned char*)buffer, 1);

safe_snprintf(buffer, sizeof(buffer), "%d", 60*(cur_stats.overall_exp - session_stats.overall_exp)/(timediff));
draw_string_small(x + 250, y+16, (unsigned char*)buffer, 1);
draw_string_small(x + 300, y+16, (unsigned char*)"/ Min", 1);

if ((cur_stats.overall_exp - session_stats.overall_exp) < 1){draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);}   
else {
   timenextlvl = (int)(((double)cur_stats.overall_exp_next_lev - (double)cur_stats.overall_exp)/(((double)cur_stats.overall_exp - (double)session_stats.overall_exp)/(timediff)));
   if (timenextlvl < 360000){		  
	  safe_snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", timenextlvl/3600, (timenextlvl/60)%60, (timenextlvl/1)%60);
	  draw_string_small(x + 350, y, (unsigned char*)buffer, 1);
   }		  
   else{
	  draw_string_small(x + 350, y, (unsigned char*)"--:--:--", 1);
   }			  
}   
//-------------------------  OVERALL END  -------------------------------//

/*
Session time using timediffms so that on reset timediffms goes to 1ms (00:00:00) instead of 1s (00:00:01)
When experience is gained in say the first ms after reset, the experience per hour could get too large for the datatype so,
I think using timediff capped at 1 sec and calculation of the expression INSIDE the safe_snprintf command neutralizes this problem.
*/

y += 40;
draw_string_small(x, y, (unsigned char*)"Session Time", 1);
safe_snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", timediffms/3600000, (timediffms/60000)%60, (timediffms/1000)%60);
draw_string_small(x + 125, y, (unsigned char*)buffer, 1);

if (show_reset_help)
{
   show_help(session_reset_help, 0, win->len_y+10);
   show_reset_help = 0;
}

#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE

return 1;
}

void init_session(void)
{
int save_server = 1;

/* if we have server info saved, compare with current */
if (last_port > 0)
{
	/* if changed, we need to reset the session stats */
	if ((last_port != port) || (strcmp((char *)last_server_address, (char *)server_address)))
	{
		LOG_TO_CONSOLE(c_red2,"Server changed so resetting session stats");
		reconnecting = 0;
	}
	/* else if the same, no need */
	else
		save_server = 0;
}

/* save the server info if first time or changed */
if (save_server)
{
	last_port = port;
	safe_strncpy((char *)last_server_address, (char *)server_address, sizeof(last_server_address));
}

if (!reconnecting){
	session_stats = your_info;
	session_start_time = cur_time;
	reconnecting = 1;
}
else if ( disconnect_time != 0 ) {
	session_start_time += (cur_time-disconnect_time);
	disconnect_time = 0;
}
}

int session_reset_handler(void)
{
static Uint32 last_click = 0;
/* provide some protection for inadvertent pressing (double click that can be disabled) */
if (safe_button_click(&last_click))
{
	init_session();
	session_stats = your_info;
	session_start_time = cur_time;
	reset_session_counters();
}
return 0;
}

Edited by ProHibited

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×