1 // Crimson Fields -- a game of tactical warfare
2 // Copyright (C) 2000-2007 Jens Granseuer
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
19 /////////////////////////////////////////////////////////////////////////
20 // lset.h - level set handling
21 // A level set contains the definitions of terrain and unit types as
22 // well as the corresponding graphics and sound data.
23 /////////////////////////////////////////////////////////////////////////
24 
25 #ifndef _INCLUDE_LSET_H
26 #define _INCLUDE_LSET_H
27 
28 #include <string>
29 
30 #include "gamedefs.h"
31 #include "sound.h"
32 #include "surface.h"
33 #include "lang.h"
34 
35 #define FID_UNITSET       MakeID('U','S','E','T')
36 #define FID_TERRAINSET    MakeID('T','S','E','T')
37 
38 // terrain type definitions
39 class TerrainType {
40 public:
41   int Load( MemBuffer &file );
42 
43   unsigned short tt_type;       // one (or more) of the TT_ defined above
44   unsigned short tt_image;
45   signed char tt_att_mod;       // attack modifier (-20% to +20%)
46   signed char tt_def_mod;       // defence modifier (-20% to +20%)
47   signed char tt_move;          // cost to cross hex type
48   char reserved;
49   unsigned long tt_color;       // color shown on the overview map display
50 };
51 
52 class UnitSet;
53 
54 class UnitType {
55 public:
UnitType(void)56   UnitType( void ) {}
57   int Load( MemBuffer &file, const UnitSet *set );
SetName(const char * name)58   void SetName( const char *name ) { ut_name = name; }
59 
Terrain(void)60   unsigned short Terrain( void ) const { return ut_terrain; }
Image(void)61   unsigned short Image( void ) const { return ut_image; }
Flags(void)62   unsigned short Flags( void ) const { return ut_flags; }
Speed(void)63   unsigned char Speed( void ) const { return ut_moves; }
Weight(void)64   unsigned char Weight( void ) const { return ut_weight; }
Armour(void)65   unsigned char Armour( void ) const { return ut_defence; }
66   unsigned char Firepower( unsigned long target_type ) const;
67   bool IsInFOF( unsigned short dist, unsigned long target_type ) const;
68   unsigned char MaxFOF( unsigned long target_type ) const;
69   unsigned char MinFOF( unsigned long target_type ) const;
Cost(void)70   unsigned char Cost( void ) const { return ut_build; }
Slots(void)71   unsigned char Slots( void ) const { return ut_trans_slots; }
MinWeight(void)72   unsigned char MinWeight( void ) const { return ut_trans_min_weight; }
MaxWeight(void)73   unsigned char MaxWeight( void ) const { return ut_trans_max_weight; }
Name(void)74   const char *Name( void ) const { return ut_name; }
MoveSound(void)75   SoundEffect *MoveSound( void ) const { return ut_snd_move; }
FireSound(void)76   SoundEffect *FireSound( void ) const { return ut_snd_fire; }
ID(void)77   unsigned char ID( void ) const { return ut_typeid; }
Portrait(void)78   signed char Portrait( void ) const { return ut_portrait; }
79 
80 protected:
81   unsigned short ut_terrain;		// wherever it may roam...
82   unsigned short ut_image;
83   unsigned short ut_flags;
84   unsigned char ut_moves;
85   unsigned char ut_weight;		// used by transports
86   unsigned char ut_defence;		// defensive strength
87   unsigned char ut_pow_ground;		// offensive strengths
88   unsigned char ut_pow_ship;
89   unsigned char ut_pow_air;
90   unsigned char ut_min_range_ground;
91   unsigned char ut_max_range_ground;
92   unsigned char ut_min_range_ship;
93   unsigned char ut_max_range_ship;
94   unsigned char ut_min_range_air;
95   unsigned char ut_max_range_air;
96   unsigned char ut_build;		// resources needed to build this unit type
97   unsigned char ut_trans_slots;		// max number of units the transport can carry
98   unsigned char ut_trans_min_weight;	// min weight of units the transport can carry
99   unsigned char ut_trans_max_weight;	// max weight of units the transport can carry
100   unsigned char ut_typeid;
101   signed char ut_portrait;		// portrait gfx index
102   SoundEffect *ut_snd_move;
103   SoundEffect *ut_snd_fire;
104   const char *ut_name;
105 };
106 
107 
108 #define DEFAULT_TILE_WIDTH    32
109 #define DEFAULT_TILE_HEIGHT   28
110 
111 // generic set of images
112 class TileSet {
113 public:
TileSet(void)114   TileSet( void ) : num_tiles(0) {}
~TileSet(void)115   virtual ~TileSet( void ) {}
116 
117   virtual int Load( MemBuffer &file, const char *setname );
118 
TileWidth(void)119   unsigned short TileWidth( void ) const { return DEFAULT_TILE_WIDTH; }
TileHeight(void)120   unsigned short TileHeight( void ) const { return DEFAULT_TILE_HEIGHT; }
TileShiftX(void)121   unsigned short TileShiftX( void ) const { return 9; }
TileShiftY(void)122   unsigned short TileShiftY( void ) const { return 14; }
123 
124   void DrawTile( unsigned short n, Surface *dest,
125                  short px, short py, const Rect &clip ) const;
GetName(void)126   const string &GetName( void ) const { return name; }
NumTiles(void)127   unsigned short NumTiles( void ) const { return num_tiles; }
128 
129 protected:
130   unsigned short num_tiles;
131   Surface tiles;
132   string name;
133 };
134 
135 class UnitSet : public TileSet {
136 public:
137   UnitSet( void );
138   ~UnitSet( void );
139 
140   int Load( MemBuffer &file, const char *setname );
141 
142   const UnitType *GetUnitInfo( unsigned short utid ) const;
143   SoundEffect *GetSound( unsigned short sfxid ) const;
GetPortrait(unsigned char ptid)144   Surface *GetPortrait( unsigned char ptid ) const { return &portraits[ptid]; }
UnitName(unsigned short utid)145   const char *UnitName( unsigned short utid ) const
146              { return unit_names.GetMsg( utid ); }
147 
148   void SetLocale( const string &lang );
149 
150 protected:
151   int LoadUnitTypes( MemBuffer &file );
152   int LoadSfx( MemBuffer &file );
153 
154   unsigned short num_sfx;
155 
156   UnitType *ut;
157   SoundEffect **sfx;
158   Surface *portraits;
159 
160   Locale unit_names;
161 };
162 
163 class TerrainSet : public TileSet {
164 public:
TerrainSet(void)165   TerrainSet( void ) : tt(0) {}
166   ~TerrainSet( void );
167 
168   int Load( MemBuffer &file, const char *setname );
169 
GetTerrainClassID(unsigned char num)170   unsigned short GetTerrainClassID( unsigned char num ) const { return classid[num]; }
171   const TerrainType *GetTerrainInfo( unsigned short ttid ) const;
172 
173   void DrawFog( Surface *dest, short px, short py, const Rect &clip ) const;
HexMask(void)174   const Surface &HexMask( void ) const { return fog; }
175 
176 protected:
177   int LoadTerrainTypes( MemBuffer &file );
178 
179   TerrainType *tt;
180   Surface fog;
181   unsigned short classid[10]; // IDs of the 10 most important terrain classes;
182                               // determines which images are shown in unit info dialog
183 };
184 
185 #endif	/* _INCLUDE_LSET_H */
186 
187