本文整理汇总了C++中PlayerState类的典型用法代码示例。如果您正苦于以下问题:C++ PlayerState类的具体用法?C++ PlayerState怎么用?C++ PlayerState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PlayerState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
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;
}
示例2: npmodule_listPlayers
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;
}
示例3: UseItem
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) );
}
示例4: create_ships
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);
}
}
}
示例5: operator
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;
}
示例6: enter
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();
}
示例7: process
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;
}
示例8: RandomInt
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() ) );
}
示例9: Vehicle
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;
}
示例10: operator
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);
}
示例11: netPacketClientDisconnect
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());
}
示例12: while
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();
}
}
示例13: update_player_state
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);
}
示例14: pay
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;
}
示例15: hold
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());
}
}
}