bool Game::GameState::PlayAtIndex(int idx, int player) { assert(idx >= 0 && idx < boardDesc->nbCase); assert(player >= 0 && player < boardDesc->nbPlayer); GameDiff diff; if (board[idx] != -1) return false; int otherPlayer = 1 - player; int previousNb; PlayerState *stateMe = playerState[player]; PlayerState *stateOther = playerState[otherPlayer]; for (int &algt : boardDesc->alignementFromCase[idx]) { if (stateMe->PlayAlignement(algt)) { diff.aligntPlayed.push_back({ player, algt }); } if (stateOther->LooseAlignement(algt, previousNb)) { diff.aligntLoosed.push_back({ otherPlayer, algt, previousNb }); } } board[idx] = player; columnNbPlayed[idx % boardDesc->columns]++; diff.casePlayed = idx; gameDiff.push_back(diff); return true; }
static int npmodule_listPlayers (lua_State *L) { int tindex = 0; // will push ++tindex lua_newtable(L); for ( int n = 0; n < PlayerInterface::getMaxPlayers(); n++) { PlayerState *p = PlayerInterface::getPlayer(n); if ( ! p->isFree() ) { lua_newtable(L); lua_pushinteger(L, n); lua_setfield(L, -2, "id"); lua_pushstring(L, p->isAllocated() ? "<preconnect>" : p->getName().c_str()); lua_setfield(L, -2, "name"); lua_pushstring(L, PlayerInterface::isLocalPlayer(n) ? "local" : SERVER->getIP(n).c_str()); lua_setfield(L, -2, "ip"); lua_rawseti(L, -2, ++tindex); } } return 1; }
void Inventory::UseItem( int iSlot ) { Attack* pInventory = m_pPlayerState->m_Inventory; //[NUM_INVENTORY_SLOTS] if( pInventory[iSlot].IsBlank() ) return; PlayerNumber pn = m_pPlayerState->m_PlayerNumber; Attack a = pInventory[iSlot]; // remove the item pInventory[iSlot].MakeBlank(); m_vpSoundUseItem[a.level]->Play(false); PlayerNumber pnToAttack = OPPOSITE_PLAYER[pn]; PlayerState *pPlayerStateToAttack = GAMESTATE->m_pPlayerState[pnToAttack]; pPlayerStateToAttack->LaunchAttack( a ); float fPercentHealthToDrain = (a.level+1) / 10.f; ASSERT( fPercentHealthToDrain > 0 ); GAMESTATE->m_fOpponentHealthPercent -= fPercentHealthToDrain; CLAMP( GAMESTATE->m_fOpponentHealthPercent, 0.f, 1.f ); // play announcer sound SCREENMAN->SendMessageToTopScreen( ssprintf("SM_BattleDamageLevel%d",a.level+1) ); }
void ObjectManager::create_ships(PlayerState& player_state) { for (int i = 1; i <= NUM_OF_POSSIBLE_PLAYERS; i++) { if (player_state.energy_max(i)) { std::string name = "Player " + std::to_string(i); int s = player_state.score(i); int e = player_state.energy_max(i); player_state.set_energy(i, e); // reset energy to max ObjIndex player_index = Object::parse_player_index(i); sdlc::Surface& gfx = obj[player_index]; sdlc::Surface& hit_gfx = obj_hit[player_index]; auto w1 = create_main_weapon(i, player_state); auto w2 = create_extra_weapon(i, player_state); KeySet keyset(i); // For now we don't set custom keys auto new_ship = std::make_shared<Ship>(name, e, s, gfx, hit_gfx, w1, w2, keyset); new_ship->set_locked_to_screen(false); new_ship->set_x((float)(213 * i - new_ship->width())); new_ship->set_y(480); new_ship->set_vel(0, -200.0f); queue.push_back(new_ship); } } }
int PlayerHuman::operator()(GameState& game_state, PlayerState& player_state, int minimum_money) { CardMask cards; CardMask_OR(cards, game_state.flop, player_state.cards()); cout << endl; cout << "Player " << player_state.get_number() << " (min/max : " << minimum_money << "/" << player_state.get_money() << ")"; if (StdDeck_numCards(cards) >= 5) { cout << " [ "; int eval = StdDeck_StdRules_EVAL_N(cards, StdDeck_numCards(cards)); HandVal_print(eval); cout << " ]"; } cout << endl; cout << "(-1 to fold, 0 to check, number to raise)" << endl; cout << " > "; int x; cin >> x; cout << endl; return x; }
virtual void enter() { player = PlayerInterface::getPlayer(connect_client->getPlayerIndex()); sync_count = 0; sync_done = 0; sync_end = 0; sync_total = UnitInterface::getTotalUnitCount(); if ( sync_total ) { sync_end = UnitInterface::getUnits().rbegin()->first; } sync_end += 1; ConnectProcessStateMessage state_mesg; state_mesg.setMessageEnum(_connect_state_message_sync_units); connect_client->sendMessage( &state_mesg, sizeof(ConnectProcessStateMessage)); SERVER->addClientToSendList( connect_client ); PlayerState *p = PlayerInterface::getPlayer(connect_client->getPlayerIndex()); PlayerStateSync player_state_update( p->getNetworkPlayerState() ); SERVER->broadcastMessage(&player_state_update, sizeof(PlayerStateSync)); sendunitpercent_timer.reset(); time_out_timer.reset(); }
virtual T process() { ObjectiveInterface::syncObjectives( connect_client ); PowerUpInterface::syncPowerUps( connect_client ); PlayerState * player = PlayerInterface::getPlayer(connect_client->getPlayerIndex()); player->setStateSelectingFlag(); PlayerFlagSync pfs; pfs.player_id = connect_client->player_id; ResourceManager::getFlag(connect_client->player_id)->frameToBuffer(pfs.player_flag, sizeof(pfs.player_flag)); SERVER->broadcastMessage(&pfs, sizeof(pfs)); PlayerStateSync player_state_update (player->getNetworkPlayerState()); SERVER->broadcastMessage( &player_state_update, sizeof(PlayerStateSync)); ConnectProcessStateMessage state_mesg; state_mesg.setMessageEnum(_connect_state_sync_complete); connect_client->sendMessage( &state_mesg, sizeof(ConnectProcessStateMessage)); sendConnectionAlert( connect_client ); if (GameControlRulesDaemon::getGameState() == _game_state_prepare_team) { GameControlCyclePrepareTeam prepare_team_mesg; SERVER->sendMessage(connect_client->player_id, &prepare_team_mesg, sizeof(GameControlCyclePrepareTeam)); } return connect_state_idle; }
void ScoreKeeperRave::LaunchAttack( AttackLevel al ) { PlayerNumber pn = m_pPlayerState->m_PlayerNumber; RString* asAttacks = GAMESTATE->m_pCurCharacters[pn]->m_sAttacks[al]; // [NUM_ATTACKS_PER_LEVEL] RString sAttackToGive; if (GAMESTATE->m_pCurCharacters[pn] != NULL) sAttackToGive = asAttacks[ RandomInt(NUM_ATTACKS_PER_LEVEL) ]; else { // "If you add any noteskins here, you need to make sure they're cached, too." -? // Noteskins probably won't work here anymore. -aj RString DefaultAttacks[8] = { "1.5x", "2.0x", "0.5x", "reverse", "sudden", "boost", "brake", "wave" }; sAttackToGive = DefaultAttacks[ RandomInt(8) ]; } PlayerNumber pnToAttack = OPPOSITE_PLAYER[pn]; PlayerState *pPlayerStateToAttack = GAMESTATE->m_pPlayerState[pnToAttack]; Attack a; a.level = al; a.fSecsRemaining = ATTACK_DURATION_SECONDS; a.sModifiers = sAttackToGive; // remove current attack (if any) pPlayerStateToAttack->RemoveActiveAttacks(); // apply new attack pPlayerStateToAttack->LaunchAttack( a ); // SCREENMAN->SystemMessage( ssprintf( "attacking %d with %s", pnToAttack, sAttackToGive.c_str() ) ); }
virtual T message(const NetMessage* msg) { if ( msg->message_id == _net_message_id_connect_client_settings ) { ConnectClientSettings *client_setting; client_setting = (ConnectClientSettings *) msg; player->setName( client_setting->player_name ); ResourceManager::updateFlagData(player->getID(), client_setting->player_flag, sizeof(client_setting->player_flag) ); player->setStateConnecting(); // ** send server game setting map, units, player, etc. ConnectMesgServerGameSettings* server_game_setup = GameManager::getServerGameSetup(); connect_client->sendMessage( server_game_setup, sizeof(ConnectMesgServerGameSettings)); connect_client->sendRemaining(); delete server_game_setup; return connect_state_wait_for_client_game_setup_ack; } return State<T>::state; }
virtual T message(const NetMessage* msg) { T new_state = connect_state_drop_bad_connecting_client; if ( msg->message_id == _net_message_id_client_connect_request ) { ClientConnectResult connect_result; if ((GameConfig::game_allowmultiip == false) && (SERVER->isAlreadyConnected(connect_client) == true)) { connect_result.result_code = _connect_result_server_already_connected; LOGGER.warning("Client already connected!!!!, die"); } else { PlayerState * player = PlayerInterface::allocateNewPlayer(); if ( player == 0 ) { connect_result.result_code = _connect_result_server_full; } else { connect_result.result_code = _connect_result_success; connect_client->player_id = player->getID(); new_state = connect_state_wait_for_client_settings; } } connect_client->sendMessage( &connect_result, sizeof(ClientConnectResult)); connect_client->sendRemaining(); } return new_state; }
UnitBase * UnitInterface::newUnit( unsigned short unit_type, const iXY &location, unsigned short player_index, UnitID id) { UnitBase* unit = 0; bool color_flag; unsigned char unit_flag; if ( player_index == PlayerInterface::getLocalPlayerIndex() ) { color_flag = true; } else { color_flag = false; } PlayerState* player = PlayerInterface::getPlayer( player_index ); unit_flag = player->getFlag(); if ( unit_type < UnitProfileInterface::getNumUnitTypes() ) { unit = new Vehicle(player, unit_type, id, location); } else { // XXX change for a error window assert("unknown unit_type" == 0); } return unit; }
void PlayerUpdater::operator()(osg::Node* node, osg::NodeVisitor* nv) { PlayerState *playerState = _player->getPlayerState(); osg::Vec3 newPosition = calculateNextPosition(playerState); _player->setPosition(newPosition); _player->setAngles(playerState->getAngleX(), playerState->getAngleY()); traverse(node, nv); }
void ServerConnectDaemon::netPacketClientDisconnect(const NetPacket *packet) { // Note: this invalidates the ConnectMesgNetPanzerClientDisconnect playerID // value, just use the networkID, this way avoid possible fake packet // to kick other player. // In a future protocol version PlayerID should be removed from this packet. PlayerState *player = PlayerInterface::getPlayerByNetworkID(packet->fromID); if (player) startDisconnectionProcess(player->getPlayerID()); }
void CDynamicProgrammingStrategy::calculatePaths() { while (!stateQueue.empty()) { PlayerState currentState = stateQueue.front(); for (int xDeviation = -1; xDeviation <= 1; ++xDeviation) { for (int yDeviation = -1; yDeviation <= 1; ++yDeviation) { PlayerState newState( currentState.GetX() + currentState.GetXVelocity() + xDeviation, currentState.GetY() + currentState.GetYVelocity() + yDeviation, currentState.GetXVelocity() + xDeviation, currentState.GetYVelocity() + yDeviation ); if (newState.GetX() < 0 || newState.GetX() >= map.sizeOnXaxis() || newState.GetY() < 0 || newState.GetY() >= map.sizeOnYaxis() || !map.canPlayerStayOnCell(newState.GetX(), newState.GetY()) || map.hasBarrierOnPath(currentState.GetX(), currentState.GetY(), newState.GetX(), newState.GetY())) { continue; } if (minPath.GetStepCount(newState) == -1 || minPath.GetStepCount(newState) > minPath.GetStepCount(currentState) + 1) { minPath.SetStepCount(newState, minPath.GetStepCount(currentState) + 1); minPath.SetPreviousState(newState, currentState); stateQueue.push(newState); } } } stateQueue.pop(); } }
void ObjectManager::update_player_state(std::shared_ptr<IObject>& object, PlayerState& player_state) { assert(object->type() == ObjType::player); // Get the player number from the name std::string name = object->name(); int player_id = name[name.length() - 1] - (int)'0'; player_state.set_energy(player_id, object->energy()); player_state.set_energy_max(player_id, object->energy_max()); player_state.set_score(player_id, object->score()); //Ship* s = (Ship*)object; std::shared_ptr<Ship> s = std::dynamic_pointer_cast<Ship>(object); if (s->main_weapon_) { player_state.set_main_weapon(player_id, s->main_weapon_->name); player_state.set_main_weapon_level(player_id, s->main_weapon_->level()); } if (s->extra_weapon_) { player_state.set_extra_weapon(player_id, s->extra_weapon_->name); player_state.set_extra_weapon_count(player_id, s->extra_weapon_->count()); } else player_state.set_extra_weapon(player_id, "none"); if (object->energy() == 0) player_state.set_energy_max(player_id, 0); }
GameRules::EGR_result GameRules::pay(int& amt) { PlayerState& plr = fState->get_player(fState->get_current_turn()); PlayerState* onr = NULL; unsigned pay = 0; // check to see if we are dealing with an ownable property if (fState->get_property(fMoveTo).has_owner()) onr = &(fState->get_player(fState->get_property(fMoveTo).get_owner())); // figure out how much the player owes switch (fBase.type(fMoveTo)) { case Game_Base::kITax: // percentage tax pay = plr.get_money() * fBase.price(fMoveTo) / 100; break; case Game_Base::kLTax: // flat tax pay = fBase.price(fMoveTo); break; case Game_Base::kUtil: // utility pay = fRoll * count_mems(*onr, fMoveTo) * 4; break; case Game_Base::kRRoad: // rail road pay = fBase.rent(fMoveTo, count_mems(*onr, fMoveTo) - 1); break; case Game_Base::kProp: // property pay = fBase.rent(fMoveTo, fState->get_property(fMoveTo).get_level()); if (fState->get_property(fMoveTo).get_level() == 0 && owns_group((unsigned)onr->get_id(), fBase.group(fMoveTo))) pay *= 2; break; } // return the amount to be paid amt = pay; // check for insufficient assets if (plr.get_money() < pay) if (!free(plr.get_id(), pay)) // if still insufficient { if (Game_Base::kUtil <= fBase.type(fMoveTo)) onr->add_money(plr.get_money()); // tranfer whatever they have return kConcede; // and send concede signal } // if they have enough, transfer funds to owner plr.sub_money(pay); if (Game_Base::kUtil <= fBase.type(fMoveTo)) onr->add_money(pay); return kDone; }
void BehaviorHoldPlanner::Plan(std::list<ActiveBehavior> & behavior_list) { if (!mSelfState.IsKickable()) return; if (mSelfState.IsGoalie()) return; if(mStrategy.GetSureOppInterCycle() <= 2 && mStrategy.GetSureOppInterCycle() != 0 ){ ActiveBehavior hold(mAgent, BT_Hold); double dDist; Vector posAgent = mSelfState.GetPos(); PlayerState objOpp = mWorldState.GetOpponent(mPositionInfo.GetClosestOpponentToBall()); Vector posOpp = objOpp.GetPos(); dDist = (posOpp - posAgent).Mod(); AngleDeg angOpp = objOpp.GetBodyDir(); AngleDeg ang = 0.0; if(dDist < 5 ) { ang = ( posAgent - posOpp ).Dir(); int iSign = (GetNormalizeAngleDeg( angOpp - ang )) >0 ? -1:1; ang += iSign*45 - mSelfState.GetBodyDir(); ang = GetNormalizeAngleDeg( ang ); } if( mBallState.GetPos().Dist(posAgent + Polar2Vector(0.7,ang))< 0.3 ) { Vector posBallPred = mBallState.GetPredictedPos(1); Vector posPred = mSelfState.GetPredictedPos(1); if( posPred.Dist( posBallPred )< 0.85 * mSelfState.GetKickableArea() ) { hold.mDetailType = BDT_Hold_Turn; hold.mEvaluation = 1.0 + FLOAT_EPS; hold.mAngle = (Vector(ServerParam::instance().PITCH_LENGTH / 2.0, 0.0) - mSelfState.GetPos()).Dir(); mActiveBehaviorList.push_back(hold); } } else { hold.mDetailType = BDT_Hold_Kick; hold.mAngle = ang; hold.mEvaluation = 1.0 + FLOAT_EPS; mActiveBehaviorList.push_back(hold); } if (!mActiveBehaviorList.empty()) { mActiveBehaviorList.sort(std::greater<ActiveBehavior>()); behavior_list.push_back(mActiveBehaviorList.front()); } } }
std::unique_ptr<Weapon> ObjectManager::create_extra_weapon(int player, PlayerState player_state) { std::unique_ptr<Weapon> w; if (player_state.extra_weapon(player) == "Rocket Weapon") { sdlc::Sound& sfx = snd[ObjSnd::rocket]; Owner own = Object::parse_owner(player); w = std::unique_ptr<Weapon>(new WeaponRocket(sfx, own)); w->set_count(player_state.extra_weapon_count(player)); } return w; }
Uint16 BotManager::addBot() { PlayerState *p = PlayerInterface::allocateNewPlayer(); if ( p ) { Bot * b = new BotPlayer(p->getID()); bot_list.push_back(b); ResourceManagerSyncFlagMessage flagmsg; ResourceManager::getFlagData("bot.bmp",(Uint8*)&flagmsg.flagdata); flagmsg.setFlagID(ResourceManager::registerFlagFromData((Uint8*)&flagmsg.flagdata)); p->setName("Bot"); p->setFlag(flagmsg.getFlagID()); p->setStatus(_player_state_active); NetworkServer::broadcastMessage(&flagmsg, sizeof(flagmsg)); PlayerStateSync updatemsg(p->getNetworkPlayerState()); NetworkServer::broadcastMessage( &updatemsg, sizeof(updatemsg)); SystemConnectAlert connect_alert; connect_alert.set( p->getID(), _connect_alert_mesg_connect ); NetworkServer::broadcastMessage( &connect_alert, sizeof(SystemConnectAlert)); NetworkClient::sendMessage(&connect_alert, sizeof(SystemConnectAlert)); return p->getID(); } return 0xffff; }
void tPlayerStateBox::onPaint(Surface &dst, const DataItem& data) { char statBuf[256]; int StartX = 1; PlayerState *state = (PlayerState*)(data.Data); if (DrawFlags) { Surface * flag = 0; flag = ResourceManager::getFlag(state->getFlag()); flag->blt(dst, 0, 0); StartX = flag->getWidth()+4; } snprintf(statBuf, sizeof(statBuf), "%-20s", state->getName().c_str()); dst.bltString(StartX , 4, statBuf, ctTexteNormal); }
/** * 通过传入kick的参数,计算kick后球的位置和速度 * Calculate ball position and velocity after a kick action. * \param kick_power. * \param kick_angle. * \param player_state state of the player who is performing kick. * \param ball_state ball state before the kick action is performed. * \param ball_pos will be set to ball position after kick. * \param ball_vel will be set to ball velocity after kick. * \param is_self if the action is performed by the agent this process represents. */ void ActionEffector::ComputeInfoAfterKick(const double kick_power, const double kick_angle, const PlayerState &player_state, const BallState &ball_state, Vector &ball_pos, Vector &ball_vel, bool is_self) { double power = GetNormalizeKickPower(kick_power); double dir = GetNormalizeMoment(kick_angle); Vector ball_2_player = (ball_state.GetPos() - player_state.GetPos()).Rotate(-player_state.GetBodyDir()); double eff_power = power * (is_self ? player_state.GetKickRate() : GetKickRate(ball_2_player, player_state.GetPlayerType())); Vector accel = Polar2Vector(eff_power, player_state.GetBodyDir() + dir); ball_vel = ball_state.GetVel() + accel; ball_pos = ball_state.GetPos() + ball_vel; ball_vel *= ServerParam::instance().ballDecay(); }
void Team::addPlayer(PlayerID new_player) { for ( PlayerID player_id = 0; player_id < PlayerInterface::getMaxPlayers(); ++player_id ) { PlayerState* state = PlayerInterface::getPlayer(player_id); if (state->isActive()) { if (state->getTeamID() == teamID && (player_id != new_player)) { PlayerInterface::allyplayers( player_id, new_player); } } } PlayerInterface::getPlayer(new_player)->setTeamID(teamID); }
std::unique_ptr<Weapon> ObjectManager::create_main_weapon(int player, PlayerState player_state) { std::unique_ptr<Weapon> w; if (player_state.main_weapon(player) == "Blaster Weapon") { sdlc::Sound& sfx = snd[ObjSnd::blaster]; Owner own = Object::parse_owner(player); w = std::unique_ptr<Weapon>(new WeaponBlaster(sfx, own)); } for (int j = 1; j < player_state.main_weapon_level(player); ++j) w->upgrade(); return w; }
/** * player 跑到 target 的所需的最小周期数 * This function returns the minimum cycles for a player to go to a target position. * @param player the player to caculate. * @param target the target position to go to. * @param can_inverse true means consider running backwards. * @param buffer * @return an integer to show the minimum cycles caculated. */ int Dasher::CycleNeedToPoint(const PlayerState & player, Vector target, bool can_inverse, double *buf) { const Vector & pos = player.GetPos(); const Vector & vel = player.GetVel(); const double dir = (target - pos).Dir(); double facing; if (player.IsBodyDirValid()) { facing = player.GetBodyDir(); } else if (vel.Mod() > 0.26){ facing = vel.Dir(); } else { facing = dir; //认为不用转身 } double diffang = fabs(GetNormalizeAngleDeg(dir - facing)); if (diffang < 90.0){ can_inverse = false; //没有必要倒着跑 } if (can_inverse){ if (buf != 0) { double tmp; int cycle1 = CycleNeedToPointWithCertainPosture(player, target, true, buf); int cycle2 = CycleNeedToPointWithCertainPosture(player, target, false, &tmp); if (cycle2 <= cycle1) { *buf = tmp; } return Min(cycle1, cycle2); } else { int cycle1 = CycleNeedToPointWithCertainPosture(player, target, true); int cycle2 = CycleNeedToPointWithCertainPosture(player, target, false); return Min(cycle1, cycle2); } } else { return CycleNeedToPointWithCertainPosture(player, target, false, buf); } }
// drawPlayerStats //--------------------------------------------------------------------------- // Purpose: //--------------------------------------------------------------------------- void RankView::drawPlayerStats(Surface &dest) { char statBuf[256]; ObjectiveInterface::updatePlayerObjectiveCounts(); std::vector<const PlayerState*> states; for(size_t i = 0; i < PlayerInterface::getMaxPlayers(); ++i) { PlayerState* state = PlayerInterface::getPlayerState(i); if(state->getStatus() != _player_state_active) continue; states.push_back(state); } switch(gameconfig->gametype) { case _gametype_objective: std::sort(states.begin(), states.end(), StatesSortByObjectives()); break; case _gametype_timelimit: case _gametype_fraglimit: std::sort(states.begin(), states.end(), StatesSortByFrags()); break; } unsigned int CHAR_YPIX = Surface::getFontHeight(); unsigned int entryHeight = std::max(CHAR_YPIX, UNIT_FLAGS_SURFACE.getHeight()) + 2; iXY offset(2, 40); iXY flagOffset(162, 40 + (int(CHAR_YPIX - UNIT_FLAGS_SURFACE.getHeight()))/2); for(std::vector<const PlayerState*>::iterator i = states.begin(); i != states.end(); ++i) { const PlayerState* state = *i; snprintf(statBuf, sizeof(statBuf), "%-20s%10i%7i%6i%10i", state->getName().substr(0,20).c_str(), state->getKills(), state->getLosses(), state->getTotal(), state->getObjectivesHeld()); dest.bltString(offset.x, offset.y, statBuf, state->getColor()); UNIT_FLAGS_SURFACE.setFrame(state->getFlag()); UNIT_FLAGS_SURFACE.blt( dest, flagOffset.x, flagOffset.y ); offset.y += entryHeight; flagOffset.y += entryHeight; } } // end RankView::drawPlayerStats
/** * 主要是为了调整power用,为了避免power过大而跑过可 * 目标点。原则视为了更高层协调,power只可能减小不可 * 能增大。为了不必要到dash,power也可可能为零。也就 * dash不执行 * power 的正负由外面给定 * This funcition is mainly used to adjust ( usually decrease ) the dash power * to avoid run over the target position by using a big power. The final power * could be 0 to avoid an unnecessary dash. * The sign of power is given outside the function. * @param player the player to caculate. * @param target the target position to go to. * @param buffer * @param power orignal power given. * @return power adjusted. */ double Dasher::AdjustPowerForDash(const PlayerState & player, Vector target, double buffer, double power) { const double & speedmax = player.GetEffectiveSpeedMax(); const double & effort = player.GetEffort(); const double & accrate = player.GetDashPowerRate(); const Vector & pos = player.GetPos(); const Vector & vel = player.GetVel(); const double & facing = player.GetBodyDir(); if (pos.Dist(target) > speedmax + buffer){ //怎么跑的都不会跑过 return power; } if((pos + vel).Dist(target) < buffer) { //不跑也能到到达,就不用跑了 return 0.0; } Line dash_line(Ray(pos, player.GetBodyDir())); Vector projective_target = dash_line.GetProjectPoint(target); Vector acc = projective_target - pos - vel; double dash_power = acc.Mod() / (effort * accrate); if (GetAngleDegDiffer(acc.Dir(), facing) > 90.0){ dash_power = -dash_power; } if (power > 0){ return MinMax(ServerParam::instance().minDashPower(), dash_power, power); } else { return MinMax(power, dash_power, ServerParam::instance().maxDashPower()); } }
virtual T process() { if ( time_out_timer.count() ) { player->setStateFree(); return connect_state_drop_bad_connecting_client; } return State<T>::state; }
short Team::getTeamObjective() const { short TeamObjective = 0; PlayerID player_id; for ( player_id = 0; player_id < PlayerInterface::getMaxPlayers(); ++player_id ) { PlayerState* state = PlayerInterface::getPlayer(player_id); if (state->isActive()) { if (state->getTeamID() == teamID) { TeamObjective += state->getObjectivesHeld(); } } } return TeamObjective; }
virtual T process() { if ( time_out_timer.count() ) { player->setStateFree(); return connect_state_idle; } return State<T>::state; }
AngleDeg PositionInfo::GetShootAngle(AngleDeg left,AngleDeg right, const PlayerState & state , AngleDeg & interval) { vector< pair<Unum, AngleDeg> > tmp; for (vector<PlayerState*>::const_iterator it = mpWorldState->GetPlayerList().begin(); it != mpWorldState->GetPlayerList().end(); ++it){ if ((*it)->IsAlive() && (*it)->GetPosConf() > FLOAT_EPS && (*it)->GetUnum() != state.GetUnum() &&((*it)->GetPos()-state.GetPos()).Dir() + Rad2Deg(1/10) >left&&((*it)->GetPos()-state.GetPos()).Dir() - Rad2Deg(1/10) <right){//介于左右门柱之间 tmp.push_back(pair<Unum, AngleDeg>((*it)->GetUnum(), ((*it)->GetPos()-state.GetPos()).Dir())); } } if(tmp.size()!=0){ sort(tmp.begin(),tmp.end(),PlayerDirCompare()); vector<pair<int,AngleDeg> > dis; int i=0; vector<pair<int,AngleDeg> >::const_iterator it; for(it = tmp.begin(); it != tmp.end();++it){ if(i==0){ dis.push_back(pair<int,AngleDeg>(i++,((*it).second-left/* - Rad2Deg(1/10) - Rad2Deg(1/3)*/))); } else{ dis.push_back(pair<int,AngleDeg>(i++,((*it).second-(*(it-1)).second)/*- 2*Rad2Deg(1/10) - Rad2Deg(1/3)*/)); } } dis.push_back(pair<int,AngleDeg>(i,(right-(*(it-1)).second)/*- Rad2Deg(1/10) - Rad2Deg(1/3)*/)); sort(dis.begin(),dis.end(),PlayerDirCompare()); if(dis.back().first==0){ interval = dis.back().second-Rad2Deg(1.0/10.0)-Rad2Deg(1.0/4.0); return MinMax(left + 1,dis.back().second/2+left-Rad2Deg(1.0/10.0)-Rad2Deg(1.0/4.0),right -1 ); } else if(dis.back().first == i){ interval = dis.back().second-Rad2Deg(1.0/10.0)-Rad2Deg(1.0/4.0); return MinMax(left + 1,right -dis.back().second/2+Rad2Deg(1.0/10.0)+Rad2Deg(1.0/4.0),right -1); } else{ interval = dis.back().second - 2* Rad2Deg(1.0/10.0) - Rad2Deg(1.0/4.0); return MinMax(left +1,(*(tmp.begin()+dis.back().first-1)).second + dis.back().second/2 ,right -1); } } else { interval = right-left ; return (left+right)/2; } }