Skip to content

Instantly share code, notes, and snippets.

@MarianoGnu
Created March 31, 2013 17:28
Show Gist options
  • Save MarianoGnu/5281369 to your computer and use it in GitHub Desktop.
Save MarianoGnu/5281369 to your computer and use it in GitHub Desktop.
/////////////////////////////////////////////////////////////////////////////
// This file is part of EasyRPG Player.
//
// EasyRPG Player is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// EasyRPG Player is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////
#ifndef _SCENE_BATTLE2k_H_
#define _SCENE_BATTLE2k_H_
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include "scene.h"
#include "battle_interface.h"
#include "battle_battler.h"
#include "battle_animation.h"
#include "window_help.h"
#include "window_battleitem.h"
#include "window_battleskill.h"
#include "window_battleoption.h"
#include "window_battlecommand.h"
#include "window_battlestatus.h"
#include "window_command.h"
#include "Window_BattleMessage.h"
#include "rpg_troopmember.h"
#include "rpg_actor.h"
#include "rpg_enemy.h"
#include "game_actor.h"
#include "game_enemy.h"
#include "drawable.h"
#include "zobj.h"
#include "background.h"
#include <deque>
#include <boost/scoped_ptr.hpp>
namespace Battle{
struct BattleAction { //Struct: contains the information of the action for a given actor.
bool is_actor; //true-(index points to an actor) false-(index points to a enemy).
int index; //index-who executes this action.
int command_id; //0-Attack 1-Skill 2-Defend 3-Item.
int target; //index of the target(Actor or Enemy is defined by action scope).
int skill; //id of the selected skill (if any).
int item; //id the the selected item (if any).
int speed; //battle speed, to decide who attacs first (real speed+-20%).
void reset(){is_actor = true; index= -1; command_id= -1; target= -1; skill= -1;item= -1;speed= -1; };
};
}
////////////////////////////////////////////////////////////
/// Scene_Battle2k class.
/// Manages the battles for RM2k games.
////////////////////////////////////////////////////////////
class Scene_Battle2k : public Scene, Battle_Interface {
public:
/***************************
* Scene related methods *
***************************/
Scene_Battle2k();
~Scene_Battle2k();
void Start();
void Update();
void ProcessInput();
private:
/***************************
* Action related methods *
***************************/
Battle::BattleAction current_action; //Action if the current Actor.
std::vector<Battle::BattleAction> actions; //List of all actions used in a turn.
/***************************
* State related methods *
***************************/
enum State { //Enum: List of all posible states of the interface.
State_Start, //Start: Initial Message.
State_Options, //Options: Select 0-Fight 1-Autobattle 2-Flee.
State_Battle, //Battle: Transition beatwhen Options to Command.
State_AutoBattle, //AutoBattle: Ramdomly selects actors's actions.
State_Command, //Command: 0-Attack 1-Skill 2-Defend 3-Item.
State_Item, //Item: Chose an item.
State_Skill, //Skill: Chose a Skill.
State_TargetEnemy, //TargetEnemy: select an enemy.
State_TargetAlly, //TargetAlly: select an ally.
State_Action, //Action: animate and show battle messages.
State_Victory, //Victory: Show victory message and calculate experience and item reward.
State_Defeat //Defeat: Show defeat message and manage GameOver or event based result.
};
State state; //Current state.
State target_state; //Previus state, to return from target state.
int window_speed; //The speed (and direction) that windows moves when changing a state.
void SetState(State new_state, bool cancel = false); //Set new_state as current state.
void UpdateState(); //Update windows related to current state
/***************************
* Window related methods *
***************************/ //Initialize the Windows.
boost::scoped_ptr<Window_Help> help_window; //Help window for Skill & Item windows.
boost::scoped_ptr<Window_BattleOption> options_window; //Command window: 0-Fight 1-Autobattle 2-Flee.
boost::scoped_ptr<Window_BattleStatus> status_window; //Status window: displays information for party members. Also used to target an Ally.
boost::scoped_ptr<Window_BattleCommand> command_window; //Command window: 0-Attack 1-Skill 2-Defend 3-Item.
boost::scoped_ptr<Window_BattleItem> item_window; //Item window.
boost::scoped_ptr<Window_BattleSkill> skill_window; //Skill window.
boost::scoped_ptr<Window_Command> enemytarget_window; //Command window: list of alive enemies.
boost::scoped_ptr<Window_BattleMessage> message_window; //Message Window: to display battle information.
boost::scoped_ptr<Background> background; //Current background.
void CreateWindows();
void UpdateBackground();
/***************************
*Animation related methods*
***************************/
std::deque<EASYRPG_SHARED_PTR<BattleAnimation>> animations; //List of all animations being executed.
bool Scene_Battle2k::IsAnimationRuning(); //Used to decide if animatios should be updated.
void UpdateAnimations(); //Update Animations.
void ShowAnimation(int animation_id, bool allies, Battle::Ally* ally, Battle::Enemy* enemy, bool wait); //Add an animation to the query.
/***************************
*Stupid BattleInterface>_>*
***************************/
void Restart();
void Message(const std::string& msg, bool pause = true);
void Floater(const Sprite* ref, int color, const std::string& text, int duration);
void Floater(const Sprite* ref, int color, int value, int duration);
bool IsAnimationWaiting();
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment