1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
-- RST
-- immovable_help.lua
-- ------------------
--
-- This script returns a formatted entry for the in-game immovable help (Tribal Encyclopedia).
-- Pass the internal tribe name and immovable name to the coroutine to select the
-- immovable type.
include "tribes/scripting/help/format_help.lua"
-- =======================================================
-- ************ Main immovable help functions ************
-- =======================================================
-- RST
-- .. function:: immovable_help_string(tribe, immovable_description)
--
-- Displays the immovable with a helptext.
--
-- :arg tribe: the tribe that we are displaying this help for; the same immovable
-- can be used by various tribes in different ways.
-- :type tribe: :class:`LuaTribeDescription`
--
-- :arg immovable_description: the immovable_description that the help is
-- being displayed for.
-- :type immovable_description: :class:`LuaImmovableDescription`
--
-- :returns: Help string for the immovable
--
function immovable_help_string(tribe, immovable_description)
local helptexts = immovable_description:helptexts(tribe.name)
local result = ""
local image = immovable_description.icon_name
if helptexts.purpose ~= nil then
result = h2(_("Purpose")) ..
li_object(immovable_description.name, helptexts.purpose)
elseif image ~= "" then
result = p(vspace(styles.get_size("wui_space_before_immovable_icon")) ..
img(immovable_description.icon_name))
end
if helptexts.note ~= nil then
result = result .. h2(_("Note")) .. p(helptexts.note)
end
-- Build cost
local buildcost = ""
for ware, amount in pairs(immovable_description.buildcost) do
local ware_description = wl.Game():get_ware_description(ware)
buildcost = buildcost .. help_ware_amount_line(ware_description, amount)
end
-- Space required
local space_required = plot_size_line(immovable_description.size)
if (buildcost ~= "" or space_required ~= "") then
if (buildcost ~= "") then
result = result .. h2(_("Requirements"))
result = result .. h3(_("Build cost:")) .. buildcost
result = result .. plot_size_line(immovable_description.size)
else
result = result .. h2(_("Size"))
result = result .. plot_size_line(immovable_description.size, true)
end
if (immovable_description.size == "small") then
result = result .. p(_("Workers and animals can walk across fields with this immovable."))
else
result = result .. p(_("Workers and animals can’t walk across fields with this immovable."))
end
end
local becomes_list = immovable_description.becomes
if (#becomes_list > 0) then
result = result .. h2(_("Becomes"))
for index, target in ipairs(becomes_list) do
local target_description = nil
if (wl.Game():immovable_exists(target)) then
-- We turn into another immovable
target_description = wl.Game():get_immovable_description(target)
else
-- Target must be a ship
target_description = wl.Game():get_ship_description(target)
end
if (target_description ~= nil) then
local icon = target_description.icon_name
local target_rt = immovable_description:has_attribute("tree") and target_description.descname or linkify_encyclopedia_object(target_description)
if (icon ~= "") then
result = result .. li_image(icon, target_rt)
else
result = result .. li(target_rt)
end
end
end
end
-- Terrain affinity
local affinity = immovable_description.terrain_affinity
if (affinity ~= nil) then
include "scripting/help.lua"
result = result .. h2(_("Preferred Terrains"))
result = result .. terrain_affinity_help(immovable_description)
end
return result
end
return {
func = function(tribename, immovablename)
push_textdomain("tribes_encyclopedia")
local tribe = wl.Game():get_tribe_description(tribename)
local immovable_description = wl.Game():get_immovable_description(immovablename)
local t = immovable_description.descname
if immovable_description:has_attribute("tree") then
t = immovable_description.species
end
local r = {
title = t,
text = immovable_help_string(tribe, immovable_description)
}
pop_textdomain()
return r
end
}
|