• 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!

Fixed When upgrading hull goes to 105%

Levis

Find(Rum) = false;
Staff member
Administrator
Creative Support
Programmer
Storm Modder
* This issue existed from previous versions as well. When I get ship upgrade regarding hull.. the ship turns 105% which on the lower left corner bar it shows black color as in 0% hull health.
View attachment 22979 View attachment 22980

I think I've only fixed it in some interfaces but need to look again. Might just be a matter of updating the max HP
 
Max HP is probably updated but current HP is not. So if you bought an upgrade which reduced the max HP then your current HP is now higher than the maximum, which is why the ship's health bar looks wrong. The first hit won't sink you but if it drops your HP from 105% to 100% or less then you'll get the normal red bar back.
 
The only time I have seen this is when relaunching a birthed ship. It always has a black bar, but the first storm usually fixes that.
 
It's using this function to get the hull percentage:

Code:
float GetHullPercent(ref _refCharacter)
{
    if(!CheckAttribute(_refCharacter,"Ship.HP")) return 100.0;
    int iHP = GetCharacterShipHP(_refCharacter);
    if(iHP<=0) return 100.0;
    float fphp = 100.0*stf(_refCharacter.Ship.HP)/iHP;
    return fphp;
}

This calles for GetCharacterShipHP:

Code:
int GetCharacterShipHP(ref _refCharacter)
{
    int nShipType = GetCharacterShipType(_refCharacter);
    if (nShipType <0 || nShipType >= SHIP_TYPES_QUANTITY) { return 0; } // PB: Prevent CTDs
    aref arship; makearef(arship, _refCharacter.ship); // PRS3
    return sti(GetLocalShipAttrib(arship, &ShipsTypes[nShipType], "HP")); // PRS3
}

This calles for GetLocalShipAttrib:
Code:
string GetLocalShipAttrib(aref chrship, ref ship, string attrib) //pass this the chr and the shipstypes[] entry and the attribute name. Will return local version if there.
{
    //originally written to use a string; should work ok without it.
    //string tmpstr;
    //tmpstr = ship.(attrib);
    // NK special handling for cannon qty 05-04-18 -->
    if(attrib == "CurCanQty")
    {
// KK -->
        if (CheckAttribute(chrship, "Cannons.Type") == true && sti(chrship.Cannons.Type) == CANNON_TYPE_NONECANNON) return "0";
        if (CheckAttribute(chrship,"Cannons.Borts.cannonf.qty") && CheckAttribute(chrship,"Cannons.Borts.cannonb.qty") && CheckAttribute(chrship,"Cannons.Borts.cannonl.qty") && CheckAttribute(chrship,"Cannons.Borts.cannonr.qty"))
            return "" + (sti(chrship.Cannons.Borts.cannonf.qty) + sti(chrship.Cannons.Borts.cannonb.qty) + sti(chrship.Cannons.Borts.cannonl.qty) + sti(chrship.Cannons.Borts.cannonr.qty));
        else
            return GetLocalShipAttrib(&chrship, &ship, "CannonsQuantity");
        // TIH <-- empty cannons bug fix
// <-- KK
    }
    if(attrib == "MaxCanQty")
    {
        int fullqty = sti(GetLocalShipAttrib(&chrship, &ship, "Cannons.Borts.cannonf.qty"));
        fullqty += sti(GetLocalShipAttrib(&chrship, &ship, "Cannons.Borts.cannonb.qty"));
        fullqty += sti(GetLocalShipAttrib(&chrship, &ship, "Cannons.Borts.cannonl.qty"));
        fullqty += sti(GetLocalShipAttrib(&chrship, &ship, "Cannons.Borts.cannonr.qty"));
        return ""+fullqty;
    }
    // NK <--
    if(CheckAttribute(chrship,"stats."+attrib)) return chrship.stats.(attrib);   <------------THIS LINE SHOULD RETURN
    if (CheckAttribute(ship, attrib)) return ship.(attrib); // KK
    return ""; // KK
}

So it should return the stats.HP of the chrship which is compared to the HP
But Applytun does this:
Code:
void applytunhullhp(ref _char, string _improvement, float rangemax, float rangemin) {
    float j;
    float pertoadd;
    aref temparef;
 
    j = rangemax - rangemin;
    pertoadd = j*frnd()+rangemin;
    if (rand(11) <= GetCharacterSkill(_char, "sneak")) { pertoadd=pertoadd+1; } // KK
    if (rand(11) <= GetCharacterSkill(_char, "sailing")) { pertoadd=pertoadd+(0.5*j); } // KK
    if (pertoadd > rangemax) { pertoadd = rangemax;}
    _char.ship.tune.(_improvement).on = 1;
    // KB & PB: Error control -->
    makearef(temparef,_char.ship.stats);
    if (!CheckAttribute(temparef,"orighp"))
    {
        if(!CheckAttribute(temparef, "hp"))
        {
            int HP = GetCharacterShipValue(_char, "HP");
            temparef.hp = HP; // PB: Why does "temparef.hp = GetCharacterShipValue(_char, "HP");" return 0???
        }
        temparef.orighp = temparef.hp;
    }
    // KB & PB: Error control <--
    _char.ship.tune.(_improvement).hp = stf(_char.ship.stats.orighp) * pertoadd/100;
    _char.ship.stats.hp = sti(_char.ship.stats.hp) + sti(_char.ship.tune.(_improvement).hp); <----------AFTER THIS LINE
/*    if(IsMainCharacter(_char))
    {
        LogIt("Ships hull hps increased by " + _char.ship.tune.(_improvement).hp);
        LogIt("Max possible improvement = " + (stf(_char.ship.stats.orighp) * rangemax/100));
        LogIt("Ships new hps = " + _char.ship.stats.hp);
    }*/
}
So everything seems to be okay.
Untill we have a negative change cause then the HP isn't updated indeed.
And flushing seems to have an negative increase on the HP so that's what causing it.
Adding an change to the current HP here should do the trick.
So I sugest adding this line:
Code:
_char.ship.hp = sti(_char.ship.hp) + sti(_char.ship.tune.(_improvement).hp);
After the line I showed.
I included a version of the file in here. Place it in PROGRAM. Could someone test it? I can't atm.
 
Last edited:
That's fine so long as your ship is at full HP before the upgrade. (Do you need to repair the ship to 100% hull before upgrading?)

If I understand all the variable correctly, might not this be better?
Code:
if (sti(_char.ship.hp) > sti(_char.ship.stats.hp)) _char.ship.hp = _char.ship.stats.hp;
If I haven't got the variables right, the logic should at least be valid - if the ship's actual HP is greater than the maximum HP, set HP to the maximum.
 
That's fine so long as your ship is at full HP before the upgrade. (Do you need to repair the ship to 100% hull before upgrading?)

If I understand all the variable correctly, might not this be better?
Code:
if (sti(_char.ship.hp) > sti(_char.ship.stats.hp)) _char.ship.hp = _char.ship.stats.hp;
If I haven't got the variables right, the logic should at least be valid - if the ship's actual HP is greater than the maximum HP, set HP to the maximum.

the one I posted should work just fine.
The only thing which could make it fail if the HP is lower then the amount you are going to substract so it could get below 0. Might need to add a check for that.
 
Now the check is also included
 

Attachments

  • KB_routines.c
    23.8 KB · Views: 127
I had to change the code to this:
Code:
  if (CheckAttribute(_char, "ship.hp"))
   {
     int shipHP = sti(_char.ship.hp);
     int tuneHP = sti(_char.ship.tune.(_improvement).hp));
     if(shipHP + tuneHP > 0) _char.ship.hp = shipHP + tuneHP; //Levis added check to make sure we dont go under 0
   }
   else
   {
     Trace("Error: " + GetMySimpleName(_char) + " does not have ship HP!");
   }
Got the following log messages on a New Game:
Code:
Error: Mergildo Hurtado does not have ship HP!
Error: Mystery Man does not have ship HP!
Error: Mystery Man does not have ship HP!
Error: Mystery Man does not have ship HP!
Error: Mystery Man does not have ship HP!
Error: Mystery Man does not have ship HP!
Error: Mystery Man does not have ship HP!
Error: Mystery Man does not have ship HP!
Error: Mystery Man does not have ship HP!
Error: Mystery Man does not have ship HP!
Error: Mystery Man does not have ship HP!
Error: Simon Blunden does not have ship HP!
Error: Xabe Oraglio does not have ship HP!
Error: Xabe Oraglio does not have ship HP!
Error: Gyles Dubois does not have ship HP!
Error: Gyles Dubois does not have ship HP!
Error: Gyles Dubois does not have ship HP!
Error: Giraldo Figuiera does not have ship HP!
Error: Giraldo Figuiera does not have ship HP!
Error: Pirate seven does not have ship HP!
Error: Ethilrede Claar does not have ship HP!
Error: Ethilrede Claar does not have ship HP!
Error: Jack Greenfield does not have ship HP!
Error: Silver does not have ship HP!
Error: Claire Larrouse does not have ship HP!
Error: Skull does not have ship HP!
Error: Skull does not have ship HP!
Error: Will Turner does not have ship HP!
Error: Txiki Pijuan does not have ship HP!
Error: Vigila Mendes does not have ship HP!
Error: Isenbrandt Jurcksen does not have ship HP!
Error: John Coxon does not have ship HP!
Error: John Coxon does not have ship HP!
Error: Randolf Blecher does not have ship HP!
Error: Aron Bester does not have ship HP!
Error: Enrique Padilla does not have ship HP!
Error: Nicholas Butcher does not have ship HP!
Error:  roche Brasiliano does not have ship HP!
Error:  roche Brasiliano does not have ship HP!
Error: Rabel Chardon does not have ship HP!
Error: Clement Bossicar does not have ship HP!
Error: Henry Morgan does not have ship HP!
Error: Henry Morgan does not have ship HP!
Error: Diablo does not have ship HP!
Error: Gilles Chennault does not have ship HP!
Error: David Fewster does not have ship HP!
Error: Laurence Damson does not have ship HP!
Error: Lorenzo Barrigo does not have ship HP!
Error: Bautista Lozano does not have ship HP!
Error: Lunes Suarez does not have ship HP!
Error: Mary Wood does not have ship HP!
Error: Malcolm Hatcher does not have ship HP!
Error:  does not have ship HP!
Error:  does not have ship HP!
Error:  does not have ship HP!
Perhaps a bit weird, no?

For now, I'll leave that CheckAttribute in place but perhaps a better fix to prevent this would be needed?
 
Back
Top