diff --git a/cpp/game_main.cpp b/cpp/game_main.cpp index 8ecb37597b..9dc8546112 100644 --- a/cpp/game_main.cpp +++ b/cpp/game_main.cpp @@ -168,13 +168,28 @@ GameMain::GameMain(Engine *engine) foundation_size.se ); + int creation_sound = building.sound_creation0; + int dying_sound = building.sound_dying; + + if (creation_sound == -1) { + creation_sound = building.sound_creation1; + } + + if (creation_sound == -1) { + creation_sound = building.sound_selection; + } + + if (dying_sound == -1) { + dying_sound = 323; //generic explosion sound + } + TestBuilding *newbuilding = new TestBuilding{ this->assetmanager.get_texture(tex_fname), building.name, foundation_size, building.terrain_id, - building.sound_creation0, - building.sound_dying, + creation_sound, + dying_sound }; this->available_buildings.push_back(newbuilding); @@ -386,18 +401,16 @@ bool GameMain::on_input(SDL_Event *e) { if (obj != nullptr) { obj->remove(); this->placed_buildings.erase(obj); + this->available_sounds[obj->sound_id_destruction].play(); delete obj; - - // TODO: play destruction sound - //int rand = util::random_range(0, obj->destruction_snd_count + 1); - //sounds[rand].play() } else { TestBuilding *newbuilding = this->available_buildings[this->editor_current_building]; int coloring = util::random_range(1, 8 + 1); TerrainObject *newobj = new TerrainObject( newbuilding->texture, newbuilding->foundation_size, - coloring + coloring, + newbuilding->sound_id_destruction ); // try to place the obj, it knows best whether it will fit. diff --git a/cpp/terrain_object.cpp b/cpp/terrain_object.cpp index a637a98062..a22a885c0d 100644 --- a/cpp/terrain_object.cpp +++ b/cpp/terrain_object.cpp @@ -17,11 +17,13 @@ namespace openage { TerrainObject::TerrainObject(Texture *tex, coord::tile_delta foundation_size, - unsigned player) { - this->placed = false; - this->texture = tex; - this->size = foundation_size; - this->player = player; + unsigned player, int sound_id_destruction) { + + this->placed = false; + this->texture = tex; + this->size = foundation_size; + this->player = player; + this->sound_id_destruction = sound_id_destruction; this->occupied_chunk_count = 0; } diff --git a/cpp/terrain_object.h b/cpp/terrain_object.h index 8c8e51acc5..993c85d5d6 100644 --- a/cpp/terrain_object.h +++ b/cpp/terrain_object.h @@ -29,13 +29,15 @@ terrain object class represents one immobile object on the map (building, trees, */ class TerrainObject { public: - TerrainObject(Texture *tex, coord::tile_delta foundation_size, unsigned player); + TerrainObject(Texture *tex, coord::tile_delta foundation_size, unsigned player, int sound_id_destruction); ~TerrainObject(); coord::tile start_pos; coord::phys3 draw_pos; coord::tile end_pos; + int sound_id_destruction; + /** * tests whether this terrain object will fit at the given position. *