~ubuntu-branches/ubuntu/maverick/asc/maverick

« back to all changes in this revision

Viewing changes to source/itemrepository.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Eddy Petrișor, Gonéri Le Bouder, Cyril Brulebois, Barry deFreese
  • Date: 2008-01-08 19:54:18 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080108195418-n19fc4eobhhqxcy5
Tags: 2.0.1.0-1
[ Eddy Petrișor ]
* fixed Homepage semifield

[ Gonéri Le Bouder ]
* add a watchfile
* move homepage from the description to the new Homepage field

[ Cyril Brulebois ]
* Added Vcs-Svn and Vcs-Browser fields in the control file.

[ Barry deFreese ]
* Fix make-clean lintian warning
* New upstream release
* Bump debhelper build-dep to match compat
* Add desktop file
* Update watch file for new upstream naming
* Remove nostrip check from rules
* Bump Standards Version to 3.7.3
* Add myself to uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
1
2
/***************************************************************************
2
3
                          itemrepository.cpp   -  description
3
4
                             -------------------
25
26
#include "textfileparser.h"
26
27
#include "sgstream.h"
27
28
#include "textfile_evaluation.h"
28
 
 
29
 
#ifndef converter
30
 
#  include "dialog.h"
31
 
#  include "sg.h"
32
 
#else
33
 
 class ProgressBar {
34
 
    public:
35
 
       void point() {};
36
 
 };
37
 
ProgressBar* actprogressbar = NULL;
38
 
#endif
39
 
 
40
 
pobjecttype eisbrecherobject = NULL;
41
 
pobjecttype fahrspurobject = NULL;
42
 
 
 
29
#include "messaginghub.h"
 
30
 
 
31
 
 
32
SigC::Signal0<void> dataLoaderTicker;
 
33
 
 
34
 
 
35
const char* cacheFileName = "asc2.cache";
43
36
 
44
37
typedef vector<TextFileDataLoader*> DataLoaders;
45
38
DataLoaders dataLoaders;
60
53
}
61
54
 
62
55
 
 
56
template<class T> 
 
57
void ItemRepository<T>::RegisterID::operator() (int id )
 
58
{
 
59
   typename ObjectMap::iterator i = repository.hash.find ( id );
 
60
   if ( i != repository.hash.end() && i->second )
 
61
      duplicateIDError ( repository.typeName, id, object->location, object->name, i->second->location, i->second->name );
 
62
   repository.hash[ id ] = object;
 
63
}
 
64
 
 
65
 
63
66
 
64
67
template<class T>
65
68
void ItemRepository<T>::add( T* obj )
66
69
{
67
 
   typename ObjectMap::iterator i = hash.find ( obj->id );
68
 
   if ( i != hash.end() && i->second )
69
 
     duplicateIDError ( typeName, obj->id, obj->location, obj->name, i->second->location, i->second->name );
 
70
   RegisterID reg(*this, obj);
 
71
   reg( obj->id );
 
72
 
 
73
   for_each ( obj->secondaryIDs.begin(), obj->secondaryIDs.end(), reg );
 
74
 
70
75
 
71
76
   container.push_back( obj );
72
 
   hash[ obj->id ] = obj;
73
77
}
74
78
 
75
79
 
76
80
template<class T>
77
 
void ItemRepository<T>::readTextFiles( PropertyReadingContainer& prc, const ASCString& fileName, const ASCString& location )
 
81
void ItemRepositoryLoader<T>::readTextFiles( PropertyReadingContainer& prc, const ASCString& fileName, const ASCString& location )
78
82
{
79
83
   T* t = new T;
80
84
   t->runTextIO ( prc );
81
 
   prc.run();
82
85
 
83
86
   t->filename = fileName;
84
87
   t->location = location;
87
90
 
88
91
 
89
92
template<class T>
90
 
void ItemRepository<T>::read( tnstream& stream )
 
93
void ItemRepositoryLoader<T>::read( tnstream& stream )
91
94
{
92
95
   int version = stream.readInt();
 
96
   if ( version != 1 )
 
97
      throw tinvalidversion( stream.getLocation(), 1, version );
93
98
   int num = stream.readInt();
94
99
   for ( int i = 0; i< num; ++i ) {
95
 
      if ( actprogressbar )
96
 
        actprogressbar->point();
 
100
      dataLoaderTicker();
97
101
 
98
102
      T* t = new T;
99
103
      t->read( stream );
100
104
 
101
105
      t->filename = stream.readString();
102
106
      t->location = stream.readString();
 
107
      dataLoaderTicker();
103
108
 
104
109
      add ( t );
105
110
      // add ( T::newFromStream(stream ));
108
113
 
109
114
 
110
115
template<class T>
111
 
void ItemRepository<T>::write( tnstream& stream )
 
116
void ItemRepositoryLoader<T>::write( tnstream& stream )
112
117
{
113
118
   stream.writeInt( 1 );
114
 
   stream.writeInt( container.size() );
115
 
   for ( typename vector<T*>::iterator i = container.begin(); i != container.end(); ++i ) {
 
119
   stream.writeInt( ItemRepository<T>::container.size() );
 
120
   for ( typename ItemRepository<T>::ItemContainerType::iterator i = ItemRepository<T>::container.begin(); i != ItemRepository<T>::container.end(); ++i ) {
116
121
       (*i)->write( stream );
117
122
       stream.writeString ( (*i)->filename );
118
123
       stream.writeString ( (*i)->location );
119
124
   }
120
125
}
121
126
 
 
127
 
122
128
template<class T>
123
129
void ItemRepository<T>::addIdTranslation( int from, int to )
124
130
{
125
131
    idTranslation[from] = to;
126
132
}
127
133
 
128
 
 
129
 
ItemRepository<Vehicletype>  vehicleTypeRepository( "vehicletype" );
130
 
ItemRepository<TerrainType>  terrainTypeRepository( "terraintype" );
131
 
ItemRepository<ObjectType>   objectTypeRepository ( "objecttype" );
132
 
ItemRepository<BuildingType> buildingTypeRepository ("buildingtype");
133
 
ItemRepository<Technology>   technologyRepository ( "technology");
 
134
MineTypeRepository  mineTypeRepository;
 
135
 
 
136
 
 
137
MineTypeRepository::MineTypeRepository() : ItemRepository<MineType>("Mines")
 
138
{
 
139
   add( new MineType( cmantipersonnelmine ) );
 
140
   add( new MineType( cmantitankmine ) );
 
141
   add( new MineType( cmmooredmine ) );
 
142
   add( new MineType( cmfloatmine ) );
 
143
}
 
144
 
 
145
 
 
146
ItemRepositoryLoader<Vehicletype>  vehicleTypeRepository( "vehicletype" );
 
147
ItemRepositoryLoader<TerrainType>  terrainTypeRepository( "terraintype" );
 
148
ItemRepositoryLoader<ObjectType>   objectTypeRepository ( "objecttype" );
 
149
ItemRepositoryLoader<BuildingType> buildingTypeRepository ("buildingtype");
 
150
ItemRepositoryLoader<Technology>   technologyRepository ( "technology");
134
151
 
135
152
TechAdapterContainer techAdapterContainer;
136
153
 
145
162
      void readTextFiles(PropertyReadingContainer& prc, const ASCString& fileName, const ASCString& location ) {
146
163
           TechAdapter* ta = new TechAdapter;
147
164
           ta->runTextIO ( prc );
148
 
           prc.run();
149
165
 
150
166
           ta->filename = fileName;
151
167
           ta->location = location;
167
183
 
168
184
void  loadalltextfiles ( );
169
185
 
170
 
const int cacheVersion = 14;
 
186
const int cacheVersion = 22;
171
187
 
172
188
class FileCache {
173
189
      vector<tfindfile::FileInfo> actualFileInfo;
188
204
{
189
205
   tfindfile::FileInfo fi;
190
206
   {
191
 
      tfindfile f ( "*.con", tfindfile::AllDirs, tfindfile::OutsideContainer);
 
207
      tfindfile f ( "*.ascdat", tfindfile::AllDirs, tfindfile::OutsideContainer);
192
208
      while ( f.getnextname( fi ))
193
209
         actualFileInfo.push_back ( fi );
194
210
   }
198
214
         actualFileInfo.push_back ( fi );
199
215
   }
200
216
 
201
 
   if ( exist ( "asc.cache" )) {
202
 
      stream = new tnfilestream ( "asc.cache", tnstream::reading );
 
217
   if ( exist ( cacheFileName )) {
 
218
      stream = new tnfilestream ( cacheFileName, tnstream::reading );
203
219
      int version = stream->readInt();
204
220
 
205
221
      if ( version == cacheVersion )
256
272
   if ( stream )
257
273
      delete stream;
258
274
 
259
 
   stream = new tn_file_buf_stream ( "asc.cache", tnstream::writing );
 
275
   stream = new tn_file_buf_stream ( cacheFileName, tnstream::writing );
260
276
 
261
277
   stream->writeInt ( cacheVersion );
262
278
   writeClassContainer ( actualFileInfo, *stream );
310
326
         cache.load();
311
327
      }
312
328
      catch ( tinvalidversion err ) {
313
 
         fatalError("the cache seems to have been generated with a newer version of ASC than this one.\nPlease upgrade to that version, or delete asc.cache and try again");
 
329
         fatalError("the cache seems to have been generated with a newer version of ASC than this one.\nPlease upgrade to that version, or delete " + ASCString(cacheFileName) + " and try again");
314
330
      }
315
331
      displayLogMessage ( 4, "loading of cache completed\n");
316
332
   } else {
 
333
      MessagingHub::Instance().statusInformation("rebuilding data cache, please be patient");
 
334
      
317
335
      loadalltextfiles();
318
336
 
319
337
      for ( DataLoaders::iterator dl = dataLoaders.begin(); dl != dataLoaders.end(); ++dl) {
320
338
         TextPropertyList& tpl = textFileRepository[ (*dl)->getTypeName() ];
321
339
         for ( TextPropertyList::iterator i = tpl.begin(); i != tpl.end(); i++ ) {
322
 
            if ( actprogressbar )
323
 
              actprogressbar->point();
 
340
            dataLoaderTicker();
324
341
 
325
342
            if ( !(*i)->isAbstract() ) {
326
343
               PropertyReadingContainer pc ( (*dl)->getTypeName(), *i );
327
344
 
 
345
               displayLogMessage ( 5, "loading " + (*i)->location );
328
346
               (*dl)->readTextFiles( pc, (*i)->fileName, (*i)->location );
 
347
               displayLogMessage ( 5, " done\n");
329
348
            }
330
349
         }
331
350
 
345
364
      textFileRepository.clear();
346
365
   }
347
366
 
348
 
   eisbrecherobject = objectTypeRepository.getObject_byID( 6 );
349
 
   fahrspurobject   = objectTypeRepository.getObject_byID( 7 );
350
367
}
351
368
 
352
369
 
359
376
   ASCString c = ff.getnextname();
360
377
 
361
378
   while( !c.empty() ) {
362
 
      if ( actprogressbar )
363
 
         actprogressbar->point();
 
379
      dataLoaderTicker();
364
380
 
365
381
      tnfilestream s ( c, tnstream::reading );
366
382
 
388
404
      for ( TextPropertyList::iterator j = i->second.begin(); j != i->second.end(); j++ ) {
389
405
          displayLogMessage( 9, "Building inheritance: " + (*j)->location + "\n");
390
406
          (*j)->buildInheritance( i->second );
391
 
          if ( verbosity >= 10 )
 
407
          if ( MessagingHub::Instance().getVerbosity() >= 10 )
392
408
             (*j)->print();
393
409
      }
394
410
   }
401
417
 
402
418
 
403
419
 
404
 
vector<ItemFiltrationSystem::ItemFilter*> ItemFiltrationSystem::itemFilters;
 
420
deallocating_vector<ItemFiltrationSystem::ItemFilter*> ItemFiltrationSystem::itemFilters;
405
421
 
406
422
 
407
423
ItemFiltrationSystem::ItemFilter::ItemFilter( const ASCString& _name, const IntRangeArray& unitsetIDs, bool _active )
491
507
}
492
508
 
493
509
 
 
510
bool ItemFiltrationSystem::isFiltered( const Vehicletype* item )
 
511
{
 
512
   return isFiltered( Vehicle, item->id );
 
513
}
 
514
 
 
515
bool ItemFiltrationSystem::isFiltered( const BuildingType* item )
 
516
{
 
517
   return isFiltered( Building, item->id );
 
518
}
 
519
 
 
520
bool ItemFiltrationSystem::isFiltered( const ObjectType* item )
 
521
{
 
522
   return isFiltered( Object, item->id );
 
523
}
 
524
 
 
525
bool ItemFiltrationSystem::isFiltered( const TerrainType* item )
 
526
{
 
527
   return isFiltered( Terrain, item->id );
 
528
}
 
529
 
 
530
bool ItemFiltrationSystem::isFiltered( const MineType* item )
 
531
{
 
532
   return false;
 
533
}
 
534
 
 
535
 
494
536
void ItemFiltrationSystem::DataLoader::readTextFiles( PropertyReadingContainer& prc, const ASCString& fileName, const ASCString& location )
495
537
{
496
538
   ItemFilter* itf = new ItemFilter;
497
539
   itf->runTextIO ( prc );
498
 
   prc.run();
499
540
 
500
541
   // bmtt->filename = (*i)->fileName;
501
542
   // bmtt->location = (*i)->location;