[C++] How to increase maximum level on server

Discussion in 'Programming & Scripting' started by Gesior.pl, Mar 19, 2015.

  1. Gesior.pl

    Gesior.pl Mega Noob&LOL 2012

    Joined:
    Sep 18, 2007
    Messages:
    1,809
    Likes Received:
    625
    Best Answers:
    1
    This is not 'code release' (only)! There is full description of problem with maximum number value in C++.

    Let's fix max. level problem (for high exp servers)!
    THIS FIX YOU CAN ONLY INSTALL BEFORE SERVER START. THIS FIX REQUIRES ALL CHARACTERS RESET (level and exp).

    Example with formulat with max. level over 250.000.000:
    1. First thing to do is to reduce exp ratio/exp from monsters [.xml / .lua files]. When experience reaches '18.446.744.073.709.551.615' it stops leveling.

    2. Change getExpForLevel function in player.h (sources)
    There is something like:
    Code (Text):
    1. static uint64_t getExpForLevel(int32_t lv) {
    2. ... (no matter what is here, we replace it!) ...
    3. }
    Replace it with (this is just example function, you should make some better, as it's growing flat lvl 1 = X exp, lvl 2 = 2*X exp, .. lvl N = N * X exp):
    Code (Text):
    1. static uint64_t getExpForLevel(int32_t lv) {
    2. lv--;
    3. return ((150ULL * lv * lv) - (50ULL * lv * lv) + (1200ULL)) / 3ULL;
    4. }
    3. Rebuild sources (this change requires 'rebuild', not just 'compile'!)
    [How to rebuild 0.3.6/0.4 on linux? Remove all .o files from compilation folder: rm *.o ]

    Compare exp required for level:
    Normal formula 'lvl 29' exp is equal to new formula 'lvl 100' exp - players gain levels much faster with same exp ratio!

    -------------------------------------------------------------
    Why? What? Where? Short explanation:

    Exp-level formula is: ((50ULL * lv * lv * lv) - (150ULL * lv * lv) + (400ULL * lv)) / 3ULL
    Now change it into math parts that computer must calculate (in computer-calculation order - different then school/human calculation):
    $x1 = 400ULL * lv
    $x2 = 150ULL * lv * lv
    $x3 = 50ULL * lv * lv * lv
    $x4 = $x3 + ($x1 - $x2)
    $x5 = 3ULL
    $x6 = $x4 / $x5

    Now use some level in these calculations, hmm... 5.000.000 level? OK!
    $lv = 5.000.000
    $x1 = 2.000.000.000
    $x2 = 3.750.000.000.000.000
    $x3 = 6.249.999.999.999.999.475.712
    $x4 = 6.249.996.250.001.999.659.008
    $x5 = 3
    $x6 = 2.083.332.083.333.999.886.336

    18.446.744.073.709.551.615 - this is max. allowed value for math calculation [high precision] in C++ [and many other languanges]
    (first 18 digits of numbers are bold to let you see which numbers are too high)


    As you can see value of $x3 [50ULL * lv * lv * lv] for level 5.000.000 is much higher then maximum allowed value for number (and because of it $x4 and $x6 are also too high). So problem is with too high 'exp' value, not too high 'level' value.
    Can you change maximum value in C++? No (there is possibility, but it's not easy.. it's super hard! - you must change it everywhere is sources).
    Only thing you can do is to give more levels for X 'exp points'. Then when player reaches exp 'max', his level will be 5.000.000 not 717.206.


    --------------------------------------------
    Extra info + calculator:

    ULL - unsigned long long (integer) - max. value: 18.446.744.073.709.551.615 , you must add it to every number in math formula to tell computer to calculate with highest precision (highest maximum value)

    Awesome formula level calculator. Find too high number easy.
    http://writecodeonline.com/php/
    Paste in this *magic* formula (compare your exp-level calculation part values with maximum possible 'unsigned 64 bit integer value'):
    Code (Text):
    1.  
    2. $lv = 5000000;
    3. $x1 = 400 * $lv;
    4. $x2 = 150 * $lv * $lv;
    5. $x3 = 50 * $lv * $lv * $lv;
    6. $x4 = $x3 + ($x1 - $x2);
    7. $x5 = 3;
    8. $x6 = $x4 / $x5;
    9.  
    10. echo number_format($x1, 0, '', '.') . "\n" . number_format($x2, 0, '', '.') . "\n" . number_format($x3, 0, '', '.') . "\n" . number_format($x4, 0, '', '.') . "\n" . number_format($x5, 0, '', '.') . "\n" . number_format($x6, 0, '', '.') . "\n18.446.744.073.709.551.615 - this is max. allowed value";
    11.  
    You can modify values $x1 to $x5 and check why some changes in formula does not help.
     
    Last edited: Mar 19, 2015
  2. Niioxce

    Niioxce Otland lurker

    Joined:
    Jun 22, 2012
    Messages:
    297
    Likes Received:
    2
    Best Answers:
    0
    This is amazing, i'll check this out later, AKA now... :D
     
  3. Niioxce

    Niioxce Otland lurker

    Joined:
    Jun 22, 2012
    Messages:
    297
    Likes Received:
    2
    Best Answers:
    0
    By the way is this:
    Code (Text):
    1.  
    2. static uint64_t getExpForLevel(uint32_t lv)
    3. {
    4. static std::map<uint32_t, uint64_t> cache;
    5. lv--;
    6.  
    7. std::map<uint32_t, uint64_t>::iterator it = cache.find(lv);
    8. if(it != cache.end())
    9. return it->second;
    10.  
    11. uint64_t exp = ((50ULL * (lv+1ULL) / 3ULL - 100ULL) * (lv+1ULL) + 850ULL / 3ULL) * (lv+1ULL) - 200ULL;
    12. cache[lv] = exp;
    13. return exp;
    14. }
    15.  
    Better than this

    Code (Text):
    1.  
    2. static uint64_t getExpForLevel(int32_t lv) {
    3. lv--;
    4. return ((150ULL * lv * lv) - (50ULL * lv * lv) + (1200ULL)) / 3ULL;
    5. }
    6.  
    ?

    Also what exp ratio do you suggest?

    Thanks again!

    Edit: I tried this and i reached level:
    Code (Text):
    1. 13:32 You are level : ----> 429496730 <----
    haha
     
    Last edited: Mar 19, 2015
  4. EvilSkillz

    EvilSkillz Back

    Joined:
    Jul 12, 2012
    Messages:
    1,691
    Likes Received:
    321
    Best Answers:
    0
    the secret has been revealed :D
     
  5. Sir Islam

    Sir Islam Never Give Up

    Joined:
    Jun 6, 2008
    Messages:
    500
    Likes Received:
    116
    Best Answers:
    0
    to maximum level 5 000 000 will be ?
     
  6. Niioxce

    Niioxce Otland lurker

    Joined:
    Jun 22, 2012
    Messages:
    297
    Likes Received:
    2
    Best Answers:
    0
    You can change that in stages if you want.
     
  7. Sir Islam

    Sir Islam Never Give Up

    Joined:
    Jun 6, 2008
    Messages:
    500
    Likes Received:
    116
    Best Answers:
    0
    by stages i got max Level: 94869
    Code (Text):
    1.     <world id="0" multiplier="1">
    2.         <stage minlevel="1" maxlevel="8" multiplier="100"/>
    3.         <stage minlevel="9" maxlevel="20" multiplier="100"/>
    4.         <stage minlevel="21" maxlevel="50" multiplier="100"/>
    5.         <stage minlevel="51" maxlevel="100" multiplier="100"/>
    6.         <stage minlevel="100" maxlevel="120" multiplier="100"/>
    7.         <stage minlevel="130" maxlevel="150" multiplier="100"/>
    8.         <stage minlevel="300" maxlevel="400" multiplier="100"/>
    9.         <stage minlevel="717217" maxlevel="1000000" multiplier="100"/>
    10.         <stage minlevel="2000000" maxlevel="3000000" multiplier="100"/>
    11.         <stage minlevel="4000000" maxlevel="5000000" multiplier="0"/>
     
    Last edited: Mar 20, 2015
  8. Niioxce

    Niioxce Otland lurker

    Joined:
    Jun 22, 2012
    Messages:
    297
    Likes Received:
    2
    Best Answers:
    0
    Try this

    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="UTF-8"?>
    3. <stages>
    4.      <stage minlevel="1" maxlevel="5000000" multiplier="100"/>
    5. </stages>
    6.  
    Also have you done as @Gesior.pl told you, or similar atleast?
    Btw have you edited your config so Experiencestages = true?
    Code (Text):
    1. experienceStages = true
     
    Last edited: Mar 20, 2015
  9. Sir Islam

    Sir Islam Never Give Up

    Joined:
    Jun 6, 2008
    Messages:
    500
    Likes Received:
    116
    Best Answers:
    0
    16:48 You advanced from Level 4879037 to Level 5320245.

    i want 5 000 000 no more
     
  10. Niioxce

    Niioxce Otland lurker

    Joined:
    Jun 22, 2012
    Messages:
    297
    Likes Received:
    2
    Best Answers:
    0
    I think you have to change the formula a bit, not quite sure. You can also try to lower the exp ratio on the mobs or the multiplier in stages..

    Good luck :p
     
  11. Gesior.pl

    Gesior.pl Mega Noob&LOL 2012

    Joined:
    Sep 18, 2007
    Messages:
    1,809
    Likes Received:
    625
    Best Answers:
    1
    1. Edit formula to make it lower (but it won't block at lvl 5000000, you got 1% chance to make it stop at lvl 5000000 exactly).
    but let's try:
    ... wolfram alpha failed :( ...
    You cannot make nice formula for 5.000.000 lvl, but you can check what I found with super-math computer http://www.wolframalpha.com/
    This is formula for max level 5.000.003 (im not 100% sure that it will work):
    Code (Text):
    1.  
    2. static uint64_t getExpForLevel(int32_t lv) {
    3. return 400ULL + 737869ULL * lv * lv - 737869ULL * lv;
    4. }
    5.  
    Problem can be on low level, it will lvl up very slowly.

    Of course best lvl 5.000.000 limit is stages.xml multiplier ZERO on lvl 5.000.000
     
    Limos and Evil Puncker like this.
  12. Evil Puncker

    Evil Puncker I'd rather kiss a rattlesnake

    Joined:
    May 30, 2009
    Messages:
    5,367
    Likes Received:
    1,593
    Best Answers:
    1
    great gesior! and what about tfs 1.x?
     
  13. Gesior.pl

    Gesior.pl Mega Noob&LOL 2012

    Joined:
    Sep 18, 2007
    Messages:
    1,809
    Likes Received:
    625
    Best Answers:
    1
    It's same in all TFSes.
     
    Evil Puncker likes this.
  14. Sir Islam

    Sir Islam Never Give Up

    Joined:
    Jun 6, 2008
    Messages:
    500
    Likes Received:
    116
    Best Answers:
    0
    ty alot @Gesior
    I Want To Break Monsters' Hp Limit, have any idea
     
  15. Gesior.pl

    Gesior.pl Mega Noob&LOL 2012

    Joined:
    Sep 18, 2007
    Messages:
    1,809
    Likes Received:
    625
    Best Answers:
    1
    Version with cache is 10-20 times slower (I did tests with 200.000 reading same level with cache and without). I think that why it's not cached in TFS 1.0.
    Cache is good when you make some very advanced calculations, not 10 x simple +,-,*. Allocating RAM, store data, read data, search something in 'map' - it all takes much more time then simple math.

    Solution: do not break limits of INTs, it's not a good plan. First you change something in one place, then you must change it everywhere in sources.. and then you figure out that there is no chance to show it in client, because you cannot modify tibia client variables.
    Like OTS did with experience, you can get 18.000.000.000.000.000.000.000 exp, but in client it shows only 2.147.000.000 and Hp/mana: you can get 2.147.000.000 HP/MANA, but in client it shows only 65515 (at least in this case HP % bar works fine).
     
  16. Niioxce

    Niioxce Otland lurker

    Joined:
    Jun 22, 2012
    Messages:
    297
    Likes Received:
    2
    Best Answers:
    0
    Yea, i noticed that because when i raised the exp ratio to like 12000000000 it collected around 2GB of ram lol and then crashed :D

    By the way @Gesior.pl i also noticed that my damage has increased significantly, just check this out
    Code (Text):
    1.  
    2. 23:26 You deal 1316134911 damage to a Trainer.
    3.  
    I literally one shotted a trainer, Evil hero said to me that i had to edit the source ALOT.
    Any other way to fix this? :)

    Btw thanks for the tutorial, much love from sweden!
     
  17. StreamSide

    StreamSide Joseluis Gonzalez

    Joined:
    Aug 31, 2007
    Messages:
    2,576
    Likes Received:
    507
    Best Answers:
    1
    is just a formula
     
  18. Semsem

    Semsem New Member

    Joined:
    Jun 1, 2013
    Messages:
    15
    Likes Received:
    4
    Best Answers:
    0
    what about cntrol+S bug?
     
  19. cuba

    cuba Member

    Joined:
    Feb 24, 2015
    Messages:
    136
    Likes Received:
    2
    Best Answers:
    0
    how can i remove all .o files to rebuild source?
     
  20. Gesior.pl

    Gesior.pl Mega Noob&LOL 2012

    Joined:
    Sep 18, 2007
    Messages:
    1,809
    Likes Received:
    625
    Best Answers:
    1
    I dont know in which folder are these files in TFS 1.0, but in 0.3.6 and 0.4 it was in folder in which you type 'make' to compile TFS. In this folder type:
    rm *.o
    to remove all files that ends with .o
     

Share This Page

Loading...