Author: mir3x
Date: Fri Jul 15 08:22:01 2016
New Revision: 33245

URL: http://svn.gna.org/viewcvs/freeciv?rev=33245&view=rev
Log:
Qt client - Added rally points for cities.

See patch #7465


Modified:
    trunk/client/gui-qt/fc_client.h
    trunk/client/gui-qt/mapctrl.cpp
    trunk/client/gui-qt/mapview.cpp
    trunk/client/gui-qt/menu.cpp
    trunk/client/gui-qt/menu.h

Modified: trunk/client/gui-qt/fc_client.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/fc_client.h?rev=33245&r1=33244&r2=33245&view=diff
==============================================================================
--- trunk/client/gui-qt/fc_client.h     (original)
+++ trunk/client/gui-qt/fc_client.h     Fri Jul 15 08:22:01 2016
@@ -248,6 +248,7 @@
   pregame_options *pr_options;
   fc_settings qt_settings;
   trade_generator trade_gen;
+  qfc_rally_list rallies;
   void gimme_place(QWidget* widget, QString str);
   int gimme_index_of(QString str);
   void remove_repo_dlg(QString str);

Modified: trunk/client/gui-qt/mapctrl.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/mapctrl.cpp?rev=33245&r1=33244&r2=33245&view=diff
==============================================================================
--- trunk/client/gui-qt/mapctrl.cpp     (original)
+++ trunk/client/gui-qt/mapctrl.cpp     Fri Jul 15 08:22:01 2016
@@ -242,6 +242,48 @@
     gui()->trade_gen.hover_city = false;
     gui()->trade_gen.add_tile(ptile);
     gui()->mapview_wdg->repaint();
+    return;
+  }
+  /* Rally point - select city */
+  if (event->button() == Qt::LeftButton
+      && gui()->rallies.hover_city == true) {
+    char text[1024];
+    ptile = canvas_pos_to_tile(event->pos().x(), event->pos().y());
+    if (tile_city(ptile)) {
+      gui()->rallies.hover_city = false;
+      gui()->rallies.hover_tile = true;
+      gui()->rallies.rally_city = tile_city(ptile);
+
+      if (gui()->rallies.clear(tile_city(ptile))) {
+        fc_snprintf(text, sizeof(text),
+                  _("Rally point cleared for city %s"),
+                  city_link(tile_city(ptile)));
+        output_window_append(ftc_client, text);
+        gui()->rallies.hover_tile = false;
+        return;
+      }
+      fc_snprintf(text, sizeof(text),
+                  _("Selected city %s. Now choose rally point."),
+                  city_link(tile_city(ptile)));
+      output_window_append(ftc_client, text);
+    } else {
+      output_window_append(ftc_client, _("No city selected. Aborted"));
+    }
+    return;
+  }
+  /* Rally point - select tile */
+  if (event->button() == Qt::LeftButton
+      && gui()->rallies.hover_tile == true) {
+    char text[1024];
+    qfc_rally *rally = new qfc_rally;
+    rally->ptile = canvas_pos_to_tile(event->pos().x(), event->pos().y());
+    rally->pcity = gui()->rallies.rally_city;
+    fc_snprintf(text, sizeof(text),
+                _("Tile %s set as rally point from city %s."),
+                tile_link(ptile), city_link(rally->pcity));
+    gui()->rallies.hover_tile = false;
+    gui()->rallies.add(rally);
+    output_window_append(ftc_client, text);
     return;
   }
   if (event->button() == Qt::LeftButton

Modified: trunk/client/gui-qt/mapview.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/mapview.cpp?rev=33245&r1=33244&r2=33245&view=diff
==============================================================================
--- trunk/client/gui-qt/mapview.cpp     (original)
+++ trunk/client/gui-qt/mapview.cpp     Fri Jul 15 08:22:01 2016
@@ -55,6 +55,7 @@
 #define MAX_DIRTY_RECTS 20
 static int num_dirty_rects = 0;
 static QRect dirty_rects[MAX_DIRTY_RECTS];
+static int last_turn = 0;
 
 /**************************************************************************
   Check if point x, y is in area (px -> pxe, py - pye)
@@ -1502,6 +1503,10 @@
 {
   gui()->game_info_label->set_time_info(get_timeout_label_text());
   gui()->game_info_label->resize(gui()->game_info_label->sizeHint());
+  if (last_turn != game.info.turn) {
+    qt_start_turn();
+  }
+  last_turn = game.info.turn;
 }
 
 /****************************************************************************

Modified: trunk/client/gui-qt/menu.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/menu.cpp?rev=33245&r1=33244&r2=33245&view=diff
==============================================================================
--- trunk/client/gui-qt/menu.cpp        (original)
+++ trunk/client/gui-qt/menu.cpp        Fri Jul 15 08:22:01 2016
@@ -57,6 +57,75 @@
 #include "menu.h"
 
 extern QApplication *qapp;
+
+/**************************************************************************
+  New turn callback
+**************************************************************************/
+void qt_start_turn()
+{
+  gui()->rallies.run();
+}
+
+/**************************************************************************
+  Sends new built units to target tile
+**************************************************************************/
+void qfc_rally_list::run()
+{
+  qfc_rally *rally;
+  struct unit_list *units;
+  struct unit *last_unit;;
+  int max;
+
+  if (rally_list.isEmpty()) {
+    return;
+  }
+
+  foreach (rally, rally_list) {
+    max = 0;
+    last_unit = nullptr;
+
+    if (rally->pcity->turn_last_built == game.info.turn - 1) {
+      units = rally->pcity->units_supported;
+
+      unit_list_iterate(units, punit) {
+        if (punit->id > max) {
+          last_unit = punit;
+          max = punit->id;
+        }
+      } unit_list_iterate_end;
+
+      if (last_unit && rally->pcity->production.kind == VUT_UTYPE) {
+        send_attack_tile(last_unit, rally->ptile);
+      }
+    }
+  }
+}
+
+/**************************************************************************
+  Adds rally point
+**************************************************************************/
+void qfc_rally_list::add(qfc_rally* rally)
+{
+  rally_list.append(rally);
+}
+
+/**************************************************************************
+  Clears rally point. Returns false if rally was not set for that city.
+**************************************************************************/
+bool qfc_rally_list::clear(city* rcity)
+{
+  qfc_rally *rally;
+
+  foreach (rally, rally_list) {
+    if (rally->pcity == rcity) {
+      rally_list.removeAll(rally);
+      return true;
+    }
+  }
+
+  return false;
+}
+
 
 /**************************************************************************
   Constructor for trade city used to trade calculation
@@ -1418,6 +1487,9 @@
   connect(act, SIGNAL(triggered()), this, SLOT(slot_trade_city()));
   act = menu->addAction(_("Clear Trade Planning"));
   connect(act, SIGNAL(triggered()), this, SLOT(slot_clear_trade()));
+  act = menu->addAction(_("Set/Unset rally point"));
+  act->setShortcut(QKeySequence(tr("shift+s")));
+  connect(act, SIGNAL(triggered()), this, SLOT(slot_rally()));
 
   /* Civilization menu */
   menu = this->addMenu(_("Civilization"));
@@ -2327,6 +2399,15 @@
 }
 
 /***************************************************************************
+  Sets/unset rally point
+***************************************************************************/
+void mr_menu::slot_rally()
+{
+  gui()->rallies.hover_tile = false;
+  gui()->rallies.hover_city = true;
+}
+
+/***************************************************************************
   Adds one city to trade planning
 ***************************************************************************/
 void mr_menu::slot_trade_city()

Modified: trunk/client/gui-qt/menu.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/menu.h?rev=33245&r1=33244&r2=33245&view=diff
==============================================================================
--- trunk/client/gui-qt/menu.h  (original)
+++ trunk/client/gui-qt/menu.h  Fri Jul 15 08:22:01 2016
@@ -33,6 +33,8 @@
 class QPushButton;
 class QSignalMapper;
 class QScrollArea;
+
+void qt_start_turn();
 
 /** used for indicating menu about current option - for renaming
  * and enabling, disabling */
@@ -83,6 +85,34 @@
 };
 
 /**************************************************************************
+  Struct holding rally point for city
+**************************************************************************/
+struct qfc_rally
+{
+  struct city *pcity;
+  struct tile *ptile;
+};
+
+/**************************************************************************
+  Class holding city list for rally points
+**************************************************************************/
+class qfc_rally_list
+{
+public:
+  qfc_rally_list() {
+    hover_tile = false;
+    hover_city = false;
+  };
+  void add(qfc_rally* rally);
+  bool clear(struct city *rcity);
+  QList<qfc_rally*> rally_list;
+  void run();
+  bool hover_tile;
+  bool hover_city;
+  struct city *rally_city;
+};
+
+/**************************************************************************
   Class representing one unit for delayed goto
 **************************************************************************/
 class qfc_delayed_unit_item
@@ -371,6 +401,7 @@
   void slot_trade_city();
   void slot_calculate();
   void slot_clear_trade();
+  void slot_rally();
 
   /*used by civilization menu */
   void slot_show_map();


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to