bool Tile::isFogged(int houseID) { if(debug) return false; if(currentGame->getGameInitSettings().getGameOptions().fogOfWar == false) { return false; } else if((currentGame->getGameCycleCount() - lastAccess[houseID]) >= MILLI2CYCLES(10*1000)) { return true; } else { return false; } }
void UnitBase::handleDamage(int damage, Uint32 damagerID, House* damagerOwner) { // shorten deviation time if(deviationTimer > 0) { deviationTimer = std::max(0,deviationTimer - MILLI2CYCLES(damage*20*1000)); } ObjectBase::handleDamage(damage, damagerID, damagerOwner); if(attackMode == HUNT && !forced) { ObjectBase* pDamager = currentGame->getObjectManager().getObject(damagerID); if(pDamager != NULL && canAttack(pDamager)) { if(!target || target.getObjPointer() == NULL || !isInWeaponRange(target.getObjPointer())) { // no target or target not on weapon range => switch target doAttackObject(pDamager, false); } } } }
void CommandManager::update() { if(pNetworkManager != NULL) { CommandList commandList; for(Uint32 i = std::max((int) currentGame->getGameCycleCount() - MILLI2CYCLES(2500), 0); i < currentGame->getGameCycleCount() + networkCycleBuffer; i++) { std::vector<Command> commands; if(i < timeslot.size()) { std::vector<Command>::const_iterator iter; for(iter = timeslot[i].begin(); iter != timeslot[i].end(); ++iter) { if(iter->getPlayerID() == pLocalPlayer->getPlayerID()) { commands.push_back(*iter); } } } commandList.commandList.push_back(CommandList::CommandListEntry(i, commands)); } pNetworkManager->sendCommandList(commandList); } }
void UnitBase::navigate() { if(isAFlyingUnit() || (((currentGame->getGameCycleCount() + getObjectID()*1337) % 5) == 0)) { // navigation is only performed every 5th frame if(!moving && !justStoppedMoving) { if(location != destination) { if(nextSpotFound == false) { if(pathList.empty() && (recalculatePathTimer == 0)) { recalculatePathTimer = 100; if(!SearchPathWithAStar() && (++noCloserPointCount >= 3) && (location != oldLocation)) { //try searching for a path a number of times then give up if (target.getObjPointer() != NULL && targetFriendly && (target.getObjPointer()->getItemID() != Structure_RepairYard) && ((target.getObjPointer()->getItemID() != Structure_Refinery) || (getItemID() != Unit_Harvester))) { setTarget(NULL); } setDestination(location); //can't get any closer, give up forced = false; } } if(!pathList.empty()) { nextSpot = pathList.front(); pathList.pop_front(); nextSpotFound = true; recalculatePathTimer = 0; noCloserPointCount = 0; } } else { int tempAngle = currentGameMap->getPosAngle(location, nextSpot); if(tempAngle != INVALID) { nextSpotAngle = tempAngle; } if(!canPass(nextSpot.x, nextSpot.y)) { clearPath(); } else { if (drawnAngle == nextSpotAngle) { moving = true; nextSpotFound = false; assignToMap(nextSpot); angle = drawnAngle; setSpeeds(); } } } } else if(!target) { if(((currentGame->getGameCycleCount() + getObjectID()*1337) % MILLI2CYCLES(UNITIDLETIMER)) == 0) { idleAction(); } } } } }
void UnitBase::attack() { if(numWeapons) { Coord targetCenterPoint; Coord centerPoint = getCenterPoint(); bool bAirBullet; if(target.getObjPointer() != NULL) { targetCenterPoint = target.getObjPointer()->getClosestCenterPoint(location); bAirBullet = target.getObjPointer()->isAFlyingUnit(); } else { targetCenterPoint = currentGameMap->getTile(attackPos)->getCenterPoint(); bAirBullet = false; } int currentBulletType = bulletType; Sint32 currentWeaponDamage = currentGame->objectData.data[itemID][originalHouseID].weapondamage; if(getItemID() == Unit_Trooper) { // Troopers change weapon type depending on distance float distance = distanceFrom(centerPoint, targetCenterPoint); if(distance > 2*TILESIZE) { currentBulletType = Bullet_SmallRocket; } } if(primaryWeaponTimer == 0) { bulletList.push_back( new Bullet( objectID, ¢erPoint, &targetCenterPoint, currentBulletType, currentWeaponDamage, bAirBullet) ); playAttackSound(); primaryWeaponTimer = getWeaponReloadTime(); secondaryWeaponTimer = 15; if(attackPos && getItemID() != Unit_SonicTank && currentGameMap->getTile(attackPos)->isSpiceBloom()) { setDestination(location); forced = false; attackPos.invalidate(); } // shorten deviation time if(deviationTimer > 0) { deviationTimer = std::max(0,deviationTimer - MILLI2CYCLES(20*1000)); } } if((numWeapons == 2) && (secondaryWeaponTimer == 0) && (isBadlyDamaged() == false)) { bulletList.push_back( new Bullet( objectID, ¢erPoint, &targetCenterPoint, currentBulletType, currentWeaponDamage, bAirBullet) ); playAttackSound(); secondaryWeaponTimer = -1; if(attackPos && getItemID() != Unit_SonicTank && currentGameMap->getTile(attackPos)->isSpiceBloom()) { setDestination(location); forced = false; attackPos.invalidate(); } // shorten deviation time if(deviationTimer > 0) { deviationTimer = std::max(0,deviationTimer - MILLI2CYCLES(20*1000)); } } } }