~ubuntu-branches/ubuntu/raring/lordsawar/raring

« back to all changes in this revision

Viewing changes to src/game.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese, Gonéri Le Bouder
  • Date: 2008-06-17 11:15:26 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080617111526-yjyvu9df50zmpdo0
Tags: 0.0.9-1
[ Barry deFreese ]
* New upstream release.
  + Fixes gcc-4.3 builds so drop ftbfs_gcc-4.3_fix.diff.
  + Add new build-dependency for libgnet-dev.
* Add simple man page for new lordsawar-tile-editor.
* Add desktop file for lordsawar-tile-editor.
* Remove French translation on install.

[ Gonéri Le Bouder ]
* bump Debian Policy to 3.8.0. No change needed.
* fix wording in the 0.0.8-3 entry of the Debian changelog

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2006, 2007, 2008 Ben Asselstine
 
2
// Copyright (C) 2007, 2008 Ole Laursen
 
3
//
1
4
//  This program is free software; you can redistribute it and/or modify
2
5
//  it under the terms of the GNU General Public License as published by
3
6
//  the Free Software Foundation; either version 2 of the License, or
10
13
//
11
14
//  You should have received a copy of the GNU General Public License
12
15
//  along with this program; if not, write to the Free Software
13
 
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
16
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 
17
//  02110-1301, USA.
14
18
 
15
19
#include <config.h>
16
20
 
28
32
#include "sound.h"
29
33
#include "GraphicsCache.h"
30
34
#include "GameScenario.h"
31
 
#include "QuestsManager.h"
32
35
#include "NextTurn.h"
33
36
 
34
37
#include "gamebigmap.h"
42
45
#include "ruinlist.h"
43
46
#include "templelist.h"
44
47
#include "signpostlist.h"
45
 
#include "armysetlist.h"
46
48
#include "city.h"
47
49
#include "ruin.h"
48
50
#include "signpost.h"
59
61
#include "GameMap.h"
60
62
#include "history.h"
61
63
 
 
64
#include "herotemplates.h"
 
65
 
 
66
Game *Game::current_game = 0;
62
67
 
63
68
//#define debug(x) {cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<flush<<endl;}
64
69
#define debug(x)
72
77
    (*it).disconnect();
73
78
  connections[p->getId()].clear();
74
79
 
75
 
  connections[p->getId()].push_back
76
 
    (p->sdyingStack.connect(sigc::mem_fun(this, &Game::stackDied)));
77
 
 
78
80
  if (p->getType() == Player::HUMAN)
79
81
    {
80
82
      connections[p->getId()].push_back
82
84
      connections[p->getId()].push_back
83
85
        (p->snewMedalArmy.connect(sigc::mem_fun(this, &Game::newMedalArmy)));
84
86
      connections[p->getId()].push_back
85
 
        (p->srecruitingHero.connect
86
 
         (sigc::bind<0>
87
 
          (sigc::mem_fun
88
 
           (hero_offers_service, &sigc::signal<bool, Player *, 
89
 
            Hero *, City *, int>::emit), p)));
 
87
        (p->srecruitingHero.connect(sigc::mem_fun(this, &Game::recruitHero)));
 
88
 
90
89
      connections[p->getId()].push_back
91
90
        (p->streachery.connect
92
91
         (sigc::bind<0>
93
92
          (sigc::mem_fun
94
93
           (stack_considers_treachery, 
95
94
            &sigc::signal<bool, Player *, Stack *, Player *, Vector<int> >::emit), p)));
 
95
      connections[p->getId()].push_back
 
96
        (p->hero_arrives_with_allies.connect
 
97
         (sigc::mem_fun
 
98
          (hero_arrives, &sigc::signal<void, int>::emit)));
96
99
    }
97
100
        
98
101
      
123
126
     (sigc::mem_fun(advice_asked, &sigc::signal<void, float>::emit)));
124
127
}
125
128
 
 
129
#define NETWORK_TESTING 1
 
130
 
 
131
#include "game-server.h"
 
132
 
 
133
GameServer *game_server = 0;
 
134
 
126
135
Game::Game(GameScenario* gameScenario)
127
136
    : d_gameScenario(gameScenario) 
128
137
{
 
138
    current_game = this;
129
139
    input_locked = false;
 
140
 
 
141
#if NETWORK_TESTING
 
142
    game_server = new GameServer();
 
143
    game_server->start();
 
144
#endif
130
145
    
131
146
    // init the bigmap
132
147
    bigmap.reset(new GameBigMap
191
206
    center_view_on_city();
192
207
    update_control_panel();
193
208
 
194
 
    loadHeroTemplates();
 
209
    HeroTemplates::getInstance();
195
210
}
196
211
 
197
212
Game::~Game()
205
220
    }
206
221
    delete d_gameScenario;
207
222
    delete d_nextTurn;
208
 
}
 
223
    
 
224
    HeroTemplates::deleteInstance();
 
225
}
 
226
 
 
227
GameScenario *Game::getScenario()
 
228
{
 
229
  return current_game->d_gameScenario;
 
230
}
 
231
 
209
232
 
210
233
void Game::end_turn()
211
234
{
221
244
{
222
245
    Stack* stack = Playerlist::getActiveplayer()->getActivestack();
223
246
 
224
 
    if (Playerlist::getActiveplayer()->getType() != Player::HUMAN &&
225
 
        GameScenario::s_hidden_map == true)
226
 
      return;
 
247
    //if (Playerlist::getActiveplayer()->getType() != Player::HUMAN &&
 
248
        //GameScenario::s_hidden_map == true)
 
249
      //return;
227
250
    stack_info_changed.emit(stack);
228
251
}
229
252
 
244
267
    s.income = s.cities = 0;
245
268
    for (Citylist::iterator i = Citylist::getInstance()->begin(),
246
269
             end = Citylist::getInstance()->end(); i != end; ++i)
247
 
        if (i->getPlayer() == player)
 
270
        if (i->getOwner() == player)
248
271
        {
249
272
            s.income += i->getGold();
250
273
            ++s.cities;
264
287
void Game::redraw()
265
288
{
266
289
    if (bigmap.get())
 
290
      {
267
291
        bigmap->draw();
 
292
      }
268
293
    if (smallmap.get())
269
294
      {
270
 
        if (Playerlist::getActiveplayer()->getType() == Player::HUMAN ||
271
 
            GameScenario::s_hidden_map == false)
 
295
        //if (Playerlist::getActiveplayer()->getType() == Player::HUMAN ||
 
296
            //GameScenario::s_hidden_map == false)
272
297
          smallmap->draw();
273
298
      }
274
299
}
284
309
void Game::move_selected_stack_dir(int diffx, int diffy)
285
310
{
286
311
  Stack *stack = Playerlist::getActiveplayer()->getActivestack();
 
312
  if (!stack)
 
313
    return;
287
314
  // Get rid of the old path if there is one
288
315
  if (stack->getPath()->size())
289
316
    stack->getPath()->flClear();
351
378
    Playerlist::getActiveplayer()->stackSplit(stack);
352
379
 
353
380
  Playerlist::getActiveplayer()->stackMove(stack);
354
 
                  
355
 
  if (stack->canMove() == false)
 
381
 
 
382
  //maybe we joined another stack
 
383
  stack = Playerlist::getActiveplayer()->getActivestack();
 
384
  if (stack && stack->canMove() == false)
356
385
    {
357
386
      Playerlist::getActiveplayer()->getStacklist()->setActivestack(0);
358
387
      unselect_active_stack();
499
528
    }
500
529
}
501
530
 
502
 
// the parameter is currently not used (=0), but may be used for more detailed
503
 
// descriptions later on
504
531
void Game::stackUpdate(Stack* s)
505
532
{
506
533
  if (!s)
507
534
    s = Playerlist::getActiveplayer()->getActivestack();
508
535
 
 
536
  //FIXME: if player is not to be observed, bail now
509
537
  if (s)
510
 
    smallmap->center_view(s->getPos(), true);
 
538
    smallmap->center_view_on_tile(s->getPos(), true);
511
539
 
512
540
  redraw();
513
541
 
514
542
  update_stack_info();
515
543
  update_control_panel();
516
 
}
517
 
 
518
 
// s is currently unused, but can later be filled with reasonable data
519
 
void Game::stackDied(Stack* s)
520
 
{
521
 
  unselect_active_stack();
522
 
  redraw();
523
 
  update_control_panel();
524
 
}
525
 
 
 
544
 
 
545
  // sleep for a specified amount of time
 
546
  SDL_Delay(Configuration::s_displaySpeedDelay);
 
547
}
526
548
 
527
549
Army::Stat Game::newLevelArmy(Army* a)
528
550
{
529
551
  // don't show a dialog if computer or enemy's armies advance
530
 
  if ((a->getPlayer()->getType() != Player::HUMAN) ||
531
 
      (a->getPlayer() != Playerlist::getInstance()->getActiveplayer()))
 
552
  if ((a->getOwner()->getType() != Player::HUMAN) ||
 
553
      (a->getOwner() != Playerlist::getInstance()->getActiveplayer()))
532
554
    return Army::STRENGTH;
533
555
 
534
556
  return army_gains_level.emit(a);
537
559
void Game::newMedalArmy(Army* a)
538
560
{
539
561
  // We don't want to have medal awards of computer players displayed
540
 
  if (!a->getPlayer()
541
 
      || (a->getPlayer()->getType() != Player::HUMAN)
542
 
      || a->getPlayer() != Playerlist::getInstance()->getActiveplayer())
 
562
  if (!a->getOwner()
 
563
      || (a->getOwner()->getType() != Player::HUMAN)
 
564
      || a->getOwner() != Playerlist::getInstance()->getActiveplayer())
543
565
    return;
544
566
 
545
567
  medal_awarded_to_army.emit(a);
556
578
{
557
579
  if (c)
558
580
    {
559
 
      Player *player = c->getPlayer();
 
581
      Player *player = c->getOwner();
560
582
 
561
583
      if (brief)
562
584
        {
644
666
{
645
667
  if (s)
646
668
    {
647
 
      Rectangle r = s->get_area();
648
 
      //r.w *= s->size();
649
 
      MapTipPosition mpos = bigmap->map_tip_position(r);
 
669
      MapTipPosition mpos = bigmap->map_tip_position(s->getPos());
650
670
      stack_tip_changed.emit(s, mpos);
651
671
    }
652
672
  else
680
700
  Citylist *clist = Citylist::getInstance();
681
701
  Playerlist *plist = Playerlist::getInstance();
682
702
  Player *attacker = plist->getActiveplayer();
683
 
  Player *defender = city->getPlayer();
 
703
  Player *defender = city->getOwner();
684
704
  int amt = (defender->getGold() / (2 * clist->countCities (defender)) * 2);
685
705
  // give (Enemy-Gold/(2Enemy-Cities)) to the attacker 
686
706
  // and then take away twice that from the defender.
693
713
  return;
694
714
}
695
715
 
696
 
void Game::invading_city(City* city)
 
716
void Game::invading_city(City* city, int gold)
697
717
{
698
 
  Playerlist *plist = Playerlist::getInstance();
699
 
  Player *player = plist->getActiveplayer();
700
 
  int gold = 0;
701
 
 
702
 
  // See if this is the last city for that player, and alter the 
703
 
  // diplomatic scores.
704
 
  if (Citylist::getInstance()->countCities(city->getPlayer()) == 1)
705
 
    {
706
 
      if (city->getPlayer()->getDiplomaticRank() < 
707
 
          player->getDiplomaticRank())
708
 
        player->deteriorateDiplomaticRelationship (2);
709
 
      else if (city->getPlayer()->getDiplomaticRank() > 
710
 
          player->getDiplomaticRank())
711
 
        player->improveDiplomaticRelationship (2, city->getPlayer());
712
 
    }
713
 
 
714
 
  // loot the city
715
 
  // if the attacked city isn't neutral, loot some gold
716
 
  if (city->getPlayer() != plist->getNeutral())
717
 
    looting_city (city, gold);
718
 
 
719
 
  if (!input_locked)
 
718
  Player *player = Playerlist::getInstance()->getActiveplayer();
 
719
  
 
720
  if (player->getType() == Player::HUMAN)
720
721
    {
721
722
      redraw();
722
723
      CityDefeatedAction a = city_defeated.emit(city, gold);
750
751
        city_visited.emit(city);
751
752
    }
752
753
 
753
 
  //fixme: check for end of game here
754
754
  redraw();
755
755
  update_stack_info();
756
756
  update_sidebar_stats();
833
833
  if (stack)
834
834
    {
835
835
      can_move_selected_stack_along_path.emit
836
 
        (stack->getPath()->size() > 0 && stack->enoughMoves() ||
837
 
         (stack->getPath()->size() && stack->getMovesExhaustedAtPoint() > 0));
 
836
        (!stack->getPath()->empty() && stack->enoughMoves() ||
 
837
         (!stack->getPath()->empty() && stack->getPath()->getMovesExhaustedAtPoint() > 0));
838
838
 
839
839
      /*
840
840
       * a note about searching.
948
948
 
949
949
void Game::startGame()
950
950
{
951
 
 
952
951
  debug ("start_game()");
953
952
  lock_inputs();
954
953
 
955
954
  d_nextTurn->start();
956
 
  update_control_panel();
 
955
  if (Playerlist::getInstance()->countPlayersAlive())
 
956
    update_control_panel();
957
957
}
958
958
 
959
959
void Game::loadGame()
970
970
      update_stack_info();
971
971
      game_loaded.emit(player);
972
972
    }
 
973
 
 
974
  d_nextTurn->setContinuingTurn();
 
975
  d_nextTurn->start();
 
976
#if 0
973
977
  else
974
978
    {
975
979
      lock_inputs();
976
980
      update_sidebar_stats();
977
981
      player->startTurn();
978
982
      d_nextTurn->endTurn();
979
 
      update_control_panel();
 
983
      if (Playerlist::getInstance()->countPlayersAlive())
 
984
        update_control_panel();
980
985
    }
 
986
#endif
981
987
}
982
988
 
983
989
void Game::stopGame()
991
997
  return d_gameScenario->saveGame(file);
992
998
}
993
999
 
994
 
 
995
 
/*
996
 
 *
997
 
 * what are the chances of a hero showing up?
998
 
 *
999
 
 * 1 in 6 if you have enough gold, where "enough gold" is...
1000
 
 *
1001
 
 * ... 1500 if the player already has a hero, then:  1500 is generally 
1002
 
 * enough to buy all the heroes.  I forget the exact distribution of 
1003
 
 * hero prices but memory says from 1000 to 1500.  (But, if you don't 
1004
 
 * have 1500 gold, and the price is less, you still get the offer...  
1005
 
 * So, calculate price, compare to available gold, then decided whether 
1006
 
 * or not to offer...)
1007
 
 *
1008
 
 * ...500 if all your heroes are dead: then prices are cut by about 
1009
 
 * a factor of 3.
1010
 
 */
1011
 
void Game::maybeRecruitHero (Player *p)
1012
 
{
1013
 
  City *city;
1014
 
  Playerlist *plist = Playerlist::getInstance();
1015
 
  int gold_needed = 0;
1016
 
  if (Citylist::getInstance()->countCities(p) == 0)
1017
 
    return;
1018
 
  //give the player a hero if it's the first round.
1019
 
  //otherwise we get a hero based on chance
1020
 
  //a hero costs a random number of gold pieces
1021
 
  if (d_gameScenario->getRound() == 0)
1022
 
    gold_needed = 0;
1023
 
  else
1024
 
    {
1025
 
      bool exists = false;
1026
 
      Stacklist *stacklist = p->getStacklist();
1027
 
      for (Stacklist::iterator it = stacklist->begin(); 
1028
 
           it != stacklist->end(); it++)
1029
 
        if ((*it)->hasHero())
1030
 
          exists = true; 
1031
 
 
1032
 
      gold_needed = (rand() % 500) + 1000;
1033
 
      if (exists == false)
1034
 
        gold_needed /= 3;
1035
 
    }
1036
 
 
1037
 
  //we set the chance of some hero recruitment to, ehm, 10 percent
1038
 
  if (((((rand() % 6) == 0) && (gold_needed < p->getGold())) 
1039
 
       || gold_needed == 0)
1040
 
      && (p != plist->getNeutral()))
1041
 
    {
1042
 
      const Armysetlist* al = Armysetlist::getInstance();
1043
 
      int num = rand() % d_herotemplates[p->getId()].size();
1044
 
      Hero *templateHero = d_herotemplates[p->getId()][num];
1045
 
      const Army *heroType = al->getArmy (p->getArmyset(), 
1046
 
                                          templateHero->getType());
1047
 
      Hero* newhero = new Hero(*heroType, templateHero->getName(), p);
1048
 
      newhero->setGender(Army::Gender(templateHero->getGender()));
1049
 
      if (gold_needed == 0)
1050
 
        city = Citylist::getInstance()->getFirstCity(p);
1051
 
      else
1052
 
        {
1053
 
          std::vector<City*> cities;
1054
 
          Citylist* cl = Citylist::getInstance();
1055
 
          for (Citylist::iterator it = cl->begin(); it != cl->end(); ++it)
1056
 
            if (!(*it).isBurnt() && (*it).getPlayer() == p)
1057
 
              cities.push_back(&(*it));
1058
 
          if (cities.empty())
1059
 
            return;
1060
 
          city = cities[rand() % cities.size()];
1061
 
        }
1062
 
 
1063
 
      bool accepted = p->recruitHero(newhero, city, gold_needed);
1064
 
      if (accepted)
1065
 
        {
1066
 
          History_HeroEmerges *item = new History_HeroEmerges();
1067
 
          item->fillData(newhero, city);
1068
 
          p->getHistorylist()->push_back(item);
1069
 
 
1070
 
          newhero->setPlayer(p);
1071
 
 
1072
 
          int alliesCount;
1073
 
          GameMap::getInstance()->addArmy(city, newhero);
1074
 
          /* now maybe add a few allies */
1075
 
          if (gold_needed > 1300)
1076
 
            alliesCount = 3;
1077
 
          else if (gold_needed > 1000)
1078
 
            alliesCount = 2;
1079
 
          else if (gold_needed > 800)
1080
 
            alliesCount = 1;
1081
 
          else
1082
 
            alliesCount = 0;
1083
 
 
1084
 
          if (alliesCount > 0)
1085
 
            {
1086
 
              const Army *army = Reward_Allies::randomArmyAlly();
1087
 
              if (army)
1088
 
                {
1089
 
                  Reward_Allies::addAllies(p, city->getPos(), army,alliesCount);
1090
 
                  if (p->getType() == Player::HUMAN)
1091
 
                    hero_arrives.emit(alliesCount);
1092
 
                }
1093
 
            }
1094
 
          if (gold_needed == 0)
1095
 
            {
1096
 
              // Initially give the first hero the player's standard.
1097
 
              std::string name = p->getName() + " " + _("Standard");
1098
 
              Item *battle_standard = new Item (name, true, p);
1099
 
              battle_standard->setBonus(Item::ADD1STACK);
1100
 
              newhero->addToBackpack(battle_standard, 0);
1101
 
            }
1102
 
          p->withdrawGold(gold_needed);
1103
 
          p->supdatingStack.emit(0);
1104
 
        }
1105
 
      else
1106
 
        delete newhero;
1107
 
    }
1108
 
  return;
1109
 
}
1110
 
 
1111
 
int
1112
 
Game::loadHeroTemplates()
1113
 
{
1114
 
  FILE *fileptr = fopen (File::getMiscFile("heronames").c_str(), "r");
1115
 
  char *line = NULL;
1116
 
  size_t len = 0;
1117
 
  ssize_t read;
1118
 
  int retval;
1119
 
  int gender;
1120
 
  int side;
1121
 
  size_t bytesread = 0;
1122
 
  char *tmp;
1123
 
  const Armysetlist* al = Armysetlist::getInstance();
1124
 
  const Army* herotype;
1125
 
 
1126
 
  // list all the army types that are heroes.
1127
 
  std::vector<const Army*> heroes;
1128
 
  Player *p = Playerlist::getInstance()->getNeutral();
1129
 
  for (unsigned int j = 0; j < al->getSize(p->getArmyset()); j++)
1130
 
    {
1131
 
      const Army *a = al->getArmy (p->getArmyset(), j);
1132
 
      if (a->isHero())
1133
 
        heroes.push_back(a);
1134
 
    }
1135
 
 
1136
 
  if (fileptr == NULL)
1137
 
    return -1;
1138
 
  while ((read = getline (&line, &len, fileptr)) != -1)
1139
 
    {
1140
 
      bytesread = 0;
1141
 
      retval = sscanf (line, "%d%d%n", &side, &gender, &bytesread);
1142
 
      if (retval != 2)
1143
 
        {
1144
 
          free (line);
1145
 
          return -2;
1146
 
        }
1147
 
      while (isspace(line[bytesread]) && line[bytesread] != '\0')
1148
 
        bytesread++;
1149
 
      tmp = strchr (&line[bytesread], '\n');
1150
 
      if (tmp)
1151
 
        tmp[0] = '\0';
1152
 
      if (strlen (&line[bytesread]) == 0)
1153
 
        {
1154
 
          free (line);
1155
 
          return -3;
1156
 
        }
1157
 
      if (side < 0 || side > (int) MAX_PLAYERS)
1158
 
        {
1159
 
          free (line);
1160
 
          return -4;
1161
 
        }
1162
 
 
1163
 
      herotype = heroes[rand() % heroes.size()];
1164
 
      Hero *newhero = new Hero (*herotype, "", NULL);
1165
 
      if (gender)
1166
 
        newhero->setGender(Hero::MALE);
1167
 
      else
1168
 
        newhero->setGender(Hero::FEMALE);
1169
 
      newhero->setName (&line[bytesread]);
1170
 
      d_herotemplates[side].push_back (newhero);
1171
 
    }
1172
 
  if (line)
1173
 
    free (line);
1174
 
  fclose (fileptr);
1175
 
  return 0;
1176
 
}
1177
 
 
1178
 
bool Game::init_turn_for_player(Player* p)
 
1000
void Game::init_turn_for_player(Player* p)
1179
1001
{
1180
1002
  Playerlist* pl = Playerlist::getInstance();
1181
 
  // FIXME: Currently this function only checks for a human player. You
1182
 
  // can also have it check for e.g. escape key pressed to interrupt
1183
 
  // an AI-only game to save/quit.
1184
1003
 
 
1004
  if (GameScenario::s_hidden_map && p->getType() == Player::HUMAN)
 
1005
    {
 
1006
      smallmap->blank();
 
1007
      bigmap->blank();
 
1008
    }
 
1009
  next_player_turn.emit(p, d_gameScenario->getRound() + 1);
1185
1010
  center_view_on_city();
1186
 
  if (Playerlist::isFinished())
1187
 
    return true; //closing game window while the computer is moving
1188
 
 
1189
 
  next_player_turn.emit(p, d_gameScenario->getRound() + 1);
1190
1011
  if (p->getType() == Player::HUMAN)
1191
1012
    {
1192
1013
      unlock_inputs();
1193
1014
 
1194
 
 
1195
1015
      update_sidebar_stats();
1196
1016
      update_stack_info();
1197
1017
      update_control_panel();
1198
1018
 
1199
 
      QuestsManager::getInstance()->nextTurn(p);
1200
 
 
1201
 
      maybeRecruitHero(p);
1202
 
 
1203
 
      if (d_gameScenario->getRound() == 0)
1204
 
        {
1205
 
          Citylist *clist = Citylist::getInstance();
1206
 
          city_visited.emit(clist->getFirstCity(p));
1207
 
        }
 
1019
      //if (d_gameScenario->getRound() == 0)
 
1020
        //{
 
1021
          //Citylist *clist = Citylist::getInstance();
 
1022
          //city_visited.emit(clist->getFirstCity(p));
 
1023
        //}
1208
1024
 
1209
1025
      // update the diplomacy icon if we've received a proposal
1210
1026
      bool proposal_received = false;
1223
1039
            }
1224
1040
        }
1225
1041
      received_diplomatic_proposal.emit(proposal_received);
1226
 
 
1227
 
      return true;
1228
1042
    }
1229
1043
  else
1230
1044
    {
1231
1045
      SDL_Delay(250);
1232
 
      QuestsManager::getInstance()->nextTurn(p);
1233
 
      maybeRecruitHero(p);
1234
 
      if (d_gameScenario->s_cusp_of_war == true &&
1235
 
          d_gameScenario->getRound() == CUSP_OF_WAR_ROUND)
1236
 
        {
1237
 
          for (Playerlist::iterator it = pl->begin(); it != pl->end(); ++it)
1238
 
            if ((*it)->getType() == Player::HUMAN)
1239
 
              {
1240
 
                if ((*it)->isDead())
1241
 
                  continue;
1242
 
                if (p->getDiplomaticState(*it) != Player::AT_WAR)
1243
 
                  {
1244
 
                    p->proposeDiplomacy (Player::PROPOSE_WAR, *it);
1245
 
                    (*it)->proposeDiplomacy (Player::PROPOSE_WAR, p);
1246
 
                    p->declareDiplomacy (Player::AT_WAR, *it);
1247
 
  
1248
 
                    History_DiplomacyWar *item1 = new History_DiplomacyWar();
1249
 
                    item1->fillData(*it);
1250
 
                    p->getHistorylist()->push_back(item1);
1251
 
                  }
1252
 
              }
1253
 
        }
1254
 
          return false;
1255
1046
    }
1256
1047
}
1257
1048
 
1266
1057
 
1267
1058
void Game::on_fight_started(Fight &fight)
1268
1059
{
1269
 
  Player* pd = (*(fight.getDefenders().begin()))->getPlayer();
1270
 
  Player* pa = (*(fight.getAttackers().begin()))->getPlayer();
 
1060
#if 0
 
1061
  Player* pd = fight.getDefenders().front()->getOwner();
 
1062
  Player* pa = fight.getAttackers().front()->getOwner();
1271
1063
  if ((pa->getType() == Player::HUMAN || pd->getType() == Player::HUMAN) ||
1272
1064
      (pa->getType() != Player::HUMAN && pd->getType() != Player::HUMAN 
1273
1065
       && pd != Playerlist::getInstance()->getNeutral()))
1274
 
    {
 
1066
  {
1275
1067
 
1276
 
      if (Playerlist::getActiveplayer()->getType() != Player::HUMAN &&
1277
 
          GameScenario::s_hidden_map == true)
1278
 
        return;
1279
 
    }
 
1068
    //short circuit the battle sequence
 
1069
    if (pa->getType() != Player::HUMAN && pd->getType() != Player::HUMAN &&
 
1070
        GameScenario::s_hidden_map == true)
 
1071
      return;
 
1072
  }
1280
1073
  else
1281
 
    {
1282
 
      //short circuit the battle sequence
1283
 
      fight.battle(GameScenario::s_intense_combat);
1284
 
      return;
1285
 
    }
 
1074
    return; //short circuit the battle sequence
 
1075
#endif
 
1076
  
 
1077
  //FIXME: zoom the map here if we're attacking an observable human, 
 
1078
  //from an unobservable computer player
1286
1079
  bigmap->setFighting(true);
1287
1080
  bigmap->draw();
1288
 
  fight_started.emit(fight, GameScenario::s_intense_combat);
 
1081
  fight_started.emit(fight);
1289
1082
  bigmap->setFighting(false);
1290
1083
  bigmap->draw();
1291
1084
}
1296
1089
 
1297
1090
  if (p == Playerlist::getInstance()->getNeutral())
1298
1091
    return;
 
1092
  if (Playerlist::getActiveplayer()->getType() != Player::HUMAN &&
 
1093
      GameScenario::s_hidden_map == true)
 
1094
    return;
 
1095
  //FIXME: if player is not to be observed, bail now
1299
1096
  // preferred city is a capital city that belongs to the player 
1300
1097
  for (Citylist::iterator i = Citylist::getInstance()->begin();
1301
1098
       i != Citylist::getInstance()->end(); i++)
1302
1099
    {
1303
 
      if (i->getPlayer() == p && i->isCapital())
 
1100
      if (i->getOwner() == p && i->isCapital() &&
 
1101
          i->getCapitalOwner() == p)
1304
1102
        {
1305
 
          smallmap->center_view(i->getPos(), true);
 
1103
          smallmap->center_view_on_tile(i->getPos(), 
 
1104
                                        !GameScenario::s_hidden_map);
1306
1105
          return;
1307
1106
        }
1308
1107
    }
1311
1110
  for (Citylist::iterator i = Citylist::getInstance()->begin();
1312
1111
       i != Citylist::getInstance()->end(); i++)
1313
1112
    {
1314
 
      if (i->getPlayer() == p)
 
1113
      if (i->getOwner() == p)
1315
1114
        {
1316
1115
          if (Playerlist::isFinished())
1317
1116
            return;
1318
 
          smallmap->center_view(i->getPos(), true);
 
1117
          smallmap->center_view_on_tile(i->getPos(), 
 
1118
                                        !GameScenario::s_hidden_map);
1319
1119
          break;
1320
1120
        }
1321
1121
    }
1322
1122
}
1323
1123
void Game::select_active_stack()
1324
1124
{
 
1125
  //if (Playerlist::getActiveplayer()->getType() != Player::HUMAN &&
 
1126
      //GameScenario::s_hidden_map == true)
 
1127
    //return;
1325
1128
  Player *p = Playerlist::getInstance()->getActiveplayer();
1326
 
  smallmap->center_view(p->getActivestack()->getPos(), true);
 
1129
  smallmap->center_view_on_tile (p->getActivestack()->getPos(), true);
1327
1130
  bigmap->select_active_stack();
1328
1131
}
1329
1132
void Game::unselect_active_stack()
1333
1136
 
1334
1137
bool Game::maybeTreachery(Stack *stack, Player *them, Vector<int> pos)
1335
1138
{
1336
 
  Player *me = stack->getPlayer();
 
1139
  Player *me = stack->getOwner();
1337
1140
  bool treachery = me->treachery (stack, them, pos);
1338
1141
  if (treachery == false)
1339
1142
    return false;
1389
1192
      //if this is a neutral city, and we're playing with 
1390
1193
      //active neutral cities, AND it hasn't already been attacked
1391
1194
      //then it's production gets turned on
1392
 
      Player *neu = city->getPlayer(); //neutral player
 
1195
      Player *neu = city->getOwner(); //neutral player
1393
1196
      if (GameScenario::s_neutral_cities == GameParameters::ACTIVE &&
1394
1197
          neu == Playerlist::getInstance()->getNeutral() &&
1395
 
          city->getProductionIndex() == -1)
 
1198
          city->getActiveProductionSlot() == -1)
1396
1199
        {
1397
1200
          //great, then let's turn on the production.
1398
1201
          //well, we already made a unit, and we want to produce more
1401
1204
          if (o)
1402
1205
            {
1403
1206
              int army_type = o->getStrongestArmy()->getType();
1404
 
              for (int i = 0; i < 4; i++)
 
1207
              for (int i = 0; i < city->getMaxNoOfProductionBases(); i++)
1405
1208
                {
1406
1209
                  if (city->getArmytype(i) == army_type)
1407
1210
                    {
1408
1211
                      // hey, we found the droid we were looking for
1409
 
                      city->setProduction(i);
 
1212
                      city->setActiveProductionSlot(i);
1410
1213
                      break;
1411
1214
                    }
1412
1215
                }
1415
1218
    }
1416
1219
  return;
1417
1220
}
 
1221
    
 
1222
bool Game::recruitHero(Hero *hero, City *city, int gold)
 
1223
{
 
1224
  bool retval = hero_offers_service (city->getOwner(), hero, city, gold);
 
1225
  if (d_gameScenario->getRound() == 0)
 
1226
    city_visited.emit(city);
 
1227
  return retval;
 
1228
}