Author: cazfi
Date: Wed Mar 18 21:53:14 2015
New Revision: 28577

URL: http://svn.gna.org/viewcvs/freeciv?rev=28577&view=rev
Log:
Added generic specialists support for sdl-client

See patch #5868

Modified:
    branches/S2_5/client/gui-sdl/citydlg.c
    branches/S2_5/client/gui-sdl/gui_tilespec.c
    branches/S2_5/client/gui-sdl/gui_tilespec.h
    branches/S2_5/client/tilespec.c

Modified: branches/S2_5/client/gui-sdl/citydlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-sdl/citydlg.c?rev=28577&r1=28576&r2=28577&view=diff
==============================================================================
--- branches/S2_5/client/gui-sdl/citydlg.c      (original)
+++ branches/S2_5/client/gui-sdl/citydlg.c      Wed Mar 18 21:53:14 2015
@@ -33,6 +33,7 @@
 /* common */
 #include "game.h"
 #include "movement.h"
+#include "specialist.h"
 #include "unitlist.h"
 
 /* client */
@@ -95,13 +96,10 @@
   struct widget *pResource_Map;
   struct widget *pCity_Name_Edit;
 
-  SDL_Rect specs_area[3];      /* active area of specialist
-                                  0 - elvis
-                                  1 - taxman
-                                  2 - scientists
-                                  change when pressed on this area */
-  bool specs[3];
-  
+  int citizen_step;
+
+  SDL_Rect spec_area;
+
   bool lock;
 } *pCityDlg = NULL;
 
@@ -193,39 +191,23 @@
 }
 
 /**************************************************************************
-  Main Citu Dlg. window callback.
-  Here was implemented change specialist ( Elvis, Taxman, Scientist ) code. 
+  Main City Dlg. window callback.
+  This implements specialist change ( Elvis, Taxman, Scientist )
 **************************************************************************/
 static int city_dlg_callback(struct widget *pWindow)
 {  
   if (Main.event.button.button == SDL_BUTTON_LEFT) {
     if (!cma_is_city_under_agent(pCityDlg->pCity, NULL)
        && city_owner(pCityDlg->pCity) == client.conn.playing) {
-         
-      /* check elvis area */
-      if (pCityDlg->specs[0]
-         && is_in_rect_area(Main.event.motion.x, Main.event.motion.y,
-                                          pCityDlg->specs_area[0])) {
-        city_change_specialist(pCityDlg->pCity, SP_ELVIS, SP_TAXMAN);
+
+      if (is_in_rect_area(Main.event.motion.x, Main.event.motion.y,
+                          pCityDlg->spec_area)) {
+        city_rotate_specialist(pCityDlg->pCity,
+                               (Main.event.motion.x - pCityDlg->spec_area.x)
+                               / pCityDlg->citizen_step);
+
         return -1;
       }
-  
-      /* check TAXMANs area */
-      if (pCityDlg->specs[1]
-         && is_in_rect_area(Main.event.motion.x, Main.event.motion.y,
-                                          pCityDlg->specs_area[1])) {
-        city_change_specialist(pCityDlg->pCity, SP_TAXMAN, SP_SCIENTIST);
-        return -1;
-      }
-  
-      /* check SCIENTISTs area */
-      if (pCityDlg->specs[2]
-         && is_in_rect_area(Main.event.motion.x, Main.event.motion.y,
-                                          pCityDlg->specs_area[2])) {
-        city_change_specialist(pCityDlg->pCity, SP_SCIENTIST, SP_ELVIS);
-        return -1;
-      }
-      
     }
     
     if (!pCityDlg->lock) {
@@ -2086,8 +2068,7 @@
 
   count = (pCity->feel[CITIZEN_HAPPY][FEELING_FINAL] + 
pCity->feel[CITIZEN_CONTENT][FEELING_FINAL]
           + pCity->feel[CITIZEN_UNHAPPY][FEELING_FINAL] + 
pCity->feel[CITIZEN_ANGRY][FEELING_FINAL]
-          + pCity->specialists[SP_ELVIS] + pCity->specialists[SP_SCIENTIST]
-          + pCity->specialists[SP_TAXMAN]);
+          + city_specialists(pCity));
 
   if (count * pIcons->pMale_Happy->w > adj_size(166)) {
     step = (adj_size(166) - pIcons->pMale_Happy->w) / (count - 1);
@@ -2100,6 +2081,7 @@
        || pCity->feel[CITIZEN_CONTENT][j - 1] != 
pCity->feel[CITIZEN_CONTENT][j]
        || pCity->feel[CITIZEN_UNHAPPY][j - 1] != 
pCity->feel[CITIZEN_UNHAPPY][j]
        || pCity->feel[CITIZEN_ANGRY][j - 1] != pCity->feel[CITIZEN_ANGRY][j]) {
+      int spe, spe_max;
 
       if (j != 0) {
        putline(pCityWindow->dst->surface,
@@ -2160,25 +2142,14 @@
        }
       }
 
-      if (pCity->specialists[SP_ELVIS]) {
-       for (i = 0; i < pCity->specialists[SP_ELVIS]; i++) {
-         alphablit(pIcons->pSpec_Lux, NULL, pCityWindow->dst->surface, &dest);
-         dest.x += step;
-       }
-      }
-
-      if (pCity->specialists[SP_TAXMAN]) {
-       for (i = 0; i < pCity->specialists[SP_TAXMAN]; i++) {
-         alphablit(pIcons->pSpec_Tax, NULL, pCityWindow->dst->surface, &dest);
-         dest.x += step;
-       }
-      }
-
-      if (pCity->specialists[SP_SCIENTIST]) {
-       for (i = 0; i < pCity->specialists[SP_SCIENTIST]; i++) {
-         alphablit(pIcons->pSpec_Sci, NULL, pCityWindow->dst->surface, &dest);
-         dest.x += step;
-       }
+      spe_max = specialist_count();
+      for (spe = 0 ; spe < spe_max; spe++) {
+        if (pCity->specialists[spe]) {
+          for (i = 0; i < pCity->specialists[spe]; i++) {
+            alphablit(pIcons->specialists[spe], NULL, 
pCityWindow->dst->surface, &dest);
+            dest.x += step;
+          }
+        }
       }
 
       if (j == 1) { /* luxury effect */
@@ -2518,6 +2489,7 @@
   struct widget *pWindow = pCityDlg->pEndCityWidgetList;
   SDL_Surface *pBuf = NULL, *pBuf2 = NULL;
   SDL_String16 *pStr = NULL;
+  int spe, spe_max;
 
   refresh_city_names(pCity);
 
@@ -3379,23 +3351,27 @@
   /* ==================================================== */
   /* Draw Citizens */
   count = (pCity->feel[CITIZEN_HAPPY][FEELING_FINAL] + 
pCity->feel[CITIZEN_CONTENT][FEELING_FINAL]
-          + pCity->feel[CITIZEN_UNHAPPY][FEELING_FINAL] + 
pCity->feel[CITIZEN_ANGRY][FEELING_FINAL]
-          + pCity->specialists[SP_ELVIS] + pCity->specialists[SP_SCIENTIST]
-          + pCity->specialists[SP_TAXMAN]);
-
-  pBuf = get_tax_surface(O_LUXURY);
-  
+           + pCity->feel[CITIZEN_UNHAPPY][FEELING_FINAL] + 
pCity->feel[CITIZEN_ANGRY][FEELING_FINAL]
+           + city_specialists(pCity));
+
+  pBuf = get_citizen_surface(CITIZEN_HAPPY, 0);
+
   if (count > 13) {
     step = (adj_size(440) - pBuf->w) / (adj_size(12 + count - 13));
   } else {
     step = pBuf->w;
   }
 
+  pCityDlg->citizen_step = step;
+
   dest.x = pWindow->size.x + adj_size(198);
   dest.y = pWindow->size.y + pWindow->area.y + adj_size(1) + (adj_size(22) - 
pBuf->h) / 2;
 
-  FREESURFACE(pBuf);
-  
+  pCityDlg->spec_area.x = pWindow->dst->dest_rect.x + dest.x;
+  pCityDlg->spec_area.y = pWindow->dst->dest_rect.y + dest.y;
+  pCityDlg->spec_area.w = count * step;
+  pCityDlg->spec_area.h = pBuf->h;
+
   if (pCity->feel[CITIZEN_HAPPY][FEELING_FINAL]) {
     for (i = 0; i < pCity->feel[CITIZEN_HAPPY][FEELING_FINAL]; i++) {
       pBuf = adj_surf(get_citizen_surface(CITIZEN_HAPPY, i));
@@ -3434,60 +3410,18 @@
       FREESURFACE(pBuf);
     }
   }
-    
-  pCityDlg->specs[0] = FALSE;
-  pCityDlg->specs[1] = FALSE;
-  pCityDlg->specs[2] = FALSE;
-  
-  if (pCity->specialists[SP_ELVIS]) {
-    pBuf = get_tax_surface(O_LUXURY);
-    
-    pCityDlg->specs_area[0].x = pWindow->dst->dest_rect.x + dest.x;
-    pCityDlg->specs_area[0].y = pWindow->dst->dest_rect.y + dest.y;
-    pCityDlg->specs_area[0].w = pBuf->w;
-    pCityDlg->specs_area[0].h = pBuf->h;
-    for (i = 0; i < pCity->specialists[SP_ELVIS]; i++) {
-      alphablit(pBuf, NULL, pWindow->dst->surface, &dest);
-      dest.x += step;
-      pCityDlg->specs_area[0].w += step;
-    }
-    FREESURFACE(pBuf);
-    pCityDlg->specs_area[0].w -= step;
-    pCityDlg->specs[0] = TRUE;
-  }
-
-  if (pCity->specialists[SP_TAXMAN]) {
-    pBuf = get_tax_surface(O_GOLD);
-    
-    pCityDlg->specs_area[1].x = pWindow->dst->dest_rect.x + dest.x;
-    pCityDlg->specs_area[1].y = pWindow->dst->dest_rect.y + dest.y;
-    pCityDlg->specs_area[1].w = pBuf->w;
-    pCityDlg->specs_area[1].h = pBuf->h;
-    for (i = 0; i < pCity->specialists[SP_TAXMAN]; i++) {
-      alphablit(pBuf, NULL, pWindow->dst->surface, &dest);
-      dest.x += step;
-      pCityDlg->specs_area[1].w += step;
-    }
-    FREESURFACE(pBuf);
-    pCityDlg->specs_area[1].w -= step;
-    pCityDlg->specs[1] = TRUE;
-  }
-
-  if (pCity->specialists[SP_SCIENTIST]) {
-    pBuf = get_tax_surface(O_SCIENCE);
-    
-    pCityDlg->specs_area[2].x = pWindow->dst->dest_rect.x + dest.x;
-    pCityDlg->specs_area[2].y = pWindow->dst->dest_rect.y + dest.y;
-    pCityDlg->specs_area[2].w = pBuf->w;
-    pCityDlg->specs_area[2].h = pBuf->h;
-    for (i = 0; i < pCity->specialists[SP_SCIENTIST]; i++) {
-      alphablit(pBuf, NULL, pWindow->dst->surface, &dest);
-      dest.x += step;
-      pCityDlg->specs_area[2].w += step;
-    }
-    FREESURFACE(pBuf);
-    pCityDlg->specs_area[2].w -= step;
-    pCityDlg->specs[2] = TRUE;
+
+  spe_max = specialist_count();
+  for (spe = 0; spe < spe_max; spe++) {
+    if (pCity->specialists[spe] > 0) {
+      pBuf = adj_surf(get_citizen_surface(CITIZEN_SPECIALIST + spe, i));
+  
+      for (i = 0; i < pCity->specialists[spe]; i++) {
+        alphablit(pBuf, NULL, pWindow->dst->surface, &dest);
+        dest.x += step;
+      }
+      FREESURFACE(pBuf);
+    }
   }
 
   /* ==================================================== */

Modified: branches/S2_5/client/gui-sdl/gui_tilespec.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-sdl/gui_tilespec.c?rev=28577&r1=28576&r2=28577&view=diff
==============================================================================
--- branches/S2_5/client/gui-sdl/gui_tilespec.c (original)
+++ branches/S2_5/client/gui-sdl/gui_tilespec.c Wed Mar 18 21:53:14 2015
@@ -29,6 +29,9 @@
 #include "fcintl.h"
 #include "log.h"
 
+/* common */
+#include "specialist.h"
+
 /* client */
 #include "client_main.h"
 
@@ -75,6 +78,9 @@
  
*******************************************************************************/
 static void reload_small_citizens_icons(int style)
 {
+  int i;
+  int spe_max;
+
   /* free info icons */
   FREESURFACE(pIcons->pMale_Content);
   FREESURFACE(pIcons->pFemale_Content);
@@ -84,11 +90,12 @@
   FREESURFACE(pIcons->pFemale_Unhappy);
   FREESURFACE(pIcons->pMale_Angry);
   FREESURFACE(pIcons->pFemale_Angry);
-  
-  FREESURFACE(pIcons->pSpec_Lux); /* Elvis */
-  FREESURFACE(pIcons->pSpec_Tax); /* TaxMan */
-  FREESURFACE(pIcons->pSpec_Sci); /* Scientist */
-  
+
+  spe_max = specialist_count();
+  for (i = 0; i < spe_max; i++) {
+    FREESURFACE(pIcons->specialists[i]);
+  }
+
   /* allocate icons */
   pIcons->pMale_Happy = adj_surf(get_citizen_surface(CITIZEN_HAPPY, 0));
   pIcons->pFemale_Happy = adj_surf(get_citizen_surface(CITIZEN_HAPPY, 1));
@@ -98,9 +105,10 @@
   pIcons->pFemale_Unhappy = adj_surf(get_citizen_surface(CITIZEN_UNHAPPY, 1));
   pIcons->pMale_Angry = adj_surf(get_citizen_surface(CITIZEN_ANGRY, 0));
   pIcons->pFemale_Angry = adj_surf(get_citizen_surface(CITIZEN_ANGRY, 1));
-  pIcons->pSpec_Lux = get_tax_surface(O_LUXURY);
-  pIcons->pSpec_Tax = get_tax_surface(O_GOLD);
-  pIcons->pSpec_Sci = get_tax_surface(O_SCIENCE);
+
+  for (i = 0; i < spe_max; i++) {
+    pIcons->specialists[i] = adj_surf(get_citizen_surface(CITIZEN_SPECIALIST + 
i, 0));
+  }
 }
 
 /* 
=================================================================================
 */
@@ -201,6 +209,9 @@
 ***********************************************************************/
 void tilespec_free_city_icons(void)
 {
+  int i;
+  int spe_max;
+
   if (!pIcons) {
     return;
   }
@@ -215,9 +226,10 @@
   FREESURFACE(pIcons->pMale_Angry);
   FREESURFACE(pIcons->pFemale_Angry);
 
-  FREESURFACE(pIcons->pSpec_Lux); /* Elvis */
-  FREESURFACE(pIcons->pSpec_Tax); /* TaxMan */
-  FREESURFACE(pIcons->pSpec_Sci); /* Scientist */
+  spe_max = specialist_count();
+  for (i = 0; i < spe_max; i++) {
+    FREESURFACE(pIcons->specialists[i]);
+  }
 
   FC_FREE(pIcons);
 }

Modified: branches/S2_5/client/gui-sdl/gui_tilespec.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-sdl/gui_tilespec.h?rev=28577&r1=28576&r2=28577&view=diff
==============================================================================
--- branches/S2_5/client/gui-sdl/gui_tilespec.h (original)
+++ branches/S2_5/client/gui-sdl/gui_tilespec.h Wed Mar 18 21:53:14 2015
@@ -181,11 +181,8 @@
   SDL_Surface *pFemale_Unhappy;
   SDL_Surface *pMale_Angry;
   SDL_Surface *pFemale_Angry;
-       
-  SDL_Surface *pSpec_Lux; /* Elvis */
-  SDL_Surface *pSpec_Tax; /* TaxMan */
-  SDL_Surface *pSpec_Sci; /* Scientist */
-
+
+  SDL_Surface *specialists[SP_MAX];
 };
 
 extern struct Theme *pTheme;

Modified: branches/S2_5/client/tilespec.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/tilespec.c?rev=28577&r1=28576&r2=28577&view=diff
==============================================================================
--- branches/S2_5/client/tilespec.c     (original)
+++ branches/S2_5/client/tilespec.c     Wed Mar 18 21:53:14 2015
@@ -5357,6 +5357,10 @@
     graphic = &t->sprites.specialist[type - CITIZEN_SPECIALIST];
   }
 
+  if (graphic->count == 0) {
+    return NULL;
+  }
+
   return graphic->sprite[citizen_index % graphic->count];
 }
 


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

Reply via email to