void UnitBase::doAttackObject(const ObjectBase* pTargetObject, bool bForced) { if (pTargetObject == NULL) { return; } if(pTargetObject->getObjectID() == getObjectID() || (!canAttack() && getItemID() != Unit_Harvester)) { return; } if(attackMode == CAPTURE) { doSetAttackMode(GUARD); } setDestination(INVALID_POS,INVALID_POS); setTarget(pTargetObject); // hack to make it possible to attack own repair yard if(goingToRepairYard && target && (target.getObjPointer()->getItemID() == Structure_RepairYard)) { ((RepairYard*)target.getObjPointer())->unBook(); goingToRepairYard = false; } setForced(bForced); clearPath(); findTargetTimer = 0; }
void UnitBase::releaseTarget() { if(forced == true) { guardPoint = location; } setDestination(guardPoint); findTargetTimer = 0; setForced(false); setTarget(NULL); }
void TurretClass::DoAttackObject(Uint32 TargetObjectID) { ObjectClass* pObject = currentGame->getObjectManager().getObject(TargetObjectID); if(pObject == NULL) { return; } setDestination(INVALID_POS,INVALID_POS); setTarget(pObject); setForced(true); }
void UnitBase::doAttackPos(int xPos, int yPos, bool bForced) { if(attackMode == CAPTURE) { doSetAttackMode(GUARD); } setDestination(xPos,yPos); setTarget(NULL); setForced(bForced); attackPos.x = xPos; attackPos.y = yPos; clearPath(); findTargetTimer = 0; }
void UnitBase::doMove2Pos(int xPos, int yPos, bool bForced) { if(attackMode == CAPTURE || attackMode == HUNT) { doSetAttackMode(GUARD); } if((xPos != destination.x) || (yPos != destination.y)) { clearPath(); findTargetTimer = 0; } setTarget(NULL); setDestination(xPos,yPos); setForced(bForced); setGuardPoint(xPos,yPos); }
void UnitBase::doMove2Object(const ObjectBase* pTargetObject) { if(pTargetObject->getObjectID() == getObjectID()) { return; } if(attackMode == CAPTURE || attackMode == HUNT) { doSetAttackMode(GUARD); } setDestination(INVALID_POS,INVALID_POS); setTarget(pTargetObject); setForced(true); bFollow = true; clearPath(); findTargetTimer = 0; }
void UnitBase::move() { if(!moving && !justStoppedMoving && (isAFlyingUnit() == false) && currentGame->randomGen.rand(0,40) == 0 && itemID != Unit_Sandworm) { currentGameMap->viewMap(owner->getTeam(), location, getViewRange() ); } if(moving && !justStoppedMoving) { if((isBadlyDamaged() == false) || isAFlyingUnit()) { realX += xSpeed; realY += ySpeed; } else { realX += xSpeed/2; realY += ySpeed/2; } // check if vehicle is on the first half of the way float fromDistanceX; float fromDistanceY; float toDistanceX; float toDistanceY; if(location != nextSpot) { // check if vehicle is half way out of old tile fromDistanceX = strictmath::abs(location.x*TILESIZE - (realX-bumpyOffsetX) + TILESIZE/2); fromDistanceY = strictmath::abs(location.y*TILESIZE - (realY-bumpyOffsetY) + TILESIZE/2); toDistanceX = strictmath::abs(nextSpot.x*TILESIZE - (realX-bumpyOffsetX) + TILESIZE/2); toDistanceY = strictmath::abs(nextSpot.y*TILESIZE - (realY-bumpyOffsetY) + TILESIZE/2); if((fromDistanceX >= TILESIZE/2) || (fromDistanceY >= TILESIZE/2)) { // let something else go in unassignFromMap(location); oldLocation = location; location = nextSpot; if(isAFlyingUnit() == false && itemID != Unit_Sandworm) { currentGameMap->viewMap(owner->getTeam(), location, getViewRange()); } } } else { // if vehicle is out of old tile fromDistanceX = strictmath::abs(oldLocation.x*TILESIZE - (realX-bumpyOffsetX) + TILESIZE/2); fromDistanceY = strictmath::abs(oldLocation.y*TILESIZE - (realY-bumpyOffsetY) + TILESIZE/2); toDistanceX = strictmath::abs(location.x*TILESIZE - (realX-bumpyOffsetX) + TILESIZE/2); toDistanceY = strictmath::abs(location.y*TILESIZE - (realY-bumpyOffsetY) + TILESIZE/2); if ((fromDistanceX >= TILESIZE) || (fromDistanceY >= TILESIZE)) { if(forced && (location == destination) && !target) { setForced(false); } moving = false; justStoppedMoving = true; realX = location.x * TILESIZE + TILESIZE/2; realY = location.y * TILESIZE + TILESIZE/2; bumpyOffsetX = 0.0f; bumpyOffsetY = 0.0f; oldLocation.invalidate(); } } bumpyMovementOnRock(fromDistanceX, fromDistanceY, toDistanceX, toDistanceY); } else { justStoppedMoving = false; } checkPos(); }