From 4e82795c5314d092675bc826347967f5a17e4ffa Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Wed, 13 Nov 2024 06:26:01 +0200
Subject: [PATCH 82/82] Make default animation speed tileset controlled

See RM #1107

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/tilespec.c        | 17 +++++++++++++----
 data/3d.tilespec         |  4 ++++
 data/alio.tilespec       |  4 ++++
 data/amplio.tilespec     |  4 ++++
 data/amplio2.tilespec    |  4 ++++
 data/cimpletoon.tilespec |  4 ++++
 data/hex2t.tilespec      |  4 ++++
 data/hexemplio.tilespec  |  4 ++++
 data/isophex.tilespec    |  4 ++++
 data/isotrident.tilespec |  4 ++++
 data/toonhex.tilespec    |  4 ++++
 data/trident.tilespec    |  4 ++++
 12 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/client/tilespec.c b/client/tilespec.c
index 1b156c314a..aa32f3b45a 100644
--- a/client/tilespec.c
+++ b/client/tilespec.c
@@ -514,6 +514,8 @@ struct tileset {
   int max_upkeep_height;
   int svg_height;
 
+  int default_time_per_frame;
+
   char *main_intro_filename;
 
   enum direction8 unit_default_orientation;
@@ -2244,6 +2246,7 @@ static struct tileset *tileset_read_toplevel(const char *tileset_name,
   t->unit_upkeep_small_offset_y = secfile_lookup_int_default(file, t->unit_upkeep_offset_y,
                                                              "tilespec.unit_upkeep_small_offset_y");
   t->svg_height = secfile_lookup_int_default(file, 44, "tilespec.svg_height");
+  t->default_time_per_frame = secfile_lookup_int_default(file, 3, "tilespec.time_per_frame");
 
   t->city_size_offset_x = t->scale * t->city_size_offset_x;
   t->city_size_offset_y = t->scale * t->city_size_offset_y;
@@ -2959,7 +2962,7 @@ static bool sprite_exists(const struct tileset *t, const char *tag_name)
 
 #define SET_ANIM(field, tag)                                      \
   do {                                                            \
-    t->sprites.field = anim_load(t, tag, 3);                      \
+    t->sprites.field = anim_load(t, tag, 0);                      \
     if (t->sprites.field == NULL) {                               \
       tileset_error(LOG_FATAL, tileset_name_get(t),               \
                     _("Animation for tag '%s' missing."), tag);   \
@@ -2969,8 +2972,10 @@ static bool sprite_exists(const struct tileset *t, const char *tag_name)
 /************************************************************************//**
   Load an animation
 
-  @param t   Tileset to load animation from
-  @param tag Base tag of the animation sprites
+  @param t              Tileset to load animation from
+  @param tag            Base tag of the animation sprites
+  @param time_per_frame How many refreshes there's between advancing to
+                        the next frame. 0 for default.
 ****************************************************************************/
 static struct anim *anim_load(struct tileset *t, const char *tag,
                               int time_per_frame)
@@ -2988,6 +2993,10 @@ static struct anim *anim_load(struct tileset *t, const char *tag,
     return nullptr;
   }
 
+  if (time_per_frame <= 0) {
+    time_per_frame = t->default_time_per_frame;
+  }
+
   ret = anim_new(frames, time_per_frame);
 
   for (i = 0; i < frames; i++) {
@@ -3433,7 +3442,7 @@ static void tileset_lookup_sprite_tags(struct tileset *t)
   SET_SPRITE(unit.tired, "unit.tired");
 
   t->sprites.unit.action_decision_want = anim_load(t, "unit.action_decision_want",
-                                                   3);
+                                                   0);
 
   for (i = 0; i < NUM_TILES_HP_BAR; i++) {
     fc_snprintf(buffer, sizeof(buffer), "unit.hp_%d", i*10);
diff --git a/data/3d.tilespec b/data/3d.tilespec
index 4736f06821..5566540439 100644
--- a/data/3d.tilespec
+++ b/data/3d.tilespec
@@ -100,6 +100,10 @@ unit_upkeep_small_offset_y = 20
 ; valid direction for the tileset.
 ;unit_default_orientation = "s"
 
+; How long (number of refreshes) it takes to move from an animation
+; frame to the next.
+time_per_frame = 3
+
 ; The map is rendered in "layers", just like any decent image editor
 ; supports. The setting below allows to change the layer drawing order. The
 ; first layer in the list will be drawn below the others; the second on top
diff --git a/data/alio.tilespec b/data/alio.tilespec
index 504df97940..0847e9a804 100644
--- a/data/alio.tilespec
+++ b/data/alio.tilespec
@@ -110,6 +110,10 @@ tilelabel_offset_y = 20
 ; valid direction for the tileset.
 unit_default_orientation = "s"
 
+; How long (number of refreshes) it takes to move from an animation
+; frame to the next.
+time_per_frame = 3
+
 ; The map is rendered in "layers", just like any decent image editor
 ; supports. The setting below allows to change the layer drawing order. The
 ; first layer in the list will be drawn below the others; the second on top
diff --git a/data/amplio.tilespec b/data/amplio.tilespec
index 09af0272b1..64b889f45e 100644
--- a/data/amplio.tilespec
+++ b/data/amplio.tilespec
@@ -97,6 +97,10 @@ tilelabel_offset_y = 15
 ; valid direction for the tileset.
 ;unit_default_orientation = "s"
 
+; How long (number of refreshes) it takes to move from an animation
+; frame to the next.
+time_per_frame = 3
+
 ; The map is rendered in "layers", just like any decent image editor
 ; supports. The setting below allows to change the layer drawing order. The
 ; first layer in the list will be drawn below the others; the second on top
diff --git a/data/amplio2.tilespec b/data/amplio2.tilespec
index 2110944858..8f3dbb7cc0 100644
--- a/data/amplio2.tilespec
+++ b/data/amplio2.tilespec
@@ -97,6 +97,10 @@ tilelabel_offset_y = 15
 ; valid direction for the tileset.
 ;unit_default_orientation = "s"
 
+; How long (number of refreshes) it takes to move from an animation
+; frame to the next.
+time_per_frame = 3
+
 ; The map is rendered in "layers", just like any decent image editor
 ; supports. The setting below allows to change the layer drawing order. The
 ; first layer in the list will be drawn below the others; the second on top
diff --git a/data/cimpletoon.tilespec b/data/cimpletoon.tilespec
index 68404e6b49..d96a693514 100644
--- a/data/cimpletoon.tilespec
+++ b/data/cimpletoon.tilespec
@@ -100,6 +100,10 @@ tilelabel_offset_y = 15
 ; valid direction for the tileset.
 unit_default_orientation = "s"
 
+; How long (number of refreshes) it takes to move from an animation
+; frame to the next.
+time_per_frame = 3
+
 ; The map is rendered in "layers", just like any decent image editor
 ; supports. The setting below allows to change the layer drawing order. The
 ; first layer in the list will be drawn below the others; the second on top
diff --git a/data/hex2t.tilespec b/data/hex2t.tilespec
index 18cfe9dc85..b1d3f99739 100644
--- a/data/hex2t.tilespec
+++ b/data/hex2t.tilespec
@@ -100,6 +100,10 @@ tilelabel_offset_y = 28
 ; valid direction for the tileset.
 ;unit_default_orientation = "s"
 
+; How long (number of refreshes) it takes to move from an animation
+; frame to the next.
+time_per_frame = 3
+
 ; The map is rendered in "layers", just like any decent image editor
 ; supports. The setting below allows to change the layer drawing order. The
 ; first layer in the list will be drawn below the others; the second on top
diff --git a/data/hexemplio.tilespec b/data/hexemplio.tilespec
index cdf1657ffe..3e5667b7c4 100644
--- a/data/hexemplio.tilespec
+++ b/data/hexemplio.tilespec
@@ -102,6 +102,10 @@ tilelabel_offset_y = 20
 ; valid direction for the tileset.
 ;unit_default_orientation = "s"
 
+; How long (number of refreshes) it takes to move from an animation
+; frame to the next.
+time_per_frame = 3
+
 ; The map is rendered in "layers", just like any decent image editor
 ; supports. The setting below allows to change the layer drawing order. The
 ; first layer in the list will be drawn below the others; the second on top
diff --git a/data/isophex.tilespec b/data/isophex.tilespec
index 2ad66ee9d5..cd3e029125 100644
--- a/data/isophex.tilespec
+++ b/data/isophex.tilespec
@@ -100,6 +100,10 @@ tilelabel_offset_y = 10
 ; valid direction for the tileset.
 ;unit_default_orientation = "s"
 
+; How long (number of refreshes) it takes to move from an animation
+; frame to the next.
+time_per_frame = 3
+
 ; The map is rendered in "layers", just like any decent image editor
 ; supports. The setting below allows to change the layer drawing order. The
 ; first layer in the list will be drawn below the others; the second on top
diff --git a/data/isotrident.tilespec b/data/isotrident.tilespec
index d27165dca3..04fb20c3d7 100644
--- a/data/isotrident.tilespec
+++ b/data/isotrident.tilespec
@@ -99,6 +99,10 @@ tilelabel_offset_y = 10
 ; valid direction for the tileset.
 ;unit_default_orientation = "s"
 
+; How long (number of refreshes) it takes to move from an animation
+; frame to the next.
+time_per_frame = 3
+
 ; The map is rendered in "layers", just like any decent image editor
 ; supports. The setting below allows to change the layer drawing order. The
 ; first layer in the list will be drawn below the others; the second on top
diff --git a/data/toonhex.tilespec b/data/toonhex.tilespec
index d97cc943f4..68fc71cfb5 100644
--- a/data/toonhex.tilespec
+++ b/data/toonhex.tilespec
@@ -104,6 +104,10 @@ tilelabel_offset_y = 20
 ; valid direction for the tileset.
 unit_default_orientation = "s"
 
+; How long (number of refreshes) it takes to move from an animation
+; frame to the next.
+time_per_frame = 3
+
 ; The map is rendered in "layers", just like any decent image editor
 ; supports. The setting below allows to change the layer drawing order. The
 ; first layer in the list will be drawn below the others; the second on top
diff --git a/data/trident.tilespec b/data/trident.tilespec
index 55eea8b7dd..2df1f7e9c9 100644
--- a/data/trident.tilespec
+++ b/data/trident.tilespec
@@ -100,6 +100,10 @@ unit_upkeep_small_offset_y = 20
 ; valid direction for the tileset.
 ;unit_default_orientation = "s"
 
+; How long (number of refreshes) it takes to move from an animation
+; frame to the next.
+time_per_frame = 3
+
 ; The map is rendered in "layers", just like any decent image editor
 ; supports. The setting below allows to change the layer drawing order. The
 ; first layer in the list will be drawn below the others; the second on top
-- 
2.45.2

