OSDN Git Service

fix cmake/Macros.cmake
[moflib/moflib.git] / saisei-1.0 / rpg / rpg / oldcode / BattleData.cpp
1 #include "BattleData.h"
2 #include "mof/KeyFrameAnimation.h"
3 #include "AttackAction.h"
4 #include "SpecialAction.h"
5 #include "GameData.h"
6 #include "BattlerGroup.h"
7 #include "BattlerFacade.h"
8
9
10 et::BattleData::BattleData(mof::TextureManager* pTextureManager , et::GameData* pGameData , et::BattlerGroup* pGroup)
11 {
12         m_pGameData = pGameData;
13         m_pTextureManager = pTextureManager;
14         m_battleAction.type = BattleAction::NONE;
15         et::BattlerParameter parameter;
16         m_pGroup = pGroup;
17         //m_battlerList.push_back(new Battler(parameter , m_pTextureManager));
18 }
19
20 et::BattleData::~BattleData(void)
21 {
22         delete m_pGroup;
23 }
24
25
26
27 /*
28 void et::BattleData::addBattler(et::BattlerFacade* pBattler){
29         m_battlerList.push_back(pBattler);
30 }
31
32
33 void et::BattleData::layoutBattler(){
34         int nEnemy = 0;
35         int nIdeal = 0;
36         
37         //\91O\92²\8d¸
38         for(std::list<BattlerFacade*>::iterator itr = m_battlerList.begin() ; itr != m_battlerList.end() ; ++itr){
39                 if((*itr)->getType() == et::ENEMY)nEnemy++;
40                 else if((*itr)->getType() == et::IDEAL)nIdeal++;
41         }
42
43         int cntEnemy = 0;
44         int cntIdeal = 0;
45         float zTable[3][3] = { {0.6f , 0.6f , 0.6f} , { 0.8f , 0.4f , 0.6f} , {0.86f , 0.6f , 0.34f} };//[\91\8d\90\94][\94Ô\8d\86]
46         float xTable[3][3] = { {0.0f , 0.0f , 0.0f} , { 0.1f , -0.1f , 0.6f} , {0.15f , 0.0f , -0.15f} };//[\91\8d\90\94][\94Ô\8d\86]
47         float ixTable[3][3] = { {0.2f , 0.0f , 0.0f} , { 0.0f , 0.07f , 0.6f} , {0.0f , 0.1f , 0.15f} };//[\91\8d\90\94][\94Ô\8d\86]
48         for(std::list<BattlerFacade*>::iterator itr = m_battlerList.begin() ; itr != m_battlerList.end() ; ++itr){
49                 if((*itr)->getType() == et::HERO){
50                         (*itr)->setAidlingAnimation(mof::Vector3D(0.3f , 0.0f , 0.6f));
51                         (*itr)->setBasePosition(mof::Vector3D(0.3f , 0.0f , 0.6f));
52                 }
53                 else if((*itr)->getType() == et::ENEMY){
54                         mof::KeyFrameAnimation* pAnimation = new mof::KeyFrameAnimation();
55                         (*itr)->setAidlingAnimation(mof::Vector3D(-0.45f + xTable[nEnemy-1][cntEnemy] , 0.0f , zTable[nEnemy-1][cntEnemy]));
56                         (*itr)->setBasePosition(mof::Vector3D(-0.45f + xTable[nEnemy-1][cntEnemy] , 0.0f , zTable[nEnemy-1][cntEnemy]));
57                         cntEnemy++;     
58                 }
59                 else if((*itr)->getType() == et::IDEAL){
60                         mof::KeyFrameAnimation* pAnimation = new mof::KeyFrameAnimation();
61                         (*itr)->setAidlingAnimation(mof::Vector3D(0.6 +ixTable[nIdeal-1][cntIdeal] , 0.0f , zTable[nIdeal-1][cntIdeal]));
62                         cntIdeal++;     
63                 }
64         }
65
66 }
67
68
69 et::BattlerFacade* et::BattleData::getHeroBattler(){
70         for(std::list<BattlerFacade*>::iterator itr = m_battlerList.begin() ; itr != m_battlerList.end() ; ++itr){
71                 if((*itr)->getType() == et::HERO){
72                         return *itr;
73                 }
74         }
75         assert(0);
76         return NULL;
77 }
78
79 et::BattlerFacade* et::BattleData::getEnemyBattler(int index){
80         int cntEnemy = 0;
81         for(std::list<BattlerFacade*>::iterator itr = m_battlerList.begin() ; itr != m_battlerList.end() ; ++itr){
82                 if((*itr)->getType() == et::ENEMY){
83                         if(cntEnemy++ == index)return *itr;
84                 }
85         }
86         return NULL;
87
88 }
89
90
91 et::BattlerFacade* et::BattleData::getIdealBattler(int index){
92         int cntIdeal = 0;
93         for(std::list<BattlerFacade*>::iterator itr = m_battlerList.begin() ; itr != m_battlerList.end() ; ++itr){
94                 if((*itr)->getType() == et::IDEAL){
95                         if(cntIdeal++ == index)return *itr;
96                 }
97         }
98         return NULL;
99 }
100
101
102 et::Action* et::BattleData::createBattlerAction(et::BattlerFacade* pBattler){
103         if(pBattler->getType() == et::HERO){
104                 et::BattleAction action = m_battleAction;
105                 m_battleAction.type = et::BattleAction::NONE;
106                 if(action.type == et::BattleAction::ATTACK_WEAPON){
107                         return new AttackAction(pBattler , action.pTarget , 3);
108                 }
109                 else if(action.type == et::BattleAction::WAIT || action.type == et::BattleAction::GUARD){
110                         return NULL;
111                 }
112                 else if(action.type == et::BattleAction::CAST){
113                         et::BattlerFacade* pIdeal = getIdealBattler(action.idealIndex);
114                         et::BattlerParameter parameter = pIdeal->getParameter();
115                         parameter.dActionPoint -= 5;
116                         pIdeal->setParameter(parameter);
117                         std::list<et::BattlerFacade*> targetList;
118                         if(action.pTarget != NULL)targetList.push_back(action.pTarget);
119                         else {
120                                 for(std::list<et::BattlerFacade*>::const_iterator itr = getBattlerList().begin() ; itr != getBattlerList().end() ; ++itr){
121                                         if((*itr)->getType() == et::ENEMY && (*itr)->getParameter().alive)targetList.push_back(*itr);
122                                 }
123                         }
124                         //\93Á\8eê\8bZ\82Ì\8eí\97Þ\82ð\93¾\82é
125                         return new SpecialAction(pBattler , targetList , 5 , action.idealIndex);
126                 }
127                 else if(action.type == et::BattleAction::USE_ITEM){
128                         //\83A\83C\83e\83\80\82ð\82È\82­\82·
129                         std::list<et::ItemData> &refList = getItemList();
130                         for(std::list<et::ItemData>::iterator itr = refList.begin() ; itr != refList.end() ; ++itr){
131                                 if(action.pTargetItem == &(*itr)){
132                                         refList.erase(itr);
133                                         break;
134                                 }
135                         }
136                         std::list<et::BattlerFacade*> targetList;
137                         if(action.pTarget != NULL)targetList.push_back(action.pTarget);
138                         else {
139                                 for(std::list<et::BattlerFacade*>::const_iterator itr = getBattlerList().begin() ; itr != getBattlerList().end() ; ++itr){
140                                         if((*itr)->getType() == et::ENEMY && (*itr)->getParameter().alive)targetList.push_back(*itr);
141                                 }
142                         }
143                         //\93Á\8eê\8bZ\82Ì\8eí\97Þ\82ð\93¾\82é
144                         return new SpecialAction(pBattler , targetList , 2 , 3);
145                 }
146                 else return NULL;
147         }
148         else {
149                 std::list<BattlerFacade*> enemyList;
150                 enemyList.push_back(getHeroBattler());
151                 std::list<BattlerFacade*> allyList;
152                 for(std::list<BattlerFacade*>::iterator itr = m_battlerList.begin() ; itr != m_battlerList.end() ; ++itr){
153                         if((*itr)->getType() == et::ENEMY && *itr != pBattler)allyList.push_back(*itr);
154                 }
155                 return pBattler->createNextAction(enemyList , allyList);
156                 
157         }
158
159 }*/
160
161 et::BattleAction et::BattleData::pollBattleAction(){
162         BattleAction action = m_battleAction;
163         m_battleAction.type = BattleAction::NONE;
164         return action;
165 }
166
167 bool et::BattleData::isOver(){
168         if(!m_pGroup->getHeroBattler()->getParameter().alive)return true;
169         //et::BattlerFacade* pEnemy = NULL;
170         return m_pGroup->getEnemyBattlerListAlive().size() == 0;
171         /*for(int i = 0 ; (pEnemy = m_pGroup->getEnemyBattlerAt(i)) != NULL ; i++){
172                 if(pEnemy->getParameter().alive)return false;
173         }
174         return true;*/
175         
176 }
177
178
179 std::list<et::ItemData>& et::BattleData::getItemList(){
180         return m_pGameData->getBattleItemList();
181 }