~ubuntu-branches/ubuntu/precise/lordsawar/precise

« back to all changes in this revision

Viewing changes to src/gui/game-window.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2007-10-29 15:38:06 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071029153806-z2j47adhmdjc7wae
Tags: 0.0.4-1
* New upstream release
* Add desktop file and simple manpage for new binary lordsawar-army-editor
* Syntax fixes on manpages
* Move manpages to correct section (6)

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
#include "army-gains-level-dialog.h"
53
53
#include "hero-dialog.h"
54
54
#include "sage-dialog.h"
 
55
#include "ruin-rewarded-dialog.h"
55
56
#include "hero-offer-dialog.h"
56
57
#include "quest-report-dialog.h"
57
58
#include "quest-assigned-dialog.h"
64
65
#include "item-bonus-dialog.h"
65
66
#include "history-report-dialog.h"
66
67
#include "report-dialog.h"
 
68
#include "triumphs-dialog.h"
67
69
 
68
70
#include "../ucompose.hpp"
69
71
#include "../defs.h"
98
100
#include "../reward.h"
99
101
#include "../Configuration.h"
100
102
#include "../GameMap.h"
 
103
#include "../Item.h"
101
104
 
102
105
 
103
106
GameWindow::GameWindow()
111
114
    xml->get_widget("window", w);
112
115
    window.reset(w);
113
116
 
114
 
    w->signal_delete_event().connect(
115
 
        sigc::mem_fun(*this, &GameWindow::on_delete_event));
 
117
      w->signal_delete_event().connect
 
118
       (sigc::mem_fun(*this, &GameWindow::on_delete_event));
116
119
 
117
120
    xml->get_widget("sdl_container", sdl_container);
118
121
    xml->get_widget("stack_info_box", stack_info_box);
132
135
    xml->get_widget("map_eventbox", map_eventbox);
133
136
    map_eventbox->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK |
134
137
                             Gdk::POINTER_MOTION_MASK);
135
 
    map_eventbox->signal_button_press_event().connect(
136
 
        sigc::mem_fun(*this, &GameWindow::on_map_mouse_button_event));
137
 
    map_eventbox->signal_button_release_event().connect(
138
 
        sigc::mem_fun(*this, &GameWindow::on_map_mouse_button_event));
139
 
    map_eventbox->signal_motion_notify_event().connect(
140
 
        sigc::mem_fun(*this, &GameWindow::on_map_mouse_motion_event));
 
138
      map_eventbox->signal_button_press_event().connect
 
139
       (sigc::mem_fun(*this, &GameWindow::on_map_mouse_button_event));
 
140
      map_eventbox->signal_button_release_event().connect
 
141
       (sigc::mem_fun(*this, &GameWindow::on_map_mouse_button_event));
 
142
      map_eventbox->signal_motion_notify_event().connect
 
143
       (sigc::mem_fun(*this, &GameWindow::on_map_mouse_motion_event));
141
144
 
142
145
    // the stats
143
 
    xml->get_widget("stats_label", stats_label);
144
 
    stats_text = stats_label->get_text();
145
146
    Gtk::Image *image;
146
147
    xml->get_widget("cities_stats_image", image);
147
 
    image->property_file() = File::getMiscFile("various/items.png");
 
148
    image->property_file() = File::getMiscFile("various/smallcity.png");
148
149
    xml->get_widget("gold_stats_image", image);
149
 
    image->property_file() = File::getMiscFile("various/items.png");
 
150
    image->property_file() = File::getMiscFile("various/smalltreasury.png");
150
151
    xml->get_widget("income_stats_image", image);
151
 
    image->property_file() = File::getMiscFile("various/items.png");
 
152
    image->property_file() = File::getMiscFile("various/smallincome.png");
 
153
    xml->get_widget("upkeep_stats_image", image);
 
154
    image->property_file() = File::getMiscFile("various/smallupkeep.png");
152
155
    
153
156
    xml->get_widget("cities_stats_label", cities_stats_label);
154
157
    xml->get_widget("gold_stats_label", gold_stats_label);
155
158
    xml->get_widget("income_stats_label", income_stats_label);
 
159
    xml->get_widget("upkeep_stats_label", upkeep_stats_label);
156
160
    xml->get_widget("turn_label", turn_label);
157
161
    xml->get_widget("turn_hbox", turn_hbox);
158
162
    xml->get_widget("shield_image_0", shield_image[0]);
169
173
    xml->get_widget("center_button", center_button);
170
174
    xml->get_widget("defend_button", defend_button);
171
175
    xml->get_widget("park_button", park_button);
 
176
    xml->get_widget("deselect_button", deselect_button);
172
177
    xml->get_widget("search_button", search_button);
173
178
    xml->get_widget("move_button", move_button);
174
179
    xml->get_widget("move_all_button", move_all_button);
181
186
    center_button->add(*manage(new Gtk::Image(button_images[5])));
182
187
    defend_button->add(*manage(new Gtk::Image(button_images[6])));
183
188
    park_button->add(*manage(new Gtk::Image(button_images[1])));
 
189
    deselect_button->add(*manage(new Gtk::Image(button_images[7])));
184
190
    search_button->add(*manage(new Gtk::Image(button_images[9])));
185
191
    move_button->add(*manage(new Gtk::Image(button_images[3])));
186
192
    move_all_button->add(*manage(new Gtk::Image(button_images[4])));
240
246
                         sigc::mem_fun(*this, &GameWindow::on_item_bonus_activated));
241
247
    xml->connect_clicked("production_report_menuitem",
242
248
                         sigc::mem_fun(*this, &GameWindow::on_production_report_activated));
 
249
    xml->connect_clicked("triumphs_menuitem",
 
250
                         sigc::mem_fun(*this, &GameWindow::on_triumphs_activated));
243
251
    d_quick_fights = false;
244
252
}
245
253
 
246
254
GameWindow::~GameWindow()
247
255
{
 
256
  std::list<sigc::connection>::iterator it = connections.begin();
 
257
  for (; it != connections.end(); it++) 
 
258
    (*it).disconnect();
 
259
  connections.clear();
248
260
    clear_army_buttons();
249
261
}
250
262
 
254
266
    center_button->show_all();
255
267
    defend_button->show_all();
256
268
    park_button->show_all();
 
269
    deselect_button->show_all();
257
270
    search_button->show_all();
258
271
    move_button->show_all();
259
272
    move_all_button->show_all();
284
297
    sdl_widget->set_flags(Gtk::CAN_FOCUS);
285
298
 
286
299
    sdl_widget->grab_focus();
287
 
    sdl_widget->add_events(Gdk::KEY_PRESS_MASK |
 
300
    sdl_widget->add_events(Gdk::KEY_PRESS_MASK | 
288
301
                  Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK |
289
302
                  Gdk::POINTER_MOTION_MASK);
290
303
 
 
304
    sdl_widget->signal_key_press_event().connect(
 
305
        sigc::mem_fun(*this, &GameWindow::on_sdl_key_event));
 
306
    sdl_widget->signal_key_release_event().connect(
 
307
        sigc::mem_fun(*this, &GameWindow::on_sdl_key_event));
291
308
    sdl_widget->signal_button_press_event().connect(
292
309
        sigc::mem_fun(*this, &GameWindow::on_sdl_mouse_button_event));
293
310
    sdl_widget->signal_button_release_event().connect(
294
311
        sigc::mem_fun(*this, &GameWindow::on_sdl_mouse_button_event));
295
312
    sdl_widget->signal_motion_notify_event().connect(
296
313
        sigc::mem_fun(*this, &GameWindow::on_sdl_mouse_motion_event));
297
 
    sdl_widget->signal_key_press_event().connect(
298
 
        sigc::mem_fun(*this, &GameWindow::on_sdl_key_event));
299
314
    
300
315
    // connect to the special signal that signifies that a new surface has been
301
316
    // generated and attached to the widget
312
327
 
313
328
    // then fill the other players
314
329
    int c = 0;
315
 
    int army_id = Armysetlist::getInstance()->file_names[g.army_theme];
 
330
    int army_id = Armysetlist::getInstance()->getArmysetId(g.army_theme);
316
331
    for (std::vector<GameParameters::Player>::const_iterator
317
332
             i = g.players.begin(), end = g.players.end();
318
333
         i != end; ++i, ++c) {
334
349
        creator.addPlayer(i->name, army_id, Player::get_color_for_no(c), type);
335
350
    }
336
351
 
337
 
    // first insert the neutral player
 
352
    // the neutral player must come last so it has the highest id among players
338
353
    creator.addNeutral(_("Neutral"), army_id, Player::get_color_for_neutral(),
339
354
                       Player::AI_DUMMY);
340
355
 
351
366
 
352
367
    int area = g.map.width * g.map.height;
353
368
    creator.setNoSignposts(int(area * (g.map.grass / 100.0) * 0.0030));
354
 
    creator.setNoStones(int(area * (g.map.grass / 100.0) * 0.0022));
355
369
 
356
370
    // tell it the dimensions
357
371
    creator.setWidth(g.map.width);
392
406
    setup_game(file_path);
393
407
    setup_signals();
394
408
    game->loadGame();
 
409
    game->redraw();
395
410
}
396
411
 
397
412
void GameWindow::setup_button(Gtk::Button *button,
432
447
  setup_button(park_button,
433
448
               sigc::mem_fun(game.get(), &Game::park_selected_stack),
434
449
               game->can_park_selected_stack);
 
450
  setup_button(deselect_button,
 
451
               sigc::mem_fun(game.get(), &Game::deselect_selected_stack),
 
452
               game->can_deselect_selected_stack);
435
453
  setup_button(search_button,
436
454
               sigc::mem_fun(game.get(), &Game::search_selected_stack),
437
455
               game->can_search_selected_stack);
496
514
    (game->smallmap_changed.connect
497
515
     (sigc::mem_fun(*this, &GameWindow::on_smallmap_changed)));
498
516
  connections.push_back
 
517
    (game->get_smallmap().view_slid.connect
 
518
     (sigc::mem_fun(*this, &GameWindow::on_smallmap_slid)));
 
519
  connections.push_back
499
520
    (game->stack_info_changed.connect
500
521
     (sigc::mem_fun(*this, &GameWindow::on_stack_info_changed)));
501
522
  connections.push_back
508
529
    (game->ruin_searched.connect
509
530
     (sigc::mem_fun(*this, &GameWindow::on_ruin_searched)));
510
531
  connections.push_back
 
532
    (game->sage_visited.connect
 
533
     (sigc::mem_fun(*this, &GameWindow::on_sage_visited)));
 
534
  connections.push_back
511
535
    (game->fight_started.connect
512
536
     (sigc::mem_fun(*this, &GameWindow::on_fight_started)));
513
537
  connections.push_back
567
591
  connections.push_back
568
592
    (game->player_died.connect
569
593
     (sigc::mem_fun(*this, &GameWindow::on_player_died)));
 
594
  connections.push_back
 
595
    (game->advice_asked.connect
 
596
     (sigc::mem_fun(*this, &GameWindow::on_advice_asked)));
570
597
 
571
598
  // misc callbacks
572
599
  QuestsManager *q = QuestsManager::getInstance();
582
609
        (game->get_bigmap().cursor_changed.connect
583
610
         (sigc::mem_fun(*this, &GameWindow::on_bigmap_cursor_changed)));
584
611
    }
585
 
  else
586
 
    printf("couldn't setup cursor changed event\n");
587
612
 
588
613
}
589
614
 
591
616
{
592
617
  stop_game();
593
618
 
594
 
  bool broken;
 
619
  bool broken = false;
595
620
  GameScenario* game_scenario = new GameScenario(file_path, broken);
596
621
 
597
622
  if (broken)
627
652
bool GameWindow::on_sdl_mouse_motion_event(GdkEventMotion *e)
628
653
{
629
654
  if (game.get())
630
 
    game->get_bigmap().mouse_motion_event(to_input_event(e));
 
655
    {
 
656
      game->get_bigmap().mouse_motion_event(to_input_event(e));
 
657
      sdl_widget->grab_focus();
 
658
    }
631
659
  return true;
632
660
}
633
661
 
641
669
 
642
670
bool GameWindow::on_sdl_key_event(GdkEventKey *e)
643
671
{
644
 
#if 0
645
 
  // keypresses are not implemented in the bigmap at this point,
646
 
  // to_input_event must also be defined to something sensible
647
 
  if (game.get())
648
 
    game->get_bigmap().key_press_event(to_input_event(e));
649
 
#endif
 
672
  static int left_shift_down = 0;
 
673
  static int right_shift_down = 0;
 
674
  if (e->keyval == GDK_Shift_L) 
 
675
    left_shift_down = !left_shift_down;
 
676
  else if (e->keyval == GDK_Shift_R)
 
677
    right_shift_down = !right_shift_down;
 
678
 
 
679
  if (e->keyval == GDK_Shift_L || e->keyval == GDK_Shift_R)
 
680
    game->get_bigmap().set_shift_key_down (right_shift_down || left_shift_down);
650
681
 
651
682
  return true;
652
683
}
692
723
 
693
724
void GameWindow::on_load_game_activated()
694
725
{
 
726
  return;
695
727
  Gtk::FileChooserDialog chooser(*window.get(), _("Choose Game to Load"));
696
728
  Gtk::FileFilter sav_filter;
697
729
  sav_filter.add_pattern("*.sav");
767
799
 
768
800
  if (end) {
769
801
    stop_game();
770
 
    quit_requested.emit();
 
802
    game_ended.emit();
771
803
  }
772
804
}
773
805
 
891
923
{
892
924
  PreferencesDialog d;
893
925
  d.set_parent_window(*window.get());
894
 
  d.run();
 
926
  d.run(game.get());
895
927
}
896
928
 
897
929
void GameWindow::on_group_ungroup_activated()
1006
1038
  d.run();
1007
1039
}
1008
1040
 
 
1041
void GameWindow::on_triumphs_activated()
 
1042
{
 
1043
  TriumphsDialog d(Playerlist::getActiveplayer());
 
1044
  d.set_parent_window(*window.get());
 
1045
  d.run();
 
1046
}
 
1047
 
1009
1048
void GameWindow::stop_game()
1010
1049
{
1011
1050
  Sound::getInstance()->disableBackground();
1019
1058
 
1020
1059
void GameWindow::on_game_over(Player *winner)
1021
1060
{
 
1061
 
1022
1062
  std::auto_ptr<Gtk::Dialog> dialog;
1023
1063
 
1024
1064
  Glib::RefPtr<Gnome::Glade::Xml> xml
1053
1093
  Gtk::Label *label;
1054
1094
  xml->get_widget("label", label);
1055
1095
  Glib::ustring s;
1056
 
  s += String::ucompose(_("%1 has taken over the world!"), winner->getName());
1057
 
  if (winner->getType() == Player::HUMAN)
1058
 
    {
1059
 
      s += " ";
1060
 
      s += _("Congratulations!");
1061
 
    }
 
1096
  s += String::ucompose(_("Congratulations to %1 for conquering the world!"), 
 
1097
        winner->getName());
1062
1098
  label->set_text(s);
1063
1099
 
1064
1100
  dialog->show_all();
1087
1123
  Glib::ustring s;
1088
1124
  s += String::ucompose(_("The rule of %1 has permanently ended!"),
1089
1125
                        player->getName());
 
1126
  if (Playerlist::getInstance()->countHumanPlayersAlive() == 0 &&
 
1127
      player->getType() == Player::HUMAN)
 
1128
    {
 
1129
      s += "\n";
 
1130
      s += _("No further human resistance is possible");
 
1131
      s += "\n";
 
1132
      s += _("but the battle will continue!");
 
1133
      s += "\n";
 
1134
      s += _("Press `CTRL-P' to stop the war");
 
1135
      s += "\n";
 
1136
      s += _("and visit the sites of thy old battles.");
 
1137
    }
1090
1138
  label->set_text(s);
1091
1139
 
1092
1140
  dialog->show_all();
1145
1193
  return false;
1146
1194
}
1147
1195
 
1148
 
void GameWindow::on_army_button_has_size()
1149
 
{
1150
 
  // fix height to prevent flickering
1151
 
  int height = stack_info_box->get_height();
1152
 
  stack_info_box->property_height_request() = height;
1153
 
  stats_box->property_height_request() = height;
1154
 
}
1155
 
 
1156
1196
void GameWindow::clear_army_buttons()
1157
1197
{
1158
1198
  for (army_buttons_type::iterator i = army_buttons.begin(),
1195
1235
 
1196
1236
void GameWindow::on_sidebar_stats_changed(SidebarStats s)
1197
1237
{
1198
 
  Glib::ustring n = String::ucompose(
1199
 
                                     stats_text, s.name, s.gold, s.income, s.cities, s.units);
1200
 
 
1201
 
  stats_label->set_text(n);
1202
 
 
1203
1238
  cities_stats_label->set_text(String::ucompose("%1", s.cities));
1204
1239
  gold_stats_label->set_text(String::ucompose("%1", s.gold));
1205
1240
  income_stats_label->set_text(String::ucompose("%1", s.income));
 
1241
  upkeep_stats_label->set_text(String::ucompose("%1", s.upkeep));
1206
1242
  turn_label->set_text(String::ucompose("Turn %1", s.turns + 1));
1207
1243
}
1208
1244
 
1209
1245
void GameWindow::on_smallmap_changed(SDL_Surface *map)
1210
1246
{
1211
 
  //while (g_main_context_iteration(NULL, FALSE)); //doEvents
1212
1247
  map_image->property_pixbuf() = to_pixbuf(map);
1213
1248
}
1214
1249
 
 
1250
void GameWindow::on_smallmap_slid(Rectangle view)
 
1251
{
 
1252
  on_smallmap_changed(game->get_smallmap().get_surface());
 
1253
  while (g_main_context_iteration(NULL, FALSE)); //doEvents
 
1254
}
 
1255
 
1215
1256
void GameWindow::on_stack_info_changed(Stack *s)
1216
1257
{
1217
1258
  clear_army_buttons();
1231
1272
 
1232
1273
void GameWindow::show_stats()
1233
1274
{
 
1275
  Armysetlist *al = Armysetlist::getInstance();
 
1276
  int height = al->getTileSize(Playerlist::getActiveplayer()->getArmyset());
 
1277
  height += turn_label->get_height();
 
1278
  height += 20;
 
1279
  stack_info_box->get_parent()->property_height_request() = height;
 
1280
  stats_box->get_parent()->property_height_request() = height;
1234
1281
  stack_info_container->hide();
1235
1282
  stats_box->show();
1236
1283
}
1241
1288
  GraphicsCache *gc = GraphicsCache::getInstance();
1242
1289
  SDL_Surface *terrain = gc->getMoveBonusPic(bonus, s->hasShip());
1243
1290
  terrain_image->property_pixbuf() = to_pixbuf(terrain);
1244
 
  group_moves_label->set_text(String::ucompose(_("Group\nMoves\n%1"),
 
1291
  group_moves_label->set_text(String::ucompose("%1",
1245
1292
                                               s->getGroupMoves()));
1246
1293
  group_ungroup_toggle->set_active(s->isGrouped());
1247
1294
}
1279
1326
      toggle->signal_button_release_event().connect(
1280
1327
                                                    sigc::bind(sigc::mem_fun(*this, &GameWindow::on_army_button_event),
1281
1328
                                                               toggle, army), false);
1282
 
      toggle->signal_size_allocate().connect_notify(
1283
 
                                                    sigc::hide(sigc::mem_fun(*this, &GameWindow::on_army_button_has_size)));
1284
 
 
1285
1329
      // add it
1286
1330
      stack_info_box->pack_start(*toggle, Gtk::PACK_SHRINK);
1287
1331
      army_buttons.push_back(toggle);
1368
1412
  SageDialog d(stack->getFirstHero()->getPlayer(), 
1369
1413
               static_cast<Hero*>(stack->getFirstHero()), ruin);
1370
1414
  d.set_parent_window(*window.get());
 
1415
  Reward *reward = d.run();
 
1416
  ruin->setReward(reward);
 
1417
}
 
1418
 
 
1419
void GameWindow::on_ruin_rewarded (Reward_Ruin *reward)
 
1420
{
 
1421
  RuinRewardedDialog d(reward);
 
1422
  d.set_parent_window(*window.get());
1371
1423
  d.run();
1372
1424
}
1373
1425
 
1375
1427
{
1376
1428
  std::auto_ptr<Gtk::Dialog> dialog;
1377
1429
  if (ruin->hasSage())
1378
 
    return on_sage_visited (ruin, stack);
 
1430
    {
 
1431
      if (reward->getType() == Reward::RUIN)
 
1432
        return on_ruin_rewarded(static_cast<Reward_Ruin*>(reward));
 
1433
    }
1379
1434
 
1380
1435
  Glib::RefPtr<Gnome::Glade::Xml> xml
1381
1436
    = Gnome::Glade::Xml::create(get_glade_path() + "/ruin-searched-dialog.glade");
1397
1452
 
1398
1453
  Glib::ustring s = label->get_text();
1399
1454
  s += "\n\n";
 
1455
  s += String::ucompose("%1 finds ", stack->getFirstHero()->getName());
1400
1456
  if (reward->getType() == Reward::GOLD)
1401
 
    s += String::ucompose("%1 finds %2 gp.", stack->getFirstHero()->getName(), 
1402
 
                          dynamic_cast<Reward_Gold*>(reward)->getGold());
 
1457
    {
 
1458
      Reward_Gold *gold = dynamic_cast<Reward_Gold*>(reward);
 
1459
      s += String::ucompose("%1 gold pieces.", gold->getGold());
 
1460
    }
1403
1461
  else if (reward->getType() == Reward::ALLIES)
1404
 
    s += String::ucompose("%1 gets %2 allies.", stack->getFirstHero()->getName(), 
1405
 
                          dynamic_cast<Reward_Allies*>(reward)->getNoOfAllies());
 
1462
    {
 
1463
      Reward_Allies *allies = dynamic_cast<Reward_Allies*>(reward);
 
1464
      s += String::ucompose("%1 allies.", allies->getNoOfAllies());
 
1465
    }
1406
1466
  else if (reward->getType() == Reward::ITEM)
1407
 
    s += String::ucompose("%1 gets the %2.", stack->getFirstHero()->getName(), 
1408
 
                          dynamic_cast<Reward_Item*>(reward)->getItem()->getName());
 
1467
    {
 
1468
      Reward_Item *item = dynamic_cast<Reward_Item*>(reward);
 
1469
      s += String::ucompose("the %1.", item->getItem()->getName());
 
1470
    }
 
1471
  else if (reward->getType() == Reward::MAP)
 
1472
    {
 
1473
      Reward_Map *map = dynamic_cast<Reward_Map*>(reward);
 
1474
      s += String::ucompose("the %2.", map->getLocation()->getName());
 
1475
    }
1409
1476
 
1410
1477
  label->set_text(s);
1411
1478
 
1804
1871
  if (gold == 0)
1805
1872
    {
1806
1873
      SDL_Surface *s
1807
 
        = GraphicsCache::getInstance()->getArmyPic(as, 0, player, 1, NULL);
 
1874
        = GraphicsCache::getInstance()->getArmyPic(as, 0, player, NULL);
1808
1875
      Glib::RefPtr<Gdk::Pixbuf> empty_pic
1809
1876
        = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, s->w, s->h);
1810
1877
      empty_pic->fill(0x00000000);
1814
1881
  else
1815
1882
    {
1816
1883
      Glib::RefPtr<Gdk::Pixbuf> pic;
1817
 
      pic = to_pixbuf(gc->getArmyPic(as, pillaged_army_type, player, 1, NULL));
 
1884
      pic = to_pixbuf(gc->getArmyPic(as, pillaged_army_type, player, NULL));
1818
1885
      pillaged_army_type_image->set(pic);
1819
1886
      pillaged_army_type_cost_label->set_text(String::ucompose("%1 gp", gold));
1820
1887
    }
1876
1943
 
1877
1944
  Glib::RefPtr<Gdk::Pixbuf> pic;
1878
1945
  SDL_Surface *surf
1879
 
    = GraphicsCache::getInstance()->getArmyPic(as, 0, player, 1, NULL);
 
1946
    = GraphicsCache::getInstance()->getArmyPic(as, 0, player, NULL);
1880
1947
  Glib::RefPtr<Gdk::Pixbuf> empty_pic
1881
1948
    = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, surf->w, surf->h);
1882
1949
  empty_pic->fill(0x00000000);
1900
1967
          sack_image = sacked_army_3_image;
1901
1968
          break;
1902
1969
        }
1903
 
      pic = to_pixbuf(gc->getArmyPic(as, *it, player, 1, NULL));
 
1970
      pic = to_pixbuf(gc->getArmyPic(as, *it, player, NULL));
1904
1971
      sack_image->set(pic);
1905
1972
      const Army *a = 
1906
1973
        Armysetlist::getInstance()->getArmy (player->getArmyset(), *it);
2117
2184
  xml->get_widget("label", label);
2118
2185
  Glib::ustring s;
2119
2186
  s += String::ucompose(_("%1 did not complete the quest."),
2120
 
                        quest->getHero()->getName());
 
2187
                        quest->getHeroName());
2121
2188
  s += "\n\n";
2122
2189
 
2123
2190
  // add messages from the quest
2148
2215
{
2149
2216
  Playerlist::getActiveplayer()->heroPlantStandard(NULL);
2150
2217
}
 
2218
    
 
2219
void GameWindow::on_advice_asked(float percent)
 
2220
{
 
2221
  //we asked for advice on a fight, and we're being told that we 
 
2222
  //have a PERCENT chance of winning the fight
 
2223
  std::auto_ptr<Gtk::Dialog> dialog;
 
2224
 
 
2225
  Glib::RefPtr<Gnome::Glade::Xml> xml
 
2226
    = Gnome::Glade::Xml::create(get_glade_path() + "/military-advisor-dialog.glade");
 
2227
 
 
2228
  Gtk::Dialog *d;
 
2229
  xml->get_widget("dialog", d);
 
2230
  dialog.reset(d);
 
2231
  dialog->set_transient_for(*window.get());
 
2232
 
 
2233
  dialog->set_title(_("Advisor!"));
 
2234
 
 
2235
  Gtk::Label *label;
 
2236
  xml->get_widget("label", label);
 
2237
  Glib::ustring s;
 
2238
 
 
2239
  int num = rand() % 5;
 
2240
  if (num == 0)
 
2241
    s += _("My Good Lord!");
 
2242
  else if (num == 1)
 
2243
    s += _("Great and Worthy Lord!");
 
2244
  else if (num == 2)
 
2245
    s += _("O Champion of Justice!");
 
2246
  else if (num == 3)
 
2247
    s += _("O Mighty Leader!");
 
2248
  else if (num == 4)
 
2249
    s += _("O Great Warlord!");
 
2250
  s += "\n";
 
2251
 
 
2252
  num = rand() % 7;
 
2253
  if (num == 0)
 
2254
    s += _("This battle will surely be");
 
2255
  else if (num == 1)
 
2256
    s += _("A battle here would be");
 
2257
  else if (num == 2)
 
2258
    s += _("I believe this battle will surely be");
 
2259
  else if (num == 3)
 
2260
    s += _("This battle would be");
 
2261
  else if (num == 4)
 
2262
    s += _("A battle here would be");
 
2263
  else if (num == 5)
 
2264
    s += _("I believe this battle will be");
 
2265
  else if (num == 6)
 
2266
    s += _("This battle shall be");
 
2267
  s += "\n";
 
2268
 
 
2269
 
 
2270
  if (percent >= 90.0)
 
2271
    s += _("as simple as butchering sleeping cattle!");
 
2272
  else if (percent >= 80.0)
 
2273
    s += _("an easy victory!  We cannot lose!");
 
2274
  else if (percent >= 70.0)
 
2275
    s += _("a comfortable victory");
 
2276
  else if (percent >= 60.0)
 
2277
    s += _("a hard fought victory! But we shall win!");
 
2278
  else if (percent >= 50.0)
 
2279
    s += _("very evenly matched!");
 
2280
  else if (percent >= 40.0)
 
2281
    s += _("difficult but not impossible to win!");
 
2282
  else if (percent >= 30.0)
 
2283
    s += _("a brave choice! I leave it to thee!");
 
2284
  else if (percent >= 20.0)
 
2285
    s += _("a foolish decision!");
 
2286
  else if (percent >= 10.0)
 
2287
    s += _("sheerest folly!  Thou shouldst not attack!");
 
2288
  else
 
2289
    s += _("complete and utter suicide!");
 
2290
  label->set_text(s);
 
2291
 
 
2292
  dialog->show_all();
 
2293
  dialog->run();
 
2294
  return;
 
2295
}