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 "scene_teleport.h"
20 #include "game_party.h"
21 #include "game_player.h"
22 #include "game_system.h"
23 #include "input.h"
24 #include "transition.h"
25 
Scene_Teleport(Game_Actor & actor,const lcf::rpg::Skill & skill)26 Scene_Teleport::Scene_Teleport(Game_Actor& actor, const lcf::rpg::Skill& skill)
27 		: actor(&actor), skill(&skill) {
28 	type = Scene::Teleport;
29 }
30 
Scene_Teleport(const lcf::rpg::Item & item,const lcf::rpg::Skill & skill)31 Scene_Teleport::Scene_Teleport(const lcf::rpg::Item& item, const lcf::rpg::Skill& skill)
32 		: skill(&skill), item(&item) {
33 	type = Scene::Teleport;
34 	assert(item.skill_id == skill.ID && "Item doesn't invoke the skill");
35 }
36 
Start()37 void Scene_Teleport::Start() {
38 	teleport_window.reset(new Window_Teleport(0, SCREEN_TARGET_HEIGHT - 80, SCREEN_TARGET_WIDTH, 80));
39 	teleport_window->SetActive(true);
40 	teleport_window->SetIndex(0);
41 }
42 
Update()43 void Scene_Teleport::Update() {
44 	teleport_window->Update();
45 
46 	if (Input::IsTriggered(Input::DECISION)) {
47 		if (item) {
48 			Main_Data::game_party->ConsumeItemUse(item->ID);
49 		} else {
50 			Main_Data::game_party->UseSkill(skill->ID, actor, actor);
51 		}
52 
53 		Main_Data::game_system->SePlay(skill->sound_effect);
54 
55 		const lcf::rpg::SaveTarget& target = teleport_window->GetTarget();
56 
57 		Main_Data::game_player->ForceGetOffVehicle();
58 		Main_Data::game_player->ReserveTeleport(target);
59 
60 		Scene::PopUntil(Scene::Map);
61 	} else if (Input::IsTriggered(Input::CANCEL)) {
62 		Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Cancel));
63 
64 		Scene::Pop();
65 	}
66 }
67 
TransitionOut(SceneType next_scene)68 void Scene_Teleport::TransitionOut(SceneType next_scene) {
69 	if (next_scene == Map) {
70 		Transition::instance().InitErase(Transition::TransitionFadeOut, this);
71 	} else {
72 		Scene::TransitionOut(next_scene);
73 	}
74 }
75