Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2003:
[Freeciv-Dev] (PR#6625) destroy_unit_goto_route
Home

[Freeciv-Dev] (PR#6625) destroy_unit_goto_route

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#6625) destroy_unit_goto_route
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 24 Oct 2003 09:15:50 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch (based on PR#4242) introduces a function 
destroy_unit_goto_route.  It frees and resets (to NULL) the punit->pgr 
struct.

jason

Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.186
diff -u -d -r1.186 unit.c
--- common/unit.c       2003/10/21 21:49:55     1.186
+++ common/unit.c       2003/10/24 16:14:07
@@ -1496,10 +1496,19 @@
 **************************************************************************/
 void destroy_unit_virtual(struct unit *punit)
 {
+  destroy_unit_goto_route(punit);
+  free(punit);
+}
+
+/**************************************************************************
+  Free and reset the unit's goto route (punit->pgr).  Only used by the
+  server.
+**************************************************************************/
+void destroy_unit_goto_route(struct unit *punit)
+{
   if (punit->pgr) {
     free(punit->pgr->pos);
     free(punit->pgr);
     punit->pgr = NULL;
   }
-  free(punit);
 }
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.102
diff -u -d -r1.102 unit.h
--- common/unit.h       2003/10/07 18:55:09     1.102
+++ common/unit.h       2003/10/24 16:14:07
@@ -295,5 +295,6 @@
 struct unit *create_unit_virtual(struct player *pplayer, struct city *pcity,
                                  Unit_Type_id type, bool make_veteran);
 void destroy_unit_virtual(struct unit *punit);
+void destroy_unit_goto_route(struct unit *punit);
 
 #endif  /* FC__UNIT_H */
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.275
diff -u -d -r1.275 unithand.c
--- server/unithand.c   2003/10/08 16:56:07     1.275
+++ server/unithand.c   2003/10/24 16:14:07
@@ -1425,12 +1425,9 @@
   if (can_unit_do_activity(punit, new_activity)) {
     enum unit_activity old_activity = punit->activity;
     enum tile_special_type old_target = punit->activity_target;
+
     set_unit_activity(punit, new_activity);
-    if (punit->pgr) {
-      free(punit->pgr->pos);
-      free(punit->pgr);
-      punit->pgr = NULL;
-    }
+    destroy_unit_goto_route(punit);
     send_unit_info(NULL, punit);
     handle_unit_activity_dependencies(punit, old_activity, old_target);
   }
@@ -1448,16 +1445,10 @@
   if (can_unit_do_activity_targeted(punit, new_activity, new_target)) {
     enum unit_activity old_activity = punit->activity;
     enum tile_special_type old_target = punit->activity_target;
-    set_unit_activity_targeted(punit, new_activity, new_target);
 
-    if (punit->pgr) {
-      free(punit->pgr->pos);
-      free(punit->pgr);
-      punit->pgr = NULL;
-    }
-    
-    send_unit_info(NULL, punit);
-    
+    set_unit_activity_targeted(punit, new_activity, new_target);
+    destroy_unit_goto_route(punit);
+    send_unit_info(NULL, punit);    
     handle_unit_activity_dependencies(punit, old_activity, old_target);
   }
 }
@@ -1565,10 +1556,7 @@
   struct goto_route *pgr = NULL;
   struct unit *punit = player_find_unit_by_id(pplayer, packet->unit_id);
 
-  if (punit->pgr) {
-    free(punit->pgr->pos);
-    free(punit->pgr);
-  }
+  destroy_unit_goto_route(punit);
 
   pgr = fc_malloc(sizeof(struct goto_route));
 
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.260
diff -u -d -r1.260 unittools.c
--- server/unittools.c  2003/10/13 21:33:59     1.260
+++ server/unittools.c  2003/10/24 16:14:07
@@ -3151,9 +3151,7 @@
 
     index = pgr->first_index;
     if (index == pgr->last_index) {
-      free(punit->pgr->pos);
-      free(punit->pgr);
-      punit->pgr = NULL;
+      destroy_unit_goto_route(punit);
       if (punit->activity == ACTIVITY_GOTO) 
        /* the activity could already be SENTRY (if boarded a ship) 
           -- leave it as it is then */

[Prev in Thread] Current Thread [Next in Thread]