[AStyle]
This commit is contained in:
parent
ab720b4508
commit
d42b58d1d2
7 changed files with 87 additions and 87 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<CUnit*> teleporters;
|
||||
std::vector<CUnit *> teleporters;
|
||||
for (CUnitManager::Iterator it = UnitManager.begin(); it != UnitManager.end(); ++it) {
|
||||
const CUnit &unit = **it;
|
||||
f->printf("unit = CreateUnit(\"%s\", %d, {%d, %d})\n",
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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")) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue