Merge lp:~widelands-dev/widelands/bug-1455732 into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 7468
Proposed branch: lp:~widelands-dev/widelands/bug-1455732
Merge into: lp:widelands
Diff against target: 168 lines (+66/-33)
3 files modified
src/scripting/lua_map.cc (+46/-20)
src/scripting/lua_map.h (+19/-12)
tribes/scripting/format_help.lua (+1/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1455732
Reviewer Review Type Date Requested Status
TiborB Approve
GunChleoc Needs Resubmitting
Hans Joachim Desserud Needs Fixing
Review via email: mp+259326@code.launchpad.net

Description of the change

This fixes a bug in the Tribal Encyclopedia where Dismantlesites weren't persisted.

We still have a bug with the Constructionsite that I can't figure out.

To post a comment you must log in.
Revision history for this message
Hans Joachim Desserud (hjd) wrote :

Hi, I did some quick testing of this patch. I found that if any mine is selected, I get a similar crash when attempting to save. I guess that needs a similar fix.

I saw some crashes when selecting dismantling site and then something else, but those might have been caused by the other building happening to be a mine. Hard to tell, but I can check again once that's fixed.

I only skimmed the code changes, but thumbs up for replacing the if statements with a switch, :)

review: Needs Fixing
Revision history for this message
GunChleoc (gunchleoc) wrote :

Good catch, the culprit is actually the mine, not the construction site.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Found the other bug - a global variable in Lua. The bug has been there for a while, ever since we added the automated building help.

review: Needs Resubmitting
Revision history for this message
Hans Joachim Desserud (hjd) wrote :

I am no longer able to trigger a crash when selecting things in the building list and saving. :)

I have not reviewed the code.

Revision history for this message
TiborB (tiborb95) wrote :

I have not tested it but the code looks good to me :)

review: Approve
Revision history for this message
GunChleoc (gunchleoc) wrote :

I think we're good to go then. Will merge.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/scripting/lua_map.cc'
2--- src/scripting/lua_map.cc 2015-05-10 10:59:28 +0000
3+++ src/scripting/lua_map.cc 2015-05-21 06:58:26 +0000
4@@ -550,6 +550,8 @@
5 switch (descr->type()) {
6 case MapObjectType::CONSTRUCTIONSITE:
7 return CAST_TO_LUA(ConstructionSiteDescr, LuaConstructionSiteDescription);
8+ case MapObjectType::DISMANTLESITE:
9+ return CAST_TO_LUA(DismantleSiteDescr, LuaDismantleSiteDescription);
10 case MapObjectType::PRODUCTIONSITE:
11 return CAST_TO_LUA(ProductionSiteDescr, LuaProductionSiteDescription);
12 case MapObjectType::MILITARYSITE:
13@@ -1357,6 +1359,26 @@
14
15
16 /* RST
17+DismantleSiteDescription
18+---------------------------
19+
20+.. class:: DismantleSiteDescription
21+
22+ A static description of a tribe's dismantlesite, so it can be used in help files
23+ without having to access an actual building on the map.
24+ See also class BuildingDescription and class MapObjectDescription for more properties.
25+*/
26+const char LuaDismantleSiteDescription::className[] = "DismantleSiteDescription";
27+const MethodType<LuaDismantleSiteDescription> LuaDismantleSiteDescription::Methods[] = {
28+ {nullptr, nullptr},
29+};
30+const PropertyType<LuaDismantleSiteDescription> LuaDismantleSiteDescription::Properties[] = {
31+ {nullptr, nullptr, nullptr},
32+};
33+
34+
35+
36+/* RST
37 ProductionSiteDescription
38 -------------------------
39
40@@ -2085,31 +2107,30 @@
41 /* RST
42 .. attribute:: descr
43
44- (RO) The description object for this immovable, e.g. BuildingDescription.
45+ (RO) The description object for this immovable, e.g. BuildingDescription.
46 */
47 int LuaMapObject::get_descr(lua_State * L) {
48 const MapObjectDescr* desc = &get(L, get_egbase(L))->descr();
49 assert(desc != nullptr);
50
51- if (is_a(MilitarySiteDescr, desc)) {
52- return CAST_TO_LUA(MilitarySiteDescr, LuaMilitarySiteDescription);
53- }
54- else if (is_a(TrainingSiteDescr, desc)) {
55- return CAST_TO_LUA(TrainingSiteDescr, LuaTrainingSiteDescription);
56- }
57- else if (is_a(ProductionSiteDescr, desc)) {
58- return CAST_TO_LUA(ProductionSiteDescr, LuaProductionSiteDescription);
59- }
60- else if (is_a(WarehouseDescr, desc)) {
61- return CAST_TO_LUA(WarehouseDescr, LuaWarehouseDescription);
62- }
63- else if (is_a(ConstructionSiteDescr, desc)) {
64- return CAST_TO_LUA(ConstructionSiteDescr, LuaConstructionSiteDescription);
65- }
66- else if (is_a(BuildingDescr, desc)) {
67- return CAST_TO_LUA(BuildingDescr, LuaBuildingDescription);
68- }
69- return CAST_TO_LUA(MapObjectDescr, LuaMapObjectDescription);
70+ switch (desc->type()) {
71+ case (MapObjectType::BUILDING):
72+ return CAST_TO_LUA(BuildingDescr, LuaBuildingDescription);
73+ case (MapObjectType::CONSTRUCTIONSITE):
74+ return CAST_TO_LUA(ConstructionSiteDescr, LuaConstructionSiteDescription);
75+ case (MapObjectType::DISMANTLESITE):
76+ return CAST_TO_LUA(DismantleSiteDescr, LuaDismantleSiteDescription);
77+ case (MapObjectType::PRODUCTIONSITE):
78+ return CAST_TO_LUA(ProductionSiteDescr, LuaProductionSiteDescription);
79+ case (MapObjectType::MILITARYSITE):
80+ return CAST_TO_LUA(MilitarySiteDescr, LuaMilitarySiteDescription);
81+ case (MapObjectType::TRAININGSITE):
82+ return CAST_TO_LUA(TrainingSiteDescr, LuaTrainingSiteDescription);
83+ case (MapObjectType::WAREHOUSE):
84+ return CAST_TO_LUA(WarehouseDescr, LuaWarehouseDescription);
85+ default:
86+ return CAST_TO_LUA(MapObjectDescr, LuaMapObjectDescription);
87+ }
88 }
89
90 #undef CAST_TO_LUA
91@@ -4452,6 +4473,11 @@
92 add_parent<LuaConstructionSiteDescription, LuaMapObjectDescription>(L);
93 lua_pop(L, 1); // Pop the meta table
94
95+ register_class<LuaDismantleSiteDescription>(L, "map", true);
96+ add_parent<LuaDismantleSiteDescription, LuaBuildingDescription>(L);
97+ add_parent<LuaDismantleSiteDescription, LuaMapObjectDescription>(L);
98+ lua_pop(L, 1); // Pop the meta table
99+
100 register_class<LuaProductionSiteDescription>(L, "map", true);
101 add_parent<LuaProductionSiteDescription, LuaBuildingDescription>(L);
102 add_parent<LuaProductionSiteDescription, LuaMapObjectDescription>(L);
103
104=== modified file 'src/scripting/lua_map.h'
105--- src/scripting/lua_map.h 2015-05-10 10:59:28 +0000
106+++ src/scripting/lua_map.h 2015-05-21 06:58:26 +0000
107@@ -26,6 +26,7 @@
108 #include "economy/portdock.h"
109 #include "economy/road.h"
110 #include "logic/constructionsite.h"
111+#include "logic/dismantlesite.h"
112 #include "logic/game.h"
113 #include "logic/militarysite.h"
114 #include "logic/productionsite.h"
115@@ -204,22 +205,28 @@
116 LuaConstructionSiteDescription(lua_State* L) : LuaBuildingDescription(L) {
117 }
118
119- /*
120- * Properties
121- */
122-
123- /*
124- * Lua methods
125- */
126-
127- /*
128- * C methods
129- */
130-
131 private:
132 CASTED_GET_DESCRIPTION(ConstructionSiteDescr)
133 };
134
135+class LuaDismantleSiteDescription : public LuaBuildingDescription {
136+public:
137+ LUNA_CLASS_HEAD(LuaDismantleSiteDescription);
138+
139+ virtual ~LuaDismantleSiteDescription() {}
140+
141+ LuaDismantleSiteDescription() {}
142+ LuaDismantleSiteDescription(const Widelands::DismantleSiteDescr* const dismantlesitedescr)
143+ : LuaBuildingDescription(dismantlesitedescr) {
144+ }
145+ LuaDismantleSiteDescription(lua_State* L) : LuaBuildingDescription(L) {
146+ }
147+
148+private:
149+ CASTED_GET_DESCRIPTION(DismantleSiteDescr)
150+};
151+
152+
153
154 class LuaProductionSiteDescription : public LuaBuildingDescription {
155 public:
156
157=== modified file 'tribes/scripting/format_help.lua'
158--- tribes/scripting/format_help.lua 2014-10-19 12:02:45 +0000
159+++ tribes/scripting/format_help.lua 2015-05-21 06:58:26 +0000
160@@ -120,7 +120,7 @@
161 if not text then
162 text = ""
163 end
164- string = "image=tribes/" .. tribename .. "/" .. resource .. "/resi_00.png"
165+ local string = "image=tribes/" .. tribename .. "/" .. resource .. "/resi_00.png"
166 for k,v in ipairs({table.unpack(items)}) do
167 string = string .. ";pics/arrow-right.png;" .. v.icon_name
168 end

Subscribers

People subscribed via source and target branches

to status/vote changes: