diff --git a/configure.ac b/configure.ac index cb05d9307..6a1be93a4 100644 --- a/configure.ac +++ b/configure.ac @@ -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 \ diff --git a/data/bowling.projectile b/data/bowling.projectile deleted file mode 100644 index b8f041578..000000000 --- a/data/bowling.projectile +++ /dev/null @@ -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 ;; diff --git a/data/bubblegum.projectile b/data/bubblegum.projectile deleted file mode 100644 index 76e33d2e3..000000000 --- a/data/bubblegum.projectile +++ /dev/null @@ -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 ;; diff --git a/data/bubblegum.xml b/data/bubblegum.xml deleted file mode 100644 index b503dde70..000000000 --- a/data/bubblegum.xml +++ /dev/null @@ -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 ;; diff --git a/data/cake.projectile b/data/cake.projectile deleted file mode 100644 index 57bc8f203..000000000 --- a/data/cake.projectile +++ /dev/null @@ -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 ;; diff --git a/data/items.items b/data/items.items deleted file mode 100644 index e35c7e71b..000000000 --- a/data/items.items +++ /dev/null @@ -1,10 +0,0 @@ -;; -*- mode: lisp -*- - -(item - (gold "nitrotank-big" ) - (silver "nitrotank-small") - (green "banana" ) - (red "gift-box") -) - -;; EOF ;; diff --git a/data/items.xml b/data/items.xml new file mode 100644 index 000000000..5b5a50bb9 --- /dev/null +++ b/data/items.xml @@ -0,0 +1,12 @@ + + + + + + + + + + diff --git a/data/items/License.txt b/data/items/License.txt deleted file mode 100644 index 9170285db..000000000 --- a/data/items/License.txt +++ /dev/null @@ -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/] diff --git a/data/items/Makefile.am b/data/items/Makefile.am deleted file mode 100644 index 3ee15fcb9..000000000 --- a/data/items/Makefile.am +++ /dev/null @@ -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 - diff --git a/data/items/key.b3d b/data/items/key.b3d deleted file mode 100644 index b09455b0e..000000000 Binary files a/data/items/key.b3d and /dev/null differ diff --git a/data/models/License.txt b/data/models/License.txt index 9d84c3dd7..06a77eb19 100644 --- a/data/models/License.txt +++ b/data/models/License.txt @@ -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. \ No newline at end of file +* 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. diff --git a/data/items/banana.b3d b/data/models/banana.b3d similarity index 100% rename from data/items/banana.b3d rename to data/models/banana.b3d diff --git a/data/items/banana.png b/data/models/banana.png similarity index 100% rename from data/items/banana.png rename to data/models/banana.png diff --git a/data/items/bonusblock1.png b/data/models/bonusblock1.png similarity index 100% rename from data/items/bonusblock1.png rename to data/models/bonusblock1.png diff --git a/data/items/bonusblock2.b3d b/data/models/bonusblock2.b3d similarity index 100% rename from data/items/bonusblock2.b3d rename to data/models/bonusblock2.b3d diff --git a/data/items/bubblegum.b3d b/data/models/bubblegum.b3d similarity index 100% rename from data/items/bubblegum.b3d rename to data/models/bubblegum.b3d diff --git a/data/items/bubblegum.png b/data/models/bubblegum.png similarity index 100% rename from data/items/bubblegum.png rename to data/models/bubblegum.png diff --git a/data/items/gift-box.b3d b/data/models/gift-box.b3d similarity index 100% rename from data/items/gift-box.b3d rename to data/models/gift-box.b3d diff --git a/data/items/gift-box.png b/data/models/gift-box.png similarity index 100% rename from data/items/gift-box.png rename to data/models/gift-box.png diff --git a/data/items/gift-loop.png b/data/models/gift-loop.png similarity index 100% rename from data/items/gift-loop.png rename to data/models/gift-loop.png diff --git a/data/items/gold.png b/data/models/gold.png similarity index 100% rename from data/items/gold.png rename to data/models/gold.png diff --git a/data/items/nitro-tank.png b/data/models/nitro-tank.png similarity index 100% rename from data/items/nitro-tank.png rename to data/models/nitro-tank.png diff --git a/data/items/nitrotank-big.b3d b/data/models/nitrotank-big.b3d similarity index 100% rename from data/items/nitrotank-big.b3d rename to data/models/nitrotank-big.b3d diff --git a/data/items/nitrotank-small.b3d b/data/models/nitrotank-small.b3d similarity index 100% rename from data/items/nitrotank-small.b3d rename to data/models/nitrotank-small.b3d diff --git a/data/items/tank-blue.png b/data/models/tank-blue.png similarity index 100% rename from data/items/tank-blue.png rename to data/models/tank-blue.png diff --git a/data/items/tank-cyan.png b/data/models/tank-cyan.png similarity index 100% rename from data/items/tank-cyan.png rename to data/models/tank-cyan.png diff --git a/data/items/tank-green.png b/data/models/tank-green.png similarity index 100% rename from data/items/tank-green.png rename to data/models/tank-green.png diff --git a/data/items/warning.b3d b/data/models/warning.b3d similarity index 100% rename from data/items/warning.b3d rename to data/models/warning.b3d diff --git a/data/items/warning.png b/data/models/warning.png similarity index 100% rename from data/items/warning.png rename to data/models/warning.png diff --git a/data/plunger.projectile b/data/plunger.projectile deleted file mode 100644 index 9692eda32..000000000 --- a/data/plunger.projectile +++ /dev/null @@ -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 ;; diff --git a/data/powerup.xml b/data/powerup.xml new file mode 100644 index 000000000..479084a76 --- /dev/null +++ b/data/powerup.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index c87eac615..f086f5c3e 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -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(); diff --git a/src/items/bowling.cpp b/src/items/bowling.cpp index 90a4f01ef..4e146aaba 100644 --- a/src/items/bowling.cpp +++ b/src/items/bowling.cpp @@ -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 // ----------------------------------------------------------------------------- diff --git a/src/items/bowling.hpp b/src/items/bowling.hpp index 72e974921..65fe981f4 100644 --- a/src/items/bowling.hpp +++ b/src/items/bowling.hpp @@ -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; } diff --git a/src/items/cake.cpp b/src/items/cake.cpp index e106b5fdd..b362d7558 100644 --- a/src/items/cake.cpp +++ b/src/items/cake.cpp @@ -24,6 +24,7 @@ #include +#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 diff --git a/src/items/cake.hpp b/src/items/cake.hpp index d3207d0e7..16083b6c4 100644 --- a/src/items/cake.hpp +++ b/src/items/cake.hpp @@ -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 diff --git a/src/items/flyable.cpp b/src/items/flyable.cpp index 6b943125d..299cfb236 100644 --- a/src/items/flyable.cpp +++ b/src/items/flyable.cpp @@ -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; diff --git a/src/items/flyable.hpp b/src/items/flyable.hpp index dd7b5c095..88602821d 100644 --- a/src/items/flyable.hpp +++ b/src/items/flyable.hpp @@ -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); diff --git a/src/items/item_manager.cpp b/src/items/item_manager.cpp index 06c8eb8ac..809ebcec0 100644 --- a/src/items/item_manager.cpp +++ b/src/items/item_manager.cpp @@ -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 files; - file_manager->listFiles(files, file_manager->getItemsDir(), - /*is_full_path*/true, - /*make_full_path*/true); - for(std::set::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) diff --git a/src/items/item_manager.hpp b/src/items/item_manager.hpp index 2dd2ce197..0fc55debc 100644 --- a/src/items/item_manager.hpp +++ b/src/items/item_manager.hpp @@ -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 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 &switch_items); - void setStyle (); scene::IMesh* getItemModel (Item::ItemType type) {return m_item_mesh[type];} scene::IMesh* getOtherModel (const std::string modelName) diff --git a/src/items/plunger.cpp b/src/items/plunger.cpp index 4bc8704d8..bc1d1949a 100644 --- a/src/items/plunger.cpp +++ b/src/items/plunger.cpp @@ -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 // ----------------------------------------------------------------------------- diff --git a/src/items/plunger.hpp b/src/items/plunger.hpp index 36a795d38..4bad28910 100644 --- a/src/items/plunger.hpp +++ b/src/items/plunger.hpp @@ -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. */ diff --git a/src/items/powerup_manager.cpp b/src/items/powerup_manager.cpp index cc145bcd3..89f875f71 100644 --- a/src/items/powerup_manager.cpp +++ b/src/items/powerup_manager.cpp @@ -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; igetNumNodes(); 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 '"< loadAllKarts (); unlock_manager = new UnlockManager(); projectile_manager -> loadData (); - powerup_manager -> loadPowerups (); + powerup_manager -> loadAllPowerups (); item_manager -> loadDefaultItems(); attachment_manager -> loadModels (); diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 440cd9f83..9fc6977ac 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -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