1 ////////////////////////////////////////////////////////////////////////////////
2 //            Copyright (C) 2004-2010 by The Allacrost Project
3 //                         All Rights Reserved
4 //
5 // This code is licensed under the GNU GPL version 2. It is free software and
6 // 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    battle_finish.h
12 *** \author  Tyler Olsen, roots@allacrost.org
13 *** \brief   Header file for battle finish menu
14 ***
15 *** This code takes effect after either the character or enemy party has emerged
16 *** victorious in the battle.
17 *** ***************************************************************************/
18 
19 #ifndef __BATTLE_FINISH_HEADER__
20 #define __BATTLE_FINISH_HEADER__
21 
22 #include "utils.h"
23 #include "defs.h"
24 
25 #include "video.h"
26 
27 #include "gui.h"
28 #include "global.h"
29 
30 #include "battle_utils.h"
31 
32 namespace hoa_battle {
33 
34 namespace private_battle {
35 
36 //! \brief The set of defeat options that the player can select
37 //@{
38 const uint32 DEFEAT_OPTION_RETRY     = 0;
39 const uint32 DEFEAT_OPTION_RESTART   = 1;
40 const uint32 DEFEAT_OPTION_RETURN    = 2;
41 const uint32 DEFEAT_OPTION_RETIRE    = 3;
42 //@}
43 
44 //! \brief The maximum number of times that the player can retry the battle if they lose
45 const uint32 MAX_NUMBER_RETRIES   = 2;
46 
47 /** ****************************************************************************
48 *** \brief A collection of GUI objects drawn when the player loses the battle
49 ***
50 *** This class assists the FinishSupervisor class. It is only utilized when the
51 *** player's characters are defeated in battle and presents the player with a
52 *** number of options
53 ***
54 *** - Retry: resets the state of the battle to the beginning and allows the
55 *** - Restart: loads the game state from the last save point
56 *** - Return: brings the player back to boot mode
57 *** - Retire: exits the game
58 *** ***************************************************************************/
59 class FinishDefeat {
60 public:
61 	FinishDefeat();
62 
~FinishDefeat()63 	~FinishDefeat()
64 		{}
65 
GetNumberRetryTimes()66 	uint32 GetNumberRetryTimes() const
67 		{ return _number_retry_times; }
68 
69 	//! \brief Processes user input and updates the GUI controls
70 	void Update();
71 
72 	//! \brief Draws the finish window and GUI contents to the screen
73 	void Draw();
74 
75 private:
76 	//! \brief The number of times that the player has lost and chosen to retry the battle
77 	uint32 _number_retry_times;
78 
79 	//! \brief The window that the defeat message and options are displayed upon
80 	hoa_gui::MenuWindow _options_window;
81 
82 	//! \brief The window that the defeat message and options are displayed upon
83 	hoa_gui::MenuWindow _tooltip_window;
84 
85 	//! \brief Text that displays the battle's outcome
86 	hoa_gui::TextBox _outcome_message;
87 
88 	//! \brief The list of options that the player may choose from when they lose the battle
89 	hoa_gui::OptionBox _options;
90 
91 	//! \brief Tooltip text explaining the currently selected option
92 	hoa_gui::TextBox _tooltip;
93 }; // class FinishDefeat
94 
95 
96 /** ****************************************************************************
97 *** \brief The window displayed once a battle has either been won or lost
98 ***
99 *** This window is located in the center right portion of the screen and only appears
100 *** when an outcome has been decided in the battle. The contents of this window differ
101 *** depending on whether the battle was victorious or a loss. If the player won
102 *** the battle, they will have their victory spoils written to the screen along
103 *** with any character growth information (e.g. experience level up). If the player
104 *** lost the battle, they will be presented with a number of options. The player
105 *** may choose to:
106 ***
107 *** - Retry the battle from the beginning
108 *** - Load the game from the last save point
109 *** - Return to the game's main menu
110 *** - Exit the game
111 ***
112 *** \todo Add feature where spoils (XP, drunes, etc) are quickly counted down as
113 *** they go into the party's posession.
114 *** ***************************************************************************/
115 class FinishWindow : public hoa_gui::MenuWindow {
116 	friend class hoa_battle::BattleMode;
117 
118 public:
119 	FinishWindow();
120 
121 	~FinishWindow();
122 
123 	/** \brief Un-hides the window display and creates the window contents
124 	*** \param victory Set to true if the player's party was victorious in battle; false if he/she was defeated
125 	**/
126 	void Initialize(bool victory);
127 
128 	//! \brief Updates the state of the window
129 	void Update();
130 
131 	//! \brief Draws the window and its contents
132 	void Draw();
133 
GetState()134 	FINISH_STATE GetState() const
135 		{ return _state; }
136 
137 private:
138 	//! \brief The state that the window is in, which determines its contents
139 	FINISH_STATE _state;
140 
141 	//! \brief The amount of money won
142 	int32 _victory_money;
143 
144 	//! \brief The amount of xp earned (per character)
145 	int32 _victory_xp;
146 
147 	//! \brief Tallies the amount of growth each character has received for each stat
148 	int _growth_gained[4][8];
149 
150 	//! \brief Pointers to all characters who took part in the battle
151 	std::vector<hoa_global::GlobalCharacter*> _characters;
152 
153 	//! \brief The growth members for all object pointers in the _characters table
154 	std::vector<hoa_global::GlobalCharacterGrowth*> _character_growths;
155 
156 	//! \brief The music to play if the character party is victorious
157 	hoa_audio::MusicDescriptor _victory_music;
158 
159 	//! \brief The music to play if the character party is defeated
160 	hoa_audio::MusicDescriptor _defeat_music;
161 
162 	//! \brief Text that displays the battle's outcome (victory or defeat)
163 	hoa_gui::TextBox _finish_outcome;
164 
165 	//! \brief The list of options that the player may choose from when they lose the battle
166 	hoa_gui::OptionBox _lose_options;
167 
168 	//! \brief The window containing the XP and money won
169 	hoa_gui::MenuWindow _xp_and_money_window;
170 
171 	//! \brief The windows that show character portraits and stats
172 	hoa_gui::MenuWindow _character_window[4];
173 
174 	//! \brief Lists the items won
175 	hoa_gui::MenuWindow _items_window;
176 
177 	//! \brief Character portraits
178 	hoa_video::StillImage _char_portraits[4];
179 
180 	//! \brief Items won from battle (<ID, quantity>)
181 	std::map<hoa_global::GlobalObject*, int32> _victory_items;
182 
183 	// ----- Private methods
184 
185 	/** \brief Creates 4 character windows
186 	*** \param start_x The x coordinate for the upper left corner of the window
187 	*** \param start_y The y coordinate for the upper left corner of the window
188 	**/
189 	void _InitCharacterWindows(float start_x, float start_y);
190 
191 	/** \brief Creates _xp_and_money_window and _items_window
192 	*** \param start_x The x coordinate for the upper left corner of the window
193 	*** \param start_y The y coordinate for the upper left corner of the window
194 	**/
195 	void _InitSpoilsWindows(float start_x, float start_y);
196 
197 	//! \brief Sets up the OptionBox for things like retrying the battle
198 	void _InitLoseOptions();
199 
200 	//! \brief Either victory or death
201 	void _InitVictoryText();
202 
203 	//! \brief Tallies up the xp, money, and items earned from killing the enemies
204 	void _TallyXPMoneyAndItems();
205 
206 	//! \brief Use this to clear learned skills after they've been shown so that they don't render every battle
207 	void _ClearLearnedSkills();
208 
209 	//! \brief Handles update processing when the _state member is FINISH_ANNOUNCE_WIN
210 	void _UpdateAnnounceWin();
211 
212 	//! \brief Handles update processing when the _state member is FINISH_WIN_GROWTH
213 	void _UpdateWinGrowth();
214 
215 	//! \brief Just waits for the player to press OK, then moves on
216 	void _UpdateWinWaitForOK();
217 
218 	//! \brief Handles update processing when the _state member is FINISH_WIN_SPOILS
219 	void _UpdateWinSpoils();
220 
221 	//! \brief Handles update processing when the _state member is FINISH_ANNOUNCE_LOSE
222 	void _UpdateAnnounceLose();
223 
224 	//! \brief Handles update processing when the _state member is FINISH_LOSE_CONFIRM
225 	void _UpdateLoseConfirm();
226 
227 	//! \brief Handles update processing when the _state member is FINISH_ANNOUNCE_WIN
228 	void _DrawAnnounceWin();
229 
230 	//! \brief Handles update processing when the _state member is FINISH_WIN_GROWTH
231 	void _DrawWinGrowth();
232 
233 	//! \brief Handles update processing when the _state member is FINISH_WIN_GROWTH
234 	void _DrawWinSkills();
235 
236 	//! \brief Handles update processing when the _state member is FINISH_WIN_SPOILS
237 	void _DrawWinSpoils();
238 
239 	//! \brief Handles update processing when the _state member is FINISH_ANNOUNCE_LOSE
240 	void _DrawAnnounceLose();
241 
242 	//! \brief Handles update processing when the _state member is FINISH_LOSE_CONFIRM
243 	void _DrawLoseConfirm();
244 }; // class FinishWindow : public hoa_video:MenuWindow
245 
246 } // namespace private_battle
247 
248 } // namespace hoa_battle
249 
250 #endif // __BATTLE_FINISH_HEADER__
251