widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #06365
[Merge] lp:~widelands-dev/widelands/employers into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/employers into lp:widelands.
Commit message:
Added the buildings where a worker can work to worker help.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/employers/+merge/287384
Added the buildings where a worker can work to worker help.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/employers into lp:widelands.
=== modified file 'data/tribes/scripting/help/building_help.lua'
--- data/tribes/scripting/help/building_help.lua 2016-02-14 16:31:07 +0000
+++ data/tribes/scripting/help/building_help.lua 2016-02-27 09:19:24 +0000
@@ -662,7 +662,11 @@
end
end
- result = result .. help_tool_string(tribe, toolnames, number_of_workers)
+ if (number_of_workers > 0) then
+ local tool_string = help_tool_string(tribe, toolnames, number_of_workers)
+ -- TRANSLATORS: Tribal Encyclopedia: Heading for which tool workers use
+ result = result .. rt(h3(ngettext("Worker uses:","Workers use:", number_of_workers))) .. tool_string
+ end
if(becomes_description) then
=== modified file 'data/tribes/scripting/help/format_help.lua'
--- data/tribes/scripting/help/format_help.lua 2016-01-28 05:24:34 +0000
+++ data/tribes/scripting/help/format_help.lua 2016-02-27 09:19:24 +0000
@@ -106,10 +106,6 @@
result = result .. image_line(ware_description.icon_name, 1, p(ware_description.descname))
end
end
- if (result ~= "") then
- -- TRANSLATORS: Tribal Encyclopedia: Heading for which tools a worker uses
- result = rt(h3(ngettext("Worker uses:","Workers use:", no_of_workers))) .. result
- end
return result
end
=== modified file 'data/tribes/scripting/help/worker_help.lua'
--- data/tribes/scripting/help/worker_help.lua 2015-11-05 12:53:49 +0000
+++ data/tribes/scripting/help/worker_help.lua 2016-02-27 09:19:24 +0000
@@ -76,6 +76,31 @@
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 = ""
+ local employers = worker_description.employers;
+
+ if (#employers > 0) then
+ -- TRANSLATORS: Worker Encyclopedia: A list of buildings where a worker can work
+ -- TRANSLATORS: You can also translate this as 'workplace(s)'
+ result = result .. rt(h2(ngettext("Works at", "Works at", #employers)))
+ for i, building in ipairs(worker_description.employers) do
+ result = result .. dependencies({worker_description, building}, building.descname)
+ end
+ end
+ return result
+end
+
+
-- RST
-- .. function worker_help_string(worker_description)
--
@@ -102,19 +127,22 @@
end
end
- if(#toolnames > 0) then
- result = result .. help_tool_string(tribe, toolnames, 1)
+ 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 .. rt(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(GunChleoc): Add "enhanced from" info in one_tribe branch
local becomes_description = worker_description.becomes
if (becomes_description) then
- result = result .. rt(h3(_"Experience levels:"))
+ result = result .. rt(h2(_"Experience levels"))
local exp_string = _"%s to %s (%s EP)":format(
worker_description.descname,
becomes_description.descname,
=== modified file 'src/logic/map_objects/tribes/tribes.cc'
--- src/logic/map_objects/tribes/tribes.cc 2016-01-23 16:35:30 +0000
+++ src/logic/map_objects/tribes/tribes.cc 2016-02-27 09:19:24 +0000
@@ -366,6 +366,9 @@
for (const DescriptionIndex& wareindex : de->output_ware_types()) {
wares_->get_mutable(wareindex)->add_producer(i);
}
+ for (const WareAmount& job : de->working_positions()) {
+ workers_->get_mutable(job.first)->add_employer(i);
+ }
}
// Register which buildings buildings can have been enhanced from
=== modified file 'src/logic/map_objects/tribes/worker_descr.cc'
--- src/logic/map_objects/tribes/worker_descr.cc 2015-12-11 19:06:50 +0000
+++ src/logic/map_objects/tribes/worker_descr.cc 2016-02-27 09:19:24 +0000
@@ -206,4 +206,13 @@
return egbase_.tribes().worker_index(name());
}
-}
+void WorkerDescr::add_employer(const DescriptionIndex& building_index) {
+ employers_.insert(building_index);
+}
+
+const std::set<DescriptionIndex>& WorkerDescr::employers() const {
+ return employers_;
+}
+
+
+} // namespace Widelands
=== modified file 'src/logic/map_objects/tribes/worker_descr.h'
--- src/logic/map_objects/tribes/worker_descr.h 2015-12-11 19:06:50 +0000
+++ src/logic/map_objects/tribes/worker_descr.h 2016-02-27 09:19:24 +0000
@@ -95,6 +95,12 @@
DescriptionIndex worker_index() const;
bool can_act_as(DescriptionIndex) const;
+ // Add a building to the list of employers
+ void add_employer(const DescriptionIndex& building_index);
+
+ // The buildings where this worker can work
+ const std::set<DescriptionIndex>& employers() const;
+
Worker & create
(EditorGameBase &, Player &, PlayerImmovable *, Coords) const;
@@ -123,6 +129,7 @@
*/
DescriptionIndex becomes_;
Programs programs_;
+ std::set<DescriptionIndex> employers_; // Buildings where ths worker can work
private:
const EditorGameBase& egbase_;
DISALLOW_COPY_AND_ASSIGN(WorkerDescr);
=== modified file 'src/scripting/lua_map.cc'
--- src/scripting/lua_map.cc 2016-02-18 08:42:46 +0000
+++ src/scripting/lua_map.cc 2016-02-27 09:19:24 +0000
@@ -2602,6 +2602,7 @@
const PropertyType<LuaWorkerDescription> LuaWorkerDescription::Properties[] = {
PROP_RO(LuaWorkerDescription, becomes),
PROP_RO(LuaWorkerDescription, buildcost),
+ PROP_RO(LuaWorkerDescription, employers),
PROP_RO(LuaWorkerDescription, helptext_script),
PROP_RO(LuaWorkerDescription, is_buildable),
PROP_RO(LuaWorkerDescription, needed_experience),
@@ -2665,6 +2666,22 @@
}
/* RST
+ .. attribute:: employers
+ (RO) An array with :class:`LuaBuildingDescription` with buildings where
+ this worker can be employed.
+*/
+int LuaWorkerDescription::get_employers(lua_State * L) {
+ lua_newtable(L);
+ int index = 1;
+ for (const DescriptionIndex& building_index : get()->employers()) {
+ lua_pushint32(L, index++);
+ upcasted_map_object_descr_to_lua(L, get_egbase(L).tribes().get_building_descr(building_index));
+ lua_rawset(L, -3);
+ }
+ return 1;
+}
+
+/* RST
.. attribute:: helptext_script
(RO) The path and filename to the worker's helptext script
=== modified file 'src/scripting/lua_map.h'
--- src/scripting/lua_map.h 2016-02-14 16:31:07 +0000
+++ src/scripting/lua_map.h 2016-02-27 09:19:24 +0000
@@ -541,6 +541,7 @@
*/
int get_becomes(lua_State*);
int get_buildcost(lua_State*);
+ int get_employers(lua_State*);
int get_helptext_script(lua_State*);
int get_is_buildable(lua_State*);
int get_needed_experience(lua_State*);
Follow ups