Advanced Strategic Command
ed_mapcomponent.h
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 #ifndef edmapcomponentH
22 #define edmapcomponentH
23 
24 #include <algorithm>
25 
26 #include <paragui.h>
27 #include <pgwidget.h>
28 
29 #include "mapitemtype.h"
30 #include "vehicletype.h"
31 #include "buildingtype.h"
32 #include "objecttype.h"
33 #include "objects.h"
34 
35 
36 extern sigc::signal<void> filtersChangedSignal;
37 
38 
39 class Placeable {
40  public:
41  virtual ~Placeable() {};
42  virtual bool supportMultiFieldPlacement() const = 0;
43  virtual int place( const MapCoordinate& mc ) const = 0;
45  void vPlace( const MapCoordinate& mc ) const { place( mc ); };
46  virtual Placeable* clone() const = 0;
47  virtual bool remove ( const MapCoordinate& mc ) const { return false; };
48  virtual ASCString getName() const = 0;
49 };
50 
54 class MapComponent : public Placeable {
55  static int currentPlayer;
56  static void setPlayer( int player );
57  static bool initialized;
58  protected:
60  virtual Surface& getClippingSurface() const = 0;
61  int getPlayer() const { return currentPlayer; };
62  public:
63  MapComponent( const MapItemType* item );
64  static const int fontHeight = 20;
65  const MapItemType* getItemType() const { return mapItem; };
66  virtual int displayWidth() const = 0;
67  virtual int displayHeight() const = 0;
68  virtual void display( Surface& s, const SPoint& pos ) const = 0;
69  virtual bool supportMultiFieldPlacement() const { return true; };
70  void displayClip( PG_Widget* parent, SDL_Surface * surface, const PG_Rect & src, const PG_Rect & dst ) const;
71  virtual ASCString getName() const { return mapItem->getName(); };
72 };
73 
74 
75 template<class Item> class BasicItem : public MapComponent {
76  protected:
77  const Item* item;
80  public:
81  BasicItem( const Item* i ) : MapComponent(i), item( i ) {};
82  ASCString getName() const { return item->getName(); };
83  virtual int displayWidth() const { return Width(); };
84  static int Width() { return fieldsizex; };
85  virtual int displayHeight() const { return Height(); };
86  static int Height() { return fieldsizey; };
87  virtual int getID() const { return item->id; };
88 };
89 
90 template<class C> class ItemTypeSelector {};
91 
92 class VehicleItem : public BasicItem<VehicleType> {
93  public:
94  VehicleItem( const VehicleType* vehicle ) : BasicItem<VehicleType>( vehicle ) {};
95  virtual int place( const MapCoordinate& mc ) const ;
96  static int place( GameMap* gamemap, const MapCoordinate& mc, const VehicleType* v, int owner );
97  virtual void display( Surface& s, const SPoint& pos ) const;
98  virtual MapComponent* clone() const { return new VehicleItem( item ); };
99 };
100 template<> class ItemTypeSelector<VehicleType> {
101  public:
102  typedef VehicleItem type;
103 };
104 
105 
106 
107 class BuildingItem : public MapComponent {
108  const BuildingType* bld;
109  static Surface clippingSurface;
110  static Surface fullSizeImage;
111  protected:
112  Surface& getClippingSurface() const { return clippingSurface; };
113  public:
114  BuildingItem( const BuildingType* building ) : MapComponent( building ), bld( building ) {};
115  ASCString getName() const { return bld->getName(); };
116  virtual int displayWidth() const { return Width(); };
117  static int Width() { return (fieldsizex+(4-1)*fielddistx+fielddisthalfx)/2; };
118  virtual int displayHeight() const { return Height(); };
119  static int Height() { return (fieldsizey+(6-1)*fielddisty)/2; };
120  virtual bool supportMultiFieldPlacement() const { return false; };
121  virtual int place( const MapCoordinate& mc ) const ;
122  virtual void display( Surface& s, const SPoint& pos ) const;
123  virtual MapComponent* clone() const { return new BuildingItem( bld ); };
124  virtual int getID() const { return bld->id; };
125 };
126 template<> class ItemTypeSelector<BuildingType> {
127  public:
129 };
130 
131 
132 class ObjectItem : public BasicItem<ObjectType> {
133  public:
134  ObjectItem( const ObjectType* object ) : BasicItem<ObjectType>( object ) {};
135  virtual int place( const MapCoordinate& mc ) const;
136  virtual void display( Surface& s, const SPoint& pos ) const { item->display (s, pos); };
137  virtual MapComponent* clone() const { return new ObjectItem( item ); };
138  virtual bool remove ( const MapCoordinate& mc ) const;
139 };
140 template<> class ItemTypeSelector<ObjectType> {
141  public:
142  typedef ObjectItem type;
143 };
144 
145 
146 class TerrainItem : public BasicItem<TerrainType> {
147  public:
148  TerrainItem( const TerrainType* object ) : BasicItem<TerrainType>( object ) {};
149  virtual int place( const MapCoordinate& mc ) const;
150  virtual void display( Surface& s, const SPoint& pos ) const { item->weather[0]->paint (s, pos); };
151  virtual MapComponent* clone() const { return new TerrainItem( item ); };
152 };
153 
154 template<> class ItemTypeSelector<TerrainType> {
155  public:
156  typedef TerrainItem type;
157 };
158 
159 
160 
161 
162 class MineItem : public BasicItem<MineType> {
163  public:
164  MineItem( const MineType* object ) : BasicItem<MineType>( object ) {};
165  virtual int place( const MapCoordinate& mc ) const;
166  virtual void display( Surface& s, const SPoint& pos ) const { item->paint(s, pos); };
167  virtual MapComponent* clone() const { return new MineItem( item ); };
168 };
169 
170 template<> class ItemTypeSelector<MineType> {
171  public:
172  typedef MineItem type;
173 };
174 
175 
176 
177 class LuaBrush : public Placeable {
178  protected:
180  public:
181  LuaBrush( const ASCString& filename );
182  bool supportMultiFieldPlacement() const { return false; };
183  int place( const MapCoordinate& mc ) const;
184  virtual LuaBrush* clone() const;
185  virtual ASCString getName() const { return script; };
186 };
187 
188 
189 #endif
The type of a field.
Definition: terraintype.h:75
virtual void display(Surface &s, const SPoint &pos) const
sigc::signal< void > filtersChangedSignal
Definition: edselfnt.cpp:42
void vPlace(const MapCoordinate &mc) const
just a wrapper so we have a function return void
virtual bool supportMultiFieldPlacement() const =0
static int Height()
static int Width()
virtual int place(const MapCoordinate &mc) const
Definition: edselfnt.cpp:193
static int Height()
Weather * weather[cwettertypennum]
Definition: terraintype.h:140
virtual int place(const MapCoordinate &mc) const =0
TerrainItem(const TerrainType *object)
BasicItem(const Item *i)
const MapItemType * mapItem
virtual MapComponent * clone() const
virtual Surface & getClippingSurface() const =0
virtual int displayHeight() const
void display(Surface &surface, const SPoint &pos) const
displays the objecttype at x/y on the screen
Definition: objecttype.cpp:289
MapComponent(const MapItemType *item)
virtual LuaBrush * clone() const
virtual MapComponent * clone() const
void displayClip(PG_Widget *parent, SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst) const
Definition: edselfnt.cpp:101
LuaBrush(const ASCString &filename)
Surface & getClippingSurface() const
virtual int getID() const
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
const Item * item
virtual int place(const MapCoordinate &mc) const
Definition: edselfnt.cpp:275
int place(const MapCoordinate &mc) const
virtual int place(const MapCoordinate &mc) const
Definition: edselfnt.cpp:186
virtual void display(Surface &s, const SPoint &pos) const
Definition: edselfnt.cpp:218
#define fieldsizey
Definition: typen.h:441
#define fielddisthalfx
Definition: typen.h:435
The class describing properties that are common to all vehicles of a certain kind.
Definition: vehicletype.h:177
virtual bool supportMultiFieldPlacement() const
A MapComponent represents any kind of item that can be placed on the map by the user.
The class describing properties that are common to all buildings of a certain kind.
Definition: buildingtype.h:35
virtual ASCString getName() const
MineItem(const MineType *object)
The base class for everything that can be placed on a map field.
Definition: mapitemtype.h:16
virtual MapComponent * clone() const
virtual void display(Surface &s, const SPoint &pos) const
An object that can be placed on fields. Roads, pipelines and ditches are examples of objects...
Definition: objecttype.h:30
Coordinate on the twodimensional map.
Definition: typen.h:202
void paint(Surface &surface, const SPoint &pos) const
Definition: objects.cpp:41
virtual ~Placeable()
The interface for the buildingtype class.
virtual int displayHeight() const =0
ASCString script
virtual ASCString getName() const =0
#define fieldsizex
Definition: typen.h:440
virtual void display(Surface &s, const SPoint &pos) const
void paint(Surface &s, SPoint pos)
displays the image on the screen coordinates x1/y1
SDLmm::SPoint SPoint
Definition: surface.h:27
virtual bool supportMultiFieldPlacement() const
Surface & getClippingSurface() const
#define fielddistx
Definition: typen.h:433
virtual int displayWidth() const
virtual int displayWidth() const =0
virtual int displayHeight() const
static Surface clippingSurface
static const int fontHeight
BuildingItem(const BuildingType *building)
Mine and Objects which can be placed on a map field.
ASCString getName() const
virtual void display(Surface &s, const SPoint &pos) const =0
virtual int place(const MapCoordinate &mc) const
Definition: edselfnt.cpp:258
virtual ASCString getName() const
int getPlayer() const
VehicleItem(const VehicleType *vehicle)
ObjectItem(const ObjectType *object)
virtual ASCString getName() const =0
virtual void display(Surface &s, const SPoint &pos) const
const MapItemType * getItemType() const
virtual int place(const MapCoordinate &mc) const
Definition: edselfnt.cpp:236
bool supportMultiFieldPlacement() const
ASCString getName() const
virtual int displayWidth() const
virtual int getID() const
ASCString getName() const
static int Width()
virtual MapComponent * clone() const
virtual MapComponent * clone() const
#define fielddisty
Definition: typen.h:434
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
virtual Placeable * clone() const =0