1. Dismiss Notice
  2. GOG.com logo

    Thanks to YOUR votes, GOG.com now sells:
    - Sea Dogs - Sea Dogs: Caribbean Tales
    - Sea Dogs: City of Abandoned Ships

    Vote now to add Pirates of the Caribbean to the list!

    Dismiss Notice
  3. Under the Crossbones Podcast

    A Pirate Podcast with Interviews
    Music, Comedy and all things Pirate!

    - Episode Guide - About - Subscribe -
    - Twitter - Facebook - iTunes - Android -
    - Youtube - Fill the Coffers -

    Dismiss Notice
  4. New Horizons logo

    Quick links for PotC: New Horizons
    - Download latest version
    - Wiki - FAQ - Report bugs here
    - ModDB profile

  5. GOF logo

    Quick links for AoP2: Gentlemen of Fortune 2
    - Downloads and info
    - Historical Immersion Supermod
    - ModDB Profile

Dismiss Notice
New to the forum?
Please take a moment to read our Welcome Message and Forum Rules.

Making MaxHealthPotionForCharacter less wasteful

Discussion in 'Build Beta and Brainstorming' started by MrMister, Jan 4, 2018.

  1. MrMister

    MrMister Landlubber

    Joined:
    Jan 13, 2014
    Messages:
    24
    Gender:
    Male
    By default, the potion hotkey uses the least powerful potion in the player's inventory, found with the function MaxHealthPotionForCharacter. This can be changed by redefining USEMAXPOTION_ONKEYPRESS to 1 instead of the default 0, which will instead choose the most powerful potion avaliable, as found by function MaxHealthPotionForCharacter.


    I've just taken a quick look at MaxHealthPotionForCharacter, and I'm 99% sure it does still choose the most powerful potion even if a less powerful one would be enough to restore the player's health to full, which is a less efficient potion usage than using the least powerful potion able to completely heal the player.

    My idea/suggestion:

    Redefine MaxHealthPotionForCharacter so that it chooses the least powerful potion that would heal to full, and if none would do so, still chose the most powerful one. I think it is possible to do so without adding arguments, by using functions LAi_GetCharacterHP(PChar) and LAi_GetCharacterMaxHP(PChar) inside of it, but adding the difference between those two as a third argument is also possible, since it is only used once in the whole gamecode, in seadogs.c.

    This would greatly increase the usefulness of the potion hotkey in combat, and if working well could be reason to default USEMAXPOTION_ONKEYPRESS to 1.

    I miiiiiiight or might not look into changing the code myself, but I'm leaving this here as a reminder anyway.
     
  2. Pieter Boelen

    Pieter Boelen (Not So) Old Seadog Staff Member Administrator Storm Modder Hearts of Oak Donator

    Joined:
    Nov 11, 2004
    Messages:
    66,957
    Gender:
    Male
    Occupation:
    Maritime Research: Project Engineer (Analysis)
    Location:
    Wageningen, The Netherlands
    The idea definitely makes sense. I like it! :onya
     
  3. MrMister

    MrMister Landlubber

    Joined:
    Jan 13, 2014
    Messages:
    24
    Gender:
    Male
    Did it; code doesn't crash the game, but I don't have the time to test it properly right now, and might not have for a couple of weeks.

    If anyone with a savegame with multiple potions wanna test it, just change the MaxHealthPotionForCharacter function's code items_utilite.c for the one in the attached file. And also change its call in seadogs.c to:

    MaxHealthPotionForCharacter(PChar, &idx, LAi_GetCharacterMaxHP(PChar) - LAi_GetCharacterHP(PChar));

    And of course enable USEMAXPOTION_ONKEYPRESS in internal_settings.h.
     

    Attached Files:

    Pieter Boelen likes this.
  4. Pieter Boelen

    Pieter Boelen (Not So) Old Seadog Staff Member Administrator Storm Modder Hearts of Oak Donator

    Joined:
    Nov 11, 2004
    Messages:
    66,957
    Gender:
    Male
    Occupation:
    Maritime Research: Project Engineer (Analysis)
    Location:
    Wageningen, The Netherlands
  5. Grey Roger

    Grey Roger Sea Dog Staff Member Storm Modder

    Joined:
    Feb 12, 2007
    Messages:
    6,663
    I'm not sure how much use this would be. Bandages heal 30 and are common (by the time I finished a playthrough of one storyline, I had over 1000 of them, despite occasionally using them myself and also handing them out to officers who used them more frequently). Cauterization kits heal 60 and are less common. The various potions are even rarer; small potions heal 100, large potions heal 150, mixtures heal 60 as well as cure poison, rum heals 50, wine heals 180. A low level character is likely to be healed by one bandage. A high level character probably won't be healed even by wine, which is presumably what will be selected if you set "USEMAXPOTION_ONKEYPRESS" to 1 at present and which would presumably also be selected by the proposed version. So the only character who is likely to benefit is a mid-level character who has taken over 50 and less than 60 damage before reaching for the "heal" button, so that the game doesn't choose to use your only bottle of rum in preference to one of the dozen or so cauterization kits you're carrying.

    However, if @MrMister can provide modified versions of "items_utilite.c" and "seadogs.c" which recognise three possible settings of "USEMAXPOTION_ONKEYPRESS" (0 = use smallest potion, 1 = use largest potion, 2 = use smallest potion which heals to full), and if it is fully tested, then I'll include it. (But because of the prevalence of bandages, I'd still prefer to keep "USEMAXPOTION_ONKEYPRESS" default to 0.)
     
  6. Pieter Boelen

    Pieter Boelen (Not So) Old Seadog Staff Member Administrator Storm Modder Hearts of Oak Donator

    Joined:
    Nov 11, 2004
    Messages:
    66,957
    Gender:
    Male
    Occupation:
    Maritime Research: Project Engineer (Analysis)
    Location:
    Wageningen, The Netherlands
    What would be the advantage to having a "largest" and a "smallest that heals to maximum" version?
    "Largest" would just be wasteful, wouldn't it? :unsure
     
  7. Myth

    Myth Master Mariner

    Joined:
    Mar 25, 2014
    Messages:
    225
    Gender:
    Male
    case "BOAL_UsePotion": // boal KEY_C
    if (bLandInterfaceStart)
    {
    if(!LAi_IsBottleWork(pchar))
    {
    itmIdx = FindPotionFromChr(pchar, &arItm, 0);
    while(itmIdx>=0)
    {
    if( EnablePotionUsing(pchar, arItm) && !LAi_IsPoison (pchar))
    {
    PlaySound("Ambient\Tavern\glotok_001.wav");
    DoCharacterUsedItem(pchar, arItm.id);
    break;
    }
    itmIdx = FindPotionFromChr(pchar, &arItm, itmIdx+1);
    }
    if(itmIdx == -1 && LAi_GetCharacterHP(pchar)<LAi_GetCharacterMaxHP(pchar) && !LAi_IsPoison (pchar) )
    {
    Log_Info("Элексир не найден!");
    PlaySound("interface\knock.wav");
    }
    }
    else
    {
    PlaySound("interface\notebook.wav");
    Log_Info("Элексир все еще действует!");
    }
    }
    break;

    I especially did not play in new horizons. It is difficult to say how the treatment of the hero is arranged there. But I know that in pure COAS potions you can drink without stopping, even if another potion works. In my fashion, I adjusted it.
     
  8. Grey Roger

    Grey Roger Sea Dog Staff Member Storm Modder

    Joined:
    Feb 12, 2007
    Messages:
    6,663
    That is why "InternalSettings.h" should leave the default set to 0. ;) Depending on what you're carrying, the "largest" and "smallest that heals to maximum" may also be the only one of that potion which you're carrying - if you have 200 bandages, 20 cauterization kits and 1 bottle of rum, and you've taken 40 points of damage, which would you rather use? Bandages are the smallest and are easily available, cauterization kits are the largest and are not so easily available, rum is "smallest that heals to maximum" and good luck finding another one!
     
  9. MrMister

    MrMister Landlubber

    Joined:
    Jan 13, 2014
    Messages:
    24
    Gender:
    Male
    I guess I could also make a "largest that doesn't overheal, else smallest" setting, but yeah, at least "smallest that fully heals, else largest" should have no disadvantage over "largest". Or one that uses "smallest" with blade sheated and one of the two optimizing ones when in combat with blade drawn.

    Anyway, I'll look into it again after exams.
     
    Pieter Boelen likes this.
  10. Pieter Boelen

    Pieter Boelen (Not So) Old Seadog Staff Member Administrator Storm Modder Hearts of Oak Donator

    Joined:
    Nov 11, 2004
    Messages:
    66,957
    Gender:
    Male
    Occupation:
    Maritime Research: Project Engineer (Analysis)
    Location:
    Wageningen, The Netherlands

Share This Page