Pol  Revision:cb584c9
musicrgn.cpp
Go to the documentation of this file.
1 
7 #include "musicrgn.h"
8 
9 #include "../clib/cfgelem.h"
10 #include "../clib/random.h"
11 #include "globals/uvars.h"
12 
13 namespace Pol
14 {
15 namespace Core
16 {
18 {
19  unsigned short midi_add;
20  while ( elem.remove_prop( "Midi", &midi_add ) )
21  {
22  midilist_.push_back( midi_add );
23  }
24 }
25 
27 {
28  return base::estimateSize() + 3 * sizeof( unsigned short* ) +
29  midilist_.capacity() * sizeof( unsigned short );
30 }
31 
32 unsigned short MusicRegion::getmidi() const
33 {
34  if ( !midilist_.empty() )
35  {
36  int idx = Clib::random_int( static_cast<int>( midilist_.size() - 1 ) );
37  return midilist_[idx];
38  }
39  else
40  {
41  return 0;
42  }
43 }
44 
46 {
47  gamestate.musicdef = new MusicDef( "Music" );
49  "regions/music.cfg", // preferred
50  "regions/regions.cfg", // other
51  "MusicRegion Region" );
52 }
53 }
54 }
void read_region_data(RegionGroupBase &grp, const char *preferred_filename, const char *other_filename, const char *tags_expected)
Definition: region.cpp:225
MusicDef * musicdef
Definition: uvars.h:152
RegionGroup< MusicRegion > MusicDef
Definition: uvars.h:96
unsigned short getmidi() const
Definition: musicrgn.cpp:32
void read_music_zones()
Definition: musicrgn.cpp:45
virtual size_t estimateSize() const
Definition: region.cpp:38
int random_int(int i)
Definition: random.cpp:34
std::vector< unsigned short > midilist_
Definition: musicrgn.h:43
GameState gamestate
Definition: uvars.cpp:74
bool remove_prop(const char *propname, std::string *value)
Definition: cfgfile.cpp:128
MusicRegion(Clib::ConfigElem &elem, RegionId id)
Definition: musicrgn.cpp:17
unsigned short RegionId
Definition: zone.h:23
virtual size_t estimateSize() const POL_OVERRIDE
Definition: musicrgn.cpp:26
Definition: berror.cpp:12