File indexing completed on 2024-07-14 07:35:37

0001 /*
0002     SPDX-FileCopyrightText: 2003 Russell Steffen <rsteffen@bayarea.net>
0003     SPDX-FileCopyrightText: 2003 Stephan Zehetner <s.zehetner@nevox.org>
0004     SPDX-FileCopyrightText: 2006 Dmitry Suzdalev <dimsuz@gmail.com>
0005     SPDX-FileCopyrightText: 2006 Inge Wallin <inge@lysator.liu.se>
0006     SPDX-FileCopyrightText: 2006 Pierre Ducroquet <pinaraf@gmail.com>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef KONQUEST_MAP_H
0012 #define KONQUEST_MAP_H
0013 
0014 #include <QList>
0015 #include <QObject>
0016 
0017 #include "sector.h"
0018 #include "../players/player.h"
0019 
0020 
0021 class Map : public QObject
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     Map(int rows, int cols);
0027     ~Map() override;
0028 
0029     int  rows()     { return m_rows;    }
0030     int  columns()  { return m_columns; }
0031 
0032     void    addPlanet(Sector *sector, Player *player, int production, double killpercentage);
0033     Planet* addPlayerPlanetSomewhere(Player *player);
0034     Planet* addNeutralPlanetSomewhere(Player *neutral);
0035     bool    removePlayerPlanet(Player *player);
0036     void    removePlayerPlanets(Player *player);
0037     int     playerPlanetCount(Player *player);
0038     void    turnOverPlayerPlanets(Player* owner, Player* newOwner);
0039 
0040     void    clearMap();
0041     void    resizeMap(int rows, int cols);
0042 
0043     void    populateMap( const QList<Player*> &players, Player *neutral, int numNeutralPlanets);
0044 
0045     double  distance( Planet *p1, Planet *p2 );
0046 
0047     Sector *sector(Coordinate coord)
0048     {
0049         if (coord.y() >= 0 && coord.y() < m_grid.size()) {
0050             if (coord.x() >= 0 && coord.x() < m_grid[coord.y()].size()) {
0051                 return &m_grid[coord.y()][coord.x()];
0052             }
0053         }
0054 
0055         return nullptr;
0056     }
0057 
0058     const QList<Planet*> planets() const;
0059 
0060 protected:
0061     void childSectorUpdate();
0062 
0063 Q_SIGNALS:
0064     void update();
0065 
0066 private:
0067     Sector* findRandomFreeSector();
0068     QString UniquePlanetName() const;
0069 
0070 protected:
0071     // A map is a 2-D array of Sectors.
0072     QList<QList<Sector> > m_grid;
0073     int  m_rows; // size of grid in sectors
0074     int  m_columns;
0075 };
0076 
0077 #endif // KONQUEST_MAP_H