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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
|
-- RST
-- worker_help.lua
-- ---------------
--
-- This script returns a formatted entry for the ingame worker help.
-- Pass the internal tribe name and worker name to the coroutine to select the
-- worker type.
include "tribes/scripting/help/format_help.lua"
include "tribes/scripting/help/calculations.lua"
-- =======================================================
-- ************* Main worker help functions *************
-- =======================================================
-- RST
-- .. function:: worker_help_producers_string(worker_description)
--
-- Displays the buildings that can produce the worker
--
-- :arg tribe: the worker's tribe from C++.
-- :arg worker_description: the worker_description from C++.
-- :returns: Info about buildings that produce this worker
--
function worker_help_producers_string(tribe, worker_description)
local result = ""
for i, building in ipairs(tribe.buildings) do
if (building.type_name == "productionsite") then
local recruits_this = false;
for j, output in ipairs(building.output_worker_types) do
if (output.name == worker_description.name) then
recruits_this = true;
break;
end
end
if (recruits_this) then
-- TRANSLATORS: Worker Encyclopedia: A building recruiting a worker
result = result .. h2(_("Producer"))
result = result .. dependencies({building, worker_description}, linkify_encyclopedia_object(building))
-- -- Find out which programs in the building recruit this worker if any
producing_programs, recruited_workers_counters, recruited_workers_strings = programs_workers_count(tribe, building, worker_description)
-- Now collect the consumed wares for each filtered program and print the program info
for j, program_name in ipairs(producing_programs) do
result = result .. help_consumed_wares_workers(tribe, building, program_name)
if (recruited_workers_counters[program_name] > 0) then
if (recruited_workers_counters[program_name] == 1) then
-- TRANSLATORS: Worker Encyclopedia: 1 worker recruited by a productionsite
result = result .. h3(_("Worker recruited:"))
else
-- TRANSLATORS: Worker Encyclopedia: More than 1 worker recruited by a productionsite
result = result .. h3(_("Workers recruited:"))
end
result = result .. recruited_workers_strings[program_name]
end
end
end
end
end
return result
end
-- RST
-- .. function:: worker_help_employers_string(worker_description)
--
-- Displays the buildings where the worker can work
--
-- :arg worker_description: the worker_description from C++.
-- :returns: Info about buildings that use this worker
--
function worker_help_employers_string(worker_description)
local result = ""
if (#worker_description.employers > 0) then
local normal = {}
local additional = {}
if (#worker_description.employers == 1) then
-- TRANSLATORS: Worker Encyclopedia: Heading for 1 building where a worker can work
-- TRANSLATORS: You can also translate this as 'workplace'
result = result .. h2(pgettext("workerhelp_one_building", "Works at"))
else
-- TRANSLATORS: Worker Encyclopedia: A list of more than 1 building where a worker can work
-- TRANSLATORS: You can also translate this as 'workplaces'
result = result .. h2(pgettext("workerhelp_multiple_buildings", "Works at"))
end
for i, building in ipairs(worker_description.employers) do
result = result .. dependencies({worker_description, building}, linkify_encyclopedia_object(building))
normal[building.name] = true
end
building = worker_description.employers[1]
if #building.working_positions > 1 and worker_description.name ~= building.working_positions[1].name then
for i, build in ipairs(building.working_positions[1].employers) do
if not normal[build.name] then
table.insert(additional, build)
end
end
if #additional == 1 then
-- Translators: Worker Encyclopedia: Heading above a list 1 building where a worker may work instead of a less experienced worker
-- TRANSLATORS: You can also translate this as 'additional workplace'
result = result .. h2(pgettext("workerhelp_one_building", "Can also work at"))
else
-- Translators: Worker Encyclopedia: Heading above a list of buildings where a worker may work instead of a less experienced worker
-- TRANSLATORS: You can also translate this as 'additional workplaces'
result = result .. h2(pgettext("workerhelp_multiple_buildings", "Can also work at"))
end
for i, build in ipairs(additional) do
result = result .. dependencies({worker_description, build}, linkify_encyclopedia_object(build))
end
end
end
return result
end
-- RST
-- .. function:: worker_help_string(worker_description)
--
-- Displays the worker with a helptext, an image and the tool used
--
-- :arg tribe: The :class:`LuaTribeDescription` for the tribe
-- that we are displaying this help for.
-- :arg worker_description: the worker_description from C++.
--
-- :returns: Help string for the worker
--
function worker_help_string(tribe, worker_description)
local helptexts = worker_description:helptexts(tribe.name)
local result = ""
if helptexts["purpose"] ~= nil then
result = h2(_("Purpose")) ..
li_image(worker_description.icon_name, helptexts["purpose"])
else
result = img(worker_description.icon_name)
end
if helptexts["note"] ~= nil then
result = result .. h2(_("Note")) .. p(helptexts["note"])
end
if (worker_description.buildable) then
-- Get the tools for the workers.
local toolnames = {}
for j, buildcost in ipairs(worker_description.buildcost) do
if (buildcost ~= nil and (tribe:has_ware(buildcost) or (tribe:has_worker(buildcost) and buildcost ~= tribe.carriers[1]))) then
toolnames[#toolnames + 1] = buildcost
end
end
if (#toolnames > 0) then
local tool_string = help_tool_string(tribe, toolnames, 1)
-- TRANSLATORS: Tribal Encyclopedia: Heading for which tool a worker uses
result = result .. h2(_("Worker uses")) .. tool_string
end
else
result = result .. worker_help_producers_string(tribe, worker_description)
end
result = result .. worker_help_employers_string(worker_description)
-- TODO(hessenfarmer): make this work for more then 2 promotion steps
local becomes_description = worker_description.becomes
local promoted_from_description = worker_description.promoted_from
if (promoted_from_description) then
becomes_description = worker_description
if (promoted_from_description.promoted_from) then
becomes_description = promoted_from_description
promoted_from_description = promoted_from_description.promoted_from
end
else
promoted_from_description = worker_description
end
if (becomes_description) then
result = result .. h2(_("Experience levels"))
result = result .. help_worker_experience(promoted_from_description, becomes_description)
end
-- Soldier properties
if (worker_description.type_name == "soldier") then
-- TRANSLATORS: Soldier levels
result = result .. h2(_("Levels"))
result = result .. h3(_("Health"))
result = result ..
li(
-- TRANSLATORS: Soldier health / defense / evade points. A 5 digit number.
(_("Starts at %1% points.")):bformat(worker_description.base_health)) ..
li(
-- TRANSLATORS: Soldier health / attack defense / evade points
ngettext("Increased by %1% point for each level.", "Increased by %1% points for each level.", worker_description.health_incr_per_level):bformat(worker_description.health_incr_per_level)) ..
li(
-- TRANSLATORS: Soldier health / attack defense / evade level
ngettext("The maximum level is %1%.", "The maximum level is %1%.", worker_description.max_health_level):bformat(worker_description.max_health_level))
result = result .. h3(_("Attack"))
result = result ..
-- TRANSLATORS: Points are 4 digit numbers.
li(_("A random value between %1% and %2% points is added to each attack.")):bformat(worker_description.base_min_attack, worker_description.base_max_attack) ..
li(
ngettext("Increased by %1% point for each level.", "Increased by %1% points for each level.", worker_description.attack_incr_per_level):bformat(worker_description.attack_incr_per_level)) ..
li(
ngettext("The maximum level is %1%.", "The maximum level is %1%.", worker_description.max_attack_level):bformat(worker_description.max_attack_level))
result = result .. h3(_("Defense"))
if (worker_description.max_defense_level > 0) then
result = result ..
li(
(_("Starts at %d%%.")):bformat(worker_description.base_defense)) ..
li(
(_("Increased by %d%% for each level.")):bformat(worker_description.defense_incr_per_level)) ..
li(
ngettext("The maximum level is %1%.", "The maximum level is %1%.", worker_description.max_defense_level):bformat(worker_description.max_defense_level))
else
result = result ..
li(
(_("Starts at %d%%.")):bformat(worker_description.base_defense)) ..
li(_("This soldier cannot be trained in defense."))
end
result = result .. h3(_("Evade"))
result = result ..
li(
(_("Starts at %d%%.")):bformat(worker_description.base_evade)) ..
li(
(_("Increased by %d%% for each level.")):bformat(worker_description.evade_incr_per_level)) ..
li(
ngettext("The maximum level is %1%.", "The maximum level is %1%.", worker_description.max_evade_level):bformat(worker_description.max_evade_level))
end
return result
end
return {
func = function(tribename, workername)
push_textdomain("tribes_encyclopedia")
local tribe = wl.Game():get_tribe_description(tribename)
local worker_description = wl.Game():get_worker_description(workername)
local r = {
title = worker_description.descname,
text = worker_help_string(tribe, worker_description)
}
pop_textdomain()
return r
end
}
|