When an explosion is triggered by driving on a banana with a bomb attached,
the banana will now be disabled long enough to drive away once the explosion animation is finished (previously karts would get punished twice, since after the explosion they would be hit by the banana again). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5830 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "items/attachment.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include "config/stk_config.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
@@ -92,19 +93,28 @@ void Attachment::clear()
|
||||
} // clear
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void Attachment::hitBanana(const Item &item, int new_attachment)
|
||||
void Attachment::hitBanana(Item *item, int new_attachment)
|
||||
{
|
||||
float leftover_time = 0.0f;
|
||||
|
||||
switch(getType()) // If there already is an attachment, make it worse :)
|
||||
{
|
||||
case ATTACH_BOMB:
|
||||
{
|
||||
projectile_manager->newExplosion(m_kart->getXYZ());
|
||||
m_kart->handleExplosion(m_kart->getXYZ(), /*direct_hit*/ true);
|
||||
clear();
|
||||
if(new_attachment==-1)
|
||||
new_attachment = m_random.get(3);
|
||||
// Disable the banana on which the kart just is for more than the
|
||||
// default time. This is necessary to avoid that a kart lands on the
|
||||
// same banana again once the explosion animation is finished, giving
|
||||
// the kart the same penalty twice.
|
||||
float f = std::max(item->getDisableTime(),
|
||||
m_kart->getKartProperties()->getExplosionTime()+2.0f);
|
||||
item->setDisableTime(f);
|
||||
break;
|
||||
}
|
||||
case ATTACH_ANVIL:
|
||||
// if the kart already has an anvil, attach a new anvil,
|
||||
// and increase the overall time
|
||||
@@ -129,7 +139,7 @@ void Attachment::hitBanana(const Item &item, int new_attachment)
|
||||
if(network_manager->getMode()==NetworkManager::NW_SERVER)
|
||||
{
|
||||
race_state->itemCollected(m_kart->getWorldKartId(),
|
||||
item.getItemId(),
|
||||
item->getItemId(),
|
||||
new_attachment);
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
* \param new_attachment Optional: only used on the clients, it
|
||||
* specifies the new attachment to use
|
||||
*/
|
||||
void hitBanana(const Item &item, int new_attachment=-1);
|
||||
void hitBanana(Item *item, int new_attachment=-1);
|
||||
void update (float dt);
|
||||
void moveBombFromTo(Kart *from, Kart *to);
|
||||
};
|
||||
|
||||
@@ -135,6 +135,19 @@ public:
|
||||
* be removed when the game is reset. */
|
||||
bool canBeUsedUp() const {return m_disappear_counter>-1; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets how long an item should be disabled. While item itself sets
|
||||
* a default, this time is too short in case that a kart that has a bomb
|
||||
* hits a banana: by the time the explosion animation is ended and the
|
||||
* kart is back at its original position, the banana would be back again
|
||||
* and therefore hit the kart again. See Attachment::hitBanana for more
|
||||
* details.
|
||||
* \param f Time till the item can be used again.
|
||||
*/
|
||||
void setDisableTime(float f) { m_time_till_return = f; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the time the item is disabled for. */
|
||||
float getDisableTime() const { return m_time_till_return; }
|
||||
// ------------------------------------------------------------------------
|
||||
void setParent(Kart* parent);
|
||||
void reset();
|
||||
void switchTo(ItemType type, scene::IMesh *mesh);
|
||||
|
||||
@@ -169,7 +169,7 @@ void ItemManager::collectedItem(int item_id, Kart *kart, int add_info)
|
||||
Item *item=m_all_items[item_id];
|
||||
assert(item);
|
||||
item->collected(kart);
|
||||
kart->collectedItem(*item, add_info);
|
||||
kart->collectedItem(item, add_info);
|
||||
} // collectedItem
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -532,10 +532,10 @@ void Kart::finishedRace(float time)
|
||||
* a specific item to be used (instead of a random item) to keep
|
||||
* all karts in synch.
|
||||
*/
|
||||
void Kart::collectedItem(const Item &item, int add_info)
|
||||
void Kart::collectedItem(Item *item, int add_info)
|
||||
{
|
||||
float old_energy = m_collected_energy;
|
||||
const Item::ItemType type = item.getType();
|
||||
const Item::ItemType type = item->getType();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
@@ -550,7 +550,7 @@ void Kart::collectedItem(const Item &item, int add_info)
|
||||
// In wheelie style, karts get more items depending on energy,
|
||||
// in nitro mode it's only one item.
|
||||
int n = 1;
|
||||
m_powerup.hitBonusBox(n, item, add_info);
|
||||
m_powerup.hitBonusBox(n, *item, add_info);
|
||||
break;
|
||||
}
|
||||
case Item::ITEM_BUBBLEGUM:
|
||||
@@ -570,12 +570,12 @@ void Kart::collectedItem(const Item &item, int add_info)
|
||||
if(network_manager->getMode()==NetworkManager::NW_SERVER &&
|
||||
(type==Item::ITEM_NITRO_BIG || type==Item::ITEM_NITRO_SMALL) )
|
||||
{
|
||||
race_state->itemCollected(getWorldKartId(), item.getItemId());
|
||||
race_state->itemCollected(getWorldKartId(), item->getItemId());
|
||||
}
|
||||
|
||||
if ( m_collected_energy > MAX_ITEMS_COLLECTED )
|
||||
m_collected_energy = MAX_ITEMS_COLLECTED;
|
||||
m_controller->collectedItem(item, add_info, old_energy);
|
||||
m_controller->collectedItem(*item, add_info, old_energy);
|
||||
|
||||
} // collectedItem
|
||||
|
||||
|
||||
@@ -375,7 +375,7 @@ public:
|
||||
const std::string& getIdent () const {return m_kart_properties->getIdent();}
|
||||
// addMessages gets called by world to add messages to the gui
|
||||
virtual void addMessages () {};
|
||||
virtual void collectedItem (const Item &item, int random_attachment);
|
||||
virtual void collectedItem (Item *item, int random_attachment);
|
||||
virtual void reset ();
|
||||
virtual void handleZipper ();
|
||||
virtual void crashed (Kart *k);
|
||||
|
||||
Reference in New Issue
Block a user