Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] (PR#11172) output_type_iterate
Home

[Freeciv-Dev] (PR#11172) output_type_iterate

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11172) output_type_iterate
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 23 Nov 2004 20:21:24 -0800
Reply-to: rt@xxxxxxxxxxx

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

Here's a new iterator: output_type_iterate.

Rather simple.

jason

Index: client/options.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.c,v
retrieving revision 1.107
diff -u -r1.107 options.c
--- client/options.c    24 Nov 2004 03:34:56 -0000      1.107
+++ client/options.c    24 Nov 2004 04:16:01 -0000
@@ -638,16 +638,15 @@
 {
   struct cm_parameter parameter;
   const char *name;
-  int i;
 
   name = secfile_lookup_str_default(file, "preset", 
                                    "cma.preset%d.name", inx);
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     parameter.minimal_surplus[i] =
        secfile_lookup_int_default(file, 0, "cma.preset%d.minsurp%d", inx, i);
     parameter.factor[i] =
        secfile_lookup_int_default(file, 0, "cma.preset%d.factor%d", inx, i);
-  }
+  } output_type_iterate_end;
   parameter.require_happy =
       secfile_lookup_bool_default(file, FALSE, "cma.preset%d.reqhappy", inx);
   parameter.happy_factor =
@@ -665,15 +664,13 @@
                            const struct cm_parameter *const pparam,
                            int inx)
 {
-  int i;
-
   secfile_insert_str(file, name, "cma.preset%d.name", inx);
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     secfile_insert_int(file, pparam->minimal_surplus[i],
                       "cma.preset%d.minsurp%d", inx, i);
     secfile_insert_int(file, pparam->factor[i],
                       "cma.preset%d.factor%d", inx, i);
-  }
+  } output_type_iterate_end;
   secfile_insert_bool(file, pparam->require_happy,
                      "cma.preset%d.reqhappy", inx);
   secfile_insert_int(file, pparam->happy_factor,
Index: client/agents/cma_core.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_core.c,v
retrieving revision 1.66
diff -u -r1.66 cma_core.c
--- client/agents/cma_core.c    24 Nov 2004 03:34:56 -0000      1.66
+++ client/agents/cma_core.c    24 Nov 2004 04:16:01 -0000
@@ -100,8 +100,6 @@
                             const struct cm_result *const result1,
                             const struct cm_result *const result2)
 {
-  Output_type_id stat;
-
   T(disorder);
   T(happy);
 
@@ -109,9 +107,9 @@
     T(specialists[sp]);
   } specialist_type_iterate_end;
 
-  for (stat = 0; stat < O_COUNT; stat++) {
+  output_type_iterate(stat) {
     T(surplus[stat]);
-  }
+  } output_type_iterate_end;
 
   my_city_map_iterate(pcity, x, y) {
     if (result1->worker_positions_used[x][y] !=
@@ -571,7 +569,7 @@
   size_t len;
   char buffer[SAVED_PARAMETER_SIZE];
   struct data_in din;
-  int i, version, dummy;
+  int version, dummy;
 
   /* Changing this function is likely to break compatability with old
    * savegames that store these values. */
@@ -587,10 +585,10 @@
   dio_get_uint8(&din, &version);
   assert(version == 2);
 
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     dio_get_sint16(&din, &parameter->minimal_surplus[i]);
     dio_get_sint16(&din, &parameter->factor[i]);
-  }
+  } output_type_iterate_end;
 
   dio_get_sint16(&din, &parameter->happy_factor);
   dio_get_uint8(&din, &dummy); /* Dummy value; used to be factor_target. */
@@ -610,7 +608,6 @@
 {
   char buffer[SAVED_PARAMETER_SIZE];
   struct data_out dout;
-  int i;
 
   /* Changing this function is likely to break compatability with old
    * savegames that store these values. */
@@ -619,10 +616,10 @@
 
   dio_put_uint8(&dout, 2);
 
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     dio_put_sint16(&dout, parameter->minimal_surplus[i]);
     dio_put_sint16(&dout, parameter->factor[i]);
-  }
+  } output_type_iterate_end;
 
   dio_put_sint16(&dout, parameter->happy_factor);
   dio_put_uint8(&dout, 0); /* Dummy value; used to be factor_target. */
Index: client/agents/cma_fec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_fec.c,v
retrieving revision 1.27
diff -u -r1.27 cma_fec.c
--- client/agents/cma_fec.c     24 Nov 2004 03:34:56 -0000      1.27
+++ client/agents/cma_fec.c     24 Nov 2004 04:16:01 -0000
@@ -333,9 +333,9 @@
     for (j = 0; j < RESULT_COLUMNS; j++)
       my_snprintf(buf[j], BUFFER_SIZE, "---");
   } else {
-    for (j = 0; j < O_COUNT; j++) {
+    output_type_iterate(j) {
       my_snprintf(buf[j], BUFFER_SIZE, "%+3d", result->surplus[j]);
-    }
+    } output_type_iterate_end;
 
     my_snprintf(buf[6], BUFFER_SIZE, "%d/%s%s",
                pcity->size - cm_count_specialist(pcity, result),
Index: client/gui-gtk/cma_fe.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/cma_fe.c,v
retrieving revision 1.23
diff -u -r1.23 cma_fe.c
--- client/gui-gtk/cma_fe.c     24 Nov 2004 03:34:56 -0000      1.23
+++ client/gui-gtk/cma_fe.c     24 Nov 2004 04:16:01 -0000
@@ -223,7 +223,7 @@
   gtk_misc_set_alignment(GTK_MISC(label), 0.1, 0.5);
   gtk_table_attach_defaults(GTK_TABLE(table), label, 2, 3, 0, 1);
 
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     label = gtk_label_new(cm_get_stat_name(i));
     gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, i + 1, i + 2);
     gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
@@ -250,7 +250,7 @@
 
     gtk_signal_connect(GTK_OBJECT(pdialog->factor[i]), "value_changed",
                       GTK_SIGNAL_FUNC(hscale_changed), pdialog);
-  }
+  } iterate_type_iterate_end;
 
   /* Happy Surplus and Factor */
 
@@ -640,14 +640,12 @@
 static void set_hscales(const struct cm_parameter *const parameter,
                        struct cma_dialog *pdialog)
 {
-  int i;
-
   allow_refreshes = 0;
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     gtk_adjustment_set_value(pdialog->minimal_surplus[i],
                             parameter->minimal_surplus[i]);
     gtk_adjustment_set_value(pdialog->factor[i], parameter->factor[i]);
-  }
+  } output_type_iterate_end;
   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pdialog->happy_button),
                               parameter->require_happy);
   gtk_adjustment_set_value(pdialog->factor[O_COUNT],
@@ -662,17 +660,16 @@
 {
   struct cma_dialog *pdialog = (struct cma_dialog *) data;
   struct cm_parameter param;
-  int i;
 
   if (!allow_refreshes) {
     return;
   }
 
   cmafec_get_fe_parameter(pdialog->pcity, &param);
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     param.minimal_surplus[i] = (int) (pdialog->minimal_surplus[i]->value);
     param.factor[i] = (int) (pdialog->factor[i]->value);
-  }
+  } output_type_iterate_end;
   param.require_happy =
       (GTK_TOGGLE_BUTTON(pdialog->happy_button)->active ? 1 : 0);
   param.happy_factor = (int) (pdialog->factor[O_COUNT]->value);
Index: client/gui-gtk-2.0/cma_fe.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/cma_fe.c,v
retrieving revision 1.22
diff -u -r1.22 cma_fe.c
--- client/gui-gtk-2.0/cma_fe.c 24 Nov 2004 03:34:56 -0000      1.22
+++ client/gui-gtk-2.0/cma_fe.c 24 Nov 2004 04:16:02 -0000
@@ -138,7 +138,6 @@
   struct cm_parameter param;
   GtkWidget *frame, *page, *hbox, *label, *table;
   GtkWidget *vbox, *sw, *hscale;
-  int i;
   GtkListStore *store;
   GtkCellRenderer *rend;
   GtkWidget *view;
@@ -244,7 +243,7 @@
   gtk_misc_set_alignment(GTK_MISC(label), 0.1, 0.5);
   gtk_table_attach_defaults(GTK_TABLE(table), label, 2, 3, 0, 1);
 
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     label = gtk_label_new(cm_get_stat_name(i));
     gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, i + 1, i + 2);
     gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
@@ -271,7 +270,7 @@
 
     g_signal_connect(pdialog->factor[i], "value_changed",
                     G_CALLBACK(hscale_changed), pdialog);
-  }
+  } output_type_iterate_end;
 
   /* Happy Surplus and Factor */
 
@@ -656,14 +655,12 @@
 static void set_hscales(const struct cm_parameter *const parameter,
                        struct cma_dialog *pdialog)
 {
-  int i;
-
   allow_refreshes = 0;
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     gtk_adjustment_set_value(pdialog->minimal_surplus[i],
                             parameter->minimal_surplus[i]);
     gtk_adjustment_set_value(pdialog->factor[i], parameter->factor[i]);
-  }
+  } output_type_iterate_end;
   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pdialog->happy_button),
                               parameter->require_happy);
   gtk_adjustment_set_value(pdialog->factor[O_COUNT],
@@ -678,17 +675,16 @@
 {
   struct cma_dialog *pdialog = (struct cma_dialog *) data;
   struct cm_parameter param;
-  int i;
 
   if (!allow_refreshes) {
     return;
   }
 
   cmafec_get_fe_parameter(pdialog->pcity, &param);
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     param.minimal_surplus[i] = (int) (pdialog->minimal_surplus[i]->value);
     param.factor[i] = (int) (pdialog->factor[i]->value);
-  }
+  } output_type_iterate_end;
   param.require_happy =
       (GTK_TOGGLE_BUTTON(pdialog->happy_button)->active ? 1 : 0);
   param.happy_factor = (int) (pdialog->factor[O_COUNT]->value);
Index: client/gui-mui/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/citydlg.c,v
retrieving revision 1.84
diff -u -r1.84 citydlg.c
--- client/gui-mui/citydlg.c    24 Nov 2004 03:34:56 -0000      1.84
+++ client/gui-mui/citydlg.c    24 Nov 2004 04:16:02 -0000
@@ -1147,13 +1147,12 @@
 {
   struct city_dialog *pdialog = *ppdialog; 
   struct cm_parameter param;
-  int i;
 
   cmafec_get_fe_parameter(pdialog->pcity, &param);
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     param.minimal_surplus[i] = 
(int)xget(pdialog->minimal_surplus_slider[i],MUIA_Numeric_Value);
     param.factor[i] = (int)xget(pdialog->factor_slider[i],MUIA_Numeric_Value);
-  }
+  } output_type_iterate_end;
   param.require_happy = xget(pdialog->celebrate_check, MUIA_Selected);
   param.happy_factor = xget(pdialog->factor_slider[6],MUIA_Numeric_Value);
 
@@ -2154,11 +2153,10 @@
 
   
   /* if called from a hscale, we _don't_ want to do this */
-  for (i = 0; i < O_COUNT; i++)
-  {
+  output_type_iterate(i) {
     
nnset(pdialog->minimal_surplus_slider[i],MUIA_Numeric_Value,param.minimal_surplus[i]);
     nnset(pdialog->factor_slider[i],MUIA_Numeric_Value,param.factor[i]);
-  }
+  } output_type_iterate_end;
   nnset(pdialog->celebrate_check, MUIA_Selected,param.require_happy);
   nnset(pdialog->factor_slider[6], MUIA_Numeric_Value, param.happy_factor);
 
Index: client/gui-sdl/cma_fe.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/cma_fe.c,v
retrieving revision 1.14
diff -u -r1.14 cma_fe.c
--- client/gui-sdl/cma_fe.c     24 Nov 2004 03:34:56 -0000      1.14
+++ client/gui-sdl/cma_fe.c     24 Nov 2004 04:16:02 -0000
@@ -599,8 +599,7 @@
   
   /* exit button */
   pBuf = pCma->pDlg->pEndWidgetList->prev;
-  for (i = 0; i < O_COUNT; i++) {
-    
+  output_type_iterate(i) {
     /* min label */
     pBuf = pBuf->prev;
     my_snprintf(cBuf, sizeof(cBuf), "%d", *(int *)pBuf->prev->data.ptr);
@@ -621,7 +620,7 @@
     pBuf->size.x = pBuf->next->size.x 
                + pBuf->next->size.w + 5 + *(int *)pBuf->data.ptr - 1;
     
-  }
+  } output_type_iterate_end;
   
   /* happy factor label */
   pBuf = pBuf->prev;
@@ -857,8 +856,7 @@
   pFactor = create_text_surf_from_str16(pStr);
     
   /* ---------- */
-  for (i = 0; i < O_COUNT; i++) {
-    
+  output_type_iterate(i) {
     copy_chars_to_string16(pStr, cm_get_stat_name(i));
     pText[i] = create_text_surf_from_str16(pStr);
     text_w = MAX(text_w, pText[i]->w);
@@ -899,7 +897,7 @@
     set_wstate(pBuf, FC_WS_NORMAL);
 
     add_to_gui_list(ID_SCROLLBAR, pBuf);
-  }
+  } output_type_iterate_end;
   
   copy_chars_to_string16(pStr, _("Celebrate"));
   pText[O_COUNT] = create_text_surf_from_str16(pStr);
@@ -1039,9 +1037,7 @@
   SDL_BlitSurface(pCity_Map, NULL, pWindow->theme, &area);
   FREESURFACE(pCity_Map);
   
-  
-  for (i = 0; i < O_COUNT; i++) {
-            
+  output_type_iterate(i) {
     /* min label */
     pBuf = pBuf->prev;
     pBuf->size.x = pWindow->size.x + dst.x + text_w + 10;
@@ -1082,7 +1078,7 @@
     dst.y += pText[i]->h + 6;
     FREESURFACE(pText[i]);
     
-  }
+  } output_type_iterate_end;
   
   /* happy factor label */
   pBuf = pBuf->prev;
Index: client/gui-win32/cma_fe.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/cma_fe.c,v
retrieving revision 1.3
diff -u -r1.3 cma_fe.c
--- client/gui-win32/cma_fe.c   24 Nov 2004 03:34:56 -0000      1.3
+++ client/gui-win32/cma_fe.c   24 Nov 2004 04:16:02 -0000
@@ -203,8 +203,8 @@
                               HWND win, struct fcwin_box *box)
 {
   struct fcwin_box *hbox = fcwin_hbox_new(win, FALSE);
-  int i;
   struct fcwin_box *vbox[3];
+
   fcwin_box_add_box(box, hbox, FALSE,FALSE, 0);
   for (i = 0; i < 3; i++) {
     vbox[i] = fcwin_vbox_new(win, TRUE);
@@ -213,9 +213,9 @@
   fcwin_box_add_static(vbox[0], " ",0, SS_LEFT,TRUE, TRUE, 0);
   fcwin_box_add_static(vbox[1], _("Minimal Surplus"), 0, SS_LEFT, TRUE, TRUE, 
0);
   fcwin_box_add_static(vbox[2], _("Factor"), 0, SS_LEFT, TRUE, TRUE, 0);
-  for (i = 0; i< O_COUNT; i++) {
+  output_type_iterate(i) {
     cmagui_add_slider(pdialog, win, vbox, FALSE, cm_get_stat_name(i), i);
-  } 
+  } output_type_iterate_end;
   cmagui_add_slider(pdialog, win, vbox, TRUE, _("Celebrate"), i);
 }
 
@@ -226,14 +226,13 @@
 static void set_hscales(const struct cm_parameter *const parameter,
                         struct cma_dialog *pdialog)
 {
-  int i;
   allow_refreshes = 0;
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     handle_hscroll(pdialog->mainwin, pdialog->minimal_surplus[i],
                   SB_THUMBTRACK, parameter->minimal_surplus[i]);
     handle_hscroll(pdialog->mainwin, pdialog->factor[i],
                   SB_THUMBTRACK, parameter->factor[i]);
-  }
+  } output_type_iterate_end;
   Button_SetCheck(pdialog->happy,
                  parameter->require_happy ? BST_CHECKED : BST_UNCHECKED);
   handle_hscroll(pdialog->mainwin, pdialog->factor[i],
@@ -508,17 +507,16 @@
 static void hscale_changed(struct cma_dialog *pdialog)
 {
   struct cm_parameter param;
-  int i;
 
   if (!allow_refreshes) {
     return;
   }
   
   cmafec_get_fe_parameter(pdialog->pcity, &param);
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     param.minimal_surplus[i] = ScrollBar_GetPos(pdialog->minimal_surplus[i]);
     param.factor[i] = ScrollBar_GetPos(pdialog->factor[i]);
-  }
+  } output_type_iterate_end;
   
   param.require_happy = (Button_GetCheck(pdialog->happy) == BST_CHECKED) ? 1 : 
0;
   param.happy_factor = ScrollBar_GetPos(pdialog->factor[O_COUNT]);
Index: client/gui-xaw/cma_fe.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/cma_fe.c,v
retrieving revision 1.3
diff -u -r1.3 cma_fe.c
--- client/gui-xaw/cma_fe.c     24 Nov 2004 03:34:56 -0000      1.3
+++ client/gui-xaw/cma_fe.c     24 Nov 2004 04:16:02 -0000
@@ -187,7 +187,7 @@
 
   /* Create scrollbars in the minimal surplus column. */
   prev = surplus_header;
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     surplus_slider[i] = 
       XtVaCreateManagedWidget("cmapresetscroll",
                                   scrollbarWidgetClass, form,
@@ -195,7 +195,7 @@
                                   XtNfromVert, prev,
                                   NULL);
     prev = stat_surplus_label[i];
-  }
+  } output_type_iterate_end;
 
   celebrate_toggle = 
     I_L(XtVaCreateManagedWidget("cmapresettoggle",
@@ -306,12 +306,12 @@
   XtAddCallback(close_button, XtNcallback,
                 close_callback, NULL);
 
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     XtAddCallback(surplus_slider[i], XtNscrollProc,
                   sliders_scroll_callback, NULL);
     XtAddCallback(surplus_slider[i], XtNjumpProc,
                   sliders_jump_callback, NULL);
-  }
+  } output_type_iterate_end;
 
   for (i = 0; i < (O_COUNT + 1); i++) {
     XtAddCallback(factor_slider[i], XtNscrollProc,
@@ -323,9 +323,9 @@
   /* Update dialog with CMA parameters from city.  */
   cmafec_get_fe_parameter(current_city, &parameter);
 
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     minimal_surplus[i] = parameter.minimal_surplus[i];
-  }
+  } output_type_iterate_end;
 
   XtVaSetValues(celebrate_toggle, 
          XtNlabel, parameter.require_happy ? _("Yes") : _("No"),
@@ -337,9 +337,9 @@
     factors[O_COUNT] = 1;
   }
 
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     factors[i] = parameter.factor[i];
-  }
+  } output_type_iterate_end;
 
   set_slider_values();
   update_cma_preset_list();
@@ -350,10 +350,10 @@
   XtVaSetValues(result_label, XtNwidth, 360, NULL);
   XtVaSetValues(result_label, XtNheight, 110, NULL);
 
-  for(i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     XtVaSetValues(stat_surplus_label[i], XtNwidth, 90, NULL);
     XtVaSetValues(stat_factor_label[i], XtNwidth, 90, NULL);
-  }
+  } output_type_iterate_end;
   XtVaSetValues(stat_factor_label[i], XtNwidth, 90, NULL);
 
   XtRealizeWidget(cma_dialog);
@@ -507,9 +507,9 @@
     xaw_set_label(result_label,
         (char *) cmafec_get_result_descr(current_city, &result, &parameter));
 
-    for (i = 0; i < O_COUNT; i++) {
+    output_type_iterate(i) {
       minimal_surplus[i] = param->minimal_surplus[i];
-    }
+    } output_type_iterate_end;
 
     XtVaSetValues(celebrate_toggle, XtNlabel,
             param->require_happy ? _("Yes") : _("No"),
@@ -517,9 +517,9 @@
 
     factors[O_COUNT] = param->happy_factor;
 
-    for (i = 0; i < O_COUNT; i++) {
+    output_type_iterate(i) {
       factors[i] = param->factor[i];
-    }
+    } output_type_iterate_end;
   }
 
   update_stat_labels(result.found_a_valid);
@@ -541,10 +541,10 @@
 {
   int i;
   
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     XawScrollbarSetThumb(surplus_slider[i],
                      (((20 + minimal_surplus[i])))*1/41.0f, 1/41.0f);
-  }
+  } output_type_iterate_end;
 
   for (i = 0; i < (O_COUNT + 1); i++) { 
     XawScrollbarSetThumb(factor_slider[i],
@@ -563,7 +563,7 @@
   struct cm_result result;
   int i, preset_index;
 
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     if (w == surplus_slider[i]) {
       if (pos > 0 ) {
         minimal_surplus[i]++;
@@ -577,7 +577,7 @@
         }
       }
     }
-  }
+  } output_type_iterate_end;
 
   for (i = 0; i < (O_COUNT + 1); i++) {
     if (w == factor_slider[i]) {
@@ -597,10 +597,10 @@
 
   cmafec_get_fe_parameter(current_city, &parameter);
 
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     parameter.minimal_surplus[i] = minimal_surplus[i];
     parameter.factor[i] = factors[i];
-  }
+  } output_type_iterate_end;
 
   XtVaGetValues(celebrate_toggle, XtNstate, &parameter.require_happy, NULL);
   parameter.happy_factor = factors[O_COUNT];
@@ -638,13 +638,12 @@
   struct cm_result result;
   int i, preset_index;
 
-
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     if (w == surplus_slider[i]) {
       /* convert from percent to [-20..20] */
       minimal_surplus[i] = (int)(percent * 41) - 20;
     }
-  }
+  } output_type_iterate_end;
 
   for (i = 0; i < (O_COUNT + 1); i++) {
     if (w == factor_slider[i]) {
@@ -655,10 +654,10 @@
 
   cmafec_get_fe_parameter(current_city, &parameter);
 
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     parameter.minimal_surplus[i] = minimal_surplus[i];
     parameter.factor[i] = factors[i];
-  }
+  } output_type_iterate_end;
 
   XtVaGetValues(celebrate_toggle, XtNstate, &parameter.require_happy, NULL);
   parameter.happy_factor = factors[O_COUNT];
@@ -693,19 +692,19 @@
   char buf[256]; 
   int i;
 
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     my_snprintf(buf, sizeof(buf), "%-9s%3d",
                 cm_get_stat_name(i),
                 minimal_surplus[i]);
     xaw_set_label(stat_surplus_label[i], buf);
-  }
+  } output_type_iterate_end;
 
-  for (i = 0; i < O_COUNT; i++) { 
+  output_type_iterate(i) {
     my_snprintf(buf, sizeof(buf), "%-9s%3d",
                 cm_get_stat_name(i),
                 factors[i]);
     xaw_set_label(stat_factor_label[i], buf);
-  }
+  } output_type_iterate_end;
   my_snprintf(buf, sizeof(buf), "%-9s%3d",
               "Celebrate",
               factors[O_COUNT]);
@@ -743,12 +742,10 @@
     XtVaGetValues(celebrate_toggle, XtNstate, &celebrate_setting, NULL);
     cmafec_get_fe_parameter(current_city, &parameter);
 
-    for (i = 0; i < O_COUNT; i++) {
+    output_type_iterate(i) {
       parameter.minimal_surplus[i] = minimal_surplus[i];
-    }
-    for (i = 0; i < O_COUNT; i++) {
       parameter.factor[i] = factors[i];
-    }
+    } output_type_iterate_end;
 
     parameter.happy_factor = factors[O_COUNT];
     parameter.require_happy = celebrate_setting;
@@ -776,10 +773,10 @@
 
   /* Update parameters with new celebrate setting. */
   cmafec_get_fe_parameter(current_city, &parameter);
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     parameter.minimal_surplus[i] = minimal_surplus[i];
     parameter.factor[i] = factors[i];
-  }
+  } output_type_iterate_end;
 
   XtVaGetValues(celebrate_toggle, XtNstate, &parameter.require_happy, NULL);
   parameter.happy_factor = factors[O_COUNT];
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.167
diff -u -r1.167 city.h
--- common/city.h       24 Nov 2004 03:34:57 -0000      1.167
+++ common/city.h       24 Nov 2004 04:16:02 -0000
@@ -543,6 +543,18 @@
 #define built_impr_iterate_end                                                \
   } impr_type_iterate_end;
 
+
+/* Iterates over all output types in the game. */
+#define output_type_iterate(output)                                        \
+{                                                                          \
+  Output_type_id output;                                                   \
+                                                                           \
+  for (output = 0; output < O_COUNT; output++) {
+
+#define output_type_iterate_end                                                
    \
+  }                                                                        \
+}
+
 /**************************************************************************
   Return TRUE iff the given city coordinate pair is the center tile of
   the citymap.
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.45
diff -u -r1.45 cm.c
--- common/aicore/cm.c  24 Nov 2004 03:34:57 -0000      1.45
+++ common/aicore/cm.c  24 Nov 2004 04:16:03 -0000
@@ -383,13 +383,11 @@
 static bool tile_type_equal(const struct cm_tile_type *a,
                            const struct cm_tile_type *b)
 {
-  Output_type_id stat;
-
-  for (stat = 0; stat < O_COUNT; stat++) {
+  output_type_iterate(stat) {
     if (a->production[stat] != b->production[stat])  {
       return FALSE;
     }
-  }
+  } output_type_iterate_end;
 
   if (a->is_specialist != b->is_specialist) {
     return FALSE;
@@ -407,13 +405,11 @@
 static bool tile_type_better(const struct cm_tile_type *a,
                             const struct cm_tile_type *b)
 {
-  Output_type_id stat;
-
-  for (stat = 0; stat < O_COUNT; stat++) {
+  output_type_iterate(stat) {
     if (a->production[stat] < b->production[stat])  {
       return FALSE;
     }
-  }
+  } output_type_iterate_end;
 
   if (a->is_specialist && !b->is_specialist) {
     /* If A is a specialist and B isn't, and all of A's production is at
@@ -538,18 +534,17 @@
                                         bool disorder, bool happy,
                                        const struct cm_parameter *parameter)
 {
-  Output_type_id stat;
   struct cm_fitness fitness;
 
   fitness.sufficient = TRUE;
   fitness.weighted = 0;
 
-  for (stat = 0; stat < O_COUNT; stat++) {
+  output_type_iterate(stat) {
     fitness.weighted += surplus[stat] * parameter->factor[stat];
     if (surplus[stat] < parameter->minimal_surplus[stat]) {
       fitness.sufficient = FALSE;
     }
-  }
+  } output_type_iterate_end;
 
   if (happy) {
     fitness.weighted += parameter->happy_factor;
@@ -766,8 +761,6 @@
 static int compare_tile_type_by_lattice_order(const struct cm_tile_type *a,
                                              const struct cm_tile_type *b)
 {
-  Output_type_id stat;
-
   if (a == b) {
     return 0;
   }
@@ -778,11 +771,11 @@
   }
 
   /* With equal depth, break ties arbitrarily, more production first. */
-  for (stat = 0; stat < O_COUNT; stat++) {
+  output_type_iterate(stat) {
     if (a->production[stat] != b->production[stat]) {
       return b->production[stat] - a->production[stat];
     }
-  }
+  } output_type_iterate_end;
 
   /* If we get here, then we have two copies of identical types, an error */
   assert(0);
@@ -1202,7 +1195,6 @@
                        int itype, int number,
                        const struct cm_state *state)
 {
-  Output_type_id stat;
   const struct cm_tile_type *ptype = tile_type_get(state, itype);
   int newcount;
   int old_worker_count = soln->worker_counts[itype];
@@ -1241,11 +1233,11 @@
   }
 
   /* update production */
-  for (stat = 0 ; stat < O_COUNT; stat++) {
+  output_type_iterate(stat) {
     newcount = soln->production[stat] + number * ptype->production[stat];
     assert(newcount >= 0);
     soln->production[stat] = newcount;
-  }
+  } output_type_iterate_end;
 }
 
 /****************************************************************************
@@ -1464,7 +1456,6 @@
                                        int production[],
                                        int check_choice)
 {
-  Output_type_id stat;
   struct partial_solution solnplus; /* will be soln, plus some tiles */
 
   /* Production is whatever the solution produces, plus the
@@ -1474,20 +1465,19 @@
   if (soln->idle == 1) {
     /* Then the total solution is soln + this new worker.  So we know the
        production exactly, and can shortcut the later code. */
-    Output_type_id stat;
     const struct cm_tile_type *ptype = tile_type_get(state, check_choice);
 
     memcpy(production, soln->production, sizeof(soln->production));
-    for (stat = 0; stat < O_COUNT; stat++) {
+    output_type_iterate(stat) {
       production[stat] += ptype->production[stat];
-    }
+    } output_type_iterate_end;
     return;
   }
 
   /* initialize solnplus here, after the shortcut check */
   init_partial_solution(&solnplus, num_types(state), state->pcity->size);
 
-  for (stat = 0; stat < O_COUNT; stat++) {
+  output_type_iterate(stat) {
     /* compute the solution that has soln, then the check_choice,
        then complete it with the best available tiles for the stat. */
     copy_partial_solution(&solnplus, soln, state);
@@ -1495,7 +1485,7 @@
     complete_solution(&solnplus, state, &state->lattice_by_prod[stat]);
 
     production[stat] = solnplus.production[stat];
-  }
+  } output_type_iterate_end;
 
   destroy_partial_solution(&solnplus);
 }
@@ -1509,12 +1499,11 @@
 static bool choice_is_promising(struct cm_state *state, int newchoice)
 {
   int production[O_COUNT];
-  Output_type_id stat;
   bool beats_best = FALSE;
 
   compute_max_stats_heuristic(state, &state->current, production, newchoice);
 
-  for (stat = 0; stat < O_COUNT; stat++) {
+  output_type_iterate(stat) {
     if (production[stat] < state->min_production[stat]) {
       freelog(LOG_PRUNE_BRANCH, "--- pruning: insufficient %s (%d < %d)",
              cm_get_stat_name(stat), production[stat],
@@ -1526,7 +1515,7 @@
       /* may still fail to meet min at another production type, so
        * don't short-circuit */
     }
-  }
+  } output_type_iterate_end;
   if (!beats_best) {
     freelog(LOG_PRUNE_BRANCH, "--- pruning: best is better in all ways");
   }
@@ -1615,13 +1604,12 @@
                               const int production[]) {
   const struct city *pcity = state->pcity;
   const struct player *pplayer = get_player(pcity->owner);
-  Output_type_id stat;
   double estimates[O_COUNT];
   double sum = 0;
 
-  for (stat = 0; stat < O_COUNT; stat++) {
+  output_type_iterate(stat) {
     estimates[stat] = production[stat];
-  }
+  } output_type_iterate_end;
 
   /* sci/lux/gold get benefit from the tax rates (in percentage) */
   estimates[O_SCIENCE]
@@ -1639,9 +1627,9 @@
 
   /* finally, sum it all up, weighted by the parameter, but give additional
    * weight to luxuries to take account of disorder/happy constraints */
-  for (stat = 0; stat < O_COUNT; stat++) {
+  output_type_iterate(stat) {
     sum += estimates[stat] * state->parameter.factor[stat];
-  }
+  } output_type_iterate_end;
   sum += estimates[O_LUXURY];
   return sum;
 }
@@ -1699,7 +1687,6 @@
 struct cm_state *cm_init_state(struct city *pcity)
 {
   int numtypes;
-  Output_type_id stat;
   struct cm_state *state = fc_malloc(sizeof(*state));
 
   freelog(LOG_CM_STATE, "creating cm_state for %s (size %d)",
@@ -1714,14 +1701,14 @@
   numtypes = tile_type_vector_size(&state->lattice);
 
   /* For the heuristic, make sorted copies of the lattice */
-  for (stat = 0; stat < O_COUNT; stat++) {
+  output_type_iterate(stat) {
     tile_type_vector_init(&state->lattice_by_prod[stat]);
     tile_type_vector_copy(&state->lattice_by_prod[stat], &state->lattice);
     compare_key = stat;
     qsort(state->lattice_by_prod[stat].p, state->lattice_by_prod[stat].size,
          sizeof(*state->lattice_by_prod[stat].p),
          compare_tile_type_by_stat);
-  }
+  } output_type_iterate_end;
 
   /* We have no best solution yet, so its value is the worst possible. */
   init_partial_solution(&state->best, numtypes, pcity->size);
@@ -1784,12 +1771,10 @@
 ****************************************************************************/
 void cm_free_state(struct cm_state *state)
 {
-  Output_type_id stat;
-
   tile_type_vector_free_all(&state->lattice);
-  for (stat = 0; stat < O_COUNT; stat++) {
+  output_type_iterate(stat) {
     tile_type_vector_free(&state->lattice_by_prod[stat]);
-  }
+  } output_type_iterate_end;
   destroy_partial_solution(&state->best);
   destroy_partial_solution(&state->current);
   free(state->choice.stack);
@@ -1865,16 +1850,14 @@
 bool cm_are_parameter_equal(const struct cm_parameter *const p1,
                            const struct cm_parameter *const p2)
 {
-  int i;
-
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     if (p1->minimal_surplus[i] != p2->minimal_surplus[i]) {
       return FALSE;
     }
     if (p1->factor[i] != p2->factor[i]) {
       return FALSE;
     }
-  }
+  } output_type_iterate_end;
   if (p1->require_happy != p2->require_happy) {
     return FALSE;
   }
@@ -1905,12 +1888,10 @@
 **************************************************************************/
 void cm_init_parameter(struct cm_parameter *dest)
 {
-  Output_type_id stat;
-
-  for (stat = 0; stat < O_COUNT; stat++) {
+  output_type_iterate(stat) {
     dest->minimal_surplus[stat] = 0;
     dest->factor[stat] = 1;
-  }
+  } output_type_iterate_end;
 
   dest->happy_factor = 1;
   dest->require_happy = FALSE;
@@ -1924,12 +1905,10 @@
 ***************************************************************************/
 void cm_init_emergency_parameter(struct cm_parameter *dest)
 {
-  Output_type_id stat;
-
-  for (stat = 0; stat < O_COUNT; stat++) {
+  output_type_iterate(stat) {
     dest->minimal_surplus[stat] = -FC_INFINITY;
     dest->factor[stat] = 1;
-  }
+  } output_type_iterate_end;
 
   dest->happy_factor = 1;
   dest->require_happy = FALSE;
@@ -2146,7 +2125,8 @@
 void cm_print_result(const struct city *pcity,
                     const struct cm_result *result)
 {
-  int y, i, worker = cm_count_worker(pcity, result);
+  int y, worker = cm_count_worker(pcity, result);
+
   freelog(LOG_NORMAL, "print_result(result=%p)", result);
   freelog(LOG_NORMAL,
       "print_result:  found_a_valid=%d disorder=%d happy=%d",
@@ -2182,8 +2162,8 @@
       "print_result:  people: (workers/specialists) %d/%s",
       worker, specialists_string(result->specialists));
 
-  for (i = 0; i < O_COUNT; i++) {
+  output_type_iterate(i) {
     freelog(LOG_NORMAL, "print_result:  %10s surplus=%d",
         cm_get_stat_name(i), result->surplus[i]);
-  }
+  } output_type_iterate_end;
 }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11172) output_type_iterate, Jason Short <=