本文整理汇总了C++中SoccerWorld::handlePlayerGoalFromServer方法的典型用法代码示例。如果您正苦于以下问题:C++ SoccerWorld::handlePlayerGoalFromServer方法的具体用法?C++ SoccerWorld::handlePlayerGoalFromServer怎么用?C++ SoccerWorld::handlePlayerGoalFromServer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SoccerWorld
的用法示例。
在下文中一共展示了SoccerWorld::handlePlayerGoalFromServer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: notifyEvent
// ----------------------------------------------------------------------------
bool GameEventsProtocol::notifyEvent(Event* event)
{
// Avoid crash in case that we still receive race events when
// the race is actually over.
if (event->getType() != EVENT_TYPE_MESSAGE || !World::getWorld())
return true;
NetworkString &data = event->data();
if (data.size() < 1) // for type
{
Log::warn("GameEventsProtocol", "Too short message.");
return true;
}
uint8_t type = data.getUInt8();
CaptureTheFlag* ctf = dynamic_cast<CaptureTheFlag*>(World::getWorld());
FreeForAll* ffa = dynamic_cast<FreeForAll*>(World::getWorld());
SoccerWorld* sw = dynamic_cast<SoccerWorld*>(World::getWorld());
LinearWorld* lw = dynamic_cast<LinearWorld*>(World::getWorld());
switch (type)
{
case GE_KART_FINISHED_RACE:
kartFinishedRace(data); break;
case GE_RESET_BALL:
{
if (!sw)
throw std::invalid_argument("No soccer world");
sw->handleResetBallFromServer(data);
break;
}
case GE_PLAYER_GOAL:
{
if (!sw)
throw std::invalid_argument("No soccer world");
sw->handlePlayerGoalFromServer(data);
break;
}
case GE_BATTLE_KART_SCORE:
{
if (!ffa)
throw std::invalid_argument("No free-for-all world");
ffa->setKartScoreFromServer(data);
break;
}
case GE_CTF_SCORED:
{
if (!ctf)
throw std::invalid_argument("No CTF world");
uint8_t kart_id = data.getUInt8();
bool red_team_scored = data.getUInt8() == 1;
int16_t new_kart_scores = data.getUInt16();
int new_red_scores = data.getUInt8();
int new_blue_scores = data.getUInt8();
ctf->ctfScored(kart_id, red_team_scored, new_kart_scores,
new_red_scores, new_blue_scores);
break;
}
case GE_STARTUP_BOOST:
{
if (NetworkConfig::get()->isServer())
{
uint8_t kart_id = data.getUInt8();
if (!event->getPeer()->availableKartID(kart_id))
{
Log::warn("GameProtocol", "Wrong kart id %d from %s.",
kart_id, event->getPeer()->getAddress().toString().c_str());
return true;
}
float f = LobbyProtocol::get<ServerLobby>()
->getStartupBoostOrPenaltyForKart(
event->getPeer()->getAveragePing(), kart_id);
NetworkString *ns = getNetworkString();
ns->setSynchronous(true);
ns->addUInt8(GE_STARTUP_BOOST).addUInt8(kart_id).addFloat(f);
sendMessageToPeers(ns, true);
delete ns;
}
else
{
uint8_t kart_id = data.getUInt8();
float boost = data.getFloat();
AbstractKart* k = World::getWorld()->getKart(kart_id);
if (boost < 0.0f)
{
PlayerController* pc =
dynamic_cast<PlayerController*>(k->getController());
pc->displayPenaltyWarning();
}
else
k->setStartupBoost(boost);
}
break;
}
case GE_CHECK_LINE:
{
if (!lw)
throw std::invalid_argument("No linear world");
if (NetworkConfig::get()->isClient())
lw->updateCheckLinesClient(data);
break;
}
//.........这里部分代码省略.........