Author: jtn Date: Tue Jun 21 10:27:46 2016 New Revision: 32941 URL: http://svn.gna.org/viewcvs/freeciv?rev=32941&view=rev Log: Fix all random unit type orientations at tileset load time. Remove all hard-coded orientations from the clients.
Suggested by Marko Lindqvist (cazfi@gna). See gna bug #24771. Modified: branches/S2_5/client/gui-gtk-2.0/wldlg.c branches/S2_5/client/gui-gtk-3.0/wldlg.c branches/S2_5/client/gui-qt/repodlgs.cpp branches/S2_5/client/gui-sdl/citydlg.c branches/S2_5/client/reqtree.c branches/S2_5/client/tilespec.c Modified: branches/S2_5/client/gui-gtk-2.0/wldlg.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-2.0/wldlg.c?rev=32941&r1=32940&r2=32941&view=diff ============================================================================== --- branches/S2_5/client/gui-gtk-2.0/wldlg.c (original) +++ branches/S2_5/client/gui-gtk-2.0/wldlg.c Tue Jun 21 10:27:46 2016 @@ -951,7 +951,7 @@ store.type = CANVAS_PIXBUF; store.v.pixbuf = pix; - create_overlay_unit(&store, target.value.utype, DIR8_SOUTH); + create_overlay_unit(&store, target.value.utype, direction8_invalid()); g_object_set(rend, "pixbuf", pix, NULL); g_object_unref(pix); Modified: branches/S2_5/client/gui-gtk-3.0/wldlg.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-3.0/wldlg.c?rev=32941&r1=32940&r2=32941&view=diff ============================================================================== --- branches/S2_5/client/gui-gtk-3.0/wldlg.c (original) +++ branches/S2_5/client/gui-gtk-3.0/wldlg.c Tue Jun 21 10:27:46 2016 @@ -951,7 +951,7 @@ if (VUT_UTYPE == target.kind) { sprite = sprite_scale(get_unittype_sprite(tileset, target.value.utype, - DIR8_SOUTH, TRUE), + direction8_invalid(), TRUE), max_unit_width, max_unit_height); } else { Modified: branches/S2_5/client/gui-qt/repodlgs.cpp URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/repodlgs.cpp?rev=32941&r1=32940&r2=32941&view=diff ============================================================================== --- branches/S2_5/client/gui-qt/repodlgs.cpp (original) +++ branches/S2_5/client/gui-qt/repodlgs.cpp Tue Jun 21 10:27:46 2016 @@ -162,7 +162,8 @@ if (advance_number(unit->require_advance) != node->tech) { continue; } - sprite = get_unittype_sprite(tileset, unit, DIR8_SOUTH, TRUE); + sprite = get_unittype_sprite(tileset, unit, + direction8_invalid(), TRUE); get_sprite_dimensions(sprite, &swidth, &sheight); rttp = new req_tooltip_help(); rttp->rect = QRect(icon_startx, starty + text_h + 4 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=32941&r1=32940&r2=32941&view=diff ============================================================================== --- branches/S2_5/client/gui-sdl/citydlg.c (original) +++ branches/S2_5/client/gui-sdl/citydlg.c Tue Jun 21 10:27:46 2016 @@ -3214,7 +3214,7 @@ copy_chars_to_string16(pStr, utype_name_translation(pUnitType)); pBuf = create_text_surf_from_str16(pStr); - pBuf2 = get_unittype_surface(pUnitType, DIR8_EAST); + pBuf2 = get_unittype_surface(pUnitType, direction8_invalid()); pBuf2 = zoomSurface(pBuf2, DEFAULT_ZOOM * ((float)32 / pBuf2->h), DEFAULT_ZOOM * ((float)32 / pBuf2->h), 1); /* blit unit icon */ Modified: branches/S2_5/client/reqtree.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/reqtree.c?rev=32941&r1=32940&r2=32941&view=diff ============================================================================== --- branches/S2_5/client/reqtree.c (original) +++ branches/S2_5/client/reqtree.c Tue Jun 21 10:27:46 2016 @@ -1085,7 +1085,8 @@ if (advance_number(unit->require_advance) != node->tech) { continue; } - sprite = get_unittype_sprite(tileset, unit, DIR8_SOUTH, TRUE); + sprite = get_unittype_sprite(tileset, unit, + direction8_invalid(), TRUE); get_sprite_dimensions(sprite, &swidth, &sheight); canvas_put_sprite_full(pcanvas, icon_startx, Modified: branches/S2_5/client/tilespec.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/tilespec.c?rev=32941&r1=32940&r2=32941&view=diff ============================================================================== --- branches/S2_5/client/tilespec.c (original) +++ branches/S2_5/client/tilespec.c Tue Jun 21 10:27:46 2016 @@ -230,6 +230,7 @@ struct { struct sprite *icon[U_LAST]; struct sprite *facing[U_LAST][DIR8_MAGIC_MAX]; + unsigned int default_dir_seed[U_LAST]; } units; struct sprite *resource[MAX_NUM_RESOURCES]; @@ -3017,6 +3018,12 @@ return FALSE; } + /* Fix a random orientation for displaying unit type in help etc. + * We don't necessarily know the map topology yet, so choose a seed + * that can be used to pick a valid direction later (24 is lcm(6,8)). + * See get_unittype_sprite(). */ + t->sprites.units.default_dir_seed[uidx] = fc_rand(24); + return TRUE; #undef LOAD_FACING_SPRITE @@ -5496,8 +5503,21 @@ fc_assert_ret_val(NULL != punittype, NULL); if (!direction8_is_valid(facing) || !is_valid_dir(facing)) { - /* Fallback to using random orientation sprite. */ - facing = rand_direction(); + /* Fallback to random orientation sprite. + * The randomness was fixed at tileset load time for stability + * (in tileset_setup_unit_type_from_tag()); here we need to adapt + * that to the map topology (which is now known). + * default_dir_seed was set to give uniform distribution for either + * 6 or 8 valid directions. + * Thus this direction is stable for a given unit type unless the + * map topology changes. */ + unsigned int dir_index; + + fc_assert_ret_val(map.num_valid_dirs > 0, NULL); + dir_index + = t->sprites.units.default_dir_seed[uidx] % map.num_valid_dirs; + facing = map.valid_dirs[dir_index]; + fc_assert_ret_val(is_valid_dir(facing), NULL); } if (t->sprites.units.icon[uidx] _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits