Clean up selection.cpp

- Replace raw array by std::vector.
- use unsigned int instead of int.
This commit is contained in:
joris 2013-10-25 12:56:46 +02:00
parent d55f0acadd
commit a0ed13735b
10 changed files with 98 additions and 119 deletions

View file

@ -372,7 +372,7 @@ int AiForce::PlanAttack()
Vec2i pos = this->GoalPos;
if (AiFindTarget(*landUnit, transporterTerrainTraversal, &pos)) {
const int forceIndex = AiPlayer->Force.getIndex(this) + 1;
const unsigned int forceIndex = AiPlayer->Force.getIndex(this) + 1;
if (transporter->GroupId != forceIndex) {
DebugPrint("%d: Assign any transporter #%d\n" _C_ player.Index _C_ UnitNumber(*transporter));

View file

@ -380,8 +380,8 @@ public:
unsigned long TTL; /// time to live
int GroupId; /// unit belongs to this group id
int LastGroup; /// unit belongs to this last group
unsigned int GroupId; /// unit belongs to this group id
unsigned int LastGroup; /// unit belongs to this last group
unsigned int Wait; /// action counter
int Threshold; /// The counter while ai unit couldn't change target.
@ -448,17 +448,15 @@ extern unsigned long ShowNameDelay; /// Delay to show unit's name
extern unsigned long ShowNameTime; /// Show unit's name for some time
extern bool EnableTrainingQueue; /// Config: training queues enabled
extern bool EnableBuildingCapture; /// Config: building capture enabled
extern bool RevealAttacker; /// Config: reveal attacker enabled
extern bool RevealAttacker; /// Config: reveal attacker enabled
extern int ResourcesMultiBuildersMultiplier; /// Config: spend resources for building with multiple workers
extern const CViewport *CurrentViewport; /// CurrentViewport
extern void DrawUnitSelection(const CViewport &vp, const CUnit &unit);
extern void (*DrawSelection)(IntColor, int, int, int, int);
extern int MaxSelectable; /// How many units could be selected
extern CUnit **Selected; /// currently selected units
extern CUnit **TeamSelected[PlayerMax]; /// teams currently selected units
extern int NumSelected; /// how many units selected
extern int TeamNumSelected[PlayerMax]; /// Number of Units a team member has selected
extern unsigned int MaxSelectable; /// How many units could be selected
extern CUnit **Selected; /// currently selected units
extern unsigned int NumSelected; /// how many units selected
/*----------------------------------------------------------------------------
-- Functions
@ -614,9 +612,9 @@ extern CUnit **GetUnitsOfGroup(int num);
/// Remove all units from a group
extern void ClearGroup(int num);
/// Add the array of units to the group
extern void AddToGroup(CUnit **units, int nunits, int num);
extern void AddToGroup(CUnit **units, unsigned int nunits, int num);
/// Set the contents of a particular group with an array of units
extern void SetGroup(CUnit **units, int nunits, int num);
extern void SetGroup(CUnit **units, unsigned int nunits, int num);
/// Remove a unit from a group
extern void RemoveUnitFromGroups(CUnit &unit);
/// Register CCL group features

View file

@ -416,7 +416,7 @@ void CViewport::Draw() const
if (!Preference.ShowOrders) {
} else if (Preference.ShowOrders < 0
|| (ShowOrdersCount >= GameCycle) || (KeyModifiers & ModifierShift)) {
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
ShowOrder(*Selected[i]);
}
}

View file

@ -57,7 +57,7 @@
*/
struct CUnitGroup {
CUnit **Units; /// Units in the group
int NumUnits; /// How many units in the group
unsigned int NumUnits; /// How many units in the group
bool tainted; /// Group hold unit which can't be SelectableByRectangle
}; /// group of units
@ -94,7 +94,7 @@ void SaveGroups(CFile &file)
for (int g = 0; g < NUM_GROUPS; ++g) {
file.printf("Group(%d, %d, {", g, Groups[g].NumUnits);
for (int i = 0; i < Groups[g].NumUnits; ++i) {
for (unsigned int i = 0; i < Groups[g].NumUnits; ++i) {
file.printf("\"%s\", ", UnitReference(*Groups[g].Units[i]).c_str());
}
file.printf("})\n");
@ -132,7 +132,7 @@ int GetNumberUnitsOfGroup(int num, GroupSelectionMode mode)
Assert(num < NUM_GROUPS);
if (mode != SELECT_ALL && Groups[num].tainted && Groups[num].NumUnits) {
int count = 0;
for (int i = 0; i < Groups[num].NumUnits; ++i) {
for (unsigned int i = 0; i < Groups[num].NumUnits; ++i) {
const CUnitType *type = Groups[num].Units[i]->Type;
if (type && type->CanSelect(mode)) {
count++;
@ -166,7 +166,7 @@ void ClearGroup(int num)
Assert(num < NUM_GROUPS);
CUnitGroup &group = Groups[num];
for (int i = 0; i < group.NumUnits; ++i) {
for (unsigned int i = 0; i < group.NumUnits; ++i) {
group.Units[i]->GroupId &= ~(1 << num);
Assert(!group.Units[i]->Destroyed);
}
@ -181,12 +181,12 @@ void ClearGroup(int num)
** @param nunits Number of units in array.
** @param num Group number for storage.
*/
void AddToGroup(CUnit **units, int nunits, int num)
void AddToGroup(CUnit **units, unsigned int nunits, int num)
{
Assert(num <= NUM_GROUPS);
CUnitGroup &group = Groups[num];
for (int i = 0; group.NumUnits < MaxSelectable && i < nunits; ++i) {
for (unsigned int i = 0; group.NumUnits < MaxSelectable && i < nunits; ++i) {
// Add to group only if they are on our team
// Buildings can be in group but it "taint" the group.
// Taited groups normaly select only SelectableByRectangle units but
@ -209,7 +209,7 @@ void AddToGroup(CUnit **units, int nunits, int num)
** @param nunits Number of units in array.
** @param num Group number for storage.
*/
void SetGroup(CUnit **units, int nunits, int num)
void SetGroup(CUnit **units, unsigned int nunits, int num)
{
Assert(num <= NUM_GROUPS && nunits <= MaxSelectable);
@ -232,7 +232,7 @@ void RemoveUnitFromGroups(CUnit &unit)
}
CUnitGroup &group = Groups[num];
int ind;
unsigned int ind;
for (ind = 0; group.Units[ind] != &unit; ++ind) {
Assert(ind < group.NumUnits); // oops not found
}
@ -243,7 +243,7 @@ void RemoveUnitFromGroups(CUnit &unit)
// Update tainted flag.
if (group.tainted && !unit.Type->SelectableByRectangle) {
group.tainted = false;
for (int i = 0; i < group.NumUnits; ++i) {
for (unsigned int i = 0; i < group.NumUnits; ++i) {
if (group.Units[i]->Type && !group.Units[i]->Type->SelectableByRectangle) {
group.tainted = true;
}

View file

@ -52,16 +52,14 @@
-- Variables
----------------------------------------------------------------------------*/
int NumSelected; /// Number of selected units
int TeamNumSelected[PlayerMax]; /// How many units selected
int MaxSelectable; /// Maximum number of selected units
CUnit **Selected; /// All selected units
CUnit **TeamSelected[PlayerMax]; /// teams currently selected units
unsigned int MaxSelectable; /// Maximum number of selected units
static int _NumSelected; /// save of NumSelected
static int _TeamNumSelected[PlayerMax]; /// save of TeamNumSelected
static CUnit **_Selected; /// save of Selected
static CUnit **_TeamSelected[PlayerMax]; /// save of TeamSelected
unsigned int NumSelected; /// Number of selected units
CUnit **Selected; /// All selected units
static std::vector<CUnit *> TeamSelected[PlayerMax]; /// teams currently selected units
static std::vector<CUnit *> _Selected; /// save of Selected
static std::vector<CUnit *> _TeamSelected[PlayerMax]; /// save of TeamSelected
static unsigned GroupId; /// Unique group # for automatic groups
@ -75,14 +73,12 @@ static unsigned GroupId; /// Unique group # for automatic groups
void SaveSelection()
{
for (int i = 0; i < PlayerMax; ++i) {
_TeamNumSelected[i] = TeamNumSelected[i];
for (int j = 0; j < TeamNumSelected[i]; ++j) {
_TeamSelected[i][j] = TeamSelected[i][j];
}
_TeamSelected[i] = TeamSelected[i];
}
_NumSelected = NumSelected;
for (int j = 0; j < NumSelected; ++j) {
_Selected[j] = Selected[j];
// TODO: _Selected = Selected;
_Selected.clear();
for (unsigned int j = 0; j < NumSelected; ++j) {
_Selected.push_back(Selected[j]);
}
}
@ -93,14 +89,13 @@ void RestoreSelection()
{
UnSelectAll();
for (int i = 0; i < PlayerMax; ++i) {
TeamNumSelected[i] = _TeamNumSelected[i];
for (int j = 0; j < _TeamNumSelected[i]; ++j) {
TeamSelected[i][j] = _TeamSelected[i][j];
TeamSelected[i] = _TeamSelected[i];
for (size_t j = 0; j != _TeamSelected[i].size(); ++j) {
TeamSelected[i][j]->TeamSelected |= (1 << i);
}
}
NumSelected = _NumSelected;
for (int j = 0; j < _NumSelected; ++j) {
NumSelected = _Selected.size();
for (size_t j = 0; j != _Selected.size(); ++j) {
Selected[j] = _Selected[j];
Selected[j]->Selected = 1;
}
@ -153,7 +148,7 @@ static void HandleSuicideClick(CUnit &unit)
** @param units Array of units to be selected.
** @param count Number of units in array to be selected.
*/
static void ChangeSelectedUnits(CUnit **units, int count)
static void ChangeSelectedUnits(CUnit **units, unsigned int count)
{
Assert(count <= MaxSelectable);
@ -167,8 +162,8 @@ static void ChangeSelectedUnits(CUnit **units, int count)
}
UnSelectAll();
NetworkSendSelection(units, count);
int n = 0;
for (int i = 0; i < count; ++i) {
unsigned int n = 0;
for (unsigned int i = 0; i < count; ++i) {
CUnit &unit = *units[i];
if (!unit.Removed && !unit.TeamSelected && !unit.Type->IsNotSelectable) {
Selected[n++] = &unit;
@ -190,21 +185,21 @@ static void ChangeSelectedUnits(CUnit **units, int count)
void ChangeTeamSelectedUnits(CPlayer &player, const std::vector<CUnit *> &units)
{
// UnSelectAllTeam(player);
while (TeamNumSelected[player.Index]) {
CUnit *unit = TeamSelected[player.Index][--TeamNumSelected[player.Index]];
while (!TeamSelected[player.Index].empty()) {
CUnit *unit = TeamSelected[player.Index].back();
TeamSelected[player.Index].pop_back();
unit->TeamSelected &= ~(1 << player.Index);
TeamSelected[player.Index][TeamNumSelected[player.Index]] = NULL; // FIXME: only needed for old code
}
// Add to selection
for (size_t i = 0; i != units.size(); ++i) {
CUnit &unit = *units[i];
Assert(!unit.Removed);
if (!unit.Type->IsNotSelectable) {
TeamSelected[player.Index][TeamNumSelected[player.Index]++] = &unit;
TeamSelected[player.Index].push_back(&unit);
unit.TeamSelected |= 1 << player.Index;
}
}
Assert(TeamNumSelected[player.Index] <= MaxSelectable);
Assert(TeamSelected[player.Index].size() <= MaxSelectable);
}
/**
@ -270,16 +265,14 @@ void UnSelectUnit(CUnit &unit)
if (unit.TeamSelected) {
for (int i = 0; i < PlayerMax; ++i) {
if (unit.TeamSelected & (1 << i)) {
int j;
size_t j;
for (j = 0; TeamSelected[i][j] != &unit; ++i) {
;
// Empty
}
Assert(j < TeamNumSelected[i]);
Assert(j < TeamSelected[i].size());
if (j < --TeamNumSelected[i]) {
TeamSelected[i][j] = TeamSelected[i][TeamNumSelected[i]];
}
std::swap(TeamSelected[i][j], TeamSelected[i].back());
TeamSelected[i].pop_back();
unit.TeamSelected &= ~(1 << i);
}
}
@ -287,7 +280,7 @@ void UnSelectUnit(CUnit &unit)
if (!unit.Selected) {
return;
}
int j;
unsigned int j;
for (j = 0; Selected[j] != &unit; ++j) {
;
@ -301,7 +294,7 @@ void UnSelectUnit(CUnit &unit)
if (NumSelected > 1) { // Assign new group to remaining units
while (!++GroupId) { // Advance group id, but keep non zero
}
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
Selected[i]->LastGroup = GroupId;
}
}
@ -414,7 +407,7 @@ int SelectUnitsByType(CUnit &base)
}
}
if (NumSelected > 1) {
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
Selected[i]->LastGroup = GroupId;
}
}
@ -540,7 +533,7 @@ int SelectGroup(int group_number, GroupSelectionMode mode)
*/
int AddGroupFromUnitToSelection(CUnit &unit)
{
int group = unit.LastGroup;
unsigned int group = unit.LastGroup;
if (!group) { // belongs to no group
return 0;
@ -589,7 +582,7 @@ int SelectGroupFromUnit(CUnit &unit)
*/
static bool SelectOrganicUnitsInTable(std::vector<CUnit *> &table)
{
int n = 0;
unsigned int n = 0;
for (size_t i = 0; i != table.size(); ++i) {
CUnit &unit = *table[i];
@ -795,7 +788,7 @@ int SelectGroundUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos
Select(t0 - range, t1 + range, table);
SelectSpritesInsideRectangle(corner_topleft, corner_bottomright, table);
int n = 0;
unsigned int n = 0;
for (size_t i = 0; i != table.size(); ++i) {
CUnit &unit = *table[i];
@ -839,7 +832,7 @@ int SelectAirUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &co
Select(t0 - range, t1 + range, table);
SelectSpritesInsideRectangle(corner_topleft, corner_bottomright, table);
int n = 0;
unsigned int n = 0;
for (size_t i = 0; i != table.size(); ++i) {
CUnit &unit = *table[i];
if (!CanSelectMultipleUnits(*unit.Player) || !unit.Type->SelectableByRectangle) {
@ -898,7 +891,7 @@ int AddSelectedGroundUnitsInRectangle(const PixelPos &corner_topleft, const Pixe
Select(t0 - range, t1 + range, table);
SelectSpritesInsideRectangle(corner_topleft, corner_bottomright, table);
int n = 0;
unsigned int n = 0;
for (size_t i = 0; i < table.size(); ++i) {
CUnit &unit = *table[i];
@ -922,7 +915,7 @@ int AddSelectedGroundUnitsInRectangle(const PixelPos &corner_topleft, const Pixe
}
// Add the units to selected.
for (int i = 0; i < n && NumSelected < MaxSelectable; ++i) {
for (unsigned int i = 0; i < n && NumSelected < MaxSelectable; ++i) {
SelectUnit(*table[i]);
}
return NumSelected;
@ -959,7 +952,7 @@ int AddSelectedAirUnitsInRectangle(const PixelPos &corner_topleft, const PixelPo
Select(t0 - range, t1 + range, table);
SelectSpritesInsideRectangle(corner_topleft, corner_bottomright, table);
int n = 0;
unsigned int n = 0;
for (size_t i = 0; i < table.size(); ++i) {
CUnit &unit = *table[i];
if (!CanSelectMultipleUnits(*unit.Player) ||
@ -982,7 +975,7 @@ int AddSelectedAirUnitsInRectangle(const PixelPos &corner_topleft, const PixelPo
}
// Add the units to selected.
for (int i = 0; i < n && NumSelected < MaxSelectable; ++i) {
for (unsigned int i = 0; i < n && NumSelected < MaxSelectable; ++i) {
SelectUnit(*table[i]);
}
return NumSelected;
@ -996,13 +989,6 @@ void InitSelections()
// This could have been initialized already when loading a game
if (!Selected) {
Selected = new CUnit *[MaxSelectable];
_Selected = new CUnit *[MaxSelectable];
}
for (int i = 0; i < PlayerMax; ++i) {
if (!TeamSelected[i]) {
TeamSelected[i] = new CUnit *[MaxSelectable];
_TeamSelected[i] = new CUnit *[MaxSelectable];
}
}
}
@ -1018,7 +1004,7 @@ void SaveSelections(CFile &file)
file.printf("SetGroupId(%d)\n", GroupId);
file.printf("Selection(%d, {", NumSelected);
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
file.printf("\"%s\", ", UnitReference(*Selected[i]).c_str());
}
file.printf("})\n");
@ -1033,16 +1019,11 @@ void CleanSelections()
NumSelected = 0;
delete[] Selected;
Selected = NULL;
delete[] _Selected;
_Selected = NULL;
_Selected.clear();
for (int i = 0; i < PlayerMax; ++i) {
delete[] TeamSelected[i];
TeamSelected[i] = NULL;
delete[] _TeamSelected[i];
_TeamSelected[i] = NULL;
TeamNumSelected[i] = 0;
_TeamNumSelected[i] = 0;
TeamSelected[i].clear();
_TeamSelected[i].clear();
}
}

View file

@ -218,8 +218,8 @@ void CleanButtons()
*/
static int GetButtonStatus(const ButtonAction &button, int UnderCursor)
{
int res = 0;
int i;
unsigned int res = 0;
unsigned int i;
/* parallel drawing */
if (!NumSelected) {
@ -760,7 +760,7 @@ void CButtonPanel::Draw()
bool gray = false;
bool cooldownSpell = false;
int maxCooldown = 0;
for (int j = 0; j < NumSelected; ++j) {
for (unsigned int j = 0; j < NumSelected; ++j) {
if (!IsButtonAllowed(*Selected[j], buttons[i])) {
gray = true;
break;
@ -980,7 +980,7 @@ static void UpdateButtonPanelMultipleUnits(std::vector<ButtonAction> *buttonActi
bool allow = true;
if (UnitButtonTable[z]->AlwaysShow == false) {
for (int i = 0; i < NumSelected; i++) {
for (unsigned int i = 0; i < NumSelected; i++) {
if (!IsButtonAllowed(*Selected[i], *UnitButtonTable[z])) {
allow = false;
break;
@ -1086,7 +1086,7 @@ void CButtonPanel::Update()
bool sameType = true;
// multiple selected
for (int i = 1; i < NumSelected; ++i) {
for (unsigned int i = 1; i < NumSelected; ++i) {
if (Selected[i]->Type != unit.Type) {
sameType = false;
break;
@ -1151,13 +1151,13 @@ void CButtonPanel::DoClicked_SpellCast(int button)
//autocast = 0;
// If any selected unit doesn't have autocast on turn it on
// for everyone
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
if (Selected[i]->AutoCastSpell[spellId] == 0) {
autocast = 1;
break;
}
}
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
if (Selected[i]->AutoCastSpell[spellId] != autocast) {
SendCommandAutoSpellCast(*Selected[i], spellId, autocast);
}
@ -1167,7 +1167,7 @@ void CButtonPanel::DoClicked_SpellCast(int button)
if (SpellTypeTable[spellId]->IsCasterOnly()) {
const int flush = !(KeyModifiers & ModifierShift);
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
CUnit &unit = *Selected[i];
// CursorValue here holds the spell type id
SendCommandSpellCast(unit, unit.tilePos, &unit, spellId, flush);
@ -1183,13 +1183,13 @@ void CButtonPanel::DoClicked_Repair(int button)
unsigned autorepair = 0;
// If any selected unit doesn't have autocast on turn it on
// for everyone
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
if (Selected[i]->AutoRepair == 0) {
autorepair = 1;
break;
}
}
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
if (Selected[i]->AutoRepair != autorepair) {
SendCommandAutoRepair(*Selected[i], autorepair);
}
@ -1202,21 +1202,21 @@ void CButtonPanel::DoClicked_Repair(int button)
void CButtonPanel::DoClicked_Return()
{
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
SendCommandReturnGoods(*Selected[i], NoUnitP, !(KeyModifiers & ModifierShift));
}
}
void CButtonPanel::DoClicked_Stop()
{
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
SendCommandStopUnit(*Selected[i]);
}
}
void CButtonPanel::DoClicked_StandGround()
{
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
SendCommandStandGround(*Selected[i], !(KeyModifiers & ModifierShift));
}
}
@ -1310,7 +1310,7 @@ void CButtonPanel::DoClicked_UpgradeTo(int button)
{
// FIXME: store pointer in button table!
CUnitType &type = *UnitTypes[CurrentButtons[button].Value];
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
if (Selected[0]->Player->CheckLimits(type) != -6 && !Selected[i]->Player->CheckUnitType(type)) {
if (Selected[i]->CurrentAction() != UnitActionUpgradeTo) {
SendCommandUpgradeTo(*Selected[i], type, !(KeyModifiers & ModifierShift));

View file

@ -222,7 +222,7 @@ static void UiAddGroupToSelection(unsigned group)
*/
static void UiDefineGroup(unsigned group)
{
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
if (Selected[i]->Player == ThisPlayer && Selected[i]->GroupId) {
RemoveUnitFromGroups(*Selected[i]);
}

View file

@ -1089,10 +1089,10 @@ void CInfoPanel::Draw()
UI.StatusLine.Set(Selected[i]->Type->Name);
}
}
if (NumSelected > (int)UI.SelectedButtons.size()) {
if (NumSelected > UI.SelectedButtons.size()) {
char buf[5];
sprintf(buf, "+%u", static_cast<unsigned int>(NumSelected - UI.SelectedButtons.size()));
sprintf(buf, "+%u", NumSelected - UI.SelectedButtons.size());
CLabel(*UI.MaxSelectedFont).Draw(UI.MaxSelectedTextX, UI.MaxSelectedTextY, buf);
}
return;

View file

@ -567,7 +567,7 @@ void DoRightButton(const PixelPos &mapPixelPos)
}
if (dest != NULL && dest->Type->CanTransport()) {
for (int i = 0; i < NumSelected; i++) {
for (unsigned int i = 0; i < NumSelected; i++) {
if (CanTransport(*dest, *Selected[i])) {
// We are clicking on a transporter. We have to:
// 1) Flush the transporters orders.
@ -583,7 +583,7 @@ void DoRightButton(const PixelPos &mapPixelPos)
}
int acknowledged = 0; // to play sound
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
Assert(Selected[i]);
CUnit &unit = *Selected[i];
@ -949,7 +949,7 @@ void UIHandleMouseMove(const PixelPos &cursorPos)
// 0 Test build, don't really build
if (CanBuildUnitType(Selected[0], *CursorBuilding, tilePos, 0) && buildable && (explored || ReplayRevealMap)) {
const int flush = !(KeyModifiers & ModifierShift);
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
SendCommandBuildBuilding(*Selected[i], tilePos, *CursorBuilding, flush);
}
if (!(KeyModifiers & (ModifierAlt | ModifierShift))) {
@ -1072,7 +1072,7 @@ static int SendRepair(const Vec2i &tilePos)
if (dest && dest->Variable[HP_INDEX].Value < dest->Variable[HP_INDEX].Max
&& dest->Type->RepairHP
&& (dest->Player == ThisPlayer || ThisPlayer->IsAllied(*dest))) {
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
CUnit *unit = Selected[i];
if (unit->Type->RepairRange) {
@ -1104,7 +1104,7 @@ static int SendMove(const Vec2i &tilePos)
// Alt makes unit to defend goal
if (goal && (KeyModifiers & ModifierAlt)) {
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
CUnit *unit = Selected[i];
goal->Blink = 4;
@ -1114,7 +1114,7 @@ static int SendMove(const Vec2i &tilePos)
} else {
// Move to a transporter.
if (goal && goal->Type->CanTransport()) {
int i;
unsigned int i;
for (i = 0; i < NumSelected; ++i) {
if (CanTransport(*goal, *Selected[i])) {
SendCommandStopUnit(*goal);
@ -1129,7 +1129,7 @@ static int SendMove(const Vec2i &tilePos)
goal = NULL;
}
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
CUnit *unit = Selected[i];
if (goal && CanTransport(*goal, *unit)) {
@ -1170,7 +1170,7 @@ static int SendAttack(const Vec2i &tilePos)
if (dest && dest->Type->Decoration) {
dest = NULL;
}
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
CUnit &unit = *Selected[i];
if (unit.Type->CanAttack) {
@ -1201,7 +1201,7 @@ static int SendAttackGround(const Vec2i &tilePos)
const int flush = !(KeyModifiers & ModifierShift);
int ret = 0;
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
CUnit &unit = *Selected[i];
if (unit.Type->CanAttack) {
SendCommandAttackGround(unit, tilePos, flush);
@ -1223,7 +1223,7 @@ static int SendPatrol(const Vec2i &tilePos)
{
const int flush = !(KeyModifiers & ModifierShift);
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
CUnit &unit = *Selected[i];
SendCommandPatrol(unit, tilePos, flush);
}
@ -1245,7 +1245,7 @@ static int SendResource(const Vec2i &pos)
const int flush = !(KeyModifiers & ModifierShift);
const CMapField &mf = *Map.Field(pos);
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
CUnit &unit = *Selected[i];
if (unit.Type->Harvester) {
@ -1306,7 +1306,7 @@ static int SendUnload(const Vec2i &tilePos)
{
const int flush = !(KeyModifiers & ModifierShift);
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
// FIXME: not only transporter selected?
SendCommandUnload(*Selected[i], tilePos, NoUnitP, flush);
}
@ -1335,7 +1335,7 @@ static int SendSpellCast(const Vec2i &tilePos)
(if exists). All checks are performed at spell cast handle
function which will cancel function if cannot be executed
*/
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
CUnit &unit = *Selected[i];
if (!unit.Type->CanCastSpell) {
DebugPrint("but unit %d(%s) can't cast spells?\n" _C_
@ -1402,7 +1402,7 @@ static void SendCommand(const Vec2i &tilePos)
}
if (ret) {
// Acknowledge the command with first selected unit.
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
if (ret == ButtonAttack || ret == ButtonAttackGround || ret == ButtonSpellCast) {
if (Selected[i]->Type->Sound.Attack.Sound) {
PlayUnitSound(*Selected[i], VoiceAttack);
@ -1437,7 +1437,7 @@ static void DoSelectionButtons(int num, unsigned)
return;
}
if (num >= NumSelected || !(MouseButtons & LeftButton)) {
if (static_cast<unsigned int>(num) >= NumSelected || !(MouseButtons & LeftButton)) {
return;
}
@ -1585,7 +1585,7 @@ static void UIHandleButtonDown_OnMap(unsigned button)
if (CanBuildUnitType(Selected[0], *CursorBuilding, tilePos, 0) && (explored || ReplayRevealMap)) {
const int flush = !(KeyModifiers & ModifierShift);
PlayGameSound(GameSounds.PlacementSuccess[ThisPlayer->Race].Sound, MaxSampleVolume);
for (int i = 0; i < NumSelected; ++i) {
for (unsigned int i = 0; i < NumSelected; ++i) {
SendCommandBuildBuilding(*Selected[i], tilePos, *CursorBuilding, flush);
}
if (!(KeyModifiers & (ModifierAlt | ModifierShift))) {
@ -2116,7 +2116,7 @@ void DrawPieMenu()
const PixelPos pos(x, y);
bool gray = false;
for (int j = 0; j < NumSelected; ++j) {
for (unsigned int j = 0; j < NumSelected; ++j) {
if (!IsButtonAllowed(*Selected[j], buttons[i])) {
gray = true;
break;

View file

@ -196,7 +196,7 @@ static void DrawBuildingCursor()
int f;
if (NumSelected) {
f = 1;
for (int i = 0; f && i < NumSelected; ++i) {
for (unsigned int i = 0; f && i < NumSelected; ++i) {
f = ((ontop = CanBuildHere(Selected[i], *CursorBuilding, mpos)) != NULL);
// Assign ontop or NULL
ontop = (ontop == Selected[i] ? NULL : ontop);