Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
[sailors] fix the rest of rand()
Browse files Browse the repository at this point in the history
  • Loading branch information
espkk committed Jun 12, 2022
1 parent e27d13e commit e308252
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/libs/sailors/src/sailors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,12 @@ bool ShipMan::RotateToAngle(uint32_t &dltTime, SailorsPoints &sailorsPoints)

int ShipMan::FindRandomPoint(SailorsPoints &sailorsPoints, ShipState &shipState)
{
int ran;
// If combat mode or reload, then look for free guns
for (auto m = 0; m < sailorsPoints.points.count; m++)
{
for (auto i = 0; i < sailorsPoints.points.count; i++)
{
ran = static_cast<int>(rand() * (sailorsPoints.points.count - 1) / static_cast<float>(RAND_MAX));
const int ran = rand() % sailorsPoints.points.count;

if (sailorsPoints.points.point[ran].IsCannon())
{
Expand All @@ -200,7 +199,7 @@ int ShipMan::FindRandomPoint(SailorsPoints &sailorsPoints, ShipState &shipState)
{
for (auto i = 0; i < sailorsPoints.points.count; i++)
{
ran = static_cast<int>(rand() * (sailorsPoints.points.count - 1) / static_cast<float>(RAND_MAX));
const int ran = rand() % sailorsPoints.points.count;

if (!sailorsPoints.points.point[ran].disabled)
{
Expand All @@ -223,7 +222,7 @@ int ShipMan::FindRandomPoint(SailorsPoints &sailorsPoints, ShipState &shipState)
{
for (auto i = 0; i < sailorsPoints.points.count; i++)
{
ran = static_cast<int>(rand() * (sailorsPoints.points.count - 1) / static_cast<float>(RAND_MAX));
const int ran = rand() % sailorsPoints.points.count;

if (ran != targetWayPoint && !sailorsPoints.points.point[ran].buisy &&
sailorsPoints.points.point[ran].pointType == PT_TYPE_NORMAL)
Expand All @@ -240,7 +239,6 @@ int ShipMan::FindRandomPoint(SailorsPoints &sailorsPoints, ShipState &shipState)
int ShipMan::FindRandomPointWithoutType(const SailorsPoints &sailorsPoints) const
// Find any simple point
{

for (size_t i = 0; i != sailorsPoints.points.count; ++i)
{
const auto idx = rand() % sailorsPoints.points.count;
Expand Down Expand Up @@ -479,7 +477,6 @@ void ShipMan::SetAnimation(uint32_t dltTime, ShipState &shipState)
{
if (const auto ani = model->GetAnimation(); mode == lastMode && ani && ani->Player(0).IsPlaying())
return;
float ran;

switch (mode)
{
Expand All @@ -488,6 +485,7 @@ void ShipMan::SetAnimation(uint32_t dltTime, ShipState &shipState)
model->GetAnimation()->Player(0).SetPosition(rand() / static_cast<float>(RAND_MAX));
model->GetAnimation()->Player(0).Play();

// TODO: check this
manSpeed = MOVE_SPEED + rand() * MOVE_SPEED / static_cast<float>(RAND_MAX) / 4.0f -
rand() * MOVE_SPEED / static_cast<float>(RAND_MAX) / 4.0f;

Expand All @@ -501,9 +499,8 @@ void ShipMan::SetAnimation(uint32_t dltTime, ShipState &shipState)
manSpeed = RUN_SPEED;
rotSpeed = MOVE_SPEED * 5.0f;
break;
case MAN_STAY:

ran = rand() / static_cast<float>(RAND_MAX);
case MAN_STAY: {
float ran = rand() / static_cast<float>(RAND_MAX);

if (ran < 0.25f)
model->GetAnimation()->Player(0).SetAction("action1");
Expand All @@ -516,6 +513,7 @@ void ShipMan::SetAnimation(uint32_t dltTime, ShipState &shipState)

model->GetAnimation()->Player(0).SetPosition(rand() / static_cast<float>(RAND_MAX));
model->GetAnimation()->Player(0).Play();
}
break;
case MAN_TURNLEFT:
model->GetAnimation()->Player(0).SetAction("turn_left");
Expand Down Expand Up @@ -620,16 +618,16 @@ void ShipMan::NewAction(SailorsPoints &sailorsPoints, ShipState &shipState, uint

switch (shipState.mode)
{
case SHIP_SAIL:
float ran;
ran = rand() / static_cast<float>(RAND_MAX);
case SHIP_SAIL: {
float ran = rand() / static_cast<float>(RAND_MAX);

if (mode != MAN_STAY && ran < 0.1f)
mode = MAN_RUN;
else if (ran < 0.6f || mode == MAN_STAY)
mode = MAN_WALK;
else
mode = MAN_STAY;
}
break;
case SHIP_WAR:
case SHIP_STORM:
Expand Down

0 comments on commit e308252

Please sign in to comment.