Merge lp:~widelands-dev/widelands/bug-1530370-soldiers-lua into lp:widelands
- bug-1530370-soldiers-lua
- Merge into trunk
Proposed by
GunChleoc
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 7938 | ||||
Proposed branch: | lp:~widelands-dev/widelands/bug-1530370-soldiers-lua | ||||
Merge into: | lp:widelands | ||||
Diff against target: |
387 lines (+292/-21) 4 files modified
data/campaigns/tutorial02_warfare.wmf/scripting/texts.lua (+17/-6) data/tribes/scripting/help/worker_help.lua (+53/-1) src/scripting/lua_map.cc (+178/-14) src/scripting/lua_map.h (+44/-0) |
||||
To merge this branch: | bzr merge lp:~widelands-dev/widelands/bug-1530370-soldiers-lua | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Miroslav Remák | code review + testing | Approve | |
Review via email: mp+290800@code.launchpad.net |
Commit message
The soldier values in the warfare tutorial are now calculated from the actual values. Added soldier values to worker help.
Description of the change
See commit message.
To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote : | # |
Revision history for this message
Miroslav Remák (miroslavr256) wrote : | # |
LGTM, just a few minor typos in documentation (see diff comments).
review:
Approve
(code review + testing)
Revision history for this message
GunChleoc (gunchleoc) wrote : | # |
Thanks!
@bunnybot merge
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'data/campaigns/tutorial02_warfare.wmf/scripting/texts.lua' |
2 | --- data/campaigns/tutorial02_warfare.wmf/scripting/texts.lua 2016-02-17 22:13:21 +0000 |
3 | +++ data/campaigns/tutorial02_warfare.wmf/scripting/texts.lua 2016-04-03 18:54:54 +0000 |
4 | @@ -9,6 +9,10 @@ |
5 | include "scripting/formatting.lua" |
6 | include "scripting/format_scenario.lua" |
7 | |
8 | +-- We want the soldier here so we can get some actual stats. |
9 | +local tribe = wl.Game():get_tribe_description("barbarians") |
10 | +local soldier = wl.Game():get_worker_description(tribe.soldier) |
11 | + |
12 | -- ============= |
13 | -- Texts below |
14 | -- ============= |
15 | @@ -29,17 +33,24 @@ |
16 | body = rt( |
17 | p(_[[A new soldier is created like a worker: when a military building needs a soldier, a carrier grabs the needed weapons and armor from a warehouse (or your headquarters) and walks up the road to your new building. Basic Barbarian soldiers do not use armor, they only need an ax.]]) .. |
18 | p(_[[Take a look at the soldiers that are on their way to our military buildings. They look different from normal workers: they have a health bar over their head that displays their remaining health, and they have four symbols, which symbolize the individual soldier’s current levels in the four different categories: health, attack, defense and evade.]]) .. |
19 | - p(_[[If a Barbarian soldier is fully trained, he has level 3 health, level 5 attack, level 0 defense and level 2 evade. This is one fearsome warrior then! The individual abilities have the following meaning:]]) |
20 | + -- TRANSLATORS: the current stats are: 3 health, 5 attack, 0 defense, 2 evade. |
21 | + p((_[[If a Barbarian soldier is fully trained, he has level %1% health, level %2% attack, level %3% defense and level %4% evade. This is one fearsome warrior then! The individual abilities have the following meaning:]]):bformat(soldier.max_health_level, soldier.max_attack_level, soldier.max_defense_level, soldier.max_evade_level)) |
22 | ) .. |
23 | - rt("image=tribes/workers/barbarians/soldier/health_level0.png", h2(_"Health:")).. |
24 | - rt(p(_[[The total life of a soldier. A Barbarian soldier starts with 130 health, and he will gain 28 health with each health level.]])) .. |
25 | + rt("image=tribes/workers/barbarians/soldier/health_level0.png", h2(_"Health:")) .. |
26 | + -- TRANSLATORS: the current stats are: 13000 health, 2800 health gain. |
27 | + rt(p((_[[The total life of a soldier. A Barbarian soldier starts with %1% health, and he will gain %2% health with each health level.]]):bformat(soldier.base_health, soldier.health_incr_per_level))) .. |
28 | rt("image=tribes/workers/barbarians/soldier/attack_level0.png", h2(_"Attack:")) .. |
29 | - rt(p(_[[The amount of damage a soldier will inflict on the enemy when an attack is successful. A Barbarian soldier with attack level 0 inflicts ~14 points of health damage when he succeeds in hitting an enemy. For each attack level, he gains 7 damage points.]])) .. |
30 | + -- TRANSLATORS: the current stats are: 1400 damage, gains 850 damage points. |
31 | + rt(p(_[[The amount of damage a soldier will inflict on the enemy when an attack is successful. A Barbarian soldier with attack level 0 inflicts ~%1% points of health damage when he succeeds in hitting an enemy. For each attack level, he gains %2% damage points.]]):bformat(soldier.base_min_attack + (soldier.base_max_attack - soldier.base_min_attack) / 2, soldier.attack_incr_per_level)) .. |
32 | -- The Atlanteans' image, because the Barbarian one has a white background |
33 | rt("image=tribes/workers/atlanteans/soldier/defense_level0.png", h2(_"Defense:")) .. |
34 | - rt(p(_[[The defense is the percentage that is subtracted from the attack value. The Barbarians cannot train in this skill and therefore have always defense level 0, which means that the damage is always reduced by 3%. If an attacker with an attack value of 35 points hits a Barbarian soldier, the Barbarian will lose 35·0.97 = 34 health.]])) .. |
35 | + -- TRANSLATORS: the current stats are: 3%. The calculated health value is 3395 |
36 | + -- TRANSLATORS: The last two %% after the placeholder are the percent symbol. |
37 | + rt(p(_[[The defense is the percentage that is subtracted from the attack value. The Barbarians cannot train in this skill and therefore have always defense level 0, which means that the damage is always reduced by %1%%%. If an attacker with an attack value of 3500 points hits a Barbarian soldier, the Barbarian will lose 3500·%2%%% = %3% health.]]):bformat(soldier.base_defense, (100 - soldier.base_defense), 3500 * (100 - soldier.base_defense) / 100)) .. |
38 | rt("image=tribes/workers/barbarians/soldier/evade_level0.png", h2(_"Evade:")) .. |
39 | - rt(p(_[[Evade is the chance that the soldier is able to dodge an attack. A level 0 Barbarian has a 25% chance to evade an attack, and this increases in steps of 15% for each level.]])) |
40 | + -- TRANSLATORS: the current stats are: 25% evade, increases in steps of 15%. |
41 | + -- TRANSLATORS: The last two %% after the placeholder are the percent symbol. |
42 | + rt(p(_[[Evade is the chance that the soldier is able to dodge an attack. A level 0 Barbarian has a %1%%% chance to evade an attack, and this increases in steps of %2%%% for each level.]]):bformat(soldier.base_evade, soldier.evade_incr_per_level)) |
43 | } |
44 | |
45 | battlearena1 = { |
46 | |
47 | === modified file 'data/tribes/scripting/help/worker_help.lua' |
48 | --- data/tribes/scripting/help/worker_help.lua 2016-03-22 07:32:14 +0000 |
49 | +++ data/tribes/scripting/help/worker_help.lua 2016-04-03 18:54:54 +0000 |
50 | @@ -157,7 +157,59 @@ |
51 | worker_description.needed_experience |
52 | ) |
53 | end |
54 | - result = result .. rt("text-align=right", p(exp_string)) |
55 | + result = result .. rt("text-align=right", p(exp_string)) |
56 | + end |
57 | + -- Soldier properties |
58 | + if (worker_description.type_name == "soldier") then |
59 | + -- TRANSLATORS: Soldier levels |
60 | + result = result .. rt(h2(_"Levels")) |
61 | + |
62 | + result = result .. rt(h3(_"Health")) |
63 | + result = result .. rt(p( |
64 | + listitem_bullet( |
65 | + -- TRANSLATORS: Soldier health / defense / evade points. A 5 digit number. |
66 | + (_"Starts at %1% points."):bformat(worker_description.base_health)) .. |
67 | + listitem_bullet( |
68 | + -- TRANSLATORS: Soldier health / attack defense / evade points |
69 | + 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)) .. |
70 | + listitem_bullet( |
71 | + -- TRANSLATORS: Soldier health / attack defense / evade level |
72 | + ngettext("The maximum level is %1%.", "The maximum level is %1%.", worker_description.max_health_level):bformat(worker_description.max_health_level)))) |
73 | + |
74 | + result = result .. rt(h3(_"Attack")) |
75 | + result = result .. rt(p( |
76 | + -- TRANSLATORS: Points are 4 digit numbers. |
77 | + listitem_bullet(_"A random value between %1% and %2% points is added to each attack."):bformat(worker_description.base_min_attack, worker_description.base_max_attack) .. |
78 | + |
79 | + listitem_bullet( |
80 | + 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)) .. |
81 | + listitem_bullet( |
82 | + ngettext("The maximum level is %1%.", "The maximum level is %1%.", worker_description.max_attack_level):bformat(worker_description.max_attack_level)))) |
83 | + |
84 | + result = result .. rt(h3(_"Defense")) |
85 | + if (worker_description.max_defense_level > 0) then |
86 | + result = result .. rt(p( |
87 | + listitem_bullet( |
88 | + (_"Starts at %d%%."):bformat(worker_description.base_defense)) .. |
89 | + listitem_bullet( |
90 | + (_"Increased by %d%% for each level."):bformat(worker_description.defense_incr_per_level)) .. |
91 | + listitem_bullet( |
92 | + ngettext("The maximum level is %1%.", "The maximum level is %1%.", worker_description.max_defense_level):bformat(worker_description.max_defense_level)))) |
93 | + else |
94 | + result = result .. rt(p( |
95 | + listitem_bullet( |
96 | + (_"Starts at %d%%."):bformat(worker_description.base_defense)) .. |
97 | + listitem_bullet(_"This solder cannot be trained in defense"))) |
98 | + end |
99 | + |
100 | + result = result .. rt(h3(_"Evade")) |
101 | + result = result .. rt(p( |
102 | + listitem_bullet( |
103 | + (_"Starts at %d%%."):bformat(worker_description.base_evade)) .. |
104 | + listitem_bullet( |
105 | + (_"Increased by %d%% for each level."):bformat(worker_description.evade_incr_per_level)) .. |
106 | + listitem_bullet( |
107 | + ngettext("The maximum level is %1%.", "The maximum level is %1%.", worker_description.max_evade_level):bformat(worker_description.max_evade_level)))) |
108 | end |
109 | return result |
110 | end |
111 | |
112 | === modified file 'src/scripting/lua_map.cc' |
113 | --- src/scripting/lua_map.cc 2016-03-22 07:32:14 +0000 |
114 | +++ src/scripting/lua_map.cc 2016-04-03 18:54:54 +0000 |
115 | @@ -606,7 +606,7 @@ |
116 | case MapObjectType::CARRIER: |
117 | return CAST_TO_LUA(WorkerDescr, LuaWorkerDescription); |
118 | case MapObjectType::SOLDIER: |
119 | - return CAST_TO_LUA(WorkerDescr, LuaWorkerDescription); |
120 | + return CAST_TO_LUA(SoldierDescr, LuaSoldierDescription); |
121 | case MapObjectType::IMMOVABLE: |
122 | return CAST_TO_LUA(ImmovableDescr, LuaImmovableDescription); |
123 | default: |
124 | @@ -2716,19 +2716,176 @@ |
125 | |
126 | |
127 | |
128 | -/* |
129 | - ========================================================== |
130 | - LUA METHODS |
131 | - ========================================================== |
132 | - */ |
133 | - |
134 | - |
135 | - |
136 | -/* |
137 | - ========================================================== |
138 | - C METHODS |
139 | - ========================================================== |
140 | - */ |
141 | + |
142 | +/* RST |
143 | +SoldierDescription |
144 | +----------------- |
145 | + |
146 | +.. class:: SoldierDescription |
147 | + |
148 | + A static description of a tribe's soldier, so it can be used in help files |
149 | + without having to access an actual instance of the worker on the map. |
150 | + See also class WorkerDescription for more properties. |
151 | +*/ |
152 | +const char LuaSoldierDescription::className[] = "SoldierDescription"; |
153 | +const MethodType<LuaSoldierDescription> LuaSoldierDescription::Methods[] = { |
154 | + {nullptr, nullptr}, |
155 | +}; |
156 | +const PropertyType<LuaSoldierDescription> LuaSoldierDescription::Properties[] = { |
157 | + PROP_RO(LuaSoldierDescription, max_health_level), |
158 | + PROP_RO(LuaSoldierDescription, max_attack_level), |
159 | + PROP_RO(LuaSoldierDescription, max_defense_level), |
160 | + PROP_RO(LuaSoldierDescription, max_evade_level), |
161 | + PROP_RO(LuaSoldierDescription, base_health), |
162 | + PROP_RO(LuaSoldierDescription, base_min_attack), |
163 | + PROP_RO(LuaSoldierDescription, base_max_attack), |
164 | + PROP_RO(LuaSoldierDescription, base_defense), |
165 | + PROP_RO(LuaSoldierDescription, base_evade), |
166 | + PROP_RO(LuaSoldierDescription, health_incr_per_level), |
167 | + PROP_RO(LuaSoldierDescription, attack_incr_per_level), |
168 | + PROP_RO(LuaSoldierDescription, defense_incr_per_level), |
169 | + PROP_RO(LuaSoldierDescription, evade_incr_per_level), |
170 | + {nullptr, nullptr, nullptr}, |
171 | +}; |
172 | + |
173 | + |
174 | +/* |
175 | + ========================================================== |
176 | + PROPERTIES |
177 | + ========================================================== |
178 | + */ |
179 | + |
180 | + |
181 | +/* RST |
182 | + .. attribute:: get_max_health_level |
183 | + |
184 | + (RO) The maximum health level that the soldier can have. |
185 | +*/ |
186 | +int LuaSoldierDescription::get_max_health_level(lua_State * L) { |
187 | + lua_pushinteger(L, get()->get_max_health_level()); |
188 | + return 1; |
189 | +} |
190 | + |
191 | +/* RST |
192 | + .. attribute:: max_attack_level |
193 | + |
194 | + (RO) The maximum attack level that the soldier can have. |
195 | +*/ |
196 | +int LuaSoldierDescription::get_max_attack_level(lua_State * L) { |
197 | + lua_pushinteger(L, get()->get_max_attack_level()); |
198 | + return 1; |
199 | +} |
200 | + |
201 | +/* RST |
202 | + .. attribute:: max_defense_level |
203 | + |
204 | + (RO) The maximum defense level that the soldier can have. |
205 | +*/ |
206 | +int LuaSoldierDescription::get_max_defense_level(lua_State * L) { |
207 | + lua_pushinteger(L, get()->get_max_defense_level()); |
208 | + return 1; |
209 | +} |
210 | + |
211 | +/* RST |
212 | + .. attribute:: max_evade_level |
213 | + |
214 | + (RO) The maximum evade level that the soldier can have. |
215 | +*/ |
216 | +int LuaSoldierDescription::get_max_evade_level(lua_State * L) { |
217 | + lua_pushinteger(L, get()->get_max_evade_level()); |
218 | + return 1; |
219 | +} |
220 | + |
221 | +/* RST |
222 | + .. attribute:: get_base_health |
223 | + |
224 | + (RO) The health points that the soldier starts with |
225 | +*/ |
226 | +int LuaSoldierDescription::get_base_health(lua_State * L) { |
227 | + lua_pushinteger(L, get()->get_base_health()); |
228 | + return 1; |
229 | +} |
230 | + |
231 | + |
232 | +/* RST |
233 | + .. attribute:: base_min_attack |
234 | + |
235 | + (RO) The minimum random attack points that get added to a soldier's attack |
236 | +*/ |
237 | +int LuaSoldierDescription::get_base_min_attack(lua_State * L) { |
238 | + lua_pushinteger(L, get()->get_base_min_attack()); |
239 | + return 1; |
240 | +} |
241 | + |
242 | +/* RST |
243 | + .. attribute:: base_max_attack |
244 | + |
245 | + (RO) The maximum random attack points that get added to a soldier's attack |
246 | +*/ |
247 | +int LuaSoldierDescription::get_base_max_attack(lua_State * L) { |
248 | + lua_pushinteger(L, get()->get_base_max_attack()); |
249 | + return 1; |
250 | +} |
251 | + |
252 | +/* RST |
253 | + .. attribute:: base_defense |
254 | + |
255 | + (RO) The defense % that the soldier starts with |
256 | +*/ |
257 | +int LuaSoldierDescription::get_base_defense(lua_State * L) { |
258 | + lua_pushinteger(L, get()->get_base_defense()); |
259 | + return 1; |
260 | +} |
261 | + |
262 | +/* RST |
263 | + .. attribute:: base_evade |
264 | + |
265 | + (RO) The evade % that the soldier starts with |
266 | +*/ |
267 | +int LuaSoldierDescription::get_base_evade(lua_State * L) { |
268 | + lua_pushinteger(L, get()->get_base_evade()); |
269 | + return 1; |
270 | +} |
271 | + |
272 | +/* RST |
273 | + .. attribute:: get_health_incr_per_level |
274 | + |
275 | + (RO) The health points that the soldier will gain with each level. |
276 | +*/ |
277 | +int LuaSoldierDescription::get_health_incr_per_level(lua_State * L) { |
278 | + lua_pushinteger(L, get()->get_health_incr_per_level()); |
279 | + return 1; |
280 | +} |
281 | + |
282 | +/* RST |
283 | + .. attribute:: attack_incr_per_level |
284 | + |
285 | + (RO) The attack points that the soldier will gain with each level. |
286 | +*/ |
287 | +int LuaSoldierDescription::get_attack_incr_per_level(lua_State * L) { |
288 | + lua_pushinteger(L, get()->get_attack_incr_per_level()); |
289 | + return 1; |
290 | +} |
291 | + |
292 | +/* RST |
293 | + .. attribute:: defense_incr_per_level |
294 | + |
295 | + (RO) The defense % that the soldier will gain with each level. |
296 | +*/ |
297 | +int LuaSoldierDescription::get_defense_incr_per_level(lua_State * L) { |
298 | + lua_pushinteger(L, get()->get_defense_incr_per_level()); |
299 | + return 1; |
300 | +} |
301 | + |
302 | +/* RST |
303 | + .. attribute:: evade_incr_per_level |
304 | + |
305 | + (RO) The evade % that the soldier will gain with each level. |
306 | +*/ |
307 | +int LuaSoldierDescription::get_evade_incr_per_level(lua_State * L) { |
308 | + lua_pushinteger(L, get()->get_evade_incr_per_level()); |
309 | + return 1; |
310 | +} |
311 | |
312 | /* RST |
313 | ResourceDescription |
314 | @@ -3142,6 +3299,8 @@ |
315 | return CAST_TO_LUA(ImmovableDescr, LuaImmovableDescription); |
316 | case (MapObjectType::WORKER): |
317 | return CAST_TO_LUA(WorkerDescr, LuaWorkerDescription); |
318 | + case (MapObjectType::SOLDIER): |
319 | + return CAST_TO_LUA(SoldierDescr, LuaSoldierDescription); |
320 | default: |
321 | return CAST_TO_LUA(MapObjectDescr, LuaMapObjectDescription); |
322 | } |
323 | @@ -5536,6 +5695,11 @@ |
324 | add_parent<LuaWorkerDescription, LuaMapObjectDescription>(L); |
325 | lua_pop(L, 1); // Pop the meta table |
326 | |
327 | + register_class<LuaSoldierDescription>(L, "map", true); |
328 | + add_parent<LuaSoldierDescription, LuaWorkerDescription>(L); |
329 | + add_parent<LuaSoldierDescription, LuaMapObjectDescription>(L); |
330 | + lua_pop(L, 1); // Pop the meta table |
331 | + |
332 | register_class<LuaResourceDescription>(L, "map"); |
333 | register_class<LuaTerrainDescription>(L, "map"); |
334 | |
335 | |
336 | === modified file 'src/scripting/lua_map.h' |
337 | --- src/scripting/lua_map.h 2016-03-14 19:56:14 +0000 |
338 | +++ src/scripting/lua_map.h 2016-04-03 18:54:54 +0000 |
339 | @@ -558,6 +558,50 @@ |
340 | CASTED_GET_DESCRIPTION(WorkerDescr) |
341 | }; |
342 | |
343 | + |
344 | +class LuaSoldierDescription : public LuaWorkerDescription { |
345 | +public: |
346 | + LUNA_CLASS_HEAD(LuaSoldierDescription); |
347 | + |
348 | + virtual ~LuaSoldierDescription() {} |
349 | + |
350 | + LuaSoldierDescription() {} |
351 | + LuaSoldierDescription(const Widelands::SoldierDescr* const soldierdescr) |
352 | + : LuaWorkerDescription(soldierdescr) { |
353 | + } |
354 | + LuaSoldierDescription(lua_State* L) : LuaWorkerDescription(L) { |
355 | + } |
356 | + |
357 | + |
358 | + /* |
359 | + * Properties |
360 | + */ |
361 | + int get_max_health_level(lua_State*); |
362 | + int get_max_attack_level(lua_State*); |
363 | + int get_max_defense_level(lua_State*); |
364 | + int get_max_evade_level(lua_State*); |
365 | + int get_base_health(lua_State*); |
366 | + int get_base_min_attack(lua_State*); |
367 | + int get_base_max_attack(lua_State*); |
368 | + int get_base_defense(lua_State*); |
369 | + int get_base_evade(lua_State*); |
370 | + int get_health_incr_per_level(lua_State*); |
371 | + int get_attack_incr_per_level(lua_State*); |
372 | + int get_defense_incr_per_level(lua_State*); |
373 | + int get_evade_incr_per_level(lua_State*); |
374 | + |
375 | + /* |
376 | + * Lua methods |
377 | + */ |
378 | + |
379 | + /* |
380 | + * C methods |
381 | + */ |
382 | + |
383 | +private: |
384 | + CASTED_GET_DESCRIPTION(SoldierDescr) |
385 | +}; |
386 | + |
387 | #undef CASTED_GET_DESCRIPTION |
388 | |
389 |
Continuous integration builds have changed state:
Travis build 937. State: passed. Details: https:/ /travis- ci.org/ widelands/ widelands/ builds/ 120305987. /ci.appveyor. com/project/ widelands- dev/widelands/ build/_ widelands_ dev_widelands_ bug_1530370_ soldiers_ lua-770.
Appveyor build 770. State: success. Details: https:/