widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #10658
Re: [Merge] lp:~widelands-dev/widelands/reveal_hide_animations into lp:widelands
A couple of nits, code LGTM otherwise. Needs testing.
Diff comments:
>
> === modified file 'data/campaigns/bar01.wmf/scripting/mission_thread.lua'
> --- data/campaigns/bar01.wmf/scripting/mission_thread.lua 2016-12-29 10:31:07 +0000
> +++ data/campaigns/bar01.wmf/scripting/mission_thread.lua 2017-07-09 10:09:27 +0000
> @@ -15,15 +15,21 @@
> -- =====================================================
>
> function introduction_thread()
> + reveal_concentric(plr, sf, 13)
> sleep(2000)
>
> message_box_objective(plr, briefing_msg_01)
> -- these buildings are still burning, but only for a while
> map:place_immovable("destroyed_building",map:get_field(7,41),"tribes")
> map:place_immovable("destroyed_building",map:get_field(5,52),"tribes")
> - plr:reveal_fields(al_thunran:region(8))
> + -- plr:reveal_fields(al_thunran:region(8))
Remove commented out line.
> + scroll_to_field(al_thunran)
> + reveal_concentric(plr, al_thunran, 8, true, 50)
> message_box_objective(plr, briefing_msg_02) -- Al'thunran
> - plr:reveal_fields(grave:region(4))
> + scroll_to_field(sf)
> + sleep(1000)
> + scroll_to_field(grave)
> + reveal_concentric(plr, grave, 4)
> message_box_objective(plr, briefing_msg_03) -- grave, Boldreth
> message_box_objective(plr, briefing_msg_04) -- wait
> -- introduction of Khantrukh
>
> === modified file 'data/campaigns/bar02.wmf/scripting/mission_thread.lua'
> --- data/campaigns/bar02.wmf/scripting/mission_thread.lua 2017-01-17 08:52:14 +0000
> +++ data/campaigns/bar02.wmf/scripting/mission_thread.lua 2017-07-09 10:09:27 +0000
> @@ -11,6 +12,9 @@
> fr2 = game.map:get_field(85,1)
> fr3 = game.map:get_field(85,11)
>
> +-- Starting field
> +sf = game.map.player_slots[1].starting_field
Check if this also works with local sf = ... local is always better.
> +
> function check_conquered_footprints()
> if p1:seen_field(game.map:get_field(65, 28))
> then
>
> === modified file 'data/campaigns/emp02.wmf/scripting/mission_thread.lua'
> --- data/campaigns/emp02.wmf/scripting/mission_thread.lua 2017-03-16 21:54:07 +0000
> +++ data/campaigns/emp02.wmf/scripting/mission_thread.lua 2017-07-09 10:09:27 +0000
> @@ -111,16 +113,16 @@
> -- Reveal the other mountains
> local coal_mountain = wl.Game().map:get_field(49,22)
> local iron_mountain = wl.Game().map:get_field(38,37)
> - p1:reveal_fields(coal_mountain:region(6))
> +
> + --local move_point = wl.Game().map:get_field(49,22)
Remove commented out line.
> + wait_for_roadbuilding_and_scroll(coal_mountain)
> + reveal_concentric(p1, coal_mountain, 6, false)
> p1:reveal_fields(iron_mountain:region(6))
> run(function() sleep(5000)
> p1:hide_fields(coal_mountain:region(6))
> p1:hide_fields(iron_mountain:region(6))
> end)
>
> - local move_point = wl.Game().map:get_field(49,22)
> - wait_for_roadbuilding_and_scroll(move_point)
> -
> campaign_message_box(saledus_3)
> p1:allow_buildings{
> "empire_coalmine",
>
> === added file 'data/scripting/field_animations.lua'
> --- data/scripting/field_animations.lua 1970-01-01 00:00:00 +0000
> +++ data/scripting/field_animations.lua 2017-07-09 10:09:27 +0000
> @@ -0,0 +1,173 @@
> +-- RST
> +-- .. _field_animations:
> +--
> +-- field_animations.lua
> +-- --------------------
> +--
> +-- This script contain some animations to reveal and hide fields seen
contain -> contains
> +-- by a player. This functions are currently used in the campaigns and scenarios
> +-- to tell the prologue to a story.
> +
> +-- RST
> +-- .. function:: reveal_randomly(player, region, time)
> +--
> +-- Reveal a given region field by field, where the fields
> +-- are chosen randomly. The region get hidden prior revealing.
"The region get hidden prior revealing." - I do not understand this sentence. The region will be hidden before being revealed?
> +-- The animation runs the specified time.
> +-- See also :meth:`wl.map.Field.region`
> +--
> +-- :arg player: The player who get sight to the region
get -> gets
> +-- :arg region: The region that has to be revealed
> +-- :type region: :class:`array` of :class:`wl.map.Fields`
> +-- :arg time: Optional. The time the whole animation will run.
> +-- Defaults to 1000 (1 sec)
> +
> +function reveal_randomly(plr, region, time)
> + -- If no 'time' is given use a default
> + time = time or 1000
> +
> + -- Make sure the region is hidden
> + plr:hide_fields(region, true)
> +
> + -- Turn off buildhelp during animation
> + local buildhelp_state = wl.ui.MapView().buildhelp
> + if buildhelp_state then
> + wl.ui.MapView().buildhelp = false
> + end
> +
> + -- Calculate delay as integer
> + local delay = math.floor(time / #region)
> + -- Make sure 'delay' is valid
> + if delay < 1 then delay = 1 end
> +
> + -- Reveal field by field
> + while #region > 0 do
> + local t = {}
> + local id = math.random(1, #region)
> + table.insert(t, region[id])
> + plr:reveal_fields(t)
> + sleep(delay)
> + table.remove(region, id)
> + end
> + -- Restore buildhelp status
> + wl.ui.MapView().buildhelp = buildhelp_state
> +end
> +
> +-- RST
> +-- .. function:: hide_randomly(player, region, time)
> +--
> +-- Hide a given region field by field, where the fields
> +-- are chosen randomly. The animation runs the specified time regardless
> +-- how big the given region is. So region(6) and region(13) will take
> +-- the same time. See also :meth:`wl.map.Field.region`
> +--
> +-- :arg player: The player who's sight get hidden
whose sight gets hidden
> +-- :arg region: The region that has to be hidden
has to be -> will be
> +-- :type region: :class:`array` of :class:`wl.map.Fields`
> +-- :arg time: Optional. The time the whole animation will run.
> +-- Defaults to 1000 (1 sec)
> +
> +function hide_randomly(plr, region, time)
> + time = time or 1000
> + -- Turn off buildhelp
> + wl.ui.MapView().buildhelp = false
> +
> + local delay = math.floor(time / #region)
> + if delay < 1 then delay = 1 end
> + while #region > 0 do
> + local id = math.random(1, #region)
> + plr:hide_fields({region[id]},true)
> + table.remove(region, id)
> + sleep(delay)
> + end
> +end
> +
> +-- RST
> +-- .. function:: reveal_concentric(player, center, max_radius, hide, delay)
> +--
> +-- Reveal a part of the map in a concentric way beginning from center onto
> +-- max_radius. The region get hidden prior revealing as default.
By default, ... get -> gets .. prior to revealing.
> +--
> +-- :arg player: The player who get sight to the region
gets
> +-- :arg center: The field from where the animation should start revealing
> +-- :arg max_radius: The last ring to reveal
> +-- :arg hide: Optional, if `false` automatic hiding is disabled
> +-- :type hide: :class:`boolean`
> +-- :arg delay: Optional, defaults to 100. The delay between each ring is
between -> before
Or: The delay between revealing each ring.
> +-- revealed. If you want to set the delay, you must also set `hide`
> +
> +function reveal_concentric(plr, center, max_radius, hide, delay)
> + delay = delay or 100
> + if hide == nil then hide = true end
> +
> + local buildhelp_state = wl.ui.MapView().buildhelp
> + if buildhelp_state then
> + -- Turn off buildhelp during animation
> + wl.ui.MapView().buildhelp = false
> + end
> +
> + if hide then
> + plr:hide_fields(center:region(max_radius), true)
> + end
> +
> + local radius = 0
> + while radius <= max_radius do
> + plr:reveal_fields(center:region(radius))
> + radius = radius + 1
> + sleep(delay)
> + end
> + wl.ui.MapView().buildhelp = buildhelp_state
> +end
> +
> +-- RST
> +-- .. function:: hide_concentric(player, center, max_radius, delay)
> +--
> +-- Hide a part of the map in a concentric way beginning from max_radius onto
> +-- center.
> +--
> +-- :arg player: The player who's sight get hidden
whose... gets
> +-- :arg center: The field where the animation should end hiding
> +-- :arg max_radius: The first ring to hide
> +-- :arg delay: Optional, defaults to 100. The delay between each ring is
between -> before.
Or: The delay between revealing each ring.
> +-- revealed
> +
> +function hide_concentric(plr, center, max_radius, delay)
> + delay = delay or 100
> + -- Turn off buildhelp
> + wl.ui.MapView().buildhelp = false
> + while max_radius > 0 do
> + local to_hide = center:region(max_radius, max_radius - 1)
> + plr:hide_fields(to_hide, true)
> + sleep(delay)
> + max_radius = max_radius -1
> + end
> + -- Hide the remaining field
> + plr:hide_fields({center},true)
> +end
> +
> +-- RST
> +-- .. function:: get_sees_fields(player)
> +--
> +-- Gather all fields a player can see in the current view. The current view
> +-- is the whole area of the map in the current game window. You can use this
> +-- function to get an unregular (non hexagonal) region and feed e.g.
> +-- :meth:`reveal_randomly()` with it.
> +--
> +-- :arg player: The player for whom the fields get gathered
> +-- :returns: A table containing all visible fields in the current view
> +
> +function get_sees_fields(plr)
> + local sees_fields = {}
> + for x=0, wl.Game().map.width-1 do
> + for y=0, wl.Game().map.height-1 do
double blank space
> + f = wl.Game().map:get_field(x,y)
> + if wl.ui.MapView():is_visible(f) then
> + -- Gather only fields which are seen in the view
> + if plr:sees_field(f) then
> + table.insert(sees_fields, f)
> + end
> + end
> + end
> + end
> + return sees_fields
> +end
--
https://code.launchpad.net/~widelands-dev/widelands/reveal_hide_animations/+merge/327062
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/reveal_hide_animations into lp:widelands.
References