//----------------------------------------------------------------------------- void ArenaAI::checkIfStuck(const float dt) { if (m_is_stuck) return; if (m_kart->getKartAnimation() || isWaiting()) { m_on_node.clear(); m_time_since_driving = 0.0f; } m_on_node.insert(getCurrentNode()); m_time_since_driving += dt; if ((m_time_since_driving >= (m_cur_difficulty == RaceManager::DIFFICULTY_EASY ? 2.0f : 1.5f) && m_on_node.size() < 2 && !m_is_uturn && fabsf(m_kart->getSpeed()) < 3.0f) || isStuck() == true) { // Check whether a kart stay on the same node for a period of time // Or crashed 3 times m_on_node.clear(); m_time_since_driving = 0.0f; AIBaseController::reset(); m_is_stuck = true; } else if (m_time_since_driving >= (m_cur_difficulty == RaceManager::DIFFICULTY_EASY ? 2.0f : 1.5f)) { m_on_node.clear(); // Reset for any correct movement m_time_since_driving = 0.0f; } } // checkIfStuck
/** Determine whether AI is stuck, by checking if it stays on the same node for * a long period of time (see \ref m_on_node), or \ref isStuck() is true. * \param dt Time step size. * \return True if AI is stuck */ void ArenaAI::checkIfStuck(const float dt) { if (m_is_stuck) return; if (m_kart->getKartAnimation() || isWaiting()) { m_on_node.clear(); m_time_since_driving = 0.0f; } m_on_node.insert(getCurrentNode()); m_time_since_driving += dt; if ((m_time_since_driving >= (m_cur_difficulty == RaceManager::DIFFICULTY_EASY ? 2.0f : 1.5f) && m_on_node.size() < 2 && !m_is_uturn && fabsf(m_kart->getSpeed()) < 3.0f) || isStuck() == true) { // AI is stuck, reset now and try to get unstuck at next frame m_on_node.clear(); m_time_since_driving = 0.0f; AIBaseController::reset(); m_is_stuck = true; } else if (m_time_since_driving >= (m_cur_difficulty == RaceManager::DIFFICULTY_EASY ? 2.0f : 1.5f)) { m_on_node.clear(); // Reset for any correct movement m_time_since_driving = 0.0f; } } // checkIfStuck
void RemoteRulesManager::updatePlayerPos(const btVector3& position) { if(isWaiting()) return; sendMessage(MessagePtr(new UpdatePos(position)), ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT); }
void HardcoreProtester::doSomething(){ if(!isAlive()) return; if(isWaiting()) return; if(isActiveP() && !getWorld()->isNearFrackMan(this, 4)){ if(getWorld()->curHeatVal(getX(), getY()) < 16 + getWorld()->getLevel()*2){ Direction dir = getWorld()->determineFirstMoveToFrackMan(this, getX(), getY()); if(dir != none) setDirection(dir); move(getDirection()); return; } } Protester::doSomething(); }
bool CNetworkDetectionBase::SetNetworkPollInterval(int iInterval) { if (iInterval >= NETWORK_DETECT_MINIMUM_POLL_INTERVAL) { m_iNetworkPollInterval = iInterval; if (isWaiting()) stopWait(); return true; } else { LOG(INFO) + "Network Poll Interval property ignored, value is too small, it must be more than " + NETWORK_DETECT_MINIMUM_POLL_INTERVAL; return false; } }
bool osLoopClass::scheduleLoop( uint8_t my_id, uint8_t time_10mS ) { if (my_id >= maxNum_id) return false; if( !isWaiting(my_id) ) { if( qHead_id == eOsNoAction ) { qHead_id = my_id; qTail_id = my_id; } else { loopQue[qTail_id].qNext_id = my_id; qTail_id = my_id; } return true; } else { return false; } }//scheduleLoop
/** This is the main entry point for the AI. * It is called once per frame for each AI and determines the behaviour of * the AI, e.g. steering, accelerating/braking, firing. */ void ArenaAI::update(float dt) { // This is used to enable firing an item backwards. m_controls->m_look_back = false; m_controls->m_nitro = false; // Don't do anything if there is currently a kart animations shown. if (m_kart->getKartAnimation()) return; if (isWaiting()) { AIBaseController::update(dt); return; } checkIfStuck(dt); if (handleArenaUnstuck(dt)) return; findClosestKart(true); findTarget(); handleArenaItems(dt); handleArenaBanana(); if (m_kart->getSpeed() > 15.0f && m_cur_kart_pos_data.angle < 0.2f) { // Only use nitro when target is straight m_controls->m_nitro = true; } if (m_is_uturn) { handleArenaUTurn(dt); } else { handleArenaAcceleration(dt); handleArenaSteering(dt); handleArenaBraking(); } AIBaseController::update(dt); } // update
void Opa::kitRead(OpaKit * kitData) { // Check for port if (port < 0 || !enabled) return; #ifdef DEBUG fprintf(stdout, "Kit read\n"); fflush(stdout); #endif // Store the pointer if (isWaiting()) return; kitReturn = kitData; // Prepare the message char buffer[3]; buffer[0] = OPA_KITREAD; buffer[1] = sizeof(OpaKit); buffer[2] = 0; // Send the message comWrite(port, buffer, 3); }
void Opa::globalsRead(OpaGlobals * globalsData) { // Check for port if (port < 0 || !enabled) return; #ifdef DEBUG fprintf(stdout, "Global read\n"); fflush(stdout); #endif // Store the pointer if (isWaiting()) return; globalsReturn = globalsData; // Prepare the message char buffer[3]; buffer[0] = OPA_GLOBALSREAD; buffer[1] = sizeof(OpaGlobals); buffer[2] = 0; // Send the message comWrite(port, buffer, 3); }
void Opa::globalsParamRead(int param, int * value) { // Check for port if (port < 0 || !enabled) return; #ifdef DEBUG fprintf(stdout, "Globals: reading param %i\n", param); fflush(stdout); #endif // Store the pointer if (isWaiting()) return; programParamReturn = value; programParamReturnIndex = param; // Prepare the message char buffer[3]; buffer[0] = OPA_GLOBALSPARAMREAD; buffer[1] = param; buffer[2] = 0; // Send the message comWrite(port, buffer, 3); }
void Opa::internalRead(int slot, OpaProgram * programData) { // Check for port if (port < 0 || !enabled) return; #ifdef DEBUG fprintf(stdout, "Internal read %i\n", slot); fflush(stdout); #endif // Store the pointer if (isWaiting()) return; programReturn = programData; programReturnIndex = slot; // Prepare the message char buffer[4]; buffer[0] = OPA_INTERNALREAD; buffer[1] = slot; buffer[2] = sizeof(OpaProgram); buffer[3] = 0; // Send the message comWrite(port, buffer, 4); }
void Opa::kitParamRead(int sample, int param, int * value) { // Check for port if (port < 0 || !enabled) return; #ifdef DEBUG fprintf(stdout, "Kit sample %i: reading param %i\n", sample, param); fflush(stdout); #endif // Store the pointer if (isWaiting()) return; kitParamReturn = value; kitParamReturnIndex = param; // Prepare the message char buffer[4]; buffer[0] = OPA_KITPARAMREAD; buffer[1] = sample; buffer[2] = param; buffer[3] = 0; // Send the message comWrite(port, buffer, 4); }
void Opa::update() { if (port < 0) return; int size = OPA_RXBUFFER_LEN - rxLen; rxLen += comRead(port, &rxBuffer[rxLen], size); // Check for reception if (programParamReturn && rxLen >= 4) parseProgramParameter(); if (kitParamReturn && rxLen >= 4) parseKitParameter(); if (programReturn && rxLen >= 4 + sizeof(OpaProgram)) parseProgram(); if (kitReturn && rxLen >= 3 + sizeof(OpaKit)) parseKit(); if (globalsReturn && rxLen >= 3 + sizeof(OpaGlobals)) parseGlobals(); // Expected nothing if (!isWaiting()) rxLen = 0; }
/** This is the main entry point for the AI. * It is called once per frame for each AI and determines the behaviour of * the AI, e.g. steering, accelerating/braking, firing. * \param dt Time step size. */ void ArenaAI::update(float dt) { // This is used to enable firing an item backwards. m_controls->setLookBack(false); m_controls->setNitro(false); // Let the function below to reset it later m_controls->setAccel(0.0f); m_controls->setBrake(false); m_mini_skid = false; // Don't do anything if there is currently a kart animations shown. if (m_kart->getKartAnimation()) { resetAfterStop(); return; } if (!isKartOnRoad() && m_kart->isOnGround()) { m_time_since_off_road += dt; } else if (m_time_since_off_road != 0.0f) { m_time_since_off_road = 0.0f; } // If the kart needs to be rescued, do it now (and nothing else) if (m_time_since_off_road > 5.0f && m_kart->isOnGround()) { m_time_since_off_road = 0.0f; new RescueAnimation(m_kart); AIBaseController::update(dt); return; } if (isWaiting()) { AIBaseController::update(dt); return; } checkIfStuck(dt); if (gettingUnstuck(dt)) return; findTarget(); // After found target, convert it to local coordinate, used for skidding or // u-turn if (!m_is_uturn) { m_target_point_lc = m_kart->getTrans().inverse()(m_target_point); doSkiddingTest(); configSteering(); } else { m_target_point_lc = m_kart->getTrans().inverse()(m_reverse_point); } useItems(dt); if (m_kart->getSpeed() > 15.0f && !m_is_uturn && m_turn_radius > 30.0f && !ignorePathFinding()) { // Only use nitro when turn angle is big (180 - angle) m_controls->setNitro(true); } if (m_is_uturn) { resetAfterStop(); doUTurn(dt); } else { configSpeed(); setSteering(m_steering_angle, dt); } AIBaseController::update(dt); } // update
void RegularProtester::doSomething() { if(!isWaiting()) { Protester::doSomething(); }; }