2
Copyright Russell Steffen <rsteffen@bayarea.net>
3
Copyright Stephan Zehetner <s.zehetner@nevox.org>
4
Copyright Dmitry Suzdalev <dimsuz@gmail.com>
5
Copyright Inge Wallin <inge@lysator.liu.se>
6
Copyright Pierre Ducroquet <pinaraf@gmail.com>
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
#include "gamelogic.h"
34
//---------------------------------------------------------------------------
36
//---------------------------------------------------------------------------
38
Player::Player( Map *map, const QString &newName, const QColor &color, int newPlrNum, enum AiLevel level )
40
m_name( newName ), m_color( color ),
41
m_playerNum( newPlrNum ),
44
m_planetsConquered(0),
46
m_enemyFleetsDestroyed(0),
47
m_enemyShipsDestroyed(0),
58
Player::coloredName() const
60
return QString("<font color=\"%1\">%2</font>").arg(m_color.name(), m_name);
64
Player *Player::createNeutralPlayer( Map *map )
66
return new Player( map, "neutral", Qt::gray, NEUTRAL_PLAYER_NUMBER, Human );
71
Player::NewAttack( Planet *sourcePlanet, Planet *destPlanet,
72
int shipCount, int turn )
74
int arrival = int(std::ceil(
75
m_map->distance( sourcePlanet, destPlanet )
79
fleet = sourcePlanet->fleet().spawnAttackFleet( destPlanet, shipCount,
83
m_newAttacks.append(fleet);
91
void Player::doAiMove(GameLogic *gameLogic)
93
int ships, minimumShips, shipCountFactor;
98
// Error, we should not be called for human
104
case ComputerNormal: // Offensive
108
case ComputerHard: // Defensive
114
foreach (Planet *home, gameLogic->planets()) {
115
if (home->player() == gameLogic->currentPlayer()) {
116
bool hasAttack = false;
117
ships = (int)floor(home->ships() * 0.7 );
119
if (ships >= minimumShips) {
120
double minDistance = 100;
122
foreach (Planet *attack, gameLogic->planets()) {
124
double dist = gameLogic->map()->distance( home, attack );
126
if (dist < minDistance
127
&& attack->player() != gameLogic->currentPlayer()
128
&& attack->ships() < ships ) {
129
foreach (AttackFleet *curFleet, gameLogic->currentPlayer()->attackList()) {
130
if (curFleet->destination == attack) {
144
//sendAttackFleet( home, target, ships );
145
gameLogic->currentPlayer()
146
->NewAttack( home, target, ships,
147
gameLogic->turnNumber() );
151
bool hasDestination = false;
153
foreach (Planet *attack, gameLogic->planets()) {
155
double dist = gameLogic->map()->distance( home, attack );
156
int homeships = (int)floor(home->ships() * 0.5 );
158
if (dist < minDistance
159
&& attack->player() == gameLogic->currentPlayer()
160
&& attack->ships() < homeships ) {
161
foreach (AttackFleet *curFleet,
162
gameLogic->currentPlayer()->attackList()) {
163
if (curFleet->destination == attack) {
170
shipsToSend = (int)floor( double(home->ships()
171
- attack->ships()) / shipCountFactor);
174
hasDestination = true;
178
if (hasDestination) {
179
//FIXME: Move sendAttackFleet from GameView
181
//sendAttackFleet( home, target, shipsToSend );
182
gameLogic->currentPlayer()
183
->NewAttack( home, target, shipsToSend,
184
gameLogic->turnNumber() );