/*Copyright (C) 2010-2012 Duncan Deveaux

This file is part of Hikou no mizu.

Hikou no mizu is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Hikou no mizu is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Hikou no mizu.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef DEF_ARENA
#define DEF_ARENA

#include "Engines/Physics/PhysicsEngine.hpp"
#include "Platform.hpp"

//Static loadFromXML method
#include "Engines/Resources/TextureManager.hpp"
#include "extlibs/TinyXML/tinyxml.h"

//Class representing an arena.
//It can contain platforms, specify players spawn position...
class Arena
{
    public:
        Arena();
        Arena(const Sprite &background, float width, float height, float ground, float gravity, float airFriction);
        void draw();
        
        void addPlatform(const Platform &platform, int platformIx = -1);
        void removePlatform(int platformIx);
        
        void applyToPhysics(PhysicsEngine &physicsEngine);
        void subscribeObjects(PhysicsEngine &physicsEngine);
        
        //Get and set methods
            //Graphics
        void setBackground(const Sprite &background);
        const Sprite &getBackground() const;
        
            //Physics
        void setWidth(float width);
        float getWidth() const;
        
        void setHeight(float height);
        float getHeight() const;
        
        void setGround(float ground);
        float getGround() const;
        
        void setGravity(float gravity);
        float getGravity() const;
        
        void setAirFriction(float airFriction);
        float getAirFriction() const;
        
            //Other
        void setPlayerSpawn(unsigned int ix, const Vector &playerSpawn);
        bool getPlayerSpawn(unsigned int ix, Vector &target) const;
        
        //Static methods
        static Arena loadFromXML(const std::string &name, const std::string &xmlPath, TextureManager &textureManager);
    
    private:
        void resizeBackground();
        
        Sprite m_background;
        
        float m_width, m_height, m_ground;
        float m_gravity, m_airFriction;
        
        std::vector<Platform> m_platformsList;
        std::map<unsigned int, Vector> m_playerSpawns;
};

#endif
