Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
Monsterovich committed Nov 6, 2024
1 parent 41bbf99 commit f3a1727
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ int32_t objDamage(BASE_OBJECT *psObj, PROJECTILE *psProjectile, unsigned damage,
Vector3i dv;
dv.y = psProjectile->pos.z;

for (uint32_t i = 0; i < DROID_SHIELD_PARTICLES; i++)
for (int i = 0; i < DROID_SHIELD_PARTICLES; i++)
{
dv.x = psProjectile->pos.x + DROID_SHIELD_DAMAGE_SPREAD;
dv.z = psProjectile->pos.y + DROID_SHIELD_DAMAGE_SPREAD;
Expand Down
2 changes: 1 addition & 1 deletion src/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ static bool displayCompObj(DROID *psDroid, bool bButton, const glm::mat4& modelM

if (!bButton && psDroid->shieldPoints > 0 && droidGetMaxShieldPoints(psDroid) > 0)
{
double factor = static_cast<double>(psDroid->shieldPoints) / droidGetMaxShieldPoints(psDroid);
float factor = static_cast<float>(psDroid->shieldPoints) / droidGetMaxShieldPoints(psDroid);
iShieldPieData = static_cast<SDWORD>(std::round(255.0f * factor));
shieldPieFlag = pie_FORCELIGHT | pie_TRANSLUCENT | pie_SHIELD;
}
Expand Down
10 changes: 5 additions & 5 deletions src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,12 +974,12 @@ void droidUpdateShields(DROID *psDroid)
gameTime - psDroid->shieldInterruptRegenTime > droidCalculateShieldInterruptRegenTime(psDroid) &&
gameTime - psDroid->shieldRegenTime > droidCalculateShieldRegenTime(psDroid))
{
for (int i = 0; i < psDroid->getBrainStats()->shield.shieldPointsPerStep; i++)
auto availableShieldPoints = droidGetMaxShieldPoints(psDroid) - psDroid->shieldPoints;

if (availableShieldPoints > 0)
{
if (psDroid->shieldPoints < droidGetMaxShieldPoints(psDroid))
{
psDroid->shieldPoints += 1;
}
auto pointsToAdd = std::min<UDWORD>(psDroid->getBrainStats()->shield.shieldPointsPerStep, availableShieldPoints);
psDroid->shieldPoints += pointsToAdd;
}
psDroid->shieldRegenTime = gameTime;
}
Expand Down

0 comments on commit f3a1727

Please sign in to comment.