• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Making MaxHealthPotionForCharacter less wasteful

MrMister

Sailor Apprentice
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.
 
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.
 

Attachments

  • maxhealthpotionforcharacter.c
    894 bytes · Views: 178
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.)
 
1 = use largest potion, 2 = use smallest potion which heals to full
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
 
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.
 
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
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!
 
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.
 
Back
Top