ed_mapcomponent.h

Go to the documentation of this file.
00001 /*
00002     This file is part of Advanced Strategic Command; http://www.asc-hq.de
00003     Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; see the file COPYING. If not, write to the 
00017     Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00018     Boston, MA  02111-1307  USA
00019 */
00020 
00021 #ifndef edmapcomponentH
00022 #define edmapcomponentH
00023 
00024 #include <algorithm>
00025 
00026 #include <paragui.h>
00027 #include <pgwidget.h>
00028 
00029 #include "mapitemtype.h"
00030 #include "vehicletype.h"
00031 #include "buildingtype.h"
00032 #include "objecttype.h"
00033 #include "objects.h"
00034 
00035 
00036 extern SigC::Signal0<void> filtersChangedSignal;
00037 
00038 
00039 class Placeable {
00040    public:
00041       virtual ~Placeable() {};
00042       virtual bool supportMultiFieldPlacement() const = 0;
00043       virtual int place( const MapCoordinate& mc ) const = 0;
00045       void vPlace( const MapCoordinate& mc ) const { place( mc ); };
00046       virtual Placeable* clone() const = 0;
00047       virtual bool remove ( const MapCoordinate& mc ) const { return false; };
00048       virtual ASCString getName() const = 0;
00049 };
00050 
00054 class MapComponent : public Placeable {
00055        static int currentPlayer;
00056        static void setPlayer( int player );
00057        static bool initialized;
00058     protected:
00059        const MapItemType* mapItem;
00060        virtual Surface& getClippingSurface() const = 0;
00061        int getPlayer() const { return currentPlayer; };
00062     public:
00063        MapComponent( const MapItemType* item );
00064        static const int fontHeight = 20;
00065        const MapItemType* getItemType() const { return mapItem; };
00066        virtual int displayWidth() const = 0;
00067        virtual int displayHeight() const = 0;
00068        virtual void display( Surface& s, const SPoint& pos ) const = 0;
00069        virtual bool supportMultiFieldPlacement() const { return true; };
00070        void displayClip( PG_Widget* parent, SDL_Surface * surface, const PG_Rect & src, const PG_Rect & dst ) const;
00071        virtual ASCString getName() const  { return mapItem->getName(); };
00072 };
00073 
00074 
00075 template<class Item> class BasicItem : public MapComponent {
00076     protected:
00077        const Item* item;
00078        static Surface clippingSurface;
00079        Surface& getClippingSurface() const { return clippingSurface; };
00080     public:
00081        BasicItem( const Item* i ) : MapComponent(i), item( i ) {};
00082        ASCString getName() const { return item->getName(); };
00083        virtual int displayWidth() const { return Width(); };
00084        static  int Width() { return fieldsizex; };
00085        virtual int displayHeight() const { return Height(); };
00086        static int Height() { return fieldsizey; };
00087        virtual int getID() const { return item->id; };
00088 };
00089 
00090 template<class C> class ItemTypeSelector {};
00091 
00092 class VehicleItem : public BasicItem<VehicleType> {
00093     public:
00094        VehicleItem( const VehicleType* vehicle ) : BasicItem<VehicleType>( vehicle ) {};
00095        virtual int place( const MapCoordinate& mc ) const ;
00096        static int place( GameMap* gamemap, const MapCoordinate& mc, const VehicleType* v, int owner );
00097        virtual void display( Surface& s, const SPoint& pos ) const;
00098        virtual MapComponent* clone() const { return new VehicleItem( item ); };
00099 };
00100 template<> class ItemTypeSelector<VehicleType> {
00101    public:
00102       typedef VehicleItem type;
00103 };
00104 
00105 
00106 
00107 class BuildingItem : public MapComponent {
00108        const BuildingType* bld;
00109        static Surface clippingSurface;
00110        static Surface fullSizeImage;
00111     protected:
00112        Surface& getClippingSurface() const { return clippingSurface; };
00113     public:
00114        BuildingItem( const BuildingType* building ) : MapComponent( building ), bld( building ) {};
00115        ASCString getName() const { return bld->getName(); };
00116        virtual int displayWidth() const { return Width(); };
00117        static  int Width() { return (fieldsizex+(4-1)*fielddistx+fielddisthalfx)/2; };
00118        virtual int displayHeight() const { return Height(); };
00119        static int Height() { return (fieldsizey+(6-1)*fielddisty)/2; };
00120        virtual bool supportMultiFieldPlacement() const { return false; };
00121        virtual int place( const MapCoordinate& mc ) const ;
00122        virtual void display( Surface& s, const SPoint& pos ) const;
00123        virtual MapComponent* clone() const { return new BuildingItem( bld ); };
00124        virtual int getID() const { return bld->id; };
00125 };
00126 template<> class ItemTypeSelector<BuildingType> {
00127    public:
00128       typedef BuildingItem type;
00129 };
00130 
00131 
00132 class ObjectItem : public BasicItem<ObjectType> {
00133     public:
00134        ObjectItem( const ObjectType* object ) : BasicItem<ObjectType>( object ) {};
00135        virtual int place( const MapCoordinate& mc ) const;
00136        virtual void display( Surface& s, const SPoint& pos ) const { item->display (s, pos); };
00137        virtual MapComponent* clone() const { return new ObjectItem( item ); };
00138        virtual bool remove ( const MapCoordinate& mc ) const;
00139 };
00140 template<> class ItemTypeSelector<ObjectType> {
00141    public:
00142       typedef ObjectItem type;
00143 };
00144 
00145 
00146 class TerrainItem : public BasicItem<TerrainType> {
00147     public:
00148        TerrainItem( const TerrainType* object ) : BasicItem<TerrainType>( object ) {};
00149        virtual int place( const MapCoordinate& mc ) const;
00150        virtual void display( Surface& s, const SPoint& pos ) const { item->weather[0]->paint (s, pos); };
00151        virtual MapComponent* clone() const { return new TerrainItem( item ); };
00152 };
00153 
00154 template<> class ItemTypeSelector<TerrainType> {
00155    public:
00156       typedef TerrainItem type;
00157 };
00158 
00159 
00160 
00161 
00162 class MineItem : public BasicItem<MineType> {
00163     public:
00164        MineItem( const MineType* object ) : BasicItem<MineType>( object ) {};
00165        virtual int place( const MapCoordinate& mc ) const;
00166        virtual void display( Surface& s, const SPoint& pos ) const { item->paint(s, pos); };
00167        virtual MapComponent* clone() const { return new MineItem( item ); };
00168 };
00169 
00170 template<> class ItemTypeSelector<MineType> {
00171    public:
00172       typedef MineItem type;
00173 };
00174 
00175 
00176 
00177 class LuaBrush : public Placeable {
00178    protected:
00179       ASCString script;
00180    public:
00181       LuaBrush( const ASCString& filename );
00182       bool supportMultiFieldPlacement() const { return false; };
00183       int place( const MapCoordinate& mc ) const;
00184       virtual LuaBrush* clone() const;
00185       virtual ASCString getName() const { return script; };
00186 };
00187 
00188 
00189 #endif

Generated on Mon May 21 01:26:31 2012 for Advanced Strategic Command by  doxygen 1.5.1