Author: jtn Date: Mon Jul 11 21:15:07 2016 New Revision: 33227 URL: http://svn.gna.org/viewcvs/freeciv?rev=33227&view=rev Log: Changes to unit_default_orientation: - Random unit orientation is removed completely. Tileset must either set unit_default_orientation, or provide unoriented 'icon' sprites for all unit types. - Restriction that unit_default_orientation must be valid for the tileset is lifted. - README.graphics updated with a summary of how oriented units work.
After comments by Marko Lindqvist (cazfi@gna). Second part of gna patch #7243. Modified: trunk/client/tilespec.c trunk/data/alio.tilespec trunk/data/amplio.tilespec trunk/data/amplio2.tilespec trunk/data/cimpletoon.tilespec trunk/data/hex2t.tilespec trunk/data/hexemplio.tilespec trunk/data/isophex.tilespec trunk/data/isotrident.tilespec trunk/data/toonhex.tilespec trunk/data/trident.tilespec trunk/doc/README.graphics Modified: trunk/client/tilespec.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/tilespec.c?rev=33227&r1=33226&r2=33227&view=diff ============================================================================== --- trunk/client/tilespec.c (original) +++ trunk/client/tilespec.c Mon Jul 11 21:15:07 2016 @@ -1983,6 +1983,7 @@ c = secfile_lookup_str_default(file, NULL, "tilespec.unit_default_orientation"); if (!c) { + /* This is valid, but tileset must specify icon for every unit */ t->unit_default_orientation = direction8_invalid(); } else { dir = dir_by_tileset_name(c); @@ -1991,12 +1992,9 @@ tileset_error(LOG_ERROR, "Tileset \"%s\": unknown " "unit_default_orientation \"%s\"", t->name, c); goto ON_ERROR; - } else if (!is_valid_tileset_dir(t, dir)) { - tileset_error(LOG_ERROR, "Tileset \"%s\": unsuitable " - "unit_default_orientation \"%s\" for this tileset", - t->name, c); - goto ON_ERROR; } else { + /* Default orientation is allowed to not be a valid one for the + * tileset */ t->unit_default_orientation = dir; } } @@ -3192,7 +3190,8 @@ static bool tileset_setup_unit_direction(struct tileset *t, int uidx, const char *base_str, - enum direction8 dir) + enum direction8 dir, + bool has_icon) { char buf[2048]; enum direction8 loaddir = dir; @@ -3200,9 +3199,12 @@ /* * There may be more orientations available in this tileset than are * needed, if an oriented unit set has been re-used between tilesets. - * Don't bother loading unused ones. + * + * Don't bother loading unused ones, unless they might be used by + * unit_default_orientation (logic here mirrors get_unittype_sprite()). */ - if (!is_valid_tileset_dir(t, dir)) { + if (!(dir == t->unit_default_orientation && !has_icon) + && !is_valid_tileset_dir(t, dir)) { /* Instead we copy a nearby valid dir's sprite, so we're not caught * out in case this tileset is used with an incompatible topology, * although it'll be ugly. */ @@ -3234,12 +3236,13 @@ bool static tileset_setup_unit_type_from_tag(struct tileset *t, int uidx, const char *tag) { - bool facing_sprites = TRUE; + bool has_icon, facing_sprites = TRUE; t->sprites.units.icon[uidx] = load_sprite(t, tag); + has_icon = t->sprites.units.icon[uidx] != NULL; #define LOAD_FACING_SPRITE(dir) \ - if (!tileset_setup_unit_direction(t, uidx, tag, dir)) { \ + if (!tileset_setup_unit_direction(t, uidx, tag, dir, has_icon)) { \ facing_sprites = FALSE; \ } @@ -3252,7 +3255,7 @@ LOAD_FACING_SPRITE(DIR8_SOUTH); LOAD_FACING_SPRITE(DIR8_SOUTHEAST); - if (!facing_sprites && t->sprites.units.icon[uidx] == NULL) { + if (!has_icon && !facing_sprites) { /* Neither icon gfx or orientation sprites */ return FALSE; } @@ -3274,6 +3277,20 @@ && !tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_alt)) { tileset_error(LOG_FATAL, _("Missing %s unit sprite for tags \"%s\" and alternative \"%s\"."), utype_rule_name(ut), ut->graphic_str, ut->graphic_alt); + } + + if (!t->sprites.units.icon[uidx]) { + if (!direction8_is_valid(t->unit_default_orientation)) { + tileset_error(LOG_FATAL, "Unit type %s has no unoriented sprite and " + "tileset has no unit_default_orientation.", + utype_rule_name(ut)); + } else { + /* We're guaranteed to have an oriented sprite corresponding to + * unit_default_orientation, because tileset_setup_unit_type_from_tag() + * checked for this. */ + fc_assert(t->sprites.units.facing[uidx][t->unit_default_orientation] + != NULL); + } } } @@ -6054,17 +6071,19 @@ if (!direction8_is_valid(facing) || !is_valid_dir(facing)) { facing = t->unit_default_orientation; - if (!direction8_is_valid(facing)) { - /* Fallback to using random orientation sprite. */ - facing = rand_direction(); - } + /* May not have been specified, but it only matters if we don't + * turn out to have an icon sprite */ } if (t->sprites.units.icon[uidx] && (icon || t->sprites.units.facing[uidx][facing] == NULL)) { - /* Has icon sprite */ + /* Has icon sprite, and we prefer to (or must) use it */ return t->sprites.units.icon[uidx]; } else { + /* We should have a valid orientation by now. Failure to have either + * an icon sprite or default orientation should have been caught at + * tileset load. */ + fc_assert_ret_val(direction8_is_valid(facing), NULL); return t->sprites.units.facing[uidx][facing]; } } Modified: trunk/data/alio.tilespec URL: http://svn.gna.org/viewcvs/freeciv/trunk/data/alio.tilespec?rev=33227&r1=33226&r2=33227&view=diff ============================================================================== --- trunk/data/alio.tilespec (original) +++ trunk/data/alio.tilespec Mon Jul 11 21:15:07 2016 @@ -90,8 +90,8 @@ ; For tilesets with oriented units, the directional sprite to use to ; represent a unit type rather than a specific unit from the map -; (e.g., in worklists, editor, and online help). If not specified, such -; sprites will be oriented randomly. +; (e.g., in worklists, editor, and online help). Does not have to be a +; valid direction for the tileset. ;unit_default_orientation = "s" ; These are special because they get freed and reloaded Modified: trunk/data/amplio.tilespec URL: http://svn.gna.org/viewcvs/freeciv/trunk/data/amplio.tilespec?rev=33227&r1=33226&r2=33227&view=diff ============================================================================== --- trunk/data/amplio.tilespec (original) +++ trunk/data/amplio.tilespec Mon Jul 11 21:15:07 2016 @@ -80,8 +80,8 @@ ; For tilesets with oriented units, the directional sprite to use to ; represent a unit type rather than a specific unit from the map -; (e.g., in worklists, editor, and online help). If not specified, such -; sprites will be oriented randomly. +; (e.g., in worklists, editor, and online help). Does not have to be a +; valid direction for the tileset. ;unit_default_orientation = "s" ; These are special because they get freed and reloaded Modified: trunk/data/amplio2.tilespec URL: http://svn.gna.org/viewcvs/freeciv/trunk/data/amplio2.tilespec?rev=33227&r1=33226&r2=33227&view=diff ============================================================================== --- trunk/data/amplio2.tilespec (original) +++ trunk/data/amplio2.tilespec Mon Jul 11 21:15:07 2016 @@ -80,8 +80,8 @@ ; For tilesets with oriented units, the directional sprite to use to ; represent a unit type rather than a specific unit from the map -; (e.g., in worklists, editor, and online help). If not specified, such -; sprites will be oriented randomly. +; (e.g., in worklists, editor, and online help). Does not have to be a +; valid direction for the tileset. ;unit_default_orientation = "s" ; These are special because they get freed and reloaded Modified: trunk/data/cimpletoon.tilespec URL: http://svn.gna.org/viewcvs/freeciv/trunk/data/cimpletoon.tilespec?rev=33227&r1=33226&r2=33227&view=diff ============================================================================== --- trunk/data/cimpletoon.tilespec (original) +++ trunk/data/cimpletoon.tilespec Mon Jul 11 21:15:07 2016 @@ -84,8 +84,8 @@ ; For tilesets with oriented units, the directional sprite to use to ; represent a unit type rather than a specific unit from the map -; (e.g., in worklists, editor, and online help). If not specified, such -; sprites will be oriented randomly. +; (e.g., in worklists, editor, and online help). Does not have to be a +; valid direction for the tileset. unit_default_orientation = "s" ; These are special because they get freed and reloaded Modified: trunk/data/hex2t.tilespec URL: http://svn.gna.org/viewcvs/freeciv/trunk/data/hex2t.tilespec?rev=33227&r1=33226&r2=33227&view=diff ============================================================================== --- trunk/data/hex2t.tilespec (original) +++ trunk/data/hex2t.tilespec Mon Jul 11 21:15:07 2016 @@ -83,8 +83,8 @@ ; For tilesets with oriented units, the directional sprite to use to ; represent a unit type rather than a specific unit from the map -; (e.g., in worklists, editor, and online help). If not specified, such -; sprites will be oriented randomly. +; (e.g., in worklists, editor, and online help). Does not have to be a +; valid direction for the tileset. ;unit_default_orientation = "s" ; These are special because they get freed and reloaded Modified: trunk/data/hexemplio.tilespec URL: http://svn.gna.org/viewcvs/freeciv/trunk/data/hexemplio.tilespec?rev=33227&r1=33226&r2=33227&view=diff ============================================================================== --- trunk/data/hexemplio.tilespec (original) +++ trunk/data/hexemplio.tilespec Mon Jul 11 21:15:07 2016 @@ -86,8 +86,8 @@ ; For tilesets with oriented units, the directional sprite to use to ; represent a unit type rather than a specific unit from the map -; (e.g., in worklists, editor, and online help). If not specified, such -; sprites will be oriented randomly. +; (e.g., in worklists, editor, and online help). Does not have to be a +; valid direction for the tileset. ;unit_default_orientation = "s" ; These are special because they get freed and reloaded Modified: trunk/data/isophex.tilespec URL: http://svn.gna.org/viewcvs/freeciv/trunk/data/isophex.tilespec?rev=33227&r1=33226&r2=33227&view=diff ============================================================================== --- trunk/data/isophex.tilespec (original) +++ trunk/data/isophex.tilespec Mon Jul 11 21:15:07 2016 @@ -83,8 +83,8 @@ ; For tilesets with oriented units, the directional sprite to use to ; represent a unit type rather than a specific unit from the map -; (e.g., in worklists, editor, and online help). If not specified, such -; sprites will be oriented randomly. +; (e.g., in worklists, editor, and online help). Does not have to be a +; valid direction for the tileset. ;unit_default_orientation = "s" ; These are special because they get freed and reloaded Modified: trunk/data/isotrident.tilespec URL: http://svn.gna.org/viewcvs/freeciv/trunk/data/isotrident.tilespec?rev=33227&r1=33226&r2=33227&view=diff ============================================================================== --- trunk/data/isotrident.tilespec (original) +++ trunk/data/isotrident.tilespec Mon Jul 11 21:15:07 2016 @@ -82,8 +82,8 @@ ; For tilesets with oriented units, the directional sprite to use to ; represent a unit type rather than a specific unit from the map -; (e.g., in worklists, editor, and online help). If not specified, such -; sprites will be oriented randomly. +; (e.g., in worklists, editor, and online help). Does not have to be a +; valid direction for the tileset. ;unit_default_orientation = "s" ; These are special because they get freed and reloaded Modified: trunk/data/toonhex.tilespec URL: http://svn.gna.org/viewcvs/freeciv/trunk/data/toonhex.tilespec?rev=33227&r1=33226&r2=33227&view=diff ============================================================================== --- trunk/data/toonhex.tilespec (original) +++ trunk/data/toonhex.tilespec Mon Jul 11 21:15:07 2016 @@ -87,8 +87,8 @@ ; For tilesets with oriented units, the directional sprite to use to ; represent a unit type rather than a specific unit from the map -; (e.g., in worklists, editor, and online help). If not specified, such -; sprites will be oriented randomly. +; (e.g., in worklists, editor, and online help). Does not have to be a +; valid direction for the tileset. unit_default_orientation = "s" ; These are special because they get freed and reloaded Modified: trunk/data/trident.tilespec URL: http://svn.gna.org/viewcvs/freeciv/trunk/data/trident.tilespec?rev=33227&r1=33226&r2=33227&view=diff ============================================================================== --- trunk/data/trident.tilespec (original) +++ trunk/data/trident.tilespec Mon Jul 11 21:15:07 2016 @@ -83,8 +83,8 @@ ; For tilesets with oriented units, the directional sprite to use to ; represent a unit type rather than a specific unit from the map -; (e.g., in worklists, editor, and online help). If not specified, such -; sprites will be oriented randomly. +; (e.g., in worklists, editor, and online help). Does not have to be a +; valid direction for the tileset. ;unit_default_orientation = "s" ; These are special because they get freed and reloaded Modified: trunk/doc/README.graphics URL: http://svn.gna.org/viewcvs/freeciv/trunk/doc/README.graphics?rev=33227&r1=33226&r2=33227&view=diff ============================================================================== --- trunk/doc/README.graphics (original) +++ trunk/doc/README.graphics Mon Jul 11 21:15:07 2016 @@ -78,6 +78,8 @@ city_names_font : an X font string city_productions_font : an X font string main_intro_file : GFX file for the intro graphics + unit_default_orientation : Specifies a direction to use for unit types in + worklists etc. See "Unit Sprites" below. String vectors -------------- @@ -503,3 +505,31 @@ An appropriate sprite will be chosen depending on which adjacent tiles also have farmland/irrigation. If any of these sprites are not present, the default sprite will be used as a fallback. + + Unit Sprites + ------------ + + Units sprites can be either unoriented or oriented, in which case the + sprite that is displayed depends on the direction the unit is facing (it + turns when it moves or fights). + + Unoriented sprites are specified as 'u.phalanx'. Oriented sprites have + a direction suffix: 'u.phalanx_s', 'u.phalanx_nw' and so on. + For each unit type, either an unoriented sprite or a full set of + the oriented sprites needed for the tileset topology must be provided + (you can also provide both, see below). + + The game sometimes needs to draw a sprite for a unit type that doesn't + correspond to a specific unit, so is not facing a particular direction. + There are several options for oriented tilesets: + + - If the unit_default_orientation is specified for the tileset, the + game will by default use that directional sprite. (The direction + doesn't have to be a valid one for the tileset.) + + - Specific unit types may override this by providing an unoriented + sprite as well as the oriented ones; this doesn't have to be + distinct, so it can point to one of the oriented sprites, allowing + choice of the best orientation for each individual unit type. + If unit_default_orientation is not specified, an unoriented sprite + must be specified for *every* unit. _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits