google-code-export / bwapi

Automatically exported from code.google.com/p/bwapi
0 stars 0 forks source link

bug in Unit::GetDistance(Unit) #175

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

In the current code, the first couple of if statements (Unit.cpp, lines
80-92 will be ignored as result will get overwritten by remainder of the
function.  You get some odd results like those attached.

I think all it should need is to combine the two outermost ifs with an &&
and stick in an else or two

ie something like
===
    if (this->getPosition().y - this->getType().dimensionUp() <=
unit->getPosition().y + unit->getType().dimensionDown()
      && (this->getPosition().y + this->getType().dimensionDown() >=
unit->getPosition().y - unit->getType().dimensionUp())
        if (this->getPosition().x > unit->getPosition().x)
          result = this->getPosition().x - this->getType().dimensionLeft()
- unit->getPosition().x - unit->getType().dimensionRight();
        else
          result = unit->getPosition().x - unit->getType().dimensionRight()
- this->getPosition().x - this->getType().dimensionLeft();

    else if (this->getPosition().x - this->getType().dimensionLeft() <=
unit->getPosition().x + unit->getType().dimensionRight()
      && (this->getPosition().x + this->getType().dimensionRight() >=
unit->getPosition().x - unit->getType().dimensionLeft())
        if (this->getPosition().y > unit->getPosition().y)
          result = this->getPosition().y - this->getType().dimensionUp() -
unit->getPosition().y - unit->getType().dimensionDown();
        else
          result = unit->getPosition().y - unit->getType().dimensionDown()
- this->getPosition().y - this->getType().dimensionUp();

    else if (this->getPosition().x > unit->getPosition().x)
    ...

Original issue reported on code.google.com by danielst...@gmail.com on 30 Dec 2009 at 8:18

Attachments:

GoogleCodeExporter commented 9 years ago
ugh.. formatting :/

Original comment by danielst...@gmail.com on 30 Dec 2009 at 8:20

GoogleCodeExporter commented 9 years ago
Fixed in r1856

Original comment by lowerlo...@gmail.com on 30 Dec 2009 at 10:27