File: ed_mapcomponent.h

package info (click to toggle)
asc 2.6.1.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 81,740 kB
  • sloc: cpp: 158,704; sh: 11,544; ansic: 6,736; makefile: 604; perl: 138
file content (189 lines) | stat: -rw-r--r-- 6,981 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
    This file is part of Advanced Strategic Command; http://www.asc-hq.de
    Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger

    This program 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 2 of the License, or
    (at your option) any later version.

    This program 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 this program; see the file COPYING. If not, write to the 
    Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
    Boston, MA  02111-1307  USA
*/

#ifndef edmapcomponentH
#define edmapcomponentH

#include <algorithm>

#include <paragui.h>
#include <pgwidget.h>

#include "mapitemtype.h"
#include "vehicletype.h"
#include "buildingtype.h"
#include "objecttype.h"
#include "objects.h"


extern sigc::signal<void> filtersChangedSignal;


class Placeable {
   public:
      virtual ~Placeable() {};
      virtual bool supportMultiFieldPlacement() const = 0;
      virtual int place( const MapCoordinate& mc ) const = 0;
       //! just a wrapper so we have a function return void
      void vPlace( const MapCoordinate& mc ) const { place( mc ); };
      virtual Placeable* clone() const = 0;
      virtual bool remove ( const MapCoordinate& mc ) const { return false; };
      virtual ASCString getName() const = 0;
};

/** A MapComponent represents any kind of item that can be placed on the map by the user.
    It is the abstract class on which the Brush edit function operates
*/
class MapComponent : public Placeable {
       static int currentPlayer;
       static void setPlayer( int player );
       static bool initialized;
    protected:
       const MapItemType* mapItem;
       virtual Surface& getClippingSurface() const = 0;
       int getPlayer() const { return currentPlayer; };
    public:
       MapComponent( const MapItemType* item );
       static const int fontHeight = 20;
       const MapItemType* getItemType() const { return mapItem; };
       virtual int displayWidth() const = 0;
       virtual int displayHeight() const = 0;
       virtual void display( Surface& s, const SPoint& pos ) const = 0;
       virtual bool supportMultiFieldPlacement() const { return true; };
       void displayClip( PG_Widget* parent, SDL_Surface * surface, const PG_Rect & src, const PG_Rect & dst ) const;
       virtual ASCString getName() const  { return mapItem->getName(); };
};


template<class Item> class BasicItem : public MapComponent {
    protected:
       const Item* item;
       static Surface clippingSurface;
       Surface& getClippingSurface() const { return clippingSurface; };
    public:
       BasicItem( const Item* i ) : MapComponent(i), item( i ) {};
       ASCString getName() const { return item->getName(); };
       virtual int displayWidth() const { return Width(); };
       static  int Width() { return fieldsizex; };
       virtual int displayHeight() const { return Height(); };
       static int Height() { return fieldsizey; };
       virtual int getID() const { return item->id; };
};

template<class C> class ItemTypeSelector {};

class VehicleItem : public BasicItem<VehicleType> {
    public:
       VehicleItem( const VehicleType* vehicle ) : BasicItem<VehicleType>( vehicle ) {};
       virtual int place( const MapCoordinate& mc ) const ;
       static int place( GameMap* gamemap, const MapCoordinate& mc, const VehicleType* v, int owner );
       virtual void display( Surface& s, const SPoint& pos ) const;
       virtual MapComponent* clone() const { return new VehicleItem( item ); };
};
template<> class ItemTypeSelector<VehicleType> {
   public:
      typedef VehicleItem type;
};



class BuildingItem : public MapComponent {
       const BuildingType* bld;
       static Surface clippingSurface;
       static Surface fullSizeImage;
    protected:
       Surface& getClippingSurface() const { return clippingSurface; };
    public:
       BuildingItem( const BuildingType* building ) : MapComponent( building ), bld( building ) {};
       ASCString getName() const { return bld->getName(); };
       virtual int displayWidth() const { return Width(); };
       static  int Width() { return (fieldsizex+(4-1)*fielddistx+fielddisthalfx)/2; };
       virtual int displayHeight() const { return Height(); };
       static int Height() { return (fieldsizey+(6-1)*fielddisty)/2; };
       virtual bool supportMultiFieldPlacement() const { return false; };
       virtual int place( const MapCoordinate& mc ) const ;
       virtual void display( Surface& s, const SPoint& pos ) const;
       virtual MapComponent* clone() const { return new BuildingItem( bld ); };
       virtual int getID() const { return bld->id; };
};
template<> class ItemTypeSelector<BuildingType> {
   public:
      typedef BuildingItem type;
};


class ObjectItem : public BasicItem<ObjectType> {
    public:
       ObjectItem( const ObjectType* object ) : BasicItem<ObjectType>( object ) {};
       virtual int place( const MapCoordinate& mc ) const;
       virtual void display( Surface& s, const SPoint& pos ) const { item->display (s, pos); };
       virtual MapComponent* clone() const { return new ObjectItem( item ); };
       virtual bool remove ( const MapCoordinate& mc ) const;
};
template<> class ItemTypeSelector<ObjectType> {
   public:
      typedef ObjectItem type;
};


class TerrainItem : public BasicItem<TerrainType> {
    public:
       TerrainItem( const TerrainType* object ) : BasicItem<TerrainType>( object ) {};
       virtual int place( const MapCoordinate& mc ) const;
       virtual void display( Surface& s, const SPoint& pos ) const { item->weather[0]->paint (s, pos); };
       virtual MapComponent* clone() const { return new TerrainItem( item ); };
};

template<> class ItemTypeSelector<TerrainType> {
   public:
      typedef TerrainItem type;
};




class MineItem : public BasicItem<MineType> {
    public:
       MineItem( const MineType* object ) : BasicItem<MineType>( object ) {};
       virtual int place( const MapCoordinate& mc ) const;
       virtual void display( Surface& s, const SPoint& pos ) const { item->paint(s, pos); };
       virtual MapComponent* clone() const { return new MineItem( item ); };
};

template<> class ItemTypeSelector<MineType> {
   public:
      typedef MineItem type;
};



class LuaBrush : public Placeable {
   protected:
      ASCString script;
   public:
      LuaBrush( const ASCString& filename );
      bool supportMultiFieldPlacement() const { return false; };
      int place( const MapCoordinate& mc ) const;
      virtual LuaBrush* clone() const;
      virtual ASCString getName() const { return script; };
};


#endif