OSDN Git Service

780d379f6a96ca8c3be6e491c18f1249f26eb4c7
[moflib/moflib.git] / saisei-1.0 / rpg / rpg / oldcode / NormalAI.cpp
1 #include "NormalAI.h"
2 #include "AttackAction.h"
3 #include <vector>
4 #include "BattlerGroup.h"
5 #include "DataBasedBattler.h"
6 #include "DataBasedAction.h"
7
8 et::NormalAI::NormalAI(mof::DataResourceManager* pDataResourceManager)
9 : BattleAI(pDataResourceManager)
10 {
11 }
12
13 et::NormalAI::~NormalAI(){
14
15 }
16
17
18 et::Action* et::NormalAI::createAction(DataBasedBattler* pOwn , BattlerGroup* pGroup){
19         mof::DataRow targetRow = pOwn->getDataRow();
20         //\91I\91ð\89Â\94\\82È\83A\83N\83V\83\87\83\93\82Ì\92\86\82Å\8dÅ\82à\8aú\91Ò\92l\82Ì\8d\82\82¢\82à\82Ì\82ð\91I\82Ô
21         mof::DataResource monsterAction = m_pDataResourceManager->getResource(_T("data/monster.action.csv"));
22         const TCHAR* const table[] = {_T("DirectAttack1") , _T("DirectAttack2") , _T("SpecialAttack1") , _T("SpecialAttack1")};
23         int ap = pOwn->getParameter().actionPoint;
24         
25         int coefficient = -1;
26         int selectedIndex = -1;
27         mof::DataRow selectedAction;
28         mof::DataRow targetAction;
29
30         for(int i = 0 ; i < sizeof(table)/sizeof(table[0]) ; i++){
31                 mof::tstring action = targetRow.getData(table[i]);
32                 if(action == _T(""))continue;
33                 targetAction = mof::DataRow(monsterAction , action.c_str());
34                 
35                 int cost = targetAction.getIntegerData( _T("Cost"));
36                 if(ap >= cost){
37                         int tmpCoefficient = targetAction.getIntegerData( _T("Coefficient"));
38                         if(coefficient < tmpCoefficient){
39                                 //\91I\91ð\83A\83N\83V\83\87\83\93\82ð\8dX\90V
40                                 coefficient = tmpCoefficient;
41                                 selectedIndex = i;
42                                 selectedAction = targetAction;
43                         }
44                         
45                 }
46         }
47         if(selectedIndex == -1)return NULL;
48
49         return new DataBasedAction(pOwn , pGroup->getHeroBattler() ,  selectedAction , selectedIndex);
50 }
51
52 /*
53 et::Action* et::NormalAI::createAction(DataBasedBattler* pOwn , BattlerGroup* pGroup){
54         mof::DataRow targetRow = pOwn->getDataRow();
55
56         //\91I\91ð\89Â\94\\82È\83A\83N\83V\83\87\83\93\82Ì\92\86\82©\82ç\83\89\83\93\83_\83\80\82Å\91I\82Ô
57         mof::DataResource monsterAction = m_pDataResourceManager->getResource(_T("data/monster.action.csv"));
58         const TCHAR* const table[] = {_T("DirectAttack1") , _T("DirectAttack2") , _T("SpecialAttack1") , _T("SpecialAttack1")};
59         int ap = pOwn->getParameter().actionPoint;
60         
61         mof::DataRow targetAction;
62
63         std::vector<int> selectableList;
64
65         for(int i = 0 ; i < sizeof(table)/sizeof(table[0]) ; i++){
66                 mof::tstring action = targetRow.getData(table[i]);
67                 if(action == _T(""))continue;
68                 targetAction = mof::DataRow(monsterAction , action.c_str());
69                 
70                 int cost = targetAction.getIntegerData( _T("Cost"));
71                 DEBUG_PRINT(cost);
72                 if(ap >= cost)selectableList.push_back(i);
73         }
74         if(selectableList.size() == 0)return NULL;
75
76         int selectedIndex = rand() % selectableList.size();
77         return new DataBasedAction(pOwn , pGroup->getHeroBattler() ,  
78                 mof::DataRow(monsterAction , targetRow.getData(table[selectedIndex]).c_str()) , selectedIndex);
79 }*/