/** Virtual function called when the plunger hits something. * The plunger is special in that it is not deleted when hitting an object. * Instead it stays around (though not as a graphical or physical object) * till the rubber band expires. * \param kart Pointer to the kart hit (NULL if not a kart). * \param obj Pointer to PhysicalObject object if hit (NULL otherwise). */ void Plunger::hit(Kart *kart, PhysicalObject *obj) { if(isOwnerImmunity(kart)) return; RaceGUIBase* gui = World::getWorld()->getRaceGUI(); irr::core::stringw hit_message; // pulling back makes no sense in battle mode, since this mode is not a race. // so in battle mode, always hide view if( m_reverse_mode || race_manager->isBattleMode() ) { if(kart) { kart->blockViewWithPlunger(); hit_message += StringUtils::insertValues(getPlungerInFaceString(), kart->getName().c_str(), m_owner->getName().c_str() ).c_str(); gui->addMessage(hit_message, NULL, 3.0f, 40, video::SColor(255, 255, 255, 255), false); } m_keep_alive = 0; // Make this object invisible by placing it faaar down. Note that if this // objects is simply removed from the scene graph, it might be auto-deleted // because the ref count reaches zero. getNode()->setVisible(false); World::getWorld()->getPhysics()->removeBody(getBody()); } else { m_keep_alive = m_owner->getKartProperties()->getRubberBandDuration(); // Make this object invisible by placing it faaar down. Not that if this // objects is simply removed from the scene graph, it might be auto-deleted // because the ref count reaches zero. scene::ISceneNode *node = getNode(); if(node) { node->setVisible(false); } World::getWorld()->getPhysics()->removeBody(getBody()); if(kart) { m_rubber_band->hit(kart); return; } else if(obj) { Vec3 pos(obj->getBody()->getWorldTransform().getOrigin()); m_rubber_band->hit(NULL, &pos); } else { m_rubber_band->hit(NULL, &(getXYZ())); } } } // hit
/** Callback from the physics in case that a kart or physical object is hit. * \param kart The kart hit (NULL if no kart was hit). * \param object The object that was hit (NULL if none). * \return True if there was actually a hit (i.e. not owner, and target is * not immune), false otherwise. */ bool Flyable::hit(AbstractKart *kart_hit, PhysicalObject* object) { // the owner of this flyable should not be hit by his own flyable if(isOwnerImmunity(kart_hit)) return false; m_has_hit_something=true; return true; } // hit
/** Virtual function called when the plunger hits something. * The plunger is special in that it is not deleted when hitting an object. * Instead it stays around (though not as a graphical or physical object) * till the rubber band expires. * \param kart Pointer to the kart hit (NULL if not a kart). * \param obj Pointer to PhysicalObject object if hit (NULL otherwise). * \returns True if there was actually a hit (i.e. not owner, and target is * not immune), false otherwise. */ bool Plunger::hit(AbstractKart *kart, PhysicalObject *obj) { if(isOwnerImmunity(kart)) return false; // pulling back makes no sense in battle mode, since this mode is not a race. // so in battle mode, always hide view if( m_reverse_mode || race_manager->isBattleMode() ) { if(kart) { kart->blockViewWithPlunger(); if (kart->getController()->isPlayerController()) SFXManager::get()->quickSound("plunger"); } m_keep_alive = 0; // Make this object invisible. getNode()->setVisible(false); World::getWorld()->getPhysics()->removeBody(getBody()); } else { m_keep_alive = m_owner->getKartProperties()->getRubberBandDuration() * m_owner->getPlayerDifficulty()->getRubberBandDuration(); // Make this object invisible by placing it faaar down. Not that if this // objects is simply removed from the scene graph, it might be auto-deleted // because the ref count reaches zero. scene::ISceneNode *node = getNode(); if(node) { node->setVisible(false); } World::getWorld()->getPhysics()->removeBody(getBody()); if(kart) { m_rubber_band->hit(kart); return false; } else if(obj) { Vec3 pos(obj->getBody()->getWorldTransform().getOrigin()); m_rubber_band->hit(NULL, &pos); } else { m_rubber_band->hit(NULL, &(getXYZ())); } } // Rubber band attached. return false; } // hit