00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00040
00044 class MapComponent {
00045 static int currentPlayer;
00046 static void setPlayer( int player );
00047 static bool initialized;
00048 protected:
00049 const MapItemType* mapItem;
00050 virtual Surface& getClippingSurface() const = 0;
00051 int getPlayer() const { return currentPlayer; };
00052 public:
00053 MapComponent( const MapItemType* item );
00054 static const int fontHeight = 20;
00055 const MapItemType* getItemType() const { return mapItem; };
00056 virtual int displayWidth() const = 0;
00057 virtual int displayHeight() const = 0;
00058 virtual MapComponent* clone() const = 0;
00059 virtual int place( const MapCoordinate& mc ) const = 0;
00060 virtual bool remove ( const MapCoordinate& mc ) const { return false; };
00062 void vPlace( const MapCoordinate& mc ) const { place( mc ); };
00063 virtual void display( Surface& s, const SPoint& pos ) const = 0;
00064 virtual bool supportMultiFieldPlacement() const { return true; };
00065 void displayClip( PG_Widget* parent, SDL_Surface * surface, const PG_Rect & src, const PG_Rect & dst ) const;
00066 virtual ~MapComponent() {};
00067 };
00068
00069
00070 template<class Item> class BasicItem : public MapComponent {
00071 protected:
00072 const Item* item;
00073 static Surface clippingSurface;
00074 Surface& getClippingSurface() const { return clippingSurface; };
00075 public:
00076 BasicItem( const Item* i ) : MapComponent(i), item( i ) {};
00077 ASCString getName() const { return item->getName(); };
00078 virtual int displayWidth() const { return Width(); };
00079 static int Width() { return fieldsizex; };
00080 virtual int displayHeight() const { return Height(); };
00081 static int Height() { return fieldsizey; };
00082 virtual int getID() const { return item->id; };
00083 };
00084
00085 template<class C> class ItemTypeSelector {};
00086
00087 class VehicleItem : public BasicItem<Vehicletype> {
00088 public:
00089 VehicleItem( const Vehicletype* vehicle ) : BasicItem<Vehicletype>( vehicle ) {};
00090 virtual int place( const MapCoordinate& mc ) const ;
00091 virtual void display( Surface& s, const SPoint& pos ) const;
00092 virtual MapComponent* clone() const { return new VehicleItem( item ); };
00093 };
00094 template<> class ItemTypeSelector<Vehicletype> {
00095 public:
00096 typedef VehicleItem type;
00097 };
00098
00099
00100
00101 class BuildingItem : public MapComponent {
00102 const BuildingType* bld;
00103 static Surface clippingSurface;
00104 static Surface fullSizeImage;
00105 protected:
00106 Surface& getClippingSurface() const { return clippingSurface; };
00107 public:
00108 BuildingItem( const BuildingType* building ) : MapComponent( building ), bld( building ) {};
00109 ASCString getName() const { return bld->getName(); };
00110 virtual int displayWidth() const { return Width(); };
00111 static int Width() { return (fieldsizex+(4-1)*fielddistx+fielddisthalfx)/2; };
00112 virtual int displayHeight() const { return Height(); };
00113 static int Height() { return (fieldsizey+(6-1)*fielddisty)/2; };
00114 virtual bool supportMultiFieldPlacement() const { return false; };
00115 virtual int place( const MapCoordinate& mc ) const ;
00116 virtual void display( Surface& s, const SPoint& pos ) const;
00117 virtual MapComponent* clone() const { return new BuildingItem( bld ); };
00118 virtual int getID() const { return bld->id; };
00119 };
00120 template<> class ItemTypeSelector<BuildingType> {
00121 public:
00122 typedef BuildingItem type;
00123 };
00124
00125
00126 class ObjectItem : public BasicItem<ObjectType> {
00127 public:
00128 ObjectItem( const ObjectType* object ) : BasicItem<ObjectType>( object ) {};
00129 virtual int place( const MapCoordinate& mc ) const;
00130 virtual void display( Surface& s, const SPoint& pos ) const { item->display (s, pos); };
00131 virtual MapComponent* clone() const { return new ObjectItem( item ); };
00132 virtual bool remove ( const MapCoordinate& mc ) const;
00133 };
00134 template<> class ItemTypeSelector<ObjectType> {
00135 public:
00136 typedef ObjectItem type;
00137 };
00138
00139
00140 class TerrainItem : public BasicItem<TerrainType> {
00141 public:
00142 TerrainItem( const TerrainType* object ) : BasicItem<TerrainType>( object ) {};
00143 virtual int place( const MapCoordinate& mc ) const;
00144 virtual void display( Surface& s, const SPoint& pos ) const { item->weather[0]->paint (s, pos); };
00145 virtual MapComponent* clone() const { return new TerrainItem( item ); };
00146 };
00147
00148 template<> class ItemTypeSelector<TerrainType> {
00149 public:
00150 typedef TerrainItem type;
00151 };
00152
00153
00154
00155
00156 class MineItem : public BasicItem<MineType> {
00157 public:
00158 MineItem( const MineType* object ) : BasicItem<MineType>( object ) {};
00159 virtual int place( const MapCoordinate& mc ) const;
00160 virtual void display( Surface& s, const SPoint& pos ) const { item->paint(s, pos); };
00161 virtual MapComponent* clone() const { return new MineItem( item ); };
00162 };
00163
00164 template<> class ItemTypeSelector<MineType> {
00165 public:
00166 typedef MineItem type;
00167 };
00168
00169
00170
00171 #endif