Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12442) encapsulate the spaceship sprites
Home

[Freeciv-Dev] (PR#12442) encapsulate the spaceship sprites

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12442) encapsulate the spaceship sprites
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 15 Mar 2005 09:37:33 -0800
Reply-to: bugs@xxxxxxxxxxx

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

Here is a better patch that changes the spaceship parts into an enum.

-jason

? diff
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.214
diff -u -r1.214 mapview_common.c
--- client/mapview_common.c     15 Mar 2005 16:04:17 -0000      1.214
+++ client/mapview_common.c     15 Mar 2005 17:36:56 -0000
@@ -2398,7 +2398,10 @@
 ****************************************************************************/
 void get_spaceship_dimensions(int *width, int *height)
 {
-  get_sprite_dimensions(sprites.spaceship.habitation, width, height);
+  struct Sprite *sprite
+    = get_spaceship_sprite(tileset, SPACESHIP_HABITATION);
+
+  get_sprite_dimensions(sprite, width, height);
   *width *= 7;
   *height *= 7;
 }
@@ -2412,8 +2415,11 @@
   int i, x, y;  
   const struct player_spaceship *ship = &pplayer->spaceship;
   int w, h;
+  struct Sprite *sprite;
+  struct tileset *t = tileset;
 
-  get_sprite_dimensions(sprites.spaceship.habitation, &w, &h);
+  sprite = get_spaceship_sprite(t, SPACESHIP_HABITATION);
+  get_sprite_dimensions(sprite, &w, &h);
 
   canvas_put_rectangle(pcanvas, COLOR_STD_BLACK, 0, 0, w * 7, h * 7);
 
@@ -2430,9 +2436,9 @@
     x = modules_info[i].x * w / 4 - w / 2;
     y = modules_info[i].y * h / 4 - h / 2;
 
-    sprite = (k == 0 ? sprites.spaceship.habitation
-             : k == 1 ? sprites.spaceship.life_support
-             : sprites.spaceship.solar_panels);
+    sprite = (k == 0 ? get_spaceship_sprite(t, SPACESHIP_HABITATION)
+             : k == 1 ? get_spaceship_sprite(t, SPACESHIP_LIFE_SUPPORT)
+             : get_spaceship_sprite(t, SPACESHIP_SOLAR_PANEL));
     canvas_put_sprite_full(pcanvas, x, y, sprite);
   }
 
@@ -2448,8 +2454,8 @@
     x = components_info[i].x * w / 4 - w / 2;
     y = components_info[i].y * h / 4 - h / 2;
 
-    sprite = ((k == 0) ? sprites.spaceship.fuel
-             : sprites.spaceship.propulsion);
+    sprite = ((k == 0) ? get_spaceship_sprite(t, SPACESHIP_FUEL)
+             : get_spaceship_sprite(t, SPACESHIP_PROPULSION));
 
     canvas_put_sprite_full(pcanvas, x, y, sprite);
   }
@@ -2461,6 +2467,7 @@
     x = structurals_info[i].x * w / 4 - w / 2;
     y = structurals_info[i].y * h / 4 - h / 2;
 
-    canvas_put_sprite_full(pcanvas, x, y, sprites.spaceship.structural);
+    sprite = get_spaceship_sprite(t, SPACESHIP_STRUCTURAL);
+    canvas_put_sprite_full(pcanvas, x, y, sprite);
   }
 }
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.267
diff -u -r1.267 tilespec.c
--- client/tilespec.c   15 Mar 2005 16:04:17 -0000      1.267
+++ client/tilespec.c   15 Mar 2005 17:36:56 -0000
@@ -1420,12 +1420,14 @@
 
   tileset_setup_citizen_types(t);
 
-  SET_SPRITE(spaceship.solar_panels, "spaceship.solar_panels");
-  SET_SPRITE(spaceship.life_support, "spaceship.life_support");
-  SET_SPRITE(spaceship.habitation,   "spaceship.habitation");
-  SET_SPRITE(spaceship.structural,   "spaceship.structural");
-  SET_SPRITE(spaceship.fuel,         "spaceship.fuel");
-  SET_SPRITE(spaceship.propulsion,   "spaceship.propulsion");
+  for (i = 0; i < SPACESHIP_COUNT; i++) {
+    const char *names[SPACESHIP_COUNT]
+      = {"solar_panels", "life_support", "habitation",
+        "structural", "fuel", "propulsion"};
+
+    my_snprintf(buffer, sizeof(buffer), "spaceship.%s", names[i]);
+    SET_SPRITE(spaceship[i], buffer);
+  }
 
   for (i = 0; i < CURSOR_LAST; i++) {
     const char *names[CURSOR_LAST] = {"goto", "patrol", "paradrop", "nuke"};
@@ -3836,6 +3838,15 @@
 }
 
 /**************************************************************************
+  Return the sprite for drawing the given spaceship part.
+**************************************************************************/
+struct Sprite *get_spaceship_sprite(struct tileset *t,
+                                   enum spaceship_part part)
+{
+  return sprites.spaceship[part];
+}
+
+/**************************************************************************
   Return a sprite for the given citizen.  The citizen's type is given,
   as well as their index (in the range [0..pcity->size)).  The
   citizen's city can be used to determine which sprite to use (a NULL
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.128
diff -u -r1.128 tilespec.h
--- client/tilespec.h   15 Mar 2005 16:04:17 -0000      1.128
+++ client/tilespec.h   15 Mar 2005 17:36:59 -0000
@@ -206,6 +206,16 @@
   INDICATOR_COUNT
 };
 
+enum spaceship_part {
+  SPACESHIP_SOLAR_PANEL,
+  SPACESHIP_LIFE_SUPPORT,
+  SPACESHIP_HABITATION,
+  SPACESHIP_STRUCTURAL,
+  SPACESHIP_FUEL,
+  SPACESHIP_PROPULSION,
+  SPACESHIP_COUNT
+};
+
 struct named_sprites {
   struct Sprite
     *indicator[INDICATOR_COUNT][NUM_TILES_PROGRESS],
@@ -229,15 +239,7 @@
     int count;
     struct Sprite *sprite[MAX_NUM_CITIZEN_SPRITES];
   } citizen[NUM_TILES_CITIZEN], specialist[SP_MAX];
-  struct {
-    struct Sprite
-      *solar_panels,
-      *life_support,
-      *habitation,
-      *structural,
-      *fuel,
-      *propulsion;
-  } spaceship;
+  struct Sprite *spaceship[SPACESHIP_COUNT];
   struct {
     int hot_x, hot_y;
     struct Sprite *icon;
@@ -355,6 +357,8 @@
 
 extern struct named_sprites sprites;
 
+struct Sprite *get_spaceship_sprite(struct tileset *t,
+                                   enum spaceship_part part);
 struct Sprite *get_citizen_sprite(struct citizen_type type,
                                  int citizen_index,
                                  const struct city *pcity);

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