1 /*
2  * This file is part of EasyRPG Player.
3  *
4  * EasyRPG Player is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * EasyRPG Player is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 // Headers
19 #include "spriteset_battle.h"
20 #include "cache.h"
21 #include "game_actors.h"
22 #include "game_battle.h"
23 #include "game_battler.h"
24 #include "game_enemy.h"
25 #include "game_enemyparty.h"
26 #include "game_party.h"
27 #include "game_screen.h"
28 #include "main_data.h"
29 #include "player.h"
30 #include "sprite_battler.h"
31 #include "sprite_actor.h"
32 #include "sprite_enemy.h"
33 
Spriteset_Battle(const std::string bg_name,int terrain_id)34 Spriteset_Battle::Spriteset_Battle(const std::string bg_name, int terrain_id)
35 {
36 	background_name = std::move(bg_name);
37 
38 	// Create background
39 	if (!background_name.empty()) {
40 		background.reset(new Background(background_name));
41 	} else {
42 		// Background verifies that the Terrain ID is valid
43 		background.reset(new Background(terrain_id));
44 	}
45 	Game_Battle::ChangeBackground(background_name);
46 
47 	// Create the sprites
48 	std::vector<Game_Battler*> battler;
49 	Main_Data::game_enemyparty->GetBattlers(battler);
50 	if (Player::IsRPG2k3()) {
51 		for (unsigned int i = 0; i < lcf::Data::actors.size(); ++i) {
52 			battler.push_back(Main_Data::game_actors->GetActor(i + 1));
53 		}
54 	}
55 
56 	timer1.reset(new Sprite_Timer(0));
57 	timer2.reset(new Sprite_Timer(1));
58 
59 	screen.reset(new Screen());
60 }
61 
Update()62 void Spriteset_Battle::Update() {
63 	Tone new_tone = Main_Data::game_screen->GetTone();
64 
65 	// Handle background change
66 	const auto& current_bg = Game_Battle::GetBackground();
67 	if (background_name != current_bg) {
68 		background_name = current_bg;
69 		if (!background_name.empty()) {
70 			background.reset(new Background(background_name));
71 		} else {
72 			background.reset();
73 		}
74 	}
75 	background->SetTone(new_tone);
76 	background->Update();
77 }
78