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

« back to all changes in this revision

Viewing changes to source/soundList.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:
35
35
#include "basestrm.h"
36
36
#include "sgstream.h"
37
37
#include "stringtokenizer.h"
 
38
#include "textfiletags.h"
38
39
 
39
40
SoundList* SoundList::instance = NULL;
40
41
 
46
47
}
47
48
 
48
49
 
49
 
void SoundLoopManager :: activate ( )
 
50
void SoundLoopManager :: activate ( int dummy )
50
51
{
51
52
   if ( !active && sound ) {
52
53
      sound->playLoop();
71
72
      fatalError("SoundList::init() - Soundlist already initialized");
72
73
 
73
74
   instance = new SoundList;
 
75
   displayLogMessage ( 4, "  SoundList::init() : starting initialize ..." );
74
76
   instance->initialize ( );
 
77
   displayLogMessage ( 4, "  completed\n" );
 
78
 
75
79
}
76
80
 
77
 
void SoundList::readLine( PropertyContainer& pc, const ASCString& name, SoundList::Sample sample, int subtype, int fadeIn )
 
81
void SoundList::readLine( PropertyContainer& pc, const ASCString& name, SoundList::Sample sample, int subtype )
78
82
{
79
83
   vector<ASCString> labels;
80
84
   vector<ASCString> files;
85
89
 
86
90
   SoundAssignment s;
87
91
   if ( files.size() && !files[0].empty() )
88
 
      s.defaultSound = getSound( files[0], fadeIn );
 
92
      s.defaultSound = getSound( files[0] );
89
93
   else
90
94
      s.defaultSound = NULL;
91
95
 
93
97
   s.subType = subtype;
94
98
 
95
99
   for( int i = 0; i < labels.size() && i < files.size() ; i++ )
96
 
      s.snd[ copytoLower(labels[i]) ] = getSound( files[i], fadeIn );
 
100
      s.snd[ copytoLower(labels[i]) ] = getSound( files[i] );
97
101
 
98
102
   soundAssignments.push_back ( s );
99
103
}
107
111
      TextFormatParser tfp ( &s );
108
112
      tpg = tfp.run();
109
113
   }
110
 
   // auto_ptr<TextPropertyGroup> atpg ( tpg );
 
114
   auto_ptr<TextPropertyGroup> atpg ( tpg );
111
115
 
112
116
   PropertyReadingContainer pc ( "sounds", tpg );
113
117
 
114
118
   pc.openBracket("shoot");
 
119
   dataLoaderTicker();
 
120
    readLine( pc, "MACHINEGUN", SoundList::shooting, 6 );
 
121
   dataLoaderTicker();
115
122
    readLine( pc, "CRUISEMISSILE", SoundList::shooting, 0 );
 
123
   dataLoaderTicker();
116
124
    readLine( pc, "MINE", SoundList::shooting, 1 );
 
125
   dataLoaderTicker();
117
126
    readLine( pc, "BOMB", SoundList::shooting, 2 );
118
 
    readLine( pc, "AIRMISSILE", SoundList::shooting, 3 );
119
 
    readLine( pc, "GROUNDMISSILE", SoundList::shooting, 4 );
 
127
   dataLoaderTicker();
 
128
    readLine( pc, "LARGEMISSILE", SoundList::shooting, 3 );
 
129
   dataLoaderTicker();
 
130
    readLine( pc, "SMALLMISSILE", SoundList::shooting, 4 );
 
131
   dataLoaderTicker();
120
132
    readLine( pc, "TORPEDO", SoundList::shooting, 5 );
121
 
    readLine( pc, "MACHINEGUN", SoundList::shooting, 6 );
 
133
   dataLoaderTicker();
122
134
    readLine( pc, "CANNON", SoundList::shooting, 7 );
 
135
   dataLoaderTicker();
123
136
    readLine( pc, "LASER", SoundList::shooting, 10);
124
137
   pc.closeBracket();
125
138
 
 
139
   dataLoaderTicker();
126
140
   pc.openBracket("move");
127
141
    readLine( pc, "default", SoundList::moving, 0 );
 
142
   dataLoaderTicker();
128
143
    readLine( pc, "LIGHT_TRACKED_VEHICLE", SoundList::moving, 1 );
 
144
   dataLoaderTicker();
129
145
    readLine( pc, "MEDIUM_TRACKED_VEHICLE", SoundList::moving, 2 );
 
146
   dataLoaderTicker();
130
147
    readLine( pc, "HEAVY_TRACKED_VEHICLE", SoundList::moving, 3 );
 
148
   dataLoaderTicker();
131
149
    readLine( pc, "LIGHT_WHEELED_VEHICLE", SoundList::moving, 4 );
 
150
   dataLoaderTicker();
132
151
    readLine( pc, "MEDIUM_WHEELED_VEHICLE", SoundList::moving, 5 );
 
152
   dataLoaderTicker();
133
153
    readLine( pc, "HEAVY_WHEELED_VEHICLE", SoundList::moving, 6 );
 
154
   dataLoaderTicker();
134
155
    readLine( pc, "TROOPER", SoundList::moving, 7 );
 
156
   dataLoaderTicker();
135
157
    readLine( pc, "RAIL_VEHICLE", SoundList::moving, 8 );
 
158
   dataLoaderTicker();
136
159
    readLine( pc, "MEDIUM_AIRCRAFT", SoundList::moving, 9 );
 
160
   dataLoaderTicker();
137
161
    readLine( pc, "MEDIUM_SHIP", SoundList::moving, 10 );
 
162
   dataLoaderTicker();
138
163
    readLine( pc, "TURRET", SoundList::moving, 11 );
 
164
   dataLoaderTicker();
139
165
    readLine( pc, "LIGHT_AIRCRAFT", SoundList::moving, 12 );
 
166
   dataLoaderTicker();
140
167
    readLine( pc, "HEAVY_AIRCRAFT", SoundList::moving, 13 );
 
168
   dataLoaderTicker();
141
169
    readLine( pc, "LIGHT_SHIP", SoundList::moving, 14 );
 
170
   dataLoaderTicker();
142
171
    readLine( pc, "HEAVY_SHIP", SoundList::moving, 15 );
 
172
   dataLoaderTicker();
143
173
    readLine( pc, "HELICOPTER", SoundList::moving, 16 );
 
174
   dataLoaderTicker();
144
175
   pc.closeBracket();
145
176
 
146
177
   pc.openBracket("UserInterface");
147
178
    readLine( pc, "ACKNOWLEDGE", SoundList::menu_ack );
148
179
   pc.closeBracket();
 
180
   dataLoaderTicker();
149
181
   readLine( pc, "CONQUER_BUILDING", SoundList::conquer_building );
 
182
   dataLoaderTicker();
150
183
   readLine( pc, "UNIT_EXPLODES", SoundList::unitExplodes );
 
184
   dataLoaderTicker();
151
185
   readLine( pc, "BUILDING_COLLAPSES", SoundList::buildingCollapses );
 
186
   dataLoaderTicker();
152
187
   readLine( pc, "REFUEL", SoundList::refuel );
 
188
   dataLoaderTicker();
153
189
   readLine( pc, "REPAIR", SoundList::repair );
154
 
 
155
 
   pc.run();
 
190
   dataLoaderTicker();
 
191
   readLine( pc, "JUMPDRIVE", SoundList::jumpdrive );
156
192
 
157
193
}
158
194
 
159
 
Sound* SoundList::getSound( const ASCString& filename, int fadeIn )
 
195
Sound* SoundList::getSound( const ASCString& filename )
160
196
{
 
197
   if ( SoundSystem::getInstance()->isOff() )
 
198
      return NULL;
 
199
 
161
200
   displayLogMessage ( 5, " SoundList::getSound(1) : trying to acquire handle for sound %s \n", filename.c_str() );
162
201
 
163
202
   if ( soundFiles.find ( filename ) == soundFiles.end() ) {
164
203
     displayLogMessage ( 5, " Sound has not been loaded ...\n" );
165
 
     Sound* s = new Sound ( filename, fadeIn );
 
204
 
 
205
     Sound* s;
 
206
     if( filename.find(':') != ASCString::npos ) {
 
207
        ASCString primary = filename.substr( 0, filename.find(':'));
 
208
        ASCString secondary = filename.substr( filename.find(':')+1 );
 
209
        displayLogMessage ( 8, " this is a multipart sound\n" );
 
210
        s = new Sound( primary, secondary );
 
211
     } else {
 
212
        s = new Sound ( filename );
 
213
     }
 
214
 
 
215
      dataLoaderTicker();
 
216
 
 
217
 
166
218
     soundFiles[filename] = s;
167
219
     if ( s != NULL )
168
220
        displayLogMessage ( 5, " loading sound completed\n" );
175
227
}
176
228
 
177
229
 
178
 
Sound* SoundList::getSound( Sample snd, int subType, const ASCString& label )
 
230
Sound* SoundList::getSound( Sample snd, int subType, const ASCString& label, int height )
179
231
{
180
232
   if ( SoundSystem::getInstance()->isOff() )
181
233
      return NULL;
182
234
 
183
235
   if ( label.find ( "." ) != ASCString::npos ) {
184
 
      return getSound ( label, 0 );
 
236
      return getSound ( label );
185
237
   } else {
186
 
      
187
238
      ASCString newlabel = copytoLower(label);
 
239
 
188
240
      for ( vector<SoundAssignment>::iterator i = soundAssignments.begin(); i != soundAssignments.end(); i++ )
189
 
         if ( snd == i->sample && subType == i->subType )
 
241
         if ( snd == i->sample && subType == i->subType ) {
 
242
            if ( height >= 0 && height <= 7 )
 
243
               if ( i->snd.find( heightTags[height] ) != i->snd.end() ) {
 
244
                       displayLogMessage ( 10, ASCString(" SoundList::getSound(2) : heightlabel ") + heightTags[height] + " found, returning matching sound \n" );
 
245
                  return i->snd[heightTags[height]];
 
246
               }
 
247
 
190
248
            if ( newlabel.empty() || i->snd.find( newlabel ) == i->snd.end() ) {
191
249
                displayLogMessage ( 10, " SoundList::getSound(2) : label " + label + " not found, returning default sound \n" );
192
250
               if ( !i->defaultSound )
196
254
                    displayLogMessage ( 10, " SoundList::getSound(2) : label " + label + " found, returning matching sound \n" );
197
255
               return i->snd[newlabel];
198
256
            }
 
257
         }
199
258
   }
200
259
 
201
260
        displayLogMessage ( 10, " SoundList::getSound(2) : sound not found, returning NULL \n" );