<URL: http://bugs.freeciv.org/Ticket/Display.html?id=37752 >

On 3/8/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
>  This allows editing player techs in science dialog.
>
>  - Global observer cannot edit techs.
>  - Wrong cursor. This is old bug, but it's more obvious with this patch

 - Update player research structure correctly. Especially handle
correctly cases where tech currently being researched is given or
becomes unreachable.


 I'll try to look in to that cursor problem in another ticket.


 - ML

diff -Nurd -X.diff_ignore freeciv/client/gui-gtk-2.0/repodlgs.c freeciv/client/gui-gtk-2.0/repodlgs.c
--- freeciv/client/gui-gtk-2.0/repodlgs.c	2007-03-05 21:11:59.000000000 +0200
+++ freeciv/client/gui-gtk-2.0/repodlgs.c	2007-03-09 01:04:15.000000000 +0200
@@ -184,22 +184,32 @@
   if (tech == A_NONE) {
     return;
   }
-  if (event->button == 1 && can_client_issue_orders()) {
-    /* LMB: set research or research goal */
-    switch (get_invention(game.player_ptr, tech)) {
-    case TECH_REACHABLE:
-      dsend_packet_player_research(&aconnection, tech);
-      break;
-    case TECH_UNKNOWN:
-      dsend_packet_player_tech_goal(&aconnection, tech);
-      break;
-    case TECH_KNOWN:
-      break;
-    }
-  } else if (event->button == 3) {
+
+  if (event->button == 3) {
     /* RMB: get help */
     /* FIXME: this should work for ctrl+LMB or shift+LMB (?) too */
     popup_help_dialog_typed(get_tech_name(game.player_ptr, tech), HELP_TECH);
+  } else if (!can_conn_edit(&aconnection)) {
+    if (event->button == 1 && can_client_issue_orders()) {
+      /* LMB: set research or research goal */
+      switch (get_invention(game.player_ptr, tech)) {
+       case TECH_REACHABLE:
+         dsend_packet_player_research(&aconnection, tech);
+         break;
+       case TECH_UNKNOWN:
+         dsend_packet_player_tech_goal(&aconnection, tech);
+         break;
+       case TECH_KNOWN:
+         break;
+      }
+    }
+  } else {
+    /* Editor mode */
+    if (game.player_ptr) {
+      /* Not a global observer */
+      dsend_packet_edit_player_tech(&aconnection, game.player_ptr->player_no,
+                                    tech, ETECH_TOGGLE);
+    }
   }
 }
 
diff -Nurd -X.diff_ignore freeciv/common/fc_types.h freeciv/common/fc_types.h
--- freeciv/common/fc_types.h	2007-03-08 18:42:39.000000000 +0200
+++ freeciv/common/fc_types.h	2007-03-09 01:04:15.000000000 +0200
@@ -181,4 +181,11 @@
   EVISION_LAST
 };
 
+enum editor_tech_mode {
+  ETECH_ADD,
+  ETECH_REMOVE,
+  ETECH_TOGGLE,
+  ETECH_LAST
+};
+
 #endif /* FC__FC_TYPES_H */
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def	2007-03-08 20:59:09.000000000 +0200
+++ freeciv/common/packets.def	2007-03-09 01:05:07.000000000 +0200
@@ -219,6 +219,7 @@
 type TEAM		= UINT8
 type CONTINENT          = sint16(Continent_id)
 type IMPROVEMENT	= uint8(Impr_type_id)
+type EDIT_TECH_MODE     = uint8(enum editor_tech_mode)
 
 # other typedefs
 type COORD  		= UINT8
@@ -1469,3 +1470,9 @@
   COORD x, y;
   UINT8 mode;
 end
+
+PACKET_EDIT_PLAYER_TECH=133;cs,handle-per-conn,dsend
+  PLAYER          playerno;
+  TECH            tech;
+  EDIT_TECH_MODE  mode;
+end
diff -Nurd -X.diff_ignore freeciv/server/edithand.c freeciv/server/edithand.c
--- freeciv/server/edithand.c	2007-03-08 18:42:39.000000000 +0200
+++ freeciv/server/edithand.c	2007-03-09 01:33:15.000000000 +0200
@@ -455,6 +455,62 @@
 }
 
 /****************************************************************************
+  Edit techs known by player
+****************************************************************************/
+void handle_edit_player_tech(struct connection *pc,
+                             int playerno, Tech_type_id tech,
+                             enum editor_tech_mode mode)
+{
+  struct player *pplayer = get_player(playerno);
+  struct player_research *research;
+
+  if (!can_conn_edit(pc) || !pplayer || !tech_exists(tech)) {
+    return;
+  }
+
+  research = get_player_research(pplayer);
+
+  switch(mode) {
+   case ETECH_ADD:
+     set_invention(pplayer, tech, TECH_KNOWN);
+     research->techs_researched++;
+     break;
+   case ETECH_REMOVE:
+     set_invention(pplayer, tech, TECH_UNKNOWN);
+     research->techs_researched--;
+     break;
+   case ETECH_TOGGLE:
+     if (get_invention(pplayer, tech) == TECH_KNOWN) {
+       set_invention(pplayer, tech, TECH_UNKNOWN);
+       research->techs_researched--;
+     } else {
+       set_invention(pplayer, tech, TECH_KNOWN);
+       research->techs_researched++;
+     }
+     break;
+   default:
+     break;
+  }
+
+  update_research(pplayer);
+
+  if (research->researching != A_UNSET
+      && get_invention(pplayer, research->researching) != TECH_REACHABLE) {
+    research->researching = A_UNSET;
+  }
+  if (research->tech_goal != A_UNSET
+      && get_invention(pplayer, research->tech_goal) == TECH_KNOWN) {
+    research->tech_goal = A_UNSET;
+  }
+
+  /* send update back to client */
+  send_player_info(NULL, pplayer);
+
+  /* Inform everybody about global advances */
+  send_game_info(NULL);
+}
+
+/****************************************************************************
   Client editor requests us to recalculate borders. Note that this does
   not necessarily extend borders to their maximum due to the way the
   borders code is written. This may be considered a feature or limitation.
diff -Nurd -X.diff_ignore freeciv/version.in freeciv/version.in
--- freeciv/version.in	2007-03-08 20:59:09.000000000 +0200
+++ freeciv/version.in	2007-03-09 01:04:33.000000000 +0200
@@ -24,4 +24,4 @@
 #   - Avoid adding a new manditory capbility to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-FREECIV_NETWORK_CAPSTRING("+Freeciv.Devel.2007.Mar.08-3")
+FREECIV_NETWORK_CAPSTRING("+Freeciv.Devel.2007.Mar.09")
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to