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

Patch # 000220 Stats In The Hud

Recommended Posts

If you make it optional, I'm quite confident that they'd accept it :-)

 

#show_stats_in_hud = 0/1

 

EDIT:

Oh and one other thing - instead of doing all of the calculations (window_width-80), you should introduce:

int width = window_width-80;

And use that instead - then it won't have to make the same calculation over and over again.

Share this post


Link to post
Share on other sites

One more thing to add to 'simplify' things for here and other code ... if you could set up one standard place/array/structure where the short & long names for the different stats are pulled from for all the different things in the hud. One of the things I hated about one patch for the exp bar is they had repeated all pf the names again, instead of cleaning it up. Now, another dimension has been added to that and it would be better to reorganize how its done.

Share this post


Link to post
Share on other sites

Simplified like this ?

 

}
if(show_stats_in_hud==1)process_stats();
}

int process_stats()
{
 char str[5];
 int i = -275;
 glColor3f(1.0f, 1.0f, 1.0f);
 drawstats("att",your_info.attack_skill.base, i+=15);
 drawstats("def",your_info.defense_skill.base, i+=15);
 drawstats("har",your_info.harvesting_skill.base, i+=15);
 drawstats("alc",your_info.alchemy_skill.base, i+=15);
 drawstats("mag",your_info.magic_skill.base, i+=15);
 drawstats("pot",your_info.potion_skill.base, i+=15);
 drawstats("sum",your_info.summoning_skill.base, i+=15);
 drawstats("man",your_info.manufacturing_skill.base, i+=15);
 drawstats("cra",your_info.crafting_skill.base, i+=15);
 drawstats("oa ",your_info.overall_skill.base, i+=15);

}
int drawstats(Uint8 strd[5], int exp, int pos)
{
 int width;
 Uint8 str[20];
 width = window_width -80;
 sprintf(str,"%s %i",strd,exp);
 draw_string_small(width , pos , str, 1);
}

Share this post


Link to post
Share on other sites

I think learner wants something like:

 

struct stat
{
char name[20];
char shortname[4];
};

struct stat stats[10]

 

Instead of mentioning the same strings all over the place.

Share this post


Link to post
Share on other sites
While we are at it, let's add a language file, something like language_english.h and put everything there.

Even better, put it all into a strings.xml-file.

 

Teranoz - if you'll have a hard time doing this, just tell us and we'll help you get it done :blink:

Share this post


Link to post
Share on other sites

More the idea like this ?

struct stat
{
char name[20];
char shortname[4];
int level;
int exp;
};

struct stat stats[11];

void init_stat_info()
{
my_strcp(stats[1].name,"Attack");
my_strcp(stats[2].name,"Defence");
my_strcp(stats[3].name,"Harvesting");
my_strcp(stats[4].name,"Alchemy");
my_strcp(stats[5].name,"Magic");
my_strcp(stats[6].name,"Potion");
my_strcp(stats[7].name,"Summoning");
my_strcp(stats[8].name,"Manufacture");
my_strcp(stats[9].name,"Crafting");
my_strcp(stats[10].name,"Overall");
my_strcp(stats[1].shortname,"att");
my_strcp(stats[2].shortname,"def");
my_strcp(stats[3].shortname,"har");
my_strcp(stats[4].shortname,"alc");
my_strcp(stats[5].shortname,"mag");
my_strcp(stats[6].shortname,"pot");
my_strcp(stats[7].shortname,"sum");
my_strcp(stats[8].shortname,"man");
my_strcp(stats[9].shortname,"cra");
my_strcp(stats[10].shortname,"oa ");
}
void get_stat_levels()
{
stats[1].level=your_info.attack_skill.base;
stats[2].level=your_info.defense_skill.base;
stats[3].level=your_info.harvesting_skill.base;
stats[4].level=your_info.alchemy_skill.base;
stats[5].level=your_info.magic_skill.base;
stats[6].level=your_info.potion_skill.base;
stats[7].level=your_info.summoning_skill.base;
stats[8].level=your_info.manufacturing_skill.base;
stats[9].level=your_info.crafting_skill.base;
stats[10].level=your_info.overall_skill.base;

stats[1].exp=your_info.attack_exp;
stats[2].exp=your_info.defense_exp;
stats[3].exp=your_info.harvesting_exp;
stats[4].exp=your_info.alchemy_exp;
stats[5].exp=your_info.magic_exp;
stats[6].exp=your_info.potion_exp;
stats[7].exp=your_info.summoning_exp;
stats[8].exp=your_info.manufacturing_exp;
stats[9].exp=your_info.crafting_exp;
stats[10].exp=your_info.overall_exp;
}

Than we can also shorten the code for draw_exp_display and make a for/next loop instead of a switch

void draw_exp_display()
{
int exp_adjusted_x_len;
int nl_exp, baselev, cur_exp;
int delta_exp;
float prev_exp;
Uint8 str[25];
int i;

 get_stat_levels();
 cur_exp = stats[10].exp;
 baselev = stats[10].level;
 sprintf(str,"%s lvl %i",stats[10].name,stats[10].level);
 for(i=1;i<11;i++)
 {
	 if(i==watch_this_stat)
	 {
   cur_exp = stats[i].exp;
   baselev = stats[i].level;
   sprintf(str,"%s lvl %i",stats[i].name,stats[i].level);
   break;
	 }
 }

if(!baselev)
 prev_exp=0;
else
 prev_exp=exp_lev[baselev];

nl_exp=exp_lev[baselev+1];
delta_exp=nl_exp-prev_exp;

if(!cur_exp || !nl_exp)
 exp_adjusted_x_len = 0;
else
 //exp_bar_length = (int)( (((float)cur_exp - prev_exp) / ((float)nl_exp - prev_exp)) * 100.0);
 exp_adjusted_x_len = 100-100.0f/(float)((float)delta_exp/(float)(nl_exp-cur_exp));

draw_stats_bar(exp_bar_start_x, exp_bar_start_y, nl_exp - cur_exp, exp_adjusted_x_len, 0.1f, 0.8f, 0.1f, 0.1f, 0.4f, 0.1f);
draw_string_small(exp_bar_start_x, exp_bar_start_y+10, str, 1);
}

Share this post


Link to post
Share on other sites

Well, since the stats (numbers) are already in the your_info structure, perhaps you should make the stats.{level,exp} be int pointers to the appropriate ints in your_info.

 

Otherwise it looks nice - can you do the xml-part (multiple language support) as well or should this be another job?

Share this post


Link to post
Share on other sites

I'd say that's an advantage, but it'll depend on what the developers think. Loop unrolling is enabled with -O3 (as is used in the release CFLAGS) so it'll just make it more readable.

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.

×