OSDN Git Service

インクルード参照関係を一部修正。 / Fix some include references.
[deeangband/Deeangband-new.git] / Deeangband / GameEngine.cpp
1 /*!
2  * @file GameEngine.cpp
3  * @brief \83Q\81[\83\80\83G\83\93\83W\83\93\82Ì\8eÀ\91\95
4  * @date 2013/12/17
5  * @author Deskull
6  * 2014 Sikabane Works.
7  */
8
9 #pragma once
10
11 #include "stdafx.h"
12 #include "GameEngine.h"
13
14 #include "HaveGameTime.h"
15 #include "Creature.h"
16 #include "GameCampaign.h"
17 #include "GameLogger.h"
18
19 namespace Deeangband
20 {
21         GameEngine::GameEngine()
22         {
23                 gameWorld = new GameWorld();
24                 gameSurface = new GameSurfaceSDL(gameWorld);
25                 gameLogger = new GameLogger();
26
27                 gameSurface->SetField(gameWorld->GetField(0));
28                 gameSurface->SetSideStatusCreature(gameWorld->GetCreature(0));
29                 this->gameLogger->PutLog("GameEngine\8aJ\8en");
30                 Direction::Initialize();
31         }
32
33         PLAY_EXIT_CODE GameEngine::PlayLoop(void)
34         {
35                 GAME_COMMAND commandID;
36                 PLAY_EXIT_CODE code = PLAY_EXIT_NONE;
37                 ACTION_IT actionIt;
38                 gameSurface->Redraw(gameWorld->GetPlayerCreature());
39
40                 while(code == PLAY_EXIT_NONE)
41                 {
42                         this->gameSurface->UpdateTimeStatus(this->gameWorld->GetGameTime());
43                         //actionIt = this->toNextProcess();
44                         commandID = gameSurface->GetCommand(gameWorld->GetPlayerCreature());
45                         code = DoGameCommand(commandID);
46                         ProcessDeadCreatures();
47                         if(!gameWorld->GetPlayerCreature()->second->IsAlive())
48                         {
49                                 code = PLAY_EXIT_DEAD;
50                                 gameSurface->SystemMessage("\82 \82È\82½\82Í\8e\80\82É\82Ü\82µ\82½\81B");
51                         }
52                 }
53
54                 return PLAY_EXIT_QUIT;
55         }
56
57         PLAY_EXIT_CODE GameEngine::DoGameCommand(GAME_COMMAND command)
58         {
59                 CREATURE_IT playerIt = gameWorld->GetPlayerCreature();
60
61                 switch(command)
62                 {
63                 case GAME_COMMAND_VIEW_PLAYER_STATUS:
64                         gameSurface->ViewCreatureStatus(gameWorld->GetPlayerCreature()->second.get());
65                         break;
66                 case GAME_COMMAND_REDRAW:
67                         gameSurface->Redraw(playerIt);
68                         break;
69                 case GAME_COMMAND_DEBUG_XML_SAVE:
70                         gameWorld->XMLSave();
71                         gameSurface->SystemMessage("XML\82É\95Û\91\82µ\82Ü\82µ\82½\81B");
72                         break;
73                 case GAME_COMMAND_DEBUG_XML_LOAD:
74                         gameSurface->Redraw(playerIt);
75                         gameWorld->XMLLoad();
76                         gameSurface->SystemMessage("XML\82©\82ç\8cÄ\82Ñ\8fo\82µ\82Ü\82µ\82½\81B");
77                         break;
78                 case GAME_COMMAND_EXIT:
79                         return PLAY_EXIT_QUIT;
80                         break;
81                 case GAME_COMMAND_NORTH:
82                         this->WalkCreature(playerIt, DIRECTION_NORTH);
83                         break;
84                 case GAME_COMMAND_NORTH_EAST:
85                         this->WalkCreature(playerIt, DIRECTION_NORTH_EAST);
86                         break;
87                 case GAME_COMMAND_EAST:
88                         this->WalkCreature(playerIt, DIRECTION_EAST);
89                         break;
90                 case GAME_COMMAND_SOUTH_EAST:
91                         this->WalkCreature(playerIt, DIRECTION_SOUTH_EAST);
92                         break;
93                 case GAME_COMMAND_SOUTH:
94                         this->WalkCreature(playerIt, DIRECTION_SOUTH);
95                         break;
96                 case GAME_COMMAND_SOUTH_WEST:
97                         this->WalkCreature(playerIt, DIRECTION_SOUTH_WEST);
98                         break;
99                 case GAME_COMMAND_WEST:
100                         this->WalkCreature(playerIt, DIRECTION_WEST);
101                         break;
102                 case GAME_COMMAND_NORTH_WEST:
103                         this->WalkCreature(playerIt, DIRECTION_NORTH_WEST);
104                         break;
105                 }
106                 return PLAY_EXIT_NONE;
107         }
108
109         bool GameEngine::WalkCreature(CREATURE_IT creatureIt, DIRECTION direction)
110         {
111                 return this->WalkCreature(creatureIt->second.get(), direction);
112         }
113
114         bool GameEngine::WalkCreature(Creature *creaturePtr, DIRECTION direction)
115         {
116                 Coordinates nextPoint = creaturePtr->GetPosition() + Direction::DirectionVector[direction];
117                 Floor *floorPtr = gameWorld->GetFloorFromPosition(creaturePtr->GetFieldID(), &nextPoint);
118                 Creature *targetPtr;
119
120                 //! @note \88Ú\93®\90æ\82É\95Ê\82Ì\83N\83\8a\81[\83`\83\83\81[\82ª\91\8dÝ\82·\82é\82È\82ç\82Î\94\92\95º\8f\88\97\9d\82É\88Ú\8ds\82µ\82Ä FALSE
121                 targetPtr = gameWorld->GetCreatureFromPosition(creaturePtr->GetFieldID(), &nextPoint);
122                 if(targetPtr)
123                 {
124                         this->gameLogger->CreaturesCombated(creaturePtr->GetName(), targetPtr->GetName());
125                         return this->CombatCreatures(creaturePtr, targetPtr);
126                 }
127
128                 if(!creaturePtr->CanEnterPosition(floorPtr))
129                 {
130                         this->gameSurface->GameMessage("\8ds\82­\8eè\82ð\91j\82Ü\82ê\82Ä\82¢\82é\81B");
131                         return false;
132                 }
133
134                 creaturePtr->Walk(this->gameLogger, direction);
135                 this->gameSurface->FocusField(creaturePtr->GetPosition());
136                 creaturePtr->UpdateFieldLore(gameWorld->GetField(creaturePtr->GetFieldID()));
137                 this->gameSurface->GameMessage("");
138                 return true;
139         }
140
141         bool GameEngine::CombatCreatures(Creature *attackerPtr, Creature *targetPtr)
142         {
143                 attackerPtr->Melee(targetPtr);
144                 this->gameSurface->UpdateSideCreatureStatus(gameWorld->GetPlayerCreature()->second.get());
145                 return true;
146         }
147
148         int GameEngine::ProcessDeadCreatures()
149         {
150                 int deadNum = 0;
151                 CREATURE_IT creatureIt, creatureItCurrent;
152                 CREATURE_LIST *creatureList = gameWorld->GetCreatureList();
153
154                 creatureIt = creatureList->begin();
155
156                 while(creatureIt != creatureList->end())
157                 {
158                         creatureItCurrent = creatureIt;
159                         creatureIt++;
160                         if(!creatureItCurrent->second->IsAlive())
161                         {
162                                 //!< @note \83v\83\8c\83C\83\84\81[\82Ì\8e\80\96S\82È\82ç\82Î\95Ê\93r\8f\88\97\9d\82·\82é\82Ì\82Å\83X\83L\83b\83v\81A\82³\82à\82È\82­\82Î\83N\83\8a\81[\83`\83\83\81[\82Ì\8fÁ\96Å\81B
163                                 if(gameWorld->GetPlayerCreature() != creatureItCurrent)
164                                 {
165                                         gameSurface->GameMessage(creatureItCurrent->second->GetName() + "\82Í\8e\80\82ñ\82¾\81B");
166                                         creatureList->erase(creatureItCurrent);
167                                 }
168                                 deadNum++;
169                         }
170                 }
171
172                 return deadNum;
173         }
174
175         ACTION_IT GameEngine::toNextProcess(void)
176         {
177                 return this->gameWorld->GetActionList()->begin()++;
178         }
179
180 }