36 #include "Core-Level-JR.h"
38 laTileset::laTileset(
void)
40 strcpy(_strName,
"Empty Tileset");
46 laTileset::~laTileset(
void) {
48 MLOG(
"Tileset object deleted");
51 void laTileset::discard()
53 delete [] _arLitterPools;
55 std::vector<laElement>::iterator i;
56 for(i=_vElemements.begin(); i!=_vElemements.end(); i++)
60 MLOG(
"Tileset discarded");
63 void laTileset::load(
char* strFile)
70 rpgAttack::_pTS =
this;
72 progressReset(
"Loading tileset '%s'...", strFile);
75 char strFilePath[128]=M_DIR_TILESET;
79 laEnvironment_win32* pCE = ((laEnvironment_win32*)::laSystemIntegrator::getEnvironment());
83 strcat(strFilePath, strFile);
84 try{ fp.fileOpen(strFilePath); }
85 catch(
laError&){
throw laError(
"Unable to open tileset file '%s'", strFile); }
89 progressIncrease(0.05,
"Loading tileset section 'general'...");
91 try{ fp.readSectionSeparator(junk); }
92 catch(
laError& ){
throw laError(
"Section separator expected but not found (while parsing '%s')", strFile); }
94 ASSERT(!strcmp(junk,
"GENERAL"),
"Section [GENERAL] expected", junk);
96 fp.readText(_strName);
100 progressIncrease(0.05,
"Loading tileset section 'sky'...");
102 try{ fp.readSectionSeparator(junk); }
103 catch(
laError& ){
throw laError(
"Section separator expected but not found (while parsing '%s')", strFile); }
105 ASSERT(!strcmp(junk,
"SKY"),
"Section [SKY] expected", junk);
107 fp.readObj(&_TilesetSky, M_FALSE);
111 progressIncrease(0.05,
"Loading tileset section 'segment background'...");
113 try{ fp.readSectionSeparator(junk); }
114 catch(
laError& ){
throw laError(
"Section separator expected but not found (while parsing '%s')", strFile); }
116 ASSERT(!strcmp(junk,
"PER-SEGMENT BACKGROUND"),
"Section [PER-SEGMENT BACKGROUND] expected", junk);
118 fp.readUnsigned(&_nSegmentBackgroundCount);
119 strSegBgNames =
new char [_nSegmentBackgroundCount*128];
121 for(i=0; i<_nSegmentBackgroundCount; i++)
122 fp.readText(strSegBgNames+i*128);
126 progressIncrease(0.05,
"Loading tileset section 'litter-pools'...");
128 try{ fp.readSectionSeparator(junk); }
129 catch(
laError&){
throw laError(
"Section separator expected but not found (while parsing '%s')", strFile); }
131 ASSERT(!strcmp(junk,
"LITTER POOLS"),
"Section [LITTER POOLS] expected", junk);
133 fp.readUnsigned(&_nLitterPoolsCount);
136 for(i=0; i<_nLitterPoolsCount; i++)
137 fp.readObj(_arLitterPools+i);
141 progressIncrease(0.05,
"Loading tileset section 'litter-pools'...");
143 try{ fp.readSectionSeparator(junk); }
144 catch(
laError&){
throw laError(
"Section separator expected but not found (while parsing '%s')", strFile); }
146 ASSERT(!strcmp(junk,
"TS INCLUDES"),
"Section [TS INCLUDES] expected", junk);
149 _vElemements.clear();
152 char strIncludeFile[128] =
"";
153 fp.readText(strIncludeFile);
157 if( strcmp(strIncludeFile,
"END") )
159 progressIncrease( 0,
"Loading TS INCLUDE '%s'", strIncludeFile);
160 fp_include.fileOpen(strIncludeFile);
167 }
while( pfp != &fp );
172 progressIncrease(
M_ABS(0.9-progress()) ,
"Locating elements...");
174 _pLightProperties = getElement( getElementIndex(
"light") );
175 _pFogProperties = getElement( getElementIndex(
"fog") );
176 _pBackgroundProperties = getElement( getElementIndex(
"global-background") );
180 for(i=0; i<_nSegmentBackgroundCount; i++)
182 _arSegmentBackground[i] = getElementIndex(strSegBgNames+i*128);
184 _arSegmentBackground[i] < getElementCnt(),
185 "Element was requested as segment background but not found",
186 strSegBgNames+i*128);
188 MLOG(
"All segment backgrounds located...");
192 for(i=0; i<_nLitterPoolsCount; i++)
193 _arLitterPools[i].setTS(
this);
195 progressIncrease(0.1,
"Tileset loaded.");
203 progressIncrease(0.6/150,
"Loading tileset element %d...", _vElemements.size());
209 (_vElemements.end()-1)->load(pfp);
213 ASSERT( !strcmp(pe.getText(),
"END"),
214 "Corrupted element encountered (%d) \nWhy: %s ",
215 (_vElemements.size()-1), pe.getText());
217 _vElemements.pop_back();
224 unsigned laTileset::getElementIndex(
char* strName)
226 std::vector<laElement>::iterator i;
229 for(i=_vElemements.begin(); i!=_vElemements.end(); i++)
231 if( !strcmp(strName, i->name() ) )
return n;
235 ASSERT(0,
"Element not found in the TS", strName);
238 laElement* laTileset::getElement(
unsigned i)
240 ASSERT(i<=_vElemements.size(),
"Invalid element", i);
241 return &(_vElemements[i]);
244 unsigned laTileset::getLitterPoolsIndex(
char*strName)
246 for(
unsigned i=0; i<_nLitterPoolsCount; i++)
248 if(!strcmp(strName, _arLitterPools[i].name()))
return i;
251 ASSERT(0,
"No litter pool with this name", strName);
257 void laTileset::animate(laTimer &t)
260 std::vector<laElement>::iterator i;
263 for(i=_vElemements.begin(); i!=_vElemements.end(); i++)
267 _dWaveOffset += WAVE_SPEED*t.delta();
268 _dOffset += t.delta();
271 _TilesetSky.animate(t);
Base Class for Tileset Elements.
"Litter pools" to be used for populating laLitterBox
#define M_ABS(a)
Return abs(a)