~proyvind/doonlunacy/od2

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
190
#ifndef	__OD2SRC_RESOURCES_H__
#define	__OD2SRC_RESOURCES_H__	1

/* OD2 - Dune II Clone
 *  
 * Copyright (C) 2009 Robert Crossfield		<robert.crossfield@strobs.com>
 
 * 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 3 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.  If not, see <http://www.gnu.org/licenses/>.
 *  
 * 
 * $Id$
 * 
 */

#include <eastwood/Dune2File.h>
#include <eastwood/ExeFile.h>
#include <eastwood/IcnFile.h>
#include <eastwood/IniFile.h>
#include <eastwood/PakFile.h>
#include <eastwood/WsaFile.h>
#include <eastwood/SDL/Palette.h>
#include <eastwood/SDL/Surface.h>
#include <eastwood/FntFile.h>

class cScriptEmc;

class cResources : public cBase<cOD2> {
private:
	string							 _DataPath;											// Path to game data files
	dune2::Dune2File					*_D2Exe;

	map< string, cScriptEmc*>		 _dataEmc;
	map< string, eastwood::WsaFile*>			 _dataWSA;

	map< string, eastwood::PakFile*>							 _Paks;								// All game PAKs
	std::map<std::string, FntFile>				_fonts;
	map< string, eastwood::IniFile::KeyListHandle>			 _IniHandles;

	map< word, eastwood::SDL::Surface* >		 _Tiles;											// In-game tile images
			
	map< uint32_t, map< uint32_t, eastwood::SDL::Surface*> >	 _dataSHP;								// In-game graphics


	map< uint16_t, vector<uint16_t>*>	 _dataIconFrames;									// Loaded frames

	byte							 _angleAdjust[256];

	eastwood::IniFile					*_ini;												// Current loaded 'INI' scenario
	eastwood::MapFile					*_map;
	eastwood::IcnFile					*_icons;											// Loaded map Icons
	eastwood::SDL::Palette					*_paletteIBM;										// IBM Palette
	SDL_Palette						*_palIBM;

	word							 _tileFogWar, _tileBloom, _tileConcrete, _tileWall;	// Tile Reference IDs
	word							 _tileLand;											// 

	void							 angleAdjustBuild();
	string							 languageAdd( string pFilename );

	cScriptEmc						*emcGet( string pFilename );
	cScriptEmc						*emcUnitsLoad();
	cScriptEmc						*emcStructuresLoad();
	cScriptEmc						*emcHousesLoad();

	void							 pakLoad();														// Load all PAKs into '_Paks' map
	void							 mapTileIDsLoad();												// Load the Map-Tiles IDs into '_tile' variables

	void							 shpLoad();														// Load the 4 SHP files into _dataSHP
	void							 shpLoad( string Filename  );// Load the SHP file into _dataSHP

public:

									 cResources( cOD2 *pEngine, string pPath );
									~cResources();

	eastwood::SDL::Surface					*CpsGet( string fileName ) ;

	string							*fileRead( string pFileName);
	byte							*fileRead( string pFile, uint32_t	&pFileSize );		// Read from a file on disk
	byte							*fileRead( istream *pStream, uint32_t &pSize );		// Read from an istream
	istream							*fileOpen( string pFilename );						
	
	const FntFile&						getFont(std::string fileName);
	void							 IniLoad( string fileName );						// Load an ini in

	string							 IniStringGet( string pSection, string pVariable, string pDefault);
	uint32_t							 IniNumGet( string pSection, string pVariable, uint32_t pDefault );

	void							 IniSectionOpen( string pSection );
	string							 IniSectionNext( string pSection );
	void							 IniSectionClose(string pSection );

	uint16_t						actionFind( std::string pName );
	const dune2::Action				actionGet( uint16_t pIndex );

	uint32_t							 aiModeFind( string pName ) ;
	const std::vector<uint16_t>&				getAnims(uint16_t animIdx);
	const std::vector<uint16_t>&				getStructureAnims(uint16_t animIdx);
	const std::vector<uint16_t>&				getUnitAnims(uint16_t animIdx);	
	const std::vector<int16_t>&				angleTableGet();


	cScriptEmc						*emcStructuresGet();
	cScriptEmc						*emcUnitsGet();
	cScriptEmc						*emcTeamGet();

	uint16_t						houseFind( string pName );
	const dune2::House				houseGet( eHouse pHouse );

	uint16_t						structureFind(std::string pName);
	const dune2::Structure			structureGet(uint16_t pIndex);
	const std::vector<dune2::Structure>&		structureGet() { return _D2Exe->getStructureData(); }

	uint16_t						unitFind(std::string pName);
	const dune2::Unit				unitGet(uint16_t pIndex);
	const std::vector<dune2::Unit>&		unitGet() { return _D2Exe->getUnitData(); }
	
	
	const UPoint&						getLayoutTileDiff(uint8_t pIndex);

	const std::vector<uint16_t>&				getLayoutTiles(uint8_t pIndex);
	word							 foundationSizeGet( uint32_t pIndex );

	const dune2::File				fileTableGet( uint16_t pIndex );								// 

	const std::vector<int8_t>&				getMapOffsetIndexes();
	const std::vector<int8_t>&				getMapOffsets();

	const std::vector<dune2::MovementTile>&			getMovementTiles();

	const std::vector<int8_t>&				getMapSinTable();
	const std::vector<int8_t>&				getMapCosTable();	

	const MapInfo&						getMapScale(uint8_t pIndex);

	
	uint16_t							 mapIcnCount( word pIndex );
	vector<uint16_t>					*mapIcnFrameSetGet( word pIndex );

	eastwood::SDL::Surface					*mapTileGet( word pTileIndex );
	const vector<uint16_t>&					mapGet(uint16_t pIndex) { return (*_map)[pIndex]; }	

	const std::vector<uint16_t>&				mapMoveModGet();
	const std::vector<int8_t>&				mapModGet();	
	word							 movementFind( string pName );
	uint32_t							 movementNamesGet( string pName );
	uint16_t						getMovementUnk1(uint16_t pIndex);


	const std::vector<std::vector<int16_t> >&		placementPositionsGet();
	inline const std::vector<uint8_t>&			getEmc15CDA() { return _D2Exe->getEmc15CDA(); }

	const UPoint&						getUnitAngleFrameAdjust(uint8_t row, uint8_t frame);

	int8_t							unitFrameAdjustGet(uint8_t pIndex);
	const SPoint&						getUnitTurretFrame(uint8_t row, uint8_t frame);

	SDL_Palette						*paletteGet() { return _palIBM; }
	eastwood::SDL::Surface					*shpGet( word pIndex, word pMode );									// Don't free these surfaces

	eastwood::SDL::Surface					*wsaGet( string pFileName, uint32_t pFrame );

	void							 resourcePrepare();

	inline SDL_Color				*colorGet( word color ) { return &_palIBM->colors[color]; }

	inline word						 tileFogWar()						{ return _tileFogWar;	}
	inline word						 tileBloom()						{ return _tileBloom;	}
	inline word						 tileConcrete()						{ return _tileConcrete; }
	inline word						 tileWall()							{ return _tileWall;		}
	inline word						 tileLand()							{ return _tileLand;		}

	inline uint16_t						 getMapTileColor(uint16_t pTile)	{ return _D2Exe->getMapTileColors()[pTile]; }

	inline byte						 angleAdjustGet( uint32_t pIndex )	{ return  _angleAdjust[ pIndex & 0xFF ] & 0x07; }
};


#endif // __OD2SRC_RESOURCES_H__