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 "sprite_battler.h"
20 #include "game_battler.h"
21 #include "bitmap.h"
22 #include "cache.h"
23 #include "main_data.h"
24 #include "player.h"
25 #include <lcf/reader_util.h>
26 #include "output.h"
27 
Sprite_Battler(Game_Battler * battler,int index)28 Sprite_Battler::Sprite_Battler(Game_Battler* battler, int index) :
29 	battler(battler), battle_index(index) {
30 }
31 
~Sprite_Battler()32 Sprite_Battler::~Sprite_Battler() {
33 }
34 
ResetZ()35 void Sprite_Battler::ResetZ() {
36 	static_assert(Game_Battler::Type_Ally < Game_Battler::Type_Enemy, "Game_Battler enums re-ordered! Fix Z order logic here!");
37 
38 	constexpr int id_limit = 128;
39 
40 	const auto& graphic = GetBitmap();
41 	int y = battler->GetBattlePosition().y;
42 	if (battler->GetType() == Game_Battler::Type_Enemy && graphic) {
43 		y += graphic->GetHeight() / 2;
44 	} else if (battler->GetType() == Game_Battler::Type_Ally) {
45 		y += 24;
46 	}
47 
48 	int z = battler->GetType();
49 	z += y;
50 	z *= id_limit;
51 	z += id_limit - battle_index;
52 	z += Priority_Battler;
53 
54 	SetZ(z);
55 }
56 
57