initial commit, lordsawar source, slightly modified
[lordsawar] / src / real_player.cpp
1 // Copyright (C) 2002, 2003 Michael Bartl
2 // Copyright (C) 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2004, 2006 Andrea Paternesi
4 // Copyright (C) 2004 John Farrell
5 // Copyright (C) 2004 Bryan Duff
6 // Copyright (C) 2006, 2007, 2008, 2009 Ben Asselstine
7 // Copyright (C) 2007, 2008 Ole Laursen
8 //
9 //  This program is free software; you can redistribute it and/or modify
10 //  it under the terms of the GNU General Public License as published by
11 //  the Free Software Foundation; either version 3 of the License, or
12 //  (at your option) any later version.
13 //
14 //  This program is distributed in the hope that it will be useful,
15 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 //  GNU Library General Public License for more details.
18 //
19 //  You should have received a copy of the GNU General Public License
20 //  along with this program; if not, write to the Free Software
21 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
22 //  02110-1301, USA.
23
24 #include <fstream>
25 #include <algorithm>
26 #include <stdlib.h>
27
28 #include "real_player.h"
29 #include "action.h"
30 #include "history.h"
31 #include "playerlist.h"
32 #include "stacklist.h"
33 #include "citylist.h"
34 #include "city.h"
35 #include "herotemplates.h"
36 #include "game.h"
37 #include "xmlhelper.h"
38 #include "GameScenarioOptions.h"
39 #include "Sage.h"
40
41 using namespace std;
42
43 //#define debug(x) {cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<endl<<flush;}
44 #define debug(x)
45
46 RealPlayer::RealPlayer(string name, guint32 armyset, Gdk::Color color, int width,
47                        int height, Player::Type type, int player_no)
48     :Player(name, armyset, color, width, height, type, player_no),
49     d_abort_requested(false)
50 {
51 }
52
53 RealPlayer::RealPlayer(const Player& player)
54     :Player(player)
55 {
56     d_type = HUMAN;
57     d_abort_requested = false;
58 }
59
60 RealPlayer::RealPlayer(XML_Helper* helper)
61     :Player(helper), d_abort_requested(false)
62 {
63 }
64
65 RealPlayer::~RealPlayer()
66 {
67 }
68
69 bool RealPlayer::save(XML_Helper* helper) const
70 {
71     // This may seem a bit dumb, but allows derived players (especially
72     // AI's) to save additional data, such as character types or so.
73     bool retval = true;
74     retval &= helper->openTag(Player::d_tag);
75     retval &= Player::save(helper);
76     retval &= helper->closeTag();
77
78     return retval;
79 }
80
81 void RealPlayer::abortTurn()
82 {
83   aborted_turn.emit();
84 }
85
86 bool RealPlayer::startTurn()
87 {
88   return false;
89 }
90
91 void RealPlayer::endTurn()
92 {
93   History *history = new History_EndTurn();
94   addHistory(history);
95   pruneActionlist();
96   Action *action = new Action_EndTurn;
97   addAction(action);
98 }
99
100 void RealPlayer::invadeCity(City* c)
101 {
102     // For the realplayer, this function doesn't do a lot. However, an AI
103     // player has to decide here what to do (occupy, raze, pillage)
104 }
105
106 bool RealPlayer::chooseHero(HeroProto *hero, City* c, int gold)
107 {
108     // For the realplayer, this function doesn't do a lot. However, an AI
109     // player has to decide here what to do (accept/deny hero)
110     return false;
111 }
112
113 Reward *RealPlayer::chooseReward(Ruin *ruin, Sage *sage, Stack *stack)
114 {
115     // For the realplayer, this function doesn't do a lot. However, an AI
116     // player has to decide here what to do (pick a reward from sage)
117     return NULL;
118 }
119
120 bool RealPlayer::chooseTreachery (Stack *stack, Player *player, Vector <int> pos)
121 {
122     // For the realplayer, this function doesn't do a lot. However, an AI
123     // player has to decide here what to do (fight a friend or not)
124   return true;
125 }
126
127 Army::Stat RealPlayer::chooseStat(Hero *hero)
128 {
129     // For the realplayer, this function doesn't do a lot. However, an AI
130     // player has to decide here what to do (pick strength/moves/sight stat)
131   return Army::STRENGTH;
132 }
133
134 bool RealPlayer::chooseQuest(Hero *hero)
135 {
136   //we decide interactively with the gui, not by this method.
137   // For the realplayer, this function doesn't do a lot. However, an AI
138   // player has to decide here what to do (get a quest for the hero or not)
139   return true;
140 }
141
142 void RealPlayer::heroGainsLevel(Hero* a)
143 {
144     // the standard human player just asks the GUI what to do
145     Army::Stat stat = sheroGainsLevel.emit(a);
146     doHeroGainsLevel(a, stat);
147
148     Action_Level* item = new Action_Level();
149     item->fillData(a, stat);
150     addAction(item);
151 }
152 // End of file