Skip to content

Commit

Permalink
Fixed defect 221.
Browse files Browse the repository at this point in the history
  • Loading branch information
klei1984 committed Sep 24, 2024
1 parent 2a8ae03 commit 2c17d9a
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1265,8 +1265,8 @@ bool Access_IsValidNextUnit(UnitInfo* unit) {
result = false;

} else if (Access_IsWithinMovementRange(unit) ||
(unit->shots && Access_FindReachableSpot(unit->GetUnitType(), unit, &grid_x, &grid_y,
unit_values->GetAttribute(ATTRIB_RANGE), 0, 1))) {
(unit->shots > 0 && Access_FindReachableSpot(unit->GetUnitType(), unit, &grid_x, &grid_y,
unit_values->GetAttribute(ATTRIB_RANGE), 0, 1))) {
result = true;

} else {
Expand Down
4 changes: 2 additions & 2 deletions src/aiattack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ bool AiAttack_EvaluateAttack(UnitInfo* unit, bool mode) {

if (GameManager_PlayMode != PLAY_MODE_UNKNOWN) {
if (unit->ammo || (GameManager_PlayMode != PLAY_MODE_TURN_BASED || GameManager_ActiveTurnTeam == unit->team)) {
if (unit->shots || !unit->GetBaseValues()->GetAttribute(ATTRIB_MOVE_AND_FIRE)) {
if (unit->shots > 0 || !unit->GetBaseValues()->GetAttribute(ATTRIB_MOVE_AND_FIRE)) {
if (unit->delayed_reaction || TaskManager_word_1731C0 == 2) {
SmartPointer<Task> wait_to_attack_task(new (std::nothrow) TaskWaitToAttack(unit));

Expand All @@ -716,7 +716,7 @@ bool AiAttack_EvaluateAttack(UnitInfo* unit, bool mode) {
SmartPointer<SpottedUnit> spotted_unit;
int32_t attack_radius;

if (unit->shots) {
if (unit->shots > 0) {
attack_radius = unit->GetBaseValues()->GetAttribute(ATTRIB_ATTACK_RADIUS) / 2;

} else {
Expand Down
8 changes: 4 additions & 4 deletions src/drawmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ void DrawMap_RenderStatusDisplay(UnitInfo* unit, int32_t ulx, int32_t uly, int32
true, window);
}

} else if (unit->speed || unit->shots) {
} else if (unit->speed || unit->shots > 0) {
struct ImageSimpleHeader* image_speed;
struct ImageSimpleHeader* image_shots;

Expand All @@ -472,7 +472,7 @@ void DrawMap_RenderStatusDisplay(UnitInfo* unit, int32_t ulx, int32_t uly, int32
}

if (width >= 0) {
if (unit->shots) {
if (unit->shots > 0) {
image_shots = reinterpret_cast<struct ImageSimpleHeader*>(ResourceManager_LoadResource(IL_SHOTS));

if (image_shots->height > height - uly) {
Expand All @@ -484,7 +484,7 @@ void DrawMap_RenderStatusDisplay(UnitInfo* unit, int32_t ulx, int32_t uly, int32
}

if (width >= 0) {
if (unit->shots && unit->speed) {
if (unit->shots > 0 && unit->speed) {
width /= 3;

} else {
Expand All @@ -498,7 +498,7 @@ void DrawMap_RenderStatusDisplay(UnitInfo* unit, int32_t ulx, int32_t uly, int32
width = width * 2 + image_speed->width;
}

if (unit->shots) {
if (unit->shots > 0) {
WindowManager_DecodeSimpleImage(image_shots, width + ulx, height - image_shots->height - 1, true,
window);
}
Expand Down
15 changes: 8 additions & 7 deletions src/game_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3460,8 +3460,8 @@ bool GameManager_IsInteractable(UnitInfo* unit) {
int16_t grid_y = unit->grid_y;
SmartPointer<UnitValues> unit_values(unit->GetBaseValues());

if (unit->shots && Access_FindReachableSpot(unit_type, unit, &grid_x, &grid_y,
unit_values->GetAttribute(ATTRIB_RANGE), 0, 1)) {
if (unit->shots > 0 && Access_FindReachableSpot(unit_type, unit, &grid_x, &grid_y,
unit_values->GetAttribute(ATTRIB_RANGE), 0, 1)) {
result = true;

} else if ((unit_type == SPLYTRCK || unit_type == CARGOSHP || unit_type == FUELTRCK || unit_type == GOLDTRCK ||
Expand Down Expand Up @@ -4335,7 +4335,7 @@ void GameManager_SetUnitOrder(int32_t order, int32_t state, UnitInfo* unit, int3
unit->path = nullptr;

} else {
if (unit->shots) {
if (unit->shots > 0) {
unit->target_grid_x = grid_x;
unit->target_grid_y = grid_y;

Expand Down Expand Up @@ -4851,7 +4851,7 @@ void GameManager_StealUnit(UnitInfo* unit1, UnitInfo* unit2) {
unit2 = Access_GetAttackTarget(unit1, unit2->grid_x, unit2->grid_y);

if (unit2) {
if (unit1->shots) {
if (unit1->shots > 0) {
unit1->SetParent(unit2);
unit1->target_grid_x = (dos_rand() * 101) >> 15;

Expand All @@ -4867,7 +4867,7 @@ void GameManager_DisableUnit(UnitInfo* unit1, UnitInfo* unit2) {
unit2 = Access_GetAttackTarget(unit1, unit2->grid_x, unit2->grid_y);

if (unit2) {
if (unit1->shots) {
if (unit1->shots > 0) {
unit1->SetParent(unit2);
unit1->target_grid_x = (dos_rand() * 101) >> 15;

Expand Down Expand Up @@ -7775,8 +7775,9 @@ void GameManager_UpdateInfoDisplay(UnitInfo* unit) {
GameManager_DrawInfoDisplayRow(_(c372), WINDOW_STAT_ROW_3, SI_SPEED, unit->speed,
unit_values->GetAttribute(ATTRIB_SPEED), 1);

GameManager_DrawInfoDisplayRow(_(2bce), WINDOW_STAT_ROW_4, SI_SHOTS, unit->shots,
unit_values->GetAttribute(ATTRIB_ROUNDS), 1);
GameManager_DrawInfoDisplayRow(
_(2bce), WINDOW_STAT_ROW_4, SI_SHOTS, unit->shots,
std::min(unit_values->GetAttribute(ATTRIB_ROUNDS), unit_values->GetAttribute(ATTRIB_AMMO)), 1);

if (unit_values->GetAttribute(ATTRIB_STORAGE) == 0) {
GameManager_DrawInfoDisplayType2(unit);
Expand Down
2 changes: 1 addition & 1 deletion src/paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ void GroundPath::Draw(UnitInfo* unit, WindowInfo* window) {

Paths_DrawMarker(window, angle, scaled_grid_x, scaled_grid_y, color);

if (i > index && unit->shots != 0 && unit_speed >= 0) {
if (i > index && unit->shots > 0 && unit_speed >= 0) {
if (unit->GetBaseValues()->GetAttribute(ATTRIB_MOVE_AND_FIRE)) {
shots = unit->shots;

Expand Down
2 changes: 1 addition & 1 deletion src/reminders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ RemindAttack::RemindAttack(UnitInfo& unit) : unit(unit) {}
RemindAttack::~RemindAttack() {}

void RemindAttack::Execute() {
if (unit->hits && unit->shots && UnitsManager_TeamInfo[unit->team].team_type == TEAM_TYPE_COMPUTER) {
if (unit->hits && unit->shots > 0 && UnitsManager_TeamInfo[unit->team].team_type == TEAM_TYPE_COMPUTER) {
if (unit->GetTask()) {
char buffer[500];

Expand Down
5 changes: 3 additions & 2 deletions src/reportstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,9 @@ void ReportStats_Draw(UnitInfo* unit, WinID id, Rect* bounds) {

ReportStats_DrawRowEx(_(50c9), id, bounds, 2, SI_SPEED, EI_SPEED, unit->speed,
unit_values->GetAttribute(ATTRIB_SPEED), 1, true);
ReportStats_DrawRowEx(_(27e1), id, bounds, 3, SI_SHOTS, EI_SHOTS, unit->shots,
unit_values->GetAttribute(ATTRIB_ROUNDS), 1, false);
ReportStats_DrawRowEx(
_(27e1), id, bounds, 3, SI_SHOTS, EI_SHOTS, unit->shots,
std::min(unit_values->GetAttribute(ATTRIB_ROUNDS), unit_values->GetAttribute(ATTRIB_AMMO)), 1, false);

if (!unit_values->GetAttribute(ATTRIB_STORAGE)) {
ReportStats_DrawCommonUnit(unit, id, bounds);
Expand Down
4 changes: 2 additions & 2 deletions src/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void Task_RemoveMovementTasks(UnitInfo* unit) {
bool Task_ShouldReserveShot(UnitInfo* unit, Point site) {
bool result;

if (unit->shots && !unit->GetBaseValues()->GetAttribute(ATTRIB_MOVE_AND_FIRE)) {
if (unit->shots > 0 && !unit->GetBaseValues()->GetAttribute(ATTRIB_MOVE_AND_FIRE)) {
int32_t unit_range = 0;
bool relevant_teams[PLAYER_TEAM_MAX - 1];
int32_t team;
Expand Down Expand Up @@ -521,7 +521,7 @@ int32_t Task::GetCautionLevel(UnitInfo& unit) {

if (unit.base_values->GetAttribute(ATTRIB_MOVE_AND_FIRE) &&
ini_get_setting(INI_OPPONENT) >= OPPONENT_TYPE_AVERAGE) {
if (unit.shots) {
if (unit.shots > 0) {
result = CAUTION_LEVEL_AVOID_REACTION_FIRE;
} else {
result = CAUTION_LEVEL_AVOID_ALL_DAMAGE;
Expand Down
2 changes: 1 addition & 1 deletion src/unitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3256,7 +3256,7 @@ void UnitInfo::Attack(int32_t grid_x, int32_t grid_y) {
enemy->AttackUnit(this, 0, target_angle);
}

if (!shots) {
if (shots == 0) {
targeting_mode = 0;
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/unitstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,13 @@ uint8_t* UnitStats_DrawMilitary(uint8_t* buffer, int32_t screen_width, UnitValue

buffer = &buffer[screen_width * 19];

if (unit_values1->GetAttribute(ATTRIB_ROUNDS)) {
UnitStats_DrawText(buffer, screen_width, _(5e40), image_width, unit_values2->GetAttribute(ATTRIB_ROUNDS), true);
UnitStats_DrawIcons(&buffer[76], screen_width, image_width - 76, I_SHOTS, I_SHOTS,
unit_values1->GetAttribute(ATTRIB_ROUNDS), unit_values2->GetAttribute(ATTRIB_ROUNDS));
if (unit_values1->GetAttribute(ATTRIB_ROUNDS) > 0) {
UnitStats_DrawText(buffer, screen_width, _(5e40), image_width,
std::min(unit_values2->GetAttribute(ATTRIB_ROUNDS), unit_values2->GetAttribute(ATTRIB_AMMO)),
true);
UnitStats_DrawIcons(
&buffer[76], screen_width, image_width - 76, I_SHOTS, I_SHOTS, unit_values1->GetAttribute(ATTRIB_ROUNDS),
std::min(unit_values2->GetAttribute(ATTRIB_ROUNDS), unit_values2->GetAttribute(ATTRIB_AMMO)));

buffer = &buffer[screen_width * 19];
}
Expand Down

0 comments on commit 2c17d9a

Please sign in to comment.