Skip to content
This repository
Browse code

Created a script supervisor as a game mode component.

I replaced the custom scripting support in the battle media class
with it. The boot scripting support will also be done through
that component in another commit.

This will permit to have (scening) script support for any game mode.
  • Loading branch information...
commit 2b3ec1c91dafc33623ea072e6d41a5fa917be9f9 1 parent ad8b042
Yohann Ferreira authored
2  ValyriaTear.cbp
@@ -280,6 +280,8 @@
280 280 <Unit filename="src\engine\input.h" />
281 281 <Unit filename="src\engine\mode_manager.cpp" />
282 282 <Unit filename="src\engine\mode_manager.h" />
  283 + <Unit filename="src\engine\script_supervisor.cpp" />
  284 + <Unit filename="src\engine\script_supervisor.h" />
283 285 <Unit filename="src\engine\script\script.cpp" />
284 286 <Unit filename="src\engine\script\script.h" />
285 287 <Unit filename="src\engine\script\script_modify.cpp" />
38 dat/battles/desert_cave_battle_anim.lua
@@ -20,23 +20,24 @@ local fog_time_length = 8000;
20 20
21 21 function Initialize(battle_instance)
22 22 Battle = battle_instance;
  23 + Script = Battle:GetScriptSupervisor();
23 24 -- Load the creatures animated background
24   - anim_ids[0] = Battle:GetMedia():AddCustomAnimation("img/backdrops/battle/desert_cave/desert_cave_creatures.lua");
  25 + anim_ids[0] = Script:AddAnimation("img/backdrops/battle/desert_cave/desert_cave_creatures.lua");
25 26 -- Load small eyes animations
26   - anim_ids[1] = Battle:GetMedia():AddCustomAnimation("img/backdrops/battle/desert_cave/desert_cave_eyes1.lua");
27   - anim_ids[2] = Battle:GetMedia():AddCustomAnimation("img/backdrops/battle/desert_cave/desert_cave_eyes2.lua");
  27 + anim_ids[1] = Script:AddAnimation("img/backdrops/battle/desert_cave/desert_cave_eyes1.lua");
  28 + anim_ids[2] = Script:AddAnimation("img/backdrops/battle/desert_cave/desert_cave_eyes2.lua");
28 29 -- Load the water drop animation
29   - anim_ids[3] = Battle:GetMedia():AddCustomAnimation("img/backdrops/battle/desert_cave/desert_cave_waterdrop.lua");
  30 + anim_ids[3] = Script:AddAnimation("img/backdrops/battle/desert_cave/desert_cave_waterdrop.lua");
30 31 -- Load the water underground river animation
31   - anim_ids[4] = Battle:GetMedia():AddCustomAnimation("img/backdrops/battle/desert_cave/desert_cave_water.lua");
  32 + anim_ids[4] = Script:AddAnimation("img/backdrops/battle/desert_cave/desert_cave_water.lua");
32 33
33 34 -- Construct a timer used to display the fog with a custom alpha value and position
34 35 fog_timer = hoa_system.SystemTimer(fog_time_length, 0);
35 36 -- Load a fog image used later to be displayed dynamically on the battle ground
36   - fog_id = Battle:GetMedia():AddCustomImage("img/ambient/fog.png", 320.0, 256.0);
  37 + fog_id = Script:AddImage("img/ambient/fog.png", 320.0, 256.0);
37 38
38 39 -- Load a rock displayed in the foreground
39   - rock_id = Battle:GetMedia():AddCustomImage("img/backdrops/battle/rock.png", 54.0, 54.0);
  40 + rock_id = Script:AddImage("img/backdrops/battle/rock.png", 54.0, 54.0);
40 41 end
41 42
42 43
@@ -72,30 +73,27 @@ end
72 73 function DrawBackground()
73 74 -- Draw background main animations
74 75 -- Creatures
75   - Battle:GetMedia():DrawCustomAnimation(anim_ids[0], 814.0, 769.0 - 9.0);
  76 + Script:DrawAnimation(anim_ids[0], 814.0, 769.0 - 9.0);
76 77 -- Eyes 1
77   - Battle:GetMedia():DrawCustomAnimation(anim_ids[1], 28.0, 769.0 - 112.0);
  78 + Script:DrawAnimation(anim_ids[1], 28.0, 769.0 - 112.0);
78 79 -- Eyes 2
79   - Battle:GetMedia():DrawCustomAnimation(anim_ids[2], 503.0, 769.0 - 21.0);
  80 + Script:DrawAnimation(anim_ids[2], 503.0, 769.0 - 21.0);
80 81 -- Water drop
81   - Battle:GetMedia():DrawCustomAnimation(anim_ids[3], 200.0, 769.0 - 63.0);
  82 + Script:DrawAnimation(anim_ids[3], 200.0, 769.0 - 63.0);
82 83 -- Water
83   - Battle:GetMedia():DrawCustomAnimation(anim_ids[4], 235.0, 769.0 - 110.0);
  84 + Script:DrawAnimation(anim_ids[4], 235.0, 769.0 - 110.0);
84 85
85 86 -- Draw a rock in the background
86   - Battle:GetMedia():DrawCustomImage(rock_id, 800.0, 520.0, hoa_video.Color(1.0, 1.0, 1.0, 1.0));
  87 + Script:DrawImage(rock_id, 800.0, 520.0, hoa_video.Color(1.0, 1.0, 1.0, 1.0));
87 88 end
88 89
89 90
90 91 function DrawForeground()
91 92 -- Draw the rock in the foreground
92   - Battle:GetMedia():DrawCustomImage(rock_id, 300.0, 150.0, hoa_video.Color(1.0, 1.0, 1.0, 1.0));
93   -end
94   -
  93 + Script:DrawImage(rock_id, 300.0, 150.0, hoa_video.Color(1.0, 1.0, 1.0, 1.0));
95 94
96   -function DrawEffects()
97 95 -- Draw a random fog effect
98   - Battle:GetMedia():DrawCustomImage(fog_id, fog_x_position,
99   - fog_y_position,
100   - hoa_video.Color(1.0, 1.0, 1.0, fog_alpha));
  96 + Script:DrawImage(fog_id, fog_x_position,
  97 + fog_y_position,
  98 + hoa_video.Color(1.0, 1.0, 1.0, fog_alpha));
101 99 end
8 dat/config/debug_battle.lua
@@ -10,8 +10,8 @@ function BootBattleTest()
10 10 GlobalManager:AddCharacter(THANIS);
11 11 GlobalManager:AddToInventory(1, 5);
12 12
13   - -- local claudius = GlobalManager:GetCharacter(1);
14   - -- claudius:AddSkill(10001);
  13 + -- local bronann = GlobalManager:GetCharacter(1);
  14 + -- bronann:AddSkill(10001);
15 15
16 16 local battle = hoa_battle.BattleMode();
17 17 battle:AddEnemy(6);
@@ -21,8 +21,8 @@ function BootBattleTest()
21 21 battle:AddEnemy(10);
22 22 battle:AddEnemy(11);
23 23 battle:AddEnemy(12);
24   - battle:AddBattleScript("dat/battles/desert_cave_battle_anim.lua");
25   - --battle:AddBattleScript("dat/battles/tutorial_battle_dialogs.lua");
  24 + battle:GetScriptSupervisor():AddScript("dat/battles/desert_cave_battle_anim.lua");
  25 + --battle:GetScriptSupervisor():AddScript("dat/battles/tutorial_battle_dialogs.lua");
26 26
27 27 ModeManager:Push(battle, false, false);
28 28 end
2  src/CMakeLists.txt
@@ -276,6 +276,8 @@ engine/effect_supervisor.h
276 276 engine/effect_supervisor.cpp
277 277 engine/mode_manager.h
278 278 engine/mode_manager.cpp
  279 +engine/script_supervisor.h
  280 +engine/script_supervisor.cpp
279 281 engine/system.cpp
280 282 engine/system.h
281 283 engine/video/video.h
11 src/engine/engine_bindings.cpp
@@ -69,6 +69,16 @@ void BindEngineCode() {
69 69 {
70 70 using namespace hoa_mode_manager;
71 71
  72 + module(hoa_script::ScriptManager->GetGlobalState(), "hoa_mode_manager")
  73 + [
  74 + class_<ScriptSupervisor>("ScriptSupervisor")
  75 + .def("AddScript", &ScriptSupervisor::AddScript)
  76 + .def("AddAnimation", &ScriptSupervisor::AddAnimation)
  77 + .def("AddImage", &ScriptSupervisor::AddImage)
  78 + .def("DrawImage", &ScriptSupervisor::DrawImage)
  79 + .def("DrawAnimation", &ScriptSupervisor::DrawAnimation)
  80 + ];
  81 +
72 82 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_mode_manager")
73 83 [
74 84 class_<EffectSupervisor>("EffectSupervisor")
@@ -91,6 +101,7 @@ void BindEngineCode() {
91 101 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_mode_manager")
92 102 [
93 103 class_<GameMode>("GameMode")
  104 + .def("GetScriptSupervisor", &GameMode::GetScriptSupervisor)
94 105 .def("GetEffectSupervisor", &GameMode::GetEffectSupervisor)
95 106 .def("GetParticleManager", &GameMode::GetParticleManager)
96 107 ];
1  src/engine/mode_manager.cpp
@@ -58,6 +58,7 @@ GameMode::~GameMode() {
58 58 void GameMode::Update() {
59 59 uint32 frame_time = hoa_system::SystemManager->GetUpdateTime();
60 60
  61 + _script_supervisor.Update();
61 62 _effect_supervisor.Update(frame_time);
62 63 _particle_manager.Update(frame_time);
63 64 }
9 src/engine/mode_manager.h
@@ -18,6 +18,7 @@
18 18
19 19 #include "effect_supervisor.h"
20 20 #include "engine/video/particle_manager.h"
  21 +#include "engine/script_supervisor.h"
21 22
22 23 //! All calls to the mode management code are wrapped inside this namespace
23 24 namespace hoa_mode_manager {
@@ -74,7 +75,7 @@ class GameMode {
74 75 GameMode();
75 76 //! \param mt The mode_type to set the new GameMode object to.
76 77 GameMode(uint8 mt);
77   - //! Destructor is virutal, since the inherited class holds all the important data.
  78 +
78 79 virtual ~GameMode();
79 80
80 81 //! Updates the state of the game mode.
@@ -106,7 +107,13 @@ class GameMode {
106 107 ParticleManager& GetParticleManager()
107 108 { return _particle_manager; }
108 109
  110 + ScriptSupervisor& GetScriptSupervisor()
  111 + { return _script_supervisor; }
  112 +
109 113 private:
  114 + //! \brief Handles all the custom scripted animation for the given mode.
  115 + ScriptSupervisor _script_supervisor;
  116 +
110 117 //! \brief Handles the work around ambient effects for the given mode.
111 118 EffectSupervisor _effect_supervisor;
112 119
135 src/engine/script_supervisor.cpp
... ... @@ -0,0 +1,135 @@
  1 +///////////////////////////////////////////////////////////////////////////////
  2 +// Copyright (C) 2012 by Bertram (Yohann Ferreira)
  3 +// All Rights Reserved
  4 +//
  5 +// This code is licensed under the GNU GPL version 2. It is free software
  6 +// and you may modify it and/or redistribute it under the terms of this license.
  7 +// See http://www.gnu.org/copyleft/gpl.html for details.
  8 +///////////////////////////////////////////////////////////////////////////////
  9 +
  10 +/** ****************************************************************************
  11 +*** \file script_supervisor.cpp
  12 +*** \author Yohann Ferreira, yohann ferreira orange fre
  13 +*** \brief Source file for managing scriptable animated effects for any game mode.
  14 +*** ***************************************************************************/
  15 +
  16 +#include "engine/script_supervisor.h"
  17 +
  18 +#include "engine/mode_manager.h"
  19 +
  20 +using namespace hoa_video;
  21 +using namespace hoa_script;
  22 +
  23 +void ScriptSupervisor::Initialize(hoa_mode_manager::GameMode* gm) {
  24 + // Open every possible scene script files registered and process them.
  25 + for (uint32 i = 0; i < _script_filenames.size(); ++i) {
  26 + ReadScriptDescriptor scene_script;
  27 + if (!scene_script.OpenFile(_script_filenames[i]))
  28 + continue;
  29 +
  30 + if (scene_script.OpenTablespace().empty()) {
  31 + PRINT_ERROR << "The scene script file: " << _script_filenames[i]
  32 + << "has not set a correct namespace" << std::endl;
  33 + continue;
  34 + }
  35 +
  36 + _reset_functions.push_back(scene_script.ReadFunctionPointer("Reset"));
  37 + _update_functions.push_back(scene_script.ReadFunctionPointer("Update"));
  38 + _draw_background_functions.push_back(scene_script.ReadFunctionPointer("DrawBackground"));
  39 + _draw_foreground_functions.push_back(scene_script.ReadFunctionPointer("DrawForeground"));
  40 + _draw_post_effects_functions.push_back(scene_script.ReadFunctionPointer("DrawPostEffects"));
  41 +
  42 + // Trigger the Initialize functions in the loading order.
  43 + ScriptObject init_function = scene_script.ReadFunctionPointer("Initialize");
  44 + if (init_function.is_valid() && gm)
  45 + ScriptCallFunction<void>(init_function, gm);
  46 + else
  47 + PRINT_ERROR << "Couldn't initialize the scene component" << std::endl; // Should never happen
  48 +
  49 + scene_script.CloseTable(); // The tablespace
  50 + scene_script.CloseFile();
  51 + }
  52 +}
  53 +
  54 +void ScriptSupervisor::SetDrawFlag(hoa_video::VIDEO_DRAW_FLAGS draw_flag) {
  55 + VideoManager->SetDrawFlags(draw_flag, 0);
  56 +}
  57 +
  58 +void ScriptSupervisor::Reset() {
  59 + // Updates custom scripts
  60 + for (uint32 i = 0; i < _reset_functions.size(); ++i)
  61 + ReadScriptDescriptor::RunScriptObject(_reset_functions[i]);
  62 +}
  63 +
  64 +void ScriptSupervisor::Update() {
  65 + // Update custom animations
  66 + for (uint32 i = 0; i < _script_animations.size(); ++i)
  67 + _script_animations[i].Update();
  68 +
  69 + // Updates custom scripts
  70 + for (uint32 i = 0; i < _update_functions.size(); ++i)
  71 + ReadScriptDescriptor::RunScriptObject(_update_functions[i]);
  72 +}
  73 +
  74 +
  75 +void ScriptSupervisor::DrawBackground() {
  76 + // Handles custom scripted draw before sprites
  77 + for (uint32 i = 0; i < _draw_background_functions.size(); ++i)
  78 + ReadScriptDescriptor::RunScriptObject(_draw_background_functions[i]);
  79 +}
  80 +
  81 +
  82 +void ScriptSupervisor::DrawForeground() {
  83 + for (uint32 i = 0; i < _draw_foreground_functions.size(); ++i)
  84 + ReadScriptDescriptor::RunScriptObject(_draw_foreground_functions[i]);
  85 +}
  86 +
  87 +void ScriptSupervisor::DrawPostEffects() {
  88 + for (uint32 i = 0; i < _draw_post_effects_functions.size(); ++i)
  89 + ReadScriptDescriptor::RunScriptObject(_draw_post_effects_functions[i]);
  90 +}
  91 +
  92 +int32 ScriptSupervisor::AddAnimation(const std::string& filename) {
  93 + AnimatedImage anim;
  94 + if (!anim.LoadFromAnimationScript(filename)) {
  95 + PRINT_WARNING << "The animation file could not be loaded: " << filename << std::endl;
  96 + return -1;
  97 + }
  98 +
  99 + _script_animations.push_back(anim);
  100 +
  101 + int32 id = _script_animations.size() - 1;
  102 + return id;
  103 +}
  104 +
  105 +
  106 +void ScriptSupervisor::DrawAnimation(int32 id, float x, float y) {
  107 + if (id < 0 || id > static_cast<int32>(_script_animations.size()) - 1)
  108 + return;
  109 +
  110 + VideoManager->Move(x, y);
  111 + _script_animations[id].Draw();
  112 +}
  113 +
  114 +
  115 +int32 ScriptSupervisor::AddImage(const std::string& filename, float width,
  116 + float height) {
  117 + StillImage img;
  118 + if (!img.Load(filename, width, height)) {
  119 + PRINT_WARNING << "The image file could not be loaded: " << filename << std::endl;
  120 + return -1;
  121 + }
  122 +
  123 + _script_images.push_back(img);
  124 +
  125 + int32 id = _script_images.size() - 1;
  126 + return id;
  127 +}
  128 +
  129 +void ScriptSupervisor::DrawImage(int32 id, float x, float y, Color color) {
  130 + if (id < 0 || id > static_cast<int32>(_script_images.size()) - 1)
  131 + return;
  132 +
  133 + VideoManager->Move(x, y);
  134 + _script_images[id].Draw(color);
  135 +}
144 src/engine/script_supervisor.h
... ... @@ -0,0 +1,144 @@
  1 +///////////////////////////////////////////////////////////////////////////////
  2 +// Copyright (C) 2012 by Bertram (Yohann Ferreira)
  3 +// All Rights Reserved
  4 +//
  5 +// This code is licensed under the GNU GPL version 2. It is free software
  6 +// and you may modify it and/or redistribute it under the terms of this license.
  7 +// See http://www.gnu.org/copyleft/gpl.html for details.
  8 +///////////////////////////////////////////////////////////////////////////////
  9 +
  10 +/** ***************************************************************************
  11 +*** \file script_supervisor.h
  12 +*** \author Yohann Ferreira, yohann ferreira orange fre
  13 +*** \brief Source file for managing scriptable animated effects for any game mode.
  14 +*** **************************************************************************/
  15 +
  16 +#ifndef __SCRIPT_SUPERVISOR_HEADER__
  17 +#define __SCRIPT_SUPERVISOR_HEADER__
  18 +
  19 +#include "utils.h"
  20 +#include "engine/script/script_read.h"
  21 +#include "engine/video/video.h"
  22 +
  23 +class ScriptSupervisor {
  24 +public:
  25 + ScriptSupervisor()
  26 + {}
  27 +
  28 + ~ScriptSupervisor()
  29 + {}
  30 +
  31 + /** \brief Sets the name of the script to execute during the game mode
  32 + *** \param filename The filename of the Lua script to load
  33 + **/
  34 + void AddScript(const std::string& filename)
  35 + { if (!filename.empty()) _script_filenames.push_back(filename); }
  36 +
  37 + //! \brief Copy all the scene scripts filenames at once.
  38 + void SetScripts(const std::vector<std::string>& scripts)
  39 + { _script_filenames = scripts; }
  40 +
  41 + /** \brief Initializes all data necessary for the scripts to begin
  42 + *** \param gm The game mode initializing the scene component.
  43 + **/
  44 + void Initialize(hoa_mode_manager::GameMode* gm);
  45 +
  46 + ///! \brief Updates the different animations and media
  47 + void Update();
  48 +
  49 + ///! \brief calls the reset function of each scripts.
  50 + void Reset();
  51 +
  52 + /** \brief Draws all background images and animations
  53 + *** The images and effects drawn by this function will never be drawn over anything else
  54 + *** (sprites, menus, etc.).
  55 + **/
  56 + void DrawBackground();
  57 +
  58 + /** \brief Draws all foreground images and animations
  59 + *** The images and effects drawn by this function will be drawn over sprites,
  60 + *** but not over the post effects and the gui.
  61 + **/
  62 + void DrawForeground();
  63 +
  64 +
  65 + /** \brief Draws all foreground images and animations
  66 + *** This permits custom effects just below the gui.
  67 + **/
  68 + void DrawPostEffects();
  69 +
  70 +
  71 + /** \brief Loads a custom lua animation files, to be drawn through scripting
  72 + *** \param filename The filename of the new background image to load
  73 + *** \return id the id used to invoke the animation through scripted draw calls.
  74 + **/
  75 + int32 AddAnimation(const std::string& filename);
  76 +
  77 + /** \brief Draws a custom animation.
  78 + *** \param custom image id, obtained through AddCustomAnimation()
  79 + *** \param position screen position to draw at.
  80 + **/
  81 + void DrawAnimation(int32 id, float x, float y);
  82 +
  83 + /** \brief Loads a custom images, to be drawn through scripting
  84 + *** \param filename The filename of the new background image to load
  85 + *** \return id the id used to invoke the animation through scripted draw calls.
  86 + **/
  87 + int32 AddImage(const std::string& filename, float width, float height);
  88 +
  89 + /** \brief Draws a custom image.
  90 + *** \param custom image id, obtained through AddCustomImage()
  91 + *** \param position screen position to draw at.
  92 + *** \param color to blend the image at.
  93 + **/
  94 + void DrawImage(int32 id, float x, float y, hoa_video::Color color = hoa_video::Color::white);
  95 +
  96 + //! \brief Used to permit changing a draw flag at boot time. Use with caution.
  97 + void SetDrawFlag(hoa_video::VIDEO_DRAW_FLAGS draw_flag);
  98 +
  99 +private:
  100 +
  101 + //! \brief Contains a collection of custom loaded images, usable to be drawn through scripting.
  102 + std::vector<hoa_video::StillImage> _script_images;
  103 +
  104 + //! \brief Contains a collection of custom loaded animations, usable to be drawn through scripting.
  105 + std::vector<hoa_video::AnimatedImage> _script_animations;
  106 +
  107 + //! \name Script data
  108 + //@{
  109 + //! \brief The name of the Lua files used to script this mode
  110 + std::vector<std::string> _script_filenames;
  111 +
  112 + /** \brief Script functions which assists with the #Reset method
  113 + *** Those functions execute any code that needs to be performed on a reset call. An example of
  114 + *** one common operation is to reset the scene state when coming back to a given mode from another.
  115 + **/
  116 + std::vector<ScriptObject> _reset_functions;
  117 +
  118 + /** \brief Script functions which assists with the #Update method
  119 + *** Those functions execute any code that needs to be performed on an update call. An example of
  120 + *** one common operation is to detect certain conditions and respond appropriately, such as
  121 + *** triggering a dialogue.
  122 + **/
  123 + std::vector<ScriptObject> _update_functions;
  124 +
  125 + /** \brief Script functions which assists with the #DrawBackground method
  126 + *** Those functions execute any code that needs to be performed on a draw call.
  127 + *** This permits custom background effects.
  128 + **/
  129 + std::vector<ScriptObject> _draw_background_functions;
  130 +
  131 + /** \brief Script functions which assists with the #DrawForeground method
  132 + *** Those functions execute any code that needs to be performed on a draw call.
  133 + *** This permits custom visual effects over the characters and enemies sprites.
  134 + **/
  135 + std::vector<ScriptObject> _draw_foreground_functions;
  136 +
  137 + /** \brief Script functions which assists with the #DrawEffects methods
  138 + *** Those functions execute any code that needs to be performed on a draw call.
  139 + *** This permits custom effects just below the gui.
  140 + **/
  141 + std::vector<ScriptObject> _draw_post_effects_functions;
  142 +};
  143 +
  144 +#endif
112 src/modes/battle/battle.cpp
@@ -171,11 +171,6 @@ BattleMedia::~BattleMedia() {
171 171
172 172 void BattleMedia::Update() {
173 173 attack_point_indicator.Update();
174   -
175   - // Update custom animations
176   - for (uint32 i = 0; i < _custom_battle_animations.size(); ++i) {
177   - _custom_battle_animations[i].Update();
178   - }
179 174 }
180 175
181 176
@@ -186,52 +181,6 @@ void BattleMedia::SetBackgroundImage(const string& filename) {
186 181 }
187 182
188 183
189   -int32 BattleMedia::AddCustomAnimation(const std::string& filename) {
190   - AnimatedImage anim;
191   - if (!anim.LoadFromAnimationScript(filename)) {
192   - PRINT_WARNING << "Custom animation file could not be loaded: " << filename << endl;
193   - return -1;
194   - }
195   -
196   - _custom_battle_animations.push_back(anim);
197   -
198   - int32 id = _custom_battle_animations.size() - 1;
199   - return id;
200   -}
201   -
202   -
203   -void BattleMedia::DrawCustomAnimation(int32 id, float x, float y) {
204   - if (id < 0 || id > static_cast<int32>(_custom_battle_animations.size()) - 1)
205   - return;
206   -
207   - VideoManager->Move(x, y);
208   - _custom_battle_animations[id].Draw();
209   -}
210   -
211   -
212   -int32 BattleMedia::AddCustomImage(const std::string& filename, float width,
213   - float height) {
214   - StillImage img;
215   - if (!img.Load(filename, width, height)) {
216   - PRINT_WARNING << "Custom image file could not be loaded: " << filename << endl;
217   - return -1;
218   - }
219   -
220   - _custom_battle_images.push_back(img);
221   -
222   - int32 id = _custom_battle_images.size() - 1;
223   - return id;
224   -}
225   -
226   -void BattleMedia::DrawCustomImage(int32 id, float x, float y, Color color) {
227   - if (id < 0 || id > static_cast<int32>(_custom_battle_images.size()) - 1)
228   - return;
229   -
230   - VideoManager->Move(x, y);
231   - _custom_battle_images[id].Draw(color);
232   -}
233   -
234   -
235 184 void BattleMedia::SetBattleMusic(const string& filename) {
236 185 if (battle_music.LoadAudio(filename) == false) {
237 186 IF_PRINT_WARNING(BATTLE_DEBUG) << "failed to load music file: " << filename << endl;
@@ -239,7 +188,6 @@ void BattleMedia::SetBattleMusic(const string& filename) {
239 188 }
240 189
241 190
242   -
243 191 StillImage* BattleMedia::GetCharacterActionButton(uint32 index) {
244 192 if (index >= character_action_buttons.size()) {
245 193 IF_PRINT_WARNING(BATTLE_DEBUG) << "function received invalid index argument: " << index << endl;
@@ -250,7 +198,6 @@ StillImage* BattleMedia::GetCharacterActionButton(uint32 index) {
250 198 }
251 199
252 200
253   -
254 201 StillImage* BattleMedia::GetTargetTypeIcon(hoa_global::GLOBAL_TARGET target_type) {
255 202 switch (target_type) {
256 203 case GLOBAL_TARGET_SELF_POINT:
@@ -384,6 +331,9 @@ void BattleMode::Reset() {
384 331 }
385 332
386 333 UnFreezeTimers();
  334 +
  335 + // Reset potential battle scripts
  336 + GetScriptSupervisor().Reset();
387 337 }
388 338
389 339
@@ -391,6 +341,7 @@ void BattleMode::Reset() {
391 341 void BattleMode::Update() {
392 342 // Update potential battle animations
393 343 _battle_media.Update();
  344 + GameMode::Update();
394 345
395 346 // Pause/quit requests take priority
396 347 if (InputManager->QuitPress()) {
@@ -402,9 +353,6 @@ void BattleMode::Update() {
402 353 return;
403 354 }
404 355
405   - for (uint32 i = 0; i < _update_functions.size(); ++i)
406   - ReadScriptDescriptor::RunScriptObject(_update_functions[i]);
407   -
408 356 if (_dialogue_supervisor->IsDialogueActive() == true) {
409 357 _dialogue_supervisor->Update();
410 358
@@ -544,15 +492,14 @@ void BattleMode::Draw() {
544 492 _DrawBackgroundGraphics();
545 493 _DrawSprites();
546 494 _DrawForegroundGraphics();
547   -
548   - for (uint32 i = 0; i < _draw_effects_functions.size(); ++i)
549   - ReadScriptDescriptor::RunScriptObject(_draw_effects_functions[i]);
550 495 }
551 496
552 497 void BattleMode::DrawPostEffects() {
553 498 // Use custom display metrics
554 499 VideoManager->SetCoordSys(0.0f, VIDEO_STANDARD_RES_WIDTH, 0.0f, VIDEO_STANDARD_RES_HEIGHT);
555 500
  501 + GetScriptSupervisor().DrawPostEffects();
  502 +
556 503 if (_state == BATTLE_STATE_INITIAL || _state == BATTLE_STATE_EXITING) {
557 504 _sequence_supervisor->DrawPostEffects();
558 505 return;
@@ -583,18 +530,6 @@ void BattleMode::AddEnemy(GlobalEnemy* new_enemy) {
583 530 }
584 531
585 532
586   -
587   -void BattleMode::AddBattleScript(const std::string& filename) {
588   - if (_state != BATTLE_STATE_INVALID) {
589   - IF_PRINT_WARNING(BATTLE_DEBUG) << "function was called when battle mode was already initialized" << endl;
590   - return;
591   - }
592   -
593   - _script_filenames.push_back(filename);
594   -}
595   -
596   -
597   -
598 533 void BattleMode::RestartBattle() {
599 534 // Disable potential previous light effects
600 535 VideoManager->DisableFadeEffect();
@@ -896,30 +831,8 @@ void BattleMode::_Initialize() {
896 831 _enemy_actors[i]->GetStateTimer().Update(RandomBoundedInteger(0, max_init_timer));
897 832 }
898 833
899   - // Open every possible battle script files registered and process them.
900   - for (uint32 i = 0; i < _script_filenames.size(); ++i) {
901   - ReadScriptDescriptor battle_script;
902   - if (!battle_script.OpenFile(_script_filenames[i]))
903   - continue;
904   -
905   - if (battle_script.OpenTablespace().empty()) {
906   - PRINT_ERROR << "The battle script file: " << _script_filenames[i] << "has not set a correct namespace" << endl;
907   - continue;
908   - }
909   -
910   - _update_functions.push_back(battle_script.ReadFunctionPointer("Update"));
911   - _draw_background_functions.push_back(battle_script.ReadFunctionPointer("DrawBackground"));
912   - _draw_foreground_functions.push_back(battle_script.ReadFunctionPointer("DrawForeground"));
913   - _draw_effects_functions.push_back(battle_script.ReadFunctionPointer("DrawEffects"));
914   -
915   - // Trigger the Initialize functions in the loading order.
916   - ScriptObject init_function = battle_script.ReadFunctionPointer("Initialize");
917   - if (init_function.is_valid())
918   - ScriptCallFunction<void>(init_function, this);
919   -
920   - battle_script.CloseTable(); // The tablespace
921   - battle_script.CloseFile();
922   - }
  834 + // Init the script component.
  835 + GetScriptSupervisor().Initialize(this);
923 836
924 837 ChangeState(BATTLE_STATE_INITIAL);
925 838 } // void BattleMode::_Initialize()
@@ -1027,9 +940,7 @@ void BattleMode::_DrawBackgroundGraphics() {
1027 940 VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_TOP, VIDEO_BLEND, 0);
1028 941 VideoManager->SetCoordSys(0.0f, VIDEO_STANDARD_RES_WIDTH, 0.0f, VIDEO_STANDARD_RES_HEIGHT);
1029 942
1030   - // Handles custom scripted draw before sprites
1031   - for (uint32 i = 0; i < _draw_background_functions.size(); ++i)
1032   - ReadScriptDescriptor::RunScriptObject(_draw_background_functions[i]);
  943 + GetScriptSupervisor().DrawBackground();
1033 944 }
1034 945
1035 946
@@ -1037,8 +948,7 @@ void BattleMode::_DrawForegroundGraphics() {
1037 948 VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_TOP, VIDEO_BLEND, 0);
1038 949 VideoManager->SetCoordSys(0.0f, VIDEO_STANDARD_RES_WIDTH, 0.0f, VIDEO_STANDARD_RES_HEIGHT);
1039 950
1040   - for (uint32 i = 0; i < _draw_foreground_functions.size(); ++i)
1041   - ReadScriptDescriptor::RunScriptObject(_draw_foreground_functions[i]);
  951 + GetScriptSupervisor().DrawForeground();
1042 952 }
1043 953
1044 954
@@ -1265,7 +1175,7 @@ TransitionToBattleMode::TransitionToBattleMode(BattleMode *BM):
1265 1175 _BM(BM) {
1266 1176
1267 1177 _screen_capture = VideoManager->CaptureScreen();
1268   - _screen_capture.SetDimensions(1024.0f, 769.0f);
  1178 + _screen_capture.SetDimensions(VIDEO_STANDARD_RES_WIDTH, VIDEO_STANDARD_RES_HEIGHT);
1269 1179 }
1270 1180
1271 1181 void TransitionToBattleMode::Update() {
76 src/modes/battle/battle.h
@@ -70,31 +70,6 @@ class BattleMedia {
70 70 **/
71 71 void SetBackgroundImage(const std::string& filename);
72 72
73   - /** \brief Loads a custom lua animation file for the battle, to be drawn through scripting
74   - *** \param filename The filename of the new background image to load
75   - *** \return id the id used to invoke the animation through scripted draw calls.
76   - **/
77   - int32 AddCustomAnimation(const std::string& filename);
78   -
79   - /** \brief Draws a custom animation.
80   - *** \param custom image id, obtained through AddCustomAnimation()
81   - *** \param position screen position to draw at.
82   - **/
83   - void DrawCustomAnimation(int32 id, float x, float y);
84   -
85   - /** \brief Loads a custom image for the battle, to be drawn through scripting
86   - *** \param filename The filename of the new background image to load
87   - *** \return id the id used to invoke the animation through scripted draw calls.
88   - **/
89   - int32 AddCustomImage(const std::string& filename, float width, float height);
90   -
91   - /** \brief Draws a custom image .
92   - *** \param custom image id, obtained through AddCustomImage()
93   - *** \param position screen position to draw at.
94   - *** \param color to blend the image at.
95   - **/
96   - void DrawCustomImage(int32 id, float x, float y, hoa_video::Color color = hoa_video::Color::white);
97   -
98 73 /** \brief Sets the battle music to use
99 74 *** \param filename The full filename of the music to play
100 75 **/
@@ -212,13 +187,6 @@ class BattleMedia {
212 187
213 188 //! \brief Contains the entire set of status effect icons
214 189 std::vector<hoa_video::StillImage> _status_icons;
215   -
216   - //! \brief Contains a collection of custom loaded battle images, usable to be drawn through scripting.
217   - std::vector<hoa_video::StillImage> _custom_battle_images;
218   -
219   - //! \brief Contains a collection of custom loaded battle animation, usable to be drawn through scripting.
220   - std::vector<hoa_video::AnimatedImage> _custom_battle_animations;
221   -
222 190 }; // class BattleMedia
223 191
224 192 } // namespace private_battle
@@ -269,19 +237,6 @@ class BattleMode : public hoa_mode_manager::GameMode {
269 237 void DrawPostEffects();
270 238 //@}
271 239
272   - /** \brief Sets the name of the script to execute during the battle
273   - *** \param filename The filename of the Lua script to load
274   - ***
275   - *** This function should only be called once before the BattleMode class object is initialized (before Reset()
276   - *** is called for the first time). Calling it after the battle has been initialized will have no effect and
277   - *** print out a warning.
278   - **/
279   - void AddBattleScript(const std::string& filename);
280   -
281   - //! \brief Copy all the battle script filenames at once.
282   - void SetBattleScripts(const std::vector<std::string>& scripts)
283   - { _script_filenames = scripts; }
284   -
285 240 /** \brief Adds a new active enemy to the battle field
286 241 *** \param new_enemy A copy of the GlobalEnemy object to add to the battle
287 242 *** This method uses the GlobalEnemy copy constructor to create a copy of the enemy. The GlobalEnemy
@@ -401,37 +356,6 @@ class BattleMode : public hoa_mode_manager::GameMode {
401 356 //! \brief A pointer to the BattleMedia object created to coincide with this instance of BattleMode
402 357 private_battle::BattleMedia _battle_media;
403 358
404   - //! \name Battle script data
405   - //@{
406   - //! \brief The name of the Lua files used to script this battle
407   - std::vector<std::string> _script_filenames;
408   -
409   - /** \brief Script functions which assists with the BattleMode#Update method
410   - *** Those functions execute any code that needs to be performed on an update call. An example of
411   - *** one common operation is to detect certain conditions in battle and respond appropriately, such as
412   - *** triggering a dialogue.
413   - **/
414   - std::vector<ScriptObject> _update_functions;
415   -
416   - /** \brief Script functions which assists with the MapMode#DrawBackground method
417   - *** Those functions execute any code that needs to be performed on a draw call. This allows us battle's to
418   - *** utilize custom background effects.
419   - **/
420   - std::vector<ScriptObject> _draw_background_functions;
421   -
422   - /** \brief Script functions which assists with the MapMode#DrawForeground method
423   - *** Those functions execute any code that needs to be performed on a draw call. This allows us battle's to
424   - *** utilize custom visual effects over the characters and enemies sprites.
425   - **/
426   - std::vector<ScriptObject> _draw_foreground_functions;
427   -
428   - /** \brief Script functions which assists with the MapMode#DrawEffects methods
429   - *** Those functions execute any code that needs to be performed on a draw call. This allows us battle's to
430   - *** utilize custom light effects just below the gui.
431   - **/
432   - std::vector<ScriptObject> _draw_effects_functions;
433   - //@}
434   -
435 359 //! \name Battle supervisor classes
436 360 //@{
437 361 //! \brief Manages update and draw calls during special battle sequences
2  src/modes/map/map_events.cpp
@@ -254,7 +254,7 @@ void BattleEncounterEvent::_Start() {
254 254 BM->GetMedia().SetBackgroundImage(_battle_background);
255 255 BM->GetMedia().SetBattleMusic(_battle_music);
256 256 for (uint32 i = 0; i < _battle_scripts.size(); ++i)
257   - BM->AddBattleScript(_battle_scripts[i]);
  257 + BM->GetScriptSupervisor().AddScript(_battle_scripts[i]);
258 258
259 259 TransitionToBattleMode *TM = new TransitionToBattleMode(BM);
260 260
2  src/modes/map/map_events.h
@@ -372,7 +372,7 @@ class BattleEncounterEvent : public MapEvent {
372 372 void AddEnemy(uint32 enemy_id)
373 373 { _enemy_ids.push_back(enemy_id); }
374 374
375   - void AddBattleScript(const std::string& filename)
  375 + void AddScript(const std::string& filename)
376 376 { _battle_scripts.push_back(filename); }
377 377
378 378 protected:
2  src/modes/map/map_sprites.cpp
@@ -407,7 +407,7 @@ void VirtualSprite::_StartBattleEncounter(EnemySprite* enemy) {
407 407
408 408 std::vector<std::string> enemy_battle_scripts = enemy->GetBattleScripts();
409 409 if (!enemy_battle_scripts.empty())
410   - BM->SetBattleScripts(enemy_battle_scripts);
  410 + BM->GetScriptSupervisor().SetScripts(enemy_battle_scripts);
411 411
412 412 TransitionToBattleMode *TM = new TransitionToBattleMode(BM);
413 413
8 src/modes/mode_bindings.cpp
@@ -531,7 +531,7 @@ void BindModeCode() {
531 531 .def(constructor<std::string, uint32>())
532 532 .def("SetMusic", &BattleEncounterEvent::SetMusic)
533 533 .def("SetBackground", &BattleEncounterEvent::SetBackground)
534   - .def("AddBattleScript", &BattleEncounterEvent::AddBattleScript)
  534 + .def("AddScript", &BattleEncounterEvent::AddScript)
535 535 .def("AddEnemy", &BattleEncounterEvent::AddEnemy)
536 536 ];
537 537
@@ -585,8 +585,6 @@ void BindModeCode() {
585 585 class_<BattleMode, hoa_mode_manager::GameMode>("BattleMode")
586 586 .def(constructor<>())
587 587 .def("AddEnemy", (void(BattleMode::*)(uint32)) &BattleMode::AddEnemy)
588   - .def("SetBattleScripts", &BattleMode::SetBattleScripts)
589   - .def("AddBattleScript", &BattleMode::AddBattleScript)
590 588 .def("RestartBattle", &BattleMode::RestartBattle)
591 589 .def("FreezeTimers", &BattleMode::FreezeTimers)
592 590 .def("UnFreezeTimers", &BattleMode::UnFreezeTimers)
@@ -617,10 +615,6 @@ void BindModeCode() {
617 615 [
618 616 class_<BattleMedia>("BattleMedia")
619 617 .def("SetBackgroundImage", &BattleMedia::SetBackgroundImage)
620   - .def("AddCustomAnimation", &BattleMedia::AddCustomAnimation)
621   - .def("AddCustomImage", &BattleMedia::AddCustomImage)
622   - .def("DrawCustomImage", &BattleMedia::DrawCustomImage)
623   - .def("DrawCustomAnimation", &BattleMedia::DrawCustomAnimation)
624 618 .def("SetBattleMusic", &BattleMedia::SetBattleMusic)
625 619 ];
626 620

0 comments on commit 2b3ec1c

Please sign in to comment.
Something went wrong with that request. Please try again.