mirror of
https://github.com/HomeworldSDL/HomeworldSDL.git
synced 2025-10-29 19:45:21 +00:00
Fix float to int conversion in statistic code used for AI ship creation
This commit is contained in:
parent
5b23bd8d0a
commit
0eb31e67cf
@ -364,7 +364,7 @@ void aioCreateReinforcements(AITeam *team, AITeam *reinforceteam, ShipType shipt
|
||||
{
|
||||
aiplayerLog((aiIndex, "%x Issuing Reinforcements Order", team));
|
||||
|
||||
if (num)
|
||||
if (num > 0)
|
||||
{
|
||||
if (alternatives)
|
||||
{
|
||||
|
||||
@ -1726,6 +1726,7 @@ sdword statsNumShipsNeededToKillTarget(ShipStaticInfo *shipstatic,ShipStaticInfo
|
||||
{
|
||||
real32 killratio = statsGetShipKillRatingAgainstShip(shipstatic,targetstatic);
|
||||
real32 num;
|
||||
sdword num_ships = 0;
|
||||
|
||||
if (killratio >= 1)
|
||||
{
|
||||
@ -1736,13 +1737,24 @@ sdword statsNumShipsNeededToKillTarget(ShipStaticInfo *shipstatic,ShipStaticInfo
|
||||
num = 1.0f / killratio;
|
||||
}
|
||||
|
||||
return ((sdword)(num * statsOverkillfactor));
|
||||
// Ensure that after casting to sdword, we don't get a negative number (-2147483648)
|
||||
// which can happen if killratio is very small/close to 0 and we get an infty for num.
|
||||
// Probably caused by a ship for which there is no entry in the ship vs ship stats table.
|
||||
num_ships = ((sdword)(num * statsOverkillfactor));
|
||||
|
||||
if (num_ships < 0)
|
||||
{
|
||||
num_ships = 0;
|
||||
}
|
||||
|
||||
return num_ships;
|
||||
}
|
||||
|
||||
sdword statsNumShipsNeededToKillFleet(ShipStaticInfo *shipstatic,SelectCommand *targetFleet)
|
||||
{
|
||||
real32 killratio = statsGetKillRatingAgainstFleet(shipstatic,targetFleet);
|
||||
real32 num;
|
||||
sdword num_ships = 0;
|
||||
|
||||
if (killratio == 0.0f)
|
||||
{
|
||||
@ -1757,7 +1769,17 @@ sdword statsNumShipsNeededToKillFleet(ShipStaticInfo *shipstatic,SelectCommand *
|
||||
num = 1.0f / killratio;
|
||||
}
|
||||
|
||||
return (((sdword)(num * statsOverkillfactor)));
|
||||
// Ensure that after casting to sdword, we don't get a negative number (-2147483648)
|
||||
// which can happen if killratio is very small/close to 0 and we get an infty for num.
|
||||
// Probably caused by a ship for which there is no entry in the ship vs ship stats table.
|
||||
num_ships = ((sdword)(num * statsOverkillfactor));
|
||||
|
||||
if (num_ships < 0)
|
||||
{
|
||||
num_ships = 0;
|
||||
}
|
||||
|
||||
return num_ships;
|
||||
}
|
||||
|
||||
// strength of fleet2 against fleet1, e.g. fleet2/fleet1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user