initial commit, lordsawar source, slightly modified
[lordsawar] / src / Commentator.cpp
1 // Copyright (C) 2009 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
16 //  02110-1301, USA.
17
18 #include "Commentator.h"
19 #include "player.h"
20 #include "defs.h"
21 #include "playerlist.h"
22 #include "stack.h"
23 #include "GameMap.h"
24 #include "stacklist.h"
25 #include "citylist.h"
26 #include "city.h"
27
28 using namespace std;
29
30 Commentator* Commentator::d_instance = 0;
31
32 Commentator* Commentator::getInstance()
33 {
34     if (!d_instance)
35         d_instance = new Commentator();
36
37     return d_instance;
38 }
39
40 void Commentator::deleteInstance()
41 {
42     if (d_instance != 0)
43         delete d_instance;
44
45     d_instance = 0;
46 }
47
48 Commentator::Commentator()
49 {
50 }
51
52 Commentator::~Commentator()
53 {
54 }
55
56 bool Commentator::hasComment() const
57 {
58   if ((rand() % MAX_PLAYERS) == 0)
59     return true;
60   return false;
61 }
62
63 std::vector<std::string> Commentator::getComments(Player *player) const
64 {
65   std::vector<std::string> comments;
66   guint32 round = player->countEndTurnHistoryEntries();
67
68   if (round < 2)
69     return comments;
70
71   if (player->getGold() < 100)
72     comments.push_back(_("You are sadly in need of gold!"));
73   else if (player->getGold() > 2500)
74     {
75       comments.push_back(_("Your wealth is greather than the mightiest of dragons!"));
76       comments.push_back(_("All your gold must surely be a burden!"));
77     }
78   std::list<Hero*> heroes = player->getHeroes();
79   if (heroes.size() == 0)
80     comments.push_back(_("Will no hero defend your honour?"));
81   else if (heroes.size() > 3)
82     comments.push_back(_("I see heroes are flocking to your banner!"));
83         
84   if (round > 5 && player->getScore() < 10)
85     {
86       comments.push_back(_("Your enemies mock your feeble endeavours!"));
87       comments.push_back(_("How much adversity can you endure?"));
88       comments.push_back(_("Your enemies are beyond measure!"));
89       comments.push_back(_("Your dreams of conquest confound you!"));
90     }
91   else if (round > 30 && player->getScore() < 10)
92     comments.push_back(_("Your sorry efforts have come to nought!"));
93
94   if (player->getScore() >= 40 && round >= 10)
95     {
96       comments.push_back(_("Victory is just beyond your reach!"));
97       comments.push_back(_("Your destiny is forged in steel!"));
98       comments.push_back(_("You stand at the crossroads of victory!"));
99       comments.push_back(_("Attack is the best means of defence!"));
100       comments.push_back(_("Do you feel the wolves snapping at your heels?"));
101     }
102   else if (player->getScore() >= 30 && round < 15)
103     comments.push_back(_("Warlord!  Your progress is astounding!"));
104   else if (player->getScore() >= 20 && round <= 20)
105     {
106       comments.push_back(_("So, Warlord, you show some merit!"));
107       comments.push_back(_("You are doing well... ...so far!"));
108     }
109
110   if (player == Playerlist::getInstance()->getWinningPlayer())
111     {
112       comments.push_back(_("Beware!  Lest overconfidence consume you!"));
113       comments.push_back(_("Your name evokes fear and loathing!"));
114     }
115   guint32 attacking_enemy_cities = 0;
116   for (Stacklist::iterator it = player->getStacklist()->begin(); it != player->getStacklist()->end(); it++)
117     {
118       Stack *stack = *it;
119       if (stack->hasPath() && 
120           GameMap::getEnemyCity(stack->getLastPointInPath()) != NULL)
121         attacking_enemy_cities++;
122     }
123   if (attacking_enemy_cities > 0)
124     comments.push_back(_("Ahh, the expectation of a coming battle!"));
125
126   if (attacking_enemy_cities > 4)
127     comments.push_back(_("Warlord... a might battle is brewing!"));
128
129   City *capital_city = Citylist::getInstance()->getCapitalCity(player);
130   if (capital_city->getOwner() != player)
131     comments.push_back(_("As your capital city has fallen, so shall you!"));
132   return comments;
133 }