Simplify wall-dragging validity check.

Not sure why validLocation is partially responsible for updating the build position.
master
Cyp 2011-03-17 10:33:20 +01:00
parent 6b70765f42
commit e6c9c4799c
1 changed files with 18 additions and 49 deletions

View File

@ -4132,56 +4132,25 @@ bool validLocation(BASE_STATS *psStats, unsigned x, unsigned y, uint16_t directi
&& (psBuilding->type == REF_WALL || psBuilding->type == REF_DEFENSE || psBuilding->type == REF_REARM_PAD || psBuilding->type == REF_GATE)
&& !isLasSat(psBuilding))
{
UWORD dx,dy;
wallDrag.x2 = mouseTileX; // Why must this be done here? If not doing it here, dragging works almost normally, except it suddenly stops working if the drag becomes invalid.
wallDrag.y2 = mouseTileY;
wallDrag.x2 = mouseTileX;
wallDrag.y2 = mouseTileY;
dx = (UWORD)(abs(mouseTileX - wallDrag.x1));
dy = (UWORD)(abs(mouseTileY - wallDrag.y1));
if(dx >= dy)
{
//build in x direction
site.xTL = (UWORD)wallDrag.x1;
site.xBR = (UWORD)wallDrag.x2;
site.yTL = (UWORD)wallDrag.y1;
if (dy > 0)
{
site.yBR = (UWORD)(site.yTL+1);
}
else
{
site.yBR = (UWORD)(site.yTL);
}
if (site.xTL > site.xBR)
{
dx = site.xBR;
site.xBR = site.xTL;
site.xTL = dx;
}
}
else if(dx < dy)
{
//build in y direction
site.yTL = (UWORD)wallDrag.y1;
site.yBR = (UWORD)wallDrag.y2;
site.xTL = (UWORD)wallDrag.x1;
if (dx > 0)
{
site.xBR = (UWORD)(site.xTL+1);
}
else
{
site.xBR = (UWORD)(site.xTL);
}
if (site.yTL > site.yBR)
{
dy = site.yBR;
site.yBR = site.yTL;
site.yTL = dy;
}
}
int dx = abs(wallDrag.x2 - wallDrag.x1);
int dy = abs(wallDrag.y2 - wallDrag.y1);
if (dx >= dy)
{
//build in x direction
wallDrag.y2 = wallDrag.y1;
}
else
{
//build in y direction
wallDrag.x2 = wallDrag.x1;
}
site.xTL = std::min(wallDrag.x1, wallDrag.x2);
site.xBR = std::max(wallDrag.x1, wallDrag.x2);
site.yTL = std::min(wallDrag.y1, wallDrag.y2);
site.yBR = std::max(wallDrag.y1, wallDrag.y2);
}
}
else