1) Replaced all .projectile files with one powerup.xml file,

replaced items.item with items.xml. Cleaned up item_manager
   and removed support for different item styles (since it
   didn't work anyway)
2) If a swapper item is used while items are swapped, they will
   now un-swap.
3) Moved all models and textures from data/items to data/models.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4648 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2010-02-07 02:05:21 +00:00
parent 0042808800
commit 93e15df841
46 changed files with 199 additions and 379 deletions

View File

@ -423,7 +423,6 @@ AC_CONFIG_FILES([ \
data/fonts/Makefile \
data/grandprix/Makefile \
data/gui/Makefile \
data/items/Makefile \
data/karts/Makefile \
data/models/Makefile \
data/music/Makefile \

View File

@ -1,21 +0,0 @@
;; -*- mode: lisp -*-
(tuxkart-collectable
(name "Bowling")
(model "bowling.ac")
(mesh "bowling.b3d")
(icon "bowling-icon.png")
(speed 4.0)
(min-height 0.2) ; height above terrain below which a ball is
; started to be pulled up
(max-height 1.0) ; height above terrain at which a ball is
; started to be pulled back to ground
(force-updown 1.0) ; force pushing the ball down
; when it's too high above ground
(force-to-target 40) ; force with which a bowling ball flies towards
; the nearest kart
(max-distance 25) ; maximum distance the ball can be away
; from a kart when accelerating towards it
)
;; EOF ;;

View File

@ -1,13 +0,0 @@
;; -*- mode: lisp -*-
(tuxkart-collectable
(name "Bubble Gum")
(model "../items/bubblegum.ac")
(icon "bubblegum-icon.png")
(speed 50.0)
(min-height 0.3)
(max-height 1.0)
(force-updown 20)
)
;; EOF ;;

View File

@ -1,13 +0,0 @@
;; -*- mode: lisp -*-
(tuxkart-collectable
(name "Bubble Gum")
(mesh "../items/bubblegum.b3d")
(icon "bubblegum-icon.png")
(speed 50.0)
(min-height 0.3)
(max-height 1.0)
(force-updown 20)
)
;; EOF ;;

View File

@ -1,14 +0,0 @@
;; -*- mode: lisp -*-
(tuxkart-collectable
(name "cake")
(mesh "cake.b3d")
(icon "cake-icon.png")
(speed 50.0)
(min-height 0.2)
(max-height 1.0)
(force-updown 25.0) ;; force raising/lowering the homing missile if it's too low/high
(max-distance 90.0) ;; maximum distance at which a kart is still followed
)
;; EOF ;;

View File

@ -1,10 +0,0 @@
;; -*- mode: lisp -*-
(item
(gold "nitrotank-big" )
(silver "nitrotank-small")
(green "banana" )
(red "gift-box")
)
;; EOF ;;

12
data/items.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<items>
<bonus-box model="gift-box.b3d" />
<banana model="banana.b3d" />
<nitro-big model="nitrotank-big.b3d" />
<nitro-small model="nitrotank-small.b3d" />
<!-- While a bubble gum technically
isn't an item, it is internally
handled as one, so list it here -->
<bubblegum model="bubblegum.b3d" />
</items>

View File

@ -1,13 +0,0 @@
All models are released under GPL except :
* bubblegum.ac, nitrotank-big.ac, nitrotank-small.ac, giftbox.ac
created by MiniBjorn (c) 2008
released under Creative Commons Attribution-Share Alike 3.0 [http://creativecommons.org/licenses/by-sa/3.0/]
* banana.ac
created by horace aka thomas oppl (toppl@fh-sbg.ac.at) (c) 2008
released under Creative Commons Attribution-Share Alike 3.0 [http://creativecommons.org/licenses/by-sa/3.0/]
* chest_*, key
by Marianne gagnon
released under Creative Commons Attribution-Share Alike 3.0 [http://creativecommons.org/licenses/by-sa/3.0/]

View File

@ -1,9 +0,0 @@
# data/herrings/
pkgdatadir = $(datadir)/games/$(PACKAGE)/data/items
dist_pkgdata_DATA = $(shell find $(srcdir) -name "*.b3d") \
$(shell find $(srcdir) -name "*.png") \
$(shell find $(srcdir) -name "*.jpg") \
License.txt

Binary file not shown.

View File

@ -2,4 +2,16 @@
created by MiniBjorn (c) 2008
released under Creative Commons Attribution-Share Alike 3.0 [http://creativecommons.org/licenses/by-sa/3.0/]
Others are GPL.
* bubblegum.ac, nitrotank-big.ac, nitrotank-small.ac, giftbox.ac
created by MiniBjorn (c) 2008
released under Creative Commons Attribution-Share Alike 3.0 [http://creativecommons.org/licenses/by-sa/3.0/]
* banana.ac
created by horace aka thomas oppl (toppl@fh-sbg.ac.at) (c) 2008
released under Creative Commons Attribution-Share Alike 3.0 [http://creativecommons.org/licenses/by-sa/3.0/]
* chest_*, key
by Marianne gagnon
released under Creative Commons Attribution-Share Alike 3.0 [http://creativecommons.org/licenses/by-sa/3.0/]
Others are GPL.

View File

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

View File

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 78 KiB

View File

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 54 KiB

View File

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View File

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 33 KiB

View File

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View File

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 56 KiB

View File

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -1,21 +0,0 @@
;; -*- mode: lisp -*-
(tuxkart-collectable
(name "Plunger")
(model "plunger.ac")
(mesh "plunger.b3d")
(icon "plunger-icon.png")
(speed 35.0)
(min-height 0.2) ; height above terrain below which a plunger is
; started to be pulled up
(max-height 1.0) ; height above terrain at which a plunger is
; started to be pulled back to ground
(force-updown 35.0) ; force pushing the spark down
; when it's too high above ground
(force-to-target 15) ; force with which a spark flies towards
; the nearest kart
(max-distance 25) ; maximum distance the spark can be away
; from a kart when accelerating towards it
)
;; EOF ;;

25
data/powerup.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0"?>
<powerup>
<item name="zipper" icon="zipper_collect.png" />
<item name="bowling" icon="bowling-icon.png"
model="bowling.b3d" speed="4.0"
min-height="0.2" max-height="1.0"
force-updown="1" force-to-target="40"
max-distance="25" />
<item name="bubblegum" icon="bubblegum-icon.png" />
<item name="cake" icon="cake-icon.png"
model="cake.b3d" speed="50"
min-height="0.2" max-height="1.0"
force-updown="25" max-distance="90" />
<item name="anchor" icon="anchor-icon.png"
model="anchor.b3d" />
<item name="switch" icon="swap-icon.png" />
<item name="parachute" icon="parachute.png"
model="parachute.b3d" />
<item name="plunger" icon="plunger-icon.png"
model="plunger.b3d" speed="35"
min-height="0.2" max-height="1.0"
force-updown="35" force-to-target="15"
max-distance="25" />
</powerup>

View File

@ -327,7 +327,7 @@ void IrrDriver::doApplyResSettings()
material_manager->reInit();
powerup_manager -> loadPowerups();
powerup_manager -> loadAllPowerups();
kart_properties_manager -> loadAllKarts();
item_manager -> loadDefaultItems();
projectile_manager -> loadData();

View File

@ -18,6 +18,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "graphics/camera.hpp"
#include "io/xml_node.hpp"
#include "items/bowling.hpp"
#include "karts/player_kart.hpp"
@ -69,17 +70,21 @@ Bowling::Bowling(Kart *kart) : Flyable(kart, POWERUP_BOWLING, 50.0f /* mass */)
} // Bowling
// -----------------------------------------------------------------------------
void Bowling::init(const lisp::Lisp* lisp, scene::IMesh *bowling)
/** Initialises this object with data from the power.xml file.
* \param node XML Node
* \param bowling The bowling ball mesh
*/
void Bowling::init(const XMLNode &node, scene::IMesh *bowling)
{
Flyable::init(lisp, bowling, POWERUP_BOWLING);
m_st_max_distance = 20.0f;
Flyable::init(node, bowling, POWERUP_BOWLING);
m_st_max_distance = 20.0f;
m_st_max_distance_squared = 20.0f * 20.0f;
m_st_force_to_target = 10.0f;
m_st_force_to_target = 10.0f;
lisp->get("max-distance", m_st_max_distance );
node.get("max-distance", &m_st_max_distance );
m_st_max_distance_squared = m_st_max_distance*m_st_max_distance;
lisp->get("force-to-target", m_st_force_to_target);
node.get("force-to-target", &m_st_force_to_target);
} // init
// -----------------------------------------------------------------------------

View File

@ -25,6 +25,8 @@ using namespace irr;
#include "items/flyable.hpp"
class XMLNode;
class Bowling : public Flyable
{
private:
@ -34,7 +36,7 @@ private:
public:
Bowling(Kart* kart);
static void init(const lisp::Lisp* lisp, scene::IMesh *bowling);
static void init(const XMLNode &node, scene::IMesh *bowling);
virtual void update(float dt);
int getExplosionSound() const { return SFXManager::SOUND_BOWLING_STRIKE; }

View File

@ -24,6 +24,7 @@
#include <iostream>
#include "io/xml_node.hpp"
#include "karts/kart.hpp"
#include "utils/constants.hpp"
@ -114,9 +115,13 @@ Cake::Cake (Kart *kart) : Flyable(kart, POWERUP_CAKE)
} // Cake
// -----------------------------------------------------------------------------
void Cake::init(const lisp::Lisp* lisp, scene::IMesh *cake_model)
/** Initialises the object from an entry in the powerup.xml file.
* \param node The xml node for this object.
* \param cakde_model The mesh model of the cake.
*/
void Cake::init(const XMLNode &node, scene::IMesh *cake_model)
{
Flyable::init(lisp, cake_model, POWERUP_CAKE);
Flyable::init(node, cake_model, POWERUP_CAKE);
m_st_max_distance = 80.0f;
m_st_max_distance_squared = 80.0f * 80.0f;
m_gravity = 9.8f;
@ -124,8 +129,7 @@ void Cake::init(const lisp::Lisp* lisp, scene::IMesh *cake_model)
if (m_gravity < 0)
m_gravity *= -1;
lisp->get("max-distance", m_st_max_distance );
node.get("max-distance", &m_st_max_distance );
m_st_max_distance_squared = m_st_max_distance*m_st_max_distance;
} // init

View File

@ -27,6 +27,8 @@
#include "items/flyable.hpp"
class XMLNode;
class Cake : public Flyable
{
private:
@ -39,7 +41,7 @@ private:
// projectile (NULL if none)
public:
Cake (Kart *kart);
static void init (const lisp::Lisp* lisp, scene::IMesh *cake_model);
static void init (const XMLNode &node, scene::IMesh *cake_model);
virtual void update (float dt);
virtual void hitTrack () { hit(NULL); }
// Kinematic objects are not allowed to have a velocity (assertion in

View File

@ -26,6 +26,7 @@
#include "graphics/irr_driver.hpp"
#include "graphics/mesh_tools.hpp"
#include "io/xml_node.hpp"
#include "items/projectile_manager.hpp"
#include "karts/kart.hpp"
#include "modes/world.hpp"
@ -114,17 +115,17 @@ void Flyable::createPhysics(float y_offset, const btVector3 &velocity,
} // createPhysics
// -----------------------------------------------------------------------------
void Flyable::init(const lisp::Lisp* lisp, scene::IMesh *model,
void Flyable::init(const XMLNode &node, scene::IMesh *model,
PowerupType type)
{
m_st_speed[type] = 25.0f;
m_st_max_height[type] = 1.0f;
m_st_min_height[type] = 3.0f;
m_st_force_updown[type] = 15.0f;
lisp->get("speed", m_st_speed[type] );
lisp->get("min-height", m_st_min_height[type] );
lisp->get("max-height", m_st_max_height[type] );
lisp->get("force-updown", m_st_force_updown[type]);
node.get("speed", &(m_st_speed[type]) );
node.get("min-height", &(m_st_min_height[type]) );
node.get("max-height", &(m_st_max_height[type]) );
node.get("force-updown", &(m_st_force_updown[type]));
// Store the size of the model
Vec3 min, max;

View File

@ -34,6 +34,7 @@ using namespace irr;
class FlyableInfo;
class Kart;
class PhysicalObject;
class XMLNode;
class Flyable : public Moveable, public TerrainInfo
{
@ -114,7 +115,7 @@ public:
* terrain. Missiles can 'follow the terrain' with this adjustment,
* but gravity will basically be disabled. */
void setAdjustZVelocity(bool f) { m_adjust_z_velocity = f; }
static void init (const lisp::Lisp* lisp, scene::IMesh *model,
static void init (const XMLNode &node, scene::IMesh *model,
PowerupType type);
virtual void update (float);
void updateFromServer(const FlyableInfo &f, float dt);

View File

@ -98,69 +98,35 @@ ItemManager::~ItemManager()
//-----------------------------------------------------------------------------
void ItemManager::loadDefaultItems()
{
// Load all models. This can't be done in the constructor,
// since the file_manager isn't ready at that stage.
// -------------------------------------------------------
std::set<std::string> files;
file_manager->listFiles(files, file_manager->getItemsDir(),
/*is_full_path*/true,
/*make_full_path*/true);
for(std::set<std::string>::iterator i = files.begin();
i != files.end(); ++i)
// The names must be given in the order of the definition of ItemType
// in item.hpp. Note that bubblegum strictly isn't an item,
// it is implemented as one, and so loaded here, too.
static const std::string item_names[] = {"bonus-box", "banana",
"nitro-big", "nitro-small",
"bubblegum" };
const XMLNode *root = file_manager->createXMLTree("data/items.xml");
for(unsigned int i=Item::ITEM_FIRST; i<=Item::ITEM_LAST; i++)
{
if(StringUtils::getExtension(*i)!="b3d") continue;
scene::IMesh *mesh = irr_driver->getAnimatedMesh(*i);
if(!mesh) continue;
std::string shortName = StringUtils::getBasename(StringUtils::removeExtension(*i));
const XMLNode *node = root->getNode(item_names[i]);
std::string model_filename;
if (node)
node->get("model", &model_filename);
scene::IMesh *mesh = irr_driver->getAnimatedMesh(model_filename);
if(!node || model_filename.size()==0 || !mesh)
{
fprintf(stderr, "Item model '%s' in items.xml could not be loaded - aborting",
item_names[i].c_str());
exit(-1);
}
std::string shortName =
StringUtils::getBasename(StringUtils::removeExtension(model_filename));
m_all_meshes[shortName] = mesh;
m_item_mesh[i] = mesh;
mesh->grab();
} // for i
setDefaultItemStyle();
} // loadDefaultItems
//-----------------------------------------------------------------------------
void ItemManager::setDefaultItemStyle()
{
// FIXME - This should go in an internal, system wide configuration file
std::string DEFAULT_NAMES[Item::ITEM_LAST - Item::ITEM_FIRST +1];
DEFAULT_NAMES[Item::ITEM_BONUS_BOX] = "gift-box";
DEFAULT_NAMES[Item::ITEM_BANANA] = "banana";
DEFAULT_NAMES[Item::ITEM_NITRO_BIG] = "nitrotank-big";
DEFAULT_NAMES[Item::ITEM_NITRO_SMALL] = "nitrotank-small";
DEFAULT_NAMES[Item::ITEM_BUBBLEGUM] = "bubblegum";
bool bError=0;
std::ostringstream msg;
for(int i=Item::ITEM_FIRST; i<=Item::ITEM_LAST; i++)
{
m_item_mesh[i] = m_all_meshes[DEFAULT_NAMES[i]];
if(!m_item_mesh[i])
{
msg << "Item model '" << DEFAULT_NAMES[i]
<< "' is missing (see item_manager)!\n";
bError=1;
break;
} // if !m_item_model
} // for i
if(bError)
{
fprintf(stderr, "The following models are available:\n");
for(CI_type i=m_all_meshes.begin(); i!=m_all_meshes.end(); ++i)
{
if(i->second)
{
fprintf(stderr, " %s in %s.ac.\n",
i->first.c_str(),
i->first.c_str());
} // if i->second
}
throw std::runtime_error(msg.str());
exit(-1);
} // if bError
} // setDefaultItemStyle
//-----------------------------------------------------------------------------
/** Creates a new item.
* \param type Type of the item.
@ -225,40 +191,6 @@ void ItemManager::cleanup()
delete *i;
}
m_all_items.clear();
setDefaultItemStyle();
// FIXME - this seems outdated
// Then load the default style from the user_config file
// -----------------------------------------------------
// This way if an item is not defined in the item-style-file, the
// default (i.e. old herring) is used.
try
{
// FIXME: This should go in a system-wide configuration file,
// and only one of this and the hard-coded settings in
// setDefaultItemStyle are necessary!!!
loadItemStyle(UserConfigParams::m_item_style);
}
catch(std::runtime_error)
{
fprintf(stderr,"The item style '%s' in your configuration file does not exist.\nIt is ignored.\n",
UserConfigParams::m_item_style.c_str());
UserConfigParams::m_item_style="";
}
try
{
loadItemStyle(m_user_filename);
}
catch(std::runtime_error)
{
fprintf(stderr,"The item style '%s' specified on the command line does not exist.\nIt is ignored.\n",
m_user_filename.c_str());
m_user_filename=""; // reset to avoid further warnings.
}
} // cleanup
//-----------------------------------------------------------------------------
@ -288,44 +220,6 @@ void ItemManager::reset()
m_switch_time = -1;
} // reset
//-----------------------------------------------------------------------------
/** Sets the selected item style to be used in the track. The style depends on
* either the GP or the track selected.
*/
void ItemManager::setStyle()
{
if(race_manager->getMajorMode()== RaceManager::MAJOR_MODE_GRAND_PRIX)
{
try
{
item_manager->loadItemStyle(race_manager->getItemStyle());
}
catch(std::runtime_error)
{
fprintf(stderr, "The grand prix '%ls' contains an invalid item style '%s'.\n",
race_manager->getGrandPrix()->getName().c_str(),
race_manager->getItemStyle().c_str());
fprintf(stderr, "Please fix the file 'l%s'.\n",
race_manager->getGrandPrix()->getFilename().c_str());
}
}
else
{
try
{
item_manager->loadItemStyle(RaceManager::getTrack()->getItemStyle());
}
catch(std::runtime_error)
{
fprintf(stderr, "The track '%ls' contains an invalid item style '%s'.\n",
RaceManager::getTrack()->getName().c_str(),
RaceManager::getTrack()->getItemStyle().c_str());
fprintf(stderr, "Please fix the file '%s'.\n",
RaceManager::getTrack()->getFilename().c_str());
}
}
} // setStyle
//-----------------------------------------------------------------------------
void ItemManager::update(float dt)
{
@ -365,39 +259,17 @@ void ItemManager::switchItems()
(*i)->switchTo(new_type, m_item_mesh[(int)new_type]);
// FIXME: if switch is used while items are switched:
// switch back - but that doesn't work properly yet
//else
// (*i)->switchBack();
else
(*i)->switchBack();
} // for m_all_items
m_switch_time = stk_config->m_item_switch_time;
// if the items are already switched (m_switch_time >=0)
// then switch back, and set m_switch_time to -1 to indicate
// that the items are now back to normal.
m_switch_time = m_switch_time < 0 ? stk_config->m_item_switch_time : -1;
} // switchItems
//-----------------------------------------------------------------------------
void ItemManager::loadItemStyle(const std::string filename)
{
if(filename.length()==0) return;
const lisp::Lisp* root = 0;
lisp::Parser parser;
root = parser.parse(file_manager->getConfigFile(filename + ".items"));
const lisp::Lisp* item_node = root->getLisp("item");
if(!item_node)
{
std::ostringstream msg;
msg << "Couldn't load map '" << filename << "': no item node.";
delete root;
throw std::runtime_error(msg.str());
delete root;
}
setItem(item_node, "red", Item::ITEM_BONUS_BOX );
setItem(item_node, "green", Item::ITEM_BANANA );
setItem(item_node, "gold" ,Item::ITEM_NITRO_BIG );
setItem(item_node, "silver",Item::ITEM_NITRO_SMALL);
delete root;
} // loadItemStyle
//-----------------------------------------------------------------------------
void ItemManager::setItem(const lisp::Lisp *item_node,
const char *colour, Item::ItemType type)

View File

@ -44,16 +44,15 @@ private:
std::string m_user_filename;
/** Remaining time that items should remain switched. */
/** Remaining time that items should remain switched. If the
* value is <0, it indicates that the items are not switched atm. */
float m_switch_time;
/** What item is item is switched to. */
std::vector<Item::ItemType> m_switch_to;
void setDefaultItemStyle();
void setItem(const lisp::Lisp *item_node, const char *colour,
Item::ItemType type);
void loadItemStyle (const std::string filename);
public:
ItemManager();
@ -71,7 +70,6 @@ public:
int add_info=-1);
void switchItems ();
void setSwitchItems(const std::vector<int> &switch_items);
void setStyle ();
scene::IMesh* getItemModel (Item::ItemType type)
{return m_item_mesh[type];}
scene::IMesh* getOtherModel (const std::string modelName)

View File

@ -23,6 +23,7 @@
#include "items/plunger.hpp"
#include "graphics/irr_driver.hpp"
#include "io/xml_node.hpp"
#include "items/rubber_band.hpp"
#include "items/projectile_manager.hpp"
#include "karts/player_kart.hpp"
@ -107,9 +108,9 @@ Plunger::~Plunger()
} // ~Plunger
// -----------------------------------------------------------------------------
void Plunger::init(const lisp::Lisp* lisp, scene::IMesh *plunger_model)
void Plunger::init(const XMLNode &node, scene::IMesh *plunger_model)
{
Flyable::init(lisp, plunger_model, POWERUP_PLUNGER);
Flyable::init(node, plunger_model, POWERUP_PLUNGER);
} // init
// -----------------------------------------------------------------------------

View File

@ -27,9 +27,10 @@
using namespace irr;
#include "items/flyable.hpp"
class RubberBand;
class Kart;
class PhysicalObject;
class RubberBand;
class XMLNode;
class Plunger : public Flyable
{
@ -44,7 +45,7 @@ private:
public:
Plunger(Kart *kart);
~Plunger();
static void init(const lisp::Lisp* lisp, scene::IMesh* missile);
static void init(const XMLNode &node, scene::IMesh* missile);
/** Sets the keep-alive value. Setting it to 0 will remove the plunger
* at the next update - which is used if the rubber band snaps.
*/

View File

@ -27,31 +27,11 @@
#include "graphics/material.hpp"
#include "graphics/material_manager.hpp"
#include "io/file_manager.hpp"
#include "io/xml_node.hpp"
#include "items/bowling.hpp"
#include "items/cake.hpp"
#include "items/plunger.hpp"
typedef struct
{
PowerupType powerup;
const char*const dataFile;
}
initPowerupType;
initPowerupType ict[]=
{
{POWERUP_ZIPPER, "zipper.collectable" },
{POWERUP_BOWLING, "bowling.projectile" },
{POWERUP_BUBBLEGUM, "bubblegum.xml" },
{POWERUP_CAKE, "cake.projectile" },
{POWERUP_ANVIL, "anvil.collectable" },
{POWERUP_SWITCH, "switch.collectable" },
{POWERUP_PARACHUTE, "parachute.collectable" },
{POWERUP_PLUNGER, "plunger.projectile" },
{POWERUP_MAX, "" },
};
PowerupManager* powerup_manager=0;
//-----------------------------------------------------------------------------
@ -64,83 +44,96 @@ PowerupManager::PowerupManager()
}
} // PowerupManager
//-----------------------------------------------------------------------------
PowerupManager::~PowerupManager()
{
for(unsigned int i=POWERUP_FIRST; i<=POWERUP_LAST; i++)
{
m_all_meshes[(PowerupType)i]->drop();
}
} // ~PowerupManager
//-----------------------------------------------------------------------------
void PowerupManager::removeTextures()
{
} // removeTextures
//-----------------------------------------------------------------------------
/** Determines the powerup type for a given name.
* \param name Name of the powerup to look up.
* \return The type, or POWERUP_NOTHING if the name is not found
*/
PowerupType PowerupManager::getPowerupType(const std::string &name)
{
// Must match the order of PowerupType in powerup_manager.hpp!!
static std::string powerup_names[] = {
"", /* Nothing */
"bubblegum", "cake", "bowling", "zipper", "plunger", "switch",
"parachute", "anchor"
};
for(unsigned int i=POWERUP_FIRST; i<=POWERUP_LAST; i++)
{
if(powerup_names[i]==name) return(PowerupType)i;
}
return POWERUP_NOTHING;
} // getPowerupType
//-----------------------------------------------------------------------------
/** Loads all projectiles from the powerup.xml file.
*/
void PowerupManager::loadPowerups()
void PowerupManager::loadAllPowerups()
{
for(int i=0; ict[i].powerup != POWERUP_MAX; i++)
XMLNode *root = file_manager->createXMLTree("data/powerup.xml");
for(unsigned int i=0; i<root->getNumNodes(); i++)
{
Load(ict[i].powerup, ict[i].dataFile);
const XMLNode *node=root->getNode(i);
std::string name;
node->get("name", &name);
PowerupType type = getPowerupType(name);
LoadPowerup(type, *node);
}
} // loadPowerups
} // loadAllPowerups
//-----------------------------------------------------------------------------
void PowerupManager::Load(int collectType, const char* filename)
void PowerupManager::LoadPowerup(PowerupType type, const XMLNode &node)
{
const lisp::Lisp* ROOT = 0;
std::string icon_file("");
node.get("icon", &icon_file);
m_all_icons[type] = material_manager->getMaterial(icon_file,
/* full_path */ false,
/*make_permanent */ true);
lisp::Parser parser;
std::string tmp= "data/" + (std::string)filename;
ROOT = parser.parse(file_manager->getConfigFile(filename));
const lisp::Lisp* lisp = ROOT->getLisp("tuxkart-collectable");
if(!lisp)
{
std::ostringstream msg;
msg << "No 'tuxkart-collectable' node found while parsing '"
<< filename << "'.";
throw std::runtime_error(msg.str());
}
LoadNode(lisp, collectType);
delete ROOT;
} // Load
//-----------------------------------------------------------------------------
void PowerupManager::LoadNode(const lisp::Lisp* lisp, int collectType )
{
std::string sName, sModel, sIconFile;
lisp->get("name", sName );
lisp->get("mesh", sModel );
lisp->get("icon", sIconFile );
// load material
m_all_icons[collectType] = material_manager->getMaterial(sIconFile,
/* full_path */ false,
/*make_permanent */ true);
if(sModel!="")
std::string model("");
node.get("model", &model);
if(model.size()>0)
{
// FIXME LEAK: not freed (unimportant, since the models have to exist
// for the whole game anyway).
std::string full_path = file_manager->getModelFile(sModel);
m_all_meshes[collectType] = irr_driver->getMesh(full_path);
std::string full_path = file_manager->getModelFile(model);
m_all_meshes[type] = irr_driver->getMesh(full_path);
if(!m_all_meshes[type])
{
std::ostringstream o;
o<<"Can't load model '"<<model<<"' for powerup type '"<<type<<"', aborting.";
throw std::runtime_error(o.str());
}
}
else
{
m_all_meshes[collectType] = 0;
m_all_extends[collectType] = btVector3(0.0f,0.0f,0.0f);
}
if(!m_all_meshes[collectType])
{
std::ostringstream o;
o<<"Can't load model '"<<sModel<<"' for '"<<sName<<"', aborting.";
throw std::runtime_error(o.str());
m_all_meshes[type] = 0;
m_all_extends[type] = btVector3(0.0f,0.0f,0.0f);
}
// Load special attributes for certain powerups
switch (collectType) {
switch (type) {
case POWERUP_BOWLING:
Bowling::init(lisp, m_all_meshes[collectType]); break;
Bowling::init(node, m_all_meshes[type]); break;
case POWERUP_PLUNGER:
Plunger::init(lisp, m_all_meshes[collectType]); break;
Plunger::init(node, m_all_meshes[type]); break;
case POWERUP_CAKE:
Cake::init(lisp, m_all_meshes[collectType]); break;
Cake::init(node, m_all_meshes[type]); break;
default:;
} // switch
} // LoadNode

View File

@ -27,19 +27,24 @@
#include "btBulletDynamicsCommon.h"
class Material;
class XMLNode;
// The anvil and parachute must be at the end of the enum, and the
// zipper just before them (see Powerup::hitBonusBox).
enum PowerupType {POWERUP_NOTHING,
POWERUP_BUBBLEGUM, POWERUP_CAKE,
POWERUP_FIRST,
POWERUP_BUBBLEGUM = POWERUP_FIRST,
POWERUP_CAKE,
POWERUP_BOWLING, POWERUP_ZIPPER, POWERUP_PLUNGER,
POWERUP_SWITCH,
POWERUP_PARACHUTE, POWERUP_ANVIL, //powerup.cpp assumes these two come last
POWERUP_PARACHUTE,
POWERUP_ANVIL, //powerup.cpp assumes these two come last
POWERUP_LAST=POWERUP_ANVIL,
POWERUP_MAX};
class PowerupManager
{
protected:
private:
Material* m_all_icons [POWERUP_MAX];
float m_all_max_distance[POWERUP_MAX]; // if a target is closer than this
float m_all_force_to_target[POWERUP_MAX]; // apply this force to move towards
@ -48,11 +53,13 @@ protected:
scene::IMesh *m_all_meshes[POWERUP_MAX];
btVector3 m_all_extends[POWERUP_MAX];
void LoadNode (const lisp::Lisp* lisp, int collectType);
PowerupType getPowerupType(const std::string &name);
public:
PowerupManager ();
void loadPowerups();
PowerupManager ();
~PowerupManager ();
void loadAllPowerups ();
void removeTextures ();
void Load (int collectType, const char* filename);
void LoadPowerup (PowerupType type, const XMLNode &node);
Material* getIcon (int type) const {return m_all_icons [type]; }
/** Returns the mesh for a certain powerup.
* \param type Mesh type for which the model is returned. */

View File

@ -613,7 +613,7 @@ int main(int argc, char *argv[] )
kart_properties_manager -> loadAllKarts ();
unlock_manager = new UnlockManager();
projectile_manager -> loadData ();
powerup_manager -> loadPowerups ();
powerup_manager -> loadAllPowerups ();
item_manager -> loadDefaultItems();
attachment_manager -> loadModels ();

View File

@ -617,7 +617,6 @@ void Track::loadTrackModel(unsigned int mode_id)
m_has_final_camera = false;
m_is_arena = false;
m_track_object_manager = new TrackObjectManager();
item_manager->setStyle();
// Load the graph only now: this function is called from world, after
// the race gui was created. The race gui is needed since it stores