diff --git a/src/action/action_attack.cpp b/src/action/action_attack.cpp index 8239e7c92..9b341bceb 100644 --- a/src/action/action_attack.cpp +++ b/src/action/action_attack.cpp @@ -390,8 +390,8 @@ void COrder_Attack::MoveToTarget(CUnit &unit) return; } // Attacking wall or ground. - if (((goal && goal->Type && goal->Type->Wall) || ((!goal) - && (Map.WallOnMap(this->goalPos) || this->Action == UnitActionAttackGround))) + if (((goal && goal->Type && goal->Type->Wall) + || (!goal && (Map.WallOnMap(this->goalPos) || this->Action == UnitActionAttackGround))) && unit.MapDistanceTo(this->goalPos) <= unit.Stats->Variables[ATTACKRANGE_INDEX].Max) { // Reached wall or ground, now attacking it unit.State = 0; diff --git a/src/ai/ai.cpp b/src/ai/ai.cpp index bb56249a5..4eb0d4535 100644 --- a/src/ai/ai.cpp +++ b/src/ai/ai.cpp @@ -876,9 +876,9 @@ static void AiMoveUnitInTheWay(CUnit &unit) // Check for collision if (!((u0.x == b1.x + 1 || u1.x == b0.x - 1) - && (std::max(b0.y, u0.y) <= std::min(b1.y, u1.y))) + && (std::max(b0.y, u0.y) <= std::min(b1.y, u1.y))) && !((u0.y == b1.y + 1 || u1.y == b0.y - 1) - && (std::max(b0.x, u0.x) <= std::min(b1.x, u1.x)))) { + && (std::max(b0.x, u0.x) <= std::min(b1.x, u1.x)))) { continue; } diff --git a/src/ai/ai_building.cpp b/src/ai/ai_building.cpp index b06008d08..1a47ce809 100644 --- a/src/ai/ai_building.cpp +++ b/src/ai/ai_building.cpp @@ -95,8 +95,8 @@ static int AiCheckSurrounding(const CUnit &worker, if (x == worker.tilePos.x && y == worker.tilePos.y) { surrounding[surroundingnb++] = 1; } else if (Map.CheckMask(x + y_offset, - (MapFieldUnpassable | MapFieldWall | MapFieldRocks - | MapFieldForest | MapFieldBuilding))) { + (MapFieldUnpassable | MapFieldWall | MapFieldRocks + | MapFieldForest | MapFieldBuilding))) { surrounding[surroundingnb++] = 0; } else { // Can pass there diff --git a/src/ai/script_ai.cpp b/src/ai/script_ai.cpp index 451dccc6b..b65f1e383 100644 --- a/src/ai/script_ai.cpp +++ b/src/ai/script_ai.cpp @@ -397,7 +397,7 @@ static int CclDefineAiHelper(lua_State *l) return 0; } -static CAiType *GetAiTypesByName(const char* name) +static CAiType *GetAiTypesByName(const char *name) { for (size_t i = 0; i < AiTypes.size(); ++i) { CAiType *ait = AiTypes[i]; @@ -425,7 +425,7 @@ static int CclDefineAi(lua_State *l) CAiType *aitype = new CAiType; // AI Name - const char* aiName = LuaToString(l, 1); + const char *aiName = LuaToString(l, 1); aitype->Name = aiName; #ifdef DEBUG @@ -1273,7 +1273,7 @@ static int CclDefineAiPlayer(lua_State *l) ++j; if (!strcmp(value, "ai-type")) { - const char* aiName = LuaToString(l, j + 1); + const char *aiName = LuaToString(l, j + 1); CAiType *ait = GetAiTypesByName(aiName); if (ait == NULL) { lua_pushfstring(l, "ai-type not found: %s", aiName); @@ -1299,7 +1299,7 @@ static int CclDefineAiPlayer(lua_State *l) for (int k = 1; k < subargs; ++k) { lua_rawgeti(l, j + 1, k + 1); - const char* value = LuaToString(l, -1); + const char *value = LuaToString(l, -1); lua_pop(l, 1); ++k; if (!strcmp(value, "complete")) { diff --git a/src/animation/animation_spawnmissile.cpp b/src/animation/animation_spawnmissile.cpp index 8d3d104ab..52fd3ca8b 100644 --- a/src/animation/animation_spawnmissile.cpp +++ b/src/animation/animation_spawnmissile.cpp @@ -99,7 +99,7 @@ static int ParseAnimFlags(CUnit &unit, const char *parseflag) const int destx = ParseAnimInt(&unit, this->destXStr.c_str()); const int desty = ParseAnimInt(&unit, this->destYStr.c_str()); const int flags = ParseAnimFlags(unit, this->flagsStr.c_str()); - const CUnit *goal = flags & ANIM_SM_RELTARGET ? unit.CurrentOrder()->GetGoal(): &unit; + const CUnit *goal = flags & ANIM_SM_RELTARGET ? unit.CurrentOrder()->GetGoal() : &unit; PixelPos start; PixelPos dest; diff --git a/src/beos/beos.cpp b/src/beos/beos.cpp index ab2e533ed..ae0089e96 100644 --- a/src/beos/beos.cpp +++ b/src/beos/beos.cpp @@ -30,17 +30,17 @@ extern "C" { -/** -** Need init function for beos. -** -** @param argc Number of command line argurments -*/ -void beos_init(int argc, char** argv) -{ - BPath path( argv[0] ); - path.GetParent( &path ); - chdir( path.Path() ); -} + /** + ** Need init function for beos. + ** + ** @param argc Number of command line argurments + */ + void beos_init(int argc, char **argv) + { + BPath path(argv[0]); + path.GetParent(&path); + chdir(path.Path()); + } } diff --git a/src/maemo/maemo.cpp b/src/maemo/maemo.cpp index 66c2f8758..999718637 100644 --- a/src/maemo/maemo.cpp +++ b/src/maemo/maemo.cpp @@ -44,7 +44,7 @@ -- Variables ----------------------------------------------------------------------------*/ -static osso_context_t * osso = NULL; +static osso_context_t *osso = NULL; static SDL_TimerID timer = NULL; /*---------------------------------------------------------------------------- @@ -57,8 +57,9 @@ static SDL_TimerID timer = NULL; **/ static Uint32 OssoKeepBacklightAlive(Uint32 interval, void *) { - if (!osso) + if (!osso) { return 0; + } osso_display_state_on(osso); osso_display_blanking_pause(osso); @@ -72,15 +73,16 @@ static Uint32 OssoKeepBacklightAlive(Uint32 interval, void *) **/ static void OssoInitialize(void) { - char * application; + char *application; if (FullGameName.empty()) { application = strdup("org.stratagus"); } else { application = (char *)calloc(FullGameName.size() + 15, 1); strcpy(application, "org.stratagus."); - for (int i = 0; i < FullGameName.size(); i++) - application[i+14] = tolower(FullGameName[i]); + for (int i = 0; i < FullGameName.size(); i++) { + application[i + 14] = tolower(FullGameName[i]); + } } osso = osso_initialize(application, VERSION, TRUE, NULL); diff --git a/src/map/map.cpp b/src/map/map.cpp index b21fae1a3..5969e628f 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -114,9 +114,9 @@ void CMap::MarkSeenTile(const unsigned int index) // Handle Walls changes. } else if (this->Tileset.TileTypeTable[tile] == TileTypeHumanWall - || this->Tileset.TileTypeTable[tile] == TileTypeOrcWall - || this->Tileset.TileTypeTable[seentile] == TileTypeHumanWall - || this->Tileset.TileTypeTable[seentile] == TileTypeOrcWall) { + || this->Tileset.TileTypeTable[tile] == TileTypeOrcWall + || this->Tileset.TileTypeTable[seentile] == TileTypeHumanWall + || this->Tileset.TileTypeTable[seentile] == TileTypeOrcWall) { MapFixSeenWallTile(pos); MapFixSeenWallNeighbors(pos); } @@ -231,8 +231,8 @@ bool UnitTypeCanBeAt(const CUnitType &type, const Vec2i &pos) for (int addy = 0; addy < type.TileHeight; ++addy) { for (int addx = 0; addx < type.TileWidth; ++addx) { - if (!(Map.Info.IsPointOnMap(pos.x + addx, pos.y + addy) - && !Map.CheckMask(pos.x + addx + index, mask))) { + if (Map.Info.IsPointOnMap(pos.x + addx, pos.y + addy) == false + || Map.CheckMask(pos.x + addx + index, mask) == true) { return false; } } diff --git a/src/map/map_draw.cpp b/src/map/map_draw.cpp index 369fa1b8a..b14a58bed 100644 --- a/src/map/map_draw.cpp +++ b/src/map/map_draw.cpp @@ -352,7 +352,7 @@ void CViewport::Draw() const //FIXME: This is still unsecure during parallel if (!Preference.ShowOrders) { } else if (Preference.ShowOrders < 0 - || (ShowOrdersCount >= GameCycle) || (KeyModifiers & ModifierShift)) { + || (ShowOrdersCount >= GameCycle) || (KeyModifiers & ModifierShift)) { for (int i = 0; i < NumSelected; ++i) { ShowOrder(*Selected[i]); } diff --git a/src/missile/missile.cpp b/src/missile/missile.cpp index 772b07368..cadb505ac 100644 --- a/src/missile/missile.cpp +++ b/src/missile/missile.cpp @@ -781,7 +781,7 @@ void Missile::MissileHit() // if (!mtype.Range) { if (this->TargetUnit && (mtype.FriendlyFire == false - || this->TargetUnit->Player->Index != this->SourceUnit->Player->Index)) { + || this->TargetUnit->Player->Index != this->SourceUnit->Player->Index)) { // // Missiles without range only hits the goal always. // @@ -934,7 +934,7 @@ void Missile::NextMissileFrameCycle() j = f - i; } this->SpriteFrame = this->SpriteFrame % (this->Type->NumDirections / 2 + 1) + - j * (this->Type->NumDirections / 2 + 1); + j * (this->Type->NumDirections / 2 + 1); break; } } @@ -1048,7 +1048,7 @@ void Missile::SaveMissile(CFile &file) const file.printf(", \"goal\", "); SavePixelPos(file, this->destination); file.printf(",\n \"frame\", %d, \"state\", %d, \"anim-wait\", %d, \"wait\", %d, \"delay\", %d,\n ", - this->SpriteFrame, this->State, this->AnimWait, this->Wait, this->Delay); + this->SpriteFrame, this->State, this->AnimWait, this->Wait, this->Delay); if (this->SourceUnit != NULL) { file.printf(" \"source\", \"%s\",", UnitReference(this->SourceUnit).c_str()); } diff --git a/src/network/network.cpp b/src/network/network.cpp index 96303def9..2d70b6edf 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -1038,7 +1038,7 @@ void NetworkEvent() if (slot < UnitSlotFree && (UnitSlots[slot]->Player->Index == player - || Players[player].IsTeamed(*UnitSlots[slot]))) { + || Players[player].IsTeamed(*UnitSlots[slot]))) { validCommand = true; } else { validCommand = false; @@ -1054,7 +1054,7 @@ void NetworkEvent() } else { SetMessage(_("%s sent bad command"), Players[player].Name.c_str()); DebugPrint("%s sent bad command: 0x%x\n" _C_ Players[player].Name.c_str() - _C_ packet.Header.Type[i] & 0x7F); + _C_ packet.Header.Type[i] & 0x7F); } } diff --git a/src/pathfinder/astar.cpp b/src/pathfinder/astar.cpp index d222374b1..9484f4b36 100644 --- a/src/pathfinder/astar.cpp +++ b/src/pathfinder/astar.cpp @@ -201,7 +201,7 @@ inline void ProfilePrint() } std::vector prof; for (std::map::iterator i = functionProfiles.begin(); - i != functionProfiles.end(); ++i) { + i != functionProfiles.end(); ++i) { ProfileData *data = &i->second; prof.insert(std::upper_bound(prof.begin(), prof.end(), data, compProfileData), data); } @@ -415,7 +415,7 @@ static inline int AStarAddNode(const Vec2i &pos, int o, int costs) smalli = midi; } else if (costs < midcost || (costs == midcost && (costToGoal < midCostToGoal || (costToGoal == midCostToGoal - && dist < midDist)))) { + && dist < midDist)))) { if (bigi == midi) { bigi++; } else { diff --git a/src/stratagus/script_player.cpp b/src/stratagus/script_player.cpp index b427ba916..ed36bf69e 100644 --- a/src/stratagus/script_player.cpp +++ b/src/stratagus/script_player.cpp @@ -839,12 +839,12 @@ static int CclSetPlayerData(lua_State *l) const std::string res = LuaToString(l, 3); const int resId = GetResourceIdByName(l, res.c_str()); p->SetResource(resId, LuaToNumber(l, 4), true); -// } else if (!strcmp(data, "UnitTypesCount")) { -// } else if (!strcmp(data, "AiEnabled")) { -// } else if (!strcmp(data, "TotalNumUnits")) { -// } else if (!strcmp(data, "NumBuildings")) { -// } else if (!strcmp(data, "Supply")) { -// } else if (!strcmp(data, "Demand")) { + // } else if (!strcmp(data, "UnitTypesCount")) { + // } else if (!strcmp(data, "AiEnabled")) { + // } else if (!strcmp(data, "TotalNumUnits")) { + // } else if (!strcmp(data, "NumBuildings")) { + // } else if (!strcmp(data, "Supply")) { + // } else if (!strcmp(data, "Demand")) { } else if (!strcmp(data, "UnitLimit")) { p->UnitLimit = LuaToNumber(l, 3); } else if (!strcmp(data, "BuildingLimit")) { diff --git a/src/stratagus/selection.cpp b/src/stratagus/selection.cpp index 8e269d5bd..cde1ee79b 100644 --- a/src/stratagus/selection.cpp +++ b/src/stratagus/selection.cpp @@ -779,7 +779,7 @@ int AddSelectedUnitsInRectangle(int x0, int y0, int x1, int y1) // In this case, do nothing. if (NumSelected == 1 && (!CanSelectMultipleUnits(*Selected[0]->Player) - || !Selected[0]->Type->SelectableByRectangle)) { + || !Selected[0]->Type->SelectableByRectangle)) { return NumSelected; } // If there is no selected unit yet, do a simple selection. @@ -929,7 +929,7 @@ int AddSelectedGroundUnitsInRectangle(int sx0, int sy0, int sx1, int sy1) // In this case, do nothing. if (NumSelected == 1 && (!CanSelectMultipleUnits(*Selected[0]->Player) - || !Selected[0]->Type->SelectableByRectangle)) { + || !Selected[0]->Type->SelectableByRectangle)) { return NumSelected; } @@ -993,7 +993,7 @@ int AddSelectedAirUnitsInRectangle(int sx0, int sy0, int sx1, int sy1) // In this case, do nothing. if (NumSelected == 1 && (!CanSelectMultipleUnits(*Selected[0]->Player) - || !Selected[0]->Type->SelectableByRectangle)) { + || !Selected[0]->Type->SelectableByRectangle)) { return NumSelected; } diff --git a/src/stratagus/spells.cpp b/src/stratagus/spells.cpp index 6735eea70..f38b8a8eb 100644 --- a/src/stratagus/spells.cpp +++ b/src/stratagus/spells.cpp @@ -324,7 +324,6 @@ int SpawnMissile::Cast(CUnit &caster, const SpellType *, CUnit *target, const Ve missile->SourceUnit = &caster; } missile->TargetUnit = target; - return 1; } @@ -423,11 +422,11 @@ int AdjustVitals::Cast(CUnit &caster, const SpellType *spell, CUnit *target, con int castcount = 1; if (hp) { castcount = std::max(castcount, - diffHP / abs(hp) + (((hp < 0) && (diffHP % (-hp) > 0)) ? 1 : 0)); + diffHP / abs(hp) + (((hp < 0) && (diffHP % (-hp) > 0)) ? 1 : 0)); } if (mana) { castcount = std::max(castcount, - diffMana / abs(mana) + (((mana < 0) && (diffMana % (-mana) > 0)) ? 1 : 0)); + diffMana / abs(mana) + (((mana < 0) && (diffMana % (-mana) > 0)) ? 1 : 0)); } if (manacost) { castcount = std::min(castcount, caster.Variable[MANA_INDEX].Value / manacost); @@ -689,7 +688,7 @@ static Target *NewTargetUnit(CUnit &unit) ** @return true if passed, false otherwise. */ static bool PassCondition(const CUnit &caster, const SpellType *spell, const CUnit *target, - const Vec2i &/*goalPos*/, const ConditionInfo *condition) + const Vec2i &/*goalPos*/, const ConditionInfo *condition) { if (caster.Variable[MANA_INDEX].Value < spell->ManaCost) { // Check caster mana. return false; diff --git a/src/ui/botpanel.cpp b/src/ui/botpanel.cpp index ada948cbd..cba5d9482 100644 --- a/src/ui/botpanel.cpp +++ b/src/ui/botpanel.cpp @@ -352,7 +352,7 @@ int CPopupContentTypeCosts::GetWidth(const ButtonAction *button, int *Costs) con for (unsigned int i = 1; i < MaxCosts; ++i) { if (Costs[i]) { - if(UI.Resources[i].IconWidth != -1) { + if (UI.Resources[i].IconWidth != -1) { popupWidth += (UI.Resources[i].IconWidth + 5); } else { const CGraphic *G = UI.Resources[i].G; @@ -551,8 +551,8 @@ static void GetPopupSize(const ButtonAction *button, const CUIButton *uibutton, CPopup &popup = *PopupByIdent(button->Popup); for (std::vector::const_iterator it = popup.Contents.begin(); - it != popup.Contents.end(); - ++it) { + it != popup.Contents.end(); + ++it) { const CPopupContentType &content = **it; if (CanShowPopupContent(content.Condition, button, UnitTypes[button->Value])) { @@ -724,10 +724,10 @@ void DrawPopup(const ButtonAction *button, const CUIButton *uibutton) // Contents for (std::vector::const_iterator content = popup->Contents.begin(); - content != popup->Contents.end(); ++content) { - if (CanShowPopupContent((*content)->Condition, button, UnitTypes[button->Value])) { - (*content)->Draw(x + (*content)->PosX, y + (*content)->PosY, button, Costs); - } + content != popup->Contents.end(); ++content) { + if (CanShowPopupContent((*content)->Condition, button, UnitTypes[button->Value])) { + (*content)->Draw(x + (*content)->PosX, y + (*content)->PosY, button, Costs); + } } #if 0 // Fixme: need to remove soon @@ -994,9 +994,9 @@ static bool IsButtonAllowed(const CUnit &unit, const ButtonAction *buttonaction) break; case ButtonReturn: if (!(!unit.CurrentResource - || !(unit.ResourcesHeld > 0 && !unit.Type->ResInfo[unit.CurrentResource]->LoseResources) - || (unit.ResourcesHeld != unit.Type->ResInfo[unit.CurrentResource]->ResourceCapacity - && unit.Type->ResInfo[unit.CurrentResource]->LoseResources))) { + || !(unit.ResourcesHeld > 0 && !unit.Type->ResInfo[unit.CurrentResource]->LoseResources) + || (unit.ResourcesHeld != unit.Type->ResInfo[unit.CurrentResource]->ResourceCapacity + && unit.Type->ResInfo[unit.CurrentResource]->LoseResources))) { res = true; } break; @@ -1234,7 +1234,7 @@ void CButtonPanel::DoClicked(int button) // That or a bunker. // if ((NumSelected == 1 && Selected[0]->CurrentAction() == UnitActionStill - && Map.CoastOnMap(Selected[0]->tilePos)) + && Map.CoastOnMap(Selected[0]->tilePos)) || !Selected[0]->CanMove()) { SendCommandUnload(*Selected[0], Selected[0]->tilePos, NoUnitP, flush); break; @@ -1420,8 +1420,9 @@ void CButtonPanel::DoClicked(int button) UI.StatusLine.Clear(); ClearCosts(); } else if (Selected[0]->Player->CheckLimits(type) == -3) - if (GameSounds.NotEnoughFood[Selected[0]->Player->Race].Sound) + if (GameSounds.NotEnoughFood[Selected[0]->Player->Race].Sound) { PlayGameSound(GameSounds.NotEnoughFood[Selected[0]->Player->Race].Sound, MaxSampleVolume); + } break; } case ButtonUpgradeTo: { diff --git a/src/ui/mainscr.cpp b/src/ui/mainscr.cpp index fbd46649b..6bd29aa3f 100644 --- a/src/ui/mainscr.cpp +++ b/src/ui/mainscr.cpp @@ -703,7 +703,7 @@ static void DrawUnitInfo(CUnit &unit) order.GetUnitType().Icon.Icon->DrawUnitIcon( UI.UpgradingButton->Style, (ButtonAreaUnderCursor == ButtonAreaUpgrading - && ButtonUnderCursor == 0) ? + && ButtonUnderCursor == 0) ? (IconActive | (MouseButtons & LeftButton)) : 0, UI.UpgradingButton->X, UI.UpgradingButton->Y, ""); } @@ -716,7 +716,7 @@ static void DrawUnitInfo(CUnit &unit) order.GetUpgrade().Icon->DrawUnitIcon( UI.ResearchingButton->Style, (ButtonAreaUnderCursor == ButtonAreaResearching - && ButtonUnderCursor == 0) ? + && ButtonUnderCursor == 0) ? (IconActive | (MouseButtons & LeftButton)) : 0, UI.ResearchingButton->X, UI.ResearchingButton->Y, ""); } diff --git a/src/ui/script_ui.cpp b/src/ui/script_ui.cpp index a9310747e..0c6d87000 100644 --- a/src/ui/script_ui.cpp +++ b/src/ui/script_ui.cpp @@ -890,7 +890,7 @@ static PopupConditionPanel *ParsePopupConditions(lua_State *l) for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) { key = LuaToString(l, -2); if (!strcmp(key, "ButtonType")) { - + } else { int index = UnitTypeVar.BoolFlagNameLookup[key]; if (index != -1) { @@ -959,20 +959,20 @@ static CPopupContentType *CclParsePopupContent(lua_State *l) } content = contentname; } else if (!strcmp(key, "Costs")) { - CPopupContentTypeCosts *contentcosts = new CPopupContentTypeCosts; + CPopupContentTypeCosts *contentcosts = new CPopupContentTypeCosts; - Assert(lua_istable(l, -1)); - for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) { - key = LuaToString(l, -2); - if (!strcmp(key, "Font")) { - contentcosts->Font = CFont::Get(LuaToString(l, -1)); - } else if (!strcmp(key, "Centered")) { - contentcosts->Centered = LuaToBoolean(l, -1); - } else { - LuaError(l, "'%s' invalid for method 'Costs' in DefinePopups" _C_ key); - } + Assert(lua_istable(l, -1)); + for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) { + key = LuaToString(l, -2); + if (!strcmp(key, "Font")) { + contentcosts->Font = CFont::Get(LuaToString(l, -1)); + } else if (!strcmp(key, "Centered")) { + contentcosts->Centered = LuaToBoolean(l, -1); + } else { + LuaError(l, "'%s' invalid for method 'Costs' in DefinePopups" _C_ key); } - content = contentcosts; + } + content = contentcosts; } else if (!strcmp(key, "Variable")) { CPopupContentTypeVariable *contenttext = new CPopupContentTypeVariable; diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index cb55583be..27d668fb0 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -276,8 +276,8 @@ void CleanUserInterface() // Button Popups for (std::vector::iterator popup = UI.ButtonPopups.begin(); - popup != UI.ButtonPopups.end(); ++popup) { - delete *popup; + popup != UI.ButtonPopups.end(); ++popup) { + delete *popup; } UI.ButtonPopups.clear(); diff --git a/src/unit/unit.cpp b/src/unit/unit.cpp index acfa77e49..6dd0e31af 100644 --- a/src/unit/unit.cpp +++ b/src/unit/unit.cpp @@ -1591,10 +1591,10 @@ void CUnit::AssignWorkerToMine(CUnit &mine) CUnit *head = mine.Resource.Workers; #if 0 DebugPrint("%d: Worker [%d] is adding into %s [%d] on %d pos\n" - _C_ this->Player->Index _C_ this->Slot - _C_ mine.Type->Name.c_str() - _C_ mine.Slot - _C_ mine.Data.Resource.Assigned); + _C_ this->Player->Index _C_ this->Slot + _C_ mine.Type->Name.c_str() + _C_ mine.Slot + _C_ mine.Data.Resource.Assigned); #endif this->RefsIncrease(); this->NextWorker = head; @@ -1610,10 +1610,10 @@ void CUnit::DeAssignWorkerFromMine(CUnit &mine) CUnit *prev = NULL, *worker = mine.Resource.Workers; #if 0 DebugPrint("%d: Worker [%d] is removing from %s [%d] left %d units assigned\n" - _C_ this->Player->Index _C_ this->Slot - _C_ mine.Type->Name.c_str() - _C_ mine.Slot - _C_ mine.CurrentOrder()->Data.Resource.Assigned); + _C_ this->Player->Index _C_ this->Slot + _C_ mine.Type->Name.c_str() + _C_ mine.Slot + _C_ mine.CurrentOrder()->Data.Resource.Assigned); #endif for (int i = 0; NULL != worker; worker = worker->NextWorker, ++i) { if (worker == this) { diff --git a/src/unit/unit_draw.cpp b/src/unit/unit_draw.cpp index ee3dacf5d..d55239e65 100644 --- a/src/unit/unit_draw.cpp +++ b/src/unit/unit_draw.cpp @@ -578,13 +578,13 @@ static void DrawDecoration(const CUnit &unit, const CUnitType *type, int x, int Assert(value <= max); if (!((value == 0 && !var->ShowWhenNull) || (value == max && !var->ShowWhenMax) - || (var->HideHalf && value != 0 && value != max) - || (!var->ShowIfNotEnable && !unit.Variable[var->Index].Enable) - || (var->ShowOnlySelected && !unit.Selected) - || (unit.Player->Type == PlayerNeutral && var->HideNeutral) - || (ThisPlayer->IsEnemy(unit) && !var->ShowOpponent) - || (ThisPlayer->IsAllied(unit) && (unit.Player != ThisPlayer) && var->HideAllied) - || max == 0)) { + || (var->HideHalf && value != 0 && value != max) + || (!var->ShowIfNotEnable && !unit.Variable[var->Index].Enable) + || (var->ShowOnlySelected && !unit.Selected) + || (unit.Player->Type == PlayerNeutral && var->HideNeutral) + || (ThisPlayer->IsEnemy(unit) && !var->ShowOpponent) + || (ThisPlayer->IsAllied(unit) && (unit.Player != ThisPlayer) && var->HideAllied) + || max == 0)) { var->Draw( x + var->OffsetX + var->OffsetXPercent * unit.Type->TileWidth * PixelTileSize.x / 100, y + var->OffsetY + var->OffsetYPercent * unit.Type->TileHeight * PixelTileSize.y / 100, @@ -719,8 +719,9 @@ static void DrawInformations(const CUnit &unit, const CUnitType &type, int x, in // For debug draw sight, react and attack range! // if (NumSelected == 1 && unit.Selected) { - const PixelPos center = {x + type.TileWidth * PixelTileSize.x / 2, - y + type.TileHeight * PixelTileSize.y / 2}; + const PixelPos center = {x + type.TileWidth *PixelTileSize.x / 2, + y + type.TileHeight *PixelTileSize.y / 2 + }; if (Preference.ShowSightRange) { const int value = stats.Variables[SIGHTRANGE_INDEX].Max; diff --git a/src/unit/unit_save.cpp b/src/unit/unit_save.cpp index 232ac3110..d82d34659 100644 --- a/src/unit/unit_save.cpp +++ b/src/unit/unit_save.cpp @@ -61,7 +61,7 @@ std::string UnitReference(const CUnit &unit) { std::ostringstream ss; ss << "U" << std::setfill('0') << std::setw(4) << std::uppercase - << std::hex << UnitNumber(unit); + << std::hex << UnitNumber(unit); return ss.str(); } @@ -74,7 +74,7 @@ std::string UnitReference(const CUnitPtr &unit) std::ostringstream ss; ss << "U" << std::setfill('0') << std::setw(4) << std::uppercase - << std::hex << unit->Slot; + << std::hex << unit->Slot; return ss.str(); } diff --git a/src/unit/unitptr.cpp b/src/unit/unitptr.cpp index 4560fb899..d6d2a3def 100644 --- a/src/unit/unitptr.cpp +++ b/src/unit/unitptr.cpp @@ -56,7 +56,7 @@ void CUnitPtr::Reset() unit = NULL; } -CUnitPtr& CUnitPtr::operator= (CUnit *u) +CUnitPtr &CUnitPtr::operator= (CUnit *u) { if (this->unit != u) { if (u) { diff --git a/src/win32/attachconsole.cpp b/src/win32/attachconsole.cpp index 74ff95d27..54e136e2a 100644 --- a/src/win32/attachconsole.cpp +++ b/src/win32/attachconsole.cpp @@ -36,47 +36,54 @@ static HINSTANCE lib_ntdll = NULL; typedef int FAR WINAPI proto_AttachConsole(int); typedef int FAR WINAPI proto_NtQueryObject(HANDLE, int, void *, unsigned long int, unsigned long int *); -static proto_AttachConsole * func_AttachConsole = NULL; -static proto_NtQueryObject * func_NtQueryObject = NULL; +static proto_AttachConsole *func_AttachConsole = NULL; +static proto_NtQueryObject *func_NtQueryObject = NULL; /// Check if HANDLE is attached to console -static int WINAPI_CheckIfConsoleHandle(HANDLE handle) { +static int WINAPI_CheckIfConsoleHandle(HANDLE handle) +{ wchar_t filename[MAX_PATH]; unsigned long int length = 0; // Try to get filename of HANDLE - if ( func_NtQueryObject ) + if (func_NtQueryObject) { func_NtQueryObject(handle, 1, filename, MAX_PATH, &length); + } // Filename start at position 8 - if ( length > 8 ) + if (length > 8) { return 0; - else + } else { return 1; + } } /// Try to reopen FILE* from WINAPI HANDLE -static void WINAPI_ReopenFileFromHandle(HANDLE handle, FILE * file, const char * mode) { +static void WINAPI_ReopenFileFromHandle(HANDLE handle, FILE *file, const char *mode) +{ int fd; - FILE * newfile; + FILE *newfile; - if ( ! handle || handle == INVALID_HANDLE_VALUE ) + if (! handle || handle == INVALID_HANDLE_VALUE) { return; + } // Get file descriptor from HANDLE fd = _open_osfhandle((intptr_t)handle, O_TEXT); - if ( fd < 0 ) + if (fd < 0) { return; + } // Get C structure FILE* from file descriptior newfile = _fdopen(fd, mode); - if ( ! newfile ) + if (! newfile) { return; + } // Close current file fclose(file); @@ -87,7 +94,7 @@ static void WINAPI_ReopenFileFromHandle(HANDLE handle, FILE * file, const char * setvbuf(file, NULL, _IONBF, 0); // If stdout/stderr write 2 empty lines to cmd console - if ( ! fixmode && strcmp(mode, "w") == 0 ) { + if (! fixmode && strcmp(mode, "w") == 0) { fprintf(file, "\n\n"); fixmode = 1; @@ -97,27 +104,31 @@ static void WINAPI_ReopenFileFromHandle(HANDLE handle, FILE * file, const char * } /// Try to set std HANDLE from FILE* -static void WINAPI_SetStdHandleFromFile(int type, FILE * file) { +static void WINAPI_SetStdHandleFromFile(int type, FILE *file) +{ int fd; HANDLE handle; fd = _fileno(file); - if ( fd < 0 ) + if (fd < 0) { return; + } handle = (HANDLE)_get_osfhandle(fd); - if ( ! handle || handle == INVALID_HANDLE_VALUE ) + if (! handle || handle == INVALID_HANDLE_VALUE) { return; + } SetStdHandle(type, handle); } /// Try attach console of parent process for std input/output in Windows NT, 2000, XP or new -static void WINAPI_AttachConsole(void) { +static void WINAPI_AttachConsole(void) +{ OSVERSIONINFO osvi; int hasVersion; @@ -132,29 +143,34 @@ static void WINAPI_AttachConsole(void) { hasVersion = GetVersionEx(&osvi); - if ( ! hasVersion ) + if (! hasVersion) { return; + } - version = ( osvi.dwMajorVersion << 8 ) | osvi.dwMinorVersion; + version = (osvi.dwMajorVersion << 8) | osvi.dwMinorVersion; // We need Windows 2000 or new - if ( version < 0x0500 ) + if (version < 0x0500) { return; + } lib_kernel32 = LoadLibrary("kernel32.dll"); - if ( ! lib_kernel32 ) + if (! lib_kernel32) { return; + } - func_AttachConsole = (proto_AttachConsole*)GetProcAddress(lib_kernel32, "AttachConsole"); + func_AttachConsole = (proto_AttachConsole *)GetProcAddress(lib_kernel32, "AttachConsole"); - if ( ! func_AttachConsole ) + if (! func_AttachConsole) { return; + } lib_ntdll = LoadLibrary("ntdll.dll"); - if ( lib_ntdll ) - func_NtQueryObject = (proto_NtQueryObject*)GetProcAddress(lib_ntdll, "NtQueryObject"); + if (lib_ntdll) { + func_NtQueryObject = (proto_NtQueryObject *)GetProcAddress(lib_ntdll, "NtQueryObject"); + } // Ignore if HANDLE is not attached console reopen_stdin = WINAPI_CheckIfConsoleHandle(GetStdHandle(STD_INPUT_HANDLE)); @@ -163,23 +179,27 @@ static void WINAPI_AttachConsole(void) { attached = func_AttachConsole(-1); - if ( ! attached ) + if (! attached) { return; + } - if ( reopen_stdin ) + if (reopen_stdin) { WINAPI_ReopenFileFromHandle(GetStdHandle(STD_INPUT_HANDLE), stdin, "r"); - else + } else { WINAPI_SetStdHandleFromFile(STD_INPUT_HANDLE, stdin); + } - if ( reopen_stdout ) + if (reopen_stdout) { WINAPI_ReopenFileFromHandle(GetStdHandle(STD_OUTPUT_HANDLE), stdout, "w"); - else + } else { WINAPI_SetStdHandleFromFile(STD_OUTPUT_HANDLE, stdout); + } - if ( reopen_stderr ) + if (reopen_stderr) { WINAPI_ReopenFileFromHandle(GetStdHandle(STD_ERROR_HANDLE), stderr, "w"); - else + } else { WINAPI_SetStdHandleFromFile(STD_ERROR_HANDLE, stderr); + } #ifdef __cplusplus std::cin.clear();