CvPlot* CvPlayerAI::FindBestMerchantTargetPlot(CvUnit* pGreatMerchant, bool bOnlySafePaths) { CvAssertMsg(pGreatMerchant, "pGreatMerchant is null"); if(!pGreatMerchant) { return NULL; } int iBestTurnsToReach = MAX_INT; CvPlot* pBestTargetPlot = NULL; int iPathTurns; UnitHandle pMerchant = UnitHandle(pGreatMerchant); CvTeam& kTeam = GET_TEAM(getTeam()); // Loop through each city state for(int iI = 0; iI < MAX_PLAYERS; iI++) { CvPlayer& kPlayer = GET_PLAYER((PlayerTypes)iI); if(kPlayer.isMinorCiv()) { CvPlot* pCSPlot = kPlayer.getStartingPlot(); if(pCSPlot) { if(pCSPlot->isRevealed(getTeam())) { // Is this a minor we are friendly with? if(GetDiplomacyAI()->GetMinorCivApproach(kPlayer.GetID()) != MINOR_CIV_APPROACH_CONQUEST && !kTeam.isAtWar(kPlayer.getTeam()) && GetDiplomacyAI()->GetWarGoal(kPlayer.GetID()) == NO_WAR_GOAL_TYPE) { // Search all the plots adjacent to this city (since can't enter the minor city plot itself) for(int jJ = 0; jJ < NUM_DIRECTION_TYPES; jJ++) { CvPlot* pAdjacentPlot = plotDirection(pCSPlot->getX(), pCSPlot->getY(), ((DirectionTypes)jJ)); if(pAdjacentPlot != NULL) { // Make sure this is still owned by the city state and is revealed to us and isn't a water tile if(pAdjacentPlot->getOwner() == (PlayerTypes)iI && pAdjacentPlot->isRevealed(getTeam()) && !pAdjacentPlot->isWater()) { iPathTurns = TurnsToReachTarget(pMerchant, pAdjacentPlot, true /*bReusePaths*/, !bOnlySafePaths/*bIgnoreUnits*/); if(iPathTurns < iBestTurnsToReach) { iBestTurnsToReach = iPathTurns; pBestTargetPlot = pAdjacentPlot; } } } } } } } } } return pBestTargetPlot; }
bool Turret::isTargetable (Player *player, float *minDist, float useRange) { if (player && player->getTeam () != getTeam() && player->getVisibleToTeam (getTeam()) && !player->isDead()) { if (const char* script = scriptName("verifyTarget")) { const char* pRet = Console->evaluatef("%s(%d);", script, player->getId()); if (pRet[0] == 'F' || pRet[0] == 'f') return false; } Point3F playerPos = player->getLeadCenter(); float dist = m_distf (getBoxCenter(), playerPos); if (dist < useRange) targetsTracked++; if (dist < *minDist) { TMat3F invMat; getNodeOffset (&invMat, "dummy muzzle", gunNode); invMat.inverse(); m_mul (Point3F (playerPos.x, playerPos.y, playerPos.z), invMat, &playerPos); float ele = elevation (playerPos.x, playerPos.y, playerPos.z); float rotz = rotation (-playerPos.x, -playerPos.y); if (!inDeadZone (rotz, ele)) { SimContainerQuery collisionQuery; collisionQuery.id = getId(); collisionQuery.type = -1; collisionQuery.mask = SimTerrainObjectType | SimInteriorObjectType; collisionQuery.detail = SimContainerQuery::DefaultDetail; collisionQuery.box.fMin = getBoxCenter(); collisionQuery.box.fMax = player->getLeadCenter(); SimCollisionInfo collisionInfo; SimContainer* root = findObject(manager,SimRootContainerId,root); root->findLOS(collisionQuery, &collisionInfo); if (!collisionInfo.object || collisionInfo.object == player) { *minDist = dist; return true; } } } } return false; }
void CvPlayerAI::AI_launch(VictoryTypes eVictory) { if(GET_TEAM(getTeam()).isHuman()) { return; } if(!GET_TEAM(getTeam()).canLaunch(eVictory)) { return; } launch(eVictory); }
void CompanyBuilder::disbandNode(string team_name , string supervisor) { if (supervisor == "None") { printErrorMessage("disband", team_name); return;} Node* team = getNode(team_name); Group* teamGrp = getTeam(team_name); Group* super = getTeam(supervisor); super->RemoveChild(team); //remove team's pointer from super's vector for (int i=0; i < teamGrp->get_children_size(); i++) { super->AddChild(teamGrp->get_child(i)); } teamGrp->ClearNodeVec(); //prevent team from deleting its children when destructor called delete teamGrp; print(); }
bool Player::operator==(const Player& other) const { return true && _isNameSet(mgen::SHALLOW) == other._isNameSet(mgen::SHALLOW) && _isTeamSet(mgen::SHALLOW) == other._isTeamSet(mgen::SHALLOW) && getName() == other.getName() && getTeam() == other.getTeam(); }
/***** Function Re-definitions *****/ void ServantBerserkerClub::turnUpdate() { if (damageFreeTurn) { increases -= 2; } damageFreeTurn = true; if (increases < 0) increases = 0; else if (increases > 0) { int totalStrIncrease = increases * strIncrement; int totalSklIncrease = increases * sklIncrement; vector<Stat> tS; tS.push_back(STR); tS.push_back(SKL); vector<int> tA; tA.push_back(totalStrIncrease); tA.push_back(totalSklIncrease); Debuff* br = new Debuff("Barbarian's Rage", "Taking damage fuels your rage, greatly increasing your strength.", getTeam(), tS, tA, 1); addDebuff(br); } }
void CvSelectionGroupAI::AI_seperateAI(UnitAITypes eUnitAI) { CLLNode<IDInfo>* pEntityNode; CvUnit* pLoopUnit; pEntityNode = headUnitNode(); while (pEntityNode != NULL) { pLoopUnit = ::getUnit(pEntityNode->m_data); pEntityNode = nextUnitNode(pEntityNode); if (pLoopUnit->AI_getUnitAIType() == eUnitAI) { pLoopUnit->joinGroup(NULL); // TAC - AI Assault Sea - koma13, jdog5000(BBAI) // Was potential crash in use of plot() if group emptied //if (plot()->getTeam() == getTeam()) if (pLoopUnit->plot()->getTeam() == getTeam()) // TAC - AI Assault Sea - koma13, jdog5000(BBAI) { pLoopUnit->getGroup()->pushMission(MISSION_SKIP); } } } }
std::string BattleSquad::getFactionId() { int team = getTeam(); std::string factionid; DataLibrary::getSingleton().getData(str(boost::format("GameData/BattleData/Team/Team%1%/FactionId")%team),factionid); return factionid; }
// uses the same scale as CvPlayerAI::AI_getOurPlotStrength int CvSelectionGroupAI::AI_GroupPower(CvPlot* pPlot, bool bDefensiveBonuses) const { CLLNode<IDInfo>* pUnitNode; CvUnit* pLoopUnit; int iValue; iValue = 0; pUnitNode = headUnitNode(); while (pUnitNode != NULL) { pLoopUnit = ::getUnit(pUnitNode->m_data); pUnitNode = nextUnitNode(pUnitNode); if ((bDefensiveBonuses && pLoopUnit->canDefend()) || pLoopUnit->canAttack()) { if (!(pLoopUnit->isInvisible(getTeam(), false))) { if (pLoopUnit->atPlot(pPlot) || pLoopUnit->canMoveInto(pPlot) || pLoopUnit->canMoveInto(pPlot, /*bAttack*/ true)) { iValue += pLoopUnit->currEffectiveStr((bDefensiveBonuses ? pPlot : NULL), NULL); } } } } return iValue; }
Piece * Splitter::make_copy() { int piece_id = getId(); int team = getTeam(); int value = getValue(); Splitter * T = new Splitter(getName(), piece_id, team, value, o); return (Piece *) T; }
void CompanyBuilder::addNode(string first, string last, string title, string team_name) { Node* emp = constructEmp(first, last, title); Group* team = getTeam(team_name); if (team != nullptr) { team->AddChild(emp); print(); } else {printErrorMessage("find", team_name);} }
void CompanyBuilder::removeNode(string team_name , string supervisor) { if (supervisor == "None") { printErrorMessage("remove", team_name); return;} Node* team = getNode(team_name); Group* super = getTeam(supervisor); super->RemoveChild(team); //remove team's pointer from super's vector delete team; //deletes team and all of its children print(); }
void CompanyBuilder::addNode(string team_name, string supervisor) { Node* grp = constructGrp(team_name); Group* super = getTeam(supervisor); if (super != nullptr) { super->AddChild(grp); print(); }else {printErrorMessage("find", supervisor);} }
CFBTeam* CFBMatch::getDefendingTeam() { auto team = getTeam(FBDefs::SIDE::LEFT); auto player = team->getHilightPlayer(); if (!player || !player->m_isBallController) { return team; } team = getTeam(FBDefs::SIDE::RIGHT); player = team->getHilightPlayer(); if (!player || !player->m_isBallController) { return team; } CC_ASSERT(false); return nullptr; }
void Turret::update(int64 diff) { // No target : try to find a new one if(!isAttacking) { const std::map<uint32, Object*>& objects = map->getObjects(); Unit* nextTarget = 0; unsigned int nextTargetPriority = 10; for(auto& it : objects) { Unit* u = dynamic_cast<Unit*>(it.second); if(!u || u->isDead() || u->getTeam() == getTeam() || distanceWith(u) > TURRET_RANGE) { continue; } // Note: this method means that if there are two champions within turret range, // The player to have been added to the game first will always be targeted before the others if (!targetUnit) { auto priority = classifyTarget(u); if (priority < nextTargetPriority) { nextTarget = u; nextTargetPriority = priority; } } else { Champion* targetIsChampion = dynamic_cast<Champion*>(targetUnit); // Is the current target a champion? If it is, don't do anything if (!targetIsChampion) { // Find the next champion in range targeting an enemy champion who is also in range Champion* enemyChamp = dynamic_cast<Champion*>(u); if (enemyChamp&& enemyChamp->getTargetUnit() != 0) { Champion* enemyChampTarget = dynamic_cast<Champion*>(enemyChamp->getTargetUnit()); if (enemyChampTarget && // Enemy Champion is targeting an ally enemyChamp->distanceWith(enemyChampTarget) <= enemyChamp->getStats().getRange() && // Enemy within range of ally distanceWith(enemyChampTarget) <= TURRET_RANGE) { // Enemy within range of this turret nextTarget = enemyChamp; // No priority required break; } } } } } if (nextTarget) { targetUnit = nextTarget; map->getGame()->notifySetTarget(this, nextTarget); } } // Lose focus of the unit target if the target is out of range if(targetUnit && distanceWith(targetUnit) > TURRET_RANGE) { setTargetUnit(0); map->getGame()->notifySetTarget(this, 0); } Unit::update(diff); }
string LineItem::toLevelCode() const { string out = string(appendId(getClassName())) + " " + itos(getTeam()) + " " + itos(getWidth()); if(mGlobal) out += " Global"; out += " " + geomToLevelCode(); return out; }
bool CvPlayerAI::AI_captureUnit(UnitTypes, CvPlot* pPlot) { CvCity* pNearestCity; CvAssert(!isHuman()); // Barbs always capture if (isBarbarian()) return true; // we own it if (pPlot->getTeam() == getTeam()) return true; // no man's land - may as well if (pPlot->getTeam() == NO_TEAM) return true; // friendly, sure (okay, this is pretty much just means open borders) if (pPlot->IsFriendlyTerritory(GetID())) return true; // not friendly, but "near" us pNearestCity = GC.getMap().findCity(pPlot->getX(), pPlot->getY(), NO_PLAYER, getTeam()); if (pNearestCity != NULL) { if (plotDistance(pPlot->getX(), pPlot->getY(), pNearestCity->getX(), pNearestCity->getY()) <= 7) return true; } // very near someone we aren't friends with (and far from our nearest city) pNearestCity = GC.getMap().findCity(pPlot->getX(), pPlot->getY()); if (pNearestCity != NULL) { if (plotDistance(pPlot->getX(), pPlot->getY(), pNearestCity->getX(), pNearestCity->getY()) <= 4) return false; } // I'd rather we grab it and run than destroy it return true; }
void Player::collisionTickCallback(Ogre::Vector3 &hitPoint, Ogre::Real damage, unsigned int damageSection, int crashType, Player *causedByPlayer) { #else void Player::collisionTickCallback(Ogre::Vector3 hitPoint, Ogre::Real &damage, int& damageSection, int &crashType, Player *&causedByPlayer) { #endif bool isFront = ((damageSection == 0) || (damageSection == 1)); TeamID tid = (GameCore::mGameplay->getGameMode() == FFA_MODE) ? NO_TEAM : getTeam(); float shrapnelPlaneOffset = (getCarType() == CAR_SMALL) ? -0.75f : ((getCarType() == CAR_BANGER) ? -0.85f : -1.25f); float shrapnelCount = damage / 10.0f; float shrapnelMaxSpeed = damage / 20.0f; if(damage > 40.f) getCar()->removeCarPart(damageSection); switch(crashType) { case 1: #ifdef PARTICLE_EFFECT_SPARKS GameCore::mClientGraphics->generateSparks(hitPoint, Ogre::Vector3(1, 0.6f, 1)); #endif break; case 2: #ifdef PARTICLE_EFFECT_SHRAPNEL GameCore::mClientGraphics->generateShrapnel(hitPoint, tid, shrapnelCount, shrapnelMaxSpeed, shrapnelPlaneOffset); #endif { // 300 is a little louder than 400 :P (not perfect yet as it will need tuning with the final fps) float intensity = damage / 350.f; intensity = intensity < 0 ? 0 : ( intensity > 1 ? 1 : intensity ); if (causedByPlayer && causedByPlayer->getCar()) causedByPlayer->getCar()->triggerCrashSoundAt(hitPoint, intensity); } break; case 3: GameCore::mClientGraphics->mMeshDeformer->collisonDeform(this->getCar()->mBodyNode, hitPoint, damage * 0.04, isFront); #ifdef PARTICLE_EFFECT_SHRAPNEL GameCore::mClientGraphics->generateShrapnel(hitPoint, tid, shrapnelCount, shrapnelMaxSpeed, shrapnelPlaneOffset); #endif { // 300 is a little louder than 400 :P (not perfect yet as it will need tuning with the final fps) float intensity = damage / 230.f; intensity = intensity < 0 ? 0 : ( intensity > 1 ? 1 : intensity ); if (causedByPlayer && causedByPlayer->getCar()) causedByPlayer->getCar()->triggerCrashSoundAt(hitPoint, intensity); } break; default: // error break; } }
const TeamState * CGameInfoCallback::getPlayerTeam( PlayerColor color ) const { auto player = gs->players.find(color); if (player != gs->players.end()) { return getTeam (player->second.team); } else { return nullptr; } }
bool CvPlayerAI::AI_captureUnit(UnitTypes, CvPlot* pPlot) { CvCity* pNearestCity; CvAssert(!isHuman()); // Barbs always capture if (isBarbarian()) return true; if (pPlot->getTeam() == getTeam()) return true; pNearestCity = GC.getMap().findCity(pPlot->getX(), pPlot->getY(), NO_PLAYER, getTeam()); if (pNearestCity != NULL) { if (plotDistance(pPlot->getX(), pPlot->getY(), pNearestCity->getX(), pNearestCity->getY()) <= 4) return true; } return false; }
void MultiPartEntity::addPart(Part& part, float x, float y) { part.setPosition(x, y); part.setParent(this); part.setTeam(getTeam()); m_parts.push_back(part); // The texture rect acts as a bounding box float right = x + part.getWidth(); float bottom = y + part.getHeight(); float width = std::max(right, getWidth()); float height = std::max(bottom, getHeight()); setTextureRect(sf::IntRect(0, 0, width, height)); }
int BattleSquad::getFaction() { int team = getTeam(); std::string relation; bool re = DataLibrary::getSingleton().getData(str(boost::format("GameData/BattleData/Team/Team%1%/Relation")%team),relation); if(re) { if(relation == "enemy1") return 1; else if(relation == "enemy2") return 2; else if(relation == "enemy3") return 3; } return 0; }
void PlayerTank::fire() { // 向pool关送命令 PlayerBullet *bullet = new PlayerBullet(); bullet->setRotation(this->rotation()); bullet->setPos(mapToScene(0, 0 + boundingRect().height() ) ); bullet->setTeam(getTeam()); QObject::connect(bullet, SIGNAL(signal_bullet_kill_one()), this, SLOT(kill_one())); this->scene()->addItem(bullet); }
CvUnit* CvSelectionGroupAI::AI_ejectBestDefender(CvPlot* pDefendPlot) { CLLNode<IDInfo>* pEntityNode; CvUnit* pLoopUnit; pEntityNode = headUnitNode(); CvUnit* pBestUnit = NULL; int iBestUnitValue = 0; while (pEntityNode != NULL) { pLoopUnit = ::getUnit(pEntityNode->m_data); pEntityNode = nextUnitNode(pEntityNode); //if (!pLoopUnit->noDefensiveBonus()) // commented out by K-Mod. The noDefBonus thing is already taken into account. { int iValue = pLoopUnit->currEffectiveStr(pDefendPlot, NULL) * 100; if (pDefendPlot->isCity(true, getTeam())) { iValue *= 100 + pLoopUnit->cityDefenseModifier(); iValue /= 100; } iValue *= 100; iValue /= (100 + pLoopUnit->cityAttackModifier() + pLoopUnit->getExtraCityAttackPercent()); iValue /= 2 + pLoopUnit->getLevel(); if (iValue > iBestUnitValue) { iBestUnitValue = iValue; pBestUnit = pLoopUnit; } } } if (NULL != pBestUnit && getNumUnits() > 1) { pBestUnit->joinGroup(NULL); } return pBestUnit; }
void CvPlayerAI::AI_updateFoundValues(bool bStartingLoc) { int iGoodEnoughToBeWorthOurTime = GC.getAI_STRATEGY_MINIMUM_SETTLE_FERTILITY(); int iLoop; const int iNumPlots = GC.getMap().numPlots(); for(CvArea* pLoopArea = GC.getMap().firstArea(&iLoop); pLoopArea != NULL; pLoopArea = GC.getMap().nextArea(&iLoop)) { pLoopArea->setTotalFoundValue(0); } const PlayerTypes eID = GetID(); if(bStartingLoc) { for(int iI = 0; iI < iNumPlots; iI++) { GC.getMap().plotByIndexUnchecked(iI)->setFoundValue(eID, -1); } } else { const TeamTypes eTeam = getTeam(); GC.getGame().GetSettlerSiteEvaluator()->ComputeFlavorMultipliers(this); for (int iI = 0; iI < iNumPlots; iI++) { CvPlot* pLoopPlot = GC.getMap().plotByIndexUnchecked(iI); if (pLoopPlot->isRevealed(eTeam)) { const int iValue = GC.getGame().GetSettlerSiteEvaluator()->PlotFoundValue(pLoopPlot, this, NO_YIELD, false); pLoopPlot->setFoundValue(eID, iValue); if (iValue >= iGoodEnoughToBeWorthOurTime) { CvArea* pLoopArea = GC.getMap().getArea(pLoopPlot->getArea()); if(pLoopArea && !pLoopArea->isWater()) { pLoopArea->setTotalFoundValue(pLoopArea->getTotalFoundValue() + iValue); } } } else { pLoopPlot->setFoundValue(eID, -1); } } } }
void CvPlayerAI::AI_chooseFreeTech() { TechTypes eBestTech = NO_TECH; clearResearchQueue(); // TODO: script override if(eBestTech == NO_TECH) { eBestTech = GetPlayerTechs()->GetTechAI()->ChooseNextTech(/*bFreeTech*/ true); } if(eBestTech != NO_TECH) { GET_TEAM(getTeam()).setHasTech(eBestTech, true, GetID(), true, true); } }
void CvPlayerAI::AI_chooseResearch() { AI_PERF("AI-perf.csv", "AI_chooseResearch"); TechTypes eBestTech = NO_TECH; int iI; clearResearchQueue(); if(GetPlayerTechs()->GetCurrentResearch() == NO_TECH) { for(iI = 0; iI < MAX_PLAYERS; iI++) { if(GET_PLAYER((PlayerTypes)iI).isAlive()) { if((iI != GetID()) && (GET_PLAYER((PlayerTypes)iI).getTeam() == getTeam())) { if(GET_PLAYER((PlayerTypes)iI).GetPlayerTechs()->GetCurrentResearch() != NO_TECH) { if(GetPlayerTechs()->CanResearch(GET_PLAYER((PlayerTypes)iI).GetPlayerTechs()->GetCurrentResearch())) { pushResearch(GET_PLAYER((PlayerTypes)iI).GetPlayerTechs()->GetCurrentResearch()); } } } } } } if(GetPlayerTechs()->GetCurrentResearch() == NO_TECH) { //todo: script override if(eBestTech == NO_TECH) { eBestTech = GetPlayerTechs()->GetTechAI()->ChooseNextTech(); } if(eBestTech != NO_TECH) { pushResearch(eBestTech); } } }
// Is pEdict an enemy? return true if enemy / false if not // if checkWeapons is true, check if current weapon can attack enemy // return false if not bool CHLDMBot :: isEnemy ( edict_t *pEdict,bool bCheckWeapons ) { extern ConVar rcbot_notarget; static int entity_index; entity_index = ENTINDEX(pEdict); // if no target on - listen sever player is a non target if ( rcbot_notarget.GetBool() && (entity_index == 1) ) return false; // not myself if ( pEdict == m_pEdict ) return false; // not a player - false if ( !entity_index || (entity_index > CBotGlobals::maxClients()) ) { if ( !m_pCarryingObject && pEdict->GetUnknown() && (pEdict == m_NearestBreakable) && (CClassInterface::getPlayerHealth(pEdict)>0) ) { if ( distanceFrom(CBotGlobals::entityOrigin(pEdict)) < rcbot_jump_obst_dist.GetFloat() ) { if ( BotFunc_BreakableIsEnemy(m_NearestBreakable,m_pEdict) || ((CBotGlobals::entityOrigin(pEdict) - m_vMoveTo).Length()+48) < (getOrigin() - m_vMoveTo).Length() ) return true; } } return false; } // not alive -- false if ( !CBotGlobals::entityIsAlive(pEdict) ) return false; // team game? if ( CBotGlobals::getTeamplayOn() ) { // same team ? false if ( CBotGlobals::getTeam(pEdict) == getTeam() ) return false; } return true; }
void CvSelectionGroupAI::AI_separate() { CLLNode<IDInfo>* pEntityNode; CvUnit* pLoopUnit; pEntityNode = headUnitNode(); while (pEntityNode != NULL) { pLoopUnit = ::getUnit(pEntityNode->m_data); pEntityNode = nextUnitNode(pEntityNode); pLoopUnit->joinGroup(NULL); if (pLoopUnit->plot()->getTeam() == getTeam()) { pLoopUnit->getGroup()->pushMission(MISSION_SKIP); } } }
void BallSprite::InitSprite() { auto body = PhysicsBody::createCircle(this->getContentSize().width / 2, PhysicsMaterial(1, 1, 0)); if (body != nullptr) { body->setDynamic(true); body->setRotationEnable(true); if (getTeam() == 1) { body->setCollisionBitmask(HERO_BALL_COLLISION_BITMASK); } else { body->setCollisionBitmask(MONSTER_BALL_COLLISION_BITMASK); } body->setContactTestBitmask(true); this->setPhysicsBody(body); } this->setScale(_ballSize); }