fixing multiple bugs in item selection events protocol
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13432 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -406,12 +406,6 @@ void Powerup::use()
|
||||
*/
|
||||
void Powerup::hitBonusBox(const Item &item, int add_info)
|
||||
{
|
||||
if (add_info>=0)
|
||||
{
|
||||
PowerupManager::PowerupType id = (PowerupManager::PowerupType)((add_info>>4)&0x0f); // highest 4 bits for the type
|
||||
uint8_t quantity = (add_info&0x0f); // last 4 bits for the amount
|
||||
set(id,quantity);
|
||||
}
|
||||
// Position can be -1 in case of a battle mode (which doesn't have
|
||||
// positions), but this case is properly handled in getRandomPowerup.
|
||||
int position = m_owner->getPosition();
|
||||
@@ -426,13 +420,21 @@ void Powerup::hitBonusBox(const Item &item, int add_info)
|
||||
|
||||
// Check if two bouncing balls are collected less than getRubberBallTimer()
|
||||
//seconds apart. If yes, then call getRandomPowerup again. If no, then break.
|
||||
for(int i=0; i<20; i++)
|
||||
if (add_info<0)
|
||||
{
|
||||
new_powerup = powerup_manager->getRandomPowerup(position, &n);
|
||||
if(new_powerup != PowerupManager::POWERUP_RUBBERBALL ||
|
||||
( World::getWorld()->getTime() - powerup_manager->getBallCollectTime()) >
|
||||
RubberBall::getTimeBetweenRubberBalls() )
|
||||
break;
|
||||
for(int i=0; i<20; i++)
|
||||
{
|
||||
new_powerup = powerup_manager->getRandomPowerup(position, &n);
|
||||
if(new_powerup != PowerupManager::POWERUP_RUBBERBALL ||
|
||||
( World::getWorld()->getTime() - powerup_manager->getBallCollectTime()) >
|
||||
RubberBall::getTimeBetweenRubberBalls() )
|
||||
break;
|
||||
}
|
||||
}
|
||||
else // set powerup manually
|
||||
{
|
||||
new_powerup = (PowerupManager::PowerupType)((add_info>>4)&0x0f); // highest 4 bits for the type
|
||||
n = (add_info&0x0f); // last 4 bits for the amount
|
||||
}
|
||||
|
||||
if(new_powerup == PowerupManager::POWERUP_RUBBERBALL)
|
||||
|
||||
@@ -51,7 +51,7 @@ bool GameEventsProtocol::notifyEvent(Event* event)
|
||||
ItemManager::get()->getItem(item_id),
|
||||
kart,
|
||||
powerup_type);
|
||||
Log::info("GameEventsProtocol", "Item picked by a player.");
|
||||
Log::info("GameEventsProtocol", "Item %d picked by a player.", powerup_type);
|
||||
} break;
|
||||
default:
|
||||
Log::warn("GameEventsProtocol", "Unkown message type.");
|
||||
@@ -70,7 +70,6 @@ void GameEventsProtocol::update()
|
||||
|
||||
void GameEventsProtocol::collectedItem(Item* item, AbstractKart* kart)
|
||||
{
|
||||
NetworkString ns;
|
||||
GameSetup* setup = NetworkManager::getInstance()->getGameSetup();
|
||||
assert(setup);
|
||||
const NetworkPlayerProfile* player_profile = setup->getProfile(kart->getIdent()); // use kart name
|
||||
@@ -78,10 +77,12 @@ void GameEventsProtocol::collectedItem(Item* item, AbstractKart* kart)
|
||||
std::vector<STKPeer*> peers = NetworkManager::getInstance()->getPeers();
|
||||
for (unsigned int i = 0; i < peers.size(); i++)
|
||||
{
|
||||
NetworkString ns;
|
||||
ns.ai32(peers[i]->getClientServerToken());
|
||||
// 0x01 : item picked : send item id, powerup type and kart race id
|
||||
ns.ai8(0x01).ai32(item->getItemId()).ai8((int)(kart->getPowerup()->getType())).ai8(player_profile->race_id); // send item,
|
||||
uint8_t powerup = (((int)(kart->getPowerup()->getType()) << 4)&0xf0) + (kart->getPowerup()->getNum()&0x0f);
|
||||
ns.ai8(0x01).ai32(item->getItemId()).ai8(powerup).ai8(player_profile->race_id); // send item,
|
||||
m_listener->sendMessage(this, peers[i], ns, true); // reliable
|
||||
Log::info("GameEventsProtocol", "Notified a peer that a kart collected an item.");
|
||||
Log::info("GameEventsProtocol", "Notified a peer that a kart collected item %d.", (int)(kart->getPowerup()->getType()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user