char BattleHex::getDistance(BattleHex hex1, BattleHex hex2) { int y1 = hex1.getY(), y2 = hex2.getY(); int x1 = hex1.getX() + y1 / 2.0, x2 = hex2.getX() + y2 / 2.0; int xDst = x2 - x1, yDst = y2 - y1; if ((xDst >= 0 && yDst >= 0) || (xDst < 0 && yDst < 0)) return std::max(std::abs(xDst), std::abs(yDst)); else return std::abs(xDst) + std::abs(yDst); }
Point CClickableHex::getXYUnitAnim(BattleHex hexNum, const CStack * stack, CBattleInterface * cbi) { assert(cbi); Point ret(-500, -500); //returned value if(stack && stack->position < 0) //creatures in turrets { switch(stack->position) { case -2: //keep ret = cbi->siegeH->town->town->clientInfo.siegePositions[18]; break; case -3: //lower turret ret = cbi->siegeH->town->town->clientInfo.siegePositions[19]; break; case -4: //upper turret ret = cbi->siegeH->town->town->clientInfo.siegePositions[20]; break; } } else { static const Point basePos(-190, -139); // position of creature in topleft corner static const int imageShiftX = 30; // X offset to base pos for facing right stacks, negative for facing left ret.x = basePos.x + 22 * ( (hexNum.getY() + 1)%2 ) + 44 * hexNum.getX(); ret.y = basePos.y + 42 * hexNum.getY(); if (stack) { if(cbi->creDir[stack->ID]) ret.x += imageShiftX; else ret.x -= imageShiftX; //shifting position for double - hex creatures if(stack->doubleWide()) { if(stack->attackerOwned) { if(cbi->creDir[stack->ID]) ret.x -= 44; } else { if(!cbi->creDir[stack->ID]) ret.x += 44; } } } } //returning return ret +CPlayerInterface::battleInt->pos; }