From d42b58d1d2b2f33d1e18a906fe7142499b9f5d3f Mon Sep 17 00:00:00 2001 From: joris Date: Sat, 8 Mar 2014 17:12:33 +0100 Subject: [PATCH] [AStyle] --- src/action/action_attack.cpp | 58 ++++++++++++++++++------------------ src/action/action_move.cpp | 4 +-- src/game/game.cpp | 2 +- src/include/unit_find.h | 2 +- src/spell/script_spell.cpp | 2 +- src/ui/mouse.cpp | 48 ++++++++++++++--------------- src/unit/unit_find.cpp | 58 ++++++++++++++++++------------------ 7 files changed, 87 insertions(+), 87 deletions(-) diff --git a/src/action/action_attack.cpp b/src/action/action_attack.cpp index dd518fcd4..df3c89249 100644 --- a/src/action/action_attack.cpp +++ b/src/action/action_attack.cpp @@ -408,15 +408,15 @@ void COrder_Attack::MoveToTarget(CUnit &unit) } // Attacking wall or ground. if (((goal && goal->Type && goal->Type->Wall) - || (!goal && (Map.WallOnMap(this->goalPos) || this->Action == UnitActionAttackGround))) + || (!goal && (Map.WallOnMap(this->goalPos) || this->Action == UnitActionAttackGround))) && unit.MapDistanceTo(this->goalPos) <= unit.Stats->Variables[ATTACKRANGE_INDEX].Max) { - if (!GameSettings.Inside || CheckObstaclesBetweenTiles(unit.tilePos, goalPos, MapFieldRocks | MapFieldForest)) { - // Reached wall or ground, now attacking it - UnitHeadingFromDeltaXY(unit, this->goalPos - unit.tilePos); - this->State &= WEAK_TARGET; - this->State |= ATTACK_TARGET; - return; - } + if (!GameSettings.Inside || CheckObstaclesBetweenTiles(unit.tilePos, goalPos, MapFieldRocks | MapFieldForest)) { + // Reached wall or ground, now attacking it + UnitHeadingFromDeltaXY(unit, this->goalPos - unit.tilePos); + this->State &= WEAK_TARGET; + this->State |= ATTACK_TARGET; + return; + } } } // Unreachable. @@ -511,21 +511,21 @@ void COrder_Attack::AttackTarget(CUnit &unit) // Still near to target, if not goto target. const int dist = unit.MapDistanceTo(*goal); - if (dist > unit.Stats->Variables[ATTACKRANGE_INDEX].Max + if (dist > unit.Stats->Variables[ATTACKRANGE_INDEX].Max || (GameSettings.Inside && CheckObstaclesBetweenTiles(unit.tilePos, goal->tilePos, MapFieldRocks | MapFieldForest) == false)) { - // towers don't chase after goal - if (unit.CanMove()) { - if (unit.CanStoreOrder(this)) { - if (dead) { - unit.SavedOrder = COrder::NewActionAttack(unit, this->goalPos); - } else { - unit.SavedOrder = this->Clone(); - } + // towers don't chase after goal + if (unit.CanMove()) { + if (unit.CanStoreOrder(this)) { + if (dead) { + unit.SavedOrder = COrder::NewActionAttack(unit, this->goalPos); + } else { + unit.SavedOrder = this->Clone(); } } - unit.Frame = 0; - this->State &= WEAK_TARGET; - this->State |= MOVE_TO_TARGET; + } + unit.Frame = 0; + this->State &= WEAK_TARGET; + this->State |= MOVE_TO_TARGET; } if (dist < unit.Type->MinAttackRange) { this->State = MOVE_TO_TARGET; @@ -564,8 +564,8 @@ void COrder_Attack::AttackTarget(CUnit &unit) return; } if (unit.Waiting) { - unit.Anim = unit.WaitBackup; - unit.Waiting = 0; + unit.Anim = unit.WaitBackup; + unit.Waiting = 0; } switch (this->State) { @@ -581,14 +581,14 @@ void COrder_Attack::AttackTarget(CUnit &unit) if (unit.Type->MinAttackRange < dist && dist <= unit.Stats->Variables[ATTACKRANGE_INDEX].Max) { - if (!GameSettings.Inside || CheckObstaclesBetweenTiles(unit.tilePos, goalPos, MapFieldRocks | MapFieldForest)) { - const Vec2i dir = goal.tilePos + goal.Type->GetHalfTileSize() - unit.tilePos; + if (!GameSettings.Inside || CheckObstaclesBetweenTiles(unit.tilePos, goalPos, MapFieldRocks | MapFieldForest)) { + const Vec2i dir = goal.tilePos + goal.Type->GetHalfTileSize() - unit.tilePos; - UnitHeadingFromDeltaXY(unit, dir); - this->State |= ATTACK_TARGET; - AttackTarget(unit); - return; - } + UnitHeadingFromDeltaXY(unit, dir); + this->State |= ATTACK_TARGET; + AttackTarget(unit); + return; + } } } this->State = MOVE_TO_TARGET; diff --git a/src/action/action_move.cpp b/src/action/action_move.cpp index a2b769f99..295ae2947 100644 --- a/src/action/action_move.cpp +++ b/src/action/action_move.cpp @@ -112,7 +112,7 @@ } /* virtual */ void COrder_Move::UpdatePathFinderData(PathFinderInput &input) -{ +{ const Vec2i tileSize(0, 0); input.SetGoal(this->goalPos, tileSize); @@ -121,7 +121,7 @@ CheckObstaclesBetweenTiles(input.GetUnitPos(), this->HasGoal() ? this->GetGoal()->tilePos : this->goalPos, MapFieldRocks | MapFieldForest, &distance); } input.SetMaxRange(distance); - input.SetMinRange(0); + input.SetMinRange(0); } /** diff --git a/src/game/game.cpp b/src/game/game.cpp index df179e2e4..01429f1f1 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -510,7 +510,7 @@ int WriteMapSetup(const char *mapSetup, CMap &map, int writeTerrain) f->printf("-- place units\n"); f->printf("if (MapUnitsInit ~= nil) then MapUnitsInit() end\n"); - std::vector teleporters; + std::vector teleporters; for (CUnitManager::Iterator it = UnitManager.begin(); it != UnitManager.end(); ++it) { const CUnit &unit = **it; f->printf("unit = CreateUnit(\"%s\", %d, {%d, %d})\n", diff --git a/src/include/unit_find.h b/src/include/unit_find.h index 538de9e06..587bc3868 100644 --- a/src/include/unit_find.h +++ b/src/include/unit_find.h @@ -307,7 +307,7 @@ extern CUnit *ResourceOnMap(const Vec2i &pos, int resource, bool mine_on_top = t /// Return resource deposit, if on map tile extern CUnit *ResourceDepositOnMap(const Vec2i &pos, int resource); -/// Check map for obstacles in a line between 2 tiles +/// Check map for obstacles in a line between 2 tiles extern bool CheckObstaclesBetweenTiles(const Vec2i &unitPos, const Vec2i &goalPos, unsigned short flags, int *distance = NULL); /// Find best enemy in numeric range to attack extern CUnit *AttackUnitsInDistance(const CUnit &unit, int range, bool onlyBuildings = false); diff --git a/src/spell/script_spell.cpp b/src/spell/script_spell.cpp index 68d621d1d..254848aa2 100644 --- a/src/spell/script_spell.cpp +++ b/src/spell/script_spell.cpp @@ -240,7 +240,7 @@ static void CclSpellAutocast(lua_State *l, AutoCastInfo *autocast) if (!strcmp(value, "range")) { autocast->Range = LuaToNumber(l, -1, j + 1); } else if (!strcmp(value, "min-range")) { - autocast->MinRange = LuaToNumber(l, -1, j + 1); + autocast->MinRange = LuaToNumber(l, -1, j + 1); } else if (!strcmp(value, "combat")) { autocast->Combat = Ccl2Condition(l, LuaToString(l, -1, j + 1)); } else if (!strcmp(value, "attacker")) { diff --git a/src/ui/mouse.cpp b/src/ui/mouse.cpp index 8031f4a69..767fd710a 100644 --- a/src/ui/mouse.cpp +++ b/src/ui/mouse.cpp @@ -223,12 +223,12 @@ static bool DoRightButton_Harvest_Unit(CUnit &unit, CUnit &dest, int flush, int && dest.Type->CanHarvest && (dest.Player == unit.Player || dest.Player->Index == PlayerNumNeutral)) { dest.Blink = 4; - SendCommandResource(unit, dest, flush); - if (!acknowledged) { - PlayUnitSound(unit, VoiceHarvesting); - acknowledged = 1; - } - return true; + SendCommandResource(unit, dest, flush); + if (!acknowledged) { + PlayUnitSound(unit, VoiceHarvesting); + acknowledged = 1; + } + return true; } return false; } @@ -245,13 +245,13 @@ static bool DoRightButton_Harvest_Pos(CUnit &unit, const Vec2i &pos, int flush, && type.ResInfo[res]->TerrainHarvester && Map.Field(pos)->IsTerrainResourceOnMap(res) && ((unit.CurrentResource != res) - || (unit.ResourcesHeld < type.ResInfo[res]->ResourceCapacity))) { - SendCommandResourceLoc(unit, pos, flush); - if (!acknowledged) { - PlayUnitSound(unit, VoiceHarvesting); - acknowledged = 1; - } - return true; + || (unit.ResourcesHeld < type.ResInfo[res]->ResourceCapacity))) { + SendCommandResourceLoc(unit, pos, flush); + if (!acknowledged) { + PlayUnitSound(unit, VoiceHarvesting); + acknowledged = 1; + } + return true; } } return false; @@ -289,17 +289,17 @@ static bool DoRightButton_Worker(CUnit &unit, CUnit *dest, const Vec2i &pos, int // Follow another unit if (UnitUnderCursor != NULL && dest != NULL && dest != &unit && (dest->Player == unit.Player || unit.IsAllied(*dest) || dest->Player->Index == PlayerNumNeutral)) { - dest->Blink = 4; - if (!acknowledged) { - PlayUnitSound(unit, VoiceAcknowledging); - acknowledged = 1; - } - if (dest->Type->CanMove() == false && !dest->Type->Teleporter) { - SendCommandMove(unit, pos, flush); - } else { - SendCommandFollow(unit, *dest, flush); - } - return true; + dest->Blink = 4; + if (!acknowledged) { + PlayUnitSound(unit, VoiceAcknowledging); + acknowledged = 1; + } + if (dest->Type->CanMove() == false && !dest->Type->Teleporter) { + SendCommandMove(unit, pos, flush); + } else { + SendCommandFollow(unit, *dest, flush); + } + return true; } // Move if (!acknowledged) { diff --git a/src/unit/unit_find.cpp b/src/unit/unit_find.cpp index 8e3eff4fb..243d4346a 100644 --- a/src/unit/unit_find.cpp +++ b/src/unit/unit_find.cpp @@ -1061,7 +1061,7 @@ struct CompareUnitDistance { }; /** -** Check map for obstacles in a line between 2 tiles +** Check map for obstacles in a line between 2 tiles ** ** This function uses Bresenham's line algorithm ** @@ -1069,36 +1069,36 @@ struct CompareUnitDistance { ** @param goal Second tile ** @param flags Terrain type to check ** -** @return true, if an obstacle was found, false otherwise +** @return true, if an obstacle was found, false otherwise */ bool CheckObstaclesBetweenTiles(const Vec2i &unitPos, const Vec2i &goalPos, unsigned short flags, int *distance) -{ - const Vec2i delta(abs(goalPos.x - unitPos.x), abs(goalPos.y - unitPos.y)); - const Vec2i sign(unitPos.x < goalPos.x ? 1 : -1, unitPos.y < goalPos.y ? 1 : -1); - int error = delta.x - delta.y; - Vec2i pos(unitPos), oldPos(unitPos); - - while(pos.x != goalPos.x || pos.y != goalPos.y) { - const int error2 = error * 2; - - if(error2 > -delta.y) { - error -= delta.y; - pos.x += sign.x; - } - if(error2 < delta.x) { - error += delta.x; - pos.y += sign.y; - } - - if (Map.Info.IsPointOnMap(pos) == false) { - DebugPrint("outside of map\n"); - } else if (Map.Field(pos)->Flags & flags) { - if (distance) { - *distance = Distance(unitPos, pos); - } - return false; - } - oldPos = pos; +{ + const Vec2i delta(abs(goalPos.x - unitPos.x), abs(goalPos.y - unitPos.y)); + const Vec2i sign(unitPos.x < goalPos.x ? 1 : -1, unitPos.y < goalPos.y ? 1 : -1); + int error = delta.x - delta.y; + Vec2i pos(unitPos), oldPos(unitPos); + + while (pos.x != goalPos.x || pos.y != goalPos.y) { + const int error2 = error * 2; + + if (error2 > -delta.y) { + error -= delta.y; + pos.x += sign.x; + } + if (error2 < delta.x) { + error += delta.x; + pos.y += sign.y; + } + + if (Map.Info.IsPointOnMap(pos) == false) { + DebugPrint("outside of map\n"); + } else if (Map.Field(pos)->Flags & flags) { + if (distance) { + *distance = Distance(unitPos, pos); + } + return false; + } + oldPos = pos; } return true; }