OSDN Git Service

インクルード参照関係を一部修正。 / Fix some include references.
[deeangband/Deeangband-new.git] / Deeangband / Field.cpp
1 /*!
2 * @file Field.cpp
3 * @brief \83Q\81[\83\80\92\86\82Ì\83t\83\8d\83A\82ð\92è\8b`\82·\82é
4 * @date 2013/12/11
5 * @author Deskull
6 * 2013 Sikabane Works.
7 */
8
9 #include "stdafx.h"
10 #include "Field.h"
11
12 namespace Deeangband
13 {
14
15         Field::Field(std::map<TAG, boost::shared_ptr<Dungeon>>::iterator dungeonIt, DEPTH depth) : GameInstance()
16         {
17                 Dungeon *dungeonPtr = &(*dungeonIt->second);
18                 int x, y;
19                 this->dungeonTag = dungeonIt->first;
20                 this->width = dungeonPtr->GetBaseSize().GetX();
21                 this->height = dungeonPtr->GetBaseSize().GetY();
22                 this->generated = false;
23
24                 if(depth > dungeonPtr->GetMaxDepth() || depth > dungeonPtr->GetMinDepth()) return;
25
26                 squares.resize(this->height);
27                 for(y = 0; y < height; y++)
28                 {
29                         for(x = 0; x < width; x++)
30                         {
31                                 squares[y].push_back(boost::shared_ptr<Square>(new Square()));
32                                 if(Dice::Cast(1, 2) == 2) squares[y][x]->SetFloorTag(dungeonPtr->GetInnerWallFloorTag());
33                                 else squares[y][x]->SetFloorTag(dungeonPtr->GetFloorFloorTag());
34                         }
35                 }
36
37                 creatures.resize(0);
38                 doors.resize(0);
39                 traps.resize(0);
40                 items.resize(0);
41
42                 this->generated = true;
43         }
44
45         Field::Field()
46         {
47                 WipeData();
48         }
49
50         Field::~Field()
51         {
52                 WipeData();
53         }
54
55         void Field::WipeData(void)
56         {
57                 this->width = 0;
58                 this->height = 0;
59                 this->dungeonTag = "";
60                 creatures.resize(0);
61                 doors.resize(0);
62                 traps.resize(0);
63                 items.resize(0);
64         }
65
66         MAP_LENGTH Field::GetWidth(void)
67         {
68                 return width;
69         }
70
71         MAP_LENGTH Field::GetHeight(void)
72         {
73                 return height;
74         }
75
76         bool Field::SetSize(MAP_LENGTH width, MAP_LENGTH height)
77         {
78                 this->width = width;
79                 this->height = height;
80                 return true;
81         }
82
83         Square *Field::GetSquare(MAP_LENGTH x, MAP_LENGTH y)
84         {
85                 //! @note \83t\83B\81[\83\8b\83h\82Ì\94Í\88Í\8aO\82Ì\8dÀ\95W\82Ì\8fê\8d\87false\82ð\95Ô\82·\81B
86                 if(x < 0 || y < 0 || x >= this->width || y >= this->height) return NULL;
87                 return &(*(squares[x][y]));
88         }
89
90         bool Field::GenerateTrap(std::map<TAG, boost::shared_ptr<TrapBase>>::iterator trapBaseIt, Coordinates *position)
91         {
92                 traps.emplace(traps.end(), boost::make_shared<Trap>(trapBaseIt, position));
93                 return true;
94         }
95
96         bool Field::HaveSight(int bx, int by, int tx, int ty)
97         {
98                 std::vector<Coordinates> coordVec;
99                 std::vector<Coordinates>::iterator coordIt;
100
101                 if(bx < 0 || by < 0 || tx < 0 || ty < 0) return false;
102                 if(bx >= this->GetWidth() || by >= this->GetHeight() || tx >= this->GetWidth() || ty >= this->GetHeight()) return false;
103
104                 Coordinates::LineOfSight(coordVec, bx, by, tx, ty);
105                 for(coordIt = coordVec.begin(); coordIt != coordVec.end(); coordIt++)
106                 {
107                         if(bx == coordIt->GetX() && by == coordIt->GetY()) continue;
108                         if(tx == coordIt->GetX() && ty == coordIt->GetY()) continue;
109                         if(this->GetSquare(coordIt->GetX(), coordIt->GetY())->GetFloorTag() == "VANILLA_PERMANENT_WALL") return false;
110                 }
111                 return true;
112         }
113
114 }