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 #ifndef EP_GAME_VEHICLE_H
19 #define EP_GAME_VEHICLE_H
20 
21 // Headers
22 #include <string>
23 #include <lcf/rpg/music.h>
24 #include <lcf/rpg/savevehiclelocation.h>
25 #include "game_character.h"
26 
27 using Game_VehicleBase = Game_CharacterDataStorage<lcf::rpg::SaveVehicleLocation>;
28 
29 /**
30  * Game_Vehicle class.
31  */
32 class Game_Vehicle : public Game_VehicleBase {
33 public:
34 	enum Type {
35 		None = 0,
36 		Boat,
37 		Ship,
38 		Airship
39 	};
40 
41 	static const char TypeNames[4][8];
42 
43 	explicit Game_Vehicle(Type type);
44 
45 	/** Load from saved game */
46 	void SetSaveData(lcf::rpg::SaveVehicleLocation save);
47 
48 	/** @return save game data */
49 	lcf::rpg::SaveVehicleLocation GetSaveData() const;
50 
51 	/**
52 	 * Implementation of abstract methods
53 	 */
54 	/** @{ */
55 	void UpdateNextMovementAction() override;
56 	void UpdateAnimation() override;
57 	/** @} */
58 
59 	/** Update this for the current frame */
60 	void Update();
61 
62 	const lcf::rpg::Music& GetBGM();
63 	int GetVehicleType() const;
64 	bool IsInCurrentMap() const;
65 	bool IsInPosition(int x, int y) const override;
66 	bool IsVisible() const override;
67 	bool IsAscending() const;
68 	bool IsDescending() const;
69 	bool IsAscendingOrDescending() const;
70 	int GetAltitude() const;
71 	bool IsInUse() const;
72 	bool IsAboard() const;
73 	void SyncWithRider(const Game_Character* rider);
74 	bool AnimateAscentDescent();
75 	int GetScreenY(bool apply_shift = false, bool apply_jump = true) const override;
76 	bool CanLand() const;
77 	void StartAscent();
78 	void StartDescent();
79 	void SetDefaultDirection();
80 	void ForceLand();
81 
82 	/**
83 	 * Sets default sprite name. Usually the name of the graphic file.
84 	 *
85 	 * @param sprite_name new sprite name
86 	 * @param index the index of the new sprite.
87 	 */
88 	void SetOrigSpriteGraphic(std::string sprite_name, int index);
89 
90 	/** Gets the original sprite graphic name */
91 	StringView GetOrigSpriteName() const;
92 
93 	/** Gets the original sprite graphic index */
94 	int GetOrigSpriteIndex() const;
95 };
96 
SetOrigSpriteGraphic(std::string sprite_name,int index)97 inline void Game_Vehicle::SetOrigSpriteGraphic(std::string sprite_name, int index) {
98 	data()->orig_sprite_name = std::move(sprite_name);
99 	data()->orig_sprite_id = index;
100 }
101 
GetSaveData()102 inline lcf::rpg::SaveVehicleLocation Game_Vehicle::GetSaveData() const {
103 	return *data();
104 }
105 
IsInPosition(int x,int y)106 inline bool Game_Vehicle::IsInPosition(int x, int y) const {
107 	return IsInCurrentMap() && Game_Character::IsInPosition(x, y);
108 }
109 
IsAscending()110 inline bool Game_Vehicle::IsAscending() const {
111 	return data()->remaining_ascent > 0;
112 }
113 
IsDescending()114 inline bool Game_Vehicle::IsDescending() const {
115 	return data()->remaining_descent > 0;
116 }
117 
IsAscendingOrDescending()118 inline bool Game_Vehicle::IsAscendingOrDescending() const {
119 	return IsAscending() || IsDescending();
120 }
121 
IsVisible()122 inline bool Game_Vehicle::IsVisible() const {
123 	return IsInCurrentMap() && Game_Character::IsVisible();
124 }
125 
SetDefaultDirection()126 inline void Game_Vehicle::SetDefaultDirection() {
127 	SetDirection(Left);
128 	SetFacing(Left);
129 }
130 
GetVehicleType()131 inline int Game_Vehicle::GetVehicleType() const {
132 	return data()->vehicle;
133 }
134 
135 
136 #endif
137