Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2003:
[Freeciv-Dev] (PR#7040) Small cleanup packhand.c
Home

[Freeciv-Dev] (PR#7040) Small cleanup packhand.c

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#7040) Small cleanup packhand.c
From: "Arnstein Lindgard" <a-l@xxxxxxx>
Date: Thu, 4 Dec 2003 03:20:32 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=7040 >

Small cleanup of client/packhand.c: handle_unit_packet_common().

1. Remove spurious call to update_unit_foocus().

Christian: Are there any remaining focus jumping issues?

2. Add navigation comments, style brackets.
3. Remove 2 unused variables.
4. Add assert(punit), remove if (punit).


Arnstein



--- freeciv/client/packhand.c   Fri Nov 28 21:36:56 2003
+++ 1/client/packhand.c Thu Dec  4 12:10:53 2003
@@ -902,7 +902,6 @@
                                 packet_unit->id);
 
   if (punit) {
-    int dest_x, dest_y;
     ret = TRUE;
     punit->activity_count = packet_unit->activity_count;
     punit->transported_by = packet_unit->transported_by;
@@ -916,10 +915,10 @@
         check_focus = TRUE;
       }
     }
+
+    /*** Change in activity or activity's target. ***/
     if (punit->activity != packet_unit->activity
         || punit->activity_target != packet_unit->activity_target) {
-      /* change activity or act's target */
-
       /* May change focus if focus unit gets a new activity.
        * But if new activity is Idle, it means user specifically selected
        * the unit */
@@ -963,7 +962,7 @@
       if (punit == get_unit_in_focus()) {
          update_menus();
       }
-    }
+    } /*** End of Change in activity or activity's target. ***/
     
     if (punit->homecity != packet_unit->homecity) {
       /* change homecity */
@@ -1008,8 +1007,8 @@
       check_focus = TRUE;
     }
 
+    /*** Change position ***/
     if (!same_pos(punit->x, punit->y, packet_unit->x, packet_unit->y)) { 
-      /* change position */
       struct city *pcity = map_get_city(punit->x, punit->y);
 
       old_x = punit->x;
@@ -1019,8 +1018,6 @@
       /* Show where the unit is going. */
       do_move_unit(punit, packet_unit, carried);
 
-      update_unit_focus();
-
       if(pcity)  {
        /* Unit moved out of a city - update the occupied status.  The
         * logic is a little shaky since it's not clear whether we can
@@ -1057,7 +1054,8 @@
       }
       
       repaint_unit = FALSE;
-    }
+    }  /*** End of Change position. ***/
+
     if (punit->unhappiness != packet_unit->unhappiness) {
       punit->unhappiness = packet_unit->unhappiness;
       repaint_city = TRUE;
@@ -1096,12 +1094,12 @@
       punit->done_moving = packet_unit->done_moving;
       check_focus = TRUE;
     }
-  
-    dest_x = packet_unit->x;
-    dest_y = packet_unit->y;
+
     agents_unit_changed(punit);
-  } else {
-    /* create new unit */ 
+  }
+
+  /*** Create new unit ***/
+  else {
     punit = packet_unit;
     idex_register_unit(punit);
 
@@ -1124,9 +1122,12 @@
       /* The unit is in a city - obviously it's occupied. */
       pcity->client.occupied = TRUE;
     }
-  }
+  } /*** End of Create new unit ***/
+
+  /* Will agents_unit_changed() above be allowed to destroy the unit? */
+  assert(punit);
 
-  if (punit && punit == get_unit_in_focus()) {
+  if (punit == get_unit_in_focus()) {
     update_unit_info_label(punit);
   } else if (get_unit_in_focus()
             && (same_pos(get_unit_in_focus()->x, get_unit_in_focus()->y,
@@ -1137,13 +1138,15 @@
     update_unit_info_label(get_unit_in_focus());
   }
 
-  if(repaint_unit)
+  if(repaint_unit) {
     refresh_tile_mapcanvas(punit->x, punit->y, FALSE);
+  }
 
   if ((check_focus || get_unit_in_focus() == NULL) &&
-      !game.player_ptr->ai.control)
+      !game.player_ptr->ai.control) {
     update_unit_focus();
-  
+  }
+
   return ret;
 }
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#7040) Small cleanup packhand.c, Arnstein Lindgard <=