OSDN Git Service

Field::GetSight() を実装。 / Implement Field::GetSight().
authorDeskull <desull@users.sourceforge.jp>
Sat, 10 Jan 2015 04:59:48 +0000 (13:59 +0900)
committerDeskull <desull@users.sourceforge.jp>
Sat, 10 Jan 2015 04:59:48 +0000 (13:59 +0900)
Deeangband/Creature.cpp
Deeangband/Field.cpp
Deeangband/Field.h

index 5711286..ef7e437 100644 (file)
@@ -95,7 +95,6 @@ namespace Deeangband
                SetSpeciesData(speciesIt->second.get());
        }
 
-
        Creature::Creature(void)
        {
                WipeData();
index 3b7c1bd..4313dac 100644 (file)
@@ -187,8 +187,67 @@ namespace Deeangband
 
        }
 
-       void Field::GetSight(std::vector<Coordinates> &coordVec, int baseX, int baseY)
+       void Field::GetSight(std::vector<bool> &coordVec, MAP_LENGTH size, MAP_LENGTH baseX, MAP_LENGTH baseY)
        {
+               MAP_LENGTH x, y, s;
+               int sideWidth = size * 2 + 1;
+               std::vector<Coordinates> lineVec;
+               std::vector<Coordinates>::iterator lineIt;
+
+               for(y = 0 ; y < baseY + size * 2; y++)
+               {
+                       for(x = 0; x < baseX + size * 2; x++)
+                       {
+                               coordVec[y * sideWidth + x] = false;
+                       }
+               }
+
+               for(s = size; s > 0; s--)
+               {
+                       for(x = baseX - size; x <= baseX + size; x++)
+                       {
+                               if(coordVec[y * sideWidth + x]) continue;
+                               Coordinates::LineOfSight(lineVec, baseX, baseY, x, y);
+                               if(lineVec[0].GetX() == baseX && lineVec[0].GetY() == baseY)
+                               {
+                                       for(lineIt = lineVec.begin(); lineIt < lineVec.end(); lineIt++)
+                                       {
+                                               coordVec[lineIt->GetY() * sideWidth + lineIt->GetX()] = true;
+                                               if(this->GetSquare(lineIt->GetX(), lineIt->GetY())->IsWall()) break;
+                                       }
+                               }
+                               else
+                               {
+                                       for(lineIt = lineVec.end()--; lineIt > lineVec.begin(); lineIt--)
+                                       {
+                                               coordVec[lineIt->GetY() * sideWidth + lineIt->GetX()] = true;
+                                               if(this->GetSquare(lineIt->GetX(), lineIt->GetY())->IsWall()) break;
+                                       }
+                               }
+                       }
+
+                       for(y = baseY - size + 1; y <= baseY + size - 1; y++)
+                       {
+                               if(coordVec[y * sideWidth + x]) continue;
+                               Coordinates::LineOfSight(lineVec, baseX, baseY, x, y);
+                               if(lineVec[0].GetX() == baseX && lineVec[0].GetY() == baseY)
+                               {
+                                       for(lineIt = lineVec.begin(); lineIt < lineVec.end(); lineIt++)
+                                       {
+                                               coordVec[lineIt->GetY() * sideWidth + lineIt->GetX()] = true;
+                                               if(this->GetSquare(lineIt->GetX(), lineIt->GetY())->IsWall()) break;
+                                       }
+                               }
+                               else
+                               {
+                                       for(lineIt = lineVec.end()--; lineIt > lineVec.begin(); lineIt--)
+                                       {
+                                               coordVec[lineIt->GetY() * sideWidth + lineIt->GetX()] = true;
+                                               if(this->GetSquare(lineIt->GetX(), lineIt->GetY())->IsWall()) break;
+                                       }
+                               }
+                       }
+               }
        }
 
        bool Field::HaveSight(int bx, int by, int tx, int ty)
index 147217d..4b1d9ab 100644 (file)
@@ -139,11 +139,12 @@ namespace Deeangband
                /*!
                 * @brief \8ew\92è\92n\93_\82©\82ç\82Ì\8e\8b\8aE\82ð\95Ô\82·
                 * @param coordVec \8e\8b\93_\82ð\95Ô\82·Vector\82Ì\8eQ\8fÆ\93n\82µ
+                * @param rad \8aî\96{\94¼\8ca
                 * @param baseX \8e\8b\93_\8c³X\8dÀ\95W
                 * @param baseY \8e\8b\93_\8c³Y\8dÀ\95W
                 * @return \82È\82µ
                 */
-               void Field::GetSight(std::vector<Coordinates> &coordVec, int baseX, int baseY);
+               void Field::GetSight(std::vector<bool> &coordVec, MAP_LENGTH size, MAP_LENGTH baseX, MAP_LENGTH baseY);
 
                /*!
                 * @brief \8e\8b\8aE\82ª\92Ê\82Á\82Ä\82¢\82é\82©\82Ì\94»\92è\82ð\8ds\82¤